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

parseFunction + linting #9

Open
wants to merge 8 commits into
base: es6
Choose a base branch
from
102 changes: 102 additions & 0 deletions mininode.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/bin/bash
: '
This is for the package installation, debloating, and validation in the Docker
Container. Assuming the source code of the package is already downloaded as
tar.gz file and stored under the root directory.
'

: 'SHAREDMOUNT is the directory that stores the package tar.gz file'
SHAREDMOUNT="/sharedMount"
ROOT="/"
MININODE="index.js"
SUFFIX_ORIG="orig"
SUFFIX_PROD="prod"
SUFFIX_RDUC="reduced"

File_Name=$1
: 'Check whether the file exists'
if [ ! -f "$File_Name" ]; then
echo "File not found!"
exit 1
fi

echo "File_Name is $File_Name"
: 'for the full path, use this: PACKAGE_NAME=”${fullfile##*/}” '

: '
extract the tar.gz file for the original version of the package
obtain the directory of the unpacked package
modify the name of the directory by appending SUFFIX_ORIG
'
unpacked=$(tar -xvzf $File_Name)
echo "unpacked: $unpacked"
packdir=$(echo $unpacked | cut -f1 -d" ")

: 'remove the last "/" from packdir if it exists'
packdir=${packdir%/}

PACKAGE_ORIG="$packdir-$SUFFIX_ORIG"
echo "unpacked: $packdir"
echo "PACKAGE_ORIG: $PACKAGE_ORIG"
mv $packdir $PACKAGE_ORIG

: '
go to the orig directory, install the package, and run the test
'
cd $PACKAGE_ORIG
if npm install; then
echo "$PACKAGE_ORIG sucessfully installed."
else
echo "$PACKAGE_ORIG failed to be installed!"
exit 1
fi

if npm run test; then
echo "$PACKAGE_ORIG test run sucessfully."
else
echo "$PACKAGE_ORIG failed to run test!"
exit 1
fi

: '
re-extract the tar.gz file for the product version of this package
obtain the directory of the unpacked package
modify the name of the directory by appending SUFFIX_PROD
'
cd $SHAREDMOUNT
tar -xvzf $File_Name

# reuse the $packdir obtained from the original extraction
PACKAGE_PROD="$packdir-$SUFFIX_PROD"
echo "unpacked: $packdir"
echo "PACKAGE_PROD: $PACKAGE_PROD"
mv $packdir $PACKAGE_PROD

: '
go to the prod directory, install the package
'
cd $PACKAGE_PROD
if npm install --only=prod; then
echo "$PACKAGE_PROD sucessfully installed."
else
echo "$PACKAGE_PROD failed to be installed!"
exit 1
fi

cd $ROOT
# reuse the $packdir obtained from the original extraction
PACKAGE_RDUC="$packdir-$SUFFIX_RDUC"
# specify the full path of the produce version, and the reduced version, respectively
package_prod_full="$SHAREDMOUNT/$PACKAGE_PROD/"
package_rduc_full="$SHAREDMOUNT/$PACKAGE_RDUC" # take out slash so program works correctly

echo "node --max-old-space-size=8192 $MININODE $package_prod_full --mode=fine --destination=$package_rduc_full"
echo $package_rduc_full
if node --max-old-space-size=8192 $MININODE $package_prod_full --mode=fine --destination=$package_rduc_full; then
echo "$PACKAGE_PROD sucessfully debloated."
else
echo "$PACKAGE_PROD failed to be debloated!"
exit 1
fi
echo "skipped validation"
exit 1
32 changes: 15 additions & 17 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ let entries = [];
// 3. add to individual modules used globals.
for (let modul of _app.modules) {
for (let mem in modul.memusages) {
_app.globals.forEach((i) => {
if (i.name === mem) {
_app.globals.forEach((globalVar) => {
if (globalVar.name === mem) {
for (let m of modul.memusages[mem]) {
i.members.push(m);
globalVar.members.push(m);
}
}
});
Expand Down Expand Up @@ -200,26 +200,26 @@ async function init() {
if (testEntryPoints && testEntryPoints.length > 0) {
//TODO-Hui: here do we need to find the path to these test entry points?
//TODO-Hui: also, with these test entry points, perhaps we should not block test directories?
testEntryPoints.forEach(entryP => {
testEntryPoints.forEach((entryP) => {
if (!_app.main.includes(entryP)) {
_app.main.push(entryP);
}
})
});
}
if (packageJson.hasOwnProperty('directories')) {
if (packageJson.directories.hasOwnProperty('test')) {
_app.directories = packageJson.directories.test

if (packageJson.hasOwnProperty("directories")) {
if (packageJson.directories.hasOwnProperty("test")) {
_app.directories = packageJson.directories.test;
}
}

if (config.seeds.length === 0) {
if (!_app.main) {
throw new Error("NO_ENTRY_POINT");
}
_app.main.forEach(entryP => {
_app.main.forEach((entryP) => {
entries.push(path.join(_app.path, entryP));
})
});
} else {
for (let seed of config.seeds) {
let s = utils.entryPoint(location, seed);
Expand Down Expand Up @@ -541,21 +541,19 @@ function getJSFilenamesInScriptsField(packageJson) {
let stringToDealWith = scripts[key];
let words = stringToDealWith.split(" ");
for (let wPotentialFile of words) {
if (wPotentialFile.indexOf('*') > -1) {
if (wPotentialFile.indexOf("*") > -1) {
continue;
}
let splitWordArr = wPotentialFile.split(".");
if (splitWordArr.length > 1) {
if (
["js", "mjs", "cjs"].includes(
splitWordArr[splitWordArr.length - 1]
)
["js", "mjs", "cjs"].includes(splitWordArr[splitWordArr.length - 1])
) {
result.push(wPotentialFile);
}
}
}
}
}
}
return result;
}
}
Loading