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 { 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..1e07f82b 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,36 @@ 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('do not chmod +x 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 + } + + 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 +1067,7 @@ test('use rollup for treeshaking --format cjs', async () => { }`, 'input.tsx': ` import ReactSelect from 'react-select' - + export const Component = (props: {}) => { return }; @@ -1345,9 +1375,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 +1396,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', + ]) +})