Skip to content

Commit a1c5107

Browse files
authored
fix: bump package.json version in sync (#1913)
* fix: update package.json versions in sync-docs with minimal lockfile changes * fmt² * From 3 to 5min
1 parent eab3e1e commit a1c5107

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

  • apps/svelte.dev/scripts/sync-docs

apps/svelte.dev/scripts/sync-docs/index.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ const filtered =
237237
: packages.filter((pkg) => !!branches[get_trigger(pkg)]);
238238

239239
/** Retry `fn` every `interval`ms until it returns true or `timeout` is reached */
240-
async function wait_until(fn: () => Promise<boolean>, interval = 10_000, timeout = 3 * 60_000) {
240+
async function wait_until(fn: () => Promise<boolean>, interval = 10_000, timeout = 5 * 60_000) {
241241
const deadline = Date.now() + timeout;
242242
while (Date.now() < deadline) {
243243
if (await fn()) return true;
@@ -302,15 +302,29 @@ async function resolve_npm_packages(packages: Package[]) {
302302
}
303303
}
304304

305-
/** Update dependencies to latest published versions (for main branch syncs) */
305+
/** Update package.json to latest published npm versions (for main branch syncs) */
306306
async function update_published_packages(packages: Package[]) {
307307
const names = packages
308308
.filter((pkg) => pkg.npm_packages?.length && pkg.branch === 'main')
309309
.flatMap((pkg) => pkg.npm_packages!);
310310

311311
if (!names.length) return;
312312

313-
await invoke('pnpm', ['update', ...names], { cwd: path.join(dirname, '../..') });
313+
const pkg_json_path = path.join(dirname, '../../package.json');
314+
const pkg_json = JSON.parse(fs.readFileSync(pkg_json_path, 'utf-8'));
315+
316+
for (const name of names) {
317+
const latest = execSync(`npm view ${name} version`, { encoding: 'utf-8' }).trim();
318+
const section =
319+
pkg_json.dependencies?.[name] !== undefined ? 'dependencies' : 'devDependencies';
320+
pkg_json[section][name] = `^${latest}`;
321+
}
322+
323+
fs.writeFileSync(pkg_json_path, JSON.stringify(pkg_json, null, '\t') + '\n');
324+
execSync('pnpm install --lockfile-only', {
325+
cwd: path.join(dirname, '../../../..'),
326+
stdio: 'inherit'
327+
});
314328
}
315329

316330
/**

0 commit comments

Comments
 (0)