fix handling of new URL() in remote resources

This commit is contained in:
Tobias Koppers 2021-08-05 17:04:52 +02:00
parent 57dac0ea93
commit 30ebedd4dd
17 changed files with 30 additions and 4 deletions

View File

@ -62,6 +62,7 @@ class ExternalModuleFactoryPlugin {
const context = data.context;
const contextInfo = data.contextInfo;
const dependency = data.dependencies[0];
const dependencyType = data.dependencyType;
/**
* @param {string|string[]|boolean|Record<string, string|string[]>} value the external config
@ -172,7 +173,6 @@ class ExternalModuleFactoryPlugin {
cb
);
} else {
const dependencyType = dependency.category || "";
const promise = externals(
{
context,

View File

@ -46,6 +46,7 @@ const { parseResource } = require("./util/identifier");
* @property {string} request
* @property {Record<string, any> | undefined} assertions
* @property {ModuleDependency[]} dependencies
* @property {string} dependencyType
* @property {Object} createData
* @property {LazySet<string>} fileDependencies
* @property {LazySet<string>} missingDependencies
@ -345,6 +346,7 @@ class NormalModuleFactory extends ModuleFactory {
contextInfo,
context,
dependencies,
dependencyType,
request,
assertions,
resolveOptions,
@ -352,8 +354,6 @@ class NormalModuleFactory extends ModuleFactory {
missingDependencies,
contextDependencies
} = data;
const dependencyType =
(dependencies.length > 0 && dependencies[0].category) || "";
const loaderResolver = this.getResolver("loader");
/** @type {ResourceData | undefined} */
@ -757,6 +757,8 @@ class NormalModuleFactory extends ModuleFactory {
const fileDependencies = new LazySet();
const missingDependencies = new LazySet();
const contextDependencies = new LazySet();
const dependencyType =
(dependencies.length > 0 && dependencies[0].category) || "";
/** @type {ResolveData} */
const resolveData = {
contextInfo,
@ -765,6 +767,7 @@ class NormalModuleFactory extends ModuleFactory {
request,
assertions,
dependencies,
dependencyType,
fileDependencies,
missingDependencies,
contextDependencies,

View File

@ -906,7 +906,10 @@ Run build with un-frozen lockfile to automatically fix lockfile.`
.for(scheme)
.tapAsync("HttpUriPlugin", (resourceData, data, callback) => {
// Only handle relative urls (./xxx, ../xxx, /xxx, //xxx)
if (!/^\.{0,2}\//.test(resourceData.resource)) {
if (
data.dependencyType !== "url" &&
!/^\.{0,2}\//.test(resourceData.resource)
) {
return callback();
}
const url = new URL(resourceData.resource, data.context + "/");

View File

@ -1,5 +1,6 @@
{
"http://localhost:9990/asset.txt": { "integrity": "sha512-LHT9F+2v2A6ER7DUZ0HuJDt+t03SFJoKsbkkb7MDgvJ+hT2FhXGeDmfL2g2qj1FnEGRhXWRa4nrLFb+xRH9Fmw==", "contentType": "text/css" },
"http://localhost:9990/asset.txt?query": { "integrity": "sha512-LHT9F+2v2A6ER7DUZ0HuJDt+t03SFJoKsbkkb7MDgvJ+hT2FhXGeDmfL2g2qj1FnEGRhXWRa4nrLFb+xRH9Fmw==", "contentType": "text/css" },
"http://localhost:9990/fallback.js": { "integrity": "sha512-BCkBS4Wb0EreudEceuobqZZwTE7SeVUJ2vVHxDQKm8xW6dGJRcUrrSWcjd/61zijOeYAW0P+boOg7u0vxrGwYg==", "contentType": "text/javascript" },
"http://localhost:9990/folder/dependency.js": { "integrity": "sha512-N0En4W3aNPY82MPu16+50P4PqLLyPLI6l33wR2a3ue8VCRjY8RJl8erRB8ztWSEYNad7yRDPrqlYT+IBtoOA9w==", "contentType": "text/javascript" },
"http://localhost:9990/folder/sub-dependency.js": { "integrity": "sha512-Jjmwazwmg67EwNPViCBwvSIxhENfS6gwufXoQLrB0B/JDA4v1p+p2S5Y6IGP4SzZqqVTsROlU8meD6ep3q6MTA==", "contentType": "text/javascript" },
@ -10,6 +11,7 @@
"http://localhost:9990/redirect": { "resolved": "http://localhost:9990/redirect.js", "integrity": "sha512-BV/MK/QTq+NHRve1XpZyQ8V6cjRP/fwbtJvENRdm5C73qNYZ4i2/fw+soj7J4qxzBXMHDbvOnA6E0ShnX2hc1w==", "contentType": "text/javascript" },
"http://localhost:9990/redirect.js": { "integrity": "sha512-BV/MK/QTq+NHRve1XpZyQ8V6cjRP/fwbtJvENRdm5C73qNYZ4i2/fw+soj7J4qxzBXMHDbvOnA6E0ShnX2hc1w==", "contentType": "text/javascript" },
"http://localhost:9990/resolve.js": { "integrity": "sha512-6J9zBO2hXSMTO1EtXJOxSRB2nVPHCoNmNHS8an1QeehzJFc3uoBPRWu6hqHPc54gv2/QME9RBR/BXIan68virg==", "contentType": "text/javascript" },
"http://localhost:9990/url.js": { "integrity": "sha512-Dlw99Gtp/ZRxWvGlqD2EKnvbo1i6j/slwQO4WV8RIRhYZx9ErI+rndpyDMaKykSnq20HCp5H73TJ+dtO+wDyEg==", "contentType": "text/javascript" },
"https://raw.githubusercontent.com//webpack//webpack//main/CODE_OF_CONDUCT.md": { "resolved": "https://raw.githubusercontent.com/webpack/webpack/main/CODE_OF_CONDUCT.md", "integrity": "sha512-OLJ9q6iSO652hVBkTLsMLtQnFBBTzEbFqLGyWD62nPga/0DZ9bc3oOFb5OYT8RIPzmlOX4WzK2uiLgc1NSGtBA==", "contentType": "text/plain; charset=utf-8" },
"https://raw.githubusercontent.com/webpack/webpack/main/CODE_OF_CONDUCT.md": { "integrity": "sha512-OLJ9q6iSO652hVBkTLsMLtQnFBBTzEbFqLGyWD62nPga/0DZ9bc3oOFb5OYT8RIPzmlOX4WzK2uiLgc1NSGtBA==", "contentType": "text/plain; charset=utf-8" },
"version": 1

View File

@ -0,0 +1 @@
export default new URL("asset.txt?query", import.meta.url);

View File

@ -1,5 +1,6 @@
{
"http://localhost:9990/asset.txt": { "integrity": "sha512-LHT9F+2v2A6ER7DUZ0HuJDt+t03SFJoKsbkkb7MDgvJ+hT2FhXGeDmfL2g2qj1FnEGRhXWRa4nrLFb+xRH9Fmw==", "contentType": "text/css" },
"http://localhost:9990/asset.txt?query": { "integrity": "sha512-LHT9F+2v2A6ER7DUZ0HuJDt+t03SFJoKsbkkb7MDgvJ+hT2FhXGeDmfL2g2qj1FnEGRhXWRa4nrLFb+xRH9Fmw==", "contentType": "text/css" },
"http://localhost:9990/fallback.js": { "integrity": "sha512-BCkBS4Wb0EreudEceuobqZZwTE7SeVUJ2vVHxDQKm8xW6dGJRcUrrSWcjd/61zijOeYAW0P+boOg7u0vxrGwYg==", "contentType": "text/javascript" },
"http://localhost:9990/folder/dependency.js": { "integrity": "sha512-N0En4W3aNPY82MPu16+50P4PqLLyPLI6l33wR2a3ue8VCRjY8RJl8erRB8ztWSEYNad7yRDPrqlYT+IBtoOA9w==", "contentType": "text/javascript" },
"http://localhost:9990/folder/sub-dependency.js": { "integrity": "sha512-Jjmwazwmg67EwNPViCBwvSIxhENfS6gwufXoQLrB0B/JDA4v1p+p2S5Y6IGP4SzZqqVTsROlU8meD6ep3q6MTA==", "contentType": "text/javascript" },
@ -10,6 +11,7 @@
"http://localhost:9990/redirect": { "resolved": "http://localhost:9990/redirect.js", "integrity": "sha512-BV/MK/QTq+NHRve1XpZyQ8V6cjRP/fwbtJvENRdm5C73qNYZ4i2/fw+soj7J4qxzBXMHDbvOnA6E0ShnX2hc1w==", "contentType": "text/javascript" },
"http://localhost:9990/redirect.js": { "integrity": "sha512-BV/MK/QTq+NHRve1XpZyQ8V6cjRP/fwbtJvENRdm5C73qNYZ4i2/fw+soj7J4qxzBXMHDbvOnA6E0ShnX2hc1w==", "contentType": "text/javascript" },
"http://localhost:9990/resolve.js": { "integrity": "sha512-6J9zBO2hXSMTO1EtXJOxSRB2nVPHCoNmNHS8an1QeehzJFc3uoBPRWu6hqHPc54gv2/QME9RBR/BXIan68virg==", "contentType": "text/javascript" },
"http://localhost:9990/url.js": { "integrity": "sha512-Dlw99Gtp/ZRxWvGlqD2EKnvbo1i6j/slwQO4WV8RIRhYZx9ErI+rndpyDMaKykSnq20HCp5H73TJ+dtO+wDyEg==", "contentType": "text/javascript" },
"https://raw.githubusercontent.com//webpack//webpack//main/CODE_OF_CONDUCT.md": { "resolved": "https://raw.githubusercontent.com/webpack/webpack/main/CODE_OF_CONDUCT.md", "integrity": "sha512-OLJ9q6iSO652hVBkTLsMLtQnFBBTzEbFqLGyWD62nPga/0DZ9bc3oOFb5OYT8RIPzmlOX4WzK2uiLgc1NSGtBA==", "contentType": "text/plain; charset=utf-8" },
"https://raw.githubusercontent.com/webpack/webpack/main/CODE_OF_CONDUCT.md": { "integrity": "sha512-OLJ9q6iSO652hVBkTLsMLtQnFBBTzEbFqLGyWD62nPga/0DZ9bc3oOFb5OYT8RIPzmlOX4WzK2uiLgc1NSGtBA==", "contentType": "text/plain; charset=utf-8" },
"version": 1

View File

@ -0,0 +1 @@
export default new URL("asset.txt?query", import.meta.url);

View File

@ -6,6 +6,7 @@ import { fallback } from "http://localhost:9990/fallback.js";
import redirect1 from "http://localhost:9990/redirect";
import redirect2 from "http://localhost:9990/redirect.js";
import text from "http://localhost:9990/asset.txt";
import textUrl from "http://localhost:9990/url.js";
import codeOfConduct1 from "https://raw.githubusercontent.com//webpack//webpack//main/CODE_OF_CONDUCT.md";
import codeOfConduct2 from "https://raw.githubusercontent.com/webpack/webpack/main/CODE_OF_CONDUCT.md";
@ -20,6 +21,8 @@ it("http url request should be supported", () => {
expect(redirect2).toEqual({ ok: true });
expect(redirect2).not.toBe(redirect1);
expect(text.trim()).toBe("Hello World");
expect(textUrl instanceof URL).toBeTruthy();
expect(textUrl.href).toMatch(/^file:\/\/.+\.txt\?query$/);
});
it("https url request should be supported", () => {

View File

@ -1,5 +1,6 @@
{
"http://localhost:9990/asset.txt": { "integrity": "sha512-LHT9F+2v2A6ER7DUZ0HuJDt+t03SFJoKsbkkb7MDgvJ+hT2FhXGeDmfL2g2qj1FnEGRhXWRa4nrLFb+xRH9Fmw==", "contentType": "text/css" },
"http://localhost:9990/asset.txt?query": { "integrity": "sha512-LHT9F+2v2A6ER7DUZ0HuJDt+t03SFJoKsbkkb7MDgvJ+hT2FhXGeDmfL2g2qj1FnEGRhXWRa4nrLFb+xRH9Fmw==", "contentType": "text/css" },
"http://localhost:9990/fallback.js": { "integrity": "sha512-BCkBS4Wb0EreudEceuobqZZwTE7SeVUJ2vVHxDQKm8xW6dGJRcUrrSWcjd/61zijOeYAW0P+boOg7u0vxrGwYg==", "contentType": "text/javascript" },
"http://localhost:9990/folder/dependency.js": { "integrity": "sha512-N0En4W3aNPY82MPu16+50P4PqLLyPLI6l33wR2a3ue8VCRjY8RJl8erRB8ztWSEYNad7yRDPrqlYT+IBtoOA9w==", "contentType": "text/javascript" },
"http://localhost:9990/folder/sub-dependency.js": { "integrity": "sha512-Jjmwazwmg67EwNPViCBwvSIxhENfS6gwufXoQLrB0B/JDA4v1p+p2S5Y6IGP4SzZqqVTsROlU8meD6ep3q6MTA==", "contentType": "text/javascript" },
@ -10,6 +11,7 @@
"http://localhost:9990/redirect": { "resolved": "http://localhost:9990/redirect.js", "integrity": "sha512-BV/MK/QTq+NHRve1XpZyQ8V6cjRP/fwbtJvENRdm5C73qNYZ4i2/fw+soj7J4qxzBXMHDbvOnA6E0ShnX2hc1w==", "contentType": "text/javascript" },
"http://localhost:9990/redirect.js": { "integrity": "sha512-BV/MK/QTq+NHRve1XpZyQ8V6cjRP/fwbtJvENRdm5C73qNYZ4i2/fw+soj7J4qxzBXMHDbvOnA6E0ShnX2hc1w==", "contentType": "text/javascript" },
"http://localhost:9990/resolve.js": { "integrity": "sha512-6J9zBO2hXSMTO1EtXJOxSRB2nVPHCoNmNHS8an1QeehzJFc3uoBPRWu6hqHPc54gv2/QME9RBR/BXIan68virg==", "contentType": "text/javascript" },
"http://localhost:9990/url.js": { "integrity": "sha512-Dlw99Gtp/ZRxWvGlqD2EKnvbo1i6j/slwQO4WV8RIRhYZx9ErI+rndpyDMaKykSnq20HCp5H73TJ+dtO+wDyEg==", "contentType": "text/javascript" },
"https://raw.githubusercontent.com//webpack//webpack//main/CODE_OF_CONDUCT.md": { "resolved": "https://raw.githubusercontent.com/webpack/webpack/main/CODE_OF_CONDUCT.md", "integrity": "sha512-OLJ9q6iSO652hVBkTLsMLtQnFBBTzEbFqLGyWD62nPga/0DZ9bc3oOFb5OYT8RIPzmlOX4WzK2uiLgc1NSGtBA==", "contentType": "text/plain; charset=utf-8" },
"https://raw.githubusercontent.com/webpack/webpack/main/CODE_OF_CONDUCT.md": { "integrity": "sha512-OLJ9q6iSO652hVBkTLsMLtQnFBBTzEbFqLGyWD62nPga/0DZ9bc3oOFb5OYT8RIPzmlOX4WzK2uiLgc1NSGtBA==", "contentType": "text/plain; charset=utf-8" },
"version": 1

View File

@ -1,5 +1,6 @@
{
"http://localhost:9990/asset.txt": { "integrity": "sha512-LHT9F+2v2A6ER7DUZ0HuJDt+t03SFJoKsbkkb7MDgvJ+hT2FhXGeDmfL2g2qj1FnEGRhXWRa4nrLFb+xRH9Fmw==", "contentType": "text/css" },
"http://localhost:9990/asset.txt?query": { "integrity": "sha512-LHT9F+2v2A6ER7DUZ0HuJDt+t03SFJoKsbkkb7MDgvJ+hT2FhXGeDmfL2g2qj1FnEGRhXWRa4nrLFb+xRH9Fmw==", "contentType": "text/css" },
"http://localhost:9990/fallback.js": { "integrity": "sha512-BCkBS4Wb0EreudEceuobqZZwTE7SeVUJ2vVHxDQKm8xW6dGJRcUrrSWcjd/61zijOeYAW0P+boOg7u0vxrGwYg==", "contentType": "text/javascript" },
"http://localhost:9990/folder/dependency.js": { "integrity": "sha512-N0En4W3aNPY82MPu16+50P4PqLLyPLI6l33wR2a3ue8VCRjY8RJl8erRB8ztWSEYNad7yRDPrqlYT+IBtoOA9w==", "contentType": "text/javascript" },
"http://localhost:9990/folder/sub-dependency.js": { "integrity": "sha512-Jjmwazwmg67EwNPViCBwvSIxhENfS6gwufXoQLrB0B/JDA4v1p+p2S5Y6IGP4SzZqqVTsROlU8meD6ep3q6MTA==", "contentType": "text/javascript" },
@ -10,6 +11,7 @@
"http://localhost:9990/redirect": { "resolved": "http://localhost:9990/redirect.js", "integrity": "sha512-BV/MK/QTq+NHRve1XpZyQ8V6cjRP/fwbtJvENRdm5C73qNYZ4i2/fw+soj7J4qxzBXMHDbvOnA6E0ShnX2hc1w==", "contentType": "text/javascript" },
"http://localhost:9990/redirect.js": { "integrity": "sha512-BV/MK/QTq+NHRve1XpZyQ8V6cjRP/fwbtJvENRdm5C73qNYZ4i2/fw+soj7J4qxzBXMHDbvOnA6E0ShnX2hc1w==", "contentType": "text/javascript" },
"http://localhost:9990/resolve.js": { "integrity": "sha512-6J9zBO2hXSMTO1EtXJOxSRB2nVPHCoNmNHS8an1QeehzJFc3uoBPRWu6hqHPc54gv2/QME9RBR/BXIan68virg==", "contentType": "text/javascript" },
"http://localhost:9990/url.js": { "integrity": "sha512-Dlw99Gtp/ZRxWvGlqD2EKnvbo1i6j/slwQO4WV8RIRhYZx9ErI+rndpyDMaKykSnq20HCp5H73TJ+dtO+wDyEg==", "contentType": "text/javascript" },
"https://raw.githubusercontent.com//webpack//webpack//main/CODE_OF_CONDUCT.md": { "resolved": "https://raw.githubusercontent.com/webpack/webpack/main/CODE_OF_CONDUCT.md", "integrity": "sha512-OLJ9q6iSO652hVBkTLsMLtQnFBBTzEbFqLGyWD62nPga/0DZ9bc3oOFb5OYT8RIPzmlOX4WzK2uiLgc1NSGtBA==", "contentType": "text/plain; charset=utf-8" },
"https://raw.githubusercontent.com/webpack/webpack/main/CODE_OF_CONDUCT.md": { "integrity": "sha512-OLJ9q6iSO652hVBkTLsMLtQnFBBTzEbFqLGyWD62nPga/0DZ9bc3oOFb5OYT8RIPzmlOX4WzK2uiLgc1NSGtBA==", "contentType": "text/plain; charset=utf-8" },
"version": 1

View File

@ -0,0 +1 @@
export default new URL("asset.txt?query", import.meta.url);

View File

@ -0,0 +1 @@
export default new URL("asset.txt?query", import.meta.url);

View File

@ -21,6 +21,7 @@ const base = {
},
{
test: /\.txt$/,
dependency: { not: "url" },
type: "asset/source"
}
]

1
types.d.ts vendored
View File

@ -9020,6 +9020,7 @@ declare interface ResolveData {
request: string;
assertions?: Record<string, any>;
dependencies: ModuleDependency[];
dependencyType: string;
createData: Object;
fileDependencies: LazySet<string>;
missingDependencies: LazySet<string>;