diff --git a/.all-contributorsrc b/.all-contributorsrc index e8e13ee..d6173ea 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -64,7 +64,8 @@ "avatar_url": "https://avatars.githubusercontent.com/u/14267457?v=3", "profile": "https://github.com/tim-mcgee", "contributions": [ - "code" + "code", + "doc" ] }, { @@ -77,4 +78,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9049fe3..c963d60 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -41,7 +41,7 @@ Once you are ready to commit the changes, please use the below commands ## Help needed -Please checkout the [ROADMAP.md](https://github.com/kentcdodds/p-s/blob/master/ROADMAP.md) and raise an issue to discuss +Please checkout the [other/ROADMAP.md](https://github.com/kentcdodds/p-s/blob/master/ROADMAP.md) and raise an issue to discuss any of the items in the want to do or might do list. Also, please watch the repo and respond to questions/bug reports/feature requests! Thanks! diff --git a/README.md b/README.md index 1769d5d..e231046 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,7 @@ $ p-s --help -p, --parallel Scripts to run in parallel (comma seprated) -c, --config Config file to use (defaults to nearest package-scripts.js) -l, --log-level The log level to use (error, warn, info [default]) + -r, --require Module to preload Available scripts (camel or kebab case accepted) @@ -164,6 +165,10 @@ use that file instead. Specify the log level to use +#### require + +You can specify a module which will be loaded before the config file is loaded. This allows you to preload for example babel-register so you can use all babel presets you like. + #### args You can pass additional arguments to the script(s) that are being spawned: @@ -278,7 +283,7 @@ benefits of npm scripts I wanted to keep). ## In the wild -- [react-component-template](https://github.com/nkbt/react-component-template) uses `p-s` to implement shareable npm scripts. See then how dependent [react-swap](https://github.com/nkbt/react-swap) can reuse them. +- [react-component-template](https://github.com/nkbt/react-component-template) uses `p-s` to implement shareable npm scripts. See then how dependent [react-swap](https://github.com/nkbt/react-swap) can reuse them. GOTCHAS: - use `process.cwd()` as the base for all paths @@ -290,7 +295,7 @@ benefits of npm scripts I wanted to keep). Thanks goes to these people ([emoji key][emojis]): -| [
Kent C. Dodds](http://kent.doddsfamily.us)
[💻](https://github.com/kentcdodds/p-s/commits?author=kentcdodds) [📖](https://github.com/kentcdodds/p-s/commits?author=kentcdodds) 🚇 💡 | [
David Wells](http://davidwells.io)
[💻](https://github.com/kentcdodds/p-s/commits?author=DavidWells) | [
Abhishek Shende](https://twitter.com/abhishekisnot)
[💻](https://github.com/kentcdodds/p-s/commits?author=abhishekisnot) [⚠️](https://github.com/kentcdodds/p-s/commits?author=abhishekisnot) | [
Rowan Oulton](http://travelog.io)
[💻](https://github.com/kentcdodds/p-s/commits?author=rowanoulton) [📖](https://github.com/kentcdodds/p-s/commits?author=rowanoulton) [⚠️](https://github.com/kentcdodds/p-s/commits?author=rowanoulton) | [
Gilad Goldberg](https://github.com/giladgo)
[💻](https://github.com/kentcdodds/p-s/commits?author=giladgo) | [
Tim McGee](https://github.com/tim-mcgee)
[💻](https://github.com/kentcdodds/p-s/commits?author=tim-mcgee) | [
Nik Butenko](http://butenko.me)
💡 | +| [
Kent C. Dodds](http://kent.doddsfamily.us)
[💻](https://github.com/kentcdodds/p-s/commits?author=kentcdodds) [📖](https://github.com/kentcdodds/p-s/commits?author=kentcdodds) 🚇 💡 | [
David Wells](http://davidwells.io)
[💻](https://github.com/kentcdodds/p-s/commits?author=DavidWells) | [
Abhishek Shende](https://twitter.com/abhishekisnot)
[💻](https://github.com/kentcdodds/p-s/commits?author=abhishekisnot) [⚠️](https://github.com/kentcdodds/p-s/commits?author=abhishekisnot) | [
Rowan Oulton](http://travelog.io)
[💻](https://github.com/kentcdodds/p-s/commits?author=rowanoulton) [📖](https://github.com/kentcdodds/p-s/commits?author=rowanoulton) [⚠️](https://github.com/kentcdodds/p-s/commits?author=rowanoulton) | [
Gilad Goldberg](https://github.com/giladgo)
[💻](https://github.com/kentcdodds/p-s/commits?author=giladgo) | [
Tim McGee](https://github.com/tim-mcgee)
[💻](https://github.com/kentcdodds/p-s/commits?author=tim-mcgee) [📖](https://github.com/kentcdodds/p-s/commits?author=tim-mcgee) | [
Nik Butenko](http://butenko.me)
💡 | | :---: | :---: | :---: | :---: | :---: | :---: | :---: | diff --git a/bin/p-s.js b/bin/p-s.js index a5c50c4..91a664d 100755 --- a/bin/p-s.js +++ b/bin/p-s.js @@ -23,6 +23,7 @@ program .option('-p, --parallel ', 'Scripts to run in parallel (comma seprated)') .option('-c, --config ', 'Config file to use (defaults to nearest package-scripts.js)') .option('-l, --log-level ', 'The log level to use (error, warn, info [default])') + .option('-r, --require ', 'Module to preload') .on('--help', onHelp) .parse(process.argv) @@ -55,7 +56,29 @@ runPackageScript({ function getPSConfig() { var psConfigFilename = program.config ? resolve(process.cwd(), program.config) : findUp.sync('package-scripts.js') try { - return require(psConfigFilename) + // Require a module like babel-register + if (program.require) { + var requirePath = (program.require[0] === '.' + ? resolve(process.cwd(), program.require) + : program.require) + + try { + require(requirePath) + } catch (e) { + log.warn({ + message: colors.yellow('Unable to preload ' + program.require), + ref: 'unable-to-preload-module' + }) + } + } + + var config = require(psConfigFilename) + // babel-register is loading the default package into a object with the prop + // default so if it exist use it as the config + if (config.__esModule) { + config = config.default + } + return config } catch(e) { log.error({ message: colors.yellow('Unable to find config at ' + psConfigFilename), diff --git a/other/ERRORS_AND_WARNINGS.md b/other/ERRORS_AND_WARNINGS.md index bfc2cc5..8e2dbe0 100644 --- a/other/ERRORS_AND_WARNINGS.md +++ b/other/ERRORS_AND_WARNINGS.md @@ -18,3 +18,12 @@ point to a file that actually exists. This happens if you specify a script name that can't be resolved to a script. See the docs/examples for how you can define scripts and how they can be referenced. + +## Unable to preload module + +This happens when you use the `--require` flag and the module you specify cannot be resolved. + +### To fix: + +1. Check that you spelled the module correctly +2. Check that the module you wish to require is require-able diff --git a/src/bin-utils.js b/src/bin-utils.js index cd645b1..bf74208 100644 --- a/src/bin-utils.js +++ b/src/bin-utils.js @@ -25,7 +25,7 @@ function getScriptsAndArgs(program) { function getArgs(args, rawArgs, scripts) { const allArgs = rawArgs.slice(2) - const psArgs = ['-p', '--parallel', '-c', '--config'] + const psArgs = ['-p', '--parallel', '-c', '--config', '-r', '--require'] const psFlags = ['-s', '--silent'] const cleanedArgs = remove(allArgs, (item, index, arry) => { const isArgOrFlag = contains(psArgs, item) || contains(psFlags, item)