extension-develop 4.1.17 → 4.1.18-canary.1789403792.e514b06c

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/840~0.mjs CHANGED
@@ -7,7 +7,8 @@ import { EventEmitter } from "node:events";
7
7
  import { browserRowValue, ENVELOPE, CODES, prefix as messaging_prefix, card, isDebug, claimCardKey, isMachineOutput } from "./852~0.mjs";
8
8
  import { package_namespaceObject, loadCommandConfig, DEV_COMMAND_DEFAULTS, stampReadyDistExtensionId, loadProjectConfigDefaults, mergeOptionLayers, stampReadyKnownExtensionId, assertNoManagedDependencyConflicts, loadCustomConfig, START_BUILD_DEFAULTS, loadBrowserConfig, resolveCompanionExtensionsConfig, BUILD_COMMAND_DEFAULTS, getSpecialFoldersDataForProjectRoot, withDarkMode } from "./832~0.mjs";
9
9
  import { stripBom, hasProjectDependency, parseJsonSafe, findNearestProjectManifestDirSync } from "./731~0.mjs";
10
- import { buildWarningsDetails, buildFailed, getDirs, zipArtifactReady, projectInstallFallbackToNpm, debugDirs, browserLaunchFailed, buildSummaryPath, extensionLoadRecovered, extensionLoadStillRefused, writingTypeDefinitionsError, buildAssetsTree, authorInstallNotice, projectInstallScriptsDisabled, configBrowserOrThrow, needsInstall, buildCommandFailed, writingTypeDefinitions, buildComplete, ensureSessionStateInProjectGitignore, ensureSessionArtifactsIgnoreFile, normalizeBrowser, debugBrowser, debugOutputPath, devCommandFailed, getProjectStructure, getDistPath, buildShareHint, debugSplitChunksNarrowed } from "./950~0.mjs";
10
+ import { isGeckoBasedBrowser } from "./331~0.mjs";
11
+ import { buildWarningsDetails, buildFailed, getDirs, zipArtifactReady, projectInstallFallbackToNpm, debugDirs, browserLaunchFailed, buildSummaryPath, addonLintMore, extensionLoadRecovered, writingTypeDefinitionsError, extensionLoadStillRefused, projectInstallScriptsDisabled, authorInstallNotice, addonLintFailed, buildAssetsTree, addonLintSummary, addonLintFinding, configBrowserOrThrow, needsInstall, buildCommandFailed, addonLintNotInstalled, writingTypeDefinitions, buildComplete, ensureSessionStateInProjectGitignore, ensureSessionArtifactsIgnoreFile, debugBrowser, normalizeBrowser, debugOutputPath, devCommandFailed, getDistPath, buildShareHint, getProjectStructure, debugSplitChunksNarrowed } from "./950~0.mjs";
11
12
  import { publicRootsFor } from "./105~0.mjs";
12
13
  import { getCanonicalContentScriptEntryName } from "./640~0.mjs";
13
14
  import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
@@ -257,87 +258,6 @@ function attachLifecycleStream(compiler, stream) {
257
258
  } catch {}
258
259
  });
259
260
  }
