diff --git a/package.json b/package.json index 05d2007d..a4179526 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/test/.DS_Store b/test/.DS_Store new file mode 100644 index 00000000..723f762b Binary files /dev/null and b/test/.DS_Store differ diff --git a/test/spawn.test.ts b/test/spawn.test.ts index 97999d43..7754ca19 100644 --- a/test/spawn.test.ts +++ b/test/spawn.test.ts @@ -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' @@ -10,7 +10,7 @@ describe('spawn', () => { let tempDir: string beforeEach(() => { - tempDir = mkdtempSync(join(tmpdir(), 'spawn-test-')) + tempDir = mkdtempSync(path.join(tmpdir(), 'spawn-test-')) }) afterEach(() => { @@ -18,7 +18,7 @@ describe('spawn', () => { }) 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') @@ -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') @@ -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') @@ -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') @@ -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') @@ -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') diff --git a/test/tsconfig.json b/test/tsconfig.json index b9fdd635..01d9c8fb 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -1,4 +1,7 @@ { "extends": "../tsconfig", - "include": ["./**/*", "../src/**/*"] + "include": ["./**/*", "../src/**/*"], + "compilerOptions": { + "rootDir": "../" + } } diff --git a/tsconfig.json b/tsconfig.json index 26c7a548..f51dd9af 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,7 +5,8 @@ "module": "Node16", "outDir": "./lib", "pretty": true, - "rootDirs": ["./src"], + "rootDir": "./src", + "types": ["node", "mocha"], "strict": true, "target": "ES2022", "moduleResolution": "Node16", diff --git a/yarn.lock b/yarn.lock index 7f7608ae..81af3b4c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"