diff --git a/lib/commands/init.js b/lib/commands/init.js index 284d38fe822..b355434a155 100644 --- a/lib/commands/init.js +++ b/lib/commands/init.js @@ -9,9 +9,9 @@ const modifyHelper = require("../utils/modify-config-helper"); * First function to be called after running the init flag. This is a check, * if we are running the init command with no arguments or if we got dependencies * - * @param {Array} args - array of arguments such as + * @param {Array} args - array of arguments such as * packages included when running the init command - * @returns {Function} creator/npmPackagesExists - returns an installation of the package, + * @returns {Function} creator/npmPackagesExists - returns an installation of the package, * followed up with a yeoman instance of that if there's packages. If not, it creates a defaultGenerator */ diff --git a/lib/generators/utils/entry.js b/lib/generators/utils/entry.js index 3bb64cccfd9..54f14a8af17 100644 --- a/lib/generators/utils/entry.js +++ b/lib/generators/utils/entry.js @@ -7,9 +7,9 @@ const validate = require("./validate"); * * Prompts for entry points, either if it has multiple or one entry * - * @param {Object} self - A variable holding the instance of the prompting - * @param {Object} answer - Previous answer from asking if the user wants single or multiple entries - * @returns {Object} An Object that holds the answers given by the user, later used to scaffold + * @param {Object} self - A variable holding the instance of the prompting + * @param {Object} answer - Previous answer from asking if the user wants single or multiple entries + * @returns {Object} An Object that holds the answers given by the user, later used to scaffold */ module.exports = (self, answer) => { @@ -28,7 +28,7 @@ module.exports = (self, answer) => { let webpackEntryPoint = {}; entryIdentifiers = multipleEntriesAnswer["multipleEntries"].split(","); function forEachPromise(obj, fn) { - return obj.reduce(function(promise, prop) { + return obj.reduce((promise, prop) => { const trimmedProp = prop.trim(); return promise.then(n => { if (n) { @@ -40,7 +40,7 @@ module.exports = (self, answer) => { !n[val].includes("path") && !n[val].includes("process") ) { - n[val] = `"'${n[val]}.js'"`; + n[val] = `\'${n[val].replace(/"|'/g,"").concat(".js")}\'`; } webpackEntryPoint[val] = n[val]; }); @@ -59,18 +59,18 @@ module.exports = (self, answer) => { validate ) ]) - ).then(propAns => { - Object.keys(propAns).forEach(val => { + ).then(entryPropAnswer => { + Object.keys(entryPropAnswer).forEach(val => { if ( - propAns[val].charAt(0) !== "(" && - propAns[val].charAt(0) !== "[" && - !propAns[val].includes("function") && - !propAns[val].includes("path") && - !propAns[val].includes("process") + entryPropAnswer[val].charAt(0) !== "(" && + entryPropAnswer[val].charAt(0) !== "[" && + !entryPropAnswer[val].includes("function") && + !entryPropAnswer[val].includes("path") && + !entryPropAnswer[val].includes("process") ) { - propAns[val] = `"'${propAns[val]}.js'"`; + entryPropAnswer[val] = `\'${entryPropAnswer[val].replace(/"|'/g,"").concat(".js")}\'`; } - webpackEntryPoint[val] = propAns[val]; + webpackEntryPoint[val] = entryPropAnswer[val]; }); return webpackEntryPoint; }); @@ -83,7 +83,11 @@ module.exports = (self, answer) => { "Which module will be the first to enter the application? [default: ./src/index]" ) ]) - .then(singularAnswer => `"${singularAnswer["singularEntry"]}"`); + .then(singularEntryAnswer => { + let { singularEntry } = singularEntryAnswer; + if (singularEntry.indexOf("\"") >= 0) singularEntry = singularEntry.replace(/"/g, "'"); + return singularEntry; + }); } return result; }; diff --git a/lib/init/index.js b/lib/init/index.js index 89aa16fab9c..791ebea02e0 100644 --- a/lib/init/index.js +++ b/lib/init/index.js @@ -72,8 +72,8 @@ const transformsObject = { * Maps back transforms that needs to be run using the configuration * provided. * - * @param {Object} transformObject - An Object with all transformations - * @param {Object} config - Configuration to transform + * @param {Object} transformObject - An Object with all transformations + * @param {Object} config - Configuration to transform * @returns {Object} - An Object with the transformations to be run */ @@ -104,8 +104,8 @@ function mapOptionsToTransform(transformObject, config) { * * Runs the transformations from an object we get from yeoman * - * @param {Object} webpackProperties - Configuration to transform - * @param {String} action - Action to be done on the given ast + * @param {Object} webpackProperties - Configuration to transform + * @param {String} action - Action to be done on the given ast * @returns {Promise} - A promise that writes each transform, runs prettier * and writes the file */ diff --git a/lib/init/transformations/entry/__snapshots__/entry.test.js.snap b/lib/init/transformations/entry/__snapshots__/entry.test.js.snap index 8d92d0c9f61..0b26cdf44f3 100644 --- a/lib/init/transformations/entry/__snapshots__/entry.test.js.snap +++ b/lib/init/transformations/entry/__snapshots__/entry.test.js.snap @@ -9,12 +9,19 @@ exports[`entry transforms correctly using "entry-0" data 1`] = ` exports[`entry transforms correctly using "entry-0" data 2`] = ` "module.exports = { - entry: ['index.js', 'app.js'] + entry: \\"index.js\\" } " `; exports[`entry transforms correctly using "entry-0" data 3`] = ` +"module.exports = { + entry: ['index.js', 'app.js'] +} +" +`; + +exports[`entry transforms correctly using "entry-0" data 4`] = ` "module.exports = { entry: { index: 'index.js', @@ -24,7 +31,7 @@ exports[`entry transforms correctly using "entry-0" data 3`] = ` " `; -exports[`entry transforms correctly using "entry-0" data 4`] = ` +exports[`entry transforms correctly using "entry-0" data 5`] = ` "module.exports = { entry: { something, @@ -35,42 +42,42 @@ exports[`entry transforms correctly using "entry-0" data 4`] = ` " `; -exports[`entry transforms correctly using "entry-0" data 5`] = ` +exports[`entry transforms correctly using "entry-0" data 6`] = ` "module.exports = { entry: () => 'index.js' } " `; -exports[`entry transforms correctly using "entry-0" data 6`] = ` +exports[`entry transforms correctly using "entry-0" data 7`] = ` "module.exports = { entry: () => new Promise((resolve) => resolve(['./app', './router'])) } " `; -exports[`entry transforms correctly using "entry-0" data 7`] = ` +exports[`entry transforms correctly using "entry-0" data 8`] = ` "module.exports = { entry: entryStringVariable } " `; -exports[`entry transforms correctly using "entry-0" data 8`] = ` +exports[`entry transforms correctly using "entry-0" data 9`] = ` "module.exports = { entry: 'index.js' } " `; -exports[`entry transforms correctly using "entry-0" data 9`] = ` +exports[`entry transforms correctly using "entry-0" data 10`] = ` "module.exports = { entry: ['index.js', 'app.js'] } " `; -exports[`entry transforms correctly using "entry-0" data 10`] = ` +exports[`entry transforms correctly using "entry-0" data 11`] = ` "module.exports = { entry: { something, @@ -81,14 +88,14 @@ exports[`entry transforms correctly using "entry-0" data 10`] = ` " `; -exports[`entry transforms correctly using "entry-0" data 11`] = ` +exports[`entry transforms correctly using "entry-0" data 12`] = ` "module.exports = { entry: () => new Promise((resolve) => resolve(['./app', './router'])) } " `; -exports[`entry transforms correctly using "entry-0" data 12`] = ` +exports[`entry transforms correctly using "entry-0" data 13`] = ` "module.exports = { entry: entryStringVariable } diff --git a/lib/init/transformations/entry/entry.js b/lib/init/transformations/entry/entry.js index 184229179e9..2878ff5cdc5 100644 --- a/lib/init/transformations/entry/entry.js +++ b/lib/init/transformations/entry/entry.js @@ -7,11 +7,11 @@ const utils = require("../../../utils/ast-utils"); * Transform for entry. Finds the entry property from yeoman and creates a * property based on what the user has given us. * - * @param j — jscodeshift API - * @param ast - jscodeshift API - * @param {any} webpackProperties - transformation object to scaffold - * @param {String} action - action that indicates what to be done to the AST - * @returns ast - jscodeshift API + * @param j - jscodeshift API + * @param ast - jscodeshift API + * @param {any} webpackProperties - transformation object to scaffold + * @param {String} action - action that indicates what to be done to the AST + * @returns ast - jscodeshift API */ module.exports = function entryTransform(j, ast, webpackProperties, action) { diff --git a/lib/init/transformations/entry/entry.test.js b/lib/init/transformations/entry/entry.test.js index 406c8830ea3..4b2b2c41ca5 100644 --- a/lib/init/transformations/entry/entry.test.js +++ b/lib/init/transformations/entry/entry.test.js @@ -3,6 +3,7 @@ const defineTest = require("../../../utils/defineTest"); defineTest(__dirname, "entry", "entry-0", "'index.js'", "init"); +defineTest(__dirname, "entry", "entry-0", "\"index.js\"", "init"); defineTest(__dirname, "entry", "entry-0", ["'index.js'", "'app.js'"], "init"); defineTest( __dirname, diff --git a/lib/utils/prop-types.js b/lib/utils/prop-types.js index 7d3bff7c0a3..ae5ab1daf97 100644 --- a/lib/utils/prop-types.js +++ b/lib/utils/prop-types.js @@ -6,30 +6,30 @@ */ module.exports = new Set([ + "amd", + "bail", + "cache", "context", "devServer", "devtool", "entry", "externals", + "merge", + "mode", "module", "node", "output", + "parallelism", "performance", "plugins", - "resolve", - "target", - "watch", - "watchOptions", - "stats", - "mode", - "amd", - "bail", - "cache", "profile", - "merge", - "parallelism", "recordsInputPath", "recordsOutputPath", "recordsPath", - "resolveLoader" + "resolve", + "resolveLoader", + "stats", + "target", + "watch", + "watchOptions", ]);