Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(remix-dev): allow serverBuildPath to end with .cjs #7180

Merged
merged 4 commits into from
Sep 8, 2023
Merged
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
7 changes: 7 additions & 0 deletions .changeset/wild-steaks-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@remix-run/dev": patch
---

Fix server builds where serverBuildPath extension is `.cjs`.

Fix a bug that caused the server build file to be emitted into the assets directory if the value of `serverBuildPath` ended in `.cjs`.
35 changes: 35 additions & 0 deletions integration/compiler-mjs-cjs-output-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { test, expect } from "@playwright/test";
import * as fs from "node:fs";
import * as path from "node:path";

import { createFixtureProject, js } from "./helpers/create-fixture.js";

test.describe("", () => {
for (let [serverModuleExt, serverModuleFormat, exportStatement] of [
["mjs", "esm", "export {"],
["cjs", "cjs", "module.exports ="],
]) {
test(`can write .${serverModuleExt} server output module`, async () => {
let projectDir = await createFixtureProject({
files: {
// Ensure the config is valid ESM
"remix.config.js": js`
export default {
serverModuleFormat: "${serverModuleFormat}",
serverBuildPath: "build/index.${serverModuleExt}",
};
`,
},
});

let buildPath = path.resolve(
projectDir,
"build",
`index.${serverModuleExt}`
);
expect(fs.existsSync(buildPath), "doesn't exist").toBe(true);
let contents = fs.readFileSync(buildPath, "utf8");
expect(contents, "no export statement").toContain(exportStatement);
});
}
});
69 changes: 0 additions & 69 deletions integration/compiler-mjs-output-test.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/remix-dev/compiler/server/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export async function write(
await fse.ensureDir(path.dirname(config.serverBuildPath));

for (let file of outputFiles) {
if (file.path.endsWith(".js") || file.path.endsWith(".mjs")) {
if ([".js", ".cjs", ".mjs"].some((ext) => file.path.endsWith(ext))) {
// fix sourceMappingURL to be relative to current path instead of /build
let filename = file.path.substring(file.path.lastIndexOf(path.sep) + 1);
let escapedFilename = filename.replace(/\./g, "\\.");
Expand Down