Skip to content

Commit 675abe4

Browse files
committed
fixup! add test
1 parent 2edb99a commit 675abe4

File tree

3 files changed

+88
-3
lines changed

3 files changed

+88
-3
lines changed

packages/cloudflare/src/cli/build/patches/plugins/build-id.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Inline `getBuildId` as it relies on `readFileSync`that is not supported by workerd.
2+
* Inline `getBuildId` as it relies on `readFileSync` that is not supported by workerd.
33
*/
44

55
import { getCrossPlatformPathRegex } from "@opennextjs/aws/utils/regex.js";
@@ -18,7 +18,7 @@ export function inlineBuildId(updater: ContentUpdater) {
1818
);
1919
}
2020

21-
const rule = `
21+
export const rule = `
2222
rule:
2323
kind: method_definition
2424
has:
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import { describe, expect, test } from "vitest";
2+
3+
import { patchCode } from "../ast/util.js";
4+
import { rule } from "./build-id.js";
5+
6+
describe("getBuildId", () => {
7+
test("patch", () => {
8+
const code = `
9+
class NextNodeServer extends _baseserver.default {
10+
constructor(options){
11+
// Initialize super class
12+
super(options);
13+
this.handleNextImageRequest = async (req, res, parsedUrl) => { /* ... */ };
14+
}
15+
async handleUpgrade() {
16+
// The web server does not support web sockets, it's only used for HMR in
17+
// development.
18+
}
19+
loadEnvConfig({ dev, forceReload, silent }) {
20+
(0, _env.loadEnvConfig)(this.dir, dev, silent ? {
21+
info: ()=>{},
22+
error: ()=>{}
23+
} : _log, forceReload);
24+
}
25+
async hasPage(pathname) {
26+
var _this_nextConfig_i18n;
27+
return !!(0, _require.getMaybePagePath)(pathname, this.distDir, (_this_nextConfig_i18n = this.nextConfig.i18n) == null ? void 0 : _this_nextConfig_i18n.locales, this.enabledDirectories.app);
28+
}
29+
getBuildId() {
30+
const buildIdFile = (0, _path.join)(this.distDir, _constants.BUILD_ID_FILE);
31+
try {
32+
return _fs.default.readFileSync(buildIdFile, "utf8").trim();
33+
} catch (err) {
34+
if (err.code === "ENOENT") {
35+
throw new Error(\`Could not find a production build in the '${this.distDir}' directory. Try building your app with 'next build' before starting the production server. https://nextjs.org/docs/messages/production-start-no-build-id\`);
36+
}
37+
throw err;
38+
}
39+
}
40+
getEnabledDirectories(dev) {
41+
const dir = dev ? this.dir : this.serverDistDir;
42+
return {
43+
app: (0, _findpagesdir.findDir)(dir, "app") ? true : false,
44+
pages: (0, _findpagesdir.findDir)(dir, "pages") ? true : false
45+
};
46+
}
47+
// ...
48+
}`;
49+
50+
expect(patchCode(code, rule)).toMatchInlineSnapshot(`
51+
"class NextNodeServer extends _baseserver.default {
52+
constructor(options){
53+
// Initialize super class
54+
super(options);
55+
this.handleNextImageRequest = async (req, res, parsedUrl) => { /* ... */ };
56+
}
57+
async handleUpgrade() {
58+
// The web server does not support web sockets, it's only used for HMR in
59+
// development.
60+
}
61+
loadEnvConfig({ dev, forceReload, silent }) {
62+
(0, _env.loadEnvConfig)(this.dir, dev, silent ? {
63+
info: ()=>{},
64+
error: ()=>{}
65+
} : _log, forceReload);
66+
}
67+
async hasPage(pathname) {
68+
var _this_nextConfig_i18n;
69+
return !!(0, _require.getMaybePagePath)(pathname, this.distDir, (_this_nextConfig_i18n = this.nextConfig.i18n) == null ? void 0 : _this_nextConfig_i18n.locales, this.enabledDirectories.app);
70+
}
71+
getBuildId() {
72+
return process.env.NEXT_BUILD_ID;
73+
}
74+
getEnabledDirectories(dev) {
75+
const dir = dev ? this.dir : this.serverDistDir;
76+
return {
77+
app: (0, _findpagesdir.findDir)(dir, "app") ? true : false,
78+
pages: (0, _findpagesdir.findDir)(dir, "pages") ? true : false
79+
};
80+
}
81+
// ...
82+
}"
83+
`);
84+
});
85+
});

packages/cloudflare/src/cli/build/patches/plugins/load-manifest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Inline `loadManifest` as it relies on `readFileSync`that is not supported by workerd.
2+
* Inline `loadManifest` as it relies on `readFileSync` that is not supported by workerd.
33
*/
44

55
import { readFile } from "node:fs/promises";

0 commit comments

Comments
 (0)