Skip to content

Commit

Permalink
chore: add script to delete node_modules
Browse files Browse the repository at this point in the history
This new script deletes all node_modules folders recursively which is useful when `npm install`
fails for some reason and these folders are in a corrupted state
TEST PLAN:
run clean-node and observe that all node_modules folders are deleted
  • Loading branch information
matyasf committed Aug 14, 2024
1 parent 054d761 commit 3d7611b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"build:types": "tsc -b tsconfig.references.json",
"build:ts": "lerna run prepare-build --stream --scope @instructure/ui-icons && npm run build:types --verbose",
"clean": "node scripts/clean.js",
"clean-node": "node scripts/clean.js --nuke_node",
"export:icons": "lerna run export --stream --scope @instructure/ui-icons",
"bump": "ui-scripts bump",
"release": "ui-scripts publish",
Expand Down
23 changes: 22 additions & 1 deletion scripts/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

const fs = require('fs')
const path = require('path')
const url = require('url')

const NODE_PACKAGES = [
'ui-icons-build',
Expand Down Expand Up @@ -57,6 +58,7 @@ function deleteDirs(dirs = []) {
fs.rmSync(dir, { force: true, recursive: true })
})
}
// deletes built files from tooling packages (NODE_PACKAGES const)
function clean() {
const packagesPath = path.resolve('./packages')
const dir = fs.opendirSync(packagesPath)
Expand All @@ -74,8 +76,27 @@ function clean() {
}
}
}
// deletes node_modules recursively
function removeNodeModules() {
const dirs = fs.readdirSync('.', { recursive: true, withFileTypes: true })
const toRemove = []
for (const dir of dirs) {
if (dir.isDirectory() && dir.name.toLowerCase() === 'node_modules') {
toRemove.push(url.pathToFileURL(path.join(dir.parentPath, dir.name)))
}
}
deleteDirs(toRemove)
}

// eslint-disable-next-line no-console
console.info('cleaning packages...')
console.info('Deleting built files from tooling packages...')
clean()
const args = process.argv.slice(2)
if (args.length > 0 && args[0] === '--nuke_node') {
// eslint-disable-next-line no-console
console.info('Deleting node_modules recursively...')
removeNodeModules()
}

// eslint-disable-next-line no-console
console.info('clean finished')

0 comments on commit 3d7611b

Please sign in to comment.