Skip to content

Commit 055c579

Browse files
committed
Address PR review comments
1 parent fbb3dd3 commit 055c579

File tree

8 files changed

+29
-114
lines changed

8 files changed

+29
-114
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,5 @@ dbs
7979

8080
# workspace customization file
8181
codeql-sap-js.code-workspace
82+
.vscode/settings.json
8283

extractors/cds/tools/dist/cds-extractor.bundle.js

Lines changed: 7 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extractors/cds/tools/dist/cds-extractor.bundle.js.map

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extractors/cds/tools/dist/compile-test-cds-lib.cjs.map

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

extractors/cds/tools/package-lock.json

Lines changed: 1 addition & 50 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extractors/cds/tools/package.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,9 @@
2323
"test:coverage": "npm run build:tests && jest --coverage"
2424
},
2525
"dependencies": {
26-
"child_process": "^1.0.2",
27-
"fs": "^0.0.2",
2826
"glob": "^13.0.6",
2927
"js-yaml": "^4.1.1",
3028
"minimatch": "^10.2.4",
31-
"os": "^0.1.2",
32-
"path": "^0.12.7",
3329
"tmp": "^0.2.5"
3430
},
3531
"devDependencies": {

extractors/cds/tools/src/paths-ignore.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { existsSync, readFileSync } from 'fs';
22
import { join } from 'path';
33

4-
import jsYaml from 'js-yaml';
4+
import { load as yamlLoad } from 'js-yaml';
55
import { minimatch } from 'minimatch';
66

77
import { cdsExtractorLog } from './logging';
@@ -66,9 +66,10 @@ export function getPathsIgnorePatterns(sourceRoot: string): string[] {
6666

6767
try {
6868
const content = readFileSync(configPath, 'utf8');
69-
const config = jsYaml.load(content) as CodeqlConfig | null;
69+
const config = yamlLoad(content) as CodeqlConfig | null;
7070

7171
if (!config || !Array.isArray(config['paths-ignore'])) {
72+
patternsCache.set(sourceRoot, []);
7273
return [];
7374
}
7475

@@ -106,18 +107,20 @@ export function getPathsIgnorePatterns(sourceRoot: string): string[] {
106107
* @returns true if the path should be ignored
107108
*/
108109
export function shouldIgnorePath(relativePath: string, patterns: string[]): boolean {
110+
const matchOptions = { dot: true, windowsPathsNoEscape: true };
111+
109112
for (const raw of patterns) {
110113
// Strip trailing slashes so `vendor/` is treated the same as `vendor`
111114
const pattern = raw.replace(/\/+$/, '');
112115

113116
// Direct minimatch check
114-
if (minimatch(relativePath, pattern, { dot: true })) {
117+
if (minimatch(relativePath, pattern, matchOptions)) {
115118
return true;
116119
}
117120

118121
// Also match as a directory prefix: pattern `vendor` should
119122
// match `vendor/lib/foo.cds` (i.e. anything nested underneath).
120-
if (minimatch(relativePath, `${pattern}/**`, { dot: true })) {
123+
if (minimatch(relativePath, `${pattern}/**`, matchOptions)) {
121124
return true;
122125
}
123126
}

extractors/cds/tools/test/src/paths-ignore.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { existsSync, readFileSync } from 'fs';
22

3-
import jsYaml from 'js-yaml';
3+
import { load as yamlLoad } from 'js-yaml';
44

55
import {
66
clearPathsIgnoreCache,
@@ -70,7 +70,7 @@ describe('paths-ignore', () => {
7070
(p: string) => p === '/source/.github/codeql/codeql-config.yml',
7171
);
7272
(readFileSync as jest.Mock).mockReturnValue('yaml-content');
73-
(jsYaml.load as jest.Mock).mockReturnValue({
73+
(yamlLoad as jest.Mock).mockReturnValue({
7474
name: 'My CodeQL config',
7575
'paths-ignore': ['src/node_modules', '**/*.test.js'],
7676
queries: [{ uses: 'security-extended' }],
@@ -92,7 +92,7 @@ describe('paths-ignore', () => {
9292
(p: string) => p === '/source/.github/codeql/codeql-config.yml',
9393
);
9494
(readFileSync as jest.Mock).mockReturnValue('yaml-content');
95-
(jsYaml.load as jest.Mock).mockReturnValue({
95+
(yamlLoad as jest.Mock).mockReturnValue({
9696
name: 'My CodeQL config',
9797
queries: [{ uses: 'security-extended' }],
9898
});
@@ -106,7 +106,7 @@ describe('paths-ignore', () => {
106106
(p: string) => p === '/source/.github/codeql/codeql-config.yml',
107107
);
108108
(readFileSync as jest.Mock).mockReturnValue('yaml-content');
109-
(jsYaml.load as jest.Mock).mockReturnValue({
109+
(yamlLoad as jest.Mock).mockReturnValue({
110110
'paths-ignore': ['vendor/**', 'test/data'],
111111
});
112112

@@ -119,7 +119,7 @@ describe('paths-ignore', () => {
119119
(p: string) => p === '/source/.github/codeql/codeql-config.yml',
120120
);
121121
(readFileSync as jest.Mock).mockReturnValue('yaml-content');
122-
(jsYaml.load as jest.Mock).mockReturnValue({
122+
(yamlLoad as jest.Mock).mockReturnValue({
123123
'paths-ignore': ['vendor'],
124124
});
125125

@@ -136,7 +136,7 @@ describe('paths-ignore', () => {
136136
(p: string) => p === '/source/.github/codeql/codeql-config.yml',
137137
);
138138
(readFileSync as jest.Mock).mockReturnValue('{{invalid');
139-
(jsYaml.load as jest.Mock).mockImplementation(() => {
139+
(yamlLoad as jest.Mock).mockImplementation(() => {
140140
throw new Error('YAML parse error');
141141
});
142142

@@ -161,7 +161,7 @@ describe('paths-ignore', () => {
161161
(p: string) => p === '/source/.github/codeql/codeql-config.yml',
162162
);
163163
(readFileSync as jest.Mock).mockReturnValue('yaml-content');
164-
(jsYaml.load as jest.Mock).mockReturnValue({
164+
(yamlLoad as jest.Mock).mockReturnValue({
165165
'paths-ignore': ['vendor', '', null, 42, 'test'],
166166
});
167167

@@ -174,7 +174,7 @@ describe('paths-ignore', () => {
174174
(p: string) => p === '/source/.github/codeql/codeql-config.yml',
175175
);
176176
(readFileSync as jest.Mock).mockReturnValue('');
177-
(jsYaml.load as jest.Mock).mockReturnValue(null);
177+
(yamlLoad as jest.Mock).mockReturnValue(null);
178178

179179
const result = getPathsIgnorePatterns('/source');
180180
expect(result).toEqual([]);
@@ -185,7 +185,7 @@ describe('paths-ignore', () => {
185185
(p: string) => p === '/source/.github/codeql/codeql-config.yml',
186186
);
187187
(readFileSync as jest.Mock).mockReturnValue('yaml-content');
188-
(jsYaml.load as jest.Mock).mockReturnValue({
188+
(yamlLoad as jest.Mock).mockReturnValue({
189189
'paths-ignore': 'not-an-array',
190190
});
191191

0 commit comments

Comments
 (0)