extension-develop 3.15.1 → 3.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/0~branding.mjs +26 -0
  2. package/dist/0~dev-server.mjs +488 -0
  3. package/dist/0~rslib-runtime.mjs +40 -0
  4. package/dist/0~rspack-config.mjs +8648 -0
  5. package/dist/0~stats-handler.mjs +25 -0
  6. package/dist/0~zip.mjs +34 -0
  7. package/dist/314.mjs +35 -0
  8. package/dist/526.mjs +23 -0
  9. package/dist/946.mjs +1670 -0
  10. package/dist/962.mjs +1389 -0
  11. package/dist/ensure-hmr-for-scripts.js +12 -56
  12. package/dist/{ensure-hmr-for-scripts.cjs → ensure-hmr-for-scripts.mjs} +12 -56
  13. package/dist/feature-scripts-content-script-wrapper.js +23 -98
  14. package/dist/{feature-scripts-content-script-wrapper.cjs → feature-scripts-content-script-wrapper.mjs} +23 -98
  15. package/dist/main-world-bridge.js +0 -18
  16. package/dist/{main-world-bridge.cjs → main-world-bridge.mjs} +0 -18
  17. package/dist/minimum-chromium-file.js +0 -5
  18. package/dist/minimum-chromium-file.mjs +5 -0
  19. package/dist/minimum-firefox-file.js +0 -5
  20. package/dist/minimum-firefox-file.mjs +5 -0
  21. package/dist/minimum-script-file.js +0 -18
  22. package/dist/{minimum-script-file.cjs → minimum-script-file.mjs} +0 -18
  23. package/dist/module.mjs +3 -0
  24. package/dist/package.json +1 -1
  25. package/dist/preact-refresh-shim.mjs +7 -0
  26. package/dist/preview.mjs +2 -0
  27. package/dist/resolve-paths-loader.js +1043 -1093
  28. package/dist/resolve-paths-loader.mjs +1300 -0
  29. package/package.json +8 -8
  30. package/dist/221.cjs +0 -513
  31. package/dist/442.cjs +0 -9226
  32. package/dist/504.cjs +0 -65
  33. package/dist/787.cjs +0 -44
  34. package/dist/minimum-chromium-file.cjs +0 -10
  35. package/dist/minimum-firefox-file.cjs +0 -10
  36. package/dist/module.cjs +0 -3479
  37. package/dist/preact-refresh-shim.cjs +0 -25
  38. package/dist/preview.cjs +0 -1464
  39. package/dist/resolve-paths-loader.cjs +0 -1350
