webpack-cli
Advanced tools
Comparing version 2.0.10 to 2.0.11
@@ -28,3 +28,4 @@ /** | ||
{ value: "chore", name: "chore: Updating docs, linting, etc" }, | ||
{ value: "fix", name: "bugs, typos, etc" } | ||
] | ||
}; |
@@ -156,7 +156,5 @@ module.exports = function processOptions(yargs, argv) { | ||
const ProgressPlugin = require("webpack").ProgressPlugin; | ||
compiler.apply( | ||
new ProgressPlugin({ | ||
profile: argv.profile | ||
}) | ||
); | ||
new ProgressPlugin({ | ||
profile: argv.profile | ||
}).apply(compiler); | ||
} | ||
@@ -163,0 +161,0 @@ |
@@ -444,7 +444,5 @@ #!/usr/bin/env node | ||
const ProgressPlugin = require("webpack").ProgressPlugin; | ||
compiler.apply( | ||
new ProgressPlugin({ | ||
profile: argv.profile | ||
}) | ||
); | ||
new ProgressPlugin({ | ||
profile: argv.profile | ||
}).apply(compiler); | ||
} | ||
@@ -451,0 +449,0 @@ |
@@ -0,1 +1,34 @@ | ||
<a name="2.0.11"></a> | ||
# 2.0.11 (2018-03-10) | ||
[Full Changelog](https://github.com/webpack/webpack-cli/compare/v2.0.10...v2.0.11) | ||
## Chore | ||
* bundlesize: change threshold ([2aedfda](https://github.com/webpack/webpack-cli/commit/2aedfda)) | ||
* deps: upgrade deps ([#319](https://github.com/webpack/webpack-cli/pull/319)) | ||
* docs: update docs ([3307e3b](https://github.com/webpack/webpack-cli/commit/3307e3b)) | ||
* es6: changed 'var' into 'const' where convenient ([#325](https://github.com/webpack/webpack-cli/pull/325)) | ||
* test: updated tests file names ([#324](https://github.com/webpack/webpack-cli/pull/324)) | ||
## CLI | ||
* init: Refactor Yeoman ([#323](https://github.com/webpack/webpack-cli/pull/323)) | ||
* tapable: Remove Tapable#apply calls ([#305](https://github.com/webpack/webpack-cli/pull/305)) | ||
## Docs | ||
* update README to remove inconsistent CLI messaging (#327) ([#328](https://github.com/webpack/webpack-cli/pull/328)) | ||
## Fix | ||
* migrate: move options to use ([#308](https://github.com/webpack/webpack-cli/pull/308)) | ||
* adding 'fix' to whitelist ([10a00df](https://github.com/webpack/webpack-cli/commit/10a00df)) | ||
## Misc | ||
* deps: clean up dependencies ([7078282](https://github.com/webpack/webpack-cli/commit/7078282)) | ||
* generator: Allow local paths to generators ([#265](https://github.com/webpack/webpack-cli/pull/265)) | ||
* grammar: revise spelling and incorrect syntax ([#293](https://github.com/webpack/webpack-cli/pull/293)) | ||
* readme: add npm badge ([#303](https://github.com/webpack/webpack-cli/pull/303)) | ||
<a name="2.0.10"></a> | ||
@@ -2,0 +35,0 @@ # 2.0.10 (2018-03-02) |
@@ -1,3 +0,3 @@ | ||
var yeoman = require("yeoman-environment"); | ||
var LoaderGenerator = require("../generators/loader-generator").LoaderGenerator; | ||
const yeoman = require("yeoman-environment"); | ||
const { LoaderGenerator } = require("../generators/loader-generator"); | ||
@@ -9,4 +9,4 @@ /** | ||
function loaderCreator() { | ||
var env = yeoman.createEnv(); | ||
var generatorName = "webpack-loader-generator"; | ||
const env = yeoman.createEnv(); | ||
const generatorName = "webpack-loader-generator"; | ||
@@ -13,0 +13,0 @@ env.registerStub(LoaderGenerator, generatorName); |
@@ -1,3 +0,3 @@ | ||
var yeoman = require("yeoman-environment"); | ||
var PluginGenerator = require("../generators/plugin-generator").PluginGenerator; | ||
const yeoman = require("yeoman-environment"); | ||
const PluginGenerator = require("../generators/plugin-generator").PluginGenerator; | ||
@@ -9,4 +9,4 @@ /** | ||
function pluginCreator() { | ||
var env = yeoman.createEnv(); | ||
var generatorName = "webpack-plugin-generator"; | ||
const env = yeoman.createEnv(); | ||
const generatorName = "webpack-plugin-generator"; | ||
@@ -13,0 +13,0 @@ env.registerStub(PluginGenerator, generatorName); |
@@ -343,3 +343,4 @@ "use strict"; | ||
this.configuration.config.topScope.push(tooltip.cssPlugin()); | ||
this.dependencies.push("extract-text-webpack-plugin"); | ||
// TODO: Replace with regular version once v.4 is out | ||
this.dependencies.push("extract-text-webpack-plugin@next"); | ||
@@ -414,2 +415,5 @@ if (cssBundleName.length !== 0) { | ||
} | ||
writing() { | ||
this.config.set("configuration", this.configuration); | ||
} | ||
}; |
@@ -1,4 +0,4 @@ | ||
var path = require("path"); | ||
var _ = require("lodash"); | ||
var webpackGenerator = require("./webpack-generator"); | ||
const path = require("path"); | ||
const _ = require("lodash"); | ||
const webpackGenerator = require("./webpack-generator"); | ||
@@ -28,3 +28,3 @@ /** | ||
*/ | ||
var LoaderGenerator = webpackGenerator( | ||
const LoaderGenerator = webpackGenerator( | ||
[ | ||
@@ -31,0 +31,0 @@ { |
@@ -1,4 +0,4 @@ | ||
var path = require("path"); | ||
var _ = require("lodash"); | ||
var webpackGenerator = require("./webpack-generator"); | ||
const path = require("path"); | ||
const _ = require("lodash"); | ||
const webpackGenerator = require("./webpack-generator"); | ||
@@ -13,3 +13,3 @@ /** | ||
*/ | ||
var PluginGenerator = webpackGenerator( | ||
const PluginGenerator = webpackGenerator( | ||
[ | ||
@@ -16,0 +16,0 @@ { |
"use strict"; | ||
/** | ||
* | ||
* Tooltip object that consits of tooltips for various of | ||
* Tooltip object that consists of tooltips for various of | ||
* features | ||
@@ -6,0 +6,0 @@ * |
@@ -1,5 +0,5 @@ | ||
var path = require("path"); | ||
var mkdirp = require("mkdirp"); | ||
var Generator = require("yeoman-generator"); | ||
var copyUtils = require("../utils/copy-utils"); | ||
const path = require("path"); | ||
const mkdirp = require("mkdirp"); | ||
const Generator = require("yeoman-generator"); | ||
const copyUtils = require("../utils/copy-utils"); | ||
@@ -43,3 +43,3 @@ /** | ||
default() { | ||
var currentDirName = path.basename(this.destinationPath()); | ||
const currentDirName = path.basename(this.destinationPath()); | ||
if (currentDirName !== this.props.name) { | ||
@@ -51,3 +51,3 @@ this.log(` | ||
mkdirp(this.props.name); | ||
var pathToProjectDir = this.destinationPath(this.props.name); | ||
const pathToProjectDir = this.destinationPath(this.props.name); | ||
this.destinationRoot(pathToProjectDir); | ||
@@ -54,0 +54,0 @@ } |
"use strict"; | ||
const yeoman = require("yeoman-environment"); | ||
const Generator = require("yeoman-generator"); | ||
const path = require("path"); | ||
const defaultGenerator = require("../generators/init-generator"); | ||
const runTransform = require("./transformations/index"); | ||
const j = require("jscodeshift"); | ||
const chalk = require("chalk"); | ||
const pEachSeries = require("p-each-series"); | ||
const runPrettier = require("../utils/run-prettier"); | ||
const entryTransform = require("./transformations/entry/entry"); | ||
const outputTransform = require("./transformations/output/output"); | ||
const contextTransform = require("./transformations/context/context"); | ||
const resolveTransform = require("./transformations/resolve/resolve"); | ||
const devtoolTransform = require("./transformations/devtool/devtool"); | ||
const targetTransform = require("./transformations/target/target"); | ||
const watchTransform = require("./transformations/watch/watch"); | ||
const watchOptionsTransform = require("./transformations/watch/watchOptions"); | ||
const externalsTransform = require("./transformations/externals/externals"); | ||
const nodeTransform = require("./transformations/node/node"); | ||
const performanceTransform = require("./transformations/performance/performance"); | ||
const statsTransform = require("./transformations/stats/stats"); | ||
const amdTransform = require("./transformations/other/amd"); | ||
const bailTransform = require("./transformations/other/bail"); | ||
const cacheTransform = require("./transformations/other/cache"); | ||
const profileTransform = require("./transformations/other/profile"); | ||
const mergeTransform = require("./transformations/other/merge"); | ||
const parallelismTransform = require("./transformations/other/parallelism"); | ||
const recordsInputPathTransform = require("./transformations/other/recordsInputPath"); | ||
const recordsOutputPathTransform = require("./transformations/other/recordsOutputPath"); | ||
const recordsPathTransform = require("./transformations/other/recordsPath"); | ||
const moduleTransform = require("./transformations/module/module"); | ||
const pluginsTransform = require("./transformations/plugins/plugins"); | ||
const topScopeTransform = require("./transformations/top-scope/top-scope"); | ||
const devServerTransform = require("./transformations/devServer/devServer"); | ||
const modeTransform = require("./transformations/mode/mode"); | ||
const resolveLoaderTransform = require("./transformations/resolveLoader/resolveLoader"); | ||
const transformsObject = { | ||
entryTransform, | ||
outputTransform, | ||
contextTransform, | ||
resolveTransform, | ||
devtoolTransform, | ||
targetTransform, | ||
watchTransform, | ||
watchOptionsTransform, | ||
externalsTransform, | ||
nodeTransform, | ||
performanceTransform, | ||
statsTransform, | ||
amdTransform, | ||
bailTransform, | ||
cacheTransform, | ||
profileTransform, | ||
moduleTransform, | ||
pluginsTransform, | ||
topScopeTransform, | ||
mergeTransform, | ||
devServerTransform, | ||
modeTransform, | ||
parallelismTransform, | ||
recordsInputPathTransform, | ||
recordsOutputPathTransform, | ||
recordsPathTransform, | ||
resolveLoaderTransform | ||
}; | ||
/** | ||
* | ||
* Runs yeoman and runs the transformations based on the object | ||
* built up from an author/user | ||
* Maps back transforms that needs to be run using the configuration | ||
* provided. | ||
* | ||
* @param {String} options - An path to the given generator | ||
* @returns {Function} runTransform - Run transformations based on the finished | ||
* yeoman instance | ||
* @param {Object} transformObject - An Object with all transformations | ||
* @param {Object} config - Configuration to transform | ||
* @returns {Object} - An Object with the transformations to be run | ||
*/ | ||
function creator(options) { | ||
let env = yeoman.createEnv("webpack", null); | ||
const generatorName = options | ||
? replaceGeneratorName(path.basename(options[0])) | ||
: "webpack-default-generator"; | ||
if (options) { | ||
const WebpackGenerator = class extends Generator { | ||
initializing() { | ||
options.forEach(path => { | ||
return this.composeWith(require.resolve(path)); | ||
}); | ||
function mapOptionsToTransform(transformObject, config) { | ||
return Object.keys(transformObject) | ||
.map(transformKey => { | ||
const stringVal = transformKey.substr( | ||
0, | ||
transformKey.indexOf("Transform") | ||
); | ||
if (Object.keys(config.webpackOptions).length) { | ||
if (config.webpackOptions[stringVal]) { | ||
return [ | ||
transformObject[transformKey], | ||
config.webpackOptions[stringVal] | ||
]; | ||
} else { | ||
return [transformObject[transformKey], config[stringVal]]; | ||
} | ||
} else { | ||
return [transformObject[transformKey]]; | ||
} | ||
}; | ||
env.registerStub(WebpackGenerator, generatorName); | ||
} else { | ||
env.registerStub(defaultGenerator, "webpack-default-generator"); | ||
} | ||
}) | ||
.filter(e => e[1]); | ||
} | ||
env.run(generatorName).on("end", _ => { | ||
if (generatorName !== "webpack-default-generator") { | ||
//HACK / FIXME | ||
env = env.options.env; | ||
return runTransform(env.configuration); | ||
} else { | ||
return runTransform(env.getArgument("configuration")); | ||
} | ||
/** | ||
* | ||
* 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 | ||
* @returns {Promise} - A promise that writes each transform, runs prettier | ||
* and writes the file | ||
*/ | ||
module.exports = function runTransform(webpackProperties, action) { | ||
// webpackOptions.name sent to nameTransform if match | ||
const webpackConfig = Object.keys(webpackProperties).filter(p => { | ||
return p !== "configFile" && p !== "configPath"; | ||
}); | ||
} | ||
const initActionNotDefined = action && action !== "init" ? true : false; | ||
/* | ||
* @function replaceGeneratorName | ||
* | ||
* Replaces the webpack-addons pattern with the end of the addons name merged | ||
* with 'generator' | ||
* | ||
* @param { String } name - name of the generator | ||
* @returns { String } name - replaced pattern of the name | ||
*/ | ||
webpackConfig.forEach(scaffoldPiece => { | ||
const config = webpackProperties[scaffoldPiece]; | ||
const transformations = mapOptionsToTransform(transformsObject, config); | ||
const ast = j( | ||
initActionNotDefined | ||
? webpackProperties.configFile | ||
: "module.exports = {}" | ||
); | ||
const transformAction = action || null; | ||
function replaceGeneratorName(name) { | ||
return name.replace(/(webpack-addons)?([^:]+)(:.*)?/g, "generator$2"); | ||
} | ||
return pEachSeries(transformations, f => { | ||
if (!f[1]) { | ||
return f[0](j, ast, transformAction); | ||
} else { | ||
return f[0](j, ast, f[1], transformAction); | ||
} | ||
}) | ||
.then(_ => { | ||
let configurationName; | ||
if (!config.configName) { | ||
configurationName = "webpack.config.js"; | ||
} else { | ||
configurationName = "webpack." + config.configName + ".js"; | ||
} | ||
module.exports = { | ||
creator, | ||
replaceGeneratorName | ||
const outputPath = initActionNotDefined | ||
? webpackProperties.configPath | ||
: path.join(process.cwd(), configurationName); | ||
const source = ast.toSource({ | ||
quote: "single" | ||
}); | ||
runPrettier(outputPath, source); | ||
}) | ||
.catch(err => { | ||
console.error(err.message ? err.message : err); | ||
}); | ||
}); | ||
if (initActionNotDefined && webpackProperties.config.item) { | ||
process.stdout.write( | ||
"\n" + | ||
chalk.green( | ||
`Congratulations! ${ | ||
webpackProperties.config.item | ||
} has been ${action}ed!\n` | ||
) | ||
); | ||
} else { | ||
process.stdout.write( | ||
"\n" + | ||
chalk.green( | ||
"Congratulations! Your new webpack configuration file has been created!\n" | ||
) | ||
); | ||
} | ||
}; |
@@ -51,3 +51,3 @@ const jscodeshift = require("jscodeshift"); | ||
* @param {Function[]} [transforms] - List of transformation functions, defined in the | ||
* order to apply them in. By default, all defined transfomations. | ||
* order to apply them in. By default, all defined transformations. | ||
* @param {Object} [options] - recast formatting options | ||
@@ -54,0 +54,0 @@ * @returns {String} source — transformed source code |
@@ -322,2 +322,47 @@ const utils = require("../../utils/ast-utils"); | ||
/** | ||
* | ||
* Puts options object outside use object into use object | ||
* | ||
* @param {Node} p - object expression ast that has a key for either 'options' or 'use' | ||
* @returns {Node} objectExpression - an use object expression ast containing the options and loader | ||
*/ | ||
const fitOptionsToUse = p => { | ||
let options; | ||
p.value.properties.forEach(prop => { | ||
const keyName = prop.key.name; | ||
if (keyName === "options") { | ||
options = prop; | ||
} | ||
}); | ||
if (options) { | ||
p.value.properties = p.value.properties.filter( | ||
prop => prop.key.name !== "options" | ||
); | ||
p.value.properties.forEach(prop => { | ||
const keyName = prop.key.name; | ||
if (keyName === "use") { | ||
prop.value.elements[0].properties.push(options); | ||
} | ||
}); | ||
} | ||
return p; | ||
}; | ||
/** | ||
* Move `options` inside the Array of {Rule.Use} | ||
* | ||
* @returns {Node} ast - jscodeshift ast | ||
*/ | ||
const moveOptionsToUse = () => | ||
ast | ||
.find(j.ObjectExpression) | ||
.filter(p => utils.findObjWithOneOfKeys(p, ["use"])) | ||
.forEach(fitOptionsToUse); | ||
const transforms = [ | ||
@@ -329,3 +374,4 @@ prepostLoaders, | ||
loaderWithQueryProp, | ||
addLoaderSuffix | ||
addLoaderSuffix, | ||
moveOptionsToUse | ||
]; | ||
@@ -332,0 +378,0 @@ transforms.forEach(t => t()); |
@@ -30,3 +30,3 @@ const utils = require("../../utils/ast-utils"); | ||
let isPathPresent = false; | ||
const pathDecalaration = ast | ||
const pathDeclaration = ast | ||
.find(j.VariableDeclarator) | ||
@@ -46,5 +46,5 @@ .filter( | ||
if (pathDecalaration) { | ||
if (pathDeclaration) { | ||
isPathPresent = true; | ||
pathDecalaration.forEach(p => { | ||
pathDeclaration.forEach(p => { | ||
pathVarName = utils.safeTraverse(p, ["value", "id", "name"]); | ||
@@ -51,0 +51,0 @@ }); |
@@ -161,4 +161,4 @@ const hashtable = require("./hashtable"); | ||
* | ||
* Findes or creates a node for a given plugin name string with options object | ||
* If plugin decalaration already exist, options are merged. | ||
* Finds or creates a node for a given plugin name string with options object | ||
* If plugin declaration already exist, options are merged. | ||
* | ||
@@ -238,3 +238,3 @@ * @param {any} j — jscodeshift API | ||
* @param {String} pluginPackageName - ex. `extract-text-plugin` | ||
* @returns {String} variable name - ex. 'var s = require(s) gives "s"` | ||
* @returns {String} variable name - ex. 'const s = require(s) gives "s"` | ||
*/ | ||
@@ -241,0 +241,0 @@ |
@@ -1,2 +0,2 @@ | ||
var path = require("path"); | ||
const path = require("path"); | ||
@@ -11,9 +11,9 @@ /** | ||
*/ | ||
var generatorCopy = ( | ||
const generatorCopy = ( | ||
generator, | ||
templateDir | ||
) => /** @param {string} filePath */ filePath => { | ||
var sourceParts = templateDir.split(path.delimiter); | ||
const sourceParts = templateDir.split(path.delimiter); | ||
sourceParts.push.apply(sourceParts, filePath.split("/")); | ||
var targetParts = path.dirname(filePath).split("/"); | ||
const targetParts = path.dirname(filePath).split("/"); | ||
targetParts.push(path.basename(filePath, ".tpl")); | ||
@@ -38,3 +38,3 @@ | ||
*/ | ||
var generatorCopyTpl = ( | ||
const generatorCopyTpl = ( | ||
generator, | ||
@@ -44,5 +44,5 @@ templateDir, | ||
) => /** @param {string} filePath */ filePath => { | ||
var sourceParts = templateDir.split(path.delimiter); | ||
const sourceParts = templateDir.split(path.delimiter); | ||
sourceParts.push.apply(sourceParts, filePath.split("/")); | ||
var targetParts = path.dirname(filePath).split("/"); | ||
const targetParts = path.dirname(filePath).split("/"); | ||
targetParts.push(path.basename(filePath, ".tpl").slice(1)); | ||
@@ -49,0 +49,0 @@ |
@@ -30,3 +30,3 @@ "use strict"; | ||
*/ | ||
function runSingleTansform( | ||
function runSingleTransform( | ||
dirName, | ||
@@ -95,3 +95,3 @@ transformName, | ||
it(testName, () => { | ||
const output = runSingleTansform( | ||
const output = runSingleTransform( | ||
dirName, | ||
@@ -98,0 +98,0 @@ transformName, |
@@ -9,7 +9,7 @@ /** | ||
module.exports = function hashtable(a) { | ||
var prims = { boolean: {}, number: {}, string: {} }, | ||
const prims = { boolean: {}, number: {}, string: {} }, | ||
objs = []; | ||
return a.filter(function(item) { | ||
var type = typeof item; | ||
const type = typeof item; | ||
if (type in prims) | ||
@@ -16,0 +16,0 @@ return prims[type].hasOwnProperty(item) |
@@ -5,4 +5,6 @@ "use strict"; | ||
const path = require("path"); | ||
const chalk = require("chalk"); | ||
const yeoman = require("yeoman-environment"); | ||
const runTransform = require("../init/transformations/index"); | ||
const runTransform = require("../init/index"); | ||
const Generator = require("yeoman-generator"); | ||
@@ -19,3 +21,3 @@ /** | ||
module.exports = function modifyHelperUtil(action, generator) { | ||
module.exports = function modifyHelperUtil(action, generator, packages) { | ||
let configPath = path.resolve(process.cwd(), "webpack.config.js"); | ||
@@ -28,5 +30,40 @@ const webpackConfigExists = fs.existsSync(configPath); | ||
const generatorName = `webpack-${action}-generator`; | ||
if (!generator) { | ||
generator = class extends Generator { | ||
initializing() { | ||
packages.forEach(pkgPath => { | ||
return this.composeWith(require.resolve(pkgPath)); | ||
}); | ||
} | ||
}; | ||
} | ||
env.registerStub(generator, generatorName); | ||
env.run(generatorName).on("end", () => { | ||
let configModule; | ||
try { | ||
const configPath = path.resolve(process.cwd(), ".yo-rc.json"); | ||
configModule = require(configPath); | ||
// Change structure of the config to be transformed | ||
let tmpConfig = {}; | ||
Object.keys(configModule).forEach(prop => { | ||
const configs = Object.keys(configModule[prop].configuration); | ||
configs.forEach(config => { | ||
tmpConfig[config] = configModule[prop].configuration[config]; | ||
}); | ||
}); | ||
configModule = tmpConfig; | ||
} catch (err) { | ||
console.error( | ||
chalk.red("\nCould not find a yeoman configuration file.\n") | ||
); | ||
console.error( | ||
chalk.red( | ||
"\nPlease make sure to use 'this.config.set('configuration', this.configuration);' at the end of the generator.\n" | ||
) | ||
); | ||
Error.stackTraceLimit = 0; | ||
process.exitCode = -1; | ||
} | ||
const config = Object.assign( | ||
@@ -37,3 +74,3 @@ { | ||
}, | ||
env.getArgument("configuration") | ||
configModule | ||
); | ||
@@ -40,0 +77,0 @@ return runTransform(config, action); |
"use strict"; | ||
const chalk = require("chalk"); | ||
const isLocalPath = require("./is-local-path"); | ||
const npmExists = require("./npm-exists"); | ||
const resolvePackages = require("./resolve-packages").resolvePackages; | ||
const WEBPACK_ADDON_PREFIX = "webpack-addons"; | ||
/** | ||
@@ -17,12 +20,29 @@ * | ||
let acceptedPackages = []; | ||
function resolvePackagesIfReady() { | ||
if (acceptedPackages.length === pkg.length) | ||
return resolvePackages(acceptedPackages); | ||
} | ||
pkg.forEach(addon => { | ||
//eslint-disable-next-line | ||
if (addon.length <= 14 || addon.slice(0, 14) !== "webpack-addons") { | ||
if (isLocalPath(addon)) { | ||
// If the addon is a path to a local folder, no name validation is necessary. | ||
acceptedPackages.push(addon); | ||
resolvePackagesIfReady(); | ||
return; | ||
} | ||
// The addon is on npm; validate name and existence | ||
if ( | ||
addon.length <= WEBPACK_ADDON_PREFIX.length || | ||
addon.slice(0, WEBPACK_ADDON_PREFIX.length) !== WEBPACK_ADDON_PREFIX | ||
) { | ||
throw new TypeError( | ||
chalk.bold(`${addon} isn't a valid name.\n`) + | ||
chalk.red( | ||
"\nIt should be prefixed with 'webpack-addons', but have different suffix.\n" | ||
`\nIt should be prefixed with '${WEBPACK_ADDON_PREFIX}', but have different suffix.\n` | ||
) | ||
); | ||
} | ||
npmExists(addon) | ||
@@ -32,3 +52,3 @@ .then(moduleExists => { | ||
Error.stackTraceLimit = 0; | ||
throw new TypeError("Package isn't registered on npm."); | ||
throw new TypeError(`Cannot resolve location of package ${addon}.`); | ||
} | ||
@@ -43,7 +63,4 @@ if (moduleExists) { | ||
}) | ||
.then(_ => { | ||
if (acceptedPackages.length === pkg.length) | ||
return resolvePackages(acceptedPackages); | ||
}); | ||
.then(resolvePackagesIfReady); | ||
}); | ||
}; |
@@ -51,3 +51,4 @@ "use strict"; | ||
function spawnChild(pkg) { | ||
const pkgPath = path.resolve(globalPath, pkg); | ||
const rootPath = getPathToGlobalPackages(); | ||
const pkgPath = path.resolve(rootPath, pkg); | ||
const packageManager = getPackageManager(); | ||
@@ -75,5 +76,32 @@ const isNew = !fs.existsSync(pkgPath); | ||
/** | ||
* | ||
* Returns the path to globally installed | ||
* npm packages, depending on the available | ||
* package manager determined by `getPackageManager` | ||
* | ||
* @returns {String} path - Path to global node_modules folder | ||
*/ | ||
function getPathToGlobalPackages() { | ||
const manager = getPackageManager(); | ||
if (manager === "yarn") { | ||
try { | ||
const yarnDir = spawn | ||
.sync("yarn", ["global", "dir"]) | ||
.stdout.toString() | ||
.trim(); | ||
return path.join(yarnDir, "node_modules"); | ||
} catch (e) { | ||
// Default to the global npm path below | ||
} | ||
} | ||
return globalPath; | ||
} | ||
module.exports = { | ||
getPackageManager, | ||
getPathToGlobalPackages, | ||
spawnChild | ||
}; |
@@ -5,6 +5,8 @@ "use strict"; | ||
const chalk = require("chalk"); | ||
const globalPath = require("global-modules"); | ||
const creator = require("../init/index").creator; | ||
const modifyConfigHelper = require("./modify-config-helper"); | ||
const getPathToGlobalPackages = require("./package-manager") | ||
.getPathToGlobalPackages; | ||
const isLocalPath = require("./is-local-path"); | ||
const spawnChild = require("./package-manager").spawnChild; | ||
@@ -45,6 +47,32 @@ | ||
function invokeGeneratorIfReady() { | ||
if (packageLocations.length === pkg.length) | ||
return modifyConfigHelper("init", null, packageLocations); | ||
} | ||
pkg.forEach(addon => { | ||
// Resolve paths to modules on local filesystem | ||
if (isLocalPath(addon)) { | ||
let absolutePath = addon; | ||
try { | ||
absolutePath = path.resolve(process.cwd(), addon); | ||
require.resolve(absolutePath); | ||
packageLocations.push(absolutePath); | ||
} catch (err) { | ||
console.log(`Cannot find a generator at ${absolutePath}.`); | ||
console.log("\nReason:\n"); | ||
console.error(chalk.bold.red(err)); | ||
process.exitCode = 1; | ||
} | ||
invokeGeneratorIfReady(); | ||
return; | ||
} | ||
// Resolve modules on npm registry | ||
processPromise(spawnChild(addon)) | ||
.then(_ => { | ||
try { | ||
const globalPath = getPathToGlobalPackages(); | ||
packageLocations.push(path.resolve(globalPath, addon)); | ||
@@ -60,3 +88,3 @@ } catch (err) { | ||
.catch(err => { | ||
console.log("Package Coudln't be installed, aborting.."); | ||
console.log("Package couldn't be installed, aborting.."); | ||
console.log("\nReason: \n"); | ||
@@ -66,6 +94,3 @@ console.error(chalk.bold.red(err)); | ||
}) | ||
.then(_ => { | ||
if (packageLocations.length === pkg.length) | ||
return creator(packageLocations); | ||
}); | ||
.then(invokeGeneratorIfReady); | ||
}); | ||
@@ -72,0 +97,0 @@ } |
@@ -13,3 +13,3 @@ "use strict"; | ||
* @param {Node} source - AST to write at the given path | ||
* @param {Function} cb - exectues a callback after execution if supplied | ||
* @param {Function} cb - executes a callback after execution if supplied | ||
* @returns {Function} Writes a file at given location and prints messages accordingly | ||
@@ -16,0 +16,0 @@ */ |
{ | ||
"name": "webpack-cli", | ||
"version": "2.0.10", | ||
"version": "2.0.11", | ||
"description": "CLI for webpack & friends", | ||
@@ -67,3 +67,3 @@ "license": "MIT", | ||
"path": "./lib/init/**/**.js", | ||
"maxSize": "1.5 kB" | ||
"maxSize": "1.6 kB" | ||
}, | ||
@@ -84,9 +84,7 @@ { | ||
"dependencies": { | ||
"chalk": "^2.3.1", | ||
"codecov": "^3.0.0", | ||
"cross-spawn": "^6.0.4", | ||
"diff": "^3.3.0", | ||
"chalk": "^2.3.2", | ||
"cross-spawn": "^6.0.5", | ||
"diff": "^3.5.0", | ||
"enhanced-resolve": "^4.0.0", | ||
"glob-all": "^3.1.0", | ||
"global": "^4.3.2", | ||
"global-modules": "^1.0.0", | ||
@@ -96,7 +94,7 @@ "got": "^8.2.0", | ||
"interpret": "^1.0.4", | ||
"jscodeshift": "^0.4.1", | ||
"jscodeshift": "^0.5.0", | ||
"listr": "^0.13.0", | ||
"loader-utils": "^1.1.0", | ||
"lodash": "^4.17.5", | ||
"log-symbols": "2.2.0", | ||
"log-symbols": "^2.2.0", | ||
"mkdirp": "^0.5.1", | ||
@@ -106,25 +104,24 @@ "p-each-series": "^1.0.0", | ||
"prettier": "^1.5.3", | ||
"recast": "^0.14.4", | ||
"resolve-cwd": "^2.0.0", | ||
"supports-color": "^5.2.0", | ||
"uglifyjs-webpack-plugin": "^1.2.2", | ||
"supports-color": "^5.3.0", | ||
"v8-compile-cache": "^1.1.2", | ||
"webpack-addons": "^1.1.5", | ||
"yargs": "9.0.1", | ||
"yargs": "^11.0.0", | ||
"yeoman-environment": "^2.0.0", | ||
"yeoman-generator": "github:ev1stensberg/generator#Feature-getArgument" | ||
"yeoman-generator": "^2.0.3" | ||
}, | ||
"peerDependencies": { | ||
"webpack": "^4.0.0-beta.1" | ||
"webpack": "^4.0.0" | ||
}, | ||
"devDependencies": { | ||
"@commitlint/cli": "^6.1.2", | ||
"@commitlint/prompt-cli": "^6.1.2", | ||
"@commitlint/travis-cli": "^6.1.2", | ||
"@commitlint/cli": "^6.1.3", | ||
"@commitlint/prompt-cli": "^6.1.3", | ||
"@commitlint/travis-cli": "^6.1.3", | ||
"bundlesize": "^0.16.0", | ||
"codecov": "^3.0.0", | ||
"commitizen": "^2.9.6", | ||
"conventional-changelog-cli": "^1.3.15", | ||
"conventional-changelog-cli": "^1.3.16", | ||
"conventional-changelog-lint-config-cz": "^0.3.0", | ||
"cz-customizable": "^5.2.0", | ||
"eslint": "^4.18.1", | ||
"eslint": "^4.18.2", | ||
"eslint-plugin-node": "^6.0.1", | ||
@@ -139,5 +136,5 @@ "husky": "^0.14.3", | ||
"schema-utils": "^0.4.5", | ||
"webpack": "^4.0.1", | ||
"webpack": "^4.1.1", | ||
"webpack-dev-server": "^3.0.0" | ||
} | ||
} |
@@ -1,7 +0,9 @@ | ||
<a href="https://gitter.im/webpack/webpack"> | ||
<div align="center"><a href="https://github.com/webpack/webpack-cli"> | ||
<img width="200" height="200" src="https://webpack.js.org/assets/icon-square-big.svg"> | ||
</a> | ||
<div align="center"> | ||
<a href="https://github.com/webpack/webpack-cli"> | ||
<img width="200" height="200" src="https://webpack.js.org/assets/icon-square-big.svg"> | ||
</a> | ||
</div> | ||
<br> | ||
[![npm](https://img.shields.io/npm/v/webpack-cli.svg)](https://www.npmjs.com/package/webpack-cli) | ||
[![Build Status](https://travis-ci.org/webpack/webpack-cli.svg)](https://travis-ci.org/webpack/webpack-cli) | ||
@@ -15,3 +17,3 @@ [![Build status](https://ci.appveyor.com/api/projects/status/c2a37nlrfv9mg64f?svg=true)](https://ci.appveyor.com/project/ev1stensberg/webpack-cli) | ||
Webpack CLI encapsulates all code related to CLI handling. It captures options and sends them to webpack compiler. You can also find functionality for initializing a project and migrating between versions. For the time being, it is backwards-compatible with the CLI included in webpack itself. | ||
Webpack CLI encapsulates all code related to CLI handling. It captures options and sends them to webpack compiler. You can also find functionality for initializing a project and migrating between versions. | ||
@@ -18,0 +20,0 @@ ## Migration from webpack v1 to v2 |
@@ -17,4 +17,9 @@ # Introduction | ||
In order for `webpack-cli` to compile your package, it relies on a prefix of `webpack-addons`. The package must also be published on npm. If you are curious about how you can create your very own `addon`, please read [How do I compose a webpack-addon?](https://github.com/ev1stensberg/webpack-addons-demo). | ||
In order for `webpack-cli` to compile your package, it must be available on npm or on your local filesystem. If you are curious about how you can create your very own `addon`, please read [How do I compose a | ||
webpack-addon?](https://github.com/ev1stensberg/webpack-addons-demo). | ||
If the package is on npm, its name must have a prefix of `webpack-addons`. | ||
If the package is on your local filesystem, it can be named whatever you want. Pass the path to the package. | ||
## API | ||
@@ -21,0 +26,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
GitHub dependency
Supply chain riskContains a dependency which resolves to a GitHub URL. Dependencies fetched from GitHub specifiers are not immutable can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 1 instance in 1 package
26
7420
39
0
272865
21
104
24
+ Addedarray-differ@1.0.0(transitive)
+ Addedarrify@1.0.1(transitive)
+ Addedast-types@0.11.5(transitive)
+ Addedbabylon@7.0.0-beta.47(transitive)
+ Addedbuffer-alloc@1.2.0(transitive)
+ Addedbuffer-alloc-unsafe@1.1.0(transitive)
+ Addedbuffer-fill@1.0.0(transitive)
+ Addedcliui@4.1.0(transitive)
+ Addeddargs@5.1.0(transitive)
+ Addeddetect-conflict@1.0.1(transitive)
+ Addedejs@2.7.4(transitive)
+ Addedexeca@1.0.0(transitive)
+ Addedget-stream@4.1.0(transitive)
+ Addedgh-got@6.0.0(transitive)
+ Addedgithub-username@4.1.0(transitive)
+ Addedglobby@7.1.1(transitive)
+ Addedgot@7.1.0(transitive)
+ Addedignore@3.3.10(transitive)
+ Addedinvert-kv@2.0.0(transitive)
+ Addedisbinaryfile@3.0.3(transitive)
+ Addedjscodeshift@0.5.1(transitive)
+ Addedlcid@2.0.0(transitive)
+ Addedload-json-file@4.0.0(transitive)
+ Addedmap-age-cleaner@0.1.3(transitive)
+ Addedmem@4.3.0(transitive)
+ Addedmem-fs-editor@4.0.3(transitive)
+ Addedmultimatch@2.1.0(transitive)
+ Addedos-locale@3.1.0(transitive)
+ Addedp-cancelable@0.3.0(transitive)
+ Addedp-defer@1.0.0(transitive)
+ Addedp-is-promise@2.1.0(transitive)
+ Addedp-timeout@1.2.1(transitive)
+ Addedparse-json@4.0.0(transitive)
+ Addedpretty-bytes@4.0.2(transitive)
+ Addedread-chunk@2.1.0(transitive)
+ Addedread-pkg@3.0.0(transitive)
+ Addedread-pkg-up@3.0.0(transitive)
+ Addedrecast@0.15.5(transitive)
+ Addedtype-fest@0.21.3(transitive)
+ Addedyargs@11.1.1(transitive)
+ Addedyargs-parser@9.0.2(transitive)
+ Addedyeoman-generator@2.0.5(transitive)
- Removedcodecov@^3.0.0
- Removedglobal@^4.3.2
- Removedrecast@^0.14.4
- Removeduglifyjs-webpack-plugin@^1.2.2
- Removed@tootallnate/once@1.1.2(transitive)
- Removedagent-base@6.0.2(transitive)
- Removedargparse@1.0.10(transitive)
- Removedargv@0.0.2(transitive)
- Removedast-types@0.11.3(transitive)
- Removedcacache@10.0.4(transitive)
- Removedcliui@3.2.0(transitive)
- Removedcodecov@3.8.3(transitive)
- Removedcommander@2.14.1(transitive)
- Removedcross-spawn@5.1.0(transitive)
- Removeddom-walk@0.1.2(transitive)
- Removedexeca@0.7.0(transitive)
- Removedfast-url-parser@1.1.3(transitive)
- Removedfind-cache-dir@1.0.0(transitive)
- Removedglobal@4.4.0(transitive)
- Removedhttp-proxy-agent@4.0.1(transitive)
- Removedhttps-proxy-agent@5.0.1(transitive)
- Removedignore-walk@3.0.4(transitive)
- Removedinvert-kv@1.0.0(transitive)
- Removedjs-yaml@3.14.1(transitive)
- Removedlcid@1.0.0(transitive)
- Removedload-json-file@2.0.0(transitive)
- Removedlru-cache@4.1.5(transitive)
- Removedmem@1.1.0(transitive)
- Removedmin-document@2.19.0(transitive)
- Removedmississippi@2.0.0(transitive)
- Removedos-locale@2.1.0(transitive)
- Removedparse-json@2.2.0(transitive)
- Removedpath-type@2.0.0(transitive)
- Removedpkg-dir@2.0.0(transitive)
- Removedpseudomap@1.0.2(transitive)
- Removedread-pkg@2.0.0(transitive)
- Removedread-pkg-up@2.0.0(transitive)
- Removedrecast@0.14.7(transitive)
- Removedschema-utils@0.4.7(transitive)
- Removedserialize-javascript@1.9.1(transitive)
- Removedsprintf-js@1.0.3(transitive)
- Removedssri@5.3.0(transitive)
- Removedstream-events@1.0.5(transitive)
- Removedstubs@3.0.0(transitive)
- Removedteeny-request@7.1.1(transitive)
- Removeduglify-es@3.3.10(transitive)
- Removeduglifyjs-webpack-plugin@1.3.0(transitive)
- Removedurlgrey@1.0.0(transitive)
- Removeduuid@8.3.2(transitive)
- Removedyallist@2.1.2(transitive)
- Removedyargs@9.0.1(transitive)
- Removedyargs-parser@7.0.0(transitive)
Updatedchalk@^2.3.2
Updatedcross-spawn@^6.0.5
Updateddiff@^3.5.0
Updatedjscodeshift@^0.5.0
Updatedlog-symbols@^2.2.0
Updatedsupports-color@^5.3.0
Updatedyargs@^11.0.0
Updatedyeoman-generator@^2.0.3