From c478c11975a3ab124822cb1dc9033a2adb21f44c Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Thu, 9 Nov 2023 05:32:18 -0800 Subject: [PATCH] chore: no need for 'packages' in "lerna.json" (#4264) --- CHANGELOG.md | 2 ++ lerna.json | 17 +---------------- package.json | 1 - scripts/update-ts-configs.js | 28 ++++++++++++++-------------- 4 files changed, 17 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 887ccf13a3..b5b4161d52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/ ### :house: (Internal) +* chore: no need for 'packages' in lerna.json [#4264](https://github.com/open-telemetry/opentelemetry-js/pull/4264) @trentm + ## 1.18.1 ### :bug: (Bug Fix) diff --git a/lerna.json b/lerna.json index 4e03ac4f79..336c3e85ca 100644 --- a/lerna.json +++ b/lerna.json @@ -1,20 +1,5 @@ { "version": "independent", "npmClient": "npm", - "useWorkspaces": true, - "// packages": "Please sync with package.json#workspaces", - "packages": [ - "api", - "packages/*", - "experimental/packages/*", - "experimental/examples/*", - "experimental/backwards-compatibility/*", - "integration-tests/*", - "selenium-tests", - "examples/otlp-exporter-node", - "examples/opentelemetry-web", - "examples/http", - "examples/https", - "examples/esm-http-ts" - ] + "useWorkspaces": true } diff --git a/package.json b/package.json index bfc13ff392..7e7cb81ade 100644 --- a/package.json +++ b/package.json @@ -102,7 +102,6 @@ }, "cacheDir": ".changelog" }, - "// workspaces": "Please sync with lerna.json#packages", "workspaces": [ "api", "packages/*", diff --git a/scripts/update-ts-configs.js b/scripts/update-ts-configs.js index d437172181..bc3319f4de 100644 --- a/scripts/update-ts-configs.js +++ b/scripts/update-ts-configs.js @@ -71,23 +71,23 @@ main(); function main() { const pkgRoot = process.cwd(); const projectRoot = findProjectRoot(pkgRoot); - const lernaPackages = resolveLernaPackages(projectRoot); + const workspacePackages = resolveWorkspacePackages(projectRoot); - generateTsConfig(projectRoot, lernaPackages, pkgRoot, true); - for (const packageMeta of lernaPackages.values()) { - generateTsConfig(projectRoot, lernaPackages, path.join(projectRoot, packageMeta.dir), false, packageMeta); + generateTsConfig(projectRoot, workspacePackages, pkgRoot, true); + for (const packageMeta of workspacePackages.values()) { + generateTsConfig(projectRoot, workspacePackages, path.join(projectRoot, packageMeta.dir), false, packageMeta); } } -function generateTsConfig(projectRoot, lernaProjects, pkgRoot, isLernaRoot, packageMeta) { +function generateTsConfig(projectRoot, workspacePackages, pkgRoot, isLernaRoot, packageMeta) { // Root tsconfig.json if (isLernaRoot) { - writeRootTsConfigJson(pkgRoot, projectRoot, lernaProjects); + writeRootTsConfigJson(pkgRoot, projectRoot, workspacePackages); return; } const otelDependencies = getOtelDependencies(packageMeta.pkgJson); - const dependenciesDir = resolveDependencyDirs(lernaProjects, otelDependencies); + const dependenciesDir = resolveDependencyDirs(workspacePackages, otelDependencies); const references = dependenciesDir.map(it => path.relative(pkgRoot, path.join(projectRoot, it))).sort(); if (packageMeta.hasMultiTarget) { @@ -97,16 +97,16 @@ function generateTsConfig(projectRoot, lernaProjects, pkgRoot, isLernaRoot, pack writeSingleTargetTsConfig(pkgRoot, projectRoot, references); } -function writeRootTsConfigJson(pkgRoot, projectRoot, lernaProjects) { +function writeRootTsConfigJson(pkgRoot, projectRoot, workspacePackages) { const tsconfigPath = path.join(pkgRoot, 'tsconfig.json'); const tsconfig = readJSON(tsconfigPath); - const references = Array.from(lernaProjects.values()) + const references = Array.from(workspacePackages.values()) .filter(it => it.isTsProject) .map(it => toPosix(path.relative(pkgRoot, path.join(projectRoot, it.dir)))).sort(); tsconfig.references = references.map(path => { return { path: toPosix(path) } }); - tsconfig.typedocOptions.entryPoints = Array.from(lernaProjects.values()) + tsconfig.typedocOptions.entryPoints = Array.from(workspacePackages.values()) .filter(it => !it.private && it.isTsProject) .map(it => toPosix(path.relative(pkgRoot, path.join(projectRoot, it.dir)))).sort(); writeJSON(tsconfigPath, tsconfig, dryRun); @@ -114,7 +114,7 @@ function writeRootTsConfigJson(pkgRoot, projectRoot, lernaProjects) { for (const tsconfigName of ['tsconfig.esm.json', 'tsconfig.esnext.json']) { const tsconfigPath = path.join(pkgRoot, tsconfigName); const tsconfig = readJSON(tsconfigPath); - const references = Array.from(lernaProjects.values()) + const references = Array.from(workspacePackages.values()) .filter(it => it.isTsProject && it.hasMultiTarget) .map(it => toPosix(path.relative(pkgRoot, path.join(projectRoot, it.dir)))).sort(); tsconfig.references = references.map(pkgPath => { @@ -182,10 +182,10 @@ function getOtelDependencies(packageJson) { return Array.from(deps.values()); } -function resolveLernaPackages(projectRoot) { +function resolveWorkspacePackages(projectRoot) { const map = new Map(); - const lernaJson = readJSON(`${projectRoot}/lerna.json`); - for (const pkgDefinition of lernaJson.packages) { + const packageJson = readJSON(`${projectRoot}/package.json`); + for (const pkgDefinition of packageJson.workspaces) { if (ignoredLernaProjects.includes(pkgDefinition)) { continue; }