Skip to content

Commit

Permalink
adds @std/esm and babel-register alias/compat
Browse files Browse the repository at this point in the history
  • Loading branch information
evenstensberg committed Dec 19, 2017
1 parent 1f24d19 commit ab94211
Show file tree
Hide file tree
Showing 68 changed files with 578 additions and 362 deletions.
11 changes: 9 additions & 2 deletions bin/config-yargs.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = function(yargs) {
describe:
"Initializes a new webpack configuration or loads a" +
"\n" +
"plugin if specified",
"addon if specified",
group: INIT_GROUP
},
migrate: {
Expand Down Expand Up @@ -53,14 +53,21 @@ module.exports = function(yargs) {
describe: "Generates a new webpack plugin project",
group: INIT_GROUP
},

config: {
type: "string",
describe: "Path to the config file",
group: CONFIG_GROUP,
defaultDescription: "webpack.config.js or webpackfile.js",
requiresArg: true
},
"config-register": {
type: "string",
alias: "r",

This comment has been minimized.

Copy link
@jdalton

jdalton Dec 19, 2017

👆 The type should be an "array" to allow for multiple -r calls.
Folks will stack them like -r @std/esm -r @babel/register.

describe: "Allows to use import/export in the webpack configuration",
group: CONFIG_GROUP,
defaultDescription: "@std/esm or babel-register",
requiresArg: true
},

This comment has been minimized.

Copy link
@jdalton

jdalton Dec 19, 2017

The current"describe" field 👆 is describing one possible use for -r but not describing -r.

The description should be more generic. Something like:
"Preload one or more modules before loading the webpack configuration"

The "defaultDescription" should be something like:
"module id or path"

"config-name": {
type: "string",
describe: "Name of the config to use",
Expand Down
25 changes: 20 additions & 5 deletions bin/convert-argv.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ var fs = require("fs");
fs.existsSync = fs.existsSync || path.existsSync;
var interpret = require("interpret");
var prepareOptions = require("./prepareOptions");

module.exports = function(yargs, argv, convertOptions) {
var options = [];

// Shortcuts
if (argv.d) {
argv.debug = true;
Expand All @@ -27,7 +25,6 @@ module.exports = function(yargs, argv, convertOptions) {
argv.mode = "production";
}
}

var configFileLoaded = false;
var configFiles = [];
var extensions = Object.keys(interpret.extensions).sort(function(a, b) {
Expand Down Expand Up @@ -85,7 +82,6 @@ module.exports = function(yargs, argv, convertOptions) {
}
}
}

if (configFiles.length > 0) {
var registerCompiler = function registerCompiler(moduleDescriptor) {
if (moduleDescriptor) {
Expand All @@ -108,7 +104,26 @@ module.exports = function(yargs, argv, convertOptions) {

var requireConfig = function requireConfig(configPath) {
var options = (function WEBPACK_OPTIONS() {
return require(configPath);

This comment has been minimized.

Copy link
@jdalton

jdalton Dec 19, 2017

Can you explain a bit more on the special casing here?

The @std/esm package should be requirable from -r without any other special invocations. So shouldn't need to be loaded and invoked with its programmatic API as it is here.

The same goes for babel-register, which is the v6 of @babel/register v7.

This comment has been minimized.

Copy link
@evenstensberg

evenstensberg Dec 19, 2017

Author Member

So for the programatic API, just doing a require will mean that we'd need to trigger a process to install it each time instead of taking it for granted that the user has installed, say @std/esm in their project. One problem ( which I'm committing now, is that if we just do a require we'd get an error, cause babel-register and @std/esm has two different ways of requiring the module.

Just doing require with babel-register fails, cause it can't find the preset in .babelrc at the root path where webpack was invoked from

This comment has been minimized.

Copy link
@jdalton

jdalton Dec 19, 2017

So shouldn't need to be loaded and invoked with its programmatic API as it is here.

By programmatic API I mean requiring it and invoking it in the file with:
require("@std/esm")(module, options) or require("@babel/register")({presets:["es2015"]}).

This shouldn't be needed as the user can specify options in their package.json, .esmrc or .babelrc configs.

For example here is how Mocha handles its -r flags

mocha/bin/_mocha

// requires
requires.forEach(mod => {
  require(mod);
});

This comment has been minimized.

Copy link
@evenstensberg

evenstensberg Dec 19, 2017

Author Member

hm, weird. Did that approach before you linked it, and its throwing on babel, but @std/esm works

This comment has been minimized.

Copy link
@jdalton

jdalton Dec 19, 2017

So for the programatic API, just doing a require will mean that we'd need to trigger a process to install it each time instead of taking it for granted that the user has installed, say @std/esm in their project.

You shouldn't have to trigger an install. The -r flag is opt in to just load a module before loading the config.
It can be any module they have installed.

Just doing require with babel-register fails, cause it can't find the preset in .babelrc at the root path where webpack was invoked from

Check out how Mocha handles this here:
It adds paths to the module (mocha cli module) here then invokes the requires here.

This comment has been minimized.

Copy link
@evenstensberg

evenstensberg Dec 19, 2017

Author Member

Gotcha, so I changed it now, it works 👍 , would be nice if you tested it locally yourself if you've got time!

This comment has been minimized.

Copy link
@jdalton

jdalton Dec 19, 2017

I looked at the commits and I don't see it doing the mocha bit here. Here's the blame view for it to dig into it a bit more. I'm not sure if it's needed as the code has changed over the years and it might just be cruft.

The resolution stuff probably isn't needed as Node's require will do all of that. The interesting bit is the adding of the cwd and {cwd}/node_modules to the module.paths of the bin/_mocha.

This comment has been minimized.

Copy link
@evenstensberg

evenstensberg Dec 19, 2017

Author Member
if (argv.configRegister === "@std/esm") {
return require(path.resolve(
process.cwd(),
"node_modules",
"@std/esm"
))(module, {
esm: "js"
})(configPath);
} else if (argv.configRegister === "babel-register") {
require(path.resolve(
process.cwd(),
"node_modules",
"babel-register"
))({
presets: ["es2015"]
});
return require(configPath);
} else {
return require(configPath);
}
})();
options = prepareOptions(options, argv);
return options;
Expand Down
4 changes: 2 additions & 2 deletions docs/AddGenerator.html
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,13 @@ <h3 class="subsection-title">Extends</h3>
</div>

<nav>

This comment has been minimized.

Copy link
@jdalton

jdalton Dec 19, 2017

Did this commit get squashed with docs? 👇

<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="AddGenerator.html">AddGenerator</a></li><li><a href="InitGenerator.html">InitGenerator</a></li><li><a href="LoaderGenerator.html">LoaderGenerator</a></li><li><a href="PluginGenerator.html">PluginGenerator</a></li></ul><h3>Global</h3><ul><li><a href="global.html#checkIfExistsAndAddValue">checkIfExistsAndAddValue</a></li><li><a href="global.html#createArrayWithChildren">createArrayWithChildren</a></li><li><a href="global.html#createEmptyArrayProperty">createEmptyArrayProperty</a></li><li><a href="global.html#createEmptyCallableFunctionWithArguments">createEmptyCallableFunctionWithArguments</a></li><li><a href="global.html#createExternalRegExp">createExternalRegExp</a></li><li><a href="global.html#createIdentifierOrLiteral">createIdentifierOrLiteral</a></li><li><a href="global.html#createLiteral">createLiteral</a></li><li><a href="global.html#createObjectWithSuppliedProperty">createObjectWithSuppliedProperty</a></li><li><a href="global.html#createOrUpdatePluginByName">createOrUpdatePluginByName</a></li><li><a href="global.html#createProperty">createProperty</a></li><li><a href="global.html#creator">creator</a></li><li><a href="global.html#defineTest">defineTest</a></li><li><a href="global.html#findPluginsByName">findPluginsByName</a></li><li><a href="global.html#findRootNodesByName">findRootNodesByName</a></li><li><a href="global.html#findVariableToPlugin">findVariableToPlugin</a></li><li><a href="global.html#generatorCopy">generatorCopy</a></li><li><a href="global.html#generatorCopyTpl">generatorCopyTpl</a></li><li><a href="global.html#getPackageManager">getPackageManager</a></li><li><a href="global.html#getRequire">getRequire</a></li><li><a href="global.html#getRootPathModule">getRootPathModule</a></li><li><a href="global.html#isAssignment">isAssignment</a></li><li><a href="global.html#isType">isType</a></li><li><a href="global.html#loaderCreator">loaderCreator</a></li><li><a href="global.html#loopThroughObjects">loopThroughObjects</a></li><li><a href="global.html#makeLoaderName">makeLoaderName</a></li><li><a href="global.html#pluginCreator">pluginCreator</a></li><li><a href="global.html#processPromise">processPromise</a></li><li><a href="global.html#pushCreateProperty">pushCreateProperty</a></li><li><a href="global.html#pushObjectKeys">pushObjectKeys</a></li><li><a href="global.html#replaceAt">replaceAt</a></li><li><a href="global.html#runSingleTansform">runSingleTansform</a></li><li><a href="global.html#spawnChild">spawnChild</a></li><li><a href="global.html#spawnNPM">spawnNPM</a></li><li><a href="global.html#spawnNPMWithArg">spawnNPMWithArg</a></li><li><a href="global.html#spawnYarn">spawnYarn</a></li><li><a href="global.html#spawnYarnWithArg">spawnYarnWithArg</a></li><li><a href="global.html#transformsObject">transformsObject</a></li><li><a href="global.html#traverseAndGetProperties">traverseAndGetProperties</a></li><li><a href="global.html#webpackGenerator">webpackGenerator</a></li></ul>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="AddGenerator.html">AddGenerator</a></li><li><a href="InitGenerator.html">InitGenerator</a></li><li><a href="LoaderGenerator.html">LoaderGenerator</a></li><li><a href="PluginGenerator.html">PluginGenerator</a></li></ul><h3>Global</h3><ul><li><a href="global.html#checkIfExistsAndAddValue">checkIfExistsAndAddValue</a></li><li><a href="global.html#createArrayWithChildren">createArrayWithChildren</a></li><li><a href="global.html#createEmptyArrayProperty">createEmptyArrayProperty</a></li><li><a href="global.html#createEmptyCallableFunctionWithArguments">createEmptyCallableFunctionWithArguments</a></li><li><a href="global.html#createExternalRegExp">createExternalRegExp</a></li><li><a href="global.html#createIdentifierOrLiteral">createIdentifierOrLiteral</a></li><li><a href="global.html#createLiteral">createLiteral</a></li><li><a href="global.html#createObjectWithSuppliedProperty">createObjectWithSuppliedProperty</a></li><li><a href="global.html#createOrUpdatePluginByName">createOrUpdatePluginByName</a></li><li><a href="global.html#createProperty">createProperty</a></li><li><a href="global.html#creator">creator</a></li><li><a href="global.html#defineTest">defineTest</a></li><li><a href="global.html#findPluginsByName">findPluginsByName</a></li><li><a href="global.html#findRootNodesByName">findRootNodesByName</a></li><li><a href="global.html#findVariableToPlugin">findVariableToPlugin</a></li><li><a href="global.html#generatorCopy">generatorCopy</a></li><li><a href="global.html#generatorCopyTpl">generatorCopyTpl</a></li><li><a href="global.html#getPackageManager">getPackageManager</a></li><li><a href="global.html#getRequire">getRequire</a></li><li><a href="global.html#getRootPathModule">getRootPathModule</a></li><li><a href="global.html#isAssignment">isAssignment</a></li><li><a href="global.html#isType">isType</a></li><li><a href="global.html#loaderCreator">loaderCreator</a></li><li><a href="global.html#loopThroughObjects">loopThroughObjects</a></li><li><a href="global.html#makeLoaderName">makeLoaderName</a></li><li><a href="global.html#pluginCreator">pluginCreator</a></li><li><a href="global.html#processPromise">processPromise</a></li><li><a href="global.html#pushCreateProperty">pushCreateProperty</a></li><li><a href="global.html#pushObjectKeys">pushObjectKeys</a></li><li><a href="global.html#replaceAt">replaceAt</a></li><li><a href="global.html#resolvePackages">resolvePackages</a></li><li><a href="global.html#runSingleTansform">runSingleTansform</a></li><li><a href="global.html#serve">serve</a></li><li><a href="global.html#spawnChild">spawnChild</a></li><li><a href="global.html#spawnNPM">spawnNPM</a></li><li><a href="global.html#spawnNPMWithArg">spawnNPMWithArg</a></li><li><a href="global.html#spawnYarn">spawnYarn</a></li><li><a href="global.html#spawnYarnWithArg">spawnYarnWithArg</a></li><li><a href="global.html#transformsObject">transformsObject</a></li><li><a href="global.html#traverseAndGetProperties">traverseAndGetProperties</a></li><li><a href="global.html#webpackGenerator">webpackGenerator</a></li></ul>
</nav>

<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Dec 19 2017 13:32:26 GMT+0100 (CET)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Dec 19 2017 15:40:49 GMT+0100 (CET)
</footer>

<script> prettyPrint(); </script>
Expand Down
4 changes: 2 additions & 2 deletions docs/InitGenerator.html
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,13 @@ <h3 class="subsection-title">Extends</h3>
</div>

<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="AddGenerator.html">AddGenerator</a></li><li><a href="InitGenerator.html">InitGenerator</a></li><li><a href="LoaderGenerator.html">LoaderGenerator</a></li><li><a href="PluginGenerator.html">PluginGenerator</a></li></ul><h3>Global</h3><ul><li><a href="global.html#checkIfExistsAndAddValue">checkIfExistsAndAddValue</a></li><li><a href="global.html#createArrayWithChildren">createArrayWithChildren</a></li><li><a href="global.html#createEmptyArrayProperty">createEmptyArrayProperty</a></li><li><a href="global.html#createEmptyCallableFunctionWithArguments">createEmptyCallableFunctionWithArguments</a></li><li><a href="global.html#createExternalRegExp">createExternalRegExp</a></li><li><a href="global.html#createIdentifierOrLiteral">createIdentifierOrLiteral</a></li><li><a href="global.html#createLiteral">createLiteral</a></li><li><a href="global.html#createObjectWithSuppliedProperty">createObjectWithSuppliedProperty</a></li><li><a href="global.html#createOrUpdatePluginByName">createOrUpdatePluginByName</a></li><li><a href="global.html#createProperty">createProperty</a></li><li><a href="global.html#creator">creator</a></li><li><a href="global.html#defineTest">defineTest</a></li><li><a href="global.html#findPluginsByName">findPluginsByName</a></li><li><a href="global.html#findRootNodesByName">findRootNodesByName</a></li><li><a href="global.html#findVariableToPlugin">findVariableToPlugin</a></li><li><a href="global.html#generatorCopy">generatorCopy</a></li><li><a href="global.html#generatorCopyTpl">generatorCopyTpl</a></li><li><a href="global.html#getPackageManager">getPackageManager</a></li><li><a href="global.html#getRequire">getRequire</a></li><li><a href="global.html#getRootPathModule">getRootPathModule</a></li><li><a href="global.html#isAssignment">isAssignment</a></li><li><a href="global.html#isType">isType</a></li><li><a href="global.html#loaderCreator">loaderCreator</a></li><li><a href="global.html#loopThroughObjects">loopThroughObjects</a></li><li><a href="global.html#makeLoaderName">makeLoaderName</a></li><li><a href="global.html#pluginCreator">pluginCreator</a></li><li><a href="global.html#processPromise">processPromise</a></li><li><a href="global.html#pushCreateProperty">pushCreateProperty</a></li><li><a href="global.html#pushObjectKeys">pushObjectKeys</a></li><li><a href="global.html#replaceAt">replaceAt</a></li><li><a href="global.html#runSingleTansform">runSingleTansform</a></li><li><a href="global.html#spawnChild">spawnChild</a></li><li><a href="global.html#spawnNPM">spawnNPM</a></li><li><a href="global.html#spawnNPMWithArg">spawnNPMWithArg</a></li><li><a href="global.html#spawnYarn">spawnYarn</a></li><li><a href="global.html#spawnYarnWithArg">spawnYarnWithArg</a></li><li><a href="global.html#transformsObject">transformsObject</a></li><li><a href="global.html#traverseAndGetProperties">traverseAndGetProperties</a></li><li><a href="global.html#webpackGenerator">webpackGenerator</a></li></ul>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="AddGenerator.html">AddGenerator</a></li><li><a href="InitGenerator.html">InitGenerator</a></li><li><a href="LoaderGenerator.html">LoaderGenerator</a></li><li><a href="PluginGenerator.html">PluginGenerator</a></li></ul><h3>Global</h3><ul><li><a href="global.html#checkIfExistsAndAddValue">checkIfExistsAndAddValue</a></li><li><a href="global.html#createArrayWithChildren">createArrayWithChildren</a></li><li><a href="global.html#createEmptyArrayProperty">createEmptyArrayProperty</a></li><li><a href="global.html#createEmptyCallableFunctionWithArguments">createEmptyCallableFunctionWithArguments</a></li><li><a href="global.html#createExternalRegExp">createExternalRegExp</a></li><li><a href="global.html#createIdentifierOrLiteral">createIdentifierOrLiteral</a></li><li><a href="global.html#createLiteral">createLiteral</a></li><li><a href="global.html#createObjectWithSuppliedProperty">createObjectWithSuppliedProperty</a></li><li><a href="global.html#createOrUpdatePluginByName">createOrUpdatePluginByName</a></li><li><a href="global.html#createProperty">createProperty</a></li><li><a href="global.html#creator">creator</a></li><li><a href="global.html#defineTest">defineTest</a></li><li><a href="global.html#findPluginsByName">findPluginsByName</a></li><li><a href="global.html#findRootNodesByName">findRootNodesByName</a></li><li><a href="global.html#findVariableToPlugin">findVariableToPlugin</a></li><li><a href="global.html#generatorCopy">generatorCopy</a></li><li><a href="global.html#generatorCopyTpl">generatorCopyTpl</a></li><li><a href="global.html#getPackageManager">getPackageManager</a></li><li><a href="global.html#getRequire">getRequire</a></li><li><a href="global.html#getRootPathModule">getRootPathModule</a></li><li><a href="global.html#isAssignment">isAssignment</a></li><li><a href="global.html#isType">isType</a></li><li><a href="global.html#loaderCreator">loaderCreator</a></li><li><a href="global.html#loopThroughObjects">loopThroughObjects</a></li><li><a href="global.html#makeLoaderName">makeLoaderName</a></li><li><a href="global.html#pluginCreator">pluginCreator</a></li><li><a href="global.html#processPromise">processPromise</a></li><li><a href="global.html#pushCreateProperty">pushCreateProperty</a></li><li><a href="global.html#pushObjectKeys">pushObjectKeys</a></li><li><a href="global.html#replaceAt">replaceAt</a></li><li><a href="global.html#resolvePackages">resolvePackages</a></li><li><a href="global.html#runSingleTansform">runSingleTansform</a></li><li><a href="global.html#serve">serve</a></li><li><a href="global.html#spawnChild">spawnChild</a></li><li><a href="global.html#spawnNPM">spawnNPM</a></li><li><a href="global.html#spawnNPMWithArg">spawnNPMWithArg</a></li><li><a href="global.html#spawnYarn">spawnYarn</a></li><li><a href="global.html#spawnYarnWithArg">spawnYarnWithArg</a></li><li><a href="global.html#transformsObject">transformsObject</a></li><li><a href="global.html#traverseAndGetProperties">traverseAndGetProperties</a></li><li><a href="global.html#webpackGenerator">webpackGenerator</a></li></ul>
</nav>

<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Dec 19 2017 13:32:26 GMT+0100 (CET)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Dec 19 2017 15:40:49 GMT+0100 (CET)
</footer>

<script> prettyPrint(); </script>
Expand Down
Loading

0 comments on commit ab94211

Please sign in to comment.