Skip to content

Commit 0810a27

Browse files
committed
lint fix
1 parent 12c78fc commit 0810a27

File tree

2 files changed

+17
-30
lines changed

2 files changed

+17
-30
lines changed

packages/cloudflare/src/cli/build/utils/workerd.spec.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { describe, expect, test } from "vitest";
33
import { transformBuildCondition, transformPackageJson } from "./workerd";
44

55
describe("transformBuildCondition", () => {
6-
76
test("top level", () => {
87
const exports = {
98
workerd: "./path/to/workerd.js",
@@ -102,7 +101,6 @@ describe("transformBuildCondition", () => {
102101
},
103102
},
104103
});
105-
106104
});
107105
});
108106

@@ -119,8 +117,7 @@ describe("transformPackageJson", () => {
119117

120118
expect(transformed).toEqual(json);
121119
expect(hasBuildCondition).toBe(false);
122-
}
123-
);
120+
});
124121

125122
test("exports only with no workerd condition", () => {
126123
const json = {
@@ -135,7 +132,7 @@ describe("transformPackageJson", () => {
135132

136133
expect(transformed).toEqual(json);
137134
expect(hasBuildCondition).toBe(false);
138-
})
135+
});
139136

140137
test("exports only with nested workerd condition", () => {
141138
const json = {
@@ -177,7 +174,7 @@ describe("transformPackageJson", () => {
177174
},
178175
});
179176
expect(hasBuildCondition).toBe(true);
180-
})
177+
});
181178

182179
test("exports and imports with workerd condition both nested and top level", () => {
183180
const json = {
@@ -208,5 +205,5 @@ describe("transformPackageJson", () => {
208205
},
209206
});
210207
expect(hasBuildCondition).toBe(true);
211-
})
208+
});
212209
});

packages/cloudflare/src/cli/build/utils/workerd.ts

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,15 @@ import { getCrossPlatformPathRegex } from "@opennextjs/aws/utils/regex.js";
1515
* @param condition The build condition to look for
1616
* @returns An object with the transformed exports and a boolean indicating if the build condition was found
1717
*/
18-
export function transformBuildCondition(
19-
exports: { [key: string]: unknown },
20-
condition: string
21-
) {
18+
export function transformBuildCondition(exports: { [key: string]: unknown }, condition: string) {
2219
const transformed: { [key: string]: unknown } = {};
23-
const hasTopLevelBuildCondition = Object.keys(exports).some((key) => (key === condition && typeof exports[key] === "string"));
20+
const hasTopLevelBuildCondition = Object.keys(exports).some(
21+
(key) => key === condition && typeof exports[key] === "string"
22+
);
2423
let hasBuildCondition = hasTopLevelBuildCondition;
2524
for (const [key, value] of Object.entries(exports)) {
2625
if (typeof value === "object" && value != null) {
27-
const {transformedExports, hasBuildCondition: innerBuildCondition } = transformBuildCondition(
26+
const { transformedExports, hasBuildCondition: innerBuildCondition } = transformBuildCondition(
2827
value as { [key: string]: unknown },
2928
condition
3029
);
@@ -34,15 +33,14 @@ export function transformBuildCondition(
3433
// If it doesn't have the build condition, we need to keep everything as is
3534
// If it has the build condition, we need to keep only the build condition
3635
// and remove everything else
37-
if(!hasTopLevelBuildCondition) {
36+
if (!hasTopLevelBuildCondition) {
3837
transformed[key] = value;
39-
}else if (key === condition) {
38+
} else if (key === condition) {
4039
transformed[key] = value;
4140
}
42-
4341
}
4442
}
45-
return {transformedExports: transformed, hasBuildCondition};
43+
return { transformedExports: transformed, hasBuildCondition };
4644
}
4745
// We only care about these 2 fields
4846
interface PackageJson {
@@ -52,7 +50,7 @@ interface PackageJson {
5250
}
5351

5452
/**
55-
*
53+
*
5654
* @param json The package.json object
5755
* @returns An object with the transformed package.json and a boolean indicating if the build condition was found
5856
*/
@@ -69,7 +67,7 @@ export function transformPackageJson(json: PackageJson) {
6967
transformed.imports = imp.transformedExports;
7068
hasBuildCondition = hasBuildCondition || imp.hasBuildCondition;
7169
}
72-
return {transformed, hasBuildCondition};
70+
return { transformed, hasBuildCondition };
7371
}
7472

7573
export async function copyWorkerdPackages(options: BuildOptions, nodePackages: Map<string, string>) {
@@ -81,23 +79,15 @@ export async function copyWorkerdPackages(options: BuildOptions, nodePackages: M
8179
for (const [src, dst] of nodePackages.entries()) {
8280
try {
8381
const pkgJson = JSON.parse(await fs.readFile(path.join(src, "package.json"), "utf8"));
84-
const {transformed, hasBuildCondition} = transformPackageJson(pkgJson);
82+
const { transformed, hasBuildCondition } = transformPackageJson(pkgJson);
8583
const match = src.match(isNodeModuleRegex);
86-
if (
87-
match?.groups?.pkg &&
88-
externalPackages.includes(match.groups.pkg) &&
89-
hasBuildCondition
90-
) {
84+
if (match?.groups?.pkg && externalPackages.includes(match.groups.pkg) && hasBuildCondition) {
9185
logger.debug(
9286
`Copying package using a workerd condition: ${path.relative(options.appPath, src)} -> ${path.relative(options.appPath, dst)}`
9387
);
9488
fs.cp(src, dst, { recursive: true, force: true });
9589
// Write the transformed package.json
96-
await fs.writeFile(
97-
path.join(dst, "package.json"),
98-
JSON.stringify(transformed),
99-
"utf8"
100-
);
90+
await fs.writeFile(path.join(dst, "package.json"), JSON.stringify(transformed), "utf8");
10191
}
10292
} catch {
10393
logger.error(`Failed to copy ${src}`);

0 commit comments

Comments
 (0)