|
| 1 | +"use strict"; |
| 2 | + |
| 3 | +const path = require("path"); |
| 4 | + |
| 5 | +/** @type {import("../../../../").LoaderDefinition} */ |
| 6 | +module.exports = async function () { |
| 7 | + /** @type {[string, import("../../../../").ResolveOptions][]} */ |
| 8 | + const cases = [ |
| 9 | + ["javascript", { restrictions: [/\.js$/] }], |
| 10 | + ["json", { restrictions: [/\.json$/] }], |
| 11 | + ["caseSensitive", { restrictions: [/\.JS$/] }], |
| 12 | + ["caseInsensitive", { restrictions: [/\.JS$/i] }], |
| 13 | + ["equivalent", { restrictions: [new RegExp("\\.js$")] }], |
| 14 | + ["string", { restrictions: [String(/\.js$/)] }], |
| 15 | + [ |
| 16 | + "nestedJavascript", |
| 17 | + { byDependency: { esm: { restrictions: [/\.js$/] } } } |
| 18 | + ], |
| 19 | + ["nestedJson", { byDependency: { esm: { restrictions: [/\.json$/] } } }] |
| 20 | + ]; |
| 21 | + /** @type {Record<string, string | false>} */ |
| 22 | + const results = {}; |
| 23 | + for (const [name, options] of cases) { |
| 24 | + const resolve = this.getResolve({ |
| 25 | + dependencyType: "esm", |
| 26 | + extensions: [".js", ".json"], |
| 27 | + ...options |
| 28 | + }); |
| 29 | + const resolved = await resolve(this.context, "./module").catch(error => { |
| 30 | + expect(error.message).toContain("Can't resolve './module'"); |
| 31 | + return false; |
| 32 | + }); |
| 33 | + results[name] = typeof resolved === "string" ? path.basename(resolved) : false; |
| 34 | + } |
| 35 | + return `export default ${JSON.stringify(results)};`; |
| 36 | +}; |
0 commit comments