@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.
Files changed (167) hide show
  1. package/CLAUDE.md +22 -0
  2. package/dist/development/run.cjs +7 -7
  3. package/dist/development/run.cjs.map +1 -1
  4. package/dist/development/run.js +8 -8
  5. package/dist/development/run.js.map +1 -1
  6. package/dist/development/src/commands/WorkspaceCreateCommand.cjs +36 -23
  7. package/dist/development/src/commands/WorkspaceCreateCommand.cjs.map +1 -1
  8. package/dist/development/src/commands/WorkspaceCreateCommand.js +37 -24
  9. package/dist/development/src/commands/WorkspaceCreateCommand.js.map +1 -1
  10. package/dist/development/src/lib/FileSystem.cjs +10 -4
  11. package/dist/development/src/lib/FileSystem.cjs.map +1 -1
  12. package/dist/development/src/lib/FileSystem.js +8 -2
  13. package/dist/development/src/lib/FileSystem.js.map +1 -1
  14. package/dist/development/src/lib/TemplateInstaller.cjs +71 -60
  15. package/dist/development/src/lib/TemplateInstaller.cjs.map +1 -1
  16. package/dist/development/src/lib/TemplateInstaller.js +71 -60
  17. package/dist/development/src/lib/TemplateInstaller.js.map +1 -1
  18. package/dist/development/src/lib/fsErrors.cjs +7 -0
  19. package/dist/development/src/lib/fsErrors.cjs.map +1 -0
  20. package/dist/development/src/lib/fsErrors.js +7 -0
  21. package/dist/development/src/lib/fsErrors.js.map +1 -0
  22. package/dist/development/src/lib/projectPath.cjs +66 -0
  23. package/dist/development/src/lib/projectPath.cjs.map +1 -0
  24. package/dist/development/src/lib/projectPath.js +66 -0
  25. package/dist/development/src/lib/projectPath.js.map +1 -0
  26. package/dist/development/src/lib/remoteTemplate.cjs +108 -0
  27. package/dist/development/src/lib/remoteTemplate.cjs.map +1 -0
  28. package/dist/development/src/lib/remoteTemplate.js +108 -0
  29. package/dist/development/src/lib/remoteTemplate.js.map +1 -0
  30. package/dist/development/src/lib/tar.cjs +243 -0
  31. package/dist/development/src/lib/tar.cjs.map +1 -0
  32. package/dist/development/src/lib/tar.js +243 -0
  33. package/dist/development/src/lib/tar.js.map +1 -0
  34. package/dist/production/run.cjs +7 -7
  35. package/dist/production/run.cjs.map +1 -1
  36. package/dist/production/run.js +8 -8
  37. package/dist/production/run.js.map +1 -1
  38. package/dist/production/src/commands/WorkspaceCreateCommand.cjs +36 -23
  39. package/dist/production/src/commands/WorkspaceCreateCommand.cjs.map +1 -1
  40. package/dist/production/src/commands/WorkspaceCreateCommand.js +37 -24
  41. package/dist/production/src/commands/WorkspaceCreateCommand.js.map +1 -1
  42. package/dist/production/src/lib/FileSystem.cjs +10 -4
  43. package/dist/production/src/lib/FileSystem.cjs.map +1 -1
  44. package/dist/production/src/lib/FileSystem.js +8 -2
  45. package/dist/production/src/lib/FileSystem.js.map +1 -1
  46. package/dist/production/src/lib/TemplateInstaller.cjs +71 -60
  47. package/dist/production/src/lib/TemplateInstaller.cjs.map +1 -1
  48. package/dist/production/src/lib/TemplateInstaller.js +71 -60
  49. package/dist/production/src/lib/TemplateInstaller.js.map +1 -1
  50. package/dist/production/src/lib/fsErrors.cjs +7 -0
  51. package/dist/production/src/lib/fsErrors.cjs.map +1 -0
  52. package/dist/production/src/lib/fsErrors.js +7 -0
  53. package/dist/production/src/lib/fsErrors.js.map +1 -0
  54. package/dist/production/src/lib/projectPath.cjs +66 -0
  55. package/dist/production/src/lib/projectPath.cjs.map +1 -0
  56. package/dist/production/src/lib/projectPath.js +66 -0
  57. package/dist/production/src/lib/projectPath.js.map +1 -0
  58. package/dist/production/src/lib/remoteTemplate.cjs +108 -0
  59. package/dist/production/src/lib/remoteTemplate.cjs.map +1 -0
  60. package/dist/production/src/lib/remoteTemplate.js +108 -0
  61. package/dist/production/src/lib/remoteTemplate.js.map +1 -0
  62. package/dist/production/src/lib/tar.cjs +243 -0
  63. package/dist/production/src/lib/tar.cjs.map +1 -0
  64. package/dist/production/src/lib/tar.js +243 -0
  65. package/dist/production/src/lib/tar.js.map +1 -0
  66. package/dist/types/commands/WorkspaceCreateCommand.d.ts +15 -3
  67. package/dist/types/commands/WorkspaceCreateCommand.d.ts.map +1 -1
  68. package/dist/types/lib/FileSystem.d.ts +2 -0
  69. package/dist/types/lib/FileSystem.d.ts.map +1 -1
  70. package/dist/types/lib/TemplateInstaller.d.ts +9 -1
  71. package/dist/types/lib/TemplateInstaller.d.ts.map +1 -1
  72. package/dist/types/lib/fsErrors.d.ts +3 -0
  73. package/dist/types/lib/fsErrors.d.ts.map +1 -0
  74. package/dist/types/lib/projectPath.d.ts +12 -0
  75. package/dist/types/lib/projectPath.d.ts.map +1 -0
  76. package/dist/types/lib/remoteTemplate.d.ts +15 -0
  77. package/dist/types/lib/remoteTemplate.d.ts.map +1 -0
  78. package/dist/types/lib/tar.d.ts +28 -0
  79. package/dist/types/lib/tar.d.ts.map +1 -0
  80. package/dist/types/tsconfig.tsbuildinfo +1 -1
  81. package/package.json +5 -7
  82. package/resources/templates/default/README.md +3 -1
  83. package/resources/templates/default/admin/app/components/navigation.tsx +95 -8
  84. package/resources/templates/default/admin/app/pages/tenant.tsx +328 -77
  85. package/resources/templates/default/admin/entrypoint/components/login.tsx +1 -1
  86. package/resources/templates/default/admin/entrypoint/pages/magicLink.tsx +1 -1
  87. package/resources/templates/default/admin/entrypoint/pages/magicLinkSent.tsx +1 -1
  88. package/resources/templates/default/admin/entrypoint/pages/passwordReset.tsx +1 -1
  89. package/resources/templates/default/admin/entrypoint/pages/resetRequest.tsx +1 -1
  90. package/resources/templates/default/admin/entrypoint/pages/resetRequestSuccess.tsx +1 -1
  91. package/resources/templates/default/admin/lib/editor/common/editor-inline-toolbar.tsx +3 -0
  92. package/resources/templates/default/admin/lib/editor/sortable-block.tsx +5 -4
  93. package/resources/templates/default/admin/lib/tenant/config/auth-policy-list.tsx +86 -0
  94. package/resources/templates/default/admin/lib/tenant/config/common.tsx +71 -0
  95. package/resources/templates/default/admin/lib/tenant/config/identity-provider-list.tsx +113 -0
  96. package/resources/templates/default/admin/lib/tenant/config/index.ts +5 -0
  97. package/resources/templates/default/admin/lib/tenant/config/mail-template-list.tsx +108 -0
  98. package/resources/templates/default/admin/lib/tenant/config/tenant-config-view.tsx +182 -0
  99. package/resources/templates/default/admin/lib/tenant/dict.ts +453 -4
  100. package/resources/templates/default/admin/lib/tenant/errors.ts +10 -0
  101. package/resources/templates/default/admin/lib/tenant/forms/add-project-member.tsx +57 -0
  102. package/resources/templates/default/admin/lib/tenant/forms/change-my-profile.tsx +40 -0
  103. package/resources/templates/default/admin/lib/tenant/forms/change-profile.tsx +55 -0
  104. package/resources/templates/default/admin/lib/tenant/forms/common.tsx +9 -2
  105. package/resources/templates/default/admin/lib/tenant/forms/create-global-api-key.tsx +69 -0
  106. package/resources/templates/default/admin/lib/tenant/forms/global-roles-control.tsx +113 -0
  107. package/resources/templates/default/admin/lib/tenant/forms/index.ts +11 -0
  108. package/resources/templates/default/admin/lib/tenant/forms/invite.tsx +42 -4
  109. package/resources/templates/default/admin/lib/tenant/forms/login.tsx +4 -10
  110. package/resources/templates/default/admin/lib/tenant/forms/memberships-control.tsx +3 -1
  111. package/resources/templates/default/admin/lib/tenant/forms/mfa-code-fields.tsx +81 -0
  112. package/resources/templates/default/admin/lib/tenant/forms/passwordless-signin.tsx +4 -10
  113. package/resources/templates/default/admin/lib/tenant/forms/set-person-password.tsx +58 -0
  114. package/resources/templates/default/admin/lib/tenant/forms/set-project-secret.tsx +59 -0
  115. package/resources/templates/default/admin/lib/tenant/forms/sign-up.tsx +73 -0
  116. package/resources/templates/default/admin/lib/tenant/hooks/index.ts +2 -0
  117. package/resources/templates/default/admin/lib/tenant/idp/identity-provider-connections.tsx +124 -0
  118. package/resources/templates/default/admin/lib/tenant/idp/index.ts +1 -0
  119. package/resources/templates/default/admin/lib/tenant/index.ts +7 -0
  120. package/resources/templates/default/admin/lib/tenant/listing/api-key-list.tsx +160 -22
  121. package/resources/templates/default/admin/lib/tenant/listing/auth-log-list.tsx +179 -0
  122. package/resources/templates/default/admin/lib/tenant/listing/global-api-key-list.tsx +149 -0
  123. package/resources/templates/default/admin/lib/tenant/listing/index.ts +7 -0
  124. package/resources/templates/default/admin/lib/tenant/listing/member-delete-dialog.tsx +1 -1
  125. package/resources/templates/default/admin/lib/tenant/listing/member-list.tsx +20 -11
  126. package/resources/templates/default/admin/lib/tenant/listing/mfa.tsx +29 -0
  127. package/resources/templates/default/admin/lib/tenant/listing/person-actions.tsx +179 -0
  128. package/resources/templates/default/admin/lib/tenant/listing/person-detail.tsx +141 -0
  129. package/resources/templates/default/admin/lib/tenant/listing/person-list.tsx +13 -2
  130. package/resources/templates/default/admin/lib/tenant/listing/persons-list.tsx +128 -0
  131. package/resources/templates/default/admin/lib/tenant/listing/project-secret-list.tsx +82 -0
  132. package/resources/templates/default/admin/lib/tenant/otp/backup-codes.tsx +81 -0
  133. package/resources/templates/default/admin/lib/tenant/otp/email-otp-setup.tsx +133 -0
  134. package/resources/templates/default/admin/lib/tenant/otp/index.ts +2 -0
  135. package/resources/templates/default/admin/lib/tenant/security/index.ts +2 -0
  136. package/resources/templates/default/admin/lib/tenant/security/passwordless-toggle.tsx +63 -0
  137. package/resources/templates/default/admin/lib/tenant/security/session-list.tsx +143 -0
  138. package/resources/templates/default/admin/lib/ui/label.tsx +25 -2
  139. package/resources/templates/default/admin/lib/ui/menu.tsx +1 -1
  140. package/resources/templates/default/admin/lib/ui/progress.tsx +75 -11
  141. package/resources/templates/default/admin/lib/ui/separator.tsx +27 -3
  142. package/resources/templates/default/admin/lib/ui/sidebar.tsx +1 -1
  143. package/resources/templates/default/admin/lib/ui/toggle.tsx +41 -2
  144. package/resources/templates/default/admin/lib/utils/classNames.ts +107 -0
  145. package/resources/templates/default/admin/lib/utils/cn.ts +3 -3
  146. package/resources/templates/default/admin/lib/utils/index.ts +1 -0
  147. package/resources/templates/default/admin/lib/utils/uic.tsx +2 -3
  148. package/resources/templates/default/admin/package.json +1 -7
  149. package/resources/templates/default/docker/object-storage/README.md +13 -0
  150. package/resources/templates/default/docker/object-storage/identities.json +13 -0
  151. package/resources/templates/default/docker-compose.yaml +29 -7
  152. package/src/commands/WorkspaceCreateCommand.ts +51 -24
  153. package/src/lib/FileSystem.ts +7 -2
  154. package/src/lib/TemplateInstaller.ts +87 -69
  155. package/src/lib/fsErrors.ts +2 -0
  156. package/src/lib/projectPath.ts +79 -0
  157. package/src/lib/remoteTemplate.ts +130 -0
  158. package/src/lib/tar.ts +283 -0
  159. package/src/run.ts +8 -7
  160. package/tests/cases/unit/create-process.test.ts +66 -0
  161. package/tests/cases/unit/fileSystem.test.ts +14 -0
  162. package/tests/cases/unit/fixtures/template.tar.gz +0 -0
  163. package/tests/cases/unit/remoteTemplate.test.ts +277 -0
  164. package/tests/cases/unit/template-installer-cleanup.test.ts +150 -0
  165. package/tests/cases/unit/template-installer-containment.test.ts +133 -0
  166. package/tests/cases/unit/template-installer-symlinks.test.ts +37 -0
  167. package/tests/cases/unit/workspace-create.test.ts +81 -0
