extension-create 3.6.3 → 3.7.0-canary.170.2b1f54a

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 (2) hide show
  1. package/dist/module.cjs +88 -254
  2. package/package.json +4 -7
package/dist/module.cjs CHANGED
@@ -202,23 +202,6 @@ function cantSetupBuiltInTests(projectName, error) {
202
202
  return `${external_pintor_default().red('Error')} Couldn't set up built-in tests for ${external_pintor_default().yellow(projectName)}.\n${external_pintor_default().red(String(error))}\n${external_pintor_default().red('Next step: run the setup step again or skip tests.')}`;
203
203
  }
204
204
  const promises_namespaceObject = require("fs/promises");
205
- async function copyDirectoryWithSymlinks(source, destination) {
206
- const entries = await promises_namespaceObject.readdir(source, {
207
- withFileTypes: true
208
- });
209
- await promises_namespaceObject.mkdir(destination, {
210
- recursive: true
211
- });
212
- for (const entry of entries){
213
- const sourcePath = external_path_namespaceObject.join(source, entry.name);
214
- const destPath = external_path_namespaceObject.join(destination, entry.name);
215
- if (entry.isDirectory()) await copyDirectoryWithSymlinks(sourcePath, destPath);
216
- else if (entry.isSymbolicLink()) {
217
- const target = await promises_namespaceObject.readlink(sourcePath);
218
- await promises_namespaceObject.symlink(target, destPath);
219
- } else await promises_namespaceObject.copyFile(sourcePath, destPath);
220
- }
221
- }
222
205
  async function moveDirectoryContents(source, destination) {
223
206
  await promises_namespaceObject.mkdir(destination, {
224
207
  recursive: true
@@ -230,10 +213,18 @@ async function moveDirectoryContents(source, destination) {
230
213
  const sourcePath = external_path_namespaceObject.join(source, entry.name);
231
214
  const destPath = external_path_namespaceObject.join(destination, entry.name);
232
215
  if (entry.isDirectory()) await moveDirectoryContents(sourcePath, destPath);
233
- else if (entry.isSymbolicLink()) {
216
+ else if (entry.isSymbolicLink()) try {
234
217
  const target = await promises_namespaceObject.readlink(sourcePath);
235
218
  await promises_namespaceObject.symlink(target, destPath);
236
- } else try {
219
+ } catch (err) {
220
+ if (err?.code === 'EPERM' || err?.code === 'ENOTSUP') {
221
+ const real = await promises_namespaceObject.realpath(sourcePath);
222
+ await promises_namespaceObject.cp(real, destPath, {
223
+ recursive: true
224
+ });
225
+ } else throw err;
226
+ }
227
+ else try {
237
228
  await promises_namespaceObject.rename(sourcePath, destPath);
238
229
  } catch (err) {
239
230
  if (err && ('EXDEV' === err.code || 'EINVAL' === err.code)) {
@@ -294,7 +285,6 @@ async function createDirectory(projectPath, projectName) {
294
285
  throw new Error(createDirectoryError(projectName, error));
295
286
  }
296
287
  }
297
- const external_url_namespaceObject = require("url");
298
288
  const external_os_namespaceObject = require("os");
299
289
  const external_axios_namespaceObject = require("axios");
300
290
  var external_axios_default = /*#__PURE__*/ __webpack_require__.n(external_axios_namespaceObject);
@@ -302,149 +292,77 @@ const external_adm_zip_namespaceObject = require("adm-zip");
302
292
  var external_adm_zip_default = /*#__PURE__*/ __webpack_require__.n(external_adm_zip_namespaceObject);
303
293
  const external_go_git_it_namespaceObject = require("go-git-it");
304
294
  var external_go_git_it_default = /*#__PURE__*/ __webpack_require__.n(external_go_git_it_namespaceObject);
305
- const import_external_template_filename = (0, external_url_namespaceObject.fileURLToPath)(__rslib_import_meta_url__);
306
- const import_external_template_dirname = external_path_namespaceObject.dirname(import_external_template_filename);
295
+ function getArchiveBaseName(url) {
296
+ const withoutQuery = url.split('?')[0];
297
+ const fileName = external_path_namespaceObject.basename(withoutQuery);
298
+ if (!fileName.toLowerCase().endsWith('.zip')) return fileName;
299
+ return fileName.slice(0, -4);
300
+ }
301
+ async function getZipSourcePath(tempPath, templateUrl) {
302
+ const archiveBase = getArchiveBaseName(templateUrl);
303
+ let entries = [];
304
+ try {
305
+ entries = await promises_namespaceObject.readdir(tempPath, {
306
+ withFileTypes: true
307
+ });
308
+ } catch {
309
+ return tempPath;
310
+ }
311
+ const dirs = entries.filter((entry)=>entry.isDirectory());
312
+ if (1 !== dirs.length) return tempPath;
313
+ const onlyDir = dirs[0];
314
+ if (onlyDir.name === archiveBase) return external_path_namespaceObject.join(tempPath, onlyDir.name);
315
+ return tempPath;
316
+ }
307
317
  async function importExternalTemplate(projectPath, projectName, template) {
308
318
  const templateName = external_path_namespaceObject.basename(template);
309
319
  const examplesUrl = 'https://github.com/extension-js/examples/tree/main/examples';
310
320
  const resolvedTemplate = 'init' === templateName ? "javascript" : template;
311
321
  const resolvedTemplateName = 'init' === templateName ? "javascript" : templateName;
312
322
  const templateUrl = `${examplesUrl}/${resolvedTemplate}`;
313
- const examplesZipUrl = 'https://codeload.github.com/extension-js/examples/zip/refs/heads/main';
314
323
  try {
315
324
  await promises_namespaceObject.mkdir(projectPath, {
316
325
  recursive: true
317
326
  });
318
- if ('development' === process.env.EXTENSION_ENV) {
319
- console.log(installingFromTemplate(projectName, template));
320
- async function findTemplatesRoot(startDir) {
321
- let current = startDir;
322
- const maxDepth = 6;
323
- for(let i = 0; i < maxDepth; i++){
324
- const candidate = external_path_namespaceObject.join(current, 'templates');
325
- try {
326
- const stats = await promises_namespaceObject.stat(candidate);
327
- if (stats.isDirectory()) return candidate;
328
- } catch {}
329
- const parent = external_path_namespaceObject.dirname(current);
330
- if (parent === current) break;
331
- current = parent;
332
- }
333
- }
334
- const localTemplatesRoot = await findTemplatesRoot(import_external_template_dirname);
335
- if (!localTemplatesRoot) throw new Error('Local templates directory not found');
336
- const localTemplatePath = external_path_namespaceObject.join(localTemplatesRoot, resolvedTemplateName);
337
- await copyDirectoryWithSymlinks(localTemplatePath, projectPath);
338
- } else {
339
- const tempRoot = await promises_namespaceObject.mkdtemp(external_path_namespaceObject.join(external_os_namespaceObject.tmpdir(), 'extension-js-create-'));
340
- const tempPath = external_path_namespaceObject.join(tempRoot, projectName + '-temp');
341
- await promises_namespaceObject.mkdir(tempPath, {
342
- recursive: true
327
+ const tempRoot = await promises_namespaceObject.mkdtemp(external_path_namespaceObject.join(external_os_namespaceObject.tmpdir(), 'extension-js-create-'));
328
+ const tempPath = external_path_namespaceObject.join(tempRoot, projectName + '-temp');
329
+ await promises_namespaceObject.mkdir(tempPath, {
330
+ recursive: true
331
+ });
332
+ const isHttp = /^https?:\/\//i.test(template);
333
+ const isGithub = /^https?:\/\/github.com\//i.test(template);
334
+ const runGoGitIt = async (templatePath, destination)=>{
335
+ await external_go_git_it_default()(templatePath, destination, installingFromTemplate(projectName, templateName));
336
+ };
337
+ if (isGithub) {
338
+ await runGoGitIt(template, tempPath);
339
+ const candidates = await promises_namespaceObject.readdir(tempPath, {
340
+ withFileTypes: true
343
341
  });
344
- const isHttp = /^https?:\/\//i.test(template);
345
- const isGithub = /^https?:\/\/github.com\//i.test(template);
346
- async function withFilteredOutput(fn) {
347
- const originalStdoutWrite = process.stdout.write.bind(process.stdout);
348
- const originalStderrWrite = process.stderr.write.bind(process.stderr);
349
- const stdoutBuffer = {
350
- value: ''
351
- };
352
- const stderrBuffer = {
353
- value: ''
354
- };
355
- let suppressGoGitItStack = false;
356
- const toText = (chunk)=>'string' == typeof chunk ? chunk : chunk?.toString?.() ?? '';
357
- const shouldFilterLine = (line)=>{
358
- if (!line) return false;
359
- const trimmed = line.trim();
360
- if (!trimmed) return false;
361
- if (/Using git version/i.test(line) || /GitHub API rate limit reached, continuing without connectivity check/i.test(line) || /^Downloading extension\b/i.test(trimmed) || /^URL https?:\/\/codeload\.github\.com\/extension-js\/examples\/zip\/refs\/heads\/main\b/i.test(trimmed) || /^\[[=\s]+\]\s*\d+%/i.test(trimmed)) {
362
- suppressGoGitItStack = true;
363
- return true;
364
- }
365
- if (suppressGoGitItStack && /^\s+at\b/.test(line)) return true;
366
- if (suppressGoGitItStack && !/^\s+at\b/.test(line)) suppressGoGitItStack = false;
367
- return false;
368
- };
369
- const writeWithFilter = (originalWrite, buffer)=>(chunk, ...args)=>{
370
- const text = buffer.value + toText(chunk);
371
- if (!text) return true;
372
- const parts = text.split(/\r?\n|\r/);
373
- buffer.value = parts.pop() ?? '';
374
- if (0 === parts.length) return true;
375
- const kept = [];
376
- for (const line of parts)if (!shouldFilterLine(line)) kept.push(line);
377
- if (0 === kept.length) return true;
378
- return originalWrite(kept.join('\n') + '\n', ...args);
379
- };
380
- process.stdout.write = writeWithFilter(originalStdoutWrite, stdoutBuffer);
381
- process.stderr.write = writeWithFilter(originalStderrWrite, stderrBuffer);
382
- try {
383
- return await fn();
384
- } finally{
385
- process.stdout.write = originalStdoutWrite;
386
- process.stderr.write = originalStderrWrite;
387
- }
388
- }
389
- if (isGithub) {
390
- await withFilteredOutput(()=>external_go_git_it_default()(template, tempPath, installingFromTemplate(projectName, templateName)));
391
- const candidates = await promises_namespaceObject.readdir(tempPath, {
392
- withFileTypes: true
393
- });
394
- const preferred = candidates.find((d)=>d.isDirectory() && d.name === templateName);
395
- const srcPath = preferred ? external_path_namespaceObject.join(tempPath, templateName) : tempPath;
396
- await moveDirectoryContents(srcPath, projectPath);
397
- } else if (isHttp) {
398
- const { data, headers } = await external_axios_default().get(template, {
399
- responseType: 'arraybuffer',
400
- maxRedirects: 5
401
- });
402
- const contentType = String(headers?.['content-type'] || '');
403
- const looksZip = /zip|octet-stream/i.test(contentType) || template.toLowerCase().endsWith('.zip');
404
- if (!looksZip) throw new Error(`Remote template does not appear to be a ZIP archive: ${template}`);
405
- const zip = new (external_adm_zip_default())(Buffer.from(data));
406
- zip.extractAllTo(tempPath, true);
407
- await moveDirectoryContents(tempPath, projectPath);
408
- } else {
409
- const ok = await (async ()=>{
410
- const zipExtractRoot = external_path_namespaceObject.join(tempPath, 'zip-extract');
411
- try {
412
- const { data } = await external_axios_default().get(examplesZipUrl, {
413
- responseType: 'arraybuffer',
414
- maxRedirects: 5
415
- });
416
- const zip = new (external_adm_zip_default())(Buffer.from(data));
417
- zip.extractAllTo(zipExtractRoot, true);
418
- const entries = await promises_namespaceObject.readdir(zipExtractRoot, {
419
- withFileTypes: true
420
- });
421
- const rootDir = entries.find((e)=>e.isDirectory())?.name;
422
- if (!rootDir) return false;
423
- const srcPath = external_path_namespaceObject.join(zipExtractRoot, rootDir, 'examples', resolvedTemplateName);
424
- await moveDirectoryContents(srcPath, projectPath);
425
- return true;
426
- } catch {
427
- return false;
428
- } finally{
429
- try {
430
- await promises_namespaceObject.rm(zipExtractRoot, {
431
- recursive: true,
432
- force: true
433
- });
434
- } catch {}
435
- }
436
- })();
437
- if (!ok) {
438
- await withFilteredOutput(()=>external_go_git_it_default()(templateUrl, tempPath, installingFromTemplate(projectName, templateName)));
439
- const srcPath = external_path_namespaceObject.join(tempPath, resolvedTemplateName);
440
- await moveDirectoryContents(srcPath, projectPath);
441
- }
442
- }
443
- await promises_namespaceObject.rm(tempRoot, {
444
- recursive: true,
445
- force: true
342
+ const preferred = candidates.find((d)=>d.isDirectory() && d.name === templateName);
343
+ const srcPath = preferred ? external_path_namespaceObject.join(tempPath, templateName) : tempPath;
344
+ await moveDirectoryContents(srcPath, projectPath);
345
+ } else if (isHttp) {
346
+ const { data, headers } = await external_axios_default().get(template, {
347
+ responseType: 'arraybuffer',
348
+ maxRedirects: 5
446
349
  });
350
+ const contentType = String(headers?.['content-type'] || '');
351
+ const looksZip = /zip|octet-stream/i.test(contentType) || template.toLowerCase().endsWith('.zip');
352
+ if (!looksZip) throw new Error(`Remote template does not appear to be a ZIP archive: ${template}`);
353
+ const zip = new (external_adm_zip_default())(Buffer.from(data));
354
+ zip.extractAllTo(tempPath, true);
355
+ const sourcePath = await getZipSourcePath(tempPath, template);
356
+ await moveDirectoryContents(sourcePath, projectPath);
357
+ } else {
358
+ await runGoGitIt(templateUrl, tempPath);
359
+ const srcPath = external_path_namespaceObject.join(tempPath, resolvedTemplateName);
360
+ await moveDirectoryContents(srcPath, projectPath);
447
361
  }
362
+ await promises_namespaceObject.rm(tempRoot, {
363
+ recursive: true,
364
+ force: true
365
+ });
448
366
  } catch (error) {
449
367
  console.error(installingFromTemplateError(projectName, templateName, error));
450
368
  throw error;
@@ -506,52 +424,6 @@ async function overridePackageJson(projectPath, projectName, { template: _templa
506
424
  throw error;
507
425
  }
508
426
  }
509
- function clearLine() {
510
- if (!process.stdout.isTTY) return;
511
- process.stdout.write('\r');
512
- process.stdout.write('\x1b[2K');
513
- }
514
- function stripAnsi(input) {
515
- return input.replace(/\x1b\[[0-9;]*m/g, '');
516
- }
517
- function shouldShowProgress() {
518
- return Boolean(process.stdout.isTTY) && !process.env.CI;
519
- }
520
- function startProgressBar(label, options) {
521
- const enabled = (options?.enabled ?? true) && shouldShowProgress();
522
- if (!enabled) return {
523
- stop: ()=>void 0
524
- };
525
- const width = Math.max(10, options?.width ?? 24);
526
- const intervalMs = Math.max(50, options?.intervalMs ?? 90);
527
- let tick = 0;
528
- let lastVisibleLength = 0;
529
- const render = ()=>{
530
- const filled = tick % (width + 1);
531
- const empty = width - filled;
532
- const bar = `[${'='.repeat(filled)}${' '.repeat(empty)}]`;
533
- const line = `${label} ${bar}`;
534
- lastVisibleLength = stripAnsi(line).length;
535
- clearLine();
536
- process.stdout.write(line);
537
- tick = (tick + 1) % (width + 1);
538
- };
539
- render();
540
- const timer = setInterval(render, intervalMs);
541
- return {
542
- stop: ()=>{
543
- clearInterval(timer);
544
- if (process.stdout.isTTY) {
545
- clearLine();
546
- if (lastVisibleLength > 0) {
547
- process.stdout.write(' '.repeat(lastVisibleLength));
548
- process.stdout.write('\r');
549
- }
550
- if (options?.persistLabel) process.stdout.write(`${label}\n`);
551
- }
552
- }
553
- };
554
- }
555
427
  const external_cross_spawn_namespaceObject = require("cross-spawn");
556
428
  function buildExecEnv() {
557
429
  if ('win32' !== process.platform) return;
@@ -652,38 +524,19 @@ async function installDependencies(projectPath, projectName) {
652
524
  const command = await getInstallCommand();
653
525
  const dependenciesArgs = getInstallArgs();
654
526
  const installMessage = installingDependencies();
655
- const progressEnabled = shouldShowProgress();
656
- const progress = startProgressBar(installMessage, {
657
- enabled: progressEnabled,
658
- persistLabel: true
659
- });
660
- if (!progressEnabled) console.log(installMessage);
527
+ console.log(installMessage);
661
528
  try {
662
529
  await external_fs_namespaceObject.promises.mkdir(nodeModulesPath, {
663
530
  recursive: true
664
531
  });
665
532
  const stdio = 'development' === process.env.EXTENSION_ENV ? 'inherit' : 'pipe';
666
- let firstRun;
667
- try {
668
- firstRun = await install_dependencies_runInstall(command, dependenciesArgs, projectPath, stdio);
669
- } finally{
670
- progress.stop();
671
- }
533
+ const firstRun = await install_dependencies_runInstall(command, dependenciesArgs, projectPath, stdio);
672
534
  if (0 !== firstRun.code) {
673
535
  const output = `${firstRun.stdout}\n${firstRun.stderr}`;
674
536
  const shouldRetry = shouldRetryWithTagFallback(output);
675
537
  const didUpdate = shouldRetry ? await updateExtensionDependencyTag(projectPath, projectName) : false;
676
538
  if (didUpdate) {
677
- const retryProgress = startProgressBar(installMessage, {
678
- enabled: progressEnabled,
679
- persistLabel: true
680
- });
681
- let retryRun;
682
- try {
683
- retryRun = await install_dependencies_runInstall(command, dependenciesArgs, projectPath, stdio);
684
- } finally{
685
- retryProgress.stop();
686
- }
539
+ const retryRun = await install_dependencies_runInstall(command, dependenciesArgs, projectPath, stdio);
687
540
  if (0 === retryRun.code) return;
688
541
  }
689
542
  throw new Error(installingDependenciesFailed(command, dependenciesArgs, firstRun.code));
@@ -1183,29 +1036,19 @@ async function installBuildDependencies(developRoot, plan) {
1183
1036
  if (0 === plan.dependencies.length) return;
1184
1037
  const pm = detectPackageManagerFromEnv();
1185
1038
  const installMessage = installingBuildDependencies(plan.dependencies);
1186
- const progressEnabled = shouldShowProgress();
1187
- const progress = startProgressBar(installMessage, {
1188
- enabled: progressEnabled,
1189
- persistLabel: true
1039
+ console.log(installMessage);
1040
+ const args = buildBuildInstallArgs(pm, plan.dependencies, plan.dependencyMap);
1041
+ const stdio = 'development' === process.env.EXTENSION_ENV ? 'inherit' : 'ignore';
1042
+ const result = await runInstall(pm, args, {
1043
+ cwd: developRoot,
1044
+ stdio
1190
1045
  });
1191
- if (!progressEnabled) console.log(installMessage);
1192
- try {
1193
- const args = buildBuildInstallArgs(pm, plan.dependencies, plan.dependencyMap);
1194
- const stdio = 'development' === process.env.EXTENSION_ENV ? 'inherit' : 'ignore';
1195
- const result = await runInstall(pm, args, {
1196
- cwd: developRoot,
1197
- stdio
1198
- });
1199
- if (0 !== result.code) throw new Error(installingDependenciesFailed(pm, args, result.code));
1200
- } finally{
1201
- progress.stop();
1202
- }
1046
+ if (0 !== result.code) throw new Error(installingDependenciesFailed(pm, args, result.code));
1203
1047
  }
1204
1048
  async function installOptionalDependencies(developRoot, projectPath, plan) {
1205
1049
  if (0 === plan.dependencies.length) return;
1206
1050
  const pm = detectPackageManagerFromEnv();
1207
1051
  const stdio = 'development' === process.env.EXTENSION_ENV ? 'inherit' : 'ignore';
1208
- const progressEnabled = shouldShowProgress();
1209
1052
  console.log(foundSpecializedDependencies(plan.integrations.length));
1210
1053
  for (const [index, integration] of plan.integrations.entries()){
1211
1054
  const missingDeps = plan.dependenciesByIntegration[integration] || [];
@@ -1213,25 +1056,16 @@ async function installOptionalDependencies(developRoot, projectPath, plan) {
1213
1056
  integration
1214
1057
  ]);
1215
1058
  const installMessage = baseMessage.replace('►►► ', `►►► [${index + 1}/${plan.integrations.length}] `);
1216
- const progress = startProgressBar(installMessage, {
1217
- enabled: progressEnabled,
1218
- persistLabel: true
1219
- });
1220
- if (!progressEnabled) console.log(installMessage);
1221
- try {
1222
- if (0 === missingDeps.length) continue;
1223
- for (const dep of missingDeps){
1224
- const args = buildOptionalInstallArgs(pm, [
1225
- dep
1226
- ], developRoot);
1227
- const result = await runInstall(pm, args, {
1228
- cwd: developRoot,
1229
- stdio
1230
- });
1231
- if (0 !== result.code) throw new Error(installingDependenciesFailed(pm, args, result.code));
1232
- }
1233
- } finally{
1234
- progress.stop();
1059
+ console.log(installMessage);
1060
+ if (0 !== missingDeps.length) for (const dep of missingDeps){
1061
+ const args = buildOptionalInstallArgs(pm, [
1062
+ dep
1063
+ ], developRoot);
1064
+ const result = await runInstall(pm, args, {
1065
+ cwd: developRoot,
1066
+ stdio
1067
+ });
1068
+ if (0 !== result.code) throw new Error(installingDependenciesFailed(pm, args, result.code));
1235
1069
  }
1236
1070
  }
1237
1071
  }
package/package.json CHANGED
@@ -23,7 +23,7 @@
23
23
  "dist"
24
24
  ],
25
25
  "name": "extension-create",
26
- "version": "3.6.3",
26
+ "version": "3.7.0-canary.170.2b1f54a",
27
27
  "description": "The standalone extension creation engine for Extension.js",
28
28
  "author": {
29
29
  "name": "Cezar Augusto",
@@ -42,8 +42,8 @@
42
42
  "clean": "rm -rf dist",
43
43
  "watch": "rslib build --watch",
44
44
  "compile": "rslib build",
45
- "format": "prettier --write \"**/*.{ts,tsx,md,js,json}\"",
46
- "lint": "eslint .",
45
+ "format": "biome format --write .",
46
+ "lint": "biome lint .",
47
47
  "pretest:create": "pnpm compile",
48
48
  "test:create": "vitest run",
49
49
  "test:coverage": "vitest run --coverage"
@@ -79,8 +79,8 @@
79
79
  "tiny-glob": "^0.2.9"
80
80
  },
81
81
  "devDependencies": {
82
+ "@biomejs/biome": "^2.2.4",
82
83
  "@changesets/cli": "^2.29.8",
83
- "@eslint/js": "^9.39.2",
84
84
  "@rslib/core": "^0.19.4",
85
85
  "@types/adm-zip": "^0.5.7",
86
86
  "@types/chrome": "^0.1.33",
@@ -88,9 +88,6 @@
88
88
  "@types/node": "^25.2.0",
89
89
  "@types/webextension-polyfill": "0.12.4",
90
90
  "@vitest/coverage-v8": "^4.0.17",
91
- "eslint": "^9.39.2",
92
- "globals": "^17.3.0",
93
- "prettier": "^3.8.0",
94
91
  "tsconfig": "*",
95
92
  "typescript": "5.9.3",
96
93
  "vitest": "^4.0.17",