Skip to content

Commit

Permalink
Ditch esbuild
Browse files Browse the repository at this point in the history
evanw/esbuild#253

Webpack is slow, but it seems to be full-featured.
  • Loading branch information
petervdonovan committed May 22, 2024
1 parent 9f7e318 commit 3cb4710
Show file tree
Hide file tree
Showing 12 changed files with 1,990 additions and 650 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ out/*
.gradle/*
__pycache__/*
lfw-pkg/
dist/
2,429 changes: 1,890 additions & 539 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@
"chai-spies": "^1.0.0",
"colorette": "^2.0.16",
"commander": "^8.3.0",
"esbuild": "^0.14.2",
"glob": "^8.0.3",
"maven": "^5.0.0",
"mocha": "^10.0.0",
Expand All @@ -178,18 +177,20 @@
"url-exist": "^3.0.0",
"vscode-oniguruma": "^1.7.0",
"vscode-textmate": "^9.0.0",
"which": "^2.0.2"
"which": "^2.0.2",
"webpack": "^5.90.0",
"webpack-cli": "^5.1.4"
},
"dependencies": {
"lfwasm": "file:lfw-pkg",
"vscode-languageclient": "^6.1.3"
},
"scripts": {
"clean": "rimraf out && rimraf lib && rimraf vscode-lingua-franca-*.vsix",
"esbuild-base": "node src/tsbuild.mjs",
"vscode:prepublish": "npm run esbuild-base -- --minify",
"compile": "./write-version-to-file.sh src/extension_version.ts && npm run esbuild-base -- --sourcemap",
"watch": "npm run esbuild-base -- --sourcemap --watch",
"transpile": "webpack",
"vscode:prepublish": "npm run transpile -- --minify",
"compile": "./write-version-to-file.sh src/extension_version.ts && npm run transpile -- --sourcemap",
"watch": "npm run transpile -- --sourcemap --watch",
"build": "npx ts-node src/build_lds.ts",
"compile-tests": "npx tsc --lib \"dom\" --outDir out/test --inlineSourceMap",
"package": "move-cli lingua-franca ../temp-lingua-franca89539275 && vsce package && move-cli ../temp-lingua-franca89539275 lingua-franca",
Expand Down
34 changes: 18 additions & 16 deletions src/build_commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const getAst =
withLogs(vscode.window.showErrorMessage)("Failed to get AST.");
return;
}
// vscode.window.showInformationMessage("AST received: " + ret);
vscode.window.showInformationMessage("AST received: " + ret);
return ret;
};

Expand Down Expand Up @@ -109,7 +109,7 @@ const build = (withLogs: MessageShowerTransformer, client: LanguageClient) =>
});
};

function getJson(uri: string): string {
async function getJson(uri: string): Promise<string> {
let json: string | undefined = lfw.lfc_json(vscode.Uri.parse(uri).fsPath, (p: string) => vscode.workspace.fs.readFile(vscode.Uri.file(p)));
if (!json) {
json = "";
Expand All @@ -124,22 +124,24 @@ function getJson(uri: string): string {
* @returns The action that should be taken in case of a request to build and run.
*/
const buildAndRun = (withLogs: MessageShowerTransformer, client: LanguageClient) =>
(textEditor: vscode.TextEditor) => {
async (textEditor: vscode.TextEditor) => {
const uri = getLfUri(textEditor.document);
if (!uri) return;
vscode.workspace.saveAll().then((successful: boolean) => {
if (!successful) return;
client.sendRequest('generator/buildAndRun', [uri, getJson(uri)]).then((commandAny: any) => {
const command: string[] = commandAny;
if (!command || !command.length) {
withLogs(vscode.window.showErrorMessage)('Build failed.');
return;
}
const terminal = getTerminal('Lingua Franca: Run', command[0]);
terminal.sendText(`cd "${command[0]}"`);
terminal.show(true);
terminal.sendText(command.slice(1).join(' '));
});
const successful = vscode.workspace.saveAll();
if (!successful) {
return;
}
vscode.window.showInformationMessage("DEBUG: doing build and run.");
client.sendRequest('generator/buildAndRun', [uri, await getJson(uri)]).then((commandAny: any) => {
const command: string[] = commandAny;
if (!command || !command.length) {
withLogs(vscode.window.showErrorMessage)('Build failed.');
return;
}
const terminal = getTerminal('Lingua Franca: Run', command[0]);
terminal.sendText(`cd "${command[0]}"`);
terminal.show(true);
terminal.sendText(command.slice(1).join(' '));
});
};

Expand Down
26 changes: 13 additions & 13 deletions src/test/check_dependencies.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ suite('test dependency checking', () => {

const dependencies: DependencyStatus = dependency_status();

type Spy = ChaiSpies.SpyFunc1Proxy<string, Thenable<string>>;
type Spy = ChaiSpies.SpyFunc1Proxy<string, Thenable<string | undefined>>;

function getMockMessageShower(): Spy {
const mock: MessageDisplayHelper = (message: string, ...items: string[]) =>
Expand All @@ -49,33 +49,33 @@ suite('test dependency checking', () => {
};

function checkBasicDependency(dependency: Dependency, depMissingMessage: string): Test {
return async function () {
return async function (this: any) {
this.timeout(basicTimeoutMilliseconds);
const spy = getMockMessageShower();
switch (dependencies) {
case DependencyStatus.Present:
await expectSuccess(dependency, spy);
break;
case DependencyStatus.Outdated:
this.test.skip();
this.test?.skip();
case DependencyStatus.Missing0:
await expectFailure(dependency, spy);
expect(spy).to.have.been.called.with(depMissingMessage + " " + checkDependencies.caveat);
break;
case DependencyStatus.Missing1:
this.test.skip();
this.test?.skip();
default:
throw new Error('unreachable');
}
};
}

const expectSuccess = async (dependency: Dependency, spy: Spy) => {
expect(await checkDependencies.checkerFor(dependency)(spy)()).to.be.true;
expect(await checkDependencies.checkerFor(dependency)!(spy)()).to.be.true;
expect(spy).not.to.have.been.called;
};
const expectFailure = async (dependency: Dependency, spy: Spy) => {
expect(await checkDependencies.checkerFor(dependency)(spy)()).to.be.false;
expect(await checkDependencies.checkerFor(dependency)!(spy)()).to.be.false;
expect(spy).to.have.been.called;
};

Expand All @@ -93,7 +93,7 @@ suite('test dependency checking', () => {
await expectSuccess(Dependency.Pylint, spy);
break;
case DependencyStatus.Missing0:
this.test.skip();
this.test?.skip();
case DependencyStatus.Missing1:
await expectFailure(Dependency.Pylint, spy);
expect(spy).to.have.been.called.with(checkDependencies.pylintMessage + " " + checkDependencies.caveat);
Expand Down Expand Up @@ -138,7 +138,7 @@ suite('test dependency checking', () => {
await expectSuccess(Dependency.Pnpm, spy);
break;
case DependencyStatus.Outdated:
this.test.skip();
this.test?.skip();
default:
throw new Error('unreachable');
}
Expand All @@ -161,14 +161,14 @@ suite('test dependency checking', () => {
expect(spy).to.have.been.called.with(checkDependencies.rustMessage + " " + checkDependencies.caveat);
break;
case DependencyStatus.Missing1:
this.test.skip();
this.test?.skip();
default:
throw new Error('unreachable');
}
});

test('rti', async function() {
if (os.platform() == 'win32') this.test.skip(); // No Windows federated support.
if (os.platform() == 'win32') this.test?.skip(); // No Windows federated support.
this.timeout(basicTimeoutMilliseconds);
const spy = getMockMessageShower();
switch (dependencies) {
Expand All @@ -177,7 +177,7 @@ suite('test dependency checking', () => {
break;
case DependencyStatus.Missing0:
case DependencyStatus.Outdated:
this.test.skip();
this.test?.skip();
case DependencyStatus.Missing1:
await expectFailure(Dependency.Rti, spy);
expect(spy).to.have.been.called.with(checkDependencies.rtiMessage + " " + checkDependencies.caveat);
Expand All @@ -189,7 +189,7 @@ suite('test dependency checking', () => {

test('hyperlinks', async function() {
this.timeout(linkCheckingTimeoutMilliseconds);
if (dependencies != DependencyStatus.Present) this.test.skip();
if (dependencies != DependencyStatus.Present) this.test?.skip();
for (const checkset of checkDependencies.watcherConfig) {
for (const check of checkset.checks) {
if (check.installLink) {
Expand All @@ -200,7 +200,7 @@ suite('test dependency checking', () => {
{ host: installUrl.host, path: installUrl.pathname },
res => {
console.log(`Got status=${res.statusCode}`);
resolve(res.statusCode);
resolve(res.statusCode!);
}
).end();
}))).to.be.lessThan(400);
Expand Down
2 changes: 1 addition & 1 deletion src/test/check_highlighting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ suite('test syntax highlighting', () => {
let files = glob.sync(`lingua-franca/test/**/**.lf`, { cwd: root, ignore: "**/*-gen/**" })
for (const file of files.map(it => path.resolve(root, it))) {
const code = fs.readFileSync(file).toString()
const annotated = annotateCode(code, grammar)
const annotated = annotateCode(code, grammar!)
const relPath = path.relative(path.join(root, "lingua-franca", "test"), file)
const testPath = path.resolve(root, "test", "known-good", relPath.replace(".lf", ".html"))
if (fs.existsSync(testPath)) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/dependency_status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default () => {
const dependenciesString = process.env.dependencies.toLowerCase();
for (const v in DependencyStatus) {
if (v === undefined) return DependencyStatus.Present
if (v.toLowerCase() === dependenciesString) return DependencyStatus[v];
if (v.toLowerCase() === dependenciesString) return (DependencyStatus as any)[v];
}
throw new Error(
`"${dependenciesString}" is not a valid dependency state.
Expand Down
2 changes: 1 addition & 1 deletion src/test/test_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const minimalDependenciesPath = 'temporary_test_deps_please_remove';
async function getFreshPath(): Promise<string> {
fs.mkdirSync(minimalDependenciesPath);
for (const d of minimalDependencies) {
let currentLocation: string;
let currentLocation: string | undefined;
try {
currentLocation = await which(d);
} catch (e) { /* Do nothing */ }
Expand Down
67 changes: 0 additions & 67 deletions src/tsbuild.mjs

This file was deleted.

2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as vscode from 'vscode';

export function getTerminal(name: string, cwd?: string) {
let terminal: vscode.Terminal = vscode.window.terminals.find(
let terminal: vscode.Terminal | undefined = vscode.window.terminals.find(
t => t.name === name
);
if (!terminal) {
Expand Down
11 changes: 6 additions & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"compilerOptions": {
"esModuleInterop": true,
// "esModuleInterop": true,
"inlineSources": false,
"lib": [
"esnext"
"ES2022",
"DOM" // hackily added to include wasm support
],
"module": "commonjs",
"moduleResolution": "node",
"module": "Node16",
// "moduleResolution": "node",
"outDir": "./out",
"sourceMap": false,
"target": "esnext",
"target": "ES2022",
"rootDir": "./src",
"strict": true
},
Expand Down
51 changes: 51 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//@ts-check

'use strict';

const path = require('path');

//@ts-check
/** @typedef {import('webpack').Configuration} WebpackConfig **/

/** @type WebpackConfig */
const extensionConfig = {
target: 'node', // VS Code extensions run in a Node.js-context πŸ“– -> https://webpack.js.org/configuration/node/
mode: 'none', // this leaves the source code as close as possible to the original (when packaging we set this to 'production')

entry: './src/extension.ts', // the entry point of this extension, πŸ“– -> https://webpack.js.org/configuration/entry-context/
output: {
// the bundle is stored in the 'dist' folder (check package.json), πŸ“– -> https://webpack.js.org/configuration/output/
path: path.resolve(__dirname, 'dist'),
filename: 'extension.js',
libraryTarget: 'commonjs2'
},
externals: {
vscode: 'commonjs vscode' // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, πŸ“– -> https://webpack.js.org/configuration/externals/
// modules added here also need to be added in the .vscodeignore file
},
resolve: {
// support reading TypeScript and JavaScript files, πŸ“– -> https://github.com/TypeStrong/ts-loader
extensions: ['.ts', '.js']
},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: 'ts-loader'
}
]
}
]
},
devtool: 'nosources-source-map',
infrastructureLogging: {
level: "log", // enables logging required for problem matchers
},
experiments: {
asyncWebAssembly: true
}
};
module.exports = [ extensionConfig ];

0 comments on commit 3cb4710

Please sign in to comment.