Skip to content

Commit

Permalink
Fix require hook skipping compiling files when just an entrypoint is …
Browse files Browse the repository at this point in the history
…loaded
  • Loading branch information
emmatown committed Jul 2, 2023
1 parent a58f021 commit 58df49f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/cold-teachers-sin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@preconstruct/cli": patch
---

Fix require hook skipping compiling files when just an entrypoint is loaded
32 changes: 32 additions & 0 deletions packages/cli/src/__tests__/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -673,3 +673,35 @@ test("imports conditions", async () => {
`);
});

test("dev command entrypoint", async () => {
let tmpPath = await testdir({
"package.json": JSON.stringify({
name: "pkg",
preconstruct: {
entrypoints: ["something.ts"],
},
}),
"something/package.json": JSON.stringify({
main: "dist/pkg-something.cjs.js",
module: "dist/pkg-something.esm.js",
}),
".babelrc": JSON.stringify({
presets: [require.resolve("@babel/preset-typescript")],
}),
"src/something.ts": js`
const a: string = "message from something";
console.log(a);
`,
});

await dev(tmpPath);

// i would require it but i don't want jest to do magical things
let { code, stdout, stderr } = await spawn("node", [
path.join(tmpPath, "something"),
]);
expect(stderr.toString()).toBe("");
expect(stdout.toString().split("\n")).toEqual(["message from something", ""]);
expect(code).toBe(0);
});
2 changes: 1 addition & 1 deletion packages/cli/src/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ let unregister = require(${JSON.stringify(
path.relative(distDirectory, entrypoint.package.project.directory)
)
)}, ${JSON.stringify(
normalizePath(path.relative(distDirectory, entrypoint.directory))
normalizePath(path.relative(distDirectory, entrypoint.package.directory))
)});
// this re-exports the source file
Expand Down

0 comments on commit 58df49f

Please sign in to comment.