borp 0.9.1 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,6 +18,9 @@ jobs:
18
18
  matrix:
19
19
  node-version: [18.x, 20.x, 21.x]
20
20
  os: [ubuntu-latest, windows-latest]
21
+ exclude:
22
+ - os: windows-latest
23
+ node-version: 21.x
21
24
  steps:
22
25
  - uses: actions/checkout@v4
23
26
 
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "project-build",
3
+ "version": "1.0.0",
4
+ "lockfileVersion": 3,
5
+ "requires": true,
6
+ "packages": {
7
+ "": {
8
+ "name": "project-build",
9
+ "version": "1.0.0",
10
+ "license": "ISC",
11
+ "workspaces": [
12
+ "package*"
13
+ ]
14
+ },
15
+ "node_modules/package1": {
16
+ "resolved": "package1",
17
+ "link": true
18
+ },
19
+ "node_modules/package2": {
20
+ "resolved": "package2",
21
+ "link": true
22
+ },
23
+ "package1": {
24
+ "version": "1.0.0",
25
+ "license": "ISC"
26
+ },
27
+ "package2": {
28
+ "version": "1.0.0",
29
+ "license": "ISC",
30
+ "dependencies": {
31
+ "package1": "file:../package1"
32
+ }
33
+ }
34
+ }
35
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "project-build",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "keywords": [],
10
+ "author": "",
11
+ "workspaces": [
12
+ "package*"
13
+ ],
14
+ "license": "ISC"
15
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "package1",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "dist/src/lib/add.js",
6
+ "types": "dist/src/lib/add.d.ts",
7
+ "scripts": {
8
+ "test": "echo \"Error: no test specified\" && exit 1"
9
+ },
10
+ "keywords": [],
11
+ "author": "",
12
+ "license": "ISC"
13
+ }
@@ -0,0 +1,4 @@
1
+
2
+ export function add (x: number, y: number): number {
3
+ return x + y
4
+ }
@@ -0,0 +1,7 @@
1
+ import { test } from 'node:test'
2
+ import { add } from '../lib/add.js'
3
+ import { strictEqual } from 'node:assert'
4
+
5
+ test('add', () => {
6
+ strictEqual(add(1, 2), 3)
7
+ })
@@ -0,0 +1,7 @@
1
+ import { test } from 'node:test'
2
+ import { add } from '../lib/add.js'
3
+ import { strictEqual } from 'node:assert'
4
+
5
+ test('add2', () => {
6
+ strictEqual(add(3, 2), 5)
7
+ })
@@ -0,0 +1,10 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "../tsconfig.base.json",
4
+ "compilerOptions": {
5
+ "outDir": "./dist"
6
+ },
7
+ "references": [
8
+ ]
9
+ }
10
+
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "package2",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "dependencies": {
10
+ "package1": "file:../package1"
11
+ },
12
+ "keywords": [],
13
+ "author": "",
14
+ "license": "ISC"
15
+ }
@@ -0,0 +1,4 @@
1
+ import { add as add2 } from 'package1'
2
+ export function add (x: number, y: number): number {
3
+ return add2(x, y)
4
+ }
@@ -0,0 +1,7 @@
1
+ import { test } from 'node:test'
2
+ import { add } from '../lib/add.js'
3
+ import { strictEqual } from 'node:assert'
4
+
5
+ test('package2-add', () => {
6
+ strictEqual(add(1, 2), 3)
7
+ })
@@ -0,0 +1,7 @@
1
+ import { test } from 'node:test'
2
+ import { add } from '../lib/add.js'
3
+ import { strictEqual } from 'node:assert'
4
+
5
+ test('package2-add2', () => {
6
+ strictEqual(add(3, 2), 5)
7
+ })
@@ -0,0 +1,11 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "../tsconfig.base.json",
4
+ "compilerOptions": {
5
+ "outDir": "./dist"
6
+ },
7
+ "references": [
8
+ { "path": "../package1" }
9
+ ]
10
+ }
11
+
@@ -0,0 +1,24 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "compilerOptions": {
4
+ "sourceMap": true,
5
+ "target": "ES2022",
6
+ "composite": true,
7
+ "module": "NodeNext",
8
+ "moduleResolution": "NodeNext",
9
+ "esModuleInterop": true,
10
+ "strict": true,
11
+ "resolveJsonModule": true,
12
+ "removeComments": true,
13
+ "newLine": "lf",
14
+ "noUnusedLocals": true,
15
+ "noFallthroughCasesInSwitch": true,
16
+ "isolatedModules": true,
17
+ "forceConsistentCasingInFileNames": true,
18
+ "skipLibCheck": true,
19
+ "lib": [
20
+ "ESNext"
21
+ ],
22
+ "incremental": true
23
+ }
24
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "files": [],
3
+ "references": [
4
+ { "path": "package1" },
5
+ { "path": "package2" }
6
+ ]
7
+ }
package/lib/run.js CHANGED
@@ -27,8 +27,10 @@ export default async function runWithTypeScript (config) {
27
27
 
28
28
  let prefix = ''
29
29
  let tscPath
30
+ const typescriptCliArgs = []
30
31
 
31
32
  if (tsconfigPath && config.typescript !== false) {
33
+ const tsconfig = JSON.parse(await readFile(tsconfigPath))
32
34
  const _require = createRequire(tsconfigPath)
33
35
  const typescriptPathCWD = _require.resolve('typescript')
34
36
  tscPath = join(typescriptPathCWD, '..', '..', 'bin', 'tsc')
@@ -38,19 +40,22 @@ export default async function runWithTypeScript (config) {
38
40
 
39
41
  // Watch is handled aftterwards
40
42
  if (!config.watch) {
43
+ if (Array.isArray(tsconfig.references) && tsconfig.references.length > 0) {
44
+ typescriptCliArgs.push('--build')
45
+ }
41
46
  const start = Date.now()
42
- await execa('node', [tscPath], { cwd: dirname(tsconfigPath) })
47
+ await execa('node', [tscPath, ...typescriptCliArgs], { cwd: dirname(tsconfigPath) })
43
48
  process.stdout.write(`TypeScript compilation complete (${Date.now() - start}ms)\n`)
44
49
  pushable.push({
45
50
  type: 'test:diagnostic',
46
51
  data: {
47
52
  nesting: 0,
48
- message: `TypeScript compilation complete (${Date.now() - start}ms)`
53
+ message: `TypeScript compilation complete (${Date.now() - start}ms)`,
54
+ typescriptCliArgs
49
55
  }
50
56
  })
51
57
  }
52
58
  }
53
- const tsconfig = JSON.parse(await readFile(tsconfigPath))
54
59
  const outDir = tsconfig.compilerOptions.outDir
55
60
  if (outDir) {
56
61
  prefix = join(dirname(tsconfigPath), outDir)
@@ -83,17 +88,21 @@ export default async function runWithTypeScript (config) {
83
88
  let p
84
89
 
85
90
  if (config.watch) {
91
+ typescriptCliArgs.push('--watch')
86
92
  p = deferred()
87
- const start = Date.now()
88
- tscChild = execa('node', [tscPath, '--watch'], { cwd })
93
+ let start = Date.now()
94
+ tscChild = execa('node', [tscPath, ...typescriptCliArgs], { cwd })
89
95
  tscChild.stdout.setEncoding('utf8')
90
96
  tscChild.stdout.on('data', (data) => {
91
- if (data.includes('Watching for file changes')) {
97
+ if (data.includes('File change detected')) {
98
+ start = Date.now()
99
+ } else if (data.includes('Watching for file changes')) {
92
100
  pushable.push({
93
101
  type: 'test:diagnostic',
94
102
  data: {
95
103
  nesting: 0,
96
- message: `TypeScript compilation complete (${Date.now() - start}ms)`
104
+ message: `TypeScript compilation complete (${Date.now() - start}ms)`,
105
+ typescriptCliArgs
97
106
  }
98
107
  })
99
108
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "borp",
3
- "version": "0.9.1",
3
+ "version": "0.10.0",
4
4
  "type": "module",
5
5
  "description": "node:test wrapper with TypeScript support",
6
6
  "main": "borp.js",
@@ -2,6 +2,7 @@ import { test } from 'node:test'
2
2
  import { tspl } from '@matteo.collina/tspl'
3
3
  import runWithTypeScript from '../lib/run.js'
4
4
  import { join } from 'desm'
5
+ import { execa } from 'execa'
5
6
 
6
7
  test('ts-esm', async (t) => {
7
8
  const { strictEqual, completed, match } = tspl(t, { plan: 4 })
@@ -141,7 +142,31 @@ test('src-to-dist', async (t) => {
141
142
 
142
143
  await completed
143
144
  })
145
+ test('monorepo', async (t) => {
146
+ const { strictEqual, completed, match, deepEqual } = tspl(t, { plan: 5 })
147
+ const config = {
148
+ files: [],
149
+ cwd: join(import.meta.url, '..', 'fixtures', 'monorepo/package2')
150
+ }
151
+
152
+ await execa('npm', ['install'], { cwd: join(import.meta.url, '..', 'fixtures', 'monorepo') })
153
+ const stream = await runWithTypeScript(config)
154
+
155
+ const names = new Set(['package2-add', 'package2-add2'])
156
+
157
+ stream.once('data', (test) => {
158
+ strictEqual(test.type, 'test:diagnostic')
159
+ match(test.data.message, /TypeScript compilation complete \(\d+ms\)/)
160
+ deepEqual(test.data.typescriptCliArgs, ['--build'])
161
+ })
144
162
 
163
+ stream.on('test:pass', (test) => {
164
+ strictEqual(names.has(test.name), true)
165
+ names.delete(test.name)
166
+ })
167
+
168
+ await completed
169
+ })
145
170
  test('only-src', async (t) => {
146
171
  const { strictEqual, completed, match } = tspl(t, { plan: 4 })
147
172
  const config = {