@pnpm/resolving.tarball-url 1100.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015-2016 Rico Sta. Cruz and other contributors
4
+ Copyright (c) 2016-2026 Zoltan Kochan and other contributors
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # @pnpm/resolving.tarball-url
2
+
3
+ > Build and recognize the canonical tarball URL of an npm package
4
+
5
+ <!--@shields('npm')-->
6
+ [![npm version](https://img.shields.io/npm/v/@pnpm/resolving.tarball-url.svg)](https://npmx.dev/package/@pnpm/resolving.tarball-url)
7
+ <!--/@-->
8
+
9
+ ## Installation
10
+
11
+ ```sh
12
+ pnpm add @pnpm/resolving.tarball-url
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```ts
18
+ import {
19
+ getNpmTarballUrl,
20
+ isCanonicalRegistryTarballUrl,
21
+ } from '@pnpm/resolving.tarball-url'
22
+
23
+ const registry = 'https://registry.npmjs.org/'
24
+
25
+ getNpmTarballUrl('foo', '1.0.0', { registry })
26
+ //=> 'https://registry.npmjs.org/foo/-/foo-1.0.0.tgz'
27
+
28
+ isCanonicalRegistryTarballUrl(
29
+ 'https://registry.npmjs.org/foo/-/foo-1.0.0.tgz',
30
+ { name: 'foo', version: '1.0.0' },
31
+ registry
32
+ )
33
+ //=> true
34
+ ```
35
+
36
+ ## License
37
+
38
+ MIT
package/lib/index.d.ts ADDED
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Build the canonical tarball URL of an npm package — i.e. the URL pnpm derives
3
+ * from a package's name, version, and registry. Vendored from the
4
+ * `get-npm-tarball-url` package so the logic and its inverse
5
+ * ({@link isCanonicalRegistryTarballUrl}) live together in the monorepo.
6
+ */
7
+ export declare function getNpmTarballUrl(pkgName: string, pkgVersion: string, opts?: {
8
+ registry?: string;
9
+ }): string;
10
+ /**
11
+ * Whether `tarball` is the canonical npm registry URL derived from the package
12
+ * name, version, and registry — i.e. it can be dropped from the lockfile and
13
+ * rebuilt on demand by {@link getNpmTarballUrl}.
14
+ *
15
+ * The lockfile writer uses this to decide whether to persist a tarball URL.
16
+ * It is exported so custom resolvers (pnpmfile `resolvers`) can emit a URL the
17
+ * writer will treat as canonical, instead of re-deriving pnpm's URL shape by
18
+ * hand. A resolver fronting a proxy that serves tarballs on a non-canonical
19
+ * path (e.g. an ephemeral `localhost:<port>`) can rewrite the resolved tarball
20
+ * to `getNpmTarballUrl(name, version, { registry })` so nothing host-specific
21
+ * is persisted to `pnpm-lock.yaml`.
22
+ *
23
+ * Percent-encoding is case-insensitive, so the `%2f` unescape matches both
24
+ * `%2f` and `%2F` in the URLs npm produces for scoped packages.
25
+ */
26
+ export declare function isCanonicalRegistryTarballUrl(tarball: string, pkg: {
27
+ name: string;
28
+ version: string;
29
+ }, registry: string): boolean;
package/lib/index.js ADDED
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Build the canonical tarball URL of an npm package — i.e. the URL pnpm derives
3
+ * from a package's name, version, and registry. Vendored from the
4
+ * `get-npm-tarball-url` package so the logic and its inverse
5
+ * ({@link isCanonicalRegistryTarballUrl}) live together in the monorepo.
6
+ */
7
+ export function getNpmTarballUrl(pkgName, pkgVersion, opts) {
8
+ const registry = normalizeRegistry(opts?.registry);
9
+ const scopelessName = getScopelessName(pkgName);
10
+ return `${registry}${pkgName}/-/${scopelessName}-${removeBuildMetadataFromVersion(pkgVersion)}.tgz`;
11
+ }
12
+ /**
13
+ * Whether `tarball` is the canonical npm registry URL derived from the package
14
+ * name, version, and registry — i.e. it can be dropped from the lockfile and
15
+ * rebuilt on demand by {@link getNpmTarballUrl}.
16
+ *
17
+ * The lockfile writer uses this to decide whether to persist a tarball URL.
18
+ * It is exported so custom resolvers (pnpmfile `resolvers`) can emit a URL the
19
+ * writer will treat as canonical, instead of re-deriving pnpm's URL shape by
20
+ * hand. A resolver fronting a proxy that serves tarballs on a non-canonical
21
+ * path (e.g. an ephemeral `localhost:<port>`) can rewrite the resolved tarball
22
+ * to `getNpmTarballUrl(name, version, { registry })` so nothing host-specific
23
+ * is persisted to `pnpm-lock.yaml`.
24
+ *
25
+ * Percent-encoding is case-insensitive, so the `%2f` unescape matches both
26
+ * `%2f` and `%2F` in the URLs npm produces for scoped packages.
27
+ */
28
+ export function isCanonicalRegistryTarballUrl(tarball, pkg, registry) {
29
+ const expectedTarball = getNpmTarballUrl(pkg.name, pkg.version, { registry });
30
+ const actualTarball = tarball.replace(/%2f/gi, '/');
31
+ return removeProtocol(expectedTarball) === removeProtocol(actualTarball);
32
+ }
33
+ function normalizeRegistry(registry) {
34
+ if (!registry)
35
+ return 'https://registry.npmjs.org/';
36
+ return registry.endsWith('/') ? registry : `${registry}/`;
37
+ }
38
+ function removeBuildMetadataFromVersion(version) {
39
+ const plusPos = version.indexOf('+');
40
+ if (plusPos === -1)
41
+ return version;
42
+ return version.substring(0, plusPos);
43
+ }
44
+ function getScopelessName(name) {
45
+ if (name[0] !== '@') {
46
+ return name;
47
+ }
48
+ return name.split('/')[1];
49
+ }
50
+ // Strips only a leading http(s) scheme so URLs are compared protocol-insensitively
51
+ // without truncating on a later `://` in the path or query.
52
+ function removeProtocol(url) {
53
+ return url.replace(/^https?:\/\//i, '');
54
+ }
55
+ //# sourceMappingURL=index.js.map
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@pnpm/resolving.tarball-url",
3
+ "version": "1100.0.0",
4
+ "description": "Build and recognize the canonical tarball URL of an npm package",
5
+ "keywords": [
6
+ "pnpm",
7
+ "pnpm11",
8
+ "npm",
9
+ "tarball"
10
+ ],
11
+ "license": "MIT",
12
+ "funding": "https://opencollective.com/pnpm",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/pnpm/pnpm/tree/main/pnpm11/resolving/tarball-url"
16
+ },
17
+ "homepage": "https://github.com/pnpm/pnpm/tree/main/pnpm11/resolving/tarball-url#readme",
18
+ "bugs": {
19
+ "url": "https://github.com/pnpm/pnpm/issues"
20
+ },
21
+ "type": "module",
22
+ "main": "lib/index.js",
23
+ "types": "lib/index.d.ts",
24
+ "exports": {
25
+ ".": "./lib/index.js"
26
+ },
27
+ "files": [
28
+ "lib",
29
+ "!*.map"
30
+ ],
31
+ "devDependencies": {
32
+ "@jest/globals": "30.4.1",
33
+ "@pnpm/resolving.tarball-url": "1100.0.0"
34
+ },
35
+ "engines": {
36
+ "node": ">=22.13"
37
+ },
38
+ "jest": {
39
+ "preset": "@pnpm/jest-config"
40
+ },
41
+ "scripts": {
42
+ "lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
43
+ "test": "pn compile && pn .test",
44
+ "compile": "tsgo --build && pn lint --fix",
45
+ ".test": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules --disable-warning=ExperimentalWarning --disable-warning=DEP0169\" jest"
46
+ }
47
+ }