Skip to content

Commit

Permalink
Switch stdin to a regular two-state flag
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jan 4, 2020
1 parent 0b70094 commit 77694f4
Show file tree
Hide file tree
Showing 9 changed files with 6 additions and 40 deletions.
5 changes: 1 addition & 4 deletions cli/run/index.ts
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
12 changes: 4 additions & 8 deletions docs/01-command-line-reference.md
Expand Up @@ -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 <file> 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
Expand Down Expand Up @@ -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

Expand All @@ -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.
5 changes: 0 additions & 5 deletions test/cli/samples/stdin/force-stdin-config-file/_config.js

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion test/cli/samples/stdin/force-stdin-config-file/a.mjs

This file was deleted.

1 change: 0 additions & 1 deletion test/cli/samples/stdin/force-stdin-config-file/b.mjs

This file was deleted.

16 changes: 0 additions & 16 deletions test/cli/samples/stdin/force-stdin-config-file/rollup.config.js

This file was deleted.

2 changes: 1 addition & 1 deletion 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`
};

0 comments on commit 77694f4

Please sign in to comment.