Skip to content

Commit

Permalink
Fix slash mismatch between Windows and Unix #289
Browse files Browse the repository at this point in the history
  • Loading branch information
RadValentin committed Mar 4, 2017
1 parent 8887652 commit 68a307c
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 15 deletions.
3 changes: 2 additions & 1 deletion packages/react-cosmos-config/package.json
Expand Up @@ -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
}
19 changes: 10 additions & 9 deletions 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) => {
Expand Down Expand Up @@ -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'))]);
});
});

Expand Down Expand Up @@ -128,35 +129,35 @@ 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')));
});
});

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', () => {
Expand Down
5 changes: 3 additions & 2 deletions 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: [],
Expand Down
1 change: 1 addition & 0 deletions packages/react-cosmos-voyager/package.json
Expand Up @@ -15,6 +15,7 @@
"devDependencies": {
"mkdirp": "^0.5.1",
"rimraf": "^2.5.4",
"slash": "^1.0.0",
"touch": "^1.0.0"
},
"dependencies": {
Expand Down
3 changes: 2 additions & 1 deletion 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 = [],
Expand Down
1 change: 1 addition & 0 deletions packages/react-cosmos-webpack/package.json
Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion packages/react-cosmos-webpack/src/__tests__/module-loader.js
Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion 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
Expand Down

0 comments on commit 68a307c

Please sign in to comment.