Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions .github/scripts/upgrade-deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@ type PnpmWorkspaceEntry = {
newVersion: string;
};

type PackageJson = {
devDependencies?: Record<string, string>;
peerDependencies?: Record<string, string>;
};

const STABLE_SEMVER_TAG_RE = /^v?\d+\.\d+\.\d+$/;

const isFullSha = (s: string): boolean => /^[0-9a-f]{40}$/.test(s);
Expand Down Expand Up @@ -465,23 +460,6 @@ async function updateReadmeVitestPins(vitestVersion: string): Promise<void> {
recordChange('README vitest pins', oldVersion ?? null, vitestVersion);
}

// ============ Update packages/core/package.json ============
async function updateCorePackage(devtoolsVersion: string): Promise<void> {
const filePath = path.join(ROOT, 'packages/core/package.json');
const pkg: PackageJson = readJsonFile(filePath);

const devDependencies = pkg.devDependencies;
const currentDevtools = devDependencies?.['@vitejs/devtools'];
if (!currentDevtools) {
return;
}
devDependencies['@vitejs/devtools'] = `^${devtoolsVersion}`;
recordChange('@vitejs/devtools', currentDevtools.replace(/^[\^~]/, ''), devtoolsVersion);

fs.writeFileSync(filePath, JSON.stringify(pkg, null, 2) + '\n');
console.log('Updated packages/core/package.json');
}

