-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(puppeteer): Cleanup node_modules (#1497)
## Problem - The Puppeteer `node_modules` directory is huge ## Solution - Delete the not needed content from `node_modules` - Inspired by [node-prune](https://github.com/tj/node-prune/) tool (written in Go, not much suitable to run during RPM build, I rewrote that to shell) ## Testing - Tested manually ## Numbers - The `node_modules` directory size went down from 39MB to 15MB (-62%) - The built RPM size went down from 3.5MB to 1.9MB (-46%) - I expect the Live ISO size reduction similar to the RPM reduction
- Loading branch information
Showing
5 changed files
with
186 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
#! /bin/bash | ||
|
||
# This script clean up the node_modules directory which is usually huge and | ||
# contains a lot of not needed files. It was inspired by the node-prune tool | ||
# (https://github.com/tj/node-prune). | ||
# | ||
# Usage: | ||
# | ||
# node-prune.sh [path] | ||
# | ||
# The optional [path] argument is a path to the node_modules directory, if it is | ||
# not specified it uses node_modules in the current directory. | ||
# | ||
# This is a generic tool, you might run it against any node_modules directory, | ||
# not only in Agama Puppeteer tests. | ||
|
||
MODULES_PATH="${1:-./node_modules}" | ||
|
||
# The list of names/patterns comes from | ||
# https://github.com/tj/node-prune/blob/master/internal/prune/prune.go | ||
|
||
# files to delete | ||
FILES=( | ||
Jenkinsfile | ||
Makefile | ||
Gulpfile.js | ||
Gruntfile.js | ||
gulpfile.js | ||
.DS_Store | ||
.tern-project | ||
.gitattributes | ||
.editorconfig | ||
.eslintrc | ||
eslint | ||
.eslintrc.js | ||
.eslintrc.json | ||
.eslintrc.yml | ||
.eslintignore | ||
.stylelintrc | ||
stylelint.config.js | ||
.stylelintrc.json | ||
.stylelintrc.yaml | ||
.stylelintrc.yml | ||
.stylelintrc.js | ||
.htmllintrc | ||
htmllint.js | ||
.lint | ||
.npmrc | ||
.npmignore | ||
.jshintrc | ||
.flowconfig | ||
.documentup.json | ||
.yarn-metadata.json | ||
.travis.yml | ||
appveyor.yml | ||
.gitlab-ci.yml | ||
circle.yml | ||
.coveralls.yml | ||
CHANGES | ||
changelog | ||
# keep the package licenses, it's unclear if we can legally delete them... | ||
# LICENSE.txt | ||
# LICENSE | ||
# LICENSE-MIT | ||
# LICENSE.BSD | ||
# license | ||
# LICENCE.txt | ||
# LICENCE | ||
# LICENCE-MIT | ||
# LICENCE.BSD | ||
# licence | ||
AUTHORS | ||
CONTRIBUTORS | ||
.yarn-integrity | ||
.yarnclean | ||
_config.yml | ||
.babelrc | ||
.yo-rc.json | ||
jest.config.js | ||
karma.conf.js | ||
wallaby.js | ||
wallaby.conf.js | ||
.prettierrc | ||
.prettierrc.yml | ||
.prettierrc.toml | ||
.prettierrc.js | ||
.prettierrc.json | ||
prettier.config.js | ||
.appveyor.yml | ||
tsconfig.json | ||
tslint.json | ||
) | ||
|
||
# directories to delete | ||
DIRECTORIES=( | ||
test | ||
tests | ||
powered-test | ||
docs | ||
doc | ||
.idea | ||
.vscode | ||
website | ||
images | ||
assets | ||
example | ||
examples | ||
coverage | ||
.nyc_output | ||
.circleci | ||
.github | ||
) | ||
|
||
# delete files with specific extensions | ||
EXTENSIONS=( | ||
markdown | ||
md | ||
mkd | ||
ts | ||
jst | ||
coffee | ||
tgz | ||
swp | ||
) | ||
|
||
# delete additional files with specific extensions (not deleted by the original | ||
# node-prune tool) | ||
EXTRA_EXTENSIONS=( | ||
# The map files take almost half of the node_modules content! An they would be | ||
# useful only for reporting bugs in Puppeteer itself or in some dependent | ||
# library. | ||
map | ||
) | ||
|
||
echo -n "Before cleanup: " | ||
du -h -s "$MODULES_PATH" | cut -f1 | ||
|
||
# delete files | ||
for F in "${FILES[@]}"; do | ||
find "$MODULES_PATH" -type f -name "$F" -delete | ||
done | ||
|
||
# delete directories recursively | ||
for D in "${DIRECTORIES[@]}"; do | ||
find "$MODULES_PATH" -type d -name "$D" -prune -exec rm -rf \{\} \; | ||
done | ||
|
||
# delete files with specific extenstions | ||
for E in "${EXTENSIONS[@]}"; do | ||
find "$MODULES_PATH" -type f -name "*.$E" -delete | ||
done | ||
|
||
# delete additional files with extensions | ||
for EE in "${EXTRA_EXTENSIONS[@]}"; do | ||
find "$MODULES_PATH" -type f -name "*.$EE" -delete | ||
done | ||
|
||
echo -n "After cleanup: " | ||
du -h -s "$MODULES_PATH" | cut -f1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#! /bin/sh | ||
|
||
# This is a helper script which deletes some not needed files from NPM packages. | ||
# This script is specific for Puppeteer installations. | ||
|
||
MODULES_PATH="${1:-./node_modules}" | ||
|
||
# delete Puppeteer CommonJS modules, we use the ES modules (in lib/esm) | ||
rm -rf "$MODULES_PATH/puppeteer-core/lib/cjs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
------------------------------------------------------------------- | ||
Wed Jul 24 15:03:25 UTC 2024 - Ladislav Slezák <[email protected]> | ||
|
||
- Reduce the node_modules size, delete not needed files | ||
(gh#openSUSE/agama#1497) | ||
|
||
------------------------------------------------------------------- | ||
Fri Jul 19 10:18:37 UTC 2024 - Ladislav Slezák <[email protected]> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters