Skip to content

Commit

Permalink
fix: Make paths platform agnostic to fix Windows error
Browse files Browse the repository at this point in the history
  • Loading branch information
ademuk committed Nov 12, 2020
1 parent c7fb19e commit da38d6a
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {JSDOM, VirtualConsole} from 'jsdom';
import webpack from "webpack";
import {getTsPropTypes} from "./propTypes";

const hostNodeModulesPath = `${process.cwd()}/node_modules`;
const {act} = require(`${hostNodeModulesPath}/react-dom/test-utils`);
const hostNodeModulesPath = path.join(process.cwd(), 'node_modules');
const {act} = require(path.join(hostNodeModulesPath, 'react-dom/test-utils'));

const findModulesWithComponents = (searchPath: string): Promise<LoadedModule[]> =>
new Promise((resolve, reject) => {
Expand Down Expand Up @@ -42,7 +42,7 @@ const findModulesWithComponents = (searchPath: string): Promise<LoadedModule[]>
});

const compileModuleWithHostWebpack = (modulePath: string): Promise<[string, string]> => {
const craWebpackConfig = require(`${hostNodeModulesPath}/react-scripts/config/webpack.config`)(process.env.NODE_ENV);
const craWebpackConfig = require(path.join(hostNodeModulesPath, 'react-scripts/config/webpack.config'))(process.env.NODE_ENV);
const outputModulePath = modulePath.replace(/\.[^.]+$/, '.js');

return new Promise((resolve, reject) =>
Expand Down Expand Up @@ -136,8 +136,8 @@ const compileWrapperAndModuleWithWebpack = (wrapperModulePath: string, modulePat
extensions: [ '.tsx', '.ts', '.js' ],
alias: {
module: modulePath && path.resolve(path.join(modulePath, moduleFilename)),
react: `${hostNodeModulesPath}/react`,
"react-dom": `${hostNodeModulesPath}/react-dom`,
react: path.join(hostNodeModulesPath, 'react'),
"react-dom": path.join(hostNodeModulesPath, 'react-dom')
}
},
}, (err, stats) => {
Expand Down Expand Up @@ -582,7 +582,7 @@ const runComponentTest = (file, exportName, testId, step): Promise<ResultsAndCon

const getComponentPropTypes = (modulePath, exportName) => {
if (/tsx?$/.test(modulePath)) {
return getTsPropTypes(modulePath, exportName, require(`${hostNodeModulesPath}/react-scripts/config/paths`).appTsConfig);
return getTsPropTypes(modulePath, exportName, require(path.join(hostNodeModulesPath, 'react-scripts/config/paths')).appTsConfig);
}

return compileModuleWithHostWebpack(modulePath)
Expand Down

0 comments on commit da38d6a

Please sign in to comment.