diff --git a/packages/react-cosmos-config/package.json b/packages/react-cosmos-config/package.json index 5843db90ab..3d3b1f694f 100644 --- a/packages/react-cosmos-config/package.json +++ b/packages/react-cosmos-config/package.json @@ -11,7 +11,8 @@ "main": "lib/index.js", "dependencies": { "react-cosmos-utils": "^2.0.0-beta.6", - "resolve-from": "^2.0.0" + "resolve-from": "^2.0.0", + "slash": "^1.0.0" }, "xo": false } diff --git a/packages/react-cosmos-config/src/__tests__/index.js b/packages/react-cosmos-config/src/__tests__/index.js index be0f68e465..8a53595f57 100644 --- a/packages/react-cosmos-config/src/__tests__/index.js +++ b/packages/react-cosmos-config/src/__tests__/index.js @@ -1,4 +1,5 @@ import path from 'path'; +import slash from 'slash'; import getCosmosConfig from '../index'; const mockUserConfig = (path, mockConfig) => { @@ -50,11 +51,11 @@ describe('resolves module paths', () => { }); test('global imports', () => { - expect(globalImports).toEqual([path.join(__dirname, '../../../react-cosmos-utils/src/import-module.js')]); + expect(globalImports).toEqual([slash(path.join(__dirname, '../../../react-cosmos-utils/src/import-module.js'))]); }); test('proxies', () => { - expect(proxies).toEqual([path.join(__dirname, '../../../react-cosmos-utils/src/linked-list.js')]); + expect(proxies).toEqual([slash(path.join(__dirname, '../../../react-cosmos-utils/src/linked-list.js'))]); }); }); @@ -128,27 +129,27 @@ describe('resolves relative paths', () => { }); test('components', () => { - expect(componentPaths).toEqual([path.join(__dirname, 'mock-cwd/custom-path/path/to/components')]); + expect(componentPaths).toEqual([slash(path.join(__dirname, 'mock-cwd/custom-path/path/to/components'))]); }); test('fixtures', () => { - expect(fixturePaths).toEqual([path.join(__dirname, 'mock-cwd/custom-path/path/to/fixtures')]); + expect(fixturePaths).toEqual([slash(path.join(__dirname, 'mock-cwd/custom-path/path/to/fixtures'))]); }); test('global imports', () => { - expect(globalImports).toEqual([path.join(__dirname, 'mock-cwd/custom-path/path/to/import')]); + expect(globalImports).toEqual([slash(path.join(__dirname, 'mock-cwd/custom-path/path/to/import'))]); }); test('proxies', () => { - expect(proxies).toEqual([path.join(__dirname, 'mock-cwd/custom-path/path/to/proxy')]); + expect(proxies).toEqual([slash(path.join(__dirname, 'mock-cwd/custom-path/path/to/proxy'))]); }); test('public', () => { - expect(publicPath).toEqual(path.join(__dirname, 'mock-cwd/custom-path/path/to/static')); + expect(publicPath).toEqual(slash(path.join(__dirname, 'mock-cwd/custom-path/path/to/static'))); }); test('webpack config', () => { - expect(webpackConfigPath).toEqual(path.join(__dirname, 'mock-cwd/custom-path/path/to/webpack')); + expect(webpackConfigPath).toEqual(slash(path.join(__dirname, 'mock-cwd/custom-path/path/to/webpack'))); }); }); @@ -156,7 +157,7 @@ describe('defaults', () => { test('provide relative webpack path', () => { mockUserConfig('./mock-cwd/cosmos.config', {}); - expect(getCosmosConfig().webpackConfigPath).toBe(path.join(__dirname, 'mock-cwd/webpack.config')); + expect(getCosmosConfig().webpackConfigPath).toBe(slash(path.join(__dirname, 'mock-cwd/webpack.config'))); }); test('provide hot reloading', () => { diff --git a/packages/react-cosmos-config/src/index.js b/packages/react-cosmos-config/src/index.js index 20e0a70a78..000c2cf588 100644 --- a/packages/react-cosmos-config/src/index.js +++ b/packages/react-cosmos-config/src/index.js @@ -1,11 +1,12 @@ import path from 'path'; +import slash from 'slash'; import resolveFrom from 'resolve-from'; import importModule from 'react-cosmos-utils/lib/import-module'; const resolveUserPath = (userPath, rootPath) => - path.isAbsolute(userPath) ? userPath : ( + slash(path.isAbsolute(userPath) ? userPath : ( resolveFrom(rootPath, userPath) || path.join(rootPath, userPath) - ); + )); const defaults = { componentPaths: [], diff --git a/packages/react-cosmos-voyager/package.json b/packages/react-cosmos-voyager/package.json index fd6d4c09cd..291a5c19f1 100644 --- a/packages/react-cosmos-voyager/package.json +++ b/packages/react-cosmos-voyager/package.json @@ -15,6 +15,7 @@ "devDependencies": { "mkdirp": "^0.5.1", "rimraf": "^2.5.4", + "slash": "^1.0.0", "touch": "^1.0.0" }, "dependencies": { diff --git a/packages/react-cosmos-voyager/src/__tests__/index.js b/packages/react-cosmos-voyager/src/__tests__/index.js index 2b37c576cf..4add46995e 100644 --- a/packages/react-cosmos-voyager/src/__tests__/index.js +++ b/packages/react-cosmos-voyager/src/__tests__/index.js @@ -1,8 +1,9 @@ import path from 'path'; +import slash from 'slash'; import traverse from 'traverse'; import getFilePaths from '../index'; -const resolvePath = relPath => path.join(__dirname, '../use-cases', relPath); +const resolvePath = relPath => slash(path.join(__dirname, '../use-cases', relPath)); const testUseCase = (useCase, { componentPaths = [], diff --git a/packages/react-cosmos-webpack/package.json b/packages/react-cosmos-webpack/package.json index 552be726f4..6fb29e5994 100644 --- a/packages/react-cosmos-webpack/package.json +++ b/packages/react-cosmos-webpack/package.json @@ -23,6 +23,7 @@ "react-cosmos-config": "^2.0.0-beta.7", "react-cosmos-utils": "^2.0.0-beta.6", "react-cosmos-voyager": "^2.0.0-beta.7", + "slash": "^1.0.0", "style-loader": "^0.13.1", "traverse": "^0.6.6", "webpack-dev-middleware": "^1.8.4", diff --git a/packages/react-cosmos-webpack/src/__tests__/module-loader.js b/packages/react-cosmos-webpack/src/__tests__/module-loader.js index a32d5ec6c4..486e3d90b9 100644 --- a/packages/react-cosmos-webpack/src/__tests__/module-loader.js +++ b/packages/react-cosmos-webpack/src/__tests__/module-loader.js @@ -28,7 +28,9 @@ const mockGetFilePaths = jest.fn(() => ({ })); jest.mock('react-cosmos-voyager', () => mockGetFilePaths); -const jsonLoader = require.resolve('json-loader'); +const slash = require('slash'); + +const jsonLoader = slash(require.resolve('json-loader')); const moduleLoader = require('../module-loader'); const mockAddDependency = jest.fn(); diff --git a/packages/react-cosmos-webpack/src/module-loader.js b/packages/react-cosmos-webpack/src/module-loader.js index 1a44fc14c8..f7ba22d23b 100644 --- a/packages/react-cosmos-webpack/src/module-loader.js +++ b/packages/react-cosmos-webpack/src/module-loader.js @@ -1,10 +1,11 @@ import path from 'path'; +import slash from 'slash'; import loaderUtils from 'loader-utils'; import traverse from 'traverse'; import getCosmosConfig from 'react-cosmos-config'; import getFilePaths from 'react-cosmos-voyager'; -const jsonLoader = require.resolve('json-loader'); +const jsonLoader = slash(require.resolve('json-loader')); const getRequirePath = filePath => ( path.extname(filePath) === '.json' ? `${jsonLoader}!${filePath}` : filePath