update-example-versions.js — astro Source File
Architecture documentation for update-example-versions.js, a javascript file in the astro codebase. 4 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 8c4e2ca6_f86d_b536_f8e4_62e5725e6e63["update-example-versions.js"] 5d6d1861_a18d_b246_cd94_08889ab7e74c["promises"] 8c4e2ca6_f86d_b536_f8e4_62e5725e6e63 --> 5d6d1861_a18d_b246_cd94_08889ab7e74c c52a5f83_66e3_37d7_9ebb_767f7129bc62["node:path"] 8c4e2ca6_f86d_b536_f8e4_62e5725e6e63 --> c52a5f83_66e3_37d7_9ebb_767f7129bc62 d9a92db9_c95e_9165_13ac_24b3d859d946["node:url"] 8c4e2ca6_f86d_b536_f8e4_62e5725e6e63 --> d9a92db9_c95e_9165_13ac_24b3d859d946 e64464d4_88a4_c7e2_f90f_758b06231bbe["tinyglobby"] 8c4e2ca6_f86d_b536_f8e4_62e5725e6e63 --> e64464d4_88a4_c7e2_f90f_758b06231bbe style 8c4e2ca6_f86d_b536_f8e4_62e5725e6e63 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
// @ts-check
import fs from 'node:fs/promises';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { glob } from 'tinyglobby';
/*
This file updates the dependencies' versions in `examples/*` to match the workspace packages' versions.
This should be run after `changeset version` so the release PR updates all the versions together.
*/
const rootUrl = new URL('../..', import.meta.url);
const rootPackageJson = JSON.parse(await fs.readFile(new URL('./package.json', rootUrl), 'utf-8'));
// get all workspace package name to versions
/** @type {Map<string, string>} */
const packageToVersions = new Map();
// Changeset detects workspace packages to publish via `workspaces` in package.json.
// Although this conflicts with the `pnpm-workspace.yaml` config, it's easier to configure what gets
// published through this field, so this file also respects this field when updating the versions.
const workspaceDirs = await glob(rootPackageJson.workspaces, {
onlyDirectories: true,
cwd: fileURLToPath(rootUrl),
});
for (const workspaceDir of workspaceDirs) {
const packageJsonPath = path.join(workspaceDir, './package.json');
const packageJson = await readAndParsePackageJson(packageJsonPath);
if (!packageJson) continue;
if (packageJson.private === true) continue;
if (!packageJson.name) {
throw new Error(`${packageJsonPath} does not contain a "name" field.`);
}
if (!packageJson.version) {
throw new Error(`${packageJsonPath} does not contain a "version" field.`);
}
packageToVersions.set(packageJson.name, packageJson.version);
}
// Update all examples' package.json
const exampleDirs = await glob('examples/*', {
onlyDirectories: true,
cwd: fileURLToPath(rootUrl),
});
for (const exampleDir of exampleDirs) {
const packageJsonPath = path.join(exampleDir, './package.json');
const packageJson = await readAndParsePackageJson(packageJsonPath);
if (!packageJson) continue;
// Update dependencies
for (const depName of Object.keys(packageJson.dependencies ?? [])) {
if (packageToVersions.has(depName)) {
packageJson.dependencies[depName] = `^${packageToVersions.get(depName)}`;
}
}
// Update devDependencies
for (const depName of Object.keys(packageJson.devDependencies ?? [])) {
if (packageToVersions.has(depName)) {
packageJson.devDependencies[depName] = `^${packageToVersions.get(depName)}`;
}
}
await fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n');
}
/**
* @param {string} packageJsonPath
* @returns {Promise<Record<string, any> | undefined>}
*/
async function readAndParsePackageJson(packageJsonPath) {
try {
return JSON.parse(await fs.readFile(packageJsonPath, 'utf-8'));
} catch {}
}
Domain
Subdomains
Functions
Dependencies
- node:path
- node:url
- promises
- tinyglobby
Source
Frequently Asked Questions
What does update-example-versions.js do?
update-example-versions.js is a source file in the astro codebase, written in javascript. It belongs to the CoreAstro domain, RenderingEngine subdomain.
What functions are defined in update-example-versions.js?
update-example-versions.js defines 1 function(s): readAndParsePackageJson.
What does update-example-versions.js depend on?
update-example-versions.js imports 4 module(s): node:path, node:url, promises, tinyglobby.
Where is update-example-versions.js in the architecture?
update-example-versions.js is located at scripts/deps/update-example-versions.js (domain: CoreAstro, subdomain: RenderingEngine, directory: scripts/deps).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free