This commit is contained in:
2025-09-19 14:25:20 +08:00
parent 269893a435
commit fbf3f77229
24949 changed files with 2839404 additions and 0 deletions

73
node_modules/webpack/lib/schemes/DataUriPlugin.js generated vendored Normal file
View File

@@ -0,0 +1,73 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
"use strict";
const NormalModule = require("../NormalModule");
/** @typedef {import("../Compiler")} Compiler */
// data URL scheme: "data:text/javascript;charset=utf-8;base64,some-string"
// http://www.ietf.org/rfc/rfc2397.txt
const URIRegEx = /^data:([^;,]+)?((?:;[^;,]+)*?)(?:;(base64)?)?,(.*)$/i;
/**
* @param {string} uri data URI
* @returns {Buffer | null} decoded data
*/
const decodeDataURI = (uri) => {
const match = URIRegEx.exec(uri);
if (!match) return null;
const isBase64 = match[3];
const body = match[4];
if (isBase64) {
return Buffer.from(body, "base64");
}
// CSS allows to use `data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg"><rect width="100%" height="100%" style="stroke: rgb(223,224,225); stroke-width: 2px; fill: none; stroke-dasharray: 6px 3px" /></svg>`
// so we return original body if we can't `decodeURIComponent`
try {
return Buffer.from(decodeURIComponent(body), "ascii");
} catch (_) {
return Buffer.from(body, "ascii");
}
};
const PLUGIN_NAME = "DataUriPlugin";
class DataUriPlugin {
/**
* Apply the plugin
* @param {Compiler} compiler the compiler instance
* @returns {void}
*/
apply(compiler) {
compiler.hooks.compilation.tap(
PLUGIN_NAME,
(compilation, { normalModuleFactory }) => {
normalModuleFactory.hooks.resolveForScheme
.for("data")
.tap(PLUGIN_NAME, (resourceData) => {
const match = URIRegEx.exec(resourceData.resource);
if (match) {
resourceData.data.mimetype = match[1] || "";
resourceData.data.parameters = match[2] || "";
resourceData.data.encoding = /** @type {"base64" | false} */ (
match[3] || false
);
resourceData.data.encodedContent = match[4] || "";
}
});
NormalModule.getCompilationHooks(compilation)
.readResourceForScheme.for("data")
.tap(PLUGIN_NAME, (resource) => decodeDataURI(resource));
}
);
}
}
module.exports = DataUriPlugin;

51
node_modules/webpack/lib/schemes/FileUriPlugin.js generated vendored Normal file
View File

@@ -0,0 +1,51 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
"use strict";
const { fileURLToPath } = require("url");
const { NormalModule } = require("..");
/** @typedef {import("../Compiler")} Compiler */
const PLUGIN_NAME = "FileUriPlugin";
class FileUriPlugin {
/**
* Apply the plugin
* @param {Compiler} compiler the compiler instance
* @returns {void}
*/
apply(compiler) {
compiler.hooks.compilation.tap(
PLUGIN_NAME,
(compilation, { normalModuleFactory }) => {
normalModuleFactory.hooks.resolveForScheme
.for("file")
.tap(PLUGIN_NAME, (resourceData) => {
const url = new URL(resourceData.resource);
const path = fileURLToPath(url);
const query = url.search;
const fragment = url.hash;
resourceData.path = path;
resourceData.query = query;
resourceData.fragment = fragment;
resourceData.resource = path + query + fragment;
return true;
});
const hooks = NormalModule.getCompilationHooks(compilation);
hooks.readResource
.for(undefined)
.tapAsync(PLUGIN_NAME, (loaderContext, callback) => {
const { resourcePath } = loaderContext;
loaderContext.addDependency(resourcePath);
loaderContext.fs.readFile(resourcePath, callback);
});
}
);
}
}
module.exports = FileUriPlugin;

1302
node_modules/webpack/lib/schemes/HttpUriPlugin.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

222
node_modules/webpack/lib/schemes/VirtualUrlPlugin.js generated vendored Normal file
View File

