Skip to content

Commit

Permalink
Merge pull request #8 from VictorSt3/master
Browse files Browse the repository at this point in the history
fix: normalize path for windows systems
  • Loading branch information
atanasster authored Oct 7, 2020
2 parents d63c505 + 3224214 commit 4898141
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 11 deletions.
2 changes: 2 additions & 0 deletions core/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ export type SetControlValueFn = (
value: any,
) => void;
export type ClickControlFn = (storyId: string, propertyName: string) => void;

export const normalizePath = (fillePath: string) => process.platform === 'win32' ? fillePath.replace(/\\/g, '\\\\') : fillePath;
13 changes: 7 additions & 6 deletions core/loader/src/replaceSource.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RequireContextProps } from '@component-controls/config';
import { BuildConfiguration } from '@component-controls/core';
import { BuildConfiguration, normalizePath } from '@component-controls/core';

export interface StoryPath {
absPath: string;
Expand All @@ -12,18 +12,19 @@ export const replaceSource = (
config: BuildConfiguration | undefined,
hashKey: string,
) => {

const imports = `
const configJSON = ${
configFilePath ? `require("${configFilePath}")` : 'undefined'
configFilePath ? `require("${normalizePath(configFilePath)}")` : 'undefined'
};
const contexts = [];
${contexts
.map(
context =>
`contexts.push({
folder: "${context.directory}",
req: require.context('${context.directory}', ${
folder: "${normalizePath(context.directory)}",
req: require.context('${normalizePath(context.directory)}', ${
context.useSubdirectories ? 'true' : 'false'
}, ${context.regExp})
});`,
Expand Down Expand Up @@ -54,9 +55,9 @@ ${contexts
let exports = null;
for (const context of contexts) {
const key = context.req.keys().find(k => {
const fullPath = path.resolve(context.folder, k);
const fullPath = path.join(context.folder, k).split('/').join('\\\\');
return doc.fileName === fullPath;
})
});
if (key) {
exports = context.req(key);
break;
Expand Down
9 changes: 6 additions & 3 deletions core/store/src/webpack/loader.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { loader } from 'webpack';
import { getOptions } from 'loader-utils';
import { normalizePath } from '@component-controls/core';

module.exports = function(content: string) {
const context = (this as unknown) as loader.LoaderContext;
const options = getOptions(context) || {};
const { bundleFileName } = options;
const bundleNormalized = normalizePath(bundleFileName);
content = `
import { loadStore } from './dist/load-store';
export let store = loadStore(require('${bundleFileName}'));
export let store = loadStore(require('${bundleNormalized}'));
if (module.hot) {
module.hot.accept('${bundleFileName}', () => {
import('${bundleFileName}').then(updated => {
module.hot.accept('${bundleNormalized}', () => {
import('${bundleNormalized}').then(updated => {
store = loadStore(updated);
});
});
Expand Down
3 changes: 2 additions & 1 deletion core/store/src/webpack/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as path from 'path';
import * as webpack from 'webpack';
import { normalizePath } from '@component-controls/core';

export interface StorePluginOptions {
bundleFileName: string;
Expand All @@ -19,7 +20,7 @@ export class StorePlugin {

private installStoreLoader(compiler: webpack.Compiler) {
const nmrp = new webpack.NormalModuleReplacementPlugin(
new RegExp(path.resolve(__dirname, '../controls-store.js')),
new RegExp(normalizePath(path.resolve(__dirname, '../controls-store.js'))),
(resource: any) => {
if (resource.resource) {
resource.loaders.push({
Expand Down
1 change: 1 addition & 0 deletions core/webpack-compile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
},
"license": "MIT",
"dependencies": {
"@component-controls/config": "^1.27.0",
"@component-controls/loader": "^1.27.2",
"@component-controls/logger": "^1.22.0",
"@component-controls/webpack-configs": "^1.27.2",
Expand Down
3 changes: 2 additions & 1 deletion core/webpack-compile/src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export const getBundleName = () => {
distFolder = path.resolve(process.cwd(), distFolder);
}
const bundleName = args.bundle || defBundleName;
return `${path.join(distFolder, bundleName)}`;

return path.join(distFolder, bundleName);
};
/**
* callback function to monitor new documents/deleted documents
Expand Down

0 comments on commit 4898141

Please sign in to comment.