@@ -0,0 +1,243 @@
1
+ import { mkdir, writeFile, symlink, lstat } from "node:fs/promises";
2
+ import { resolve, sep, join } from "node:path";
3
+ import { isNotFound, hasCode } from "./fsErrors.js";
4
+ const blockSize = 512;
5
+ const decoder = new TextDecoder();
6
+ const readString = (block, offset, length) => {
7
+ const field = block.subarray(offset, offset + length);
8
+ const end = field.indexOf(0);
9
+ return decoder.decode(end === -1 ? field : field.subarray(0, end));
10
+ };
11
+ const readOctal = (block, offset, length, field) => {
12
+ const text = readString(block, offset, length).trim();
13
+ if (!/^[0-7]*$/.test(text)) {
14
+ throw new Error(`Invalid tar archive: unreadable ${field} field`);
15
+ }
16
+ return text === "" ? 0 : Number.parseInt(text, 8);
17
+ };
18
+ const verifyChecksum = (block) => {
19
+ const expected = readOctal(block, 148, 8, "checksum");
20
+ let sum = 0;
21
+ for (let i = 0; i < blockSize; i++) {
22
+ sum += i >= 148 && i < 156 ? 32 : block[i];
23
+ }
24
+ if (sum !== expected) {
25
+ throw new Error("Invalid tar archive: header checksum mismatch");
26
+ }
27
+ };
28
+ const parsePax = (data) => {
29
+ const records = /* @__PURE__ */ new Map();
30
+ let offset = 0;
31
+ while (offset < data.length) {
32
+ const space = data.indexOf(32, offset);
33
+ const length = space === -1 ? Number.NaN : Number(decoder.decode(data.subarray(offset, space)));
34
+ if (!Number.isSafeInteger(length) || length <= 0 || offset + length > data.length) {
35
+ throw new Error("Invalid tar archive: malformed PAX header");
36
+ }
37
+ const record = decoder.decode(data.subarray(space + 1, offset + length - 1));
38
+ const equals = record.indexOf("=");
39
+ if (equals > 0) {
40
+ records.set(record.slice(0, equals), record.slice(equals + 1));
41
+ }
42
+ offset += length;
43
+ }
44
+ return records;
45
+ };
46
+ const parseTar = (archive) => {
47
+ const entries = [];
48
+ let pax = /* @__PURE__ */ new Map();
49
+ let longName;
50
+ let longLink;
51
+ let offset = 0;
52
+ while (offset + blockSize <= archive.length) {
53
+ const header = archive.subarray(offset, offset + blockSize);
54
+ if (header.every((byte) => byte === 0)) {
55
+ return entries;
56
+ }
57
+ verifyChecksum(header);
58
+ const type = String.fromCharCode(header[156]);
59
+ const paxSize = pax.get("size");
60
+ if (paxSize !== void 0 && !/^\d+$/.test(paxSize)) {
61
+ throw new Error("Invalid tar archive: unreadable PAX size");
62
+ }
63
+ const size = paxSize !== void 0 ? Number(paxSize) : readOctal(header, 124, 12, "size");
64
+ const dataStart = offset + blockSize;
65
+ if (!Number.isSafeInteger(size) || dataStart + size > archive.length) {
66
+ throw new Error("Invalid tar archive: entry exceeds the archive");
67
+ }
68
+ const data = archive.subarray(dataStart, dataStart + size);
69
+ offset = dataStart + Math.ceil(size / blockSize) * blockSize;
70
+ if (type === "x") {
71
+ pax = parsePax(data);
72
+ continue;
73
+ }
74
+ if (type === "g") {
75
+ continue;
76
+ }
77
+ if (type === "L" || type === "K") {
78
+ const value = readString(data, 0, data.length);
79
+ if (type === "L") {
80
+ longName = value;
81
+ } else {
82
+ longLink = value;
83
+ }
84
+ continue;
85
+ }
86
+ const isUstar = readString(header, 257, 5) === "ustar";
87
+ const prefix = isUstar ? readString(header, 345, 155) : "";
88
+ const name = readString(header, 0, 100);
89
+ const path = pax.get("path") ?? longName ?? (prefix ? `${prefix}/${name}` : name);
90
+ const linkTarget = pax.get("linkpath") ?? longLink ?? readString(header, 157, 100);
91
+ pax = /* @__PURE__ */ new Map();
92
+ longName = void 0;
93
+ longLink = void 0;
94
+ if (type === "0" || type === "\0" || type === "7") {
95
+ entries.push({ type: "file", path, mode: readOctal(header, 100, 8, "mode"), data });
96
+ } else if (type === "5") {
97
+ entries.push({ type: "directory", path });
98
+ } else if (type === "2") {
99
+ entries.push({ type: "symlink", path, target: linkTarget });
100
+ } else {
101
+ throw new Error(`Unsupported tar entry "${path}" (type ${JSON.stringify(type)})`);
102
+ }
103
+ }
104
+ throw new Error("Invalid tar archive: missing end-of-archive marker");
105
+ };
106
+ const unsafe = (what, value) => new Error(`Refusing ${what} in template archive: ${JSON.stringify(value)}`);
107
+ const maxPathLength = 4096;
108
+ const maxPathDepth = 256;
109
+ const relativeComponents = (path, strip, subdir) => {
110
+ if (path.startsWith("/")) {
111
+ throw unsafe("absolute path", path);
112
+ }
113
+ if (path.length > maxPathLength) {
114
+ throw unsafe("overlong path", path.slice(0, 100));
115
+ }
116
+ const components = path.split("/").filter((it) => it !== "" && it !== ".").slice(strip);
117
+ if (components.length > maxPathDepth) {
118
+ throw unsafe("too deeply nested path", path.slice(0, 100));
119
+ }
120
+ if (components.length <= subdir.length || subdir.some((it, index) => components[index] !== it)) {
121
+ return void 0;
122
+ }
123
+ const relative = components.slice(subdir.length);
124
+ if (relative.some((it) => it === ".." || it.includes("\\"))) {
125
+ throw unsafe("path", path);
126
+ }
127
+ return relative;
128
+ };
129
+ const isContainedLinkTarget = (link, target, links) => {
130
+ if (target.length > maxPathLength || target.startsWith("/") || target.includes("\\") || /^[a-zA-Z]:/.test(target)) {
131
+ return false;
132
+ }
133
+ const resolved = link.slice(0, -1);
134
+ const parts = target.split("/").filter((it) => it !== "" && it !== ".");
135
+ if (parts.length > maxPathDepth) {
136
+ return false;
137
+ }
138
+ for (const [index, part] of parts.entries()) {
139
+ if (part === "..") {
140
+ if (resolved.length === 0) {
141
+ return false;
142
+ }
143
+ resolved.pop();
144
+ } else {
145
+ resolved.push(part);
146
+ if (index < parts.length - 1 && links.has(resolved.join("/"))) {
147
+ return false;
148
+ }
149
+ }
150
+ }
151
+ return true;
152
+ };
153
+ const ensureDirectory = async (root, components, path) => {
154
+ let current = root;
155
+ for (const component of components) {
156
+ current = join(current, component);
157
+ try {
158
+ const stat = await lstat(current);
159
+ if (stat.isSymbolicLink()) {
160
+ throw unsafe("entry below a symlink", path);
161
+ }
162
+ if (!stat.isDirectory()) {
163
+ throw new Error(`Template archive entry ${JSON.stringify(path)} collides with a file`);
164
+ }
165
+ } catch (error) {
166
+ if (!isNotFound(error)) {
167
+ throw error;
168
+ }
169
+ await mkdir(current);
170
+ }
171
+ }
172
+ };
173
+ const assertTargetWithoutLinks = async (root, link, target, path) => {
174
+ const resolved = link.slice(0, -1);
175
+ const parts = target.split("/").filter((it) => it !== "" && it !== ".");
176
+ for (const [index, part] of parts.entries()) {
177
+ if (part === "..") {
178
+ resolved.pop();
179
+ continue;
180
+ }
181
+ resolved.push(part);
182
+ if (index === parts.length - 1) {
183
+ return;
184
+ }
185
+ try {
186
+ if ((await lstat(join(root, ...resolved))).isSymbolicLink()) {
187
+ throw unsafe("symlink pointing outside the template", `${path} -> ${target}`);
188
+ }
189
+ } catch (error) {
190
+ if (isNotFound(error)) {
191
+ return;
192
+ }
193
+ if (hasCode(error, "ENOTDIR")) {
194
+ throw unsafe("symlink resolving through a file", `${path} -> ${target}`);
195
+ }
196
+ throw error;
197
+ }
198
+ }
199
+ };
200
+ const extractTar = async (entries, targetDir, { strip, subdir = [] }) => {
201
+ const root = resolve(targetDir);
202
+ const selected = entries.flatMap((entry) => {
203
+ const relative = relativeComponents(entry.path, strip, subdir);
204
+ return relative ? [{ entry, relative }] : [];
205
+ });
206
+ const links = new Set(selected.filter((it) => it.entry.type === "symlink").map((it) => it.relative.join("/")));
207
+ for (const { entry, relative } of selected) {
208
+ if (relative.some((_, index) => index > 0 && links.has(relative.slice(0, index).join("/")))) {
209
+ throw unsafe("entry below a symlink", entry.path);
210
+ }
211
+ if (entry.type === "symlink" && !isContainedLinkTarget(relative, entry.target, links)) {
212
+ throw unsafe("symlink pointing outside the template", `${entry.path} -> ${entry.target}`);
213
+ }
214
+ if (!resolve(root, ...relative).startsWith(root + sep)) {
215
+ throw unsafe("path", entry.path);
216
+ }
217
+ }
218
+ await mkdir(root, { recursive: true });
219
+ for (const { entry, relative } of selected) {
220
+ if (entry.type === "directory") {
221
+ await ensureDirectory(root, relative, entry.path);
222
+ } else if (entry.type === "file") {
223
+ await ensureDirectory(root, relative.slice(0, -1), entry.path);
224
+ await writeFile(join(root, ...relative), entry.data, { mode: entry.mode & 511 || 420, flag: "wx" });
225
+ }
226
+ }
227
+ const created = [];
228
+ for (const { entry, relative } of selected) {
229
+ if (entry.type === "symlink") {
230
+ await ensureDirectory(root, relative.slice(0, -1), entry.path);
231
+ await symlink(entry.target, join(root, ...relative));
232
+ created.push({ relative, target: entry.target, path: entry.path });
233
+ }
234
+ }
235
+ for (const link of created) {
236
+ await assertTargetWithoutLinks(root, link.relative, link.target, link.path);
237
+ }
238
+ };
239
+ export {
240
+ extractTar,
241
+ parseTar
242
+ };
243
+ //# sourceMappingURL=tar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tar.js","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":[],"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,QAAM,8BAAc,IAAA;AACpB,MAAI,SAAS;AACb,SAAO,SAAS,KAAK,QAAQ;AAC5B,UAAM,QAAQ,KAAK,QAAQ,IAAM,MAAM;AACvC,UAAM,SAAS,UAAU,KAAK,OAAO,MAAM,OAAO,QAAQ,OAAO,KAAK,SAAS,QAAQ,KAAK,CAAC,CAAC;AAC9F,QAAI,CAAC,OAAO,cAA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AAM,gBAAgB,MAAM,SAAS,MAAM,GAAG,EAAE,GAAG,MAAM,IAAI;AAE7D,YAAM,UAAU,KAAK,MAAM,GAAG,QAAQ,GAAG,MAAM,MAAM,EAAE,MAAO,MAAM,OAAO,OAAU,KAAO,MAAM,MAAM;AAAA,IACzG;AAAA,EACD;AACA,QAAM,UAA2E,CAAA;AACjF,aAAW,EAAE,OAAO,SAAA,KAAc,UAAU;AAC3C,QAAI,MAAM,SAAS,WAAW;AAC7B,YAAM,gBAAgB,MAAM,SAAS,MAAM,GAAG,EAAE,GAAG,MAAM,IAAI;AAC7D,YAAM,QAAQ,MAAM,QAAQ,KAAK,MAAM,GAAG,QAAQ,CAAC;AACnD,cAAQ,KAAK,EAAE,UAAU,QAAQ,MAAM,QAAQ,MAAM,MAAM,MAAM;AAAA,IAClE;AAAA,EACD;AACA,aAAW,QAAQ,SAAS;AAC3B,UAAM,yBAAyB,MAAM,KAAK,UAAU,KAAK,QAAQ,KAAK,IAAI;AAAA,EAC3E;AACD;"}
@@ -1,4 +1,4 @@
1
- import { Command, CommandConfiguration, Input } from '@contember/cli-common';
1
+ import { Command, CommandConfiguration, Input, Output } from '@contember/cli-common';
2
2
  import { TemplateInstaller } from '../lib/TemplateInstaller.js';
