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

Adds ability to install a missing bsc version #583

Merged
merged 31 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
26ec6f7
Adds ability to install a missing bsc version
TwitchBronBron Jul 30, 2024
190ea99
Merge branch 'master' into enhanced-bsc-picker
TwitchBronBron Jul 30, 2024
4bd3d8d
Fix broken test
TwitchBronBron Jul 30, 2024
83eeef0
Add support for loading lsp from npm or url
TwitchBronBron Jul 30, 2024
24ef473
Proper url hashing
TwitchBronBron Aug 6, 2024
7bb3902
Add command to clear local npm cache
TwitchBronBron Aug 20, 2024
8c6600f
Add language server menu option for clearing cached packages
TwitchBronBron Aug 20, 2024
43fa9da
Delete bsc versions after 45 days of inactivity
TwitchBronBron Sep 11, 2024
13b6abf
Add command to view packages dir in explorer
TwitchBronBron Sep 11, 2024
45cf3f2
Prevent installing same bsc dependency multiple times
TwitchBronBron Sep 16, 2024
fb8c811
Merge branch 'master' into enhanced-bsc-picker
TwitchBronBron Sep 16, 2024
25f240d
Better messaging around removing cached brighterscript versions
TwitchBronBron Sep 16, 2024
87a9228
Fix bug keeping test process alive for too long
TwitchBronBron Sep 16, 2024
97c7dd3
Add `LocalPackageManager` class, not finished yet
TwitchBronBron Sep 18, 2024
a26f523
Add ability to delete all of a given package
TwitchBronBron Sep 18, 2024
9409054
Add ability to remove a specific package.
TwitchBronBron Sep 18, 2024
0aeed72
Fix coverage issues
TwitchBronBron Sep 18, 2024
998f953
Update LanguageServermanager to use localPackageManager
TwitchBronBron Sep 18, 2024
a409812
Tweak comment
TwitchBronBron Sep 18, 2024
277d21c
Better internal package object handling
TwitchBronBron Sep 19, 2024
91fc994
Add live npm install test
TwitchBronBron Sep 19, 2024
4147d31
support for non-semver versions
TwitchBronBron Sep 19, 2024
1f0f921
Refactored LanguageServerManager to better handle bsc version
TwitchBronBron Sep 19, 2024
0b0c12c
Add unit tests for parseVersionInfo and getVersionDirName
TwitchBronBron Sep 20, 2024
bca7a87
Fix some broken tests
TwitchBronBron Sep 20, 2024
c7bf7e5
Handle loading bsc version using version number
TwitchBronBron Sep 20, 2024
758c2a8
Split mainline releases and prereleases
TwitchBronBron Sep 20, 2024
b037ce0
Merge branch 'master' into enhanced-bsc-picker
TwitchBronBron Sep 23, 2024
112a5d1
Merge branch 'master' into enhanced-bsc-picker
TwitchBronBron Sep 23, 2024
524489b
Fixed json parse issue when fetching npm package versions
TwitchBronBron Sep 23, 2024
43e015f
Fix lint issue
TwitchBronBron Sep 23, 2024
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
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"--timeout",
"0"
"987654"
],
"internalConsoleOptions": "openOnSessionStart"
}
Expand Down Expand Up @@ -104,4 +104,4 @@
]
}
]
}
}
56 changes: 48 additions & 8 deletions package-lock.json

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

