Skip to content

Commit

Permalink
Proper url hashing
Browse files Browse the repository at this point in the history
  • Loading branch information
TwitchBronBron committed Aug 6, 2024
1 parent 83eeef0 commit 24ef473
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 3 deletions.
32 changes: 32 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"iconv-lite": "0.4.24",
"jszip": "^3.10.1",
"just-throttle": "^4.0.1",
"md5": "^2.3.0",
"net": "^1.0.2",
"node-cache": "^4.2.0",
"node-ssdp": "^4.0.0",
Expand Down
19 changes: 18 additions & 1 deletion src/LanguageServerManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ describe('LanguageServerManager', () => {
});
}

afterEach(() => {
afterEach(function() {
//deleting certain directories take a while
this.timeout(30_000);

sinon.restore();
fsExtra.removeSync(tempDir);
});
Expand Down Expand Up @@ -358,6 +361,20 @@ describe('LanguageServerManager', () => {
expect(spy.called).to.be.false;
});

it('installs from url', async () => {
fsExtra.ensureDirSync(
s`${storageDir}/packages/brighterscript-0.65.0/node_modules/brighterscript/dist/index.js`
);
expect(
await languageServerManager['ensureBscVersionInstalled'](
'https://github.com/rokucommunity/brighterscript/releases/download/v0.0.0-packages/brighterscript-0.67.5-lsp-refactor.20240806164122.tgz'
)
).to.eql(s`${storageDir}/packages/brighterscript-028738851c072bf844c10c260d6d2c65/node_modules/brighterscript`);
expect(
fsExtra.pathExistsSync(s`${storageDir}/packages/brighterscript-028738851c072bf844c10c260d6d2c65/node_modules/brighterscript`)
).to.be.true;
});

it('repairs a broken bsc version', async () => {
let stub = sinon.stub(fsExtra, 'remove');
fsExtra.ensureDirSync(
Expand Down
4 changes: 3 additions & 1 deletion src/LanguageServerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import * as fsExtra from 'fs-extra';
import { EventEmitter } from 'eventemitter3';
import * as childProcess from 'child_process';
import * as semver from 'semver';
import * as md5 from 'md5';

/**
* Tracks the running/stopped state of the language server. When the lsp crashes, vscode will restart it. After the 5th crash, they'll leave it permanently crashed.
Expand Down Expand Up @@ -482,7 +483,8 @@ export class LanguageServerManager {
let packageJsonEntry: string;
//if this is a URL
if (/^(http|https):\/\//.test(bsdkEntry)) {
folderName = `brighterscript-${btoa(bsdkEntry.trim())}`.substring(0, 30);
//hash the URL to create a unique folder name. There is next to zero possibility these will clash, so the hash should be fine.
folderName = `brighterscript-${md5(bsdkEntry.trim())}`;
packageJsonEntry = bsdkEntry.trim();

//this is a valid semantic version
Expand Down
3 changes: 2 additions & 1 deletion src/commands/LanguageServerInfoCommand.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ describe('LanguageServerInfoCommand', () => {
fsExtra.removeSync(tempDir);
});

describe('getBscVersionsFromNpm', () => {
describe('getBscVersionsFromNpm', function() {
this.timeout(20_000);
it('returns a list of versions', async () => {
const results = await command['getBscVersionsFromNpm']();
// `results` is entire list of all bsc versions, live from npm. so we obviously can't make a test that ensure they're all correct.
Expand Down

0 comments on commit 24ef473

Please sign in to comment.