From 4987c7202a98981c89d2e2e83490230e72d712bf Mon Sep 17 00:00:00 2001 From: LingyuCoder Date: Mon, 5 Aug 2024 12:44:23 +0800 Subject: [PATCH] feat: add compiler.rspack --- packages/rspack-test-tools/tests/errorCases/error-test-push.js | 2 +- packages/rspack-test-tools/tests/errorCases/error-test-shift.js | 2 +- .../rspack-test-tools/tests/errorCases/error-test-splice-1.js | 2 +- .../rspack-test-tools/tests/errorCases/error-test-splice-2.js | 2 +- .../rspack-test-tools/tests/errorCases/warning-test-push.js | 2 +- .../rspack-test-tools/tests/errorCases/warning-test-shift.js | 2 +- .../rspack-test-tools/tests/errorCases/warning-test-splice-1.js | 2 +- .../rspack-test-tools/tests/errorCases/warning-test-splice-2.js | 2 +- packages/rspack/etc/api.md | 2 ++ packages/rspack/src/Compiler.ts | 2 ++ 10 files changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/rspack-test-tools/tests/errorCases/error-test-push.js b/packages/rspack-test-tools/tests/errorCases/error-test-push.js index 21405f96dcc5..4bbb10ba53b2 100644 --- a/packages/rspack-test-tools/tests/errorCases/error-test-push.js +++ b/packages/rspack-test-tools/tests/errorCases/error-test-push.js @@ -20,7 +20,7 @@ module.exports = { Object { "message": " × Error: test push\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n", "moduleTrace": Array [], - "stack": "Error: test push\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/error-test-push.js:10:31)\\n at next (packages/rspack-lite-tapable/dist/index.js:529:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:549:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:458:41\\n at packages/rspack/dist/Compiler.js:525:23", + "stack": "Error: test push\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/error-test-push.js:10:31)\\n at next (packages/rspack-lite-tapable/dist/index.js:529:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:549:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:459:41\\n at packages/rspack/dist/Compiler.js:526:23", }, Object { "loc": "1:0-33", diff --git a/packages/rspack-test-tools/tests/errorCases/error-test-shift.js b/packages/rspack-test-tools/tests/errorCases/error-test-shift.js index e61a107167c1..6e2dc7f7a2a2 100644 --- a/packages/rspack-test-tools/tests/errorCases/error-test-shift.js +++ b/packages/rspack-test-tools/tests/errorCases/error-test-shift.js @@ -24,7 +24,7 @@ module.exports = { Object { "message": " × Error: test unshift\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n", "moduleTrace": Array [], - "stack": "Error: test unshift\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/error-test-shift.js:13:35)\\n at next (packages/rspack-lite-tapable/dist/index.js:529:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:549:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:458:41\\n at packages/rspack/dist/Compiler.js:525:23", + "stack": "Error: test unshift\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/error-test-shift.js:13:35)\\n at next (packages/rspack-lite-tapable/dist/index.js:529:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:549:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:459:41\\n at packages/rspack/dist/Compiler.js:526:23", }, ], "warnings": Array [], diff --git a/packages/rspack-test-tools/tests/errorCases/error-test-splice-1.js b/packages/rspack-test-tools/tests/errorCases/error-test-splice-1.js index 9eac3926e4bc..f8c298cf5e8b 100644 --- a/packages/rspack-test-tools/tests/errorCases/error-test-splice-1.js +++ b/packages/rspack-test-tools/tests/errorCases/error-test-splice-1.js @@ -20,7 +20,7 @@ module.exports = { Object { "message": " × Error: test splice\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n", "moduleTrace": Array [], - "stack": "Error: test splice\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/error-test-splice-1.js:10:39)\\n at next (packages/rspack-lite-tapable/dist/index.js:529:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:549:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:458:41\\n at packages/rspack/dist/Compiler.js:525:23", + "stack": "Error: test splice\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/error-test-splice-1.js:10:39)\\n at next (packages/rspack-lite-tapable/dist/index.js:529:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:549:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:459:41\\n at packages/rspack/dist/Compiler.js:526:23", }, ], "warnings": Array [], diff --git a/packages/rspack-test-tools/tests/errorCases/error-test-splice-2.js b/packages/rspack-test-tools/tests/errorCases/error-test-splice-2.js index 7e8ead949a9b..e670ad4958c4 100644 --- a/packages/rspack-test-tools/tests/errorCases/error-test-splice-2.js +++ b/packages/rspack-test-tools/tests/errorCases/error-test-splice-2.js @@ -20,7 +20,7 @@ module.exports = { Object { "message": " × Error: test splice\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n", "moduleTrace": Array [], - "stack": "Error: test splice\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/error-test-splice-2.js:10:39)\\n at next (packages/rspack-lite-tapable/dist/index.js:529:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:549:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:458:41\\n at packages/rspack/dist/Compiler.js:525:23", + "stack": "Error: test splice\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/error-test-splice-2.js:10:39)\\n at next (packages/rspack-lite-tapable/dist/index.js:529:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:549:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:459:41\\n at packages/rspack/dist/Compiler.js:526:23", }, Object { "loc": "1:0-33", diff --git a/packages/rspack-test-tools/tests/errorCases/warning-test-push.js b/packages/rspack-test-tools/tests/errorCases/warning-test-push.js index 89b5eea422e9..46e6b9e28355 100644 --- a/packages/rspack-test-tools/tests/errorCases/warning-test-push.js +++ b/packages/rspack-test-tools/tests/errorCases/warning-test-push.js @@ -21,7 +21,7 @@ module.exports = { Object { "message": " ⚠ Error: test push\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n", "moduleTrace": Array [], - "stack": "Error: test push\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/warning-test-push.js:10:33)\\n at next (packages/rspack-lite-tapable/dist/index.js:529:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:549:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:458:41\\n at packages/rspack/dist/Compiler.js:525:23", + "stack": "Error: test push\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/warning-test-push.js:10:33)\\n at next (packages/rspack-lite-tapable/dist/index.js:529:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:549:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:459:41\\n at packages/rspack/dist/Compiler.js:526:23", }, Object { "message": " ⚠ Module parse warning:\\n ╰─▶ ⚠ Unsupported feature: require.main.require() is not supported by Rspack.\\n ╭────\\n 1 │ require.main.require('./file');\\n · ──────────────────────────────\\n ╰────\\n \\n", diff --git a/packages/rspack-test-tools/tests/errorCases/warning-test-shift.js b/packages/rspack-test-tools/tests/errorCases/warning-test-shift.js index bbca70a6063b..401a173dbfe5 100644 --- a/packages/rspack-test-tools/tests/errorCases/warning-test-shift.js +++ b/packages/rspack-test-tools/tests/errorCases/warning-test-shift.js @@ -25,7 +25,7 @@ module.exports = { Object { "message": " ⚠ Error: test unshift\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n", "moduleTrace": Array [], - "stack": "Error: test unshift\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/warning-test-shift.js:13:37)\\n at next (packages/rspack-lite-tapable/dist/index.js:529:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:549:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:458:41\\n at packages/rspack/dist/Compiler.js:525:23", + "stack": "Error: test unshift\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/warning-test-shift.js:13:37)\\n at next (packages/rspack-lite-tapable/dist/index.js:529:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:549:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:459:41\\n at packages/rspack/dist/Compiler.js:526:23", }, ], } diff --git a/packages/rspack-test-tools/tests/errorCases/warning-test-splice-1.js b/packages/rspack-test-tools/tests/errorCases/warning-test-splice-1.js index 38d104a1d0a1..78e76704e34a 100644 --- a/packages/rspack-test-tools/tests/errorCases/warning-test-splice-1.js +++ b/packages/rspack-test-tools/tests/errorCases/warning-test-splice-1.js @@ -21,7 +21,7 @@ module.exports = { Object { "message": " ⚠ Error: test splice\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n", "moduleTrace": Array [], - "stack": "Error: test splice\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/warning-test-splice-1.js:10:41)\\n at next (packages/rspack-lite-tapable/dist/index.js:529:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:549:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:458:41\\n at packages/rspack/dist/Compiler.js:525:23", + "stack": "Error: test splice\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/warning-test-splice-1.js:10:41)\\n at next (packages/rspack-lite-tapable/dist/index.js:529:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:549:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:459:41\\n at packages/rspack/dist/Compiler.js:526:23", }, ], } diff --git a/packages/rspack-test-tools/tests/errorCases/warning-test-splice-2.js b/packages/rspack-test-tools/tests/errorCases/warning-test-splice-2.js index 7ab5d04d3da2..10ca082df286 100644 --- a/packages/rspack-test-tools/tests/errorCases/warning-test-splice-2.js +++ b/packages/rspack-test-tools/tests/errorCases/warning-test-splice-2.js @@ -21,7 +21,7 @@ module.exports = { Object { "message": " ⚠ Error: test splice\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n", "moduleTrace": Array [], - "stack": "Error: test splice\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/warning-test-splice-2.js:10:41)\\n at next (packages/rspack-lite-tapable/dist/index.js:529:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:549:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:458:41\\n at packages/rspack/dist/Compiler.js:525:23", + "stack": "Error: test splice\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/warning-test-splice-2.js:10:41)\\n at next (packages/rspack-lite-tapable/dist/index.js:529:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:549:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:459:41\\n at packages/rspack/dist/Compiler.js:526:23", }, Object { "message": " ⚠ Module parse warning:\\n ╰─▶ ⚠ Unsupported feature: require.main.require() is not supported by Rspack.\\n ╭────\\n 1 │ require.main.require('./file');\\n · ──────────────────────────────\\n ╰────\\n \\n", diff --git a/packages/rspack/etc/api.md b/packages/rspack/etc/api.md index 1253fe262923..5615c10939df 100644 --- a/packages/rspack/etc/api.md +++ b/packages/rspack/etc/api.md @@ -1322,6 +1322,8 @@ export class Compiler { // (undocumented) root: Compiler; // (undocumented) + rspack: typeof rspack; + // (undocumented) run(callback: liteTapable.Callback): void; // (undocumented) runAsChild(callback: (err?: null | Error, entries?: Chunk[], compilation?: Compilation) => any): void; diff --git a/packages/rspack/src/Compiler.ts b/packages/rspack/src/Compiler.ts index 29e2c782bb29..0256e59a9d7c 100644 --- a/packages/rspack/src/Compiler.ts +++ b/packages/rspack/src/Compiler.ts @@ -122,6 +122,7 @@ class Compiler { }; webpack: typeof rspack; + rspack: typeof rspack; name?: string; parentCompilation?: Compilation; root: Compiler; @@ -210,6 +211,7 @@ class Compiler { }; this.webpack = rspack; + this.rspack = rspack; this.root = this; this.outputPath = "";