-
-
Notifications
You must be signed in to change notification settings - Fork 616
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support invalidate persistent cache using
config.mode
and `co…
…nfig.name` (#8920) * feat: support invalidate persistent cache using `mode` and `name` * test: add test case
- Loading branch information
1 parent
aa8732c
commit 96084cc
Showing
14 changed files
with
124 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
packages/rspack-test-tools/tests/cacheCases/invalidation/config-mode/file.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default 1; | ||
--- | ||
export default 2; | ||
--- | ||
export default 3; | ||
--- | ||
export default 4; |
15 changes: 15 additions & 0 deletions
15
packages/rspack-test-tools/tests/cacheCases/invalidation/config-mode/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import value from "./file"; | ||
|
||
it("should invalidation using config.mode work", async () => { | ||
if (COMPILER_INDEX == 0) { | ||
expect(value).toBe(1); | ||
await NEXT_HMR(); | ||
expect(value).toBe(2); | ||
await NEXT_START(); | ||
} | ||
if (COMPILER_INDEX == 1) { | ||
expect(value).toBe(3); | ||
await NEXT_HMR(); | ||
expect(value).toBe(4); | ||
} | ||
}); |
30 changes: 30 additions & 0 deletions
30
packages/rspack-test-tools/tests/cacheCases/invalidation/config-mode/rspack.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const path = require("path"); | ||
|
||
let index = 1; | ||
|
||
/** @type {import("@rspack/core").Configuration} */ | ||
module.exports = { | ||
context: __dirname, | ||
experiments: { | ||
cache: { | ||
type: "persistent", | ||
snapshot: { | ||
immutablePaths: [path.join(__dirname, "./file.js")] | ||
} | ||
} | ||
}, | ||
plugins: [ | ||
{ | ||
apply(compiler) { | ||
compiler.hooks.beforeCompile.tap("Test Plugin", function () { | ||
if (index === 1) { | ||
compiler.options.mode = "development"; | ||
} else { | ||
compiler.options.mode = "production"; | ||
} | ||
index++; | ||
}); | ||
} | ||
} | ||
] | ||
}; |
7 changes: 7 additions & 0 deletions
7
packages/rspack-test-tools/tests/cacheCases/invalidation/config-name/file.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default 1; | ||
--- | ||
export default 2; | ||
--- | ||
export default 3; | ||
--- | ||
export default 4; |
15 changes: 15 additions & 0 deletions
15
packages/rspack-test-tools/tests/cacheCases/invalidation/config-name/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import value from "./file"; | ||
|
||
it("should invalidation using config.name work", async () => { | ||
if (COMPILER_INDEX == 0) { | ||
expect(value).toBe(1); | ||
await NEXT_HMR(); | ||
expect(value).toBe(2); | ||
await NEXT_START(); | ||
} | ||
if (COMPILER_INDEX == 1) { | ||
expect(value).toBe(3); | ||
await NEXT_HMR(); | ||
expect(value).toBe(4); | ||
} | ||
}); |
26 changes: 26 additions & 0 deletions
26
packages/rspack-test-tools/tests/cacheCases/invalidation/config-name/rspack.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const path = require("path"); | ||
|
||
let index = 1; | ||
|
||
/** @type {import("@rspack/core").Configuration} */ | ||
module.exports = { | ||
context: __dirname, | ||
experiments: { | ||
cache: { | ||
type: "persistent", | ||
snapshot: { | ||
immutablePaths: [path.join(__dirname, "./file.js")] | ||
} | ||
} | ||
}, | ||
plugins: [ | ||
{ | ||
apply(compiler) { | ||
compiler.hooks.beforeCompile.tap("Test Plugin", function () { | ||
compiler.options.name = String(index); | ||
index++; | ||
}); | ||
} | ||
} | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96084cc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 Benchmark detail: Open