Skip to content

Commit 72b867f

Browse files
chore: update deps.
1 parent 48aac92 commit 72b867f

File tree

8 files changed

+404
-241
lines changed

8 files changed

+404
-241
lines changed

codecov.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ coverage:
66
threshold: 0.5
77
patch:
88
default:
9-
target: 80.0
109
threshold: 5.0

package-lock.json

Lines changed: 356 additions & 220 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@knighted/duel",
3-
"version": "2.1.0",
3+
"version": "2.1.1",
44
"description": "TypeScript dual packages.",
55
"type": "module",
66
"main": "dist/esm/duel.js",
@@ -66,11 +66,11 @@
6666
"prettier": "^3.4.2",
6767
"tsx": "^4.19.3",
6868
"typescript": "^5.8.2",
69-
"vite": "^6.2.3"
69+
"vite": "^6.2.4"
7070
},
7171
"dependencies": {
72-
"@knighted/module": "^1.0.0-alpha.4",
73-
"@knighted/specifier": "^2.0.0-rc.1",
72+
"@knighted/module": "^1.0.0-alpha.5",
73+
"@knighted/specifier": "^2.0.0",
7474
"find-up": "^6.3.0",
7575
"get-tsconfig": "^4.10.0",
7676
"glob": "^11.0.1",

src/duel.js

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,8 @@ import { getRealPathAsFileUrl, getCompileFiles, logError, log } from './util.js'
1818
const handleErrorAndExit = message => {
1919
const exitCode = Number(message)
2020

21-
if (isNaN(exitCode)) {
22-
logError(message)
23-
process.exit(1)
24-
} else {
25-
logError('Compilation errors found.')
26-
process.exit(exitCode)
27-
}
21+
logError('Compilation errors found.')
22+
process.exit(exitCode)
2823
}
2924
const duel = async args => {
3025
const ctx = await init(args)
@@ -46,10 +41,6 @@ const duel = async args => {
4641
const args = outDir ? ['-p', project, '--outDir', outDir] : ['-p', project]
4742
const build = spawn(tsc, args, { stdio: 'inherit', shell: platform === 'win32' })
4843

49-
build.on('error', err => {
50-
reject(new Error(`Failed to compile: ${err.message}`))
51-
})
52-
5344
build.on('exit', code => {
5445
if (code > 0) {
5546
return reject(new Error(code))
@@ -92,7 +83,7 @@ const duel = async args => {
9283
const outFilename = dts.test(filename)
9384
? filename.replace(dts, isCjsBuild ? '.d.cts' : '.d.mts')
9485
: filename.replace(/\.js$/, targetExt)
95-
const { code, error } = await specifier.update(filename, ({ value }) => {
86+
const update = await specifier.update(filename, ({ value }) => {
9687
// Collapse any BinaryExpression or NewExpression to test for a relative specifier
9788
const collapsed = value.replace(/['"`+)\s]|new String\(/g, '')
9889
const relative = /^(?:\.|\.\.)\//
@@ -103,10 +94,8 @@ const duel = async args => {
10394
}
10495
})
10596

106-
if (code && !error) {
107-
await writeFile(outFilename, code)
108-
await rm(filename, { force: true })
109-
}
97+
await writeFile(outFilename, update)
98+
await rm(filename, { force: true })
11099
}
111100
}
112101
const logSuccess = start => {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "module"
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import.meta.resolve('./foo.js')
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"compilerOptions": {
3+
"module": "NodeNext",
4+
"outDir": "dist"
5+
},
6+
"include": ["./src/index.ts"]
7+
}

test/integration.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ const project = resolve(__dirname, '__fixtures__/project')
1616
const esmProject = resolve(__dirname, '__fixtures__/esmProject')
1717
const cjsProject = resolve(__dirname, '__fixtures__/cjsProject')
1818
const extended = resolve(__dirname, '__fixtures__/extended')
19+
const dualError = resolve(__dirname, '__fixtures__/compileErrorsDual')
1920
const plainDist = join(plain, 'dist')
2021
const proDist = join(project, 'dist')
2122
const esmDist = join(esmProject, 'dist')
2223
const cjsDist = join(cjsProject, 'dist')
2324
const extDist = join(extended, 'dist')
25+
const errDistDual = join(dualError, 'dist')
2426
const errDist = resolve(__dirname, '__fixtures__/compileErrors/dist')
2527
const rmDist = async distPath => {
2628
await rm(distPath, { recursive: true, force: true })
@@ -219,6 +221,32 @@ describe('duel', () => {
219221
assert.equal(spy.mock.calls[1].arguments[1], 'Compilation errors found.')
220222
})
221223

224+
/**
225+
* Check for compilation errors in the dual build.
226+
* This test targets unexpected behavior by tsc:
227+
* @see https://github.com/microsoft/TypeScript/issues/58658
228+
*/
229+
it('reports compile errors for the dual build', async t => {
230+
const spy = t.mock.method(global.console, 'log')
231+
const spyExit = t.mock.method(process, 'exit')
232+
233+
t.after(async () => {
234+
await rmDist(errDistDual)
235+
})
236+
spyExit.mock.mockImplementation(number => {
237+
throw new Error(`Mocked process.exit: ${number}`)
238+
})
239+
await assert.rejects(
240+
async () => {
241+
await duel(['-p', dualError])
242+
},
243+
{ message: /Mocked process\.exit/ },
244+
)
245+
246+
assert.ok(spyExit.mock.calls[0].arguments > 0)
247+
assert.equal(spy.mock.calls[2].arguments[1], 'Compilation errors found.')
248+
})
249+
222250
it('reports an error when no package.json file found', async t => {
223251
const spy = t.mock.method(global.console, 'log')
224252

0 commit comments

Comments
 (0)