@md-oss/scripts
v0.10.0
Published
Reusable monorepo maintenance scripts
Downloads
297
Readme
@md-oss/scripts
Reusable package scripts for monorepo maintenance tasks.
Included Scripts
- ./find-dependency-mismatches
- ./add-module-directives
- ./sync-package-exports
- ./apply-package-publish-config
find-dependency-mismatches
This script scans workspace package.json files and reports dependency version mismatches across:
- dependencies
- devDependencies
- peerDependencies
- optionalDependencies
CLI usage
pnpm exec md-oss-find-dependency-mismatchesOptional flags:
--cwd <path>: run against a specific workspace root.
Programmatic usage
import { findDependencyMismatches } from '@md-oss/scripts/find-dependency-mismatches';
const mismatches = findDependencyMismatches();
if (mismatches.size > 0) {
console.debug(mismatches);
}It expects a pnpm-workspace.yaml file at the repository root.
add-module-directives
Adds a module-level directive (for example, use client or use server) to one or more built files.
CLI usage
The directive is required and must be explicit.
pnpm exec md-oss-add-module-directives --directive='use client' dist/next-client.mjs dist/next-client.cjsOptional flags:
--cwd <path>: resolve file paths from a specific directory.--directive <value>: required module directive to prepend.
Programmatic usage
import { addModuleDirectivesToFiles } from '@md-oss/scripts/add-module-directives';
await addModuleDirectivesToFiles({
directive: 'use client',
files: ['dist/next-client.mjs', 'dist/next-client.cjs'],
});sync-package-exports
Synchronizes publishConfig.exports from exports in a package.json.
- Source code exports (for example,
./src/foo.tsx) are converted to dist conditional exports withrequire/importandtypes/defaultfields. - Non-source targets (for example css files or config files) are preserved as-is.
CLI usage
pnpm exec md-oss-sync-package-exports --cwd vendor/design-systemOptional flags:
--cwd <path>: working directory containing package.json.--package-json <path>: custom package.json relative to cwd.--dry-run: report whether sync is needed without writing changes.
Programmatic usage
import { syncPackageExports } from '@md-oss/scripts/sync-package-exports';
const result = await syncPackageExports({
cwd: 'vendor/design-system',
});
console.debug(result.changed);apply-package-publish-config
Applies publishConfig fields to the root level of a package.json, preparing it for publishing.
- Non-registry fields from
publishConfigare promoted to the root level (overwriting any existing root fields). - Registry metadata fields (
registry,access,tag,directory,provenance,@npmjs:bypass-log-bin) are retained inpublishConfig. - The
publishConfigfield is removed only if all fields were applied; otherwise it contains only the retained npm metadata. - Useful as the final step before publishing to npm or other registries.
CLI usage
pnpm exec md-oss-apply-package-publish-config --cwd vendor/design-systemOptional flags:
--cwd <path>: working directory containing package.json.--package-json <path>: custom package.json relative to cwd.--dry-run: report what would be applied without writing changes.
Programmatic usage
import { applyPackagePublishConfigToFile } from '@md-oss/scripts/apply-package-publish-config';
const result = await applyPackagePublishConfigToFile({
cwd: 'vendor/design-system',
});
console.debug(result.changed);