Skip to content

Commit 18c96f9

Browse files
authored
chore: avoid fs/promises unless multi-tasking (#2406)
1 parent eb1945d commit 18c96f9

File tree

5 files changed

+24
-16
lines changed

5 files changed

+24
-16
lines changed

scripts/apply-config-plugins.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22
// @ts-check
33

4-
import * as fs from "node:fs/promises";
4+
import * as fs from "node:fs";
55
import * as path from "node:path";
66
import { parseArgs } from "node:util";
77
import { findFile } from "./helpers.js";
@@ -17,7 +17,7 @@ async function main(projectRoot = process.cwd(), platforms) {
1717
throw new Error("Failed to find `package.json`");
1818
}
1919

20-
const content = await fs.readFile(packageJsonPath, { encoding: "utf-8" });
20+
const content = fs.readFileSync(packageJsonPath, { encoding: "utf-8" });
2121
if (!content.includes('"@expo/config-plugins"')) {
2222
return;
2323
}

scripts/config-plugins/apply.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @ts-check
2-
import * as fs from "node:fs/promises";
2+
import * as fs from "node:fs";
33
import { withPlugins } from "./ExpoConfigPlugins.mjs";
44
import { compileModsAsync } from "./plugins/mod-compiler.mjs";
55
import { withInternal } from "./plugins/withInternal.mjs";
@@ -14,7 +14,7 @@ export async function applyConfigPlugins({ appJsonPath, ...info }) {
1414
return;
1515
}
1616

17-
const content = await fs.readFile(appJsonPath, { encoding: "utf-8" });
17+
const content = fs.readFileSync(appJsonPath, { encoding: "utf-8" });
1818
const { plugins, ...config } = JSON.parse(content);
1919
if (!Array.isArray(plugins) || plugins.length === 0) {
2020
return;

scripts/internal/generate-manifest.mts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// eslint-disable-next-line no-restricted-imports
22
import type { SchemaObject } from "ajv";
3-
import * as fs from "node:fs/promises";
3+
import * as fs from "node:fs";
44
import * as path from "node:path";
55
import { URL, fileURLToPath } from "node:url";
66
import { generateSchema } from "../schema.mjs";
@@ -200,7 +200,7 @@ function generateType(
200200
/**
201201
* Generates manifest data models and writes them to specified path.
202202
*/
203-
async function generate(schema: SchemaObject, output: string) {
203+
function generate(schema: SchemaObject, output: string) {
204204
const lang = getLanguage(output);
205205
const lines = [
206206
`// This file was generated by ${path.basename(thisScript)}.`,
@@ -226,17 +226,17 @@ async function generate(schema: SchemaObject, output: string) {
226226

227227
const code = lines.join("\n");
228228

229-
const content = await fs.readFile(output, { encoding: "utf-8" });
229+
const content = fs.readFileSync(output, { encoding: "utf-8" });
230230
if (content !== code) {
231-
fs.writeFile(output, code);
231+
fs.writeFileSync(output, code);
232232
}
233233
}
234234

235235
function main() {
236236
const schema = generateSchema();
237237
const projectDir = fileURLToPath(new URL("../..", import.meta.url));
238238

239-
[
239+
const outputs = [
240240
path.join(
241241
projectDir,
242242
"android",
@@ -252,7 +252,15 @@ function main() {
252252
),
253253
path.join(projectDir, "ios", "ReactTestApp", "Manifest.swift"),
254254
path.join(projectDir, "windows", "Shared", "Manifest.h"),
255-
].forEach((output) => generate(schema, output).catch(console.error));
255+
];
256+
257+
for (const output of outputs) {
258+
try {
259+
generate(schema, output);
260+
} catch (e) {
261+
console.error(e);
262+
}
263+
}
256264
}
257265

258266
main();

scripts/internal/generate-schema.mts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,12 @@ export async function readDocumentation(): Promise<Partial<Docs>> {
6363
"windows.certificateThumbprint",
6464
];
6565

66+
const fileReadOptions = { encoding: "utf-8" } as const;
67+
6668
await Promise.all(
6769
keys.map(async (name) => {
6870
const filename = path.join(docsDir, name + ".md");
69-
const md = await fs.readFile(filename, { encoding: "utf-8" });
71+
const md = await fs.readFile(filename, fileReadOptions);
7072
docs[name] = stripCarriageReturn(md).trim();
7173
})
7274
);

test/android/gradle.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,9 @@ async function makeProject(
7777
await writeAllFiles(files, packagePath);
7878

7979
try {
80-
await fsp.symlink(
81-
fileURLToPath(new URL("../../example/node_modules", import.meta.url)),
82-
path.join(packagePath, "node_modules"),
83-
"dir"
84-
);
80+
const target = new URL("../../example/node_modules", import.meta.url);
81+
const nodeModulesDir = path.join(packagePath, "node_modules");
82+
fs.symlinkSync(fileURLToPath(target), nodeModulesDir, "dir");
8583
} catch (e) {
8684
if (e && typeof e === "object" && "code" in e && e.code !== "EEXIST") {
8785
throw e;

0 commit comments

Comments
 (0)