Skip to content

Instantly share code, notes, and snippets.

@evocateur
Created November 11, 2019 01:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evocateur/9ab014add6744046ff82487de98e63ba to your computer and use it in GitHub Desktop.
Save evocateur/9ab014add6744046ff82487de98e63ba to your computer and use it in GitHub Desktop.
Setup relative tsconfig references in Lerna monorepo leaf nodes
#!/usr/bin/env node
'use strict';
const path = require('path');
const fs = require('fs-extra');
const { getPackages } = require('@lerna/project');
const PackageGraph = require('@lerna/package-graph');
(async () => {
const pkgs = await getPackages(__dirname);
const graph = new PackageGraph(pkgs, 'allDependencies', true);
const writes = [];
for (const node of graph.values()) {
const references = [];
for (const result of node.localDependencies.values()) {
references.push({
path: path.relative(result.where, result.fetchSpec),
});
}
if (references.length) {
const tsconfigPath = path.join(node.location, 'tsconfig.json');
writes.push(
Promise.resolve()
.then(() => fs.readJSON(tsconfigPath))
.then(json =>
fs.outputJSON(
tsconfigPath,
{
...json,
references,
},
{ spaces: 2 }
)
)
);
}
}
await Promise.all(writes);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment