@contember/create 2.2.0-alpha.2 → 2.2.0-alpha.20
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/CLAUDE.md +22 -0
- package/dist/development/run.cjs +7 -7
- package/dist/development/run.cjs.map +1 -1
- package/dist/development/run.js +8 -8
- package/dist/development/run.js.map +1 -1
- package/dist/development/src/commands/WorkspaceCreateCommand.cjs +36 -23
- package/dist/development/src/commands/WorkspaceCreateCommand.cjs.map +1 -1
- package/dist/development/src/commands/WorkspaceCreateCommand.js +37 -24
- package/dist/development/src/commands/WorkspaceCreateCommand.js.map +1 -1
- package/dist/development/src/lib/FileSystem.cjs +10 -4
- package/dist/development/src/lib/FileSystem.cjs.map +1 -1
- package/dist/development/src/lib/FileSystem.js +8 -2
- package/dist/development/src/lib/FileSystem.js.map +1 -1
- package/dist/development/src/lib/TemplateInstaller.cjs +71 -60
- package/dist/development/src/lib/TemplateInstaller.cjs.map +1 -1
- package/dist/development/src/lib/TemplateInstaller.js +71 -60
- package/dist/development/src/lib/TemplateInstaller.js.map +1 -1
- package/dist/development/src/lib/fsErrors.cjs +7 -0
- package/dist/development/src/lib/fsErrors.cjs.map +1 -0
- package/dist/development/src/lib/fsErrors.js +7 -0
- package/dist/development/src/lib/fsErrors.js.map +1 -0
- package/dist/development/src/lib/projectPath.cjs +66 -0
- package/dist/development/src/lib/projectPath.cjs.map +1 -0
- package/dist/development/src/lib/projectPath.js +66 -0
- package/dist/development/src/lib/projectPath.js.map +1 -0
- package/dist/development/src/lib/remoteTemplate.cjs +108 -0
- package/dist/development/src/lib/remoteTemplate.cjs.map +1 -0
- package/dist/development/src/lib/remoteTemplate.js +108 -0
- package/dist/development/src/lib/remoteTemplate.js.map +1 -0
- package/dist/development/src/lib/tar.cjs +243 -0
- package/dist/development/src/lib/tar.cjs.map +1 -0
- package/dist/development/src/lib/tar.js +243 -0
- package/dist/development/src/lib/tar.js.map +1 -0
- package/dist/production/run.cjs +7 -7
- package/dist/production/run.cjs.map +1 -1
- package/dist/production/run.js +8 -8
- package/dist/production/run.js.map +1 -1
- package/dist/production/src/commands/WorkspaceCreateCommand.cjs +36 -23
- package/dist/production/src/commands/WorkspaceCreateCommand.cjs.map +1 -1
- package/dist/production/src/commands/WorkspaceCreateCommand.js +37 -24
- package/dist/production/src/commands/WorkspaceCreateCommand.js.map +1 -1
- package/dist/production/src/lib/FileSystem.cjs +10 -4
- package/dist/production/src/lib/FileSystem.cjs.map +1 -1
- package/dist/production/src/lib/FileSystem.js +8 -2
- package/dist/production/src/lib/FileSystem.js.map +1 -1
- package/dist/production/src/lib/TemplateInstaller.cjs +71 -60
- package/dist/production/src/lib/TemplateInstaller.cjs.map +1 -1
- package/dist/production/src/lib/TemplateInstaller.js +71 -60
- package/dist/production/src/lib/TemplateInstaller.js.map +1 -1
- package/dist/production/src/lib/fsErrors.cjs +7 -0
- package/dist/production/src/lib/fsErrors.cjs.map +1 -0
- package/dist/production/src/lib/fsErrors.js +7 -0
- package/dist/production/src/lib/fsErrors.js.map +1 -0
- package/dist/production/src/lib/projectPath.cjs +66 -0
- package/dist/production/src/lib/projectPath.cjs.map +1 -0
- package/dist/production/src/lib/projectPath.js +66 -0
- package/dist/production/src/lib/projectPath.js.map +1 -0
- package/dist/production/src/lib/remoteTemplate.cjs +108 -0
- package/dist/production/src/lib/remoteTemplate.cjs.map +1 -0
- package/dist/production/src/lib/remoteTemplate.js +108 -0
- package/dist/production/src/lib/remoteTemplate.js.map +1 -0
- package/dist/production/src/lib/tar.cjs +243 -0
- package/dist/production/src/lib/tar.cjs.map +1 -0
- package/dist/production/src/lib/tar.js +243 -0
- package/dist/production/src/lib/tar.js.map +1 -0
- package/dist/types/commands/WorkspaceCreateCommand.d.ts +15 -3
- package/dist/types/commands/WorkspaceCreateCommand.d.ts.map +1 -1
- package/dist/types/lib/FileSystem.d.ts +2 -0
- package/dist/types/lib/FileSystem.d.ts.map +1 -1
- package/dist/types/lib/TemplateInstaller.d.ts +9 -1
- package/dist/types/lib/TemplateInstaller.d.ts.map +1 -1
- package/dist/types/lib/fsErrors.d.ts +3 -0
- package/dist/types/lib/fsErrors.d.ts.map +1 -0
- package/dist/types/lib/projectPath.d.ts +12 -0
- package/dist/types/lib/projectPath.d.ts.map +1 -0
- package/dist/types/lib/remoteTemplate.d.ts +15 -0
- package/dist/types/lib/remoteTemplate.d.ts.map +1 -0
- package/dist/types/lib/tar.d.ts +28 -0
- package/dist/types/lib/tar.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -7
- package/resources/templates/default/README.md +3 -1
- package/resources/templates/default/admin/app/components/navigation.tsx +95 -8
- package/resources/templates/default/admin/app/pages/tenant.tsx +328 -77
- package/resources/templates/default/admin/entrypoint/components/login.tsx +1 -1
- package/resources/templates/default/admin/entrypoint/pages/magicLink.tsx +1 -1
- package/resources/templates/default/admin/entrypoint/pages/magicLinkSent.tsx +1 -1
- package/resources/templates/default/admin/entrypoint/pages/passwordReset.tsx +1 -1
- package/resources/templates/default/admin/entrypoint/pages/resetRequest.tsx +1 -1
- package/resources/templates/default/admin/entrypoint/pages/resetRequestSuccess.tsx +1 -1
- package/resources/templates/default/admin/lib/editor/common/editor-inline-toolbar.tsx +3 -0
- package/resources/templates/default/admin/lib/editor/sortable-block.tsx +5 -4
- package/resources/templates/default/admin/lib/tenant/config/auth-policy-list.tsx +86 -0
- package/resources/templates/default/admin/lib/tenant/config/common.tsx +71 -0
- package/resources/templates/default/admin/lib/tenant/config/identity-provider-list.tsx +113 -0
- package/resources/templates/default/admin/lib/tenant/config/index.ts +5 -0
- package/resources/templates/default/admin/lib/tenant/config/mail-template-list.tsx +108 -0
- package/resources/templates/default/admin/lib/tenant/config/tenant-config-view.tsx +182 -0
- package/resources/templates/default/admin/lib/tenant/dict.ts +453 -4
- package/resources/templates/default/admin/lib/tenant/errors.ts +10 -0
- package/resources/templates/default/admin/lib/tenant/forms/add-project-member.tsx +57 -0
- package/resources/templates/default/admin/lib/tenant/forms/change-my-profile.tsx +40 -0
- package/resources/templates/default/admin/lib/tenant/forms/change-profile.tsx +55 -0
- package/resources/templates/default/admin/lib/tenant/forms/common.tsx +9 -2
- package/resources/templates/default/admin/lib/tenant/forms/create-global-api-key.tsx +69 -0
- package/resources/templates/default/admin/lib/tenant/forms/global-roles-control.tsx +113 -0
- package/resources/templates/default/admin/lib/tenant/forms/index.ts +11 -0
- package/resources/templates/default/admin/lib/tenant/forms/invite.tsx +42 -4
- package/resources/templates/default/admin/lib/tenant/forms/login.tsx +4 -10
- package/resources/templates/default/admin/lib/tenant/forms/memberships-control.tsx +3 -1
- package/resources/templates/default/admin/lib/tenant/forms/mfa-code-fields.tsx +81 -0
- package/resources/templates/default/admin/lib/tenant/forms/passwordless-signin.tsx +4 -10
- package/resources/templates/default/admin/lib/tenant/forms/set-person-password.tsx +58 -0
- package/resources/templates/default/admin/lib/tenant/forms/set-project-secret.tsx +59 -0
- package/resources/templates/default/admin/lib/tenant/forms/sign-up.tsx +73 -0
- package/resources/templates/default/admin/lib/tenant/hooks/index.ts +2 -0
- package/resources/templates/default/admin/lib/tenant/idp/identity-provider-connections.tsx +124 -0
- package/resources/templates/default/admin/lib/tenant/idp/index.ts +1 -0
- package/resources/templates/default/admin/lib/tenant/index.ts +7 -0
- package/resources/templates/default/admin/lib/tenant/listing/api-key-list.tsx +160 -22
- package/resources/templates/default/admin/lib/tenant/listing/auth-log-list.tsx +179 -0
- package/resources/templates/default/admin/lib/tenant/listing/global-api-key-list.tsx +149 -0
- package/resources/templates/default/admin/lib/tenant/listing/index.ts +7 -0
- package/resources/templates/default/admin/lib/tenant/listing/member-delete-dialog.tsx +1 -1
- package/resources/templates/default/admin/lib/tenant/listing/member-list.tsx +20 -11
- package/resources/templates/default/admin/lib/tenant/listing/mfa.tsx +29 -0
- package/resources/templates/default/admin/lib/tenant/listing/person-actions.tsx +179 -0
- package/resources/templates/default/admin/lib/tenant/listing/person-detail.tsx +141 -0
- package/resources/templates/default/admin/lib/tenant/listing/person-list.tsx +13 -2
- package/resources/templates/default/admin/lib/tenant/listing/persons-list.tsx +128 -0
- package/resources/templates/default/admin/lib/tenant/listing/project-secret-list.tsx +82 -0
- package/resources/templates/default/admin/lib/tenant/otp/backup-codes.tsx +81 -0
- package/resources/templates/default/admin/lib/tenant/otp/email-otp-setup.tsx +133 -0
- package/resources/templates/default/admin/lib/tenant/otp/index.ts +2 -0
- package/resources/templates/default/admin/lib/tenant/security/index.ts +2 -0
- package/resources/templates/default/admin/lib/tenant/security/passwordless-toggle.tsx +63 -0
- package/resources/templates/default/admin/lib/tenant/security/session-list.tsx +143 -0
- package/resources/templates/default/admin/lib/ui/label.tsx +25 -2
- package/resources/templates/default/admin/lib/ui/menu.tsx +1 -1
- package/resources/templates/default/admin/lib/ui/progress.tsx +75 -11
- package/resources/templates/default/admin/lib/ui/separator.tsx +27 -3
- package/resources/templates/default/admin/lib/ui/sidebar.tsx +1 -1
- package/resources/templates/default/admin/lib/ui/toggle.tsx +41 -2
- package/resources/templates/default/admin/lib/utils/classNames.ts +107 -0
- package/resources/templates/default/admin/lib/utils/cn.ts +3 -3
- package/resources/templates/default/admin/lib/utils/index.ts +1 -0
- package/resources/templates/default/admin/lib/utils/uic.tsx +2 -3
- package/resources/templates/default/admin/package.json +1 -7
- package/resources/templates/default/docker/object-storage/README.md +13 -0
- package/resources/templates/default/docker/object-storage/identities.json +13 -0
- package/resources/templates/default/docker-compose.yaml +29 -7
- package/src/commands/WorkspaceCreateCommand.ts +51 -24
- package/src/lib/FileSystem.ts +7 -2
- package/src/lib/TemplateInstaller.ts +87 -69
- package/src/lib/fsErrors.ts +2 -0
- package/src/lib/projectPath.ts +79 -0
- package/src/lib/remoteTemplate.ts +130 -0
- package/src/lib/tar.ts +283 -0
- package/src/run.ts +8 -7
- package/tests/cases/unit/create-process.test.ts +66 -0
- package/tests/cases/unit/fileSystem.test.ts +14 -0
- package/tests/cases/unit/fixtures/template.tar.gz +0 -0
- package/tests/cases/unit/remoteTemplate.test.ts +277 -0
- package/tests/cases/unit/template-installer-cleanup.test.ts +150 -0
- package/tests/cases/unit/template-installer-containment.test.ts +133 -0
- package/tests/cases/unit/template-installer-symlinks.test.ts +37 -0
- package/tests/cases/unit/workspace-create.test.ts +81 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projectPath.cjs","sources":["../../../../../packages/create/src/lib/projectPath.ts"],"sourcesContent":["import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path'\nimport { FileSystem } from './FileSystem.js'\nimport { isNotFound } from './fsErrors.js'\n\n/**\n * Resolves a path from a template directive against the project root.\n * Refuses absolute paths, the root itself and anything that leaves the root, lexically or through a symlink.\n */\nexport const resolveProjectPath = async (fs: FileSystem, root: string, path: string): Promise<string> => {\n\tconst outside = new Error(`Template path \"${path}\" points outside the project`)\n\tif (isAbsolute(path)) {\n\t\tthrow outside\n\t}\n\tconst resolved = resolve(root, path)\n\tif (!isStrictlyInside(root, resolved)) {\n\t\tthrow outside\n\t}\n\tconst realRoot = await fs.realPath(root)\n\tconst realPath = await resolveExistingPrefix(fs, resolved)\n\tif (realPath === undefined) {\n\t\tthrow new Error(`Template path \"${path}\" passes through a dangling symlink`)\n\t}\n\tif (!isStrictlyInside(realRoot, realPath)) {\n\t\tthrow outside\n\t}\n\treturn resolved\n}\n\n/**\n * Like resolveProjectPath, and the path must not exist yet. fs.cp into an existing directory writes entries the check\n * above never saw, and Bun's fs.cp follows symlinks it finds there.\n */\nexport const resolveNewProjectPath = async (fs: FileSystem, root: string, path: string): Promise<string> => {\n\tconst resolved = await resolveProjectPath(fs, root, path)\n\tif (await isPresent(fs, resolved)) {\n\t\tthrow new Error(`Template path \"${path}\" already exists`)\n\t}\n\treturn resolved\n}\n\nconst isStrictlyInside = (root: string, path: string): boolean => {\n\tconst rel = relative(root, path)\n\treturn rel !== '' && rel !== '..' && !rel.startsWith(`..${sep}`) && !isAbsolute(rel)\n}\n\n/**\n * realpath() of the longest existing prefix, with the missing components appended (they cannot be symlinks).\n * Returns undefined for a dangling symlink: writing to it would create its target, wherever that is.\n */\nconst resolveExistingPrefix = async (fs: FileSystem, path: string): Promise<string | undefined> => {\n\ttry {\n\t\treturn await fs.realPath(path)\n\t} catch (error) {\n\t\tif (!isNotFound(error)) {\n\t\t\tthrow error\n\t\t}\n\t}\n\tif (await isPresent(fs, path)) {\n\t\treturn undefined\n\t}\n\tconst parent = dirname(path)\n\tif (parent === path) {\n\t\treturn path\n\t}\n\tconst realParent = await resolveExistingPrefix(fs, parent)\n\treturn realParent === undefined ? undefined : join(realParent, basename(path))\n}\n\nconst isPresent = async (fs: FileSystem, path: string): Promise<boolean> => {\n\ttry {\n\t\tawait fs.lstat(path)\n\t\treturn true\n\t} catch (error) {\n\t\tif (isNotFound(error)) {\n\t\t\treturn false\n\t\t}\n\t\tthrow error\n\t}\n}\n"],"names":["path","isAbsolute","resolve","relative","sep","isNotFound","dirname","join","basename"],"mappings":";;;;AAQO,MAAM,qBAAqB,OAAO,IAAgB,MAAcA,WAAkC;AACxG,QAAM,UAAU,IAAI,MAAM,kBAAkBA,MAAI,8BAA8B;AAC9E,MAAIC,KAAAA,WAAWD,MAAI,GAAG;AACrB,UAAM;AAAA,EACP;AACA,QAAM,WAAWE,KAAAA,QAAQ,MAAMF,MAAI;AACnC,MAAI,CAAC,iBAAiB,MAAM,QAAQ,GAAG;AACtC,UAAM;AAAA,EACP;AACA,QAAM,WAAW,MAAM,GAAG,SAAS,IAAI;AACvC,QAAM,WAAW,MAAM,sBAAsB,IAAI,QAAQ;AACzD,MAAI,aAAa,QAAW;AAC3B,UAAM,IAAI,MAAM,kBAAkBA,MAAI,qCAAqC;AAAA,EAC5E;AACA,MAAI,CAAC,iBAAiB,UAAU,QAAQ,GAAG;AAC1C,UAAM;AAAA,EACP;AACA,SAAO;AACR;AAMO,MAAM,wBAAwB,OAAO,IAAgB,MAAcA,UAAkC;AAC3G,QAAM,WAAW,MAAM,mBAAmB,IAAI,MAAMA,KAAI;AACxD,MAAI,MAAM,UAAU,IAAI,QAAQ,GAAG;AAClC,UAAM,IAAI,MAAM,kBAAkBA,KAAI,kBAAkB;AAAA,EACzD;AACA,SAAO;AACR;AAEA,MAAM,mBAAmB,CAAC,MAAcA,WAA0B;AACjE,QAAM,MAAMG,KAAAA,SAAS,MAAMH,MAAI;AAC/B,SAAO,QAAQ,MAAM,QAAQ,QAAQ,CAAC,IAAI,WAAW,KAAKI,KAAAA,GAAG,EAAE,KAAK,CAACH,KAAAA,WAAW,GAAG;AACpF;AAMA,MAAM,wBAAwB,OAAO,IAAgBD,WAA8C;AAClG,MAAI;AACH,WAAO,MAAM,GAAG,SAASA,MAAI;AAAA,EAC9B,SAAS,OAAO;AACf,QAAI,CAACK,SAAAA,WAAW,KAAK,GAAG;AACvB,YAAM;AAAA,IACP;AAAA,EACD;AACA,MAAI,MAAM,UAAU,IAAIL,MAAI,GAAG;AAC9B,WAAO;AAAA,EACR;AACA,QAAM,SAASM,KAAAA,QAAQN,MAAI;AAC3B,MAAI,WAAWA,QAAM;AACpB,WAAOA;AAAAA,EACR;AACA,QAAM,aAAa,MAAM,sBAAsB,IAAI,MAAM;AACzD,SAAO,eAAe,SAAY,SAAYO,KAAAA,KAAK,YAAYC,KAAAA,SAASR,MAAI,CAAC;AAC9E;AAEA,MAAM,YAAY,OAAO,IAAgBA,UAAmC;AAC3E,MAAI;AACH,UAAM,GAAG,MAAMA,KAAI;AACnB,WAAO;AAAA,EACR,SAAS,OAAO;AACf,QAAIK,SAAAA,WAAW,KAAK,GAAG;AACtB,aAAO;AAAA,IACR;AACA,UAAM;AAAA,EACP;AACD;;;"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { isAbsolute, resolve, relative, sep, dirname, join, basename } from "node:path";
|
|
2
|
+
import { isNotFound } from "./fsErrors.js";
|
|
3
|
+
const resolveProjectPath = async (fs, root, path) => {
|
|
4
|
+
const outside = new Error(`Template path "${path}" points outside the project`);
|
|
5
|
+
if (isAbsolute(path)) {
|
|
6
|
+
throw outside;
|
|
7
|
+
}
|
|
8
|
+
const resolved = resolve(root, path);
|
|
9
|
+
if (!isStrictlyInside(root, resolved)) {
|
|
10
|
+
throw outside;
|
|
11
|
+
}
|
|
12
|
+
const realRoot = await fs.realPath(root);
|
|
13
|
+
const realPath = await resolveExistingPrefix(fs, resolved);
|
|
14
|
+
if (realPath === void 0) {
|
|
15
|
+
throw new Error(`Template path "${path}" passes through a dangling symlink`);
|
|
16
|
+
}
|
|
17
|
+
if (!isStrictlyInside(realRoot, realPath)) {
|
|
18
|
+
throw outside;
|
|
19
|
+
}
|
|
20
|
+
return resolved;
|
|
21
|
+
};
|
|
22
|
+
const resolveNewProjectPath = async (fs, root, path) => {
|
|
23
|
+
const resolved = await resolveProjectPath(fs, root, path);
|
|
24
|
+
if (await isPresent(fs, resolved)) {
|
|
25
|
+
throw new Error(`Template path "${path}" already exists`);
|
|
26
|
+
}
|
|
27
|
+
return resolved;
|
|
28
|
+
};
|
|
29
|
+
const isStrictlyInside = (root, path) => {
|
|
30
|
+
const rel = relative(root, path);
|
|
31
|
+
return rel !== "" && rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute(rel);
|
|
32
|
+
};
|
|
33
|
+
const resolveExistingPrefix = async (fs, path) => {
|
|
34
|
+
try {
|
|
35
|
+
return await fs.realPath(path);
|
|
36
|
+
} catch (error) {
|
|
37
|
+
if (!isNotFound(error)) {
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (await isPresent(fs, path)) {
|
|
42
|
+
return void 0;
|
|
43
|
+
}
|
|
44
|
+
const parent = dirname(path);
|
|
45
|
+
if (parent === path) {
|
|
46
|
+
return path;
|
|
47
|
+
}
|
|
48
|
+
const realParent = await resolveExistingPrefix(fs, parent);
|
|
49
|
+
return realParent === void 0 ? void 0 : join(realParent, basename(path));
|
|
50
|
+
};
|
|
51
|
+
const isPresent = async (fs, path) => {
|
|
52
|
+
try {
|
|
53
|
+
await fs.lstat(path);
|
|
54
|
+
return true;
|
|
55
|
+
} catch (error) {
|
|
56
|
+
if (isNotFound(error)) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
export {
|
|
63
|
+
resolveNewProjectPath,
|
|
64
|
+
resolveProjectPath
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=projectPath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projectPath.js","sources":["../../../../../packages/create/src/lib/projectPath.ts"],"sourcesContent":["import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path'\nimport { FileSystem } from './FileSystem.js'\nimport { isNotFound } from './fsErrors.js'\n\n/**\n * Resolves a path from a template directive against the project root.\n * Refuses absolute paths, the root itself and anything that leaves the root, lexically or through a symlink.\n */\nexport const resolveProjectPath = async (fs: FileSystem, root: string, path: string): Promise<string> => {\n\tconst outside = new Error(`Template path \"${path}\" points outside the project`)\n\tif (isAbsolute(path)) {\n\t\tthrow outside\n\t}\n\tconst resolved = resolve(root, path)\n\tif (!isStrictlyInside(root, resolved)) {\n\t\tthrow outside\n\t}\n\tconst realRoot = await fs.realPath(root)\n\tconst realPath = await resolveExistingPrefix(fs, resolved)\n\tif (realPath === undefined) {\n\t\tthrow new Error(`Template path \"${path}\" passes through a dangling symlink`)\n\t}\n\tif (!isStrictlyInside(realRoot, realPath)) {\n\t\tthrow outside\n\t}\n\treturn resolved\n}\n\n/**\n * Like resolveProjectPath, and the path must not exist yet. fs.cp into an existing directory writes entries the check\n * above never saw, and Bun's fs.cp follows symlinks it finds there.\n */\nexport const resolveNewProjectPath = async (fs: FileSystem, root: string, path: string): Promise<string> => {\n\tconst resolved = await resolveProjectPath(fs, root, path)\n\tif (await isPresent(fs, resolved)) {\n\t\tthrow new Error(`Template path \"${path}\" already exists`)\n\t}\n\treturn resolved\n}\n\nconst isStrictlyInside = (root: string, path: string): boolean => {\n\tconst rel = relative(root, path)\n\treturn rel !== '' && rel !== '..' && !rel.startsWith(`..${sep}`) && !isAbsolute(rel)\n}\n\n/**\n * realpath() of the longest existing prefix, with the missing components appended (they cannot be symlinks).\n * Returns undefined for a dangling symlink: writing to it would create its target, wherever that is.\n */\nconst resolveExistingPrefix = async (fs: FileSystem, path: string): Promise<string | undefined> => {\n\ttry {\n\t\treturn await fs.realPath(path)\n\t} catch (error) {\n\t\tif (!isNotFound(error)) {\n\t\t\tthrow error\n\t\t}\n\t}\n\tif (await isPresent(fs, path)) {\n\t\treturn undefined\n\t}\n\tconst parent = dirname(path)\n\tif (parent === path) {\n\t\treturn path\n\t}\n\tconst realParent = await resolveExistingPrefix(fs, parent)\n\treturn realParent === undefined ? undefined : join(realParent, basename(path))\n}\n\nconst isPresent = async (fs: FileSystem, path: string): Promise<boolean> => {\n\ttry {\n\t\tawait fs.lstat(path)\n\t\treturn true\n\t} catch (error) {\n\t\tif (isNotFound(error)) {\n\t\t\treturn false\n\t\t}\n\t\tthrow error\n\t}\n}\n"],"names":[],"mappings":";;AAQO,MAAM,qBAAqB,OAAO,IAAgB,MAAc,SAAkC;AACxG,QAAM,UAAU,IAAI,MAAM,kBAAkB,IAAI,8BAA8B;AAC9E,MAAI,WAAW,IAAI,GAAG;AACrB,UAAM;AAAA,EACP;AACA,QAAM,WAAW,QAAQ,MAAM,IAAI;AACnC,MAAI,CAAC,iBAAiB,MAAM,QAAQ,GAAG;AACtC,UAAM;AAAA,EACP;AACA,QAAM,WAAW,MAAM,GAAG,SAAS,IAAI;AACvC,QAAM,WAAW,MAAM,sBAAsB,IAAI,QAAQ;AACzD,MAAI,aAAa,QAAW;AAC3B,UAAM,IAAI,MAAM,kBAAkB,IAAI,qCAAqC;AAAA,EAC5E;AACA,MAAI,CAAC,iBAAiB,UAAU,QAAQ,GAAG;AAC1C,UAAM;AAAA,EACP;AACA,SAAO;AACR;AAMO,MAAM,wBAAwB,OAAO,IAAgB,MAAc,SAAkC;AAC3G,QAAM,WAAW,MAAM,mBAAmB,IAAI,MAAM,IAAI;AACxD,MAAI,MAAM,UAAU,IAAI,QAAQ,GAAG;AAClC,UAAM,IAAI,MAAM,kBAAkB,IAAI,kBAAkB;AAAA,EACzD;AACA,SAAO;AACR;AAEA,MAAM,mBAAmB,CAAC,MAAc,SAA0B;AACjE,QAAM,MAAM,SAAS,MAAM,IAAI;AAC/B,SAAO,QAAQ,MAAM,QAAQ,QAAQ,CAAC,IAAI,WAAW,KAAK,GAAG,EAAE,KAAK,CAAC,WAAW,GAAG;AACpF;AAMA,MAAM,wBAAwB,OAAO,IAAgB,SAA8C;AAClG,MAAI;AACH,WAAO,MAAM,GAAG,SAAS,IAAI;AAAA,EAC9B,SAAS,OAAO;AACf,QAAI,CAAC,WAAW,KAAK,GAAG;AACvB,YAAM;AAAA,IACP;AAAA,EACD;AACA,MAAI,MAAM,UAAU,IAAI,IAAI,GAAG;AAC9B,WAAO;AAAA,EACR;AACA,QAAM,SAAS,QAAQ,IAAI;AAC3B,MAAI,WAAW,MAAM;AACpB,WAAO;AAAA,EACR;AACA,QAAM,aAAa,MAAM,sBAAsB,IAAI,MAAM;AACzD,SAAO,eAAe,SAAY,SAAY,KAAK,YAAY,SAAS,IAAI,CAAC;AAC9E;AAEA,MAAM,YAAY,OAAO,IAAgB,SAAmC;AAC3E,MAAI;AACH,UAAM,GAAG,MAAM,IAAI;AACnB,WAAO;AAAA,EACR,SAAS,OAAO;AACf,QAAI,WAAW,KAAK,GAAG;AACtB,aAAO;AAAA,IACR;AACA,UAAM;AAAA,EACP;AACD;"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const fs = require("node:fs/promises");
|
|
4
|
+
const node_util = require("node:util");
|
|
5
|
+
const zlib = require("node:zlib");
|
|
6
|
+
const tar = require("./tar.cjs");
|
|
7
|
+
const hosts = /* @__PURE__ */ new Set(["github", "gitlab", "bitbucket", "git.sr.ht"]);
|
|
8
|
+
const isTemplateHost = (value) => hosts.has(value);
|
|
9
|
+
const sourcePattern = /^(?:(?:https:\/\/)?([^:/]+\.[^:/]+)\/|git@([^:/]+)[:/]|([^/]+):)?([^/\s]+)\/([^/\s#]+)(?:((?:\/[^/\s#]+)+))?(?:\/)?(?:#(.+))?/;
|
|
10
|
+
const isSafeSegment = (segment) => segment !== "" && segment !== "." && segment !== "..";
|
|
11
|
+
const parseTemplateSource = (source) => {
|
|
12
|
+
const match = sourcePattern.exec(source);
|
|
13
|
+
if (!match) {
|
|
14
|
+
throw new Error(`Could not parse template source ${JSON.stringify(source)}`);
|
|
15
|
+
}
|
|
16
|
+
const host = (match[1] ?? match[2] ?? match[3] ?? "github").replace(/\.(com|org)$/, "");
|
|
17
|
+
if (!isTemplateHost(host)) {
|
|
18
|
+
throw new Error("Remote templates are supported from GitHub, GitLab, Bitbucket and Sourcehut");
|
|
19
|
+
}
|
|
20
|
+
const user = match[4];
|
|
21
|
+
const name = match[5].replace(/\.git$/, "");
|
|
22
|
+
const subdir = (match[6] ?? "").split("/").filter((it) => it !== "");
|
|
23
|
+
const ref = match[7] ?? "HEAD";
|
|
24
|
+
if (![user, name, ...subdir, ...ref.split("/")].every(isSafeSegment)) {
|
|
25
|
+
throw new Error(`Could not parse template source ${JSON.stringify(source)}`);
|
|
26
|
+
}
|
|
27
|
+
return { host, user, name, subdir, ref };
|
|
28
|
+
};
|
|
29
|
+
const templateArchiveUrl = ({ host, user, name, ref }) => {
|
|
30
|
+
const repo = `${encodeURIComponent(user)}/${encodeURIComponent(name)}`;
|
|
31
|
+
const path = ref.split("/").map(encodeURIComponent).join("/");
|
|
32
|
+
switch (host) {
|
|
33
|
+
case "github":
|
|
34
|
+
return `https://github.com/${repo}/archive/${path}.tar.gz`;
|
|
35
|
+
case "gitlab":
|
|
36
|
+
return `https://gitlab.com/${repo}/-/archive/${path}/${encodeURIComponent(`${name}-${ref.split("/").join("-")}`)}.tar.gz`;
|
|
37
|
+
case "bitbucket":
|
|
38
|
+
return `https://bitbucket.org/${repo}/get/${path}.tar.gz`;
|
|
39
|
+
case "git.sr.ht":
|
|
40
|
+
return `https://git.sr.ht/${repo}/archive/${path}.tar.gz`;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const maxArchiveBytes = 64 * 1024 * 1024;
|
|
44
|
+
const maxExtractedBytes = 512 * 1024 * 1024;
|
|
45
|
+
const readBody = async (response, url) => {
|
|
46
|
+
const declared = Number(response.headers.get("content-length"));
|
|
47
|
+
if (declared > maxArchiveBytes) {
|
|
48
|
+
throw new Error(`Template archive ${url} is larger than ${maxArchiveBytes} bytes`);
|
|
49
|
+
}
|
|
50
|
+
if (!response.body) {
|
|
51
|
+
return new Uint8Array();
|
|
52
|
+
}
|
|
53
|
+
const chunks = [];
|
|
54
|
+
let total = 0;
|
|
55
|
+
for await (const chunk of response.body) {
|
|
56
|
+
total += chunk.length;
|
|
57
|
+
if (total > maxArchiveBytes) {
|
|
58
|
+
throw new Error(`Template archive ${url} is larger than ${maxArchiveBytes} bytes`);
|
|
59
|
+
}
|
|
60
|
+
chunks.push(chunk);
|
|
61
|
+
}
|
|
62
|
+
return Buffer.concat(chunks);
|
|
63
|
+
};
|
|
64
|
+
const maxRedirects = 5;
|
|
65
|
+
const fetchOverHttps = async (url, fetchArchive) => {
|
|
66
|
+
let current = url;
|
|
67
|
+
for (let hop = 0; ; hop++) {
|
|
68
|
+
let response;
|
|
69
|
+
try {
|
|
70
|
+
response = await fetchArchive(current, { redirect: "manual" });
|
|
71
|
+
} catch (error) {
|
|
72
|
+
throw new Error(`Could not download ${current}: ${error}. Behind a proxy, Node needs NODE_USE_ENV_PROXY=1 with HTTPS_PROXY.`);
|
|
73
|
+
}
|
|
74
|
+
if (response.status < 300 || response.status >= 400) {
|
|
75
|
+
if (!response.ok) {
|
|
76
|
+
throw new Error(`Could not download ${current}: HTTP ${response.status}`);
|
|
77
|
+
}
|
|
78
|
+
return response;
|
|
79
|
+
}
|
|
80
|
+
const location = response.headers.get("location");
|
|
81
|
+
if (location === null || hop >= maxRedirects) {
|
|
82
|
+
throw new Error(`Could not download ${url}: too many or invalid redirects`);
|
|
83
|
+
}
|
|
84
|
+
const next = new URL(location, current);
|
|
85
|
+
if (next.protocol !== "https:") {
|
|
86
|
+
throw new Error(`Could not download ${url}: redirected to a non-HTTPS location`);
|
|
87
|
+
}
|
|
88
|
+
current = next.href;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const downloadTemplate = async (source, targetDir, fetchArchive = fetch) => {
|
|
92
|
+
const parsed = parseTemplateSource(source);
|
|
93
|
+
const url = templateArchiveUrl(parsed);
|
|
94
|
+
const response = await fetchOverHttps(url, fetchArchive);
|
|
95
|
+
const compressed = await readBody(response, url);
|
|
96
|
+
let archive;
|
|
97
|
+
try {
|
|
98
|
+
archive = await node_util.promisify(zlib.gunzip)(compressed, { maxOutputLength: maxExtractedBytes });
|
|
99
|
+
} catch (error) {
|
|
100
|
+
throw new Error(`Template archive ${url} is not a readable gzip file (or exceeds ${maxExtractedBytes} bytes): ${error}`);
|
|
101
|
+
}
|
|
102
|
+
await fs.mkdir(targetDir, { recursive: true });
|
|
103
|
+
await tar.extractTar(tar.parseTar(archive), targetDir, { strip: 1, subdir: parsed.subdir });
|
|
104
|
+
};
|
|
105
|
+
exports.downloadTemplate = downloadTemplate;
|
|
106
|
+
exports.parseTemplateSource = parseTemplateSource;
|
|
107
|
+
exports.templateArchiveUrl = templateArchiveUrl;
|
|
108
|
+
//# sourceMappingURL=remoteTemplate.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remoteTemplate.cjs","sources":["../../../../../packages/create/src/lib/remoteTemplate.ts"],"sourcesContent":["import { mkdir } from 'node:fs/promises'\nimport { promisify } from 'node:util'\nimport { gunzip } from 'node:zlib'\nimport { extractTar, parseTar } from './tar.js'\n\nexport type TemplateHost = 'github' | 'gitlab' | 'bitbucket' | 'git.sr.ht'\n\nexport interface RemoteTemplateSource {\n\treadonly host: TemplateHost\n\treadonly user: string\n\treadonly name: string\n\treadonly subdir: readonly string[]\n\t/** A branch, tag or commit; `HEAD` is the default branch. */\n\treadonly ref: string\n}\n\nconst hosts: ReadonlySet<string> = new Set(['github', 'gitlab', 'bitbucket', 'git.sr.ht'])\nconst isTemplateHost = (value: string): value is TemplateHost => hosts.has(value)\n\n// The source grammar of degit 2.8.4: `[host:|https://host/|git@host:]user/repo[/subdir][#ref]`.\nconst sourcePattern = /^(?:(?:https:\\/\\/)?([^:/]+\\.[^:/]+)\\/|git@([^:/]+)[:/]|([^/]+):)?([^/\\s]+)\\/([^/\\s#]+)(?:((?:\\/[^/\\s#]+)+))?(?:\\/)?(?:#(.+))?/\n\nconst isSafeSegment = (segment: string): boolean => segment !== '' && segment !== '.' && segment !== '..'\n\nexport const parseTemplateSource = (source: string): RemoteTemplateSource => {\n\tconst match = sourcePattern.exec(source)\n\tif (!match) {\n\t\tthrow new Error(`Could not parse template source ${JSON.stringify(source)}`)\n\t}\n\tconst host = (match[1] ?? match[2] ?? match[3] ?? 'github').replace(/\\.(com|org)$/, '')\n\tif (!isTemplateHost(host)) {\n\t\tthrow new Error('Remote templates are supported from GitHub, GitLab, Bitbucket and Sourcehut')\n\t}\n\tconst user = match[4]\n\tconst name = match[5].replace(/\\.git$/, '')\n\tconst subdir = (match[6] ?? '').split('/').filter(it => it !== '')\n\tconst ref = match[7] ?? 'HEAD'\n\tif (![user, name, ...subdir, ...ref.split('/')].every(isSafeSegment)) {\n\t\tthrow new Error(`Could not parse template source ${JSON.stringify(source)}`)\n\t}\n\treturn { host, user, name, subdir, ref }\n}\n\nexport const templateArchiveUrl = ({ host, user, name, ref }: RemoteTemplateSource): string => {\n\tconst repo = `${encodeURIComponent(user)}/${encodeURIComponent(name)}`\n\tconst path = ref.split('/').map(encodeURIComponent).join('/')\n\tswitch (host) {\n\t\tcase 'github':\n\t\t\treturn `https://github.com/${repo}/archive/${path}.tar.gz`\n\t\tcase 'gitlab':\n\t\t\treturn `https://gitlab.com/${repo}/-/archive/${path}/${encodeURIComponent(`${name}-${ref.split('/').join('-')}`)}.tar.gz`\n\t\tcase 'bitbucket':\n\t\t\treturn `https://bitbucket.org/${repo}/get/${path}.tar.gz`\n\t\tcase 'git.sr.ht':\n\t\t\treturn `https://git.sr.ht/${repo}/archive/${path}.tar.gz`\n\t}\n}\n\n/** Generous for a project template; it bounds what a hostile or broken archive can make us buffer or write. */\nconst maxArchiveBytes = 64 * 1024 * 1024\nconst maxExtractedBytes = 512 * 1024 * 1024\n\nconst readBody = async (response: Response, url: string): Promise<Uint8Array> => {\n\tconst declared = Number(response.headers.get('content-length'))\n\tif (declared > maxArchiveBytes) {\n\t\tthrow new Error(`Template archive ${url} is larger than ${maxArchiveBytes} bytes`)\n\t}\n\tif (!response.body) {\n\t\treturn new Uint8Array()\n\t}\n\tconst chunks: Uint8Array[] = []\n\tlet total = 0\n\tfor await (const chunk of response.body) {\n\t\ttotal += chunk.length\n\t\tif (total > maxArchiveBytes) {\n\t\t\tthrow new Error(`Template archive ${url} is larger than ${maxArchiveBytes} bytes`)\n\t\t}\n\t\tchunks.push(chunk)\n\t}\n\treturn Buffer.concat(chunks)\n}\n\nexport type Fetch = (url: string, init: RequestInit) => Promise<Response>\n\nconst maxRedirects = 5\n\n/** Follows redirects by hand, so that every hop, not only the last one, has to stay on HTTPS. */\nconst fetchOverHttps = async (url: string, fetchArchive: Fetch): Promise<Response> => {\n\tlet current = url\n\tfor (let hop = 0;; hop++) {\n\t\tlet response: Response\n\t\ttry {\n\t\t\tresponse = await fetchArchive(current, { redirect: 'manual' })\n\t\t} catch (error) {\n\t\t\tthrow new Error(`Could not download ${current}: ${error}. Behind a proxy, Node needs NODE_USE_ENV_PROXY=1 with HTTPS_PROXY.`)\n\t\t}\n\t\tif (response.status < 300 || response.status >= 400) {\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow new Error(`Could not download ${current}: HTTP ${response.status}`)\n\t\t\t}\n\t\t\treturn response\n\t\t}\n\t\tconst location = response.headers.get('location')\n\t\tif (location === null || hop >= maxRedirects) {\n\t\t\tthrow new Error(`Could not download ${url}: too many or invalid redirects`)\n\t\t}\n\t\tconst next = new URL(location, current)\n\t\tif (next.protocol !== 'https:') {\n\t\t\tthrow new Error(`Could not download ${url}: redirected to a non-HTTPS location`)\n\t\t}\n\t\tcurrent = next.href\n\t}\n}\n\n/** Downloads the source's archive over HTTPS and extracts it (or its subdirectory) into `targetDir`. */\nexport const downloadTemplate = async (source: string, targetDir: string, fetchArchive: Fetch = fetch): Promise<void> => {\n\tconst parsed = parseTemplateSource(source)\n\tconst url = templateArchiveUrl(parsed)\n\tconst response = await fetchOverHttps(url, fetchArchive)\n\tconst compressed = await readBody(response, url)\n\tlet archive: Uint8Array\n\ttry {\n\t\tarchive = await promisify(gunzip)(compressed, { maxOutputLength: maxExtractedBytes })\n\t} catch (error) {\n\t\tthrow new Error(`Template archive ${url} is not a readable gzip file (or exceeds ${maxExtractedBytes} bytes): ${error}`)\n\t}\n\tawait mkdir(targetDir, { recursive: true })\n\t// Every host wraps the repository in one top-level directory.\n\tawait extractTar(parseTar(archive), targetDir, { strip: 1, subdir: parsed.subdir })\n}\n"],"names":["promisify","gunzip","mkdir","extractTar","parseTar"],"mappings":";;;;;;AAgBA,MAAM,4BAAiC,IAAI,CAAC,UAAU,UAAU,aAAa,WAAW,CAAC;AACzF,MAAM,iBAAiB,CAAC,UAAyC,MAAM,IAAI,KAAK;AAGhF,MAAM,gBAAgB;AAEtB,MAAM,gBAAgB,CAAC,YAA6B,YAAY,MAAM,YAAY,OAAO,YAAY;AAE9F,MAAM,sBAAsB,CAAC,WAAyC;AAC5E,QAAM,QAAQ,cAAc,KAAK,MAAM;AACvC,MAAI,CAAC,OAAO;AACX,UAAM,IAAI,MAAM,mCAAmC,KAAK,UAAU,MAAM,CAAC,EAAE;AAAA,EAC5E;AACA,QAAM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GAAG,sCAAsC;AAAA,IAChF;AACA,cAAU,KAAK;AAAA,EAChB;AACD;AAGO,MAAM,mBAAmB,OAAO,QAAgB,WAAmB,eAAsB,UAAyB;AACxH,QAAM,SAAS,oBAAoB,MAAM;AACzC,QAAM,MAAM,mBAAmB,MAAM;AACrC,QAAM,WAAW,MAAM,eAAe,KAAK,YAAY;AACvD,QAAM,aAAa,MAAM,SAAS,UAAU,GAAG;AAC/C,MAAI;AACJ,MAAI;AACH,cAAU,MAAMA,UAAAA,UAAUC,KAAAA,MAAM,EAAE,YAAY,EAAE,iBAAiB,mBAAmB;AAAA,EACrF,SAAS,OAAO;AACf,UAAM,IAAI,MAAM,oBAAoB,GAAG,4CAA4C,iBAAiB,YAAY,KAAK,EAAE;AAAA,EACxH;AACA,QAAMC,GAAAA,MAAM,WAAW,EAAE,WAAW,MAAM;AAE1C,QAAMC,eAAWC,IAAAA,SAAS,OAAO,GAAG,WAAW,EAAE,OAAO,GAAG,QAAQ,OAAO,OAAA,CAAQ;AACnF;;;;"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { mkdir } from "node:fs/promises";
|
|
2
|
+
import { promisify } from "node:util";
|
|
3
|
+
import { gunzip } from "node:zlib";
|
|
4
|
+
import { extractTar, parseTar } from "./tar.js";
|
|
5
|
+
const hosts = /* @__PURE__ */ new Set(["github", "gitlab", "bitbucket", "git.sr.ht"]);
|
|
6
|
+
const isTemplateHost = (value) => hosts.has(value);
|
|
7
|
+
const sourcePattern = /^(?:(?:https:\/\/)?([^:/]+\.[^:/]+)\/|git@([^:/]+)[:/]|([^/]+):)?([^/\s]+)\/([^/\s#]+)(?:((?:\/[^/\s#]+)+))?(?:\/)?(?:#(.+))?/;
|
|
8
|
+
const isSafeSegment = (segment) => segment !== "" && segment !== "." && segment !== "..";
|
|
9
|
+
const parseTemplateSource = (source) => {
|
|
10
|
+
const match = sourcePattern.exec(source);
|
|
11
|
+
if (!match) {
|
|
12
|
+
throw new Error(`Could not parse template source ${JSON.stringify(source)}`);
|
|
13
|
+
}
|
|
14
|
+
const host = (match[1] ?? match[2] ?? match[3] ?? "github").replace(/\.(com|org)$/, "");
|
|
15
|
+
if (!isTemplateHost(host)) {
|
|
16
|
+
throw new Error("Remote templates are supported from GitHub, GitLab, Bitbucket and Sourcehut");
|
|
17
|
+
}
|
|
18
|
+
const user = match[4];
|
|
19
|
+
const name = match[5].replace(/\.git$/, "");
|
|
20
|
+
const subdir = (match[6] ?? "").split("/").filter((it) => it !== "");
|
|
21
|
+
const ref = match[7] ?? "HEAD";
|
|
22
|
+
if (![user, name, ...subdir, ...ref.split("/")].every(isSafeSegment)) {
|
|
23
|
+
throw new Error(`Could not parse template source ${JSON.stringify(source)}`);
|
|
24
|
+
}
|
|
25
|
+
return { host, user, name, subdir, ref };
|
|
26
|
+
};
|
|
27
|
+
const templateArchiveUrl = ({ host, user, name, ref }) => {
|
|
28
|
+
const repo = `${encodeURIComponent(user)}/${encodeURIComponent(name)}`;
|
|
29
|
+
const path = ref.split("/").map(encodeURIComponent).join("/");
|
|
30
|
+
switch (host) {
|
|
31
|
+
case "github":
|
|
32
|
+
return `https://github.com/${repo}/archive/${path}.tar.gz`;
|
|
33
|
+
case "gitlab":
|
|
34
|
+
return `https://gitlab.com/${repo}/-/archive/${path}/${encodeURIComponent(`${name}-${ref.split("/").join("-")}`)}.tar.gz`;
|
|
35
|
+
case "bitbucket":
|
|
36
|
+
return `https://bitbucket.org/${repo}/get/${path}.tar.gz`;
|
|
37
|
+
case "git.sr.ht":
|
|
38
|
+
return `https://git.sr.ht/${repo}/archive/${path}.tar.gz`;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const maxArchiveBytes = 64 * 1024 * 1024;
|
|
42
|
+
const maxExtractedBytes = 512 * 1024 * 1024;
|
|
43
|
+
const readBody = async (response, url) => {
|
|
44
|
+
const declared = Number(response.headers.get("content-length"));
|
|
45
|
+
if (declared > maxArchiveBytes) {
|
|
46
|
+
throw new Error(`Template archive ${url} is larger than ${maxArchiveBytes} bytes`);
|
|
47
|
+
}
|
|
48
|
+
if (!response.body) {
|
|
49
|
+
return new Uint8Array();
|
|
50
|
+
}
|
|
51
|
+
const chunks = [];
|
|
52
|
+
let total = 0;
|
|
53
|
+
for await (const chunk of response.body) {
|
|
54
|
+
total += chunk.length;
|
|
55
|
+
if (total > maxArchiveBytes) {
|
|
56
|
+
throw new Error(`Template archive ${url} is larger than ${maxArchiveBytes} bytes`);
|
|
57
|
+
}
|
|
58
|
+
chunks.push(chunk);
|
|
59
|
+
}
|
|
60
|
+
return Buffer.concat(chunks);
|
|
61
|
+
};
|
|
62
|
+
const maxRedirects = 5;
|
|
63
|
+
const fetchOverHttps = async (url, fetchArchive) => {
|
|
64
|
+
let current = url;
|
|
65
|
+
for (let hop = 0; ; hop++) {
|
|
66
|
+
let response;
|
|
67
|
+
try {
|
|
68
|
+
response = await fetchArchive(current, { redirect: "manual" });
|
|
69
|
+
} catch (error) {
|
|
70
|
+
throw new Error(`Could not download ${current}: ${error}. Behind a proxy, Node needs NODE_USE_ENV_PROXY=1 with HTTPS_PROXY.`);
|
|
71
|
+
}
|
|
72
|
+
if (response.status < 300 || response.status >= 400) {
|
|
73
|
+
if (!response.ok) {
|
|
74
|
+
throw new Error(`Could not download ${current}: HTTP ${response.status}`);
|
|
75
|
+
}
|
|
76
|
+
return response;
|
|
77
|
+
}
|
|
78
|
+
const location = response.headers.get("location");
|
|
79
|
+
if (location === null || hop >= maxRedirects) {
|
|
80
|
+
throw new Error(`Could not download ${url}: too many or invalid redirects`);
|
|
81
|
+
}
|
|
82
|
+
const next = new URL(location, current);
|
|
83
|
+
if (next.protocol !== "https:") {
|
|
84
|
+
throw new Error(`Could not download ${url}: redirected to a non-HTTPS location`);
|
|
85
|
+
}
|
|
86
|
+
current = next.href;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const downloadTemplate = async (source, targetDir, fetchArchive = fetch) => {
|
|
90
|
+
const parsed = parseTemplateSource(source);
|
|
91
|
+
const url = templateArchiveUrl(parsed);
|
|
92
|
+
const response = await fetchOverHttps(url, fetchArchive);
|
|
93
|
+
const compressed = await readBody(response, url);
|
|
94
|
+
let archive;
|
|
95
|
+
try {
|
|
96
|
+
archive = await promisify(gunzip)(compressed, { maxOutputLength: maxExtractedBytes });
|
|
97
|
+
} catch (error) {
|
|
98
|
+
throw new Error(`Template archive ${url} is not a readable gzip file (or exceeds ${maxExtractedBytes} bytes): ${error}`);
|
|
99
|
+
}
|
|
100
|
+
await mkdir(targetDir, { recursive: true });
|
|
101
|
+
await extractTar(parseTar(archive), targetDir, { strip: 1, subdir: parsed.subdir });
|
|
102
|
+
};
|
|
103
|
+
export {
|
|
104
|
+
downloadTemplate,
|
|
105
|
+
parseTemplateSource,
|
|
106
|
+
templateArchiveUrl
|
|
107
|
+
};
|
|
108
|
+
//# sourceMappingURL=remoteTemplate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remoteTemplate.js","sources":["../../../../../packages/create/src/lib/remoteTemplate.ts"],"sourcesContent":["import { mkdir } from 'node:fs/promises'\nimport { promisify } from 'node:util'\nimport { gunzip } from 'node:zlib'\nimport { extractTar, parseTar } from './tar.js'\n\nexport type TemplateHost = 'github' | 'gitlab' | 'bitbucket' | 'git.sr.ht'\n\nexport interface RemoteTemplateSource {\n\treadonly host: TemplateHost\n\treadonly user: string\n\treadonly name: string\n\treadonly subdir: readonly string[]\n\t/** A branch, tag or commit; `HEAD` is the default branch. */\n\treadonly ref: string\n}\n\nconst hosts: ReadonlySet<string> = new Set(['github', 'gitlab', 'bitbucket', 'git.sr.ht'])\nconst isTemplateHost = (value: string): value is TemplateHost => hosts.has(value)\n\n// The source grammar of degit 2.8.4: `[host:|https://host/|git@host:]user/repo[/subdir][#ref]`.\nconst sourcePattern = /^(?:(?:https:\\/\\/)?([^:/]+\\.[^:/]+)\\/|git@([^:/]+)[:/]|([^/]+):)?([^/\\s]+)\\/([^/\\s#]+)(?:((?:\\/[^/\\s#]+)+))?(?:\\/)?(?:#(.+))?/\n\nconst isSafeSegment = (segment: string): boolean => segment !== '' && segment !== '.' && segment !== '..'\n\nexport const parseTemplateSource = (source: string): RemoteTemplateSource => {\n\tconst match = sourcePattern.exec(source)\n\tif (!match) {\n\t\tthrow new Error(`Could not parse template source ${JSON.stringify(source)}`)\n\t}\n\tconst host = (match[1] ?? match[2] ?? match[3] ?? 'github').replace(/\\.(com|org)$/, '')\n\tif (!isTemplateHost(host)) {\n\t\tthrow new Error('Remote templates are supported from GitHub, GitLab, Bitbucket and Sourcehut')\n\t}\n\tconst user = match[4]\n\tconst name = match[5].replace(/\\.git$/, '')\n\tconst subdir = (match[6] ?? '').split('/').filter(it => it !== '')\n\tconst ref = match[7] ?? 'HEAD'\n\tif (![user, name, ...subdir, ...ref.split('/')].every(isSafeSegment)) {\n\t\tthrow new Error(`Could not parse template source ${JSON.stringify(source)}`)\n\t}\n\treturn { host, user, name, subdir, ref }\n}\n\nexport const templateArchiveUrl = ({ host, user, name, ref }: RemoteTemplateSource): string => {\n\tconst repo = `${encodeURIComponent(user)}/${encodeURIComponent(name)}`\n\tconst path = ref.split('/').map(encodeURIComponent).join('/')\n\tswitch (host) {\n\t\tcase 'github':\n\t\t\treturn `https://github.com/${repo}/archive/${path}.tar.gz`\n\t\tcase 'gitlab':\n\t\t\treturn `https://gitlab.com/${repo}/-/archive/${path}/${encodeURIComponent(`${name}-${ref.split('/').join('-')}`)}.tar.gz`\n\t\tcase 'bitbucket':\n\t\t\treturn `https://bitbucket.org/${repo}/get/${path}.tar.gz`\n\t\tcase 'git.sr.ht':\n\t\t\treturn `https://git.sr.ht/${repo}/archive/${path}.tar.gz`\n\t}\n}\n\n/** Generous for a project template; it bounds what a hostile or broken archive can make us buffer or write. */\nconst maxArchiveBytes = 64 * 1024 * 1024\nconst maxExtractedBytes = 512 * 1024 * 1024\n\nconst readBody = async (response: Response, url: string): Promise<Uint8Array> => {\n\tconst declared = Number(response.headers.get('content-length'))\n\tif (declared > maxArchiveBytes) {\n\t\tthrow new Error(`Template archive ${url} is larger than ${maxArchiveBytes} bytes`)\n\t}\n\tif (!response.body) {\n\t\treturn new Uint8Array()\n\t}\n\tconst chunks: Uint8Array[] = []\n\tlet total = 0\n\tfor await (const chunk of response.body) {\n\t\ttotal += chunk.length\n\t\tif (total > maxArchiveBytes) {\n\t\t\tthrow new Error(`Template archive ${url} is larger than ${maxArchiveBytes} bytes`)\n\t\t}\n\t\tchunks.push(chunk)\n\t}\n\treturn Buffer.concat(chunks)\n}\n\nexport type Fetch = (url: string, init: RequestInit) => Promise<Response>\n\nconst maxRedirects = 5\n\n/** Follows redirects by hand, so that every hop, not only the last one, has to stay on HTTPS. */\nconst fetchOverHttps = async (url: string, fetchArchive: Fetch): Promise<Response> => {\n\tlet current = url\n\tfor (let hop = 0;; hop++) {\n\t\tlet response: Response\n\t\ttry {\n\t\t\tresponse = await fetchArchive(current, { redirect: 'manual' })\n\t\t} catch (error) {\n\t\t\tthrow new Error(`Could not download ${current}: ${error}. Behind a proxy, Node needs NODE_USE_ENV_PROXY=1 with HTTPS_PROXY.`)\n\t\t}\n\t\tif (response.status < 300 || response.status >= 400) {\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow new Error(`Could not download ${current}: HTTP ${response.status}`)\n\t\t\t}\n\t\t\treturn response\n\t\t}\n\t\tconst location = response.headers.get('location')\n\t\tif (location === null || hop >= maxRedirects) {\n\t\t\tthrow new Error(`Could not download ${url}: too many or invalid redirects`)\n\t\t}\n\t\tconst next = new URL(location, current)\n\t\tif (next.protocol !== 'https:') {\n\t\t\tthrow new Error(`Could not download ${url}: redirected to a non-HTTPS location`)\n\t\t}\n\t\tcurrent = next.href\n\t}\n}\n\n/** Downloads the source's archive over HTTPS and extracts it (or its subdirectory) into `targetDir`. */\nexport const downloadTemplate = async (source: string, targetDir: string, fetchArchive: Fetch = fetch): Promise<void> => {\n\tconst parsed = parseTemplateSource(source)\n\tconst url = templateArchiveUrl(parsed)\n\tconst response = await fetchOverHttps(url, fetchArchive)\n\tconst compressed = await readBody(response, url)\n\tlet archive: Uint8Array\n\ttry {\n\t\tarchive = await promisify(gunzip)(compressed, { maxOutputLength: maxExtractedBytes })\n\t} catch (error) {\n\t\tthrow new Error(`Template archive ${url} is not a readable gzip file (or exceeds ${maxExtractedBytes} bytes): ${error}`)\n\t}\n\tawait mkdir(targetDir, { recursive: true })\n\t// Every host wraps the repository in one top-level directory.\n\tawait extractTar(parseTar(archive), targetDir, { strip: 1, subdir: parsed.subdir })\n}\n"],"names":[],"mappings":";;;;AAgBA,MAAM,4BAAiC,IAAI,CAAC,UAAU,UAAU,aAAa,WAAW,CAAC;AACzF,MAAM,iBAAiB,CAAC,UAAyC,MAAM,IAAI,KAAK;AAGhF,MAAM,gBAAgB;AAEtB,MAAM,gBAAgB,CAAC,YAA6B,YAAY,MAAM,YAAY,OAAO,YAAY;AAE9F,MAAM,sBAAsB,CAAC,WAAyC;AAC5E,QAAM,QAAQ,cAAc,KAAK,MAAM;AACvC,MAAI,CAAC,OAAO;AACX,UAAM,IAAI,MAAM,mCAAmC,KAAK,UAAU,MAAM,CAAC,EAAE;AAAA,EAC5E;AACA,QAAM,QAAQ,MAAM,CAAC,KAAK,MAAM,CAAC,KAAK,MAAM,CAAC,KAAK,UAAU,QAAQ,gBAAgB,EAAE;AACtF,MAAI,CAAC,eAAe,IAAI,GAAG;AAC1B,UAAM,IAAI,MAAM,6EAA6E;AAAA,EAC9F;AACA,QAAM,OAAO,MAAM,CAAC;AACpB,QAAM,OAAO,MAAM,CAAC,EAAE,QAAQ,UAAU,EAAE;AAC1C,QAAM,UAAU,MAAM,CAAC,KAAK,IAAI,MAAM,GAAG,EAAE,OAAO,CAAA,OAAM,OAAO,EAAE;AACjE,QAAM,MAAM,MAAM,CAAC,KAAK;AACxB,MAAI,CAAC,CAAC,MAAM,MAAM,GAAG,QAAQ,GAAG,IAAI,MAAM,GAAG,CAAC,EAAE,MAAM,aAAa,GAAG;A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,WAAW,MAAM;AAE1C,QAAM,WAAW,SAAS,OAAO,GAAG,WAAW,EAAE,OAAO,GAAG,QAAQ,OAAO,OAAA,CAAQ;AACnF;"}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const fs = require("node:fs/promises");
|
|
4
|
+
const path = require("node:path");
|
|
5
|
+
const fsErrors = require("./fsErrors.cjs");
|
|
6
|
+
const blockSize = 512;
|
|
7
|
+
const decoder = new TextDecoder();
|
|
8
|
+
const readString = (block, offset, length) => {
|
|
9
|
+
const field = block.subarray(offset, offset + length);
|
|
10
|
+
const end = field.indexOf(0);
|
|
11
|
+
return decoder.decode(end === -1 ? field : field.subarray(0, end));
|
|
12
|
+
};
|
|
13
|
+
const readOctal = (block, offset, length, field) => {
|
|
14
|
+
const text = readString(block, offset, length).trim();
|
|
15
|
+
if (!/^[0-7]*$/.test(text)) {
|
|
16
|
+
throw new Error(`Invalid tar archive: unreadable ${field} field`);
|
|
17
|
+
}
|
|
18
|
+
return text === "" ? 0 : Number.parseInt(text, 8);
|
|
19
|
+
};
|
|
20
|
+
const verifyChecksum = (block) => {
|
|
21
|
+
const expected = readOctal(block, 148, 8, "checksum");
|
|
22
|
+
let sum = 0;
|
|
23
|
+
for (let i = 0; i < blockSize; i++) {
|
|
24
|
+
sum += i >= 148 && i < 156 ? 32 : block[i];
|
|
25
|
+
}
|
|
26
|
+
if (sum !== expected) {
|
|
27
|
+
throw new Error("Invalid tar archive: header checksum mismatch");
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const parsePax = (data) => {
|
|
31
|
+
const records = /* @__PURE__ */ new Map();
|
|
32
|
+
let offset = 0;
|
|
33
|
+
while (offset < data.length) {
|
|
34
|
+
const space = data.indexOf(32, offset);
|
|
35
|
+
const length = space === -1 ? Number.NaN : Number(decoder.decode(data.subarray(offset, space)));
|
|
36
|
+
if (!Number.isSafeInteger(length) || length <= 0 || offset + length > data.length) {
|
|
37
|
+
throw new Error("Invalid tar archive: malformed PAX header");
|
|
38
|
+
}
|
|
39
|
+
const record = decoder.decode(data.subarray(space + 1, offset + length - 1));
|
|
40
|
+
const equals = record.indexOf("=");
|
|
41
|
+
if (equals > 0) {
|
|
42
|
+
records.set(record.slice(0, equals), record.slice(equals + 1));
|
|
43
|
+
}
|
|
44
|
+
offset += length;
|
|
45
|
+
}
|
|
46
|
+
return records;
|
|
47
|
+
};
|
|
48
|
+
const parseTar = (archive) => {
|
|
49
|
+
const entries = [];
|
|
50
|
+
let pax = /* @__PURE__ */ new Map();
|
|
51
|
+
let longName;
|
|
52
|
+
let longLink;
|
|
53
|
+
let offset = 0;
|
|
54
|
+
while (offset + blockSize <= archive.length) {
|
|
55
|
+
const header = archive.subarray(offset, offset + blockSize);
|
|
56
|
+
if (header.every((byte) => byte === 0)) {
|
|
57
|
+
return entries;
|
|
58
|
+
}
|
|
59
|
+
verifyChecksum(header);
|
|
60
|
+
const type = String.fromCharCode(header[156]);
|
|
61
|
+
const paxSize = pax.get("size");
|
|
62
|
+
if (paxSize !== void 0 && !/^\d+$/.test(paxSize)) {
|
|
63
|
+
throw new Error("Invalid tar archive: unreadable PAX size");
|
|
64
|
+
}
|
|
65
|
+
const size = paxSize !== void 0 ? Number(paxSize) : readOctal(header, 124, 12, "size");
|
|
66
|
+
const dataStart = offset + blockSize;
|
|
67
|
+
if (!Number.isSafeInteger(size) || dataStart + size > archive.length) {
|
|
68
|
+
throw new Error("Invalid tar archive: entry exceeds the archive");
|
|
69
|
+
}
|
|
70
|
+
const data = archive.subarray(dataStart, dataStart + size);
|
|
71
|
+
offset = dataStart + Math.ceil(size / blockSize) * blockSize;
|
|
72
|
+
if (type === "x") {
|
|
73
|
+
pax = parsePax(data);
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (type === "g") {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (type === "L" || type === "K") {
|
|
80
|
+
const value = readString(data, 0, data.length);
|
|
81
|
+
if (type === "L") {
|
|
82
|
+
longName = value;
|
|
83
|
+
} else {
|
|
84
|
+
longLink = value;
|
|
85
|
+
}
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
const isUstar = readString(header, 257, 5) === "ustar";
|
|
89
|
+
const prefix = isUstar ? readString(header, 345, 155) : "";
|
|
90
|
+
const name = readString(header, 0, 100);
|
|
91
|
+
const path2 = pax.get("path") ?? longName ?? (prefix ? `${prefix}/${name}` : name);
|
|
92
|
+
const linkTarget = pax.get("linkpath") ?? longLink ?? readString(header, 157, 100);
|
|
93
|
+
pax = /* @__PURE__ */ new Map();
|
|
94
|
+
longName = void 0;
|
|
95
|
+
longLink = void 0;
|
|
96
|
+
if (type === "0" || type === "\0" || type === "7") {
|
|
97
|
+
entries.push({ type: "file", path: path2, mode: readOctal(header, 100, 8, "mode"), data });
|
|
98
|
+
} else if (type === "5") {
|
|
99
|
+
entries.push({ type: "directory", path: path2 });
|
|
100
|
+
} else if (type === "2") {
|
|
101
|
+
entries.push({ type: "symlink", path: path2, target: linkTarget });
|
|
102
|
+
} else {
|
|
103
|
+
throw new Error(`Unsupported tar entry "${path2}" (type ${JSON.stringify(type)})`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
throw new Error("Invalid tar archive: missing end-of-archive marker");
|
|
107
|
+
};
|
|
108
|
+
const unsafe = (what, value) => new Error(`Refusing ${what} in template archive: ${JSON.stringify(value)}`);
|
|
109
|
+
const maxPathLength = 4096;
|
|
110
|
+
const maxPathDepth = 256;
|
|
111
|
+
const relativeComponents = (path2, strip, subdir) => {
|
|
112
|
+
if (path2.startsWith("/")) {
|
|
113
|
+
throw unsafe("absolute path", path2);
|
|
114
|
+
}
|
|
115
|
+
if (path2.length > maxPathLength) {
|
|
116
|
+
throw unsafe("overlong path", path2.slice(0, 100));
|
|
117
|
+
}
|
|
118
|
+
const components = path2.split("/").filter((it) => it !== "" && it !== ".").slice(strip);
|
|
119
|
+
if (components.length > maxPathDepth) {
|
|
120
|
+
throw unsafe("too deeply nested path", path2.slice(0, 100));
|
|
121
|
+
}
|
|
122
|
+
if (components.length <= subdir.length || subdir.some((it, index) => components[index] !== it)) {
|
|
123
|
+
return void 0;
|
|
124
|
+
}
|
|
125
|
+
const relative = components.slice(subdir.length);
|
|
126
|
+
if (relative.some((it) => it === ".." || it.includes("\\"))) {
|
|
127
|
+
throw unsafe("path", path2);
|
|
128
|
+
}
|
|
129
|
+
return relative;
|
|
130
|
+
};
|
|
131
|
+
const isContainedLinkTarget = (link, target, links) => {
|
|
132
|
+
if (target.length > maxPathLength || target.startsWith("/") || target.includes("\\") || /^[a-zA-Z]:/.test(target)) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
const resolved = link.slice(0, -1);
|
|
136
|
+
const parts = target.split("/").filter((it) => it !== "" && it !== ".");
|
|
137
|
+
if (parts.length > maxPathDepth) {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
for (const [index, part] of parts.entries()) {
|
|
141
|
+
if (part === "..") {
|
|
142
|
+
if (resolved.length === 0) {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
resolved.pop();
|
|
146
|
+
} else {
|
|
147
|
+
resolved.push(part);
|
|
148
|
+
if (index < parts.length - 1 && links.has(resolved.join("/"))) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return true;
|
|
154
|
+
};
|
|
155
|
+
const ensureDirectory = async (root, components, path$1) => {
|
|
156
|
+
let current = root;
|
|
157
|
+
for (const component of components) {
|
|
158
|
+
current = path.join(current, component);
|
|
159
|
+
try {
|
|
160
|
+
const stat = await fs.lstat(current);
|
|
161
|
+
if (stat.isSymbolicLink()) {
|
|
162
|
+
throw unsafe("entry below a symlink", path$1);
|
|
163
|
+
}
|
|
164
|
+
if (!stat.isDirectory()) {
|
|
165
|
+
throw new Error(`Template archive entry ${JSON.stringify(path$1)} collides with a file`);
|
|
166
|
+
}
|
|
167
|
+
} catch (error) {
|
|
168
|
+
if (!fsErrors.isNotFound(error)) {
|
|
169
|
+
throw error;
|
|
170
|
+
}
|
|
171
|
+
await fs.mkdir(current);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
const assertTargetWithoutLinks = async (root, link, target, path$1) => {
|
|
176
|
+
const resolved = link.slice(0, -1);
|
|
177
|
+
const parts = target.split("/").filter((it) => it !== "" && it !== ".");
|
|
178
|
+
for (const [index, part] of parts.entries()) {
|
|
179
|
+
if (part === "..") {
|
|
180
|
+
resolved.pop();
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
resolved.push(part);
|
|
184
|
+
if (index === parts.length - 1) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
try {
|
|
188
|
+
if ((await fs.lstat(path.join(root, ...resolved))).isSymbolicLink()) {
|
|
189
|
+
throw unsafe("symlink pointing outside the template", `${path$1} -> ${target}`);
|
|
190
|
+
}
|
|
191
|
+
} catch (error) {
|
|
192
|
+
if (fsErrors.isNotFound(error)) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
if (fsErrors.hasCode(error, "ENOTDIR")) {
|
|
196
|
+
throw unsafe("symlink resolving through a file", `${path$1} -> ${target}`);
|
|
197
|
+
}
|
|
198
|
+
throw error;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
const extractTar = async (entries, targetDir, { strip, subdir = [] }) => {
|
|
203
|
+
const root = path.resolve(targetDir);
|
|
204
|
+
const selected = entries.flatMap((entry) => {
|
|
205
|
+
const relative = relativeComponents(entry.path, strip, subdir);
|
|
206
|
+
return relative ? [{ entry, relative }] : [];
|
|
207
|
+
});
|
|
208
|
+
const links = new Set(selected.filter((it) => it.entry.type === "symlink").map((it) => it.relative.join("/")));
|
|
209
|
+
for (const { entry, relative } of selected) {
|
|
210
|
+
if (relative.some((_, index) => index > 0 && links.has(relative.slice(0, index).join("/")))) {
|
|
211
|
+
throw unsafe("entry below a symlink", entry.path);
|
|
212
|
+
}
|
|
213
|
+
if (entry.type === "symlink" && !isContainedLinkTarget(relative, entry.target, links)) {
|
|
214
|
+
throw unsafe("symlink pointing outside the template", `${entry.path} -> ${entry.target}`);
|
|
215
|
+
}
|
|
216
|
+
if (!path.resolve(root, ...relative).startsWith(root + path.sep)) {
|
|
217
|
+
throw unsafe("path", entry.path);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
await fs.mkdir(root, { recursive: true });
|
|
221
|
+
for (const { entry, relative } of selected) {
|
|
222
|
+
if (entry.type === "directory") {
|
|
223
|
+
await ensureDirectory(root, relative, entry.path);
|
|
224
|
+
} else if (entry.type === "file") {
|
|
225
|
+
await ensureDirectory(root, relative.slice(0, -1), entry.path);
|
|
226
|
+
await fs.writeFile(path.join(root, ...relative), entry.data, { mode: entry.mode & 511 || 420, flag: "wx" });
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
const created = [];
|
|
230
|
+
for (const { entry, relative } of selected) {
|
|
231
|
+
if (entry.type === "symlink") {
|
|
232
|
+
await ensureDirectory(root, relative.slice(0, -1), entry.path);
|
|
233
|
+
await fs.symlink(entry.target, path.join(root, ...relative));
|
|
234
|
+
created.push({ relative, target: entry.target, path: entry.path });
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
for (const link of created) {
|
|
238
|
+
await assertTargetWithoutLinks(root, link.relative, link.target, link.path);
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
exports.extractTar = extractTar;
|
|
242
|
+
exports.parseTar = parseTar;
|
|
243
|
+
//# sourceMappingURL=tar.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tar.cjs","sources":["../../../../../packages/create/src/lib/tar.ts"],"sourcesContent":["import { lstat, mkdir, symlink, writeFile } from 'node:fs/promises'\nimport { join, resolve, sep } from 'node:path'\nimport { hasCode, isNotFound } from './fsErrors.js'\n\nexport type TarEntry =\n\t| { readonly type: 'file'; readonly path: string; readonly mode: number; readonly data: Uint8Array }\n\t| { readonly type: 'directory'; readonly path: string }\n\t| { readonly type: 'symlink'; readonly path: string; readonly target: string }\n\nconst blockSize = 512\nconst decoder = new TextDecoder()\n\nconst readString = (block: Uint8Array, offset: number, length: number): string => {\n\tconst field = block.subarray(offset, offset + length)\n\tconst end = field.indexOf(0)\n\treturn decoder.decode(end === -1 ? field : field.subarray(0, end))\n}\n\nconst readOctal = (block: Uint8Array, offset: number, length: number, field: string): number => {\n\tconst text = readString(block, offset, length).trim()\n\tif (!/^[0-7]*$/.test(text)) {\n\t\tthrow new Error(`Invalid tar archive: unreadable ${field} field`)\n\t}\n\treturn text === '' ? 0 : Number.parseInt(text, 8)\n}\n\nconst verifyChecksum = (block: Uint8Array): void => {\n\tconst expected = readOctal(block, 148, 8, 'checksum')\n\tlet sum = 0\n\tfor (let i = 0; i < blockSize; i++) {\n\t\tsum += i >= 148 && i < 156 ? 0x20 : block[i]\n\t}\n\tif (sum !== expected) {\n\t\tthrow new Error('Invalid tar archive: header checksum mismatch')\n\t}\n}\n\n/** PAX extended header records: `<length> <key>=<value>\\n`. */\nconst parsePax = (data: Uint8Array): Map<string, string> => {\n\tconst records = new Map<string, string>()\n\tlet offset = 0\n\twhile (offset < data.length) {\n\t\tconst space = data.indexOf(0x20, offset)\n\t\tconst length = space === -1 ? Number.NaN : Number(decoder.decode(data.subarray(offset, space)))\n\t\tif (!Number.isSafeInteger(length) || length <= 0 || offset + length > data.length) {\n\t\t\tthrow new Error('Invalid tar archive: malformed PAX header')\n\t\t}\n\t\tconst record = decoder.decode(data.subarray(space + 1, offset + length - 1))\n\t\tconst equals = record.indexOf('=')\n\t\tif (equals > 0) {\n\t\t\trecords.set(record.slice(0, equals), record.slice(equals + 1))\n\t\t}\n\t\toffset += length\n\t}\n\treturn records\n}\n\n/** Reads a POSIX (ustar/PAX) or GNU tar archive. Rejects entry types other than files, directories and symlinks. */\nexport const parseTar = (archive: Uint8Array): TarEntry[] => {\n\tconst entries: TarEntry[] = []\n\tlet pax = new Map<string, string>()\n\tlet longName: string | undefined\n\tlet longLink: string | undefined\n\tlet offset = 0\n\twhile (offset + blockSize <= archive.length) {\n\t\tconst header = archive.subarray(offset, offset + blockSize)\n\t\tif (header.every(byte => byte === 0)) {\n\t\t\treturn entries\n\t\t}\n\t\tverifyChecksum(header)\n\t\tconst type = String.fromCharCode(header[156])\n\t\tconst paxSize = pax.get('size')\n\t\tif (paxSize !== undefined && !/^\\d+$/.test(paxSize)) {\n\t\t\tthrow new Error('Invalid tar archive: unreadable PAX size')\n\t\t}\n\t\tconst size = paxSize !== undefined ? Number(paxSize) : readOctal(header, 124, 12, 'size')\n\t\tconst dataStart = offset + blockSize\n\t\tif (!Number.isSafeInteger(size) || dataStart + size > archive.length) {\n\t\t\tthrow new Error('Invalid tar archive: entry exceeds the archive')\n\t\t}\n\t\tconst data = archive.subarray(dataStart, dataStart + size)\n\t\toffset = dataStart + Math.ceil(size / blockSize) * blockSize\n\n\t\tif (type === 'x') {\n\t\t\tpax = parsePax(data)\n\t\t\tcontinue\n\t\t}\n\t\tif (type === 'g') {\n\t\t\tcontinue\n\t\t}\n\t\tif (type === 'L' || type === 'K') {\n\t\t\tconst value = readString(data, 0, data.length)\n\t\t\tif (type === 'L') {\n\t\t\t\tlongName = value\n\t\t\t} else {\n\t\t\t\tlongLink = value\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\n\t\tconst isUstar = readString(header, 257, 5) === 'ustar'\n\t\tconst prefix = isUstar ? readString(header, 345, 155) : ''\n\t\tconst name = readString(header, 0, 100)\n\t\tconst path = pax.get('path') ?? longName ?? (prefix ? `${prefix}/${name}` : name)\n\t\tconst linkTarget = pax.get('linkpath') ?? longLink ?? readString(header, 157, 100)\n\t\tpax = new Map()\n\t\tlongName = undefined\n\t\tlongLink = undefined\n\n\t\tif (type === '0' || type === '\\0' || type === '7') {\n\t\t\tentries.push({ type: 'file', path, mode: readOctal(header, 100, 8, 'mode'), data })\n\t\t} else if (type === '5') {\n\t\t\tentries.push({ type: 'directory', path })\n\t\t} else if (type === '2') {\n\t\t\tentries.push({ type: 'symlink', path, target: linkTarget })\n\t\t} else {\n\t\t\tthrow new Error(`Unsupported tar entry \"${path}\" (type ${JSON.stringify(type)})`)\n\t\t}\n\t}\n\tthrow new Error('Invalid tar archive: missing end-of-archive marker')\n}\n\nconst unsafe = (what: string, value: string): Error => new Error(`Refusing ${what} in template archive: ${JSON.stringify(value)}`)\n\n/** Longer and deeper than any real template path; together they bound the per-component work for each entry. */\nconst maxPathLength = 4096\nconst maxPathDepth = 256\n\n/** The entry's path components below `subdir`, or `undefined` when it lies outside; throws on paths that could escape. */\nconst relativeComponents = (path: string, strip: number, subdir: readonly string[]): string[] | undefined => {\n\tif (path.startsWith('/')) {\n\t\tthrow unsafe('absolute path', path)\n\t}\n\tif (path.length > maxPathLength) {\n\t\tthrow unsafe('overlong path', path.slice(0, 100))\n\t}\n\tconst components = path.split('/').filter(it => it !== '' && it !== '.').slice(strip)\n\tif (components.length > maxPathDepth) {\n\t\tthrow unsafe('too deeply nested path', path.slice(0, 100))\n\t}\n\tif (components.length <= subdir.length || subdir.some((it, index) => components[index] !== it)) {\n\t\treturn undefined\n\t}\n\tconst relative = components.slice(subdir.length)\n\tif (relative.some(it => it === '..' || it.includes('\\\\'))) {\n\t\tthrow unsafe('path', path)\n\t}\n\treturn relative\n}\n\n/** Resolves `target` from the link's directory; it must stay inside the root and not pass through another archive link. */\nconst isContainedLinkTarget = (link: readonly string[], target: string, links: ReadonlySet<string>): boolean => {\n\tif (target.length > maxPathLength || target.startsWith('/') || target.includes('\\\\') || /^[a-zA-Z]:/.test(target)) {\n\t\treturn false\n\t}\n\tconst resolved = link.slice(0, -1)\n\tconst parts = target.split('/').filter(it => it !== '' && it !== '.')\n\tif (parts.length > maxPathDepth) {\n\t\treturn false\n\t}\n\tfor (const [index, part] of parts.entries()) {\n\t\tif (part === '..') {\n\t\t\tif (resolved.length === 0) {\n\t\t\t\treturn false\n\t\t\t}\n\t\t\tresolved.pop()\n\t\t} else {\n\t\t\tresolved.push(part)\n\t\t\tif (index < parts.length - 1 && links.has(resolved.join('/'))) {\n\t\t\t\treturn false\n\t\t\t}\n\t\t}\n\t}\n\treturn true\n}\n\n/**\n * Creates the directories one component at a time and refuses to pass through a symlink. The string checks cannot see\n * aliases a case-insensitive or normalising filesystem makes (`D/L` is `d/l`), the filesystem itself can.\n */\nconst ensureDirectory = async (root: string, components: readonly string[], path: string): Promise<void> => {\n\tlet current = root\n\tfor (const component of components) {\n\t\tcurrent = join(current, component)\n\t\ttry {\n\t\t\tconst stat = await lstat(current)\n\t\t\tif (stat.isSymbolicLink()) {\n\t\t\t\tthrow unsafe('entry below a symlink', path)\n\t\t\t}\n\t\t\tif (!stat.isDirectory()) {\n\t\t\t\tthrow new Error(`Template archive entry ${JSON.stringify(path)} collides with a file`)\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (!isNotFound(error)) {\n\t\t\t\tthrow error\n\t\t\t}\n\t\t\tawait mkdir(current)\n\t\t}\n\t}\n}\n\n/** Walks a created link's target on the filesystem: no component before the last may be a symlink. */\nconst assertTargetWithoutLinks = async (root: string, link: readonly string[], target: string, path: string): Promise<void> => {\n\tconst resolved = link.slice(0, -1)\n\tconst parts = target.split('/').filter(it => it !== '' && it !== '.')\n\tfor (const [index, part] of parts.entries()) {\n\t\tif (part === '..') {\n\t\t\tresolved.pop()\n\t\t\tcontinue\n\t\t}\n\t\tresolved.push(part)\n\t\tif (index === parts.length - 1) {\n\t\t\treturn\n\t\t}\n\t\ttry {\n\t\t\tif ((await lstat(join(root, ...resolved))).isSymbolicLink()) {\n\t\t\t\tthrow unsafe('symlink pointing outside the template', `${path} -> ${target}`)\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (isNotFound(error)) {\n\t\t\t\t// a dangling target; the string check already kept it inside\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif (hasCode(error, 'ENOTDIR')) {\n\t\t\t\tthrow unsafe('symlink resolving through a file', `${path} -> ${target}`)\n\t\t\t}\n\t\t\tthrow error\n\t\t}\n\t}\n}\n\nexport interface ExtractOptions {\n\t/** Leading path components dropped from every entry, e.g. the archive's top-level directory. */\n\treadonly strip: number\n\t/** Only entries below this directory (after `strip`) are extracted, relative to it. */\n\treadonly subdir?: readonly string[]\n}\n\n/**\n * Writes the entries into `targetDir`. Paths stay inside it, no entry may sit below a symlink, and a link target must\n * resolve inside without passing through another link. Checked on the names first, then on the filesystem while\n * writing. Links are created last, so no file is written through one.\n */\nexport const extractTar = async (entries: readonly TarEntry[], targetDir: string, { strip, subdir = [] }: ExtractOptions): Promise<void> => {\n\tconst root = resolve(targetDir)\n\tconst selected = entries.flatMap(entry => {\n\t\tconst relative = relativeComponents(entry.path, strip, subdir)\n\t\treturn relative ? [{ entry, relative }] : []\n\t})\n\tconst links = new Set(selected.filter(it => it.entry.type === 'symlink').map(it => it.relative.join('/')))\n\tfor (const { entry, relative } of selected) {\n\t\tif (relative.some((_, index) => index > 0 && links.has(relative.slice(0, index).join('/')))) {\n\t\t\tthrow unsafe('entry below a symlink', entry.path)\n\t\t}\n\t\tif (entry.type === 'symlink' && !isContainedLinkTarget(relative, entry.target, links)) {\n\t\t\tthrow unsafe('symlink pointing outside the template', `${entry.path} -> ${entry.target}`)\n\t\t}\n\t\tif (!resolve(root, ...relative).startsWith(root + sep)) {\n\t\t\tthrow unsafe('path', entry.path)\n\t\t}\n\t}\n\tawait mkdir(root, { recursive: true })\n\tfor (const { entry, relative } of selected) {\n\t\tif (entry.type === 'directory') {\n\t\t\tawait ensureDirectory(root, relative, entry.path)\n\t\t} else if (entry.type === 'file') {\n\t\t\tawait ensureDirectory(root, relative.slice(0, -1), entry.path)\n\t\t\t// `wx` never follows or replaces an existing entry\n\t\t\tawait writeFile(join(root, ...relative), entry.data, { mode: (entry.mode & 0o777) || 0o644, flag: 'wx' })\n\t\t}\n\t}\n\tconst created: { relative: readonly string[]; target: string; path: string }[] = []\n\tfor (const { entry, relative } of selected) {\n\t\tif (entry.type === 'symlink') {\n\t\t\tawait ensureDirectory(root, relative.slice(0, -1), entry.path)\n\t\t\tawait symlink(entry.target, join(root, ...relative))\n\t\t\tcreated.push({ relative, target: entry.target, path: entry.path })\n\t\t}\n\t}\n\tfor (const link of created) {\n\t\tawait assertTargetWithoutLinks(root, link.relative, link.target, link.path)\n\t}\n}\n"],"names":["path","join","lstat","isNotFound","mkdir","hasCode","resolve","sep","writeFile","symlink"],"mappings":";;;;;AASA,MAAM,YAAY;AAClB,MAAM,UAAU,IAAI,YAAA;AAEpB,MAAM,aAAa,CAAC,OAAmB,QAAgB,WAA2B;AACjF,QAAM,QAAQ,MAAM,SAAS,QAAQ,SAAS,MAAM;AACpD,QAAM,MAAM,MAAM,QAAQ,CAAC;AAC3B,SAAO,QAAQ,OAAO,QAAQ,KAAK,QAAQ,MAAM,SAAS,GAAG,GAAG,CAAC;AAClE;AAEA,MAAM,YAAY,CAAC,OAAmB,QAAgB,QAAgB,UAA0B;AAC/F,QAAM,OAAO,WAAW,OAAO,QAAQ,MAAM,EAAE,KAAA;AAC/C,MAAI,CAAC,WAAW,KAAK,IAAI,GAAG;AAC3B,UAAM,IAAI,MAAM,mCAAmC,KAAK,QAAQ;AAAA,EACjE;AACA,SAAO,SAAS,KAAK,IAAI,OAAO,SAAS,MAAM,CAAC;AACjD;AAEA,MAAM,iBAAiB,CAAC,UAA4B;AACnD,QAAM,WAAW,UAAU,OAAO,KAAK,GAAG,UAAU;AACpD,MAAI,MAAM;AACV,WAAS,IAAI,GAAG,IAAI,WAAW,KAAK;AACnC,WAAO,KAAK,OAAO,IAAI,MAAM,KAAO,MAAM,CAAC;AAAA,EAC5C;AACA,MAAI,QAAQ,UAAU;AACrB,UAAM,IAAI,MAAM,+CAA+C;AAAA,EAChE;AACD;AAGA,MAAM,WAAW,CAAC,SAA0C;AAC3D,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