-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stop package.json type field from influencing corepack binaries (#1271)
* Stop package.json type field from influencing corepack binaries This is a small workaround for a side-effect caused by storing corepack installed binaries within the application folder where the `type` field from the application's `package.json` file can affect which module system those binaries are loaded with. This change adds a dummy `package.json` file to the folder that the corepack binaries are installed into which should prevent the following from happening: - Node.js will treat the following as ES modules when passed to node as the initial input, or when referenced by import statements or import() expressions - Files with a .js extension when the nearest parent package.json file contains a top-level "type" field with a value of "module". - Node.js will treat the following as CommonJS when passed to node as the initial input, or when referenced by import statements or import() expressions - Files with a .js extension when the nearest parent package.json file contains a top-level field "type" with a value of "commonjs". Instead, because the dummy `package.json` does not declare a `type` field, the following rule should apply: - Node.js defaults to one module system or the other based on the value of the ``--experimental-default-type` flag - Files ending in .js or with no extension, if the nearest parent package.json field lacks a "type" field; unless the folder is inside a node_modules folder. See https://nodejs.org/api/packages.html#determining-module-system. @fixes #1270
- Loading branch information
1 parent
555fe89
commit 1c0e88a
Showing
13 changed files
with
89 additions
and
0 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
6 changes: 6 additions & 0 deletions
6
test/fixtures/corepack_pnpm_with_package_type_module/README.md
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,6 @@ | ||
This test verifies that the Node.js module resolution rules don't adversely affect | ||
pnpm when installed using corepack. | ||
|
||
See: | ||
- https://nodejs.org/api/packages.html#determining-module-system | ||
- https://github.com/heroku/heroku-buildpack-nodejs/issues/1270 |
9 changes: 9 additions & 0 deletions
9
test/fixtures/corepack_pnpm_with_package_type_module/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,9 @@ | ||
{ | ||
"name": "corepack_pnpm_with_package_type_module", | ||
"packageManager": "[email protected]", | ||
"private": true, | ||
"type": "module", | ||
"engines": { | ||
"node": "^22.1" | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
test/fixtures/corepack_pnpm_with_package_type_module/pnpm-lock.yaml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
test/fixtures/corepack_yarn_with_package_type_module/.editorconfig
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,10 @@ | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
|
||
[*.{js,json,yml}] | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 2 |
4 changes: 4 additions & 0 deletions
4
test/fixtures/corepack_yarn_with_package_type_module/.gitattributes
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,4 @@ | ||
/.yarn/** linguist-vendored | ||
/.yarn/releases/* binary | ||
/.yarn/plugins/**/* binary | ||
/.pnp.* binary linguist-generated |
13 changes: 13 additions & 0 deletions
13
test/fixtures/corepack_yarn_with_package_type_module/.gitignore
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,13 @@ | ||
.yarn/* | ||
!.yarn/patches | ||
!.yarn/plugins | ||
!.yarn/releases | ||
!.yarn/sdks | ||
!.yarn/versions | ||
|
||
# Swap the comments on the following lines if you wish to use zero-installs | ||
# In that case, don't forget to run `yarn config set enableGlobalCache false`! | ||
# Documentation here: https://yarnpkg.com/features/caching#zero-installs | ||
|
||
#!.yarn/cache | ||
.pnp.* |
3 changes: 3 additions & 0 deletions
3
test/fixtures/corepack_yarn_with_package_type_module/.yarnrc.yml
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 @@ | ||
compressionLevel: mixed | ||
|
||
enableGlobalCache: false |
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 @@ | ||
# yarn_with_package_type_module |
4 changes: 4 additions & 0 deletions
4
test/fixtures/corepack_yarn_with_package_type_module/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,4 @@ | ||
{ | ||
"name": "yarn_with_package_type_module", | ||
"packageManager": "[email protected]" | ||
} |
12 changes: 12 additions & 0 deletions
12
test/fixtures/corepack_yarn_with_package_type_module/yarn.lock
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,12 @@ | ||
# This file is generated by running "yarn install" inside your project. | ||
# Manual changes might be lost - proceed with caution! | ||
|
||
__metadata: | ||
version: 8 | ||
cacheKey: 10 | ||
|
||
"yarn_with_package_type_module@workspace:.": | ||
version: 0.0.0-use.local | ||
resolution: "yarn_with_package_type_module@workspace:." | ||
languageName: unknown | ||
linkType: soft |
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