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: write other server build output files #3817

Merged
merged 6 commits into from
Jul 25, 2022
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
6 changes: 6 additions & 0 deletions .changeset/famous-schools-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"remix": patch
"@remix-run/dev": patch
---

write other server build output files so that assets only imported in resource routes are written to disk
Binary file added integration/assets/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 7 additions & 2 deletions integration/helpers/create-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const TMP_DIR = path.join(process.cwd(), ".tmp", "integration");
interface FixtureInit {
buildStdio?: Writable;
sourcemap?: boolean;
files?: { [filename: string]: string };
files?: { [filename: string]: string | Buffer };
template?: "cf-template" | "deno-template" | "node-template";
setup?: "node" | "cloudflare";
}
Expand Down Expand Up @@ -205,7 +205,12 @@ async function writeTestFiles(init: FixtureInit, dir: string) {
Object.keys(init.files ?? {}).map(async (filename) => {
let filePath = path.join(dir, filename);
await fse.ensureDir(path.dirname(filePath));
await fse.writeFile(filePath, stripIndent(init.files![filename]));
let file = init.files![filename];
if (typeof file === "string") {
await fse.writeFile(filePath, stripIndent(file));
} else {
await fse.writeFile(filePath, file);
}
})
);
}
24 changes: 24 additions & 0 deletions integration/resource-routes-test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import path from "node:path";
import fse from "fs-extra";
import { test, expect } from "@playwright/test";

import { createAppFixture, createFixture, js } from "./helpers/create-fixture";
Expand All @@ -7,6 +9,8 @@ import { PlaywrightFixture } from "./helpers/playwright-fixture";
test.describe("loader in an app", () => {
let appFixture: AppFixture;

let image = fse.readFileSync(path.join(__dirname, "./assets/image.png"));

test.beforeAll(async () => {
appFixture = await createAppFixture(
await createFixture({
Expand Down Expand Up @@ -47,6 +51,20 @@ test.describe("loader in an app", () => {
import { json } from "@remix-run/node";
export let loader = () => json({hello: "world"});
`,
"app/assets/image.png": image,
"app/routes/image[.]png.jsx": js`
import fs from "node:fs";
import path from "node:path";
import image from "~/assets/image.png";

export let loader = () => {
return new Response(fs.readFileSync(path.join(__dirname, "..", image)), {
headers: {
"Content-Type": "image/png",
},
});
};
`,
},
})
);
Expand Down Expand Up @@ -85,5 +103,11 @@ test.describe("loader in an app", () => {
await app.goto("/data.json");
expect(await page.content()).toContain('{"hello":"world"}');
});

test("should include imported asset in build", async ({ page }) => {
let app = new PlaywrightFixture(appFixture, page);
let res = await app.goto("/image.png");
expect(res.status()).toBe(200);
});
}
});
3 changes: 3 additions & 0 deletions packages/remix-dev/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,9 @@ async function writeServerBuildResult(
let contents = Buffer.from(file.contents).toString("utf-8");
contents = contents.replace(/"route:/gm, '"');
await fse.writeFile(file.path, contents);
} else {
await fse.ensureDir(path.dirname(file.path));
await fse.writeFile(file.path, file.contents);
}
}
}