Skip to content

Commit

Permalink
chore: write mjs server output files (#6225)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-ebey committed Apr 28, 2023
1 parent 22280ee commit 39f6405
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/clever-hairs-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/dev": patch
---

write mjs server output files
79 changes: 79 additions & 0 deletions integration/compiler-mjs-output-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
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";

let projectDir: string;

test.beforeAll(async () => {
projectDir = await createFixtureProject({
future: { v2_routeConvention: true },
files: {
"package.json": js`
{
"name": "remix-template-remix",
"private": true,
"sideEffects": false,
"type": "module",
"scripts": {
"build": "node ../../../build/node_modules/@remix-run/dev/dist/cli.js build",
"dev": "node ../../../build/node_modules/@remix-run/dev/dist/cli.js dev",
"start": "node ../../../build/node_modules/@remix-run/serve/dist/cli.js build"
},
"dependencies": {
"@remix-run/node": "0.0.0-local-version",
"@remix-run/react": "0.0.0-local-version",
"@remix-run/serve": "0.0.0-local-version",
"isbot": "0.0.0-local-version",
"react": "0.0.0-local-version",
"react-dom": "0.0.0-local-version"
},
"devDependencies": {
"@remix-run/dev": "0.0.0-local-version",
"@types/react": "0.0.0-local-version",
"@types/react-dom": "0.0.0-local-version",
"typescript": "0.0.0-local-version"
},
"engines": {
"node": ">=14"
}
}
`,
"remix.config.js": js`
export default {
serverModuleFormat: "esm",
serverBuildPath: "build/index.mjs",
future: {
v2_routeConvention: true,
},
};
`,
"app/routes/_index.jsx": js`
import { json } from "@remix-run/node";
import { useLoaderData, Link } from "@remix-run/react";
export function loader() {
return json("pizza");
}
export default function Index() {
let data = useLoaderData();
return (
<div>
{data}
<Link to="/burgers">Other Route</Link>
</div>
)
}
`,
},
});
});

test("can write .mjs server output module", () => {
let buildPath = path.resolve(projectDir, "build", "index.mjs");
expect(fs.existsSync(buildPath), "doesn't exist").toBe(true);
let contents = fs.readFileSync(buildPath, "utf8");
expect(contents, "no export statement").toContain("export {");
});
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")) {
if (file.path.endsWith(".js") || file.path.endsWith(".mjs")) {
// 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

0 comments on commit 39f6405

Please sign in to comment.