| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -871,6 +871,109 @@ if (foo) { | |||
| 871 | 871 | Entries in `optionalDependencies` will override entries of the same name in | |
| 872 | 872 | `dependencies`, so it's usually best to only put in one place. | |
| 873 | 873 | ||
| 874 | + ### overrides | ||
| 875 | + | ||
| 876 | + If you need to make specific changes to dependencies of your dependencies, for | ||
| 877 | + example replacing the version of a dependency with a known security issue, | ||
| 878 | + replacing an existing dependency with a fork, or making sure that the same | ||
| 879 | + version of a package is used everywhere, then you may add an override. | ||
| 880 | + | ||
| 881 | + Overrides provide a way to replace a package in your dependency tree with | ||
| 882 | + another version, or another package entirely. These changes can be scoped as | ||
| 883 | + specific or as vague as desired. | ||
| 884 | + | ||
| 885 | + To make sure the package `foo` is always installed as version `1.0.0` no matter | ||
| 886 | + what version your dependencies rely on: | ||
| 887 | + | ||
| 888 | + ```json | ||
| 889 | + { | ||
| 890 | + "overrides": { | ||
| 891 | + "foo": "1.0.0" | ||
| 892 | + } | ||
| 893 | + } | ||
| 894 | + ``` | ||
| 895 | + | ||
| 896 | + The above is a short hand notation, the full object form can be used to allow | ||
| 897 | + overriding a package itself as well as a child of the package. This will cause | ||
| 898 | + `foo` to always be `1.0.0` while also making `bar` at any depth beyond `foo` | ||
| 899 | + also `1.0.0`: | ||
| 900 | + | ||
| 901 | + ```json | ||
| 902 | + { | ||
| 903 | + "overrides": { | ||
| 904 | + "foo": { | ||
| 905 | + ".": "1.0.0", | ||
| 906 | + "bar": "1.0.0" | ||
| 907 | + } | ||
| 908 | + } | ||
| 909 | + } | ||
| 910 | + ``` | ||
| 911 | + | ||
| 912 | + To only override `foo` to be `1.0.0` when it's a child (or grandchild, or great | ||
| 913 | + grandchild, etc) of the package `bar`: | ||
| 914 | + | ||
| 915 | + ```json | ||
| 916 | + { | ||
| 917 | + "overrides": { | ||
| 918 | + "bar": { | ||
| 919 | + "foo": "1.0.0" | ||
| 920 | + } | ||
| 921 | + } | ||
| 922 | + } | ||
| 923 | + ``` | ||
| 924 | + | ||
| 925 | + Keys can be nested to any arbitrary length. To override `foo` only when it's a | ||
| 926 | + child of `bar` and only when `bar` is a child of `baz`: | ||
| 927 | + | ||
| 928 | + ```json | ||
| 929 | + { | ||
| 930 | + "overrides": { | ||
| 931 | + "baz": { | ||
| 932 | + "bar": { | ||
| 933 | + "foo": "1.0.0" | ||
| 934 | + } | ||
| 935 | + } | ||
| 936 | + } | ||
| 937 | + } | ||
| 938 | + ``` | ||
| 939 | + | ||
| 940 | + The key of an override can also include a version, or range of versions. | ||
| 941 | + To override `foo` to `1.0.0`, but only when it's a child of `bar@2.0.0`: | ||
| 942 | + | ||
| 943 | + ```json | ||
| 944 | + { | ||
| 945 | + "overrides": { | ||
| 946 | + "bar@2.0.0": { | ||
| 947 | + "foo": "1.0.0" | ||
| 948 | + } | ||
| 949 | + } | ||
| 950 | + } | ||
| 951 | + ``` | ||
| 952 | + | ||
| 953 | + You may not set an override for a package that you directly depend on unless | ||
| 954 | + both the dependency and the override itself share the exact same spec. To make | ||
| 955 | + this limitation easier to deal with, overrides may also be defined as a | ||
| 956 | + reference to a spec for a direct dependency by prefixing the name of the | ||
| 957 | + package you wish the version to match with a `$`. | ||
| 958 | + | ||
| 959 | + ```json | ||
| 960 | + { | ||
| 961 | + "dependencies": { | ||
| 962 | + "foo": "^1.0.0" | ||
| 963 | + }, | ||
| 964 | + "overrides": { | ||
| 965 | + // BAD, will throw an EOVERRIDE error | ||
| 966 | + // "foo": "^2.0.0" | ||
| 967 | + // GOOD, specs match so override is allowed | ||
| 968 | + // "foo": "^1.0.0" | ||
| 969 | + // BEST, the override is defined as a reference to the dependency | ||
| 970 | + "foo": "$foo", | ||
| 971 | + // the referenced package does not need to match the overridden one | ||
| 972 | + "bar": "$foo" | ||
| 973 | + } | ||
| 974 | + } | ||
| 975 | + ``` | ||
| 976 | + | ||
| 874 | 977 | ### engines | |
| 875 | 978 | ||
| 876 | 979 | You can specify the version of node that your stuff works on: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -160,7 +160,7 @@ <h3 id="description">Description</h3> | |||
| 160 | 160 | the results to only the paths to the packages named. Note that nested | |
| 161 | 161 | packages will <em>also</em> show the paths to the specified packages. For | |
| 162 | 162 | example, running <code>npm ls promzard</code> in npm's source tree will show:</p> | |
| 163 | - <pre lang="bash"><code>npm@8.2.0 /path/to/npm | ||
| 163 | + <pre lang="bash"><code>npm@8.3.0 /path/to/npm | ||
| 164 | 164 | └─┬ init-package-json@0.0.4 | |
| 165 | 165 | └── promzard@0.1.5 | |
| 166 | 166 | </code></pre> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -149,7 +149,7 @@ <h2 id="table-of-contents">Table of contents</h2> | |||
| 149 | 149 | <pre lang="bash"><code>npm <command> [args] | |
| 150 | 150 | </code></pre> | |
| 151 | 151 | <h3 id="version">Version</h3> | |
| 152 | - <p>8.2.0</p> | ||
| 152 | + <p>8.3.0</p> | ||
| 153 | 153 | <h3 id="description">Description</h3> | |
| 154 | 154 | <p>npm is the package manager for the Node JavaScript platform. It puts | |
| 155 | 155 | modules in place so that node can find them, and manages dependency | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -142,7 +142,7 @@ <h1 id="packagejson">package.json</h1> | |||
| 142 | 142 | ||
| 143 | 143 | <section id="table_of_contents"> | |
| 144 | 144 | <h2 id="table-of-contents">Table of contents</h2> | |
| 145 | - <div id="_table_of_contents"><ul><li><a href="#description">Description</a></li><li><a href="#name">name</a></li><li><a href="#version">version</a></li><li><a href="#description2">description</a></li><li><a href="#keywords">keywords</a></li><li><a href="#homepage">homepage</a></li><li><a href="#bugs">bugs</a></li><li><a href="#license">license</a></li><li><a href="#people-fields-author-contributors">people fields: author, contributors</a></li><li><a href="#funding">funding</a></li><li><a href="#files">files</a></li><li><a href="#main">main</a></li><li><a href="#browser">browser</a></li><li><a href="#bin">bin</a></li><li><a href="#man">man</a></li><li><a href="#directories">directories</a></li><ul><li><a href="#directoriesbin">directories.bin</a></li><li><a href="#directoriesman">directories.man</a></li></ul><li><a href="#repository">repository</a></li><li><a href="#scripts">scripts</a></li><li><a href="#config">config</a></li><li><a href="#dependencies">dependencies</a></li><ul><li><a href="#urls-as-dependencies">URLs as Dependencies</a></li><li><a href="#git-urls-as-dependencies">Git URLs as Dependencies</a></li><li><a href="#github-urls">GitHub URLs</a></li><li><a href="#local-paths">Local Paths</a></li></ul><li><a href="#devdependencies">devDependencies</a></li><li><a href="#peerdependencies">peerDependencies</a></li><li><a href="#peerdependenciesmeta">peerDependenciesMeta</a></li><li><a href="#bundleddependencies">bundledDependencies</a></li><li><a href="#optionaldependencies">optionalDependencies</a></li><li><a href="#engines">engines</a></li><li><a href="#os">os</a></li><li><a href="#cpu">cpu</a></li><li><a href="#private">private</a></li><li><a href="#publishconfig">publishConfig</a></li><li><a href="#workspaces">workspaces</a></li><li><a href="#default-values">DEFAULT VALUES</a></li><li><a href="#see-also">SEE ALSO</a></li></ul></div> | ||
| 145 | + <div id="_table_of_contents"><ul><li><a href="#description">Description</a></li><li><a href="#name">name</a></li><li><a href="#version">version</a></li><li><a href="#description2">description</a></li><li><a href="#keywords">keywords</a></li><li><a href="#homepage">homepage</a></li><li><a href="#bugs">bugs</a></li><li><a href="#license">license</a></li><li><a href="#people-fields-author-contributors">people fields: author, contributors</a></li><li><a href="#funding">funding</a></li><li><a href="#files">files</a></li><li><a href="#main">main</a></li><li><a href="#browser">browser</a></li><li><a href="#bin">bin</a></li><li><a href="#man">man</a></li><li><a href="#directories">directories</a></li><ul><li><a href="#directoriesbin">directories.bin</a></li><li><a href="#directoriesman">directories.man</a></li></ul><li><a href="#repository">repository</a></li><li><a href="#scripts">scripts</a></li><li><a href="#config">config</a></li><li><a href="#dependencies">dependencies</a></li><ul><li><a href="#urls-as-dependencies">URLs as Dependencies</a></li><li><a href="#git-urls-as-dependencies">Git URLs as Dependencies</a></li><li><a href="#github-urls">GitHub URLs</a></li><li><a href="#local-paths">Local Paths</a></li></ul><li><a href="#devdependencies">devDependencies</a></li><li><a href="#peerdependencies">peerDependencies</a></li><li><a href="#peerdependenciesmeta">peerDependenciesMeta</a></li><li><a href="#bundleddependencies">bundledDependencies</a></li><li><a href="#optionaldependencies">optionalDependencies</a></li><li><a href="#overrides">overrides</a></li><li><a href="#engines">engines</a></li><li><a href="#os">os</a></li><li><a href="#cpu">cpu</a></li><li><a href="#private">private</a></li><li><a href="#publishconfig">publishConfig</a></li><li><a href="#workspaces">workspaces</a></li><li><a href="#default-values">DEFAULT VALUES</a></li><li><a href="#see-also">SEE ALSO</a></li></ul></div> | ||
| 146 | 146 | </section> | |
| 147 | 147 | ||
| 148 | 148 | <div id="_content"><h3 id="description">Description</h3> | |
@@ -800,6 +800,88 @@ <h3 id="optionaldependencies">optionalDependencies</h3> | |||
| 800 | 800 | </code></pre> | |
| 801 | 801 | <p>Entries in <code>optionalDependencies</code> will override entries of the same name in | |
| 802 | 802 | <code>dependencies</code>, so it's usually best to only put in one place.</p> | |
| 803 | + <h3 id="overrides">overrides</h3> | ||
| 804 | + <p>If you need to make specific changes to dependencies of your dependencies, for | ||
| 805 | + example replacing the version of a dependency with a known security issue, | ||
| 806 | + replacing an existing dependency with a fork, or making sure that the same | ||
| 807 | + version of a package is used everywhere, then you may add an override.</p> | ||
| 808 | + <p>Overrides provide a way to replace a package in your dependency tree with | ||
| 809 | + another version, or another package entirely. These changes can be scoped as | ||
| 810 | + specific or as vague as desired.</p> | ||
| 811 | + <p>To make sure the package <code>foo</code> is always installed as version <code>1.0.0</code> no matter | ||
| 812 | + what version your dependencies rely on:</p> | ||
| 813 | + <pre lang="json"><code>{ | ||
| 814 | + "overrides": { | ||
| 815 | + "foo": "1.0.0" | ||
| 816 | + } | ||
| 817 | + } | ||
| 818 | + </code></pre> | ||
| 819 | + <p>The above is a short hand notation, the full object form can be used to allow | ||
| 820 | + overriding a package itself as well as a child of the package. This will cause | ||
| 821 | + <code>foo</code> to always be <code>1.0.0</code> while also making <code>bar</code> at any depth beyond <code>foo</code> | ||
| 822 | + also <code>1.0.0</code>:</p> | ||
| 823 | + <pre lang="json"><code>{ | ||
| 824 | + "overrides": { | ||
| 825 | + "foo": { | ||
| 826 | + ".": "1.0.0", | ||
| 827 | + "bar": "1.0.0" | ||
| 828 | + } | ||
| 829 | + } | ||
| 830 | + } | ||
| 831 | + </code></pre> | ||
| 832 | + <p>To only override <code>foo</code> to be <code>1.0.0</code> when it's a child (or grandchild, or great | ||
| 833 | + grandchild, etc) of the package <code>bar</code>:</p> | ||
| 834 | + <pre lang="json"><code>{ | ||
| 835 | + "overrides": { | ||
| 836 | + "bar": { | ||
| 837 | + "foo": "1.0.0" | ||
| 838 | + } | ||
| 839 | + } | ||
| 840 | + } | ||
| 841 | + </code></pre> | ||
| 842 | + <p>Keys can be nested to any arbitrary length. To override <code>foo</code> only when it's a | ||
| 843 | + child of <code>bar</code> and only when <code>bar</code> is a child of <code>baz</code>:</p> | ||
| 844 | + <pre lang="json"><code>{ | ||
| 845 | + "overrides": { | ||
| 846 | + "baz": { | ||
| 847 | + "bar": { | ||
| 848 | + "foo": "1.0.0" | ||
| 849 | + } | ||
| 850 | + } | ||
| 851 | + } | ||
| 852 | + } | ||
| 853 | + </code></pre> | ||
| 854 | + <p>The key of an override can also include a version, or range of versions. | ||
| 855 | + To override <code>foo</code> to <code>1.0.0</code>, but only when it's a child of <code>bar@2.0.0</code>:</p> | ||
| 856 | + <pre lang="json"><code>{ | ||
| 857 | + "overrides": { | ||
| 858 | + "bar@2.0.0": { | ||
| 859 | + "foo": "1.0.0" | ||
| 860 | + } | ||
| 861 | + } | ||
| 862 | + } | ||
| 863 | + </code></pre> | ||
| 864 | + <p>You may not set an override for a package that you directly depend on unless | ||
| 865 | + both the dependency and the override itself share the exact same spec. To make | ||
| 866 | + this limitation easier to deal with, overrides may also be defined as a | ||
| 867 | + reference to a spec for a direct dependency by prefixing the name of the | ||
| 868 | + package you wish the version to match with a <code>$</code>.</p> | ||
| 869 | + <pre lang="json"><code>{ | ||
| 870 | + "dependencies": { | ||
| 871 | + "foo": "^1.0.0" | ||
| 872 | + }, | ||
| 873 | + "overrides": { | ||
| 874 | + // BAD, will throw an EOVERRIDE error | ||
| 875 | + // "foo": "^2.0.0" | ||
| 876 | + // GOOD, specs match so override is allowed | ||
| 877 | + // "foo": "^1.0.0" | ||
| 878 | + // BEST, the override is defined as a reference to the dependency | ||
| 879 | + "foo": "$foo", | ||
| 880 | + // the referenced package does not need to match the overridden one | ||
| 881 | + "bar": "$foo" | ||
| 882 | + } | ||
| 883 | + } | ||
| 884 | + </code></pre> | ||
| 803 | 885 | <h3 id="engines">engines</h3> | |
| 804 | 886 | <p>You can specify the version of node that your stuff works on:</p> | |
| 805 | 887 | <pre lang="json"><code>{ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,7 +2,7 @@ | |||
| 2 | 2 | const configDefs = require('../utils/config/index.js') | |
| 3 | 3 | ||
| 4 | 4 | const mkdirp = require('mkdirp-infer-owner') | |
| 5 | - const { dirname } = require('path') | ||
| 5 | + const { dirname, resolve } = require('path') | ||
| 6 | 6 | const { promisify } = require('util') | |
| 7 | 7 | const fs = require('fs') | |
| 8 | 8 | const readFile = promisify(fs.readFile) | |
@@ -11,6 +11,7 @@ const { spawn } = require('child_process') | |||
| 11 | 11 | const { EOL } = require('os') | |
| 12 | 12 | const ini = require('ini') | |
| 13 | 13 | const localeCompare = require('@isaacs/string-locale-compare')('en') | |
| 14 | + const rpj = require('read-package-json-fast') | ||
| 14 | 15 | const log = require('../utils/log-shim.js') | |
| 15 | 16 | ||
| 16 | 17 | // take an array of `[key, value, k2=v2, k3, v3, ...]` and turn into | |
@@ -28,7 +29,17 @@ const keyValues = args => { | |||
| 28 | 29 | return kv | |
| 29 | 30 | } | |
| 30 | 31 | ||
| 31 | - const publicVar = k => !/^(\/\/[^:]+:)?_/.test(k) | ||
| 32 | + const publicVar = k => { | ||
| 33 | + // _password | ||
| 34 | + if (k.startsWith('_')) { | ||
| 35 | + return false | ||
| 36 | + } | ||
| 37 | + // //localhost:8080/:_password | ||
| 38 | + if (k.startsWith('//') && k.includes(':_')) { | ||
| 39 | + return false | ||
| 40 | + } | ||
| 41 | + return true | ||
| 42 | + } | ||
| 32 | 43 | ||
| 33 | 44 | const BaseCommand = require('../base-command.js') | |
| 34 | 45 | class Config extends BaseCommand { | |
@@ -147,7 +158,7 @@ class Config extends BaseCommand { | |||
| 147 | 158 | const out = [] | |
| 148 | 159 | for (const key of keys) { | |
| 149 | 160 | if (!publicVar(key)) { | |
| 150 | - throw `The ${key} option is protected, and cannot be retrieved in this way` | ||
| 161 | + throw new Error(`The ${key} option is protected, and cannot be retrieved in this way`) | ||
| 151 | 162 | } | |
| 152 | 163 | ||
| 153 | 164 | const pref = keys.length > 1 ? `${key}=` : '' | |
@@ -257,6 +268,23 @@ ${defData} | |||
| 257 | 268 | `; HOME = ${process.env.HOME}`, | |
| 258 | 269 | '; Run `npm config ls -l` to show all defaults.' | |
| 259 | 270 | ) | |
| 271 | + msg.push('') | ||
| 272 | + } | ||
| 273 | + | ||
| 274 | + if (!this.npm.config.get('global')) { | ||
| 275 | + const pkgPath = resolve(this.npm.prefix, 'package.json') | ||
| 276 | + const pkg = await rpj(pkgPath).catch(() => ({})) | ||
| 277 | + | ||
| 278 | + if (pkg.publishConfig) { | ||
| 279 | + msg.push(`; "publishConfig" from ${pkgPath}`) | ||
| 280 | + msg.push('; This set of config values will be used at publish-time.', '') | ||
| 281 | + const pkgKeys = Object.keys(pkg.publishConfig).sort(localeCompare) | ||
| 282 | + for (const k of pkgKeys) { | ||
| 283 | + const v = publicVar(k) ? JSON.stringify(pkg.publishConfig[k]) : '(protected)' | ||
| 284 | + msg.push(`${k} = ${v}`) | ||
| 285 | + } | ||
| 286 | + msg.push('') | ||
| 287 | + } | ||
| 260 | 288 | } | |
| 261 | 289 | ||
| 262 | 290 | this.npm.output(msg.join('\n').trim()) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -104,11 +104,15 @@ class Publish extends BaseCommand { | |||
| 104 | 104 | const resolved = npa.resolve(manifest.name, manifest.version) | |
| 105 | 105 | const registry = npmFetch.pickRegistry(resolved, opts) | |
| 106 | 106 | const creds = this.npm.config.getCredentialsByURI(registry) | |
| 107 | + const outputRegistry = replaceInfo(registry) | ||
| 107 | 108 | if (!creds.token && !creds.username) { | |
| 108 | - throw Object.assign(new Error('This command requires you to be logged in.'), { | ||
| 109 | - code: 'ENEEDAUTH', | ||
| 110 | - }) | ||
| 109 | + throw Object.assign( | ||
| 110 | + new Error(`This command requires you to be logged in to ${outputRegistry}`), { | ||
| 111 | + code: 'ENEEDAUTH', | ||
| 112 | + } | ||
| 113 | + ) | ||
| 111 | 114 | } | |
| 115 | + log.notice('', `Publishing to ${outputRegistry}`) | ||
| 112 | 116 | await otplease(opts, opts => libpub(manifest, tarballData, opts)) | |
| 113 | 117 | } | |
| 114 | 118 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -116,6 +116,7 @@ const exitHandler = err => { | |||
| 116 | 116 | exitCode = err.code | |
| 117 | 117 | noLogMessage = true | |
| 118 | 118 | } else if (typeof err === 'string') { | |
| 119 | + // XXX: we should stop throwing strings | ||
| 119 | 120 | log.error('', err) | |
| 120 | 121 | noLogMessage = true | |
| 121 | 122 | } else if (!(err instanceof Error)) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments