Created
November 11, 2019 01:15
-
-
Save evocateur/9ab014add6744046ff82487de98e63ba to your computer and use it in GitHub Desktop.
Setup relative tsconfig references in Lerna monorepo leaf nodes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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