extension-create 4.2.0 → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/deno-manifest.d.ts +8 -2
- package/dist/lib/format-duration.d.ts +1 -0
- package/dist/lib/install-runner.d.ts +13 -0
- package/dist/lib/messages.d.ts +6 -3
- package/dist/lib/messaging.d.ts +12 -0
- package/dist/lib/package-name.d.ts +9 -0
- package/dist/lib/utils.d.ts +7 -1
- package/dist/module.cjs +528 -96
- package/dist/module.d.ts +1 -0
- package/dist/steps/import-external-template.d.ts +11 -2
- package/dist/steps/write-package-json.d.ts +1 -0
- package/package.json +4 -4
package/dist/module.cjs
CHANGED
|
@@ -137,6 +137,177 @@ new Set([
|
|
|
137
137
|
'floorp',
|
|
138
138
|
'waterfox'
|
|
139
139
|
]);
|
|
140
|
+
const CODES = {
|
|
141
|
+
E_ARGS: 'E_ARGS',
|
|
142
|
+
E_PROJECT_NOT_FOUND: 'E_PROJECT_NOT_FOUND',
|
|
143
|
+
E_MANIFEST_NOT_FOUND: 'E_MANIFEST_NOT_FOUND',
|
|
144
|
+
E_MANIFEST_INVALID: 'E_MANIFEST_INVALID',
|
|
145
|
+
E_PACKAGE_JSON_INVALID: 'E_PACKAGE_JSON_INVALID',
|
|
146
|
+
E_FIRST_COMPILE: 'E_FIRST_COMPILE',
|
|
147
|
+
E_COMPILE: 'E_COMPILE',
|
|
148
|
+
E_BROWSER_NOT_FOUND: 'E_BROWSER_NOT_FOUND',
|
|
149
|
+
E_BROWSER_LAUNCH: 'E_BROWSER_LAUNCH',
|
|
150
|
+
E_PROFILE_LOCKED: 'E_PROFILE_LOCKED',
|
|
151
|
+
E_READY_TIMEOUT: 'E_READY_TIMEOUT',
|
|
152
|
+
E_CONTROL_DENIED: 'E_CONTROL_DENIED',
|
|
153
|
+
E_CONTROL_UNAVAILABLE: 'E_CONTROL_UNAVAILABLE',
|
|
154
|
+
E_TOKEN_MISSING: 'E_TOKEN_MISSING',
|
|
155
|
+
E_NETWORK: 'E_NETWORK',
|
|
156
|
+
E_INTERRUPTED: 'E_INTERRUPTED',
|
|
157
|
+
E_NOT_IMPLEMENTED: 'E_NOT_IMPLEMENTED',
|
|
158
|
+
E_INTERNAL: 'E_INTERNAL',
|
|
159
|
+
E_UNSUPPORTED_BROWSER: 'E_UNSUPPORTED_BROWSER',
|
|
160
|
+
E_INVALID_OPTION: 'E_INVALID_OPTION',
|
|
161
|
+
E_PORT_UNAVAILABLE: 'E_PORT_UNAVAILABLE',
|
|
162
|
+
E_DEPENDENCY_INSTALL: 'E_DEPENDENCY_INSTALL',
|
|
163
|
+
E_TEMPLATE_NOT_FOUND: 'E_TEMPLATE_NOT_FOUND',
|
|
164
|
+
E_DESTINATION_NOT_EMPTY: 'E_DESTINATION_NOT_EMPTY',
|
|
165
|
+
E_DESTINATION_NOT_WRITABLE: 'E_DESTINATION_NOT_WRITABLE',
|
|
166
|
+
E_OUTPUT_NOT_WRITABLE: 'E_OUTPUT_NOT_WRITABLE',
|
|
167
|
+
E_BROWSER_DOWNLOAD: 'E_BROWSER_DOWNLOAD',
|
|
168
|
+
E_SESSION_NOT_FOUND: 'E_SESSION_NOT_FOUND',
|
|
169
|
+
E_EVAL_REFUSED: 'E_EVAL_REFUSED',
|
|
170
|
+
E_CSP_BLOCKS_EVAL: 'E_CSP_BLOCKS_EVAL',
|
|
171
|
+
E_TARGET_NOT_FOUND: 'E_TARGET_NOT_FOUND',
|
|
172
|
+
E_HEADED_WINDOW_REQUIRED: 'E_HEADED_WINDOW_REQUIRED',
|
|
173
|
+
E_USER_GESTURE_REQUIRED: 'E_USER_GESTURE_REQUIRED',
|
|
174
|
+
E_TIMEOUT: 'E_TIMEOUT',
|
|
175
|
+
E_PUBLISH_REJECTED: 'E_PUBLISH_REJECTED',
|
|
176
|
+
E_AUTH_REQUIRED: 'E_AUTH_REQUIRED',
|
|
177
|
+
E_SAFARI_TOOLCHAIN: 'E_SAFARI_TOOLCHAIN',
|
|
178
|
+
E_SAFARI_UI: 'E_SAFARI_UI',
|
|
179
|
+
E_ACCESSIBILITY_DENIED: 'E_ACCESSIBILITY_DENIED',
|
|
180
|
+
E_EVAL: 'E_EVAL',
|
|
181
|
+
E_INSPECT: 'E_INSPECT',
|
|
182
|
+
E_STORAGE: 'E_STORAGE',
|
|
183
|
+
E_LOGS_NOT_FOUND: 'E_LOGS_NOT_FOUND',
|
|
184
|
+
E_READY_ERROR_STATUS: 'E_READY_ERROR_STATUS',
|
|
185
|
+
E_COMMAND_UNSUPPORTED_FOR_TARGET: 'E_COMMAND_UNSUPPORTED_FOR_TARGET',
|
|
186
|
+
E_FLAG_VALUE_INVALID: 'E_FLAG_VALUE_INVALID',
|
|
187
|
+
E_FLAG_NOT_SUPPORTED_HERE: 'E_FLAG_NOT_SUPPORTED_HERE',
|
|
188
|
+
E_DEV_SERVER_START: 'E_DEV_SERVER_START',
|
|
189
|
+
E_DOCTOR_CHECKS_FAILED: 'E_DOCTOR_CHECKS_FAILED',
|
|
190
|
+
E_TELEMETRY_WRITE: 'E_TELEMETRY_WRITE',
|
|
191
|
+
E_PREVIEW_NO_DIST: 'E_PREVIEW_NO_DIST',
|
|
192
|
+
E_BROWSER_UNINSTALL: 'E_BROWSER_UNINSTALL',
|
|
193
|
+
E_NODE_VERSION: 'E_NODE_VERSION',
|
|
194
|
+
E_UNKNOWN_COMMAND: 'E_UNKNOWN_COMMAND',
|
|
195
|
+
E_REMOVED_FLAG: 'E_REMOVED_FLAG',
|
|
196
|
+
E_BROWSER_NOT_INSTALLABLE: 'E_BROWSER_NOT_INSTALLABLE',
|
|
197
|
+
E_PARENT_GONE: 'E_PARENT_GONE',
|
|
198
|
+
E_REMOTE_URL_UNSUPPORTED: 'E_REMOTE_URL_UNSUPPORTED',
|
|
199
|
+
E_CONFIG_LOAD: 'E_CONFIG_LOAD',
|
|
200
|
+
E_OPTIONAL_DEP_UNRESOLVED: 'E_OPTIONAL_DEP_UNRESOLVED',
|
|
201
|
+
E_OPTIONAL_DEP_LOAD: 'E_OPTIONAL_DEP_LOAD',
|
|
202
|
+
E_OPTIONAL_DEP_UNKNOWN: 'E_OPTIONAL_DEP_UNKNOWN',
|
|
203
|
+
E_COMPANION_EXTENSION_PATH: 'E_COMPANION_EXTENSION_PATH',
|
|
204
|
+
E_MANIFEST_IN_PUBLIC: 'E_MANIFEST_IN_PUBLIC',
|
|
205
|
+
E_FOLDER_UNREADABLE: 'E_FOLDER_UNREADABLE',
|
|
206
|
+
E_RUNTIME_NOT_FOUND: 'E_RUNTIME_NOT_FOUND',
|
|
207
|
+
E_COMPILE_FATAL: 'E_COMPILE_FATAL',
|
|
208
|
+
E_MODULE_NOT_FOUND: 'E_MODULE_NOT_FOUND',
|
|
209
|
+
E_ENTRY_NOT_FOUND: 'E_ENTRY_NOT_FOUND',
|
|
210
|
+
E_ASSET_MISSING: 'E_ASSET_MISSING',
|
|
211
|
+
E_SCRIPT_DEP_MISSING: 'E_SCRIPT_DEP_MISSING',
|
|
212
|
+
E_RESERVED_FOLDER: 'E_RESERVED_FOLDER',
|
|
213
|
+
E_CSS_PARSE: 'E_CSS_PARSE',
|
|
214
|
+
E_CSS_PREPROCESSOR_MISSING: 'E_CSS_PREPROCESSOR_MISSING',
|
|
215
|
+
E_CSS_DEAD_REF: 'E_CSS_DEAD_REF',
|
|
216
|
+
E_LOCALES_LAYOUT: 'E_LOCALES_LAYOUT',
|
|
217
|
+
E_WAR_INVALID: 'E_WAR_INVALID',
|
|
218
|
+
E_THEME_INVALID: 'E_THEME_INVALID',
|
|
219
|
+
E_DEV_SESSION_DIST_SHARED: 'E_DEV_SESSION_DIST_SHARED',
|
|
220
|
+
E_BACKGROUND_REQUIRED: 'E_BACKGROUND_REQUIRED',
|
|
221
|
+
E_CONTENT_SCRIPT_SYNTAX: 'E_CONTENT_SCRIPT_SYNTAX',
|
|
222
|
+
E_PERF_BUDGET: 'E_PERF_BUDGET',
|
|
223
|
+
E_ZIP_SKIPPED: 'E_ZIP_SKIPPED',
|
|
224
|
+
E_REMOTE_FETCH_TIMEOUT: 'E_REMOTE_FETCH_TIMEOUT',
|
|
225
|
+
E_REMOTE_DOWNLOAD: 'E_REMOTE_DOWNLOAD',
|
|
226
|
+
E_REMOTE_ACCESS_DENIED: 'E_REMOTE_ACCESS_DENIED',
|
|
227
|
+
E_REMOTE_ZIP_INVALID: 'E_REMOTE_ZIP_INVALID',
|
|
228
|
+
E_LOCAL_ZIP_NOT_FOUND: 'E_LOCAL_ZIP_NOT_FOUND',
|
|
229
|
+
E_PROJECT_DOWNLOAD_EMPTY: 'E_PROJECT_DOWNLOAD_EMPTY',
|
|
230
|
+
E_BROWSER_BINARY_REQUIRED: 'E_BROWSER_BINARY_REQUIRED',
|
|
231
|
+
E_BROWSER_BINARY_INVALID: 'E_BROWSER_BINARY_INVALID',
|
|
232
|
+
E_BROWSER_EXITED: 'E_BROWSER_EXITED',
|
|
233
|
+
E_BROWSER_START_TIMEOUT: 'E_BROWSER_START_TIMEOUT',
|
|
234
|
+
E_INSTANCE_AMBIGUOUS: 'E_INSTANCE_AMBIGUOUS',
|
|
235
|
+
E_EXTENSION_LOAD_REFUSED: 'E_EXTENSION_LOAD_REFUSED',
|
|
236
|
+
E_ADDON_INSTALL: 'E_ADDON_INSTALL',
|
|
237
|
+
E_BROWSER_CONNECT: 'E_BROWSER_CONNECT',
|
|
238
|
+
E_BROWSER_CONNECTION_CLOSED: 'E_BROWSER_CONNECTION_CLOSED',
|
|
239
|
+
E_CDP_NOT_CONNECTED: 'E_CDP_NOT_CONNECTED',
|
|
240
|
+
E_CDP_TIMEOUT: 'E_CDP_TIMEOUT',
|
|
241
|
+
E_CDP_OP_FAILED: 'E_CDP_OP_FAILED',
|
|
242
|
+
E_EXTENSION_ID_UNKNOWN: 'E_EXTENSION_ID_UNKNOWN',
|
|
243
|
+
E_RDP_PROTOCOL: 'E_RDP_PROTOCOL',
|
|
244
|
+
E_SESSION_STOPPED: 'E_SESSION_STOPPED',
|
|
245
|
+
E_SESSION_EXISTS: 'E_SESSION_EXISTS',
|
|
246
|
+
E_SHUTDOWN_TIMEOUT: 'E_SHUTDOWN_TIMEOUT',
|
|
247
|
+
E_BROWSER_INSTALL_PRIVILEGE: 'E_BROWSER_INSTALL_PRIVILEGE',
|
|
248
|
+
E_BROWSER_INSTALL_TIMEOUT: 'E_BROWSER_INSTALL_TIMEOUT',
|
|
249
|
+
E_BROWSER_INSTALL_BUSY: 'E_BROWSER_INSTALL_BUSY',
|
|
250
|
+
E_BROWSER_CACHE_NOT_WRITABLE: 'E_BROWSER_CACHE_NOT_WRITABLE',
|
|
251
|
+
E_BROWSER_FOLDER_FOREIGN: 'E_BROWSER_FOLDER_FOREIGN',
|
|
252
|
+
E_BROWSER_INSTALLER_NOT_FOUND: 'E_BROWSER_INSTALLER_NOT_FOUND',
|
|
253
|
+
E_RESTART_REQUIRED: 'E_RESTART_REQUIRED',
|
|
254
|
+
E_JSON_INVALID: 'E_JSON_INVALID',
|
|
255
|
+
E_PROJECT_LAYOUT: 'E_PROJECT_LAYOUT',
|
|
256
|
+
E_ASSET_IMPORT_SHAPE: 'E_ASSET_IMPORT_SHAPE',
|
|
257
|
+
E_ENV_FILE_UNREADABLE: 'E_ENV_FILE_UNREADABLE',
|
|
258
|
+
E_INLINE_SCRIPT_SYNTAX: 'E_INLINE_SCRIPT_SYNTAX',
|
|
259
|
+
W_MANAGED_DEP_CONFLICT: 'W_MANAGED_DEP_CONFLICT',
|
|
260
|
+
W_TYPES_EMIT: 'W_TYPES_EMIT',
|
|
261
|
+
W_MODULE_NOT_FOUND: 'W_MODULE_NOT_FOUND',
|
|
262
|
+
W_ENTRY_NOT_FOUND: 'W_ENTRY_NOT_FOUND',
|
|
263
|
+
W_ASSET_MISSING: 'W_ASSET_MISSING',
|
|
264
|
+
W_SCRIPT_DEP_MISSING: 'W_SCRIPT_DEP_MISSING',
|
|
265
|
+
W_CSS_PARSE: 'W_CSS_PARSE',
|
|
266
|
+
W_CSS_PREPROCESSOR_MISSING: 'W_CSS_PREPROCESSOR_MISSING',
|
|
267
|
+
W_CSS_DEAD_REF: 'W_CSS_DEAD_REF',
|
|
268
|
+
W_POLYFILL_NOT_FOUND: 'W_POLYFILL_NOT_FOUND',
|
|
269
|
+
W_LOCALES_LAYOUT: 'W_LOCALES_LAYOUT',
|
|
270
|
+
W_PROD_LOOPBACK_ORIGIN: 'W_PROD_LOOPBACK_ORIGIN',
|
|
271
|
+
W_NO_ENTRYPOINTS: 'W_NO_ENTRYPOINTS',
|
|
272
|
+
W_REMOTE_RESOURCE_BLOCKED: 'W_REMOTE_RESOURCE_BLOCKED',
|
|
273
|
+
W_PERF_BUDGET: 'W_PERF_BUDGET',
|
|
274
|
+
W_ENV_NO_MATCH: 'W_ENV_NO_MATCH',
|
|
275
|
+
W_LAUNCH_SKIPPED_COMPILE_ERRORS: 'W_LAUNCH_SKIPPED_COMPILE_ERRORS',
|
|
276
|
+
W_UNINSTALL_NOOP: 'W_UNINSTALL_NOOP',
|
|
277
|
+
W_PORT_IN_USE: 'W_PORT_IN_USE',
|
|
278
|
+
W_LOGS_STREAM_GAP: 'W_LOGS_STREAM_GAP',
|
|
279
|
+
W_CDP_NOT_CONNECTED: 'W_CDP_NOT_CONNECTED',
|
|
280
|
+
W_CDP_TIMEOUT: 'W_CDP_TIMEOUT',
|
|
281
|
+
W_CDP_OP_FAILED: 'W_CDP_OP_FAILED',
|
|
282
|
+
W_BROWSER_CONNECTION_CLOSED: 'W_BROWSER_CONNECTION_CLOSED',
|
|
283
|
+
W_EXTENSION_ID_UNKNOWN: 'W_EXTENSION_ID_UNKNOWN',
|
|
284
|
+
W_MANIFEST_INVALID: 'W_MANIFEST_INVALID',
|
|
285
|
+
W_WAR_INVALID: 'W_WAR_INVALID',
|
|
286
|
+
W_RESERVED_FOLDER: 'W_RESERVED_FOLDER',
|
|
287
|
+
W_INTERNAL: 'W_INTERNAL',
|
|
288
|
+
W_RESTART_REQUIRED: 'W_RESTART_REQUIRED',
|
|
289
|
+
W_JSON_INVALID: 'W_JSON_INVALID',
|
|
290
|
+
W_PROJECT_LAYOUT: 'W_PROJECT_LAYOUT',
|
|
291
|
+
W_MANIFEST_COMPAT: 'W_MANIFEST_COMPAT',
|
|
292
|
+
W_STORE_READINESS: 'W_STORE_READINESS',
|
|
293
|
+
W_PERMISSION_MISMATCH: 'W_PERMISSION_MISMATCH',
|
|
294
|
+
W_API_UNSUPPORTED: 'W_API_UNSUPPORTED',
|
|
295
|
+
W_WAR_EXPOSURE: 'W_WAR_EXPOSURE',
|
|
296
|
+
W_CSS_NOT_APPLIED: 'W_CSS_NOT_APPLIED',
|
|
297
|
+
W_ENV_SECRET_PUBLIC: 'W_ENV_SECRET_PUBLIC',
|
|
298
|
+
W_BUILD_CONSTANT_UNDEFINED: 'W_BUILD_CONSTANT_UNDEFINED',
|
|
299
|
+
W_SCRIPT_WORLD_UNKNOWN: 'W_SCRIPT_WORLD_UNKNOWN',
|
|
300
|
+
W_ENV_NAME_RESERVED: 'W_ENV_NAME_RESERVED',
|
|
301
|
+
W_COMPANION_EXTENSION_PATH: 'W_COMPANION_EXTENSION_PATH',
|
|
302
|
+
W_ENV_DEFINE_WRITTEN: 'W_ENV_DEFINE_WRITTEN',
|
|
303
|
+
W_ENV_ASSET_NOT_UTF8: 'W_ENV_ASSET_NOT_UTF8',
|
|
304
|
+
W_HTML_NOT_UTF8: 'W_HTML_NOT_UTF8',
|
|
305
|
+
W_RELOAD_NOT_APPLIED: 'W_RELOAD_NOT_APPLIED',
|
|
306
|
+
W_CONTENT_SCRIPT_NOT_INJECTED: 'W_CONTENT_SCRIPT_NOT_INJECTED',
|
|
307
|
+
W_CONTENT_SCRIPT_CLEANUP: 'W_CONTENT_SCRIPT_CLEANUP',
|
|
308
|
+
W_CONTENT_SCRIPT_MOUNT: 'W_CONTENT_SCRIPT_MOUNT',
|
|
309
|
+
W_DEV_SERVER_SOCKET: 'W_DEV_SERVER_SOCKET'
|
|
310
|
+
};
|
|
140
311
|
const external_cross_spawn_namespaceObject = require("cross-spawn");
|
|
141
312
|
const external_prefers_yarn_namespaceObject = require("prefers-yarn");
|
|
142
313
|
const NPMRC_REGISTRY = /^\s*registry\s*=\s*(.*?)\s*$/;
|
|
@@ -185,6 +356,22 @@ function corepackRegistryEnv(source, projectDir) {
|
|
|
185
356
|
COREPACK_NPM_REGISTRY: origin.registry
|
|
186
357
|
} : {};
|
|
187
358
|
}
|
|
359
|
+
function formatDuration(ms) {
|
|
360
|
+
if (ms < 1000) return `${Math.max(0, Math.round(ms))} ms`;
|
|
361
|
+
if (ms >= 120000 && ms % 60000 === 0) return `${ms / 60000} minutes`;
|
|
362
|
+
const seconds = ms < 10000 ? Math.round(ms / 100) / 10 : Math.round(ms / 1000);
|
|
363
|
+
return `${seconds} ${1 === seconds ? 'second' : 'seconds'}`;
|
|
364
|
+
}
|
|
365
|
+
function _define_property(obj, key, value) {
|
|
366
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
367
|
+
value: value,
|
|
368
|
+
enumerable: true,
|
|
369
|
+
configurable: true,
|
|
370
|
+
writable: true
|
|
371
|
+
});
|
|
372
|
+
else obj[key] = value;
|
|
373
|
+
return obj;
|
|
374
|
+
}
|
|
188
375
|
const INHERITED_RELEASE_AGE = /^(?:npm|pnpm)_config_minimum[-_]?release[-_]?age$/i;
|
|
189
376
|
const INHERITED_RELEASE_AGE_RULE = /^(?:npm|pnpm)_config_minimum[-_]?release[-_]?age/i;
|
|
190
377
|
const NPMRC_RELEASE_AGE = /^\s*minimum-release-age\s*=\s*(.*?)\s*$/;
|
|
@@ -197,6 +384,18 @@ function readNpmrcReleaseAge(dir) {
|
|
|
197
384
|
} catch {}
|
|
198
385
|
return null;
|
|
199
386
|
}
|
|
387
|
+
function readWorkspaceReleaseAge(dir) {
|
|
388
|
+
try {
|
|
389
|
+
for (const line of external_node_fs_namespaceObject.readFileSync(external_node_path_namespaceObject.join(dir, 'pnpm-workspace.yaml'), 'utf8').split(/\r?\n/)){
|
|
390
|
+
if (!line.startsWith('minimumReleaseAge:')) continue;
|
|
391
|
+
const hash = line.indexOf('#');
|
|
392
|
+
const value = (-1 === hash ? line : line.slice(0, hash)).slice(18).trim();
|
|
393
|
+
const quoted = value.length >= 2 && ("'" === value[0] || '"' === value[0]) && value[value.length - 1] === value[0];
|
|
394
|
+
return quoted ? value.slice(1, -1).trim() : value;
|
|
395
|
+
}
|
|
396
|
+
} catch {}
|
|
397
|
+
return null;
|
|
398
|
+
}
|
|
200
399
|
function invokingNpmrcReleaseAge(source = process.env, cwd = process.cwd()) {
|
|
201
400
|
const starts = [
|
|
202
401
|
source.INIT_CWD,
|
|
@@ -205,7 +404,7 @@ function invokingNpmrcReleaseAge(source = process.env, cwd = process.cwd()) {
|
|
|
205
404
|
for (const start of starts){
|
|
206
405
|
let dir = external_node_path_namespaceObject.resolve(start);
|
|
207
406
|
while(true){
|
|
208
|
-
const found = readNpmrcReleaseAge(dir);
|
|
407
|
+
const found = readWorkspaceReleaseAge(dir) ?? readNpmrcReleaseAge(dir);
|
|
209
408
|
if (null !== found) return found;
|
|
210
409
|
const parent = external_node_path_namespaceObject.dirname(dir);
|
|
211
410
|
if (parent === dir) break;
|
|
@@ -246,7 +445,31 @@ function installTimeoutMs(source = process.env) {
|
|
|
246
445
|
return Number.isFinite(raw) && raw > 0 ? Math.min(raw, LONGEST_TIMER_MS) : DEFAULT_INSTALL_TIMEOUT_MS;
|
|
247
446
|
}
|
|
248
447
|
function installTimedOutReason(ms) {
|
|
249
|
-
return `The install did not finish within ${
|
|
448
|
+
return `The install did not finish within ${formatDuration(ms)} (EXTENSION_CREATE_INSTALL_TIMEOUT_MS)`;
|
|
449
|
+
}
|
|
450
|
+
function isMissingCommand(error, command) {
|
|
451
|
+
const failure = error;
|
|
452
|
+
return failure?.code === 'ENOENT' && failure.syscall === `spawn ${command}`;
|
|
453
|
+
}
|
|
454
|
+
function installExit(run) {
|
|
455
|
+
if (null !== run.code) return run.code;
|
|
456
|
+
if (void 0 !== run.reason) return 'timed out';
|
|
457
|
+
return run.signal ? `ended by ${run.signal}` : 'no exit code';
|
|
458
|
+
}
|
|
459
|
+
class InstallExitError extends Error {
|
|
460
|
+
constructor(command, args, run){
|
|
461
|
+
super(`${[
|
|
462
|
+
command,
|
|
463
|
+
...args
|
|
464
|
+
].join(' ')} ended with ${installExit(run)}` + (run.reason ? `: ${run.reason}` : '')), _define_property(this, "command", void 0), _define_property(this, "args", void 0), _define_property(this, "exitCode", void 0), _define_property(this, "signal", void 0), _define_property(this, "stdout", void 0), _define_property(this, "stderr", void 0);
|
|
465
|
+
this.name = 'InstallExitError';
|
|
466
|
+
this.command = command;
|
|
467
|
+
this.args = args;
|
|
468
|
+
this.exitCode = run.code;
|
|
469
|
+
if (run.signal) this.signal = run.signal;
|
|
470
|
+
this.stdout = run.stdout;
|
|
471
|
+
this.stderr = run.stderr;
|
|
472
|
+
}
|
|
250
473
|
}
|
|
251
474
|
const signalProcessGroup = (pid, signal)=>{
|
|
252
475
|
process.kill(-pid, signal);
|
|
@@ -255,18 +478,31 @@ const KILL_GRACE_MS = 2000;
|
|
|
255
478
|
function stillRunning(child) {
|
|
256
479
|
return null === child.exitCode && null === child.signalCode;
|
|
257
480
|
}
|
|
481
|
+
function windowsTaskkillPath(env = process.env) {
|
|
482
|
+
const root = env.SystemRoot || env.windir || 'C:\\Windows';
|
|
483
|
+
return external_node_path_namespaceObject.win32.join(root, 'System32', 'taskkill.exe');
|
|
484
|
+
}
|
|
258
485
|
function endProcessTree(child, spawnProcess, platform, signalGroup) {
|
|
259
486
|
if ('win32' === platform && void 0 !== child.pid) {
|
|
487
|
+
const killShim = ()=>{
|
|
488
|
+
try {
|
|
489
|
+
child.kill('SIGKILL');
|
|
490
|
+
} catch {}
|
|
491
|
+
};
|
|
260
492
|
try {
|
|
261
|
-
spawnProcess(
|
|
493
|
+
spawnProcess(windowsTaskkillPath(), [
|
|
262
494
|
'/pid',
|
|
263
495
|
String(child.pid),
|
|
264
496
|
'/T',
|
|
265
497
|
'/F'
|
|
266
498
|
], {
|
|
267
499
|
stdio: 'ignore'
|
|
268
|
-
}).on('error', ()=>{
|
|
269
|
-
|
|
500
|
+
}).on('error', killShim).on('close', (code)=>{
|
|
501
|
+
if (0 !== code) killShim();
|
|
502
|
+
});
|
|
503
|
+
} catch {
|
|
504
|
+
killShim();
|
|
505
|
+
}
|
|
270
506
|
return;
|
|
271
507
|
}
|
|
272
508
|
const send = (signal)=>{
|
|
@@ -323,6 +559,10 @@ async function install_runner_runInstall(command, args, opts) {
|
|
|
323
559
|
'inherit',
|
|
324
560
|
'pipe',
|
|
325
561
|
'pipe'
|
|
562
|
+
] : 'pipe' === opts.stdio ? [
|
|
563
|
+
'ignore',
|
|
564
|
+
'pipe',
|
|
565
|
+
'pipe'
|
|
326
566
|
] : opts.stdio,
|
|
327
567
|
cwd: opts.cwd,
|
|
328
568
|
env: buildExecEnv(process.env, opts.cwd, platform),
|
|
@@ -346,6 +586,9 @@ async function install_runner_runInstall(command, args, opts) {
|
|
|
346
586
|
const timer = setTimeout(()=>{
|
|
347
587
|
release();
|
|
348
588
|
endProcessTree(child, spawnProcess, platform, signalGroup);
|
|
589
|
+
child.stdout?.destroy();
|
|
590
|
+
child.stderr?.destroy();
|
|
591
|
+
child.unref();
|
|
349
592
|
resolve({
|
|
350
593
|
code: null,
|
|
351
594
|
stderr,
|
|
@@ -353,13 +596,16 @@ async function install_runner_runInstall(command, args, opts) {
|
|
|
353
596
|
reason: installTimedOutReason(timeoutMs)
|
|
354
597
|
});
|
|
355
598
|
}, timeoutMs);
|
|
356
|
-
child.on('close', (code)=>{
|
|
599
|
+
child.on('close', (code, signal)=>{
|
|
357
600
|
clearTimeout(timer);
|
|
358
601
|
release();
|
|
359
602
|
resolve({
|
|
360
603
|
code,
|
|
361
604
|
stderr,
|
|
362
|
-
stdout
|
|
605
|
+
stdout,
|
|
606
|
+
...null === code && signal ? {
|
|
607
|
+
signal
|
|
608
|
+
} : {}
|
|
363
609
|
});
|
|
364
610
|
});
|
|
365
611
|
child.on('error', (error)=>{
|
|
@@ -562,12 +808,34 @@ async function declarePackageManager(projectPath, manager, probeVersion = versio
|
|
|
562
808
|
};
|
|
563
809
|
}
|
|
564
810
|
const promises_namespaceObject = require("node:fs/promises");
|
|
565
|
-
function
|
|
566
|
-
if (
|
|
567
|
-
|
|
568
|
-
|
|
811
|
+
function utils_define_property(obj, key, value) {
|
|
812
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
813
|
+
value: value,
|
|
814
|
+
enumerable: true,
|
|
815
|
+
configurable: true,
|
|
816
|
+
writable: true
|
|
817
|
+
});
|
|
818
|
+
else obj[key] = value;
|
|
819
|
+
return obj;
|
|
820
|
+
}
|
|
821
|
+
class CreateError extends Error {
|
|
822
|
+
constructor(frame, code, cause){
|
|
823
|
+
super(frame), utils_define_property(this, "code", void 0);
|
|
824
|
+
this.code = code;
|
|
825
|
+
if (void 0 !== cause) this.cause = cause;
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
function isErrorCode(value) {
|
|
829
|
+
return 'string' == typeof value && Object.prototype.hasOwnProperty.call(CODES, value);
|
|
830
|
+
}
|
|
831
|
+
function withCode(error, code) {
|
|
832
|
+
if (!isErrorCode(error.code)) error.code = code;
|
|
569
833
|
return error;
|
|
570
834
|
}
|
|
835
|
+
function failStep(frame, cause, code) {
|
|
836
|
+
if (cause instanceof Error && hasChannelPrefix(cause.message)) return withCode(cause, code);
|
|
837
|
+
return new CreateError(frame, code, cause);
|
|
838
|
+
}
|
|
571
839
|
function isEnvFlagOn(name) {
|
|
572
840
|
const raw = String(process.env[name] ?? '').trim().toLowerCase();
|
|
573
841
|
return '1' === raw || 'true' === raw;
|
|
@@ -711,6 +979,12 @@ async function directoryHasConflicts(projectPath, conflictingFiles) {
|
|
|
711
979
|
function noProjectName() {
|
|
712
980
|
return `${prefix('error')} A project name is required.\n${external_pintor_default().red('Pass a name, for example')} ${external_pintor_default().blue('extension create my-extension')}.\n${external_pintor_default().red('Run')} ${external_pintor_default().blue('extension create --help')} ${external_pintor_default().red('for the full usage.')}`;
|
|
713
981
|
}
|
|
982
|
+
function projectFolderReserved(projectName) {
|
|
983
|
+
return `${prefix('error')} ${external_pintor_default().blue(JSON.stringify(projectName))} can't be the project folder name: npm and the tools around it treat a folder of that name as their own.\n${external_pintor_default().red('Choose another folder name, for example')} ${external_pintor_default().blue('extension create my-extension')}.`;
|
|
984
|
+
}
|
|
985
|
+
function packageNameDerived(projectName, packageName) {
|
|
986
|
+
return `${prefix('info')} package.json names it ${external_pintor_default().blue(packageName)}, because npm refuses ${external_pintor_default().blue(JSON.stringify(projectName))} as a package name. Change it in package.json if you like.`;
|
|
987
|
+
}
|
|
714
988
|
function noUrlAllowed() {
|
|
715
989
|
return `${prefix('error')} A URL is not a valid project path.\n${external_pintor_default().red('Pass a project name or a local directory path.')}`;
|
|
716
990
|
}
|
|
@@ -787,9 +1061,6 @@ function installingFromTemplateError(template, error) {
|
|
|
787
1061
|
function templateUrlNotHttps(url) {
|
|
788
1062
|
return `${prefix('error')} Can't download a template over plain HTTP.\n${fmt.label('GOT')} ${fmt.val(fmt.truncate(url, 120))}\n${external_pintor_default().red('- Use the')} ${external_pintor_default().blue('https://')} ${external_pintor_default().red('address of the template.')}\n${external_pintor_default().red('- Set')} ${external_pintor_default().blue('EXTENSION_ALLOW_HTTP_TEMPLATE=true')} ${external_pintor_default().red('to allow plain HTTP.')}`;
|
|
789
1063
|
}
|
|
790
|
-
function templateFetchTimedOut(templateName, ms) {
|
|
791
|
-
return `${prefix('error')} Couldn't fetch the template ${external_pintor_default().blue(templateName)} within ${Math.round(ms / 1000)}s.\n${external_pintor_default().red('- Check your network connection.')}\n${external_pintor_default().red('- Set')} ${external_pintor_default().blue('EXTENSION_CREATE_TIMEOUT_MS')} ${external_pintor_default().red('to allow more time.')}`;
|
|
792
|
-
}
|
|
793
1064
|
function templateNotFoundInCatalog(templateName, error) {
|
|
794
1065
|
return `${prefix('error')} The template ${external_pintor_default().blue(templateName)} is not in the extension-js/templates catalog.\n` + (error ? `${fmt.label('REASON')} ${fmt.val(fmt.truncate(String(error)))}\n` : '') + `${external_pintor_default().red('- Run')} ${external_pintor_default().blue('extension create --help')} ${external_pintor_default().red('to list the valid template names.')}\n` + `${external_pintor_default().red('- Pass a GitHub URL to use a template from anywhere.')}`;
|
|
795
1066
|
}
|
|
@@ -895,22 +1166,28 @@ function withIncompleteCleanup(frame, leftBehind, notRestored) {
|
|
|
895
1166
|
] : []
|
|
896
1167
|
].join('\n');
|
|
897
1168
|
}
|
|
898
|
-
function installingDependenciesFailed(pmCommand, pmArgs,
|
|
1169
|
+
function installingDependenciesFailed(pmCommand, pmArgs, exit, output, retry) {
|
|
899
1170
|
const digest = installOutputDigest(String(output || ''));
|
|
900
1171
|
const reason = fmt.truncate(digest, 600);
|
|
901
1172
|
const rule = RELEASE_AGE_REFUSAL.test(digest) ? `${fmt.label('RULE')} ${fmt.val('a minimum release age in the npm config holds back versions this new')}\n` : '';
|
|
902
1173
|
const nextStep = createAgainStep(retry);
|
|
903
|
-
return `${prefix('error')} Couldn't install the dependencies.\n${fmt.label('COMMAND')} ${fmt.val(`${pmCommand} ${pmArgs.join(' ')}`)}\n${fmt.label('EXIT')} ${fmt.val(String(
|
|
1174
|
+
return `${prefix('error')} Couldn't install the dependencies.\n${fmt.label('COMMAND')} ${fmt.val(`${pmCommand} ${pmArgs.join(' ')}`)}\n${fmt.label('EXIT')} ${fmt.val(String(exit))}\n` + (reason ? `${fmt.label('REASON')} ${reason}\n` : '') + rule + nextStep;
|
|
904
1175
|
}
|
|
905
1176
|
function installingDependenciesProcessError(projectName, error, retry) {
|
|
906
1177
|
return `${prefix('error')} Couldn't install the dependencies for ${external_pintor_default().blue(projectName)}.\n${fmt.label('REASON')} ${fmt.val(fmt.truncate(String(error)))}\n${external_pintor_default().red('The install process exited unexpectedly.')}\n` + createAgainStep(retry);
|
|
907
1178
|
}
|
|
1179
|
+
function packageManagerNotInstalled(projectName, pmCommand, pmArgs, retry) {
|
|
1180
|
+
return `${prefix('error')} Couldn't install the dependencies for ${external_pintor_default().blue(projectName)}.\n${fmt.label('COMMAND')} ${fmt.val(`${pmCommand} ${pmArgs.join(' ')}`)}\n${fmt.label('REASON')} ${fmt.val(`${pmCommand} is not installed, or not on PATH`)}\n${external_pintor_default().red(`Install ${pmCommand} or add it to PATH.`)}\n` + createAgainStep(retry);
|
|
1181
|
+
}
|
|
908
1182
|
function manifestNotFound(projectPath, searchDepth) {
|
|
909
1183
|
return `${prefix('error')} Couldn't read a manifest.json for this scaffold.\n${fmt.label('PATH')} ${fmt.val(projectPath)}\n${fmt.label('SEARCHED')} ${fmt.val(`the common locations, then every directory up to depth ${searchDepth}`)}\n${external_pintor_default().red('Add a manifest.json, or scaffold from a template that ships one.')}`;
|
|
910
1184
|
}
|
|
911
1185
|
function manifestNotParseable(manifestPath, error) {
|
|
912
1186
|
return `${prefix('error')} Couldn't read a manifest.json for this scaffold.\n${fmt.label('PATH')} ${fmt.val(manifestPath)}\n${fmt.label('REASON')} ${fmt.val(fmt.truncate(String(error?.message || error)))}\n${external_pintor_default().red('Fix that file, then create again.')}`;
|
|
913
1187
|
}
|
|
1188
|
+
function templateFileNotReadable(filePath, error) {
|
|
1189
|
+
return `${prefix('error')} Couldn't read the template's ${external_pintor_default().blue(external_node_path_namespaceObject.basename(filePath))}.\n${fmt.label('PATH')} ${fmt.val(filePath)}\n${fmt.label('REASON')} ${fmt.val(fmt.truncate(String(error?.message || error)))}\n${external_pintor_default().red('Fix that file in the template, then create again.')}`;
|
|
1190
|
+
}
|
|
914
1191
|
function templatePackageJsonNotParseable(packageJsonPath, error) {
|
|
915
1192
|
return `${prefix('error')} Couldn't read the template's ${external_pintor_default().blue('package.json')}.\n${fmt.label('PATH')} ${fmt.val(packageJsonPath)}\n${fmt.label('REASON')} ${fmt.val(fmt.truncate(String(error?.message || error)))}\n${external_pintor_default().red('Fix that file in the template, then create again.')}`;
|
|
916
1193
|
}
|
|
@@ -944,8 +1221,8 @@ function packageManagerUndeclared(manager, reason) {
|
|
|
944
1221
|
function writingDenoJsonc() {
|
|
945
1222
|
return `${prefix('debug')} create write file=deno.jsonc`;
|
|
946
1223
|
}
|
|
947
|
-
function writingDenoJsoncError(error) {
|
|
948
|
-
return `${prefix('error')} Couldn't write ${external_pintor_default().blue(
|
|
1224
|
+
function writingDenoJsoncError(error, fileName = 'deno.jsonc') {
|
|
1225
|
+
return `${prefix('error')} Couldn't write ${external_pintor_default().blue(fileName)}.\n${fmt.label('REASON')} ${fmt.val(fmt.truncate(String(error)))}\n${external_pintor_default().red('Check the file permissions, then try again.')}`;
|
|
949
1226
|
}
|
|
950
1227
|
function writingTemplateProvenance() {
|
|
951
1228
|
return `${prefix('debug')} create write file=.extension-create.json`;
|
|
@@ -993,6 +1270,74 @@ function keepingExistingMcpConfig(projectName) {
|
|
|
993
1270
|
function existingRepositoryKept(projectName) {
|
|
994
1271
|
return `${prefix('info')} ${external_pintor_default().blue(projectName)} is already a git repository with history.\nLeft it uncommitted. Review the scaffold and run ${external_pintor_default().blue('git add -A && git commit')} yourself.`;
|
|
995
1272
|
}
|
|
1273
|
+
const MAX_LENGTH = 214;
|
|
1274
|
+
const RESERVED = new Set([
|
|
1275
|
+
'node_modules',
|
|
1276
|
+
'favicon.ico'
|
|
1277
|
+
]);
|
|
1278
|
+
const NOT_ALLOWED = 'it has characters npm does not allow';
|
|
1279
|
+
function isAllowedChar(char) {
|
|
1280
|
+
return char >= 'a' && char <= 'z' || char >= '0' && char <= '9' || '-' === char || '.' === char || '_' === char;
|
|
1281
|
+
}
|
|
1282
|
+
function isAllowedPart(part) {
|
|
1283
|
+
if ('' === part || part.startsWith('.') || part.startsWith('_')) return false;
|
|
1284
|
+
for (const char of part.toLowerCase())if (!isAllowedChar(char)) return false;
|
|
1285
|
+
return true;
|
|
1286
|
+
}
|
|
1287
|
+
function npmNameProblem(name) {
|
|
1288
|
+
if ('' === name) return 'it is empty';
|
|
1289
|
+
if (name.length > MAX_LENGTH) return `it is longer than ${MAX_LENGTH} characters`;
|
|
1290
|
+
if (name.trim() !== name) return 'it starts or ends with a space';
|
|
1291
|
+
if (name.startsWith('.')) return 'it starts with a dot';
|
|
1292
|
+
if (name.startsWith('_')) return 'it starts with an underscore';
|
|
1293
|
+
if (RESERVED.has(name)) return 'npm reserves that name';
|
|
1294
|
+
if (name.toLowerCase() !== name) return 'it has capital letters';
|
|
1295
|
+
if (name.startsWith('@')) {
|
|
1296
|
+
const slash = name.indexOf('/');
|
|
1297
|
+
const scope = name.slice(1, slash);
|
|
1298
|
+
const bare = name.slice(slash + 1);
|
|
1299
|
+
const ok = slash > 1 && isAllowedPart(scope) && isAllowedPart(bare);
|
|
1300
|
+
return ok ? null : NOT_ALLOWED;
|
|
1301
|
+
}
|
|
1302
|
+
return isAllowedPart(name) ? null : NOT_ALLOWED;
|
|
1303
|
+
}
|
|
1304
|
+
const FALLBACK_PACKAGE_NAME = 'my-extension';
|
|
1305
|
+
function trimDashes(value) {
|
|
1306
|
+
let start = 0;
|
|
1307
|
+
let end = value.length;
|
|
1308
|
+
while(start < end && '-' === value[start])start++;
|
|
1309
|
+
while(end > start && '-' === value[end - 1])end--;
|
|
1310
|
+
return value.slice(start, end);
|
|
1311
|
+
}
|
|
1312
|
+
function convert(folderName) {
|
|
1313
|
+
let converted = '';
|
|
1314
|
+
for (const char of folderName){
|
|
1315
|
+
const lower = char.toLowerCase();
|
|
1316
|
+
if (/\s/.test(char)) {
|
|
1317
|
+
if (!converted.endsWith('-')) converted += '-';
|
|
1318
|
+
} else if (isAllowedChar(lower)) {
|
|
1319
|
+
if (!('-' === lower && converted.endsWith('-'))) converted += lower;
|
|
1320
|
+
} else if (/[\p{L}\p{N}]/u.test(char)) return null;
|
|
1321
|
+
}
|
|
1322
|
+
let start = 0;
|
|
1323
|
+
while(start < converted.length && '._-'.includes(converted[start]))start++;
|
|
1324
|
+
return trimDashes(converted.slice(start));
|
|
1325
|
+
}
|
|
1326
|
+
function packageNameFor(folderName) {
|
|
1327
|
+
if (RESERVED.has(folderName.toLowerCase())) return {
|
|
1328
|
+
reserved: true
|
|
1329
|
+
};
|
|
1330
|
+
if (null === npmNameProblem(folderName)) return {
|
|
1331
|
+
name: folderName,
|
|
1332
|
+
derived: false
|
|
1333
|
+
};
|
|
1334
|
+
const converted = convert(folderName);
|
|
1335
|
+
const usable = null !== converted && '' !== converted && null === npmNameProblem(converted);
|
|
1336
|
+
return {
|
|
1337
|
+
name: usable ? converted : FALLBACK_PACKAGE_NAME,
|
|
1338
|
+
derived: true
|
|
1339
|
+
};
|
|
1340
|
+
}
|
|
996
1341
|
function isUrlProjectName(projectNameInput) {
|
|
997
1342
|
return /^https?:\/\//i.test(projectNameInput.trim());
|
|
998
1343
|
}
|
|
@@ -1009,7 +1354,7 @@ async function createDirectory(projectPath, projectName, logger) {
|
|
|
1009
1354
|
const directoryPreExisted = (0, external_node_fs_namespaceObject.existsSync)(projectPath);
|
|
1010
1355
|
try {
|
|
1011
1356
|
const writeFailure = await directoryWriteFailure(projectPath);
|
|
1012
|
-
if (writeFailure) throw failStep(destinationNotWriteable(projectPath, writeFailure), writeFailure);
|
|
1357
|
+
if (writeFailure) throw failStep(destinationNotWriteable(projectPath, writeFailure), writeFailure, CODES.E_DESTINATION_NOT_WRITABLE);
|
|
1013
1358
|
const currentDir = await promises_namespaceObject.readdir(projectPath);
|
|
1014
1359
|
const conflictingFiles = await Promise.all(currentDir.filter((file)=>!file.startsWith('.')).filter((file)=>!file.endsWith('.log')).filter((file)=>!allowlist.includes(file)).map(async (file)=>{
|
|
1015
1360
|
const stats = await promises_namespaceObject.lstat(external_node_path_namespaceObject.join(projectPath, file));
|
|
@@ -1017,11 +1362,11 @@ async function createDirectory(projectPath, projectName, logger) {
|
|
|
1017
1362
|
}));
|
|
1018
1363
|
if (conflictingFiles.length > 0) {
|
|
1019
1364
|
const conflictMessage = await directoryHasConflicts(projectPath, conflictingFiles);
|
|
1020
|
-
throw new
|
|
1365
|
+
throw new CreateError(conflictMessage, CODES.E_DESTINATION_NOT_EMPTY);
|
|
1021
1366
|
}
|
|
1022
1367
|
for (const [hidden, keeping] of Object.entries(HIDDEN_FILES_TEMPLATES_SHIP))if (currentDir.includes(hidden)) logger.log(keeping(projectName));
|
|
1023
1368
|
} catch (error) {
|
|
1024
|
-
throw failStep(createDirectoryError(projectName, error), error);
|
|
1369
|
+
throw failStep(createDirectoryError(projectName, error), error, CODES.E_DESTINATION_NOT_WRITABLE);
|
|
1025
1370
|
}
|
|
1026
1371
|
return {
|
|
1027
1372
|
directoryCreated: !directoryPreExisted
|
|
@@ -1176,7 +1521,7 @@ async function generateExtensionTypes(projectPath, projectName, logger) {
|
|
|
1176
1521
|
if (isDebug()) logger.log(writingTypeDefinitions(projectName));
|
|
1177
1522
|
await promises_namespaceObject.writeFile(extensionEnvFile, fileContent);
|
|
1178
1523
|
} catch (error) {
|
|
1179
|
-
throw failStep(writingTypeDefinitionsError(error), error);
|
|
1524
|
+
throw failStep(writingTypeDefinitionsError(error), error, CODES.E_DESTINATION_NOT_WRITABLE);
|
|
1180
1525
|
}
|
|
1181
1526
|
}
|
|
1182
1527
|
const external_node_os_namespaceObject = require("node:os");
|
|
@@ -1279,7 +1624,7 @@ function cloneInChild(url, destination, message, options = {}) {
|
|
|
1279
1624
|
});
|
|
1280
1625
|
});
|
|
1281
1626
|
}
|
|
1282
|
-
function
|
|
1627
|
+
function import_external_template_define_property(obj, key, value) {
|
|
1283
1628
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
1284
1629
|
value: value,
|
|
1285
1630
|
enumerable: true,
|
|
@@ -1321,7 +1666,7 @@ function networkTimeoutMs() {
|
|
|
1321
1666
|
return Number.isFinite(raw) && raw > 0 ? raw : 60000;
|
|
1322
1667
|
}
|
|
1323
1668
|
const CODELOAD_BASE = 'https://codeload.github.com/extension-js/templates/zip';
|
|
1324
|
-
const DEFAULT_TEMPLATES_REF = '
|
|
1669
|
+
const DEFAULT_TEMPLATES_REF = '355e74d00daab8083237af30949cd47c49e0c0c3';
|
|
1325
1670
|
const BUNDLED_TEMPLATES = [
|
|
1326
1671
|
"javascript"
|
|
1327
1672
|
];
|
|
@@ -1364,7 +1709,7 @@ function resolveTemplateAlias(name) {
|
|
|
1364
1709
|
}
|
|
1365
1710
|
class TemplateNotFoundError extends Error {
|
|
1366
1711
|
constructor(templateName, cause){
|
|
1367
|
-
super(`template not found in catalog: ${templateName}`),
|
|
1712
|
+
super(`template not found in catalog: ${templateName}`), import_external_template_define_property(this, "code", CODES.E_TEMPLATE_NOT_FOUND), import_external_template_define_property(this, "templateName", void 0);
|
|
1368
1713
|
this.name = 'TemplateNotFoundError';
|
|
1369
1714
|
this.templateName = templateName;
|
|
1370
1715
|
if (cause) this.cause = cause;
|
|
@@ -1372,7 +1717,7 @@ class TemplateNotFoundError extends Error {
|
|
|
1372
1717
|
}
|
|
1373
1718
|
class InsecureTemplateUrlError extends Error {
|
|
1374
1719
|
constructor(url){
|
|
1375
|
-
super(`template URL is not https: ${url}`),
|
|
1720
|
+
super(`template URL is not https: ${url}`), import_external_template_define_property(this, "code", CODES.E_INVALID_OPTION), import_external_template_define_property(this, "url", void 0);
|
|
1376
1721
|
this.name = 'InsecureTemplateUrlError';
|
|
1377
1722
|
this.url = url;
|
|
1378
1723
|
}
|
|
@@ -1396,7 +1741,7 @@ function findInsecureTemplateUrlError(error) {
|
|
|
1396
1741
|
class TemplateDownloadError extends Error {
|
|
1397
1742
|
constructor(templateName, cause){
|
|
1398
1743
|
const msg = cause?.message ?? String(cause);
|
|
1399
|
-
super(msg),
|
|
1744
|
+
super(msg), import_external_template_define_property(this, "code", CODES.E_NETWORK), import_external_template_define_property(this, "templateName", void 0);
|
|
1400
1745
|
this.name = 'TemplateDownloadError';
|
|
1401
1746
|
this.templateName = templateName;
|
|
1402
1747
|
this.cause = cause;
|
|
@@ -1404,7 +1749,7 @@ class TemplateDownloadError extends Error {
|
|
|
1404
1749
|
}
|
|
1405
1750
|
class TemplateNotZipError extends Error {
|
|
1406
1751
|
constructor(url, got){
|
|
1407
|
-
super(`template URL did not answer with a ZIP archive: ${url}`),
|
|
1752
|
+
super(`template URL did not answer with a ZIP archive: ${url}`), import_external_template_define_property(this, "code", CODES.E_REMOTE_ZIP_INVALID), import_external_template_define_property(this, "url", void 0), import_external_template_define_property(this, "got", void 0);
|
|
1408
1753
|
this.name = 'TemplateNotZipError';
|
|
1409
1754
|
this.url = url;
|
|
1410
1755
|
this.got = got;
|
|
@@ -1413,7 +1758,7 @@ class TemplateNotZipError extends Error {
|
|
|
1413
1758
|
class TemplateArchiveDamagedError extends Error {
|
|
1414
1759
|
constructor(url, cause){
|
|
1415
1760
|
const reason = cause?.message ?? String(cause);
|
|
1416
|
-
super(`template archive is damaged: ${url}`),
|
|
1761
|
+
super(`template archive is damaged: ${url}`), import_external_template_define_property(this, "code", CODES.E_REMOTE_ZIP_INVALID), import_external_template_define_property(this, "url", void 0), import_external_template_define_property(this, "reason", void 0);
|
|
1417
1762
|
this.name = 'TemplateArchiveDamagedError';
|
|
1418
1763
|
this.url = url;
|
|
1419
1764
|
this.reason = reason;
|
|
@@ -1422,7 +1767,7 @@ class TemplateArchiveDamagedError extends Error {
|
|
|
1422
1767
|
}
|
|
1423
1768
|
class TemplateArchiveEntryOutsideError extends Error {
|
|
1424
1769
|
constructor(url, entry){
|
|
1425
|
-
super(`template archive has an entry outside its folder: ${entry}`),
|
|
1770
|
+
super(`template archive has an entry outside its folder: ${entry}`), import_external_template_define_property(this, "code", CODES.E_REMOTE_ZIP_INVALID), import_external_template_define_property(this, "url", void 0), import_external_template_define_property(this, "entry", void 0);
|
|
1426
1771
|
this.name = 'TemplateArchiveEntryOutsideError';
|
|
1427
1772
|
this.url = url;
|
|
1428
1773
|
this.entry = entry;
|
|
@@ -1462,27 +1807,44 @@ function startFetchBudget(ms) {
|
|
|
1462
1807
|
};
|
|
1463
1808
|
}
|
|
1464
1809
|
function fetchBudgetSpent(budget) {
|
|
1465
|
-
return new Error(`No answer within ${
|
|
1810
|
+
return new Error(`No answer within ${formatDuration(budget.ms)} (EXTENSION_CREATE_TIMEOUT_MS)`);
|
|
1466
1811
|
}
|
|
1467
1812
|
function budgetSpentBy(error, budget) {
|
|
1468
1813
|
const code = error?.code;
|
|
1469
1814
|
return Date.now() >= budget.deadline || 'ERR_CANCELED' === code || 'ECONNABORTED' === code;
|
|
1470
1815
|
}
|
|
1816
|
+
const OFFLINE_CODES = new Set([
|
|
1817
|
+
'ENOTFOUND',
|
|
1818
|
+
'EAI_AGAIN',
|
|
1819
|
+
'ENETUNREACH',
|
|
1820
|
+
'ENETDOWN',
|
|
1821
|
+
'EHOSTUNREACH'
|
|
1822
|
+
]);
|
|
1823
|
+
function isOffline(error) {
|
|
1824
|
+
const failure = error;
|
|
1825
|
+
if (!failure || void 0 !== failure.response) return false;
|
|
1826
|
+
return OFFLINE_CODES.has(String(failure.code)) || OFFLINE_CODES.has(String(failure.cause?.code));
|
|
1827
|
+
}
|
|
1471
1828
|
async function downloadArchive(url, budget, { attempts = 2, backoffMs = 400, sleep = waitFor } = {}, fetchTemplate = fetchWithAxios) {
|
|
1472
1829
|
let lastError;
|
|
1473
1830
|
for(let attempt = 1; attempt <= attempts; attempt++){
|
|
1474
1831
|
const remaining = budget.deadline - Date.now();
|
|
1475
1832
|
if (remaining <= 0) throw fetchBudgetSpent(budget);
|
|
1833
|
+
const abort = new AbortController();
|
|
1476
1834
|
try {
|
|
1477
|
-
const { data, headers } = await fetchTemplate(url, {
|
|
1835
|
+
const { data, headers } = await withTimeout(fetchTemplate(url, {
|
|
1478
1836
|
responseType: 'arraybuffer',
|
|
1479
1837
|
maxRedirects: 5,
|
|
1480
1838
|
timeout: remaining,
|
|
1481
|
-
signal:
|
|
1839
|
+
signal: abort.signal,
|
|
1482
1840
|
headers: {
|
|
1483
1841
|
'User-Agent': 'extension-create'
|
|
1484
1842
|
},
|
|
1485
1843
|
beforeRedirect: refuseHttpRedirect
|
|
1844
|
+
}), remaining, ()=>{
|
|
1845
|
+
const spent = fetchBudgetSpent(budget);
|
|
1846
|
+
abort.abort(spent);
|
|
1847
|
+
return spent;
|
|
1486
1848
|
});
|
|
1487
1849
|
return {
|
|
1488
1850
|
body: Buffer.from(data),
|
|
@@ -1491,7 +1853,8 @@ async function downloadArchive(url, budget, { attempts = 2, backoffMs = 400, sle
|
|
|
1491
1853
|
} catch (error) {
|
|
1492
1854
|
lastError = error;
|
|
1493
1855
|
if (findInsecureTemplateUrlError(error)) break;
|
|
1494
|
-
if (budgetSpentBy(error, budget)) throw fetchBudgetSpent(budget);
|
|
1856
|
+
if (abort.signal.aborted || budgetSpentBy(error, budget)) throw fetchBudgetSpent(budget);
|
|
1857
|
+
if (isOffline(error)) break;
|
|
1495
1858
|
const status = error?.response?.status;
|
|
1496
1859
|
const retriable = void 0 === status || 429 === status || status >= 500;
|
|
1497
1860
|
if (attempt >= attempts || !retriable) break;
|
|
@@ -1500,6 +1863,48 @@ async function downloadArchive(url, budget, { attempts = 2, backoffMs = 400, sle
|
|
|
1500
1863
|
}
|
|
1501
1864
|
throw lastError;
|
|
1502
1865
|
}
|
|
1866
|
+
function templateArchiveCacheDir(env = process.env, platform = process.platform, home = external_node_os_namespaceObject.homedir()) {
|
|
1867
|
+
const explicit = String(env.EXTENSION_CREATE_CACHE_DIR || '').trim();
|
|
1868
|
+
if (explicit) return external_node_path_namespaceObject.resolve(explicit);
|
|
1869
|
+
const p = 'win32' === platform ? external_node_path_namespaceObject.win32 : external_node_path_namespaceObject.posix;
|
|
1870
|
+
const userHome = env.HOME || home;
|
|
1871
|
+
if ('win32' === platform) {
|
|
1872
|
+
const local = env.LOCALAPPDATA || p.join(env.USERPROFILE || home, 'AppData', 'Local');
|
|
1873
|
+
return p.join(local, 'extension.js', 'templates');
|
|
1874
|
+
}
|
|
1875
|
+
if ('darwin' === platform) return p.join(userHome, 'Library', 'Caches', 'extension.js', 'templates');
|
|
1876
|
+
return p.join(env.XDG_CACHE_HOME || p.join(userHome, '.cache'), 'extension.js', 'templates');
|
|
1877
|
+
}
|
|
1878
|
+
const KEPT_ARCHIVES = 3;
|
|
1879
|
+
async function readCachedArchive(file) {
|
|
1880
|
+
try {
|
|
1881
|
+
const body = await promises_namespaceObject.readFile(file);
|
|
1882
|
+
return isZipBuffer(body) ? body : void 0;
|
|
1883
|
+
} catch {
|
|
1884
|
+
return;
|
|
1885
|
+
}
|
|
1886
|
+
}
|
|
1887
|
+
async function keepArchive(dir, file, body) {
|
|
1888
|
+
try {
|
|
1889
|
+
await promises_namespaceObject.mkdir(dir, {
|
|
1890
|
+
recursive: true
|
|
1891
|
+
});
|
|
1892
|
+
const partial = `${file}.${process.pid}.partial`;
|
|
1893
|
+
await promises_namespaceObject.writeFile(partial, body);
|
|
1894
|
+
await promises_namespaceObject.rename(partial, file);
|
|
1895
|
+
const kept = await Promise.all((await promises_namespaceObject.readdir(dir)).filter((name)=>name.endsWith('.zip')).map(async (name)=>{
|
|
1896
|
+
const full = external_node_path_namespaceObject.join(dir, name);
|
|
1897
|
+
return {
|
|
1898
|
+
full,
|
|
1899
|
+
mtime: (await promises_namespaceObject.stat(full)).mtimeMs
|
|
1900
|
+
};
|
|
1901
|
+
}));
|
|
1902
|
+
kept.sort((a, b)=>b.mtime - a.mtime);
|
|
1903
|
+
for (const old of kept.slice(KEPT_ARCHIVES))await promises_namespaceObject.rm(old.full, {
|
|
1904
|
+
force: true
|
|
1905
|
+
});
|
|
1906
|
+
} catch {}
|
|
1907
|
+
}
|
|
1503
1908
|
async function extractExamplesTemplateFromZip(zipBuffer, templateName, projectPath, sourceUrl) {
|
|
1504
1909
|
const entries = Object.entries(unzipRemoteArchive(zipBuffer, sourceUrl));
|
|
1505
1910
|
if (!entries.length) throw new TemplateNotFoundError(templateName, new Error('empty archive'));
|
|
@@ -1525,11 +1930,25 @@ async function extractExamplesTemplateFromZip(zipBuffer, templateName, projectPa
|
|
|
1525
1930
|
}
|
|
1526
1931
|
return written;
|
|
1527
1932
|
}
|
|
1528
|
-
async function importFromExamplesCatalog(templateName, projectPath, downloadRetry, fetchTemplate) {
|
|
1933
|
+
async function importFromExamplesCatalog(templateName, projectPath, downloadRetry, fetchTemplate, cacheDir) {
|
|
1529
1934
|
const ref = process.env.EXTENSION_CREATE_TEMPLATE_REF || DEFAULT_TEMPLATES_REF;
|
|
1530
1935
|
const overrideUrl = process.env.EXTENSION_CREATE_TEMPLATE_URL || void 0;
|
|
1531
1936
|
if (overrideUrl && isRefusedHttpTemplateUrl(overrideUrl)) throw new InsecureTemplateUrlError(overrideUrl);
|
|
1532
1937
|
const urls = resolveCatalogUrls(ref, overrideUrl);
|
|
1938
|
+
const cachedFile = cacheDir && !overrideUrl && /^[0-9a-f]{40}$/i.test(ref) ? external_node_path_namespaceObject.join(cacheDir, `${ref.toLowerCase()}.zip`) : void 0;
|
|
1939
|
+
const cached = cachedFile ? await readCachedArchive(cachedFile) : void 0;
|
|
1940
|
+
if (cachedFile && cached) try {
|
|
1941
|
+
await extractExamplesTemplateFromZip(cached, templateName, projectPath, urls[0]);
|
|
1942
|
+
return {
|
|
1943
|
+
source: urls[0],
|
|
1944
|
+
ref
|
|
1945
|
+
};
|
|
1946
|
+
} catch (error) {
|
|
1947
|
+
if (!(error instanceof TemplateArchiveDamagedError)) throw error;
|
|
1948
|
+
await promises_namespaceObject.rm(cachedFile, {
|
|
1949
|
+
force: true
|
|
1950
|
+
});
|
|
1951
|
+
}
|
|
1533
1952
|
const budget = startFetchBudget(networkTimeoutMs());
|
|
1534
1953
|
let buffer;
|
|
1535
1954
|
let contentType = '';
|
|
@@ -1545,10 +1964,12 @@ async function importFromExamplesCatalog(templateName, projectPath, downloadRetr
|
|
|
1545
1964
|
const insecure = findInsecureTemplateUrlError(error);
|
|
1546
1965
|
if (insecure) throw insecure;
|
|
1547
1966
|
lastError = error;
|
|
1967
|
+
if (isOffline(error)) break;
|
|
1548
1968
|
}
|
|
1549
1969
|
if (!buffer || !source) throw new TemplateDownloadError(templateName, lastError);
|
|
1550
1970
|
if (!isZipBuffer(buffer)) throw new TemplateNotZipError(source, describeNonZipResponse(contentType, buffer));
|
|
1551
1971
|
await extractExamplesTemplateFromZip(buffer, templateName, projectPath, source);
|
|
1972
|
+
if (cacheDir && cachedFile) await keepArchive(cacheDir, cachedFile, buffer);
|
|
1552
1973
|
return {
|
|
1553
1974
|
source,
|
|
1554
1975
|
ref: overrideUrl ? void 0 : ref
|
|
@@ -1704,10 +2125,18 @@ async function cleanupFailedImport(projectPath, ownsProjectDir, preExistingEntri
|
|
|
1704
2125
|
}
|
|
1705
2126
|
const cleanupNoted = new WeakSet();
|
|
1706
2127
|
function noteIncompleteCleanup(error, { leftBehind, notRestored }) {
|
|
1707
|
-
if (
|
|
1708
|
-
if (
|
|
2128
|
+
if (0 === leftBehind.length && 0 === notRestored.length) return error;
|
|
2129
|
+
if (!(error instanceof Error)) {
|
|
2130
|
+
const wrapped = Object.assign(new Error(withIncompleteCleanup(String(error), leftBehind, notRestored)), {
|
|
2131
|
+
cause: error
|
|
2132
|
+
});
|
|
2133
|
+
cleanupNoted.add(wrapped);
|
|
2134
|
+
return wrapped;
|
|
2135
|
+
}
|
|
2136
|
+
if (cleanupNoted.has(error)) return error;
|
|
1709
2137
|
cleanupNoted.add(error);
|
|
1710
2138
|
error.message = withIncompleteCleanup(error.message, leftBehind, notRestored);
|
|
2139
|
+
return error;
|
|
1711
2140
|
}
|
|
1712
2141
|
async function readOwnerGitignore(projectPath) {
|
|
1713
2142
|
try {
|
|
@@ -1767,12 +2196,15 @@ async function putBackOwnerHiddenFiles(projectPath, ownerFiles) {
|
|
|
1767
2196
|
for (const [name, contents] of files){
|
|
1768
2197
|
if (null === contents) continue;
|
|
1769
2198
|
const target = external_node_path_namespaceObject.join(projectPath, name);
|
|
1770
|
-
await
|
|
1771
|
-
notRestored.push(target);
|
|
1772
|
-
});
|
|
2199
|
+
if (!await putBackFile(target, contents)) notRestored.push(target);
|
|
1773
2200
|
}
|
|
1774
2201
|
return notRestored;
|
|
1775
2202
|
}
|
|
2203
|
+
async function putBackFile(target, contents) {
|
|
2204
|
+
const current = await promises_namespaceObject.readFile(target).catch(()=>null);
|
|
2205
|
+
if (current?.equals(Buffer.from(contents))) return true;
|
|
2206
|
+
return promises_namespaceObject.writeFile(target, contents).then(()=>true, ()=>false);
|
|
2207
|
+
}
|
|
1776
2208
|
async function importExternalTemplate(projectPath, projectName, template, logger, options) {
|
|
1777
2209
|
const templateName = external_node_path_namespaceObject.basename(template);
|
|
1778
2210
|
const resolvedTemplate = template;
|
|
@@ -1793,7 +2225,7 @@ async function importExternalTemplate(projectPath, projectName, template, logger
|
|
|
1793
2225
|
if (isRefusedHttpTemplateUrl(template)) throw new InsecureTemplateUrlError(template);
|
|
1794
2226
|
if (localTemplateDir) {
|
|
1795
2227
|
const outsideTemplate = external_node_path_namespaceObject.relative(realPathOrResolved(localTemplateDir), realPathOrResolved(projectPath));
|
|
1796
|
-
if (!outsideTemplate || !outsideTemplate.startsWith('..') && !external_node_path_namespaceObject.isAbsolute(outsideTemplate)) throw new
|
|
2228
|
+
if (!outsideTemplate || !outsideTemplate.startsWith('..') && !external_node_path_namespaceObject.isAbsolute(outsideTemplate)) throw new CreateError(templateDirectoryIsDestination(localTemplateDir, external_node_path_namespaceObject.resolve(projectPath)), CODES.E_INVALID_OPTION);
|
|
1797
2229
|
}
|
|
1798
2230
|
await promises_namespaceObject.mkdir(projectPath, {
|
|
1799
2231
|
recursive: true
|
|
@@ -1829,9 +2261,10 @@ async function importExternalTemplate(projectPath, projectName, template, logger
|
|
|
1829
2261
|
process.env[k] = v;
|
|
1830
2262
|
}
|
|
1831
2263
|
const abort = new AbortController();
|
|
2264
|
+
const budget = startFetchBudget(timeoutMs);
|
|
1832
2265
|
try {
|
|
1833
|
-
await withTimeout(cloneTemplate(templatePath, destination, installingFromTemplate(templateName), abort.signal),
|
|
1834
|
-
const timedOut =
|
|
2266
|
+
await withTimeout(cloneTemplate(templatePath, destination, installingFromTemplate(templateName), abort.signal), budget.ms, ()=>{
|
|
2267
|
+
const timedOut = fetchBudgetSpent(budget);
|
|
1835
2268
|
abort.abort(timedOut);
|
|
1836
2269
|
return timedOut;
|
|
1837
2270
|
});
|
|
@@ -1841,14 +2274,9 @@ async function importExternalTemplate(projectPath, projectName, template, logger
|
|
|
1841
2274
|
}
|
|
1842
2275
|
};
|
|
1843
2276
|
const fetchZipArchive = async ()=>{
|
|
1844
|
-
const {
|
|
1845
|
-
|
|
1846
|
-
maxRedirects: 5,
|
|
1847
|
-
timeout: timeoutMs,
|
|
1848
|
-
beforeRedirect: refuseHttpRedirect
|
|
2277
|
+
const { body, contentType } = await downloadArchive(template, startFetchBudget(timeoutMs), options?.downloadRetry, fetchTemplate).catch((fetchError)=>{
|
|
2278
|
+
throw findInsecureTemplateUrlError(fetchError) ?? new TemplateDownloadError(template, fetchError);
|
|
1849
2279
|
});
|
|
1850
|
-
const contentType = String(headers?.['content-type'] || '');
|
|
1851
|
-
const body = Buffer.from(data);
|
|
1852
2280
|
const looksZip = /zip|octet-stream/i.test(contentType) || template.toLowerCase().endsWith('.zip');
|
|
1853
2281
|
if (!looksZip || !isZipBuffer(body)) throw new TemplateNotZipError(template, describeNonZipResponse(contentType, body));
|
|
1854
2282
|
return body;
|
|
@@ -1872,10 +2300,7 @@ async function importExternalTemplate(projectPath, projectName, template, logger
|
|
|
1872
2300
|
source: template
|
|
1873
2301
|
};
|
|
1874
2302
|
} else if (isHttp) {
|
|
1875
|
-
const
|
|
1876
|
-
const data = await withTimeout(fetchZipArchive(), budget.ms, ()=>fetchBudgetSpent(budget)).catch((fetchError)=>{
|
|
1877
|
-
throw findInsecureTemplateUrlError(fetchError) ?? (fetchError instanceof TemplateNotZipError ? fetchError : new TemplateDownloadError(template, budgetSpentBy(fetchError, budget) ? fetchBudgetSpent(budget) : fetchError));
|
|
1878
|
-
});
|
|
2303
|
+
const data = await fetchZipArchive();
|
|
1879
2304
|
await extractZipBufferTo(data, tempPath, template);
|
|
1880
2305
|
const sourcePath = await getZipSourcePath(tempPath, template);
|
|
1881
2306
|
droppedLinks = await moveDirectoryContents(sourcePath, projectPath);
|
|
@@ -1884,7 +2309,7 @@ async function importExternalTemplate(projectPath, projectName, template, logger
|
|
|
1884
2309
|
source: template
|
|
1885
2310
|
};
|
|
1886
2311
|
} else {
|
|
1887
|
-
const catalog = await importFromExamplesCatalog(resolvedTemplateName, projectPath, options?.downloadRetry, fetchTemplate);
|
|
2312
|
+
const catalog = await importFromExamplesCatalog(resolvedTemplateName, projectPath, options?.downloadRetry, fetchTemplate, options?.archiveCacheDir ?? (options?.fetch ? void 0 : templateArchiveCacheDir()));
|
|
1888
2313
|
provenance = {
|
|
1889
2314
|
template: resolvedTemplateName,
|
|
1890
2315
|
source: catalog.source,
|
|
@@ -1913,15 +2338,14 @@ async function importExternalTemplate(projectPath, projectName, template, logger
|
|
|
1913
2338
|
}
|
|
1914
2339
|
const insecureUrl = findInsecureTemplateUrlError(error);
|
|
1915
2340
|
const frame = insecureUrl ? templateUrlNotHttps(insecureUrl.url) : error instanceof TemplateNotFoundError ? looksLikeTemplatePath(template) ? templatePathNotFound(template) : templateNotFoundInCatalog(templateName, error.cause) : error instanceof TemplateNotZipError ? templateUrlNotZip(error.url, error.got, catalogOverride) : error instanceof TemplateArchiveEntryOutsideError ? templateArchiveEntryOutside(error.url, error.entry, catalogOverride) : error instanceof TemplateArchiveDamagedError ? templateArchiveDamaged(error.url, error.reason, catalogOverride) : error instanceof TemplateDownloadError ? isHttp ? templateUrlFetchFailed(template, error) : catalogOverride ? templateOverrideFetchFailed(catalogOverride, error) : templateDownloadFailed(templateName, error) : null;
|
|
1916
|
-
const failure = null === frame ? failStep(installingFromTemplateError(templateName, error), error) : error;
|
|
2341
|
+
const failure = null === frame ? failStep(installingFromTemplateError(templateName, error), error, CODES.E_INTERNAL) : error;
|
|
1917
2342
|
if (null !== frame && failure instanceof Error) failure.message = frame;
|
|
1918
2343
|
const leftBehind = await cleanupFailedImport(projectPath, ownsProjectDir, preExistingEntries, options?.remove);
|
|
1919
2344
|
const notRestored = ownsProjectDir ? [] : await putBackOwnerHiddenFiles(projectPath, ownerFiles);
|
|
1920
|
-
noteIncompleteCleanup(failure, {
|
|
2345
|
+
throw noteIncompleteCleanup(failure, {
|
|
1921
2346
|
leftBehind,
|
|
1922
2347
|
notRestored
|
|
1923
2348
|
});
|
|
1924
|
-
throw failure;
|
|
1925
2349
|
} finally{
|
|
1926
2350
|
if (tempRoot) await promises_namespaceObject.rm(tempRoot, {
|
|
1927
2351
|
recursive: true,
|
|
@@ -2207,7 +2631,7 @@ async function findManifestJsonPath(projectPath) {
|
|
|
2207
2631
|
});
|
|
2208
2632
|
}
|
|
2209
2633
|
}
|
|
2210
|
-
throw new
|
|
2634
|
+
throw new CreateError(manifestNotFound(projectPath, manifestSearchMaxDepth), CODES.E_TEMPLATE_NOT_FOUND);
|
|
2211
2635
|
}
|
|
2212
2636
|
async function readManifestJson(projectPath) {
|
|
2213
2637
|
const manifestJsonPath = await findManifestJsonPath(projectPath);
|
|
@@ -2218,7 +2642,7 @@ async function readManifestJson(projectPath) {
|
|
|
2218
2642
|
manifestJson: JSON.parse(raw)
|
|
2219
2643
|
};
|
|
2220
2644
|
} catch (error) {
|
|
2221
|
-
throw failStep(manifestNotParseable(manifestJsonPath, error), error);
|
|
2645
|
+
throw failStep(manifestNotParseable(manifestJsonPath, error), error, CODES.E_TEMPLATE_NOT_FOUND);
|
|
2222
2646
|
}
|
|
2223
2647
|
}
|
|
2224
2648
|
function readTemplatePackageJson(projectPath) {
|
|
@@ -2229,7 +2653,7 @@ function readTemplatePackageJson(projectPath) {
|
|
|
2229
2653
|
return parsed;
|
|
2230
2654
|
} catch (error) {
|
|
2231
2655
|
if (error?.code === 'ENOENT') return;
|
|
2232
|
-
throw failStep(templatePackageJsonNotParseable(packageJsonPath, error), error);
|
|
2656
|
+
throw failStep(templatePackageJsonNotParseable(packageJsonPath, error), error, CODES.E_TEMPLATE_NOT_FOUND);
|
|
2233
2657
|
}
|
|
2234
2658
|
}
|
|
2235
2659
|
function failureOutput(run) {
|
|
@@ -2370,12 +2794,12 @@ async function installDependencies(projectPath, projectName, logger, packageMana
|
|
|
2370
2794
|
stdio
|
|
2371
2795
|
});
|
|
2372
2796
|
if (0 === retryRun.code) return;
|
|
2373
|
-
throw new
|
|
2797
|
+
throw new CreateError(installingDependenciesFailed(command, dependenciesArgs, installExit(retryRun), failureOutput(retryRun), retry), CODES.E_DEPENDENCY_INSTALL, new InstallExitError(command, dependenciesArgs, retryRun));
|
|
2374
2798
|
}
|
|
2375
|
-
throw new
|
|
2799
|
+
throw new CreateError(installingDependenciesFailed(command, dependenciesArgs, installExit(firstRun), output, retry), CODES.E_DEPENDENCY_INSTALL, new InstallExitError(command, dependenciesArgs, firstRun));
|
|
2376
2800
|
}
|
|
2377
2801
|
} catch (error) {
|
|
2378
|
-
throw failStep(installingDependenciesProcessError(projectName, error, retry), error);
|
|
2802
|
+
throw failStep(isMissingCommand(error, command) ? packageManagerNotInstalled(projectName, command, dependenciesArgs, retry) : installingDependenciesProcessError(projectName, error, retry), error, CODES.E_DEPENDENCY_INSTALL);
|
|
2379
2803
|
}
|
|
2380
2804
|
}
|
|
2381
2805
|
const requireFromCreate = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__);
|
|
@@ -2430,7 +2854,6 @@ function findConfigFile(projectPath, candidates) {
|
|
|
2430
2854
|
function detectOptionalDependencies(projectPath) {
|
|
2431
2855
|
const pkg = readPackageJson(projectPath);
|
|
2432
2856
|
const usesReact = hasDependency(pkg, 'react') || hasDependency(pkg, 'react-dom');
|
|
2433
|
-
const usesPreact = hasDependency(pkg, 'preact');
|
|
2434
2857
|
const usesVue = hasDependency(pkg, 'vue');
|
|
2435
2858
|
const usesSvelte = hasDependency(pkg, 'svelte');
|
|
2436
2859
|
const hasTsConfig = external_node_fs_namespaceObject.existsSync(external_node_path_namespaceObject.join(projectPath, 'tsconfig.json'));
|
|
@@ -2472,12 +2895,6 @@ function detectOptionalDependencies(projectPath) {
|
|
|
2472
2895
|
'react-refresh',
|
|
2473
2896
|
'@rspack/plugin-react-refresh'
|
|
2474
2897
|
]);
|
|
2475
|
-
if (usesPreact) addIntegration('Preact', [
|
|
2476
|
-
'@prefresh/core',
|
|
2477
|
-
'@prefresh/utils',
|
|
2478
|
-
'@rspack/plugin-preact-refresh',
|
|
2479
|
-
'preact'
|
|
2480
|
-
]);
|
|
2481
2898
|
if (usesVue) addIntegration('Vue', [
|
|
2482
2899
|
'vue-loader',
|
|
2483
2900
|
'@vue/compiler-sfc'
|
|
@@ -2577,19 +2994,21 @@ async function installOptionalDependencies(developRoot, projectPath, plan, logge
|
|
|
2577
2994
|
cwd: developRoot,
|
|
2578
2995
|
stdio
|
|
2579
2996
|
}).catch((error)=>{
|
|
2580
|
-
|
|
2997
|
+
const projectName = external_node_path_namespaceObject.basename(projectPath);
|
|
2998
|
+
const retry = {
|
|
2581
2999
|
projectPath,
|
|
2582
3000
|
template
|
|
2583
|
-
}
|
|
3001
|
+
};
|
|
3002
|
+
throw failStep(isMissingCommand(error, pm) ? packageManagerNotInstalled(projectName, pm, args, retry) : installingDependenciesProcessError(projectName, error, retry), error, CODES.E_DEPENDENCY_INSTALL);
|
|
2584
3003
|
});
|
|
2585
|
-
if (0 !== result.code) throw new
|
|
3004
|
+
if (0 !== result.code) throw new CreateError(installingDependenciesFailed(pm, args, installExit(result), [
|
|
2586
3005
|
result.reason,
|
|
2587
3006
|
result.stdout,
|
|
2588
3007
|
result.stderr
|
|
2589
3008
|
].filter((part)=>void 0 !== part).join('\n'), {
|
|
2590
3009
|
projectPath,
|
|
2591
3010
|
template
|
|
2592
|
-
}));
|
|
3011
|
+
}), CODES.E_DEPENDENCY_INSTALL, new InstallExitError(pm, args, result));
|
|
2593
3012
|
}
|
|
2594
3013
|
async function installInternalDependencies(projectPath, logger, packageManager, template, canResolveDependency = canResolve, cwd = process.cwd(), runInstall = install_runner_runInstall) {
|
|
2595
3014
|
if (isEnvFlagOn('EXTENSION_SKIP_INTERNAL_INSTALL')) return;
|
|
@@ -2603,7 +3022,7 @@ async function setupBuiltInTests(projectPath) {
|
|
|
2603
3022
|
const testSpecPath = external_node_path_namespaceObject.join(projectPath, 'tests', 'templates.spec.ts');
|
|
2604
3023
|
if (external_node_fs_namespaceObject.existsSync(testSpecPath)) external_node_fs_namespaceObject.unlinkSync(testSpecPath);
|
|
2605
3024
|
} catch (error) {
|
|
2606
|
-
throw failStep(cantSetupBuiltInTests(error), error);
|
|
3025
|
+
throw failStep(cantSetupBuiltInTests(error), error, CODES.E_DESTINATION_NOT_WRITABLE);
|
|
2607
3026
|
}
|
|
2608
3027
|
}
|
|
2609
3028
|
async function resolveExtensionBinary() {
|
|
@@ -2676,9 +3095,10 @@ function resolveExtensionDevDependencyVersion(cliVersion) {
|
|
|
2676
3095
|
}
|
|
2677
3096
|
async function overridePackageJson(projectPath, options, logger) {
|
|
2678
3097
|
const { template = "javascript", cliVersion } = options;
|
|
3098
|
+
const packageName = options.packageName ?? external_node_path_namespaceObject.basename(projectPath);
|
|
2679
3099
|
const extensionBinary = await resolveExtensionBinary();
|
|
2680
3100
|
const packageJson = readTemplatePackageJson(projectPath) ?? {
|
|
2681
|
-
name:
|
|
3101
|
+
name: packageName,
|
|
2682
3102
|
private: true,
|
|
2683
3103
|
scripts: {},
|
|
2684
3104
|
dependencies: {},
|
|
@@ -2732,7 +3152,7 @@ async function overridePackageJson(projectPath, options, logger) {
|
|
|
2732
3152
|
if (declaration.undeclared) delete templateFields.packageManager;
|
|
2733
3153
|
const packageMetadata = {
|
|
2734
3154
|
...templateFields,
|
|
2735
|
-
name:
|
|
3155
|
+
name: packageName,
|
|
2736
3156
|
private: true,
|
|
2737
3157
|
...packageManagerSpec ? {
|
|
2738
3158
|
packageManager: packageManagerSpec
|
|
@@ -2754,7 +3174,7 @@ async function overridePackageJson(projectPath, options, logger) {
|
|
|
2754
3174
|
if (isDebug()) logger.log(writingPackageJsonMetadata());
|
|
2755
3175
|
await promises_namespaceObject.writeFile(external_node_path_namespaceObject.join(projectPath, 'package.json'), `${JSON.stringify(packageMetadata, null, 2)}\n`);
|
|
2756
3176
|
} catch (error) {
|
|
2757
|
-
throw failStep(writingPackageJsonMetadataError(error), error);
|
|
3177
|
+
throw failStep(writingPackageJsonMetadataError(error), error, CODES.E_DESTINATION_NOT_WRITABLE);
|
|
2758
3178
|
}
|
|
2759
3179
|
if (declaration.undeclared && 'deno' !== packageManager) logger.log(packageManagerUndeclared(packageManager, declaration.undeclared));
|
|
2760
3180
|
const written = packageMetadata.packageManager;
|
|
@@ -2798,6 +3218,15 @@ async function collectTemplateImports(projectPath, cliVersion) {
|
|
|
2798
3218
|
imports.extension = `npm:extension@${extensionVersion}`;
|
|
2799
3219
|
return imports;
|
|
2800
3220
|
}
|
|
3221
|
+
async function readTemplateDenoConfig(configPath) {
|
|
3222
|
+
try {
|
|
3223
|
+
const parsed = parseJsoncSafe(await promises_namespaceObject.readFile(configPath, 'utf8'));
|
|
3224
|
+
if (!parsed || 'object' != typeof parsed || Array.isArray(parsed)) throw new TypeError('The file does not hold a JSON object');
|
|
3225
|
+
return parsed;
|
|
3226
|
+
} catch (error) {
|
|
3227
|
+
throw new CreateError(templateFileNotReadable(configPath, error), CODES.E_TEMPLATE_NOT_FOUND, error);
|
|
3228
|
+
}
|
|
3229
|
+
}
|
|
2801
3230
|
async function writeDenoJsonc(projectPath, { template = "javascript", cliVersion, primary = false }, logger) {
|
|
2802
3231
|
if (!isDenoRuntime()) return;
|
|
2803
3232
|
let existingConfig;
|
|
@@ -2812,11 +3241,11 @@ async function writeDenoJsonc(projectPath, { template = "javascript", cliVersion
|
|
|
2812
3241
|
const extensionBinary = await resolveExtensionBinary();
|
|
2813
3242
|
const tasks = getTemplateAwareScripts(template, extensionBinary);
|
|
2814
3243
|
const imports = primary ? await collectTemplateImports(projectPath, cliVersion) : void 0;
|
|
3244
|
+
const configPath = existingConfig ? external_node_path_namespaceObject.join(projectPath, existingConfig) : external_node_path_namespaceObject.join(projectPath, 'deno.jsonc');
|
|
3245
|
+
const config = existingConfig ? await readTemplateDenoConfig(configPath) : void 0;
|
|
2815
3246
|
try {
|
|
2816
3247
|
if (isDebug()) logger.log(writingDenoJsonc());
|
|
2817
|
-
if (
|
|
2818
|
-
const configPath = external_node_path_namespaceObject.join(projectPath, existingConfig);
|
|
2819
|
-
const config = parseJsoncSafe(await promises_namespaceObject.readFile(configPath, 'utf8'));
|
|
3248
|
+
if (config) {
|
|
2820
3249
|
config.imports = {
|
|
2821
3250
|
...imports || {},
|
|
2822
3251
|
...config.imports || {}
|
|
@@ -2828,12 +3257,12 @@ async function writeDenoJsonc(projectPath, { template = "javascript", cliVersion
|
|
|
2828
3257
|
...config.tasks || {}
|
|
2829
3258
|
};
|
|
2830
3259
|
await promises_namespaceObject.writeFile(configPath, `${JSON.stringify(config, null, 2)}\n`);
|
|
2831
|
-
} else await promises_namespaceObject.writeFile(
|
|
3260
|
+
} else await promises_namespaceObject.writeFile(configPath, renderDenoJsonc(tasks, imports));
|
|
2832
3261
|
if (primary) await promises_namespaceObject.rm(external_node_path_namespaceObject.join(projectPath, 'package.json'), {
|
|
2833
3262
|
force: true
|
|
2834
3263
|
});
|
|
2835
3264
|
} catch (error) {
|
|
2836
|
-
throw failStep(writingDenoJsoncError(error), error);
|
|
3265
|
+
throw failStep(writingDenoJsoncError(error, external_node_path_namespaceObject.basename(configPath)), error, CODES.E_DESTINATION_NOT_WRITABLE);
|
|
2837
3266
|
}
|
|
2838
3267
|
}
|
|
2839
3268
|
const intro = '# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.';
|
|
@@ -2904,7 +3333,7 @@ async function writeGitignore(projectPath, logger, options = {}) {
|
|
|
2904
3333
|
const templateEnvFiles = await templateEnvFilesIn(projectPath, options.ownedEntries ?? []);
|
|
2905
3334
|
const currentContents = await promises_namespaceObject.readFile(gitIgnorePath, 'utf8').catch((err)=>{
|
|
2906
3335
|
if ('ENOENT' === err.code) return '';
|
|
2907
|
-
throw failStep(writingGitIgnoreError(gitIgnorePath, err), err);
|
|
3336
|
+
throw failStep(writingGitIgnoreError(gitIgnorePath, err), err, CODES.E_DESTINATION_NOT_WRITABLE);
|
|
2908
3337
|
});
|
|
2909
3338
|
const present = new Set(currentContents.split(/\r?\n/).map(comparable).filter(Boolean));
|
|
2910
3339
|
const blocks = groups.flatMap(({ header, rules })=>{
|
|
@@ -2926,7 +3355,7 @@ async function writeGitignore(projectPath, logger, options = {}) {
|
|
|
2926
3355
|
const existing = currentContents.trimEnd();
|
|
2927
3356
|
const contents = `${existing ? `${existing}\n\n` : ''}${blocks.join('\n\n')}\n`;
|
|
2928
3357
|
await promises_namespaceObject.writeFile(gitIgnorePath, contents).catch((err)=>{
|
|
2929
|
-
throw failStep(writingGitIgnoreError(gitIgnorePath, err), err);
|
|
3358
|
+
throw failStep(writingGitIgnoreError(gitIgnorePath, err), err, CODES.E_DESTINATION_NOT_WRITABLE);
|
|
2930
3359
|
});
|
|
2931
3360
|
}
|
|
2932
3361
|
const external_node_crypto_namespaceObject = require("node:crypto");
|
|
@@ -2979,7 +3408,7 @@ async function writeManifestJson(projectPath, logger, generateAddonId = createAd
|
|
|
2979
3408
|
}
|
|
2980
3409
|
await promises_namespaceObject.writeFile(manifestJsonPath, JSON.stringify(manifestMetadata, null, 2));
|
|
2981
3410
|
} catch (error) {
|
|
2982
|
-
throw failStep(writingManifestJsonMetadataError(error), error);
|
|
3411
|
+
throw failStep(writingManifestJsonMetadataError(error), error, CODES.E_DESTINATION_NOT_WRITABLE);
|
|
2983
3412
|
}
|
|
2984
3413
|
return templateName;
|
|
2985
3414
|
}
|
|
@@ -3011,7 +3440,7 @@ async function writeReadmeFile(projectPath, projectName, logger, packageManager)
|
|
|
3011
3440
|
});
|
|
3012
3441
|
await promises_namespaceObject.writeFile(external_node_path_namespaceObject.join(projectPath, 'README.md'), readme);
|
|
3013
3442
|
} catch (error) {
|
|
3014
|
-
throw failStep(writingReadmeMetaDataError(error), error);
|
|
3443
|
+
throw failStep(writingReadmeMetaDataError(error), error, CODES.E_DESTINATION_NOT_WRITABLE);
|
|
3015
3444
|
}
|
|
3016
3445
|
}
|
|
3017
3446
|
const STORE_METADATA_FILE = 'STORE.md';
|
|
@@ -3075,12 +3504,14 @@ async function writeTemplateProvenance(projectPath, provenance, logger) {
|
|
|
3075
3504
|
}
|
|
3076
3505
|
}
|
|
3077
3506
|
async function runCreate(projectNameInput, { cliVersion, template, install = false, logger = console }, seams = {}) {
|
|
3078
|
-
if (!projectNameInput) throw new
|
|
3507
|
+
if (!projectNameInput) throw new CreateError(noProjectName(), CODES.E_ARGS);
|
|
3079
3508
|
const templateWasOmitted = null == template || '' === String(template).trim();
|
|
3080
3509
|
const effectiveTemplate = templateWasOmitted ? DEFAULT_TEMPLATE_NAME : String(template);
|
|
3081
|
-
if (isUrlProjectName(projectNameInput)) throw new
|
|
3510
|
+
if (isUrlProjectName(projectNameInput)) throw new CreateError(noUrlAllowed(), CODES.E_INVALID_OPTION);
|
|
3082
3511
|
const projectPath = external_node_path_namespaceObject.isAbsolute(projectNameInput) ? projectNameInput : external_node_path_namespaceObject.join(process.cwd(), projectNameInput);
|
|
3083
3512
|
const projectName = external_node_path_namespaceObject.basename(projectPath);
|
|
3513
|
+
const packageName = packageNameFor(projectName);
|
|
3514
|
+
if ('reserved' in packageName) throw new CreateError(projectFolderReserved(projectName), CODES.E_ARGS);
|
|
3084
3515
|
const updateSuffix = process.env.EXTENSION_CLI_UPDATE_SUFFIX || '';
|
|
3085
3516
|
if (updateSuffix) delete process.env.EXTENSION_CLI_UPDATE_SUFFIX;
|
|
3086
3517
|
const requestedTemplate = effectiveTemplate;
|
|
@@ -3113,6 +3544,7 @@ async function runCreate(projectNameInput, { cliVersion, template, install = fal
|
|
|
3113
3544
|
return await scaffoldProject({
|
|
3114
3545
|
projectPath,
|
|
3115
3546
|
projectName,
|
|
3547
|
+
packageName,
|
|
3116
3548
|
effectiveTemplate,
|
|
3117
3549
|
templateWasOmitted,
|
|
3118
3550
|
ownsProjectDir,
|
|
@@ -3127,18 +3559,15 @@ async function runCreate(projectNameInput, { cliVersion, template, install = fal
|
|
|
3127
3559
|
const notRestored = [];
|
|
3128
3560
|
if (null !== ownerGitignore) {
|
|
3129
3561
|
const gitignorePath = external_node_path_namespaceObject.join(projectPath, '.gitignore');
|
|
3130
|
-
await
|
|
3131
|
-
notRestored.push(gitignorePath);
|
|
3132
|
-
});
|
|
3562
|
+
if (!await putBackFile(gitignorePath, ownerGitignore)) notRestored.push(gitignorePath);
|
|
3133
3563
|
}
|
|
3134
|
-
noteIncompleteCleanup(error, {
|
|
3564
|
+
throw noteIncompleteCleanup(error, {
|
|
3135
3565
|
leftBehind,
|
|
3136
3566
|
notRestored
|
|
3137
3567
|
});
|
|
3138
|
-
throw error;
|
|
3139
3568
|
}
|
|
3140
3569
|
}
|
|
3141
|
-
async function scaffoldProject({ projectPath, projectName, effectiveTemplate, templateWasOmitted, ownsProjectDir, preExistingEntries = [], install, cliVersion, logger, seams }) {
|
|
3570
|
+
async function scaffoldProject({ projectPath, projectName, packageName, effectiveTemplate, templateWasOmitted, ownsProjectDir, preExistingEntries = [], install, cliVersion, logger, seams }) {
|
|
3142
3571
|
const templateProvenance = await importExternalTemplate(projectPath, projectName, effectiveTemplate, logger, {
|
|
3143
3572
|
ownsProjectDir,
|
|
3144
3573
|
allowOfflineFallback: templateWasOmitted,
|
|
@@ -3158,9 +3587,11 @@ async function scaffoldProject({ projectPath, projectName, effectiveTemplate, te
|
|
|
3158
3587
|
const written = await overridePackageJson(projectPath, {
|
|
3159
3588
|
template: scaffoldedTemplate,
|
|
3160
3589
|
cliVersion,
|
|
3590
|
+
packageName: packageName.name,
|
|
3161
3591
|
packageManager,
|
|
3162
3592
|
probeVersion: seams.probeVersion
|
|
3163
3593
|
}, logger);
|
|
3594
|
+
if (packageName.derived) logger.log(packageNameDerived(projectName, packageName.name));
|
|
3164
3595
|
packageManagerSpec = written.packageManagerSpec;
|
|
3165
3596
|
await writeDenoJsonc(projectPath, {
|
|
3166
3597
|
template: scaffoldedTemplate
|
|
@@ -3189,6 +3620,7 @@ async function scaffoldProject({ projectPath, projectName, effectiveTemplate, te
|
|
|
3189
3620
|
return {
|
|
3190
3621
|
projectPath,
|
|
3191
3622
|
projectName,
|
|
3623
|
+
packageName: packageName.name,
|
|
3192
3624
|
template: scaffoldedTemplate,
|
|
3193
3625
|
depsInstalled: install,
|
|
3194
3626
|
...void 0 === installSeconds ? {} : {
|