-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
39 additions
and
48 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,30 +1,3 @@ | ||
import Module from 'module'; | ||
import path from 'path'; | ||
|
||
/** | ||
* Loads a module as a main module, enabling the `require.main === module` pattern. | ||
*/ | ||
export function loadMainModule(id: string): void { | ||
const modulePath = Module._resolveFilename(id, null, true); | ||
|
||
const module = new Module(modulePath, undefined); | ||
|
||
module.filename = modulePath; | ||
module.paths = Module._nodeModulePaths(path.dirname(modulePath)); | ||
|
||
Module._cache[modulePath] = module; | ||
|
||
process.mainModule = module; | ||
module.id = `.`; | ||
|
||
try { | ||
return module.load(modulePath); | ||
} catch (error) { | ||
delete Module._cache[modulePath]; | ||
throw error; | ||
} | ||
} | ||
|
||
export interface NodeError extends Error { | ||
code: string; | ||
} |
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 |
---|---|---|
|
@@ -560,7 +560,10 @@ it(`should not override the package manager exit code`, async () => { | |
}); | ||
}); | ||
|
||
it(`should not override the package manager exit code when it throws`, async () => { | ||
it(`should not preserve the process.exitCode when a package manager throws`, async () => { | ||
// Node.js doesn't preserve process.exitCode when an exception is thrown | ||
// so we need to make sure we don't break this behaviour. | ||
|
||
await xfs.mktempPromise(async cwd => { | ||
await xfs.writeJsonPromise(ppath.join(cwd, `package.json` as Filename), { | ||
packageManager: `[email protected]`, | ||
|
@@ -575,9 +578,9 @@ it(`should not override the package manager exit code when it throws`, async () | |
`); | ||
|
||
await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({ | ||
exitCode: 42, | ||
stdout: expect.stringContaining(`foo`), | ||
stderr: ``, | ||
exitCode: 1, | ||
stdout: ``, | ||
stderr: expect.stringContaining(`foo`), | ||
}); | ||
}); | ||
}); | ||
|
@@ -606,3 +609,28 @@ it(`should not set the exit code after successfully launching the package manage | |
}); | ||
}); | ||
}); | ||
|
||
it(`should support package managers in ESM format`, async () => { | ||
await xfs.mktempPromise(async cwd => { | ||
await xfs.writeJsonPromise(ppath.join(cwd, `package.json` as Filename), { | ||
packageManager: `[email protected]`, | ||
}); | ||
|
||
const yarnDir = ppath.join(npath.toPortablePath(process.env.COREPACK_HOME!), `yarn/2.2.2` as PortablePath); | ||
|
||
await xfs.mkdirPromise(yarnDir, {recursive: true}); | ||
await xfs.writeFilePromise(ppath.join(yarnDir, `yarn.js` as PortablePath), ` | ||
import 'fs'; | ||
console.log(42); | ||
`); | ||
await xfs.writeJsonPromise(ppath.join(yarnDir, `package.json` as PortablePath), { | ||
type: `module`, | ||
}); | ||
|
||
await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({ | ||
exitCode: 0, | ||
stdout: `42\n`, | ||
stderr: ``, | ||
}); | ||
}); | ||
}); |
Binary file not shown.
Binary file not shown.