Skip to content

Commit 2d1ee16

Browse files
authored
Merge pull request #280 from JohT/feature/separate-install-oftypescript-project-dependencies
Install Typescript project dependencies explicitly
2 parents c4faa4e + 0eaedb7 commit 2d1ee16

File tree

6 files changed

+36
-66
lines changed

6 files changed

+36
-66
lines changed

.github/workflows/typescript-code-analysis.yml

+10-5
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,6 @@ jobs:
118118
key:
119119
${{ runner.os }}-${{ hashFiles('**/*.sh') }}
120120

121-
- name: Setup pnpm for react-router
122-
uses: pnpm/[email protected]
123-
with:
124-
version: 8.10.5
125-
126121
- name: Download ${{ env.PROJECT_NAME }}-${{ env.REACT_ROUTER_VERSION }}
127122
working-directory: temp
128123
run: |
@@ -131,6 +126,16 @@ jobs:
131126
echo "Working directory: $( pwd -P )"
132127
./../../scripts/downloader/downloadReactRouter.sh ${{ env.REACT_ROUTER_VERSION }}
133128
129+
- name: Setup pnpm for react-router
130+
uses: pnpm/[email protected]
131+
with:
132+
package_json_file: temp/${{env.PROJECT_NAME}}-${{env.REACT_ROUTER_VERSION}}/source/${{env.PROJECT_NAME}}-${{env.REACT_ROUTER_VERSION}}/package.json
133+
134+
- name: Install dependencies with pnpm
135+
working-directory: temp/${{ env.PROJECT_NAME }}-${{ env.REACT_ROUTER_VERSION }}/source/${{ env.PROJECT_NAME }}-${{ env.REACT_ROUTER_VERSION }}
136+
run: |
137+
pnpm install --frozen-lockfile --strict-peer-dependencies
138+
134139
- name: Analyze ${{ env.PROJECT_NAME }}-${{ env.REACT_ROUTER_VERSION }}
135140
working-directory: temp/${{ env.PROJECT_NAME }}-${{ env.REACT_ROUTER_VERSION }}
136141
# Shell type can be skipped if jupyter notebook reports (and therefore conda) aren't needed

scripts/downloader/downloadAntDesign.sh

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
# Downloads the Typescript project ant-design (https://github.com/ant-design/ant-design) from GitHub using git clone.
44
# The source files are written into the "source" directory of the current analysis directory.
5-
# After scanning it with jQAssistant Typescript Plugin the resulting JSON will be moved into the "artifacts" directory.
65

76
# Note: This script is meant to be started within the temporary analysis directory (e.g. "temp/AnalysisName/")
87

scripts/downloader/downloadReactRouter.sh

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
# Downloads react-router (https://github.com/remix-run/react-router) from GitHub using git clone.
44
# The source files are written into the "source" directory of the current analysis directory.
5-
# After scanning it with jQAssistant Typescript Plugin the resulting JSON will be moved into the "artifacts" directory.
65

76
# Note: This script is meant to be started within the temporary analysis directory (e.g. "temp/AnalysisName/")
87
# Note: react-router uses pnpm as package manager which needs to be installed first
@@ -30,5 +29,4 @@ echo "downloadReactRouter: DOWNLOADER_SCRIPTS_DIR=${DOWNLOADER_SCRIPTS_DIR}"
3029
source "${DOWNLOADER_SCRIPTS_DIR}/downloadTypescriptProject.sh" \
3130
--url https://github.com/remix-run/react-router.git \
3231
--version "${projectVersion}" \
33-
--tag "react-router@${projectVersion}" \
34-
--packageManager pnpm
32+
--tag "react-router@${projectVersion}"

scripts/downloader/downloadTypescriptProject.sh

+2-55
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
#!/usr/bin/env bash
22

33
# Downloads the given version of a Typescript project from a git repository using git clone.
4-
# The cloned project is then moved into the "source" directory of the current analysis directory
5-
# where its dependencies are installed by the given package manager.
6-
# After scanning it with jQAssistant's Typescript Plugin, the resulting JSON will be moved into the "artifacts/typescript" directory.
4+
# The cloned project is then moved into the "source" directory of the current analysis directory.
75

86
# Command line options:
97
# --url Git clone URL (optional, default = skip clone)
108
# --version Version of the project
119
# --tag Tag to switch to after "git clone" (optional, default = version)
1210
# --project Name of the project/repository (optional, default = clone url file name without .git extension)
13-
# --packageManager One of "npm", "pnpm" or "yarn". (optional, default = "npm")
1411

1512
# Note: This script is meant to be started within the temporary analysis directory (e.g. "temp/AnalysisName/")
1613

