mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-27 02:43:48 +02:00
Add sync workspace deps script
This commit is contained in:
+4
-4
@@ -56,10 +56,10 @@
|
||||
"examples:build": "vite build",
|
||||
"fix-build-import-paths": "tsx scripts/add-import-extensions.ts",
|
||||
"append-namespace": "echo 'export as namespace Mediabunny;' >> dist/mediabunny.d.ts",
|
||||
"bump-patch": "npm version patch --no-git-tag-version --workspaces",
|
||||
"bump-minor": "npm version minor --no-git-tag-version --workspaces",
|
||||
"bump-major": "npm version major --no-git-tag-version --workspaces",
|
||||
"set-version": "npm version --no-git-tag-version --workspaces"
|
||||
"bump-patch": "npm version patch --no-git-tag-version --workspaces && tsx scripts/sync-workspace-deps.ts",
|
||||
"bump-minor": "npm version minor --no-git-tag-version --workspaces && tsx scripts/sync-workspace-deps.ts",
|
||||
"bump-major": "npm version major --no-git-tag-version --workspaces && tsx scripts/sync-workspace-deps.ts",
|
||||
"set-version": "npm version --no-git-tag-version --workspaces && tsx scripts/sync-workspace-deps.ts"
|
||||
},
|
||||
"license": "MPL-2.0",
|
||||
"repository": {
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"node-av": "^6.0.0",
|
||||
"@mediabunny/prores": "^1.50.0"
|
||||
"@mediabunny/prores": "^1.50.4"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"mediabunny": "^1.45.0"
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
// After `npm version --workspaces` bumps each package's version, this rewrites dependency ranges that point at sibling
|
||||
// workspaces so they follow along.
|
||||
|
||||
const root = path.join(import.meta.dirname, '..');
|
||||
|
||||
const workspaceDirs = ['.', ...fs.readdirSync(path.join(root, 'packages')).map(x => `packages/${x}`)]
|
||||
.filter(dir => fs.existsSync(path.join(root, dir, 'package.json')));
|
||||
|
||||
type Manifest = {
|
||||
name: string;
|
||||
version: string;
|
||||
dependencies?: Record<string, string>;
|
||||
};
|
||||
|
||||
const manifests = workspaceDirs.map((dir) => {
|
||||
const filePath = path.join(root, dir, 'package.json');
|
||||
return { filePath, json: JSON.parse(fs.readFileSync(filePath, 'utf8')) as Manifest };
|
||||
});
|
||||
|
||||
const versions = new Map(manifests.map(({ json }) => [json.name, json.version]));
|
||||
|
||||
for (const { filePath, json } of manifests) {
|
||||
let changed = false;
|
||||
|
||||
for (const name of Object.keys(json.dependencies ?? {})) {
|
||||
const version = versions.get(name);
|
||||
if (version && json.dependencies![name] !== `^${version}`) {
|
||||
json.dependencies![name] = `^${version}`;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
fs.writeFileSync(filePath, JSON.stringify(json, null, 2) + '\n');
|
||||
console.log(`Synced workspace dependency ranges in ${path.relative(root, filePath)}`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user