Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(minor): use shell option for complex commands in onSuccess #649

Merged
merged 1 commit into from Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the interesting change. 😄

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