@dataparade/cli 0.0.10 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +1 -1
- package/dist/src/analyzers/php/dependency-manifests.d.ts +10 -0
- package/dist/src/analyzers/php/dependency-manifests.js +117 -0
- package/dist/src/analyzers/php/detector.d.ts +3 -0
- package/dist/src/analyzers/php/detector.js +20 -0
- package/dist/src/analyzers/php/index.d.ts +2 -0
- package/dist/src/analyzers/php/index.js +11 -0
- package/dist/src/analyzers/php/manifest-parsers.d.ts +14 -0
- package/dist/src/analyzers/php/manifest-parsers.js +40 -0
- package/dist/src/analyzers/php/parser.d.ts +42 -0
- package/dist/src/analyzers/php/parser.js +297 -0
- package/dist/src/analyzers/php/patterns.d.ts +3 -0
- package/dist/src/analyzers/php/patterns.js +49 -0
- package/dist/src/analyzers/php/php-detection-config.d.ts +104 -0
- package/dist/src/analyzers/php/php-detection-config.js +192 -0
- package/dist/src/analyzers/registry.js +3 -0
- package/dist/src/analyzers/shared/strip-comments.js +3 -2
- package/dist/src/classifier/postprocessing.d.ts +6 -0
- package/dist/src/classifier/postprocessing.js +61 -6
- package/dist/src/cli.js +27 -0
- package/dist/src/config/file.js +1 -0
- package/dist/src/config/resolve.js +1 -0
- package/dist/src/core/pipeline/classifier-phase.js +3 -3
- package/dist/src/core/pipeline/structural-scan.js +39 -14
- package/dist/src/core/schema/scan-config.schema.d.ts +1 -0
- package/dist/src/core/schema/scan-config.schema.js +1 -0
- package/dist/src/core/schema/scan-result.schema.d.ts +1 -0
- package/dist/src/core/schema/scan-result.schema.js +1 -0
- package/dist/src/core/sectioning/discover-service-sections.js +3 -0
- package/dist/src/core/types/file.d.ts +1 -1
- package/dist/src/ingest/file-system.js +3 -0
- package/dist/src/patterns/config.d.ts +2 -0
- package/dist/src/patterns/config.js +31 -0
- package/dist/src/patterns/detectors/php.d.ts +9 -0
- package/dist/src/patterns/detectors/php.js +466 -0
- package/dist/src/patterns/engine.js +7 -0
- package/dist/src/platform-api/telemetry-client.d.ts +6 -0
- package/dist/src/platform-api/telemetry-client.js +65 -0
- package/dist/src/platform-api/telemetry.types.d.ts +13 -0
- package/dist/src/platform-api/telemetry.types.js +2 -0
- package/dist/src/platform-api/upload-client.d.ts +2 -0
- package/dist/src/platform-api/upload-client.js +4 -0
- package/dist/src/platform-api/upload.types.d.ts +2 -0
- package/dist/src/upload/build-preview-url.d.ts +2 -2
- package/dist/src/upload/build-preview-url.js +10 -3
- package/dist/src/upload/run-upload.js +62 -19
- package/dist/src/upload/types.d.ts +2 -0
- package/dist/tests/unit/analyzers/php/dependency-manifests.spec.d.ts +1 -0
- package/dist/tests/unit/analyzers/php/dependency-manifests.spec.js +54 -0
- package/dist/tests/unit/analyzers/php/parser.spec.d.ts +1 -0
- package/dist/tests/unit/analyzers/php/parser.spec.js +128 -0
- package/dist/tests/unit/analyzers/php/patterns.spec.d.ts +1 -0
- package/dist/tests/unit/analyzers/php/patterns.spec.js +334 -0
- package/dist/tests/unit/classifier/classify.spec.js +68 -0
- package/dist/tests/unit/ingest/php-languages.spec.d.ts +1 -0
- package/dist/tests/unit/ingest/php-languages.spec.js +40 -0
- package/dist/tests/unit/platform-api/telemetry-client.spec.d.ts +1 -0
- package/dist/tests/unit/platform-api/telemetry-client.spec.js +48 -0
- package/dist/tests/unit/upload/build-preview-url.spec.js +10 -0
- package/dist/tests/unit/upload/run-upload.spec.js +18 -0
- package/package.json +1 -1
- package/patterns/php.md +74 -0
- package/patterns/php.patterns.yaml +311 -0
- package/patterns/third-party.patterns.yaml +10 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isCliTelemetryEnabled = isCliTelemetryEnabled;
|
|
7
|
+
exports.reportCliUsageEvent = reportCliUsageEvent;
|
|
8
|
+
const package_json_1 = __importDefault(require("../../package.json"));
|
|
9
|
+
const dataparade_api_base_url_1 = require("./dataparade-api-base-url");
|
|
10
|
+
const TELEMETRY_TIMEOUT_MS = 2000;
|
|
11
|
+
const FALSY = new Set(["0", "false", "no", "off"]);
|
|
12
|
+
const TRUTHY = new Set(["1", "true", "yes", "on"]);
|
|
13
|
+
function isCliTelemetryEnabled(env = process.env) {
|
|
14
|
+
const explicit = env.DATAPARADE_TELEMETRY?.trim().toLowerCase() ||
|
|
15
|
+
env.SCAN_TELEMETRY_ENABLED?.trim().toLowerCase();
|
|
16
|
+
if (explicit && FALSY.has(explicit))
|
|
17
|
+
return false;
|
|
18
|
+
if (explicit && TRUTHY.has(explicit))
|
|
19
|
+
return true;
|
|
20
|
+
if (env.NODE_ENV === "test")
|
|
21
|
+
return false;
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Fire-and-forget CLI usage telemetry. Never throws.
|
|
26
|
+
*/
|
|
27
|
+
async function reportCliUsageEvent(input, env = process.env) {
|
|
28
|
+
if (!isCliTelemetryEnabled(env))
|
|
29
|
+
return;
|
|
30
|
+
const controller = new AbortController();
|
|
31
|
+
const timer = setTimeout(() => controller.abort(), TELEMETRY_TIMEOUT_MS);
|
|
32
|
+
try {
|
|
33
|
+
const headers = {
|
|
34
|
+
"Content-Type": "application/json",
|
|
35
|
+
};
|
|
36
|
+
const apiKey = input.apiKey?.trim();
|
|
37
|
+
if (apiKey) {
|
|
38
|
+
headers.Authorization = `Bearer ${apiKey}`;
|
|
39
|
+
}
|
|
40
|
+
await fetch(`${(0, dataparade_api_base_url_1.getDataparadeApiBaseUrl)(env)}/api/scans/cli/telemetry`, {
|
|
41
|
+
method: "POST",
|
|
42
|
+
headers,
|
|
43
|
+
signal: controller.signal,
|
|
44
|
+
body: JSON.stringify({
|
|
45
|
+
sessionId: input.sessionId,
|
|
46
|
+
event: input.event,
|
|
47
|
+
command: input.command,
|
|
48
|
+
hasApiKey: Boolean(input.hasApiKey ?? apiKey),
|
|
49
|
+
cliVersion: input.cliVersion ?? package_json_1.default.version,
|
|
50
|
+
draftId: input.draftId,
|
|
51
|
+
errorCode: input.errorCode,
|
|
52
|
+
errorMessage: input.errorMessage
|
|
53
|
+
? input.errorMessage.slice(0, 500)
|
|
54
|
+
: undefined,
|
|
55
|
+
source: input.source ?? "cli",
|
|
56
|
+
}),
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
// Telemetry must never change CLI behavior.
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
clearTimeout(timer);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type CliUsageEventName = "scan_started" | "scan_succeeded" | "scan_failed" | "upload_succeeded" | "upload_failed" | "preview_opened";
|
|
2
|
+
export type ReportCliUsageEventInput = {
|
|
3
|
+
sessionId: string;
|
|
4
|
+
event: CliUsageEventName;
|
|
5
|
+
command?: "scan" | "upload";
|
|
6
|
+
hasApiKey?: boolean;
|
|
7
|
+
apiKey?: string;
|
|
8
|
+
cliVersion?: string;
|
|
9
|
+
draftId?: string;
|
|
10
|
+
errorCode?: string;
|
|
11
|
+
errorMessage?: string;
|
|
12
|
+
source?: "cli" | "web";
|
|
13
|
+
};
|
|
@@ -4,6 +4,8 @@ export declare function cliUploadAnonymousPreview(input: {
|
|
|
4
4
|
dataflow: unknown;
|
|
5
5
|
projectName?: string;
|
|
6
6
|
scanJobId?: string;
|
|
7
|
+
cliUsageSessionId?: string;
|
|
8
|
+
command?: "scan" | "upload";
|
|
7
9
|
}): Promise<CliAnonymousUploadPreviewResponse>;
|
|
8
10
|
export declare function cliUploadPreview(input: CliUploadPreviewInput & {
|
|
9
11
|
apiKey: string;
|
|
@@ -33,6 +33,8 @@ async function cliUploadAnonymousPreview(input) {
|
|
|
33
33
|
dataflow: input.dataflow,
|
|
34
34
|
projectName: input.projectName,
|
|
35
35
|
scanJobId: input.scanJobId,
|
|
36
|
+
cliUsageSessionId: input.cliUsageSessionId,
|
|
37
|
+
command: input.command,
|
|
36
38
|
}),
|
|
37
39
|
});
|
|
38
40
|
if (!res.ok) {
|
|
@@ -48,6 +50,8 @@ async function cliUploadPreview(input) {
|
|
|
48
50
|
dataflow: input.dataflow,
|
|
49
51
|
projectName: input.projectName,
|
|
50
52
|
scanJobId: input.scanJobId,
|
|
53
|
+
cliUsageSessionId: input.cliUsageSessionId,
|
|
54
|
+
command: input.command,
|
|
51
55
|
}),
|
|
52
56
|
});
|
|
53
57
|
if (!res.ok) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function buildImportPreviewUrl(draftId: string): string;
|
|
2
|
-
export declare function buildAnonymousCliPreviewUrl(claimToken: string): string;
|
|
1
|
+
export declare function buildImportPreviewUrl(draftId: string, cliSessionId?: string): string;
|
|
2
|
+
export declare function buildAnonymousCliPreviewUrl(claimToken: string, cliSessionId?: string): string;
|
|
@@ -3,14 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.buildImportPreviewUrl = buildImportPreviewUrl;
|
|
4
4
|
exports.buildAnonymousCliPreviewUrl = buildAnonymousCliPreviewUrl;
|
|
5
5
|
const dataparade_app_base_url_1 = require("../platform-api/dataparade-app-base-url");
|
|
6
|
-
function buildImportPreviewUrl(draftId) {
|
|
6
|
+
function buildImportPreviewUrl(draftId, cliSessionId) {
|
|
7
7
|
const base = (0, dataparade_app_base_url_1.getDataparadeAppBaseUrl)();
|
|
8
8
|
const url = new URL("/dashboard", `${base}/`);
|
|
9
9
|
url.searchParams.set("importDraft", draftId);
|
|
10
|
+
if (cliSessionId?.trim()) {
|
|
11
|
+
url.searchParams.set("cliSession", cliSessionId.trim());
|
|
12
|
+
}
|
|
10
13
|
return url.toString();
|
|
11
14
|
}
|
|
12
|
-
function buildAnonymousCliPreviewUrl(claimToken) {
|
|
15
|
+
function buildAnonymousCliPreviewUrl(claimToken, cliSessionId) {
|
|
13
16
|
const base = (0, dataparade_app_base_url_1.getDataparadeAppBaseUrl)();
|
|
14
17
|
const encoded = encodeURIComponent(claimToken);
|
|
15
|
-
|
|
18
|
+
const url = new URL(`/preview/cli/${encoded}`, `${base}/`);
|
|
19
|
+
if (cliSessionId?.trim()) {
|
|
20
|
+
url.searchParams.set("cliSession", cliSessionId.trim());
|
|
21
|
+
}
|
|
22
|
+
return url.toString();
|
|
16
23
|
}
|
|
@@ -2,33 +2,76 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.runDataflowUpload = runDataflowUpload;
|
|
4
4
|
const upload_client_1 = require("../platform-api/upload-client");
|
|
5
|
+
const telemetry_client_1 = require("../platform-api/telemetry-client");
|
|
5
6
|
const build_preview_url_1 = require("./build-preview-url");
|
|
6
7
|
async function runDataflowUpload(input) {
|
|
7
8
|
const prefix = input.logPrefix ?? "[upload]";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
const command = input.command ?? "scan";
|
|
10
|
+
const sessionId = input.cliUsageSessionId?.trim();
|
|
11
|
+
const apiKey = input.apiKey?.trim();
|
|
12
|
+
try {
|
|
13
|
+
if (apiKey) {
|
|
14
|
+
const result = await (0, upload_client_1.cliUploadPreview)({
|
|
15
|
+
apiKey,
|
|
16
|
+
dataflow: input.dataflow,
|
|
17
|
+
projectName: input.projectName,
|
|
18
|
+
scanJobId: input.scanJobId,
|
|
19
|
+
cliUsageSessionId: sessionId,
|
|
20
|
+
command,
|
|
21
|
+
});
|
|
22
|
+
const previewUrl = (0, build_preview_url_1.buildImportPreviewUrl)(result.draftId, sessionId);
|
|
23
|
+
// eslint-disable-next-line no-console
|
|
24
|
+
console.log(`${prefix} Preview ready: ${previewUrl}`);
|
|
25
|
+
if (sessionId) {
|
|
26
|
+
await (0, telemetry_client_1.reportCliUsageEvent)({
|
|
27
|
+
sessionId,
|
|
28
|
+
event: "upload_succeeded",
|
|
29
|
+
command,
|
|
30
|
+
hasApiKey: true,
|
|
31
|
+
apiKey,
|
|
32
|
+
draftId: result.draftId,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return { draftId: result.draftId, previewUrl };
|
|
36
|
+
}
|
|
37
|
+
const result = await (0, upload_client_1.cliUploadAnonymousPreview)({
|
|
11
38
|
dataflow: input.dataflow,
|
|
12
39
|
projectName: input.projectName,
|
|
13
40
|
scanJobId: input.scanJobId,
|
|
41
|
+
cliUsageSessionId: sessionId,
|
|
42
|
+
command,
|
|
14
43
|
});
|
|
15
|
-
const previewUrl = (0, build_preview_url_1.
|
|
44
|
+
const previewUrl = (0, build_preview_url_1.buildAnonymousCliPreviewUrl)(result.claimToken, sessionId);
|
|
16
45
|
// eslint-disable-next-line no-console
|
|
17
46
|
console.log(`${prefix} Preview ready: ${previewUrl}`);
|
|
18
|
-
|
|
47
|
+
// eslint-disable-next-line no-console
|
|
48
|
+
console.log(`${prefix} Claiming this preview after signup uses 1 scan slot` +
|
|
49
|
+
(input.scanJobId
|
|
50
|
+
? " and any platform AI tokens used during the scan."
|
|
51
|
+
: "."));
|
|
52
|
+
if (sessionId) {
|
|
53
|
+
await (0, telemetry_client_1.reportCliUsageEvent)({
|
|
54
|
+
sessionId,
|
|
55
|
+
event: "upload_succeeded",
|
|
56
|
+
command,
|
|
57
|
+
hasApiKey: false,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return { previewUrl };
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
if (sessionId) {
|
|
64
|
+
const message = error instanceof Error ? error.message : "Upload failed.";
|
|
65
|
+
await (0, telemetry_client_1.reportCliUsageEvent)({
|
|
66
|
+
sessionId,
|
|
67
|
+
event: "upload_failed",
|
|
68
|
+
command,
|
|
69
|
+
hasApiKey: Boolean(apiKey),
|
|
70
|
+
apiKey,
|
|
71
|
+
errorCode: "upload_failed",
|
|
72
|
+
errorMessage: message,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
throw error;
|
|
19
76
|
}
|
|
20
|
-
const result = await (0, upload_client_1.cliUploadAnonymousPreview)({
|
|
21
|
-
dataflow: input.dataflow,
|
|
22
|
-
projectName: input.projectName,
|
|
23
|
-
scanJobId: input.scanJobId,
|
|
24
|
-
});
|
|
25
|
-
const previewUrl = (0, build_preview_url_1.buildAnonymousCliPreviewUrl)(result.claimToken);
|
|
26
|
-
// eslint-disable-next-line no-console
|
|
27
|
-
console.log(`${prefix} Preview ready: ${previewUrl}`);
|
|
28
|
-
// eslint-disable-next-line no-console
|
|
29
|
-
console.log(`${prefix} Claiming this preview after signup uses 1 scan slot` +
|
|
30
|
-
(input.scanJobId
|
|
31
|
-
? " and any platform AI tokens used during the scan."
|
|
32
|
-
: "."));
|
|
33
|
-
return { previewUrl };
|
|
34
77
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const path_1 = __importDefault(require("path"));
|
|
7
|
+
const dependency_manifests_1 = require("../../../../src/analyzers/php/dependency-manifests");
|
|
8
|
+
const manifest_parsers_1 = require("../../../../src/analyzers/php/manifest-parsers");
|
|
9
|
+
const FIXTURE_ROOT = path_1.default.join(__dirname, "..", "..", "..", "fixtures", "php-dependency-manifests-basic");
|
|
10
|
+
describe("PHP manifest parsers", () => {
|
|
11
|
+
it("parses require and require-dev package names, skipping php/ext", () => {
|
|
12
|
+
const content = JSON.stringify({
|
|
13
|
+
name: "acme/gateway",
|
|
14
|
+
require: {
|
|
15
|
+
php: "^8.2",
|
|
16
|
+
"ext-json": "*",
|
|
17
|
+
"guzzlehttp/guzzle": "^7.0",
|
|
18
|
+
"laravel/framework": "^11.0",
|
|
19
|
+
},
|
|
20
|
+
"require-dev": {
|
|
21
|
+
"phpunit/phpunit": "^10.0",
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
const parsed = (0, manifest_parsers_1.parseComposerJson)(content);
|
|
25
|
+
expect(parsed.name).toBe("acme/gateway");
|
|
26
|
+
expect(parsed.packages.sort()).toEqual([
|
|
27
|
+
"guzzlehttp/guzzle",
|
|
28
|
+
"laravel/framework",
|
|
29
|
+
"phpunit/phpunit",
|
|
30
|
+
]);
|
|
31
|
+
});
|
|
32
|
+
it("returns empty packages for invalid JSON", () => {
|
|
33
|
+
expect((0, manifest_parsers_1.parseComposerJson)("{not json").packages).toEqual([]);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
describe("PHP dependency manifests", () => {
|
|
37
|
+
it("walks composer.json fixtures and feeds package names to matchPatterns", async () => {
|
|
38
|
+
const manifests = await (0, dependency_manifests_1.parsePhpDependencyManifests)(FIXTURE_ROOT);
|
|
39
|
+
expect(manifests.length).toBe(1);
|
|
40
|
+
expect(manifests[0].packageName).toBe("acme/billing-api");
|
|
41
|
+
expect(manifests[0].packages).toEqual(expect.arrayContaining([
|
|
42
|
+
"guzzlehttp/guzzle",
|
|
43
|
+
"laravel/framework",
|
|
44
|
+
"stripe/stripe-php",
|
|
45
|
+
"phpunit/phpunit",
|
|
46
|
+
]));
|
|
47
|
+
const findings = await (0, dependency_manifests_1.detectPhpPatternsFromDependencyManifests)(FIXTURE_ROOT);
|
|
48
|
+
expect(findings.length).toBeGreaterThan(0);
|
|
49
|
+
const dbs = findings.filter((f) => f.pattern === "database_connection");
|
|
50
|
+
expect(dbs.some((d) => d.name === "eloquent")).toBe(true);
|
|
51
|
+
const apis = findings.filter((f) => f.pattern === "external_api_call");
|
|
52
|
+
expect(apis.some((a) => a.properties.serviceName === "stripe" || a.name.includes("stripe"))).toBe(true);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const parser_1 = require("../../../../src/analyzers/php/parser");
|
|
4
|
+
function createPhpFile(content, path = "index.php") {
|
|
5
|
+
return {
|
|
6
|
+
path,
|
|
7
|
+
name: path,
|
|
8
|
+
content,
|
|
9
|
+
language: "php",
|
|
10
|
+
size: content.length,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
describe("PHP parser - parsePhpSourceFile", () => {
|
|
14
|
+
it("indexes namespace, use imports, classes, functions, and calls", () => {
|
|
15
|
+
const content = [
|
|
16
|
+
"<?php",
|
|
17
|
+
"",
|
|
18
|
+
"namespace App\\Http;",
|
|
19
|
+
"",
|
|
20
|
+
"use GuzzleHttp\\Client;",
|
|
21
|
+
"use Illuminate\\Support\\Facades\\DB as Database;",
|
|
22
|
+
"require_once 'vendor/autoload.php';",
|
|
23
|
+
"",
|
|
24
|
+
"class OrdersController",
|
|
25
|
+
"{",
|
|
26
|
+
" public function index()",
|
|
27
|
+
" {",
|
|
28
|
+
' $client = new Client();',
|
|
29
|
+
' $client->get("https://api.example.com/items");',
|
|
30
|
+
" return Database::table('orders')->get();",
|
|
31
|
+
" }",
|
|
32
|
+
"}",
|
|
33
|
+
"",
|
|
34
|
+
"function boot()",
|
|
35
|
+
"{",
|
|
36
|
+
' getenv("APP_KEY");',
|
|
37
|
+
"}",
|
|
38
|
+
"",
|
|
39
|
+
].join("\n");
|
|
40
|
+
const result = (0, parser_1.parsePhpSourceFile)(createPhpFile(content));
|
|
41
|
+
expect(result.warnings).toEqual([]);
|
|
42
|
+
expect(result.namespace).toBe("App\\Http");
|
|
43
|
+
expect(result.imports.map((i) => i.path)).toEqual([
|
|
44
|
+
"GuzzleHttp\\Client",
|
|
45
|
+
"Illuminate\\Support\\Facades\\DB",
|
|
46
|
+
"vendor/autoload.php",
|
|
47
|
+
]);
|
|
48
|
+
const guzzle = result.imports.find((i) => i.path === "GuzzleHttp\\Client");
|
|
49
|
+
expect(guzzle?.isRequire).toBe(false);
|
|
50
|
+
const db = result.imports.find((i) => i.path === "Illuminate\\Support\\Facades\\DB");
|
|
51
|
+
expect(db?.alias).toBe("Database");
|
|
52
|
+
const require = result.imports.find((i) => i.path === "vendor/autoload.php");
|
|
53
|
+
expect(require?.isRequire).toBe(true);
|
|
54
|
+
const controller = result.types.find((t) => t.name === "OrdersController");
|
|
55
|
+
expect(controller?.kind).toBe("class");
|
|
56
|
+
const index = result.functions.find((fn) => fn.name === "index");
|
|
57
|
+
expect(index?.className).toBe("OrdersController");
|
|
58
|
+
const boot = result.functions.find((fn) => fn.name === "boot");
|
|
59
|
+
expect(boot?.className).toBeUndefined();
|
|
60
|
+
expect(result.calls.some((c) => c.callee === "new Client")).toBe(true);
|
|
61
|
+
expect(result.calls.some((c) => c.callee === "->get")).toBe(true);
|
|
62
|
+
expect(result.calls.some((c) => c.callee === "Database::table")).toBe(true);
|
|
63
|
+
expect(result.calls.some((c) => c.callee === "getenv")).toBe(true);
|
|
64
|
+
});
|
|
65
|
+
it("blanks comments while preserving string literals and layout", () => {
|
|
66
|
+
const content = [
|
|
67
|
+
"<?php",
|
|
68
|
+
'// $client->get("https://old.example.com");',
|
|
69
|
+
"# ignored hash comment",
|
|
70
|
+
'/* $client->get("https://block.example.com"); */',
|
|
71
|
+
'$client->get("https://live.example.com");',
|
|
72
|
+
"",
|
|
73
|
+
].join("\n");
|
|
74
|
+
const result = (0, parser_1.parsePhpSourceFile)(createPhpFile(content));
|
|
75
|
+
expect(result.strippedContent).not.toContain("old.example.com");
|
|
76
|
+
expect(result.strippedContent).not.toContain("block.example.com");
|
|
77
|
+
expect(result.strippedContent).toContain("https://live.example.com");
|
|
78
|
+
expect(result.calls.some((c) => c.callee === "->get")).toBe(true);
|
|
79
|
+
});
|
|
80
|
+
it("preserves PHP 8 attributes when stripping hash comments", () => {
|
|
81
|
+
const content = [
|
|
82
|
+
"<?php",
|
|
83
|
+
"",
|
|
84
|
+
'#[Route("/api/users", methods: ["GET"])]',
|
|
85
|
+
"class UsersController",
|
|
86
|
+
"{",
|
|
87
|
+
"}",
|
|
88
|
+
"",
|
|
89
|
+
].join("\n");
|
|
90
|
+
const result = (0, parser_1.parsePhpSourceFile)(createPhpFile(content));
|
|
91
|
+
expect(result.strippedContent).toContain('#[Route("/api/users"');
|
|
92
|
+
});
|
|
93
|
+
it("expands grouped use imports into full paths", () => {
|
|
94
|
+
const content = [
|
|
95
|
+
"<?php",
|
|
96
|
+
"",
|
|
97
|
+
"use GuzzleHttp\\{Client, HandlerStack};",
|
|
98
|
+
"use Slim\\{App as SlimApp, Routing\\RouteCollector};",
|
|
99
|
+
"use function App\\Helpers\\{format, slugify as toSlug};",
|
|
100
|
+
"",
|
|
101
|
+
].join("\n");
|
|
102
|
+
const result = (0, parser_1.parsePhpSourceFile)(createPhpFile(content));
|
|
103
|
+
expect(result.imports.map((i) => i.path)).toEqual([
|
|
104
|
+
"GuzzleHttp\\Client",
|
|
105
|
+
"GuzzleHttp\\HandlerStack",
|
|
106
|
+
"Slim\\App",
|
|
107
|
+
"Slim\\Routing\\RouteCollector",
|
|
108
|
+
"App\\Helpers\\format",
|
|
109
|
+
"App\\Helpers\\slugify",
|
|
110
|
+
]);
|
|
111
|
+
const slimApp = result.imports.find((i) => i.path === "Slim\\App");
|
|
112
|
+
expect(slimApp?.alias).toBe("SlimApp");
|
|
113
|
+
const slugify = result.imports.find((i) => i.path === "App\\Helpers\\slugify");
|
|
114
|
+
expect(slugify?.alias).toBe("toSlug");
|
|
115
|
+
});
|
|
116
|
+
it("returns a warning for non-php language", () => {
|
|
117
|
+
const file = {
|
|
118
|
+
path: "main.go",
|
|
119
|
+
name: "main.go",
|
|
120
|
+
content: "package main",
|
|
121
|
+
language: "go",
|
|
122
|
+
size: 12,
|
|
123
|
+
};
|
|
124
|
+
const result = (0, parser_1.parsePhpSourceFile)(file);
|
|
125
|
+
expect(result.warnings.length).toBe(1);
|
|
126
|
+
expect(result.imports).toEqual([]);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|