Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions crates/rspack_storage/src/filesystem/scope_fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ impl ScopeFileSystem {
) -> Result<()> {
let from_file = from.workspace.join(relative_path.as_ref());
let to_file = to.workspace.join(relative_path.as_ref());
to.fs
.create_dir_all(to_file.parent().expect("should have parent"))
.await?;
if let Err(e) = from.fs.rename(&from_file, &to_file).await {
// If the source file is not found, ignore the error.
let e: Error = e.into();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { existsSync, readdirSync, rmSync } from "fs";
import value from "./value";

const cacheDir = __CACHE_DIR__;

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}

function listCacheFiles() {
if (!existsSync(cacheDir)) {
return [];
}

const files = [];
const walk = dir => {
let entries;
try {
entries = readdirSync(dir, { withFileTypes: true });
} catch (error) {
if (error && error.code === "ENOENT") {
return;
}
throw error;
}
for (const entry of entries) {
const file = `${dir}/${entry.name}`;
if (entry.isDirectory()) {
walk(file);
} else {
files.push(file);
}
}
};
walk(cacheDir);
return files;
}

function hasCommittedPackFile() {
return listCacheFiles().some(
file => file.endsWith(".pack") && !file.includes("/.temp/")
);
}

async function waitForPackFiles() {
const start = Date.now();
while (Date.now() - start < 5000) {
if (hasCommittedPackFile()) {
return;
}
await sleep(100);
}
throw new Error("Timed out waiting for persistent cache pack files");
}

async function removeCacheDir() {
const start = Date.now();
while (Date.now() - start < 5000) {
try {
rmSync(cacheDir, { recursive: true, force: true });
if (listCacheFiles().length === 0) {
return;
}
} catch (error) {
if (error && error.code !== "ENOTEMPTY") {
throw error;
}
}
await sleep(100);
}
throw new Error("Timed out removing persistent cache directory");
}

it("should keep writing persistent cache after the cache directory is removed", async () => {
expect(value).toBe(WATCH_STEP);
await waitForPackFiles();

if (WATCH_STEP === "0") {
await removeCacheDir();
expect(listCacheFiles().length).toBe(0);
} else {
expect(WATCH_STEP).toBe("1");
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default "0";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default "1";
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const path = require('path');
const { DefinePlugin } = require('@rspack/core');

/** @type {(_env: unknown, args: { tempPath: string }) => import("@rspack/core").Configuration} */
module.exports = (_env, { tempPath }) => {
const cacheDir = path.join(tempPath, 'node_modules/.cache/rspack');

return {
mode: 'development',
cache: {
type: 'persistent',
storage: {
type: 'filesystem',
directory: cacheDir,
},
},
watchOptions: {
ignored: /node_modules/,
},
plugins: [
new DefinePlugin({
__CACHE_DIR__: JSON.stringify(cacheDir),
}),
],
};
};
Loading