@pnpm/fetching.git-fetcher 1003.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,15 @@
1
+ # @pnpm/git-fetcher
2
+
3
+ > Fetcher for git-hosted packages
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@pnpm/git-fetcher.svg)](https://www.npmjs.com/package/@pnpm/git-fetcher)
6
+
7
+ ## Installation
8
+
9
+ ```
10
+ pnpm add @pnpm/git-fetcher
11
+ ```
12
+
13
+ ## License
14
+
15
+ MIT
package/lib/index.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import type { GitFetcher } from '@pnpm/fetching.fetcher-base';
2
+ import type { StoreIndex } from '@pnpm/store.index';
3
+ export interface CreateGitFetcherOptions {
4
+ gitShallowHosts?: string[];
5
+ rawConfig: Record<string, unknown>;
6
+ storeIndex: StoreIndex;
7
+ unsafePerm?: boolean;
8
+ ignoreScripts?: boolean;
9
+ }
10
+ export declare function createGitFetcher(createOpts: CreateGitFetcherOptions): {
11
+ git: GitFetcher;
12
+ };
package/lib/index.js ADDED
@@ -0,0 +1,88 @@
1
+ import assert from 'node:assert';
2
+ import path from 'node:path';
3
+ import { URL } from 'node:url';
4
+ import util from 'node:util';
5
+ import { PnpmError } from '@pnpm/error';
6
+ import { preparePackage } from '@pnpm/exec.prepare-package';
7
+ import { packlist } from '@pnpm/fs.packlist';
8
+ import { globalWarn } from '@pnpm/logger';
9
+ import { addFilesFromDir } from '@pnpm/worker';
10
+ import { rimraf } from '@zkochan/rimraf';
11
+ import { safeExeca as execa } from 'execa';
12
+ export function createGitFetcher(createOpts) {
13
+ const allowedHosts = new Set(createOpts?.gitShallowHosts ?? []);
14
+ const ignoreScripts = createOpts.ignoreScripts ?? false;
15
+ const gitFetcher = async (cafs, resolution, opts) => {
16
+ const tempLocation = await cafs.tempDir();
17
+ if (allowedHosts.size > 0 && shouldUseShallow(resolution.repo, allowedHosts)) {
18
+ await execGit(['init'], { cwd: tempLocation });
19
+ await execGit(['remote', 'add', 'origin', resolution.repo], { cwd: tempLocation });
20
+ await execGit(['fetch', '--depth', '1', 'origin', resolution.commit], { cwd: tempLocation });
21
+ }
22
+ else {
23
+ await execGit(['clone', resolution.repo, tempLocation]);
24
+ }
25
+ await execGit(['checkout', resolution.commit], { cwd: tempLocation });
26
+ const receivedCommit = await execGit(['rev-parse', 'HEAD'], { cwd: tempLocation });
27
+ if (receivedCommit.trim() !== resolution.commit) {
28
+ throw new PnpmError('GIT_CHECKOUT_FAILED', `received commit ${receivedCommit.trim()} does not match expected value ${resolution.commit}`);
29
+ }
30
+ let pkgDir;
31
+ try {
32
+ const prepareResult = await preparePackage({
33
+ allowBuild: opts.allowBuild,
34
+ ignoreScripts: createOpts.ignoreScripts,
35
+ rawConfig: createOpts.rawConfig,
36
+ unsafePerm: createOpts.unsafePerm,
37
+ }, tempLocation, resolution.path ?? '');
38
+ pkgDir = prepareResult.pkgDir;
39
+ if (ignoreScripts && prepareResult.shouldBeBuilt) {
40
+ globalWarn(`The git-hosted package fetched from "${resolution.repo}" has to be built but the build scripts were ignored.`);
41
+ }
42
+ }
43
+ catch (err) {
44
+ assert(util.types.isNativeError(err));
45
+ err.message = `Failed to prepare git-hosted package fetched from "${resolution.repo}": ${err.message}`;
46
+ throw err;
47
+ }
48
+ // removing /.git to make directory integrity calculation faster
49
+ await rimraf(path.join(tempLocation, '.git'));
50
+ const files = await packlist(pkgDir);
51
+ // Important! We cannot remove the temp location at this stage.
52
+ // Even though we have the index of the package,
53
+ // the linking of files to the store is in progress.
54
+ return addFilesFromDir({
55
+ storeDir: cafs.storeDir,
56
+ storeIndex: createOpts.storeIndex,
57
+ dir: pkgDir,
58
+ files,
59
+ filesIndexFile: opts.filesIndexFile,
60
+ readManifest: opts.readManifest,
61
+ pkg: opts.pkg,
62
+ });
63
+ };
64
+ return {
65
+ git: gitFetcher,
66
+ };
67
+ }
68
+ function shouldUseShallow(repoUrl, allowedHosts) {
69
+ try {
70
+ const { host } = new URL(repoUrl);
71
+ if (allowedHosts.has(host)) {
72
+ return true;
73
+ }
74
+ }
75
+ catch {
76
+ // URL might be malformed
77
+ }
78
+ return false;
79
+ }
80
+ function prefixGitArgs() {
81
+ return process.platform === 'win32' ? ['-c', 'core.longpaths=true'] : [];
82
+ }
83
+ async function execGit(args, opts) {
84
+ const fullArgs = prefixGitArgs().concat(args || []);
85
+ const { stdout } = await execa('git', fullArgs, opts);
86
+ return stdout;
87
+ }
88
+ //# sourceMappingURL=index.js.map
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@pnpm/fetching.git-fetcher",
3
+ "version": "1003.0.0",
4
+ "description": "A fetcher for git-hosted packages",
5
+ "keywords": [
6
+ "pnpm",
7
+ "pnpm11",
8
+ "fetcher"
9
+ ],
10
+ "license": "MIT",
11
+ "funding": "https://opencollective.com/pnpm",
12
+ "repository": "https://github.com/pnpm/pnpm/tree/main/fetching/git-fetcher",
13
+ "homepage": "https://github.com/pnpm/pnpm/tree/main/fetching/git-fetcher#readme",
14
+ "bugs": {
15
+ "url": "https://github.com/pnpm/pnpm/issues"
16
+ },
17
+ "type": "module",
18
+ "main": "lib/index.js",
19
+ "types": "lib/index.d.ts",
20
+ "exports": {
21
+ ".": "./lib/index.js"
22
+ },
23
+ "files": [
24
+ "lib",
25
+ "!*.map"
26
+ ],
27
+ "dependencies": {
28
+ "@zkochan/rimraf": "^4.0.0",
29
+ "execa": "npm:safe-execa@0.3.0",
30
+ "@pnpm/error": "1000.0.5",
31
+ "@pnpm/exec.prepare-package": "1000.0.26",
32
+ "@pnpm/store.index": "1000.0.0-0",
33
+ "@pnpm/fetching.fetcher-base": "1001.0.2",
34
+ "@pnpm/fs.packlist": "1000.0.0"
35
+ },
36
+ "peerDependencies": {
37
+ "@pnpm/logger": ">=1001.0.0 <1002.0.0",
38
+ "@pnpm/worker": "^1000.3.0"
39
+ },
40
+ "devDependencies": {
41
+ "@jest/globals": "30.0.5",
42
+ "@pnpm/util.lex-comparator": "^3.0.2",
43
+ "tempy": "3.0.0",
44
+ "@pnpm/fetching.git-fetcher": "1003.0.0",
45
+ "@pnpm/logger": "1001.0.1",
46
+ "@pnpm/store.cafs": "1000.0.19",
47
+ "@pnpm/store.create-cafs-store": "1000.0.20",
48
+ "@pnpm/types": "1000.9.0"
49
+ },
50
+ "engines": {
51
+ "node": ">=22.13"
52
+ },
53
+ "jest": {
54
+ "preset": "@pnpm/jest-config"
55
+ },
56
+ "scripts": {
57
+ "_test": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules --disable-warning=ExperimentalWarning --disable-warning=DEP0169\" jest",
58
+ "test": "pnpm run compile && pnpm run _test",
59
+ "lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
60
+ "compile": "tsgo --build && pnpm run lint --fix"
61
+ }
62
+ }