Skip to content

Commit

Permalink
use --build also on watch
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdoron committed Mar 3, 2024
1 parent 76d22a9 commit 37e56e3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
14 changes: 9 additions & 5 deletions lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ export default async function runWithTypeScript (config) {

let prefix = ''
let tscPath
const typescriptCliArgs = []

if (tsconfigPath && config.typescript !== false) {
const tsconfig = JSON.parse(await readFile(tsconfigPath))
const typescriptCliArgs = []
const _require = createRequire(tsconfigPath)
const typescriptPathCWD = _require.resolve('typescript')
tscPath = join(typescriptPathCWD, '..', '..', 'bin', 'tsc')
Expand Down Expand Up @@ -88,17 +88,21 @@ export default async function runWithTypeScript (config) {
let p

if (config.watch) {
typescriptCliArgs.push('--watch')
p = deferred()
const start = Date.now()
tscChild = execa('node', [tscPath, '--watch'], { cwd })
let start = Date.now()
tscChild = execa('node', [tscPath, ...typescriptCliArgs], { cwd })
tscChild.stdout.setEncoding('utf8')
tscChild.stdout.on('data', (data) => {
if (data.includes('Watching for file changes')) {
if (data.includes('File change detected')) {
start = Date.now()
} else if (data.includes('Watching for file changes')) {
pushable.push({
type: 'test:diagnostic',
data: {
nesting: 0,
message: `TypeScript compilation complete (${Date.now() - start}ms)`
message: `TypeScript compilation complete (${Date.now() - start}ms)`,
typescriptCliArgs
}
})

Expand Down
6 changes: 2 additions & 4 deletions test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { test } from 'node:test'
import { tspl } from '@matteo.collina/tspl'
import runWithTypeScript from '../lib/run.js'
import { join } from 'desm'
import { exec } from 'node:child_process'
import { promisify } from 'node:util'
const execAsync = promisify(exec)
import { execa } from 'execa'

test('ts-esm', async (t) => {
const { strictEqual, completed, match } = tspl(t, { plan: 4 })
Expand Down Expand Up @@ -151,7 +149,7 @@ test('monorepo', async (t) => {
cwd: join(import.meta.url, '..', 'fixtures', 'monorepo/package2')
}

await execAsync('npm install', { cwd: join(import.meta.url, '..', 'fixtures', 'monorepo') })
await execa('npm', ['install'], { cwd: join(import.meta.url, '..', 'fixtures', 'monorepo') })
const stream = await runWithTypeScript(config)

Check failure on line 153 in test/basic.test.js

View workflow job for this annotation

GitHub Actions / test (18.x, ubuntu-latest)

monorepo

[Error [ERR_TEST_FAILURE]: Command failed with exit code 2: node /home/runner/work/borp/borp/node_modules/typescript/bin/tsc --build src/lib/add.ts(1,29): error TS2307: Cannot find module 'package1' or its corresponding type declarations.] { failureType: 'testCodeFailure', cause: Error: Command failed with exit code 2: node /home/runner/work/borp/borp/node_modules/typescript/bin/tsc --build src/lib/add.ts(1,29): error TS2307: Cannot find module 'package1' or its corresponding type declarations. at makeError (file:///home/runner/work/borp/borp/node_modules/execa/lib/error.js:60:11) at handlePromise (file:///home/runner/work/borp/borp/node_modules/execa/index.js:124:26) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async runWithTypeScript (file:///home/runner/work/borp/borp/lib/run.js:47:9) at async TestContext.<anonymous> (file:///home/runner/work/borp/borp/test/basic.test.js:153:18) at async Test.run (node:internal/test_runner/test:632:9) at async Test.processPendingSubtests (node:internal/test_runner/test:374:7) { shortMessage: 'Command failed with exit code 2: node /home/runner/work/borp/borp/node_modules/typescript/bin/tsc --build', command: 'node /home/runner/work/borp/borp/node_modules/typescript/bin/tsc --build', escapedCommand: 'node "/home/runner/work/borp/borp/node_modules/typescript/bin/tsc" --build', exitCode: 2, signal: undefined, signalDescription: undefined, stdout: "src/lib/add.ts(1,29): error TS2307: Cannot find module 'package1' or its corresponding type declarations.", stderr: '', cwd: '/home/runner/work/borp/borp/fixtures/monorepo/package2', failed: true, timedOut: false, isCanceled: false, killed: false }, code: 'ERR_TEST_FAILURE' }

Check failure on line 153 in test/basic.test.js

View workflow job for this annotation

GitHub Actions / test (20.x, ubuntu-latest)

monorepo

[Error [ERR_TEST_FAILURE]: Command failed with exit code 2: node /home/runner/work/borp/borp/node_modules/typescript/bin/tsc --build src/lib/add.ts(1,29): error TS2307: Cannot find module 'package1' or its corresponding type declarations.] { code: 'ERR_TEST_FAILURE', failureType: 'testCodeFailure', cause: Error: Command failed with exit code 2: node /home/runner/work/borp/borp/node_modules/typescript/bin/tsc --build src/lib/add.ts(1,29): error TS2307: Cannot find module 'package1' or its corresponding type declarations. at makeError (file:///home/runner/work/borp/borp/node_modules/execa/lib/error.js:60:11) at handlePromise (file:///home/runner/work/borp/borp/node_modules/execa/index.js:124:26) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async runWithTypeScript (file:///home/runner/work/borp/borp/lib/run.js:47:9) at async TestContext.<anonymous> (file:///home/runner/work/borp/borp/test/basic.test.js:153:18) at async Test.run (node:internal/test_runner/test:632:9) at async Test.processPendingSubtests (node:internal/test_runner/test:374:7) { shortMessage: 'Command failed with exit code 2: node /home/runner/work/borp/borp/node_modules/typescript/bin/tsc --build', command: 'node /home/runner/work/borp/borp/node_modules/typescript/bin/tsc --build', escapedCommand: 'node "/home/runner/work/borp/borp/node_modules/typescript/bin/tsc" --build', exitCode: 2, signal: undefined, signalDescription: undefined, stdout: "src/lib/add.ts(1,29): error TS2307: Cannot find module 'package1' or its corresponding type declarations.", stderr: '', cwd: '/home/runner/work/borp/borp/fixtures/monorepo/package2', failed: true, timedOut: false, isCanceled: false, killed: false } }

Check failure on line 153 in test/basic.test.js

View workflow job for this annotation

GitHub Actions / test (21.x, ubuntu-latest)

monorepo

[Error [ERR_TEST_FAILURE]: Command failed with exit code 2: node /home/runner/work/borp/borp/node_modules/typescript/bin/tsc --build src/lib/add.ts(1,29): error TS2307: Cannot find module 'package1' or its corresponding type declarations.] { code: 'ERR_TEST_FAILURE', failureType: 'testCodeFailure', cause: Error: Command failed with exit code 2: node /home/runner/work/borp/borp/node_modules/typescript/bin/tsc --build src/lib/add.ts(1,29): error TS2307: Cannot find module 'package1' or its corresponding type declarations. at makeError (file:///home/runner/work/borp/borp/node_modules/execa/lib/error.js:60:11) at handlePromise (file:///home/runner/work/borp/borp/node_modules/execa/index.js:124:26) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async runWithTypeScript (file:///home/runner/work/borp/borp/lib/run.js:47:9) at async TestContext.<anonymous> (file:///home/runner/work/borp/borp/test/basic.test.js:153:18) at async Test.run (node:internal/test_runner/test:632:9) at async Test.processPendingSubtests (node:internal/test_runner/test:374:7) { shortMessage: 'Command failed with exit code 2: node /home/runner/work/borp/borp/node_modules/typescript/bin/tsc --build', command: 'node /home/runner/work/borp/borp/node_modules/typescript/bin/tsc --build', escapedCommand: 'node "/home/runner/work/borp/borp/node_modules/typescript/bin/tsc" --build', exitCode: 2, signal: undefined, signalDescription: undefined, stdout: "src/lib/add.ts(1,29): error TS2307: Cannot find module 'package1' or its corresponding type declarations.", stderr: '', cwd: '/home/runner/work/borp/borp/fixtures/monorepo/package2', failed: true, timedOut: false, isCanceled: false, killed: false } }

const names = new Set(['package2-add', 'package2-add2'])
Expand Down

0 comments on commit 37e56e3

Please sign in to comment.