Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ci): rm workspace node_modules #7490

Merged
merged 18 commits into from
May 23, 2024
21 changes: 16 additions & 5 deletions lib/commands/ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const fs = require('fs/promises')
const { log, time } = require('proc-log')
const validateLockfile = require('../utils/validate-lockfile.js')
const ArboristWorkspaceCmd = require('../arborist-cmd.js')
const getWorkspaces = require('../utils/get-workspaces.js')

class CI extends ArboristWorkspaceCmd {
static description = 'Clean install a project'
Expand Down Expand Up @@ -33,6 +34,13 @@ class CI extends ArboristWorkspaceCmd {
})
}

this.workspaces = await getWorkspaces([], {
reggi marked this conversation as resolved.
Show resolved Hide resolved
path: this.npm.localPrefix,
includeWorkspaceRoot: true,
})
this.workspaceNames = [...this.workspaces.keys()]
wraithgar marked this conversation as resolved.
Show resolved Hide resolved
this.workspacePaths = [...this.workspaces.values()]

const where = this.npm.prefix
const Arborist = require('@npmcli/arborist')
const opts = {
Expand Down Expand Up @@ -79,11 +87,14 @@ class CI extends ArboristWorkspaceCmd {
// Only remove node_modules after we've successfully loaded the virtual
// tree and validated the lockfile
await time.start('npm-ci:rm', async () => {
const path = `${where}/node_modules`
// get the list of entries so we can skip the glob for performance
const entries = await fs.readdir(path, null).catch(() => [])
return Promise.all(entries.map(f => fs.rm(`${path}/${f}`,
{ force: true, recursive: true })))
return await Promise.all([where, ...this.workspacePaths].map(async modulePath => {
reggi marked this conversation as resolved.
Show resolved Hide resolved
const path = `${modulePath}/node_modules`
reggi marked this conversation as resolved.
Show resolved Hide resolved
// get the list of entries so we can skip the glob for performance
const entries = await fs.readdir(path, null).catch(() => [])
return Promise.all(entries.map(f => {
return fs.rm(`${path}/${f}`, { force: true, recursive: true })
reggi marked this conversation as resolved.
Show resolved Hide resolved
reggi marked this conversation as resolved.
Show resolved Hide resolved
}))
}))
})
}

Expand Down