From 43b7190647122c3e32ff2bd2bbe6b714c42c797c Mon Sep 17 00:00:00 2001 From: Stanislav Khromov Date: Mon, 24 Jul 2023 22:30:12 +0200 Subject: [PATCH 1/5] Add exclude packages feature --- README.md | 2 ++ src/helpers.js | 5 +++++ src/index.js | 11 ++++++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e7fdb21..cc89e00 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,8 @@ Run `cost-of-modules` in the directory you are working in. `--include-dev` Include devDependencies as well - for 🚀 collaborator experience +`--exclude` Exclude specific packages from the calculation. Provide a comma-separated list of packages, for example: `--exclude=package1,package2` + #### Show your support :star: this repo diff --git a/src/helpers.js b/src/helpers.js index af4af4f..432c020 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -249,6 +249,10 @@ const teardown = () => { } } +let getParsedArguments = () => { + return argv; +} + module.exports = { setup, getSizeForNodeModules, @@ -257,4 +261,5 @@ module.exports = { getAllDependencies, displayResults, teardown, + getParsedArguments } diff --git a/src/index.js b/src/index.js index 405cadf..a481af9 100644 --- a/src/index.js +++ b/src/index.js @@ -17,6 +17,12 @@ console.log() */ const moduleSizes = helpers.getSizeForNodeModules() +// Get command line arguments +const argv = helpers.getParsedArguments() + +// Get the packages to be excluded +const excludePackages = argv.exclude ? argv.exclude.split(",") : []; + /* Get root dependencies from tree These are the ones declared as dependendies in package.json @@ -31,7 +37,10 @@ let rootDependencies = helpers.getRootDependencies() children: [a, b, c, d] }] */ -let flatDependencies = helpers.attachNestedDependencies(rootDependencies) +let flatDependencies = helpers.attachNestedDependencies(rootDependencies).filter((dep) => { + // Exclude the packages specified by the 'exclude' flag + return !excludePackages.includes(dep.name); + }) /* Modules actual size = size of the module + size of it's children From 4f18eb31468ebc407630a7b6e5f68c35f4f683c6 Mon Sep 17 00:00:00 2001 From: Stanislav Khromov Date: Mon, 24 Jul 2023 22:32:55 +0200 Subject: [PATCH 2/5] Add prettier --- package.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index d84e445..e3a46b5 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "build-test": "babel test/src -d test/dist", "test": "npm run build && npm run build-test && npm run ava", "ava": "ava test/dist/*.js -s --no-cache", - "precommit": "lint-staged" + "precommit": "lint-staged", + "prettier": "prettier --write --single-quote --no-semi --trailing-comma es5" }, "files": [ "dist" @@ -42,7 +43,8 @@ "babel-cli": "6.18.0", "babel-preset-env": "^1.4.0", "husky": "0.13.3", - "lint-staged": "3.4.0" + "lint-staged": "3.4.0", + "prettier": "^3.0.0" }, "babel": { "presets": [ From ed60575910a6e35e0a4a1961c272f0982342e247 Mon Sep 17 00:00:00 2001 From: Stanislav Khromov Date: Mon, 24 Jul 2023 22:33:24 +0200 Subject: [PATCH 3/5] Add nvmrc --- .nvmrc | 1 + 1 file changed, 1 insertion(+) create mode 100644 .nvmrc diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..25bf17f --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +18 \ No newline at end of file From d2ceb6a94ccf1b867142f9465aaf1607753d1df8 Mon Sep 17 00:00:00 2001 From: Stanislav Khromov Date: Mon, 24 Jul 2023 22:34:28 +0200 Subject: [PATCH 4/5] Fix husky --- src/helpers.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/helpers.js b/src/helpers.js index 432c020..5736d35 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -12,7 +12,7 @@ const path = require('path') */ let productionModifier = '--production' -let setup = includeDev => { +let setup = (includeDev) => { console.log() if (argv.includeDev || includeDev) productionModifier = '' @@ -80,14 +80,14 @@ let getRootDependencies = () => { /* to fix the missing du problem on windows */ -let dirSize = root => { +let dirSize = (root) => { let out = 0 let getDirSizeRecursively - ;(getDirSizeRecursively = rootLocal => { + ;(getDirSizeRecursively = (rootLocal) => { let itemStats = fs.lstatSync(rootLocal) if (itemStats.isDirectory()) { let allSubs = fs.readdirSync(rootLocal) - allSubs.forEach(file => { + allSubs.forEach((file) => { getDirSizeRecursively(path.join(rootLocal, file)) }) } else { @@ -100,10 +100,10 @@ let dirSize = root => { /* Get scoped modules */ -let getScopedModules = scope => { +let getScopedModules = (scope) => { let modules = {} let allScopes = fs.readdirSync(path.join('node_modules', scope)) - allScopes.forEach(name => { + allScopes.forEach((name) => { let itemStats = fs.lstatSync(path.join('node_modules', scope, name)) if (itemStats.isDirectory()) { let size = dirSize(path.join('node_modules', scope, name)) @@ -118,7 +118,7 @@ let getScopedModules = scope => { let getSizeForNodeModules = () => { let modules = {} let allModules = fs.readdirSync('node_modules') - allModules.forEach(name => { + allModules.forEach((name) => { let itemStats = fs.lstatSync(path.join('node_modules', name)) if (itemStats.isDirectory()) { if (name && name[0] === '@') { @@ -160,7 +160,7 @@ let getDependenciesRecursively = (modules = [], tree) => { children: [a, b, c, d] }] */ -let attachNestedDependencies = rootDependencies => { +let attachNestedDependencies = (rootDependencies) => { let flatDependencies = [] let dependencyTree = getDependencyTree() for (let i = 0; i < rootDependencies.length; i++) { @@ -180,7 +180,7 @@ let attachNestedDependencies = rootDependencies => { Root dependencies + all their children Deduplicate */ -let getAllDependencies = flatDependencies => { +let getAllDependencies = (flatDependencies) => { let allDependencies = [] for (let i = 0; i < flatDependencies.length; i++) { let dep = flatDependencies[i] @@ -250,7 +250,7 @@ const teardown = () => { } let getParsedArguments = () => { - return argv; + return argv } module.exports = { @@ -261,5 +261,5 @@ module.exports = { getAllDependencies, displayResults, teardown, - getParsedArguments + getParsedArguments, } From c8c77913ccdb77319241e0a2e8f436875e89429e Mon Sep 17 00:00:00 2001 From: Stanislav Khromov Date: Mon, 24 Jul 2023 23:26:44 +0200 Subject: [PATCH 5/5] Change node version --- .nvmrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.nvmrc b/.nvmrc index 25bf17f..62f9457 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -18 \ No newline at end of file +6 \ No newline at end of file