Skip to content

Commit c6ba151

Browse files
Bundle extension (#1)
Introduces bundling to improve extension load time and bundle size. We now build two files from all dependencies: `extension.js`, containing the main body of the extension, and `proxy.js`, which houses the proxy language server. This results in a reduction in package size from 20MB to 1MB, and we ship only 13 files as opposed to roughly 3300 before this PR. Due to quirks of esbuild and TypeScript, modules need to parse as "isolated" modules, meaning the global `types.ts` modules in use across the extension were no longer legal. These have been refactored to export their aliases and their uses are now explicitly imported.
1 parent c882d8c commit c6ba151

21 files changed

+533
-17
lines changed

.vscodeignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ eslint.config.mjs
1010
CONTRIBUTING.md
1111
.prettierrc
1212
.vscode-test.mjs
13+
**/*.ts
14+
node_modules/**
15+
tsconfig.json
16+
esbuild.js

esbuild.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import esbuild from 'esbuild';
2+
3+
await esbuild.build({
4+
entryPoints: ['extension/extension.ts'],
5+
bundle: true,
6+
outfile: 'out/extension.js',
7+
platform: 'node',
8+
external: ['vscode'],
9+
});
10+
11+
await esbuild.build({
12+
entryPoints: ['lsp-proxy/src/proxy.ts'],
13+
bundle: true,
14+
outfile: 'out/proxy.js',
15+
platform: 'node',
16+
external: ['vscode'],
17+
});

extension/commands/run.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import * as config from '../utils/config';
1212
import { MAXSDK } from '../sdk/sdk';
1313
import { MAXSDKManager } from '../sdk/sdkManager';
1414
import { MojoDebugConfiguration } from '../debug/debug';
15-
import * as md5 from 'md5';
15+
import md5 from 'md5';
16+
import { Optional } from '../types';
1617

1718
type FileArgs = {
1819
runArgs: string[];

extension/debug/attachQuickPick.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import * as vscode from 'vscode';
88

99
import { ProcessDescriptor, psList } from '../external/psList';
10+
import { Optional } from '../types';
1011

1112
class RefreshButton implements vscode.QuickInputButton {
1213
get iconPath(): vscode.ThemeIcon {

extension/debug/debug.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { MAXSDKManager } from '../sdk/sdkManager';
1717
import { quote } from 'shell-quote';
1818
import * as util from 'util';
1919
import { execFile as execFileBase } from 'child_process';
20+
import { Optional } from '../types';
2021
const execFile = util.promisify(execFileBase);
2122

2223
/**

extension/debug/inlineVariables.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ import { MojoExtension } from '../extension';
1010
import { DisposableContext } from '../utils/disposableContext';
1111

1212
import { DEBUG_TYPE } from './constants';
13+
import { Optional } from '../types';
14+
import {
15+
VariableEvaluateName,
16+
Variable,
17+
FrameId,
18+
RequestId,
19+
DAPScopesRequest,
20+
DAPVariablesRequest,
21+
DAPVariablesResponse,
22+
SessionId,
23+
} from './types';
1324

1425
/**
1526
* Variables grouped by evaluate name. Multiple entries per key represent

extension/debug/types.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
//
55
//===----------------------------------------------------------------------===//
66

7-
type FrameId = number;
8-
type RequestId = number;
9-
type SessionId = string;
7+
export type FrameId = number;
8+
export type RequestId = number;
9+
export type SessionId = string;
1010
/**
1111
* This is a display name generated by LLDB that attempts to be unique.
1212
*/
13-
type VariableDisplayName = string;
13+
export type VariableDisplayName = string;
1414
/**
1515
* This name is an LLDB variable path that could collide in case of shadowing.
1616
*/
17-
type VariableEvaluateName = string;
17+
export type VariableEvaluateName = string;
1818

19-
type Variable = {
19+
export type Variable = {
2020
name: VariableDisplayName;
2121
evaluateName: VariableEvaluateName;
2222
value: string;
@@ -44,19 +44,19 @@ type Variable = {
4444
};
4545
};
4646

47-
type DAPScopesRequest = {
47+
export type DAPScopesRequest = {
4848
command: 'scopes';
4949
seq: RequestId;
5050
arguments: { frameId: FrameId };
5151
};
5252

53-
type DAPVariablesRequest = {
53+
export type DAPVariablesRequest = {
5454
command: 'variables';
5555
seq: RequestId;
5656
arguments: { variablesReference: number };
5757
};
5858

59-
type DAPVariablesResponse = {
59+
export type DAPVariablesResponse = {
6060
command: 'variables';
6161
request_seq: RequestId;
6262
body: { variables: Variable[] };

extension/lsp/lsp.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { Logger } from '../logging';
1717
import { MAXSDKManager } from '../sdk/sdkManager';
1818
import { TelemetryReporter } from '../telemetry';
1919
import { LSPRecorder } from './recorder';
20+
import { Optional } from '../types';
2021

2122
/**
2223
* This type represents the initialization options send by the extension to the
@@ -252,7 +253,7 @@ export class MojoLSPManager extends DisposableContext {
252253
};
253254

254255
const module = this.extensionContext.asAbsolutePath(
255-
path.join('lsp-proxy', 'out', 'proxy.js'),
256+
path.join('out', 'proxy.js'),
256257
);
257258
const serverOptions: vscodelc.ServerOptions = {
258259
run: { module, transport: TransportKind.ipc },

extension/sdk/magicSdk.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { Logger } from '../logging';
1616
import { execFile } from 'child_process';
1717
const execFileSync = util.promisify(execFile);
1818
import { MAXSDKVersion as MaxSDKVersion } from './sdkVersion';
19+
import { Optional } from '../types';
1920

2021
const SDK_INSTALLATION_CANCELLATION_MSG = 'SDK installation cancelled';
2122
type MagicInstallationResult = 'succeeded' | 'failed' | 'cancelled';

extension/sdk/sdkConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Logger } from '../logging';
88
import { MAXSDKVersion } from './sdkVersion';
99
import * as util from 'util';
1010
import { execFile as execFileBase } from 'child_process';
11+
import { Optional } from '../types';
1112
const execFile = util.promisify(execFileBase);
1213

1314
/**

0 commit comments

Comments
 (0)