Skip to content

Commit 90453cc

Browse files
committed
Fix CDS extractor monorepo support
Fixes a regression in the CDS extractor's processing of monorepos.
1 parent d4dd37a commit 90453cc

15 files changed

Lines changed: 803 additions & 643 deletions

File tree

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,48 @@
11
@echo off
22

3-
if "%~1"=="" (
4-
echo Usage: %0 ^<response_file_path^>
5-
exit /b 1
6-
)
3+
REM This script currently:
4+
REM - ignores any arguments passed to it;
5+
REM - assumes it is run from the root of the project source directory;
76

87
where node >nul 2>nul
98
if %ERRORLEVEL% neq 0 (
109
echo node executable is required (in PATH) to run the 'cds-extractor.js' script. Please install Node.js and try again.
1110
exit /b 2
1211
)
1312

14-
where npm >nul 2>nul
15-
if %ERRORLEVEL% neq 0 (
16-
echo npm executable is required (in PATH) to install the dependencies for the 'cds-extractor.js' script.
17-
exit /b 3
18-
)
19-
20-
set "_response_file_path=%~1"
21-
set "_run_mode=index-files"
22-
set "_script_dir=%~dp0"
23-
REM Set _cwd before changing the working directory to the script directory.
24-
REM We assume this script is called from the source root directory of the
25-
REM to be scanned project.
13+
REM Set the _cwd variable to the present working directory as the directory
14+
REM from which this script was called, which we assume is the "source root" directory
15+
REM of the project that to be scanned / indexed.
2616
set "_cwd=%CD%"
17+
set "_script_dir=%~dp0"
18+
set "_cds_extractor_js_path=%_script_dir%dist\cds-extractor.js"
19+
set "_cds_extractor_node_modules_dir=%_script_dir%node_modules"
2720

28-
echo Checking response file for CDS files to index
21+
if not exist "%_cds_extractor_js_path%" (
22+
echo Error: The 'cds-extractor.js' script does not exist at the expected path: %_cds_extractor_js_path%
23+
echo Please ensure that the script has been built and is available in the 'dist' directory.
24+
exit /b 3
25+
)
2926

30-
REM Terminate early if the _response_file_path doesn't exist or is empty,
31-
REM which indicates that no CDS files were selected or found.
32-
if not exist "%_response_file_path%" (
33-
echo 'codeql database cds-extractor --language cds' command terminated early as response file '%_response_file_path%' does not exist or is empty. This is because no CDS files were selected or found.
34-
exit /b 0
27+
if not exist "%_cds_extractor_node_modules_dir%" (
28+
echo Error: The 'node_modules' directory does not exist at the expected path: %_cds_extractor_node_modules_dir%
29+
echo Please ensure that the dependencies have been installed by running 'npm install' in the 'extractors\cds\tools' directory.
30+
exit /b 4
3531
)
3632

37-
REM Change to the directory of this script to ensure that npm looks up the
33+
REM Change to the directory of this batch script to ensure that npm looks up the
3834
REM package.json file in the correct directory and installs the dependencies
3935
REM (i.e. node_modules) relative to this directory. This is technically a
4036
REM violation of the assumption that extractor scripts will be run with the
4137
REM current working directory set to the root of the project source, but we
4238
REM also need node_modules to be installed here and not in the project source
4339
REM root, so we make a compromise of:
44-
REM 1. changing to this script's directory;
45-
REM 2. installing node dependencies here;
46-
REM 3. passing the original working directory as a parameter to the
40+
REM 1. changing to this batch script's directory;
41+
REM 2. passing the original working directory as a parameter to the
4742
REM cds-extractor.js script;
48-
REM 4. expecting the cds-extractor.js script to immediately change back to
49-
REM the original working (aka the project source root) directory.
43+
REM 3. expecting the cds-extractor.js script to immediately change back to
44+
REM original working (aka the project source root) directory.
5045

5146
cd /d "%_script_dir%" && ^
52-
echo Installing node package dependencies && ^
53-
npm install --quiet --no-audit --no-fund && ^
54-
echo Building TypeScript code && ^
55-
npm run build && ^
5647
echo Running the 'cds-extractor.js' script && ^
57-
node "%_script_dir%out\cds-extractor.js" "%_run_mode%" "%_cwd%" "%_response_file_path%"
58-
59-
exit /b %ERRORLEVEL%
48+
node "%_cds_extractor_js_path%" "%_cwd%"

extractors/cds/tools/index-files.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ fi
1818
# of the project that to be scanned / indexed.
1919
_cwd="$PWD"
2020
_script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
21-
_cds_extractor_js_path="${_script_dir}/out/cds-extractor.js"
21+
_cds_extractor_js_path="${_script_dir}/dist/cds-extractor.js"
2222
_cds_extractor_node_modules_dir="${_script_dir}/node_modules"
2323

2424
if [ ! -f "${_cds_extractor_js_path}" ]; then
2525
echo "Error: The 'cds-extractor.js' script does not exist at the expected path: ${_cds_extractor_js_path}"
26-
echo "Please ensure that the script has been built and is available in the 'out' directory."
26+
echo "Please ensure that the script has been built and is available in the 'dist' directory."
2727
exit 3
2828
fi
2929

extractors/cds/tools/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
"name": "@advanced-security/codeql-sap-js_index-cds-files",
33
"version": "1.0.0",
44
"description": "CodeQL extractor for DB indexing of .cds.json files produced by the 'cds' compiler.",
5-
"main": "out/cds-extractor.js",
5+
"main": "dist/cds-extractor.js",
66
"scripts": {
77
"build": "tsc",
88
"build:all": "npm run lint:fix && npm run test:coverage && npm run build",
9-
"clean": "rm -rf out coverage",
9+
"clean": "rm -rf coverage dist",
1010
"prebuild": "npm run clean",
1111
"lint": "eslint --ext .ts src/",
1212
"lint:fix": "eslint --ext .ts --fix cds-extractor.ts src/ test/src/",

0 commit comments

Comments
 (0)