@vltpkg/git 0.0.0-6 → 0.0.0-7

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/esm/clone.js CHANGED
@@ -4,9 +4,9 @@
4
4
  // Every method ends up with the checked out working dir
5
5
  // at the specified ref, and resolves with the git sha.
6
6
  import { gitScpURL } from '@vltpkg/git-scp-url';
7
- import { mkdir, stat } from 'fs/promises';
8
- import { basename, resolve } from 'path';
9
- import { fileURLToPath } from 'url';
7
+ import { mkdir, stat } from 'node:fs/promises';
8
+ import { basename, resolve } from 'node:path';
9
+ import { fileURLToPath } from 'node:url';
10
10
  import { isWindows } from "./is-windows.js";
11
11
  import { resolveRef } from "./resolve.js";
12
12
  import { revs as getRevs } from "./revs.js";
@@ -1 +1 @@
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,aAAa,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAA;AAEnC,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,GAAG,IAAI,GAAG,CAAC;IAClC,YAAY;IACZ,iBAAiB;IACjB,YAAY;IACZ,eAAe;IACf,eAAe;CAChB,CAAC,CAAA;AAEF,MAAM,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,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 'fs/promises'\nimport { basename, resolve } from 'path'\nimport { fileURLToPath } from '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,uD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M,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"]}
package/dist/esm/find.js CHANGED
@@ -1,4 +1,4 @@
1
- import { dirname } from 'path';
1
+ import { dirname } from 'node:path';
2
2
  import { is } from "./is.js";