@@ -1,1350 +0,0 @@
1
- "use strict";
2
- var __webpack_modules__ = {
3
- "@swc/core" (module) {
4
- module.exports = require("@swc/core");
5
- }
6
- };
7
- var __webpack_module_cache__ = {};
8
- function __webpack_require__(moduleId) {
9
- var cachedModule = __webpack_module_cache__[moduleId];
10
- if (void 0 !== cachedModule) return cachedModule.exports;
11
- var module = __webpack_module_cache__[moduleId] = {
12
- exports: {}
13
- };
14
- __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
15
- return module.exports;
16
- }
17
- (()=>{
18
- __webpack_require__.n = (module)=>{
19
- var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
20
- __webpack_require__.d(getter, {
21
- a: getter
22
- });
23
- return getter;
24
- };
25
- })();
26
- (()=>{
27
- __webpack_require__.d = (exports1, definition)=>{
28
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
29
- enumerable: true,
30
- get: definition[key]
31
- });
32
- };
33
- })();
34
- (()=>{
35
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
36
- })();
37
- (()=>{
38
- __webpack_require__.r = (exports1)=>{
39
- if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
40
- value: 'Module'
41
- });
42
- Object.defineProperty(exports1, '__esModule', {
43
- value: true
44
- });
45
- };
46
- })();
47
- var __webpack_exports__ = {};
48
- (()=>{
49
- __webpack_require__.r(__webpack_exports__);
50
- __webpack_require__.d(__webpack_exports__, {
51
- default: ()=>resolvePathsLoader
52
- });
53
- const external_path_namespaceObject = require("path");
54
- const external_fs_namespaceObject = require("fs");
55
- const external_magic_string_namespaceObject = require("magic-string");
56
- var external_magic_string_default = /*#__PURE__*/ __webpack_require__.n(external_magic_string_namespaceObject);
57
- function getFilename(feature, filePath) {
58
- const entryExt = external_path_namespaceObject.extname(filePath);
59
- let fileOutputpath = feature;
60
- if ([
61
- '.js',
62
- '.jsx',
63
- '.tsx',
64
- '.ts'
65
- ].includes(entryExt)) fileOutputpath = fileOutputpath.replace(entryExt, '.js');
66
- if ([
67
- '.html',
68
- '.njk',
69
- '.nunjucks'
70
- ].includes(entryExt)) fileOutputpath = fileOutputpath.replace(entryExt, '.html');
71
- if ([
72
- '.css',
73
- '.scss',
74
- '.sass',
75
- '.less'
76
- ].includes(entryExt)) fileOutputpath = fileOutputpath.replace(entryExt, '.css');
77
- return unixify(fileOutputpath || '');
78
- }
79
- function unixify(filePath) {
80
- return filePath.replace(/\\/g, '/');
81
- }
82
- function memberChainFromCallee(callee) {
83
- const memberParts = [];
84
- let currentExpression = callee;
85
- while(currentExpression && 'ParenExpression' === currentExpression.type)currentExpression = currentExpression.expression;
86
- while(currentExpression){
87
- if ('Identifier' === currentExpression.type) {
88
- memberParts.unshift(currentExpression.value);
89
- break;
90
- }
91
- if ('MemberExpression' === currentExpression.type) {
92
- const propertyNode = currentExpression.property;
93
- if (propertyNode?.type === 'Identifier') memberParts.unshift(propertyNode.value);
94
- currentExpression = currentExpression.object;
95
- continue;
96
- }
97
- break;
98
- }
99
- return memberParts;
100
- }
101
- function getPropName(propertyNode) {
102
- if (!propertyNode || 'KeyValueProperty' !== propertyNode.type) return;
103
- const keyNode = propertyNode.key;
104
- if (keyNode?.type === 'Identifier') return keyNode.value;
105
- if (keyNode?.type === 'StringLiteral') return keyNode.value;
106
- }
107
- function isHttpLike(input) {
108
- return /^https?:\/\//i.test(input) || /^data:/i.test(input) || /^chrome:\/\//i.test(input) || /^moz-extension:\/\//i.test(input);
109
- }
110
- function hasGlob(input) {
111
- return /[*?\[\]{}]/.test(input);
112
- }
113
- function resolveLiteralToOutput(literal, opts) {
114
- const { manifestPath, packageJsonDir, authorFilePath } = opts;
115
- const root = packageJsonDir || external_path_namespaceObject.dirname(manifestPath);
116
- const canonicalUnixPath = unixify(literal || '');
117
- if (!literal || isHttpLike(literal) || hasGlob(literal)) return;
118
- if (/^\/public\//i.test(canonicalUnixPath)) {
119
- const out = canonicalUnixPath.replace(/^\/public\//i, '');
120
- return out;
121
- }
122
- if (/^(?:\.\/)?public\//i.test(canonicalUnixPath)) {
123
- const out = canonicalUnixPath.replace(/^(?:\.\/)?public\//i, '');
124
- return out;
125
- }
126
- if (/^\//.test(canonicalUnixPath)) {
127
- const trimmed = canonicalUnixPath.replace(/^\//, '');
128
- if (/^(?:pages|scripts)\//i.test(trimmed)) {
129
- const abs = external_path_namespaceObject.join(root, trimmed);
130
- return unixify(getFilename(trimmed, abs));
131
- }
132
- return trimmed;
133
- }
134
- const baseDir = /^(\.\/|\.\.\/)/.test(canonicalUnixPath) && authorFilePath ? external_path_namespaceObject.dirname(authorFilePath) : root;
135
- const candidateAbsolutePath = external_path_namespaceObject.isAbsolute(literal) ? literal : external_path_namespaceObject.resolve(baseDir, literal);
136
- const pathWithoutDotPrefix = canonicalUnixPath.replace(/^\.\//, '');
137
- if (/^pages\//i.test(pathWithoutDotPrefix)) return unixify(getFilename(pathWithoutDotPrefix, candidateAbsolutePath));
138
- if (/^scripts\//i.test(pathWithoutDotPrefix)) return unixify(getFilename(pathWithoutDotPrefix, candidateAbsolutePath));
139
- try {
140
- const normalizedRel = unixify(external_path_namespaceObject.relative(root, candidateAbsolutePath));
141
- const relNoDotPrefix = normalizedRel.replace(/^\.\//, '');
142
- if (/^public\//i.test(relNoDotPrefix)) return relNoDotPrefix.replace(/^public\//i, '');
143
- if (/^pages\//i.test(relNoDotPrefix)) return unixify(getFilename(relNoDotPrefix, candidateAbsolutePath));
144
- if (/^scripts\//i.test(relNoDotPrefix)) return unixify(getFilename(relNoDotPrefix, candidateAbsolutePath));
145
- } catch {}
146
- }
147
- function isStringLiteral(node) {
148
- return node && 'StringLiteral' === node.type && 'string' == typeof node.value;
149
- }
150
- function isStaticTemplate(node) {
151
- return node && 'TemplateLiteral' === node.type && Array.isArray(node.expressions) && 0 === node.expressions.length;
152
- }
153
- function evalStaticString(node) {
154
- if (!node) return;
155
- if (node && 'ParenExpression' === node.type) return evalStaticString(node.expression);
156
- if (isStringLiteral(node)) return node.value;
157
- if (isStaticTemplate(node)) return node.quasis?.map((quasi)=>quasi.raw ?? '').join('');
158
- if (node && 'BinaryExpression' === node.type && '+' === node.operator) {
159
- const left = evalStaticString(node.left);
160
- const right = evalStaticString(node.right);
161
- if ('string' == typeof left && 'string' == typeof right) return left + right;
162
- }
163
- }
164
- function handleRuntimeCalls(node, source, rewriteValue, manifestPath) {
165
- if ('CallExpression' !== node.type) return false;
166
- const memberChain = memberChainFromCallee(node.callee);
167
- const apiRoot = memberChain[0];
168
- if ('chrome' !== apiRoot && 'browser' !== apiRoot) return false;
169
- const method = memberChain.join('.');
170
- if ((method.endsWith('runtime.getURL') || method.endsWith('extension.getURL')) && node.arguments?.[0]) {
171
- const firstArgument = node.arguments[0].expression;
172
- if (isStringLiteral(firstArgument)) {
173
- const resolved = resolveLiteralToOutput(firstArgument.value, {
174
- manifestPath
175
- });
176
- rewriteValue(firstArgument, resolved, firstArgument.value);
177
- } else if (isStaticTemplate(firstArgument)) {
178
- const rawTemplate = source.slice(firstArgument.span.start + 1, firstArgument.span.end - 1);
179
- const resolved = resolveLiteralToOutput(rawTemplate, {
180
- manifestPath
181
- });
182
- rewriteValue(firstArgument, resolved, rawTemplate);
183
- }
184
- return true;
185
- }
186
- return false;
187
- }
188
- function handleActionAndPopup(node, source, rewriteValue, manifestPath) {
189
- if ('CallExpression' !== node.type) return false;
190
- const memberChain = memberChainFromCallee(node.callee);
191
- const apiRoot = memberChain[0];
192
- if ('chrome' !== apiRoot && 'browser' !== apiRoot) return false;
193
- const method = memberChain.join('.');
194
- if (method.endsWith('action.setIcon') || method.endsWith('pageAction.setIcon') || method.endsWith('browserAction.setIcon')) {
195
- const firstArgument = node.arguments?.[0]?.expression;
196
- if (firstArgument?.type === 'ObjectExpression') for (const propertyNode of firstArgument.properties || []){
197
- if ('KeyValueProperty' !== propertyNode.type) continue;
198
- const keyName = getPropName(propertyNode);
199
- if ('path' !== keyName) continue;
200
- const valueNode = propertyNode.value;
201
- if (isStringLiteral(valueNode)) {
202
- const resolved = resolveLiteralToOutput(valueNode.value, {
203
- manifestPath
204
- });
205
- rewriteValue(valueNode, resolved, valueNode.value);
206
- } else if (valueNode?.type === 'ObjectExpression') {
207
- for (const innerProperty of valueNode.properties || [])if ('KeyValueProperty' === innerProperty.type && isStringLiteral(innerProperty.value)) {
208
- const resolved = resolveLiteralToOutput(innerProperty.value.value, {
209
- manifestPath
210
- });
211
- rewriteValue(innerProperty.value, resolved, innerProperty.value.value);
212
- } else if ('KeyValueProperty' === innerProperty.type && isStaticTemplate(innerProperty.value)) {
213
- const raw = source.slice(innerProperty.value.span.start + 1, innerProperty.value.span.end - 1);
214
- const resolved = resolveLiteralToOutput(raw, {
215
- manifestPath
216
- });
217
- rewriteValue(innerProperty.value, resolved, raw);
218
- } else if ('KeyValueProperty' === innerProperty.type) {
219
- const raw = evalStaticString(innerProperty.value);
220
- if ('string' == typeof raw) {
221
- const resolved = resolveLiteralToOutput(raw, {
222
- manifestPath
223
- });
224
- const originalExpr = source.slice(innerProperty.value.span.start, innerProperty.value.span.end);
225
- rewriteValue(innerProperty.value, resolved, originalExpr);
226
- }
227
- }
228
- } else if (isStaticTemplate(valueNode)) {
229
- const raw = source.slice(valueNode.span.start + 1, valueNode.span.end - 1);
230
- const resolved = resolveLiteralToOutput(raw, {
231
- manifestPath
232
- });
233
- rewriteValue(valueNode, resolved, raw);
234
- } else {
235
- const raw = evalStaticString(valueNode);
236
- if ('string' == typeof raw) {
237
- const resolved = resolveLiteralToOutput(raw, {
238
- manifestPath
239
- });
240
- const originalExpr = source.slice(valueNode.span.start, valueNode.span.end);
241
- rewriteValue(valueNode, resolved, originalExpr);
242
- }
243
- }
244
- }
245
- return true;
246
- }
247
- if (method.endsWith('action.setPopup') || method.endsWith('pageAction.setPopup') || method.endsWith('browserAction.setPopup')) {
248
- const firstArgument = node.arguments?.[0]?.expression;
249
- if (firstArgument?.type === 'ObjectExpression') for (const propertyNode of firstArgument.properties || []){
250
- if ('KeyValueProperty' !== propertyNode.type) continue;
251
- const keyName = getPropName(propertyNode);
252
- if ('popup' !== keyName) continue;
253
- const valueNode = propertyNode.value;
254
- if (isStringLiteral(valueNode)) {
255
- const resolved = resolveLiteralToOutput(valueNode.value, {
256
- manifestPath
257
- });
258
- rewriteValue(valueNode, resolved);
259
- } else if (isStaticTemplate(valueNode)) {
260
- const raw = source.slice(valueNode.span.start + 1, valueNode.span.end - 1);
261
- const resolved = resolveLiteralToOutput(raw, {
262
- manifestPath
263
- });
264
- rewriteValue(valueNode, resolved);
265
- } else {
266
- const raw = evalStaticString(valueNode);
267
- if ('string' == typeof raw) {
268
- const resolved = resolveLiteralToOutput(raw, {
269
- manifestPath
270
- });
271
- const originalExpr = source.slice(valueNode.span.start, valueNode.span.end);
272
- rewriteValue(valueNode, resolved, originalExpr);
273
- }
274
- }
275
- }
276
- return true;
277
- }
278
- return false;
279
- }
280
- function handleDevtools(node, source, rewriteValue, manifestPath) {
281
- if ('CallExpression' !== node.type) return false;
282
- const memberChain = memberChainFromCallee(node.callee);
283
- const apiRoot = memberChain[0];
284
- if ('chrome' !== apiRoot && 'browser' !== apiRoot) return false;
285
- const method = memberChain.join('.');
286
- if (method.endsWith('devtools.panels.create')) {
287
- const iconArg = node.arguments?.[1]?.expression;
288
- const pageArg = node.arguments?.[2]?.expression;
289
- let touched = false;
290
- if (isStringLiteral(iconArg)) {
291
- const resolved = resolveLiteralToOutput(iconArg.value, {
292
- manifestPath
293
- });
294
- rewriteValue(iconArg, resolved, iconArg.value);
295
- touched = true;
296
- } else if (isStaticTemplate(iconArg)) {
297
- const rawTemplate = source.slice(iconArg.span.start + 1, iconArg.span.end - 1);
298
- const resolved = resolveLiteralToOutput(rawTemplate, {
299
- manifestPath
300
- });
301
- rewriteValue(iconArg, resolved, rawTemplate);
302
- } else {
303
- const staticallyEvaluated = evalStaticString(iconArg);
304
- if ('string' == typeof staticallyEvaluated) {
305
- const resolved = resolveLiteralToOutput(staticallyEvaluated, {
306
- manifestPath
307
- });
308
- const originalExpr = source.slice(iconArg.span.start, iconArg.span.end);
309
- rewriteValue(iconArg, resolved, originalExpr);
310
- touched = true;
311
- }
312
- }
313
- if (isStringLiteral(pageArg)) {
314
- const resolved = resolveLiteralToOutput(pageArg.value, {
315
- manifestPath
316
- });
317
- rewriteValue(pageArg, resolved, pageArg.value);
318
- touched = true;
319
- } else if (isStaticTemplate(pageArg)) {
320
- const rawTemplate = source.slice(pageArg.span.start + 1, pageArg.span.end - 1);
321
- const resolved = resolveLiteralToOutput(rawTemplate, {
322
- manifestPath
323
- });
324
- rewriteValue(pageArg, resolved, rawTemplate);
325
- } else {
326
- const staticallyEvaluated = evalStaticString(pageArg);
327
- if ('string' == typeof staticallyEvaluated) {
328
- const resolved = resolveLiteralToOutput(staticallyEvaluated, {
329
- manifestPath
330
- });
331
- const originalExpr = source.slice(pageArg.span.start, pageArg.span.end);
332
- rewriteValue(pageArg, resolved, originalExpr);
333
- touched = true;
334
- }
335
- }
336
- return touched;
337
- }
338
- return false;
339
- }
340
- function handleTabsAndWindows(node, source, rewriteValue, manifestPath) {
341
- if ('CallExpression' !== node.type) return false;
342
- const memberChain = memberChainFromCallee(node.callee);
343
- const apiRoot = memberChain[0];
344
- if ('chrome' !== apiRoot && 'browser' !== apiRoot) return false;
345
- const method = memberChain.join('.');
346
- if (method.endsWith('tabs.create') || method.endsWith('windows.create')) {
347
- const firstArgument = node.arguments?.[0]?.expression;
348
- if (firstArgument?.type === 'ObjectExpression') for (const propertyNode of firstArgument.properties || []){
349
- if ('KeyValueProperty' !== propertyNode.type) continue;
350
- const keyName = getPropName(propertyNode);
351
- if ('url' !== keyName) continue;
352
- const valueNode = propertyNode.value;
353
- if (isStringLiteral(valueNode)) {
354
- const resolved = resolveLiteralToOutput(valueNode.value, {
355
- manifestPath
356
- });
357
- rewriteValue(valueNode, resolved, valueNode.value);
358
- } else if (valueNode?.type === 'ArrayExpression') for (const arrayElement of valueNode.elements || []){
359
- const literalNode = arrayElement?.expression;
360
- if (isStringLiteral(literalNode)) {
361
- const resolved = resolveLiteralToOutput(literalNode.value, {
362
- manifestPath
363
- });
364
- rewriteValue(literalNode, resolved, literalNode.value);
365
- } else if (isStaticTemplate(literalNode)) {
366
- const raw = source.slice(literalNode.span.start + 1, literalNode.span.end - 1);
367
- const resolved = resolveLiteralToOutput(raw, {
368
- manifestPath
369
- });
370
- rewriteValue(literalNode, resolved, raw);
371
- } else {
372
- const raw = evalStaticString(literalNode);
373
- if ('string' == typeof raw) {
374
- const resolved = resolveLiteralToOutput(raw, {
375
- manifestPath
376
- });
377
- const originalExpr = source.slice(literalNode.span.start, literalNode.span.end);
378
- rewriteValue(literalNode, resolved, originalExpr);
379
- }
380
- }
381
- }
382
- else if (isStaticTemplate(valueNode)) {
383
- const raw = source.slice(valueNode.span.start + 1, valueNode.span.end - 1);
384
- const resolved = resolveLiteralToOutput(raw, {
385
- manifestPath
386
- });
387
- rewriteValue(valueNode, resolved, raw);
388
- } else {
389
- const raw = evalStaticString(valueNode);
390
- if ('string' == typeof raw) {
391
- const resolved = resolveLiteralToOutput(raw, {
392
- manifestPath
393
- });
394
- const originalExpr = source.slice(valueNode.span.start, valueNode.span.end);
395
- rewriteValue(valueNode, resolved, originalExpr);
396
- }
397
- }
398
- }
399
- return true;
400
- }
401
- if (method.endsWith('tabs.update')) {
402
- const optionsArgument = node.arguments?.[1]?.expression || node.arguments?.[0]?.expression;
403
- if (optionsArgument?.type === 'ObjectExpression') for (const propertyNode of optionsArgument.properties || []){
404
- if ('KeyValueProperty' !== propertyNode.type) continue;
405
- const keyName = getPropName(propertyNode);
406
- if ('url' !== keyName) continue;
407
- const valueNode = propertyNode.value;
408
- if (isStringLiteral(valueNode)) {
409
- const resolved = resolveLiteralToOutput(valueNode.value, {
410
- manifestPath
411
- });
412
- rewriteValue(valueNode, resolved, valueNode.value);
413
- } else if (isStaticTemplate(valueNode)) {
414
- const raw = source.slice(valueNode.span.start + 1, valueNode.span.end - 1);
415
- const resolved = resolveLiteralToOutput(raw, {
416
- manifestPath
417
- });
418
- rewriteValue(valueNode, resolved, raw);
419
- } else {
420
- const raw = evalStaticString(valueNode);
421
- if ('string' == typeof raw) {
422
- const resolved = resolveLiteralToOutput(raw, {
423
- manifestPath
424
- });
425
- const originalExpr = source.slice(valueNode.span.start, valueNode.span.end);
426
- rewriteValue(valueNode, resolved, originalExpr);
427
- }
428
- }
429
- }
430
- return true;
431
- }
432
- return false;
433
- }
434
- function handleScripting(node, source, rewriteValue, manifestPath) {
435
- if ('CallExpression' !== node.type) return false;
436
- const memberChain = memberChainFromCallee(node.callee);
437
- const apiRoot = memberChain[0];
438
- if ('chrome' !== apiRoot && 'browser' !== apiRoot) return false;
439
- const method = memberChain.join('.');
440
- if (method.endsWith("scripting.registerContentScripts")) {
441
- for (const argumentNode of node.arguments || []){
442
- const arrayExpressionNode = argumentNode?.expression;
443
- if (arrayExpressionNode && 'ArrayExpression' === arrayExpressionNode.type) for (const arrayElement of arrayExpressionNode.elements || []){
444
- const objectExpressionNode = arrayElement?.expression;
445
- if (objectExpressionNode && 'ObjectExpression' === objectExpressionNode.type) for (const propertyNode of objectExpressionNode.properties || []){
446
- if ('KeyValueProperty' !== propertyNode.type) continue;
447
- const keyName = getPropName(propertyNode);
448
- if ('js' !== keyName && 'css' !== keyName) continue;
449
- const valueNode = propertyNode.value;
450
- if ('ArrayExpression' === valueNode.type) for (const innerItem of valueNode.elements || []){
451
- const literalNode = innerItem?.expression;
452
- if (isStringLiteral(literalNode)) {
453
- const resolved = resolveLiteralToOutput(literalNode.value, {
454
- manifestPath
455
- });
456
- rewriteValue(literalNode, resolved, literalNode.value);
457
- } else if (isStaticTemplate(literalNode)) {
458
- const raw = source.slice(literalNode.span.start + 1, literalNode.span.end - 1);
459
- const resolved = resolveLiteralToOutput(raw, {
460
- manifestPath
461
- });
462
- rewriteValue(literalNode, resolved, raw);
463
- } else {
464
- const raw = evalStaticString(literalNode);
465
- if ('string' == typeof raw) {
466
- const resolved = resolveLiteralToOutput(raw, {
467
- manifestPath
468
- });
469
- const originalExpr = source.slice(literalNode.span.start, literalNode.span.end);
470
- rewriteValue(literalNode, resolved, originalExpr);
471
- }
472
- }
473
- }
474
- else if (isStringLiteral(valueNode)) {
475
- const resolved = resolveLiteralToOutput(valueNode.value, {
476
- manifestPath
477
- });
478
- rewriteValue(valueNode, resolved, valueNode.value);
479
- } else if (isStaticTemplate(valueNode)) {
480
- const raw = source.slice(valueNode.span.start + 1, valueNode.span.end - 1);
481
- const resolved = resolveLiteralToOutput(raw, {
482
- manifestPath
483
- });
484
- rewriteValue(valueNode, resolved, raw);
485
- } else {
486
- const raw = evalStaticString(valueNode);
487
- if ('string' == typeof raw) {
488
- const resolved = resolveLiteralToOutput(raw, {
489
- manifestPath
490
- });
491
- const originalExpr = source.slice(valueNode.span.start, valueNode.span.end);
492
- rewriteValue(valueNode, resolved, originalExpr);
493
- }
494
- }
495
- }
496
- }
497
- }
498
- return true;
499
- }
500
- if (method.endsWith("scripting.executeScript") || method.endsWith("scripting.insertCSS")) {
501
- const firstArgument = node.arguments?.[0]?.expression;
502
- if (firstArgument?.type === 'ObjectExpression') for (const propertyNode of firstArgument.properties || []){
503
- if ('KeyValueProperty' !== propertyNode.type) continue;
504
- const keyName = getPropName(propertyNode);
505
- if ('files' !== keyName) continue;
506
- const valueNode = propertyNode.value;
507
- if (valueNode?.type === 'ArrayExpression') for (const arrayElement of valueNode.elements || []){
508
- const literalNode = arrayElement?.expression;
509
- if (isStringLiteral(literalNode)) {
510
- const resolved = resolveLiteralToOutput(literalNode.value, {
511
- manifestPath
512
- });
513
- rewriteValue(literalNode, resolved, literalNode.value);
514
- } else if (isStaticTemplate(literalNode)) {
515
- const raw = source.slice(literalNode.span.start + 1, literalNode.span.end - 1);
516
- const resolved = resolveLiteralToOutput(raw, {
517
- manifestPath
518
- });
519
- rewriteValue(literalNode, resolved, raw);
520
- } else {
521
- const raw = evalStaticString(literalNode);
522
- if ('string' == typeof raw) {
523
- const resolved = resolveLiteralToOutput(raw, {
524
- manifestPath
525
- });
526
- const originalExpr = source.slice(literalNode.span.start, literalNode.span.end);
527
- rewriteValue(literalNode, resolved, originalExpr);
528
- }
529
- }
530
- }
531
- }
532
- return true;
533
- }
534
- return false;
535
- }
536
- function handleMv2Tabs(node, source, rewriteValue, manifestPath) {
537
- if ('CallExpression' !== node.type) return false;
538
- const memberChain = memberChainFromCallee(node.callee);
539
- const apiRoot = memberChain[0];
540
- if ('chrome' !== apiRoot && 'browser' !== apiRoot) return false;
541
- const method = memberChain.join('.');
542
- if (method.endsWith('tabs.executeScript') || method.endsWith('tabs.insertCSS')) {
543
- const firstArgument = node.arguments?.[0]?.expression;
544
- if (firstArgument?.type === 'ObjectExpression') for (const propertyNode of firstArgument.properties || []){
545
- if ('KeyValueProperty' !== propertyNode.type) continue;
546
- const keyName = getPropName(propertyNode);
547
- if ('file' !== keyName) continue;
548
- const valueNode = propertyNode.value;
549
- if (isStringLiteral(valueNode)) {
550
- const resolved = resolveLiteralToOutput(valueNode.value, {
551
- manifestPath
552
- });
553
- rewriteValue(valueNode, resolved, valueNode.value);
554
- } else if (isStaticTemplate(valueNode)) {
555
- const raw = source.slice(valueNode.span.start + 1, valueNode.span.end - 1);
556
- const resolved = resolveLiteralToOutput(raw, {
557
- manifestPath
558
- });
559
- rewriteValue(valueNode, resolved, raw);
560
- } else {
561
- const raw = evalStaticString(valueNode);
562
- if ('string' == typeof raw) {
563
- const resolved = resolveLiteralToOutput(raw, {
564
- manifestPath
565
- });
566
- const originalExpr = source.slice(valueNode.span.start, valueNode.span.end);
567
- rewriteValue(valueNode, resolved, originalExpr);
568
- }
569
- }
570
- }
571
- return true;
572
- }
573
- return false;
574
- }
575
- function handlePanels(node, source, rewriteValue, manifestPath) {
576
- if ('CallExpression' !== node.type) return false;
577
- const memberChain = memberChainFromCallee(node.callee);
578
- const apiRoot = memberChain[0];
579
- if ('chrome' !== apiRoot && 'browser' !== apiRoot) return false;
580
- const method = memberChain.join('.');
581
- if (method.endsWith('sidePanel.setOptions') || method.endsWith('sidebarAction.setPanel')) {
582
- const firstArgument = node.arguments?.[0]?.expression;
583
- if (method.endsWith('sidebarAction.setPanel')) {
584
- const arg = firstArgument;
585
- if (isStringLiteral(arg)) {
586
- const resolved = resolveLiteralToOutput(arg.value, {
587
- manifestPath
588
- });
589
- rewriteValue(arg, resolved, arg.value);
590
- return true;
591
- }
592
- if (isStaticTemplate(arg)) {
593
- const raw = source.slice(arg.span.start + 1, arg.span.end - 1);
594
- const resolved = resolveLiteralToOutput(raw, {
595
- manifestPath
596
- });
597
- rewriteValue(arg, resolved, raw);
598
- return true;
599
- }
600
- {
601
- const raw = evalStaticString(arg);
602
- if ('string' == typeof raw) {
603
- const resolved = resolveLiteralToOutput(raw, {
604
- manifestPath
605
- });
606
- const originalExpr = source.slice(arg.span.start, arg.span.end);
607
- rewriteValue(arg, resolved, originalExpr);
608
- return true;
609
- }
610
- }
611
- }
612
- if (firstArgument?.type === 'ObjectExpression') for (const propertyNode of firstArgument.properties || []){
613
- if ('KeyValueProperty' !== propertyNode.type) continue;
614
- const keyName = getPropName(propertyNode);
615
- if ('path' === keyName || 'panel' === keyName || 'page' === keyName) {
616
- const valueNode = propertyNode.value;
617
- if (isStringLiteral(valueNode)) {
618
- const resolved = resolveLiteralToOutput(valueNode.value, {
619
- manifestPath
620
- });
621
- rewriteValue(valueNode, resolved, valueNode.value);
622
- } else if (isStaticTemplate(valueNode)) {
623
- const raw = source.slice(valueNode.span.start + 1, valueNode.span.end - 1);
624
- const resolved = resolveLiteralToOutput(raw, {
625
- manifestPath
626
- });
627
- rewriteValue(valueNode, resolved, raw);
628
- } else {
629
- const raw = evalStaticString(valueNode);
630
- if ('string' == typeof raw) {
631
- const resolved = resolveLiteralToOutput(raw, {
632
- manifestPath
633
- });
634
- const originalExpr = source.slice(valueNode.span.start, valueNode.span.end);
635
- rewriteValue(valueNode, resolved, originalExpr);
636
- }
637
- }
638
- }
639
- }
640
- return true;
641
- }
642
- return false;
643
- }
644
- function handleNotifications(node, source, rewriteValue, manifestPath) {
645
- if ('CallExpression' !== node.type) return false;
646
- const memberChain = memberChainFromCallee(node.callee);
647
- const apiRoot = memberChain[0];
648
- if ('chrome' !== apiRoot && 'browser' !== apiRoot) return false;
649
- const method = memberChain.join('.');
650
- if (method.endsWith('notifications.create') || method.endsWith('notifications.update')) {
651
- const optionsArgument = node.arguments?.[1]?.expression || node.arguments?.[0]?.expression;
652
- if (optionsArgument?.type === 'ObjectExpression') {
653
- let touched = false;
654
- for (const propertyNode of optionsArgument.properties || []){
655
- if ('KeyValueProperty' !== propertyNode.type) continue;
656
- const keyName = getPropName(propertyNode);
657
- if ('iconUrl' === keyName || 'imageUrl' === keyName) {
658
- const valueNode = propertyNode.value;
659
- if (isStringLiteral(valueNode)) {
660
- const resolved = resolveLiteralToOutput(valueNode.value, {
661
- manifestPath
662
- });
663
- rewriteValue(valueNode, resolved, valueNode.value);
664
- touched = true;
665
- } else if (isStaticTemplate(valueNode)) {
666
- const raw = source.slice(valueNode.span.start + 1, valueNode.span.end - 1);
667
- const resolved = resolveLiteralToOutput(raw, {
668
- manifestPath
669
- });
670
- rewriteValue(valueNode, resolved, raw);
671
- touched = true;
672
- } else {
673
- const raw = evalStaticString(valueNode);
674
- if ('string' == typeof raw) {
675
- const resolved = resolveLiteralToOutput(raw, {
676
- manifestPath
677
- });
678
- const originalExpr = source.slice(valueNode.span.start, valueNode.span.end);
679
- rewriteValue(valueNode, resolved, originalExpr);
680
- touched = true;
681
- }
682
- }
683
- }
684
- }
685
- if (touched) return true;
686
- }
687
- }
688
- return false;
689
- }
690
- function handleMenus(node, source, rewriteValue, manifestPath) {
691
- if ('CallExpression' !== node.type) return false;
692
- const memberChain = memberChainFromCallee(node.callee);
693
- const apiRoot = memberChain[0];
694
- if ('chrome' !== apiRoot && 'browser' !== apiRoot) return false;
695
- const method = memberChain.join('.');
696
- if (method.endsWith('contextMenus.create') || method.endsWith('contextMenus.update') || method.endsWith('menus.create') || method.endsWith('menus.update')) {
697
- const firstArgument = node.arguments?.[0]?.expression;
698
- if (firstArgument?.type === 'ObjectExpression') for (const propertyNode of firstArgument.properties || []){
699
- if ('KeyValueProperty' !== propertyNode.type) continue;
700
- const keyNode = propertyNode.key;
701
- const keyName = keyNode?.type === 'Identifier' ? keyNode.value : keyNode?.value;
702
- if ('icons' !== keyName) continue;
703
- const valueNode = propertyNode.value;
704
- if (valueNode?.type === 'ObjectExpression') for (const innerProperty of valueNode.properties || []){
705
- if ('KeyValueProperty' !== innerProperty.type) continue;
706
- const innerValue = innerProperty.value;
707
- if (isStringLiteral(innerValue)) {
708
- const resolved = resolveLiteralToOutput(innerValue.value, {
709
- manifestPath
710
- });
711
- rewriteValue(innerValue, resolved, innerValue.value);
712
- } else if (isStaticTemplate(innerValue)) {
713
- const raw = source.slice(innerValue.span.start + 1, innerValue.span.end - 1);
714
- const resolved = resolveLiteralToOutput(raw, {
715
- manifestPath
716
- });
717
- rewriteValue(innerValue, resolved, raw);
718
- } else {
719
- const raw = evalStaticString(innerValue);
720
- if ('string' == typeof raw) {
721
- const resolved = resolveLiteralToOutput(raw, {
722
- manifestPath
723
- });
724
- const originalExpr = source.slice(innerValue.span.start, innerValue.span.end);
725
- rewriteValue(innerValue, resolved, originalExpr);
726
- }
727
- }
728
- }
729
- }
730
- return true;
731
- }
732
- return false;
733
- }
734
- function handleDeclarativeContent(node, source, rewriteValue, manifestPath) {
735
- if ('NewExpression' !== node.type) return false;
736
- const memberChain = memberChainFromCallee(node.callee);
737
- const apiRoot = memberChain[0];
738
- if ('chrome' !== apiRoot && 'browser' !== apiRoot) return false;
739
- const method = memberChain.join('.');
740
- if (method.endsWith('declarativeContent.SetIcon')) {
741
- const arg0 = node.arguments?.[0];
742
- const optionsArgument = arg0 && arg0.expression || arg0;
743
- if (optionsArgument?.type === 'ObjectExpression') for (const propertyNode of optionsArgument.properties || []){
744
- if ('KeyValueProperty' !== propertyNode.type) continue;
745
- const keyNode = propertyNode.key;
746
- const keyName = keyNode?.type === 'Identifier' ? keyNode.value : keyNode?.value;
747
- if ('path' !== keyName) continue;
748
- const valueNode = propertyNode.value;
749
- if (isStringLiteral(valueNode)) {
750
- const resolved = resolveLiteralToOutput(valueNode.value, {
751
- manifestPath
752
- });
753
- rewriteValue(valueNode, resolved, valueNode.value);
754
- } else if (valueNode?.type === 'ObjectExpression') for (const innerProperty of valueNode.properties || []){
755
- if ('KeyValueProperty' !== innerProperty.type) continue;
756
- const innerValue = innerProperty.value;
757
- if (isStringLiteral(innerValue)) {
758
- const resolved = resolveLiteralToOutput(innerValue.value, {
759
- manifestPath
760
- });
761
- rewriteValue(innerValue, resolved, innerValue.value);
762
- } else if (isStaticTemplate(innerValue)) {
763
- const raw = source.slice(innerValue.span.start + 1, innerValue.span.end - 1);
764
- const resolved = resolveLiteralToOutput(raw, {
765
- manifestPath
766
- });
767
- rewriteValue(innerValue, resolved, raw);
768
- } else {
769
- const raw = evalStaticString(innerValue);
770
- if ('string' == typeof raw) {
771
- const resolved = resolveLiteralToOutput(raw, {
772
- manifestPath
773
- });
774
- const originalExpr = source.slice(innerValue.span.start, innerValue.span.end);
775
- rewriteValue(innerValue, resolved, originalExpr);
776
- }
777
- }
778
- }
779
- else if (isStaticTemplate(valueNode)) {
780
- const raw = source.slice(valueNode.span.start + 1, valueNode.span.end - 1);
781
- const resolved = resolveLiteralToOutput(raw, {
782
- manifestPath
783
- });
784
- rewriteValue(valueNode, resolved, raw);
785
- } else {
786
- const raw = evalStaticString(valueNode);
787
- if ('string' == typeof raw) {
788
- const resolved = resolveLiteralToOutput(raw, {
789
- manifestPath
790
- });
791
- const originalExpr = source.slice(valueNode.span.start, valueNode.span.end);
792
- rewriteValue(valueNode, resolved, originalExpr);
793
- }
794
- }
795
- }
796
- return true;
797
- }
798
- return false;
799
- }
800
- const ALLOWED_KEYS = new Set([
801
- 'url',
802
- 'file',
803
- 'files',
804
- 'path',
805
- 'popup',
806
- 'panel',
807
- 'page',
808
- 'iconUrl',
809
- 'imageUrl',
810
- 'default_icon',
811
- 'default_popup',
812
- 'default_panel'
813
- ]);
814
- function processValue(valueNode, source, rewriteValue, manifestPath) {
815
- if (!valueNode) return;
816
- if (isStringLiteral(valueNode)) {
817
- const out = resolveLiteralToOutput(valueNode.value, {
818
- manifestPath
819
- });
820
- rewriteValue(valueNode, out, valueNode.value);
821
- return;
822
- }
823
- if (isStaticTemplate(valueNode)) {
824
- const raw = source.slice(valueNode.span.start + 1, valueNode.span.end - 1);
825
- const out = resolveLiteralToOutput(raw, {
826
- manifestPath
827
- });
828
- rewriteValue(valueNode, out, raw);
829
- return;
830
- }
831
- const raw = evalStaticString(valueNode);
832
- if ('string' == typeof raw) {
833
- const out = resolveLiteralToOutput(raw, {
834
- manifestPath
835
- });
836
- const originalExpr = source.slice(valueNode.span.start, valueNode.span.end);
837
- rewriteValue(valueNode, out, originalExpr);
838
- return;
839
- }
840
- }
841
- function walkCandidate(containerNode, onCandidateValue) {
842
- if (!containerNode) return;
843
- if ('ArrayExpression' === containerNode.type) {
844
- for (const elementNode of containerNode.elements || [])onCandidateValue(elementNode?.expression);
845
- return;
846
- }
847
- if ('ObjectExpression' === containerNode.type) for (const propertyNode of containerNode.properties || []){
848
- if ('KeyValueProperty' !== propertyNode.type) continue;
849
- const key = getPropName(propertyNode);
850
- if (key) {
851
- if (ALLOWED_KEYS.has(key)) onCandidateValue(propertyNode.value);
852
- if (propertyNode.value?.type === 'ArrayExpression' || propertyNode.value?.type === 'ObjectExpression') if (('default_icon' === key || 'path' === key) && propertyNode.value?.type === 'ObjectExpression') {
853
- for (const sizeProp of propertyNode.value.properties || [])if ('KeyValueProperty' === sizeProp.type) onCandidateValue(sizeProp.value);
854
- } else walkCandidate(propertyNode.value, onCandidateValue);
855
- }
856
- }
857
- }
858
- function handleGenericApiPaths(node, source, rewriteValue, manifestPath) {
859
- if ('CallExpression' !== node.type) return false;
860
- const memberChain = memberChainFromCallee(node.callee);
861
- const apiRoot = memberChain[0];
862
- if ('chrome' !== apiRoot && 'browser' !== apiRoot) return false;
863
- let touched = false;
864
- for (const argumentNode of node.arguments || []){
865
- const expressionNode = argumentNode?.expression;
866
- if (expressionNode) {
867
- if ('ObjectExpression' === expressionNode.type || 'ArrayExpression' === expressionNode.type) walkCandidate(expressionNode, (candidateValue)=>{
868
- const touchedBefore = touched;
869
- processValue(candidateValue, source, rewriteValue, manifestPath);
870
- if (!touchedBefore) touched = true;
871
- });
872
- }
873
- }
874
- return touched;
875
- }
876
- function handleCallExpression(node, source, rewriteValue, manifestPath) {
877
- if (handleRuntimeCalls(node, source, rewriteValue, manifestPath)) return;
878
- if (handleActionAndPopup(node, source, rewriteValue, manifestPath)) return;
879
- if (handleDevtools(node, source, rewriteValue, manifestPath)) return;
880
- if (handleTabsAndWindows(node, source, rewriteValue, manifestPath)) return;
881
- if (handleScripting(node, source, rewriteValue, manifestPath)) return;
882
- if (handleMv2Tabs(node, source, rewriteValue, manifestPath)) return;
883
- if (handlePanels(node, source, rewriteValue, manifestPath)) return;
884
- if (handleNotifications(node, source, rewriteValue, manifestPath)) return;
885
- if (handleMenus(node, source, rewriteValue, manifestPath)) return;
886
- if (handleDeclarativeContent(node, source, rewriteValue, manifestPath)) return;
887
- try {
888
- handleGenericApiPaths(node, source, rewriteValue, manifestPath);
889
- } catch {}
890
- }
891
- function isJsxLikePath(filePath) {
892
- return 'string' == typeof filePath && /\.[cm]?[jt]sx$/.test(String(filePath));
893
- }
894
- function stripNestedQuotes(value) {
895
- const match = /^(['"])(.*)\1$/.exec(value);
896
- return match ? match[2] : value;
897
- }
898
- function normalizeLiteralPayload(value) {
899
- const withForwardSlashes = value.replace(/\\/g, '/');
900
- const withCollapsed = withForwardSlashes.replace(/\/{2,}/g, '/');
901
- return stripNestedQuotes(withCollapsed);
902
- }
903
- function isLikelyApiContextAt(source, atIndex) {
904
- if ('number' != typeof atIndex) return false;
905
- const start = Math.max(0, atIndex - 200);
906
- const neighborhood = source.slice(start, atIndex);
907
- return /(chrome|browser)\s*\.(?:tabs|windows|scripting|action|sidePanel|sidebarAction|devtools|runtime|extension)\b/.test(neighborhood);
908
- }
909
- function resolveAndNormalizeLiteral(literal, ctx) {
910
- const normalizedInput = normalizeLiteralPayload(literal);
911
- const resolved = resolveLiteralToOutput(normalizedInput, {
912
- manifestPath: ctx.manifestPath,
913
- packageJsonDir: ctx.packageJsonDir,
914
- authorFilePath: ctx.authorFilePath
915
- });
916
- return normalizeLiteralPayload(resolved ?? normalizedInput);
917
- }
918
- function replaceRuntimeGetURL(source, input, ctx) {
919
- const rx = /(\.(?:runtime|extension)\.getURL\()\s*(['"])(.*?)\2(\))/g;
920
- function onMatch(full, pre, q, p, post, offset) {
921
- try {
922
- const resolved = resolveLiteralToOutput(normalizeLiteralPayload(p), {
923
- manifestPath: ctx.manifestPath,
924
- packageJsonDir: ctx.packageJsonDir,
925
- authorFilePath: ctx.authorFilePath
926
- });
927
- const computed = normalizeLiteralPayload(resolved ?? p);
928
- try {
929
- ctx.onResolvedLiteral?.(p, resolved ?? void 0, offset);
930
- } catch {}
931
- return `${pre}${q}${computed}${q}${post}`;
932
- } catch {
933
- return full;
934
- }
935
- }
936
- return input.replace(rx, onMatch);
937
- }
938
- function replaceObjectKeyLiterals(source, input, keys, ctx) {
939
- for (const key of keys){
940
- const rx = new RegExp(`(${key}\\s*:\\s*)(['"])(.*?)\\2`, 'g');
941
- function onMatch(full, pre, q, p, offset) {
942
- try {
943
- const resolved = resolveLiteralToOutput(normalizeLiteralPayload(p), {
944
- manifestPath: ctx.manifestPath,
945
- packageJsonDir: ctx.packageJsonDir,
946
- authorFilePath: ctx.authorFilePath
947
- });
948
- const computed = normalizeLiteralPayload(resolved ?? p);
949
- try {
950
- if (isLikelyApiContextAt(source, offset)) ctx.onResolvedLiteral?.(p, resolved ?? void 0, offset);
951
- } catch {}
952
- return `${pre}${q}${computed}${q}`;
953
- } catch {
954
- return full;
955
- }
956
- }
957
- input = input.replace(rx, onMatch);
958
- }
959
- return input;
960
- }
961
- function replaceStaticTemplateForKeys(source, input, keys, ctx) {
962
- const rx = new RegExp(`((?:${keys.join('|')})\\s*:\\s*)\`([^\\\`$]*)\``, 'g');
963
- function onMatch(full, pre, inner, offset) {
964
- try {
965
- const resolved = resolveLiteralToOutput(normalizeLiteralPayload(inner), {
966
- manifestPath: ctx.manifestPath,
967
- packageJsonDir: ctx.packageJsonDir,
968
- authorFilePath: ctx.authorFilePath
969
- });
970
- const computed = normalizeLiteralPayload(resolved ?? inner);
971
- try {
972
- if (isLikelyApiContextAt(source, offset)) ctx.onResolvedLiteral?.(inner, resolved ?? void 0, offset);
973
- } catch {}
974
- return `${pre}'${computed}'`;
975
- } catch {
976
- return full;
977
- }
978
- }
979
- return input.replace(rx, onMatch);
980
- }
981
- function replaceConcatForKeys(source, input, keys, ctx) {
982
- const rx = new RegExp(`((?:${keys.join('|')})\\s*:\\s*)((?:['"][^'"]*['"]\\s*\\+\\s*)+['"][^'"]*['"])`, 'g');
983
- function onMatch(full, pre, expr, offset) {
984
- try {
985
- const partRe = /(['"])([^'"]*?)\1/g;
986
- let m;
987
- let concatenated = '';
988
- while(m = partRe.exec(expr))concatenated += m[2];
989
- const resolved = resolveLiteralToOutput(normalizeLiteralPayload(concatenated), {
990
- manifestPath: ctx.manifestPath,
991
- packageJsonDir: ctx.packageJsonDir,
992
- authorFilePath: ctx.authorFilePath
993
- });
994
- const computed = normalizeLiteralPayload(resolved ?? concatenated);
995
- try {
996
- if (isLikelyApiContextAt(source, offset)) ctx.onResolvedLiteral?.(concatenated, resolved ?? void 0, offset);
997
- } catch {}
998
- return `${pre}'${computed}'`;
999
- } catch {
1000
- return full;
1001
- }
1002
- }
1003
- return input.replace(rx, onMatch);
1004
- }
1005
- function replaceFilesArray(source, input, ctx) {
1006
- const rx = /(files\s*:\s*\[)([^\]]*)(\])/g;
1007
- function onMatch(full, pre, inner, post, offset) {
1008
- try {
1009
- const replacedInner = inner.replace(/(['"])(.*?)(\1)/g, function(_m, q, p) {
1010
- try {
1011
- const computed = resolveAndNormalizeLiteral(p, ctx);
1012
- return `${q}${computed ?? p}${q}`;
1013
- } catch {
1014
- return `${q}${p}${q}`;
1015
- }
1016
- });
1017
- try {
1018
- if (isLikelyApiContextAt(source, offset)) {
1019
- const re = /(['"])(.*?)(\1)/g;
1020
- let match;
1021
- while(match = re.exec(inner)){
1022
- const raw = match[2];
1023
- const resolved = resolveLiteralToOutput(normalizeLiteralPayload(raw), {
1024
- manifestPath: ctx.manifestPath,
1025
- packageJsonDir: ctx.packageJsonDir,
1026
- authorFilePath: ctx.authorFilePath
1027
- });
1028
- ctx.onResolvedLiteral?.(raw, resolved ?? void 0, offset + match.index);
1029
- }
1030
- }
1031
- } catch {}
1032
- return `${pre}${replacedInner}${post}`;
1033
- } catch {
1034
- return full;
1035
- }
1036
- }
1037
- return input.replace(rx, onMatch);
1038
- }
1039
- function replaceJsCssArrays(source, input, ctx) {
1040
- for (const key of [
1041
- 'js',
1042
- 'css'
1043
- ]){
1044
- const rxArr = new RegExp(`(${key}\\s*:\\s*\\[)([^\\]]*)(\\])`, 'g');
1045
- function onMatch(full, pre, inner, post, offset) {
1046
- try {
1047
- const replacedInner = String(inner).replace(/(['"])(.*?)(\1)/g, function(_m, q, p) {
1048
- try {
1049
- const computed = resolveAndNormalizeLiteral(p, ctx);
1050
- return `${q}${computed ?? p}${q}`;
1051
- } catch {
1052
- return `${q}${p}${q}`;
1053
- }
1054
- });
1055
- try {
1056
- if (isLikelyApiContextAt(source, offset)) {
1057
- const re = /(['"])(.*?)(\1)/g;
1058
- let match;
1059
- while(match = re.exec(inner)){
1060
- const raw = match[2];
1061
- const resolved = resolveLiteralToOutput(normalizeLiteralPayload(raw), {
1062
- manifestPath: ctx.manifestPath,
1063
- packageJsonDir: ctx.packageJsonDir,
1064
- authorFilePath: ctx.authorFilePath
1065
- });
1066
- ctx.onResolvedLiteral?.(raw, resolved ?? void 0, offset + match.index);
1067
- }
1068
- }
1069
- } catch {}
1070
- return `${pre}${replacedInner}${post}`;
1071
- } catch {
1072
- return full;
1073
- }
1074
- }
1075
- input = input.replace(rxArr, onMatch);
1076
- }
1077
- return input;
1078
- }
1079
- function cleanupPublicRootLiterals(input) {
1080
- input = input.replace(/(['"])\/public\/([^'"]+?)\1/g, function(_m, q, p) {
1081
- return `${q}${normalizeLiteralPayload(p)}${q}`;
1082
- });
1083
- input = input.replace(/(['"])public\/(.*?)\1/g, function(_m, q, p) {
1084
- return `${q}${normalizeLiteralPayload(p)}${q}`;
1085
- });
1086
- return input;
1087
- }
1088
- function normalizeSpecialFolderExtensions(input) {
1089
- input = input.replace(/(['"])((?:pages|scripts)\/[^'"]+?)\.(ts|tsx)\1/g, function(_m, q, p) {
1090
- return `${q}${p}.js${q}`;
1091
- });
1092
- input = input.replace(/(['"])((?:pages|scripts)\/[^'"]+?)\.(njk|nunjucks)\1/g, function(_m, q, p) {
1093
- return `${q}${p}.html${q}`;
1094
- });
1095
- input = input.replace(/(['"])((?:pages|scripts)\/[^'"]+?)\.(scss|sass|less)\1/g, function(_m, q, p) {
1096
- return `${q}${p}.css${q}`;
1097
- });
1098
- return input;
1099
- }
1100
- function collapseAccidentalDoubleQuotes(input, keys) {
1101
- const keyUnion = `(?:${keys.join('|')})`;
1102
- input = input.replace(new RegExp(`(${keyUnion}\\s*:\\s*)''`, 'g'), "$1'");
1103
- input = input.replace(new RegExp(`(${keyUnion}\\s*:\\s*)""`, 'g'), '$1"');
1104
- input = input.replace(/:\s*''/g, ": '");
1105
- input = input.replace(/:\s*""/g, ': "');
1106
- input = input.replace(/:\s*''([^']+)'/g, ": '$1'");
1107
- input = input.replace(/:\s*\"\"([^\"]+)\"/g, ': "$1"');
1108
- input = input.replace(/''([^']*?)''/g, "'$1'");
1109
- input = input.replace(/""([^"]*?)""/g, '"$1"');
1110
- return input;
1111
- }
1112
- function textFallbackTransform(source, opts) {
1113
- let output = String(source);
1114
- const ctx = {
1115
- manifestPath: opts.manifestPath,
1116
- packageJsonDir: opts.packageJsonDir,
1117
- authorFilePath: opts.authorFilePath,
1118
- onResolvedLiteral: opts.onResolvedLiteral
1119
- };
1120
- output = replaceRuntimeGetURL(source, output, ctx);
1121
- const supportedKeys = [
1122
- 'url',
1123
- 'file',
1124
- 'path',
1125
- 'iconUrl',
1126
- 'imageUrl',
1127
- 'default_icon'
1128
- ];
1129
- output = replaceObjectKeyLiterals(source, output, supportedKeys, ctx);
1130
- output = replaceStaticTemplateForKeys(source, output, supportedKeys, ctx);
1131
- output = replaceConcatForKeys(source, output, supportedKeys, ctx);
1132
- output = replaceFilesArray(source, output, ctx);
1133
- output = replaceJsCssArrays(source, output, ctx);
1134
- if (!isJsxLikePath(opts.authorFilePath)) output = cleanupPublicRootLiterals(output);
1135
- output = normalizeSpecialFolderExtensions(output);
1136
- output = collapseAccidentalDoubleQuotes(output, supportedKeys);
1137
- return output;
1138
- }
1139
- const external_module_namespaceObject = require("module");
1140
- let swcRuntimeModule;
1141
- async function loadSwc() {
1142
- if (swcRuntimeModule) return swcRuntimeModule;
1143
- try {
1144
- const mod = await import("@swc/core");
1145
- swcRuntimeModule = mod?.default && mod.default.parse ? mod.default : mod;
1146
- } catch {
1147
- try {
1148
- const mod = __webpack_require__("@swc/core") || (0, external_module_namespaceObject.createRequire)(__filename)('@swc/core');
1149
- swcRuntimeModule = mod?.default && mod.default.parse ? mod.default : mod;
1150
- } catch {}
1151
- }
1152
- return swcRuntimeModule || null;
1153
- }
1154
- async function parseWithSwc(swc, source, flags) {
1155
- return swc.parse(source, {
1156
- syntax: flags.isTS ? "typescript" : "ecmascript",
1157
- tsx: flags.isTS && flags.isJSX,
1158
- jsx: !flags.isTS && flags.isJSX,
1159
- target: 'es2022',
1160
- isModule: true
1161
- });
1162
- }
1163
- async function resolvePathsLoader(source) {
1164
- const callback = this.async();
1165
- const options = this.getOptions?.() || {};
1166
- const manifestPath = options.manifestPath;
1167
- const packageJsonDir = options.packageJsonDir;
1168
- const outputPath = String(options.outputPath || '');
1169
- const sourceMapsOpt = 'boolean' == typeof options.sourceMaps || 'auto' === options.sourceMaps ? options.sourceMaps : 'auto';
1170
- this.cacheable && this.cacheable();
1171
- const emittedBodies = new Set();
1172
- const emitStandardWarning = (headerFilePath, bodyLines)=>{
1173
- const bodyMessage = bodyLines.join('\n');
1174
- if (emittedBodies.has(bodyMessage)) return;
1175
- emittedBodies.add(bodyMessage);
1176
- const warning = new Error(bodyMessage);
1177
- warning.file = headerFilePath;
1178
- this.emitWarning?.(warning);
1179
- };
1180
- const warnIfMissingPublic = (original, computed)=>{
1181
- try {
1182
- const canonical = unixify(original || '');
1183
- const authorUsedRoot = /^\//.test(canonical);
1184
- if (computed) {
1185
- if (/^(?:pages|scripts)\//i.test(computed)) return;
1186
- const root = packageJsonDir || external_path_namespaceObject.dirname(manifestPath);
1187
- const sourcePublicAbs = external_path_namespaceObject.join(root, 'public', computed);
1188
- if (!external_fs_namespaceObject.existsSync(sourcePublicAbs)) {
1189
- const displayPath = authorUsedRoot && outputPath ? external_path_namespaceObject.join(outputPath, computed) : sourcePublicAbs;
1190
- const lines = [
1191
- 'Check the path used in your extension API call.',
1192
- 'The path must point to an existing file that will be packaged with the extension.',
1193
- `Found value: ${original ?? ''}`,
1194
- `Resolved path: ${authorUsedRoot && outputPath ? external_path_namespaceObject.join(outputPath, computed) : sourcePublicAbs}`
1195
- ];
1196
- if (authorUsedRoot) lines.push("Paths starting with '/' are resolved from the extension output root (served from public/), not your source directory.");
1197
- lines.push('', `NOT FOUND ${displayPath}`);
1198
- emitStandardWarning(String(this.resourcePath), lines);
1199
- }
1200
- } else if (original) {
1201
- const looksNested = /(^|\/)src\/pages\//i.test(canonical) || /(^|\/)src\/scripts\//i.test(canonical);
1202
- if (looksNested) {
1203
- const root = packageJsonDir || external_path_namespaceObject.dirname(manifestPath);
1204
- const abs = external_path_namespaceObject.join(root, canonical);
1205
- const lines = [
1206
- 'Check the path used in your extension API call.',
1207
- 'The path must point to an existing file that will be packaged with the extension.',
1208
- `Found value: ${original}`
1209
- ];
1210
- lines.push('', `NOT FOUND ${abs}`);
1211
- emitStandardWarning(String(this.resourcePath), lines);
1212
- }
1213
- }
1214
- } catch {}
1215
- };
1216
- try {
1217
- const resourcePathUnix = unixify(String(this.resourcePath || ''));
1218
- if (resourcePathUnix.split('/').includes('public')) return callback(null, source);
1219
- } catch {}
1220
- try {
1221
- const sourceString = String(source);
1222
- const containsEligiblePatterns = /(?:^|[^A-Za-z0-9_$])(chrome|browser)\s*\./.test(sourceString) || /(?:^|[^A-Za-z0-9_$])(?:runtime|extension)\s*\.?\s*getURL\s*\(/.test(sourceString) || /(?:^|[^A-Za-z0-9_$])\/public\//.test(sourceString) || /(?:^|[^A-Za-z0-9_$])public\//.test(sourceString) || /(?:^|[^A-Za-z0-9_$])\/pages\//.test(sourceString) || /(?:^|[^A-Za-z0-9_$])pages\//.test(sourceString) || /(?:^|[^A-Za-z0-9_$])\/scripts\//.test(sourceString) || /(?:^|[^A-Za-z0-9_$])scripts\//.test(sourceString);
1223
- if (!containsEligiblePatterns) return callback(null, source);
1224
- } catch {}
1225
- let postTextSource;
1226
- try {
1227
- const out = textFallbackTransform(String(source), {
1228
- manifestPath,
1229
- packageJsonDir,
1230
- authorFilePath: String(this.resourcePath || ''),
1231
- onResolvedLiteral: (original, computed)=>warnIfMissingPublic(original, computed)
1232
- });
1233
- postTextSource = out;
1234
- const hasStaticTemplates = /`[^$`]*`/.test(out);
1235
- const hasBinaryConcats = /(['"`][^'"`]*['"`]\s*\+\s*['"`][^'"`]*['"`])/.test(out);
1236
- const hasApiRoots = /(?:^|[^A-Za-z0-9_$])(chrome|browser)\s*\./.test(out);
1237
- const needsStaticEval = (hasStaticTemplates || hasBinaryConcats) && hasApiRoots;
1238
- const enableMaps = 'auto' === sourceMapsOpt ? Boolean(this.sourceMap) : Boolean(sourceMapsOpt);
1239
- if (!needsStaticEval) {
1240
- if (out !== String(source) || enableMaps && /\.[cm]?tsx?$/.test(String(this.resourcePath || ''))) {
1241
- const msAll = new (external_magic_string_default())(String(source));
1242
- msAll.overwrite(0, String(source).length, out);
1243
- const map = enableMaps ? msAll.generateMap({
1244
- hires: true,
1245
- source: String(this.resourcePath),
1246
- includeContent: true
1247
- }) : void 0;
1248
- return callback(null, out, map);
1249
- }
1250
- }
1251
- } catch {}
1252
- const swc = await loadSwc();
1253
- if (!swc) return callback(null, source);
1254
- let programAst;
1255
- try {
1256
- const isTS = /\.[cm]?tsx?$/.test(this.resourcePath);
1257
- const isJSX = /\.[cm]?[jt]sx$/.test(this.resourcePath);
1258
- const parseSource = 'string' == typeof postTextSource ? postTextSource : source;
1259
- programAst = await parseWithSwc(swc, parseSource, {
1260
- isTS,
1261
- isJSX
1262
- });
1263
- } catch {
1264
- return callback(null, source);
1265
- }
1266
- const inputSource = 'string' == typeof postTextSource ? postTextSource : String(source);
1267
- const ms = new (external_magic_string_default())(inputSource);
1268
- let edited = false;
1269
- const rewriteValue = (node, computed, rawInput)=>{
1270
- if (!computed && 'string' == typeof rawInput) try {
1271
- const recomputed = resolveLiteralToOutput(rawInput, {
1272
- manifestPath,
1273
- packageJsonDir,
1274
- authorFilePath: String(this.resourcePath || '')
1275
- });
1276
- if (recomputed) computed = recomputed;
1277
- } catch {}
1278
- if (!computed) return;
1279
- try {
1280
- const span = node?.span;
1281
- if (span && 'number' == typeof span.start && 'number' == typeof span.end) {
1282
- const src = String(inputSource);
1283
- const before = src[span.start - 1];
1284
- const after = src[span.end];
1285
- const isQuote = (c)=>"'" === c || '"' === c;
1286
- if (isQuote(before) && before === after) {
1287
- let start = span.start - 1;
1288
- let end = span.end + 1;
1289
- const q = before;
1290
- const json = JSON.stringify(String(computed));
1291
- if ('"' === q) ms.overwrite(start, end, json);
1292
- else {
1293
- const inner = json.slice(1, -1).replace(/'/g, "\\'");
1294
- ms.overwrite(start, end, `'${inner}'`);
1295
- }
1296
- } else ms.overwrite(span.start, span.end, JSON.stringify(computed));
1297
- edited = true;
1298
- }
1299
- } catch {}
1300
- };
1301
- const walk = (currentNode)=>{
1302
- if (!currentNode || 'object' != typeof currentNode) return;
1303
- if ('CallExpression' === currentNode.type) try {
1304
- handleCallExpression(currentNode, String(inputSource), rewriteValue, manifestPath);
1305
- } catch {}
1306
- for(const key in currentNode){
1307
- if (!Object.prototype.hasOwnProperty.call(currentNode, key)) continue;
1308
- const childNode = currentNode[key];
1309
- if (childNode) {
1310
- if (Array.isArray(childNode)) childNode.forEach(walk);
1311
- else if (childNode && 'string' == typeof childNode.type) walk(childNode);
1312
- }
1313
- }
1314
- };
1315
- walk(programAst);
1316
- try {
1317
- if (!edited) {
1318
- if ('string' == typeof postTextSource && postTextSource !== String(source)) {
1319
- const enableMaps = 'auto' === sourceMapsOpt ? Boolean(this.sourceMap) : Boolean(sourceMapsOpt);
1320
- const msAll = new (external_magic_string_default())(String(source));
1321
- msAll.overwrite(0, String(source).length, postTextSource);
1322
- const map = enableMaps ? msAll.generateMap({
1323
- hires: true,
1324
- source: String(this.resourcePath),
1325
- includeContent: true
1326
- }) : void 0;
1327
- return callback(null, postTextSource, map);
1328
- }
1329
- return callback(null, source);
1330
- }
1331
- const enableMaps = 'auto' === sourceMapsOpt ? Boolean(this.sourceMap) : Boolean(sourceMapsOpt);
1332
- const code = ms.toString();
1333
- const map = enableMaps ? ms.generateMap({
1334
- hires: true,
1335
- source: String(this.resourcePath),
1336
- includeContent: true
1337
- }) : void 0;
1338
- return callback(null, code, map);
1339
- } catch {
1340
- return callback(null, source);
1341
- }
1342
- }
1343
- })();
1344
- exports["default"] = __webpack_exports__["default"];
1345
- for(var __rspack_i in __webpack_exports__)if (-1 === [
1346
- "default"
1347
- ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
1348
- Object.defineProperty(exports, '__esModule', {
1349
- value: true
1350
- });