diff --git a/packages/rspack/package.json b/packages/rspack/package.json index 9be975cf736..7b8bc3b05da 100644 --- a/packages/rspack/package.json +++ b/packages/rspack/package.json @@ -63,7 +63,9 @@ "compare-versions": "6.0.0-rc.1", "enhanced-resolve": "5.12.0", "graceful-fs": "4.2.10", + "json-parse-even-better-errors": "^3.0.0", "neo-async": "2.6.2", + "querystring": "^0.2.1", "react-refresh": "0.14.0", "schema-utils": "^4.0.0", "tapable": "2.2.1", diff --git a/packages/rspack/src/loader-runner/index.ts b/packages/rspack/src/loader-runner/index.ts index 51d1db02eeb..deb1b2575bd 100644 --- a/packages/rspack/src/loader-runner/index.ts +++ b/packages/rspack/src/loader-runner/index.ts @@ -96,25 +96,8 @@ function createLoaderObject(loader: any, compiler: Compiler): LoaderObject { obj.path = splittedRequest.path; obj.query = splittedRequest.query; obj.fragment = splittedRequest.fragment; - - if (obj.query.startsWith("??")) { - const ident = obj.query.slice(2); - if (ident === "[[missing ident]]") { - throw new Error( - "No ident is provided by referenced loader. " + - "When using a function for Rule.use in config you need to " + - "provide an 'ident' property for referenced loader options." - ); - } - obj.options = compiler.ruleSet.references.get(ident); - if (obj.options === undefined) { - throw new Error("Invalid ident is provided by referenced loader"); - } - obj.ident = ident; - } else { - obj.options = undefined; - obj.ident = undefined; - } + obj.options = undefined; + obj.ident = undefined; } else { if (!value.loader) throw new Error( @@ -182,9 +165,34 @@ export async function runLoaders( const buildDependencies: string[] = rawContext.buildDependencies.slice(); const assetFilenames = rawContext.assetFilenames.slice(); - const loaders = rawContext.currentLoader - .split("$") - .map(loader => createLoaderObject(loader, compiler)); + const loaders = rawContext.currentLoader.split("$").map(loader => { + const splittedRequest = parsePathQueryFragment(loader); + const obj: any = {}; + obj.loader = obj.path = splittedRequest.path; + obj.query = splittedRequest.query; + obj.fragment = splittedRequest.fragment; + const type = /\.mjs$/i.test(splittedRequest.path) ? "module" : "commonjs"; + obj.type = type; + obj.options = splittedRequest.query + ? splittedRequest.query.slice(1) + : undefined; + if (typeof obj.options === "string" && obj.options[0] === "?") { + const ident = obj.options.slice(1); + if (ident === "[[missing ident]]") { + throw new Error( + "No ident is provided by referenced loader. " + + "When using a function for Rule.use in config you need to " + + "provide an 'ident' property for referenced loader options." + ); + } + obj.options = compiler.ruleSet.references.get(ident); + if (obj.options === undefined) { + throw new Error("Invalid ident is provided by referenced loader"); + } + obj.ident = ident; + } + return createLoaderObject(obj, compiler); + }); loaderContext.__internal__context = rawContext; loaderContext.context = contextDirectory; @@ -504,6 +512,22 @@ export async function runLoaders( const loader = getCurrentLoader(loaderContext); let options = loader?.options; + if (typeof options === "string") { + if (options.startsWith("{") && options.endsWith("}")) { + try { + const parseJson = require("json-parse-even-better-errors"); + options = parseJson(options); + } catch (e: any) { + throw new Error(`Cannot parse string options: ${e.message}`); + } + } else { + const querystring = require("querystring"); + options = querystring.parse(options, "&", "=", { + maxKeys: 0 + }); + } + } + if (options === null || options === undefined) { options = {}; } diff --git a/packages/rspack/tests/configCases/builtin-swc-loader/source-map/a.ts b/packages/rspack/tests/configCases/builtin-swc-loader/source-map/a.ts new file mode 100644 index 00000000000..ec127c18f7a --- /dev/null +++ b/packages/rspack/tests/configCases/builtin-swc-loader/source-map/a.ts @@ -0,0 +1,4 @@ +let foo: string = "f1"; +let bar: string = "b1"; +let baz: string = "b2"; +const boo = "abc"; diff --git a/packages/rspack/tests/configCases/builtin-swc-loader/source-map/index.js b/packages/rspack/tests/configCases/builtin-swc-loader/source-map/index.js new file mode 100644 index 00000000000..4c158ae172d --- /dev/null +++ b/packages/rspack/tests/configCases/builtin-swc-loader/source-map/index.js @@ -0,0 +1,51 @@ +require("./a"); + +it("should generate correct sourceMap", async () => { + const path = require("path"); + const fs = require("fs"); + const source = fs.readFileSync(__filename + ".map", "utf-8"); + const map = JSON.parse(source); + const sourceContent = fs.readFileSync( + path.resolve(__dirname, "../a.ts"), + "utf-8" + ); + expect(map.sources).toContain("./a.ts"); + expect(map.sourcesContent[1]).toEqual(sourceContent); + + checkStub("fo" + "o", sourceContent); + checkStub("ba" + "r", sourceContent); + checkStub("ba" + "z", sourceContent); + checkStub(wrap("f" + 1), sourceContent); + checkStub(wrap("b" + 1), sourceContent); + checkStub(wrap("b" + 2), sourceContent); + checkStub(wrap("ab" + "c"), sourceContent); +}); + +const wrap = v => `"${v}"`; +const checkStub = async (stub, sourceContent) => { + const fs = require("fs"); + const { SourceMapConsumer } = require("source-map"); + + const source = fs.readFileSync(__filename + ".map", "utf-8"); + const map = JSON.parse(source); + const consumer = await new SourceMapConsumer(map); + const generated = fs.readFileSync(__filename, "utf-8"); + const { line, column } = consumer.originalPositionFor( + positionFor(generated, stub) + ); + const { line: originalLine, column: originalColumn } = positionFor( + sourceContent, + stub + ); + expect(line).toBe(originalLine); + expect(column).toBe(originalColumn); +}; + +const positionFor = (content, text) => { + let lines = content.split(/\r?\n/); + for (let i = 0; i < lines.length; i++) { + const column = lines[i].indexOf(text); + if (column >= 0) return { line: i + 1, column }; + } + return null; +}; diff --git a/packages/rspack/tests/configCases/builtin-swc-loader/source-map/webpack.config.js b/packages/rspack/tests/configCases/builtin-swc-loader/source-map/webpack.config.js new file mode 100644 index 00000000000..9a885b0413b --- /dev/null +++ b/packages/rspack/tests/configCases/builtin-swc-loader/source-map/webpack.config.js @@ -0,0 +1,30 @@ +module.exports = { + devtool: "source-map", + externals: ["source-map"], + externalsType: "commonjs", + module: { + rules: [ + { + test: /\.ts$/, + use: [ + { + loader: "builtin:swc-loader", + options: { + jsc: { + parser: { + syntax: "typescript" + } + } + } + } + ], + type: "javascript/auto" + } + ] + }, + experiments: { + rspackFuture: { + disableTransformByDefault: true + } + } +}; diff --git a/packages/rspack/tests/configCases/loader/options/a.js b/packages/rspack/tests/configCases/loader/options/a.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/rspack/tests/configCases/loader/options/b.js b/packages/rspack/tests/configCases/loader/options/b.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/rspack/tests/configCases/loader/options/c.js b/packages/rspack/tests/configCases/loader/options/c.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/rspack/tests/configCases/loader/options/d.js b/packages/rspack/tests/configCases/loader/options/d.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/rspack/tests/configCases/loader/options/e.js b/packages/rspack/tests/configCases/loader/options/e.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/rspack/tests/configCases/loader/options/error1.js b/packages/rspack/tests/configCases/loader/options/error1.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/rspack/tests/configCases/loader/options/error2.js b/packages/rspack/tests/configCases/loader/options/error2.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/rspack/tests/configCases/loader/options/f.js b/packages/rspack/tests/configCases/loader/options/f.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/rspack/tests/configCases/loader/options/g.js b/packages/rspack/tests/configCases/loader/options/g.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/rspack/tests/configCases/loader/options/h.js b/packages/rspack/tests/configCases/loader/options/h.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/rspack/tests/configCases/loader/options/i.js b/packages/rspack/tests/configCases/loader/options/i.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/rspack/tests/configCases/loader/options/index.js b/packages/rspack/tests/configCases/loader/options/index.js new file mode 100644 index 00000000000..66eca065d4e --- /dev/null +++ b/packages/rspack/tests/configCases/loader/options/index.js @@ -0,0 +1,45 @@ +it("should get options", function () { + expect(require("./a")).toStrictEqual({ + arg: true, + arg1: null, + arg3: 1234567890, + arg4: "string", + arg5: [1, 2, 3], + arg6: { foo: "value", bar: { baz: "other-value" } } + }); + expect(require("./b")).toStrictEqual({ + arg: true, + arg1: null, + arg3: 1234567890, + arg4: "string", + arg5: [1, 2, 3], + arg6: { foo: "value", bar: { baz: "other-value" } } + }); + expect(require("./c")).toStrictEqual({ + arg: true, + arg1: null, + arg3: 1234567890, + arg4: "string", + arg5: [1, 2, 3], + arg6: { foo: "value", bar: { baz: "other-value" } } + }); + expect(require("./d")).toStrictEqual({ + arg4: "text" + }); + expect(require("./e")).toStrictEqual({}); + expect(require("./f")).toStrictEqual({ + delicious: "", + name: "cheesecake", + slices: "8", + warm: "false" + }); + expect(require("./g")).toStrictEqual({ + "=": "=" + }); + expect(require("./h")).toStrictEqual({ + foo: "bar" + }); + expect(require("./i")).toStrictEqual({ + foo: "bar" + }); +}); diff --git a/packages/rspack/tests/configCases/loader/options/infrastructure-log.js b/packages/rspack/tests/configCases/loader/options/infrastructure-log.js new file mode 100644 index 00000000000..47af2b051a6 --- /dev/null +++ b/packages/rspack/tests/configCases/loader/options/infrastructure-log.js @@ -0,0 +1,3 @@ +module.exports = [ + /^Pack got invalid because of write to: Compilation\/modules.+loaders[/\\]options[/\\]error1\.js$/ +]; diff --git a/packages/rspack/tests/configCases/loader/options/loader-1.js b/packages/rspack/tests/configCases/loader/options/loader-1.js new file mode 100644 index 00000000000..4614a709d80 --- /dev/null +++ b/packages/rspack/tests/configCases/loader/options/loader-1.js @@ -0,0 +1,12 @@ +const schema = require("./loader-1.options.json"); + +/** @type {import("@rspack/core").LoaderDefinition} */ +module.exports = function () { + const options = this.getOptions(schema); + + const json = JSON.stringify(options) + .replace(/\u2028/g, "\\u2028") + .replace(/\u2029/g, "\\u2029"); + + return `module.exports = ${json}`; +}; diff --git a/packages/rspack/tests/configCases/loader/options/loader-1.options.json b/packages/rspack/tests/configCases/loader/options/loader-1.options.json new file mode 100644 index 00000000000..3c86ba01025 --- /dev/null +++ b/packages/rspack/tests/configCases/loader/options/loader-1.options.json @@ -0,0 +1,43 @@ +{ + "additionalProperties": false, + "properties": { + "arg": { + "type": "boolean" + }, + "arg1": { + "type": "null" + }, + "arg2": {}, + "arg3": { + "type": "number" + }, + "arg4": { + "type": "string" + }, + "arg5": { + "type": "array", + "items": { + "type": "number" + } + }, + "arg6": { + "type": "object", + "properties": { + "foo": { + "type": "string" + }, + "bar": { + "type": "object", + "properties": { + "baz": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + } + }, + "type": "object" +} diff --git a/packages/rspack/tests/configCases/loader/options/loader-2.js b/packages/rspack/tests/configCases/loader/options/loader-2.js new file mode 100644 index 00000000000..c645b12a668 --- /dev/null +++ b/packages/rspack/tests/configCases/loader/options/loader-2.js @@ -0,0 +1,12 @@ +const schema = require("./loader-2.options.json"); + +/** @type {import("@rspack/core").LoaderDefinition} */ +module.exports = function () { + const options = this.getOptions(schema); + + const json = JSON.stringify(options) + .replace(/\u2028/g, "\\u2028") + .replace(/\u2029/g, "\\u2029"); + + return `module.exports = ${json}`; +}; diff --git a/packages/rspack/tests/configCases/loader/options/loader-2.options.json b/packages/rspack/tests/configCases/loader/options/loader-2.options.json new file mode 100644 index 00000000000..d17814f5fcf --- /dev/null +++ b/packages/rspack/tests/configCases/loader/options/loader-2.options.json @@ -0,0 +1,10 @@ +{ + "title": "Custom Loader Name configuration", + "additionalProperties": false, + "properties": { + "arg": { + "enum": [true] + } + }, + "type": "object" +} diff --git a/packages/rspack/tests/configCases/loader/options/loader.js b/packages/rspack/tests/configCases/loader/options/loader.js new file mode 100644 index 00000000000..95ce29ab040 --- /dev/null +++ b/packages/rspack/tests/configCases/loader/options/loader.js @@ -0,0 +1,10 @@ +/** @type {import("@rspack/core").LoaderDefinition} */ +module.exports = function () { + const options = this.getOptions(); + + const json = JSON.stringify(options) + .replace(/\u2028/g, "\\u2028") + .replace(/\u2029/g, "\\u2029"); + + return `module.exports = ${json}`; +}; diff --git a/packages/rspack/tests/configCases/loader/options/webpack.config.js b/packages/rspack/tests/configCases/loader/options/webpack.config.js new file mode 100644 index 00000000000..56d11578126 --- /dev/null +++ b/packages/rspack/tests/configCases/loader/options/webpack.config.js @@ -0,0 +1,93 @@ +/** @type {import("@rspack/core").Configuration} */ +module.exports = { + mode: "none", + module: { + rules: [ + { + test: /a\.js$/, + loader: "./loader", + options: { + arg: true, + arg1: null, + arg2: undefined, + arg3: 1234567890, + arg4: "string", + arg5: [1, 2, 3], + arg6: { foo: "value", bar: { baz: "other-value" } } + } + }, + { + test: /b\.js$/, + loader: "./loader-1", + options: { + arg: true, + arg1: null, + arg2: undefined, + arg3: 1234567890, + arg4: "string", + arg5: [1, 2, 3], + arg6: { foo: "value", bar: { baz: "other-value" } } + } + }, + { + test: /c\.js$/, + loader: "./loader-1", + options: JSON.stringify({ + arg: true, + arg1: null, + arg2: undefined, + arg3: 1234567890, + arg4: "string", + arg5: [1, 2, 3], + arg6: { foo: "value", bar: { baz: "other-value" } } + }) + }, + { + test: /d\.js$/, + loader: "./loader-1", + options: "arg4=text" + }, + { + test: /d\.js$/, + loader: "./loader", + options: "" + }, + { + test: /f\.js$/, + loader: "./loader", + options: "name=cheesecake&slices=8&delicious&warm=false" + }, + { + test: /g\.js$/, + loader: "./loader", + options: "%3d=%3D" + }, + { + test: /h\.js$/, + loader: "./loader", + options: "foo=bar" + }, + { + test: /i\.js$/, + loader: "./loader", + options: `${JSON.stringify({ + foo: "bar" + })}` + }, + { + test: /error1\.js$/, + loader: "./loader-1", + options: { + arg6: { foo: "value", bar: { baz: 42 } } + } + }, + { + test: /error2\.js$/, + loader: "./loader-2", + options: { + arg: false + } + } + ] + } +}; diff --git a/packages/rspack/tests/configCases/source-map/source-map/index.js b/packages/rspack/tests/configCases/source-map/source-map/index.js index f18605afdac..3e95531b819 100644 --- a/packages/rspack/tests/configCases/source-map/source-map/index.js +++ b/packages/rspack/tests/configCases/source-map/source-map/index.js @@ -12,8 +12,7 @@ it("should map to the original content if `module` enabled", async () => { const consumer = await new sourceMap.SourceMapConsumer(map); expect(map.sources).toContain("./App.jsx"); expect(map.sourcesContent[1]).toEqual(app); - const STUB = - "\u0048\u0065\u006c\u006c\u006f\u0020\u0052\u0073\u0070\u0061\u0063\u006b\u0021"; + const STUB = "Hello" + " " + "Rspack!"; const { line, column } = consumer.originalPositionFor( positionFor(generated, STUB) ); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index af781c72b51..d30b8489010 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -989,12 +989,14 @@ importers: html-loader: ^4.2.0 html-webpack-plugin: ^5.5.0 jest-serializer-path: ^0.1.15 + json-parse-even-better-errors: ^3.0.0 less: 4.1.3 less-loader: ^11.1.0 neo-async: 2.6.2 postcss-loader: ^7.0.2 postcss-pxtorem: ^6.0.0 pug-loader: ^2.4.0 + querystring: ^0.2.1 react-refresh: 0.14.0 react-relay: ^14.1.0 sass: ^1.56.2 @@ -1019,7 +1021,9 @@ importers: compare-versions: 6.0.0-rc.1 enhanced-resolve: 5.12.0 graceful-fs: 4.2.10 + json-parse-even-better-errors: 3.0.0 neo-async: 2.6.2 + querystring: 0.2.1 react-refresh: 0.14.0 schema-utils: 4.0.0 tapable: 2.2.1 @@ -1289,9 +1293,10 @@ importers: babel-plugin-import: ^1.13.5 browserslist: ^4.21.3 chokidar: 3.5.3 - coffee-loader: ^4.0.0 - coffeescript: ^2.7.0 + coffee-loader: ^1.0.0 + coffeescript: ^2.5.1 copy-webpack-plugin: '5' + css-loader: ^5.0.1 csv-to-markdown-table: ^1.3.0 enhanced-resolve: 5.12.0 file-loader: ^6.2.0 @@ -1348,9 +1353,10 @@ importers: babel-loader: 9.1.2 babel-plugin-import: 1.13.5 chokidar: 3.5.3 - coffee-loader: 4.0.0_coffeescript@2.7.0 + coffee-loader: 1.0.1_coffeescript@2.7.0 coffeescript: 2.7.0 copy-webpack-plugin: 5.1.2 + css-loader: 5.0.1 csv-to-markdown-table: 1.3.0 file-loader: 6.2.0 is-ci: 3.0.1 @@ -15519,14 +15525,16 @@ packages: engines: {iojs: '>= 1.0.0', node: '>= 0.12.0'} dev: true - /coffee-loader/4.0.0_coffeescript@2.7.0: - resolution: {integrity: sha512-RvgC8c0JwRew5lq3x2J+P4z9Cvan/v91muEvV90VJXcTuJbJQN20taZxfj6/XC4yysA8PInPGpxdB1J9LphLuQ==} - engines: {node: '>= 14.15.0'} + /coffee-loader/1.0.1_coffeescript@2.7.0: + resolution: {integrity: sha512-l3lcWeyNE11ZXNYEpkIkerrvBdSpT06/kcR7MyY+0ys38MOuqzhr+s+s7Tsvv2QH1+qEmhvG8mGuUWIO2zH7Bg==} + engines: {node: '>= 10.13.0'} peerDependencies: coffeescript: '>= 2.0.0' - webpack: ^5.0.0 + webpack: ^4.0.0 || ^5.0.0 dependencies: coffeescript: 2.7.0 + loader-utils: 2.0.4 + schema-utils: 3.1.2 dev: true /coffeescript/2.7.0: @@ -16239,6 +16247,26 @@ packages: resolution: {integrity: sha512-FyyrDHZKEjXDpNJYvVsV960FiqQyXc/LlYmsxl2BcdMb2WPx0OGRVgTg55rPSyLSNMqP52R9r8geSp7apN3Ofg==} engines: {node: '>=4'} + /css-loader/5.0.1: + resolution: {integrity: sha512-cXc2ti9V234cq7rJzFKhirb2L2iPy8ZjALeVJAozXYz9te3r4eqLSixNAbMDJSgJEQywqXzs8gonxaboeKqwiw==} + engines: {node: '>= 10.13.0'} + peerDependencies: + webpack: ^4.27.0 || ^5.0.0 + dependencies: + camelcase: 6.3.0 + cssesc: 3.0.0 + icss-utils: 5.1.0_postcss@8.4.21 + loader-utils: 2.0.4 + postcss: 8.4.21 + postcss-modules-extract-imports: 3.0.0_postcss@8.4.21 + postcss-modules-local-by-default: 4.0.3_postcss@8.4.21 + postcss-modules-scope: 3.0.0_postcss@8.4.21 + postcss-modules-values: 4.0.0_postcss@8.4.21 + postcss-value-parser: 4.2.0 + schema-utils: 3.1.2 + semver: 7.5.1 + dev: true + /css-loader/6.7.3: resolution: {integrity: sha512-qhOH1KlBMnZP8FzRO6YCH9UHXQhVMcEGLyNdb7Hv2cpcmJbW0YrddO+tG1ab5nT41KpHIYGsbeHqxB9xPu1pKQ==} engines: {node: '>= 12.13.0'} @@ -21080,7 +21108,6 @@ packages: /json-parse-even-better-errors/3.0.0: resolution: {integrity: sha512-iZbGHafX/59r39gPwVPRBGw0QQKnA7tte5pSMrhWOW7swGsVvVTjmfyAV9pNqk8YGT7tRCdxRu8uzcgZwoDooA==} engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0} - dev: true /json-schema-traverse/0.4.1: resolution: {integrity: sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==} @@ -24119,6 +24146,18 @@ packages: postcss-value-parser: 4.2.0 dev: true + /postcss-modules-local-by-default/4.0.3_postcss@8.4.21: + resolution: {integrity: sha512-2/u2zraspoACtrbFRnTijMiQtb4GW4BvatjaG/bCjYQo8kLTdevCUlwuBHx2sCnSyrI3x3qj4ZK1j5LQBgzmwA==} + engines: {node: ^10 || ^12 || >= 14} + peerDependencies: + postcss: ^8.1.0 + dependencies: + icss-utils: 5.1.0_postcss@8.4.21 + postcss: 8.4.21 + postcss-selector-parser: 6.0.11 + postcss-value-parser: 4.2.0 + dev: true + /postcss-modules-local-by-default/4.0.3_postcss@8.4.23: resolution: {integrity: sha512-2/u2zraspoACtrbFRnTijMiQtb4GW4BvatjaG/bCjYQo8kLTdevCUlwuBHx2sCnSyrI3x3qj4ZK1j5LQBgzmwA==} engines: {node: ^10 || ^12 || >= 14} @@ -24698,6 +24737,12 @@ packages: deprecated: The querystring API is considered Legacy. new code should use the URLSearchParams API instead. dev: false + /querystring/0.2.1: + resolution: {integrity: sha512-wkvS7mL/JMugcup3/rMitHmd9ecIGd2lhFhK9N3UUQ450h66d1r3Y9nvXzQAW1Lq+wyx61k/1pfKS5KuKiyEbg==} + engines: {node: '>=0.4.x'} + deprecated: The querystring API is considered Legacy. new code should use the URLSearchParams API instead. + dev: false + /queue-microtask/1.2.3: resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==} diff --git a/webpack-test/cases/large/many-replacements/test.filter.js b/webpack-test/cases/large/many-replacements/test.filter.js index 1ae95bcd901..de62cf5195d 100644 --- a/webpack-test/cases/large/many-replacements/test.filter.js +++ b/webpack-test/cases/large/many-replacements/test.filter.js @@ -1,10 +1,5 @@ +// module.exports = function (config) { +// return !process.env.CI; +// }; -/* -module.exports = function (config) { - return !process.env.CI; -}; - -*/ -module.exports = () => {return "https://github.com/web-infra-dev/rspack/issues/4396"} - - \ No newline at end of file +module.exports = () => false // passed it, but it's too slow diff --git a/webpack-test/cases/loaders/coffee-loader/test.filter.js b/webpack-test/cases/loaders/coffee-loader/test.filter.js deleted file mode 100644 index 801a0693f49..00000000000 --- a/webpack-test/cases/loaders/coffee-loader/test.filter.js +++ /dev/null @@ -1,4 +0,0 @@ - -module.exports = () => {return "https://github.com/web-infra-dev/rspack/issues/4396"} - - \ No newline at end of file diff --git a/webpack-test/configCases/loaders/options/test.filter.js b/webpack-test/configCases/loaders/options/test.filter.js index 3be456dcd23..98e4afe7608 100644 --- a/webpack-test/configCases/loaders/options/test.filter.js +++ b/webpack-test/configCases/loaders/options/test.filter.js @@ -1 +1 @@ -module.exports = () => {return false} \ No newline at end of file +module.exports = () => {return false} diff --git a/webpack-test/package.json b/webpack-test/package.json index 38c2c6d0a58..174e069950f 100644 --- a/webpack-test/package.json +++ b/webpack-test/package.json @@ -27,9 +27,10 @@ "babel-loader": "^9.1.0", "babel-plugin-import": "^1.13.5", "chokidar": "3.5.3", - "coffee-loader": "^4.0.0", - "coffeescript": "^2.7.0", + "coffee-loader": "^1.0.0", + "coffeescript": "^2.5.1", "copy-webpack-plugin": "5", + "css-loader": "^5.0.1", "csv-to-markdown-table": "^1.3.0", "file-loader": "^6.2.0", "is-ci": "3.0.1", diff --git a/webpack-test/packages/rspack/node_modules/make-dir/index.d.ts b/webpack-test/packages/rspack/node_modules/make-dir/index.d.ts new file mode 100644 index 00000000000..3e1529c6210 --- /dev/null +++ b/webpack-test/packages/rspack/node_modules/make-dir/index.d.ts @@ -0,0 +1,39 @@ +/// +import * as fs from 'fs'; + +export interface Options { + /** + * Directory [permissions](https://x-team.com/blog/file-system-permissions-umask-node-js/). + * + * @default 0o777 & (~process.umask()) + */ + readonly mode?: number; + + /** + * Use a custom `fs` implementation. For example [`graceful-fs`](https://github.com/isaacs/node-graceful-fs). + * + * Using a custom `fs` implementation will block the use of the native `recursive` option if `fs.mkdir` or `fs.mkdirSync` is not the native function. + * + * @default require('fs') + */ + readonly fs?: typeof fs; +} + +/** + * Make a directory and its parents if needed - Think `mkdir -p`. + * + * @param path - Directory to create. + * @returns A `Promise` for the path to the created directory. + */ +export default function makeDir( + path: string, + options?: Options +): Promise; + +/** + * Synchronously make a directory and its parents if needed - Think `mkdir -p`. + * + * @param path - Directory to create. + * @returns The path to the created directory. + */ +export function sync(path: string, options?: Options): string; diff --git a/webpack-test/packages/rspack/node_modules/make-dir/index.js b/webpack-test/packages/rspack/node_modules/make-dir/index.js new file mode 100644 index 00000000000..4d95c916405 --- /dev/null +++ b/webpack-test/packages/rspack/node_modules/make-dir/index.js @@ -0,0 +1,139 @@ +'use strict'; +const fs = require('fs'); +const path = require('path'); +const pify = require('pify'); +const semver = require('semver'); + +const defaults = { + mode: 0o777 & (~process.umask()), + fs +}; + +const useNativeRecursiveOption = semver.satisfies(process.version, '>=10.12.0'); + +// https://github.com/nodejs/node/issues/8987 +// https://github.com/libuv/libuv/pull/1088 +const checkPath = pth => { + if (process.platform === 'win32') { + const pathHasInvalidWinCharacters = /[<>:"|?*]/.test(pth.replace(path.parse(pth).root, '')); + + if (pathHasInvalidWinCharacters) { + const error = new Error(`Path contains invalid characters: ${pth}`); + error.code = 'EINVAL'; + throw error; + } + } +}; + +const permissionError = pth => { + // This replicates the exception of `fs.mkdir` with native the + // `recusive` option when run on an invalid drive under Windows. + const error = new Error(`operation not permitted, mkdir '${pth}'`); + error.code = 'EPERM'; + error.errno = -4048; + error.path = pth; + error.syscall = 'mkdir'; + return error; +}; + +const makeDir = (input, options) => Promise.resolve().then(() => { + checkPath(input); + options = Object.assign({}, defaults, options); + + // TODO: Use util.promisify when targeting Node.js 8 + const mkdir = pify(options.fs.mkdir); + const stat = pify(options.fs.stat); + + if (useNativeRecursiveOption && options.fs.mkdir === fs.mkdir) { + const pth = path.resolve(input); + + return mkdir(pth, { + mode: options.mode, + recursive: true + }).then(() => pth); + } + + const make = pth => { + return mkdir(pth, options.mode) + .then(() => pth) + .catch(error => { + if (error.code === 'EPERM') { + throw error; + } + + if (error.code === 'ENOENT') { + if (path.dirname(pth) === pth) { + throw permissionError(pth); + } + + if (error.message.includes('null bytes')) { + throw error; + } + + return make(path.dirname(pth)).then(() => make(pth)); + } + + return stat(pth) + .then(stats => stats.isDirectory() ? pth : Promise.reject()) + .catch(() => { + throw error; + }); + }); + }; + + return make(path.resolve(input)); +}); + +module.exports = makeDir; +module.exports.default = makeDir; + +module.exports.sync = (input, options) => { + checkPath(input); + options = Object.assign({}, defaults, options); + + if (useNativeRecursiveOption && options.fs.mkdirSync === fs.mkdirSync) { + const pth = path.resolve(input); + + fs.mkdirSync(pth, { + mode: options.mode, + recursive: true + }); + + return pth; + } + + const make = pth => { + try { + options.fs.mkdirSync(pth, options.mode); + } catch (error) { + if (error.code === 'EPERM') { + throw error; + } + + if (error.code === 'ENOENT') { + if (path.dirname(pth) === pth) { + throw permissionError(pth); + } + + if (error.message.includes('null bytes')) { + throw error; + } + + make(path.dirname(pth)); + return make(pth); + } + + try { + if (!options.fs.statSync(pth).isDirectory()) { + throw new Error('The path is not a directory'); + } + } catch (_) { + throw error; + } + } + + return pth; + }; + + return make(path.resolve(input)); +}; diff --git a/webpack-test/packages/rspack/node_modules/make-dir/license b/webpack-test/packages/rspack/node_modules/make-dir/license new file mode 100644 index 00000000000..e7af2f77107 --- /dev/null +++ b/webpack-test/packages/rspack/node_modules/make-dir/license @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) Sindre Sorhus (sindresorhus.com) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/webpack-test/packages/rspack/node_modules/make-dir/package.json b/webpack-test/packages/rspack/node_modules/make-dir/package.json new file mode 100644 index 00000000000..1b51bf70f72 --- /dev/null +++ b/webpack-test/packages/rspack/node_modules/make-dir/package.json @@ -0,0 +1,59 @@ +{ + "name": "make-dir", + "version": "2.1.0", + "description": "Make a directory and its parents if needed - Think `mkdir -p`", + "license": "MIT", + "repository": "sindresorhus/make-dir", + "author": { + "name": "Sindre Sorhus", + "email": "sindresorhus@gmail.com", + "url": "sindresorhus.com" + }, + "engines": { + "node": ">=6" + }, + "scripts": { + "test": "xo && nyc ava && tsd-check" + }, + "files": [ + "index.js", + "index.d.ts" + ], + "keywords": [ + "mkdir", + "mkdirp", + "make", + "directories", + "dir", + "dirs", + "folders", + "directory", + "folder", + "path", + "parent", + "parents", + "intermediate", + "recursively", + "recursive", + "create", + "fs", + "filesystem", + "file-system" + ], + "dependencies": { + "pify": "^4.0.1", + "semver": "^5.6.0" + }, + "devDependencies": { + "@types/graceful-fs": "^4.1.3", + "@types/node": "^11.10.4", + "ava": "^1.2.0", + "codecov": "^3.0.0", + "graceful-fs": "^4.1.11", + "nyc": "^13.1.0", + "path-type": "^3.0.0", + "tempy": "^0.2.1", + "tsd-check": "^0.3.0", + "xo": "^0.24.0" + } +} diff --git a/webpack-test/packages/rspack/node_modules/make-dir/readme.md b/webpack-test/packages/rspack/node_modules/make-dir/readme.md new file mode 100644 index 00000000000..8c225c1f6a7 --- /dev/null +++ b/webpack-test/packages/rspack/node_modules/make-dir/readme.md @@ -0,0 +1,123 @@ +# make-dir [![Build Status](https://travis-ci.org/sindresorhus/make-dir.svg?branch=master)](https://travis-ci.org/sindresorhus/make-dir) [![codecov](https://codecov.io/gh/sindresorhus/make-dir/branch/master/graph/badge.svg)](https://codecov.io/gh/sindresorhus/make-dir) + +> Make a directory and its parents if needed - Think `mkdir -p` + + +## Advantages over [`mkdirp`](https://github.com/substack/node-mkdirp) + +- Promise API *(Async/await ready!)* +- Fixes many `mkdirp` issues: [#96](https://github.com/substack/node-mkdirp/pull/96) [#70](https://github.com/substack/node-mkdirp/issues/70) [#66](https://github.com/substack/node-mkdirp/issues/66) +- 100% test coverage +- CI-tested on macOS, Linux, and Windows +- Actively maintained +- Doesn't bundle a CLI +- Uses native the `fs.mkdir/mkdirSync` [`recursive` option](https://nodejs.org/dist/latest/docs/api/fs.html#fs_fs_mkdir_path_options_callback) in Node.js >=10.12.0 unless [overridden](#fs) + + +## Install + +``` +$ npm install make-dir +``` + + +## Usage + +``` +$ pwd +/Users/sindresorhus/fun +$ tree +. +``` + +```js +const makeDir = require('make-dir'); + +(async () => { + const path = await makeDir('unicorn/rainbow/cake'); + + console.log(path); + //=> '/Users/sindresorhus/fun/unicorn/rainbow/cake' +})(); +``` + +``` +$ tree +. +└── unicorn + └── rainbow + └── cake +``` + +Multiple directories: + +```js +const makeDir = require('make-dir'); + +(async () => { + const paths = await Promise.all([ + makeDir('unicorn/rainbow'), + makeDir('foo/bar') + ]); + + console.log(paths); + /* + [ + '/Users/sindresorhus/fun/unicorn/rainbow', + '/Users/sindresorhus/fun/foo/bar' + ] + */ +})(); +``` + + +## API + +### makeDir(path, [options]) + +Returns a `Promise` for the path to the created directory. + +### makeDir.sync(path, [options]) + +Returns the path to the created directory. + +#### path + +Type: `string` + +Directory to create. + +#### options + +Type: `Object` + +##### mode + +Type: `integer`
+Default: `0o777 & (~process.umask())` + +Directory [permissions](https://x-team.com/blog/file-system-permissions-umask-node-js/). + +##### fs + +Type: `Object`
+Default: `require('fs')` + +Use a custom `fs` implementation. For example [`graceful-fs`](https://github.com/isaacs/node-graceful-fs). + +Using a custom `fs` implementation will block the use of the native `recursive` option if `fs.mkdir` or `fs.mkdirSync` is not the native function. + + +## Related + +- [make-dir-cli](https://github.com/sindresorhus/make-dir-cli) - CLI for this module +- [del](https://github.com/sindresorhus/del) - Delete files and directories +- [globby](https://github.com/sindresorhus/globby) - User-friendly glob matching +- [cpy](https://github.com/sindresorhus/cpy) - Copy files +- [cpy-cli](https://github.com/sindresorhus/cpy-cli) - Copy files on the command-line +- [move-file](https://github.com/sindresorhus/move-file) - Move a file + + +## License + +MIT © [Sindre Sorhus](https://sindresorhus.com) diff --git a/webpack-test/scripts/test-metric-util.js b/webpack-test/scripts/test-metric-util.js index d161657ab91..e5755801e84 100644 --- a/webpack-test/scripts/test-metric-util.js +++ b/webpack-test/scripts/test-metric-util.js @@ -60,8 +60,8 @@ function renderAllTestsToMarkdown(jsonObj) { const testResults = jsonObj["testResults"]; return testResults .flatMap(testSuite => testSuite.assertionResults) - // use 1\. to break GitHub markdown list auto ordering - .map((test, index) => `${index + 1}\. ${renderTestToMarkdown(test.fullName)}`) + // use `1 ` to break GitHub markdown list auto ordering + .map((test, index) => `${index + 1} ${renderTestToMarkdown(test.fullName)}`) .join('\n') }