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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"shx": "^0.4.0",
"sinon": "^18",
"ts-node": "^10.9.2",
"typescript": "^5.7.3"
"typescript": "^6"
},
"engines": {
"node": ">=18.0.0"
Expand Down
Binary file added test/.DS_Store
Binary file not shown.
28 changes: 16 additions & 12 deletions test/spawn.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {expect} from 'chai'
import {chmodSync, mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync} from 'node:fs'
import {tmpdir} from 'node:os'
import {dirname, join} from 'node:path'
import path from 'node:path'
import {fileURLToPath} from 'node:url'

import {spawn} from '../src/spawn.js'
Expand All @@ -10,15 +10,15 @@ describe('spawn', () => {
let tempDir: string

beforeEach(() => {
tempDir = mkdtempSync(join(tmpdir(), 'spawn-test-'))
tempDir = mkdtempSync(path.join(tmpdir(), 'spawn-test-'))
})

afterEach(() => {
rmSync(tempDir, {force: true, recursive: true})
})

it('should invoke .js module paths via process.execPath', async () => {
const script = join(tempDir, 'test-script.js')
const script = path.join(tempDir, 'test-script.js')
writeFileSync(script, '#!/usr/bin/env nonexistent-node-binary\nconsole.log("spawned-ok")\n')
chmodSync(script, '755')

Expand All @@ -28,7 +28,7 @@ describe('spawn', () => {
})

it('should pass args after the .js module path', async () => {
const script = join(tempDir, 'echo-args.js')
const script = path.join(tempDir, 'echo-args.js')
writeFileSync(script, 'console.log(JSON.stringify(process.argv.slice(2)))\n')
chmodSync(script, '755')

Expand All @@ -38,9 +38,9 @@ describe('spawn', () => {
})

it('should handle .js module paths with spaces in the path', async () => {
const dir = join(tempDir, 'dir with spaces')
const dir = path.join(tempDir, 'dir with spaces')
mkdirSync(dir)
const script = join(dir, 'my script.js')
const script = path.join(dir, 'my script.js')
writeFileSync(script, 'console.log("spaces-ok")\n')
chmodSync(script, '755')

Expand All @@ -51,12 +51,12 @@ describe('spawn', () => {

it('should handle process.execPath containing spaces', async function () {
if (process.platform === 'win32') return this.skip()
const nodeDir = join(tempDir, 'path with spaces', 'bin')
const nodeDir = path.join(tempDir, 'path with spaces', 'bin')
mkdirSync(nodeDir, {recursive: true})
const nodeLink = join(nodeDir, 'node')
const nodeLink = path.join(nodeDir, 'node')
symlinkSync(process.execPath, nodeLink)

const script = join(tempDir, 'exec-path-test.js')
const script = path.join(tempDir, 'exec-path-test.js')
writeFileSync(script, 'console.log("execpath-ok")\n')
chmodSync(script, '755')

Expand All @@ -71,12 +71,16 @@ describe('spawn', () => {
})

it('must use windowsVerbatimArguments to prevent argument injection (security)', () => {
const spawnSrc = readFileSync(join(dirname(fileURLToPath(import.meta.url)), '..', 'src', 'spawn.ts'), 'utf8')
const spawnSrc = readFileSync(
// eslint-disable-next-line unicorn/max-nested-calls
path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'src', 'spawn.ts'),
'utf8',
)
expect(spawnSrc).to.include('windowsVerbatimArguments: true')
})

it('should not interpret shell metacharacters in arguments', async () => {
const script = join(tempDir, 'echo-args.js')
const script = path.join(tempDir, 'echo-args.js')
writeFileSync(script, 'console.log(JSON.stringify(process.argv.slice(2)))\n')
chmodSync(script, '755')

Expand All @@ -94,7 +98,7 @@ describe('spawn', () => {

it('should not modify non-.js module paths', async function () {
if (process.platform === 'win32') return this.skip()
const script = join(tempDir, 'test-bin')
const script = path.join(tempDir, 'test-bin')
writeFileSync(script, `#!/usr/bin/env bash\necho "bin-ok"\n`)
chmodSync(script, '755')

Expand Down
5 changes: 4 additions & 1 deletion test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"extends": "../tsconfig",
"include": ["./**/*", "../src/**/*"]
"include": ["./**/*", "../src/**/*"],
"compilerOptions": {
"rootDir": "../"
}
}
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"module": "Node16",
"outDir": "./lib",
"pretty": true,
"rootDirs": ["./src"],
"rootDir": "./src",
"types": ["node", "mocha"],
"strict": true,
"target": "ES2022",
"moduleResolution": "Node16",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6105,10 +6105,10 @@ typescript-eslint@^8.64.0, typescript-eslint@^8.66.0:
"@typescript-eslint/typescript-estree" "8.67.0"
"@typescript-eslint/utils" "8.67.0"

typescript@^5.7.3:
version "5.9.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.9.3.tgz#5b4f59e15310ab17a216f5d6cf53ee476ede670f"
integrity sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==
typescript@^6:
version "6.0.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-6.0.3.tgz#90251dc007916e972786cb94d74d15b185577d21"
integrity sha512-y2TvuxSZPDyQakkFRPZHKFm+KKVqIisdg9/CZwm9ftvKXLP8NRWj38/ODjNbr43SsoXqNuAisEf1GdCxqWcdBw==

undici-types@~5.26.4:
version "5.26.5"
Expand Down
Loading