Skip to content

Commit cbb1de4

Browse files
authored
Merge pull request #2847 from github/dependabot/npm_and_yarn/extensions/ql-vscode/types/js-yaml-4.0.6
Bump @types/js-yaml from 3.12.5 to 4.0.6 in /extensions/ql-vscode
2 parents 9e92c6c + 7864844 commit cbb1de4

21 files changed

+442
-90
lines changed

.github/workflows/main.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,42 @@ jobs:
9999
run: |
100100
npm run find-deadcode
101101
102+
generated:
103+
name: Check generated code
104+
runs-on: ubuntu-latest
105+
steps:
106+
- name: Checkout
107+
uses: actions/checkout@v4
108+
with:
109+
fetch-depth: 1
110+
111+
- uses: actions/setup-node@v3
112+
with:
113+
node-version: '16.17.1'
114+
cache: 'npm'
115+
cache-dependency-path: extensions/ql-vscode/package-lock.json
116+
117+
- name: Install dependencies
118+
working-directory: extensions/ql-vscode
119+
run: |
120+
npm ci
121+
shell: bash
122+
123+
- name: Check that repo is clean
124+
run: |
125+
git diff --exit-code
126+
git diff --exit-code --cached
127+
128+
- name: Generate code
129+
working-directory: extensions/ql-vscode
130+
run: |
131+
npm run generate
132+
133+
- name: Check for changes
134+
run: |
135+
git diff --exit-code
136+
git diff --exit-code --cached
137+
102138
unit-test:
103139
name: Unit Test
104140
runs-on: ${{ matrix.os }}

extensions/ql-vscode/package-lock.json

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

extensions/ql-vscode/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1946,6 +1946,8 @@
19461946
"storybook": "storybook dev -p 6006",
19471947
"build-storybook": "storybook build",
19481948
"lint:scenarios": "ts-node scripts/lint-scenarios.ts",
1949+
"generate": "npm-run-all -p generate:*",
1950+
"generate:schemas": "ts-node scripts/generate-schemas.ts",
19491951
"check-types": "find . -type f -name \"tsconfig.json\" -not -path \"./node_modules/*\" | sed -r 's|/[^/]+$||' | sort | uniq | xargs -I {} sh -c \"echo Checking types in {} && cd {} && npx tsc --noEmit\"",
19501952
"postinstall": "patch-package",
19511953
"prepare": "cd ../.. && husky install"
@@ -2020,7 +2022,7 @@
20202022
"@types/gulp": "^4.0.9",
20212023
"@types/gulp-replace": "^1.1.0",
20222024
"@types/jest": "^29.0.2",
2023-
"@types/js-yaml": "^3.12.5",
2025+
"@types/js-yaml": "^4.0.6",
20242026
"@types/nanoid": "^3.0.0",
20252027
"@types/node": "^16.11.25",
20262028
"@types/node-fetch": "^2.5.2",
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { createGenerator } from "ts-json-schema-generator";
2+
import { join, resolve } from "path";
3+
import { outputFile } from "fs-extra";
4+
import { format, resolveConfig } from "prettier";
5+
6+
const extensionDirectory = resolve(__dirname, "..");
7+
8+
const schemas = [
9+
{
10+
path: join(
11+
extensionDirectory,
12+
"src",
13+
"model-editor",
14+
"extension-pack-metadata.ts",
15+
),
16+
type: "ExtensionPackMetadata",
17+
schemaPath: join(
18+
extensionDirectory,
19+
"src",
20+
"model-editor",
21+
"extension-pack-metadata.schema.json",
22+
),
23+
},
24+
{
25+
path: join(
26+
extensionDirectory,
27+
"src",
28+
"model-editor",
29+
"model-extension-file.ts",
30+
),
31+
type: "ModelExtensionFile",
32+
schemaPath: join(
33+
extensionDirectory,
34+
"src",
35+
"model-editor",
36+
"model-extension-file.schema.json",
37+
),
38+
},
39+
];
40+
41+
async function generateSchema(
42+
schemaDefinition: (typeof schemas)[number],
43+
): Promise<void> {
44+
const schema = createGenerator({
45+
path: schemaDefinition.path,
46+
tsconfig: resolve(extensionDirectory, "tsconfig.json"),
47+
type: schemaDefinition.type,
48+
skipTypeCheck: true,
49+
topRef: true,
50+
additionalProperties: true,
51+
}).createSchema(schemaDefinition.type);
52+
53+
const schemaJson = JSON.stringify(schema, null, 2);
54+
55+
const prettierOptions = await resolveConfig(schemaDefinition.schemaPath);
56+
57+
const formattedSchemaJson = await format(schemaJson, {
58+
...prettierOptions,
59+
filepath: schemaDefinition.schemaPath,
60+
});
61+
62+
await outputFile(schemaDefinition.schemaPath, formattedSchemaJson);
63+
}
64+
65+
async function generateSchemas() {
66+
await Promise.all(schemas.map(generateSchema));
67+
}
68+
69+
generateSchemas().catch((e: unknown) => {
70+
console.error(e);
71+
process.exit(2);
72+
});

extensions/ql-vscode/src/local-queries/query-resolver.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { redactableError } from "../common/errors";
1313
import { showAndLogExceptionWithTelemetry } from "../common/logging";
1414
import { extLogger } from "../common/logging/vscode";
1515
import { telemetryListener } from "../common/vscode/telemetry";
16+
import { SuiteInstruction } from "../packaging/suite-instruction";
1617

