From 77694f41c4e1b8772c9d067f27715ab9e55d59f9 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Thu, 2 Jan 2020 11:23:14 +0100 Subject: [PATCH] Switch stdin to a regular two-state flag --- cli/run/index.ts | 5 +---- docs/01-command-line-reference.md | 12 ++++-------- .../stdin/force-stdin-config-file/_config.js | 5 ----- .../force-stdin-config-file/_expected/cjs.js | 3 --- .../force-stdin-config-file/_expected/esm.js | 1 - .../samples/stdin/force-stdin-config-file/a.mjs | 1 - .../samples/stdin/force-stdin-config-file/b.mjs | 1 - .../force-stdin-config-file/rollup.config.js | 16 ---------------- test/cli/samples/stdin/self-import/_config.js | 2 +- 9 files changed, 6 insertions(+), 40 deletions(-) delete mode 100644 test/cli/samples/stdin/force-stdin-config-file/_config.js delete mode 100644 test/cli/samples/stdin/force-stdin-config-file/_expected/cjs.js delete mode 100644 test/cli/samples/stdin/force-stdin-config-file/_expected/esm.js delete mode 100644 test/cli/samples/stdin/force-stdin-config-file/a.mjs delete mode 100644 test/cli/samples/stdin/force-stdin-config-file/b.mjs delete mode 100644 test/cli/samples/stdin/force-stdin-config-file/rollup.config.js diff --git a/cli/run/index.ts b/cli/run/index.ts index dca3fc91db1..d44a32a101b 100644 --- a/cli/run/index.ts +++ b/cli/run/index.ts @@ -90,7 +90,7 @@ export default function runRollup(command: any) { .then(configs => execute(configFile, configs, command)) .catch(handleError); } else { - if (!command.input && !process.stdin.isTTY) { + if (!command.input && (command.stdin || !process.stdin.isTTY)) { command.input = stdinName; } return execute(configFile, [{ input: [] }], command); @@ -116,9 +116,6 @@ async function execute( (inputOptions.onwarn as WarningHandler)({ code: 'UNKNOWN_OPTION', message: optionError }); } if (command.stdin !== false) { - if (command.stdin) { - inputOptions.input = stdinName; - } inputOptions.plugins!.push(stdinPlugin()); } await build(inputOptions, outputOptions, warnings, command.silent); diff --git a/docs/01-command-line-reference.md b/docs/01-command-line-reference.md index d9026b457d6..1bc68cd624f 100755 --- a/docs/01-command-line-reference.md +++ b/docs/01-command-line-reference.md @@ -253,7 +253,7 @@ Many options have command line equivalents. In those cases, any arguments passed --silent Don't print warnings --sourcemapExcludeSources Do not include source code in source maps --sourcemapFile Specify bundle position for source maps ---stdin read input from stdin +--no-stdin do not read "-" from stdin --strictDeprecations Throw errors for deprecated features --no-treeshake Disable tree-shaking optimisations --no-treeshake.annotations Ignore pure call annotations @@ -308,13 +308,9 @@ npm run build -- --environment BUILD:development then the config file will receive `process.env.INCLUDE_DEPS === 'true'` and `process.env.BUILD === 'development'`. -#### `--stdin` - -Read input from `stdin` instead of a file. This is the default when no config file is used and no entry point is provided and allows piping content to Rollup. When using a config file, this will replace `input` with what is read from `stdin`. See also [Reading a file from stdin](guide/en/#reading-a-file-from-stdin). - #### `--no-stdin` -Do not read input from `stdin`. Setting this flag will also make sure Rollup interprets `-` as a regular file name instead of interpreting this as the name of `stdin`. See also [Reading a file from stdin](guide/en/#reading-a-file-from-stdin). +Do not read files from `stdin`. Setting this flag will prevent piping content to Rollup and make sure Rollup interprets `-` as a regular file name instead of interpreting this as the name of `stdin`. See also [Reading a file from stdin](guide/en/#reading-a-file-from-stdin). ### Reading a file from stdin @@ -324,12 +320,12 @@ When using the command line interface, Rollup can also read content from stdin: echo "export const foo = 42;" | rollup --format cjs --file out.js ``` -When this file contains imports, Rollup will try to resolve them relative to the current working directory. When a config file is used, Rollup will only use `stdin` as an entry point if either the entry point is called `-` or you pass the [`--stdin`](guide/en/#--stdin) flag. To read a non-entry-point file from stdin, just call it `-`, which is the file name that is used internally to reference `stdin`. I.e. +When this file contains imports, Rollup will try to resolve them relative to the current working directory. When a config file is used, Rollup will only use `stdin` as an entry point if the file name of the entry point is `-`. To read a non-entry-point file from stdin, just call it `-`, which is the file name that is used internally to reference `stdin`. I.e. ```js import foo from "-"; ``` -in any file will prompt Rollup to try to read the imported file from `stdin`. You can pass the [`--no-stdin`](guide/en/#--no-stdin) CLI flag to Rollup to treat `-` as a regular file name instead. +in any file will prompt Rollup to try to read the imported file from `stdin` and assign the default export to `foo`. You can pass the [`--no-stdin`](guide/en/#--no-stdin) CLI flag to Rollup to treat `-` as a regular file name instead. The JavaScript API will always treat `-` as a regular file name. diff --git a/test/cli/samples/stdin/force-stdin-config-file/_config.js b/test/cli/samples/stdin/force-stdin-config-file/_config.js deleted file mode 100644 index 5323c73518f..00000000000 --- a/test/cli/samples/stdin/force-stdin-config-file/_config.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - description: 'allows forcing inputs to be replaced with stdin in config files', - skipIfWindows: true, - command: `echo "console.log('STDIN');" | rollup -c --stdin` -}; diff --git a/test/cli/samples/stdin/force-stdin-config-file/_expected/cjs.js b/test/cli/samples/stdin/force-stdin-config-file/_expected/cjs.js deleted file mode 100644 index bc242a09457..00000000000 --- a/test/cli/samples/stdin/force-stdin-config-file/_expected/cjs.js +++ /dev/null @@ -1,3 +0,0 @@ -'use strict'; - -console.log('STDIN'); diff --git a/test/cli/samples/stdin/force-stdin-config-file/_expected/esm.js b/test/cli/samples/stdin/force-stdin-config-file/_expected/esm.js deleted file mode 100644 index 3b4b7713c4b..00000000000 --- a/test/cli/samples/stdin/force-stdin-config-file/_expected/esm.js +++ /dev/null @@ -1 +0,0 @@ -console.log('STDIN'); diff --git a/test/cli/samples/stdin/force-stdin-config-file/a.mjs b/test/cli/samples/stdin/force-stdin-config-file/a.mjs deleted file mode 100644 index b5f9995934e..00000000000 --- a/test/cli/samples/stdin/force-stdin-config-file/a.mjs +++ /dev/null @@ -1 +0,0 @@ -console.log('IGNORED'); diff --git a/test/cli/samples/stdin/force-stdin-config-file/b.mjs b/test/cli/samples/stdin/force-stdin-config-file/b.mjs deleted file mode 100644 index b5f9995934e..00000000000 --- a/test/cli/samples/stdin/force-stdin-config-file/b.mjs +++ /dev/null @@ -1 +0,0 @@ -console.log('IGNORED'); diff --git a/test/cli/samples/stdin/force-stdin-config-file/rollup.config.js b/test/cli/samples/stdin/force-stdin-config-file/rollup.config.js deleted file mode 100644 index 00fe8ee6c43..00000000000 --- a/test/cli/samples/stdin/force-stdin-config-file/rollup.config.js +++ /dev/null @@ -1,16 +0,0 @@ -export default [ - { - input: 'b.mjs', - output: { - file: '_actual/cjs.js', - format: 'cjs' - } - }, - { - input: 'a.mjs', - output: { - file: '_actual/esm.js', - format: 'esm' - } - } -]; diff --git a/test/cli/samples/stdin/self-import/_config.js b/test/cli/samples/stdin/self-import/_config.js index 3d7e72bbe4e..0d03f53502f 100644 --- a/test/cli/samples/stdin/self-import/_config.js +++ b/test/cli/samples/stdin/self-import/_config.js @@ -1,5 +1,5 @@ module.exports = { description: 'stdin input of code that imports a copy of itself', skipIfWindows: true, - command: `shx mkdir -p _actual && shx cat input.txt | rollup -f cjs --silent` + command: `cat input.txt | rollup -f cjs --silent` };