From 63b366006492ef91c224ba5243b8f3b6ec79c003 Mon Sep 17 00:00:00 2001 From: Ian J Sikes Date: Mon, 4 Sep 2017 13:06:58 -0700 Subject: [PATCH 01/22] Add template files for loader yeoman generator --- .../templates/src/_index.js.tpl | 20 +++++++++++++++++++ lib/generate-loader/templates/src/cjs.js.tpl | 1 + 2 files changed, 21 insertions(+) create mode 100644 lib/generate-loader/templates/src/_index.js.tpl create mode 100644 lib/generate-loader/templates/src/cjs.js.tpl diff --git a/lib/generate-loader/templates/src/_index.js.tpl b/lib/generate-loader/templates/src/_index.js.tpl new file mode 100644 index 00000000000..d2d6700d122 --- /dev/null +++ b/lib/generate-loader/templates/src/_index.js.tpl @@ -0,0 +1,20 @@ +export default function loader(source) { + const { loaders, resource, request, version, webpack } = this; + + const newSource = ` + /** + * <%= name %> + * + * Resource Location: ${resource} + * Loaders chainded to module: ${JSON.stringify(loaders)} + * Loader API Version: ${version} + * Is this in "webpack mode": ${webpack} + * This is the users request for the module: ${request} + */ + /** + * Original Source From Loader + */ + ${source}`; + + return newSource; +} diff --git a/lib/generate-loader/templates/src/cjs.js.tpl b/lib/generate-loader/templates/src/cjs.js.tpl new file mode 100644 index 00000000000..82657ce3a74 --- /dev/null +++ b/lib/generate-loader/templates/src/cjs.js.tpl @@ -0,0 +1 @@ +module.exports = require('./index').default; From 14701f876844b9f821c51010be42c2cbed5a83b4 Mon Sep 17 00:00:00 2001 From: Ian J Sikes Date: Mon, 4 Sep 2017 13:09:43 -0700 Subject: [PATCH 02/22] Create yeoman generator for a webpack loader project --- lib/generate-loader/loader-generator.js | 86 +++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 lib/generate-loader/loader-generator.js diff --git a/lib/generate-loader/loader-generator.js b/lib/generate-loader/loader-generator.js new file mode 100644 index 00000000000..8583a875318 --- /dev/null +++ b/lib/generate-loader/loader-generator.js @@ -0,0 +1,86 @@ +const path = require('path'); +const mkdirp = require('mkdirp'); +const _ = require('lodash'); +const Generator = require('yeoman-generator'); + +/** + * Formats a string into webpack loader format + * (eg: 'style-loader', 'raw-loader') + * + * @param {string} name A loader name to be formatted + * @returns {string} The formatted string + */ +function makeLoaderName(name) { + name = _.kebabCase(name); + if (!/loader$/.test(name)) { + name += '-loader'; + } + return name; +} + +/** + * A yeoman generator class for creating a webpack + * loader project. It adds some starter loader code + * and runs `webpack-defaults`. + * + * @class LoaderGenerator + * @extends {Generator} + */ +class LoaderGenerator extends Generator { + prompting() { + const prompts = [ + { + type: 'input', + name: 'name', + message: 'Loader name', + default: 'my-loader', + filter: makeLoaderName, + validate: str => str.length > 0, + }, + ]; + + return this.prompt(prompts).then(props => { + this.props = props; + }); + } + + default() { + if (path.basename(this.destinationPath()) !== this.props.name) { + this.log( + 'Your loader must be inside a folder named ' + + this.props.name + + '\nI will create this folder for you.' + ); + mkdirp(this.props.name); + this.destinationRoot(this.destinationPath(this.props.name)); + } + } + + writing() { + this.fs.copyTpl( + this.templatePath('src/_index.js.tpl'), + this.destinationPath('src/index.js'), + { name: this.props.name } + ); + + this.fs.copy( + this.templatePath('src/cjs.js.tpl'), + this.destinationPath('src/cjs.js') + ); + } + + install() { + this.npmInstall(['webpack-defaults'], { 'save-dev': true }, () => { + this.spawnCommand('npm', ['run', 'webpack-defaults']); + }); + } + + end() { + this.log('All done!'); + } +} + +module.exports = { + makeLoaderName, + LoaderGenerator, +}; From 4349ba7f78f83f251ebb1d546f23b9b45f2b0393 Mon Sep 17 00:00:00 2001 From: Ian J Sikes Date: Mon, 4 Sep 2017 13:11:00 -0700 Subject: [PATCH 03/22] Add tests for loader-generator --- lib/generate-loader/loader-generator.test.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 lib/generate-loader/loader-generator.test.js diff --git a/lib/generate-loader/loader-generator.test.js b/lib/generate-loader/loader-generator.test.js new file mode 100644 index 00000000000..0e2aec154f1 --- /dev/null +++ b/lib/generate-loader/loader-generator.test.js @@ -0,0 +1,17 @@ +'use strict'; + +const makeLoaderName = require('./loader-generator').makeLoaderName; + +describe('makeLoaderName', () => { + + it('should kebab-case loader name and append \'-loader\'', () => { + const loaderName = makeLoaderName('This is a test'); + expect(loaderName).toEqual('this-is-a-test-loader'); + }); + + it('should not modify a properly formatted loader name', () => { + const loaderName = makeLoaderName('properly-named-loader'); + expect(loaderName).toEqual('properly-named-loader'); + }); + +}); From b633b146b5207f7c35d3896598ad8dbc035d0026 Mon Sep 17 00:00:00 2001 From: Ian J Sikes Date: Mon, 4 Sep 2017 13:11:31 -0700 Subject: [PATCH 04/22] Add `mkdirp` dependency for loader-generator --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 4fca0b3a08e..e10c2ad0a0c 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "listr": "^0.11.0", "loader-utils": "^0.2.16", "lodash": "^4.17.4", + "mkdirp": "^0.5.1", "p-each-series": "^1.0.0", "p-lazy": "^1.0.0", "prettier": "^1.2.2", From 9de21fa9a83bc4bde53f7f7c1661468b2c0e7b13 Mon Sep 17 00:00:00 2001 From: Ian J Sikes Date: Mon, 4 Sep 2017 13:12:17 -0700 Subject: [PATCH 05/22] Add function to create yeoman env and run loader-generator --- lib/generate-loader/index.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 lib/generate-loader/index.js diff --git a/lib/generate-loader/index.js b/lib/generate-loader/index.js new file mode 100644 index 00000000000..5f911be6219 --- /dev/null +++ b/lib/generate-loader/index.js @@ -0,0 +1,16 @@ +const yeoman = require('yeoman-environment'); +const LoaderGenerator = require('./loader-generator').LoaderGenerator; + +/** + * Runs a yeoman generator to create a new webpack loader project + */ +function loaderCreator() { + let env = yeoman.createEnv(); + const generatorName = 'webpack-loader-generator'; + + env.registerStub(LoaderGenerator, generatorName); + + env.run(generatorName); +} + +module.exports = loaderCreator; From b6972a761f4cbbc5936f9a5815d26a0412892786 Mon Sep 17 00:00:00 2001 From: Ian J Sikes Date: Mon, 4 Sep 2017 13:14:24 -0700 Subject: [PATCH 06/22] Add `generate-loader` command to webpack-cli --- bin/webpack.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/webpack.js b/bin/webpack.js index 280744cb2cf..292a14c2af3 100755 --- a/bin/webpack.js +++ b/bin/webpack.js @@ -167,6 +167,8 @@ if(argv._.includes('init')) { const inputConfigPath = path.resolve(process.cwd(), filePaths[0]); return require('../lib/migrate.js')(inputConfigPath, inputConfigPath); +} else if(argv._.includes('generate-loader')) { + return require('../lib/generate-loader/index.js')(); } else { var options = require('./convert-argv')(yargs, argv); From 91ab4ea8b51489be990afaf948755f2d22b77760 Mon Sep 17 00:00:00 2001 From: Ian J Sikes Date: Mon, 4 Sep 2017 15:15:25 -0700 Subject: [PATCH 07/22] Copy loader templates from proper directory --- lib/generate-loader/loader-generator.js | 10 +++------- lib/generate-loader/templates/src/_index.js.tpl | 7 ++++++- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/generate-loader/loader-generator.js b/lib/generate-loader/loader-generator.js index 8583a875318..cf8b73cd04a 100644 --- a/lib/generate-loader/loader-generator.js +++ b/lib/generate-loader/loader-generator.js @@ -58,26 +58,22 @@ class LoaderGenerator extends Generator { writing() { this.fs.copyTpl( - this.templatePath('src/_index.js.tpl'), + path.join(__dirname, 'templates', 'src', '_index.js.tpl'), this.destinationPath('src/index.js'), { name: this.props.name } ); this.fs.copy( - this.templatePath('src/cjs.js.tpl'), + path.join(__dirname, 'templates', 'src', 'cjs.js.tpl'), this.destinationPath('src/cjs.js') ); } install() { - this.npmInstall(['webpack-defaults'], { 'save-dev': true }, () => { + this.npmInstall(['webpack-defaults'], { 'save-dev': true }).then(() => { this.spawnCommand('npm', ['run', 'webpack-defaults']); }); } - - end() { - this.log('All done!'); - } } module.exports = { diff --git a/lib/generate-loader/templates/src/_index.js.tpl b/lib/generate-loader/templates/src/_index.js.tpl index d2d6700d122..c69d5d329a6 100644 --- a/lib/generate-loader/templates/src/_index.js.tpl +++ b/lib/generate-loader/templates/src/_index.js.tpl @@ -1,3 +1,8 @@ +/** + * See the webpack docs for more information about loaders: + * https://github.com/webpack/docs/wiki/how-to-write-a-loader + */ + export default function loader(source) { const { loaders, resource, request, version, webpack } = this; @@ -6,7 +11,7 @@ export default function loader(source) { * <%= name %> * * Resource Location: ${resource} - * Loaders chainded to module: ${JSON.stringify(loaders)} + * Loaders chained to module: ${JSON.stringify(loaders)} * Loader API Version: ${version} * Is this in "webpack mode": ${webpack} * This is the users request for the module: ${request} From 6a3e6a6f363a9464ad56a41e877833bcceee12b4 Mon Sep 17 00:00:00 2001 From: Ian J Sikes Date: Mon, 4 Sep 2017 15:16:07 -0700 Subject: [PATCH 08/22] Add template files for plugin generator --- lib/generate-plugin/templates/src/_index.js.tpl | 16 ++++++++++++++++ lib/generate-plugin/templates/src/cjs.js.tpl | 1 + 2 files changed, 17 insertions(+) create mode 100644 lib/generate-plugin/templates/src/_index.js.tpl create mode 100644 lib/generate-plugin/templates/src/cjs.js.tpl diff --git a/lib/generate-plugin/templates/src/_index.js.tpl b/lib/generate-plugin/templates/src/_index.js.tpl new file mode 100644 index 00000000000..1a9001b8d67 --- /dev/null +++ b/lib/generate-plugin/templates/src/_index.js.tpl @@ -0,0 +1,16 @@ +/** + * See the webpack docs for more information about plugins: + * https://github.com/webpack/docs/wiki/how-to-write-a-plugin + */ + +function <%= name %>(options) { + // Setup the plugin instance with options... +} + +<%= name %>.prototype.apply = function(compiler) { + compiler.plugin('done', function() { + console.log('Hello World!'); + }); +}; + +module.exports = <%= name %>; diff --git a/lib/generate-plugin/templates/src/cjs.js.tpl b/lib/generate-plugin/templates/src/cjs.js.tpl new file mode 100644 index 00000000000..82657ce3a74 --- /dev/null +++ b/lib/generate-plugin/templates/src/cjs.js.tpl @@ -0,0 +1 @@ +module.exports = require('./index').default; From 1aa6d308dcf54acf4704ee98c9027e0c4d4cfa7a Mon Sep 17 00:00:00 2001 From: Ian J Sikes Date: Mon, 4 Sep 2017 15:16:39 -0700 Subject: [PATCH 09/22] Create yeoman generator for webpack plugins --- lib/generate-plugin/plugin-generator.js | 66 +++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 lib/generate-plugin/plugin-generator.js diff --git a/lib/generate-plugin/plugin-generator.js b/lib/generate-plugin/plugin-generator.js new file mode 100644 index 00000000000..8d01db2509c --- /dev/null +++ b/lib/generate-plugin/plugin-generator.js @@ -0,0 +1,66 @@ +const path = require('path'); +const mkdirp = require('mkdirp'); +const _ = require('lodash'); +const Generator = require('yeoman-generator'); + +/** + * A yeoman generator class for creating a webpack + * plugin project. It adds some starter plugin code + * and runs `webpack-defaults`. + * + * @class PluginGenerator + * @extends {Generator} + */ +class PluginGenerator extends Generator { + prompting() { + const prompts = [ + { + type: 'input', + name: 'name', + message: 'Plugin name', + default: 'my-webpack-plugin', + filter: _.kebabCase, + validate: str => str.length > 0, + }, + ]; + + return this.prompt(prompts).then(props => { + this.props = props; + }); + } + + default() { + if (path.basename(this.destinationPath()) !== this.props.name) { + this.log( + 'Your plugin must be inside a folder named ' + + this.props.name + + '\nI will create this folder for you.' + ); + mkdirp(this.props.name); + this.destinationRoot(this.destinationPath(this.props.name)); + } + } + + writing() { + this.fs.copyTpl( + path.join(__dirname, 'templates', 'src', '_index.js.tpl'), + this.destinationPath('src/index.js'), + { name: _.upperFirst(_.camelCase(this.props.name)) } + ); + + this.fs.copy( + path.join(__dirname, 'templates', 'src', 'cjs.js.tpl'), + this.destinationPath('src/cjs.js') + ); + } + + install() { + this.npmInstall(['webpack-defaults'], { 'save-dev': true }).then(() => { + this.spawnCommand('npm', ['run', 'webpack-defaults']); + }); + } +} + +module.exports = { + PluginGenerator, +}; From 57fa95388cae5f54599db43dc72a1e22293e8240 Mon Sep 17 00:00:00 2001 From: Ian J Sikes Date: Mon, 4 Sep 2017 15:17:09 -0700 Subject: [PATCH 10/22] Add function to create yeoman env and run plugin generator --- lib/generate-plugin/index.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 lib/generate-plugin/index.js diff --git a/lib/generate-plugin/index.js b/lib/generate-plugin/index.js new file mode 100644 index 00000000000..d957a599468 --- /dev/null +++ b/lib/generate-plugin/index.js @@ -0,0 +1,16 @@ +const yeoman = require('yeoman-environment'); +const PluginGenerator = require('./plugin-generator').PluginGenerator; + +/** + * Runs a yeoman generator to create a new webpack plugin project + */ +function pluginCreator() { + let env = yeoman.createEnv(); + const generatorName = 'webpack-plugin-generator'; + + env.registerStub(PluginGenerator, generatorName); + + env.run(generatorName); +} + +module.exports = pluginCreator; From d5502063229b26ac4045a19059aefa31bf83a2f9 Mon Sep 17 00:00:00 2001 From: Ian J Sikes Date: Mon, 4 Sep 2017 15:19:05 -0700 Subject: [PATCH 11/22] Add cli command to generate plugin --- bin/webpack.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/webpack.js b/bin/webpack.js index 292a14c2af3..4899fcb3ebb 100755 --- a/bin/webpack.js +++ b/bin/webpack.js @@ -169,6 +169,8 @@ if(argv._.includes('init')) { return require('../lib/migrate.js')(inputConfigPath, inputConfigPath); } else if(argv._.includes('generate-loader')) { return require('../lib/generate-loader/index.js')(); +} else if(argv._.includes('generate-plugin')) { + return require('../lib/generate-plugin/index.js')(); } else { var options = require('./convert-argv')(yargs, argv); From 88eeede71660110c36a3752cdece6a5d4686d01d Mon Sep 17 00:00:00 2001 From: Ian J Sikes Date: Mon, 4 Sep 2017 15:19:43 -0700 Subject: [PATCH 12/22] Register generate- commands in yargs --- bin/config-yargs.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bin/config-yargs.js b/bin/config-yargs.js index e75d9b7b5f3..a50a3e6abed 100644 --- a/bin/config-yargs.js +++ b/bin/config-yargs.js @@ -25,6 +25,16 @@ module.exports = function(yargs) { describe: 'Migrate your webpack configuration from webpack 1 to webpack 2', group: INIT_GROUP }, + 'generate-loader': { + type: 'boolean', + describe: 'Generates a new webpack loader project', + group: INIT_GROUP + }, + 'generate-plugin': { + type: 'boolean', + describe: 'Generates a new webpack plugin project', + group: INIT_GROUP + }, 'config': { type: 'string', describe: 'Path to the config file', From b73a24d8251cb06d8993633b0f22d90f5eefa123 Mon Sep 17 00:00:00 2001 From: Ian J Sikes Date: Mon, 4 Sep 2017 17:24:04 -0700 Subject: [PATCH 13/22] Add template files for loader examples and tests --- .../examples/simple/src/index.js.tpl | 11 +++ .../examples/simple/src/lazy-module.js.tpl | 1 + .../simple/src/static-esm-module.js.tpl | 1 + .../examples/simple/webpack.config.js.tpl | 27 ++++++ .../test/fixtures/simple-file.js.tpl | 3 + .../templates/test/functional.test.js.tpl | 21 +++++ .../templates/test/test-utils.js.tpl | 82 +++++++++++++++++++ .../templates/test/unit.test.js.tpl | 32 ++++++++ 8 files changed, 178 insertions(+) create mode 100644 lib/generate-loader/templates/examples/simple/src/index.js.tpl create mode 100644 lib/generate-loader/templates/examples/simple/src/lazy-module.js.tpl create mode 100644 lib/generate-loader/templates/examples/simple/src/static-esm-module.js.tpl create mode 100644 lib/generate-loader/templates/examples/simple/webpack.config.js.tpl create mode 100644 lib/generate-loader/templates/test/fixtures/simple-file.js.tpl create mode 100644 lib/generate-loader/templates/test/functional.test.js.tpl create mode 100644 lib/generate-loader/templates/test/test-utils.js.tpl create mode 100644 lib/generate-loader/templates/test/unit.test.js.tpl diff --git a/lib/generate-loader/templates/examples/simple/src/index.js.tpl b/lib/generate-loader/templates/examples/simple/src/index.js.tpl new file mode 100644 index 00000000000..ed75d67d081 --- /dev/null +++ b/lib/generate-loader/templates/examples/simple/src/index.js.tpl @@ -0,0 +1,11 @@ +import esmModule from './static-esm-module'; + +const getLazyModule = () => System.import('./lazy-module'); + +setTimeout(() => { + getLazyModule.then((modDefault) => { + console.log(modDefault); //eslint-disable-line + }); +}, 300); + +console.log(esmModule); //eslint-disable-line diff --git a/lib/generate-loader/templates/examples/simple/src/lazy-module.js.tpl b/lib/generate-loader/templates/examples/simple/src/lazy-module.js.tpl new file mode 100644 index 00000000000..f3dac067326 --- /dev/null +++ b/lib/generate-loader/templates/examples/simple/src/lazy-module.js.tpl @@ -0,0 +1 @@ +export default 'lazy'; diff --git a/lib/generate-loader/templates/examples/simple/src/static-esm-module.js.tpl b/lib/generate-loader/templates/examples/simple/src/static-esm-module.js.tpl new file mode 100644 index 00000000000..d02ba545bd3 --- /dev/null +++ b/lib/generate-loader/templates/examples/simple/src/static-esm-module.js.tpl @@ -0,0 +1 @@ +export default 'foo'; diff --git a/lib/generate-loader/templates/examples/simple/webpack.config.js.tpl b/lib/generate-loader/templates/examples/simple/webpack.config.js.tpl new file mode 100644 index 00000000000..75b6744b7a2 --- /dev/null +++ b/lib/generate-loader/templates/examples/simple/webpack.config.js.tpl @@ -0,0 +1,27 @@ +const path = require('path'); + +module.exports = { + entry: './src/index.js', + output: { + path: path.join(__dirname, 'example_dist'), + filename: '[name].chunk.js', + }, + module: { + rules: [ + { + test: /\.js$/, + use: [ + { + loader: 'example-loader', + options: {}, + }, + ], + }, + ], + }, + resolveLoader: { + alias: { + 'example-loader': require.resolve('../../src/'), + }, + }, +}; diff --git a/lib/generate-loader/templates/test/fixtures/simple-file.js.tpl b/lib/generate-loader/templates/test/fixtures/simple-file.js.tpl new file mode 100644 index 00000000000..908ed137dff --- /dev/null +++ b/lib/generate-loader/templates/test/fixtures/simple-file.js.tpl @@ -0,0 +1,3 @@ +import foo from "./foo"; // eslint-disable-line + +console.log(foo); diff --git a/lib/generate-loader/templates/test/functional.test.js.tpl b/lib/generate-loader/templates/test/functional.test.js.tpl new file mode 100644 index 00000000000..ac6645a0d66 --- /dev/null +++ b/lib/generate-loader/templates/test/functional.test.js.tpl @@ -0,0 +1,21 @@ +import { + runWebpackExampleInMemory, +} from '../test/test-utils'; + +test('should run with no errors or warnings', async () => { + const buildStats = await runWebpackExampleInMemory('simple'); + const { errors, warnings } = buildStats; + + expect([...errors, ...warnings].length).toBe(0); +}); + +test('should append transformations to JavaScript module', async () => { + const buildStats = await runWebpackExampleInMemory('simple'); + const { modules } = buildStats; + + const moduleToTest = modules[0].source()._source._value; //eslint-disable-line + const loadedString = '* Original Source From Loader'; + + expect(moduleToTest).toEqual(expect.stringContaining(loadedString)); + expect(moduleToTest).toMatchSnapshot(); +}); diff --git a/lib/generate-loader/templates/test/test-utils.js.tpl b/lib/generate-loader/templates/test/test-utils.js.tpl new file mode 100644 index 00000000000..0cd61e6700c --- /dev/null +++ b/lib/generate-loader/templates/test/test-utils.js.tpl @@ -0,0 +1,82 @@ +import path from 'path'; +import webpack from 'webpack'; +import Promise from 'bluebird'; +import MemoryFs from 'memory-fs'; + +const fs = new MemoryFs(); +const unitTestFixtures = path.resolve(__dirname, 'fixtures'); + +/** + * + * + * @param {string} fixtureName + * @param {string} [withQueryString=''] + * @returns {string} Absolute path of a file with query that is to be run by a loader. + */ +function getFixtureResource(fixtureName, withQueryString = '') { + return `${getFixture(fixtureName)}?${withQueryString}`; +} + +/** + * + * + * @param {string} fixtureName + * @returns {string} Absolute path of a file with query that is to be run by a loader. + */ +function getFixture(fixtureName) { + return path.resolve(unitTestFixtures, `${fixtureName}.js`); +} + +/** + * + * + * @param {Object} withOptions - Loader Options + * @returns {{loader: string, options: Object}} + */ +function getLoader(withOptions) { + return [{ loader: path.resolve(__dirname, '../dist/index.js'), options: withOptions }]; +} + +/** + * + * + * @param {string} exampleName + * @returns {Object|Array} - Returns an object or array of objects representing the webpack configuration options + */ +function getExampleConfig(exampleName) { + return require(`../examples/${exampleName}/webpack.config.js`); //eslint-disable-line +} + +/** + * + * + * @param {string} exampleName - name of example inside of examples folder + * @returns + */ +async function runWebpackExampleInMemory(exampleName) { + const webpackConfig = getExampleConfig(exampleName); + const compiler = webpack(webpackConfig); + + compiler.outputFileSystem = fs; + + const run = Promise.promisify(compiler.run, { context: compiler }); + const stats = await run(); + + + const { compilation } = stats; + const { errors, warnings, assets, entrypoints, chunks, modules } = compilation; + const statsJson = stats.toJson(); + + return { + assets, + entrypoints, + errors, + warnings, + stats, + chunks, + modules, + statsJson, + }; +} + +export { getExampleConfig, runWebpackExampleInMemory, fs, getFixtureResource, getLoader, getFixture }; diff --git a/lib/generate-loader/templates/test/unit.test.js.tpl b/lib/generate-loader/templates/test/unit.test.js.tpl new file mode 100644 index 00000000000..3ef1728b618 --- /dev/null +++ b/lib/generate-loader/templates/test/unit.test.js.tpl @@ -0,0 +1,32 @@ +import fs from 'fs'; +import { runLoaders } from 'loader-runner'; +import Promise from 'bluebird'; +import { getFixtureResource, getFixture, getLoader } from './test-utils'; + +const runLoadersPromise = Promise.promisify(runLoaders); +const readFilePromise = Promise.promisify(fs.readFile, { context: fs }); + + +const loaders = getLoader(); + +describe('Example Loader Tests: Fixture: simple-file', () => { + const fixtureName = 'simple-file'; + const resource = getFixture(fixtureName); + + test('loaded file should be different', async () => { + const originalSource = await readFilePromise(resource); + const { result } = await runLoadersPromise({ resource: getFixtureResource(fixtureName), loaders }); + + expect(result).not.toEqual(originalSource); + }); + + test('loader prepends correct information', async () => { + const { result } = await runLoadersPromise({ resource: getFixtureResource(fixtureName), loaders }); + const resultMatcher = expect.arrayContaining([ + expect.stringContaining(' * Original Source From Loader'), + ]); + + expect(result).toEqual(resultMatcher); + expect(result).toMatchSnapshot(); + }); +}); From 0cb2f690b693bbe09c7533b517406e73c2dcfb76 Mon Sep 17 00:00:00 2001 From: Ian J Sikes Date: Mon, 4 Sep 2017 17:24:28 -0700 Subject: [PATCH 14/22] Copy loader test and example template files in generator --- lib/generate-loader/loader-generator.js | 54 ++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/lib/generate-loader/loader-generator.js b/lib/generate-loader/loader-generator.js index cf8b73cd04a..6147957fb6a 100644 --- a/lib/generate-loader/loader-generator.js +++ b/lib/generate-loader/loader-generator.js @@ -57,6 +57,10 @@ class LoaderGenerator extends Generator { } writing() { + /** + * Loader source + */ + this.fs.copyTpl( path.join(__dirname, 'templates', 'src', '_index.js.tpl'), this.destinationPath('src/index.js'), @@ -67,10 +71,58 @@ class LoaderGenerator extends Generator { path.join(__dirname, 'templates', 'src', 'cjs.js.tpl'), this.destinationPath('src/cjs.js') ); + + /** + * Tests + */ + + this.fs.copy( + path.join(__dirname, 'templates', 'test', 'test-utils.js.tpl'), + this.destinationPath('test/test-utils.js') + ); + + this.fs.copy( + path.join(__dirname, 'templates', 'test', 'unit.test.js.tpl'), + this.destinationPath('test/unit.test.js') + ); + + this.fs.copy( + path.join(__dirname, 'templates', 'test', 'functional.test.js.tpl'), + this.destinationPath('test/functional.test.js') + ); + + this.fs.copy( + path.join(__dirname, 'templates', 'test', 'fixtures', 'simple-file.js.tpl'), + this.destinationPath('test/fixtures/simple-file.js') + ); + + /** + * Examples + */ + + this.fs.copy( + path.join(__dirname, 'templates', 'examples', 'simple', 'webpack.config.js.tpl'), + this.destinationPath('examples/simple/webpack.config.js') + ); + + this.fs.copy( + path.join(__dirname, 'templates', 'examples', 'simple', 'src','index.js.tpl'), + this.destinationPath('examples/simple/src/index.js') + ); + + this.fs.copy( + path.join(__dirname, 'templates', 'examples', 'simple', 'src','lazy-module.js.tpl'), + this.destinationPath('examples/simple/src/lazy-module.js') + ); + + this.fs.copy( + path.join(__dirname, 'templates', 'examples', 'simple', 'src','static-esm-module.js.tpl'), + this.destinationPath('examples/simple/src/static-esm-module.js') + ); } install() { - this.npmInstall(['webpack-defaults'], { 'save-dev': true }).then(() => { + this.npmInstall(['webpack-defaults', 'bluebird'], { 'save-dev': true }).then(() => { this.spawnCommand('npm', ['run', 'webpack-defaults']); }); } From 7d6fd90f046d2396f10fb08ec772949bfb0d3081 Mon Sep 17 00:00:00 2001 From: Ian J Sikes Date: Mon, 4 Sep 2017 17:24:54 -0700 Subject: [PATCH 15/22] Add template files for plugin examples and tests --- .../examples/simple/src/index.js.tpl | 11 +++ .../examples/simple/src/lazy-module.js.tpl | 1 + .../simple/src/static-esm-module.js.tpl | 1 + .../examples/simple/webpack.config.js.tpl | 13 +++ .../test/fixtures/simple-file.js.tpl | 3 + .../templates/test/functional.test.js.tpl | 10 +++ .../templates/test/test-utils.js.tpl | 82 +++++++++++++++++++ 7 files changed, 121 insertions(+) create mode 100644 lib/generate-plugin/templates/examples/simple/src/index.js.tpl create mode 100644 lib/generate-plugin/templates/examples/simple/src/lazy-module.js.tpl create mode 100644 lib/generate-plugin/templates/examples/simple/src/static-esm-module.js.tpl create mode 100644 lib/generate-plugin/templates/examples/simple/webpack.config.js.tpl create mode 100644 lib/generate-plugin/templates/test/fixtures/simple-file.js.tpl create mode 100644 lib/generate-plugin/templates/test/functional.test.js.tpl create mode 100644 lib/generate-plugin/templates/test/test-utils.js.tpl diff --git a/lib/generate-plugin/templates/examples/simple/src/index.js.tpl b/lib/generate-plugin/templates/examples/simple/src/index.js.tpl new file mode 100644 index 00000000000..ed75d67d081 --- /dev/null +++ b/lib/generate-plugin/templates/examples/simple/src/index.js.tpl @@ -0,0 +1,11 @@ +import esmModule from './static-esm-module'; + +const getLazyModule = () => System.import('./lazy-module'); + +setTimeout(() => { + getLazyModule.then((modDefault) => { + console.log(modDefault); //eslint-disable-line + }); +}, 300); + +console.log(esmModule); //eslint-disable-line diff --git a/lib/generate-plugin/templates/examples/simple/src/lazy-module.js.tpl b/lib/generate-plugin/templates/examples/simple/src/lazy-module.js.tpl new file mode 100644 index 00000000000..f3dac067326 --- /dev/null +++ b/lib/generate-plugin/templates/examples/simple/src/lazy-module.js.tpl @@ -0,0 +1 @@ +export default 'lazy'; diff --git a/lib/generate-plugin/templates/examples/simple/src/static-esm-module.js.tpl b/lib/generate-plugin/templates/examples/simple/src/static-esm-module.js.tpl new file mode 100644 index 00000000000..d02ba545bd3 --- /dev/null +++ b/lib/generate-plugin/templates/examples/simple/src/static-esm-module.js.tpl @@ -0,0 +1 @@ +export default 'foo'; diff --git a/lib/generate-plugin/templates/examples/simple/webpack.config.js.tpl b/lib/generate-plugin/templates/examples/simple/webpack.config.js.tpl new file mode 100644 index 00000000000..e50ecc3e588 --- /dev/null +++ b/lib/generate-plugin/templates/examples/simple/webpack.config.js.tpl @@ -0,0 +1,13 @@ +const path = require('path'); +const <%= name %> = require('../../src/index.js'); + +module.exports = { + entry: './src/index.js', + output: { + path: path.join(__dirname, 'example_dist'), + filename: '[name].chunk.js', + }, + plugins: [ + new <%= name %>() + ] +}; diff --git a/lib/generate-plugin/templates/test/fixtures/simple-file.js.tpl b/lib/generate-plugin/templates/test/fixtures/simple-file.js.tpl new file mode 100644 index 00000000000..908ed137dff --- /dev/null +++ b/lib/generate-plugin/templates/test/fixtures/simple-file.js.tpl @@ -0,0 +1,3 @@ +import foo from "./foo"; // eslint-disable-line + +console.log(foo); diff --git a/lib/generate-plugin/templates/test/functional.test.js.tpl b/lib/generate-plugin/templates/test/functional.test.js.tpl new file mode 100644 index 00000000000..07f2099cec0 --- /dev/null +++ b/lib/generate-plugin/templates/test/functional.test.js.tpl @@ -0,0 +1,10 @@ +import { + runWebpackExampleInMemory, +} from '../test/test-utils'; + +test('should run with no errors or warnings', async () => { + const buildStats = await runWebpackExampleInMemory('simple'); + const { errors, warnings } = buildStats; + + expect([...errors, ...warnings].length).toBe(0); +}); diff --git a/lib/generate-plugin/templates/test/test-utils.js.tpl b/lib/generate-plugin/templates/test/test-utils.js.tpl new file mode 100644 index 00000000000..0cd61e6700c --- /dev/null +++ b/lib/generate-plugin/templates/test/test-utils.js.tpl @@ -0,0 +1,82 @@ +import path from 'path'; +import webpack from 'webpack'; +import Promise from 'bluebird'; +import MemoryFs from 'memory-fs'; + +const fs = new MemoryFs(); +const unitTestFixtures = path.resolve(__dirname, 'fixtures'); + +/** + * + * + * @param {string} fixtureName + * @param {string} [withQueryString=''] + * @returns {string} Absolute path of a file with query that is to be run by a loader. + */ +function getFixtureResource(fixtureName, withQueryString = '') { + return `${getFixture(fixtureName)}?${withQueryString}`; +} + +/** + * + * + * @param {string} fixtureName + * @returns {string} Absolute path of a file with query that is to be run by a loader. + */ +function getFixture(fixtureName) { + return path.resolve(unitTestFixtures, `${fixtureName}.js`); +} + +/** + * + * + * @param {Object} withOptions - Loader Options + * @returns {{loader: string, options: Object}} + */ +function getLoader(withOptions) { + return [{ loader: path.resolve(__dirname, '../dist/index.js'), options: withOptions }]; +} + +/** + * + * + * @param {string} exampleName + * @returns {Object|Array} - Returns an object or array of objects representing the webpack configuration options + */ +function getExampleConfig(exampleName) { + return require(`../examples/${exampleName}/webpack.config.js`); //eslint-disable-line +} + +/** + * + * + * @param {string} exampleName - name of example inside of examples folder + * @returns + */ +async function runWebpackExampleInMemory(exampleName) { + const webpackConfig = getExampleConfig(exampleName); + const compiler = webpack(webpackConfig); + + compiler.outputFileSystem = fs; + + const run = Promise.promisify(compiler.run, { context: compiler }); + const stats = await run(); + + + const { compilation } = stats; + const { errors, warnings, assets, entrypoints, chunks, modules } = compilation; + const statsJson = stats.toJson(); + + return { + assets, + entrypoints, + errors, + warnings, + stats, + chunks, + modules, + statsJson, + }; +} + +export { getExampleConfig, runWebpackExampleInMemory, fs, getFixtureResource, getLoader, getFixture }; From 4aa82f289bf125d26ae530a83377aa544d4ab454 Mon Sep 17 00:00:00 2001 From: Ian J Sikes Date: Mon, 4 Sep 2017 17:25:16 -0700 Subject: [PATCH 16/22] Copy plugin test and example template files in generator --- lib/generate-plugin/plugin-generator.js | 45 ++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/lib/generate-plugin/plugin-generator.js b/lib/generate-plugin/plugin-generator.js index 8d01db2509c..c39c7f19e5f 100644 --- a/lib/generate-plugin/plugin-generator.js +++ b/lib/generate-plugin/plugin-generator.js @@ -42,6 +42,10 @@ class PluginGenerator extends Generator { } writing() { + /** + * Plugin source + */ + this.fs.copyTpl( path.join(__dirname, 'templates', 'src', '_index.js.tpl'), this.destinationPath('src/index.js'), @@ -52,10 +56,49 @@ class PluginGenerator extends Generator { path.join(__dirname, 'templates', 'src', 'cjs.js.tpl'), this.destinationPath('src/cjs.js') ); + + /** + * Tests + */ + + this.fs.copy( + path.join(__dirname, 'templates', 'test', 'test-utils.js.tpl'), + this.destinationPath('test/test-utils.js') + ); + + this.fs.copy( + path.join(__dirname, 'templates', 'test', 'functional.test.js.tpl'), + this.destinationPath('test/functional.test.js') + ); + + /** + * Examples + */ + + this.fs.copyTpl( + path.join(__dirname, 'templates', 'examples', 'simple', 'webpack.config.js.tpl'), + this.destinationPath('examples/simple/webpack.config.js'), + { name: _.upperFirst(_.camelCase(this.props.name)) } + ); + + this.fs.copy( + path.join(__dirname, 'templates', 'examples', 'simple', 'src','index.js.tpl'), + this.destinationPath('examples/simple/src/index.js') + ); + + this.fs.copy( + path.join(__dirname, 'templates', 'examples', 'simple', 'src','lazy-module.js.tpl'), + this.destinationPath('examples/simple/src/lazy-module.js') + ); + + this.fs.copy( + path.join(__dirname, 'templates', 'examples', 'simple', 'src','static-esm-module.js.tpl'), + this.destinationPath('examples/simple/src/static-esm-module.js') + ); } install() { - this.npmInstall(['webpack-defaults'], { 'save-dev': true }).then(() => { + this.npmInstall(['webpack-defaults', 'bluebird'], { 'save-dev': true }).then(() => { this.spawnCommand('npm', ['run', 'webpack-defaults']); }); } From bb164a82eb8a5fe9470cd9fbbd1b149ca7aa6480 Mon Sep 17 00:00:00 2001 From: Ian J Sikes Date: Fri, 8 Sep 2017 16:32:06 -0700 Subject: [PATCH 17/22] Refactor generator file copying, switch .includes with .indexOf in CLI arg parsing --- bin/webpack.js | 8 +- lib/generate-loader/loader-generator.js | 81 ++++++------------- .../templates/test/unit.test.js.tpl | 2 +- lib/generate-plugin/plugin-generator.js | 64 +++++---------- 4 files changed, 52 insertions(+), 103 deletions(-) diff --git a/bin/webpack.js b/bin/webpack.js index 4899fcb3ebb..48c2e530b6d 100755 --- a/bin/webpack.js +++ b/bin/webpack.js @@ -155,11 +155,11 @@ if(argv.verbose) { argv['display-cached'] = true; argv['display-cached-assets'] = true; } -if(argv._.includes('init')) { +if(argv._.indexOf('init') > -1) { const initPkgs = argv._.length === 1 ? [] : [argv._.pop()]; return require('../lib/initialize')(initPkgs); -} else if(argv._.includes('migrate')) { +} else if(argv._.indexOf('migrate') > -1) { const filePaths = argv._.length === 1 ? [] : [argv._.pop()]; if (!filePaths.length) { throw new Error('Please specify a path to your webpack config'); @@ -167,9 +167,9 @@ if(argv._.includes('init')) { const inputConfigPath = path.resolve(process.cwd(), filePaths[0]); return require('../lib/migrate.js')(inputConfigPath, inputConfigPath); -} else if(argv._.includes('generate-loader')) { +} else if(argv._.indexOf('generate-loader') > -1) { return require('../lib/generate-loader/index.js')(); -} else if(argv._.includes('generate-plugin')) { +} else if(argv._.indexOf('generate-plugin') > -1) { return require('../lib/generate-plugin/index.js')(); } else { var options = require('./convert-argv')(yargs, argv); diff --git a/lib/generate-loader/loader-generator.js b/lib/generate-loader/loader-generator.js index 6147957fb6a..a67b22abf39 100644 --- a/lib/generate-loader/loader-generator.js +++ b/lib/generate-loader/loader-generator.js @@ -57,68 +57,37 @@ class LoaderGenerator extends Generator { } writing() { - /** - * Loader source - */ + const copy = (filePath) => { + const sourceParts = [__dirname, 'templates']; + sourceParts.push.apply(sourceParts, filePath.split('/')); + const targetParts = path.dirname(filePath).split('/'); + targetParts.push(path.basename(filePath, '.tpl')); + + this.fs.copy( + path.join.apply(null, sourceParts), + this.destinationPath(path.join.apply(null, targetParts)) + ); + }; + // Loader source + copy('src/cjs.js.tpl'); this.fs.copyTpl( path.join(__dirname, 'templates', 'src', '_index.js.tpl'), - this.destinationPath('src/index.js'), + this.destinationPath(path.join('src', 'index.js')), { name: this.props.name } ); - this.fs.copy( - path.join(__dirname, 'templates', 'src', 'cjs.js.tpl'), - this.destinationPath('src/cjs.js') - ); - - /** - * Tests - */ - - this.fs.copy( - path.join(__dirname, 'templates', 'test', 'test-utils.js.tpl'), - this.destinationPath('test/test-utils.js') - ); - - this.fs.copy( - path.join(__dirname, 'templates', 'test', 'unit.test.js.tpl'), - this.destinationPath('test/unit.test.js') - ); - - this.fs.copy( - path.join(__dirname, 'templates', 'test', 'functional.test.js.tpl'), - this.destinationPath('test/functional.test.js') - ); - - this.fs.copy( - path.join(__dirname, 'templates', 'test', 'fixtures', 'simple-file.js.tpl'), - this.destinationPath('test/fixtures/simple-file.js') - ); - - /** - * Examples - */ - - this.fs.copy( - path.join(__dirname, 'templates', 'examples', 'simple', 'webpack.config.js.tpl'), - this.destinationPath('examples/simple/webpack.config.js') - ); - - this.fs.copy( - path.join(__dirname, 'templates', 'examples', 'simple', 'src','index.js.tpl'), - this.destinationPath('examples/simple/src/index.js') - ); - - this.fs.copy( - path.join(__dirname, 'templates', 'examples', 'simple', 'src','lazy-module.js.tpl'), - this.destinationPath('examples/simple/src/lazy-module.js') - ); - - this.fs.copy( - path.join(__dirname, 'templates', 'examples', 'simple', 'src','static-esm-module.js.tpl'), - this.destinationPath('examples/simple/src/static-esm-module.js') - ); + // Tests + copy('test/test-utils.js.tpl'); + copy('test/unit.test.js.tpl'); + copy('test/functional.test.js.tpl'); + copy('test/fixtures/simple-file.js.tpl'); + + // Examples + copy('examples/simple/webpack.config.js.tpl'); + copy('examples/simple/src/index.js.tpl'); + copy('examples/simple/src/lazy-module.js.tpl'); + copy('examples/simple/src/static-esm-module.js.tpl'); } install() { diff --git a/lib/generate-loader/templates/test/unit.test.js.tpl b/lib/generate-loader/templates/test/unit.test.js.tpl index 3ef1728b618..ac1b90a4e4a 100644 --- a/lib/generate-loader/templates/test/unit.test.js.tpl +++ b/lib/generate-loader/templates/test/unit.test.js.tpl @@ -1,6 +1,6 @@ import fs from 'fs'; -import { runLoaders } from 'loader-runner'; import Promise from 'bluebird'; +import { runLoaders } from 'loader-runner'; import { getFixtureResource, getFixture, getLoader } from './test-utils'; const runLoadersPromise = Promise.promisify(runLoaders); diff --git a/lib/generate-plugin/plugin-generator.js b/lib/generate-plugin/plugin-generator.js index c39c7f19e5f..e19bec9d1f2 100644 --- a/lib/generate-plugin/plugin-generator.js +++ b/lib/generate-plugin/plugin-generator.js @@ -42,59 +42,39 @@ class PluginGenerator extends Generator { } writing() { - /** - * Plugin source - */ + const copy = (filePath) => { + const sourceParts = [__dirname, 'templates']; + sourceParts.push.apply(sourceParts, filePath.split('/')); + const targetParts = path.dirname(filePath).split('/'); + targetParts.push(path.basename(filePath, '.tpl')); + + this.fs.copy( + path.join.apply(null, sourceParts), + this.destinationPath(path.join.apply(null, targetParts)) + ); + }; + // Plugin source + copy('src/cjs.js.tpl'); this.fs.copyTpl( path.join(__dirname, 'templates', 'src', '_index.js.tpl'), - this.destinationPath('src/index.js'), + this.destinationPath(path.join('src', 'index.js')), { name: _.upperFirst(_.camelCase(this.props.name)) } ); - this.fs.copy( - path.join(__dirname, 'templates', 'src', 'cjs.js.tpl'), - this.destinationPath('src/cjs.js') - ); - - /** - * Tests - */ - - this.fs.copy( - path.join(__dirname, 'templates', 'test', 'test-utils.js.tpl'), - this.destinationPath('test/test-utils.js') - ); - - this.fs.copy( - path.join(__dirname, 'templates', 'test', 'functional.test.js.tpl'), - this.destinationPath('test/functional.test.js') - ); - - /** - * Examples - */ + // Tests + copy('test/test-utils.js.tpl'); + copy('test/functional.test.js.tpl'); + // Examples + copy('examples/simple/src/index.js.tpl'); + copy('examples/simple/src/lazy-module.js.tpl'); + copy('examples/simple/src/static-esm-module.js.tpl'); this.fs.copyTpl( path.join(__dirname, 'templates', 'examples', 'simple', 'webpack.config.js.tpl'), - this.destinationPath('examples/simple/webpack.config.js'), + this.destinationPath(path.join('examples', 'simple', 'webpack.config.js')), { name: _.upperFirst(_.camelCase(this.props.name)) } ); - - this.fs.copy( - path.join(__dirname, 'templates', 'examples', 'simple', 'src','index.js.tpl'), - this.destinationPath('examples/simple/src/index.js') - ); - - this.fs.copy( - path.join(__dirname, 'templates', 'examples', 'simple', 'src','lazy-module.js.tpl'), - this.destinationPath('examples/simple/src/lazy-module.js') - ); - - this.fs.copy( - path.join(__dirname, 'templates', 'examples', 'simple', 'src','static-esm-module.js.tpl'), - this.destinationPath('examples/simple/src/static-esm-module.js') - ); } install() { From 10ce3c2ef10f59794ca433cbde250c612c7f9e9b Mon Sep 17 00:00:00 2001 From: Ian J Sikes Date: Sun, 10 Sep 2017 19:40:57 -0700 Subject: [PATCH 18/22] Change `indexOf('foo') > -1` to `indexOf('foo') >= 0` --- bin/webpack.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/webpack.js b/bin/webpack.js index 48c2e530b6d..28817790848 100755 --- a/bin/webpack.js +++ b/bin/webpack.js @@ -155,11 +155,11 @@ if(argv.verbose) { argv['display-cached'] = true; argv['display-cached-assets'] = true; } -if(argv._.indexOf('init') > -1) { +if(argv._.indexOf('init') >= 0) { const initPkgs = argv._.length === 1 ? [] : [argv._.pop()]; return require('../lib/initialize')(initPkgs); -} else if(argv._.indexOf('migrate') > -1) { +} else if(argv._.indexOf('migrate') >= 0) { const filePaths = argv._.length === 1 ? [] : [argv._.pop()]; if (!filePaths.length) { throw new Error('Please specify a path to your webpack config'); @@ -167,9 +167,9 @@ if(argv._.indexOf('init') > -1) { const inputConfigPath = path.resolve(process.cwd(), filePaths[0]); return require('../lib/migrate.js')(inputConfigPath, inputConfigPath); -} else if(argv._.indexOf('generate-loader') > -1) { +} else if(argv._.indexOf('generate-loader') >= 0) { return require('../lib/generate-loader/index.js')(); -} else if(argv._.indexOf('generate-plugin') > -1) { +} else if(argv._.indexOf('generate-plugin') >= 0) { return require('../lib/generate-plugin/index.js')(); } else { var options = require('./convert-argv')(yargs, argv); From 4a8f738732d00ae05052526d8fe201607f7e5eff Mon Sep 17 00:00:00 2001 From: Ian J Sikes Date: Sun, 10 Sep 2017 19:42:09 -0700 Subject: [PATCH 19/22] Factor out generator copy utilities into separate module --- ...k.config.js.tpl => _webpack.config.js.tpl} | 0 lib/utils/copy-utils.js | 48 +++++++++++++++++++ 2 files changed, 48 insertions(+) rename lib/generate-plugin/templates/examples/simple/{webpack.config.js.tpl => _webpack.config.js.tpl} (100%) create mode 100644 lib/utils/copy-utils.js diff --git a/lib/generate-plugin/templates/examples/simple/webpack.config.js.tpl b/lib/generate-plugin/templates/examples/simple/_webpack.config.js.tpl similarity index 100% rename from lib/generate-plugin/templates/examples/simple/webpack.config.js.tpl rename to lib/generate-plugin/templates/examples/simple/_webpack.config.js.tpl diff --git a/lib/utils/copy-utils.js b/lib/utils/copy-utils.js new file mode 100644 index 00000000000..088b3ffc519 --- /dev/null +++ b/lib/utils/copy-utils.js @@ -0,0 +1,48 @@ +const path = require('path'); + +/** + * Takes in a file path in the `./templates` directory. Copies that + * file to the destination, with the `.tpl` extension stripped. + * + * @param {Generator} generator A Yeoman Generator instance + * @param {string} templateDir Absolute path to template directory + */ +const generatorCopy = (generator, templateDir) => /** @param {string} filePath */ (filePath) => { + const sourceParts = templateDir.split(path.delimiter); + sourceParts.push.apply(sourceParts, filePath.split('/')); + const targetParts = path.dirname(filePath).split('/'); + targetParts.push(path.basename(filePath, '.tpl')); + + generator.fs.copy( + path.join.apply(null, sourceParts), + generator.destinationPath(path.join.apply(null, targetParts)) + ); +}; + +/** + * Takes in a file path in the `./templates` directory. Copies that + * file to the destination, with the `.tpl` extension and `_` prefix + * stripped. Passes `this.props` to the template. + * + * @param {Generator} generator A Yeoman Generator instance + * @param {string} templateDir Absolute path to template directory + * @param {any} templateData An object containing the data passed to + * the template files. + */ +const generatorCopyTpl = (generator, templateDir, templateData) => /** @param {string} filePath */ (filePath) => { + const sourceParts = templateDir.split(path.delimiter); + sourceParts.push.apply(sourceParts, filePath.split('/')); + const targetParts = path.dirname(filePath).split('/'); + targetParts.push(path.basename(filePath, '.tpl').slice(1)); + + generator.fs.copyTpl( + path.join.apply(null, sourceParts), + generator.destinationPath(path.join.apply(null, targetParts)), + templateData + ); +}; + +module.exports = { + generatorCopy, + generatorCopyTpl, +}; From 49c887edda9c622f1fe9f17bd0932e2da68225b8 Mon Sep 17 00:00:00 2001 From: Ian J Sikes Date: Sun, 10 Sep 2017 19:44:18 -0700 Subject: [PATCH 20/22] Rewrite generators using a function that returns a customized generator class --- lib/generate-loader/loader-generator.js | 99 +++++++------------------ lib/generate-plugin/plugin-generator.js | 99 +++++++------------------ lib/utils/webpack-generator.js | 64 ++++++++++++++++ 3 files changed, 116 insertions(+), 146 deletions(-) create mode 100644 lib/utils/webpack-generator.js diff --git a/lib/generate-loader/loader-generator.js b/lib/generate-loader/loader-generator.js index a67b22abf39..be09d5e8695 100644 --- a/lib/generate-loader/loader-generator.js +++ b/lib/generate-loader/loader-generator.js @@ -1,7 +1,6 @@ const path = require('path'); -const mkdirp = require('mkdirp'); const _ = require('lodash'); -const Generator = require('yeoman-generator'); +const webpackGenerator = require('../utils/webpack-generator'); /** * Formats a string into webpack loader format @@ -26,76 +25,32 @@ function makeLoaderName(name) { * @class LoaderGenerator * @extends {Generator} */ -class LoaderGenerator extends Generator { - prompting() { - const prompts = [ - { - type: 'input', - name: 'name', - message: 'Loader name', - default: 'my-loader', - filter: makeLoaderName, - validate: str => str.length > 0, - }, - ]; - - return this.prompt(prompts).then(props => { - this.props = props; - }); - } - - default() { - if (path.basename(this.destinationPath()) !== this.props.name) { - this.log( - 'Your loader must be inside a folder named ' + - this.props.name + - '\nI will create this folder for you.' - ); - mkdirp(this.props.name); - this.destinationRoot(this.destinationPath(this.props.name)); - } - } - - writing() { - const copy = (filePath) => { - const sourceParts = [__dirname, 'templates']; - sourceParts.push.apply(sourceParts, filePath.split('/')); - const targetParts = path.dirname(filePath).split('/'); - targetParts.push(path.basename(filePath, '.tpl')); - - this.fs.copy( - path.join.apply(null, sourceParts), - this.destinationPath(path.join.apply(null, targetParts)) - ); - }; - - // Loader source - copy('src/cjs.js.tpl'); - this.fs.copyTpl( - path.join(__dirname, 'templates', 'src', '_index.js.tpl'), - this.destinationPath(path.join('src', 'index.js')), - { name: this.props.name } - ); - - // Tests - copy('test/test-utils.js.tpl'); - copy('test/unit.test.js.tpl'); - copy('test/functional.test.js.tpl'); - copy('test/fixtures/simple-file.js.tpl'); - - // Examples - copy('examples/simple/webpack.config.js.tpl'); - copy('examples/simple/src/index.js.tpl'); - copy('examples/simple/src/lazy-module.js.tpl'); - copy('examples/simple/src/static-esm-module.js.tpl'); - } - - install() { - this.npmInstall(['webpack-defaults', 'bluebird'], { 'save-dev': true }).then(() => { - this.spawnCommand('npm', ['run', 'webpack-defaults']); - }); - } -} +const LoaderGenerator = webpackGenerator( + [{ + type: 'input', + name: 'name', + message: 'Loader name', + default: 'my-loader', + filter: makeLoaderName, + validate: str => str.length > 0, + }], + path.join(__dirname, 'templates'), + [ + 'src/cjs.js.tpl', + 'test/test-utils.js.tpl', + 'test/unit.test.js.tpl', + 'test/functional.test.js.tpl', + 'test/fixtures/simple-file.js.tpl', + 'examples/simple/webpack.config.js.tpl', + 'examples/simple/src/index.js.tpl', + 'examples/simple/src/lazy-module.js.tpl', + 'examples/simple/src/static-esm-module.js.tpl', + ], + [ + 'src/_index.js.tpl', + ], + (gen) => ({ name: gen.props.name }) +); module.exports = { makeLoaderName, diff --git a/lib/generate-plugin/plugin-generator.js b/lib/generate-plugin/plugin-generator.js index e19bec9d1f2..19f48156ae4 100644 --- a/lib/generate-plugin/plugin-generator.js +++ b/lib/generate-plugin/plugin-generator.js @@ -1,7 +1,6 @@ const path = require('path'); -const mkdirp = require('mkdirp'); const _ = require('lodash'); -const Generator = require('yeoman-generator'); +const webpackGenerator = require('../utils/webpack-generator'); /** * A yeoman generator class for creating a webpack @@ -11,78 +10,30 @@ const Generator = require('yeoman-generator'); * @class PluginGenerator * @extends {Generator} */ -class PluginGenerator extends Generator { - prompting() { - const prompts = [ - { - type: 'input', - name: 'name', - message: 'Plugin name', - default: 'my-webpack-plugin', - filter: _.kebabCase, - validate: str => str.length > 0, - }, - ]; - - return this.prompt(prompts).then(props => { - this.props = props; - }); - } - - default() { - if (path.basename(this.destinationPath()) !== this.props.name) { - this.log( - 'Your plugin must be inside a folder named ' + - this.props.name + - '\nI will create this folder for you.' - ); - mkdirp(this.props.name); - this.destinationRoot(this.destinationPath(this.props.name)); - } - } - - writing() { - const copy = (filePath) => { - const sourceParts = [__dirname, 'templates']; - sourceParts.push.apply(sourceParts, filePath.split('/')); - const targetParts = path.dirname(filePath).split('/'); - targetParts.push(path.basename(filePath, '.tpl')); - - this.fs.copy( - path.join.apply(null, sourceParts), - this.destinationPath(path.join.apply(null, targetParts)) - ); - }; - - // Plugin source - copy('src/cjs.js.tpl'); - this.fs.copyTpl( - path.join(__dirname, 'templates', 'src', '_index.js.tpl'), - this.destinationPath(path.join('src', 'index.js')), - { name: _.upperFirst(_.camelCase(this.props.name)) } - ); - - // Tests - copy('test/test-utils.js.tpl'); - copy('test/functional.test.js.tpl'); - - // Examples - copy('examples/simple/src/index.js.tpl'); - copy('examples/simple/src/lazy-module.js.tpl'); - copy('examples/simple/src/static-esm-module.js.tpl'); - this.fs.copyTpl( - path.join(__dirname, 'templates', 'examples', 'simple', 'webpack.config.js.tpl'), - this.destinationPath(path.join('examples', 'simple', 'webpack.config.js')), - { name: _.upperFirst(_.camelCase(this.props.name)) } - ); - } - - install() { - this.npmInstall(['webpack-defaults', 'bluebird'], { 'save-dev': true }).then(() => { - this.spawnCommand('npm', ['run', 'webpack-defaults']); - }); - } -} +const PluginGenerator = webpackGenerator( + [{ + type: 'input', + name: 'name', + message: 'Plugin name', + default: 'my-webpack-plugin', + filter: _.kebabCase, + validate: str => str.length > 0, + }], + path.join(__dirname, 'templates'), + [ + 'src/cjs.js.tpl', + 'test/test-utils.js.tpl', + 'test/functional.test.js.tpl', + 'examples/simple/src/index.js.tpl', + 'examples/simple/src/lazy-module.js.tpl', + 'examples/simple/src/static-esm-module.js.tpl', + ], + [ + 'src/_index.js.tpl', + 'examples/simple/_webpack.config.js.tpl', + ], + (gen) => ({ name: _.upperFirst(_.camelCase(gen.props.name))}) +); module.exports = { PluginGenerator, diff --git a/lib/utils/webpack-generator.js b/lib/utils/webpack-generator.js new file mode 100644 index 00000000000..b0b0659c759 --- /dev/null +++ b/lib/utils/webpack-generator.js @@ -0,0 +1,64 @@ +const path = require('path'); +const mkdirp = require('mkdirp'); +const Generator = require('yeoman-generator'); +const copyUtils = require('../utils/copy-utils'); + +/** + * Creates a Yeoman Generator that generates a project conforming + * to webpack-defaults. + * + * @param {any[]} prompts An array of Yeoman prompt objects + * + * @param {string} templateDir Absolute path to template directory + * + * @param {string[]} copyFiles An array of file paths (relative to `./templates`) + * of files to be copied to the generated project. File paths should be of the + * form `path/to/file.js.tpl`. + * + * @param {string[]} copyTemplateFiles An array of file paths (relative to + * `./templates`) of files to be copied to the generated project. Template + * file paths should be of the form `path/to/_file.js.tpl`. + * + * @param {} templateFn A function that is passed a generator instance and + * returns an object containing data to be supplied to the template files. + * + * @returns {Generator} + */ +function webpackGenerator(prompts, templateDir, copyFiles, copyTemplateFiles, templateFn) { + return class extends Generator { + prompting() { + return this.prompt(prompts).then(props => { + this.props = props; + }); + } + + default() { + const currentDirName = path.basename(this.destinationPath()); + if (currentDirName !== this.props.name) { + this.log(` + Your project must be inside a folder named ${this.props.name} + I will create this folder for you. + `); + mkdirp(this.props.name); + const pathToProjectDir = this.destinationPath(this.props.name); + this.destinationRoot(pathToProjectDir); + } + } + + writing() { + this.copy = copyUtils.generatorCopy(this, templateDir); + this.copyTpl = copyUtils.generatorCopyTpl(this, templateDir, templateFn(this)); + + copyFiles.forEach(this.copy); + copyTemplateFiles.forEach(this.copyTpl); + } + + install() { + this.npmInstall(['webpack-defaults', 'bluebird'], { 'save-dev': true }).then(() => { + this.spawnCommand('npm', ['run', 'webpack-defaults']); + }); + } + }; +} + +module.exports = webpackGenerator; From a106d9dc61365cccf49af726317c4c6fb34be818 Mon Sep 17 00:00:00 2001 From: Ian J Sikes Date: Thu, 14 Sep 2017 22:47:58 -0700 Subject: [PATCH 21/22] Fix linting errors --- bin/config-yargs.js | 18 +- bin/webpack.js | 16 +- lib/generate-loader/index.js | 9 +- lib/generate-loader/loader-generator.js | 40 +- lib/generate-loader/loader-generator.test.js | 18 +- lib/generate-plugin/index.js | 9 +- lib/generate-plugin/plugin-generator.js | 36 +- lib/utils/copy-utils.js | 24 +- lib/utils/webpack-generator.js | 21 +- package-lock.json | 905 ------------------- 10 files changed, 98 insertions(+), 998 deletions(-) diff --git a/bin/config-yargs.js b/bin/config-yargs.js index 9db7c3a533a..ac2187e350d 100644 --- a/bin/config-yargs.js +++ b/bin/config-yargs.js @@ -28,19 +28,19 @@ module.exports = function(yargs) { "Migrate your webpack configuration from webpack 1 to webpack 2", group: INIT_GROUP }, - 'generate-loader': { - type: 'boolean', - describe: 'Generates a new webpack loader project', + "generate-loader": { + type: "boolean", + describe: "Generates a new webpack loader project", group: INIT_GROUP }, - 'generate-plugin': { - type: 'boolean', - describe: 'Generates a new webpack plugin project', + "generate-plugin": { + type: "boolean", + describe: "Generates a new webpack plugin project", group: INIT_GROUP }, - 'config': { - type: 'string', - describe: 'Path to the config file', + config: { + type: "string", + describe: "Path to the config file", group: CONFIG_GROUP, defaultDescription: "webpack.config.js or webpackfile.js", requiresArg: true diff --git a/bin/webpack.js b/bin/webpack.js index 36ecf404c88..db514c3f362 100755 --- a/bin/webpack.js +++ b/bin/webpack.js @@ -159,22 +159,22 @@ if (argv.verbose) { argv["display-cached"] = true; argv["display-cached-assets"] = true; } -if(argv._.indexOf('init') >= 0) { +if (argv._.indexOf("init") >= 0) { const initPkgs = argv._.length === 1 ? [] : [argv._.pop()]; - return require('../lib/initialize')(initPkgs); -} else if(argv._.indexOf('migrate') >= 0) { + return require("../lib/initialize")(initPkgs); +} else if (argv._.indexOf("migrate") >= 0) { const filePaths = argv._.length === 1 ? [] : [argv._.pop()]; if (!filePaths.length) { throw new Error("Please specify a path to your webpack config"); } const inputConfigPath = path.resolve(process.cwd(), filePaths[0]); - return require('../lib/migrate.js')(inputConfigPath, inputConfigPath); -} else if(argv._.indexOf('generate-loader') >= 0) { - return require('../lib/generate-loader/index.js')(); -} else if(argv._.indexOf('generate-plugin') >= 0) { - return require('../lib/generate-plugin/index.js')(); + return require("../lib/migrate.js")(inputConfigPath, inputConfigPath); +} else if (argv._.indexOf("generate-loader") >= 0) { + return require("../lib/generate-loader/index.js")(); +} else if (argv._.indexOf("generate-plugin") >= 0) { + return require("../lib/generate-plugin/index.js")(); } else { var options = require("./convert-argv")(yargs, argv); diff --git a/lib/generate-loader/index.js b/lib/generate-loader/index.js index 5f911be6219..ff83f5f84fa 100644 --- a/lib/generate-loader/index.js +++ b/lib/generate-loader/index.js @@ -1,12 +1,13 @@ -const yeoman = require('yeoman-environment'); -const LoaderGenerator = require('./loader-generator').LoaderGenerator; +var yeoman = require("yeoman-environment"); +var LoaderGenerator = require("./loader-generator").LoaderGenerator; /** * Runs a yeoman generator to create a new webpack loader project + * @returns {void} */ function loaderCreator() { - let env = yeoman.createEnv(); - const generatorName = 'webpack-loader-generator'; + var env = yeoman.createEnv(); + var generatorName = "webpack-loader-generator"; env.registerStub(LoaderGenerator, generatorName); diff --git a/lib/generate-loader/loader-generator.js b/lib/generate-loader/loader-generator.js index be09d5e8695..9e5a22e27b5 100644 --- a/lib/generate-loader/loader-generator.js +++ b/lib/generate-loader/loader-generator.js @@ -1,6 +1,6 @@ -const path = require('path'); -const _ = require('lodash'); -const webpackGenerator = require('../utils/webpack-generator'); +var path = require("path"); +var _ = require("lodash"); +var webpackGenerator = require("../utils/webpack-generator"); /** * Formats a string into webpack loader format @@ -12,7 +12,7 @@ const webpackGenerator = require('../utils/webpack-generator'); function makeLoaderName(name) { name = _.kebabCase(name); if (!/loader$/.test(name)) { - name += '-loader'; + name += "-loader"; } return name; } @@ -25,29 +25,29 @@ function makeLoaderName(name) { * @class LoaderGenerator * @extends {Generator} */ -const LoaderGenerator = webpackGenerator( +var LoaderGenerator = webpackGenerator( [{ - type: 'input', - name: 'name', - message: 'Loader name', - default: 'my-loader', + type: "input", + name: "name", + message: "Loader name", + default: "my-loader", filter: makeLoaderName, validate: str => str.length > 0, }], - path.join(__dirname, 'templates'), + path.join(__dirname, "templates"), [ - 'src/cjs.js.tpl', - 'test/test-utils.js.tpl', - 'test/unit.test.js.tpl', - 'test/functional.test.js.tpl', - 'test/fixtures/simple-file.js.tpl', - 'examples/simple/webpack.config.js.tpl', - 'examples/simple/src/index.js.tpl', - 'examples/simple/src/lazy-module.js.tpl', - 'examples/simple/src/static-esm-module.js.tpl', + "src/cjs.js.tpl", + "test/test-utils.js.tpl", + "test/unit.test.js.tpl", + "test/functional.test.js.tpl", + "test/fixtures/simple-file.js.tpl", + "examples/simple/webpack.config.js.tpl", + "examples/simple/src/index.js.tpl", + "examples/simple/src/lazy-module.js.tpl", + "examples/simple/src/static-esm-module.js.tpl", ], [ - 'src/_index.js.tpl', + "src/_index.js.tpl", ], (gen) => ({ name: gen.props.name }) ); diff --git a/lib/generate-loader/loader-generator.test.js b/lib/generate-loader/loader-generator.test.js index 0e2aec154f1..3dc3e55dd7e 100644 --- a/lib/generate-loader/loader-generator.test.js +++ b/lib/generate-loader/loader-generator.test.js @@ -1,17 +1,17 @@ -'use strict'; +"use strict"; -const makeLoaderName = require('./loader-generator').makeLoaderName; +var makeLoaderName = require("./loader-generator").makeLoaderName; -describe('makeLoaderName', () => { +describe("makeLoaderName", () => { - it('should kebab-case loader name and append \'-loader\'', () => { - const loaderName = makeLoaderName('This is a test'); - expect(loaderName).toEqual('this-is-a-test-loader'); + it("should kebab-case loader name and append '-loader'", () => { + var loaderName = makeLoaderName("This is a test"); + expect(loaderName).toEqual("this-is-a-test-loader"); }); - it('should not modify a properly formatted loader name', () => { - const loaderName = makeLoaderName('properly-named-loader'); - expect(loaderName).toEqual('properly-named-loader'); + it("should not modify a properly formatted loader name", () => { + var loaderName = makeLoaderName("properly-named-loader"); + expect(loaderName).toEqual("properly-named-loader"); }); }); diff --git a/lib/generate-plugin/index.js b/lib/generate-plugin/index.js index d957a599468..82fe7dd386d 100644 --- a/lib/generate-plugin/index.js +++ b/lib/generate-plugin/index.js @@ -1,12 +1,13 @@ -const yeoman = require('yeoman-environment'); -const PluginGenerator = require('./plugin-generator').PluginGenerator; +var yeoman = require("yeoman-environment"); +var PluginGenerator = require("./plugin-generator").PluginGenerator; /** * Runs a yeoman generator to create a new webpack plugin project + * @returns {void} */ function pluginCreator() { - let env = yeoman.createEnv(); - const generatorName = 'webpack-plugin-generator'; + var env = yeoman.createEnv(); + var generatorName = "webpack-plugin-generator"; env.registerStub(PluginGenerator, generatorName); diff --git a/lib/generate-plugin/plugin-generator.js b/lib/generate-plugin/plugin-generator.js index 19f48156ae4..fcddd43993a 100644 --- a/lib/generate-plugin/plugin-generator.js +++ b/lib/generate-plugin/plugin-generator.js @@ -1,6 +1,6 @@ -const path = require('path'); -const _ = require('lodash'); -const webpackGenerator = require('../utils/webpack-generator'); +var path = require("path"); +var _ = require("lodash"); +var webpackGenerator = require("../utils/webpack-generator"); /** * A yeoman generator class for creating a webpack @@ -10,29 +10,29 @@ const webpackGenerator = require('../utils/webpack-generator'); * @class PluginGenerator * @extends {Generator} */ -const PluginGenerator = webpackGenerator( +var PluginGenerator = webpackGenerator( [{ - type: 'input', - name: 'name', - message: 'Plugin name', - default: 'my-webpack-plugin', + type: "input", + name: "name", + message: "Plugin name", + default: "my-webpack-plugin", filter: _.kebabCase, validate: str => str.length > 0, }], - path.join(__dirname, 'templates'), + path.join(__dirname, "templates"), [ - 'src/cjs.js.tpl', - 'test/test-utils.js.tpl', - 'test/functional.test.js.tpl', - 'examples/simple/src/index.js.tpl', - 'examples/simple/src/lazy-module.js.tpl', - 'examples/simple/src/static-esm-module.js.tpl', + "src/cjs.js.tpl", + "test/test-utils.js.tpl", + "test/functional.test.js.tpl", + "examples/simple/src/index.js.tpl", + "examples/simple/src/lazy-module.js.tpl", + "examples/simple/src/static-esm-module.js.tpl", ], [ - 'src/_index.js.tpl', - 'examples/simple/_webpack.config.js.tpl', + "src/_index.js.tpl", + "examples/simple/_webpack.config.js.tpl", ], - (gen) => ({ name: _.upperFirst(_.camelCase(gen.props.name))}) + (gen) => ({ name: _.upperFirst(_.camelCase(gen.props.name)) }) ); module.exports = { diff --git a/lib/utils/copy-utils.js b/lib/utils/copy-utils.js index 088b3ffc519..e515d862257 100644 --- a/lib/utils/copy-utils.js +++ b/lib/utils/copy-utils.js @@ -1,4 +1,4 @@ -const path = require('path'); +var path = require("path"); /** * Takes in a file path in the `./templates` directory. Copies that @@ -6,12 +6,13 @@ const path = require('path'); * * @param {Generator} generator A Yeoman Generator instance * @param {string} templateDir Absolute path to template directory + * @returns {Function} A curried function that takes a file path and copies it */ -const generatorCopy = (generator, templateDir) => /** @param {string} filePath */ (filePath) => { - const sourceParts = templateDir.split(path.delimiter); - sourceParts.push.apply(sourceParts, filePath.split('/')); - const targetParts = path.dirname(filePath).split('/'); - targetParts.push(path.basename(filePath, '.tpl')); +var generatorCopy = (generator, templateDir) => /** @param {string} filePath */ (filePath) => { + var sourceParts = templateDir.split(path.delimiter); + sourceParts.push.apply(sourceParts, filePath.split("/")); + var targetParts = path.dirname(filePath).split("/"); + targetParts.push(path.basename(filePath, ".tpl")); generator.fs.copy( path.join.apply(null, sourceParts), @@ -28,12 +29,13 @@ const generatorCopy = (generator, templateDir) => /** @param {string} filePath * * @param {string} templateDir Absolute path to template directory * @param {any} templateData An object containing the data passed to * the template files. + * @returns {Function} A curried function that takes a file path and copies it */ -const generatorCopyTpl = (generator, templateDir, templateData) => /** @param {string} filePath */ (filePath) => { - const sourceParts = templateDir.split(path.delimiter); - sourceParts.push.apply(sourceParts, filePath.split('/')); - const targetParts = path.dirname(filePath).split('/'); - targetParts.push(path.basename(filePath, '.tpl').slice(1)); +var generatorCopyTpl = (generator, templateDir, templateData) => /** @param {string} filePath */ (filePath) => { + var sourceParts = templateDir.split(path.delimiter); + sourceParts.push.apply(sourceParts, filePath.split("/")); + var targetParts = path.dirname(filePath).split("/"); + targetParts.push(path.basename(filePath, ".tpl").slice(1)); generator.fs.copyTpl( path.join.apply(null, sourceParts), diff --git a/lib/utils/webpack-generator.js b/lib/utils/webpack-generator.js index b0b0659c759..f7f058098a6 100644 --- a/lib/utils/webpack-generator.js +++ b/lib/utils/webpack-generator.js @@ -1,7 +1,7 @@ -const path = require('path'); -const mkdirp = require('mkdirp'); -const Generator = require('yeoman-generator'); -const copyUtils = require('../utils/copy-utils'); +var path = require("path"); +var mkdirp = require("mkdirp"); +var Generator = require("yeoman-generator"); +var copyUtils = require("../utils/copy-utils"); /** * Creates a Yeoman Generator that generates a project conforming @@ -19,12 +19,13 @@ const copyUtils = require('../utils/copy-utils'); * `./templates`) of files to be copied to the generated project. Template * file paths should be of the form `path/to/_file.js.tpl`. * - * @param {} templateFn A function that is passed a generator instance and + * @param {Function} templateFn A function that is passed a generator instance and * returns an object containing data to be supplied to the template files. * - * @returns {Generator} + * @returns {Generator} A class extending Generator */ function webpackGenerator(prompts, templateDir, copyFiles, copyTemplateFiles, templateFn) { + //eslint-disable-next-line return class extends Generator { prompting() { return this.prompt(prompts).then(props => { @@ -33,14 +34,14 @@ function webpackGenerator(prompts, templateDir, copyFiles, copyTemplateFiles, te } default() { - const currentDirName = path.basename(this.destinationPath()); + var currentDirName = path.basename(this.destinationPath()); if (currentDirName !== this.props.name) { this.log(` Your project must be inside a folder named ${this.props.name} I will create this folder for you. `); mkdirp(this.props.name); - const pathToProjectDir = this.destinationPath(this.props.name); + var pathToProjectDir = this.destinationPath(this.props.name); this.destinationRoot(pathToProjectDir); } } @@ -54,8 +55,8 @@ function webpackGenerator(prompts, templateDir, copyFiles, copyTemplateFiles, te } install() { - this.npmInstall(['webpack-defaults', 'bluebird'], { 'save-dev': true }).then(() => { - this.spawnCommand('npm', ['run', 'webpack-defaults']); + this.npmInstall(["webpack-defaults", "bluebird"], { "save-dev": true }).then(() => { + this.spawnCommand("npm", ["run", "webpack-defaults"]); }); } }; diff --git a/package-lock.json b/package-lock.json index 4716022286a..4d2fe270d80 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1440,7 +1440,6 @@ "requires": { "anymatch": "1.3.0", "async-each": "1.0.1", - "fsevents": "1.1.2", "glob-parent": "2.0.0", "inherits": "2.0.3", "is-binary-path": "1.0.1", @@ -2639,904 +2638,6 @@ "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" }, - "fsevents": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.1.2.tgz", - "integrity": "sha512-Sn44E5wQW4bTHXvQmvSHwqbuiXtduD6Rrjm2ZtUEGbyrig+nUH3t/QD4M4/ZXViY556TBpRgZkHLDx3JxPwxiw==", - "optional": true, - "requires": { - "nan": "2.6.2", - "node-pre-gyp": "0.6.36" - }, - "dependencies": { - "abbrev": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.0.tgz", - "integrity": "sha1-0FVMIlZjbi9W58LlrRg/hZQo2B8=", - "optional": true - }, - "ajv": { - "version": "4.11.8", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-4.11.8.tgz", - "integrity": "sha1-gv+wKynmYq5TvcIK8VlHcGc5xTY=", - "optional": true, - "requires": { - "co": "4.6.0", - "json-stable-stringify": "1.0.1" - } - }, - "ansi-regex": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", - "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=" - }, - "aproba": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/aproba/-/aproba-1.1.1.tgz", - "integrity": "sha1-ldNgDwdxCqDpKYxyatXs8urLq6s=", - "optional": true - }, - "are-we-there-yet": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.4.tgz", - "integrity": "sha1-u13KOCu5TwXhUZQ3PRb9O6HKEQ0=", - "optional": true, - "requires": { - "delegates": "1.0.0", - "readable-stream": "2.2.9" - } - }, - "asn1": { - "version": "0.2.3", - "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.3.tgz", - "integrity": "sha1-2sh4dxPJlmhJ/IGAd36+nB3fO4Y=", - "optional": true - }, - "assert-plus": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-0.2.0.tgz", - "integrity": "sha1-104bh+ev/A24qttwIfP+SBAasjQ=", - "optional": true - }, - "asynckit": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=", - "optional": true - }, - "aws-sign2": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.6.0.tgz", - "integrity": "sha1-FDQt0428yU0OW4fXY81jYSwOeU8=", - "optional": true - }, - "aws4": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.6.0.tgz", - "integrity": "sha1-g+9cqGCysy5KDe7e6MdxudtXRx4=", - "optional": true - }, - "balanced-match": { - "version": "0.4.2", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-0.4.2.tgz", - "integrity": "sha1-yz8+PHMtwPAe5wtAPzAuYddwmDg=" - }, - "bcrypt-pbkdf": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.1.tgz", - "integrity": "sha1-Y7xdy2EzG5K8Bf1SiVPDNGKgb40=", - "optional": true, - "requires": { - "tweetnacl": "0.14.5" - } - }, - "block-stream": { - "version": "0.0.9", - "resolved": "https://registry.npmjs.org/block-stream/-/block-stream-0.0.9.tgz", - "integrity": "sha1-E+v+d4oDIFz+A3UUgeu0szAMEmo=", - "requires": { - "inherits": "2.0.3" - } - }, - "boom": { - "version": "2.10.1", - "resolved": "https://registry.npmjs.org/boom/-/boom-2.10.1.tgz", - "integrity": "sha1-OciRjO/1eZ+D+UkqhI9iWt0Mdm8=", - "requires": { - "hoek": "2.16.3" - } - }, - "brace-expansion": { - "version": "1.1.7", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.7.tgz", - "integrity": "sha1-Pv/DxQ4ABTH7cg6v+A8K6O8jz1k=", - "requires": { - "balanced-match": "0.4.2", - "concat-map": "0.0.1" - } - }, - "buffer-shims": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/buffer-shims/-/buffer-shims-1.0.0.tgz", - "integrity": "sha1-mXjOMXOIxkmth5MCjDR37wRKi1E=" - }, - "caseless": { - "version": "0.12.0", - "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", - "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=", - "optional": true - }, - "co": { - "version": "4.6.0", - "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", - "integrity": "sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=", - "optional": true - }, - "code-point-at": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", - "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=" - }, - "combined-stream": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.5.tgz", - "integrity": "sha1-k4NwpXtKUd6ix3wV1cX9+JUWQAk=", - "requires": { - "delayed-stream": "1.0.0" - } - }, - "concat-map": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" - }, - "console-control-strings": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", - "integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=" - }, - "core-util-is": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", - "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" - }, - "cryptiles": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/cryptiles/-/cryptiles-2.0.5.tgz", - "integrity": "sha1-O9/s3GCBR8HGcgL6KR59ylnqo7g=", - "optional": true, - "requires": { - "boom": "2.10.1" - } - }, - "dashdash": { - "version": "1.14.1", - "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", - "integrity": "sha1-hTz6D3y+L+1d4gMmuN1YEDX24vA=", - "optional": true, - "requires": { - "assert-plus": "1.0.0" - }, - "dependencies": { - "assert-plus": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", - "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=", - "optional": true - } - } - }, - "debug": { - "version": "2.6.8", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.8.tgz", - "integrity": "sha1-5zFTHKLt4n0YgiJCfaF4IdaP9Pw=", - "optional": true, - "requires": { - "ms": "2.0.0" - } - }, - "deep-extend": { - "version": "0.4.2", - "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.4.2.tgz", - "integrity": "sha1-SLaZwn4zS/ifEIkr5DL25MfTSn8=", - "optional": true - }, - "delayed-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" - }, - "delegates": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", - "integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o=", - "optional": true - }, - "ecc-jsbn": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.1.tgz", - "integrity": "sha1-D8c6ntXw1Tw4GTOYUj735UN3dQU=", - "optional": true, - "requires": { - "jsbn": "0.1.1" - } - }, - "extend": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.1.tgz", - "integrity": "sha1-p1Xqe8Gt/MWjHOfnYtuq3F5jZEQ=", - "optional": true - }, - "extsprintf": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.0.2.tgz", - "integrity": "sha1-4QgOBljjALBilJkMxw4VAiNf1VA=" - }, - "forever-agent": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", - "integrity": "sha1-+8cfDEGt6zf5bFd60e1C2P2sypE=", - "optional": true - }, - "form-data": { - "version": "2.1.4", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.1.4.tgz", - "integrity": "sha1-M8GDrPGTJ27KqYFDpp6Uv+4XUNE=", - "optional": true, - "requires": { - "asynckit": "0.4.0", - "combined-stream": "1.0.5", - "mime-types": "2.1.15" - } - }, - "fs.realpath": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" - }, - "fstream": { - "version": "1.0.11", - "resolved": "https://registry.npmjs.org/fstream/-/fstream-1.0.11.tgz", - "integrity": "sha1-XB+x8RdHcRTwYyoOtLcbPLD9MXE=", - "requires": { - "graceful-fs": "4.1.11", - "inherits": "2.0.3", - "mkdirp": "0.5.1", - "rimraf": "2.6.1" - } - }, - "fstream-ignore": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/fstream-ignore/-/fstream-ignore-1.0.5.tgz", - "integrity": "sha1-nDHa40dnAY/h0kmyTa2mfQktoQU=", - "optional": true, - "requires": { - "fstream": "1.0.11", - "inherits": "2.0.3", - "minimatch": "3.0.4" - } - }, - "gauge": { - "version": "2.7.4", - "resolved": "https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz", - "integrity": "sha1-LANAXHU4w51+s3sxcCLjJfsBi/c=", - "optional": true, - "requires": { - "aproba": "1.1.1", - "console-control-strings": "1.1.0", - "has-unicode": "2.0.1", - "object-assign": "4.1.1", - "signal-exit": "3.0.2", - "string-width": "1.0.2", - "strip-ansi": "3.0.1", - "wide-align": "1.1.2" - } - }, - "getpass": { - "version": "0.1.7", - "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", - "integrity": "sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo=", - "optional": true, - "requires": { - "assert-plus": "1.0.0" - }, - "dependencies": { - "assert-plus": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", - "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=", - "optional": true - } - } - }, - "glob": { - "version": "7.1.2", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", - "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", - "requires": { - "fs.realpath": "1.0.0", - "inflight": "1.0.6", - "inherits": "2.0.3", - "minimatch": "3.0.4", - "once": "1.4.0", - "path-is-absolute": "1.0.1" - } - }, - "graceful-fs": { - "version": "4.1.11", - "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz", - "integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=" - }, - "har-schema": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-1.0.5.tgz", - "integrity": "sha1-0mMTX0MwfALGAq/I/pWXDAFRNp4=", - "optional": true - }, - "har-validator": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/har-validator/-/har-validator-4.2.1.tgz", - "integrity": "sha1-M0gdDxu/9gDdID11gSpqX7oALio=", - "optional": true, - "requires": { - "ajv": "4.11.8", - "har-schema": "1.0.5" - } - }, - "has-unicode": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", - "integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=", - "optional": true - }, - "hawk": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/hawk/-/hawk-3.1.3.tgz", - "integrity": "sha1-B4REvXwWQLD+VA0sm3PVlnjo4cQ=", - "optional": true, - "requires": { - "boom": "2.10.1", - "cryptiles": "2.0.5", - "hoek": "2.16.3", - "sntp": "1.0.9" - } - }, - "hoek": { - "version": "2.16.3", - "resolved": "https://registry.npmjs.org/hoek/-/hoek-2.16.3.tgz", - "integrity": "sha1-ILt0A9POo5jpHcRxCo/xuCdKJe0=" - }, - "http-signature": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.1.1.tgz", - "integrity": "sha1-33LiZwZs0Kxn+3at+OE0qPvPkb8=", - "optional": true, - "requires": { - "assert-plus": "0.2.0", - "jsprim": "1.4.0", - "sshpk": "1.13.0" - } - }, - "inflight": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "requires": { - "once": "1.4.0", - "wrappy": "1.0.2" - } - }, - "inherits": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" - }, - "ini": { - "version": "1.3.4", - "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.4.tgz", - "integrity": "sha1-BTfLedr1m1mhpRff9wbIbsA5Fi4=", - "optional": true - }, - "is-fullwidth-code-point": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", - "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", - "requires": { - "number-is-nan": "1.0.1" - } - }, - "is-typedarray": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", - "integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=", - "optional": true - }, - "isarray": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", - "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" - }, - "isstream": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", - "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=", - "optional": true - }, - "jodid25519": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/jodid25519/-/jodid25519-1.0.2.tgz", - "integrity": "sha1-BtSRIlUJNBlHfUJWM2BuDpB4KWc=", - "optional": true, - "requires": { - "jsbn": "0.1.1" - } - }, - "jsbn": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", - "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=", - "optional": true - }, - "json-schema": { - "version": "0.2.3", - "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz", - "integrity": "sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM=", - "optional": true - }, - "json-stable-stringify": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/json-stable-stringify/-/json-stable-stringify-1.0.1.tgz", - "integrity": "sha1-mnWdOcXy/1A/1TAGRu1EX4jE+a8=", - "optional": true, - "requires": { - "jsonify": "0.0.0" - } - }, - "json-stringify-safe": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", - "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=", - "optional": true - }, - "jsonify": { - "version": "0.0.0", - "resolved": "https://registry.npmjs.org/jsonify/-/jsonify-0.0.0.tgz", - "integrity": "sha1-LHS27kHZPKUbe1qu6PUDYx0lKnM=", - "optional": true - }, - "jsprim": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.0.tgz", - "integrity": "sha1-o7h+QCmNjDgFUtjMdiigu5WiKRg=", - "optional": true, - "requires": { - "assert-plus": "1.0.0", - "extsprintf": "1.0.2", - "json-schema": "0.2.3", - "verror": "1.3.6" - }, - "dependencies": { - "assert-plus": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", - "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=", - "optional": true - } - } - }, - "mime-db": { - "version": "1.27.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.27.0.tgz", - "integrity": "sha1-gg9XIpa70g7CXtVeW13oaeVDbrE=" - }, - "mime-types": { - "version": "2.1.15", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.15.tgz", - "integrity": "sha1-pOv1BkCUVpI3uM9wBGd20J/JKu0=", - "requires": { - "mime-db": "1.27.0" - } - }, - "minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "requires": { - "brace-expansion": "1.1.7" - } - }, - "minimist": { - "version": "0.0.8", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" - }, - "mkdirp": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", - "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", - "requires": { - "minimist": "0.0.8" - } - }, - "ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", - "optional": true - }, - "node-pre-gyp": { - "version": "0.6.36", - "resolved": "https://registry.npmjs.org/node-pre-gyp/-/node-pre-gyp-0.6.36.tgz", - "integrity": "sha1-22BBEst04NR3VU6bUFsXq936t4Y=", - "optional": true, - "requires": { - "mkdirp": "0.5.1", - "nopt": "4.0.1", - "npmlog": "4.1.0", - "rc": "1.2.1", - "request": "2.81.0", - "rimraf": "2.6.1", - "semver": "5.3.0", - "tar": "2.2.1", - "tar-pack": "3.4.0" - } - }, - "nopt": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/nopt/-/nopt-4.0.1.tgz", - "integrity": "sha1-0NRoWv1UFRk8jHUFYC0NF81kR00=", - "optional": true, - "requires": { - "abbrev": "1.1.0", - "osenv": "0.1.4" - } - }, - "npmlog": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-4.1.0.tgz", - "integrity": "sha512-ocolIkZYZt8UveuiDS0yAkkIjid1o7lPG8cYm05yNYzBn8ykQtaiPMEGp8fY9tKdDgm8okpdKzkvu1y9hUYugA==", - "optional": true, - "requires": { - "are-we-there-yet": "1.1.4", - "console-control-strings": "1.1.0", - "gauge": "2.7.4", - "set-blocking": "2.0.0" - } - }, - "number-is-nan": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", - "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=" - }, - "oauth-sign": { - "version": "0.8.2", - "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.8.2.tgz", - "integrity": "sha1-Rqarfwrq2N6unsBWV4C31O/rnUM=", - "optional": true - }, - "object-assign": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", - "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", - "optional": true - }, - "once": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "requires": { - "wrappy": "1.0.2" - } - }, - "os-homedir": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz", - "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=", - "optional": true - }, - "os-tmpdir": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", - "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=", - "optional": true - }, - "osenv": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/osenv/-/osenv-0.1.4.tgz", - "integrity": "sha1-Qv5tWVPfBsgGS+bxdsPQWqqjRkQ=", - "optional": true, - "requires": { - "os-homedir": "1.0.2", - "os-tmpdir": "1.0.2" - } - }, - "path-is-absolute": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" - }, - "performance-now": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-0.2.0.tgz", - "integrity": "sha1-M+8wxcd9TqIcWlOGnZG1bY8lVeU=", - "optional": true - }, - "process-nextick-args": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz", - "integrity": "sha1-FQ4gt1ZZCtP5EJPyWk8q2L/zC6M=" - }, - "punycode": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz", - "integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4=", - "optional": true - }, - "qs": { - "version": "6.4.0", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.4.0.tgz", - "integrity": "sha1-E+JtKK1rD/qpExLNO/cI7TUecjM=", - "optional": true - }, - "rc": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/rc/-/rc-1.2.1.tgz", - "integrity": "sha1-LgPo5C7kULjLPc5lvhv4l04d/ZU=", - "optional": true, - "requires": { - "deep-extend": "0.4.2", - "ini": "1.3.4", - "minimist": "1.2.0", - "strip-json-comments": "2.0.1" - }, - "dependencies": { - "minimist": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", - "optional": true - } - } - }, - "readable-stream": { - "version": "2.2.9", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.2.9.tgz", - "integrity": "sha1-z3jsb0ptHrQ9JkiMrJfwQudLf8g=", - "requires": { - "buffer-shims": "1.0.0", - "core-util-is": "1.0.2", - "inherits": "2.0.3", - "isarray": "1.0.0", - "process-nextick-args": "1.0.7", - "string_decoder": "1.0.1", - "util-deprecate": "1.0.2" - } - }, - "request": { - "version": "2.81.0", - "resolved": "https://registry.npmjs.org/request/-/request-2.81.0.tgz", - "integrity": "sha1-xpKJRqDgbF+Nb4qTM0af/aRimKA=", - "optional": true, - "requires": { - "aws-sign2": "0.6.0", - "aws4": "1.6.0", - "caseless": "0.12.0", - "combined-stream": "1.0.5", - "extend": "3.0.1", - "forever-agent": "0.6.1", - "form-data": "2.1.4", - "har-validator": "4.2.1", - "hawk": "3.1.3", - "http-signature": "1.1.1", - "is-typedarray": "1.0.0", - "isstream": "0.1.2", - "json-stringify-safe": "5.0.1", - "mime-types": "2.1.15", - "oauth-sign": "0.8.2", - "performance-now": "0.2.0", - "qs": "6.4.0", - "safe-buffer": "5.0.1", - "stringstream": "0.0.5", - "tough-cookie": "2.3.2", - "tunnel-agent": "0.6.0", - "uuid": "3.0.1" - } - }, - "rimraf": { - "version": "2.6.1", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.1.tgz", - "integrity": "sha1-wjOOxkPfeht/5cVPqG9XQopV8z0=", - "requires": { - "glob": "7.1.2" - } - }, - "safe-buffer": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.0.1.tgz", - "integrity": "sha1-0mPKVGls2KMGtcplUekt5XkY++c=" - }, - "semver": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.3.0.tgz", - "integrity": "sha1-myzl094C0XxgEq0yaqa00M9U+U8=", - "optional": true - }, - "set-blocking": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", - "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=", - "optional": true - }, - "signal-exit": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", - "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=", - "optional": true - }, - "sntp": { - "version": "1.0.9", - "resolved": "https://registry.npmjs.org/sntp/-/sntp-1.0.9.tgz", - "integrity": "sha1-ZUEYTMkK7qbG57NeJlkIJEPGYZg=", - "optional": true, - "requires": { - "hoek": "2.16.3" - } - }, - "sshpk": { - "version": "1.13.0", - "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.13.0.tgz", - "integrity": "sha1-/yo+T9BEl1Vf7Zezmg/YL6+zozw=", - "optional": true, - "requires": { - "asn1": "0.2.3", - "assert-plus": "1.0.0", - "bcrypt-pbkdf": "1.0.1", - "dashdash": "1.14.1", - "ecc-jsbn": "0.1.1", - "getpass": "0.1.7", - "jodid25519": "1.0.2", - "jsbn": "0.1.1", - "tweetnacl": "0.14.5" - }, - "dependencies": { - "assert-plus": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", - "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=", - "optional": true - } - } - }, - "string-width": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", - "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", - "requires": { - "code-point-at": "1.1.0", - "is-fullwidth-code-point": "1.0.0", - "strip-ansi": "3.0.1" - } - }, - "string_decoder": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.1.tgz", - "integrity": "sha1-YuIA8DmVWmgQ2N8KM//A8BNmLZg=", - "requires": { - "safe-buffer": "5.0.1" - } - }, - "stringstream": { - "version": "0.0.5", - "resolved": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.5.tgz", - "integrity": "sha1-TkhM1N5aC7vuGORjB3EKioFiGHg=", - "optional": true - }, - "strip-ansi": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", - "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", - "requires": { - "ansi-regex": "2.1.1" - } - }, - "strip-json-comments": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", - "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=", - "optional": true - }, - "tar": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/tar/-/tar-2.2.1.tgz", - "integrity": "sha1-jk0qJWwOIYXGsYrWlK7JaLg8sdE=", - "requires": { - "block-stream": "0.0.9", - "fstream": "1.0.11", - "inherits": "2.0.3" - } - }, - "tar-pack": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/tar-pack/-/tar-pack-3.4.0.tgz", - "integrity": "sha1-I74tf2cagzk3bL2wuP4/3r8xeYQ=", - "optional": true, - "requires": { - "debug": "2.6.8", - "fstream": "1.0.11", - "fstream-ignore": "1.0.5", - "once": "1.4.0", - "readable-stream": "2.2.9", - "rimraf": "2.6.1", - "tar": "2.2.1", - "uid-number": "0.0.6" - } - }, - "tough-cookie": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.3.2.tgz", - "integrity": "sha1-8IH3bkyFcg5sN6X6ztc3FQ2EByo=", - "optional": true, - "requires": { - "punycode": "1.4.1" - } - }, - "tunnel-agent": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", - "integrity": "sha1-J6XeoGs2sEoKmWZ3SykIaPD8QP0=", - "optional": true, - "requires": { - "safe-buffer": "5.0.1" - } - }, - "tweetnacl": { - "version": "0.14.5", - "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", - "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=", - "optional": true - }, - "uid-number": { - "version": "0.0.6", - "resolved": "https://registry.npmjs.org/uid-number/-/uid-number-0.0.6.tgz", - "integrity": "sha1-DqEOgDXo61uOREnwbaHHMGY7qoE=", - "optional": true - }, - "util-deprecate": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" - }, - "uuid": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.0.1.tgz", - "integrity": "sha1-ZUS7ot/ajBzxfmKaOjBeK7H+5sE=", - "optional": true - }, - "verror": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/verror/-/verror-1.3.6.tgz", - "integrity": "sha1-z/XfEpRtKX0rqu+qJoniW+AcAFw=", - "optional": true, - "requires": { - "extsprintf": "1.0.2" - } - }, - "wide-align": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.2.tgz", - "integrity": "sha512-ijDLlyQ7s6x1JgCLur53osjm/UXUYD9+0PbYKrBsYisYXzCxN+HC3mYDNy/dWdmf3AwqwU3CXwDCvsNgGK1S0w==", - "optional": true, - "requires": { - "string-width": "1.0.2" - } - }, - "wrappy": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" - } - } - }, "functional-red-black-tree": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz", @@ -5845,12 +4946,6 @@ "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.7.tgz", "integrity": "sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s=" }, - "nan": { - "version": "2.6.2", - "resolved": "https://registry.npmjs.org/nan/-/nan-2.6.2.tgz", - "integrity": "sha1-5P805slf37WuzAjeZZb0NgWn20U=", - "optional": true - }, "natural-compare": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", From 41e2c9ea7d79969aa662884b77de9dd7aac2ca0c Mon Sep 17 00:00:00 2001 From: Ian J Sikes Date: Fri, 29 Sep 2017 14:42:45 -0700 Subject: [PATCH 22/22] Remove //eslint-disable lines from template files --- .../templates/examples/simple/src/index.js.tpl | 4 ++-- lib/generate-loader/templates/test/functional.test.js.tpl | 2 +- lib/generate-loader/templates/test/test-utils.js.tpl | 2 +- .../templates/examples/simple/src/index.js.tpl | 4 ++-- lib/generate-plugin/templates/test/test-utils.js.tpl | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/generate-loader/templates/examples/simple/src/index.js.tpl b/lib/generate-loader/templates/examples/simple/src/index.js.tpl index ed75d67d081..2c49d366408 100644 --- a/lib/generate-loader/templates/examples/simple/src/index.js.tpl +++ b/lib/generate-loader/templates/examples/simple/src/index.js.tpl @@ -4,8 +4,8 @@ const getLazyModule = () => System.import('./lazy-module'); setTimeout(() => { getLazyModule.then((modDefault) => { - console.log(modDefault); //eslint-disable-line + console.log(modDefault); }); }, 300); -console.log(esmModule); //eslint-disable-line +console.log(esmModule); diff --git a/lib/generate-loader/templates/test/functional.test.js.tpl b/lib/generate-loader/templates/test/functional.test.js.tpl index ac6645a0d66..b69f8d7f17a 100644 --- a/lib/generate-loader/templates/test/functional.test.js.tpl +++ b/lib/generate-loader/templates/test/functional.test.js.tpl @@ -13,7 +13,7 @@ test('should append transformations to JavaScript module', async () => { const buildStats = await runWebpackExampleInMemory('simple'); const { modules } = buildStats; - const moduleToTest = modules[0].source()._source._value; //eslint-disable-line + const moduleToTest = modules[0].source()._source._value; const loadedString = '* Original Source From Loader'; expect(moduleToTest).toEqual(expect.stringContaining(loadedString)); diff --git a/lib/generate-loader/templates/test/test-utils.js.tpl b/lib/generate-loader/templates/test/test-utils.js.tpl index 0cd61e6700c..bf8116f065f 100644 --- a/lib/generate-loader/templates/test/test-utils.js.tpl +++ b/lib/generate-loader/templates/test/test-utils.js.tpl @@ -44,7 +44,7 @@ function getLoader(withOptions) { * @returns {Object|Array} - Returns an object or array of objects representing the webpack configuration options */ function getExampleConfig(exampleName) { - return require(`../examples/${exampleName}/webpack.config.js`); //eslint-disable-line + return require(`../examples/${exampleName}/webpack.config.js`); } /** diff --git a/lib/generate-plugin/templates/examples/simple/src/index.js.tpl b/lib/generate-plugin/templates/examples/simple/src/index.js.tpl index ed75d67d081..2c49d366408 100644 --- a/lib/generate-plugin/templates/examples/simple/src/index.js.tpl +++ b/lib/generate-plugin/templates/examples/simple/src/index.js.tpl @@ -4,8 +4,8 @@ const getLazyModule = () => System.import('./lazy-module'); setTimeout(() => { getLazyModule.then((modDefault) => { - console.log(modDefault); //eslint-disable-line + console.log(modDefault); }); }, 300); -console.log(esmModule); //eslint-disable-line +console.log(esmModule); diff --git a/lib/generate-plugin/templates/test/test-utils.js.tpl b/lib/generate-plugin/templates/test/test-utils.js.tpl index 0cd61e6700c..bf8116f065f 100644 --- a/lib/generate-plugin/templates/test/test-utils.js.tpl +++ b/lib/generate-plugin/templates/test/test-utils.js.tpl @@ -44,7 +44,7 @@ function getLoader(withOptions) { * @returns {Object|Array} - Returns an object or array of objects representing the webpack configuration options */ function getExampleConfig(exampleName) { - return require(`../examples/${exampleName}/webpack.config.js`); //eslint-disable-line + return require(`../examples/${exampleName}/webpack.config.js`); } /**