From 35fd84a86fe6b6c8abd60aeb721494771930c4ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Kostrzewski?= Date: Fri, 26 May 2017 00:22:06 +0200 Subject: [PATCH] Fix: Async component loader wrong path for 'async!...' imports (#50) * fix: wrong build path for 'async!' imports. Fixes #47 * fix: Incorrect async-component-loader refactor * chore: Configure eslint & fix linting errors --- package.json | 3 +++ src/commands/create.js | 2 +- src/commands/serve.js | 2 +- src/commands/watch.js | 2 +- src/lib/async-command.js | 2 +- src/lib/async-component-loader.js | 9 ++++++++- src/lib/babel-config.js | 2 +- src/lib/prerender.js | 1 + src/lib/push-manifest.js | 2 +- src/lib/run-webpack.js | 2 +- 10 files changed, 19 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 2ef85fbae..4b1b6dafc 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "build": "babel src -d lib -D", "prepublish": "npm run -s build", "dev": "babel-node src", + "lint": "eslint 'src/**/*.js'", "test:build": "babel-node src build --cwd examples/root", "test:serve": "npm run -s test:build && babel-node src serve --port 3000 --cwd examples/root", "test:serve:config": "npm run -s test:build && babel-node src serve --server config --cwd examples/root", @@ -51,6 +52,8 @@ "rules": { "no-console": 1, "no-empty": 0, + "semi": 2, + "keyword-spacing": 2, "react/no-string-refs": 2, "react/no-find-dom-node": 2, "react/no-is-mounted": 2, diff --git a/src/commands/create.js b/src/commands/create.js index c934c6289..b9ffa0a4f 100644 --- a/src/commands/create.js +++ b/src/commands/create.js @@ -148,7 +148,7 @@ export default asyncCommand({ \u001b[32mnpm run serve\u001b[39m `.trim().replace(/^\t+/gm, '') + '\n'; } -}) +}); const npm = (cwd, args) => spawn('npm', args, { cwd, stdio: 'ignore' }); diff --git a/src/commands/serve.js b/src/commands/serve.js index db766ad9f..fd16845b2 100644 --- a/src/commands/serve.js +++ b/src/commands/serve.js @@ -121,7 +121,7 @@ function createHeadersFromPushManifest(pushManifest) { `<${url}>; rel=preload; as=${type}` ).join(', ') }] - }) + }); } } diff --git a/src/commands/watch.js b/src/commands/watch.js index dd4617748..cb6aeb47d 100644 --- a/src/commands/watch.js +++ b/src/commands/watch.js @@ -35,4 +35,4 @@ export default asyncCommand({ let stats = await runWebpack(true, config, showStats); showStats(stats); } -}) +}); diff --git a/src/lib/async-command.js b/src/lib/async-command.js index 8b51fa6a1..04b3fa737 100644 --- a/src/lib/async-command.js +++ b/src/lib/async-command.js @@ -16,5 +16,5 @@ export default function asyncCommand(options) { let r = options.handler(argv, done); if (r && r.then) r.then(result => done(null, result), done); } - } + }; } diff --git a/src/lib/async-component-loader.js b/src/lib/async-component-loader.js index c0a67962b..aaf2ca96a 100644 --- a/src/lib/async-component-loader.js +++ b/src/lib/async-component-loader.js @@ -6,7 +6,14 @@ module.exports.pitch = function(remainingRequest) { this.cacheable && this.cacheable(); var query = loaderUtils.getOptions(this) || {}; var routeName = typeof query.name === 'function' ? query.name(this.resourcePath) : null; - var name = routeName !== null ? routeName : ('name' in query ? query.name : (query.formatName || String)(this.resourcePath)); + var name; + if (routeName !== null) { + name = routeName; + } else if ('name' in query) { + name = query.name; + } else if ('formatName' in query) { + name = query.formatName(this.resourcePath); + } return ` import async from ${JSON.stringify(path.resolve(__dirname, '../components/async'))}; diff --git a/src/lib/babel-config.js b/src/lib/babel-config.js index 2e9fbfdde..25ae908d1 100644 --- a/src/lib/babel-config.js +++ b/src/lib/babel-config.js @@ -28,4 +28,4 @@ export default (env, options={}) => ({ import: 'h' }] ] -}) +}); diff --git a/src/lib/prerender.js b/src/lib/prerender.js index 2bd9e4e20..7ddc2f77f 100644 --- a/src/lib/prerender.js +++ b/src/lib/prerender.js @@ -37,6 +37,7 @@ export default function prerender(config, params) { app = m && m.default || m; if (typeof app!=='function') { + // eslint-disable-next-line no-console console.warn('Entry does not export a Component function/class, aborting prerendering.'); return ''; } diff --git a/src/lib/push-manifest.js b/src/lib/push-manifest.js index 480720992..bf07203fc 100644 --- a/src/lib/push-manifest.js +++ b/src/lib/push-manifest.js @@ -36,4 +36,4 @@ module.exports = class PushManifestPlugin { callback(); }); } -} +}; diff --git a/src/lib/run-webpack.js b/src/lib/run-webpack.js index d5ae49699..83cfd3f2c 100644 --- a/src/lib/run-webpack.js +++ b/src/lib/run-webpack.js @@ -13,7 +13,7 @@ export default (watch=false, config, onprogress) => new Promise( (resolve, rejec // Timeout for plugins that work on `after-emit` event of webpack setTimeout(()=>{ resolve(stats); - },20) + },20); } };