@@ -0,0 +1,222 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Natsu @xiaoxiaojx
*/
"use strict";
const { NormalModule } = require("..");
const ModuleNotFoundError = require("../ModuleNotFoundError");
const { parseResourceWithoutFragment } = require("../util/identifier");
/** @typedef {import("../Compiler")} Compiler */
/** @typedef {import("../NormalModule")} NormalModule */
/** @typedef {import("../Module").BuildInfo} BuildInfo */
/** @typedef {import("../Module").ValueCacheVersions} ValueCacheVersions */
/** @typedef {string | Set<string>} ValueCacheVersion */
/**
* @template T
* @typedef {import("../../declarations/LoaderContext").LoaderContext<T>} LoaderContext
*/
const PLUGIN_NAME = "VirtualUrlPlugin";
const DEFAULT_SCHEME = "virtual";
/**
* @typedef {object} VirtualModuleConfig
* @property {string=} type - The module type
* @property {(loaderContext: LoaderContext<EXPECTED_ANY>) => Promise<string> | string} source - The source function
* @property {(() => string) | true | string=} version - Optional version function or value
*/
/**
* @typedef {string | ((loaderContext: LoaderContext<EXPECTED_ANY>) => Promise<string> | string) | VirtualModuleConfig} VirtualModuleInput
*/
/** @typedef {{[key: string]: VirtualModuleInput}} VirtualModules */
/**
* Normalizes a virtual module definition into a standard format
* @param {VirtualModuleInput} virtualConfig The virtual module to normalize
* @returns {VirtualModuleConfig} The normalized virtual module
*/
function normalizeModule(virtualConfig) {
if (typeof virtualConfig === "string") {
return {
type: "",
source() {
return virtualConfig;
}
};
} else if (typeof virtualConfig === "function") {
return {
type: "",
source: virtualConfig
};
}
return virtualConfig;
}
/**
* Normalizes all virtual modules with the given scheme
* @param {VirtualModules} virtualConfigs The virtual modules to normalize
* @param {string} scheme The URL scheme to use
* @returns {{[key: string]: VirtualModuleConfig}} The normalized virtual modules
*/
function normalizeModules(virtualConfigs, scheme) {
return Object.keys(virtualConfigs).reduce((pre, id) => {
pre[toVid(id, scheme)] = normalizeModule(virtualConfigs[id]);
return pre;
}, /** @type {{[key: string]: VirtualModuleConfig}} */ ({}));
}
/**
* Converts a module id and scheme to a virtual module id
* @param {string} id The module id
* @param {string} scheme The URL scheme
* @returns {string} The virtual module id
*/
function toVid(id, scheme) {
return `${scheme}:${id}`;
}
const VALUE_DEP_VERSION = `webpack/${PLUGIN_NAME}/version`;
/**
* Converts a module id and scheme to a cache key
* @param {string} id The module id
* @param {string} scheme The URL scheme
* @returns {string} The cache key
*/
function toCacheKey(id, scheme) {
return `${VALUE_DEP_VERSION}/${toVid(id, scheme)}`;
}
/**
* @typedef {object} VirtualUrlPluginOptions
* @property {VirtualModules} modules - The virtual modules
* @property {string=} scheme - The URL scheme to use
*/
class VirtualUrlPlugin {
/**
* @param {VirtualModules} modules The virtual modules
* @param {string=} scheme The URL scheme to use
*/
constructor(modules, scheme) {
this.scheme = scheme || DEFAULT_SCHEME;
this.modules = normalizeModules(modules, this.scheme);
}
/**
* Apply the plugin
* @param {Compiler} compiler the compiler instance
* @returns {void}
*/
apply(compiler) {
const scheme = this.scheme;
const cachedParseResourceWithoutFragment =
parseResourceWithoutFragment.bindCache(compiler.root);
compiler.hooks.compilation.tap(
PLUGIN_NAME,
(compilation, { normalModuleFactory }) => {
normalModuleFactory.hooks.resolveForScheme
.for(scheme)
.tap(PLUGIN_NAME, (resourceData) => {
const virtualConfig = this.findVirtualModuleConfigById(
resourceData.resource
);
const url = cachedParseResourceWithoutFragment(
resourceData.resource
);
const path = url.path;
const type = virtualConfig.type;
resourceData.path = path + type;
resourceData.resource = path;
if (virtualConfig.version) {
const cacheKey = toCacheKey(resourceData.resource, scheme);
const cacheVersion = this.getCacheVersion(virtualConfig.version);
compilation.valueCacheVersions.set(
cacheKey,
/** @type {string} */ (cacheVersion)
);
}
return true;
});
const hooks = NormalModule.getCompilationHooks(compilation);
hooks.readResource
.for(scheme)
.tapAsync(PLUGIN_NAME, async (loaderContext, callback) => {
const { resourcePath } = loaderContext;
const module = /** @type {NormalModule} */ (loaderContext._module);
const cacheKey = toCacheKey(resourcePath, scheme);
const addVersionValueDependency = () => {
if (!module || !module.buildInfo) return;
const buildInfo = module.buildInfo;
if (!buildInfo.valueDependencies) {
buildInfo.valueDependencies = new Map();
}
const cacheVersion = compilation.valueCacheVersions.get(cacheKey);
if (compilation.valueCacheVersions.has(cacheKey)) {
buildInfo.valueDependencies.set(
cacheKey,
/** @type {string} */ (cacheVersion)
);
}
};
try {
const virtualConfig =
this.findVirtualModuleConfigById(resourcePath);
const content = await virtualConfig.source(loaderContext);
addVersionValueDependency();
callback(null, content);
} catch (err) {
callback(/** @type {Error} */ (err));
}
});
}
);
}
/**
* @param {string} id The module id
* @returns {VirtualModuleConfig} The virtual module config
*/
findVirtualModuleConfigById(id) {
const config = this.modules[id];
if (!config) {
throw new ModuleNotFoundError(
null,
new Error(`Can't resolve virtual module ${id}`),
{
name: `virtual module ${id}`
}
);
}
return config;
}
/**
* Get the cache version for a given version value
* @param {(() => string) | true | string} version The version value or function
* @returns {string | undefined} The cache version
*/
getCacheVersion(version) {
return version === true
? undefined
: (typeof version === "function" ? version() : version) || "unset";
}
}
VirtualUrlPlugin.DEFAULT_SCHEME = DEFAULT_SCHEME;
module.exports = VirtualUrlPlugin;