@contember/create 2.2.0-alpha.17 → 2.2.0-alpha.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/development/src/commands/WorkspaceCreateCommand.cjs +13 -14
- package/dist/development/src/commands/WorkspaceCreateCommand.cjs.map +1 -1
- package/dist/development/src/commands/WorkspaceCreateCommand.js +14 -15
- 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 +13 -14
- package/dist/development/src/lib/TemplateInstaller.cjs.map +1 -1
- package/dist/development/src/lib/TemplateInstaller.js +7 -8
- 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/src/commands/WorkspaceCreateCommand.cjs +13 -14
- package/dist/production/src/commands/WorkspaceCreateCommand.cjs.map +1 -1
- package/dist/production/src/commands/WorkspaceCreateCommand.js +14 -15
- 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 +13 -14
- package/dist/production/src/lib/TemplateInstaller.cjs.map +1 -1
- package/dist/production/src/lib/TemplateInstaller.js +7 -8
- 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.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.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/admin/lib/editor/sortable-block.tsx +5 -4
- package/resources/templates/default/admin/lib/tenant/dict.ts +3 -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 +0 -7
- package/src/commands/WorkspaceCreateCommand.ts +14 -15
- package/src/lib/FileSystem.ts +7 -2
- package/src/lib/TemplateInstaller.ts +8 -8
- 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/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-containment.test.ts +133 -0
- package/tests/cases/unit/template-installer-symlinks.test.ts +37 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TemplateInstaller.cjs","sources":["../../../../../packages/create/src/lib/TemplateInstaller.ts"],"sourcesContent":["import { join } from 'node:path'\nimport
|
|
1
|
+
{"version":3,"file":"TemplateInstaller.cjs","sources":["../../../../../packages/create/src/lib/TemplateInstaller.ts"],"sourcesContent":["import { join } from 'node:path'\nimport jsyaml from 'js-yaml'\nimport { FileSystem } from './FileSystem.js'\nimport { resolveNewProjectPath, resolveProjectPath } from './projectPath.js'\nimport { downloadTemplate } from './remoteTemplate.js'\n\ninterface TemplateInstallerOutput {\n\twarn(message: string): void\n}\n\ntype CloneTemplate = (source: string, target: string) => Promise<void>\n\nconst cloneTemplate: CloneTemplate = (source, target) => downloadTemplate(source, target)\n\nexport class TemplateInstaller {\n\tprivate localTemplates: Record<string, string>\n\n\tconstructor(\n\t\tprivate readonly resourceDir: string,\n\t\tprivate readonly fs: FileSystem,\n\t\tprivate readonly output: TemplateInstallerOutput,\n\t\tprivate readonly clone: CloneTemplate = cloneTemplate,\n\t) {\n\t\tthis.localTemplates = {\n\t\t\t['default']: join(this.resourceDir, 'templates/default'),\n\t\t}\n\t}\n\n\tinstallTemplate = async (\n\t\ttemplate: string,\n\t\ttargetDir: string,\n\t\tvariables: Record<string, string> = {},\n\t) => {\n\t\tlet temporaryTemplateDir: string | undefined\n\t\tlet remoteTemplate: string | undefined\n\n\t\tif (this.localTemplates[template]) {\n\t\t\ttemplate = this.localTemplates[template]\n\t\t} else {\n\t\t\tremoteTemplate = template\n\t\t\ttemporaryTemplateDir = await this.fs.createTempDir()\n\t\t\ttemplate = temporaryTemplateDir\n\t\t}\n\n\t\ttry {\n\t\t\tif (remoteTemplate !== undefined) {\n\t\t\t\ttry {\n\t\t\t\t\tawait this.clone(remoteTemplate, template)\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthrow new Error(`Failed to clone template from repository: ${error}`)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst templateConfigFile = join(template, 'contember.template.yaml')\n\t\t\tif (!(await this.fs.pathExists(templateConfigFile))) {\n\t\t\t\tthrow new Error(`${template} is not a Contember template`)\n\t\t\t}\n\t\t\tconst config = (await this.readYaml(templateConfigFile)) as {\n\t\t\t\ttype?: string\n\t\t\t\tremove?: string[]\n\t\t\t\tpatchPackageJson?: boolean\n\t\t\t\trename?: Record<string, string>\n\t\t\t\tcopy?: Record<string, string>\n\t\t\t\treplaceVariables?: string[]\n\t\t\t}\n\t\t\tconst nodeModulesDir = join(template, 'node_modules')\n\t\t\tconst skippedFiles = new Set([...(config.remove || []).map(it => join(template, it)), templateConfigFile])\n\t\t\tif (await this.fs.pathExists(targetDir)) {\n\t\t\t\tthrow `${targetDir} already exists`\n\t\t\t}\n\t\t\tawait this.fs.copy(template, targetDir, {\n\t\t\t\tfilter: src => !src.startsWith(nodeModulesDir) && !skippedFiles.has(src),\n\t\t\t})\n\n\t\t\tif (config.patchPackageJson) {\n\t\t\t\tawait this.replaceFileContent(join(targetDir, 'package.json'), content => {\n\t\t\t\t\tconst {\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tversion,\n\t\t\t\t\t\t'scripts-template': scripts,\n\t\t\t\t\t\tscripts: _nullScripts,\n\t\t\t\t\t\tlicense,\n\t\t\t\t\t\t...json\n\t\t\t\t\t} = JSON.parse(content)\n\t\t\t\t\treturn JSON.stringify({ scripts, ...json }, null, ' ')\n\t\t\t\t})\n\t\t\t}\n\t\t\t// The template is untrusted input: every directive path must stay inside the new project.\n\t\t\tconst projectPath = (path: string) => resolveProjectPath(this.fs, targetDir, path)\n\t\t\tfor (const [source, target] of Object.entries(config.rename || {})) {\n\t\t\t\tawait this.fs.rename(await projectPath(source), await projectPath(target))\n\t\t\t}\n\t\t\tfor (const [source, target] of Object.entries(config.copy || {})) {\n\t\t\t\tawait this.fs.copy(await projectPath(source), await resolveNewProjectPath(this.fs, targetDir, target))\n\t\t\t}\n\n\t\t\tfor (const file of config.replaceVariables || []) {\n\t\t\t\tconst path = await projectPath(file)\n\t\t\t\tif (!(await this.fs.pathExists(path))) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tawait this.replaceFileContent(path, content =>\n\t\t\t\t\tObject.entries(variables).reduce(\n\t\t\t\t\t\t(content, [key, value]) => content.replace(new RegExp(`{${key}}`, 'g'), value),\n\t\t\t\t\t\tcontent,\n\t\t\t\t\t))\n\t\t\t}\n\t\t} finally {\n\t\t\tif (temporaryTemplateDir !== undefined) {\n\t\t\t\tawait this.cleanupTemporaryTemplate(temporaryTemplateDir)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate cleanupTemporaryTemplate = async (path: string): Promise<void> => {\n\t\ttry {\n\t\t\tawait this.fs.remove(path, { recursive: true, force: true })\n\t\t} catch {\n\t\t\tthis.output.warn('Failed to clean up the temporary template directory.')\n\t\t}\n\t}\n\n\tprivate replaceFileContent = async (path: string, replacer: (content: string) => string): Promise<void> => {\n\t\tconst content = await this.fs.readFile(path, { encoding: 'utf8' })\n\t\tconst newContent = replacer(content)\n\t\tawait this.fs.writeFile(path, newContent, { encoding: 'utf8' })\n\t}\n\n\tprivate readYaml = async <T = unknown>(path: string): Promise<T> => {\n\t\tconst content = await this.fs.readFile(path, { encoding: 'utf8' })\n\t\treturn jsyaml.load(content) as unknown as T\n\t}\n}\n"],"names":["downloadTemplate","remoteTemplate","join","projectPath","path","resolveProjectPath","resolveNewProjectPath","content"],"mappings":";;;;;;;;;AAYA,MAAM,gBAA+B,CAAC,QAAQ,WAAWA,eAAAA,iBAAiB,QAAQ,MAAM;AAEjF,MAAM,kBAAkB;AAAA,EAG9B,YACkB,aACA,IACA,QACA,QAAuB,eACvC;AAJgB,SAAA,cAAA;AACA,SAAA,KAAA;AACA,SAAA,SAAA;AACA,SAAA,QAAA;AANlB,kBAAA,MAAQ,gBAAA;AAaR,kBAAA,MAAA,mBAAkB,OACjB,UACA,WACA,YAAoC,OAChC;AACJ,UAAI;AACJ,UAAIC;AAEJ,UAAI,KAAK,eAAe,QAAQ,GAAG;AAClC,mBAAW,KAAK,eAAe,QAAQ;AAAA,MACxC,OAAO;AACN,QAAAA,kBAAiB;AACjB,+BAAuB,MAAM,KAAK,GAAG,cAAA;AACrC,mBAAW;AAAA,MACZ;AAEA,UAAI;AACH,YAAIA,oBAAmB,QAAW;AACjC,cAAI;AACH,kBAAM,KAAK,MAAMA,iBAAgB,QAAQ;AAAA,UAC1C,SAAS,OAAO;AACf,kBAAM,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G,SAASA,OAAM,EAAE,UAAU,QAAQ;AACjE,aAAO,OAAO,KAAK,OAAO;AAAA,IAC3B,CAAA;AA5GC,SAAK,iBAAiB;AAAA,MACrB,CAAC,SAAS,GAAGF,KAAAA,KAAK,KAAK,aAAa,mBAAmB;AAAA,IAAA;AAAA,EAEzD;AA0GD;;"}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
|
-
import degit from "degit";
|
|
3
2
|
import jsyaml__default from "js-yaml";
|
|
3
|
+
import { resolveProjectPath, resolveNewProjectPath } from "./projectPath.js";
|
|
4
|
+
import { downloadTemplate } from "./remoteTemplate.js";
|
|
4
5
|
var __defProp = Object.defineProperty;
|
|
5
6
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
7
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
7
|
-
const cloneTemplate =
|
|
8
|
-
const emitter = degit(source, { cache: false, force: true, verbose: true });
|
|
9
|
-
await emitter.clone(target);
|
|
10
|
-
};
|
|
8
|
+
const cloneTemplate = (source, target) => downloadTemplate(source, target);
|
|
11
9
|
class TemplateInstaller {
|
|
12
10
|
constructor(resourceDir, fs, output, clone = cloneTemplate) {
|
|
13
11
|
this.resourceDir = resourceDir;
|
|
@@ -59,14 +57,15 @@ class TemplateInstaller {
|
|
|
59
57
|
return JSON.stringify({ scripts, ...json }, null, " ");
|
|
60
58
|
});
|
|
61
59
|
}
|
|
60
|
+
const projectPath = (path) => resolveProjectPath(this.fs, targetDir, path);
|
|
62
61
|
for (const [source, target] of Object.entries(config.rename || {})) {
|
|
63
|
-
await this.fs.rename(
|
|
62
|
+
await this.fs.rename(await projectPath(source), await projectPath(target));
|
|
64
63
|
}
|
|
65
64
|
for (const [source, target] of Object.entries(config.copy || {})) {
|
|
66
|
-
await this.fs.copy(
|
|
65
|
+
await this.fs.copy(await projectPath(source), await resolveNewProjectPath(this.fs, targetDir, target));
|
|
67
66
|
}
|
|
68
67
|
for (const file of config.replaceVariables || []) {
|
|
69
|
-
const path =
|
|
68
|
+
const path = await projectPath(file);
|
|
70
69
|
if (!await this.fs.pathExists(path)) {
|
|
71
70
|
continue;
|
|
72
71
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TemplateInstaller.js","sources":["../../../../../packages/create/src/lib/TemplateInstaller.ts"],"sourcesContent":["import { join } from 'node:path'\nimport
|
|
1
|
+
{"version":3,"file":"TemplateInstaller.js","sources":["../../../../../packages/create/src/lib/TemplateInstaller.ts"],"sourcesContent":["import { join } from 'node:path'\nimport jsyaml from 'js-yaml'\nimport { FileSystem } from './FileSystem.js'\nimport { resolveNewProjectPath, resolveProjectPath } from './projectPath.js'\nimport { downloadTemplate } from './remoteTemplate.js'\n\ninterface TemplateInstallerOutput {\n\twarn(message: string): void\n}\n\ntype CloneTemplate = (source: string, target: string) => Promise<void>\n\nconst cloneTemplate: CloneTemplate = (source, target) => downloadTemplate(source, target)\n\nexport class TemplateInstaller {\n\tprivate localTemplates: Record<string, string>\n\n\tconstructor(\n\t\tprivate readonly resourceDir: string,\n\t\tprivate readonly fs: FileSystem,\n\t\tprivate readonly output: TemplateInstallerOutput,\n\t\tprivate readonly clone: CloneTemplate = cloneTemplate,\n\t) {\n\t\tthis.localTemplates = {\n\t\t\t['default']: join(this.resourceDir, 'templates/default'),\n\t\t}\n\t}\n\n\tinstallTemplate = async (\n\t\ttemplate: string,\n\t\ttargetDir: string,\n\t\tvariables: Record<string, string> = {},\n\t) => {\n\t\tlet temporaryTemplateDir: string | undefined\n\t\tlet remoteTemplate: string | undefined\n\n\t\tif (this.localTemplates[template]) {\n\t\t\ttemplate = this.localTemplates[template]\n\t\t} else {\n\t\t\tremoteTemplate = template\n\t\t\ttemporaryTemplateDir = await this.fs.createTempDir()\n\t\t\ttemplate = temporaryTemplateDir\n\t\t}\n\n\t\ttry {\n\t\t\tif (remoteTemplate !== undefined) {\n\t\t\t\ttry {\n\t\t\t\t\tawait this.clone(remoteTemplate, template)\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthrow new Error(`Failed to clone template from repository: ${error}`)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst templateConfigFile = join(template, 'contember.template.yaml')\n\t\t\tif (!(await this.fs.pathExists(templateConfigFile))) {\n\t\t\t\tthrow new Error(`${template} is not a Contember template`)\n\t\t\t}\n\t\t\tconst config = (await this.readYaml(templateConfigFile)) as {\n\t\t\t\ttype?: string\n\t\t\t\tremove?: string[]\n\t\t\t\tpatchPackageJson?: boolean\n\t\t\t\trename?: Record<string, string>\n\t\t\t\tcopy?: Record<string, string>\n\t\t\t\treplaceVariables?: string[]\n\t\t\t}\n\t\t\tconst nodeModulesDir = join(template, 'node_modules')\n\t\t\tconst skippedFiles = new Set([...(config.remove || []).map(it => join(template, it)), templateConfigFile])\n\t\t\tif (await this.fs.pathExists(targetDir)) {\n\t\t\t\tthrow `${targetDir} already exists`\n\t\t\t}\n\t\t\tawait this.fs.copy(template, targetDir, {\n\t\t\t\tfilter: src => !src.startsWith(nodeModulesDir) && !skippedFiles.has(src),\n\t\t\t})\n\n\t\t\tif (config.patchPackageJson) {\n\t\t\t\tawait this.replaceFileContent(join(targetDir, 'package.json'), content => {\n\t\t\t\t\tconst {\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tversion,\n\t\t\t\t\t\t'scripts-template': scripts,\n\t\t\t\t\t\tscripts: _nullScripts,\n\t\t\t\t\t\tlicense,\n\t\t\t\t\t\t...json\n\t\t\t\t\t} = JSON.parse(content)\n\t\t\t\t\treturn JSON.stringify({ scripts, ...json }, null, ' ')\n\t\t\t\t})\n\t\t\t}\n\t\t\t// The template is untrusted input: every directive path must stay inside the new project.\n\t\t\tconst projectPath = (path: string) => resolveProjectPath(this.fs, targetDir, path)\n\t\t\tfor (const [source, target] of Object.entries(config.rename || {})) {\n\t\t\t\tawait this.fs.rename(await projectPath(source), await projectPath(target))\n\t\t\t}\n\t\t\tfor (const [source, target] of Object.entries(config.copy || {})) {\n\t\t\t\tawait this.fs.copy(await projectPath(source), await resolveNewProjectPath(this.fs, targetDir, target))\n\t\t\t}\n\n\t\t\tfor (const file of config.replaceVariables || []) {\n\t\t\t\tconst path = await projectPath(file)\n\t\t\t\tif (!(await this.fs.pathExists(path))) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tawait this.replaceFileContent(path, content =>\n\t\t\t\t\tObject.entries(variables).reduce(\n\t\t\t\t\t\t(content, [key, value]) => content.replace(new RegExp(`{${key}}`, 'g'), value),\n\t\t\t\t\t\tcontent,\n\t\t\t\t\t))\n\t\t\t}\n\t\t} finally {\n\t\t\tif (temporaryTemplateDir !== undefined) {\n\t\t\t\tawait this.cleanupTemporaryTemplate(temporaryTemplateDir)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate cleanupTemporaryTemplate = async (path: string): Promise<void> => {\n\t\ttry {\n\t\t\tawait this.fs.remove(path, { recursive: true, force: true })\n\t\t} catch {\n\t\t\tthis.output.warn('Failed to clean up the temporary template directory.')\n\t\t}\n\t}\n\n\tprivate replaceFileContent = async (path: string, replacer: (content: string) => string): Promise<void> => {\n\t\tconst content = await this.fs.readFile(path, { encoding: 'utf8' })\n\t\tconst newContent = replacer(content)\n\t\tawait this.fs.writeFile(path, newContent, { encoding: 'utf8' })\n\t}\n\n\tprivate readYaml = async <T = unknown>(path: string): Promise<T> => {\n\t\tconst content = await this.fs.readFile(path, { encoding: 'utf8' })\n\t\treturn jsyaml.load(content) as unknown as T\n\t}\n}\n"],"names":["content","jsyaml"],"mappings":";;;;;;;AAYA,MAAM,gBAA+B,CAAC,QAAQ,WAAW,iBAAiB,QAAQ,MAAM;AAEjF,MAAM,kBAAkB;AAAA,EAG9B,YACkB,aACA,IACA,QACA,QAAuB,eACvC;AAJgB,SAAA,cAAA;AACA,SAAA,KAAA;AACA,SAAA,SAAA;AACA,SAAA,Q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AAsD;AAAA,MACxE;AAAA,IACD,CAAA;AAEA,kBAAA,MAAQ,sBAAqB,OAAO,MAAc,aAAyD;AAC1G,YAAM,UAAU,MAAM,KAAK,GAAG,SAAS,MAAM,EAAE,UAAU,QAAQ;AACjE,YAAM,aAAa,SAAS,OAAO;AACnC,YAAM,KAAK,GAAG,UAAU,MAAM,YAAY,EAAE,UAAU,QAAQ;AAAA,IAC/D,CAAA;AAEA,kBAAA,MAAQ,YAAW,OAAoB,SAA6B;AACnE,YAAM,UAAU,MAAM,KAAK,GAAG,SAAS,MAAM,EAAE,UAAU,QAAQ;AACjE,aAAOC,gBAAO,KAAK,OAAO;AAAA,IAC3B,CAAA;AA5GC,SAAK,iBAAiB;AAAA,MACrB,CAAC,SAAS,GAAG,KAAK,KAAK,aAAa,mBAAmB;AAAA,IAAA;AAAA,EAEzD;AA0GD;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const hasCode = (error, code) => error instanceof Error && "code" in error && error.code === code;
|
|
4
|
+
const isNotFound = (error) => hasCode(error, "ENOENT");
|
|
5
|
+
exports.hasCode = hasCode;
|
|
6
|
+
exports.isNotFound = isNotFound;
|
|
7
|
+
//# sourceMappingURL=fsErrors.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fsErrors.cjs","sources":["../../../../../packages/create/src/lib/fsErrors.ts"],"sourcesContent":["export const hasCode = (error: unknown, code: string): boolean => error instanceof Error && 'code' in error && error.code === code\nexport const isNotFound = (error: unknown): boolean => hasCode(error, 'ENOENT')\n"],"names":[],"mappings":";;AAAO,MAAM,UAAU,CAAC,OAAgB,SAA0B,iBAAiB,SAAS,UAAU,SAAS,MAAM,SAAS;AACvH,MAAM,aAAa,CAAC,UAA4B,QAAQ,OAAO,QAAQ;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fsErrors.js","sources":["../../../../../packages/create/src/lib/fsErrors.ts"],"sourcesContent":["export const hasCode = (error: unknown, code: string): boolean => error instanceof Error && 'code' in error && error.code === code\nexport const isNotFound = (error: unknown): boolean => hasCode(error, 'ENOENT')\n"],"names":[],"mappings":"AAAO,MAAM,UAAU,CAAC,OAAgB,SAA0B,iBAAiB,SAAS,UAAU,SAAS,MAAM,SAAS;AACvH,MAAM,aAAa,CAAC,UAA4B,QAAQ,OAAO,QAAQ;"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const path = require("node:path");
|
|
4
|
+
const fsErrors = require("./fsErrors.cjs");
|
|
5
|
+
const resolveProjectPath = async (fs, root, path$1) => {
|
|
6
|
+
const outside = new Error(`Template path "${path$1}" points outside the project`);
|
|
7
|
+
if (path.isAbsolute(path$1)) {
|
|
8
|
+
throw outside;
|
|
9
|
+
}
|
|
10
|
+
const resolved = path.resolve(root, path$1);
|
|
11
|
+
if (!isStrictlyInside(root, resolved)) {
|
|
12
|
+
throw outside;
|
|
13
|
+
}
|
|
14
|
+
const realRoot = await fs.realPath(root);
|
|
15
|
+
const realPath = await resolveExistingPrefix(fs, resolved);
|
|
16
|
+
if (realPath === void 0) {
|
|
17
|
+
throw new Error(`Template path "${path$1}" passes through a dangling symlink`);
|
|
18
|
+
}
|
|
19
|
+
if (!isStrictlyInside(realRoot, realPath)) {
|
|
20
|
+
throw outside;
|
|
21
|
+
}
|
|
22
|
+
return resolved;
|
|
23
|
+
};
|
|
24
|
+
const resolveNewProjectPath = async (fs, root, path2) => {
|
|
25
|
+
const resolved = await resolveProjectPath(fs, root, path2);
|
|
26
|
+
if (await isPresent(fs, resolved)) {
|
|
27
|
+
throw new Error(`Template path "${path2}" already exists`);
|
|
28
|
+
}
|
|
29
|
+
return resolved;
|
|
30
|
+
};
|
|
31
|
+
const isStrictlyInside = (root, path$1) => {
|
|
32
|
+
const rel = path.relative(root, path$1);
|
|
33
|
+
return rel !== "" && rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel);
|
|
34
|
+
};
|
|
35
|
+
const resolveExistingPrefix = async (fs, path$1) => {
|
|
36
|
+
try {
|
|
37
|
+
return await fs.realPath(path$1);
|
|
38
|
+
} catch (error) {
|
|
39
|
+
if (!fsErrors.isNotFound(error)) {
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (await isPresent(fs, path$1)) {
|
|
44
|
+
return void 0;
|
|
45
|
+
}
|
|
46
|
+
const parent = path.dirname(path$1);
|
|
47
|
+
if (parent === path$1) {
|
|
48
|
+
return path$1;
|
|
49
|
+
}
|
|
50
|
+
const realParent = await resolveExistingPrefix(fs, parent);
|
|
51
|
+
return realParent === void 0 ? void 0 : path.join(realParent, path.basename(path$1));
|
|
52
|
+
};
|
|
53
|
+
const isPresent = async (fs, path2) => {
|
|
54
|
+
try {
|
|
55
|
+
await fs.lstat(path2);
|
|
56
|
+
return true;
|
|
57
|
+
} catch (error) {
|
|
58
|
+
if (fsErrors.isNotFound(error)) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
exports.resolveNewProjectPath = resolveNewProjectPath;
|
|
65
|
+
exports.resolveProjectPath = resolveProjectPath;
|
|
66
|
+
//# sourceMappingURL=projectPath.cjs.map
|
|
@@ -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,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;AACrE,UA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,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;A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