3
3
  type Args = {
4
4
  projectName: string;
@@ -6,11 +6,23 @@ type Args = {
6
6
  type Options = {
7
7
  template: string;
8
8
  };
9
+ export interface WorkspaceCreateResult {
10
+ projectName: string;
11
+ projectDirectory: string;
12
+ template: string;
13
+ packageManager: string;
14
+ }
15
+ export interface WorkspaceCreateRuntime {
16
+ cwd(): string;
17
+ getPackageVersion(): Promise<string>;
18
+ detectPackageManager(): string;
19
+ }
9
20
  export declare class WorkspaceCreateCommand extends Command<Args, Options> {
10
21
  private readonly templateInstaller;
11
- constructor(templateInstaller: TemplateInstaller);
22
+ private readonly runtime;
23
+ constructor(templateInstaller: Pick<TemplateInstaller, 'installTemplate'>, runtime?: WorkspaceCreateRuntime);
12
24
  protected configure(configuration: CommandConfiguration<Args, Options>): void;
13
- protected execute(input: Input<Args, Options>): Promise<void>;
25
+ protected execute(input: Input<Args, Options>, output: Output): Promise<void>;
14
26
  }
15
27
  export {};
16
28
  //# sourceMappingURL=WorkspaceCreateCommand.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"WorkspaceCreateCommand.d.ts","sourceRoot":"","sources":["../../../src/commands/WorkspaceCreateCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAA;AAG5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAA;AAI/D,KAAK,IAAI,GAAG;IACX,WAAW,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,KAAK,OAAO,GAAG;IACd,QAAQ,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,qBAAa,sBAAuB,SAAQ,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC;IAEhE,OAAO,CAAC,QAAQ,CAAC,iBAAiB;gBAAjB,iBAAiB,EAAE,iBAAiB;IAKtD,SAAS,CAAC,SAAS,CAAC,aAAa,EAAE,oBAAoB,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,IAAI;cAM7D,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAcnE"}
1
+ {"version":3,"file":"WorkspaceCreateCommand.d.ts","sourceRoot":"","sources":["../../../src/commands/WorkspaceCreateCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAsB,KAAK,EAAE,MAAM,EAAS,MAAM,uBAAuB,CAAA;AAE/G,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAA;AAI/D,KAAK,IAAI,GAAG;IACX,WAAW,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,KAAK,OAAO,GAAG;IACd,QAAQ,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,MAAM,WAAW,qBAAqB;IACrC,WAAW,EAAE,MAAM,CAAA;IACnB,gBAAgB,EAAE,MAAM,CAAA;IACxB,QAAQ,EAAE,MAAM,CAAA;IAChB,cAAc,EAAE,MAAM,CAAA;CACtB;AAED,MAAM,WAAW,sBAAsB;IACtC,GAAG,IAAI,MAAM,CAAA;IACb,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC,CAAA;IACpC,oBAAoB,IAAI,MAAM,CAAA;CAC9B;AAQD,qBAAa,sBAAuB,SAAQ,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC;IAEhE,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IAClC,OAAO,CAAC,QAAQ,CAAC,OAAO;IAFzB,YACkB,iBAAiB,EAAE,IAAI,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,EAC7D,OAAO,GAAE,sBAAuC,EAGjE;IAED,SAAS,CAAC,SAAS,CAAC,aAAa,EAAE,oBAAoB,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,IAAI,CAI5E;IAED,UAAgB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAiBlF;CACD"}
@@ -3,6 +3,8 @@ export declare class FileSystem {
3
3
  readFile: typeof fs.readFile;
4
4
  writeFile: typeof fs.writeFile;
5
5
  rename: typeof fs.rename;
6
+ realPath: typeof fs.realpath;
7
+ lstat: typeof fs.lstat;
6
8
  readDir: typeof fs.readdir;
7
9
  copy: (source: string, destination: string, options?: {
8
10
  filter?: (source: string, destination: string) => boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"FileSystem.d.ts","sourceRoot":"","sources":["../../../src/lib/FileSystem.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAItC,qBAAa,UAAU;IACtB,QAAQ,qBAAc;IACtB,SAAS,sBAAe;IACxB,MAAM,mBAAY;IAClB,OAAO,oBAAa;IACpB,IAAI,GAAI,QAAQ,MAAM,EAAE,aAAa,MAAM,EAAE,UAAU;QAAE,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,KAAK,OAAO,CAAA;KAAE,mBACxD;IAC5D,MAAM,mBAAY;IAClB,MAAM,eAAQ;IACd,UAAU,GAAU,MAAM,MAAM,sBAO/B;IACD,aAAa,wBAEZ;CACD"}
1
+ {"version":3,"file":"FileSystem.d.ts","sourceRoot":"","sources":["../../../src/lib/FileSystem.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAKtC,qBAAa,UAAU;IACtB,QAAQ,qBAAc;IACtB,SAAS,sBAAe;IACxB,MAAM,mBAAY;IAClB,QAAQ,qBAAc;IACtB,KAAK,kBAAW;IAChB,OAAO,oBAAa;IACpB,IAAI,WAAY,MAAM,eAAe,MAAM,YAAY;QAAE,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,KAAK,OAAO,CAAA;KAAE,mBAEhC;IACpF,MAAM,mBAAY;IAClB,MAAM,eAAQ;IACd,UAAU,SAAgB,MAAM,sBAO/B;IACD,aAAa,wBAGZ;CACD"}
@@ -1,11 +1,19 @@
1
1
  import { FileSystem } from './FileSystem.js';
2
+ interface TemplateInstallerOutput {
3
+ warn(message: string): void;
4
+ }
5
+ type CloneTemplate = (source: string, target: string) => Promise<void>;
2
6
  export declare class TemplateInstaller {
3
7
  private readonly resourceDir;
4
8
  private readonly fs;
9
+ private readonly output;
10
+ private readonly clone;
5
11
  private localTemplates;
6
- constructor(resourceDir: string, fs: FileSystem);
12
+ constructor(resourceDir: string, fs: FileSystem, output: TemplateInstallerOutput, clone?: CloneTemplate);
7
13
  installTemplate: (template: string, targetDir: string, variables?: Record<string, string>) => Promise<void>;
14
+ private cleanupTemporaryTemplate;
8
15
  private replaceFileContent;
9
16
  private readYaml;
10
17
  }
18
+ export {};
11
19
  //# sourceMappingURL=TemplateInstaller.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TemplateInstaller.d.ts","sourceRoot":"","sources":["../../../src/lib/TemplateInstaller.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAI5C,qBAAa,iBAAiB;IAI5B,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,EAAE;IAJpB,OAAO,CAAC,cAAc,CAAwB;gBAG5B,WAAW,EAAE,MAAM,EACnB,EAAE,EAAE,UAAU;IAOhC,eAAe,GACd,UAAU,MAAM,EAChB,WAAW,MAAM,EACjB,YAAW,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,mBAkFtC;IAED,OAAO,CAAC,kBAAkB,CAIzB;IAED,OAAO,CAAC,QAAQ,CAGf;CACD"}
1
+ {"version":3,"file":"TemplateInstaller.d.ts","sourceRoot":"","sources":["../../../src/lib/TemplateInstaller.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAI5C,UAAU,uBAAuB;IAChC,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;CAC3B;AAED,KAAK,aAAa,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;AAItE,qBAAa,iBAAiB;IAI5B,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,EAAE;IACnB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,KAAK;IANvB,OAAO,CAAC,cAAc,CAAwB;IAE9C,YACkB,WAAW,EAAE,MAAM,EACnB,EAAE,EAAE,UAAU,EACd,MAAM,EAAE,uBAAuB,EAC/B,KAAK,GAAE,aAA6B,EAKrD;IAED,eAAe,aACJ,MAAM,aACL,MAAM,cACN,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,mBAiFjC;IAED,OAAO,CAAC,wBAAwB,CAM/B;IAED,OAAO,CAAC,kBAAkB,CAIzB;IAED,OAAO,CAAC,QAAQ,CAGf;CACD"}
@@ -0,0 +1,3 @@
1
+ export declare const hasCode: (error: unknown, code: string) => boolean;
2
+ export declare const isNotFound: (error: unknown) => boolean;
3
+ //# sourceMappingURL=fsErrors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fsErrors.d.ts","sourceRoot":"","sources":["../../../src/lib/fsErrors.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,UAAW,OAAO,QAAQ,MAAM,KAAG,OAA2E,CAAA;AAClI,eAAO,MAAM,UAAU,UAAW,OAAO,KAAG,OAAmC,CAAA"}
@@ -0,0 +1,12 @@
1
+ import { FileSystem } from './FileSystem.js';
2
+ /**
3
+ * Resolves a path from a template directive against the project root.
4
+ * Refuses absolute paths, the root itself and anything that leaves the root, lexically or through a symlink.
5
+ */
6
+ export declare const resolveProjectPath: (fs: FileSystem, root: string, path: string) => Promise<string>;
7
+ /**
8
+ * Like resolveProjectPath, and the path must not exist yet. fs.cp into an existing directory writes entries the check
9
+ * above never saw, and Bun's fs.cp follows symlinks it finds there.
10
+ */
11
+ export declare const resolveNewProjectPath: (fs: FileSystem, root: string, path: string) => Promise<string>;
12
+ //# sourceMappingURL=projectPath.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"projectPath.d.ts","sourceRoot":"","sources":["../../../src/lib/projectPath.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAG5C;;;GAGG;AACH,eAAO,MAAM,kBAAkB,OAAc,UAAU,QAAQ,MAAM,QAAQ,MAAM,KAAG,OAAO,CAAC,MAAM,CAkBnG,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,qBAAqB,OAAc,UAAU,QAAQ,MAAM,QAAQ,MAAM,KAAG,OAAO,CAAC,MAAM,CAMtG,CAAA"}
@@ -0,0 +1,15 @@
1
+ export type TemplateHost = 'github' | 'gitlab' | 'bitbucket' | 'git.sr.ht';
2
+ export interface RemoteTemplateSource {
3
+ readonly host: TemplateHost;
4
+ readonly user: string;
5
+ readonly name: string;
6
+ readonly subdir: readonly string[];
7
+ /** A branch, tag or commit; `HEAD` is the default branch. */
8
+ readonly ref: string;
9
+ }
10
+ export declare const parseTemplateSource: (source: string) => RemoteTemplateSource;
11
+ export declare const templateArchiveUrl: ({ host, user, name, ref }: RemoteTemplateSource) => string;
12
+ export type Fetch = (url: string, init: RequestInit) => Promise<Response>;
13
+ /** Downloads the source's archive over HTTPS and extracts it (or its subdirectory) into `targetDir`. */
14
+ export declare const downloadTemplate: (source: string, targetDir: string, fetchArchive?: Fetch) => Promise<void>;
15
+ //# sourceMappingURL=remoteTemplate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remoteTemplate.d.ts","sourceRoot":"","sources":["../../../src/lib/remoteTemplate.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,QAAQ,GAAG,WAAW,GAAG,WAAW,CAAA;AAE1E,MAAM,WAAW,oBAAoB;IACpC,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAA;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAA;IAClC,6DAA6D;IAC7D,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CACpB;AAUD,eAAO,MAAM,mBAAmB,WAAY,MAAM,KAAG,oBAiBpD,CAAA;AAED,eAAO,MAAM,kBAAkB,8BAA+B,oBAAoB,KAAG,MAapF,CAAA;AA0BD,MAAM,MAAM,KAAK,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;AAgCzE,wGAAwG;AACxG,eAAO,MAAM,gBAAgB,WAAkB,MAAM,aAAa,MAAM,iBAAgB,KAAK,KAAW,OAAO,CAAC,IAAI,CAcnH,CAAA"}
@@ -0,0 +1,28 @@
1
+ export type TarEntry = {
2
+ readonly type: 'file';
3
+ readonly path: string;
4
+ readonly mode: number;
5
+ readonly data: Uint8Array;
6
+ } | {
7
+ readonly type: 'directory';
8
+ readonly path: string;
9
+ } | {
10
+ readonly type: 'symlink';
11
+ readonly path: string;
12
+ readonly target: string;
13
+ };
14
+ /** Reads a POSIX (ustar/PAX) or GNU tar archive. Rejects entry types other than files, directories and symlinks. */
15
+ export declare const parseTar: (archive: Uint8Array) => TarEntry[];
16
+ export interface ExtractOptions {
17
+ /** Leading path components dropped from every entry, e.g. the archive's top-level directory. */
18
+ readonly strip: number;
19
+ /** Only entries below this directory (after `strip`) are extracted, relative to it. */
20
+ readonly subdir?: readonly string[];
21
+ }
22
+ /**
23
+ * Writes the entries into `targetDir`. Paths stay inside it, no entry may sit below a symlink, and a link target must
24
+ * resolve inside without passing through another link. Checked on the names first, then on the filesystem while
25
+ * writing. Links are created last, so no file is written through one.
26
+ */
27
+ export declare const extractTar: (entries: readonly TarEntry[], targetDir: string, { strip, subdir }: ExtractOptions) => Promise<void>;
28
+ //# sourceMappingURL=tar.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tar.d.ts","sourceRoot":"","sources":["../../../src/lib/tar.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,QAAQ,GACjB;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAA;CAAE,GAClG;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACrD;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAA;AAkD/E,oHAAoH;AACpH,eAAO,MAAM,QAAQ,YAAa,UAAU,KAAG,QAAQ,EA8DtD,CAAA;AA+GD,MAAM,WAAW,cAAc;IAC9B,gGAAgG;IAChG,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,uFAAuF;IACvF,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CACnC;AAED;;;;GAIG;AACH,eAAO,MAAM,UAAU,YAAmB,SAAS,QAAQ,EAAE,aAAa,MAAM,qBAA0B,cAAc,KAAG,OAAO,CAAC,IAAI,CAuCtI,CAAA"}