Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SLVSCODE-953 untar eslint-bridge bundle and send its path to slls #659

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ its/extdir*
.DS_Store
omnisharp
.vs
eslint-bridge
39 changes: 39 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,8 @@
"typescript": "^4.9.5",
"vinyl": "^2.2.1",
"webpack": "^5.94.0",
"webpack-cli": "4.10.0"
"webpack-cli": "4.10.0",
"unzipper": "^0.12.3"
},
"prettier": {
"jsxBracketSameLine": true,
Expand Down
4 changes: 2 additions & 2 deletions scripts/dependencies.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"groupId": "org.sonarsource.sonarlint.ls",
"artifactId": "sonarlint-language-server",
"version": "3.13.2.75741",
"version": "3.14.0.75743",
"output": "server/sonarlint-ls.jar"
},
{
Expand All @@ -14,7 +14,7 @@
{
"groupId": "org.sonarsource.javascript",
"artifactId": "sonar-javascript-plugin",
"version": "10.18.0.28572",
"version": "10.19.0.29100",
"output": "analyzers/sonarjs.jar"
},
{
Expand Down
65 changes: 62 additions & 3 deletions scripts/prepare.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@
'use strict';
import { exec } from 'child_process';
import { createHash } from 'crypto';
import { createReadStream, createWriteStream, existsSync, mkdirSync, readFileSync } from 'fs';
import { createReadStream, createWriteStream, existsSync, mkdirSync, readFileSync, unlinkSync } from 'fs';
import { dirname, join, resolve } from 'path';
import * as unzipper from 'unzipper';
import { extract } from 'tar';
import { createGunzip } from 'node:zlib';

import { promisify } from 'util';

import artifactory from '../build-sonarlint/artifactory.mjs';

const execAsync = promisify(exec);
const ESLINT_BRIDGE_SERVER_BUNDLE_PATH_MATCHER = /sonarjs-\d+\.\d+\.\d+\.tgz/;

const jarDependencies = JSON.parse(readFileSync(resolve(dirname(''), 'scripts/dependencies.json')));

Expand Down Expand Up @@ -92,7 +96,12 @@ function downloadIfNeeded(url, dest) {
async function downloadIfChecksumMismatch(expectedChecksum, url, dest) {
if (!existsSync(dest)) {
(await sendRequest(url))
.pipe(createWriteStream(dest));
.pipe(createWriteStream(dest)
.on('finish', async () => {
if (dest.endsWith('sonarjs.jar')) {
unzipEslintBridgeBundle(dest);
}
}));
} else {
createReadStream(dest)
.pipe(createHash('sha1').setEncoding('hex'))
Expand All @@ -101,7 +110,12 @@ async function downloadIfChecksumMismatch(expectedChecksum, url, dest) {
if (expectedChecksum !== sha1) {
console.info(`Checksum mismatch for '${dest}'. Will download it!`);
(await sendRequest(url))
.pipe(createWriteStream(dest));
.pipe(createWriteStream(dest)
.on('finish', async () => {
if (dest.endsWith('sonarjs.jar')) {
unzipEslintBridgeBundle(dest);
}
}));
}
});
}
Expand Down Expand Up @@ -131,3 +145,48 @@ function sendRequest(url) {
});
}
}

async function unzipEslintBridgeBundle(jarPath) {
const directory = await unzipper.Open.file(jarPath);

const file = directory.files.find(d => ESLINT_BRIDGE_SERVER_BUNDLE_PATH_MATCHER.test(d.path));
if (!file) {
throw new Error(`eslint bridge server bundle not found in JAR ${jarPath}`);
}

const outputFolderPath = join('.', 'eslint-bridge');
const outputFilePath = join('.', 'eslint-bridge', 'sonarjs.tgz');
if (!existsSync(outputFolderPath)) {
mkdirSync(outputFolderPath);
}

file.stream().pipe(createWriteStream(outputFilePath))
.on('finish', async () => {
const compressedReadStream = createReadStream(join('.', outputFilePath));
const decompressionStream = createGunzip();
const extractionStream = extract({
cwd: outputFolderPath // Set the current working directory for extraction
});
compressedReadStream.pipe(decompressionStream).pipe(extractionStream);

await new Promise((resolve, reject) => {
extractionStream.on('finish', () => {
resolve();
});
compressedReadStream.on('error', err => {
console.log(err);
reject(err);
});
decompressionStream.on('error', err => {
console.error(err);
reject(err);
});
extractionStream.on('error', err => {
console.error(err);
reject(err);
});
});

unlinkSync(outputFilePath)
});
}
1 change: 1 addition & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ export async function activate(context: VSCode.ExtensionContext) {
omnisharpDirectory: Path.resolve(context.extensionPath, 'omnisharp'),
csharpOssPath: Path.resolve(context.extensionPath, 'analyzers', 'sonarcsharp.jar'),
csharpEnterprisePath: Path.resolve(context.extensionPath, 'analyzers', 'csharpenterprise.jar'),
eslintBridgeServerPath: Path.resolve(context.extensionPath, 'eslint-bridge')
sophio-japharidze-sonarsource marked this conversation as resolved.
Show resolved Hide resolved
},
enableNotebooks: true,
clientNodePath: VSCode.workspace.getConfiguration().get('sonarlint.pathToNodeExecutable'),
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"node_modules",
".vscode-test",
"its",
"dogfood"
"dogfood",
"eslint-bridge"
]
}
Loading