// ============ Write metadata files for PR description ============
function writeMetaFiles(): void {
if (!META_DIR) {
Expand Down Expand Up @@ -565,7 +543,6 @@ const [
tsdownVersion,
stableTsdownMigrateVersion,
lightningcssVersion,
devtoolsVersion,
oxcNodeCliVersion,
oxcNodeCoreVersion,
oxfmtVersion,
Expand All @@ -582,7 +559,6 @@ const [
getLatestNpmVersion('tsdown-migrate'),
// Mirror exactly what the bundled @tsdown/css depends on.
getNpmDependencyRange('@tsdown/css', 'lightningcss'),
getLatestNpmVersion('@vitejs/devtools'),
getLatestNpmVersion('@oxc-node/cli'),
getLatestNpmVersion('@oxc-node/core'),
getLatestNpmVersion('oxfmt'),
Expand All @@ -599,7 +575,6 @@ console.log(`vitest: ${vitestVersion}`);
console.log(`tsdown: ${tsdownVersion}`);
console.log(`tsdown-migrate (stable): ${stableTsdownMigrateVersion}`);
console.log(`lightningcss (from @tsdown/css): ${lightningcssVersion}`);
console.log(`@vitejs/devtools: ${devtoolsVersion}`);
console.log(`@oxc-node/cli: ${oxcNodeCliVersion}`);
console.log(`@oxc-node/core: ${oxcNodeCoreVersion}`);
console.log(`oxfmt: ${oxfmtVersion}`);
Expand Down Expand Up @@ -630,8 +605,6 @@ await updatePnpmWorkspace({
await updateTsdownMigrateVersion(tsdownVersion, stableTsdownMigrateVersion);
await updateVitestVersionConstant(vitestVersion);
await updateReadmeVitestPins(vitestVersion);
await updateCorePackage(devtoolsVersion);

writeMetaFiles();

console.log('Done!');
22 changes: 12 additions & 10 deletions packages/core/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,11 +498,10 @@ async function bundleTsdown() {
await copyFile(join(tsdownSourceDir, 'client.d.ts'), join(projectDir, 'dist/tsdown/client.d.ts'));
}

// Ensure a bundled chunk imports the given ansis color helpers (e.g. `bold`,
// `red`) from the shared `main-*.js` chunk. tsdown's logger module does not
// import every color the Vite+ branding uses, so after the logger patches we
// add any missing ones, resolving their (minified) export aliases from main's
// own `export { ... }` map so the fix survives rolldown renaming them.
// Ensure a bundled chunk has the given ansis color helpers (e.g. `bold`, `red`).
// Rolldown can inline ansis into the logger chunk or keep it in a shared chunk.
// For the latter layout, add imports for any missing helpers by resolving their
// minified aliases from the shared chunk's own `export { ... }` map.
async function ensureAnsisImports(
content: string,
names: string[],
Expand All @@ -515,10 +514,6 @@ async function ensureAnsisImports(
// chunk actually re-exports it.
const importRe = /import \{([^}]*)\} from "(\.\/[^"]+\.js)";/g;
const imports = [...content.matchAll(importRe)];
if (imports.length === 0) {
throw new Error('ensureAnsisImports: no relative chunk import found in branded logger chunk');
}

// Every binding already in scope across all imports (its local name).
const localNames = new Set<string>();
for (const [, bindings] of imports) {
Expand All @@ -531,10 +526,17 @@ async function ensureAnsisImports(
localNames.add(aliased ? aliased[1] : trimmed);
}
}
const missing = names.filter((name) => !localNames.has(name));
// Rolldown can also inline ansis into the logger chunk. Detect its destructured
// declarations so we do not try to import a binding that is already local.
const isLocallyDeclared = (name: string) =>
new RegExp(`\\b(?:const|let|var)\\s+(?:${name}\\b|\\{[^}]*\\b${name}\\b)`).test(content);
const missing = names.filter((name) => !localNames.has(name) && !isLocallyDeclared(name));
if (missing.length === 0) {
return content;
}
if (imports.length === 0) {
throw new Error('ensureAnsisImports: no relative chunk import found in branded logger chunk');
}

// Group missing colors by the imported chunk that re-exports them. Chunks
// re-export colors as `<local> as <alias>` (e.g. `bold as i`); the consumer
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
"@oxc-node/cli": "catalog:",
"@tsdown/css": "catalog:",
"@tsdown/exe": "catalog:",
"@vitejs/devtools": "^0.5.2",
"@vitejs/devtools": "^0.4.12",
"es-module-lexer": "^1.7.0",
"hookable": "^6.0.1",
"magic-string": "^0.30.21",
Expand Down
30 changes: 29 additions & 1 deletion packages/tools/src/__tests__/sync-remote-deps.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,35 @@
import * as semver from 'semver';
import { describe, expect, test } from 'vitest';

import { mergePnpmWorkspaces, syncCargoOxcVersions } from '../sync-remote-deps.ts';
import {
mergePnpmWorkspaces,
syncCargoOxcVersions,
syncViteDevtoolsDependencies,
} from '../sync-remote-deps.ts';

describe('syncViteDevtoolsDependencies()', () => {
test('uses the DevTools ranges declared by Vite', () => {
const corePackage = {
devDependencies: { '@vitejs/devtools': '^0.6.1' },
peerDependencies: { '@vitejs/devtools': '^0.4.0 || ^0.5.0 || ^0.6.0' },
};
const vitePackage = {
devDependencies: { '@vitejs/devtools': '^0.4.12' },
peerDependencies: { '@vitejs/devtools': '^0.4.0 || ^0.5.0' },
};

syncViteDevtoolsDependencies(corePackage, vitePackage);

expect(corePackage.devDependencies['@vitejs/devtools']).toBe('^0.4.12');
expect(corePackage.peerDependencies['@vitejs/devtools']).toBe('^0.4.0 || ^0.5.0');
});

test('fails when Vite no longer declares a DevTools range', () => {
expect(() => syncViteDevtoolsDependencies({}, {})).toThrow(
'Vite package.json must define @vitejs/devtools in devDependencies and peerDependencies',
);
});
});

describe('mergePnpmWorkspaces() minimumReleaseAgeExclude', () => {
test('drops versioned upstream entries already covered by a glob or bare pattern', () => {
Expand Down
36 changes: 30 additions & 6 deletions packages/tools/src/sync-remote-deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ interface PnpmWorkspace {
interface PackageJson {
name?: string;
version?: string;
devDependencies?: Record<string, string>;
peerDependencies?: Record<string, string>;
exports?: Record<string, unknown>;
[key: string]: unknown;
}
Expand All @@ -33,6 +35,7 @@ type ExportValue = string | { [condition: string]: string | ExportValue } | null
const ROLLDOWN_DIR = 'rolldown';
const VITE_DIR = 'vite';
const CORE_PACKAGE_PATH = 'packages/core';
const VITE_DEVTOOLS_PACKAGE = '@vitejs/devtools';

function log(message: string) {
console.log(`[sync-rolldown] ${message}`);
Expand Down Expand Up @@ -332,6 +335,22 @@ function mergePackageExports(
);
}

export function syncViteDevtoolsDependencies(corePkg: PackageJson, vitePkg: PackageJson): void {
const devRange = vitePkg.devDependencies?.[VITE_DEVTOOLS_PACKAGE];
const peerRange = vitePkg.peerDependencies?.[VITE_DEVTOOLS_PACKAGE];

if (!devRange || !peerRange) {
throw new Error(
`Vite package.json must define ${VITE_DEVTOOLS_PACKAGE} in devDependencies and peerDependencies`,
);
}

corePkg.devDependencies ??= {};
corePkg.peerDependencies ??= {};
corePkg.devDependencies[VITE_DEVTOOLS_PACKAGE] = devRange;
corePkg.peerDependencies[VITE_DEVTOOLS_PACKAGE] = peerRange;
}

// Oxc-related packages that should use the higher version on conflict
const OXC_PACKAGE_PREFIXES = [
'@oxc-project/',
Expand Down Expand Up @@ -887,6 +906,17 @@ export async function syncRemote() {

log('✓ pnpm-workspace.yaml updated successfully!');

const corePackagePath = join(rootDir, CORE_PACKAGE_PATH, 'package.json');
const rolldownVitePackagePath = join(rootDir, VITE_DIR, 'packages', 'vite', 'package.json');
const corePackage = JSON.parse(readFileSync(corePackagePath, 'utf-8')) as PackageJson;
const rolldownVitePackage = JSON.parse(
readFileSync(rolldownVitePackagePath, 'utf-8'),
) as PackageJson;

syncViteDevtoolsDependencies(corePackage, rolldownVitePackage);
writeFileSync(corePackagePath, JSON.stringify(corePackage, null, 2) + '\n', 'utf-8');
log('✓ package.json Vite DevTools ranges updated successfully!');

execCommand('pnpm install --no-frozen-lockfile', rootDir);

// Keep the root Cargo.toml oxc pins in lockstep with the vendored rolldown.
Expand All @@ -896,9 +926,7 @@ export async function syncRemote() {
// Merge package.json exports
log('Merging package.json exports...');

const corePackagePath = join(rootDir, CORE_PACKAGE_PATH, 'package.json');
const rolldownPackagePath = join(rootDir, ROLLDOWN_DIR, 'packages', 'rolldown', 'package.json');
const rolldownVitePackagePath = join(rootDir, VITE_DIR, 'packages', 'vite', 'package.json');
const pluginutilsPackagePath = join(
rootDir,
ROLLDOWN_DIR,
Expand All @@ -910,11 +938,7 @@ export async function syncRemote() {
'package.json',
);

const corePackage = JSON.parse(readFileSync(corePackagePath, 'utf-8')) as PackageJson;
const rolldownPackage = JSON.parse(readFileSync(rolldownPackagePath, 'utf-8')) as PackageJson;
const rolldownVitePackage = JSON.parse(
readFileSync(rolldownVitePackagePath, 'utf-8'),
) as PackageJson;
const pluginutilsPackage = JSON.parse(
readFileSync(pluginutilsPackagePath, 'utf-8'),
) as PackageJson;
Expand Down
Loading
Loading