Skip to content

Commit 19a17cf

Browse files
committed
Unminify CDS extractor bundle
1 parent a2e2850 commit 19a17cf

File tree

7 files changed

+9308
-38
lines changed

7 files changed

+9308
-38
lines changed

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

Lines changed: 9289 additions & 17 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/esbuild.config.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ const buildOptions = {
6262
logLevel: 'info',
6363
// Ensure proper module resolution
6464
mainFields: ['main', 'module'],
65-
minify: true,
65+
minifyIdentifiers: false,
66+
minifySyntax: false,
67+
minifyWhitespace: false,
6668
outfile: 'dist/cds-extractor.bundle.js',
6769
platform: 'node',
6870
// Plugin to handle shell-quote module resolution
@@ -71,6 +73,7 @@ const buildOptions = {
7173
resolveExtensions: ['.ts', '.js'],
7274
sourcemap: true,
7375
target: NODE_VERSION_TARGET,
76+
treeShaking: true,
7477
};
7578

7679
async function build() {

extractors/cds/tools/src/diagnostics.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { execFileSync } from 'child_process';
22
import { resolve } from 'path';
33

4-
import { quote } from 'shell-quote';
5-
64
import { cdsExtractorLog } from './logging';
75

86
/**
@@ -36,9 +34,6 @@ function addDiagnostic(
3634
logPrefix: string,
3735
): boolean {
3836
try {
39-
// Use shell-quote to safely escape the message
40-
const escapedMessage = quote([message]);
41-
4237
execFileSync(codeqlExePath, [
4338
'database',
4439
'add-diagnostic',
@@ -47,7 +42,7 @@ function addDiagnostic(
4742
`--source-id=${sourceId}`,
4843
`--source-name=${sourceName}`,
4944
`--severity=${severity}`,
50-
`--markdown-message=${escapedMessage.slice(1, -1)}`, // Remove the added quotes from shell-quote
45+
`--markdown-message=${message}`,
5146
`--file-path=${resolve(filePath)}`,
5247
'--',
5348
`${process.env.CODEQL_EXTRACTOR_CDS_WIP_DATABASE ?? ''}`,

extractors/cds/tools/src/packageManager/versionResolver.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { execSync } from 'child_process';
22

3-
import { quote } from 'shell-quote';
4-
53
import type { SemanticVersion } from './types';
64
import { cdsExtractorLog } from '../logging';
75

@@ -11,6 +9,9 @@ import { cdsExtractorLog } from '../logging';
119
*/
1210
const availableVersionsCache = new Map<string, string[]>();
1311

12+
// Define the set of allowed npm packages for which we cache versions.
13+
type CachedPackageName = '@sap/cds' | '@sap/cds-dk';
14+
1415
/**
1516
* Cache statistics for debugging purposes
1617
*/
@@ -128,11 +129,12 @@ export function findBestAvailableVersion(
128129
}
129130

130131
/**
131-
* Get available versions for an npm package with caching to avoid duplicate npm view calls
132-
* @param packageName Name of the npm package
132+
* Get available versions for an npm package with caching to avoid duplicate
133+
* calls of the `npm view` command.
134+
* @param packageName The {@link CachedPackageName} for which to get versions
133135
* @returns Array of available version strings
134136
*/
135-
export function getAvailableVersions(packageName: string): string[] {
137+
export function getAvailableVersions(packageName: CachedPackageName): string[] {
136138
// Check cache first
137139
if (availableVersionsCache.has(packageName)) {
138140
cacheStats.hits++;
@@ -142,9 +144,7 @@ export function getAvailableVersions(packageName: string): string[] {
142144
// Cache miss - fetch from npm
143145
cacheStats.misses++;
144146
try {
145-
// Use shell-quote to properly escape the package name to prevent injection
146-
const escapedPackageName = quote([packageName]);
147-
const output = execSync(`npm view ${escapedPackageName} versions --json`, {
147+
const output = execSync(`npm view ${packageName} versions --json`, {
148148
encoding: 'utf8',
149149
timeout: 30000, // 30 second timeout
150150
});

extractors/cds/tools/test/src/diagnostics.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ describe('diagnostics', () => {
7070

7171
// Mock error during execution
7272
(childProcess.execFileSync as jest.Mock).mockImplementation(() => {
73-
throw new Error('Failed to add diagnostic');
73+
throw new Error('Message: Failed to add diagnostic');
7474
});
7575

7676
// Mock console.error
@@ -94,7 +94,7 @@ describe('diagnostics', () => {
9494
describe('addJavaScriptExtractorDiagnostic', () => {
9595
it('should add JavaScript extractor diagnostic successfully', () => {
9696
const filePath = '/path/to/source/root';
97-
const errorMessage = 'JavaScript extractor failed';
97+
const errorMessage = 'Message: JavaScript extracutor failed';
9898
const codeqlExePath = '/path/to/codeql';
9999

100100
// Mock process.env to include necessary environment variable

extractors/cds/tools/validate-bundle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const os = require('os');
55
const path = require('path');
66

77
const DEFAULT_TIMEOUT_MS = 5000; // Default timeout for execution in milliseconds
8-
const MAX_BUNDLE_SIZE_MB = 50; // Set a reasonable max bundle size
8+
const MAX_BUNDLE_SIZE_MB = 0.5; // We expect the bundle to be quite small
99

1010
const bundlePath = path.join(__dirname, 'dist', 'cds-extractor.bundle.js');
1111

0 commit comments

Comments
 (0)