1718
export async function qlpackOfDatabase(
1819
cli: Pick<CodeQLCliServer, "resolveQlpacks">,
@@ -50,12 +51,12 @@ async function resolveQueriesFromPacks(
5051
postfix: ".qls",
5152
})
5253
).path;
53-
const suiteYaml = [];
54+
const suiteYaml: SuiteInstruction[] = [];
5455
for (const qlpack of qlpacks) {
5556
suiteYaml.push({
5657
from: qlpack,
5758
queries: ".",
58-
include: constraints,
59+
include: constraints as Record<string, string[]>,
5960
});
6061
}
6162
await writeFile(

extensions/ql-vscode/src/model-editor/data-schema.json

Lines changed: 0 additions & 45 deletions
This file was deleted.
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$ref": "#/definitions/ExtensionPackMetadata",
4+
"definitions": {
5+
"ExtensionPackMetadata": {
6+
"type": "object",
7+
"properties": {
8+
"extensionTargets": {
9+
"type": "object",
10+
"additionalProperties": {
11+
"type": "string"
12+
}
13+
},
14+
"dataExtensions": {
15+
"anyOf": [
16+
{
17+
"type": "array",
18+
"items": {
19+
"type": "string"
20+
}
21+
},
22+
{
23+
"type": "string"
24+
}
25+
]
26+
},
27+
"name": {
28+
"type": "string"
29+
},
30+
"version": {
31+
"type": "string"
32+
},
33+
"dependencies": {
34+
"type": "object",
35+
"additionalProperties": {
36+
"type": "string"
37+
}
38+
},
39+
"dbscheme": {
40+
"type": "string"
41+
},
42+
"library": {
43+
"type": "boolean"
44+
},
45+
"defaultSuite": {
46+
"type": "array",
47+
"items": {
48+
"$ref": "#/definitions/SuiteInstruction"
49+
}
50+
},
51+
"defaultSuiteFile": {
52+
"type": "string"
53+
}
54+
},
55+
"required": ["dataExtensions", "extensionTargets", "name", "version"]
56+
},
57+
"SuiteInstruction": {
58+
"type": "object",
59+
"properties": {
60+
"qlpack": {
61+
"type": "string"
62+
},
63+
"query": {
64+
"type": "string"
65+
},
66+
"queries": {
67+
"type": "string"
68+
},
69+
"include": {
70+
"type": "object",
71+
"additionalProperties": {
72+
"type": "array",
73+
"items": {
74+
"type": "string"
75+
}
76+
}
77+
},
78+
"exclude": {
79+
"type": "object",
80+
"additionalProperties": {
81+
"type": "array",
82+
"items": {
83+
"type": "string"
84+
}
85+
}
86+
},
87+
"description": {
88+
"type": "string"
89+
},
90+
"from": {
91+
"type": "string"
92+
}
93+
},
94+
"description": "A single entry in a .qls file."
95+
}
96+
}
97+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { QlPackFile } from "../packaging/qlpack-file";
2+
3+
export type ExtensionPackMetadata = QlPackFile & {
4+
// Make both extensionTargets and dataExtensions required
5+
extensionTargets: Record<string, string>;
6+
dataExtensions: string[] | string;
7+
};

extensions/ql-vscode/src/model-editor/extension-pack-picker.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { join } from "path";
22
import { outputFile, pathExists, readFile } from "fs-extra";
33
import { dump as dumpYaml, load as loadYaml } from "js-yaml";
44
import { Uri } from "vscode";
5+
import Ajv from "ajv";
56
import { CodeQLCliServer } from "../codeql-cli/cli";
67
import { getOnDiskWorkspaceFolders } from "../common/vscode/workspace-folders";
78
import { ProgressCallback } from "../common/vscode/progress";
@@ -18,6 +19,12 @@ import {
1819
} from "./extension-pack-name";
1920
import { autoPickExtensionsDirectory } from "./extensions-workspace-folder";
2021

22+
import { ExtensionPackMetadata } from "./extension-pack-metadata";
23+
import * as extensionPackMetadataSchemaJson from "./extension-pack-metadata.schema.json";
24+
25+
const ajv = new Ajv({ allErrors: true });
26+
const extensionPackValidate = ajv.compile(extensionPackMetadataSchemaJson);
27+
2128
export async function pickExtensionPack(
2229
cliServer: Pick<CodeQLCliServer, "resolveQlpacks">,
2330
databaseItem: Pick<DatabaseItem, "name" | "language">,
@@ -170,6 +177,22 @@ async function writeExtensionPack(
170177
return extensionPack;
171178
}
172179

180+
function validateExtensionPack(
181+
extensionPack: unknown,
182+
): extensionPack is ExtensionPackMetadata {
183+
extensionPackValidate(extensionPack);
184+
185+
if (extensionPackValidate.errors) {
186+
throw new Error(
187+
`Invalid extension pack YAML: ${extensionPackValidate.errors
188+
.map((error) => `${error.instancePath} ${error.message}`)
189+
.join(", ")}`,
190+
);
191+
}
192+
193+
return true;
194+
}
195+
173196
async function readExtensionPack(
174197
path: string,
175198
language: string,
@@ -188,6 +211,10 @@ async function readExtensionPack(
188211
throw new Error(`Could not parse ${qlpackPath}`);
189212
}
190213

214+
if (!validateExtensionPack(qlpack)) {
215+
throw new Error(`Could not validate ${qlpackPath}`);
216+
}
217+
191218
const dataExtensionValue = qlpack.dataExtensions;
192219
if (
193220
!(

0 commit comments

Comments
 (0)