Skip to content

Commit 4e82fe2

Browse files
committed
Fix remarks to PR
1 parent 58f6d40 commit 4e82fe2

1 file changed

Lines changed: 21 additions & 21 deletions

File tree

packages/cloudflare/src/cli/commands/populate-cache.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { copyFileSync, cpSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
1+
import fs from "node:fs";
22
import fsp from "node:fs/promises";
3-
import { tmpdir } from "node:os";
3+
import os from "node:os";
44
import path from "node:path";
55

66
import type { BuildOptions } from "@opennextjs/aws/build/helper.js";
@@ -92,7 +92,7 @@ export async function populateCache(
9292
) {
9393
const { incrementalCache, tagCache } = config.default.override ?? {};
9494

95-
if (!existsSync(buildOpts.outputDir)) {
95+
if (!fs.existsSync(buildOpts.outputDir)) {
9696
logger.error("Unable to populate cache: Open Next build not found");
9797
process.exit(1);
9898
}
@@ -213,7 +213,7 @@ type PopulateCacheOptions = {
213213
* @returns Path to the temporary config file or null if env vars not available
214214
*/
215215
function createTempRcloneConfig(accessKey: string, secretKey: string, accountId: string): string | null {
216-
const tempDir = tmpdir();
216+
const tempDir = os.tmpdir();
217217
const tempConfigPath = path.join(tempDir, `rclone-config-${Date.now()}.conf`);
218218

219219
const configContent = `[r2]
@@ -226,7 +226,7 @@ acl = private
226226
`;
227227

228228
// 0o600 means readable and writable by the file owner
229-
writeFileSync(tempConfigPath, configContent, { mode: 0o600 });
229+
fs.writeFileSync(tempConfigPath, configContent, { mode: 0o600 });
230230
return tempConfigPath;
231231
}
232232

@@ -267,14 +267,14 @@ async function populateR2IncrementalCacheWithBatchUpload(
267267
logger.info("Using rclone with R2 credentials from environment variables");
268268

269269
// Create a staging dir in temp directory with proper key paths
270-
const tempDir = tmpdir();
270+
const tempDir = os.tmpdir();
271271
const stagingDir = path.join(tempDir, `.r2-staging-${Date.now()}`);
272272

273273
// Track success to ensure cleanup happens correctly
274274
let success = null;
275275

276276
try {
277-
mkdirSync(stagingDir, { recursive: true });
277+
fs.mkdirSync(stagingDir, { recursive: true });
278278

279279
for (const { fullPath, key, buildId, isFetch } of assets) {
280280
const cacheKey = computeCacheKey(key, {
@@ -283,8 +283,8 @@ async function populateR2IncrementalCacheWithBatchUpload(
283283
cacheType: isFetch ? "fetch" : "cache",
284284
});
285285
const destPath = path.join(stagingDir, cacheKey);
286-
mkdirSync(path.dirname(destPath), { recursive: true });
287-
copyFileSync(fullPath, destPath);
286+
fs.mkdirSync(path.dirname(destPath), { recursive: true });
287+
fs.copyFileSync(fullPath, destPath);
288288
}
289289

290290
// Use rclone.js to sync the R2
@@ -303,16 +303,16 @@ async function populateR2IncrementalCacheWithBatchUpload(
303303
} finally {
304304
try {
305305
// Cleanup temporary staging directory
306-
rmSync(stagingDir, { recursive: true, force: true });
306+
fs.rmSync(stagingDir, { recursive: true, force: true });
307307
} catch {
308308
logger.info(`Failed to remove temporary staging directory at ${stagingDir}`);
309309
}
310310

311311
try {
312312
// Cleanup temporary config file
313-
rmSync(tempConfigPath);
313+
fs.rmSync(tempConfigPath);
314314
} catch {
315-
console.warn(`Failed to remove temporary config at ${tempConfigPath}`);
315+
logger.warn(`Failed to remove temporary config at ${tempConfigPath}`);
316316
}
317317
}
318318

@@ -344,10 +344,10 @@ async function populateR2WithWranglerBulkPut(
344344
file: fullPath,
345345
}));
346346

347-
const tempDir = path.join(tmpdir(), `open-next-${Date.now()}`);
348-
mkdirSync(tempDir, { recursive: true });
347+
const tempDir = path.join(os.tmpdir(), `open-next-${Date.now()}`);
348+
fs.mkdirSync(tempDir, { recursive: true });
349349
const listFile = path.join(tempDir, `r2-bulk-list.json`);
350-
writeFileSync(listFile, JSON.stringify(objectList));
350+
fs.writeFileSync(listFile, JSON.stringify(objectList));
351351

352352
const concurrency = Math.max(1, populateCacheOptions.cacheChunkSize ?? 50);
353353
const jurisdictionFlag = jurisdiction ? `--jurisdiction ${jurisdiction}` : "";
@@ -371,7 +371,7 @@ async function populateR2WithWranglerBulkPut(
371371
}
372372
);
373373

374-
rmSync(listFile, { force: true });
374+
fs.rmSync(listFile, { force: true });
375375

376376
logger.info(`Successfully populated cache with ${assets.length} assets`);
377377
}
@@ -454,7 +454,7 @@ async function populateKVIncrementalCache(
454454

455455
logger.info(`Inserting ${assets.length} assets to KV in chunks of ${chunkSize}`);
456456

457-
const tempDir = await fsp.mkdtemp(path.join(tmpdir(), "open-next-"));
457+
const tempDir = await fsp.mkdtemp(path.join(os.tmpdir(), "open-next-"));
458458

459459
for (const i of tqdm(Array.from({ length: totalChunks }, (_, i) => i))) {
460460
const chunkPath = path.join(tempDir, `cache-chunk-${i}.json`);
@@ -467,10 +467,10 @@ async function populateKVIncrementalCache(
467467
buildId,
468468
cacheType: isFetch ? "fetch" : "cache",
469469
}),
470-
value: readFileSync(fullPath, "utf8"),
470+
value: fs.readFileSync(fullPath, "utf8"),
471471
}));
472472

473-
writeFileSync(chunkPath, JSON.stringify(kvMapping));
473+
fs.writeFileSync(chunkPath, JSON.stringify(kvMapping));
474474

475475
runWrangler(
476476
buildOpts,
@@ -488,7 +488,7 @@ async function populateKVIncrementalCache(
488488
}
489489
);
490490

491-
rmSync(chunkPath, { force: true });
491+
fs.rmSync(chunkPath, { force: true });
492492
}
493493

494494
logger.info(`Successfully populated cache with ${assets.length} assets`);
@@ -530,7 +530,7 @@ function populateD1TagCache(
530530
function populateStaticAssetsIncrementalCache(options: BuildOptions) {
531531
logger.info("\nPopulating Workers static assets...");
532532

533-
cpSync(
533+
fs.cpSync(
534534
path.join(options.outputDir, "cache"),
535535
path.join(options.outputDir, "assets", STATIC_ASSETS_CACHE_DIR),
536536
{ recursive: true }

0 commit comments

Comments
 (0)