@@ -29,7 +26,6 @@ usage() {
2926
echo " [ --tag <git-tag-for-that-version> (default=version) \\]"
3027
echo " [ --url <git-clone-url> (default=skip clone)] \\"
3128
echo " [ --project <name-of-the-project> (default=url file name) \\]"
32-
echo " [ --packageManager <npm/pnpm/yarn> (default=npm) ]"
3329
echo "Example: $0 \\"
3430
echo " --url https://github.com/ant-design/ant-design.git \\"
3531
echo " --version 5.19.3"
@@ -41,7 +37,6 @@ cloneUrl=""
4137
projectName=""
4238
projectVersion=""
4339
projectTag=""
44-
packageManager="npm"
4540

4641
# Parse command line options
4742
while [[ $# -gt 0 ]]; do
@@ -65,10 +60,6 @@ while [[ $# -gt 0 ]]; do
6560
projectTag="${value}"
6661
shift
6762
;;
68-
--packageManager)
69-
packageManager="${value}"
70-
shift
71-
;;
7263
*)
7364
echo "downloadTypescriptProject Error: Unknown option: ${key}"
7465
usage
@@ -108,49 +99,10 @@ if [ -z "${projectTag}" ]; then
10899
projectTag="${projectVersion}"
109100
fi
110101

111-
case "${packageManager}" in
112-
npm|pnpm|yarn)
113-
echo "downloadTypescriptProject Using package manager ${packageManager}"
114-
;;
115-
*)
116-
echo "downloadTypescriptProject Error: Unknown package manager: ${packageManager}"
117-
usage
118-
;;
119-
esac
120-
121-
if ! command -v "${packageManager}" &> /dev/null ; then
122-
echo "downloadTypescriptProject Error: Package manager ${packageManager} could not be found"
123-
exit 1
124-
fi
125-
126-
if ! command -v "npx" &> /dev/null ; then
127-
echo "downloadTypescriptProject Error: Command npx not found. It's needed to execute npm packages."
128-
exit 1
129-
fi
130-
131102
echo "downloadTypescriptProject: cloneUrl: ${cloneUrl}"
132103
echo "downloadTypescriptProject: projectName: ${projectName}"
133104
echo "downloadTypescriptProject: projectVersion: ${projectVersion}"
134105
echo "downloadTypescriptProject: projectTag: ${projectTag}"
135-
echo "downloadTypescriptProject: packageManager: ${packageManager}"
136-
137-
usePackageManagerToInstallDependencies() {
138-
echo "downloadTypescriptProject: Installing dependencies using ${packageManager}..."
139-
case "${packageManager}" in
140-
npm)
141-
# npm ci is not sufficient for projects like "ant-design" that rely on generating the package-lock
142-
# Even if this is not standard, this is an acceptable solution since it is only used to prepare scanning.
143-
# The same applies to "--force" which shouldn't be done normally.
144-
npm install --ignore-scripts --force --verbose || exit
145-
;;
146-
pnpm)
147-
pnpm install --frozen-lockfile || exit
148-
;;
149-
yarn)
150-
yarn install --frozen-lockfile --ignore-scripts --non-interactive --verbose || exit
151-
;;
152-
esac
153-
}
154106

155107
# Create runtime logs directory if it hasn't existed yet
156108
mkdir -p ./runtime/logs
@@ -172,9 +124,4 @@ if [ ! -d "${fullSourceDirectory}" ]; then # source doesn't exist
172124
else
173125
# Source already exists. Cloning not necessary.
174126
echo "downloadTypescriptProject: Source already exists. Skip cloning ${cloneUrl}"
175-
fi
176-
177-
(
178-
cd "${fullSourceDirectory}" || exit
179-
usePackageManagerToInstallDependencies
180-
)
127+
fi

scripts/examples/analyzeAntDesign.sh

+13-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
# Fail on any error ("-e" = exit on first error, "-o pipefail" exist on errors within piped commands)
1212
set -o errexit -o pipefail
1313

14+
# Overrideable Defaults
15+
SOURCE_DIRECTORY=${SOURCE_DIRECTORY:-"source"}
16+
echo "analyzerAntDesign: SOURCE_DIRECTORY=${SOURCE_DIRECTORY}"
17+
1418
## Get this "scripts" directory if not already set
1519
# Even if $BASH_SOURCE is made for Bourne-like shells it is also supported by others and therefore here the preferred solution.
1620
# CDPATH reduces the scope of the cd command to potentially prevent unintended directory changes.
@@ -53,8 +57,16 @@ cd "./ant-design-${projectVersion}"
5357
# Create the artifacts directory that will contain the code to be analyzed.
5458
mkdir -p ./artifacts
5559

56-
# Download AxonFramework artifacts (jar files) from Maven
60+
# Download ant-design source code
5761
./../../scripts/downloader/downloadAntDesign.sh "${projectVersion}"
5862

63+
(
64+
cd "./${SOURCE_DIRECTORY}//ant-design-${projectVersion}" || exit
65+
# npm ci is not sufficient for projects like "ant-design" that rely on generating the package-lock
66+
# Even if this is not standard, this is an acceptable solution since it is only used to prepare scanning.
67+
# The same applies to "--force" which shouldn't be done normally.
68+
npm install --ignore-scripts --force --verbose || exit
69+
)
70+
5971
# Start the analysis
6072
./../../scripts/analysis/analyze.sh "${@}"

scripts/examples/analyzeReactRouter.sh

+10-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
# Fail on any error ("-e" = exit on first error, "-o pipefail" exist on errors within piped commands)
1212
set -o errexit -o pipefail
1313

14+
# Overrideable Defaults
15+
SOURCE_DIRECTORY=${SOURCE_DIRECTORY:-"source"}
16+
echo "analyzerReactRouter: SOURCE_DIRECTORY=${SOURCE_DIRECTORY}"
17+
1418
## Get this "scripts" directory if not already set
1519
# Even if $BASH_SOURCE is made for Bourne-like shells it is also supported by others and therefore here the preferred solution.
1620
# CDPATH reduces the scope of the cd command to potentially prevent unintended directory changes.
@@ -53,8 +57,13 @@ cd "./react-router-${projectVersion}"
5357
# Create the artifacts directory that will contain the code to be analyzed.
5458
mkdir -p ./artifacts
5559

56-
# Download AxonFramework artifacts (jar files) from Maven
60+
# Download react-router source code
5761
./../../scripts/downloader/downloadReactRouter.sh "${projectVersion}"
5862

63+
(
64+
cd "${SOURCE_DIRECTORY}/react-router-${projectVersion}" || exit
65+
pnpm install --frozen-lockfile --strict-peer-dependencies || exit
66+
)
67+
5968
# Start the analysis
6069
./../../scripts/analysis/analyze.sh "${@}"

0 commit comments

Comments
 (0)