From 336719b0939f78828c1e37faf6a1add88fde5a1d Mon Sep 17 00:00:00 2001 From: Kevin Yank Date: Mon, 18 Sep 2023 15:16:01 +1000 Subject: [PATCH 1/4] Fix spelling in error message --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 0eecc990..88c9376b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -176,7 +176,7 @@ export async function build(_options: Options) { }) worker.on('message', (data) => { if (data === 'error') { - reject(new Error('error occured in dts build')) + reject(new Error('error occurred in dts build')) } else if (data === 'success') { resolve() } else { From a43c103f737a063d9a3f3a2f59988d3105a67851 Mon Sep 17 00:00:00 2001 From: Kevin Yank Date: Mon, 18 Sep 2023 15:27:38 +1000 Subject: [PATCH 2/4] Fix error attempting to chmod dts files Fixes #1001 --- src/rollup.ts | 2 -- test/index.test.ts | 58 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 50 insertions(+), 10 deletions(-) diff --git a/src/rollup.ts b/src/rollup.ts index 28672fb2..35fdea1e 100644 --- a/src/rollup.ts +++ b/src/rollup.ts @@ -2,7 +2,6 @@ import { parentPort } from 'worker_threads' import { InputOptions, OutputOptions, Plugin } from 'rollup' import { NormalizedOptions } from './' import ts from 'typescript' -import hashbangPlugin from 'rollup-plugin-hashbang' import jsonPlugin from '@rollup/plugin-json' import { handleError } from './errors' import { defaultOutExtension, removeFiles } from './utils' @@ -167,7 +166,6 @@ const getRollupConfig = async ( plugins: [ tsupCleanPlugin, tsResolveOptions && tsResolvePlugin(tsResolveOptions), - hashbangPlugin(), jsonPlugin(), ignoreFiles, dtsPlugin.default({ diff --git a/test/index.test.ts b/test/index.test.ts index df2c19d7..e22a99ab 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -542,7 +542,7 @@ test('onSuccess: use a function from config file', async () => { await new Promise((resolve) => { setTimeout(() => { console.log('world') - resolve('') + resolve('') }, 1_000) }) } @@ -872,6 +872,38 @@ test('shebang', async () => { }).toThrow() }) +/** + * tsup should not attempt to `chmod +x` type definition files in the output, + * even when their corresponding module starts with a shebang. + * It might be harmless for it to do it anyway, except that + * rollup-plugin-hashbang seems to suffer from a race condition where it may + * attempt to chmod type definition files before they are written to disk, + * which fails the build with an error: + * https://github.com/egoist/tsup/issues/1001 + */ +test('shebang ignores dts files', async () => { + const { outDir, logs } = await run( + getTestName(), + { + 'a.ts': `#!/usr/bin/env node\bconsole.log('a')`, + }, + { + entry: ['a.ts'], + flags: ['--dts'], + } + ) + + if (process.platform === 'win32') { + return + } + + console.log(`LOGS: ${logs}`) + + expect(() => { + fs.accessSync(path.join(outDir, 'a.d.ts'), fs.constants.X_OK) + }).toThrow() +}) + test('es5 target', async () => { const { output, outFiles } = await run( getTestName(), @@ -1037,7 +1069,7 @@ test('use rollup for treeshaking --format cjs', async () => { }`, 'input.tsx': ` import ReactSelect from 'react-select' - + export const Component = (props: {}) => { return }; @@ -1345,9 +1377,14 @@ test('should emit a declaration file per format', async () => { format: ['esm', 'cjs'], dts: true }`, - }); - expect(outFiles).toEqual(['input.d.mts', 'input.d.ts', 'input.js', 'input.mjs']) -}); + }) + expect(outFiles).toEqual([ + 'input.d.mts', + 'input.d.ts', + 'input.js', + 'input.mjs', + ]) +}) test('should emit a declaration file per format (type: module)', async () => { const { outFiles } = await run(getTestName(), { @@ -1361,6 +1398,11 @@ test('should emit a declaration file per format (type: module)', async () => { format: ['esm', 'cjs'], dts: true }`, - }); - expect(outFiles).toEqual(['input.cjs', 'input.d.cts', 'input.d.ts', 'input.js']) -}); + }) + expect(outFiles).toEqual([ + 'input.cjs', + 'input.d.cts', + 'input.d.ts', + 'input.js', + ]) +}) From 66dd095520e69a5c53af50b3e3ceb94274fe0097 Mon Sep 17 00:00:00 2001 From: Kevin Yank Date: Mon, 18 Sep 2023 16:22:05 +1000 Subject: [PATCH 3/4] Remove log output from test --- test/index.test.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/index.test.ts b/test/index.test.ts index e22a99ab..1e2c2a7f 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -897,8 +897,6 @@ test('shebang ignores dts files', async () => { return } - console.log(`LOGS: ${logs}`) - expect(() => { fs.accessSync(path.join(outDir, 'a.d.ts'), fs.constants.X_OK) }).toThrow() From c5765b1d74d993aa32cdbd2268ef941bd0af89fb Mon Sep 17 00:00:00 2001 From: Kevin Yank Date: Mon, 18 Sep 2023 16:23:08 +1000 Subject: [PATCH 4/4] Improve test name --- test/index.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/index.test.ts b/test/index.test.ts index 1e2c2a7f..1e07f82b 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -881,7 +881,7 @@ test('shebang', async () => { * which fails the build with an error: * https://github.com/egoist/tsup/issues/1001 */ -test('shebang ignores dts files', async () => { +test('do not chmod +x dts files', async () => { const { outDir, logs } = await run( getTestName(), {