@seasb/metafab 0.0.1 → 1.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/README.md +46 -1
- package/dist/cli.d.ts +11 -0
- package/dist/cli.js +317 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/build.d.ts +2 -0
- package/dist/commands/build.js +70 -0
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/check.d.ts +2 -0
- package/dist/commands/check.js +41 -0
- package/dist/commands/check.js.map +1 -0
- package/dist/commands/create.d.ts +2 -0
- package/dist/commands/create.js +74 -0
- package/dist/commands/create.js.map +1 -0
- package/dist/commands/detach.d.ts +2 -0
- package/dist/commands/detach.js +24 -0
- package/dist/commands/detach.js.map +1 -0
- package/dist/commands/diff.d.ts +2 -0
- package/dist/commands/diff.js +35 -0
- package/dist/commands/diff.js.map +1 -0
- package/dist/commands/import.d.ts +2 -0
- package/dist/commands/import.js +107 -0
- package/dist/commands/import.js.map +1 -0
- package/dist/commands/init.d.ts +2 -0
- package/dist/commands/init.js +77 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/map.d.ts +2 -0
- package/dist/commands/map.js +43 -0
- package/dist/commands/map.js.map +1 -0
- package/dist/commands/not-implemented.d.ts +2 -0
- package/dist/commands/not-implemented.js +19 -0
- package/dist/commands/not-implemented.js.map +1 -0
- package/dist/commands/pipeline-add.d.ts +2 -0
- package/dist/commands/pipeline-add.js +67 -0
- package/dist/commands/pipeline-add.js.map +1 -0
- package/dist/commands/pipeline-remove.d.ts +2 -0
- package/dist/commands/pipeline-remove.js +44 -0
- package/dist/commands/pipeline-remove.js.map +1 -0
- package/dist/commands/publish.d.ts +2 -0
- package/dist/commands/publish.js +147 -0
- package/dist/commands/publish.js.map +1 -0
- package/dist/commands/types.d.ts +45 -0
- package/dist/commands/types.js +2 -0
- package/dist/commands/types.js.map +1 -0
- package/dist/commands/update.d.ts +2 -0
- package/dist/commands/update.js +97 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/core/adopt.d.ts +53 -0
- package/dist/core/adopt.js +676 -0
- package/dist/core/adopt.js.map +1 -0
- package/dist/core/build/agents.d.ts +23 -0
- package/dist/core/build/agents.js +60 -0
- package/dist/core/build/agents.js.map +1 -0
- package/dist/core/build/index.d.ts +4 -0
- package/dist/core/build/index.js +5 -0
- package/dist/core/build/index.js.map +1 -0
- package/dist/core/build/markers.d.ts +34 -0
- package/dist/core/build/markers.js +97 -0
- package/dist/core/build/markers.js.map +1 -0
- package/dist/core/build/plan.d.ts +48 -0
- package/dist/core/build/plan.js +792 -0
- package/dist/core/build/plan.js.map +1 -0
- package/dist/core/build/skill.d.ts +60 -0
- package/dist/core/build/skill.js +275 -0
- package/dist/core/build/skill.js.map +1 -0
- package/dist/core/check/drift.d.ts +13 -0
- package/dist/core/check/drift.js +205 -0
- package/dist/core/check/drift.js.map +1 -0
- package/dist/core/check/index.d.ts +12 -0
- package/dist/core/check/index.js +78 -0
- package/dist/core/check/index.js.map +1 -0
- package/dist/core/check/markers.d.ts +9 -0
- package/dist/core/check/markers.js +220 -0
- package/dist/core/check/markers.js.map +1 -0
- package/dist/core/config/destinations.d.ts +5 -0
- package/dist/core/config/destinations.js +20 -0
- package/dist/core/config/destinations.js.map +1 -0
- package/dist/core/config/load.d.ts +4 -0
- package/dist/core/config/load.js +41 -0
- package/dist/core/config/load.js.map +1 -0
- package/dist/core/config/parse.d.ts +8 -0
- package/dist/core/config/parse.js +198 -0
- package/dist/core/config/parse.js.map +1 -0
- package/dist/core/config/source.d.ts +14 -0
- package/dist/core/config/source.js +44 -0
- package/dist/core/config/source.js.map +1 -0
- package/dist/core/config/types.d.ts +48 -0
- package/dist/core/config/types.js +2 -0
- package/dist/core/config/types.js.map +1 -0
- package/dist/core/config/validate.d.ts +11 -0
- package/dist/core/config/validate.js +351 -0
- package/dist/core/config/validate.js.map +1 -0
- package/dist/core/config/writers.d.ts +14 -0
- package/dist/core/config/writers.js +261 -0
- package/dist/core/config/writers.js.map +1 -0
- package/dist/core/config.d.ts +7 -0
- package/dist/core/config.js +8 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/discovery.d.ts +34 -0
- package/dist/core/discovery.js +272 -0
- package/dist/core/discovery.js.map +1 -0
- package/dist/core/edit/create.d.ts +18 -0
- package/dist/core/edit/create.js +190 -0
- package/dist/core/edit/create.js.map +1 -0
- package/dist/core/edit/document.d.ts +4 -0
- package/dist/core/edit/document.js +16 -0
- package/dist/core/edit/document.js.map +1 -0
- package/dist/core/edit/factory-yaml.d.ts +17 -0
- package/dist/core/edit/factory-yaml.js +211 -0
- package/dist/core/edit/factory-yaml.js.map +1 -0
- package/dist/core/edit/files.d.ts +6 -0
- package/dist/core/edit/files.js +47 -0
- package/dist/core/edit/files.js.map +1 -0
- package/dist/core/edit/index.d.ts +9 -0
- package/dist/core/edit/index.js +10 -0
- package/dist/core/edit/index.js.map +1 -0
- package/dist/core/edit/map.d.ts +24 -0
- package/dist/core/edit/map.js +82 -0
- package/dist/core/edit/map.js.map +1 -0
- package/dist/core/edit/names.d.ts +2 -0
- package/dist/core/edit/names.js +17 -0
- package/dist/core/edit/names.js.map +1 -0
- package/dist/core/edit/paths.d.ts +8 -0
- package/dist/core/edit/paths.js +76 -0
- package/dist/core/edit/paths.js.map +1 -0
- package/dist/core/edit/pipeline.d.ts +19 -0
- package/dist/core/edit/pipeline.js +146 -0
- package/dist/core/edit/pipeline.js.map +1 -0
- package/dist/core/edit/skill.d.ts +1 -0
- package/dist/core/edit/skill.js +10 -0
- package/dist/core/edit/skill.js.map +1 -0
- package/dist/core/factory/discovery.d.ts +9 -0
- package/dist/core/factory/discovery.js +139 -0
- package/dist/core/factory/discovery.js.map +1 -0
- package/dist/core/factory/factory-yaml.d.ts +16 -0
- package/dist/core/factory/factory-yaml.js +375 -0
- package/dist/core/factory/factory-yaml.js.map +1 -0
- package/dist/core/factory/index.d.ts +5 -0
- package/dist/core/factory/index.js +6 -0
- package/dist/core/factory/index.js.map +1 -0
- package/dist/core/factory/lines.d.ts +8 -0
- package/dist/core/factory/lines.js +11 -0
- package/dist/core/factory/lines.js.map +1 -0
- package/dist/core/factory/load.d.ts +4 -0
- package/dist/core/factory/load.js +81 -0
- package/dist/core/factory/load.js.map +1 -0
- package/dist/core/factory/requires.d.ts +9 -0
- package/dist/core/factory/requires.js +123 -0
- package/dist/core/factory/requires.js.map +1 -0
- package/dist/core/factory/types.d.ts +45 -0
- package/dist/core/factory/types.js +2 -0
- package/dist/core/factory/types.js.map +1 -0
- package/dist/core/factory/validate.d.ts +41 -0
- package/dist/core/factory/validate.js +441 -0
- package/dist/core/factory/validate.js.map +1 -0
- package/dist/core/hooks/index.d.ts +8 -0
- package/dist/core/hooks/index.js +15 -0
- package/dist/core/hooks/index.js.map +1 -0
- package/dist/core/hooks/script.d.ts +21 -0
- package/dist/core/hooks/script.js +34 -0
- package/dist/core/hooks/script.js.map +1 -0
- package/dist/core/hooks/sync.d.ts +17 -0
- package/dist/core/hooks/sync.js +262 -0
- package/dist/core/hooks/sync.js.map +1 -0
- package/dist/core/import/conflicts.d.ts +82 -0
- package/dist/core/import/conflicts.js +256 -0
- package/dist/core/import/conflicts.js.map +1 -0
- package/dist/core/import/copy.d.ts +10 -0
- package/dist/core/import/copy.js +76 -0
- package/dist/core/import/copy.js.map +1 -0
- package/dist/core/import/file-tree.d.ts +43 -0
- package/dist/core/import/file-tree.js +107 -0
- package/dist/core/import/file-tree.js.map +1 -0
- package/dist/core/import/index.d.ts +5 -0
- package/dist/core/import/index.js +6 -0
- package/dist/core/import/index.js.map +1 -0
- package/dist/core/import/pipeline-changes.d.ts +8 -0
- package/dist/core/import/pipeline-changes.js +89 -0
- package/dist/core/import/pipeline-changes.js.map +1 -0
- package/dist/core/import/run.d.ts +76 -0
- package/dist/core/import/run.js +258 -0
- package/dist/core/import/run.js.map +1 -0
- package/dist/core/init/gitattributes.d.ts +20 -0
- package/dist/core/init/gitattributes.js +89 -0
- package/dist/core/init/gitattributes.js.map +1 -0
- package/dist/core/init/index.d.ts +4 -0
- package/dist/core/init/index.js +5 -0
- package/dist/core/init/index.js.map +1 -0
- package/dist/core/init/name.d.ts +1 -0
- package/dist/core/init/name.js +4 -0
- package/dist/core/init/name.js.map +1 -0
- package/dist/core/init/run.d.ts +51 -0
- package/dist/core/init/run.js +261 -0
- package/dist/core/init/run.js.map +1 -0
- package/dist/core/init/targets.d.ts +17 -0
- package/dist/core/init/targets.js +87 -0
- package/dist/core/init/targets.js.map +1 -0
- package/dist/core/merge.d.ts +88 -0
- package/dist/core/merge.js +239 -0
- package/dist/core/merge.js.map +1 -0
- package/dist/core/publish/exclude.d.ts +9 -0
- package/dist/core/publish/exclude.js +32 -0
- package/dist/core/publish/exclude.js.map +1 -0
- package/dist/core/publish/git-target.d.ts +32 -0
- package/dist/core/publish/git-target.js +447 -0
- package/dist/core/publish/git-target.js.map +1 -0
- package/dist/core/publish/index.d.ts +10 -0
- package/dist/core/publish/index.js +11 -0
- package/dist/core/publish/index.js.map +1 -0
- package/dist/core/publish/npm-target.d.ts +15 -0
- package/dist/core/publish/npm-target.js +170 -0
- package/dist/core/publish/npm-target.js.map +1 -0
- package/dist/core/publish/package-json.d.ts +31 -0
- package/dist/core/publish/package-json.js +74 -0
- package/dist/core/publish/package-json.js.map +1 -0
- package/dist/core/publish/prepare.d.ts +24 -0
- package/dist/core/publish/prepare.js +93 -0
- package/dist/core/publish/prepare.js.map +1 -0
- package/dist/core/publish/provenance.d.ts +1 -0
- package/dist/core/publish/provenance.js +20 -0
- package/dist/core/publish/provenance.js.map +1 -0
- package/dist/core/publish/publish.d.ts +13 -0
- package/dist/core/publish/publish.js +130 -0
- package/dist/core/publish/publish.js.map +1 -0
- package/dist/core/publish/readme.d.ts +22 -0
- package/dist/core/publish/readme.js +112 -0
- package/dist/core/publish/readme.js.map +1 -0
- package/dist/core/publish/stage.d.ts +19 -0
- package/dist/core/publish/stage.js +333 -0
- package/dist/core/publish/stage.js.map +1 -0
- package/dist/core/publish/types.d.ts +71 -0
- package/dist/core/publish/types.js +2 -0
- package/dist/core/publish/types.js.map +1 -0
- package/dist/core/requires/check.d.ts +15 -0
- package/dist/core/requires/check.js +83 -0
- package/dist/core/requires/check.js.map +1 -0
- package/dist/core/requires/index.d.ts +4 -0
- package/dist/core/requires/index.js +5 -0
- package/dist/core/requires/index.js.map +1 -0
- package/dist/core/requires/inspect.d.ts +44 -0
- package/dist/core/requires/inspect.js +114 -0
- package/dist/core/requires/inspect.js.map +1 -0
- package/dist/core/requires/paths.d.ts +29 -0
- package/dist/core/requires/paths.js +83 -0
- package/dist/core/requires/paths.js.map +1 -0
- package/dist/core/requires/setup.d.ts +37 -0
- package/dist/core/requires/setup.js +147 -0
- package/dist/core/requires/setup.js.map +1 -0
- package/dist/core/setup.d.ts +27 -0
- package/dist/core/setup.js +84 -0
- package/dist/core/setup.js.map +1 -0
- package/dist/core/sources/cache.d.ts +38 -0
- package/dist/core/sources/cache.js +200 -0
- package/dist/core/sources/cache.js.map +1 -0
- package/dist/core/sources/containment.d.ts +21 -0
- package/dist/core/sources/containment.js +50 -0
- package/dist/core/sources/containment.js.map +1 -0
- package/dist/core/sources/env.d.ts +12 -0
- package/dist/core/sources/env.js +28 -0
- package/dist/core/sources/env.js.map +1 -0
- package/dist/core/sources/extract.d.ts +25 -0
- package/dist/core/sources/extract.js +676 -0
- package/dist/core/sources/extract.js.map +1 -0
- package/dist/core/sources/git-process.d.ts +26 -0
- package/dist/core/sources/git-process.js +51 -0
- package/dist/core/sources/git-process.js.map +1 -0
- package/dist/core/sources/git.d.ts +41 -0
- package/dist/core/sources/git.js +511 -0
- package/dist/core/sources/git.js.map +1 -0
- package/dist/core/sources/https.d.ts +21 -0
- package/dist/core/sources/https.js +208 -0
- package/dist/core/sources/https.js.map +1 -0
- package/dist/core/sources/index.d.ts +13 -0
- package/dist/core/sources/index.js +14 -0
- package/dist/core/sources/index.js.map +1 -0
- package/dist/core/sources/npm-cli.d.ts +19 -0
- package/dist/core/sources/npm-cli.js +43 -0
- package/dist/core/sources/npm-cli.js.map +1 -0
- package/dist/core/sources/npm.d.ts +29 -0
- package/dist/core/sources/npm.js +386 -0
- package/dist/core/sources/npm.js.map +1 -0
- package/dist/core/sources/parse.d.ts +32 -0
- package/dist/core/sources/parse.js +389 -0
- package/dist/core/sources/parse.js.map +1 -0
- package/dist/core/sources/path.d.ts +10 -0
- package/dist/core/sources/path.js +316 -0
- package/dist/core/sources/path.js.map +1 -0
- package/dist/core/sources/redact.d.ts +2 -0
- package/dist/core/sources/redact.js +70 -0
- package/dist/core/sources/redact.js.map +1 -0
- package/dist/core/sources/resolve.d.ts +9 -0
- package/dist/core/sources/resolve.js +29 -0
- package/dist/core/sources/resolve.js.map +1 -0
- package/dist/core/sources/types.d.ts +86 -0
- package/dist/core/sources/types.js +2 -0
- package/dist/core/sources/types.js.map +1 -0
- package/dist/core/sources/validate.d.ts +9 -0
- package/dist/core/sources/validate.js +111 -0
- package/dist/core/sources/validate.js.map +1 -0
- package/dist/core/summary.d.ts +77 -0
- package/dist/core/summary.js +405 -0
- package/dist/core/summary.js.map +1 -0
- package/dist/core/update/clashes.d.ts +63 -0
- package/dist/core/update/clashes.js +192 -0
- package/dist/core/update/clashes.js.map +1 -0
- package/dist/core/update/detach.d.ts +21 -0
- package/dist/core/update/detach.js +38 -0
- package/dist/core/update/detach.js.map +1 -0
- package/dist/core/update/diff.d.ts +58 -0
- package/dist/core/update/diff.js +180 -0
- package/dist/core/update/diff.js.map +1 -0
- package/dist/core/update/fetch.d.ts +34 -0
- package/dist/core/update/fetch.js +73 -0
- package/dist/core/update/fetch.js.map +1 -0
- package/dist/core/update/index.d.ts +6 -0
- package/dist/core/update/index.js +7 -0
- package/dist/core/update/index.js.map +1 -0
- package/dist/core/update/restore.d.ts +20 -0
- package/dist/core/update/restore.js +195 -0
- package/dist/core/update/restore.js.map +1 -0
- package/dist/core/update/run.d.ts +113 -0
- package/dist/core/update/run.js +1132 -0
- package/dist/core/update/run.js.map +1 -0
- package/dist/core/update/select.d.ts +39 -0
- package/dist/core/update/select.js +157 -0
- package/dist/core/update/select.js.map +1 -0
- package/dist/core/update/spelling.d.ts +51 -0
- package/dist/core/update/spelling.js +185 -0
- package/dist/core/update/spelling.js.map +1 -0
- package/dist/core/update/trees.d.ts +24 -0
- package/dist/core/update/trees.js +72 -0
- package/dist/core/update/trees.js.map +1 -0
- package/dist/errors.d.ts +29 -0
- package/dist/errors.js +24 -0
- package/dist/errors.js.map +1 -0
- package/dist/help.d.ts +46 -0
- package/dist/help.js +103 -0
- package/dist/help.js.map +1 -0
- package/dist/input.d.ts +25 -0
- package/dist/input.js +173 -0
- package/dist/input.js.map +1 -0
- package/dist/output.d.ts +21 -0
- package/dist/output.js +37 -0
- package/dist/output.js.map +1 -0
- package/dist/util/frontmatter.d.ts +12 -0
- package/dist/util/frontmatter.js +58 -0
- package/dist/util/frontmatter.js.map +1 -0
- package/dist/util/fs.d.ts +32 -0
- package/dist/util/fs.js +126 -0
- package/dist/util/fs.js.map +1 -0
- package/dist/util/git-names.d.ts +8 -0
- package/dist/util/git-names.js +25 -0
- package/dist/util/git-names.js.map +1 -0
- package/dist/util/git.d.ts +12 -0
- package/dist/util/git.js +33 -0
- package/dist/util/git.js.map +1 -0
- package/dist/util/suggest.d.ts +6 -0
- package/dist/util/suggest.js +48 -0
- package/dist/util/suggest.js.map +1 -0
- package/dist/util/text.d.ts +8 -0
- package/dist/util/text.js +19 -0
- package/dist/util/text.js.map +1 -0
- package/dist/util/version.d.ts +7 -0
- package/dist/util/version.js +13 -0
- package/dist/util/version.js.map +1 -0
- package/dist/util/yaml.d.ts +30 -0
- package/dist/util/yaml.js +201 -0
- package/dist/util/yaml.js.map +1 -0
- package/package.json +50 -3
- package/resources/metafab-skill/SKILL.md +99 -0
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { ExitCode, MetafabError } from "../../errors.js";
|
|
5
|
+
import { extractTarball } from "./extract.js";
|
|
6
|
+
import { redact, stripSourceCredentials } from "./redact.js";
|
|
7
|
+
import { dropPayloadFiles, validateFab } from "./validate.js";
|
|
8
|
+
// The compressed download cap is deliberately larger than the 64 MiB extracted
|
|
9
|
+
// total (MAX_FAB_TOTAL_SIZE), so a fab at that total is rejected for its size,
|
|
10
|
+
// not for how well it compressed. npm and HTTPS share this one constant.
|
|
11
|
+
export const MAX_TARBALL_SIZE = 80 * 1024 * 1024;
|
|
12
|
+
export const DEFAULT_HTTPS_TIMEOUT_MS = 60_000;
|
|
13
|
+
export const DEFAULT_HTTPS_IDLE_TIMEOUT_MS = 60_000;
|
|
14
|
+
export const MAX_HTTPS_REDIRECTS = 5;
|
|
15
|
+
class DownloadTooLarge extends Error {
|
|
16
|
+
}
|
|
17
|
+
class DownloadIdle extends Error {
|
|
18
|
+
}
|
|
19
|
+
function fetchError(message, cause) {
|
|
20
|
+
return new MetafabError(redact(message), {
|
|
21
|
+
exitCode: ExitCode.FetchFailed,
|
|
22
|
+
code: "fetch-failed",
|
|
23
|
+
cause,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function describe(error) {
|
|
27
|
+
return error instanceof Error ? error.message : String(error);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The cleanup hook for a fetch that copied a fab into a temporary directory.
|
|
31
|
+
* Best effort: a failed removal never throws, so it cannot hide the caller's
|
|
32
|
+
* own error or result.
|
|
33
|
+
*/
|
|
34
|
+
function tempCleanup(directory) {
|
|
35
|
+
return async () => {
|
|
36
|
+
try {
|
|
37
|
+
await rm(directory, { recursive: true, force: true });
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
// Nothing to report: the directory is temporary either way.
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The URL a redirect points at, or an error when following it would leave
|
|
46
|
+
* HTTPS. The tests use a local HTTP server, so an HTTP source may redirect to
|
|
47
|
+
* HTTP; a production HTTPS source may never fall back to a plain connection.
|
|
48
|
+
*/
|
|
49
|
+
export function redirectTarget(current, location) {
|
|
50
|
+
let next;
|
|
51
|
+
let from;
|
|
52
|
+
try {
|
|
53
|
+
from = new URL(current);
|
|
54
|
+
next = new URL(location, current);
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
throw fetchError(`Cannot download ${current}: the redirect location is not a valid URL`);
|
|
58
|
+
}
|
|
59
|
+
if (next.protocol !== "http:" && next.protocol !== "https:") {
|
|
60
|
+
throw fetchError(`Cannot download ${current}: a redirect to ${next.protocol} is not allowed`);
|
|
61
|
+
}
|
|
62
|
+
if (from.protocol === "https:" && next.protocol !== "https:") {
|
|
63
|
+
throw fetchError(`Cannot download ${current}: a redirect from https to ${next.protocol}//${next.host} is not allowed`);
|
|
64
|
+
}
|
|
65
|
+
return next.toString();
|
|
66
|
+
}
|
|
67
|
+
async function readBody(response, maxBytes, idleTimeoutMs, onIdle) {
|
|
68
|
+
if (response.body === null)
|
|
69
|
+
return Buffer.alloc(0);
|
|
70
|
+
const reader = response.body.getReader();
|
|
71
|
+
const chunks = [];
|
|
72
|
+
let total = 0;
|
|
73
|
+
try {
|
|
74
|
+
for (;;) {
|
|
75
|
+
const read = reader.read();
|
|
76
|
+
read.catch(() => undefined);
|
|
77
|
+
let idleTimer;
|
|
78
|
+
const idle = new Promise((_resolve, reject) => {
|
|
79
|
+
idleTimer = setTimeout(() => {
|
|
80
|
+
reject(new DownloadIdle());
|
|
81
|
+
onIdle();
|
|
82
|
+
}, idleTimeoutMs);
|
|
83
|
+
});
|
|
84
|
+
let result;
|
|
85
|
+
try {
|
|
86
|
+
result = await Promise.race([read, idle]);
|
|
87
|
+
}
|
|
88
|
+
finally {
|
|
89
|
+
if (idleTimer !== undefined)
|
|
90
|
+
clearTimeout(idleTimer);
|
|
91
|
+
}
|
|
92
|
+
const { done, value } = result;
|
|
93
|
+
if (done)
|
|
94
|
+
break;
|
|
95
|
+
if (value === undefined)
|
|
96
|
+
continue;
|
|
97
|
+
total += value.byteLength;
|
|
98
|
+
if (total > maxBytes) {
|
|
99
|
+
await reader.cancel().catch(() => undefined);
|
|
100
|
+
throw new DownloadTooLarge();
|
|
101
|
+
}
|
|
102
|
+
chunks.push(Buffer.from(value));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
finally {
|
|
106
|
+
try {
|
|
107
|
+
reader.releaseLock();
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
void reader.cancel().catch(() => undefined);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return Buffer.concat(chunks, total);
|
|
114
|
+
}
|
|
115
|
+
export async function fetchHttps(source, options = {}) {
|
|
116
|
+
const url = source.spec.url;
|
|
117
|
+
const fetchFn = options.fetch ?? fetch;
|
|
118
|
+
const maxBytes = options.maxBytes ?? MAX_TARBALL_SIZE;
|
|
119
|
+
const responseTimeoutMs = options.timeoutMs ?? DEFAULT_HTTPS_TIMEOUT_MS;
|
|
120
|
+
const idleTimeoutMs = options.idleTimeoutMs ?? DEFAULT_HTTPS_IDLE_TIMEOUT_MS;
|
|
121
|
+
const controller = new AbortController();
|
|
122
|
+
let timer;
|
|
123
|
+
const clearTimer = () => {
|
|
124
|
+
if (timer !== undefined)
|
|
125
|
+
clearTimeout(timer);
|
|
126
|
+
timer = undefined;
|
|
127
|
+
};
|
|
128
|
+
let response;
|
|
129
|
+
let data;
|
|
130
|
+
let currentUrl = url;
|
|
131
|
+
let redirects = 0;
|
|
132
|
+
timer = setTimeout(() => controller.abort(), responseTimeoutMs);
|
|
133
|
+
try {
|
|
134
|
+
for (;;) {
|
|
135
|
+
try {
|
|
136
|
+
response = await fetchFn(currentUrl, { signal: controller.signal, redirect: "manual" });
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
if (controller.signal.aborted)
|
|
140
|
+
throw error;
|
|
141
|
+
throw fetchError(`Cannot download ${url}: ${describe(error)}`, error);
|
|
142
|
+
}
|
|
143
|
+
if (response.status < 300 || response.status >= 400)
|
|
144
|
+
break;
|
|
145
|
+
const location = response.headers.get("location");
|
|
146
|
+
if (location === null) {
|
|
147
|
+
throw fetchError(`Cannot download ${url}: the redirect has no Location header`);
|
|
148
|
+
}
|
|
149
|
+
if (redirects >= MAX_HTTPS_REDIRECTS) {
|
|
150
|
+
throw fetchError(`Cannot download ${url}: more than ${MAX_HTTPS_REDIRECTS} redirects`);
|
|
151
|
+
}
|
|
152
|
+
await response.body?.cancel().catch(() => undefined);
|
|
153
|
+
currentUrl = redirectTarget(currentUrl, location);
|
|
154
|
+
redirects += 1;
|
|
155
|
+
}
|
|
156
|
+
clearTimer();
|
|
157
|
+
if (!response.ok) {
|
|
158
|
+
const status = response.statusText === "" ? `${response.status}` : `${response.status} ${response.statusText}`;
|
|
159
|
+
throw fetchError(`Cannot download ${url}: HTTP ${status}`);
|
|
160
|
+
}
|
|
161
|
+
try {
|
|
162
|
+
data = await readBody(response, maxBytes, idleTimeoutMs, () => controller.abort());
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
if (error instanceof DownloadTooLarge) {
|
|
166
|
+
throw new MetafabError(`Cannot download ${redact(url)}: the tarball is larger than ${maxBytes} bytes`, { exitCode: ExitCode.InvalidFab, code: "invalid-fab" });
|
|
167
|
+
}
|
|
168
|
+
if (controller.signal.aborted)
|
|
169
|
+
throw error;
|
|
170
|
+
throw fetchError(`Cannot download ${url}: ${describe(error)}`, error);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
if (error instanceof DownloadIdle) {
|
|
175
|
+
throw fetchError(`Cannot download ${url}: no data received for ${idleTimeoutMs} ms`, error);
|
|
176
|
+
}
|
|
177
|
+
if (controller.signal.aborted) {
|
|
178
|
+
throw fetchError(`Cannot download ${url}: no response after ${responseTimeoutMs} ms`, error);
|
|
179
|
+
}
|
|
180
|
+
throw error;
|
|
181
|
+
}
|
|
182
|
+
finally {
|
|
183
|
+
clearTimer();
|
|
184
|
+
}
|
|
185
|
+
const staging = await mkdtemp(path.join(tmpdir(), "metafab-https-"));
|
|
186
|
+
const destination = await mkdtemp(path.join(tmpdir(), "metafab-https-fab-"));
|
|
187
|
+
try {
|
|
188
|
+
const tarball = path.join(staging, "fab.tgz");
|
|
189
|
+
await writeFile(tarball, data);
|
|
190
|
+
await extractTarball(tarball, destination, { flattenSingleDirectory: true });
|
|
191
|
+
await dropPayloadFiles(destination);
|
|
192
|
+
await validateFab(destination, { sourceLabel: url });
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
await rm(destination, { recursive: true, force: true });
|
|
196
|
+
throw error;
|
|
197
|
+
}
|
|
198
|
+
finally {
|
|
199
|
+
await rm(staging, { recursive: true, force: true });
|
|
200
|
+
}
|
|
201
|
+
return {
|
|
202
|
+
factoryDir: path.join(destination, ".factory"),
|
|
203
|
+
upstream: { kind: "unversioned", source: stripSourceCredentials(url) },
|
|
204
|
+
versioned: false,
|
|
205
|
+
cleanup: tempCleanup(destination),
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
//# sourceMappingURL=https.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"https.js","sourceRoot":"","sources":["../../../src/core/sources/https.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAE7D,OAAO,EAAE,gBAAgB,EAAE,W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,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,EAAE,CAAC,WAAW,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACxD,MAAM,KAAK,CAAC;IACd,CAAC;YAAS,CAAC;QACT,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACtD,CAAC;IAED,OAAO;QACL,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC;QAC9C,QAAQ,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,sBAAsB,CAAC,GAAG,CAAC,EAAE;QACtE,SAAS,EAAE,KAAK;QAChB,OAAO,EAAE,WAAW,CAAC,WAAW,CAAC;KAClC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from "./types.js";
|
|
2
|
+
export * from "./parse.js";
|
|
3
|
+
export * from "./extract.js";
|
|
4
|
+
export * from "./redact.js";
|
|
5
|
+
export * from "./validate.js";
|
|
6
|
+
export * from "./cache.js";
|
|
7
|
+
export * from "./env.js";
|
|
8
|
+
export * from "./npm-cli.js";
|
|
9
|
+
export * from "./npm.js";
|
|
10
|
+
export * from "./git.js";
|
|
11
|
+
export * from "./https.js";
|
|
12
|
+
export * from "./path.js";
|
|
13
|
+
export * from "./resolve.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from "./types.js";
|
|
2
|
+
export * from "./parse.js";
|
|
3
|
+
export * from "./extract.js";
|
|
4
|
+
export * from "./redact.js";
|
|
5
|
+
export * from "./validate.js";
|
|
6
|
+
export * from "./cache.js";
|
|
7
|
+
export * from "./env.js";
|
|
8
|
+
export * from "./npm-cli.js";
|
|
9
|
+
export * from "./npm.js";
|
|
10
|
+
export * from "./git.js";
|
|
11
|
+
export * from "./https.js";
|
|
12
|
+
export * from "./path.js";
|
|
13
|
+
export * from "./resolve.js";
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/sources/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface NpmInvocation {
|
|
2
|
+
command: string;
|
|
3
|
+
args: string[];
|
|
4
|
+
}
|
|
5
|
+
export interface NpmInvocationOptions {
|
|
6
|
+
platform?: NodeJS.Platform;
|
|
7
|
+
env?: NodeJS.ProcessEnv;
|
|
8
|
+
execPath?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* How to run npm without a shell.
|
|
12
|
+
*
|
|
13
|
+
* On POSIX the `npm` wrapper is an executable, so it is used directly. On
|
|
14
|
+
* Windows npm is `npm.cmd`, and Node refuses to spawn `.cmd`/`.bat` files
|
|
15
|
+
* through `execFile` without `shell: true` (and going through a shell is not an
|
|
16
|
+
* option). Running npm's JavaScript entry point with the current Node binary
|
|
17
|
+
* avoids the wrapper entirely.
|
|
18
|
+
*/
|
|
19
|
+
export declare function npmInvocation(options?: NpmInvocationOptions): Promise<NpmInvocation>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { stat } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { ExitCode, MetafabError } from "../../errors.js";
|
|
4
|
+
async function isFile(candidate) {
|
|
5
|
+
try {
|
|
6
|
+
return (await stat(candidate)).isFile();
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function isNpmCliScript(value) {
|
|
13
|
+
return value !== undefined && /npm-cli\.js$/i.test(value);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* How to run npm without a shell.
|
|
17
|
+
*
|
|
18
|
+
* On POSIX the `npm` wrapper is an executable, so it is used directly. On
|
|
19
|
+
* Windows npm is `npm.cmd`, and Node refuses to spawn `.cmd`/`.bat` files
|
|
20
|
+
* through `execFile` without `shell: true` (and going through a shell is not an
|
|
21
|
+
* option). Running npm's JavaScript entry point with the current Node binary
|
|
22
|
+
* avoids the wrapper entirely.
|
|
23
|
+
*/
|
|
24
|
+
export async function npmInvocation(options = {}) {
|
|
25
|
+
const platform = options.platform ?? process.platform;
|
|
26
|
+
const execPath = options.execPath ?? process.execPath;
|
|
27
|
+
if (platform !== "win32")
|
|
28
|
+
return { command: "npm", args: [] };
|
|
29
|
+
const env = options.env ?? process.env;
|
|
30
|
+
const candidates = [];
|
|
31
|
+
if (isNpmCliScript(env.npm_execpath))
|
|
32
|
+
candidates.push(env.npm_execpath);
|
|
33
|
+
candidates.push(path.join(path.dirname(execPath), "node_modules", "npm", "bin", "npm-cli.js"));
|
|
34
|
+
for (const candidate of candidates) {
|
|
35
|
+
if (await isFile(candidate))
|
|
36
|
+
return { command: execPath, args: [candidate] };
|
|
37
|
+
}
|
|
38
|
+
throw new MetafabError("Cannot run npm: npm could not be found", {
|
|
39
|
+
exitCode: ExitCode.FetchFailed,
|
|
40
|
+
code: "fetch-failed",
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=npm-cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"npm-cli.js","sourceRoot":"","sources":["../../../src/core/sources/npm-cli.ts"],"names":[],"mappings":"AAAA,OAAO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ACnC,IAAI,MAAM,MAAM,CAAC,SAAS,CAAC;YAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC;IAC/E,CAAC;IAED,MAAM,IAAI,YAAY,CAAC,wCAAwC,EAAE;QAC/D,QAAQ,EAAE,QAAQ,CAAC,WAAW;QAC9B,IAAI,EAAE,cAAc;KACrB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { FetchedFab, NpmSourceSpec, Resolved } from "./types.js";
|
|
2
|
+
export interface NpmOptions {
|
|
3
|
+
cwd?: string;
|
|
4
|
+
env?: NodeJS.ProcessEnv;
|
|
5
|
+
registry?: string;
|
|
6
|
+
cache?: string;
|
|
7
|
+
maxTarballSize?: number;
|
|
8
|
+
/** The extracted-size cap, so a test can reach the refusal with a small fab. */
|
|
9
|
+
maxTotalSize?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface ResolveNpmOptions extends NpmOptions {
|
|
12
|
+
to?: string;
|
|
13
|
+
/**
|
|
14
|
+
* True for the version a recorded upstream names. It was accepted once, so
|
|
15
|
+
* the metadata size check is skipped; the checks after the download still
|
|
16
|
+
* apply.
|
|
17
|
+
*/
|
|
18
|
+
recorded?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export type ResolvedNpm = Extract<Resolved, {
|
|
21
|
+
kind: "npm";
|
|
22
|
+
}>;
|
|
23
|
+
/**
|
|
24
|
+
* The versions npm reports. npm 9 prints a scalar `versions` when the package
|
|
25
|
+
* has one published version; every other npm prints a list.
|
|
26
|
+
*/
|
|
27
|
+
export declare function npmVersionList(value: unknown): string[];
|
|
28
|
+
export declare function resolveNpm(spec: NpmSourceSpec, options?: ResolveNpmOptions): Promise<ResolvedNpm>;
|
|
29
|
+
export declare function fetchNpm(source: ResolvedNpm, options?: NpmOptions): Promise<FetchedFab>;
|