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
Merged
13 changes: 13 additions & 0 deletions lib/base-cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,19 @@ class BaseCommand {
this.workspaceNames = [...ws.keys()]
this.workspacePaths = [...ws.values()]
}

/** commands like ci use workspace config but not --workspace */
async setWorkspaceFlagIndependent () {
reggi marked this conversation as resolved.
Show resolved Hide resolved
this.workspace = new Map()
this.workspaceNames = []
this.workspacePaths = []

try {
await this.setWorkspaces({ forgiveFlagError: true })
} catch {
// noop
}
}
}

module.exports = BaseCommand
15 changes: 10 additions & 5 deletions lib/commands/ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class CI extends ArboristWorkspaceCmd {
})
}

await this.setWorkspaceFlagIndependent()

const where = this.npm.prefix
const Arborist = require('@npmcli/arborist')
const opts = {
Expand Down Expand Up @@ -79,11 +81,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
Loading