Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {getPathFromEnv} from './env.js';

// See http://www.robvanderwoude.com/escapechars.php
const metaCharsRegExp = /([()\][%!^"`<>&|;, *?])/g;
const shebangRegExp = /^#!\s*(.+)$/;
const shebangRegExp = /^#!\s*(.+)/;
const isWindowsExecutableRegExp = /\.(?:com|exe)$/i;
const isNodeModulesCmdRegExp = /node_modules[\\/]\.bin[\\/][^\\/]+\.cmd$/i;
const isWindows = process.platform === 'win32';
Expand Down
12 changes: 11 additions & 1 deletion src/test/normalize_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {fileURLToPath} from 'node:url';
const isWindows = os.platform() === 'win32';
const fixturesPath = path.join(
path.dirname(fileURLToPath(import.meta.url)),
'../test/fixtures'
'../../test/fixtures'
);
const cwd = process.cwd();

Expand Down Expand Up @@ -61,6 +61,16 @@ describe('normalizeSpawnCommand', () => {
});
});

test('detects shebang and rewrites command to interpreter', () => {
const scriptPath = path.join(fixturesPath, 'shebang_script.js');
const normalized = normalizeSpawnCommand(scriptPath, []);

// where resolves to where.exe (always a .exe in System32, never a
// shim), so the cmd.exe wrapping branch is skipped
expect(normalized.command).toBe('where');
expect(normalized.args).toEqual([scriptPath]);
});

test('handles relative commands without extension', () => {
const relativePath = path.relative(
cwd,
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/shebang_script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!where
not a real script, just used to verify shebang parsing
Loading