From 89f82585100b4ac6d354e8ea84e6fef307115f0c Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Sat, 11 Jan 2025 23:15:00 +0000 Subject: [PATCH 1/2] fix: throw when errors are encountered --- scripts/release.mjs | 5 ++++- src/commands/devtools.ts | 1 + src/commands/preview.ts | 5 ++++- src/commands/typecheck.ts | 12 ++++++++++-- test/e2e/commands.spec.ts | 4 ++++ 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/scripts/release.mjs b/scripts/release.mjs index 45e6a216d..e9a599a4c 100644 --- a/scripts/release.mjs +++ b/scripts/release.mjs @@ -27,4 +27,7 @@ for (const [DISTRIBUTION, pkg] of Object.entries(distributions)) { } // clean up -x('git', ['restore', 'package.json']) +x('git', ['restore', 'package.json'], { + nodeOptions: { stdio: 'inherit' }, + throwOnError: true, +}) diff --git a/src/commands/devtools.ts b/src/commands/devtools.ts index bf0ed6ecb..37cc61709 100644 --- a/src/commands/devtools.ts +++ b/src/commands/devtools.ts @@ -33,6 +33,7 @@ export default defineCommand({ 'npx', ['@nuxt/devtools-wizard@latest', ctx.args.command, cwd], { + throwOnError: true, nodeOptions: { stdio: 'inherit', cwd, diff --git a/src/commands/preview.ts b/src/commands/preview.ts index cd16aaa89..e25f48b8f 100644 --- a/src/commands/preview.ts +++ b/src/commands/preview.ts @@ -102,6 +102,9 @@ export default defineCommand({ logger.info(`Starting preview command: \`${nitroJSON.commands.preview}\``) const [command, ...commandArgs] = nitroJSON.commands.preview.split(' ') logger.log('') - await x(command, commandArgs, { nodeOptions: { stdio: 'inherit', cwd: outputPath } }) + await x(command, commandArgs, { + throwOnError: true, + nodeOptions: { stdio: 'inherit', cwd: outputPath }, + }) }, }) diff --git a/src/commands/typecheck.ts b/src/commands/typecheck.ts index a657e425a..d584e9ce5 100644 --- a/src/commands/typecheck.ts +++ b/src/commands/typecheck.ts @@ -48,6 +48,7 @@ export default defineCommand({ ]) if (resolvedTypeScript && resolvedVueTsc) { await x(fileURLToPath(resolvedVueTsc), ['--noEmit'], { + throwOnError: true, nodeOptions: { stdio: 'inherit', cwd, @@ -59,10 +60,14 @@ export default defineCommand({ await x( 'bun', 'install typescript vue-tsc --global --silent'.split(' '), - { nodeOptions: { stdio: 'inherit', cwd } }, + { + throwOnError: true, + nodeOptions: { stdio: 'inherit', cwd }, + }, ) await x('bunx', 'vue-tsc --noEmit'.split(' '), { + throwOnError: true, nodeOptions: { stdio: 'inherit', cwd, @@ -73,7 +78,10 @@ export default defineCommand({ await x( 'npx', '-p vue-tsc -p typescript vue-tsc --noEmit'.split(' '), - { nodeOptions: { stdio: 'inherit', cwd } }, + { + throwOnError: true, + nodeOptions: { stdio: 'inherit', cwd }, + }, ) } } diff --git a/test/e2e/commands.spec.ts b/test/e2e/commands.spec.ts index a1390e993..30541dccf 100644 --- a/test/e2e/commands.spec.ts +++ b/test/e2e/commands.spec.ts @@ -20,6 +20,7 @@ describe('commands', () => { const file = join(fixtureDir, 'server/api/test.ts') await rm(file, { force: true }) await x('nuxi', ['add', 'api', 'test'], { + throwOnError: true, nodeOptions: { stdio: 'pipe', cwd: fixtureDir }, }) expect(existsSync(file)).toBeTruthy() @@ -45,6 +46,7 @@ describe('commands', () => { await rm(installPath, { recursive: true, force: true }) try { await x('nuxi', ['init', installPath, `--packageManager=${pm}`, '--gitInit=false', '--preferOffline', '--install=false'], { + throwOnError: true, nodeOptions: { stdio: 'inherit', cwd: fixtureDir }, }) const files = await readdir(installPath).catch(() => []) @@ -60,6 +62,7 @@ describe('commands', () => { it('throws error if no command is provided', async () => { const res = await x('nuxi', [], { + throwOnError: true, nodeOptions: { stdio: 'pipe', cwd: fixtureDir }, }) expect(res.exitCode).toBe(1) @@ -69,6 +72,7 @@ describe('commands', () => { // TODO: FIXME - windows currently throws 'nuxt-foo' is not recognized as an internal or external command, operable program or batch file. it.skipIf(isWindows)('throws error if wrong command is provided', async () => { const res = await x('nuxi', ['foo'], { + throwOnError: true, nodeOptions: { stdio: 'pipe', cwd: fixtureDir }, }) expect(res.exitCode).toBe(1) From a714ab373e1aeb423080ae5424b70bb58fc261c0 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Sat, 11 Jan 2025 23:18:58 +0000 Subject: [PATCH 2/2] chore: except tests we expect to fail --- test/e2e/commands.spec.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/e2e/commands.spec.ts b/test/e2e/commands.spec.ts index 30541dccf..5ef76211a 100644 --- a/test/e2e/commands.spec.ts +++ b/test/e2e/commands.spec.ts @@ -62,7 +62,6 @@ describe('commands', () => { it('throws error if no command is provided', async () => { const res = await x('nuxi', [], { - throwOnError: true, nodeOptions: { stdio: 'pipe', cwd: fixtureDir }, }) expect(res.exitCode).toBe(1) @@ -72,7 +71,6 @@ describe('commands', () => { // TODO: FIXME - windows currently throws 'nuxt-foo' is not recognized as an internal or external command, operable program or batch file. it.skipIf(isWindows)('throws error if wrong command is provided', async () => { const res = await x('nuxi', ['foo'], { - throwOnError: true, nodeOptions: { stdio: 'pipe', cwd: fixtureDir }, }) expect(res.exitCode).toBe(1)