Skip to content

Commit

Permalink
fix: file dependencies lost when incremental compiling failed in css …
Browse files Browse the repository at this point in the history
…module
  • Loading branch information
LingyuCoder committed Nov 5, 2024
1 parent d5c5508 commit d53c14e
Show file tree
Hide file tree
Showing 16 changed files with 108 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
color: blue;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
background: red;
$dep$
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
it("should have correct value", () => {
if (WATCH_STEP === "0") {
expect(require("./entry.txt").myClass).toBeTruthy();
} else if (WATCH_STEP === "1") {
expect(() => {
require("./entry.txt")
}).toThrow();
} else if (WATCH_STEP === "2") {
expect(require("./entry.txt").myClass).toBeTruthy();
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fail
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = [/Failed/, /Module build failed/];
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
color: blueviolet;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const fs = require("fs");

module.exports = function (source) {
const depPath = this.resource.replace("entry.txt", "dep.txt");
this.addDependency(depPath);
const depContent = fs.readFileSync(depPath, 'utf-8');
if (depContent === "fail") {
throw new Error("Failed");
}
return `.my-class {
${source.replace("$dep$", depContent)}
}`;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const path = require("path");
const rspack = require('@rspack/core');

/** @type {import("@rspack/core").Configuration} */
module.exports = {
module: {
rules: [{
test: /.txt$/,
type: 'javascript/auto',
use: [
{
loader: rspack.CssExtractRspackPlugin.loader,
},
{
loader: "css-loader",
options: {
modules: {
namedExport: true
}
}
},
{
loader: path.resolve(__dirname, './loader.js')
}
]
}]
},
plugins: [
new rspack.CssExtractRspackPlugin(),
],
experiments: {
css: false
},
resolve: {
extensions: ["...", ".txt"]
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dep0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
entry for $dep$
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
it("should have correct value", () => {
if (WATCH_STEP === "0") {
expect(require("./entry.txt")).toBe("entry for dep0");
} else if (WATCH_STEP === "1") {
expect(() => {
require("./entry.txt")
}).toThrow();
} else if (WATCH_STEP === "2") {
expect(require("./entry.txt")).toBe("entry for dep2");
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fail
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = [[/Failed/]];
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dep2
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const fs = require("fs");

module.exports = function (source) {
const depPath = this.resource.replace("entry.txt", "dep.txt");
this.addDependency(depPath);
const depContent = fs.readFileSync(depPath, 'utf-8');
if (depContent === "fail") {
throw new Error("Failed");
}
return `module.exports = "${source.replace("$dep$", depContent)}"`;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const path = require("path");

/** @type {import("@rspack/core").Configuration} */
module.exports = {
module: {
rules: [{
test: /.txt$/,
loader: path.resolve(__dirname, './loader.js')
}]
},
resolve: {
extensions: ["...", ".txt"]
}
};

0 comments on commit d53c14e

Please sign in to comment.