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

Introduce new parameter --post-compile, to allow custom script after typescript compilation #22

Merged
merged 6 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
test: cover case of a post-compile script with cjs
  • Loading branch information
Palaxx committed Mar 21, 2024
commit 4aee1c9c06f5ad6cdd9c59f3a66e7418a460533e
3 changes: 3 additions & 0 deletions fixtures/ts-cjs-post-compile/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
1 change: 1 addition & 0 deletions fixtures/ts-cjs-post-compile/postCompile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Doing stuff')
4 changes: 4 additions & 0 deletions fixtures/ts-cjs-post-compile/src/add.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

export function add (x: number, y: number): number {
return x + y
}
7 changes: 7 additions & 0 deletions fixtures/ts-cjs-post-compile/test/add.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { test } from 'node:test'
import { add } from '../src/add.js'
import { strictEqual } from 'node:assert'

test('add', () => {
strictEqual(add(1, 2), 3)
})
7 changes: 7 additions & 0 deletions fixtures/ts-cjs-post-compile/test/add2.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { test } from 'node:test'
import { add } from '../src/add.js'
import { strictEqual } from 'node:assert'

test('add2', () => {
strictEqual(add(3, 2), 5)
})
24 changes: 24 additions & 0 deletions fixtures/ts-cjs-post-compile/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"outDir": "dist",
"sourceMap": true,
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"strict": true,
"resolveJsonModule": true,
"removeComments": true,
"newLine": "lf",
"noUnusedLocals": true,
"noFallthroughCasesInSwitch": true,
"isolatedModules": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true,
"lib": [
"ESNext"
],
"incremental": true
}
}
2 changes: 1 addition & 1 deletion lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export default async function runWithTypeScript (config) {
let outDir = ''
if (config['post-compile'] && tsconfigPath) {
const tsconfig = JSON.parse(await readFile(tsconfigPath))
outDir = tsconfig.compilerOptions.outDir ?? ''
outDir = tsconfig.compilerOptions.outDir
}
let start = Date.now()
tscChild = execa('node', [tscPath, ...typescriptCliArgs], { cwd })
Expand Down
13 changes: 12 additions & 1 deletion test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ test('gh reporter', async () => {
strictEqual(stdout.indexOf('::notice') >= 0, true)
})

test('post-compile hook should be correctly called', async () => {
test('Post compile script should be executed when --post-compile is sent with esm', async () => {
const cwd = join(import.meta.url, '..', 'fixtures', 'ts-esm-post-compile')
const { stdout } = await execa('node', [
borp,
Expand All @@ -100,3 +100,14 @@ test('post-compile hook should be correctly called', async () => {

strictEqual(stdout.indexOf('Post compile hook complete') >= 0, true, 'Post compile message should be found in stdout')
})

test('Post compile script should be executed when --post-compile is sent with cjs', async () => {
const { stdout } = await execa('node', [
borp,
'--post-compile=postCompile.ts'
], {
cwd: join(import.meta.url, '..', 'fixtures', 'ts-cjs-post-compile')
})

strictEqual(stdout.indexOf('Post compile hook complete') >= 0, true, 'Post compile message should be found in stdout')
})
2 changes: 1 addition & 1 deletion test/watch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ test('add', () => {
await completed
})

test('watch with post compile hook', async (t) => {
test('watch with post compile hook should call the hook the right number of times', async (t) => {
const { strictEqual, completed, ok } = tspl(t, { plan: 2 })

const dir = path.resolve(await mkdtemp('.test-watch-with-post-compile-hook'))
Expand Down
Loading