diff --git a/core/core/src/index.ts b/core/core/src/index.ts index 788892c65..34fedcc6a 100644 --- a/core/core/src/index.ts +++ b/core/core/src/index.ts @@ -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; \ No newline at end of file diff --git a/core/loader/src/replaceSource.ts b/core/loader/src/replaceSource.ts index 171ee03de..8db1fc980 100644 --- a/core/loader/src/replaceSource.ts +++ b/core/loader/src/replaceSource.ts @@ -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; @@ -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}) });`, @@ -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; diff --git a/core/store/src/webpack/loader.ts b/core/store/src/webpack/loader.ts index fe1469bab..fc13e89aa 100644 --- a/core/store/src/webpack/loader.ts +++ b/core/store/src/webpack/loader.ts @@ -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); }); }); diff --git a/core/store/src/webpack/plugin.ts b/core/store/src/webpack/plugin.ts index 02d18d29e..eba7fe34d 100644 --- a/core/store/src/webpack/plugin.ts +++ b/core/store/src/webpack/plugin.ts @@ -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; @@ -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({ diff --git a/core/webpack-compile/package.json b/core/webpack-compile/package.json index 5eb8bbdbc..d816d422a 100644 --- a/core/webpack-compile/package.json +++ b/core/webpack-compile/package.json @@ -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", diff --git a/core/webpack-compile/src/utilities.ts b/core/webpack-compile/src/utilities.ts index 758479dba..a758975ea 100644 --- a/core/webpack-compile/src/utilities.ts +++ b/core/webpack-compile/src/utilities.ts @@ -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