Skip to content

Commit

Permalink
chore: no need for 'packages' in "lerna.json" (#4264)
Browse files Browse the repository at this point in the history
  • Loading branch information
trentm authored Nov 9, 2023
1 parent f665499 commit c478c11
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 31 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 1 addition & 16 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@
},
"cacheDir": ".changelog"
},
"// workspaces": "Please sync with lerna.json#packages",
"workspaces": [
"api",
"packages/*",
Expand Down
28 changes: 14 additions & 14 deletions scripts/update-ts-configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -97,24 +97,24 @@ 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);

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 => {
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit c478c11

Please sign in to comment.