Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement stdin input with optional "-" as the file name. Set default output format to "es" to save CLI typing for the most common case. closes #1440 closes #3276 * * Test if we can delete process.stdin on CI * Only allow '-' to use stdin with the JS API * Use locally installed shx * Add test for stdin read error * * Only allow stdin via the CLI * Move stdin logic to CLI * Only use stdin as input by default when there is no config file * * Allow using "-" as a regular file name with --no-stdin CLI flag * Override input with stdin with --stdin CLI flag * * Add documentation * Avoid using shx * Skip tests on Windows * Switch stdin to a regular two-state flag * Fix Windows tests Co-authored-by: kzc <kzc@users.noreply.github.com>
- Loading branch information
1 parent
6106af1
commit 42fe317
Showing
50 changed files
with
235 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Plugin } from '../../src/rollup/types'; | ||
|
||
export const stdinName = '-'; | ||
|
||
let stdinResult: Promise<string> | null = null; | ||
|
||
export function stdinPlugin(): Plugin { | ||
return { | ||
name: 'stdin', | ||
resolveId(id) { | ||
if (id === stdinName) { | ||
return id; | ||
} | ||
}, | ||
load(id) { | ||
if (id === stdinName) { | ||
return stdinResult || (stdinResult = readStdin()); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
function readStdin(): Promise<string> { | ||
return new Promise((resolve, reject) => { | ||
const chunks: Buffer[] = []; | ||
process.stdin.setEncoding('utf8'); | ||
process.stdin | ||
.on('data', chunk => chunks.push(chunk)) | ||
.on('end', () => { | ||
const result = chunks.join(''); | ||
resolve(result); | ||
}) | ||
.on('error', err => { | ||
reject(err); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.