Skip to content

Commit

Permalink
fix: add fix
Browse files Browse the repository at this point in the history
  • Loading branch information
andyjessop committed Oct 15, 2024
1 parent c70c4eb commit 5948534
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
29 changes: 29 additions & 0 deletions packages/wrangler/src/__tests__/dev.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as fs from "node:fs";
import module from "node:module";
import path from "node:path";
import getPort from "get-port";
import { http, HttpResponse } from "msw";
import patchConsole from "patch-console";
Expand Down Expand Up @@ -289,6 +290,34 @@ describe.sequential("wrangler dev", () => {
expect(config.entrypoint).toMatch(/index\.js$/);
});

it("should apply module root to parent if main is nested from base_dir", async () => {
writeWranglerToml({
main: "./some/base_dir/nested/index.js",
base_dir: "./some/base_dir",
});
fs.mkdirSync(path.dirname("./some/base_dir/nested/index.js"), {
recursive: true,
});
fs.mkdirSync(path.dirname("./some/base_dir/foo.js"), { recursive: true });

fs.writeFileSync(
"./some/base_dir/nested/index.js",
`import { x } from "../foo.js";
export default {
fetch() {
return new Response(x);
}
}`
);

fs.writeFileSync(
"./some/base_dir/foo.js",
`export const x = "Hello, world!"`
);
const config = await runWranglerUntilConfig("dev");
expect(config.entrypoint).toMatch(/some\/base_dir\/nested\/index\.js$/);
});

it("should use `main` from a named environment", async () => {
writeWranglerToml({
env: {
Expand Down
2 changes: 1 addition & 1 deletion packages/wrangler/src/dev/miniflare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ async function buildSourceOptions(
? []
: await getEntrypointNames(entrypointSource);

const modulesRoot = path.dirname(scriptPath);
const modulesRoot = config.bundle.entry.moduleRoot;
const sourceOptions: SourceOptions = {
modulesRoot,

Expand Down

0 comments on commit 5948534

Please sign in to comment.