11 changes: 9 additions & 2 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 Expand Up @@ -98,7 +99,7 @@
"@types/fs-extra": "^5.0.4",
"@types/glob": "^7.1.1",
"@types/mocha": "^7.0.2",
"@types/node": "^12.12.0",
"@types/node": "^20.14.10",
"@types/node-ssdp": "^3.3.0",
"@types/prompt": "^1.1.2",
"@types/resolve": "^1.20.6",
Expand All @@ -114,7 +115,7 @@
"chalk": "^4.1.2",
"changelog-parser": "^2.8.0",
"coveralls-next": "^4.2.0",
"dayjs": "^1.11.7",
"dayjs": "^1.11.12",
"deferred": "^0.7.11",
"eslint": "^8.10.0",
"eslint-plugin-github": "^4.3.5",
Expand Down Expand Up @@ -3084,6 +3085,12 @@
"title": "Open SceneGraph Inspector In New Window",
"category": "BrighterScript",
"icon": "$(link-external)"
},
{
"command": "extension.brightscript.clearNpmPackageCache",
"title": "Clear the extension's local node_modules cache",
"category": "BrighterScript",
"icon": "$(link-external)"
Comment on lines +3099 to +3102
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chrisdp what do you think about this command name and the message?

}
],
"keybindings": [
Expand Down
4 changes: 2 additions & 2 deletions src/ActiveDeviceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ class RokuFinder extends EventEmitter {
}

private readonly client: Client;
private intervalId: NodeJS.Timer | null = null;
private timeoutId: NodeJS.Timer | null = null;
private intervalId: NodeJS.Timeout | null = null;
private timeoutId: NodeJS.Timeout | null = null;
private running = false;

public start(timeout: number) {
Expand Down
2 changes: 1 addition & 1 deletion src/BrightScriptCommands.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('BrightScriptFileUtils ', () => {
let languagesMock;

beforeEach(() => {
commands = new BrightScriptCommands({} as any, {} as any, {} as any, {} as any, {} as any);
commands = new BrightScriptCommands({} as any, {} as any, {} as any, {} as any, {} as any, {} as any);
commandsMock = sinon.mock(commands);
languagesMock = sinon.mock(vscode.languages);
});
Expand Down
6 changes: 5 additions & 1 deletion src/BrightScriptCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import type { ActiveDeviceManager } from './ActiveDeviceManager';
import * as xml2js from 'xml2js';
import { firstBy } from 'thenby';
import type { UserInputManager } from './managers/UserInputManager';
import { clearNpmPackageCacheCommand } from './commands/ClearNpmPackageCacheCommand';
import type { LanguageServerManager } from './LanguageServerManager';

export class BrightScriptCommands {

Expand All @@ -22,7 +24,8 @@ export class BrightScriptCommands {
private whatsNewManager: WhatsNewManager,
private context: vscode.ExtensionContext,
private activeDeviceManager: ActiveDeviceManager,
private userInputManager: UserInputManager
private userInputManager: UserInputManager,
private languageServerManager: LanguageServerManager
) {
this.fileUtils = new BrightScriptFileUtils();
}
Expand All @@ -39,6 +42,7 @@ export class BrightScriptCommands {
languageServerInfoCommand.register(this.context);
captureScreenshotCommand.register(this.context, this);
rekeyAndPackageCommand.register(this.context, this, this.userInputManager);
clearNpmPackageCacheCommand.register(this.context, this.languageServerManager);

this.registerGeneralCommands();

Expand Down
88 changes: 87 additions & 1 deletion src/LanguageServerManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
LanguageClient,
State
} from 'vscode-languageclient/node';
import * as childProcess from 'child_process';
const Module = require('module');
const sinon = createSandbox();

Expand All @@ -33,6 +34,8 @@ Module.prototype.require = function hijacked(file) {
const tempDir = s`${process.cwd()}/.tmp`;

describe('LanguageServerManager', () => {
const storageDir = s`${tempDir}/brighterscript-storage`;

let languageServerManager: LanguageServerManager;

beforeEach(() => {
Expand All @@ -48,6 +51,10 @@ describe('LanguageServerManager', () => {
update: () => { }
}
} as unknown as ExtensionContext;

fsExtra.removeSync(storageDir);
(languageServerManager['context'] as any).globalStorageUri = URI.file(storageDir);

});

function stubConstructClient(processor?: (LanguageClient) => void) {
Expand All @@ -64,7 +71,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 @@ -323,4 +333,80 @@ describe('LanguageServerManager', () => {
expect(bsdkPath).to.eql(null);
});
});

describe('ensureBscVersionInstalled', function() {
//these tests take a long time (due to running `npm install`)
this.timeout(20_000);

it('installs a bsc version when not present', async () => {
expect(
await languageServerManager['ensureBscVersionInstalled']('0.65.0')
).to.eql(s`${storageDir}/packages/brighterscript-0.65.0/node_modules/brighterscript`);
expect(
fsExtra.pathExistsSync(s`${storageDir}/packages/brighterscript-0.65.0/node_modules/brighterscript`)
).to.be.true;
});

it('reuses the same bsc version when already exists', async () => {
let spy = sinon.spy(childProcess, 'exec');
fsExtra.ensureDirSync(
s`${storageDir}/packages/brighterscript-0.65.0/node_modules/brighterscript/dist/index.js`
);
expect(
await languageServerManager['ensureBscVersionInstalled']('0.65.0')
).to.eql(s`${storageDir}/packages/brighterscript-0.65.0/node_modules/brighterscript`);
expect(
fsExtra.pathExistsSync(s`${storageDir}/packages/brighterscript-0.65.0/node_modules/brighterscript`)
).to.be.true;
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(
s`${storageDir}/packages/brighterscript-0.65.1/node_modules/brighterscript`
);
fsExtra.writeFileSync(
s`${storageDir}/packages/brighterscript-0.65.1/node_modules/brighterscript/package.json`,
'bad json'
);

expect(
await languageServerManager['ensureBscVersionInstalled']('0.65.1')
).to.eql(s`${storageDir}/packages/brighterscript-0.65.1/node_modules/brighterscript`);
expect(
fsExtra.pathExistsSync(s`${storageDir}/packages/brighterscript-0.65.1/node_modules/brighterscript`)
).to.be.true;

//make sure we deleted the bad folder
expect(
s`${stub.getCalls()[0].args[0]}`
).to.eql(s`${storageDir}/packages/brighterscript-0.65.1`);
});
});

describe('clearNpmPackageCache', () => {
it('clears the cache', async () => {
fsExtra.ensureFileSync(`${storageDir}/packages/test.txt`);
expect(fsExtra.pathExistsSync(`${storageDir}/packages/test.txt`)).to.be.true;

await languageServerManager.clearNpmPackageCache();

expect(fsExtra.pathExistsSync(`${storageDir}/packages/test.txt`)).to.be.false;
});
});
});
Loading
Loading