Skip to content

Commit

Permalink
Fix error attempting to chmod dts files
Browse files Browse the repository at this point in the history
  • Loading branch information
sentience committed Sep 18, 2023
1 parent 336719b commit 17fa5e3
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 11 deletions.
12 changes: 11 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions src/rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -167,7 +166,6 @@ const getRollupConfig = async (
plugins: [
tsupCleanPlugin,
tsResolveOptions && tsResolvePlugin(tsResolveOptions),
hashbangPlugin(),
jsonPlugin(),
ignoreFiles,
dtsPlugin.default({
Expand Down
57 changes: 49 additions & 8 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
Expand Down Expand Up @@ -872,6 +872,37 @@ test('shebang', async () => {
}).toThrow()
})

/**
* shebang should not attempt to `chmod +x` type definition files in the output,
* both because these files are not intended to be executable, but also because
* they get written in parallel with the shebang plugin's execution, so may not
* exist on disk at the time the shebang plugin tries to run chmod. This race
* caused build failures before type definition files were excluded from this
* processing.
*/
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(),
Expand Down Expand Up @@ -1037,7 +1068,7 @@ test('use rollup for treeshaking --format cjs', async () => {
}`,
'input.tsx': `
import ReactSelect from 'react-select'
export const Component = (props: {}) => {
return <ReactSelect {...props} />
};
Expand Down Expand Up @@ -1345,9 +1376,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(), {
Expand All @@ -1361,6 +1397,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',
])
})

0 comments on commit 17fa5e3

Please sign in to comment.