extension-develop 3.18.3 → 3.18.4-canary.321.403955d
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/0~dev-server.mjs +6 -2
- package/dist/0~rslib-runtime.mjs +1 -17
- package/dist/0~rspack-config.mjs +261 -47
- package/dist/946.mjs +544 -534
- package/dist/962.mjs +4 -2
- package/dist/extension-js-devtools/chrome/content_scripts/content-0.js +2 -2
- package/dist/extension-js-devtools/chrome/devtools/index.js +1 -1
- package/dist/extension-js-devtools/chrome/manifest.json +3 -3
- package/dist/extension-js-devtools/chromium/content_scripts/content-0.js +2 -2
- package/dist/extension-js-devtools/chromium/devtools/index.js +1 -1
- package/dist/extension-js-devtools/chromium/manifest.json +3 -3
- package/dist/extension-js-devtools/edge/content_scripts/content-0.js +2 -2
- package/dist/extension-js-devtools/edge/devtools/index.js +1 -1
- package/dist/extension-js-devtools/edge/manifest.json +3 -3
- package/dist/extension-js-devtools/extension-js/chrome/events.ndjson +2 -2
- package/dist/extension-js-devtools/extension-js/chrome/ready.json +5 -5
- package/dist/extension-js-devtools/extension-js/chromium/events.ndjson +2 -2
- package/dist/extension-js-devtools/extension-js/chromium/ready.json +5 -5
- package/dist/extension-js-devtools/extension-js/edge/events.ndjson +2 -2
- package/dist/extension-js-devtools/extension-js/edge/ready.json +5 -5
- package/dist/extension-js-devtools/extension-js/firefox/events.ndjson +2 -2
- package/dist/extension-js-devtools/extension-js/firefox/ready.json +5 -5
- package/dist/extension-js-devtools/firefox/content_scripts/content-0.js +2 -2
- package/dist/extension-js-devtools/firefox/devtools/index.js +1 -1
- package/dist/extension-js-theme/extension-js/chrome/events.ndjson +2 -2
- package/dist/extension-js-theme/extension-js/chrome/ready.json +5 -5
- package/dist/extension-js-theme/extension-js/chromium/events.ndjson +2 -2
- package/dist/extension-js-theme/extension-js/chromium/ready.json +5 -5
- package/dist/extension-js-theme/extension-js/edge/events.ndjson +2 -2
- package/dist/extension-js-theme/extension-js/edge/ready.json +5 -5
- package/dist/extension-js-theme/extension-js/firefox/events.ndjson +4 -4
- package/dist/extension-js-theme/extension-js/firefox/ready.json +5 -5
- package/dist/feature-scripts-content-script-wrapper.js +7 -37
- package/dist/feature-scripts-content-script-wrapper.mjs +7 -37
- package/package.json +2 -7
- package/dist/resolve-paths-loader.js +0 -1300
- package/dist/resolve-paths-loader.mjs +0 -1300
package/dist/946.mjs
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { createRequire as __extjsCreateRequire } from "node:module"; const require = __extjsCreateRequire(import.meta.url);
|
|
2
|
-
import pintor from "pintor";
|
|
3
2
|
import { pathToFileURL } from "url";
|
|
4
3
|
import { createRequire } from "module";
|
|
5
4
|
import dotenv from "dotenv";
|
|
5
|
+
import pintor from "pintor";
|
|
6
6
|
import { fetchExtensionFromStore } from "extension-from-store";
|
|
7
7
|
import path_0 from "path";
|
|
8
8
|
import { getSpecialFoldersData } from "browser-extension-manifest-fields";
|
|
9
9
|
import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
|
|
10
10
|
import { dirname as __rspack_dirname } from "node:path";
|
|
11
|
-
import * as __rspack_external_path from "path";
|
|
12
11
|
import * as __rspack_external_fs from "fs";
|
|
12
|
+
import * as __rspack_external_path from "path";
|
|
13
13
|
import * as __rspack_external_os from "os";
|
|
14
14
|
import * as __rspack_external_vm from "vm";
|
|
15
|
-
var package_namespaceObject = JSON.parse('{"rE":"3.18.
|
|
15
|
+
var package_namespaceObject = JSON.parse('{"rE":"3.18.4-canary.321.403955d","El":{"@prefresh/core":"1.5.9","@prefresh/utils":"1.2.1","@rspack/core":"^2.0.1","@rspack/dev-server":"2.0.1","@rspack/plugin-preact-refresh":"2.0.1","@rspack/plugin-react-refresh":"1.6.2","@vue/compiler-sfc":"3.5.26","adm-zip":"^0.5.16","browser-extension-manifest-fields":"^2.2.3","case-sensitive-paths-webpack-plugin":"^2.4.0","content-security-policy-parser":"^0.6.0","dotenv":"^17.2.3","es-module-lexer":"^1.7.0","extension-from-store":"^0.1.1","go-git-it":"^5.1.5","ignore":"^7.0.5","less":"4.5.1","less-loader":"12.3.2","parse5-utilities":"^1.0.0","pintor":"0.3.0","postcss":"8.5.10","postcss-loader":"8.2.1","postcss-preset-env":"11.1.1","postcss-scss":"4.0.9","preact":"10.27.3","react-refresh":"0.18.0","sass-loader":"16.0.7","schema-utils":"^4.3.3","svelte-loader":"3.2.4","tiny-glob":"^0.2.9","typescript":"5.9.3","vue":"3.5.26","vue-loader":"17.4.2","webextension-polyfill":"^0.12.0","webpack-merge":"^6.0.1","webpack-target-webextension":"^2.1.3","ws":"^8.20.1"}}');
|
|
16
16
|
const fmt = {
|
|
17
17
|
heading: (title)=>pintor.underline(pintor.blue(title)),
|
|
18
18
|
label: (key)=>pintor.gray(key.toUpperCase()),
|
|
@@ -88,11 +88,20 @@ function buildWebpack(projectDir, stats, browser) {
|
|
|
88
88
|
const statsJson = stats?.toJson({
|
|
89
89
|
all: false,
|
|
90
90
|
assets: true,
|
|
91
|
-
|
|
91
|
+
timings: true
|
|
92
92
|
});
|
|
93
93
|
const outputPath = 'string' == typeof stats?.compilation?.outputOptions?.path ? stats.compilation.outputOptions.path : '';
|
|
94
|
-
const
|
|
95
|
-
const
|
|
94
|
+
const distManifestPath = outputPath ? __rspack_external_path.join(outputPath, 'manifest.json') : '';
|
|
95
|
+
const manifestPath = distManifestPath && __rspack_external_fs.existsSync(distManifestPath) ? distManifestPath : __rspack_external_path.join(projectDir, 'manifest.json');
|
|
96
|
+
let manifest = {};
|
|
97
|
+
try {
|
|
98
|
+
manifest = JSON.parse(__rspack_external_fs.readFileSync(manifestPath, 'utf8'));
|
|
99
|
+
} catch {
|
|
100
|
+
manifest = {
|
|
101
|
+
name: __rspack_external_path.basename(projectDir),
|
|
102
|
+
version: ''
|
|
103
|
+
};
|
|
104
|
+
}
|
|
96
105
|
const assets = statsJson?.assets;
|
|
97
106
|
const heading = `${getLoggingPrefix('info')} Building ${pintor.blue(manifest.name)} extension using ${capitalizedBrowserName(browser)} defaults...\n`;
|
|
98
107
|
const buildTime = `\nBuild completed in ${((statsJson?.time || 0) / 1000).toFixed(2)} seconds.\n`;
|
|
@@ -261,7 +270,7 @@ function getFileSize(fileSizeInBytes) {
|
|
|
261
270
|
function getAssetsSize(assets) {
|
|
262
271
|
let totalSize = 0;
|
|
263
272
|
assets?.forEach((asset)=>{
|
|
264
|
-
totalSize += asset
|
|
273
|
+
totalSize += asset?.size || 0;
|
|
265
274
|
});
|
|
266
275
|
return getFileSize(totalSize);
|
|
267
276
|
}
|
|
@@ -279,6 +288,7 @@ function printTree(node, prefix = '') {
|
|
|
279
288
|
function getAssetsTree(assets) {
|
|
280
289
|
const assetTree = {};
|
|
281
290
|
assets?.forEach((asset)=>{
|
|
291
|
+
if ('string' != typeof asset?.name) return;
|
|
282
292
|
const paths = asset.name.split('/');
|
|
283
293
|
let currentLevel = assetTree;
|
|
284
294
|
paths.forEach((part, index)=>{
|
|
@@ -374,117 +384,480 @@ function managedDependencyConflict(duplicates, userPackageJsonPath) {
|
|
|
374
384
|
const list = duplicates.map((d)=>`- ${pintor.yellow(d)}`).join('\n');
|
|
375
385
|
return `${getLoggingPrefix('error')} Your project declares dependencies that are managed by ${pintor.blue('Extension.js')} and referenced in ${pintor.underline('extension.config.js')}\n${pintor.red('This can cause version conflicts and break the development/build process.')}\n\n${pintor.gray('Managed dependencies (remove these from your package.json):')}\n${list}\n\n${pintor.gray('PATH')} ${pintor.underline(userPackageJsonPath)}\nIf you need a different version, open an issue so we can consider bundling it safely.\nOperation aborted.`;
|
|
376
386
|
}
|
|
377
|
-
|
|
378
|
-
const
|
|
379
|
-
|
|
387
|
+
function loadCommonJsConfigWithStableDirname(absolutePath) {
|
|
388
|
+
const code = __rspack_external_fs.readFileSync(absolutePath, 'utf-8');
|
|
389
|
+
const dirname = __rspack_external_path.dirname(absolutePath);
|
|
390
|
+
const requireFn = createRequire(absolutePath);
|
|
391
|
+
const module = {
|
|
392
|
+
exports: {}
|
|
393
|
+
};
|
|
394
|
+
const exports = module.exports;
|
|
395
|
+
const wrapped = `(function (exports, require, module, __filename, __dirname) {\n${code}\n})`;
|
|
396
|
+
const fn = new __rspack_external_vm.Script(wrapped, {
|
|
397
|
+
filename: absolutePath
|
|
398
|
+
}).runInThisContext();
|
|
399
|
+
fn(exports, requireFn, module, absolutePath, dirname);
|
|
400
|
+
return module.exports?.default || module.exports;
|
|
401
|
+
}
|
|
402
|
+
function findNearestWorkspaceRoot(startDir) {
|
|
403
|
+
let current = __rspack_external_path.resolve(startDir);
|
|
380
404
|
while(true){
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
} catch {}
|
|
386
|
-
if (currentDir === root) return;
|
|
387
|
-
currentDir = __rspack_external_path.dirname(currentDir);
|
|
405
|
+
if (__rspack_external_fs.existsSync(__rspack_external_path.join(current, 'pnpm-workspace.yaml'))) return current;
|
|
406
|
+
const parent = __rspack_external_path.dirname(current);
|
|
407
|
+
if (parent === current) return;
|
|
408
|
+
current = parent;
|
|
388
409
|
}
|
|
389
410
|
}
|
|
390
|
-
|
|
411
|
+
function preloadEnvFilesFromDir(envDir, options) {
|
|
412
|
+
let loadedAny = false;
|
|
391
413
|
try {
|
|
392
|
-
const
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
414
|
+
const defaultsPath = __rspack_external_path.join(envDir, '.env.defaults');
|
|
415
|
+
if (__rspack_external_fs.existsSync(defaultsPath)) {
|
|
416
|
+
dotenv.config({
|
|
417
|
+
path: defaultsPath,
|
|
418
|
+
override: Boolean(options?.override),
|
|
419
|
+
quiet: true
|
|
420
|
+
});
|
|
421
|
+
loadedAny = true;
|
|
422
|
+
}
|
|
423
|
+
const envCandidates = [
|
|
424
|
+
'.env.development',
|
|
425
|
+
'.env.local',
|
|
426
|
+
'.env'
|
|
427
|
+
];
|
|
428
|
+
for (const filename of envCandidates){
|
|
429
|
+
const filePath = __rspack_external_path.join(envDir, filename);
|
|
430
|
+
if (__rspack_external_fs.existsSync(filePath)) {
|
|
431
|
+
dotenv.config({
|
|
432
|
+
path: filePath,
|
|
433
|
+
override: Boolean(options?.override),
|
|
434
|
+
quiet: true
|
|
435
|
+
});
|
|
436
|
+
loadedAny = true;
|
|
437
|
+
break;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
} catch {}
|
|
441
|
+
return {
|
|
442
|
+
loadedAny,
|
|
443
|
+
envDir
|
|
444
|
+
};
|
|
401
445
|
}
|
|
402
|
-
function
|
|
446
|
+
function findConfigFile(projectPath) {
|
|
447
|
+
const candidates = [
|
|
448
|
+
__rspack_external_path.join(projectPath, 'extension.config.js'),
|
|
449
|
+
__rspack_external_path.join(projectPath, 'extension.config.mjs'),
|
|
450
|
+
__rspack_external_path.join(projectPath, 'extension.config.cjs')
|
|
451
|
+
];
|
|
452
|
+
return candidates.find((p)=>__rspack_external_fs.existsSync(p));
|
|
453
|
+
}
|
|
454
|
+
function preloadEnvFiles(projectDir) {
|
|
455
|
+
const local = preloadEnvFilesFromDir(projectDir);
|
|
456
|
+
if (local.loadedAny) return local;
|
|
457
|
+
const workspaceRoot = findNearestWorkspaceRoot(projectDir);
|
|
458
|
+
if (workspaceRoot && workspaceRoot !== projectDir) return preloadEnvFilesFromDir(workspaceRoot);
|
|
459
|
+
return local;
|
|
460
|
+
}
|
|
461
|
+
const loadedConfigCache = new Map();
|
|
462
|
+
async function loadConfigFile(configPath) {
|
|
463
|
+
const absolutePath = __rspack_external_path.resolve(configPath);
|
|
464
|
+
const cached = loadedConfigCache.get(absolutePath);
|
|
465
|
+
if (cached) return cached;
|
|
466
|
+
const loading = loadConfigFileUncached(absolutePath);
|
|
467
|
+
loadedConfigCache.set(absolutePath, loading);
|
|
403
468
|
try {
|
|
404
|
-
|
|
405
|
-
const content = __rspack_external_fs.readFileSync(packageJsonPath, 'utf-8');
|
|
406
|
-
JSON.parse(content);
|
|
407
|
-
return true;
|
|
469
|
+
return await loading;
|
|
408
470
|
} catch (error) {
|
|
409
|
-
|
|
410
|
-
|
|
471
|
+
loadedConfigCache.delete(absolutePath);
|
|
472
|
+
throw error;
|
|
411
473
|
}
|
|
412
474
|
}
|
|
413
|
-
|
|
475
|
+
async function loadConfigFileUncached(absolutePath) {
|
|
476
|
+
const projectDir = __rspack_external_path.dirname(absolutePath);
|
|
477
|
+
preloadEnvFiles(projectDir);
|
|
414
478
|
try {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
const
|
|
458
|
-
const
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
479
|
+
if (absolutePath.endsWith('.cjs')) {
|
|
480
|
+
const requireFn = createRequire(import.meta.url);
|
|
481
|
+
const required = requireFn(absolutePath);
|
|
482
|
+
return required?.default || required;
|
|
483
|
+
}
|
|
484
|
+
let esmImportPath = absolutePath;
|
|
485
|
+
let shimTmpDir;
|
|
486
|
+
try {
|
|
487
|
+
const originalContent = __rspack_external_fs.readFileSync(absolutePath, 'utf-8');
|
|
488
|
+
if (originalContent.includes('import.meta.env')) {
|
|
489
|
+
shimTmpDir = __rspack_external_fs.mkdtempSync(__rspack_external_path.join(__rspack_external_os.tmpdir(), 'extension-config-esm-'));
|
|
490
|
+
const tmpPath = __rspack_external_path.join(shimTmpDir, __rspack_external_path.basename(absolutePath));
|
|
491
|
+
const envObjectLiteral = JSON.stringify(Object.fromEntries(Object.entries(process.env).map(([k, v])=>[
|
|
492
|
+
k,
|
|
493
|
+
v
|
|
494
|
+
])), null, 0);
|
|
495
|
+
const shimHeader = `const __IMPORT_META_ENV__ = Object.freeze(${envObjectLiteral});\n`;
|
|
496
|
+
const replaced = originalContent.replace(/import\.meta\.env/g, '__IMPORT_META_ENV__');
|
|
497
|
+
__rspack_external_fs.writeFileSync(tmpPath, `${shimHeader}${replaced}`, 'utf-8');
|
|
498
|
+
esmImportPath = tmpPath;
|
|
499
|
+
}
|
|
500
|
+
} catch {}
|
|
501
|
+
try {
|
|
502
|
+
const module = await import(pathToFileURL(esmImportPath).href);
|
|
503
|
+
return module.default || module;
|
|
504
|
+
} finally{
|
|
505
|
+
if (shimTmpDir) try {
|
|
506
|
+
__rspack_external_fs.rmSync(shimTmpDir, {
|
|
507
|
+
recursive: true,
|
|
508
|
+
force: true
|
|
509
|
+
});
|
|
510
|
+
} catch {}
|
|
511
|
+
}
|
|
512
|
+
} catch (err) {
|
|
513
|
+
const error = err;
|
|
514
|
+
try {
|
|
515
|
+
if (!absolutePath.endsWith('.mjs')) {
|
|
516
|
+
const requireFn = createRequire(import.meta.url);
|
|
517
|
+
let required;
|
|
518
|
+
try {
|
|
519
|
+
required = requireFn(absolutePath);
|
|
520
|
+
} catch (requireErr) {
|
|
521
|
+
const message = String(error?.message || '') + ' ' + String(requireErr?.message || '');
|
|
522
|
+
const looksLikeCommonJsInEsm = message.includes('require is not defined in ES module scope') || message.includes('Cannot use import statement outside a module') || message.includes('ERR_REQUIRE_ESM');
|
|
523
|
+
if (looksLikeCommonJsInEsm) try {
|
|
524
|
+
required = loadCommonJsConfigWithStableDirname(absolutePath);
|
|
525
|
+
} catch {
|
|
526
|
+
const tmpDir = __rspack_external_fs.mkdtempSync(__rspack_external_path.join(__rspack_external_os.tmpdir(), 'extension-config-'));
|
|
527
|
+
try {
|
|
528
|
+
const tmpCjsPath = __rspack_external_path.join(tmpDir, __rspack_external_path.basename(absolutePath, __rspack_external_path.extname(absolutePath)) + '.cjs');
|
|
529
|
+
__rspack_external_fs.copyFileSync(absolutePath, tmpCjsPath);
|
|
530
|
+
required = requireFn(tmpCjsPath);
|
|
531
|
+
} finally{
|
|
532
|
+
try {
|
|
533
|
+
__rspack_external_fs.rmSync(tmpDir, {
|
|
534
|
+
recursive: true,
|
|
535
|
+
force: true
|
|
536
|
+
});
|
|
537
|
+
} catch {}
|
|
538
|
+
}
|
|
464
539
|
}
|
|
540
|
+
else throw requireErr;
|
|
465
541
|
}
|
|
466
|
-
return
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
542
|
+
return required?.default || required;
|
|
543
|
+
}
|
|
544
|
+
} catch {}
|
|
545
|
+
try {
|
|
546
|
+
const content = __rspack_external_fs.readFileSync(absolutePath, 'utf-8');
|
|
547
|
+
return JSON.parse(content);
|
|
548
|
+
} catch (jsonErr) {
|
|
549
|
+
throw new Error(`Failed to load config file: ${absolutePath}\nError: ${error.message || error}`);
|
|
473
550
|
}
|
|
474
|
-
} catch {}
|
|
475
|
-
async function tryGitClone() {
|
|
476
|
-
const { default: goGitIt } = await import("go-git-it");
|
|
477
|
-
await withTimeout(goGitIt(pathOrRemoteUrl, cwd, text), REMOTE_FETCH_TIMEOUT_MS, pathOrRemoteUrl);
|
|
478
551
|
}
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
552
|
+
}
|
|
553
|
+
async function loadCustomConfig(projectPath) {
|
|
554
|
+
const configPath = findConfigFile(projectPath);
|
|
555
|
+
if (configPath) {
|
|
556
|
+
if (await config_loader_isUsingExperimentalConfig(projectPath)) try {
|
|
557
|
+
const userConfig = await loadConfigFile(configPath);
|
|
558
|
+
if (userConfig && 'function' == typeof userConfig.config) return userConfig.config;
|
|
559
|
+
if (userConfig && userConfig.config && 'object' == typeof userConfig.config) {
|
|
560
|
+
const partial = userConfig.config;
|
|
561
|
+
return (config)=>{
|
|
562
|
+
const requireFn = createRequire(import.meta.url);
|
|
563
|
+
const { merge } = requireFn('webpack-merge');
|
|
564
|
+
return merge(config, partial);
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
} catch (err) {
|
|
568
|
+
const error = err;
|
|
569
|
+
console.error(configLoadingError(configPath, error));
|
|
570
|
+
throw err;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
return (config)=>config;
|
|
574
|
+
}
|
|
575
|
+
async function loadCommandConfig(projectPath, command) {
|
|
576
|
+
const configPath = findConfigFile(projectPath);
|
|
577
|
+
if (configPath) {
|
|
578
|
+
if (await config_loader_isUsingExperimentalConfig(projectPath)) try {
|
|
579
|
+
const userConfig = await loadConfigFile(configPath);
|
|
580
|
+
const baseExtensions = userConfig && userConfig.extensions ? {
|
|
581
|
+
extensions: userConfig.extensions
|
|
582
|
+
} : {};
|
|
583
|
+
const baseTranspilePackages = userConfig && Array.isArray(userConfig.transpilePackages) ? {
|
|
584
|
+
transpilePackages: userConfig.transpilePackages
|
|
585
|
+
} : {};
|
|
586
|
+
const basePerfBudgets = userConfig && userConfig.perfBudgets && 'object' == typeof userConfig.perfBudgets ? {
|
|
587
|
+
perfBudgets: userConfig.perfBudgets
|
|
588
|
+
} : {};
|
|
589
|
+
const perCommand = userConfig && userConfig.commands && userConfig.commands[command] ? userConfig.commands[command] : {};
|
|
590
|
+
return {
|
|
591
|
+
...baseExtensions,
|
|
592
|
+
...baseTranspilePackages,
|
|
593
|
+
...basePerfBudgets,
|
|
594
|
+
...perCommand
|
|
595
|
+
};
|
|
596
|
+
} catch (err) {
|
|
597
|
+
const error = err;
|
|
598
|
+
console.error(configLoadingError(configPath, error));
|
|
599
|
+
throw err;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
return {};
|
|
603
|
+
}
|
|
604
|
+
async function loadBrowserConfig(projectPath, browser = 'chrome') {
|
|
605
|
+
const configPath = findConfigFile(projectPath);
|
|
606
|
+
if (configPath) {
|
|
607
|
+
if (await config_loader_isUsingExperimentalConfig(projectPath)) try {
|
|
608
|
+
const userConfig = await loadConfigFile(configPath);
|
|
609
|
+
if (userConfig && userConfig.browser) {
|
|
610
|
+
const browsers = userConfig.browser;
|
|
611
|
+
if ('chromium-based' === browser) {
|
|
612
|
+
if (browsers['chromium-based']) return browsers['chromium-based'];
|
|
613
|
+
if (browsers.chromium) return browsers.chromium;
|
|
614
|
+
} else if ('gecko-based' === browser) {
|
|
615
|
+
if (browsers['gecko-based']) return browsers['gecko-based'];
|
|
616
|
+
if (browsers.firefox) return browsers.firefox;
|
|
617
|
+
} else {
|
|
618
|
+
const direct = browsers[browser];
|
|
619
|
+
if (direct) return direct;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
} catch (err) {
|
|
623
|
+
const error = err;
|
|
624
|
+
console.error(configLoadingError(configPath, error));
|
|
625
|
+
throw err;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
return {
|
|
629
|
+
browser: browser || 'chrome'
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
let userMessageDelivered = false;
|
|
633
|
+
async function config_loader_isUsingExperimentalConfig(projectPath) {
|
|
634
|
+
const configPath = findConfigFile(projectPath);
|
|
635
|
+
if (configPath) {
|
|
636
|
+
if (!userMessageDelivered) {
|
|
637
|
+
if ('true' === process.env.EXTENSION_AUTHOR_MODE) console.log(isUsingExperimentalConfig('extension.config.js'));
|
|
638
|
+
userMessageDelivered = true;
|
|
639
|
+
}
|
|
640
|
+
return true;
|
|
641
|
+
}
|
|
642
|
+
return false;
|
|
643
|
+
}
|
|
644
|
+
function asAbsolute(p) {
|
|
645
|
+
return __rspack_external_path.isAbsolute(p) ? p : __rspack_external_path.resolve(p);
|
|
646
|
+
}
|
|
647
|
+
function getDirs(struct) {
|
|
648
|
+
const manifestDir = asAbsolute(__rspack_external_path.dirname(struct.manifestPath));
|
|
649
|
+
const packageJsonDir = asAbsolute(struct.packageJsonPath ? __rspack_external_path.dirname(struct.packageJsonPath) : manifestDir);
|
|
650
|
+
return {
|
|
651
|
+
manifestDir,
|
|
652
|
+
packageJsonDir
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
function getNodeModulesDir(packageJsonDir) {
|
|
656
|
+
return asAbsolute(__rspack_external_path.join(packageJsonDir, 'node_modules'));
|
|
657
|
+
}
|
|
658
|
+
function needsInstall(packageJsonDir) {
|
|
659
|
+
const nm = getNodeModulesDir(packageJsonDir);
|
|
660
|
+
const packageJsonPath = __rspack_external_path.join(packageJsonDir, 'package.json');
|
|
661
|
+
if (!__rspack_external_fs.existsSync(packageJsonPath)) return false;
|
|
662
|
+
try {
|
|
663
|
+
const raw = __rspack_external_fs.readFileSync(packageJsonPath, 'utf-8');
|
|
664
|
+
const packageJson = JSON.parse(raw);
|
|
665
|
+
const depsCount = Object.keys(packageJson?.dependencies || {}).length;
|
|
666
|
+
const devDepsCount = Object.keys(packageJson?.devDependencies || {}).length;
|
|
667
|
+
if (depsCount + devDepsCount === 0) return false;
|
|
668
|
+
if (!__rspack_external_fs.existsSync(nm)) return true;
|
|
669
|
+
const deps = Object.keys(packageJson?.dependencies || {});
|
|
670
|
+
const devDeps = Object.keys(packageJson?.devDependencies || {});
|
|
671
|
+
if (__rspack_external_fs.existsSync(__rspack_external_path.join(nm, '.pnpm'))) return false;
|
|
672
|
+
if (__rspack_external_fs.existsSync(__rspack_external_path.join(nm, '.modules.yaml'))) return false;
|
|
673
|
+
const hasInstalledDep = [
|
|
674
|
+
...deps,
|
|
675
|
+
...devDeps
|
|
676
|
+
].some((dep)=>__rspack_external_fs.existsSync(__rspack_external_path.join(nm, dep)));
|
|
677
|
+
return !hasInstalledDep;
|
|
678
|
+
} catch {
|
|
679
|
+
return true;
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
function normalizeBrowser(browser, chromiumBinary, geckoBinary, safariBinary) {
|
|
683
|
+
const requested = String(browser || '');
|
|
684
|
+
if (chromiumBinary) {
|
|
685
|
+
if (!requested || 'chromium-based' === requested) return 'chromium-based';
|
|
686
|
+
if ('chromium' === requested) return 'chromium';
|
|
687
|
+
if ('edge' === requested) return 'edge';
|
|
688
|
+
if ('chrome' === requested) return 'chrome';
|
|
689
|
+
}
|
|
690
|
+
if (geckoBinary) {
|
|
691
|
+
if (!requested || 'gecko-based' === requested || 'firefox-based' === requested) return 'gecko-based';
|
|
692
|
+
if ('firefox' === requested) return 'firefox';
|
|
693
|
+
}
|
|
694
|
+
if (safariBinary) {
|
|
695
|
+
if (!requested || 'webkit-based' === requested) return 'webkit-based';
|
|
696
|
+
if ('safari' === requested) return 'safari';
|
|
697
|
+
}
|
|
698
|
+
switch(requested){
|
|
699
|
+
case 'chrome':
|
|
700
|
+
return 'chrome';
|
|
701
|
+
case 'edge':
|
|
702
|
+
return 'edge';
|
|
703
|
+
case 'chromium':
|
|
704
|
+
return 'chromium';
|
|
705
|
+
case 'chromium-based':
|
|
706
|
+
return 'chromium-based';
|
|
707
|
+
case 'firefox':
|
|
708
|
+
return 'firefox';
|
|
709
|
+
case 'gecko-based':
|
|
710
|
+
case 'firefox-based':
|
|
711
|
+
return 'gecko-based';
|
|
712
|
+
case 'safari':
|
|
713
|
+
return 'safari';
|
|
714
|
+
case 'webkit-based':
|
|
715
|
+
return 'webkit-based';
|
|
716
|
+
default:
|
|
717
|
+
return 'chrome';
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
function getDistPath(packageJsonDir, browser) {
|
|
721
|
+
return asAbsolute(__rspack_external_path.join(packageJsonDir, 'dist', browser));
|
|
722
|
+
}
|
|
723
|
+
function computePreviewOutputPath(struct, browser, explicitOutputPath) {
|
|
724
|
+
const { manifestDir, packageJsonDir } = getDirs(struct);
|
|
725
|
+
if (explicitOutputPath) return asAbsolute(explicitOutputPath);
|
|
726
|
+
if (struct.packageJsonPath) {
|
|
727
|
+
const distDir = getDistPath(packageJsonDir, browser);
|
|
728
|
+
try {
|
|
729
|
+
if (__rspack_external_fs.existsSync(__rspack_external_path.join(distDir, 'manifest.json'))) return distDir;
|
|
730
|
+
} catch {}
|
|
731
|
+
}
|
|
732
|
+
return manifestDir;
|
|
733
|
+
}
|
|
734
|
+
function devtoolsEngineFor(browser) {
|
|
735
|
+
switch(browser){
|
|
736
|
+
case 'chrome':
|
|
737
|
+
return 'chrome';
|
|
738
|
+
case 'edge':
|
|
739
|
+
return 'edge';
|
|
740
|
+
case 'chromium':
|
|
741
|
+
case 'chromium-based':
|
|
742
|
+
return 'chromium';
|
|
743
|
+
case 'firefox':
|
|
744
|
+
case 'gecko-based':
|
|
745
|
+
return 'firefox';
|
|
746
|
+
default:
|
|
747
|
+
return 'chrome';
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
async function findUpLocal(filename, options) {
|
|
751
|
+
const root = __rspack_external_path.parse(options.cwd).root;
|
|
752
|
+
let currentDir = options.cwd;
|
|
753
|
+
while(true){
|
|
754
|
+
const candidate = __rspack_external_path.join(currentDir, filename);
|
|
755
|
+
try {
|
|
756
|
+
const stat = await __rspack_external_fs.promises.stat(candidate);
|
|
757
|
+
if (stat.isFile()) return candidate;
|
|
758
|
+
} catch {}
|
|
759
|
+
if (currentDir === root) return;
|
|
760
|
+
currentDir = __rspack_external_path.dirname(currentDir);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
async function findNearestPackageJson(manifestPath) {
|
|
764
|
+
try {
|
|
765
|
+
const manifestDir = __rspack_external_path.dirname(manifestPath);
|
|
766
|
+
const packageJsonPath = await findUpLocal('package.json', {
|
|
767
|
+
cwd: manifestDir
|
|
768
|
+
});
|
|
769
|
+
return packageJsonPath || null;
|
|
770
|
+
} catch (error) {
|
|
771
|
+
console.warn('Failed to find package.json:', error);
|
|
772
|
+
return null;
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
function validatePackageJson(packageJsonPath) {
|
|
776
|
+
try {
|
|
777
|
+
if (!__rspack_external_fs.existsSync(packageJsonPath)) return false;
|
|
778
|
+
const content = __rspack_external_fs.readFileSync(packageJsonPath, 'utf-8');
|
|
779
|
+
JSON.parse(content);
|
|
780
|
+
return true;
|
|
781
|
+
} catch (error) {
|
|
782
|
+
console.warn('Invalid package.json at:', packageJsonPath, error);
|
|
783
|
+
return false;
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
const isUrl = (url)=>{
|
|
787
|
+
try {
|
|
788
|
+
new URL(url);
|
|
789
|
+
return true;
|
|
790
|
+
} catch (e) {
|
|
791
|
+
return false;
|
|
792
|
+
}
|
|
793
|
+
};
|
|
794
|
+
const REMOTE_FETCH_TIMEOUT_MS = (()=>{
|
|
795
|
+
const raw = parseInt(String(process.env.EXTENSION_FETCH_TIMEOUT_MS || ''), 10);
|
|
796
|
+
return Number.isFinite(raw) && raw > 0 ? raw : 60000;
|
|
797
|
+
})();
|
|
798
|
+
function withTimeout(task, ms, label) {
|
|
799
|
+
let timer;
|
|
800
|
+
const timeout = new Promise((_, reject)=>{
|
|
801
|
+
timer = setTimeout(()=>reject(new Error(remoteFetchTimedOut(label, ms))), ms);
|
|
802
|
+
});
|
|
803
|
+
return Promise.race([
|
|
804
|
+
task,
|
|
805
|
+
timeout
|
|
806
|
+
]).finally(()=>{
|
|
807
|
+
if (timer) clearTimeout(timer);
|
|
808
|
+
});
|
|
809
|
+
}
|
|
810
|
+
async function importUrlSourceFromGithub(pathOrRemoteUrl, text) {
|
|
811
|
+
const cwd = process.cwd();
|
|
812
|
+
const url = new URL(pathOrRemoteUrl);
|
|
813
|
+
const segments = url.pathname.split('/').filter(Boolean);
|
|
814
|
+
const repoName = segments.length >= 2 ? segments[1] : segments[segments.length - 1];
|
|
815
|
+
const treeIndex = segments.indexOf('tree');
|
|
816
|
+
const expectedName = -1 !== treeIndex && segments.length > treeIndex + 2 ? segments[segments.length - 1] : repoName;
|
|
817
|
+
const expectedPath = __rspack_external_path.resolve(cwd, expectedName);
|
|
818
|
+
if (__rspack_external_fs.existsSync(expectedPath)) try {
|
|
819
|
+
const entries = __rspack_external_fs.readdirSync(expectedPath);
|
|
820
|
+
if (0 === entries.length) __rspack_external_fs.rmSync(expectedPath, {
|
|
821
|
+
recursive: true,
|
|
822
|
+
force: true
|
|
823
|
+
});
|
|
824
|
+
else {
|
|
825
|
+
const hasManifest = (dir)=>{
|
|
826
|
+
const stack = [
|
|
827
|
+
dir
|
|
828
|
+
];
|
|
829
|
+
while(stack.length){
|
|
830
|
+
const current = stack.pop();
|
|
831
|
+
const items = __rspack_external_fs.readdirSync(current, {
|
|
832
|
+
withFileTypes: true
|
|
833
|
+
});
|
|
834
|
+
for (const it of items){
|
|
835
|
+
if (it.isFile() && 'manifest.json' === it.name) return true;
|
|
836
|
+
if (it.isDirectory() && 'node_modules' !== it.name && 'dist' !== it.name && !it.name.startsWith('.')) stack.push(__rspack_external_path.join(current, it.name));
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
return false;
|
|
840
|
+
};
|
|
841
|
+
if (hasManifest(expectedPath)) return expectedPath;
|
|
842
|
+
__rspack_external_fs.rmSync(expectedPath, {
|
|
843
|
+
recursive: true,
|
|
844
|
+
force: true
|
|
845
|
+
});
|
|
846
|
+
}
|
|
847
|
+
} catch {}
|
|
848
|
+
async function tryGitClone() {
|
|
849
|
+
const { default: goGitIt } = await import("go-git-it");
|
|
850
|
+
await withTimeout(goGitIt(pathOrRemoteUrl, cwd, text), REMOTE_FETCH_TIMEOUT_MS, pathOrRemoteUrl);
|
|
851
|
+
}
|
|
852
|
+
async function tryZipFallback() {
|
|
853
|
+
const branch = -1 !== treeIndex && segments.length > treeIndex + 1 ? segments[treeIndex + 1] : 'main';
|
|
854
|
+
const owner = segments[0];
|
|
855
|
+
const repo = segments[1];
|
|
856
|
+
const subdir = -1 !== treeIndex && segments.length > treeIndex + 2 ? segments.slice(treeIndex + 2).join('/') : '';
|
|
857
|
+
const zipUrl = `https://codeload.github.com/${owner}/${repo}/zip/refs/heads/${branch}`;
|
|
858
|
+
const extractedPath = await importUrlSourceFromZip(zipUrl);
|
|
859
|
+
const extractedDirs = __rspack_external_fs.readdirSync(extractedPath, {
|
|
860
|
+
withFileTypes: true
|
|
488
861
|
}).filter((d)=>d.isDirectory()).map((d)=>d.name);
|
|
489
862
|
const repoRootDir = extractedDirs.find((d)=>d.startsWith(`${repo}-${branch}`));
|
|
490
863
|
const repoRoot = repoRootDir ? __rspack_external_path.join(extractedPath, repoRootDir) : extractedPath;
|
|
@@ -574,341 +947,84 @@ function collectManifestCandidates(rootDir, maxDepth) {
|
|
|
574
947
|
try {
|
|
575
948
|
entries = __rspack_external_fs.readdirSync(dir, {
|
|
576
949
|
withFileTypes: true
|
|
577
|
-
});
|
|
578
|
-
} catch {
|
|
579
|
-
return;
|
|
580
|
-
}
|
|
581
|
-
for (const entry of entries){
|
|
582
|
-
if (entry.isFile() && 'manifest.json' === entry.name) {
|
|
583
|
-
results.push(__rspack_external_path.join(dir, entry.name));
|
|
584
|
-
continue;
|
|
585
|
-
}
|
|
586
|
-
if (entry.isDirectory() && !entry.name.startsWith('.') && !SKIP_DIRS.has(entry.name)) walk(__rspack_external_path.join(dir, entry.name), depth + 1);
|
|
587
|
-
}
|
|
588
|
-
};
|
|
589
|
-
walk(rootDir, 0);
|
|
590
|
-
return results;
|
|
591
|
-
}
|
|
592
|
-
async function getProjectStructure(pathOrRemoteUrl) {
|
|
593
|
-
const projectPath = await getProjectPath(pathOrRemoteUrl);
|
|
594
|
-
const isUnderDir = (baseDir, candidatePath)=>{
|
|
595
|
-
const rel = __rspack_external_path.relative(baseDir, candidatePath);
|
|
596
|
-
return Boolean(rel && !rel.startsWith('..') && !__rspack_external_path.isAbsolute(rel));
|
|
597
|
-
};
|
|
598
|
-
const packageJsonPathFromProject = await findNearestPackageJson(__rspack_external_path.join(projectPath, 'manifest.json'));
|
|
599
|
-
const packageJsonDirFromProject = packageJsonPathFromProject ? __rspack_external_path.dirname(packageJsonPathFromProject) : void 0;
|
|
600
|
-
const rootManifestPath = __rspack_external_path.join(projectPath, 'manifest.json');
|
|
601
|
-
const srcManifestPath = __rspack_external_path.join(projectPath, 'src', 'manifest.json');
|
|
602
|
-
let manifestPath = __rspack_external_fs.existsSync(srcManifestPath) ? srcManifestPath : rootManifestPath;
|
|
603
|
-
if (!__rspack_external_fs.existsSync(manifestPath)) if (packageJsonDirFromProject) {
|
|
604
|
-
const absoluteCandidates = collectManifestCandidates(projectPath, 3);
|
|
605
|
-
const relativeCandidates = absoluteCandidates.map((candidate)=>__rspack_external_path.relative(projectPath, candidate) || candidate);
|
|
606
|
-
if (1 === absoluteCandidates.length) {
|
|
607
|
-
manifestPath = absoluteCandidates[0];
|
|
608
|
-
console.log(resolvedWorkspaceManifest(projectPath, manifestPath));
|
|
609
|
-
} else throw new Error(manifestNotFoundError(manifestPath, relativeCandidates));
|
|
610
|
-
} else {
|
|
611
|
-
const MAX_DEPTH = 5;
|
|
612
|
-
const findManifest = (dir, depth)=>{
|
|
613
|
-
if (depth > MAX_DEPTH) return null;
|
|
614
|
-
let files;
|
|
615
|
-
try {
|
|
616
|
-
files = __rspack_external_fs.readdirSync(dir, {
|
|
617
|
-
withFileTypes: true
|
|
618
|
-
});
|
|
619
|
-
} catch {
|
|
620
|
-
return null;
|
|
621
|
-
}
|
|
622
|
-
for (const file of files){
|
|
623
|
-
if (file.isFile() && 'manifest.json' === file.name) return __rspack_external_path.join(dir, file.name);
|
|
624
|
-
if (file.isDirectory() && !file.name.startsWith('.') && 'node_modules' !== file.name && 'dist' !== file.name && 'public' !== file.name) {
|
|
625
|
-
const found = findManifest(__rspack_external_path.join(dir, file.name), depth + 1);
|
|
626
|
-
if (found) return found;
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
return null;
|
|
630
|
-
};
|
|
631
|
-
const foundManifest = findManifest(projectPath, 0);
|
|
632
|
-
if (foundManifest) manifestPath = foundManifest;
|
|
633
|
-
else throw new Error(manifestNotFoundError(manifestPath));
|
|
634
|
-
}
|
|
635
|
-
const packageJsonPath = await findNearestPackageJson(manifestPath);
|
|
636
|
-
const packageJsonDir = packageJsonPath ? __rspack_external_path.dirname(packageJsonPath) : void 0;
|
|
637
|
-
if (packageJsonDir) {
|
|
638
|
-
const publicRoot = __rspack_external_path.join(packageJsonDir, 'public');
|
|
639
|
-
if (isUnderDir(publicRoot, manifestPath)) {
|
|
640
|
-
const fallbackSrc = __rspack_external_path.join(packageJsonDir, 'src', 'manifest.json');
|
|
641
|
-
const fallbackRoot = __rspack_external_path.join(packageJsonDir, 'manifest.json');
|
|
642
|
-
if (__rspack_external_fs.existsSync(fallbackSrc)) manifestPath = fallbackSrc;
|
|
643
|
-
else if (__rspack_external_fs.existsSync(fallbackRoot)) manifestPath = fallbackRoot;
|
|
644
|
-
else throw new Error(manifestNotFoundError(fallbackRoot));
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
if (!packageJsonPath || !validatePackageJson(packageJsonPath)) return {
|
|
648
|
-
manifestPath
|
|
649
|
-
};
|
|
650
|
-
return {
|
|
651
|
-
manifestPath,
|
|
652
|
-
packageJsonPath
|
|
653
|
-
};
|
|
654
|
-
}
|
|
655
|
-
function loadCommonJsConfigWithStableDirname(absolutePath) {
|
|
656
|
-
const code = __rspack_external_fs.readFileSync(absolutePath, 'utf-8');
|
|
657
|
-
const dirname = __rspack_external_path.dirname(absolutePath);
|
|
658
|
-
const requireFn = createRequire(absolutePath);
|
|
659
|
-
const module = {
|
|
660
|
-
exports: {}
|
|
661
|
-
};
|
|
662
|
-
const exports = module.exports;
|
|
663
|
-
const wrapped = `(function (exports, require, module, __filename, __dirname) {\n${code}\n})`;
|
|
664
|
-
const fn = new __rspack_external_vm.Script(wrapped, {
|
|
665
|
-
filename: absolutePath
|
|
666
|
-
}).runInThisContext();
|
|
667
|
-
fn(exports, requireFn, module, absolutePath, dirname);
|
|
668
|
-
return module.exports?.default || module.exports;
|
|
669
|
-
}
|
|
670
|
-
function findNearestWorkspaceRoot(startDir) {
|
|
671
|
-
let current = __rspack_external_path.resolve(startDir);
|
|
672
|
-
while(true){
|
|
673
|
-
if (__rspack_external_fs.existsSync(__rspack_external_path.join(current, 'pnpm-workspace.yaml'))) return current;
|
|
674
|
-
const parent = __rspack_external_path.dirname(current);
|
|
675
|
-
if (parent === current) return;
|
|
676
|
-
current = parent;
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
function preloadEnvFilesFromDir(envDir, options) {
|
|
680
|
-
let loadedAny = false;
|
|
681
|
-
try {
|
|
682
|
-
const defaultsPath = __rspack_external_path.join(envDir, '.env.defaults');
|
|
683
|
-
if (__rspack_external_fs.existsSync(defaultsPath)) {
|
|
684
|
-
dotenv.config({
|
|
685
|
-
path: defaultsPath,
|
|
686
|
-
override: Boolean(options?.override),
|
|
687
|
-
quiet: true
|
|
688
|
-
});
|
|
689
|
-
loadedAny = true;
|
|
690
|
-
}
|
|
691
|
-
const envCandidates = [
|
|
692
|
-
'.env.development',
|
|
693
|
-
'.env.local',
|
|
694
|
-
'.env'
|
|
695
|
-
];
|
|
696
|
-
for (const filename of envCandidates){
|
|
697
|
-
const filePath = __rspack_external_path.join(envDir, filename);
|
|
698
|
-
if (__rspack_external_fs.existsSync(filePath)) {
|
|
699
|
-
dotenv.config({
|
|
700
|
-
path: filePath,
|
|
701
|
-
override: Boolean(options?.override),
|
|
702
|
-
quiet: true
|
|
703
|
-
});
|
|
704
|
-
loadedAny = true;
|
|
705
|
-
break;
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
} catch {}
|
|
709
|
-
return {
|
|
710
|
-
loadedAny,
|
|
711
|
-
envDir
|
|
712
|
-
};
|
|
713
|
-
}
|
|
714
|
-
function findConfigFile(projectPath) {
|
|
715
|
-
const candidates = [
|
|
716
|
-
__rspack_external_path.join(projectPath, 'extension.config.js'),
|
|
717
|
-
__rspack_external_path.join(projectPath, 'extension.config.mjs'),
|
|
718
|
-
__rspack_external_path.join(projectPath, 'extension.config.cjs')
|
|
719
|
-
];
|
|
720
|
-
return candidates.find((p)=>__rspack_external_fs.existsSync(p));
|
|
721
|
-
}
|
|
722
|
-
function preloadEnvFiles(projectDir) {
|
|
723
|
-
const local = preloadEnvFilesFromDir(projectDir);
|
|
724
|
-
if (local.loadedAny) return local;
|
|
725
|
-
const workspaceRoot = findNearestWorkspaceRoot(projectDir);
|
|
726
|
-
if (workspaceRoot && workspaceRoot !== projectDir) return preloadEnvFilesFromDir(workspaceRoot);
|
|
727
|
-
return local;
|
|
728
|
-
}
|
|
729
|
-
const loadedConfigCache = new Map();
|
|
730
|
-
async function loadConfigFile(configPath) {
|
|
731
|
-
const absolutePath = __rspack_external_path.resolve(configPath);
|
|
732
|
-
const cached = loadedConfigCache.get(absolutePath);
|
|
733
|
-
if (cached) return cached;
|
|
734
|
-
const loading = loadConfigFileUncached(absolutePath);
|
|
735
|
-
loadedConfigCache.set(absolutePath, loading);
|
|
736
|
-
try {
|
|
737
|
-
return await loading;
|
|
738
|
-
} catch (error) {
|
|
739
|
-
loadedConfigCache.delete(absolutePath);
|
|
740
|
-
throw error;
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
async function loadConfigFileUncached(absolutePath) {
|
|
744
|
-
const projectDir = __rspack_external_path.dirname(absolutePath);
|
|
745
|
-
preloadEnvFiles(projectDir);
|
|
746
|
-
try {
|
|
747
|
-
if (absolutePath.endsWith('.cjs')) {
|
|
748
|
-
const requireFn = createRequire(import.meta.url);
|
|
749
|
-
const required = requireFn(absolutePath);
|
|
750
|
-
return required?.default || required;
|
|
751
|
-
}
|
|
752
|
-
let esmImportPath = absolutePath;
|
|
753
|
-
let shimTmpDir;
|
|
754
|
-
try {
|
|
755
|
-
const originalContent = __rspack_external_fs.readFileSync(absolutePath, 'utf-8');
|
|
756
|
-
if (originalContent.includes('import.meta.env')) {
|
|
757
|
-
shimTmpDir = __rspack_external_fs.mkdtempSync(__rspack_external_path.join(__rspack_external_os.tmpdir(), 'extension-config-esm-'));
|
|
758
|
-
const tmpPath = __rspack_external_path.join(shimTmpDir, __rspack_external_path.basename(absolutePath));
|
|
759
|
-
const envObjectLiteral = JSON.stringify(Object.fromEntries(Object.entries(process.env).map(([k, v])=>[
|
|
760
|
-
k,
|
|
761
|
-
v
|
|
762
|
-
])), null, 0);
|
|
763
|
-
const shimHeader = `const __IMPORT_META_ENV__ = Object.freeze(${envObjectLiteral});\n`;
|
|
764
|
-
const replaced = originalContent.replace(/import\.meta\.env/g, '__IMPORT_META_ENV__');
|
|
765
|
-
__rspack_external_fs.writeFileSync(tmpPath, `${shimHeader}${replaced}`, 'utf-8');
|
|
766
|
-
esmImportPath = tmpPath;
|
|
767
|
-
}
|
|
768
|
-
} catch {}
|
|
769
|
-
try {
|
|
770
|
-
const module = await import(pathToFileURL(esmImportPath).href);
|
|
771
|
-
return module.default || module;
|
|
772
|
-
} finally{
|
|
773
|
-
if (shimTmpDir) try {
|
|
774
|
-
__rspack_external_fs.rmSync(shimTmpDir, {
|
|
775
|
-
recursive: true,
|
|
776
|
-
force: true
|
|
777
|
-
});
|
|
778
|
-
} catch {}
|
|
779
|
-
}
|
|
780
|
-
} catch (err) {
|
|
781
|
-
const error = err;
|
|
782
|
-
try {
|
|
783
|
-
if (!absolutePath.endsWith('.mjs')) {
|
|
784
|
-
const requireFn = createRequire(import.meta.url);
|
|
785
|
-
let required;
|
|
786
|
-
try {
|
|
787
|
-
required = requireFn(absolutePath);
|
|
788
|
-
} catch (requireErr) {
|
|
789
|
-
const message = String(error?.message || '') + ' ' + String(requireErr?.message || '');
|
|
790
|
-
const looksLikeCommonJsInEsm = message.includes('require is not defined in ES module scope') || message.includes('Cannot use import statement outside a module') || message.includes('ERR_REQUIRE_ESM');
|
|
791
|
-
if (looksLikeCommonJsInEsm) try {
|
|
792
|
-
required = loadCommonJsConfigWithStableDirname(absolutePath);
|
|
793
|
-
} catch {
|
|
794
|
-
const tmpDir = __rspack_external_fs.mkdtempSync(__rspack_external_path.join(__rspack_external_os.tmpdir(), 'extension-config-'));
|
|
795
|
-
try {
|
|
796
|
-
const tmpCjsPath = __rspack_external_path.join(tmpDir, __rspack_external_path.basename(absolutePath, __rspack_external_path.extname(absolutePath)) + '.cjs');
|
|
797
|
-
__rspack_external_fs.copyFileSync(absolutePath, tmpCjsPath);
|
|
798
|
-
required = requireFn(tmpCjsPath);
|
|
799
|
-
} finally{
|
|
800
|
-
try {
|
|
801
|
-
__rspack_external_fs.rmSync(tmpDir, {
|
|
802
|
-
recursive: true,
|
|
803
|
-
force: true
|
|
804
|
-
});
|
|
805
|
-
} catch {}
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
else throw requireErr;
|
|
809
|
-
}
|
|
810
|
-
return required?.default || required;
|
|
811
|
-
}
|
|
812
|
-
} catch {}
|
|
813
|
-
try {
|
|
814
|
-
const content = __rspack_external_fs.readFileSync(absolutePath, 'utf-8');
|
|
815
|
-
return JSON.parse(content);
|
|
816
|
-
} catch (jsonErr) {
|
|
817
|
-
throw new Error(`Failed to load config file: ${absolutePath}\nError: ${error.message || error}`);
|
|
950
|
+
});
|
|
951
|
+
} catch {
|
|
952
|
+
return;
|
|
818
953
|
}
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
if (configPath) {
|
|
824
|
-
if (await config_loader_isUsingExperimentalConfig(projectPath)) try {
|
|
825
|
-
const userConfig = await loadConfigFile(configPath);
|
|
826
|
-
if (userConfig && 'function' == typeof userConfig.config) return userConfig.config;
|
|
827
|
-
if (userConfig && userConfig.config && 'object' == typeof userConfig.config) {
|
|
828
|
-
const partial = userConfig.config;
|
|
829
|
-
return (config)=>{
|
|
830
|
-
const requireFn = createRequire(import.meta.url);
|
|
831
|
-
const { merge } = requireFn('webpack-merge');
|
|
832
|
-
return merge(config, partial);
|
|
833
|
-
};
|
|
954
|
+
for (const entry of entries){
|
|
955
|
+
if (entry.isFile() && 'manifest.json' === entry.name) {
|
|
956
|
+
results.push(__rspack_external_path.join(dir, entry.name));
|
|
957
|
+
continue;
|
|
834
958
|
}
|
|
835
|
-
|
|
836
|
-
const error = err;
|
|
837
|
-
console.error(configLoadingError(configPath, error));
|
|
838
|
-
throw err;
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
return (config)=>config;
|
|
842
|
-
}
|
|
843
|
-
async function loadCommandConfig(projectPath, command) {
|
|
844
|
-
const configPath = findConfigFile(projectPath);
|
|
845
|
-
if (configPath) {
|
|
846
|
-
if (await config_loader_isUsingExperimentalConfig(projectPath)) try {
|
|
847
|
-
const userConfig = await loadConfigFile(configPath);
|
|
848
|
-
const baseExtensions = userConfig && userConfig.extensions ? {
|
|
849
|
-
extensions: userConfig.extensions
|
|
850
|
-
} : {};
|
|
851
|
-
const baseTranspilePackages = userConfig && Array.isArray(userConfig.transpilePackages) ? {
|
|
852
|
-
transpilePackages: userConfig.transpilePackages
|
|
853
|
-
} : {};
|
|
854
|
-
const basePerfBudgets = userConfig && userConfig.perfBudgets && 'object' == typeof userConfig.perfBudgets ? {
|
|
855
|
-
perfBudgets: userConfig.perfBudgets
|
|
856
|
-
} : {};
|
|
857
|
-
const perCommand = userConfig && userConfig.commands && userConfig.commands[command] ? userConfig.commands[command] : {};
|
|
858
|
-
return {
|
|
859
|
-
...baseExtensions,
|
|
860
|
-
...baseTranspilePackages,
|
|
861
|
-
...basePerfBudgets,
|
|
862
|
-
...perCommand
|
|
863
|
-
};
|
|
864
|
-
} catch (err) {
|
|
865
|
-
const error = err;
|
|
866
|
-
console.error(configLoadingError(configPath, error));
|
|
867
|
-
throw err;
|
|
959
|
+
if (entry.isDirectory() && !entry.name.startsWith('.') && !SKIP_DIRS.has(entry.name)) walk(__rspack_external_path.join(dir, entry.name), depth + 1);
|
|
868
960
|
}
|
|
869
|
-
}
|
|
870
|
-
|
|
961
|
+
};
|
|
962
|
+
walk(rootDir, 0);
|
|
963
|
+
return results;
|
|
871
964
|
}
|
|
872
|
-
async function
|
|
873
|
-
const
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
965
|
+
async function getProjectStructure(pathOrRemoteUrl) {
|
|
966
|
+
const projectPath = await getProjectPath(pathOrRemoteUrl);
|
|
967
|
+
const isUnderDir = (baseDir, candidatePath)=>{
|
|
968
|
+
const rel = __rspack_external_path.relative(baseDir, candidatePath);
|
|
969
|
+
return Boolean(rel && !rel.startsWith('..') && !__rspack_external_path.isAbsolute(rel));
|
|
970
|
+
};
|
|
971
|
+
const packageJsonPathFromProject = await findNearestPackageJson(__rspack_external_path.join(projectPath, 'manifest.json'));
|
|
972
|
+
const packageJsonDirFromProject = packageJsonPathFromProject ? __rspack_external_path.dirname(packageJsonPathFromProject) : void 0;
|
|
973
|
+
const rootManifestPath = __rspack_external_path.join(projectPath, 'manifest.json');
|
|
974
|
+
const srcManifestPath = __rspack_external_path.join(projectPath, 'src', 'manifest.json');
|
|
975
|
+
let manifestPath = __rspack_external_fs.existsSync(srcManifestPath) ? srcManifestPath : rootManifestPath;
|
|
976
|
+
if (!__rspack_external_fs.existsSync(manifestPath)) if (packageJsonDirFromProject) {
|
|
977
|
+
const absoluteCandidates = collectManifestCandidates(projectPath, 3);
|
|
978
|
+
const relativeCandidates = absoluteCandidates.map((candidate)=>__rspack_external_path.relative(projectPath, candidate) || candidate);
|
|
979
|
+
if (1 === absoluteCandidates.length) {
|
|
980
|
+
manifestPath = absoluteCandidates[0];
|
|
981
|
+
console.log(resolvedWorkspaceManifest(projectPath, manifestPath));
|
|
982
|
+
} else throw new Error(manifestNotFoundError(manifestPath, relativeCandidates));
|
|
983
|
+
} else {
|
|
984
|
+
const MAX_DEPTH = 5;
|
|
985
|
+
const findManifest = (dir, depth)=>{
|
|
986
|
+
if (depth > MAX_DEPTH) return null;
|
|
987
|
+
let files;
|
|
988
|
+
try {
|
|
989
|
+
files = __rspack_external_fs.readdirSync(dir, {
|
|
990
|
+
withFileTypes: true
|
|
991
|
+
});
|
|
992
|
+
} catch {
|
|
993
|
+
return null;
|
|
994
|
+
}
|
|
995
|
+
for (const file of files){
|
|
996
|
+
if (file.isFile() && 'manifest.json' === file.name) return __rspack_external_path.join(dir, file.name);
|
|
997
|
+
if (file.isDirectory() && !file.name.startsWith('.') && 'node_modules' !== file.name && 'dist' !== file.name && 'public' !== file.name) {
|
|
998
|
+
const found = findManifest(__rspack_external_path.join(dir, file.name), depth + 1);
|
|
999
|
+
if (found) return found;
|
|
888
1000
|
}
|
|
889
1001
|
}
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
1002
|
+
return null;
|
|
1003
|
+
};
|
|
1004
|
+
const foundManifest = findManifest(projectPath, 0);
|
|
1005
|
+
if (foundManifest) manifestPath = foundManifest;
|
|
1006
|
+
else throw new Error(manifestNotFoundError(manifestPath));
|
|
1007
|
+
}
|
|
1008
|
+
const packageJsonPath = await findNearestPackageJson(manifestPath);
|
|
1009
|
+
const packageJsonDir = packageJsonPath ? __rspack_external_path.dirname(packageJsonPath) : void 0;
|
|
1010
|
+
if (packageJsonDir) {
|
|
1011
|
+
const publicRoot = __rspack_external_path.join(packageJsonDir, 'public');
|
|
1012
|
+
if (isUnderDir(publicRoot, manifestPath)) {
|
|
1013
|
+
const fallbackSrc = __rspack_external_path.join(packageJsonDir, 'src', 'manifest.json');
|
|
1014
|
+
const fallbackRoot = __rspack_external_path.join(packageJsonDir, 'manifest.json');
|
|
1015
|
+
if (__rspack_external_fs.existsSync(fallbackSrc)) manifestPath = fallbackSrc;
|
|
1016
|
+
else if (__rspack_external_fs.existsSync(fallbackRoot)) manifestPath = fallbackRoot;
|
|
1017
|
+
else throw new Error(manifestNotFoundError(fallbackRoot));
|
|
894
1018
|
}
|
|
895
1019
|
}
|
|
1020
|
+
if (!packageJsonPath || !validatePackageJson(packageJsonPath)) return {
|
|
1021
|
+
manifestPath
|
|
1022
|
+
};
|
|
896
1023
|
return {
|
|
897
|
-
|
|
1024
|
+
manifestPath,
|
|
1025
|
+
packageJsonPath
|
|
898
1026
|
};
|
|
899
1027
|
}
|
|
900
|
-
let userMessageDelivered = false;
|
|
901
|
-
async function config_loader_isUsingExperimentalConfig(projectPath) {
|
|
902
|
-
const configPath = findConfigFile(projectPath);
|
|
903
|
-
if (configPath) {
|
|
904
|
-
if (!userMessageDelivered) {
|
|
905
|
-
if ('true' === process.env.EXTENSION_AUTHOR_MODE) console.log(isUsingExperimentalConfig('extension.config.js'));
|
|
906
|
-
userMessageDelivered = true;
|
|
907
|
-
}
|
|
908
|
-
return true;
|
|
909
|
-
}
|
|
910
|
-
return false;
|
|
911
|
-
}
|
|
912
1028
|
function isReferencedAsModuleSpecifier(configSource, dep) {
|
|
913
1029
|
const escaped = dep.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
914
1030
|
const specifierRe = new RegExp(`['"\`]${escaped}(?:/[^'"\`]*)?['"\`]`);
|
|
@@ -944,112 +1060,6 @@ function assertNoManagedDependencyConflicts(userPackageJsonPath, projectPath) {
|
|
|
944
1060
|
if ('true' === process.env.EXTENSION_AUTHOR_MODE) console.warn(error);
|
|
945
1061
|
}
|
|
946
1062
|
}
|
|
947
|
-
function asAbsolute(p) {
|
|
948
|
-
return __rspack_external_path.isAbsolute(p) ? p : __rspack_external_path.resolve(p);
|
|
949
|
-
}
|
|
950
|
-
function getDirs(struct) {
|
|
951
|
-
const manifestDir = asAbsolute(__rspack_external_path.dirname(struct.manifestPath));
|
|
952
|
-
const packageJsonDir = asAbsolute(struct.packageJsonPath ? __rspack_external_path.dirname(struct.packageJsonPath) : manifestDir);
|
|
953
|
-
return {
|
|
954
|
-
manifestDir,
|
|
955
|
-
packageJsonDir
|
|
956
|
-
};
|
|
957
|
-
}
|
|
958
|
-
function getNodeModulesDir(packageJsonDir) {
|
|
959
|
-
return asAbsolute(__rspack_external_path.join(packageJsonDir, 'node_modules'));
|
|
960
|
-
}
|
|
961
|
-
function needsInstall(packageJsonDir) {
|
|
962
|
-
const nm = getNodeModulesDir(packageJsonDir);
|
|
963
|
-
const packageJsonPath = __rspack_external_path.join(packageJsonDir, 'package.json');
|
|
964
|
-
if (!__rspack_external_fs.existsSync(packageJsonPath)) return false;
|
|
965
|
-
try {
|
|
966
|
-
const raw = __rspack_external_fs.readFileSync(packageJsonPath, 'utf-8');
|
|
967
|
-
const packageJson = JSON.parse(raw);
|
|
968
|
-
const depsCount = Object.keys(packageJson?.dependencies || {}).length;
|
|
969
|
-
const devDepsCount = Object.keys(packageJson?.devDependencies || {}).length;
|
|
970
|
-
if (depsCount + devDepsCount === 0) return false;
|
|
971
|
-
if (!__rspack_external_fs.existsSync(nm)) return true;
|
|
972
|
-
const deps = Object.keys(packageJson?.dependencies || {});
|
|
973
|
-
const devDeps = Object.keys(packageJson?.devDependencies || {});
|
|
974
|
-
if (__rspack_external_fs.existsSync(__rspack_external_path.join(nm, '.pnpm'))) return false;
|
|
975
|
-
if (__rspack_external_fs.existsSync(__rspack_external_path.join(nm, '.modules.yaml'))) return false;
|
|
976
|
-
const hasInstalledDep = [
|
|
977
|
-
...deps,
|
|
978
|
-
...devDeps
|
|
979
|
-
].some((dep)=>__rspack_external_fs.existsSync(__rspack_external_path.join(nm, dep)));
|
|
980
|
-
return !hasInstalledDep;
|
|
981
|
-
} catch {
|
|
982
|
-
return true;
|
|
983
|
-
}
|
|
984
|
-
}
|
|
985
|
-
function normalizeBrowser(browser, chromiumBinary, geckoBinary, safariBinary) {
|
|
986
|
-
const requested = String(browser || '');
|
|
987
|
-
if (chromiumBinary) {
|
|
988
|
-
if (!requested || 'chromium-based' === requested) return 'chromium-based';
|
|
989
|
-
if ('chromium' === requested) return 'chromium';
|
|
990
|
-
if ('edge' === requested) return 'edge';
|
|
991
|
-
if ('chrome' === requested) return 'chrome';
|
|
992
|
-
}
|
|
993
|
-
if (geckoBinary) {
|
|
994
|
-
if (!requested || 'gecko-based' === requested || 'firefox-based' === requested) return 'gecko-based';
|
|
995
|
-
if ('firefox' === requested) return 'firefox';
|
|
996
|
-
}
|
|
997
|
-
if (safariBinary) {
|
|
998
|
-
if (!requested || 'webkit-based' === requested) return 'webkit-based';
|
|
999
|
-
if ('safari' === requested) return 'safari';
|
|
1000
|
-
}
|
|
1001
|
-
switch(requested){
|
|
1002
|
-
case 'chrome':
|
|
1003
|
-
return 'chrome';
|
|
1004
|
-
case 'edge':
|
|
1005
|
-
return 'edge';
|
|
1006
|
-
case 'chromium':
|
|
1007
|
-
return 'chromium';
|
|
1008
|
-
case 'chromium-based':
|
|
1009
|
-
return 'chromium-based';
|
|
1010
|
-
case 'firefox':
|
|
1011
|
-
return 'firefox';
|
|
1012
|
-
case 'gecko-based':
|
|
1013
|
-
case 'firefox-based':
|
|
1014
|
-
return 'gecko-based';
|
|
1015
|
-
case 'safari':
|
|
1016
|
-
return 'safari';
|
|
1017
|
-
case 'webkit-based':
|
|
1018
|
-
return 'webkit-based';
|
|
1019
|
-
default:
|
|
1020
|
-
return 'chrome';
|
|
1021
|
-
}
|
|
1022
|
-
}
|
|
1023
|
-
function getDistPath(packageJsonDir, browser) {
|
|
1024
|
-
return asAbsolute(__rspack_external_path.join(packageJsonDir, 'dist', browser));
|
|
1025
|
-
}
|
|
1026
|
-
function computePreviewOutputPath(struct, browser, explicitOutputPath) {
|
|
1027
|
-
const { manifestDir, packageJsonDir } = getDirs(struct);
|
|
1028
|
-
if (explicitOutputPath) return asAbsolute(explicitOutputPath);
|
|
1029
|
-
if (struct.packageJsonPath) {
|
|
1030
|
-
const distDir = getDistPath(packageJsonDir, browser);
|
|
1031
|
-
try {
|
|
1032
|
-
if (__rspack_external_fs.existsSync(__rspack_external_path.join(distDir, 'manifest.json'))) return distDir;
|
|
1033
|
-
} catch {}
|
|
1034
|
-
}
|
|
1035
|
-
return manifestDir;
|
|
1036
|
-
}
|
|
1037
|
-
function devtoolsEngineFor(browser) {
|
|
1038
|
-
switch(browser){
|
|
1039
|
-
case 'chrome':
|
|
1040
|
-
return 'chrome';
|
|
1041
|
-
case 'edge':
|
|
1042
|
-
return 'edge';
|
|
1043
|
-
case 'chromium':
|
|
1044
|
-
case 'chromium-based':
|
|
1045
|
-
return 'chromium';
|
|
1046
|
-
case 'firefox':
|
|
1047
|
-
case 'gecko-based':
|
|
1048
|
-
return 'firefox';
|
|
1049
|
-
default:
|
|
1050
|
-
return 'chrome';
|
|
1051
|
-
}
|
|
1052
|
-
}
|
|
1053
1063
|
function isDir(p) {
|
|
1054
1064
|
try {
|
|
1055
1065
|
return __rspack_external_fs.existsSync(p) && __rspack_external_fs.statSync(p).isDirectory();
|