You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -34,7 +34,7 @@ part, eg `foo` then the specifier will default to `latest`.
34
34
35
35
**Throws** if the package name is invalid, a dist-tag is invalid or a URL's protocol is not supported.
36
36
37
-
### var result = npa.resolve(*name*, *spec*[, *where*])
37
+
### const result = npa.resolve(*name*, *spec*[, *where*])
38
38
39
39
**name* - The name of the module you want to install. For example: `foo` or `@bar/foo`.
40
40
**spec* - The specifier indicating where and how you can get this module. Something like:
@@ -45,7 +45,7 @@ included then the default is `latest`.
45
45
46
46
**Throws** if the package name is invalid, a dist-tag is invalid or a URL's protocol is not supported.
47
47
48
-
### var purl = npa.toPurl(*arg*, *reg*)
48
+
### const purl = npa.toPurl(*arg*, *reg*)
49
49
50
50
Returns the [purl (package URL)](https://github.com/package-url/purl-spec) form of the given package name/spec.
51
51
@@ -79,9 +79,9 @@ keys:
79
79
specification. Mostly used when making requests against a registry. When
80
80
`name` is `null`, `escapedName` will also be `null`.
81
81
*`rawSpec` - The specifier part that was parsed out in calls to `npa(arg)`,
82
-
or the value of `spec` in calls to `npa.resolve(name, spec).
82
+
or the value of `spec` in calls to `npa.resolve(name, spec)`.
83
83
*`saveSpec` - The normalized specifier, for saving to package.json files.
84
-
`null` for registry dependencies.
84
+
`null` for registry dependencies. See note below about how this is (not) encoded.
85
85
*`fetchSpec` - The version of the specifier to be used to fetch this
86
86
resource. `null` for shortcuts to hosted git dependencies as there isn't
87
87
just one URL to try with them.
@@ -94,3 +94,11 @@ keys:
94
94
`npa.resolve(name, spec)` then this will be `name + '@' + spec`.
95
95
*`subSpec` - If `type === 'alias'`, this is a Result Object for parsing the
96
96
target specifier for the alias.
97
+
98
+
## SAVE SPECS
99
+
100
+
TLDR: `file:` urls are NOT uri encoded.
101
+
102
+
Historically, npm would uri decode file package args, but did not do any uri encoding for the `saveSpec`. This meant that it generated incorrect saveSpecs for directories with characters that *looked* like encoded uri characters, and also that it could not parse directories with some unencoded uri characters (such as `%`).
103
+
104
+
In order to fix this, and to not break all existing versions of npm, this module now parses all file package args as not being uri encoded. And in order to not break all of the package.json files npm has made in the past, it also does not uri encode the saveSpec. This includes package args that start with `file:`. This does mean that npm `file:` package args are not RFC compliant, and making them so constitutes quite a breaking change.
// We need to use path/win32 so that we get consistent results in tests, but this also means we need to manually convert backslashes to forward slashes when generating file: urls with paths.
0 commit comments