260
- const DIST_STAGING_PREFIX = '.extension-build-';
261
- function stagingDistPathFor(distPath) {
262
- const unique = `${process.pid.toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
263
- return __rspack_external_node_path_806ed179.join(__rspack_external_node_path_806ed179.dirname(distPath), `${DIST_STAGING_PREFIX}${__rspack_external_node_path_806ed179.basename(distPath)}-${unique}`);
264
- }
265
- function removeStaleStagingDirs(distPath) {
266
- const parent = __rspack_external_node_path_806ed179.dirname(distPath);
267
- const prefix = `${DIST_STAGING_PREFIX}${__rspack_external_node_path_806ed179.basename(distPath)}-`;
268
- let entries;
269
- try {
270
- entries = __rspack_external_node_fs_1b05aee1.readdirSync(parent, {
271
- withFileTypes: true
272
- });
273
- } catch {
274
- return;
275
- }
276
- for (const entry of entries)try {
277
- if (!entry.isDirectory() || !entry.name.startsWith(prefix)) continue;
278
- __rspack_external_node_fs_1b05aee1.rmSync(__rspack_external_node_path_806ed179.join(parent, entry.name), {
279
- recursive: true,
280
- force: true
281
- });
282
- } catch {}
283
- }
284
- function removeStagingDir(stagingPath) {
285
- try {
286
- __rspack_external_node_fs_1b05aee1.rmSync(stagingPath, {
287
- recursive: true,
288
- force: true
289
- });
290
- } catch {}
291
- }
292
- function promoteStagingDist(stagingPath, distPath) {
293
- const parent = __rspack_external_node_path_806ed179.dirname(distPath);
294
- __rspack_external_node_fs_1b05aee1.mkdirSync(parent, {
295
- recursive: true
296
- });
297
- const retiredPath = `${stagingPath}-retired`;
298
- let retired = false;
299
- if (__rspack_external_node_fs_1b05aee1.existsSync(distPath)) {
300
- __rspack_external_node_fs_1b05aee1.renameSync(distPath, retiredPath);
301
- retired = true;
302
- }
303
- try {
304
- __rspack_external_node_fs_1b05aee1.renameSync(stagingPath, distPath);
305
- } catch (error) {
306
- if (retired) try {
307
- __rspack_external_node_fs_1b05aee1.renameSync(retiredPath, distPath);
308
- } catch {}
309
- throw error;
310
- }
311
- if (retired) try {
312
- __rspack_external_node_fs_1b05aee1.rmSync(retiredPath, {
313
- recursive: true,
314
- force: true
315
- });
316
- } catch {}
317
- }
318
- const MAX_SUMMARY_WARNINGS = 20;
319
- const build_summary_ANSI_PATTERN = /\u001b\[[0-9;]*m/g;
320
- function getBuildSummary(browser, info, outputPath) {
321
- const assets = info?.assets || [];
322
- const warnings = (info?.warnings || []).slice(0, MAX_SUMMARY_WARNINGS).map((warning)=>{
323
- const message = warning && 'object' == typeof warning ? String(warning.message ?? '') : String(warning ?? '');
324
- return message.replace(build_summary_ANSI_PATTERN, '').trim();
325
- }).filter(Boolean);
326
- return {
327
- browser,
328
- ...outputPath ? {
329
- output_path: outputPath
330
- } : {},
331
- total_assets: assets.length,
332
- total_bytes: assets.reduce((n, a)=>n + (a.size || 0), 0),
333
- largest_asset_bytes: assets.reduce((m, a)=>Math.max(m, a.size || 0), 0),
334
- warnings_count: (info?.warnings || []).length,
335
- errors_count: (info?.errors || []).length,
336
- ...warnings.length ? {
337
- warnings
338
- } : {}
339
- };
340
- }
341
261
  const cjsRequire = createRequire(import.meta.url);
342
262
  if (!process.env.EXTENSION_JS_OPTIONAL_DEPS_VERSION) process.env.EXTENSION_JS_OPTIONAL_DEPS_VERSION = package_namespaceObject.rE;
343
263
  function resolveDevelopRootFromDir(dir) {
@@ -410,6 +330,155 @@ function resolveDevelopDistFile(stem) {
410
330
  if ('1' === process.env.EXTENSION_DEBUG_DEVELOP_ROOT) console.log(`[extjs:develop-root] ${stem} -> ${base} (fallback, installRoot=${installRoot || '<none>'})`);
411
331
  return base;
412
332
  }
333
+ const BUNDLED_DEPENDENCY_VERSIONS = {
334
+ ...package_namespaceObject.El || {}
335
+ };
336
+ function optional_deps_contracts_spec(packageId) {
337
+ const version = BUNDLED_DEPENDENCY_VERSIONS[packageId];
338
+ return version ? `${packageId}@${version}` : packageId;
339
+ }
340
+ function specs(packageIds) {
341
+ return packageIds.map(optional_deps_contracts_spec);
342
+ }
343
+ function installRootRules(packageIds) {
344
+ return packageIds.map((packageId)=>({
345
+ type: 'install-root',
346
+ packageId
347
+ }));
348
+ }
349
+ function defineContract(contract) {
350
+ return contract;
351
+ }
352
+ const OPTIONAL_DEPENDENCY_CONTRACTS = {
353
+ 'react-refresh': defineContract({
354
+ id: 'react-refresh',
355
+ integration: 'React',
356
+ installPackages: specs([
357
+ 'react-refresh',
358
+ '@rspack/plugin-react-refresh'
359
+ ]),
360
+ verificationRules: [
361
+ ...installRootRules([
362
+ 'react-refresh',
363
+ '@rspack/plugin-react-refresh'
364
+ ]),
365
+ {
366
+ type: 'module-context-resolve',
367
+ fromPackage: '@rspack/plugin-react-refresh',
368
+ packageId: 'react-refresh'
369
+ }
370
+ ]
371
+ }),
372
+ 'preact-refresh': defineContract({
373
+ id: 'preact-refresh',
374
+ integration: 'Preact',
375
+ installPackages: specs([
376
+ '@prefresh/core',
377
+ '@prefresh/utils',
378
+ '@rspack/plugin-preact-refresh',
379
+ 'preact'
380
+ ]),
381
+ verificationRules: [
382
+ ...installRootRules([
383
+ '@prefresh/core',
384
+ '@prefresh/utils',
385
+ '@rspack/plugin-preact-refresh',
386
+ 'preact'
387
+ ]),
388
+ {
389
+ type: 'module-context-resolve',
390
+ fromPackage: '@rspack/plugin-preact-refresh',
391
+ packageId: '@prefresh/core'
392
+ },
393
+ {
394
+ type: 'module-context-resolve',
395
+ fromPackage: '@rspack/plugin-preact-refresh',
396
+ packageId: '@prefresh/utils'
397
+ },
398
+ {
399
+ type: 'module-context-resolve',
400
+ fromPackage: '@rspack/plugin-preact-refresh',
401
+ packageId: 'preact'
402
+ }
403
+ ]
404
+ }),
405
+ vue: defineContract({
406
+ id: 'vue',
407
+ integration: 'Vue',
408
+ installPackages: specs([
409
+ 'vue-loader',
410
+ '@vue/compiler-sfc',
411
+ 'vue'
412
+ ]),
413
+ verificationRules: [
414
+ ...installRootRules([
415
+ 'vue-loader',
416
+ '@vue/compiler-sfc',
417
+ 'vue'
418
+ ]),
419
+ {
420
+ type: 'module-context-load',
421
+ fromPackage: 'vue-loader',
422
+ packageId: '@vue/compiler-sfc'
423
+ }
424
+ ]
425
+ }),
426
+ svelte: defineContract({
427
+ id: 'svelte',
428
+ integration: 'Svelte',
429
+ installPackages: specs([
430
+ 'svelte-loader'
431
+ ]),
432
+ verificationRules: installRootRules([
433
+ 'svelte-loader'
434
+ ])
435
+ }),
436
+ less: defineContract({
437
+ id: 'less',
438
+ integration: 'LESS',
439
+ installPackages: specs([
440
+ 'less',
441
+ 'less-loader'
442
+ ]),
443
+ verificationRules: installRootRules([
444
+ 'less',
445
+ 'less-loader'
446
+ ])
447
+ }),
448
+ postcss: defineContract({
449
+ id: 'postcss',
450
+ integration: 'PostCSS',
451
+ installPackages: specs([
452
+ 'postcss',
453
+ 'postcss-loader'
454
+ ]),
455
+ verificationRules: installRootRules([
456
+ 'postcss',
457
+ 'postcss-loader'
458
+ ])
459
+ }),
460
+ sass: defineContract({
461
+ id: 'sass',
462
+ integration: 'SASS',
463
+ installPackages: specs([
464
+ 'postcss-loader',
465
+ 'postcss-scss',
466
+ 'postcss-preset-env',
467
+ 'sass-loader'
468
+ ]),
469
+ verificationRules: installRootRules([
470
+ 'postcss-loader',
471
+ 'postcss-scss',
472
+ 'postcss-preset-env',
473
+ 'sass-loader'
474
+ ])
475
+ })
476
+ };
477
+ function getOptionalDependencyContract(contractId) {
478
+ const contract = OPTIONAL_DEPENDENCY_CONTRACTS[contractId];
479
+ if (!contract) throw new Error(`Unknown optional dependency contract: ${contractId}`);
480
+ return contract;
481
+ }
413
482
  const package_manager_require = createRequire(import.meta.url);
414
483
  function normalizePackageManager(value) {
415
484
  if (!value) return;
@@ -749,6 +818,600 @@ function execInstallCommand(command, args, options) {
749
818
  child.on('error', (error)=>reject(error));
750
819
  });
751
820
  }
821
+ function debugSwallowed(step, error) {
822
+ if (!isVerboseMode()) return;
823
+ console.log(`${messaging_prefix('debug')} optional-deps ${step}: ${String(error?.message || error)}`);
824
+ }
825
+ function isVerboseMode() {
826
+ return '1' === String(process.env.EXTENSION_VERBOSE || '').trim();
827
+ }
828
+ function installVerbForPackageManager(name) {
829
+ if ('npm' === name) return 'install -D';
830
+ if ('deno' === name) return 'add --dev';
831
+ return 'add -D';
832
+ }
833
+ function formatInstallHint(projectPath, packageSpecs) {
834
+ const { name } = resolvePackageManager({
835
+ cwd: projectPath
836
+ });
837
+ const verb = installVerbForPackageManager(name);
838
+ return `${name} ${verb} ${packageSpecs.join(' ')}`;
839
+ }
840
+ function formatResolverError(args) {
841
+ const hint = formatInstallHint(args.projectPath, args.installSpecs);
842
+ const readableLine = `[${args.integration}] ${args.headline} Install it with: ${hint}`;
843
+ if (!isVerboseMode()) return readableLine;
844
+ return `${readableLine}\n${JSON.stringify(args.diagnostics, null, 2)}`;
845
+ }
846
+ function toInstallRootContract(integration, contractId, installDependencies, verifyPackageIds) {
847
+ return {
848
+ id: contractId,
849
+ integration,
850
+ installPackages: installDependencies,
851
+ verificationRules: verifyPackageIds.map((packageId)=>({
852
+ type: 'install-root',
853
+ packageId
854
+ }))
855
+ };
856
+ }
857
+ function getVerificationContract(input) {
858
+ if (input.contract) return input.contract;
859
+ const installDependencies = input.installDependencies || [
860
+ input.dependencyId
861
+ ];
862
+ const verifyPackageIds = input.verifyPackageIds || installDependencies;
863
+ return toInstallRootContract(input.integration, input.integration, installDependencies, verifyPackageIds);
864
+ }
865
+ function getResolutionBases(projectPath) {
866
+ const extensionRoot = resolveDevelopInstallRoot();
867
+ const bases = [
868
+ projectPath,
869
+ extensionRoot || void 0,
870
+ process.cwd()
871
+ ].filter(Boolean);
872
+ if (extensionRoot?.includes('.pnpm')) bases.push(__rspack_external_node_path_806ed179.join(extensionRoot, '..', '..'));
873
+ return Array.from(new Set(bases));
874
+ }
875
+ function optional_deps_resolver_packageJsonPath(basePath) {
876
+ return __rspack_external_node_path_806ed179.join(basePath, 'package.json');
877
+ }
878
+ function tryResolveWithBase(dependencyId, basePath) {
879
+ try {
880
+ const req = createRequire(optional_deps_resolver_packageJsonPath(basePath));
881
+ return req.resolve(dependencyId);
882
+ } catch (error) {
883
+ debugSwallowed(`resolve ${dependencyId} from ${basePath}`, error);
884
+ return;
885
+ }
886
+ }
887
+ function resolveDependency(dependencyId, projectPath) {
888
+ const bases = getResolutionBases(projectPath);
889
+ for (const basePath of bases){
890
+ const resolvedPath = tryResolveWithBase(dependencyId, basePath);
891
+ if (resolvedPath) return {
892
+ resolvedPath,
893
+ basePath
894
+ };
895
+ }
896
+ try {
897
+ const resolvedPath = require.resolve(dependencyId, {
898
+ paths: bases
899
+ });
900
+ return {
901
+ resolvedPath,
902
+ basePath: projectPath
903
+ };
904
+ } catch (error) {
905
+ debugSwallowed(`resolve ${dependencyId} from the project bases`, error);
906
+ return;
907
+ }
908
+ }
909
+ function resolveFromKnownLocations(dependencyId, projectPath) {
910
+ const direct = resolveDependency(dependencyId, projectPath)?.resolvedPath;
911
+ if (direct) return direct;
912
+ if (declaresDependency(projectPath, dependencyId)) return projectPath;
913
+ }
914
+ function declaresDependency(projectPath, dependencyId) {
915
+ try {
916
+ return hasProjectDependency(projectPath, dependencyId);
917
+ } catch (error) {
918
+ debugSwallowed(`read the project manifest for ${dependencyId}`, error);
919
+ return false;
920
+ }
921
+ }
922
+ function dedupeFailures(packageIds) {
923
+ return Array.from(new Set(packageIds));
924
+ }
925
+ function resolveRealPathSafe(targetPath) {
926
+ try {
927
+ return __rspack_external_node_fs_1b05aee1.realpathSync(targetPath);
928
+ } catch (error) {
929
+ debugSwallowed(`realpath ${targetPath}`, error);
930
+ return __rspack_external_node_path_806ed179.resolve(targetPath);
931
+ }
932
+ }
933
+ function findOwningPackageDir(resolvedPath) {
934
+ let currentPath = __rspack_external_node_path_806ed179.dirname(resolvedPath);
935
+ for(let depth = 0; depth < 8; depth++){
936
+ const packageJson = __rspack_external_node_path_806ed179.join(currentPath, 'package.json');
937
+ if (__rspack_external_node_fs_1b05aee1.existsSync(packageJson)) return currentPath;
938
+ const parent = __rspack_external_node_path_806ed179.dirname(currentPath);
939
+ if (parent === currentPath) break;
940
+ currentPath = parent;
941
+ }
942
+ }
943
+ function isSameInstalledPackage(resolvedPath, expectedInstalledPath) {
944
+ const resolvedPackageDir = findOwningPackageDir(resolvedPath);
945
+ const expectedPackageDir = findOwningPackageDir(expectedInstalledPath);
946
+ if (resolvedPackageDir && expectedPackageDir) return resolveRealPathSafe(resolvedPackageDir) === resolveRealPathSafe(expectedPackageDir);
947
+ return resolveRealPathSafe(resolvedPath) === resolveRealPathSafe(expectedInstalledPath);
948
+ }
949
+ function evaluateModuleContextRule(rule, fromPackagePath, options) {
950
+ try {
951
+ const req = createRequire(fromPackagePath);
952
+ const resolvedPeer = req.resolve(rule.packageId);
953
+ if (options?.expectedInstalledPath && !isSameInstalledPackage(resolvedPeer, options.expectedInstalledPath)) return rule.packageId;
954
+ if ('module-context-load' === rule.type) req(rule.packageId);
955
+ return;
956
+ } catch (error) {
957
+ debugSwallowed(`verify ${rule.packageId}`, error);
958
+ return rule.packageId;
959
+ }
960
+ }
961
+ function getContractVerificationFailuresFromKnownLocations(contract, projectPath) {
962
+ const resolvedByPackage = new Map();
963
+ const resolvePackage = (packageId)=>{
964
+ if (!resolvedByPackage.has(packageId)) resolvedByPackage.set(packageId, resolveFromKnownLocations(packageId, projectPath));
965
+ return resolvedByPackage.get(packageId);
966
+ };
967
+ const failures = [];
968
+ for (const rule of contract.verificationRules){
969
+ if ('install-root' === rule.type) {
970
+ if (!resolvePackage(rule.packageId)) failures.push(rule.packageId);
971
+ continue;
972
+ }
973
+ const fromPackagePath = resolvePackage(rule.fromPackage);
974
+ if (!fromPackagePath) {
975
+ failures.push(rule.fromPackage);
976
+ continue;
977
+ }
978
+ const failure = evaluateModuleContextRule(rule, fromPackagePath);
979
+ if (!(failure && declaresDependency(projectPath, failure))) {
980
+ if (failure) failures.push(failure);
981
+ }
982
+ }
983
+ return dedupeFailures(failures);
984
+ }
985
+ function buildDiagnostics(input) {
986
+ const bases = getResolutionBases(input.projectPath);
987
+ return {
988
+ contractId: input.contract?.id || null,
989
+ integration: input.integration,
990
+ dependencyId: input.dependencyId,
991
+ projectPath: input.projectPath,
992
+ installDependencies: input.installDependencies,
993
+ verifyPackageIds: input.verifyPackageIds,
994
+ resolutionBases: bases
995
+ };
996
+ }
997
+ async function ensureOptionalPackageResolved(input) {
998
+ const contract = getVerificationContract(input);
999
+ const missing = getContractVerificationFailuresFromKnownLocations(contract, input.projectPath);
1000
+ const resolved = resolveFromKnownLocations(input.dependencyId, input.projectPath);
1001
+ if (resolved && 0 === missing.length) return resolved;
1002
+ const diagnostics = buildDiagnostics({
1003
+ integration: input.integration,
1004
+ dependencyId: input.dependencyId,
1005
+ projectPath: input.projectPath,
1006
+ contract,
1007
+ installDependencies: contract.installPackages,
1008
+ verifyPackageIds: contract.installPackages
1009
+ });
1010
+ const headline = `${input.dependencyId} could not be resolved.` + (missing.length > 0 ? ` Missing or invalid packages: ${missing.join(', ')}.` : '');
1011
+ throw new Error(formatResolverError({
1012
+ integration: input.integration,
1013
+ dependencyId: input.dependencyId,
1014
+ headline,
1015
+ installSpecs: missing.length > 0 ? missing : contract.installPackages,
1016
+ projectPath: input.projectPath,
1017
+ diagnostics: {
1018
+ ...diagnostics,
1019
+ missing
1020
+ }
1021
+ }));
1022
+ }
1023
+ function resolveOptionalPackageWithoutInstall(input) {
1024
+ const contract = getVerificationContract(input);
1025
+ const resolved = resolveFromKnownLocations(input.dependencyId, input.projectPath);
1026
+ const missingPeerDeps = getContractVerificationFailuresFromKnownLocations(contract, input.projectPath);
1027
+ if (resolved && 0 === missingPeerDeps.length) return resolved;
1028
+ const diagnostics = buildDiagnostics({
1029
+ integration: input.integration,
1030
+ dependencyId: input.dependencyId,
1031
+ projectPath: input.projectPath,
1032
+ contract,
1033
+ installDependencies: contract.installPackages,
1034
+ verifyPackageIds: contract.installPackages
1035
+ });
1036
+ throw new Error(formatResolverError({
1037
+ integration: input.integration,
1038
+ dependencyId: input.dependencyId,
1039
+ headline: `${input.dependencyId} could not be resolved from the project or extension-develop.`,
1040
+ installSpecs: missingPeerDeps.length > 0 ? missingPeerDeps : contract.installPackages,
1041
+ projectPath: input.projectPath,
1042
+ diagnostics: {
1043
+ ...diagnostics,
1044
+ missingPeerDeps,
1045
+ expectation: 'Run optional dependency preflight or reinstall extension-develop.'
1046
+ }
1047
+ }));
1048
+ }
1049
+ async function ensureOptionalModuleLoaded(input) {
1050
+ const resolvedPath = await ensureOptionalPackageResolved(input);
1051
+ const candidateBases = getResolutionBases(input.projectPath);
1052
+ let loaded;
1053
+ let didLoad = false;
1054
+ let lastLoadError;
1055
+ for (const basePath of candidateBases){
1056
+ const req = createRequire(optional_deps_resolver_packageJsonPath(basePath));
1057
+ const candidateModuleIds = [
1058
+ input.dependencyId,
1059
+ resolvedPath
1060
+ ];
1061
+ for (const candidateModuleId of candidateModuleIds)try {
1062
+ loaded = req(candidateModuleId);
1063
+ didLoad = true;
1064
+ break;
1065
+ } catch (error) {
1066
+ lastLoadError = error;
1067
+ }
1068
+ if (didLoad) break;
1069
+ }
1070
+ if (!didLoad) try {
1071
+ loaded = require(resolvedPath);
1072
+ didLoad = true;
1073
+ } catch (directRequireError) {
1074
+ lastLoadError = directRequireError;
1075
+ }
1076
+ if (!didLoad) {
1077
+ const diagnostics = {
1078
+ ...buildDiagnostics({
1079
+ integration: input.integration,
1080
+ dependencyId: input.dependencyId,
1081
+ projectPath: input.projectPath,
1082
+ installDependencies: input.installDependencies || [
1083
+ input.dependencyId
1084
+ ],
1085
+ verifyPackageIds: input.verifyPackageIds || input.installDependencies || [
1086
+ input.dependencyId
1087
+ ]
1088
+ }),
1089
+ resolvedPath,
1090
+ loadError: lastLoadError instanceof Error ? lastLoadError.message : String(lastLoadError)
1091
+ };
1092
+ throw new Error(formatResolverError({
1093
+ integration: input.integration,
1094
+ dependencyId: input.dependencyId,
1095
+ headline: `${input.dependencyId} could not be loaded after it resolved.`,
1096
+ installSpecs: input.installDependencies || [
1097
+ input.dependencyId
1098
+ ],
1099
+ projectPath: input.projectPath,
1100
+ diagnostics
1101
+ }));
1102
+ }
1103
+ return input.moduleAdapter ? input.moduleAdapter(loaded) : loaded;
1104
+ }
1105
+ function loadOptionalModuleWithoutInstall(input) {
1106
+ const resolvedPath = resolveOptionalPackageWithoutInstall(input);
1107
+ const candidateBases = getResolutionBases(input.projectPath);
1108
+ let loaded;
1109
+ let didLoad = false;
1110
+ let lastLoadError;
1111
+ for (const basePath of candidateBases){
1112
+ const req = createRequire(optional_deps_resolver_packageJsonPath(basePath));
1113
+ const candidateModuleIds = [
1114
+ input.dependencyId,
1115
+ resolvedPath
1116
+ ];
1117
+ for (const candidateModuleId of candidateModuleIds)try {
1118
+ loaded = req(candidateModuleId);
1119
+ didLoad = true;
1120
+ break;
1121
+ } catch (error) {
1122
+ lastLoadError = error;
1123
+ }
1124
+ if (didLoad) break;
1125
+ }
1126
+ if (!didLoad) try {
1127
+ loaded = require(resolvedPath);
1128
+ didLoad = true;
1129
+ } catch (directRequireError) {
1130
+ lastLoadError = directRequireError;
1131
+ }
1132
+ if (!didLoad) throw new Error(formatResolverError({
1133
+ integration: input.integration,
1134
+ dependencyId: input.dependencyId,
1135
+ headline: `${input.dependencyId} could not be loaded after resolving.`,
1136
+ installSpecs: input.installDependencies || [
1137
+ input.dependencyId
1138
+ ],
1139
+ projectPath: input.projectPath,
1140
+ diagnostics: {
1141
+ resolvedPath,
1142
+ loadError: lastLoadError instanceof Error ? lastLoadError.message : String(lastLoadError)
1143
+ }
1144
+ }));
1145
+ return input.moduleAdapter ? input.moduleAdapter(loaded) : loaded;
1146
+ }
1147
+ async function ensureOptionalContractPackageResolved(input) {
1148
+ const contract = getOptionalDependencyContract(input.contractId);
1149
+ return ensureOptionalPackageResolved({
1150
+ integration: contract.integration,
1151
+ projectPath: input.projectPath,
1152
+ dependencyId: input.dependencyId,
1153
+ contract
1154
+ });
1155
+ }
1156
+ async function ensureOptionalContractModuleLoaded(input) {
1157
+ const contract = getOptionalDependencyContract(input.contractId);
1158
+ return ensureOptionalModuleLoaded({
1159
+ integration: contract.integration,
1160
+ projectPath: input.projectPath,
1161
+ dependencyId: input.dependencyId,
1162
+ contract,
1163
+ moduleAdapter: input.moduleAdapter
1164
+ });
1165
+ }
1166
+ function resolveOptionalContractPackageWithoutInstall(input) {
1167
+ const contract = getOptionalDependencyContract(input.contractId);
1168
+ return resolveOptionalPackageWithoutInstall({
1169
+ integration: contract.integration,
1170
+ projectPath: input.projectPath,
1171
+ dependencyId: input.dependencyId,
1172
+ contract
1173
+ });
1174
+ }
1175
+ function loadOptionalContractModuleWithoutInstall(input) {
1176
+ const contract = getOptionalDependencyContract(input.contractId);
1177
+ return loadOptionalModuleWithoutInstall({
1178
+ integration: contract.integration,
1179
+ projectPath: input.projectPath,
1180
+ dependencyId: input.dependencyId,
1181
+ contract,
1182
+ moduleAdapter: input.moduleAdapter
1183
+ });
1184
+ }
1185
+ const ADDON_LINT_DEFAULT = true;
1186
+ const ADDON_LINT_TIMEOUT_MS = 10000;
1187
+ const ADDON_LINT_MAX_PRINTED = 20;
1188
+ const ADDON_LINT_PACKAGE = 'addons-linter';
1189
+ const DUPLICATED_BY_BUILD_WARNINGS = new Set([
1190
+ 'MISSING_DATA_COLLECTION_PERMISSIONS'
1191
+ ]);
1192
+ const hintedProjects = new Set();
1193
+ function toModule(loaded) {
1194
+ const candidate = loaded?.createInstance ? loaded : loaded?.default;
1195
+ if ('function' != typeof candidate?.createInstance) throw new Error(`${ADDON_LINT_PACKAGE} exports no createInstance`);
1196
+ return candidate;
1197
+ }
1198
+ const defaultLoadLinter = (projectPath)=>ensureOptionalModuleLoaded({
1199
+ integration: 'AMO',
1200
+ projectPath,
1201
+ dependencyId: ADDON_LINT_PACKAGE,
1202
+ moduleAdapter: toModule
1203
+ });
1204
+ function shouldRunAddonLint(input) {
1205
+ if ((input.enabled ?? ADDON_LINT_DEFAULT) === false) return {
1206
+ status: 'skipped',
1207
+ reason: 'disabled'
1208
+ };
1209
+ if ('production' !== input.mode) return {
1210
+ status: 'skipped',
1211
+ reason: 'mode'
1212
+ };
1213
+ if (!isGeckoBasedBrowser(String(input.browser))) return {
1214
+ status: 'skipped',
1215
+ reason: 'browser'
1216
+ };
1217
+ return null;
1218
+ }
1219
+ function locationOf(finding) {
1220
+ const file = String(finding.file || '').trim();
1221
+ if (!file) return '';
1222
+ const line = 'number' == typeof finding.line ? `:${finding.line}` : '';
1223
+ return `${file}${line}`;
1224
+ }
1225
+ function toLine(level, finding) {
1226
+ return {
1227
+ level,
1228
+ code: String(finding.code || 'UNKNOWN').trim(),
1229
+ message: String(finding.message || finding.description || '').replace(/\s+/g, ' ').trim(),
1230
+ location: locationOf(finding)
1231
+ };
1232
+ }
1233
+ function collectAddonLintLines(output) {
1234
+ const errors = Array.isArray(output?.errors) ? output.errors : [];
1235
+ const warnings = Array.isArray(output?.warnings) ? output.warnings : [];
1236
+ return [
1237
+ ...errors.map((finding)=>toLine('error', finding)),
1238
+ ...warnings.map((finding)=>toLine('warning', finding))
1239
+ ].filter((line)=>!DUPLICATED_BY_BUILD_WARNINGS.has(line.code));
1240
+ }
1241
+ function formatAddonLintFindings(output, distDisplay, maxPrinted = ADDON_LINT_MAX_PRINTED) {
1242
+ const all = collectAddonLintLines(output);
1243
+ if (0 === all.length) return {
1244
+ findings: 0,
1245
+ lines: []
1246
+ };
1247
+ const errorCount = all.filter((line)=>'error' === line.level).length;
1248
+ const warningCount = all.length - errorCount;
1249
+ const shown = all.slice(0, Math.max(0, maxPrinted));
1250
+ const lines = [
1251
+ addonLintSummary(errorCount, warningCount, distDisplay),
1252
+ ...shown.map((line)=>addonLintFinding(line.level, line.code, line.message, line.location))
1253
+ ];
1254
+ if (all.length > shown.length) lines.push(addonLintMore(all.length - shown.length, distDisplay));
1255
+ return {
1256
+ findings: all.length,
1257
+ lines
1258
+ };
1259
+ }
1260
+ function withTimeout(promise, ms) {
1261
+ return new Promise((resolve, reject)=>{
1262
+ const timer = setTimeout(()=>{
1263
+ reject(new Error(`timed out after ${Math.round(ms / 1000)} s`));
1264
+ }, ms);
1265
+ timer.unref?.();
1266
+ promise.then((value)=>{
1267
+ clearTimeout(timer);
1268
+ resolve(value);
1269
+ }, (error)=>{
1270
+ clearTimeout(timer);
1271
+ reject(error);
1272
+ });
1273
+ });
1274
+ }
1275
+ function silentConsole() {
1276
+ return {
1277
+ log () {},
1278
+ error () {},
1279
+ warn () {},
1280
+ info () {}
1281
+ };
1282
+ }
1283
+ async function runAddonLint(input) {
1284
+ const skipped = shouldRunAddonLint(input);
1285
+ if (skipped) return skipped;
1286
+ let linter;
1287
+ try {
1288
+ linter = await (input.loadLinter || defaultLoadLinter)(input.projectPath);
1289
+ } catch {
1290
+ if (hintedProjects.has(input.projectPath)) return {
1291
+ status: 'missing',
1292
+ hint: null
1293
+ };
1294
+ hintedProjects.add(input.projectPath);
1295
+ return {
1296
+ status: 'missing',
1297
+ hint: addonLintNotInstalled(formatInstallHint(input.projectPath, [
1298
+ ADDON_LINT_PACKAGE
1299
+ ]))
1300
+ };
1301
+ }
1302
+ try {
1303
+ const instance = linter.createInstance({
1304
+ config: {
1305
+ _: [
1306
+ input.distPath
1307
+ ],
1308
+ logLevel: 'fatal',
1309
+ stack: false,
1310
+ pretty: false,
1311
+ boring: true,
1312
+ warningsAsErrors: false,
1313
+ metadata: false,
1314
+ output: 'none',
1315
+ selfHosted: false,
1316
+ shouldScanFile: (fileName)=>!/\.map$/i.test(fileName)
1317
+ },
1318
+ runAsBinary: false
1319
+ });
1320
+ const output = await withTimeout(instance.run({
1321
+ _console: silentConsole()
1322
+ }), input.timeoutMs ?? ADDON_LINT_TIMEOUT_MS);
1323
+ return {
1324
+ status: 'linted',
1325
+ ...formatAddonLintFindings(output, input.distDisplay)
1326
+ };
1327
+ } catch (error) {
1328
+ return {
1329
+ status: 'failed',
1330
+ debugLine: addonLintFailed(String(error?.message || error))
1331
+ };
1332
+ }
1333
+ }
1334
+ const DIST_STAGING_PREFIX = '.extension-build-';
1335
+ function stagingDistPathFor(distPath) {
1336
+ const unique = `${process.pid.toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
1337
+ return __rspack_external_node_path_806ed179.join(__rspack_external_node_path_806ed179.dirname(distPath), `${DIST_STAGING_PREFIX}${__rspack_external_node_path_806ed179.basename(distPath)}-${unique}`);
1338
+ }
1339
+ function removeStaleStagingDirs(distPath) {
1340
+ const parent = __rspack_external_node_path_806ed179.dirname(distPath);
1341
+ const prefix = `${DIST_STAGING_PREFIX}${__rspack_external_node_path_806ed179.basename(distPath)}-`;
1342
+ let entries;
1343
+ try {
1344
+ entries = __rspack_external_node_fs_1b05aee1.readdirSync(parent, {
1345
+ withFileTypes: true
1346
+ });
1347
+ } catch {
1348
+ return;
1349
+ }
1350
+ for (const entry of entries)try {
1351
+ if (!entry.isDirectory() || !entry.name.startsWith(prefix)) continue;
1352
+ __rspack_external_node_fs_1b05aee1.rmSync(__rspack_external_node_path_806ed179.join(parent, entry.name), {
1353
+ recursive: true,
1354
+ force: true
1355
+ });
1356
+ } catch {}
1357
+ }
1358
+ function removeStagingDir(stagingPath) {
1359
+ try {
1360
+ __rspack_external_node_fs_1b05aee1.rmSync(stagingPath, {
1361
+ recursive: true,
1362
+ force: true
1363
+ });
1364
+ } catch {}
1365
+ }
1366
+ function promoteStagingDist(stagingPath, distPath) {
1367
+ const parent = __rspack_external_node_path_806ed179.dirname(distPath);
1368
+ __rspack_external_node_fs_1b05aee1.mkdirSync(parent, {
1369
+ recursive: true
1370
+ });
1371
+ const retiredPath = `${stagingPath}-retired`;
1372
+ let retired = false;
1373
+ if (__rspack_external_node_fs_1b05aee1.existsSync(distPath)) {
1374
+ __rspack_external_node_fs_1b05aee1.renameSync(distPath, retiredPath);
1375
+ retired = true;
1376
+ }
1377
+ try {
1378
+ __rspack_external_node_fs_1b05aee1.renameSync(stagingPath, distPath);
1379
+ } catch (error) {
1380
+ if (retired) try {
1381
+ __rspack_external_node_fs_1b05aee1.renameSync(retiredPath, distPath);
1382
+ } catch {}
1383
+ throw error;
1384
+ }
1385
+ if (retired) try {
1386
+ __rspack_external_node_fs_1b05aee1.rmSync(retiredPath, {
1387
+ recursive: true,
1388
+ force: true
1389
+ });
1390
+ } catch {}
1391
+ }
1392
+ const MAX_SUMMARY_WARNINGS = 20;
1393
+ const build_summary_ANSI_PATTERN = /\u001b\[[0-9;]*m/g;
1394
+ function getBuildSummary(browser, info, outputPath) {
1395
+ const assets = info?.assets || [];
1396
+ const warnings = (info?.warnings || []).slice(0, MAX_SUMMARY_WARNINGS).map((warning)=>{
1397
+ const message = warning && 'object' == typeof warning ? String(warning.message ?? '') : String(warning ?? '');
1398
+ return message.replace(build_summary_ANSI_PATTERN, '').trim();
1399
+ }).filter(Boolean);
1400
+ return {
1401
+ browser,
1402
+ ...outputPath ? {
1403
+ output_path: outputPath
1404
+ } : {},
1405
+ total_assets: assets.length,
1406
+ total_bytes: assets.reduce((n, a)=>n + (a.size || 0), 0),
1407
+ largest_asset_bytes: assets.reduce((m, a)=>Math.max(m, a.size || 0), 0),
1408
+ warnings_count: (info?.warnings || []).length,
1409
+ errors_count: (info?.errors || []).length,
1410
+ ...warnings.length ? {
1411
+ warnings
1412
+ } : {}
1413
+ };
1414
+ }
752
1415
  async function ensureUserProjectDependencies(packageJsonDir) {
753
1416
  if (!needsInstall(packageJsonDir)) return;
754
1417
  const pm = resolvePackageManager({
@@ -1345,6 +2008,31 @@ async function extensionBuild(pathOrRemoteUrl, buildOptions) {
1345
2008
  errors: true
1346
2009
  });
1347
2010
  summary = getBuildSummary(browser, info, displayDistPath);
2011
+ const distDisplay = relativeToCwd(displayDistPath) || collapseHomeDir(displayDistPath);
2012
+ const lintLines = [];
2013
+ try {
2014
+ const lint = await runAddonLint({
2015
+ projectPath: packageJsonDir,
2016
+ distPath: displayDistPath,
2017
+ distDisplay,
2018
+ browser,
2019
+ mode: resolvedMode,
2020
+ enabled: mergedBuildOptions.addonLint
2021
+ });
2022
+ if ('missing' === lint.status && lint.hint) lintLines.push(lint.hint);
2023
+ else if ('failed' === lint.status && isDebug()) lintLines.push(lint.debugLine);
2024
+ else if ('linted' === lint.status && lint.findings > 0) {
2025
+ lintLines.push(...lint.lines);
2026
+ summary = {
2027
+ ...summary,
2028
+ warnings_count: summary.warnings_count + lint.findings,
2029
+ warnings: [
2030
+ ...summary.warnings || [],
2031
+ ...lint.lines.map((line)=>stripAnsi(line))
2032
+ ]
2033
+ };
2034
+ }
2035
+ } catch {}
1348
2036
  try {
1349
2037
  const summaryFile = buildSummaryPath(packageJsonDir, browser);
1350
2038
  __rspack_external_node_fs_1b05aee1.mkdirSync(__rspack_external_node_path_806ed179.dirname(summaryFile), {
@@ -1354,11 +2042,11 @@ async function extensionBuild(pathOrRemoteUrl, buildOptions) {
1354
2042
  ensureSessionStateInProjectGitignore(packageJsonDir);
1355
2043
  __rspack_external_node_fs_1b05aee1.writeFileSync(summaryFile, JSON.stringify(summary));
1356
2044
  } catch {}
1357
- if (summary.warnings_count > 0) {
2045
+ if ((info?.warnings || []).length > 0) {
1358
2046
  const warningDetails = buildWarningsDetails((info?.warnings || []).filter((warning)=>!isEmitTimeWarning(warning)));
1359
2047
  if (warningDetails) humanLine(warningDetails);
1360
2048
  }
1361
- const distDisplay = relativeToCwd(displayDistPath) || collapseHomeDir(displayDistPath);
2049
+ for (const line of lintLines)humanLine(line);
1362
2050
  humanLine(buildComplete(browser, distDisplay, summary.total_bytes));
1363
2051
  for (const artifact of getZipArtifacts(stats.compilation)){
1364
2052
  const artifactPath = useStagingSwap && artifact.path.startsWith(stagingDistPath) ? distPath + artifact.path.slice(stagingDistPath.length) : artifact.path;
@@ -2045,4 +2733,4 @@ async function extensionDev(pathOrRemoteUrl, devOptions) {
2045
2733
  process.exit(1);
2046
2734
  }
2047
2735
  }
2048
- export { BuildEmitter, applySplitChunksGuard, attachLifecycleStream, buildSourceFeatureIndex, classifyEntrySurface, classifyReloadFromSources, createChangedSourcesTracker, createLifecycleStream, defaultSplitChunks, dispatchReload, ensureTypeScriptConfig, extensionBuild, extensionDev, getUserTypeScriptConfigFile, hasDependency, humanLine, isUsingCustomLoader, isUsingIntegration, isUsingTypeScript, jsFrameworksConfigsDetected, jsFrameworksHmrSummary, jsFrameworksIntegrationsEnabled, readContentScriptCount, recordZipArtifact, resolveDevelopDistFile, resolveDevelopInstallRoot, resolvePackageManager };
2736
+ export { BuildEmitter, applySplitChunksGuard, attachLifecycleStream, buildSourceFeatureIndex, classifyEntrySurface, classifyReloadFromSources, createChangedSourcesTracker, createLifecycleStream, defaultSplitChunks, dispatchReload, ensureOptionalContractModuleLoaded, ensureOptionalContractPackageResolved, ensureTypeScriptConfig, extensionBuild, extensionDev, getUserTypeScriptConfigFile, hasDependency, humanLine, isUsingCustomLoader, isUsingIntegration, isUsingTypeScript, jsFrameworksConfigsDetected, jsFrameworksHmrSummary, jsFrameworksIntegrationsEnabled, loadOptionalContractModuleWithoutInstall, readContentScriptCount, recordZipArtifact, resolveDevelopDistFile, resolveDevelopInstallRoot, resolveOptionalContractPackageWithoutInstall };