diff options
author | 2023-07-20 16:44:43 -0700 | |
---|---|---|
committer | 2023-07-20 16:44:43 -0700 | |
commit | 134c97a28289e7811d68652caf9feb2e9c80db44 (patch) | |
tree | 6906b346b7a11f79429c04a57bf5ab28c83d4684 | |
parent | e2c11c4856f27ea3f93a9c1d2efb899a39dccb7f (diff) | |
download | bun-134c97a28289e7811d68652caf9feb2e9c80db44.tar.gz bun-134c97a28289e7811d68652caf9feb2e9c80db44.tar.zst bun-134c97a28289e7811d68652caf9feb2e9c80db44.zip |
fix directory caching with workaround (#3710)
* ok
* test
-rw-r--r-- | src/bun.js/javascript.zig | 5 | ||||
-rw-r--r-- | test/regression/issue/03091.test.ts (renamed from test/regression/issue/003091.test.ts) | 0 | ||||
-rw-r--r-- | test/regression/issue/03216.test.ts | 42 |
3 files changed, 46 insertions, 1 deletions
diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig index 94d82c496..00c663077 100644 --- a/src/bun.js/javascript.zig +++ b/src/bun.js/javascript.zig @@ -1298,7 +1298,10 @@ pub const VirtualMachine = struct { jsc_vm.bundler.fs.top_level_dir; const result: Resolver.Result = try brk: { - var retry_on_not_found = query_string.len > 0; + // TODO: We only want to retry on not found only when the directories we searched for were cached. + // This fixes an issue where new files created in cached directories were not picked up. + // See https://github.com/oven-sh/bun/issues/3216 + var retry_on_not_found = true; while (true) { break :brk switch (jsc_vm.bundler.resolver.resolveAndAutoInstall( source_to_use, diff --git a/test/regression/issue/003091.test.ts b/test/regression/issue/03091.test.ts index ee115a2a1..ee115a2a1 100644 --- a/test/regression/issue/003091.test.ts +++ b/test/regression/issue/03091.test.ts diff --git a/test/regression/issue/03216.test.ts b/test/regression/issue/03216.test.ts new file mode 100644 index 000000000..fd4f391d0 --- /dev/null +++ b/test/regression/issue/03216.test.ts @@ -0,0 +1,42 @@ +// https://github.com/oven-sh/bun/issues/3216 +import { test, expect } from "bun:test"; +import { tmpdir } from "os"; +import { mkdtempSync, writeFileSync } from "fs"; +import { join } from "path"; +import { bunExe } from "harness"; + +test("runtime directory caching gets invalidated", () => { + const tmp = mkdtempSync(join(tmpdir(), "bun-test-")); + writeFileSync( + join(tmp, "index.ts"), + `const file = \`\${import.meta.dir}/temp.mjs\`; + +import { existsSync, unlinkSync, writeFileSync } from "fs"; + +if (existsSync(file)) { + console.log("temp.mjs cannot exist before running this script"); + unlinkSync(file); + process.exit(2); +} + +writeFileSync(file, "export default 1;"); + +try { + const module = await import(file); + console.log(module.default); +} finally { + unlinkSync(file); +} +`, + ); + + const result = Bun.spawnSync({ + cmd: [bunExe(), "run", join(tmp, "index.ts")], + cwd: tmp, + }); + + console.log(bunExe(), join(tmp, "index.ts"), result.stdout.toString("utf-8")); + + expect(result.exitCode).toBe(0); + expect(result.stdout.toString("utf-8")).toBe("1\n"); +}); |