extension-develop 4.1.31 → 4.1.32
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/README.md +2 -0
- package/dist/105~0.mjs +1 -1
- package/dist/177~0.mjs +87 -19
- package/dist/273~0.mjs +13 -3
- package/dist/363~0.mjs +1874 -0
- package/dist/{896~0.mjs → 469~0.mjs} +116 -586
- package/dist/519~0.mjs +21 -8
- package/dist/616~0.mjs +1 -1
- package/dist/771~0.mjs +103 -0
- package/dist/832~0.mjs +229 -463
- package/dist/840~0.mjs +1189 -54
- package/dist/846~0.mjs +453 -0
- package/dist/852~0.mjs +8 -6
- package/dist/bridge.mjs +3 -2
- package/dist/command-preview.d.ts +1 -0
- package/dist/contract/codes.json +39 -29
- package/dist/contract/envelope.schema.json +16 -0
- package/dist/contract/golden.build.compile.json +20 -3
- package/dist/contract/golden.eval.csp-blocks-eval.page.json +15 -0
- package/dist/css-parse-guard-loader.mjs +3 -1
- package/dist/dead-css-url-loader.mjs +129 -13
- package/dist/dev-server/cleanup.d.ts +1 -1
- package/dist/dev-server/lifecycle-stream.d.ts +14 -3
- package/dist/dev-server/session-start-prune.d.ts +13 -0
- package/dist/dev-server~0.mjs +91 -14
- package/dist/ensure-hmr-for-scripts.js +4 -8
- package/dist/ensure-hmr-for-scripts.mjs +4 -8
- package/dist/extension-js-devtools/build-stamp.json +2 -2
- package/dist/extension-js-theme/build-stamp.json +2 -2
- package/dist/feature-scripts-content-script-wrapper.js +7 -4
- package/dist/feature-scripts-content-script-wrapper.mjs +7 -4
- package/dist/lib/build-summary.d.ts +4 -1
- package/dist/lib/coded-warnings.d.ts +3 -0
- package/dist/lib/compilation-diagnostics.d.ts +23 -0
- package/dist/lib/config-loader.d.ts +2 -2
- package/dist/lib/config-resolved-plugin.d.ts +3 -2
- package/dist/lib/corepack-registry.d.ts +3 -0
- package/dist/lib/diagnostic-code.d.ts +6 -0
- package/dist/lib/merge-options.d.ts +1 -0
- package/dist/lib/messages.d.ts +4 -1
- package/dist/lib/messaging.d.ts +12 -4
- package/dist/lib/output-files.d.ts +11 -0
- package/dist/lib/package-manager.d.ts +2 -2
- package/dist/module.mjs +2 -1
- package/dist/plugin-browsers/index.d.ts +1 -0
- package/dist/plugin-compatibility/compatibility-lib/free-browser-references.d.ts +9 -0
- package/dist/plugin-css/css-lib/dead-url-refs.d.ts +5 -1
- package/dist/plugin-css/css-lib/inline-content-script-css.d.ts +4 -2
- package/dist/plugin-css/css-lib/line-rewrite-source-map.d.ts +8 -0
- package/dist/plugin-css/dead-css-url-loader.d.ts +0 -2
- package/dist/plugin-css/public-css-url-loader.d.ts +8 -3
- package/dist/plugin-playwright/index.d.ts +9 -4
- package/dist/plugin-reload/classify-reload.d.ts +2 -0
- package/dist/plugin-reload/messages.d.ts +1 -0
- package/dist/plugin-reload/reload-lib/dev-content-scripts.d.ts +4 -0
- package/dist/plugin-reload/steps/prune-unreachable-chunks.d.ts +5 -0
- package/dist/plugin-special-folders/messages.d.ts +1 -1
- package/dist/plugin-special-folders/prune-removed-public-files.d.ts +7 -0
- package/dist/plugin-static-assets/check-namespace-imports.d.ts +4 -0
- package/dist/plugin-static-assets/static-assets-lib/asset-output-name.d.ts +8 -0
- package/dist/plugin-static-assets/static-assets-lib/messages.d.ts +1 -0
- package/dist/plugin-web-extension/feature-html/html-lib/utils.d.ts +2 -1
- package/dist/plugin-web-extension/feature-icons/messages.d.ts +1 -4
- package/dist/plugin-web-extension/feature-locales/get-locales.d.ts +2 -0
- package/dist/plugin-web-extension/feature-locales/messages.d.ts +3 -1
- package/dist/plugin-web-extension/feature-locales/validation.d.ts +1 -0
- package/dist/plugin-web-extension/feature-manifest/manifest-lib/filter-keys-safari.d.ts +1 -0
- package/dist/plugin-web-extension/feature-manifest/manifest-overrides/common/content_scripts.d.ts +1 -0
- package/dist/plugin-web-extension/feature-manifest/messages.d.ts +1 -0
- package/dist/plugin-web-extension/feature-scripts/index.d.ts +2 -0
- package/dist/plugin-web-extension/feature-scripts/messages.d.ts +4 -3
- package/dist/plugin-web-extension/feature-scripts/scripts-lib/load-time-constants.d.ts +11 -0
- package/dist/plugin-web-extension/feature-scripts/steps/trace-runtime-loaded-files.d.ts +4 -0
- package/dist/plugin-web-extension/feature-scripts/steps/warn-missing-build-constants.d.ts +24 -0
- package/dist/plugin-web-extension/feature-web-resources/web-resources-lib/declared-pages.d.ts +2 -0
- package/dist/plugin-web-extension/feature-web-resources/web-resources-lib/resolve-war.d.ts +5 -0
- package/dist/plugin-web-extension/index.d.ts +1 -0
- package/dist/plugin-web-extension/shared/classic-concat.d.ts +1 -0
- package/dist/plugin-web-extension/shared/compilation-issues.d.ts +1 -1
- package/dist/preprocessor-passthrough-loader.mjs +3 -1
- package/dist/public-css-url-loader.mjs +1 -1
- package/dist/rspack-config~0.mjs +4925 -5885
- package/dist/stats-handler~0.mjs +12 -4
- package/dist/types.d.ts +19 -2
- package/dist/zip~0.mjs +20 -2
- package/package.json +4 -4
- package/dist/300~0.mjs +0 -394
- package/dist/747~0.mjs +0 -90
package/dist/stats-handler~0.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire as __extjsCreateRequire } from "node:module"; const require = __extjsCreateRequire(import.meta.url);
|
|
2
|
-
import { prefix, isDebug } from "./852~0.mjs";
|
|
2
|
+
import { humanLine, prefix, isDebug } from "./852~0.mjs";
|
|
3
3
|
function scrubBrand(txt, brand = 'Extension.js') {
|
|
4
4
|
if (!txt) return txt;
|
|
5
5
|
const safeBrand = brand.replace(/\$/g, '$$$$');
|
|
@@ -18,8 +18,8 @@ function scrubBrand(txt, brand = 'Extension.js') {
|
|
|
18
18
|
function makeSanitizedConsole(brand = 'Extension.js') {
|
|
19
19
|
const sanitize = (a)=>'string' == typeof a ? scrubBrand(a, brand) : a;
|
|
20
20
|
return {
|
|
21
|
-
log: (...args)=>
|
|
22
|
-
info: (...args)=>
|
|
21
|
+
log: (...args)=>humanLine(...args.map(sanitize)),
|
|
22
|
+
info: (...args)=>humanLine(...args.map(sanitize)),
|
|
23
23
|
warn: (...args)=>console.warn(...args.map(sanitize)),
|
|
24
24
|
error: (...args)=>console.error(...args.map(sanitize))
|
|
25
25
|
};
|
|
@@ -104,6 +104,11 @@ function humanizeCaseMismatchBlocks(raw, showStack = isDebug()) {
|
|
|
104
104
|
}
|
|
105
105
|
return out.join('\n');
|
|
106
106
|
}
|
|
107
|
+
const MESSAGE_HEAD_PATTERN = /^[⚠×]\s/;
|
|
108
|
+
const LEADING_SPACE_PATTERN = new RegExp(`^((?:${ANSI_PATTERN.source})*)\\s+`);
|
|
109
|
+
function messageOfHead(line) {
|
|
110
|
+
return line.slice(line.indexOf(' in ') + 4).replace(LEADING_SPACE_PATTERN, '$1');
|
|
111
|
+
}
|
|
107
112
|
function wrapStatsBlocks(raw) {
|
|
108
113
|
const lines = String(raw || '').split('\n');
|
|
109
114
|
const wrapped = [];
|
|
@@ -113,11 +118,14 @@ function wrapStatsBlocks(raw) {
|
|
|
113
118
|
const errorHead = /^ERROR(?: in (.+))?$/.exec(plain);
|
|
114
119
|
const warningHead = /^WARNING(?: in (.+))?$/.exec(plain);
|
|
115
120
|
if (errorHead || warningHead) {
|
|
116
|
-
const
|
|
121
|
+
const subject = String((errorHead || warningHead)?.[1] || '').trim();
|
|
122
|
+
const headIsMessage = MESSAGE_HEAD_PATTERN.test(subject);
|
|
123
|
+
const file = headIsMessage ? '' : subject.replace(/\.$/, '');
|
|
117
124
|
const kind = errorHead ? 'error' : 'warning';
|
|
118
125
|
const channel = errorHead ? 'error' : 'warn';
|
|
119
126
|
const location = file ? ` in ${file}` : '';
|
|
120
127
|
wrapped.push(`${prefix(channel)} Build ${kind}${location}.`);
|
|
128
|
+
if (headIsMessage) wrapped.push(` ${messageOfHead(line)}`);
|
|
121
129
|
inBlock = true;
|
|
122
130
|
continue;
|
|
123
131
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -261,6 +261,12 @@ export interface BuildOptions {
|
|
|
261
261
|
* receipt names the command the user actually ran.
|
|
262
262
|
*/
|
|
263
263
|
metadataCommand?: 'dev' | 'start' | 'preview' | 'build';
|
|
264
|
+
/**
|
|
265
|
+
* Internal: `extension start` sets it when a browser launch follows the
|
|
266
|
+
* build, so the receipt stays `starting` with `compiledAt` set and only
|
|
267
|
+
* the launch phase stamps `ready`.
|
|
268
|
+
*/
|
|
269
|
+
launchFollows?: boolean;
|
|
264
270
|
appName?: SafariOptions['appName'];
|
|
265
271
|
bundleId?: SafariOptions['bundleId'];
|
|
266
272
|
developmentTeam?: SafariOptions['developmentTeam'];
|
|
@@ -525,7 +531,11 @@ export interface FileConfig {
|
|
|
525
531
|
* `browser.<vendor>.folders` and `commands.<name>.folders` override it.
|
|
526
532
|
*/
|
|
527
533
|
folders?: SpecialFoldersConfig;
|
|
528
|
-
|
|
534
|
+
/**
|
|
535
|
+
* Customizes the bundler config before the compiler is built. The second
|
|
536
|
+
* argument names the target browser, the bundler mode and the command.
|
|
537
|
+
*/
|
|
538
|
+
config?: (config: Configuration, context: ConfigHookContext) => Configuration;
|
|
529
539
|
/**
|
|
530
540
|
* Runs once the bundler config is final, right before the first build, with
|
|
531
541
|
* every loader rule attached. It can change `module`, `resolve`,
|
|
@@ -534,8 +544,15 @@ export interface FileConfig {
|
|
|
534
544
|
* `environment`. Every other key is fixed by then (`entry`, `plugins`,
|
|
535
545
|
* `mode`, `devtool`, `target`, `externals`, `output.path`, the rest of
|
|
536
546
|
* `optimization`): a change is ignored with a warning, use `config`.
|
|
547
|
+
* The second argument is the same context `config` receives.
|
|
537
548
|
*/
|
|
538
|
-
configResolved?: (config: Configuration) => Configuration | undefined | Promise<Configuration | undefined>;
|
|
549
|
+
configResolved?: (config: Configuration, context: ConfigHookContext) => Configuration | undefined | Promise<Configuration | undefined>;
|
|
550
|
+
}
|
|
551
|
+
/** What the `config` and `configResolved` hooks are told about the run. */
|
|
552
|
+
export interface ConfigHookContext {
|
|
553
|
+
browser: BrowserType;
|
|
554
|
+
mode: 'development' | 'production' | 'none';
|
|
555
|
+
command: 'dev' | 'build' | 'start' | 'preview';
|
|
539
556
|
}
|
|
540
557
|
export interface SpecialFoldersConfig {
|
|
541
558
|
scripts?: string | false;
|
package/dist/zip~0.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { createRequire as __extjsCreateRequire } from "node:module"; const require = __extjsCreateRequire(import.meta.url);
|
|
2
2
|
import { unzipSync } from "fflate";
|
|
3
|
-
import {
|
|
4
|
-
import { CODES } from "./852~0.mjs";
|
|
3
|
+
import { sessionArtifactsRootDir } from "./771~0.mjs";
|
|
4
|
+
import { humanLine, CODES } from "./852~0.mjs";
|
|
5
|
+
import { unpackagingExtension, notAZipArchive, remoteZipDamaged, failedToDownloadOrWriteZIPFileError, unpackagedSuccessfully, localZipNotFound, zipEntryOutsideFolder, downloadingText, localZipUnreadable, codedError, invalidRemoteZip, failedToWriteZIPFileError, remoteSourceDestinationTaken } from "./469~0.mjs";
|
|
5
6
|
import * as __rspack_external_node_fs_1b05aee1 from "node:fs";
|
|
6
7
|
import * as __rspack_external_node_path_806ed179 from "node:path";
|
|
7
8
|
function isZipBuffer(buffer) {
|
|
@@ -50,6 +51,19 @@ function writeEntries(entries, root) {
|
|
|
50
51
|
__rspack_external_node_fs_1b05aee1.writeFileSync(target, data);
|
|
51
52
|
}
|
|
52
53
|
}
|
|
54
|
+
function moveSessionArtifacts(from, to) {
|
|
55
|
+
const kept = sessionArtifactsRootDir(from);
|
|
56
|
+
if (!__rspack_external_node_fs_1b05aee1.existsSync(kept)) return;
|
|
57
|
+
const target = sessionArtifactsRootDir(to);
|
|
58
|
+
__rspack_external_node_fs_1b05aee1.rmSync(target, {
|
|
59
|
+
recursive: true,
|
|
60
|
+
force: true
|
|
61
|
+
});
|
|
62
|
+
__rspack_external_node_fs_1b05aee1.mkdirSync(__rspack_external_node_path_806ed179.dirname(target), {
|
|
63
|
+
recursive: true
|
|
64
|
+
});
|
|
65
|
+
__rspack_external_node_fs_1b05aee1.renameSync(kept, target);
|
|
66
|
+
}
|
|
53
67
|
function extractBuffer(entries, destinationPath) {
|
|
54
68
|
humanLine(unpackagingExtension(destinationPath));
|
|
55
69
|
const root = __rspack_external_node_path_806ed179.resolve(destinationPath);
|
|
@@ -64,6 +78,7 @@ function extractBuffer(entries, destinationPath) {
|
|
|
64
78
|
throw error;
|
|
65
79
|
}
|
|
66
80
|
try {
|
|
81
|
+
moveSessionArtifacts(root, staging);
|
|
67
82
|
__rspack_external_node_fs_1b05aee1.rmSync(root, {
|
|
68
83
|
recursive: true,
|
|
69
84
|
force: true
|
|
@@ -83,6 +98,9 @@ function extractBuffer(entries, destinationPath) {
|
|
|
83
98
|
});
|
|
84
99
|
}
|
|
85
100
|
} catch (error) {
|
|
101
|
+
try {
|
|
102
|
+
moveSessionArtifacts(staging, root);
|
|
103
|
+
} catch {}
|
|
86
104
|
__rspack_external_node_fs_1b05aee1.rmSync(staging, {
|
|
87
105
|
recursive: true,
|
|
88
106
|
force: true
|
package/package.json
CHANGED
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"runtime"
|
|
49
49
|
],
|
|
50
50
|
"name": "extension-develop",
|
|
51
|
-
"version": "4.1.
|
|
51
|
+
"version": "4.1.32",
|
|
52
52
|
"description": "Develop, build, preview, and package Extension.js projects.",
|
|
53
53
|
"author": {
|
|
54
54
|
"name": "Cezar Augusto",
|
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
"@rspack/dev-server": "2.1.0",
|
|
106
106
|
"@rspack/plugin-preact-refresh": "2.0.1",
|
|
107
107
|
"@rspack/plugin-react-refresh": "2.0.2",
|
|
108
|
-
"@vue/compiler-sfc": "3.5.
|
|
108
|
+
"@vue/compiler-sfc": "3.5.43",
|
|
109
109
|
"acorn": "^8.16.0",
|
|
110
110
|
"babel-loader": "10.1.1",
|
|
111
111
|
"babel-preset-solid": "1.9.15",
|
|
@@ -127,14 +127,14 @@
|
|
|
127
127
|
"postcss-loader": "8.2.1",
|
|
128
128
|
"postcss-preset-env": "11.1.1",
|
|
129
129
|
"postcss-scss": "4.0.9",
|
|
130
|
-
"preact": "
|
|
130
|
+
"preact": "11.0.0",
|
|
131
131
|
"prefers-yarn": "2.0.1",
|
|
132
132
|
"react-refresh": "0.18.0",
|
|
133
133
|
"sass-loader": "17.0.0",
|
|
134
134
|
"schema-utils": "^4.3.3",
|
|
135
135
|
"svelte-loader": "3.2.4",
|
|
136
136
|
"tiny-glob": "^0.2.9",
|
|
137
|
-
"vue": "3.5.
|
|
137
|
+
"vue": "3.5.43",
|
|
138
138
|
"vue-loader": "17.4.2",
|
|
139
139
|
"webextension-polyfill": "^0.12.0",
|
|
140
140
|
"webpack-merge": "^6.0.1",
|
package/dist/300~0.mjs
DELETED
|
@@ -1,394 +0,0 @@
|
|
|
1
|
-
import { createRequire as __extjsCreateRequire } from "node:module"; const require = __extjsCreateRequire(import.meta.url);
|
|
2
|
-
import { findPublicFile } from "./105~0.mjs";
|
|
3
|
-
import * as __rspack_external_node_fs_1b05aee1 from "node:fs";
|
|
4
|
-
import * as __rspack_external_node_path_806ed179 from "node:path";
|
|
5
|
-
import * as __rspack_external_parse5_utilities_4a00fdd6 from "parse5-utilities";
|
|
6
|
-
function normalizeManifestOutputPath(originalPath) {
|
|
7
|
-
if (!originalPath) return originalPath;
|
|
8
|
-
const unixPath = originalPath.replace(/\\/g, '/');
|
|
9
|
-
if (/^\/public\//i.test(unixPath)) return unixPath.replace(/^\/public\//i, '');
|
|
10
|
-
if (/^(?:\.\/)?public\//i.test(unixPath)) return unixPath.replace(/^(?:\.\/)?public\//i, '');
|
|
11
|
-
if (/^\//.test(unixPath)) return unixPath.replace(/^\//, '');
|
|
12
|
-
return unixPath;
|
|
13
|
-
}
|
|
14
|
-
function manifestPageOutputTarget(raw, compiledTarget, manifestPath, projectPath) {
|
|
15
|
-
const unixPath = raw.replace(/\\/g, '/');
|
|
16
|
-
if (/^(?:\/public\/|(?:\.\/)?public\/)/i.test(unixPath)) return normalizeManifestOutputPath(unixPath);
|
|
17
|
-
if (/^\//.test(unixPath)) {
|
|
18
|
-
const rest = unixPath.replace(/^\/+/, '');
|
|
19
|
-
if (manifestPath && rest) {
|
|
20
|
-
const manifestDir = __rspack_external_node_path_806ed179.dirname(manifestPath);
|
|
21
|
-
const inPublic = Boolean(findPublicFile(manifestPath, projectPath, rest));
|
|
22
|
-
const inRoot = __rspack_external_node_fs_1b05aee1.existsSync(__rspack_external_node_path_806ed179.join(manifestDir, rest));
|
|
23
|
-
if (inRoot && !inPublic) return compiledTarget;
|
|
24
|
-
}
|
|
25
|
-
return normalizeManifestOutputPath(unixPath);
|
|
26
|
-
}
|
|
27
|
-
const rest = unixPath.replace(/^\.\//, '');
|
|
28
|
-
if (!manifestPath || !rest || rest.split('/').includes('..')) return compiledTarget;
|
|
29
|
-
if (__rspack_external_node_fs_1b05aee1.existsSync(__rspack_external_node_path_806ed179.join(__rspack_external_node_path_806ed179.dirname(manifestPath), rest))) return compiledTarget;
|
|
30
|
-
if (findPublicFile(manifestPath, projectPath, rest)) return rest;
|
|
31
|
-
return compiledTarget;
|
|
32
|
-
}
|
|
33
|
-
function manifestJsonOutputTarget(raw, compiledTarget, manifestPath, projectPath) {
|
|
34
|
-
return manifestPageOutputTarget(raw, compiledTarget, manifestPath, projectPath);
|
|
35
|
-
}
|
|
36
|
-
function pathEscapesExtensionRoot(normalized) {
|
|
37
|
-
return !normalized || normalized.split('/').includes('..') || /^[A-Za-z]:/.test(normalized);
|
|
38
|
-
}
|
|
39
|
-
function externalAssetOutputPath(normalized, root) {
|
|
40
|
-
const unix = normalized.replace(/\\/g, '/');
|
|
41
|
-
const noDrive = unix.replace(/^([A-Za-z]):(?:\/|$)/, '_drive_$1/');
|
|
42
|
-
const safe = noDrive.split('/').map((segment)=>{
|
|
43
|
-
if ('..' === segment) return '_';
|
|
44
|
-
if ('.' === segment || !segment) return '';
|
|
45
|
-
return segment.replace(/[<>:"|?*\x00-\x1F]/g, '_');
|
|
46
|
-
}).filter(Boolean).join('/');
|
|
47
|
-
return safe ? `${root}/${safe}` : `${root}/external`;
|
|
48
|
-
}
|
|
49
|
-
function iconOutputPath(raw) {
|
|
50
|
-
if (/^(?:\/public\/|(?:\.\/)?public\/)/i.test(raw)) return normalizeManifestOutputPath(raw);
|
|
51
|
-
const normalized = normalizeManifestOutputPath(raw).replace(/^\.\//, '');
|
|
52
|
-
if (!pathEscapesExtensionRoot(normalized)) return normalized;
|
|
53
|
-
return externalAssetOutputPath(normalized, 'icons');
|
|
54
|
-
}
|
|
55
|
-
function themeIconOutputPath(raw, folder) {
|
|
56
|
-
return featureAssetOutputPath(raw, folder);
|
|
57
|
-
}
|
|
58
|
-
function themeImageOutputPath(raw) {
|
|
59
|
-
return featureAssetOutputPath(raw, 'theme/images');
|
|
60
|
-
}
|
|
61
|
-
function featureAssetOutputPath(raw, folder) {
|
|
62
|
-
if (/^(?:\/public\/|(?:\.\/)?public\/)/i.test(raw)) return normalizeManifestOutputPath(raw);
|
|
63
|
-
const normalized = normalizeManifestOutputPath(raw).replace(/^\.\//, '');
|
|
64
|
-
if (!pathEscapesExtensionRoot(normalized)) return `${folder}/${normalized}`;
|
|
65
|
-
return externalAssetOutputPath(normalized, folder);
|
|
66
|
-
}
|
|
67
|
-
function isUrl(src) {
|
|
68
|
-
try {
|
|
69
|
-
new URL(src);
|
|
70
|
-
return true;
|
|
71
|
-
} catch (err) {
|
|
72
|
-
return false;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
function emitSrcsetCandidates(srcset, node, assetType, attributeName, onResourceFound) {
|
|
76
|
-
for (const candidate of srcset.split(',')){
|
|
77
|
-
const url = candidate.trim().split(/\s+/)[0];
|
|
78
|
-
if (!url) continue;
|
|
79
|
-
const { cleanPath } = cleanAssetUrl(url);
|
|
80
|
-
if (cleanPath && !isUrl(cleanPath)) onResourceFound({
|
|
81
|
-
filePath: url,
|
|
82
|
-
childNode: node,
|
|
83
|
-
assetType,
|
|
84
|
-
attributeName
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
function parseHtml(node, onResourceFound) {
|
|
89
|
-
if ('#comment' === node.nodeName || '#text' === node.nodeName) return;
|
|
90
|
-
if ("script" === node.nodeName) {
|
|
91
|
-
const src = node.attrs?.find((attr)=>'src' === attr.name)?.value;
|
|
92
|
-
if (!src) return;
|
|
93
|
-
if (isUrl(src)) return;
|
|
94
|
-
onResourceFound({
|
|
95
|
-
filePath: src,
|
|
96
|
-
childNode: node,
|
|
97
|
-
assetType: "script"
|
|
98
|
-
});
|
|
99
|
-
} else if ('link' === node.nodeName) {
|
|
100
|
-
const href = node.attrs?.find((attr)=>'href' === attr.name)?.value;
|
|
101
|
-
const rel = node.attrs?.find((attr)=>'rel' === attr.name)?.value;
|
|
102
|
-
const imagesrcset = node.attrs?.find((attr)=>'imagesrcset' === attr.name)?.value;
|
|
103
|
-
if (imagesrcset) emitSrcsetCandidates(imagesrcset, node, 'staticHref', 'imagesrcset', onResourceFound);
|
|
104
|
-
if (!href) return;
|
|
105
|
-
if (isUrl(href)) return;
|
|
106
|
-
const nonStylesheetRelTokens = [
|
|
107
|
-
'dns-prefetch',
|
|
108
|
-
'icon',
|
|
109
|
-
'apple-touch-icon',
|
|
110
|
-
'apple-touch-icon-precomposed',
|
|
111
|
-
'mask-icon',
|
|
112
|
-
'manifest',
|
|
113
|
-
'modulepreload',
|
|
114
|
-
'preconnect',
|
|
115
|
-
'prefetch',
|
|
116
|
-
'preload',
|
|
117
|
-
'prerender'
|
|
118
|
-
];
|
|
119
|
-
const relTokens = rel ? rel.toLowerCase().split(/\s+/) : [];
|
|
120
|
-
onResourceFound(relTokens.some((token)=>nonStylesheetRelTokens.includes(token)) ? {
|
|
121
|
-
filePath: href,
|
|
122
|
-
childNode: node,
|
|
123
|
-
assetType: 'staticHref',
|
|
124
|
-
attributeName: 'href'
|
|
125
|
-
} : {
|
|
126
|
-
filePath: href,
|
|
127
|
-
childNode: node,
|
|
128
|
-
assetType: 'css'
|
|
129
|
-
});
|
|
130
|
-
} else if ('audio' === node.nodeName || 'embed' === node.nodeName || 'iframe' === node.nodeName || 'img' === node.nodeName || 'input' === node.nodeName || 'source' === node.nodeName || 'track' === node.nodeName || 'video' === node.nodeName) {
|
|
131
|
-
const src = node.attrs?.find((attr)=>'src' === attr.name)?.value;
|
|
132
|
-
if (src && !isUrl(src)) onResourceFound({
|
|
133
|
-
filePath: src,
|
|
134
|
-
childNode: node,
|
|
135
|
-
assetType: 'staticSrc',
|
|
136
|
-
attributeName: 'src'
|
|
137
|
-
});
|
|
138
|
-
const srcset = node.attrs?.find((attr)=>'srcset' === attr.name)?.value;
|
|
139
|
-
if (srcset) emitSrcsetCandidates(srcset, node, 'staticSrc', 'srcset', onResourceFound);
|
|
140
|
-
if ('video' === node.nodeName) {
|
|
141
|
-
const poster = node.attrs?.find((attr)=>'poster' === attr.name)?.value;
|
|
142
|
-
if (poster && !isUrl(poster)) onResourceFound({
|
|
143
|
-
filePath: poster,
|
|
144
|
-
childNode: node,
|
|
145
|
-
assetType: 'staticSrc',
|
|
146
|
-
attributeName: 'poster'
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
const { childNodes = [] } = node;
|
|
151
|
-
for (const childNode of childNodes)if ('#comment' !== childNode.nodeName && '#text' !== childNode.nodeName) parseHtml(childNode, onResourceFound);
|
|
152
|
-
}
|
|
153
|
-
const cloneParsedHtmlAsset = (assets)=>({
|
|
154
|
-
css: [
|
|
155
|
-
...assets.css || []
|
|
156
|
-
],
|
|
157
|
-
js: [
|
|
158
|
-
...assets.js || []
|
|
159
|
-
],
|
|
160
|
-
moduleJs: [
|
|
161
|
-
...assets.moduleJs || []
|
|
162
|
-
],
|
|
163
|
-
static: [
|
|
164
|
-
...assets.static || []
|
|
165
|
-
],
|
|
166
|
-
authored: {
|
|
167
|
-
...assets.authored || {}
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
const assetsFromHtmlCache = new Map();
|
|
171
|
-
function getAssetsFromHtml(htmlFilePath, htmlContent) {
|
|
172
|
-
const assets = {
|
|
173
|
-
css: [],
|
|
174
|
-
js: [],
|
|
175
|
-
moduleJs: [],
|
|
176
|
-
static: [],
|
|
177
|
-
authored: {}
|
|
178
|
-
};
|
|
179
|
-
if (!htmlFilePath) return assets;
|
|
180
|
-
let cacheKey;
|
|
181
|
-
if (void 0 === htmlContent) try {
|
|
182
|
-
const stat = __rspack_external_node_fs_1b05aee1.statSync(htmlFilePath);
|
|
183
|
-
cacheKey = `${stat.mtimeMs}:${stat.size}`;
|
|
184
|
-
const cached = assetsFromHtmlCache.get(htmlFilePath);
|
|
185
|
-
if (cached && cached.key === cacheKey) return cloneParsedHtmlAsset(cached.assets);
|
|
186
|
-
} catch {
|
|
187
|
-
cacheKey = void 0;
|
|
188
|
-
}
|
|
189
|
-
try {
|
|
190
|
-
const htmlString = htmlContent || __rspack_external_node_fs_1b05aee1.readFileSync(htmlFilePath, {
|
|
191
|
-
encoding: 'utf8'
|
|
192
|
-
});
|
|
193
|
-
if (!htmlString) return assets;
|
|
194
|
-
const htmlDocument = __rspack_external_parse5_utilities_4a00fdd6.parse(htmlString);
|
|
195
|
-
const baseHref = getBaseHref(htmlDocument);
|
|
196
|
-
const getAbsolutePath = (htmlFilePath, filePathWithParts)=>{
|
|
197
|
-
const { cleanPath } = cleanAssetUrl(filePathWithParts);
|
|
198
|
-
return resolveHtmlRefPath(htmlFilePath, baseHref, cleanPath);
|
|
199
|
-
};
|
|
200
|
-
parseHtml(htmlDocument, ({ filePath, childNode, assetType })=>{
|
|
201
|
-
const fileAbsolutePath = getAbsolutePath(htmlFilePath, filePath);
|
|
202
|
-
switch(assetType){
|
|
203
|
-
case "script":
|
|
204
|
-
{
|
|
205
|
-
assets.js?.push(fileAbsolutePath);
|
|
206
|
-
const scriptType = childNode?.attrs?.find((attr)=>'type' === attr.name)?.value;
|
|
207
|
-
if ('module' === String(scriptType || '').toLowerCase()) assets.moduleJs?.push(fileAbsolutePath);
|
|
208
|
-
break;
|
|
209
|
-
}
|
|
210
|
-
case 'css':
|
|
211
|
-
assets.css?.push(fileAbsolutePath);
|
|
212
|
-
break;
|
|
213
|
-
case 'staticSrc':
|
|
214
|
-
case 'staticHref':
|
|
215
|
-
if (!filePath.trim() || filePath.startsWith('#')) break;
|
|
216
|
-
assets.static?.push(fileAbsolutePath);
|
|
217
|
-
if (assets.authored && !(fileAbsolutePath in assets.authored)) assets.authored[fileAbsolutePath] = filePath;
|
|
218
|
-
break;
|
|
219
|
-
default:
|
|
220
|
-
break;
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
} catch (error) {
|
|
224
|
-
const code = error?.code;
|
|
225
|
-
if (void 0 === htmlContent && 'ENOENT' === code) {
|
|
226
|
-
assetsFromHtmlCache.delete(htmlFilePath);
|
|
227
|
-
throw error;
|
|
228
|
-
}
|
|
229
|
-
return assets;
|
|
230
|
-
}
|
|
231
|
-
if (cacheKey) assetsFromHtmlCache.set(htmlFilePath, {
|
|
232
|
-
key: cacheKey,
|
|
233
|
-
assets: cloneParsedHtmlAsset(assets)
|
|
234
|
-
});
|
|
235
|
-
return assets;
|
|
236
|
-
}
|
|
237
|
-
function getHtmlPageDeclaredAssetPath(filepathList, filePath, extension) {
|
|
238
|
-
const entryname = Object.keys(filepathList).find((key)=>{
|
|
239
|
-
const includePath = filepathList[key];
|
|
240
|
-
if (includePath === filePath) return true;
|
|
241
|
-
if (!includePath || !__rspack_external_node_fs_1b05aee1.existsSync(includePath)) return false;
|
|
242
|
-
const assets = getAssetsFromHtml(includePath);
|
|
243
|
-
return Boolean(assets?.js?.includes(filePath) || assets?.css?.includes(filePath));
|
|
244
|
-
}) || '';
|
|
245
|
-
const extname = getExtname(filePath);
|
|
246
|
-
if (!entryname) return `${filePath.replace(extname, '')}${extension}`;
|
|
247
|
-
return `/${entryname.replace(extname, '')}${extension}`;
|
|
248
|
-
}
|
|
249
|
-
function getExtname(filePath) {
|
|
250
|
-
return __rspack_external_node_path_806ed179.extname(filePath);
|
|
251
|
-
}
|
|
252
|
-
function getFilePath(filePath, extension, isPublic) {
|
|
253
|
-
if (isPublic) return `/${filePath}${extension}`;
|
|
254
|
-
return `${filePath}${extension}`;
|
|
255
|
-
}
|
|
256
|
-
function isFromIncludeList(filePath, includeList) {
|
|
257
|
-
return Object.values(includeList || {}).some((value)=>value === filePath);
|
|
258
|
-
}
|
|
259
|
-
function utils_isUrl(src) {
|
|
260
|
-
try {
|
|
261
|
-
new URL(src);
|
|
262
|
-
return true;
|
|
263
|
-
} catch (err) {
|
|
264
|
-
return false;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
function resolveStaticAttributeName(assetType, attributeName) {
|
|
268
|
-
if (attributeName) return attributeName;
|
|
269
|
-
return 'staticSrc' === assetType ? 'src' : 'href';
|
|
270
|
-
}
|
|
271
|
-
function rewriteSrcsetCandidate(srcset, fromCleanPath, toUrl) {
|
|
272
|
-
return srcset.split(',').map((candidate)=>{
|
|
273
|
-
const match = candidate.match(/^(\s*)(\S+)(.*)$/);
|
|
274
|
-
if (!match) return candidate;
|
|
275
|
-
const [, lead, url, rest] = match;
|
|
276
|
-
const { cleanPath } = cleanAssetUrl(url);
|
|
277
|
-
if (cleanPath !== fromCleanPath && url !== fromCleanPath) return candidate;
|
|
278
|
-
return `${lead}${toUrl}${rest}`;
|
|
279
|
-
}).join(',');
|
|
280
|
-
}
|
|
281
|
-
function applyRewrittenStaticUrl(node, attributeName, cleanPath, value) {
|
|
282
|
-
if ('srcset' === attributeName || 'imagesrcset' === attributeName) {
|
|
283
|
-
const current = __rspack_external_parse5_utilities_4a00fdd6.getAttribute(node, attributeName) || '';
|
|
284
|
-
return __rspack_external_parse5_utilities_4a00fdd6.setAttribute(node, attributeName, rewriteSrcsetCandidate(current, cleanPath, value));
|
|
285
|
-
}
|
|
286
|
-
return __rspack_external_parse5_utilities_4a00fdd6.setAttribute(node, attributeName, value);
|
|
287
|
-
}
|
|
288
|
-
function cleanAssetUrl(url) {
|
|
289
|
-
const hashIndex = url.indexOf('#');
|
|
290
|
-
const queryIndex = url.indexOf('?');
|
|
291
|
-
let endIndex = url.length;
|
|
292
|
-
if (-1 !== hashIndex && -1 !== queryIndex) endIndex = Math.min(hashIndex, queryIndex);
|
|
293
|
-
else if (-1 !== hashIndex) endIndex = hashIndex;
|
|
294
|
-
else if (-1 !== queryIndex) endIndex = queryIndex;
|
|
295
|
-
const cleanPath = url.slice(0, endIndex);
|
|
296
|
-
const hash = -1 !== hashIndex ? url.slice(hashIndex) : '';
|
|
297
|
-
const search = -1 !== queryIndex ? url.slice(queryIndex, -1 !== hashIndex ? hashIndex : void 0) : '';
|
|
298
|
-
return {
|
|
299
|
-
cleanPath,
|
|
300
|
-
hash,
|
|
301
|
-
search
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
function isHttpLike(inputUrl) {
|
|
305
|
-
return /^https?:\/\//i.test(inputUrl) || inputUrl.startsWith('//');
|
|
306
|
-
}
|
|
307
|
-
function isSpecialScheme(u) {
|
|
308
|
-
return /^(data:|blob:|chrome-extension:|javascript:|about:)/i.test(u);
|
|
309
|
-
}
|
|
310
|
-
function cleanLeading(s) {
|
|
311
|
-
return s.replace(/^\/+/, '').replace(/^\.\//, '').replace(/^\./, '');
|
|
312
|
-
}
|
|
313
|
-
function joinEmittedAssetName(prefix, rel) {
|
|
314
|
-
const parts = __rspack_external_node_path_806ed179.posix.join(prefix, rel).split('/');
|
|
315
|
-
let i = 0;
|
|
316
|
-
while(i < parts.length && ('..' === parts[i] || '.' === parts[i]))i++;
|
|
317
|
-
return parts.slice(i).join('/') || __rspack_external_node_path_806ed179.posix.basename(rel);
|
|
318
|
-
}
|
|
319
|
-
function htmlStaticAssetOutputName(manifestDir, htmlEntry, absolutePath) {
|
|
320
|
-
if ('string' == typeof manifestDir && manifestDir) {
|
|
321
|
-
const rel = __rspack_external_node_path_806ed179.relative(manifestDir, absolutePath);
|
|
322
|
-
if (rel && !__rspack_external_node_path_806ed179.isAbsolute(rel)) {
|
|
323
|
-
const posix = rel.split(__rspack_external_node_path_806ed179.sep).join('/');
|
|
324
|
-
const escapes = posix.split('/').includes('..');
|
|
325
|
-
return escapes ? externalAssetOutputPath(posix, 'assets') : joinEmittedAssetName('assets', posix);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
return joinEmittedAssetName('assets', computePosixRelative(htmlEntry, absolutePath));
|
|
329
|
-
}
|
|
330
|
-
function computePosixRelative(fromPath, toPath) {
|
|
331
|
-
const fromRoot = __rspack_external_node_path_806ed179.parse(fromPath).root;
|
|
332
|
-
const toRoot = __rspack_external_node_path_806ed179.parse(toPath).root;
|
|
333
|
-
if (fromRoot && toRoot && String(fromRoot).toLowerCase() !== String(toRoot).toLowerCase()) {
|
|
334
|
-
const base = __rspack_external_node_path_806ed179.basename(toPath);
|
|
335
|
-
return base.split(__rspack_external_node_path_806ed179.sep).join('/');
|
|
336
|
-
}
|
|
337
|
-
const rel = __rspack_external_node_path_806ed179.relative(__rspack_external_node_path_806ed179.dirname(fromPath), toPath) || toPath;
|
|
338
|
-
return rel.split(__rspack_external_node_path_806ed179.sep).join('/');
|
|
339
|
-
}
|
|
340
|
-
function resolveAbsoluteFsPath(params) {
|
|
341
|
-
const { asset, projectRoot, publicRootForResource, outputRoot, manifestRoot } = params;
|
|
342
|
-
const looksLikeRootUrl = asset.startsWith('/') && !(asset.startsWith(projectRoot) || asset.startsWith(publicRootForResource) || asset.startsWith(outputRoot));
|
|
343
|
-
const rootUrlIsClaimed = (value)=>{
|
|
344
|
-
const normalized = cleanLeading(value.slice(1));
|
|
345
|
-
const withoutPublicPrefix = normalized.replace(/^public\//, '');
|
|
346
|
-
if (__rspack_external_node_fs_1b05aee1.existsSync(__rspack_external_node_path_806ed179.join(publicRootForResource, withoutPublicPrefix))) return true;
|
|
347
|
-
return Boolean(manifestRoot && __rspack_external_node_fs_1b05aee1.existsSync(__rspack_external_node_path_806ed179.join(manifestRoot, normalized)));
|
|
348
|
-
};
|
|
349
|
-
const isRootUrl = looksLikeRootUrl && (rootUrlIsClaimed(asset) || !__rspack_external_node_fs_1b05aee1.existsSync(asset));
|
|
350
|
-
const isDotPublic = asset.startsWith('./public/');
|
|
351
|
-
const isPlainPublic = asset.startsWith('public/');
|
|
352
|
-
const absoluteFsPath = isRootUrl ? (()=>{
|
|
353
|
-
const rootRelative = asset.slice(1);
|
|
354
|
-
const normalized = cleanLeading(rootRelative);
|
|
355
|
-
const withoutPublicPrefix = normalized.replace(/^public\//, '');
|
|
356
|
-
const candidate = __rspack_external_node_path_806ed179.join(publicRootForResource, withoutPublicPrefix);
|
|
357
|
-
if (__rspack_external_node_fs_1b05aee1.existsSync(candidate)) return candidate;
|
|
358
|
-
const manifestCandidate = manifestRoot ? __rspack_external_node_path_806ed179.join(manifestRoot, normalized) : '';
|
|
359
|
-
if (manifestCandidate && __rspack_external_node_fs_1b05aee1.existsSync(manifestCandidate)) return manifestCandidate;
|
|
360
|
-
return manifestCandidate || candidate;
|
|
361
|
-
})() : isDotPublic ? __rspack_external_node_path_806ed179.join(projectRoot, cleanLeading(asset)) : isPlainPublic ? __rspack_external_node_path_806ed179.join(projectRoot, asset.replace(/^\./, '')) : __rspack_external_node_path_806ed179.isAbsolute(asset) ? asset : __rspack_external_node_path_806ed179.join(projectRoot, asset);
|
|
362
|
-
const relToPublic = __rspack_external_node_path_806ed179.relative(publicRootForResource, absoluteFsPath);
|
|
363
|
-
const isUnderPublicRoot = relToPublic && !relToPublic.startsWith('..') && !__rspack_external_node_path_806ed179.isAbsolute(relToPublic);
|
|
364
|
-
return {
|
|
365
|
-
absoluteFsPath,
|
|
366
|
-
isUnderPublicRoot: Boolean(isUnderPublicRoot),
|
|
367
|
-
isRootUrl
|
|
368
|
-
};
|
|
369
|
-
}
|
|
370
|
-
function resolveHtmlRefPath(htmlFilePath, baseHref, cleanPath) {
|
|
371
|
-
if (utils_isUrl(cleanPath)) return cleanPath;
|
|
372
|
-
if (cleanPath.startsWith('/')) return cleanPath;
|
|
373
|
-
const htmlDir = __rspack_external_node_path_806ed179.dirname(htmlFilePath);
|
|
374
|
-
const pageRelative = __rspack_external_node_path_806ed179.join(htmlDir, cleanPath);
|
|
375
|
-
if (!baseHref || utils_isUrl(baseHref)) return pageRelative;
|
|
376
|
-
const throughBase = __rspack_external_node_path_806ed179.join(htmlDir, baseHref, cleanPath);
|
|
377
|
-
if (__rspack_external_node_fs_1b05aee1.existsSync(throughBase) || !__rspack_external_node_fs_1b05aee1.existsSync(pageRelative)) return throughBase;
|
|
378
|
-
return pageRelative;
|
|
379
|
-
}
|
|
380
|
-
function getBaseHref(htmlDocument) {
|
|
381
|
-
return getBaseNode(htmlDocument)?.attrs?.find((a)=>'href' === a.name)?.value;
|
|
382
|
-
}
|
|
383
|
-
function getBaseNode(htmlDocument) {
|
|
384
|
-
const htmlChildren = htmlDocument.childNodes || [];
|
|
385
|
-
for (const node of htmlChildren)if (node?.nodeName === 'html') {
|
|
386
|
-
for (const child of node.childNodes || [])if (child?.nodeName === 'head') {
|
|
387
|
-
for (const headChild of child.childNodes || [])if (headChild?.nodeName === 'base') {
|
|
388
|
-
const href = headChild.attrs?.find((a)=>'href' === a.name)?.value;
|
|
389
|
-
if (href) return headChild;
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
export { applyRewrittenStaticUrl, cleanAssetUrl, cleanLeading, getAssetsFromHtml, getBaseHref, getBaseNode, getExtname, getFilePath, getHtmlPageDeclaredAssetPath, htmlStaticAssetOutputName, iconOutputPath, isFromIncludeList, isHttpLike, isSpecialScheme, manifestJsonOutputTarget, manifestPageOutputTarget, normalizeManifestOutputPath, parseHtml, resolveAbsoluteFsPath, resolveHtmlRefPath, resolveStaticAttributeName, themeIconOutputPath, themeImageOutputPath, utils_isUrl };
|
package/dist/747~0.mjs
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { createRequire as __extjsCreateRequire } from "node:module"; const require = __extjsCreateRequire(import.meta.url);
|
|
2
|
-
import { htmlStaticAssetOutputName } from "./300~0.mjs";
|
|
3
|
-
import { replaceCssUrlRefs, toPosixPath } from "./273~0.mjs";
|
|
4
|
-
import * as __rspack_external_node_fs_1b05aee1 from "node:fs";
|
|
5
|
-
import * as __rspack_external_node_path_806ed179 from "node:path";
|
|
6
|
-
const EXTENSION_ROOT_PLACEHOLDER = '__EXTENSIONJS_EXTENSION_ROOT__/';
|
|
7
|
-
function isFile(candidate) {
|
|
8
|
-
try {
|
|
9
|
-
return __rspack_external_node_fs_1b05aee1.statSync(candidate).isFile();
|
|
10
|
-
} catch {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
function resolveTarget(req, { resourcePath, manifestDir, publicRoot }) {
|
|
15
|
-
if (req.startsWith('/')) {
|
|
16
|
-
const rel = req.slice(1);
|
|
17
|
-
const fromPublic = __rspack_external_node_path_806ed179.join(publicRoot, rel);
|
|
18
|
-
if (isFile(fromPublic)) return {
|
|
19
|
-
absolutePath: fromPublic,
|
|
20
|
-
outputName: toPosixPath(__rspack_external_node_path_806ed179.normalize(rel)),
|
|
21
|
-
publicOwned: true
|
|
22
|
-
};
|
|
23
|
-
const fromManifest = __rspack_external_node_path_806ed179.join(manifestDir, rel);
|
|
24
|
-
if (!isFile(fromManifest)) return;
|
|
25
|
-
return {
|
|
26
|
-
absolutePath: fromManifest,
|
|
27
|
-
outputName: htmlStaticAssetOutputName(manifestDir, resourcePath, fromManifest),
|
|
28
|
-
publicOwned: false
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
const absolutePath = __rspack_external_node_path_806ed179.resolve(__rspack_external_node_path_806ed179.dirname(resourcePath), req);
|
|
32
|
-
if (!isFile(absolutePath)) return;
|
|
33
|
-
return {
|
|
34
|
-
absolutePath,
|
|
35
|
-
outputName: htmlStaticAssetOutputName(manifestDir, resourcePath, absolutePath),
|
|
36
|
-
publicOwned: false
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
function rewriteInlinedCssUrls(source, context) {
|
|
40
|
-
const targets = [];
|
|
41
|
-
const seen = new Map();
|
|
42
|
-
const css = replaceCssUrlRefs(source, (request)=>{
|
|
43
|
-
const suffixAt = request.search(/[?#]/);
|
|
44
|
-
const req = -1 === suffixAt ? request : request.slice(0, suffixAt);
|
|
45
|
-
const suffix = -1 === suffixAt ? '' : request.slice(suffixAt);
|
|
46
|
-
if (!req || req.startsWith('//') || /^[a-z][a-z0-9+.-]*:/i.test(req)) return;
|
|
47
|
-
if (req.startsWith('~') || req.startsWith('@')) return;
|
|
48
|
-
if (req.startsWith(EXTENSION_ROOT_PLACEHOLDER)) return;
|
|
49
|
-
let outputName = seen.get(req);
|
|
50
|
-
if (!outputName) {
|
|
51
|
-
const target = resolveTarget(req, context);
|
|
52
|
-
if (!target) return;
|
|
53
|
-
outputName = target.outputName;
|
|
54
|
-
seen.set(req, outputName);
|
|
55
|
-
targets.push({
|
|
56
|
-
request: req,
|
|
57
|
-
...target
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
return `${EXTENSION_ROOT_PLACEHOLDER}${outputName}${suffix}`;
|
|
61
|
-
});
|
|
62
|
-
return {
|
|
63
|
-
css,
|
|
64
|
-
targets
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
function toRuntimeStylesheetModule(css) {
|
|
68
|
-
return [
|
|
69
|
-
`var __extjsCssText = ${JSON.stringify(css)};`,
|
|
70
|
-
'function __extjsExtensionRoot() {',
|
|
71
|
-
' try {',
|
|
72
|
-
' var b = globalThis.browser;',
|
|
73
|
-
' if (typeof b === "object" && b && b.runtime && typeof b.runtime.getURL === "function") return String(b.runtime.getURL("/"));',
|
|
74
|
-
' } catch (error) {}',
|
|
75
|
-
' try {',
|
|
76
|
-
' var c = globalThis.chrome;',
|
|
77
|
-
' if (typeof c === "object" && c && c.runtime && typeof c.runtime.getURL === "function") return String(c.runtime.getURL("/"));',
|
|
78
|
-
' } catch (error) {}',
|
|
79
|
-
' try {',
|
|
80
|
-
' var base = (typeof globalThis === "object" && globalThis && globalThis.__EXTJS_EXTENSION_BASE__) ? String(globalThis.__EXTJS_EXTENSION_BASE__) : "";',
|
|
81
|
-
' if (!base && typeof document === "object" && document && document.documentElement) base = String(document.documentElement.getAttribute("data-extjs-extension-base") || "");',
|
|
82
|
-
' if (base) return base.replace(/\\/+$/, "") + "/";',
|
|
83
|
-
' } catch (error) {}',
|
|
84
|
-
' return "/";',
|
|
85
|
-
'}',
|
|
86
|
-
`module.exports = "data:text/css;charset=utf-8," + encodeURIComponent(__extjsCssText.split(${JSON.stringify(EXTENSION_ROOT_PLACEHOLDER)}).join(__extjsExtensionRoot()));`,
|
|
87
|
-
''
|
|
88
|
-
].join('\n');
|
|
89
|
-
}
|
|
90
|
-
export { EXTENSION_ROOT_PLACEHOLDER, rewriteInlinedCssUrls, toRuntimeStylesheetModule };
|