-
-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
--cwd
to actually set the working directory and work with ESM c…
…hild process Currently the `--esm` option does not necessarily do what the documentation suggests. i.e. the script does not run as if the working directory is the specified directory. This commit fixes this, so that the option is useful for TSConfig resolution, as well as for controlling the script working directory. Also fixes that the CWD encoded in the bootstrap brotli state for the ESM child process messes with the entry-point resolution, if e.g. the entry-point in `child_process.fork` is relative to a specified `cwd`.
- Loading branch information
1 parent
796b593
commit d78e437
Showing
17 changed files
with
235 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
tests/esm-child-process/process-forking-nested-relative/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { fork } from 'child_process'; | ||
import { join } from 'path'; | ||
|
||
// Initially set the exit code to non-zero. We only set it to `0` when the | ||
// worker process finishes properly with the expected stdout message. | ||
process.exitCode = 1; | ||
|
||
const workerProcess = fork('./worker.ts', [], { | ||
stdio: 'pipe', | ||
cwd: join(process.cwd(), 'subfolder/'), | ||
}); | ||
|
||
let stdout = ''; | ||
|
||
workerProcess.stdout.on('data', (chunk) => (stdout += chunk.toString('utf8'))); | ||
workerProcess.on('error', () => (process.exitCode = 1)); | ||
workerProcess.on('close', (status, signal) => { | ||
if (status === 0 && signal === null && stdout.trim() === 'Works') { | ||
console.log('Passing: from main'); | ||
process.exitCode = 0; | ||
} | ||
}); |
3 changes: 3 additions & 0 deletions
3
tests/esm-child-process/process-forking-nested-relative/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "module" | ||
} |
3 changes: 3 additions & 0 deletions
3
tests/esm-child-process/process-forking-nested-relative/subfolder/worker.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const message: string = 'Works'; | ||
|
||
console.log(message); |
5 changes: 5 additions & 0 deletions
5
tests/esm-child-process/process-forking-nested-relative/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "ESNext" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { strictEqual } from 'assert'; | ||
import { normalize } from 'path'; | ||
|
||
// Expect the working directory to be the current directory. | ||
strictEqual(normalize(process.cwd()), normalize(__dirname)); | ||
|
||
console.log('Passing'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { strictEqual } from 'assert'; | ||
import { normalize, dirname } from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
|
||
// Expect the working directory to be the current directory. | ||
strictEqual( | ||
normalize(process.cwd()), | ||
normalize(dirname(fileURLToPath(import.meta.url))) | ||
); | ||
|
||
console.log('Passing'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "module" | ||
} |
Oops, something went wrong.