@vltpkg/git 1.0.0-rc.13 → 1.0.0-rc.14

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/dist/clone.d.ts CHANGED
@@ -9,5 +9,5 @@ import type { GitOptions } from './index.ts';
9
9
  * as well.
10
10
  */
11
11
  export declare const shallowHosts: Set<string>;
12
- export declare const clone: (repo: string, ref?: string, target?: string | undefined, opts?: GitOptions) => Promise<string>;
12
+ export declare const clone: (repo: string, ref?: string, target?: string, opts?: GitOptions) => Promise<string>;
13
13
  //# sourceMappingURL=clone.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"clone.d.ts","sourceRoot":"","sources":["../src/clone.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAM5C;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,aAMvB,CAAA;AAEF,eAAO,MAAM,KAAK,SACV,MAAM,yBAEJ,MAAM,GAAG,SAAS,SACpB,UAAU,oBAajB,CAAA"}
1
+ {"version":3,"file":"clone.d.ts","sourceRoot":"","sources":["../src/clone.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAM5C;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,aAMvB,CAAA;AAEF,eAAO,MAAM,KAAK,SACV,MAAM,yBAEH,MAAM,SACT,UAAU,oBAajB,CAAA"}
package/dist/clone.js CHANGED
@@ -27,7 +27,7 @@ export const shallowHosts = new Set([
27
27
  'bitbucket.com',
28
28
  'bitbucket.org',
29
29
  ]);
30
- export const clone = async (repo, ref = 'HEAD', target = undefined, opts = {}) => {
30
+ export const clone = async (repo, ref = 'HEAD', target, opts = {}) => {
31
31
  repo = String(gitScpURL(repo) ?? repo).replace(/^git\+/, '');
32
32
  if (repo.startsWith('file://'))
33
33
  repo = fileURLToPath(repo);
package/dist/clone.js.map CHANGED
@@ -1 +1 @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A;IACpC,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,CAAC,WAAW,EAAE,aAAa,EAAE,MAAM,CAAC,CAAC,CAAA;IAC9D,OAAO,MAAM,CAAC,MAAM,CAAA;AACtB,CAAC,CAAA","sourcesContent":["// The goal here is to minimize both git workload and\n// the number of refs we download over the network.\n//\n// Every method ends up with the checked out working dir\n// at the specified ref, and resolves with the git sha.\n\nimport type { RevDoc, RevDocEntry } from '@vltpkg/types'\nimport { gitScpURL } from '@vltpkg/git-scp-url'\nimport { mkdir, stat } from 'node:fs/promises'\nimport { basename, resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport type { GitOptions } from './index.ts'\nimport { isWindows } from './is-windows.ts'\nimport { resolveRef } from './resolve.ts'\nimport { revs as getRevs } from './revs.ts'\nimport { spawn } from './spawn.ts'\n\n/**\n * Only these whitelisted hosts get shallow cloning. Many hosts (including GHE)\n * don't always support it. A failed shallow fetch takes a LOT longer than a\n * full fetch in most cases, so we skip it entirely. Set opts.gitShallow =\n * true/false to force this behavior one way or the other.\n *\n * If other hosts are added to this set, then they will be shallowly cloned\n * as well.\n */\nexport const shallowHosts = new Set([\n 'github.com',\n 'gist.github.com',\n 'gitlab.com',\n 'bitbucket.com',\n 'bitbucket.org',\n])\n\nexport const clone = async (\n repo: string,\n ref = 'HEAD',\n target: string | undefined = undefined,\n opts: GitOptions = {},\n) => {\n repo = String(gitScpURL(repo) ?? repo).replace(/^git\\+/, '')\n if (repo.startsWith('file://')) repo = fileURLToPath(repo)\n const revs = await getRevs(repo, opts)\n return await clone_(\n repo,\n revs,\n ref,\n revs && resolveRef(revs, ref, opts),\n target || defaultTarget(repo, opts.cwd),\n opts,\n )\n}\n\nconst maybeShallow = (repo: string, opts: GitOptions) => {\n if (opts['git-shallow'] === false || opts['git-shallow']) {\n return opts['git-shallow']\n }\n const host = gitScpURL(repo)?.host ?? ''\n return shallowHosts.has(host)\n}\n\nconst defaultTarget = (\n repo: string,\n /* c8 ignore next */ cwd = process.cwd(),\n) => resolve(cwd, basename(repo.replace(/[/\\\\]?\\.git$/, '')))\n\nconst clone_ = (\n repo: string,\n revs: RevDoc | undefined,\n ref: string,\n revDoc: RevDocEntry | undefined,\n target: string,\n opts: GitOptions,\n) => {\n if (!revDoc || !revs) {\n return unresolved(repo, ref, target, opts)\n }\n if (revDoc.sha === revs.refs.HEAD?.sha) {\n return plain(repo, revDoc, target, opts)\n }\n if (revDoc.type === 'tag' || revDoc.type === 'branch') {\n return branch(repo, revDoc, target, opts)\n }\n return other(repo, revDoc, target, opts)\n}\n\n// pull request or some other kind of advertised ref\nconst other = async (\n repo: string,\n revDoc: RevDocEntry,\n target: string,\n opts: GitOptions,\n) => {\n const shallow = maybeShallow(repo, opts)\n\n const fetchOrigin = ['fetch', 'origin', revDoc.rawRef].concat(\n shallow ? ['--depth=1'] : [],\n )\n\n const git = (args: string[]) =>\n spawn(args, { ...opts, cwd: target })\n await mkdir(target, { recursive: true })\n await git(['init'])\n if (isWindows(opts)) {\n await git([\n 'config',\n '--local',\n '--add',\n 'core.longpaths',\n 'true',\n ])\n }\n await git(['remote', 'add', 'origin', repo])\n await git(fetchOrigin)\n await git(['checkout', revDoc.sha])\n await updateSubmodules(target, opts)\n return revDoc.sha\n}\n\n// tag or branches. use -b\nconst branch = async (\n repo: string,\n revDoc: RevDocEntry,\n target: string,\n opts: GitOptions,\n) => {\n const args = [\n 'clone',\n '-b',\n revDoc.ref,\n repo,\n target,\n '--recurse-submodules',\n ]\n if (maybeShallow(repo, opts)) {\n args.push('--depth=1')\n }\n if (isWindows(opts)) {\n args.push('--config', 'core.longpaths=true')\n }\n await spawn(args, opts)\n return revDoc.sha\n}\n\n// just the head. clone it\nconst plain = async (\n repo: string,\n revDoc: RevDocEntry,\n target: string,\n opts: GitOptions,\n) => {\n const args = ['clone', repo, target, '--recurse-submodules']\n if (maybeShallow(repo, opts)) {\n args.push('--depth=1')\n }\n if (isWindows(opts)) {\n args.push('--config', 'core.longpaths=true')\n }\n await spawn(args, opts)\n return revDoc.sha\n}\n\nconst updateSubmodules = async (target: string, opts: GitOptions) => {\n const hasSubmodules = await stat(`${target}/.gitmodules`)\n .then(() => true)\n .catch(() => false)\n if (!hasSubmodules) {\n return\n }\n await spawn(\n ['submodule', 'update', '-q', '--init', '--recursive'],\n { ...opts, cwd: target },\n )\n}\n\nconst unresolved = async (\n repo: string,\n ref: string,\n target: string,\n opts: GitOptions,\n) => {\n // can't do this one shallowly, because the ref isn't advertised\n // but we can avoid checking out the working dir twice, at least\n const lp =\n isWindows(opts) ? ['--config', 'core.longpaths=true'] : []\n const cloneArgs = [\n 'clone',\n '--mirror',\n '-q',\n repo,\n target + '/.git',\n ]\n const git = (args: string[]) =>\n spawn(args, { ...opts, cwd: target })\n await mkdir(target, { recursive: true })\n await git(cloneArgs.concat(lp))\n await git(['init'])\n await git(['checkout', ref])\n await updateSubmodules(target, opts)\n const result = await git(['rev-parse', '--revs-only', 'HEAD'])\n return result.stdout\n}\n"]}
1
+ {"version":3,"file":"clone.js","sourceRoot":"","sources":["../src/clone.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,mDAAmD;AACnD,EAAE;AACF,wDAAwD;AACxD,uDAAuD;AAGvD,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAC/C,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,IAAI,IAAI,OAAO,EAAE,MAAM,WAAW,CAAA;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAElC;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,YAAY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C,CAAC,CAAC,CAAC,EAAE,CAAA;IAC5D,MAAM,SAAS,GAAG;QAChB,OAAO;QACP,UAAU;QACV,IAAI;QACJ,IAAI;QACJ,MAAM,GAAG,OAAO;KACjB,CAAA;IACD,MAAM,GAAG,GAAG,CAAC,IAAc,EAAE,EAAE,CAC7B,KAAK,CAAC,IAAI,EAAE,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAA;IACvC,MAAM,KAAK,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IACxC,MAAM,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAA;IAC/B,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;IACnB,MAAM,GAAG,CAAC,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC,CAAA;IAC5B,MAAM,gBAAgB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IACpC,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,CAAC,WAAW,EAAE,aAAa,EAAE,MAAM,CAAC,CAAC,CAAA;IAC9D,OAAO,MAAM,CAAC,MAAM,CAAA;AACtB,CAAC,CAAA","sourcesContent":["// The goal here is to minimize both git workload and\n// the number of refs we download over the network.\n//\n// Every method ends up with the checked out working dir\n// at the specified ref, and resolves with the git sha.\n\nimport type { RevDoc, RevDocEntry } from '@vltpkg/types'\nimport { gitScpURL } from '@vltpkg/git-scp-url'\nimport { mkdir, stat } from 'node:fs/promises'\nimport { basename, resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport type { GitOptions } from './index.ts'\nimport { isWindows } from './is-windows.ts'\nimport { resolveRef } from './resolve.ts'\nimport { revs as getRevs } from './revs.ts'\nimport { spawn } from './spawn.ts'\n\n/**\n * Only these whitelisted hosts get shallow cloning. Many hosts (including GHE)\n * don't always support it. A failed shallow fetch takes a LOT longer than a\n * full fetch in most cases, so we skip it entirely. Set opts.gitShallow =\n * true/false to force this behavior one way or the other.\n *\n * If other hosts are added to this set, then they will be shallowly cloned\n * as well.\n */\nexport const shallowHosts = new Set([\n 'github.com',\n 'gist.github.com',\n 'gitlab.com',\n 'bitbucket.com',\n 'bitbucket.org',\n])\n\nexport const clone = async (\n repo: string,\n ref = 'HEAD',\n target?: string,\n opts: GitOptions = {},\n) => {\n repo = String(gitScpURL(repo) ?? repo).replace(/^git\\+/, '')\n if (repo.startsWith('file://')) repo = fileURLToPath(repo)\n const revs = await getRevs(repo, opts)\n return await clone_(\n repo,\n revs,\n ref,\n revs && resolveRef(revs, ref, opts),\n target || defaultTarget(repo, opts.cwd),\n opts,\n )\n}\n\nconst maybeShallow = (repo: string, opts: GitOptions) => {\n if (opts['git-shallow'] === false || opts['git-shallow']) {\n return opts['git-shallow']\n }\n const host = gitScpURL(repo)?.host ?? ''\n return shallowHosts.has(host)\n}\n\nconst defaultTarget = (\n repo: string,\n /* c8 ignore next */ cwd = process.cwd(),\n) => resolve(cwd, basename(repo.replace(/[/\\\\]?\\.git$/, '')))\n\nconst clone_ = (\n repo: string,\n revs: RevDoc | undefined,\n ref: string,\n revDoc: RevDocEntry | undefined,\n target: string,\n opts: GitOptions,\n) => {\n if (!revDoc || !revs) {\n return unresolved(repo, ref, target, opts)\n }\n if (revDoc.sha === revs.refs.HEAD?.sha) {\n return plain(repo, revDoc, target, opts)\n }\n if (revDoc.type === 'tag' || revDoc.type === 'branch') {\n return branch(repo, revDoc, target, opts)\n }\n return other(repo, revDoc, target, opts)\n}\n\n// pull request or some other kind of advertised ref\nconst other = async (\n repo: string,\n revDoc: RevDocEntry,\n target: string,\n opts: GitOptions,\n) => {\n const shallow = maybeShallow(repo, opts)\n\n const fetchOrigin = ['fetch', 'origin', revDoc.rawRef].concat(\n shallow ? ['--depth=1'] : [],\n )\n\n const git = (args: string[]) =>\n spawn(args, { ...opts, cwd: target })\n await mkdir(target, { recursive: true })\n await git(['init'])\n if (isWindows(opts)) {\n await git([\n 'config',\n '--local',\n '--add',\n 'core.longpaths',\n 'true',\n ])\n }\n await git(['remote', 'add', 'origin', repo])\n await git(fetchOrigin)\n await git(['checkout', revDoc.sha])\n await updateSubmodules(target, opts)\n return revDoc.sha\n}\n\n// tag or branches. use -b\nconst branch = async (\n repo: string,\n revDoc: RevDocEntry,\n target: string,\n opts: GitOptions,\n) => {\n const args = [\n 'clone',\n '-b',\n revDoc.ref,\n repo,\n target,\n '--recurse-submodules',\n ]\n if (maybeShallow(repo, opts)) {\n args.push('--depth=1')\n }\n if (isWindows(opts)) {\n args.push('--config', 'core.longpaths=true')\n }\n await spawn(args, opts)\n return revDoc.sha\n}\n\n// just the head. clone it\nconst plain = async (\n repo: string,\n revDoc: RevDocEntry,\n target: string,\n opts: GitOptions,\n) => {\n const args = ['clone', repo, target, '--recurse-submodules']\n if (maybeShallow(repo, opts)) {\n args.push('--depth=1')\n }\n if (isWindows(opts)) {\n args.push('--config', 'core.longpaths=true')\n }\n await spawn(args, opts)\n return revDoc.sha\n}\n\nconst updateSubmodules = async (target: string, opts: GitOptions) => {\n const hasSubmodules = await stat(`${target}/.gitmodules`)\n .then(() => true)\n .catch(() => false)\n if (!hasSubmodules) {\n return\n }\n await spawn(\n ['submodule', 'update', '-q', '--init', '--recursive'],\n { ...opts, cwd: target },\n )\n}\n\nconst unresolved = async (\n repo: string,\n ref: string,\n target: string,\n opts: GitOptions,\n) => {\n // can't do this one shallowly, because the ref isn't advertised\n // but we can avoid checking out the working dir twice, at least\n const lp =\n isWindows(opts) ? ['--config', 'core.longpaths=true'] : []\n const cloneArgs = [\n 'clone',\n '--mirror',\n '-q',\n repo,\n target + '/.git',\n ]\n const git = (args: string[]) =>\n spawn(args, { ...opts, cwd: target })\n await mkdir(target, { recursive: true })\n await git(cloneArgs.concat(lp))\n await git(['init'])\n await git(['checkout', ref])\n await updateSubmodules(target, opts)\n const result = await git(['rev-parse', '--revs-only', 'HEAD'])\n return result.stdout\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vltpkg/git",
3
3
  "description": "a util for spawning git from npm CLI contexts",
4
- "version": "1.0.0-rc.13",
4
+ "version": "1.0.0-rc.14",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/vltpkg/vltpkg.git",
@@ -13,13 +13,13 @@
13
13
  "lru-cache": "^11.2.4",
14
14
  "promise-retry": "^2.0.1",
15
15
  "retry": "^0.13.1",
16
- "@vltpkg/pick-manifest": "1.0.0-rc.13",
17
- "@vltpkg/error-cause": "1.0.0-rc.13",
18
- "@vltpkg/git-scp-url": "1.0.0-rc.13",
19
- "@vltpkg/promise-spawn": "1.0.0-rc.13",
20
- "@vltpkg/semver": "1.0.0-rc.13",
21
- "@vltpkg/spec": "1.0.0-rc.13",
22
- "@vltpkg/which": "1.0.0-rc.13"
16
+ "@vltpkg/error-cause": "1.0.0-rc.14",
17
+ "@vltpkg/pick-manifest": "1.0.0-rc.14",
18
+ "@vltpkg/git-scp-url": "1.0.0-rc.14",
19
+ "@vltpkg/promise-spawn": "1.0.0-rc.14",
20
+ "@vltpkg/which": "1.0.0-rc.14",
21
+ "@vltpkg/semver": "1.0.0-rc.14",
22
+ "@vltpkg/spec": "1.0.0-rc.14"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@eslint/js": "^9.39.1",
@@ -31,7 +31,7 @@
31
31
  "typedoc": "~0.27.9",
32
32
  "typescript": "5.7.3",
33
33
  "typescript-eslint": "^8.49.0",
34
- "@vltpkg/types": "1.0.0-rc.13"
34
+ "@vltpkg/types": "1.0.0-rc.14"
35
35
  },
36
36
  "license": "ISC",
37
37
  "engines": {