From c5bbf0671dc07f77d1b4490443b7be6f0c390d5b Mon Sep 17 00:00:00 2001 From: Shriram Balaji Date: Mon, 18 Nov 2019 21:34:31 +0530 Subject: [PATCH 01/14] chore: migrate rollup-plugin-run --- packages/run/.gitignore | 2 + packages/run/CHANGELOG.md | 17 ++++++++ packages/run/README.md | 80 ++++++++++++++++++++++++++++++++++ packages/run/index.js | 69 +++++++++++++++++++++++++++++ packages/run/package-lock.json | 5 +++ packages/run/package.json | 24 ++++++++++ 6 files changed, 197 insertions(+) create mode 100644 packages/run/.gitignore create mode 100644 packages/run/CHANGELOG.md create mode 100644 packages/run/README.md create mode 100644 packages/run/index.js create mode 100644 packages/run/package-lock.json create mode 100644 packages/run/package.json diff --git a/packages/run/.gitignore b/packages/run/.gitignore new file mode 100644 index 000000000..91dfed8d4 --- /dev/null +++ b/packages/run/.gitignore @@ -0,0 +1,2 @@ +.DS_Store +node_modules \ No newline at end of file diff --git a/packages/run/CHANGELOG.md b/packages/run/CHANGELOG.md new file mode 100644 index 000000000..b21bd388b --- /dev/null +++ b/packages/run/CHANGELOG.md @@ -0,0 +1,17 @@ +# rollup-plugin-run changelog + +## 1.1.0 + +- Allow arguments and options to be passed to `child_process.fork` + +## 1.0.2 + +- Warn if Rollup version is too low + +## 1.0.1 + +- Handle output files with different names from input files + +## 1.0.0 + +- First release diff --git a/packages/run/README.md b/packages/run/README.md new file mode 100644 index 000000000..2b1f97bad --- /dev/null +++ b/packages/run/README.md @@ -0,0 +1,80 @@ +# @rollup/plugin-run + +🍣 A Rollup plugin which runs your bundles in Node once they're built. + +Using this plugin gives much faster results compared to what you would do with [nodemon](https://nodemon.io/). + +## Install + +Using npm: + +```console +npm i -D @rollup/plugin-run +``` + +## Usage + +Create a `rollup.config.js` [configuration file](https://www.rollupjs.org/guide/en/#configuration-files) and import the plugin: + +```js +// rollup.config.js +import run from "@rollup/plugin-run"; + +export default { + input: "src/index.js", + output: { + file: "dist/index.js", + format: "cjs" + }, + plugins: [run()] +}; +``` + +The app is run in a child process using [child_process.fork(...)](https://nodejs.org/api/child_process.html#child_process_child_process_fork_modulepath_args_options). Each time your bundle is rebuilt when the source code changes, this plugin starts the generated file as a child process (after first closing the previous process, if it's not the first run). + +Since this feature is intended for development use, you may prefer to only include it when Rollup is being run in watch mode: + +```diff +// rollup.config.js +import run from '@rollup/plugin-run'; + ++const dev = process.env.ROLLUP_WATCH === 'true'; + +export default { + input: 'src/index.js', + output: { + file: 'dist/index.js', + format: 'cjs' + }, + plugins: [ +- run() ++ dev && run() + ] +}; +``` + +> NOTE: It works with Rollup's code-splitting if you're using dynamic `import(...)` — the only constraint is that you have a single entry point specified in the config. + +## Options + +You can pass through options such as `env` and `execArgv`. For example, to debug with sourcemaps using [source-map-support](https://www.npmjs.com/package/source-map-support) you could do this: + +```diff +// rollup.config.js +import run from '@rollup/plugin-run'; + +export default { + input: 'src/index.js', + output: { + file: 'dist/index.js', + format: 'cjs', ++ sourcemap: true + }, + plugins: [ +- run() ++ run({ ++ execArgv: ['-r', 'source-map-support/register'] ++ }) + ] +}; +``` diff --git a/packages/run/index.js b/packages/run/index.js new file mode 100644 index 000000000..57911cbf7 --- /dev/null +++ b/packages/run/index.js @@ -0,0 +1,69 @@ +const path = require('path'); +const childProcess = require('child_process'); + +module.exports = (opts = {}) => { + let input; + let proc; + + const args = opts.args || []; + const forkOptions = opts.options || opts; + delete forkOptions.args; + + return { + name: 'run', + + // eslint-disable-next-line no-shadow + options(opts) { + let inputs = opts.input; + + if (typeof inputs === 'string') { + inputs = [inputs]; + } + + if (typeof inputs === 'object') { + inputs = Object.values(inputs); + } + + if (inputs.length > 1) { + throw new Error(`rollup-plugin-run only works with a single entry point`); + } + + input = path.resolve(inputs[0]); + }, + + generateBundle(outputOptions, bundle, isWrite) { + if (!isWrite) { + this.error(`rollup-plugin-run currently only works with bundles that are written to disk`); + } + + const dir = outputOptions.dir || path.dirname(outputOptions.file); + + let dest; + + for (const fileName in bundle) { + if (Object.prototype.hasOwnProperty.call(bundle, fileName)) { + const chunk = bundle[fileName]; + + if (!('isEntry' in chunk)) { + this.error(`rollup-plugin-run requires Rollup 0.65 or higher`); + } + + // eslint-disable-next-line no-continue + if (!chunk.isEntry) continue; + + if (chunk.modules[input]) { + dest = path.join(dir, fileName); + break; + } + } + } + + if (dest) { + if (proc) proc.kill(); + proc = childProcess.fork(dest, args, forkOptions); + } else { + this.error(`rollup-plugin-run could not find output chunk`); + } + } + }; +}; diff --git a/packages/run/package-lock.json b/packages/run/package-lock.json new file mode 100644 index 000000000..b82c2a21d --- /dev/null +++ b/packages/run/package-lock.json @@ -0,0 +1,5 @@ +{ + "name": "@rollup/plugin-run", + "version": "1.1.0", + "lockfileVersion": 1 +} diff --git a/packages/run/package.json b/packages/run/package.json new file mode 100644 index 000000000..2202f8b2f --- /dev/null +++ b/packages/run/package.json @@ -0,0 +1,24 @@ +{ + "name": "@rollup/plugin-run", + "version": "1.1.0", + "publishConfig": { + "access": "public" + }, + "description": "Run your bundle after you've built it", + "license": "MIT", + "repository": "rollup/plugins", + "author": "Rich Harris", + "homepage": "https://github.com/rollup/plugins/packages/run/#readme", + "bugs": "https://github.com/rollup/plugins/issues", + "main": "index.js", + "scripts": { + "lint": "pnpm run lint:js && pnpm run lint:docs && pnpm run lint:package", + "lint:docs": "prettier --single-quote --write README.md", + "lint:js": "eslint --fix --cache *.js", + "lint:package": "prettier --write package.json --plugin=prettier-plugin-package", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [ + "rollup" + ] +} From aa430235a869c1302ce7792131fb6bdaa852265b Mon Sep 17 00:00:00 2001 From: Shriram Balaji Date: Tue, 19 Nov 2019 00:38:59 +0530 Subject: [PATCH 02/14] chore: remove unnecessary .gitignore file --- packages/run/.gitignore | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 packages/run/.gitignore diff --git a/packages/run/.gitignore b/packages/run/.gitignore deleted file mode 100644 index 91dfed8d4..000000000 --- a/packages/run/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.DS_Store -node_modules \ No newline at end of file From 521ed2ad551081120898aa975a1b29f803dbefa7 Mon Sep 17 00:00:00 2001 From: Shriram Balaji Date: Tue, 19 Nov 2019 00:40:10 +0530 Subject: [PATCH 03/14] chore: replace all with @rollup/plugin-run --- packages/run/CHANGELOG.md | 2 +- packages/run/index.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/run/CHANGELOG.md b/packages/run/CHANGELOG.md index b21bd388b..87b1183a0 100644 --- a/packages/run/CHANGELOG.md +++ b/packages/run/CHANGELOG.md @@ -1,4 +1,4 @@ -# rollup-plugin-run changelog +# @rollup/plugin-run Change Log ## 1.1.0 diff --git a/packages/run/index.js b/packages/run/index.js index 57911cbf7..ec2befc60 100644 --- a/packages/run/index.js +++ b/packages/run/index.js @@ -25,7 +25,7 @@ module.exports = (opts = {}) => { } if (inputs.length > 1) { - throw new Error(`rollup-plugin-run only works with a single entry point`); + throw new Error(`@rollup/plugin-run only works with a single entry point`); } input = path.resolve(inputs[0]); @@ -33,7 +33,7 @@ module.exports = (opts = {}) => { generateBundle(outputOptions, bundle, isWrite) { if (!isWrite) { - this.error(`rollup-plugin-run currently only works with bundles that are written to disk`); + this.error(`@rollup/plugin-run currently only works with bundles that are written to disk`); } const dir = outputOptions.dir || path.dirname(outputOptions.file); @@ -45,7 +45,7 @@ module.exports = (opts = {}) => { const chunk = bundle[fileName]; if (!('isEntry' in chunk)) { - this.error(`rollup-plugin-run requires Rollup 0.65 or higher`); + this.error(`@rollup/plugin-run requires Rollup 0.65 or higher`); } // eslint-disable-next-line no-continue @@ -62,7 +62,7 @@ module.exports = (opts = {}) => { if (proc) proc.kill(); proc = childProcess.fork(dest, args, forkOptions); } else { - this.error(`rollup-plugin-run could not find output chunk`); + this.error(`@rollup/plugin-run could not find output chunk`); } } }; From c0bf5ee28f74e6771116e01fa1035ac37023b647 Mon Sep 17 00:00:00 2001 From: Shriram Balaji Date: Tue, 19 Nov 2019 00:42:13 +0530 Subject: [PATCH 04/14] chore: add missing ci scripts --- packages/run/package.json | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/run/package.json b/packages/run/package.json index 2202f8b2f..0fa5360a1 100644 --- a/packages/run/package.json +++ b/packages/run/package.json @@ -12,13 +12,20 @@ "bugs": "https://github.com/rollup/plugins/issues", "main": "index.js", "scripts": { + "ci:coverage": "nyc pnpm run test && nyc report --reporter=text-lcov > coverage.lcov", + "ci:lint": "pnpm run build && pnpm run lint && pnpm run security", + "ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}", + "ci:test": "pnpm run test -- --verbose", "lint": "pnpm run lint:js && pnpm run lint:docs && pnpm run lint:package", "lint:docs": "prettier --single-quote --write README.md", "lint:js": "eslint --fix --cache *.js", "lint:package": "prettier --write package.json --plugin=prettier-plugin-package", + "prepublishOnly": "pnpm run lint && pnpm run test", "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [ - "rollup" + "rollup", + "plugin", + "run" ] } From 32358794d007f9bd524db8cdd5cb89a762c0d98a Mon Sep 17 00:00:00 2001 From: Shriram Balaji Date: Tue, 19 Nov 2019 01:11:54 +0530 Subject: [PATCH 05/14] chore: add meta links to readme * update Options and Usage Sections --- packages/run/README.md | 58 +++++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/packages/run/README.md b/packages/run/README.md index 2b1f97bad..5f74b366b 100644 --- a/packages/run/README.md +++ b/packages/run/README.md @@ -1,3 +1,12 @@ +[npm]: https://img.shields.io/npm/v/@rollup/plugin-run +[npm-url]: https://www.npmjs.com/package/@rollup/plugin-run +[size]: https://packagephobia.now.sh/badge?p=@rollup/plugin-run +[size-url]: https://packagephobia.now.sh/result?p=@rollup/plugin-run + +[![npm][npm]][npm-url] +[![size][size]][size-url] +[![libera manifesto](https://img.shields.io/badge/libera-manifesto-lightgrey.svg)](https://liberamanifesto.com) + # @rollup/plugin-run 🍣 A Rollup plugin which runs your bundles in Node once they're built. @@ -9,7 +18,7 @@ Using this plugin gives much faster results compared to what you would do with [ Using npm: ```console -npm i -D @rollup/plugin-run +npm install @rollup/plugin-run --save-dev ``` ## Usage @@ -17,7 +26,6 @@ npm i -D @rollup/plugin-run Create a `rollup.config.js` [configuration file](https://www.rollupjs.org/guide/en/#configuration-files) and import the plugin: ```js -// rollup.config.js import run from "@rollup/plugin-run"; export default { @@ -30,51 +38,65 @@ export default { }; ``` -The app is run in a child process using [child_process.fork(...)](https://nodejs.org/api/child_process.html#child_process_child_process_fork_modulepath_args_options). Each time your bundle is rebuilt when the source code changes, this plugin starts the generated file as a child process (after first closing the previous process, if it's not the first run). +Then call `rollup` either via the [CLI](https://www.rollupjs.org/guide/en/#command-line-reference) or the [API](https://www.rollupjs.org/guide/en/#javascript-api). If the build produces any errors, the plugin will write a 'alias' character to stderr, which should be audible on most systems. + +The plugin `forks` a child process with the generated file, every time the bundle is rebuilt (after first closing the previous process, if it's not the first run). + +_Note: This plugin works with Rollup's code-splitting if you're using dynamic `import(...)` — the only constraint is that you have a single entry point specified in the config._ + +## Options + +This plugin supports pass through option available for [child_process.fork(...)](https://nodejs.org/api/child_process.html#child_process_child_process_fork_modulepath_args_options). + +Example: -Since this feature is intended for development use, you may prefer to only include it when Rollup is being run in watch mode: +Debugging with sourcemaps using [source-map-support](https://www.npmjs.com/package/source-map-support): ```diff // rollup.config.js import run from '@rollup/plugin-run'; -+const dev = process.env.ROLLUP_WATCH === 'true'; - export default { input: 'src/index.js', output: { file: 'dist/index.js', - format: 'cjs' + format: 'cjs', ++ sourcemap: true }, plugins: [ - run() -+ dev && run() ++ run({ ++ execArgv: ['-r', 'source-map-support/register'] ++ }) ] }; ``` -> NOTE: It works with Rollup's code-splitting if you're using dynamic `import(...)` — the only constraint is that you have a single entry point specified in the config. - -## Options +## Practical Example -You can pass through options such as `env` and `execArgv`. For example, to debug with sourcemaps using [source-map-support](https://www.npmjs.com/package/source-map-support) you could do this: +The feature is usually intended for development use, you may prefer to only include it when Rollup is being run in watch mode: ```diff // rollup.config.js -import run from '@rollup/plugin-run'; +import run from 'rollup-plugin-run'; + ++const dev = process.env.ROLLUP_WATCH === 'true'; export default { input: 'src/index.js', output: { file: 'dist/index.js', - format: 'cjs', -+ sourcemap: true + format: 'cjs' }, plugins: [ - run() -+ run({ -+ execArgv: ['-r', 'source-map-support/register'] -+ }) ++ dev && run() ] }; ``` + +## Meta + +[CONTRIBUTING](/.github/CONTRIBUTING.md) + +[LICENSE (MIT)](/LICENSE) From bfb053566e8f3282fcb16507cbc2a16111935d2d Mon Sep 17 00:00:00 2001 From: Shriram Balaji Date: Tue, 19 Nov 2019 01:25:34 +0530 Subject: [PATCH 06/14] chore: remove unnecessary package-lock.json --- packages/run/package-lock.json | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 packages/run/package-lock.json diff --git a/packages/run/package-lock.json b/packages/run/package-lock.json deleted file mode 100644 index b82c2a21d..000000000 --- a/packages/run/package-lock.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "@rollup/plugin-run", - "version": "1.1.0", - "lockfileVersion": 1 -} From 584932088d15bdd60755b51591865763ef02a1d6 Mon Sep 17 00:00:00 2001 From: Shriram Balaji Date: Tue, 19 Nov 2019 05:09:23 +0530 Subject: [PATCH 07/14] deps: add sinon, del packages * also add `ava` test script --- packages/run/package.json | 14 ++++- pnpm-lock.yaml | 105 +++++++++++++++++++++++++++++++++++++- 2 files changed, 116 insertions(+), 3 deletions(-) diff --git a/packages/run/package.json b/packages/run/package.json index 0fa5360a1..9bb977bf3 100644 --- a/packages/run/package.json +++ b/packages/run/package.json @@ -21,11 +21,21 @@ "lint:js": "eslint --fix --cache *.js", "lint:package": "prettier --write package.json --plugin=prettier-plugin-package", "prepublishOnly": "pnpm run lint && pnpm run test", - "test": "echo \"Error: no test specified\" && exit 1" + "test": "ava" }, "keywords": [ "rollup", "plugin", "run" - ] + ], + "devDependencies": { + "del": "^5.1.0", + "rollup": "^1.27.2", + "sinon": "^7.5.0" + }, + "ava": { + "files": [ + "!**/fixtures/**" + ] + } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index efa7724ce..3d7cac150 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -155,6 +155,15 @@ importers: rollup-pluginutils: ^2.6.0 source-map: ^0.7.3 typescript: ^3.4.3 + packages/run: + devDependencies: + del: 5.1.0 + rollup: 1.27.2 + sinon: 7.5.0 + specifiers: + del: ^5.1.0 + rollup: ^1.27.2 + sinon: ^7.5.0 packages/strip: dependencies: estree-walker: 0.6.1 @@ -1002,6 +1011,31 @@ packages: node: '>=6' resolution: integrity: sha512-9NET910DNaIPngYnLLPeg+Ogzqsi9uM4mSboU5y6p8S5DzMTVEsJZrawi+BoDNUVBa2DhJqQYUFvMDfgU062LQ== + /@sinonjs/commons/1.6.0: + dependencies: + type-detect: 4.0.8 + dev: true + resolution: + integrity: sha512-w4/WHG7C4WWFyE5geCieFJF6MZkbW4VAriol5KlmQXpAQdxvV0p26sqNZOW6Qyw6Y0l9K4g+cHvvczR2sEEpqg== + /@sinonjs/formatio/3.2.2: + dependencies: + '@sinonjs/commons': 1.6.0 + '@sinonjs/samsam': 3.3.3 + dev: true + resolution: + integrity: sha512-B8SEsgd8gArBLMD6zpRw3juQ2FVSsmdd7qlevyDqzS9WTCtvF55/gAL+h6gue8ZvPYcdiPdvueM/qm//9XzyTQ== + /@sinonjs/samsam/3.3.3: + dependencies: + '@sinonjs/commons': 1.6.0 + array-from: 2.1.1 + lodash: 4.17.15 + dev: true + resolution: + integrity: sha512-bKCMKZvWIjYD0BLGnNrxVuw4dkWCYsLqFOUWw8VgKF/+5Y+mE7LfHWPIYoDXowH+3a9LsWDMo0uAP8YDosPvHQ== + /@sinonjs/text-encoding/0.7.1: + dev: true + resolution: + integrity: sha512-+iTbntw2IZPb/anVDbypzfQa+ay64MW0Zo8aJ8gZPWMMK6/OubMVb6lUPMagqjOPnmtauXnFCACVl3O7ogjeqQ== /@szmarczak/http-timer/1.1.2: dependencies: defer-to-connect: 1.1.0 @@ -1026,7 +1060,7 @@ packages: dependencies: '@types/events': 3.0.0 '@types/minimatch': 3.0.3 - '@types/node': 12.12.8 + '@types/node': 12.12.9 dev: true resolution: integrity: sha512-1Bh06cbWJUHMC97acuD6UMG29nMt0Aqz1vF3guLfG+kHHJhy3AyohZFFxYk2f7Q1SQIrNwvncxAE0N/9s70F2w== @@ -1038,6 +1072,10 @@ packages: dev: true resolution: integrity: sha512-XLla8N+iyfjvsa0KKV+BP/iGSoTmwxsu5Ci5sM33z9TjohF72DEz95iNvD6pPmemvbQgxAv/909G73gUn8QR7w== + /@types/node/12.12.9: + dev: true + resolution: + integrity: sha512-kV3w4KeLsRBW+O2rKhktBwENNJuqAUQHS3kf4ia2wIaF/MN6U7ANgTsx7tGremcA0Pk3Yh0Hl0iKiLPuBdIgmw== /@types/normalize-package-data/2.4.0: dev: true resolution: @@ -1211,6 +1249,10 @@ packages: node: '>=0.10.0' resolution: integrity: sha1-3wEKoSh+Fku9pvlyOwqWoexBh6E= + /array-from/2.1.1: + dev: true + resolution: + integrity: sha1-z+nYwmYoudxa7MYqn12PHzUsEZU= /array-includes/3.0.3: dependencies: define-properties: 1.1.3 @@ -2015,6 +2057,12 @@ packages: node: '>=8' resolution: integrity: sha512-wH9xOVHnczo9jN2IW68BabcecVPxacIA3g/7z6vhSU/4stOKQzeCRK0yD0A24WiAAUJmmVpWqrERcTxnLo3AnA== + /diff/3.5.0: + dev: true + engines: + node: '>=0.3.1' + resolution: + integrity: sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA== /diff/4.0.1: dev: true engines: @@ -3146,6 +3194,10 @@ packages: dev: true resolution: integrity: sha512-VjSeb/lHmkoyd8ryPVIKvOCn4D1koMqY+vqyjjUfc3xyKtP4dYOxM44sZrnqQSzSds3xyOrUTLTC9LVCVgLngw== + /isarray/0.0.1: + dev: true + resolution: + integrity: sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8= /isarray/1.0.0: dev: true resolution: @@ -3277,6 +3329,10 @@ packages: hasBin: true resolution: integrity: sha512-l+3HXD0GEI3huGq1njuqtzYK8OYJyXMkOLtQ53pjWh89tvWS2h6l+1zMkYWqlb57+SiQodKZyvMEFb2X+KrFhQ== + /just-extend/4.0.2: + dev: true + resolution: + integrity: sha512-FrLwOgm+iXrPV+5zDU6Jqu4gCRXbWEQg2O3SKONsWE4w7AXFRkryS53bpWdaL9cNol+AmR3AEYz6kn+o0fCPnw== /keyv/3.1.0: dependencies: json-buffer: 3.0.0 @@ -3495,6 +3551,10 @@ packages: node: '>=4' resolution: integrity: sha1-iDKP19HOeTiykoN0bwsbwSayRwg= + /lolex/4.2.0: + dev: true + resolution: + integrity: sha512-gKO5uExCXvSm6zbF562EvM+rd1kQDnB9AZBbiQVzf1ZmdDpxUSvpnAaVOP83N/31mRK8Ml8/VE8DMvsAZQ+7wg== /loose-envify/1.4.0: dependencies: js-tokens: 4.0.0 @@ -3729,6 +3789,16 @@ packages: dev: true resolution: integrity: sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ== + /nise/1.5.2: + dependencies: + '@sinonjs/formatio': 3.2.2 + '@sinonjs/text-encoding': 0.7.1 + just-extend: 4.0.2 + lolex: 4.2.0 + path-to-regexp: 1.8.0 + dev: true + resolution: + integrity: sha512-/6RhOUlicRCbE9s+94qCUsyE+pKlVJ5AhIv+jEE7ESKwnbXqulKZ1FYU+XAtHHWE9TinYvAxDUJAb912PwPoWA== /node-noop/1.0.0: dev: false resolution: @@ -4143,6 +4213,12 @@ packages: dev: true resolution: integrity: sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw== + /path-to-regexp/1.8.0: + dependencies: + isarray: 0.0.1 + dev: true + resolution: + integrity: sha512-n43JRhlUKUAlibEJhPeir1ncUID16QnEjNpwzNdO3Lm4ywrBpBZ5oLD0I6br9evr1Y9JTqwRtAh7JLoOzAQdVA== /path-type/2.0.0: dependencies: pify: 2.3.0 @@ -4660,6 +4736,15 @@ packages: hasBin: true resolution: integrity: sha512-yaMna4MJ8LLEHhHl1ilgHakylf0LKeQctDxhngZLQ+W57GnXa5vtH7XKaK8zlAhNEhlWiH5YFVFt+QCDPUmNkw== + /rollup/1.27.2: + dependencies: + '@types/estree': 0.0.39 + '@types/node': 12.12.8 + acorn: 7.1.0 + dev: true + hasBin: true + resolution: + integrity: sha512-sD3iyd0zlvgK1S3MmICi6F/Y+R/QWY5XxzsTGN4pAd+nCasDUizmAhgq2hdh1t2eLux974NHU2TW41fhuGPv+Q== /run-async/2.3.0: dependencies: is-promise: 2.1.0 @@ -4763,6 +4848,18 @@ packages: dev: true resolution: integrity: sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0= + /sinon/7.5.0: + dependencies: + '@sinonjs/commons': 1.6.0 + '@sinonjs/formatio': 3.2.2 + '@sinonjs/samsam': 3.3.3 + diff: 3.5.0 + lolex: 4.2.0 + nise: 1.5.2 + supports-color: 5.5.0 + dev: true + resolution: + integrity: sha512-AoD0oJWerp0/rY9czP/D6hDTTUYGpObhZjMpd7Cl/A6+j0xBE+ayL/ldfggkBXUs0IkvIiM1ljM8+WkOc5k78Q== /slash/3.0.0: engines: node: '>=8' @@ -5191,6 +5288,12 @@ packages: node: '>= 0.8.0' resolution: integrity: sha1-WITKtRLPHTVeP7eE8wgEsrUg23I= + /type-detect/4.0.8: + dev: true + engines: + node: '>=4' + resolution: + integrity: sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g== /type-fest/0.3.1: dev: true engines: From 684d8f8f22702f3b46bd53c432d07ba1e4fd6530 Mon Sep 17 00:00:00 2001 From: Shriram Balaji Date: Tue, 19 Nov 2019 05:11:39 +0530 Subject: [PATCH 08/14] test: add unit tests for plugin-run with fixtures --- .../run/test/fixtures/change-detect-input.js | 1 + packages/run/test/fixtures/input.js | 1 + packages/run/test/test.js | 87 +++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 packages/run/test/fixtures/change-detect-input.js create mode 100644 packages/run/test/fixtures/input.js create mode 100644 packages/run/test/test.js diff --git a/packages/run/test/fixtures/change-detect-input.js b/packages/run/test/fixtures/change-detect-input.js new file mode 100644 index 000000000..93c705970 --- /dev/null +++ b/packages/run/test/fixtures/change-detect-input.js @@ -0,0 +1 @@ +export const Greeting = () => 'Hola'; // eslint-disable-line diff --git a/packages/run/test/fixtures/input.js b/packages/run/test/fixtures/input.js new file mode 100644 index 000000000..0f5dc63f6 --- /dev/null +++ b/packages/run/test/fixtures/input.js @@ -0,0 +1 @@ +export const Greeting = () => 'Hello'; // eslint-disable-line diff --git a/packages/run/test/test.js b/packages/run/test/test.js new file mode 100644 index 000000000..c4bc79764 --- /dev/null +++ b/packages/run/test/test.js @@ -0,0 +1,87 @@ +const fs = require('fs'); +const { EventEmitter } = require('events'); + +const { join } = require('path'); + +const childProcess = require('child_process'); + +const del = require('del'); +const { rollup } = require('rollup'); +const test = require('ava'); +const sinon = require('sinon'); + +const writeFile = require('util').promisify(fs.writeFile); + +const run = require('..'); + +const cwd = join(__dirname, 'fixtures/'); +const file = join(cwd, 'output/bundle.js'); +const input = join(cwd, 'input.js'); + +process.chdir(cwd); + +const outputOptions = { file, format: 'cjs' }; + +let mockChildProcess; +test.before(() => { + mockChildProcess = sinon + .stub(childProcess, ['fork']) + .returns({ ...new EventEmitter(), kill: sinon.fake() }); +}); + +test('builds the bundle and forks a child process', async (t) => { + const bundle = await rollup({ + input, + plugins: [run()] + }); + await bundle.write(outputOptions); + t.true(mockChildProcess.calledWithExactly(outputOptions.file, [], {})); +}); + +test('allows pass-through options for child_process.fork', async (t) => { + const forkOptions = { + cwd, + detached: false, + silent: false + }; + const bundle = await rollup({ + input, + plugins: [run(forkOptions)] + }); + + await bundle.write(outputOptions); + t.true(mockChildProcess.calledWithExactly(outputOptions.file, [], forkOptions)); +}); + +test('throws an error when bundle is not written to disk', async (t) => { + const bundle = await rollup({ + input, + plugins: [run()] + }); + await t.throwsAsync( + async () => { + await bundle.generate(outputOptions); + }, + { + instanceOf: Error, + message: '@rollup/plugin-run currently only works with bundles that are written to disk' + } + ); +}); + +test('detects changes - forks a new child process and kills older process', async (t) => { + const input = join(cwd, 'change-detect-input.js'); + const bundle = await rollup({ + input, + plugins: [run()] + }); + await bundle.write(outputOptions); + await writeFile(input, 'export const Greeting = () => "Hola"'); + await bundle.write(outputOptions); + t.true(mockChildProcess.calledWithExactly(outputOptions.file, [], {})); + t.is(mockChildProcess().kill.callCount, 1); +}); + +test.after(async () => { + await del(['output']); +}); From 607b4cc2d72c7ca12dcc144ff0be3a758709ad94 Mon Sep 17 00:00:00 2001 From: Shriram Balaji Date: Tue, 19 Nov 2019 05:25:04 +0530 Subject: [PATCH 09/14] chore: fix ci lint scripts --- packages/run/package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/run/package.json b/packages/run/package.json index 9bb977bf3..58d923b1b 100644 --- a/packages/run/package.json +++ b/packages/run/package.json @@ -13,7 +13,7 @@ "main": "index.js", "scripts": { "ci:coverage": "nyc pnpm run test && nyc report --reporter=text-lcov > coverage.lcov", - "ci:lint": "pnpm run build && pnpm run lint && pnpm run security", + "ci:lint": "pnpm run lint && pnpm run security", "ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}", "ci:test": "pnpm run test -- --verbose", "lint": "pnpm run lint:js && pnpm run lint:docs && pnpm run lint:package", @@ -21,6 +21,7 @@ "lint:js": "eslint --fix --cache *.js", "lint:package": "prettier --write package.json --plugin=prettier-plugin-package", "prepublishOnly": "pnpm run lint && pnpm run test", + "security": "echo 'pnpm needs `npm audit` support'", "test": "ava" }, "keywords": [ From 2c85800e69ac5760174bba3c7ecea06c825bb975 Mon Sep 17 00:00:00 2001 From: Shriram Balaji Date: Thu, 21 Nov 2019 13:07:28 +0530 Subject: [PATCH 10/14] chore: rename rollup-plugin-run in readme examples Co-Authored-By: Andrew Powell --- packages/run/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/run/README.md b/packages/run/README.md index 5f74b366b..c43aeafcf 100644 --- a/packages/run/README.md +++ b/packages/run/README.md @@ -78,7 +78,7 @@ The feature is usually intended for development use, you may prefer to only incl ```diff // rollup.config.js -import run from 'rollup-plugin-run'; +import run from '@rollup/plugin-run'; +const dev = process.env.ROLLUP_WATCH === 'true'; From 5d03218f50b9f83daa5456b8722767882e324efe Mon Sep 17 00:00:00 2001 From: Shriram Balaji Date: Thu, 21 Nov 2019 08:06:52 +0000 Subject: [PATCH 11/14] deps: add rollup@^1.20.0 as peer dependency --- packages/run/package.json | 5 ++++- pnpm-lock.yaml | 14 +++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/run/package.json b/packages/run/package.json index 58d923b1b..57d6b2dae 100644 --- a/packages/run/package.json +++ b/packages/run/package.json @@ -29,9 +29,12 @@ "plugin", "run" ], + "peerDependencies": { + "rollup": "^1.20.0" + }, "devDependencies": { "del": "^5.1.0", - "rollup": "^1.27.2", + "rollup": "^1.20.0", "sinon": "^7.5.0" }, "ava": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3d7cac150..64c77882d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -158,11 +158,11 @@ importers: packages/run: devDependencies: del: 5.1.0 - rollup: 1.27.2 + rollup: 1.27.3 sinon: 7.5.0 specifiers: del: ^5.1.0 - rollup: ^1.27.2 + rollup: ^1.20.0 sinon: ^7.5.0 packages/strip: dependencies: @@ -1068,6 +1068,10 @@ packages: dev: true resolution: integrity: sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA== + /@types/node/12.12.11: + dev: true + resolution: + integrity: sha512-O+x6uIpa6oMNTkPuHDa9MhMMehlxLAd5QcOvKRjAFsBVpeFWTOPnXbDvILvFgFFZfQ1xh1EZi1FbXxUix+zpsQ== /@types/node/12.12.8: dev: true resolution: @@ -4736,15 +4740,15 @@ packages: hasBin: true resolution: integrity: sha512-yaMna4MJ8LLEHhHl1ilgHakylf0LKeQctDxhngZLQ+W57GnXa5vtH7XKaK8zlAhNEhlWiH5YFVFt+QCDPUmNkw== - /rollup/1.27.2: + /rollup/1.27.3: dependencies: '@types/estree': 0.0.39 - '@types/node': 12.12.8 + '@types/node': 12.12.11 acorn: 7.1.0 dev: true hasBin: true resolution: - integrity: sha512-sD3iyd0zlvgK1S3MmICi6F/Y+R/QWY5XxzsTGN4pAd+nCasDUizmAhgq2hdh1t2eLux974NHU2TW41fhuGPv+Q== + integrity: sha512-79AEh4m5NPCz97GTuIoXpSFIMPyk2AiqVQp040baSRPXk/I4YMGt5/CR9GX5oEYEkxwBZoWLheaS1/w/FidfJw== /run-async/2.3.0: dependencies: is-promise: 2.1.0 From 7406c4d0480ea12729c0aa70458ef55b8f2fa16a Mon Sep 17 00:00:00 2001 From: Shriram Balaji Date: Thu, 21 Nov 2019 08:41:57 +0000 Subject: [PATCH 12/14] chore: move main index.js into lib directory * add files section to package.json * lint fix tests and fixtures * lint fix readme --- packages/run/{ => lib}/index.js | 0 packages/run/package.json | 7 +++++-- packages/run/test/fixtures/change-detect-input.js | 2 +- packages/run/test/test.js | 9 +++++---- 4 files changed, 11 insertions(+), 7 deletions(-) rename packages/run/{ => lib}/index.js (100%) diff --git a/packages/run/index.js b/packages/run/lib/index.js similarity index 100% rename from packages/run/index.js rename to packages/run/lib/index.js diff --git a/packages/run/package.json b/packages/run/package.json index 57d6b2dae..e1392ccb6 100644 --- a/packages/run/package.json +++ b/packages/run/package.json @@ -10,7 +10,7 @@ "author": "Rich Harris", "homepage": "https://github.com/rollup/plugins/packages/run/#readme", "bugs": "https://github.com/rollup/plugins/issues", - "main": "index.js", + "main": "lib/index.js", "scripts": { "ci:coverage": "nyc pnpm run test && nyc report --reporter=text-lcov > coverage.lcov", "ci:lint": "pnpm run lint && pnpm run security", @@ -18,12 +18,15 @@ "ci:test": "pnpm run test -- --verbose", "lint": "pnpm run lint:js && pnpm run lint:docs && pnpm run lint:package", "lint:docs": "prettier --single-quote --write README.md", - "lint:js": "eslint --fix --cache *.js", + "lint:js": "eslint --fix --cache lib test", "lint:package": "prettier --write package.json --plugin=prettier-plugin-package", "prepublishOnly": "pnpm run lint && pnpm run test", "security": "echo 'pnpm needs `npm audit` support'", "test": "ava" }, + "files": [ + "lib" + ], "keywords": [ "rollup", "plugin", diff --git a/packages/run/test/fixtures/change-detect-input.js b/packages/run/test/fixtures/change-detect-input.js index 93c705970..83a20c5af 100644 --- a/packages/run/test/fixtures/change-detect-input.js +++ b/packages/run/test/fixtures/change-detect-input.js @@ -1 +1 @@ -export const Greeting = () => 'Hola'; // eslint-disable-line +export const Greeting = () => 'Hola'; // eslint-disable-line \ No newline at end of file diff --git a/packages/run/test/test.js b/packages/run/test/test.js index c4bc79764..a20e1441b 100644 --- a/packages/run/test/test.js +++ b/packages/run/test/test.js @@ -5,14 +5,14 @@ const { join } = require('path'); const childProcess = require('child_process'); +const writeFile = require('util').promisify(fs.writeFile); + const del = require('del'); const { rollup } = require('rollup'); const test = require('ava'); const sinon = require('sinon'); -const writeFile = require('util').promisify(fs.writeFile); - -const run = require('..'); +const run = require('../lib/'); const cwd = join(__dirname, 'fixtures/'); const file = join(cwd, 'output/bundle.js'); @@ -70,13 +70,14 @@ test('throws an error when bundle is not written to disk', async (t) => { }); test('detects changes - forks a new child process and kills older process', async (t) => { + // eslint-disable-next-line no-shadow const input = join(cwd, 'change-detect-input.js'); const bundle = await rollup({ input, plugins: [run()] }); await bundle.write(outputOptions); - await writeFile(input, 'export const Greeting = () => "Hola"'); + await writeFile(input, "export const Greeting = () => 'Hola'; // eslint-disable-line"); await bundle.write(outputOptions); t.true(mockChildProcess.calledWithExactly(outputOptions.file, [], {})); t.is(mockChildProcess().kill.callCount, 1); From d9716990593a6d9e6eb93067fb7d189969ace76f Mon Sep 17 00:00:00 2001 From: Shriram Balaji Date: Thu, 21 Nov 2019 22:28:59 +0530 Subject: [PATCH 13/14] chore: fix pull_request template deviate from master --- .github/PULL_REQUEST_TEMPLATE.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 1d3197801..3cf0b5fa9 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -14,11 +14,9 @@ --> - ## Rollup Plugin Name: `{name}` This PR contains: - - [ ] bugfix - [ ] feature - [ ] refactor @@ -26,13 +24,11 @@ This PR contains: - [ ] other Are tests included? - -- [ ] yes (_bugfixes and features will not be merged without tests_) +- [ ] yes (*bugfixes and features will not be merged without tests*) - [ ] no Breaking Changes? - -- [ ] yes (_breaking changes will not be merged unless absolutely necessary_) +- [ ] yes (*breaking changes will not be merged unless absolutely necessary*) - [ ] no List any relevant issue numbers: From 841bf4c56731ed6c325bd5714e6b1abb399888c5 Mon Sep 17 00:00:00 2001 From: Shriram Balaji Date: Thu, 21 Nov 2019 17:09:30 +0000 Subject: [PATCH 14/14] deps: fix pnpm lockfile issue --- pnpm-lock.yaml | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fe2e7ae1f..3d88c1b50 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,7 +14,7 @@ importers: pnpm: 4.3.0 prettier: 1.19.1 prettier-plugin-package: 0.3.1_prettier@1.19.1 - rollup: 1.27.2 + rollup: 1.27.3 tslib: 1.10.0 tslint: 5.20.1_typescript@3.7.2 typescript: 3.7.2 @@ -1070,7 +1070,7 @@ packages: dependencies: '@types/events': 3.0.0 '@types/minimatch': 3.0.3 - '@types/node': 12.12.9 + '@types/node': 12.12.11 dev: true resolution: integrity: sha512-1Bh06cbWJUHMC97acuD6UMG29nMt0Aqz1vF3guLfG+kHHJhy3AyohZFFxYk2f7Q1SQIrNwvncxAE0N/9s70F2w== @@ -1086,10 +1086,6 @@ packages: dev: true resolution: integrity: sha512-XLla8N+iyfjvsa0KKV+BP/iGSoTmwxsu5Ci5sM33z9TjohF72DEz95iNvD6pPmemvbQgxAv/909G73gUn8QR7w== - /@types/node/12.12.9: - dev: true - resolution: - integrity: sha512-kV3w4KeLsRBW+O2rKhktBwENNJuqAUQHS3kf4ia2wIaF/MN6U7ANgTsx7tGremcA0Pk3Yh0Hl0iKiLPuBdIgmw== /@types/normalize-package-data/2.4.0: dev: true resolution: @@ -2229,7 +2225,7 @@ packages: dependencies: is-callable: 1.1.4 is-date-object: 1.0.1 - is-symbol: 1.0.2 + is-symbol: 1.0.3 dev: true engines: node: '>= 0.4' @@ -3219,14 +3215,14 @@ packages: node: '>=8' resolution: integrity: sha512-XCoy+WlUr7d1+Z8GgSuXmpuUFC9fOhRXglJMx+dwLKTkL44Cjd4W1Z5P+BQZpr+cR93aGP4S/s7Ftw6Nd/kiEw== - /is-symbol/1.0.2: + /is-symbol/1.0.3: dependencies: has-symbols: 1.0.1 dev: true engines: node: '>= 0.4' resolution: - integrity: sha512-HS8bZ9ox60yCJLH9snBpIwv9pYUAkcuLhSA1oero1UB5y9aiQpRA8y2ex945AOtCZL1lJDeIk3G5LthswI46Lw== + integrity: sha512-OwijhaRSgqvhm/0ZdAcXNZt9lYdKFpcRDT5ULUuYXPoT794UNOdU+gpT6Rzo7b4V2HUl/op6GqY894AZwv9faQ== /is-typedarray/1.0.0: dev: true resolution: @@ -4805,6 +4801,15 @@ packages: hasBin: true resolution: integrity: sha512-yaMna4MJ8LLEHhHl1ilgHakylf0LKeQctDxhngZLQ+W57GnXa5vtH7XKaK8zlAhNEhlWiH5YFVFt+QCDPUmNkw== + /rollup/1.27.2: + dependencies: + '@types/estree': 0.0.39 + '@types/node': 12.12.11 + acorn: 7.1.0 + dev: true + hasBin: true + resolution: + integrity: sha512-sD3iyd0zlvgK1S3MmICi6F/Y+R/QWY5XxzsTGN4pAd+nCasDUizmAhgq2hdh1t2eLux974NHU2TW41fhuGPv+Q== /rollup/1.27.3: dependencies: '@types/estree': 0.0.39