Skip to content

Commit 4e4d8b2

Browse files
committed
Fix js-yaml issues
With js-yaml 4.0, safeLoad is no longer available. Use load instead.
1 parent c32b536 commit 4e4d8b2

12 files changed

Lines changed: 23 additions & 23 deletions

File tree

extensions/ql-vscode/gulpfile.ts/textmate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,14 @@ function transformFile(yaml: any) {
219219
}
220220

221221
export function transpileTextMateGrammar() {
222-
return through.obj((file: Vinyl, _encoding: string, callback: Function): void => {
222+
return through.obj((file: Vinyl, _encoding: string, callback: (err: string | null, file: Vinyl | PluginError) => void): void => {
223223
if (file.isNull()) {
224224
callback(null, file);
225225
}
226226
else if (file.isBuffer()) {
227227
const buf: Buffer = file.contents;
228228
const yamlText: string = buf.toString('utf8');
229-
const jsonData: any = jsYaml.safeLoad(yamlText);
229+
const jsonData: any = jsYaml.load(yamlText);
230230
transformFile(jsonData);
231231

232232
file.contents = Buffer.from(JSON.stringify(jsonData, null, 2), 'utf8');

extensions/ql-vscode/src/contextual/queryResolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ async function resolveQueriesFromPacks(cli: CodeQLCliServer, qlpacks: string[],
4545
}
4646
});
4747
}
48-
await fs.writeFile(suiteFile, yaml.safeDump(suiteYaml), 'utf8');
48+
await fs.writeFile(suiteFile, yaml.dump(suiteYaml), 'utf8');
4949

5050
const queries = await cli.resolveQueriesInSuite(suiteFile, helpers.getOnDiskWorkspaceFolders());
5151
return queries;

extensions/ql-vscode/src/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ interface QlPackWithPath {
289289
async function findDbschemePack(packs: QlPackWithPath[], dbschemePath: string): Promise<{ name: string; isLibraryPack: boolean; }> {
290290
for (const { packDir, packName } of packs) {
291291
if (packDir !== undefined) {
292-
const qlpack = yaml.safeLoad(await fs.readFile(path.join(packDir, 'qlpack.yml'), 'utf8')) as { dbscheme?: string; library?: boolean; };
292+
const qlpack = yaml.load(await fs.readFile(path.join(packDir, 'qlpack.yml'), 'utf8')) as { dbscheme?: string; library?: boolean; };
293293
if (qlpack.dbscheme !== undefined && path.basename(qlpack.dbscheme) === path.basename(dbschemePath)) {
294294
return {
295295
name: packName,

extensions/ql-vscode/src/quick-query.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export async function displayQuickQuery(
123123
version: '1.0.0',
124124
libraryPathDependencies: [qlpack]
125125
};
126-
await fs.writeFile(qlPackFile, QLPACK_FILE_HEADER + yaml.safeDump(quickQueryQlpackYaml), 'utf8');
126+
await fs.writeFile(qlPackFile, QLPACK_FILE_HEADER + yaml.dump(quickQueryQlpackYaml), 'utf8');
127127
}
128128

129129
if (shouldRewrite || !(await fs.pathExists(qlFile))) {
@@ -144,6 +144,6 @@ async function checkShouldRewrite(qlPackFile: string, newDependency: string) {
144144
if (!(await fs.pathExists(qlPackFile))) {
145145
return true;
146146
}
147-
const qlPackContents: any = yaml.safeLoad(await fs.readFile(qlPackFile, 'utf8'));
147+
const qlPackContents: any = yaml.load(await fs.readFile(qlPackFile, 'utf8'));
148148
return qlPackContents.libraryPathDependencies?.[0] !== newDependency;
149149
}

extensions/ql-vscode/src/remote-queries/run-remote-query.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ async function generateQueryPack(cliServer: cli.CodeQLCliServer, queryFile: stri
110110
[`codeql/${language}-all`]: '*',
111111
}
112112
};
113-
await fs.writeFile(path.join(queryPackDir, 'qlpack.yml'), yaml.safeDump(syntheticQueryPack));
113+
await fs.writeFile(path.join(queryPackDir, 'qlpack.yml'), yaml.dump(syntheticQueryPack));
114114
}
115115
if (!language) {
116116
throw new UserCancellationException('Could not determine language.');
@@ -378,7 +378,7 @@ export function parseResponse(owner: string, repo: string, response: QueriesResp
378378
*/
379379
async function ensureNameAndSuite(queryPackDir: string, packRelativePath: string): Promise<void> {
380380
const packPath = path.join(queryPackDir, 'qlpack.yml');
381-
const qlpack = yaml.safeLoad(await fs.readFile(packPath, 'utf8')) as QlPack;
381+
const qlpack = yaml.load(await fs.readFile(packPath, 'utf8')) as QlPack;
382382
delete qlpack.defaultSuiteFile;
383383

384384
qlpack.name = QUERY_PACK_NAME;
@@ -388,7 +388,7 @@ async function ensureNameAndSuite(queryPackDir: string, packRelativePath: string
388388
}, {
389389
query: packRelativePath.replace(/\\/g, '/')
390390
}];
391-
await fs.writeFile(packPath, yaml.safeDump(qlpack));
391+
await fs.writeFile(packPath, yaml.dump(qlpack));
392392
}
393393

394394
async function buildRemoteQueryEntity(

extensions/ql-vscode/src/vscode-tests/cli-integration/queries.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,15 @@ describe('Queries', function() {
149149
expect(fs.pathExistsSync(qlFile)).to.be.true;
150150
expect(fs.pathExistsSync(qlpackFile)).to.be.true;
151151

152-
const qlpackContents: any = await yaml.safeLoad(
152+
const qlpackContents: any = await yaml.load(
153153
fs.readFileSync(qlpackFile, 'utf8')
154154
);
155155
// Should have chosen the js libraries
156156
expect(qlpackContents.libraryPathDependencies[0]).to.include('javascript');
157157
});
158158

159159
it('should avoid creating a quick query', async () => {
160-
fs.writeFileSync(qlpackFile, yaml.safeDump({
160+
fs.writeFileSync(qlpackFile, yaml.dump({
161161
name: 'quick-query',
162162
version: '1.0.0',
163163
libraryPathDependencies: ['codeql-javascript']

extensions/ql-vscode/src/vscode-tests/cli-integration/remote-queries/run-remote-query.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ describe('Remote queries', function() {
102102
expect(fs.existsSync(path.join(compiledPackDir, 'lib.qll'))).to.be.true;
103103
expect(fs.existsSync(path.join(compiledPackDir, 'qlpack.yml'))).to.be.true;
104104
// should have generated a correct qlpack file
105-
const qlpackContents: any = yaml.safeLoad(fs.readFileSync(path.join(compiledPackDir, 'qlpack.yml'), 'utf8'));
105+
const qlpackContents: any = yaml.load(fs.readFileSync(path.join(compiledPackDir, 'qlpack.yml'), 'utf8'));
106106
expect(qlpackContents.name).to.equal('codeql-remote/query');
107107

108108
// depending on the cli version, we should have one of these files
@@ -168,7 +168,7 @@ describe('Remote queries', function() {
168168
expect(fs.existsSync(path.join(compiledPackDir, 'lib.qll'))).to.be.false;
169169
expect(fs.existsSync(path.join(compiledPackDir, 'not-in-pack.ql'))).to.be.false;
170170
// should have generated a correct qlpack file
171-
const qlpackContents: any = yaml.safeLoad(fs.readFileSync(path.join(compiledPackDir, 'qlpack.yml'), 'utf8'));
171+
const qlpackContents: any = yaml.load(fs.readFileSync(path.join(compiledPackDir, 'qlpack.yml'), 'utf8'));
172172
expect(qlpackContents.name).to.equal('codeql-remote/query');
173173
expect(qlpackContents.version).to.equal('0.0.0');
174174
expect(qlpackContents.dependencies?.['codeql/javascript-all']).to.equal('*');
@@ -228,7 +228,7 @@ describe('Remote queries', function() {
228228
).to.be.true;
229229
expect(fs.existsSync(path.join(compiledPackDir, 'not-in-pack.ql'))).to.be.false;
230230
// should have generated a correct qlpack file
231-
const qlpackContents: any = yaml.safeLoad(fs.readFileSync(path.join(compiledPackDir, 'qlpack.yml'), 'utf8'));
231+
const qlpackContents: any = yaml.load(fs.readFileSync(path.join(compiledPackDir, 'qlpack.yml'), 'utf8'));
232232
expect(qlpackContents.name).to.equal('codeql-remote/query');
233233
expect(qlpackContents.version).to.equal('0.0.0');
234234
expect(qlpackContents.dependencies?.['codeql/javascript-all']).to.equal('*');
@@ -260,7 +260,7 @@ describe('Remote queries', function() {
260260
});
261261

262262
function verifyQlPack(qlpackPath: string, queryPath: string, packVersion: string, pathSerializationBroken: boolean) {
263-
const qlPack = yaml.safeLoad(fs.readFileSync(qlpackPath, 'utf8')) as QlPack;
263+
const qlPack = yaml.load(fs.readFileSync(qlpackPath, 'utf8')) as QlPack;
264264

265265
if (pathSerializationBroken) {
266266
// the path serialization is broken, so we force it to be the path in the pack to be same as the query path

extensions/ql-vscode/src/vscode-tests/no-workspace/astViewer.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ describe('AstViewer', () => {
131131
}
132132

133133
async function buildAst() {
134-
const astRoots = yaml.safeLoad(await fs.readFile(`${__dirname}/data/astViewer.yml`, 'utf8')) as AstItem[];
134+
const astRoots = yaml.load(await fs.readFile(`${__dirname}/data/astViewer.yml`, 'utf8')) as AstItem[];
135135

136136
// convert range properties into vscode.Range instances
137137
function convertToRangeInstances(obj: any) {

extensions/ql-vscode/src/vscode-tests/no-workspace/contextual/queryResolver.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('queryResolver', () => {
2929
const result = await module.resolveQueries(mockCli, { dbschemePack: 'my-qlpack' }, KeyType.DefinitionQuery);
3030
expect(result).to.deep.equal(['a', 'b']);
3131
expect(writeFileSpy.getCall(0).args[0]).to.match(/.qls$/);
32-
expect(yaml.safeLoad(writeFileSpy.getCall(0).args[1])).to.deep.equal([{
32+
expect(yaml.load(writeFileSpy.getCall(0).args[1])).to.deep.equal([{
3333
from: 'my-qlpack',
3434
queries: '.',
3535
include: {
@@ -46,7 +46,7 @@ describe('queryResolver', () => {
4646
const result = await module.resolveQueries(mockCli, { dbschemePackIsLibraryPack: true, dbschemePack: 'my-qlpack', queryPack: 'my-qlpack2' }, KeyType.DefinitionQuery);
4747
expect(result).to.deep.equal(['a', 'b']);
4848
expect(writeFileSpy.getCall(0).args[0]).to.match(/.qls$/);
49-
expect(yaml.safeLoad(writeFileSpy.getCall(0).args[1])).to.deep.equal([{
49+
expect(yaml.load(writeFileSpy.getCall(0).args[1])).to.deep.equal([{
5050
from: 'my-qlpack2',
5151
queries: '.',
5252
include: {

0 commit comments

Comments
 (0)