test typings and fix type problems in loaders in the test suite
This commit is contained in:
parent
ea53a23827
commit
4e70b37579
|
@ -1,6 +1,8 @@
|
|||
module.exports = function() {
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function () {
|
||||
var err = new Error("Message");
|
||||
err.stack = "Stack";
|
||||
//@ts-expect-error hideStack is not a property on normal errors
|
||||
err.hideStack = true;
|
||||
throw err;
|
||||
};
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
exports.default = function(source) {
|
||||
/** @type {import("../../../../").LoaderDefinitionFunction} */
|
||||
exports.default = function (source) {
|
||||
const ref = JSON.parse(source);
|
||||
const callback = this.async();
|
||||
this.loadModule("../loader!" + ref, (err, source, sourceMap, module) => {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
exports.default = function(source) {
|
||||
/** @type {import("../../../../").LoaderDefinitionFunction} */
|
||||
exports.default = function (source) {
|
||||
const callback = this.async();
|
||||
const ref = JSON.parse(source);
|
||||
this.loadModule("./error-loader!" + ref, (err, source, sourceMap, module) => {
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
module.exports = function(source) {
|
||||
/** @type {import("../../../../").LoaderDefinition<string>} */
|
||||
module.exports = function (source) {
|
||||
//@ts-expect-error errors must be Errors, string is not recommended and should lead to type error
|
||||
this.emitError(this.query.substr(1));
|
||||
return source;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
module.exports = function(source) {
|
||||
/** @type {import("../../../../").LoaderDefinition<string>} */
|
||||
module.exports = function (source) {
|
||||
//@ts-expect-error warnings must be Errors, string is not recommended and should lead to type error
|
||||
this.emitWarning(this.query.substr(1));
|
||||
return source;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
module.exports = function(content) {
|
||||
/** @type {import("../../../../../").LoaderDefinition} */
|
||||
module.exports = function (content) {
|
||||
var cb = this.async();
|
||||
if(!cb) throw new Error("Loader should allow async mode");
|
||||
if(cb !== this.callback) throw new Error("result of this.async() should be equal to this.callback");
|
||||
process.nextTick(function() {
|
||||
if (!cb) throw new Error("Loader should allow async mode");
|
||||
if (cb !== this.callback)
|
||||
throw new Error("result of this.async() should be equal to this.callback");
|
||||
process.nextTick(function () {
|
||||
cb(null, content);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
module.exports = function(content) {
|
||||
/** @type {import("../../../../../").LoaderDefinition} */
|
||||
module.exports = function (content) {
|
||||
return content;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
module.exports = function(content) {
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function (content) {
|
||||
this.emitFile("extra-file.js", content);
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
|
|
@ -2,22 +2,25 @@ const { getRemainingRequest, stringifyRequest } = require("loader-utils");
|
|||
|
||||
const loaderPath = require.resolve("./loader");
|
||||
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function () {
|
||||
if (this.query === "?load") {
|
||||
return `
|
||||
import { answer } from "./lib";
|
||||
|
||||
export default answer;
|
||||
`
|
||||
`;
|
||||
}
|
||||
|
||||
const matchResource = `${this.resourcePath}.js`;
|
||||
const loader = `${loaderPath}?load`;
|
||||
const remaining = getRemainingRequest(this);
|
||||
const request = JSON.parse(stringifyRequest(this, `${matchResource}!=!${loader}!${remaining}`));
|
||||
const request = JSON.parse(
|
||||
stringifyRequest(this, `${matchResource}!=!${loader}!${remaining}`)
|
||||
);
|
||||
|
||||
this.async();
|
||||
this.loadModule(request, (err, source) => {
|
||||
this.callback(err, source)
|
||||
this.callback(err, source);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
module.exports = function(content) {
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function (content) {
|
||||
return content.split("").reverse().join("");
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
module.exports = function(content) {
|
||||
return "module.exports = " + JSON.stringify({
|
||||
resourceQuery: this.resourceQuery,
|
||||
query: this.query,
|
||||
prev: content
|
||||
});
|
||||
}
|
||||
/** @type {import("../../../../../").LoaderDefinition} */
|
||||
module.exports = function (content) {
|
||||
return (
|
||||
"module.exports = " +
|
||||
JSON.stringify({
|
||||
resourceQuery: this.resourceQuery,
|
||||
query: this.query,
|
||||
prev: content
|
||||
})
|
||||
);
|
||||
};
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
const path = require("path");
|
||||
module.exports = function() {
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function () {
|
||||
const resolve1 = this.getResolve();
|
||||
const resolve2 = this.getResolve({
|
||||
extensions: [".xyz", ".js"]
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function () {
|
||||
return `module.exports = {
|
||||
request1: ${JSON.stringify(
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
module.exports = function(content) {
|
||||
return "module.exports = " + JSON.stringify({
|
||||
resourceQuery: this.resourceQuery,
|
||||
query: this.query,
|
||||
prev: content
|
||||
});
|
||||
/** @type {import("../../../../../").LoaderDefinition} */
|
||||
module.exports = function (content) {
|
||||
return (
|
||||
"module.exports = " +
|
||||
JSON.stringify({
|
||||
resourceQuery: this.resourceQuery,
|
||||
query: this.query,
|
||||
prev: content
|
||||
})
|
||||
);
|
||||
};
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
const acorn = require("acorn");
|
||||
const acornParser = acorn.Parser;
|
||||
|
||||
module.exports = function(source) {
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function (source) {
|
||||
const comments = [];
|
||||
|
||||
const ast = acornParser.parse(source, {
|
||||
|
@ -15,9 +16,12 @@ module.exports = function(source) {
|
|||
});
|
||||
|
||||
// change something to test if it's really used
|
||||
//@ts-ignore
|
||||
ast.body[0].expression.right.arguments[0].value = "./ok";
|
||||
ast.body[0].expression.right.arguments[0].raw = "\"./ok\"";
|
||||
//@ts-ignore
|
||||
ast.body[0].expression.right.arguments[0].raw = '"./ok"';
|
||||
|
||||
//@ts-ignore
|
||||
ast.comments = comments;
|
||||
this.callback(null, source, null, {
|
||||
webpackAST: ast
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
module.exports = function(content) {
|
||||
return "module.exports = " + JSON.stringify({
|
||||
resourceQuery: this.resourceQuery,
|
||||
query: this.query,
|
||||
prev: content
|
||||
});
|
||||
}
|
||||
/** @type {import("../../../../../").LoaderDefinition} */
|
||||
module.exports = function (content) {
|
||||
return (
|
||||
"module.exports = " +
|
||||
JSON.stringify({
|
||||
resourceQuery: this.resourceQuery,
|
||||
query: this.query,
|
||||
prev: content
|
||||
})
|
||||
);
|
||||
};
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
const stringifyRequest = require("loader-utils").stringifyRequest;
|
||||
|
||||
/** @type {import("../../../../").PitchLoaderDefinitionFunction} */
|
||||
module.exports.pitch = function (remainingRequest) {
|
||||
return `
|
||||
import { getString as _getString, memory } from ${stringifyRequest(
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
const stringifyRequest = require("loader-utils").stringifyRequest;
|
||||
|
||||
/** @type {import("../../../../").PitchLoaderDefinitionFunction} */
|
||||
module.exports.pitch = function (remainingRequest) {
|
||||
return `
|
||||
import { getString as _getString, memory } from ${stringifyRequest(
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
const path = require("path");
|
||||
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function (source) {
|
||||
this.addDependency(path.resolve(__dirname, "node_modules/package/extra.js"));
|
||||
this.addDependency(path.resolve(__dirname, "extra.js"));
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
module.exports = function(content) {
|
||||
return "module.exports = " + JSON.stringify({
|
||||
resourceQuery: this.resourceQuery,
|
||||
query: this.query,
|
||||
prev: content.replace(/\r\n?/g, "\n")
|
||||
});
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function (content) {
|
||||
return (
|
||||
"module.exports = " +
|
||||
JSON.stringify({
|
||||
resourceQuery: this.resourceQuery,
|
||||
query: this.query,
|
||||
prev: content.replace(/\r\n?/g, "\n")
|
||||
})
|
||||
);
|
||||
};
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function (source) {
|
||||
this.addDependency("loader.js");
|
||||
this.addDependency("../**/dir/*.js");
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
module.exports = function(source) {
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function (source) {
|
||||
return source;
|
||||
};
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
module.exports = function() {
|
||||
/** @type {import("../../../../").LoaderDefinition<string>} */
|
||||
module.exports = function () {
|
||||
const { name, expect, usedExports } = JSON.parse(this.query.slice(1));
|
||||
return [
|
||||
`if (Math.random() < 0) require(${JSON.stringify(
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
module.exports = function() {
|
||||
/** @type {import("../../../../").LoaderDefinition<string>} */
|
||||
module.exports = function () {
|
||||
const usedExports = JSON.parse(this.query.slice(1));
|
||||
return [
|
||||
`import { ${usedExports
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/** @type {import("../../../../").LoaderDefinition<{ value: any }>} */
|
||||
module.exports = function (source) {
|
||||
const options = this.getOptions();
|
||||
return `${source}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/** @type {import("../../../../").PitchLoaderDefinitionFunction} */
|
||||
exports.pitch = async function (remaining) {
|
||||
const result = await this.importModule(
|
||||
this.resourcePath + ".webpack[javascript/auto]" + "!=!" + remaining,
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
module.exports.pitch = function(remainingRequest) {
|
||||
return "module.exports = require(" + JSON.stringify("!!" + remainingRequest) + ");";
|
||||
/** @type {import("../../../../").PitchLoaderDefinitionFunction} */
|
||||
module.exports.pitch = function (remainingRequest) {
|
||||
return (
|
||||
"module.exports = require(" + JSON.stringify("!!" + remainingRequest) + ");"
|
||||
);
|
||||
};
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
module.exports = function(source) {
|
||||
/** @type {import("../../../../").LoaderDefinition<{ f(): any }>} */
|
||||
module.exports = function (source) {
|
||||
if (typeof this.query === "string")
|
||||
throw new Error("query must be an object");
|
||||
return "module.exports = " + JSON.stringify(this.query.f());
|
||||
};
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
module.exports = function() {
|
||||
/** @type {import("../../../../").LoaderDefinition}} */
|
||||
module.exports = function () {
|
||||
return `module.exports = ${JSON.stringify(!!this.hot)};`;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
module.exports = function(source) {
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function (source) {
|
||||
return `module.exports = "${this.mode}";`;
|
||||
};
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
module.exports = function(source) {
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function (source) {
|
||||
return `module.exports = "${this.mode}";`;
|
||||
};
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
module.exports = function(source) {
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function (source) {
|
||||
return `module.exports = "${this.mode}";`;
|
||||
};
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
module.exports = function(source) {
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function (source) {
|
||||
return `module.exports = "${this.mode}";`;
|
||||
};
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
const schema = require("./loader-1.options");
|
||||
const schema = require("./loader-1.options.json");
|
||||
|
||||
module.exports = function() {
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function () {
|
||||
const options = this.getOptions(schema);
|
||||
|
||||
const json = JSON.stringify(options)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
const schema = require("./loader-2.options");
|
||||
const schema = require("./loader-2.options.json");
|
||||
|
||||
module.exports = function() {
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function () {
|
||||
const options = this.getOptions(schema);
|
||||
|
||||
const json = JSON.stringify(options)
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
module.exports = function() {
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function () {
|
||||
const options = this.getOptions();
|
||||
|
||||
const json = JSON.stringify(options)
|
||||
.replace(/\u2028/g, '\\u2028')
|
||||
.replace(/\u2029/g, '\\u2029');
|
||||
.replace(/\u2028/g, "\\u2028")
|
||||
.replace(/\u2029/g, "\\u2029");
|
||||
|
||||
return `module.exports = ${json}`;
|
||||
};
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
module.exports = function(source) {
|
||||
return source + "module.exports += \" loader1\";\n";
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function (source) {
|
||||
return source + 'module.exports += " loader1";\n';
|
||||
};
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
module.exports = function(source) {
|
||||
return source + "module.exports += \" loader2\";\n";
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function (source) {
|
||||
return source + 'module.exports += " loader2";\n';
|
||||
};
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
module.exports = function(source) {
|
||||
return source + "module.exports += \" loader3\";\n";
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function (source) {
|
||||
return source + 'module.exports += " loader3";\n';
|
||||
};
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
module.exports.pitch = function(remainingRequest) {
|
||||
return "module.exports = require(" + JSON.stringify("!!" + remainingRequest) + ");";
|
||||
/** @type {import("../../../../").PitchLoaderDefinitionFunction} */
|
||||
module.exports.pitch = function (remainingRequest) {
|
||||
return (
|
||||
"module.exports = require(" + JSON.stringify("!!" + remainingRequest) + ");"
|
||||
);
|
||||
};
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
module.exports = function(source) {
|
||||
/** @type {import("../../../../").LoaderDefinition<{ f(): any }>} */
|
||||
module.exports = function (source) {
|
||||
if (typeof this.query === "string")
|
||||
throw new Error("query must be an object");
|
||||
return "module.exports = " + JSON.stringify(this.query.f());
|
||||
};
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
module.exports = function(src) {
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function (src) {
|
||||
return `module.exports = "loader-a" + module.id`;
|
||||
};
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
module.exports = function(src) {
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function (src) {
|
||||
return `module.exports = "loader-b" + module.id`;
|
||||
};
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
module.exports = function() {
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function () {
|
||||
var str = "export default Promise.all([\n";
|
||||
for(var i = 0; i < 6; i++) {
|
||||
for(var j = 0; j < 2; j++) {
|
||||
for (var i = 0; i < 6; i++) {
|
||||
for (var j = 0; j < 2; j++) {
|
||||
str += `import("./reexport.loader.js!?${i}"),\n`;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
module.exports = function() {
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function () {
|
||||
var str = "";
|
||||
for(var i = 0; i < 1000; i++) {
|
||||
for (var i = 0; i < 1000; i++) {
|
||||
str += `export var a${i} = ${i};\n`;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
module.exports = function() {
|
||||
var str = "import * as i from \"./file.loader.js!\";\n";
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function () {
|
||||
var str = 'import * as i from "./file.loader.js!";\n';
|
||||
str += "var sum = 0;\n";
|
||||
for(var i = 0; i < 1000; i++) {
|
||||
for (var i = 0; i < 1000; i++) {
|
||||
str += `sum += i.a${i};\n`;
|
||||
}
|
||||
str += "export default sum;\n";
|
||||
return str;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
module.exports = function() {
|
||||
return "module.exports = " + JSON.stringify({
|
||||
minimize: this.minimize,
|
||||
jsfile: this.jsfile
|
||||
});
|
||||
/** @type {import("../../../../").LoaderDefinition<{}, { minimize: boolean, jsfile: boolean }>} */
|
||||
module.exports = function () {
|
||||
return (
|
||||
"module.exports = " +
|
||||
JSON.stringify({
|
||||
minimize: this.minimize,
|
||||
jsfile: this.jsfile
|
||||
})
|
||||
);
|
||||
};
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
module.exports = function() {
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function () {
|
||||
const callback = this.async();
|
||||
let finished = false;
|
||||
this.loadModule("./module.js", (err, result) => {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/** @type {import("../../../../").LoaderDefinition<{}, { shouldReplace: boolean }>} */
|
||||
module.exports = function (source) {
|
||||
if (this.shouldReplace) {
|
||||
this._module.buildInfo._isReplaced = true;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/** @type {import("../../../../").LoaderDefinition<{}, { shouldReplace: boolean }>} */
|
||||
module.exports = function (source) {
|
||||
if (this.shouldReplace) {
|
||||
this._module.buildInfo._isReplaced = true;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
module.exports = function(source) {
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function (source) {
|
||||
return source;
|
||||
};
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = async function () {
|
||||
const defaultResolve = this.getResolve({});
|
||||
const overrideResolve = this.getResolve({
|
||||
|
@ -20,6 +21,7 @@ module.exports = async function () {
|
|||
expect(await defaultResolve(undefined, "package2").catch(e => "ok")).toBe(
|
||||
"ok"
|
||||
);
|
||||
// @ts-expect-error undefined should not be a valid type
|
||||
expect(await defaultResolve(undefined).catch(e => "ok")).toBe("ok");
|
||||
return `
|
||||
export { default as a } from ${JSON.stringify(resolved1)};
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
module.exports = function(source) {
|
||||
/** @type {import("../../../../").LoaderDefinition<{ get(): string }>} */
|
||||
module.exports = function (source) {
|
||||
var query = this.query;
|
||||
if(typeof query === "object" && typeof query.get === "function") {
|
||||
if (typeof query === "object" && typeof query.get === "function") {
|
||||
query = query.get();
|
||||
}
|
||||
return source + "\nmodule.exports.push(" + JSON.stringify(query) + ");";
|
||||
};
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
module.exports = function(source) {
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function (source) {
|
||||
return "module.exports = " + JSON.stringify("loader matched");
|
||||
};
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
module.exports = function(source) {
|
||||
/** @type {import("../../../../").LoaderDefinition<{ get(): string }>} */
|
||||
module.exports = function (source) {
|
||||
var query = this.query;
|
||||
if(typeof query === "object" && typeof query.get === "function") {
|
||||
if (typeof query === "object" && typeof query.get === "function") {
|
||||
query = query.get();
|
||||
}
|
||||
return source + "\nmodule.exports.push(" + JSON.stringify(query) + ");";
|
||||
};
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
module.exports = function(source) {
|
||||
/** @type {import("../../../../").LoaderDefinition<{ get(): string }>} */
|
||||
module.exports = function (source) {
|
||||
var query = this.query;
|
||||
if(typeof query === "object" && typeof query.get === "function") {
|
||||
if (typeof query === "object" && typeof query.get === "function") {
|
||||
query = query.get();
|
||||
}
|
||||
return source + "\nmodule.exports.push(" + JSON.stringify(query) + ");";
|
||||
};
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
module.exports = function(source) {
|
||||
/** @type {import("../../../../").LoaderDefinition<{ get(): string }>} */
|
||||
module.exports = function (source) {
|
||||
var query = this.query;
|
||||
if(typeof query === "object" && typeof query.get === "function") {
|
||||
if (typeof query === "object" && typeof query.get === "function") {
|
||||
query = query.get();
|
||||
}
|
||||
return source + "\nmodule.exports.push(" + JSON.stringify(query) + ");";
|
||||
};
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
module.exports = function(source) {
|
||||
/** @type {import("../../../../").LoaderDefinition<{ get(): string }>} */
|
||||
module.exports = function (source) {
|
||||
var query = this.query;
|
||||
if(typeof query === "object" && typeof query.get === "function") {
|
||||
if (typeof query === "object" && typeof query.get === "function") {
|
||||
query = query.get();
|
||||
}
|
||||
return source + "\nmodule.exports.push(" + JSON.stringify(query) + ");";
|
||||
};
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
module.exports = function(source) {
|
||||
/** @type {import("../../../../").LoaderDefinition<{ get(): string }>} */
|
||||
module.exports = function (source) {
|
||||
var query = this.query;
|
||||
if(typeof query === "object" && typeof query.get === "function") {
|
||||
if (typeof query === "object" && typeof query.get === "function") {
|
||||
query = query.get();
|
||||
}
|
||||
return source + "\nmodule.exports.push(" + JSON.stringify(query) + ");";
|
||||
};
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const path = require("path");
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function () {
|
||||
this.callback(null, "module.exports = 'ok';", {
|
||||
version: 3,
|
||||
|
@ -6,6 +7,7 @@ module.exports = function () {
|
|||
sourceRoot: path.join(__dirname, "folder"),
|
||||
sources: ["test1.txt"],
|
||||
sourcesContent: ["Test"],
|
||||
names: [],
|
||||
mappings: "AAAA"
|
||||
});
|
||||
};
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
const path = require("path");
|
||||
module.exports = function() {
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function () {
|
||||
this.callback(null, "module.exports = 'ok';", {
|
||||
version: 3,
|
||||
file: "/should/be/removed",
|
||||
sources: [path.join(__dirname, "folder", "test5.txt")],
|
||||
sourcesContent: ["Test"],
|
||||
names: [],
|
||||
mappings: "AAAA"
|
||||
});
|
||||
};
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
module.exports = function() {
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function () {
|
||||
this.callback(null, "module.exports = 'ok';", {
|
||||
version: 3,
|
||||
file: "/should/be/removed",
|
||||
sources: ["webpack://./folder/test6.txt"],
|
||||
sourcesContent: ["Test"],
|
||||
names: [],
|
||||
mappings: "AAAA"
|
||||
});
|
||||
};
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
const path = require("path");
|
||||
module.exports = function() {
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function () {
|
||||
this.callback(null, "module.exports = 'ok';", {
|
||||
version: 3,
|
||||
file: "/should/be/removed",
|
||||
sourceRoot: path.join(__dirname, "folder") + "/",
|
||||
sources: ["/test4.txt"],
|
||||
sourcesContent: ["Test"],
|
||||
names: [],
|
||||
mappings: "AAAA"
|
||||
});
|
||||
};
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
const path = require("path");
|
||||
module.exports = function() {
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function () {
|
||||
this.callback(null, "module.exports = 'ok';", {
|
||||
version: 3,
|
||||
file: "/should/be/removed",
|
||||
sourceRoot: path.join(__dirname, "folder") + "/",
|
||||
sources: ["test3.txt"],
|
||||
sourcesContent: ["Test"],
|
||||
names: [],
|
||||
mappings: "AAAA"
|
||||
});
|
||||
};
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
const path = require("path");
|
||||
module.exports = function() {
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function () {
|
||||
this.callback(null, "module.exports = 'ok';", {
|
||||
version: 3,
|
||||
file: "/should/be/removed",
|
||||
sourceRoot: path.join(__dirname, "folder"),
|
||||
sources: ["/test2.txt"],
|
||||
sourcesContent: ["Test"],
|
||||
names: [],
|
||||
mappings: "AAAA"
|
||||
});
|
||||
};
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
const path = require("path");
|
||||
module.exports = function() {
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function () {
|
||||
this.callback(null, "module.exports = 'ok';", {
|
||||
version: 3,
|
||||
file: "/should/be/removed",
|
||||
sourceRoot: path.join(__dirname, "folder"),
|
||||
sources: ["test1.txt"],
|
||||
sourcesContent: ["Test"],
|
||||
names: [],
|
||||
mappings: "AAAA"
|
||||
});
|
||||
};
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
let counter = 0;
|
||||
|
||||
module.exports = function() {
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function () {
|
||||
return `module.exports = ${counter++};`;
|
||||
};
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
module.exports = function(source) {
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function (source) {
|
||||
var cb = this.async();
|
||||
setTimeout(function() {
|
||||
setTimeout(function () {
|
||||
cb(null, source);
|
||||
}, 500);
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
module.exports = function(source) {
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function (source) {
|
||||
return source + "// some comment";
|
||||
};
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
module.exports = function(source) {
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function (source) {
|
||||
const callback = this.async();
|
||||
const error = new Error("this is a callback error");
|
||||
callback(error, source);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
module.exports = function(source) {
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function (source) {
|
||||
this.emitWarning(new Error("this is a warning"));
|
||||
this.emitError(new Error("this is an error"));
|
||||
return source;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
module.exports = function(source) {
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function (source) {
|
||||
return source;
|
||||
};
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
module.exports = function(source) {
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function (source) {
|
||||
const empty = null;
|
||||
const emptyError = new Error();
|
||||
this.emitWarning(empty);
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
module.exports = function(){
|
||||
}
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function () {};
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
module.exports = function(source) {
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function (source) {
|
||||
throw new Error("this is a thrown error");
|
||||
};
|
||||
|
|
|
@ -5,6 +5,7 @@ const {
|
|||
|
||||
const compilerCache = new WeakMap();
|
||||
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function (source) {
|
||||
let childCompiler = compilerCache.get(this._compiler);
|
||||
if (childCompiler === undefined) {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
module.exports = function(source) {
|
||||
/** @type {import("../../").LoaderDefinition<{}, { updateIndex: number }>} */
|
||||
module.exports = function (source) {
|
||||
var idx = this.updateIndex;
|
||||
var items = source.split(/---+\r?\n/g);
|
||||
if (items.length > 1) {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/** @type {import("../../../../").PitchLoaderDefinitionFunction} */
|
||||
exports.pitch = async function (remaining) {
|
||||
const result = await this.importModule(
|
||||
this.resourcePath + ".webpack[javascript/auto]" + "!=!" + remaining
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
module.exports = function(source) {
|
||||
if(source.indexOf("error") >= 0)
|
||||
throw new Error(source.trim());
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function (source) {
|
||||
if (source.indexOf("error") >= 0) throw new Error(source.trim());
|
||||
return source;
|
||||
};
|
||||
|
|
|
@ -4,30 +4,38 @@ var cacheMap = new WeakMap();
|
|||
|
||||
const getCache = (associate, path) => {
|
||||
let o = cacheMap.get(associate);
|
||||
if(o === undefined) {
|
||||
if (o === undefined) {
|
||||
o = new Map();
|
||||
cacheMap.set(associate, o);
|
||||
}
|
||||
let c = o.get(path);
|
||||
if(c === undefined) {
|
||||
if (c === undefined) {
|
||||
c = { counter: 0 };
|
||||
o.set(path, c);
|
||||
}
|
||||
return c;
|
||||
};
|
||||
|
||||
module.exports = function(source) {
|
||||
if(map.has(currentWatchStepModule.step)) return map.get(currentWatchStepModule.step);
|
||||
/** @type {import("../../../../../").LoaderDefinition} */
|
||||
module.exports = function (source) {
|
||||
if (map.has(currentWatchStepModule.step))
|
||||
return map.get(currentWatchStepModule.step);
|
||||
|
||||
const compilationCache = getCache(this._compiler.root, this._compilation.compilerPath);
|
||||
const compilationCache = getCache(
|
||||
this._compiler.root,
|
||||
this._compilation.compilerPath
|
||||
);
|
||||
compilationCache.counter++;
|
||||
|
||||
var childCompiler = this._compilation.createChildCompiler("my-compiler " + source.trim(), {
|
||||
filename: "test"
|
||||
});
|
||||
var childCompiler = this._compilation.createChildCompiler(
|
||||
"my-compiler " + source.trim(),
|
||||
{
|
||||
filename: "test"
|
||||
}
|
||||
);
|
||||
var callback = this.async();
|
||||
childCompiler.runAsChild((err, entries, compilation) => {
|
||||
if(err) return callback(err);
|
||||
if (err) return callback(err);
|
||||
|
||||
const childCache = getCache(this._compiler.root, compilation.compilerPath);
|
||||
childCache.counter++;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/** @type {import("../../../../../").PitchLoaderDefinitionFunction} */
|
||||
exports.pitch = async function (remaining) {
|
||||
const result = await this.importModule(
|
||||
`${this.resourcePath}.webpack[javascript/auto]!=!${remaining}`
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
const path = require("path");
|
||||
const directory = path.resolve(__dirname, "directory");
|
||||
|
||||
module.exports = function() {
|
||||
/** @type {import("../../../../../").LoaderDefinition} */
|
||||
module.exports = function () {
|
||||
this.addContextDependency(directory);
|
||||
const callback = this.async();
|
||||
this.fs.readdir(directory, (err, files) => {
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
module.exports = function() {
|
||||
/** @type {import("../../../../../").LoaderDefinition} */
|
||||
module.exports = function () {
|
||||
const callback = this.async();
|
||||
this.resolve(this.context, "./file", (err, file) => {
|
||||
if (err) return callback(err);
|
||||
if (!file) return callback(new Error("Resolving failed"));
|
||||
this.fs.readFile(file, (err, result) => {
|
||||
if (err) return callback(err);
|
||||
callback(
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
module.exports = function(source) {
|
||||
/** @type {import("../../../../../").LoaderDefinition} */
|
||||
module.exports = function (source) {
|
||||
this.emitWarning(new Error(source.trim()));
|
||||
return "";
|
||||
};
|
||||
|
|
|
@ -12,5 +12,12 @@
|
|||
"types": ["node", "jest"],
|
||||
"esModuleInterop": true
|
||||
},
|
||||
"include": ["test/**/webpack.config.js", "declarations.test.d.ts"]
|
||||
"include": [
|
||||
"test/**/webpack.config.js",
|
||||
"test/cases/**/*loader*.js",
|
||||
"test/watchCases/**/*loader*.js",
|
||||
"test/configCases/**/*loader*.js",
|
||||
"test/hotCases/**/*loader*.js",
|
||||
"declarations.test.d.ts"
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue