Skip to content

Commit a4172f7

Browse files
authoredJan 6, 2023
fix: update monorepo detection and use (#1155)
Remove assumption that monorepos use lerna
1 parent f4805ed commit a4172f7

File tree

5 files changed

+13
-65
lines changed

5 files changed

+13
-65
lines changed
 

‎src/check-project/check-monorepo-files.js

-14
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,6 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url))
1515
export async function checkMonorepoFiles (projectDir) {
1616
console.info('Check monorepo files')
1717

18-
const pkg = fs.readJSONSync(path.join(projectDir, 'package.json'))
19-
20-
let defaultLernaContent = fs.readFileSync(path.join(__dirname, 'files/lerna.json'), {
21-
encoding: 'utf-8'
22-
})
23-
24-
// ensure lerna version is in sync
25-
const lernaConfig = JSON.parse(defaultLernaContent)
26-
lernaConfig.lerna = pkg.dependencies.lerna.replace(/\^/, '')
27-
28-
defaultLernaContent = JSON.stringify(lernaConfig, null, 2)
29-
30-
await ensureFileHasContents(projectDir, 'lerna.json', defaultLernaContent)
31-
3218
// disable package-lock.json in monorepos until https://github.com/semantic-release/github/pull/487 is merged
3319
await ensureFileHasContents(projectDir, '.npmrc', fs.readFileSync(path.join(__dirname, 'files/npmrc'), {
3420
encoding: 'utf-8'

‎src/check-project/files/lerna.json

-10
This file was deleted.

‎src/test-dependant/index.js

+10-23
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ const dependsOn = (name, pkg) => {
4444
* @param {string} targetDir
4545
*/
4646
const isMonoRepo = (targetDir) => {
47-
return fs.existsSync(path.join(targetDir, 'lerna.json'))
47+
const modulePkgPath = path.join(targetDir, 'package.json')
48+
const modulePkg = fs.readJSONSync(modulePkgPath)
49+
50+
// monorepos declare workspaces in their root package.json
51+
return Boolean(modulePkg.workspaces)
4852
}
4953

5054
/**
@@ -185,32 +189,15 @@ const testRepo = async (targetDir, deps, scriptName) => {
185189
const testMonoRepo = async (targetDir, deps, scriptName) => {
186190
await installDependencies(targetDir)
187191

188-
let lerna = path.join('node_modules', '.bin', 'lerna')
189-
190-
if (!fs.existsSync(lerna)) {
191-
// no lerna in project dependencies :(
192-
await exec('npm', ['install', '-g', 'lerna'], {
193-
cwd: targetDir
194-
})
195-
lerna = 'lerna'
196-
}
197-
198-
await exec(lerna, ['bootstrap'], {
199-
cwd: targetDir
200-
})
201-
202192
// read package targetDir config
203-
const config = await fs.readJSON(path.join(targetDir, 'lerna.json'))
204-
205-
// find where the packages are stored
206-
let packages = config.packages || 'packages'
193+
const config = await fs.readJSON(path.join(targetDir, 'package.json'))
207194

208-
if (!Array.isArray(packages)) {
209-
packages = [packages]
195+
if (config.workspaces == null) {
196+
throw new Error('Package config did not contain workspaces')
210197
}
211198

212-
// test each package that depends on ipfs/http client
213-
for (const pattern of packages) {
199+
// test each package that depends on passed deps
200+
for (const pattern of config.workspaces) {
214201
for await (const match of glob(targetDir, pattern)) {
215202
await testModule(path.join(targetDir, match), deps, scriptName)
216203
}

‎test/fixtures/test-dependant/monorepo/lerna.json

-15
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "monorepo",
33
"version": "1.0.0",
4-
"devDependencies": {
5-
"lerna": "^3.20.2"
6-
}
4+
"workspaces": [
5+
"packages/*"
6+
]
77
}

0 commit comments

Comments
 (0)
Please sign in to comment.