Skip to content

Commit

Permalink
feat(minor): use shell option for complex commands in onSuccess (#649)
Browse files Browse the repository at this point in the history
  • Loading branch information
jgoux committed Jun 10, 2022
1 parent 36e2199 commit be48b8b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 36 deletions.
5 changes: 2 additions & 3 deletions package.json
Expand Up @@ -58,7 +58,6 @@
"resolve": "1.20.0",
"rollup-plugin-dts": "4.2.1",
"rollup-plugin-hashbang": "2.2.2",
"string-argv": "0.3.1",
"strip-json-comments": "4.0.0",
"svelte": "3.46.4",
"ts-essentials": "9.1.2",
Expand All @@ -69,9 +68,9 @@
"wait-for-expect": "3.0.2"
},
"peerDependencies": {
"typescript": "^4.1.0",
"@swc/core": "^1",
"postcss": "^8.4.12",
"@swc/core": "^1"
"typescript": "^4.1.0"
},
"peerDependenciesMeta": {
"typescript": {
Expand Down
7 changes: 0 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 15 additions & 19 deletions src/index.ts
Expand Up @@ -7,7 +7,6 @@ import { loadTsupConfig } from './load'
import glob from 'globby'
import { loadTsConfig } from 'bundle-require'
import { handleError, PrettyError } from './errors'
import { parseArgsStringToArgv } from 'string-argv'
import type { ChildProcess } from 'child_process'
import execa from 'execa'
import kill from 'tree-kill'
Expand All @@ -29,9 +28,9 @@ export const defineConfig = (
| Options
| Options[]
| ((
/** The options derived from CLI flags */
overrideOptions: Options
) => MaybePromise<Options | Options[]>)
/** The options derived from CLI flags */
overrideOptions: Options
) => MaybePromise<Options | Options[]>)
) => options

const killProcess = ({
Expand Down Expand Up @@ -68,8 +67,8 @@ const normalizeOptions = async (
? {}
: undefined
: typeof _options.dts === 'string'
? { entry: _options.dts }
: _options.dts,
? { entry: _options.dts }
: _options.dts,
}

setSilent(options.silent)
Expand Down Expand Up @@ -121,9 +120,9 @@ export async function build(_options: Options) {
_options.config === false
? {}
: await loadTsupConfig(
process.cwd(),
_options.config === true ? undefined : _options.config
)
process.cwd(),
_options.config === true ? undefined : _options.config
)

const configData =
typeof config.data === 'function'
Expand Down Expand Up @@ -244,10 +243,8 @@ export async function build(_options: Options) {
])
await killPromise
if (options.onSuccess) {
const parts = parseArgsStringToArgv(options.onSuccess)
const exec = parts[0]
const args = parts.splice(1)
existingOnSuccess = execa(exec, args, {
existingOnSuccess = execa(options.onSuccess, {
shell: true,
stdio: 'inherit',
})
}
Expand All @@ -274,17 +271,16 @@ export async function build(_options: Options) {
typeof options.watch === 'boolean'
? '.'
: Array.isArray(options.watch)
? options.watch.filter(
? options.watch.filter(
(path): path is string => typeof path === 'string'
)
: options.watch
: options.watch

logger.info(
'CLI',
`Watching for changes in ${
Array.isArray(watchPaths)
? watchPaths.map((v) => '"' + v + '"').join(' | ')
: '"' + watchPaths + '"'
`Watching for changes in ${Array.isArray(watchPaths)
? watchPaths.map((v) => '"' + v + '"').join(' | ')
: '"' + watchPaths + '"'
}`
)
logger.info(
Expand Down
14 changes: 7 additions & 7 deletions test/index.test.ts
Expand Up @@ -279,7 +279,7 @@ test('import css', async () => {
`,
'foo.css': `
$color: blue;
.foo {
color: $color;
}
Expand All @@ -297,7 +297,7 @@ test('import css in --dts', async () => {
'input.ts': `
import './foo.css'
`,
'foo.css': `
'foo.css': `
.foo {
color: blue
}
Expand Down Expand Up @@ -425,18 +425,18 @@ test('svelte: typescript support', async () => {
})

test('onSuccess', async () => {
const randomNumber = Math.random() + ''
const { logs } = await run(
getTestName(),
{
'input.ts': "console.log('test');",
},
{
flags: ['--onSuccess', 'echo ' + randomNumber],
flags: ['--onSuccess', 'echo hello && echo world'],
}
)

expect(logs.includes(randomNumber)).toEqual(true)
expect(logs.includes("hello")).toEqual(true)
expect(logs.includes("world")).toEqual(true)
})

test('support baseUrl and paths in tsconfig.json', async () => {
Expand Down Expand Up @@ -751,7 +751,7 @@ test('es5 target', async () => {
export class Foo {
hi (): void {
let a = () => 'foo'
console.log(a())
}
}
Expand Down Expand Up @@ -848,7 +848,7 @@ test('use rollup for treeshaking', async () => {
getTestName(),
{
'input.ts': `
export { useRoute } from 'vue-router'
export { useRoute } from 'vue-router'
`,
},
{
Expand Down

0 comments on commit be48b8b

Please sign in to comment.