Skip to content

Commit

Permalink
Add new optional param name of plugin-run-script (#1414)
Browse files Browse the repository at this point in the history
* Add new optional param name of plugin-run-script

Its useful run two same cli.

In old case, i cannot make a distinction between those

* add testcase of plugin-run-script name
  • Loading branch information
moonrailgun authored Oct 27, 2020
1 parent 71f07ba commit b0d7b09
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions plugins/plugin-run-script/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ Supply any CLI command in `cmd`. Note that this is the same as running the comma
| Name | Type | Description |
| :------- | :-------: | :-------------------------------------------------------------------------- |
| `cmd` | `string` | The CLI command to run. Note that this will run **before** Snowpack builds. |
| `name` | `string` | (optional) Set name of console output, default is program name. |
| `watch` | `string` | (optional) A watch command to run during the dev server. |
| `output` | `"stream" | "dashboard"` | (optional) Set how the output should be recorded during dev. |
4 changes: 2 additions & 2 deletions plugins/plugin-run-script/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ const execa = require('execa');
const npmRunPath = require('npm-run-path');
const cwd = process.cwd();

function runScriptPlugin(_, {cmd, watch, output}) {
function runScriptPlugin(_, {name, cmd, watch, output}) {
const [cmdProgram] = cmd.split(' ');
const watchCmd = watch && watch.replace('$1', cmd);

return {
name: cmdProgram,
name: name || cmdProgram,
async run({isDev, log}) {
const workerPromise = execa.command(isDev ? watchCmd || cmd : cmd, {
env: npmRunPath.env(),
Expand Down
10 changes: 6 additions & 4 deletions plugins/plugin-run-script/test/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ const {EventEmitter} = require('events');
jest.mock('execa');
const execa = require('execa');

// NOTE(fks): This is skipped due to refactoring happening in https://github.com/snowpackjs/snowpack/pull/1203
// Once that PR is merged, this should be safe to unskip
describe.skip('plugin-run-script', () => {
describe('plugin-run-script', () => {
const DEFAULT_OPTIONS = {
cmd: 'CMD',
watch: '$1 --additional-test-watch-options',
Expand All @@ -33,7 +31,7 @@ describe.skip('plugin-run-script', () => {
test('calls the given "watch" command when isDev=true', async () => {
const p = plugin(null, {cmd: 'CMD', watch: '$1 --additional-test-watch-options'});
await p.run({isDev: true, log: jest.fn});
expect(execaFn.mock.calls[0][0]).toMatch('cmd --additional-test-watch-options');
expect(execaFn.mock.calls[0][0]).toMatch('CMD --additional-test-watch-options');
});
test('handles command output in "stream" mode', async () => {
const logFn = jest.fn();
Expand Down Expand Up @@ -70,4 +68,8 @@ describe.skip('plugin-run-script', () => {
['WORKER_MSG', {level: 'log', msg: 'TEST_CLEAR_MESSAGE'}],
]);
});
test('modify plugin name when specify name', async() => {
const p = plugin(null, {...DEFAULT_OPTIONS, output: 'dashboard', name: 'test'});
expect(p.name).toBe('test')
})
});

1 comment on commit b0d7b09

@vercel
Copy link

@vercel vercel bot commented on b0d7b09 Oct 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.