Skip to content

Commit

Permalink
Apply fixes for various path issues in compileClient. Remove console.…
Browse files Browse the repository at this point in the history
…log instrumentation. Update gulpfile and test spec.
  • Loading branch information
drewpc committed Jan 15, 2017
1 parent 49f1740 commit c0ef934
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/react-server-cli/gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ gulp.task("eslint", [], () => {
gulp.task("test", ["default", "eslint"], () => {
process.env.NODE_ENV = "__react-server-cli-unit-test__"; // eslint-disable-line no-process-env
return gulp.src(getSpecGlob("target/__tests__/**/"))
.pipe(jasmine({verbose:true, includeStackTrace: true}));
.pipe(jasmine({}));
});

gulp.task("watch", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ describe("compileClient", () => {

const coreMiddlewareStringified = JSON.stringify(require.resolve("react-server-core-middleware"));
const filePathStringified = JSON.stringify(filePath);

// These four strings are important when using multiple platforms or strings with weird characters in them.
// If we're going to output something to a file and then import that file later, we'd better be darn sure
// it's all correctly formatted! Apostrophes, quotes, and windows-style file path characters \ vs / are the worst!
const filePathRegexStrings = [
"var coreJsMiddleware = require(" + coreMiddlewareStringified + ").coreJsMiddleware;",
"var coreCssMiddleware = require(" + coreMiddlewareStringified + ").coreCssMiddleware;",
Expand Down
2 changes: 0 additions & 2 deletions packages/react-server-cli/src/callerDependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,5 @@ export default function callerDependency(dep) {
} else {
lookupResult = lookup("node_modules/" + dep, {cwd: cwd});
}
console.log('cwd: ', cwd);
console.log(lookupResult);
return lookupResult;
}
20 changes: 10 additions & 10 deletions packages/react-server-cli/src/compileClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,18 +268,18 @@ function packageCodeForBrowser(entrypoints, outputDir, outputUrl, hot, minify, l
}

// writes out a routes file that can be used at runtime.
function writeWebpackCompatibleRoutesFile(routes, routesDir, workingDirAbsolute, staticUrl, isClient, manifest) {
export function writeWebpackCompatibleRoutesFile(routes, routesDir, workingDirAbsolute, staticUrl, isClient, manifest) {
let routesOutput = [];

const coreMiddleware = require.resolve("react-server-core-middleware");
const coreMiddleware = JSON.stringify(require.resolve("react-server-core-middleware"));
const existingMiddleware = routes.middleware ? routes.middleware.map((middlewareRelativePath) => {
return `unwrapEs6Module(require("${path.relative(workingDirAbsolute, path.resolve(routesDir, middlewareRelativePath))}"))`
return `unwrapEs6Module(require(${JSON.stringify(path.relative(workingDirAbsolute, path.resolve(routesDir, middlewareRelativePath)))}))`
}) : [];
routesOutput.push(`
var manifest = ${manifest ? JSON.stringify(manifest) : "undefined"};
function unwrapEs6Module(module) { return module.__esModule ? module.default : module }
var coreJsMiddleware = require('${coreMiddleware}').coreJsMiddleware;
var coreCssMiddleware = require('${coreMiddleware}').coreCssMiddleware;
var coreJsMiddleware = require(${coreMiddleware}).coreJsMiddleware;
var coreCssMiddleware = require(${coreMiddleware}).coreCssMiddleware;
module.exports = {
middleware:[
coreJsMiddleware(${JSON.stringify(staticUrl)}, manifest),
Expand All @@ -305,22 +305,22 @@ module.exports = {
page: {`);
for (let format of Object.keys(formats)) {
const formatModule = formats[format];
var relativePathToPage = path.relative(workingDirAbsolute, path.resolve(routesDir, formatModule));
var relativePathToPage = JSON.stringify(path.relative(workingDirAbsolute, path.resolve(routesDir, formatModule)));
routesOutput.push(`
${format}: function() {
return {
done: function(cb) {`);
if (isClient) {
routesOutput.push(`
require.ensure("${relativePathToPage}", function() {
cb(unwrapEs6Module(require("${relativePathToPage}")));
require.ensure(${relativePathToPage}, function() {
cb(unwrapEs6Module(require(${relativePathToPage})));
});`);
} else {
routesOutput.push(`
try {
cb(unwrapEs6Module(require("${relativePathToPage}")));
cb(unwrapEs6Module(require(${relativePathToPage})));
} catch (e) {
console.error('Failed to load page at "${relativePathToPage}"', e.stack);
console.error('Failed to load page at ${relativePathToPage}', e.stack);
}`);
}
routesOutput.push(`
Expand Down

0 comments on commit c0ef934

Please sign in to comment.