3
3
  export const find = async ({ cwd = process.cwd(), root, } = {}) => {
4
4
  while (true) {
@@ -1 +1 @@
1
- {"version":3,"file":"find.js","sourceRoot":"","sources":["../../src/find.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAC9B,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAM5B,MAAM,CAAC,MAAM,IAAI,GAAG,KAAK,EAAE,EACzB,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,EACnB,IAAI,MACQ,EAAE,EAAE,EAAE;IAClB,OAAO,IAAI,EAAE,CAAC;QACZ,IAAI,MAAM,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;YACtB,OAAO,GAAG,CAAA;QACZ,CAAC;QACD,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;QACzB,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;YACjC,OAAO,SAAS,CAAA;QAClB,CAAC;QACD,GAAG,GAAG,IAAI,CAAA;IACZ,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { dirname } from 'path'\nimport { is } from './is.ts'\n\nexport type FindOpts = {\n cwd?: string\n root?: string\n}\nexport const find = async ({\n cwd = process.cwd(),\n root,\n}: FindOpts = {}) => {\n while (true) {\n if (await is({ cwd })) {\n return cwd\n }\n const next = dirname(cwd)\n if (cwd === root || cwd === next) {\n return undefined\n }\n cwd = next\n }\n}\n"]}
1
+ {"version":3,"file":"find.js","sourceRoot":"","sources":["../../src/find.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAM5B,MAAM,CAAC,MAAM,IAAI,GAAG,KAAK,EAAE,EACzB,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,EACnB,IAAI,MACQ,EAAE,EAAE,EAAE;IAClB,OAAO,IAAI,EAAE,CAAC;QACZ,IAAI,MAAM,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;YACtB,OAAO,GAAG,CAAA;QACZ,CAAC;QACD,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;QACzB,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;YACjC,OAAO,SAAS,CAAA;QAClB,CAAC;QACD,GAAG,GAAG,IAAI,CAAA;IACZ,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { dirname } from 'node:path'\nimport { is } from './is.ts'\n\nexport type FindOpts = {\n cwd?: string\n root?: string\n}\nexport const find = async ({\n cwd = process.cwd(),\n root,\n}: FindOpts = {}) => {\n while (true) {\n if (await is({ cwd })) {\n return cwd\n }\n const next = dirname(cwd)\n if (cwd === root || cwd === next) {\n return undefined\n }\n cwd = next\n }\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import type { PickManifestOptions } from '@vltpkg/pick-manifest';
2
2
  import type { Spec } from '@vltpkg/spec';
3
- import type { SpawnOptions } from 'child_process';
3
+ import type { SpawnOptions } from 'node:child_process';
4
4
  import type { WrapOptions } from 'retry';
5
5
  export * from './clone.ts';
6
6
  export * from './find.ts';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAChE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AAExC,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA;AAC7B,cAAc,SAAS,CAAA;AACvB,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AAEzB;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,mBAAmB,GAC1C,YAAY,GAAG;IACb,uEAAuE;IACvE,GAAG,CAAC,EAAE,MAAM,GAAG,KAAK,CAAA;IACpB,iEAAiE;IACjE,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,wDAAwD;IACxD,IAAI,CAAC,EAAE,IAAI,CAAA;IACX;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,4EAA4E;IAC5E,eAAe,CAAC,EAAE,WAAW,CAAC,SAAS,CAAC,CAAA;IACxC,4EAA4E;IAC5E,oBAAoB,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAA;IAC5C;;;OAGG;IACH,wBAAwB,CAAC,EAAE,WAAW,CAAC,YAAY,CAAC,CAAA;IACpD;;;OAGG;IACH,wBAAwB,CAAC,EAAE,WAAW,CAAC,YAAY,CAAC,CAAA;IACpD;;;OAGG;IACH,YAAY,CAAC,E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Aa,CAAC,EAAE,OAAO,CAAA;CACxB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAKA,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA;AAC7B,cAAc,SAAS,CAAA;AACvB,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA","sourcesContent":["import type { PickManifestOptions } from '@vltpkg/pick-manifest'\nimport type { Spec } from '@vltpkg/spec'\nimport type { SpawnOptions } from 'child_process'\nimport type { WrapOptions } from 'retry'\n\nexport * from './clone.ts'\nexport * from './find.ts'\nexport * from './is-clean.ts'\nexport * from './is.ts'\nexport * from './resolve.ts'\nexport * from './revs.ts'\nexport * from './spawn.ts'\nexport * from './user.ts'\n\n/**\n * This extends all options that can be passed to spawn() or pickManifest.\n */\nexport type GitOptions = PickManifestOptions &\n SpawnOptions & {\n /** the path to git binary, or 'false' to prevent all git operations */\n git?: string | false\n /** the current working directory to perform git operations in */\n cwd?: string\n /** Parsed git specifier to be cloned, if we have one */\n spec?: Spec\n /**\n * Set to a boolean to force cloning with/without `--depth=1`. If left\n * undefined, then shallow cloning will only be performed on hosts known to\n * support it.\n */\n 'git-shallow'?: boolean\n /** Only relevant if `retry` is unset. Value for retry.retries, default 2 */\n 'fetch-retries'?: WrapOptions['retries']\n /** Only relevant if `retry` is unset. Value for retry.factor, default 10 */\n 'fetch-retry-factor'?: WrapOptions['factor']\n /**\n * Only relevant if `retry` is unset. Value for retry.maxTimeout, default\n * 60_000\n */\n 'fetch-retry-maxtimeout'?: WrapOptions['maxTimeout']\n /**\n * Only relevant if `retry` is unset. Value for retry.minTimeout, default\n * 1_000\n */\n 'fetch-retry-mintimeout'?: WrapOptions['minTimeout']\n /**\n * Used to test platform-specific behavior.\n * @internal\n */\n fakePlatform?: NodeJS.Platform\n /**\n * Just to test rev lookup without continually clearing the cache\n */\n noGitRevCache?: boolean\n }\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAKA,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA;AAC7B,cAAc,SAAS,CAAA;AACvB,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA","sourcesContent":["import type { PickManifestOptions } from '@vltpkg/pick-manifest'\nimport type { Spec } from '@vltpkg/spec'\nimport type { SpawnOptions } from 'node:child_process'\nimport type { WrapOptions } from 'retry'\n\nexport * from './clone.ts'\nexport * from './find.ts'\nexport * from './is-clean.ts'\nexport * from './is.ts'\nexport * from './resolve.ts'\nexport * from './revs.ts'\nexport * from './spawn.ts'\nexport * from './user.ts'\n\n/**\n * This extends all options that can be passed to spawn() or pickManifest.\n */\nexport type GitOptions = PickManifestOptions &\n SpawnOptions & {\n /** the path to git binary, or 'false' to prevent all git operations */\n git?: string | false\n /** the current working directory to perform git operations in */\n cwd?: string\n /** Parsed git specifier to be cloned, if we have one */\n spec?: Spec\n /**\n * Set to a boolean to force cloning with/without `--depth=1`. If left\n * undefined, then shallow cloning will only be performed on hosts known to\n * support it.\n */\n 'git-shallow'?: boolean\n /** Only relevant if `retry` is unset. Value for retry.retries, default 2 */\n 'fetch-retries'?: WrapOptions['retries']\n /** Only relevant if `retry` is unset. Value for retry.factor, default 10 */\n 'fetch-retry-factor'?: WrapOptions['factor']\n /**\n * Only relevant if `retry` is unset. Value for retry.maxTimeout, default\n * 60_000\n */\n 'fetch-retry-maxtimeout'?: WrapOptions['maxTimeout']\n /**\n * Only relevant if `retry` is unset. Value for retry.minTimeout, default\n * 1_000\n */\n 'fetch-retry-mintimeout'?: WrapOptions['minTimeout']\n /**\n * Used to test platform-specific behavior.\n * @internal\n */\n fakePlatform?: NodeJS.Platform\n /**\n * Just to test rev lookup without continually clearing the cache\n */\n noGitRevCache?: boolean\n }\n"]}
package/dist/esm/is.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // not an airtight indicator, but a good gut-check to even bother trying
2
- import { stat } from 'fs/promises';
2
+ import { stat } from 'node:fs/promises';
3
3
  export const is = ({ cwd = process.cwd() } = {}) => stat(cwd + '/.git').then(() => true, () => false);
4
4
  //# sourceMappingURL=is.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"is.js","sourceRoot":"","sources":["../../src/is.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAClC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,CACjD,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,CAAC,IAAI,CACtB,GAAG,EAAE,CAAC,IAAI,EACV,GAAG,EAAE,CAAC,KAAK,CACZ,CAAA","sourcesContent":["// not an airtight indicator, but a good gut-check to even bother trying\nimport { stat } from 'fs/promises'\nexport const is = ({ cwd = process.cwd() } = {}) =>\n stat(cwd + '/.git').then(\n () => true,\n () => false,\n )\n"]}
1
+ {"version":3,"file":"is.js","sourceRoot":"","sources":["../../src/is.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AACvC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,CACjD,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,CAAC,IAAI,CACtB,GAAG,EAAE,CAAC,IAAI,EACV,GAAG,EAAE,CAAC,KAAK,CACZ,CAAA","sourcesContent":["// not an airtight indicator, but a good gut-check to even bother trying\nimport { stat } from 'node:fs/promises'\nexport const is = ({ cwd = process.cwd() } = {}) =>\n stat(cwd + '/.git').then(\n () => true,\n () => false,\n )\n"]}
@@ -1,4 +1,4 @@
1
1
  import type { PromiseSpawnOptionsStderrString, PromiseSpawnOptionsStdoutString } from '@vltpkg/promise-spawn';
2
- import type { SpawnOptions } from 'child_process';
2
+ import type { SpawnOptions } from 'node:child_process';
3
3
  export declare const opts: (opts?: SpawnOptions) => PromiseSpawnOptionsStderrString & PromiseSpawnOptionsStdoutString;
4
4
  //# sourceMappingURL=opts.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"opts.d.ts","sourceRoot":"","sources":["../../src/opts.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,+BAA+B,EAC/B,+BAA+B,EAChC,MAAM,uBAAuB,CAAA;AAC9B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAQjD,eAAO,MAAM,IAAI,UACT,YAAY,KACjB,+BAA+B,GAChC,+BAOA,CAAA"}
1
+ {"version":3,"file":"opts.d.ts","sourceRoot":"","sources":["../../src/opts.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,+BAA+B,EAC/B,+BAA+B,EAChC,MAAM,uBAAuB,CAAA;AAC9B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAQtD,eAAO,MAAM,IAAI,UACT,YAAY,KACjB,+BAA+B,GAChC,+BAOA,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"opts.js","sourceRoot":"","sources":["../../src/opts.ts"],"names":[],"mappings":"AAAA,uEAAuE;AAQvE,2DAA2D;AAC3D,MAAM,MAAM,GAAG;IACb,WAAW,EAAE,MAAM;IACnB,eAAe,EAAE,wCAAwC;CAC1D,CAAA;AAED,MAAM,CAAC,MAAM,IAAI,GAAG,CAClB,OAAqB,EAAE,EAES,EAAE,CAAC,CAAC;IACpC,UAAU,EAAE,IAAI;IAChB,GAAG,IAAI;IACP,GAAG,EAAE,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE;IAC9C,KAAK,EAAE,MAAM;IACb,WAAW,EAAE,IAAI;IACjB,KAAK,EAAE,KAAK;CACb,CAAC,CAAA","sourcesContent":["// Values we want to set if they're not already defined by the end user\n\nimport type {\n PromiseSpawnOptionsStderrString,\n PromiseSpawnOptionsStdoutString,\n} from '@vltpkg/promise-spawn'\nimport type { SpawnOptions } from 'child_process'\n\n// This defaults to accepting new ssh host key fingerprints\nconst gitEnv = {\n GIT_ASKPASS: 'echo',\n GIT_SSH_COMMAND: 'ssh -oStrictHostKeyChecking=accept-new',\n}\n\nexport const opts = (\n opts: SpawnOptions = {},\n): PromiseSpawnOptionsStderrString &\n PromiseSpawnOptionsStdoutString => ({\n acceptFail: true,\n ...opts,\n env: opts.env ?? { ...gitEnv, ...process.env },\n stdio: 'pipe',\n stdioString: true,\n shell: false,\n})\n"]}
1
+ {"version":3,"file":"opts.js","sourceRoot":"","sources":["../../src/opts.ts"],"names":[],"mappings":"AAAA,uEAAuE;AAQvE,2DAA2D;AAC3D,MAAM,MAAM,GAAG;IACb,WAAW,EAAE,MAAM;IACnB,eAAe,EAAE,wCAAwC;CAC1D,CAAA;AAED,MAAM,CAAC,MAAM,IAAI,GAAG,CAClB,OAAqB,EAAE,EAES,EAAE,CAAC,CAAC;IACpC,UAAU,EAAE,IAAI;IAChB,GAAG,IAAI;IACP,GAAG,EAAE,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE;IAC9C,KAAK,EAAE,MAAM;IACb,WAAW,EAAE,IAAI;IACjB,KAAK,EAAE,KAAK;CACb,CAAC,CAAA","sourcesContent":["// Values we want to set if they're not already defined by the end user\n\nimport type {\n PromiseSpawnOptionsStderrString,\n PromiseSpawnOptionsStdoutString,\n} from '@vltpkg/promise-spawn'\nimport type { SpawnOptions } from 'node:child_process'\n\n// This defaults to accepting new ssh host key fingerprints\nconst gitEnv = {\n GIT_ASKPASS: 'echo',\n GIT_SSH_COMMAND: 'ssh -oStrictHostKeyChecking=accept-new',\n}\n\nexport const opts = (\n opts: SpawnOptions = {},\n): PromiseSpawnOptionsStderrString &\n PromiseSpawnOptionsStdoutString => ({\n acceptFail: true,\n ...opts,\n env: opts.env ?? { ...gitEnv, ...process.env },\n stdio: 'pipe',\n stdioString: true,\n shell: false,\n})\n"]}
package/dist/esm/revs.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { gitScpURL } from '@vltpkg/git-scp-url';
2
2
  import { LRUCache } from 'lru-cache';
3
- import { fileURLToPath } from 'url';
3
+ import { fileURLToPath } from 'node:url';
4
4
  import { linesToRevs } from "./lines-to-revs.js";
5
5
  import { spawn } from "./spawn.js";
6
6
  const fetchMethod = async (repo, _, options) => {
@@ -1 +1 @@
1
- {"version":3,"file":"revs.js","sourceRoot":"","sources":["../../src/revs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAK/C,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAA;AAEnC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAEhD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAElC,MAAM,WAAW,GAAG,KAAK,EACvB,IAAY,EACZ,CAAM,EACN,OAAgC,EAChC,EAAE;IACF,MAAM,MAAM,GACV,MAAM,KAAK,CAAC,CAAC,WAAW,EAAE,IAAI,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;IACnD,MAAM,OAAO,GAAG,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAA;IACtD,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAED,MAAM,SAAS,GAAG,IAAI,QAAQ,CAA6B;IACzD,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI;IAClB,sBAAsB,EAAE,IAAI;IAC5B,0BAA0B,EAAE,IAAI;IAChC,WAAW;CACZ,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,IAAI,GAAG,KAAK,EAAE,IAAY,EAAE,OAAmB,EAAE,EAAE,EAAE;IAChE,IAAI,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;IAC5D,IAAI,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC;QAAE,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC,CAAA;IAC1D,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;QACvB,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,IAAI,EAAE,SAAS,EAAE;YAChD,OAAO,EAAE,IAAI;SACd,CAAC,CAAA;QACF,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;QAC3B,OAAO,MAAM,CAAA;IACf,CAAC;IACD,OAAO,MAAM,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAA;AACvD,CAAC,CAAA","sourcesContent":["import { gitScpURL } from '@vltpkg/git-scp-url'\nimport type {\n SpawnResultStderrString,\n SpawnResultStdoutString,\n} from '@vltpkg/promise-spawn'\nimport { LRUCache } from 'lru-cache'\nimport { fileURLToPath } from 'url'\nimport type { GitOptions } from './index.ts'\nimport { linesToRevs } from './lines-to-revs.ts'\nimport type { RevDoc } from '@vltpkg/types'\nimport { spawn } from './spawn.ts'\n\nconst fetchMethod = async (\n repo: string,\n _: any,\n options: { context: GitOptions },\n) => {\n const result: SpawnResultStderrString & SpawnResultStdoutString =\n await spawn(['ls-remote', repo], options.context)\n const revsDoc = linesToRevs(result.stdout.split('\\n'))\n return revsDoc\n}\n\nconst revsCache = new LRUCache<string, RevDoc, GitOptions>({\n max: 100,\n ttl: 5 * 60 * 1000,\n allowStaleOnFetchAbort: true,\n allowStaleOnFetchRejection: true,\n fetchMethod,\n})\n\nexport const revs = async (repo: string, opts: GitOptions = {}) => {\n repo = String(gitScpURL(repo) ?? repo).replace(/^git\\+/, '')\n if (repo.startsWith('file://')) repo = fileURLToPath(repo)\n if (opts.noGitRevCache) {\n const result = await fetchMethod(repo, undefined, {\n context: opts,\n })\n revsCache.set(repo, result)\n return result\n }\n return await revsCache.fetch(repo, { context: opts })\n}\n"]}
1
+ {"version":3,"file":"revs.js","sourceRoot":"","sources":["../../src/revs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAK/C,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAEhD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAElC,MAAM,WAAW,GAAG,KAAK,EACvB,IAAY,EACZ,CAAM,EACN,OAAgC,EAChC,EAAE;IACF,MAAM,MAAM,GACV,MAAM,KAAK,CAAC,CAAC,WAAW,EAAE,IAAI,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;IACnD,MAAM,OAAO,GAAG,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAA;IACtD,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAED,MAAM,SAAS,GAAG,IAAI,QAAQ,CAA6B;IACzD,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI;IAClB,sBAAsB,EAAE,IAAI;IAC5B,0BAA0B,EAAE,IAAI;IAChC,WAAW;CACZ,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,IAAI,GAAG,KAAK,EAAE,IAAY,EAAE,OAAmB,EAAE,EAAE,EAAE;IAChE,IAAI,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;IAC5D,IAAI,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC;QAAE,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC,CAAA;IAC1D,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;QACvB,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,IAAI,EAAE,SAAS,EAAE;YAChD,OAAO,EAAE,IAAI;SACd,CAAC,CAAA;QACF,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;QAC3B,OAAO,MAAM,CAAA;IACf,CAAC;IACD,OAAO,MAAM,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAA;AACvD,CAAC,CAAA","sourcesContent":["import { gitScpURL } from '@vltpkg/git-scp-url'\nimport type {\n SpawnResultStderrString,\n SpawnResultStdoutString,\n} from '@vltpkg/promise-spawn'\nimport { LRUCache } from 'lru-cache'\nimport { fileURLToPath } from 'node:url'\nimport type { GitOptions } from './index.ts'\nimport { linesToRevs } from './lines-to-revs.ts'\nimport type { RevDoc } from '@vltpkg/types'\nimport { spawn } from './spawn.ts'\n\nconst fetchMethod = async (\n repo: string,\n _: any,\n options: { context: GitOptions },\n) => {\n const result: SpawnResultStderrString & SpawnResultStdoutString =\n await spawn(['ls-remote', repo], options.context)\n const revsDoc = linesToRevs(result.stdout.split('\\n'))\n return revsDoc\n}\n\nconst revsCache = new LRUCache<string, RevDoc, GitOptions>({\n max: 100,\n ttl: 5 * 60 * 1000,\n allowStaleOnFetchAbort: true,\n allowStaleOnFetchRejection: true,\n fetchMethod,\n})\n\nexport const revs = async (repo: string, opts: GitOptions = {}) => {\n repo = String(gitScpURL(repo) ?? repo).replace(/^git\\+/, '')\n if (repo.startsWith('file://')) repo = fileURLToPath(repo)\n if (opts.noGitRevCache) {\n const result = await fetchMethod(repo, undefined, {\n context: opts,\n })\n revsCache.set(repo, result)\n return result\n }\n return await revsCache.fetch(repo, { context: opts })\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": "0.0.0-6",
4
+ "version": "0.0.0-7",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/vltpkg/vltpkg.git",
@@ -23,13 +23,13 @@
23
23
  "lru-cache": "^11.0.2",
24
24
  "promise-retry": "^2.0.1",
25
25
  "retry": "^0.13.1",
26
- "@vltpkg/error-cause": "0.0.0-6",
27
- "@vltpkg/git-scp-url": "0.0.0-6",
28
- "@vltpkg/pick-manifest": "0.0.0-6",
29
- "@vltpkg/promise-spawn": "0.0.0-6",
30
- "@vltpkg/spec": "0.0.0-6",
31
- "@vltpkg/which": "0.0.0-6",
32
- "@vltpkg/semver": "0.0.0-6"
26
+ "@vltpkg/error-cause": "0.0.0-7",
27
+ "@vltpkg/pick-manifest": "0.0.0-7",
28
+ "@vltpkg/git-scp-url": "0.0.0-7",
29
+ "@vltpkg/promise-spawn": "0.0.0-7",
30
+ "@vltpkg/semver": "0.0.0-7",
31
+ "@vltpkg/spec": "0.0.0-7",
32
+ "@vltpkg/which": "0.0.0-7"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@eslint/js": "^9.20.0",
@@ -43,7 +43,7 @@
43
43
  "typedoc": "0.27.6",
44
44
  "typescript": "5.7.3",
45
45
  "typescript-eslint": "^8.23.0",
46
- "@vltpkg/types": "0.0.0-6"
46
+ "@vltpkg/types": "0.0.0-7"
47
47
  },
48
48
  "license": "ISC",
49
49
  "engines": {