Skip to content

Commit 48753d5

Browse files
JrubzjeknfRobinprivatenumber
authored
fix: prepend hashbang on nested binary in Windows (#114)
Co-authored-by: Robin <[email protected]> Co-authored-by: Hiroki Osame <[email protected]>
1 parent f313e1f commit 48753d5

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/rollup/get-rollup-configs.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export const getRollupConfigs = async (
120120
entryFileNames: (chunk) => {
121121
const realPath = fs.realpathSync.native(stripQuery(chunk.facadeModuleId!));
122122
const relativePath = realPath.slice(sourceDirectoryPath.length);
123-
const filePath = path.join(path.dirname(relativePath), chunk.name);
123+
const filePath = path.posix.join(path.dirname(relativePath), chunk.name);
124124
return filePath + distExtension;
125125
},
126126
};

tests/specs/builds/bin.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ export default testSuite(({ describe }, nodePath: string) => {
88
describe('bin', ({ test }) => {
99
test('supports single path', async () => {
1010
await using fixture = await createFixture({
11-
...packageFixture(),
11+
// Using a subpath tests that the paths are joined correctly on Windows
12+
'src/subpath/bin.ts': 'console.log("Hello, world!");',
1213
'package.json': createPackageJson({
13-
bin: './dist/index.mjs',
14-
exports: './dist/index.mjs',
14+
bin: './dist/subpath/bin.mjs',
1515
}),
1616
});
1717

@@ -24,12 +24,12 @@ export default testSuite(({ describe }, nodePath: string) => {
2424
expect(pkgrollProcess.stderr).toBe('');
2525

2626
await test('is executable', async () => {
27-
const content = await fixture.readFile('dist/index.mjs', 'utf8');
27+
const content = await fixture.readFile('dist/subpath/bin.mjs', 'utf8');
2828
expect(content).toMatch('#!/usr/bin/env node');
2929

3030
// File modes don't exist on Windows
3131
if (process.platform !== 'win32') {
32-
const stats = await fs.stat(`${fixture.path}/dist/index.mjs`);
32+
const stats = await fs.stat(fixture.getPath('dist/subpath/bin.mjs'));
3333
const unixFilePermissions = `0${(stats.mode & 0o777).toString(8)}`; // eslint-disable-line no-bitwise
3434

3535
expect(unixFilePermissions).toBe('0755');

0 commit comments

Comments
 (0)