diff options
author | Maël Nison <nison.mael@gmail.com> | 2020-09-28 18:35:09 +0300 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2021-08-25 17:55:32 +0300 |
commit | 46598b88bfaecbad92492b03758c3dcc69d5e4d0 (patch) | |
tree | ac3ed059af38f63d22e9242dca6596a71d97af87 /doc/api/packages.md | |
parent | f581f6da94d011684661d48c9557d5aaf0d13c19 (diff) |
deps: add corepack
Corepack provides shims for Yarn and pnpm in order to soften the
developer experience when working on Node projects.
Refs: https://github.com/nodejs/node/issues/15244
Refs: https://github.com/nodejs/TSC/issues/904
PR-URL: https://github.com/nodejs/node/pull/39608
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Diffstat (limited to 'doc/api/packages.md')
-rw-r--r-- | doc/api/packages.md | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/doc/api/packages.md b/doc/api/packages.md index 0278b649087..09acf5a5490 100644 --- a/doc/api/packages.md +++ b/doc/api/packages.md @@ -156,6 +156,21 @@ For completeness there is also `--input-type=commonjs`, for explicitly running string input as CommonJS. This is the default behavior if `--input-type` is unspecified. +## Determining package manager + +> Stability: 1 - Experimental + +While all Node.js projects are expected to be installable by all package +managers once published, their development teams are often required to use one +specific package manager. To make this process easier, Node.js ships with a +tool called [Corepack][] that aims to make all package managers transparently +available in your environment - provided you have Node.js installed. + +By default Corepack won't enforce any specific package manager and will use +the generic "Last Known Good" versions associated with each Node.js release, +but you can improve this experience by setting the [`"packageManager"`][] field +in your project's `package.json`. + ## Package entry points In a package’s `package.json` file, two fields can define entry points for a @@ -1008,6 +1023,8 @@ The following fields in `package.json` files are used in Node.js: by package managers as the name of the package. * [`"main"`][] - The default module when loading the package, if exports is not specified, and in versions of Node.js prior to the introduction of exports. +* [`"packageManager"`][] - The package manager recommended when contributing to + the package. Leveraged by the [Corepack][] shims. * [`"type"`][] - The package type determining whether to load `.js` files as CommonJS or ES modules. * [`"exports"`][] - Package exports and conditional exports. When present, @@ -1067,6 +1084,30 @@ require('./path/to/directory'); // This resolves to ./path/to/directory/main.js. When a package has an [`"exports"`][] field, this will take precedence over the `"main"` field when importing the package by name. +### `"packageManager"` +<!-- YAML +added: REPLACEME +--> + +> Stability: 1 - Experimental + +* Type: {string} + +```json +{ + "packageManager": "<package manager name>@<version>" +} +``` + +The `"packageManager"` field defines which package manager is expected to be +used when working on the current project. It can set to any of the +[supported package managers][], and will ensure that your teams use the exact +same package manager versions without having to install anything else than +Node.js. + +This field is currently experimental and needs to be opted-in; check the +[Corepack][] page for details about the procedure. + ### `"type"` <!-- YAML added: v12.0.0 @@ -1199,6 +1240,7 @@ This field defines [subpath imports][] for the current package. [Babel]: https://babeljs.io/ [CommonJS]: modules.md [Conditional exports]: #packages_conditional_exports +[Corepack]: corepack.md [ES module]: esm.md [ES modules]: esm.md [Node.js documentation for this section]: https://github.com/nodejs/node/blob/HEAD/doc/api/packages.md#conditions-definitions @@ -1206,6 +1248,7 @@ This field defines [subpath imports][] for the current package. [`"imports"`]: #packages_imports [`"main"`]: #packages_main [`"name"`]: #packages_name +[`"packageManager"`]: #packages_packagemanager [`"type"`]: #packages_type [`ERR_PACKAGE_PATH_NOT_EXPORTED`]: errors.md#errors_err_package_path_not_exported [`esm`]: https://github.com/standard-things/esm#readme @@ -1215,5 +1258,6 @@ This field defines [subpath imports][] for the current package. [subpath exports]: #packages_subpath_exports [subpath imports]: #packages_subpath_imports [subpath patterns]: #packages_subpath_patterns +[supported package managers]: corepack.md#corepack_supported_package_managers [the dual CommonJS/ES module packages section]: #packages_dual_commonjs_es_module_packages [the full specifier path]: esm.md#esm_mandatory_file_extensions |