Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 0 additions & 24 deletions .eslintrc.json

This file was deleted.

21 changes: 19 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ jobs:

- name: Lint TypeScript
run: yarn lint
continue-on-error: true

- name: Compile TypeScript
run: yarn compile
Expand Down Expand Up @@ -201,8 +200,26 @@ jobs:
- name: Unit tests
run: yarn test

# `vscode:prepublish` bundles the extension (scripts/bundle.mjs) and
# prints every package that went into the bundle.
- name: Test packaging (without binaries)
run: npx vsce package --yarn
run: npx vsce package --no-dependencies

- name: The package is the bundle, with no node_modules
run: scripts/check-package.sh comline-vscode-*.vsix

- name: Unpack the package
run: unzip -q comline-vscode-*.vsix -d "$RUNNER_TEMP/vsix"

# The oldest editor package.json allows (engines.vscode ^1.75.0) runs
# extensions on Node 16.
- name: Setup Node.js 16, the oldest extension host
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 16.20.2

- name: The bundle loads on Node 16
run: node scripts/check-bundle.cjs "$RUNNER_TEMP/vsix"

- name: Upload test package
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,9 @@ jobs:
run: |
chmod +x bin/*/comline-lsp 2>/dev/null || true
if [ "$TARGET" = universal ]; then
npx vsce package --yarn -o "$VSIX"
npx vsce package --no-dependencies -o "$VSIX"
else
npx vsce package --yarn --target "$TARGET" -o "$VSIX"
npx vsce package --no-dependencies --target "$TARGET" -o "$VSIX"
fi

- name: Verify the package holds exactly its own binary
Expand All @@ -302,6 +302,9 @@ jobs:
|| { echo "::error::expected exactly extension/bin/$TARGET/$name"; exit 1; }
fi

- name: Verify the package is the bundle, with no node_modules
run: scripts/check-package.sh "$VSIX"

- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: vsix-${{ matrix.target }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules
out
dist
*.vsix
.vscode-test/
*.log
Expand Down
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"${workspaceFolder}/test-workspace"
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
"${workspaceFolder}/dist/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
}
Expand Down
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"tasks": [
{
"type": "npm",
"script": "compile",
"script": "bundle",
"group": {
"kind": "build",
"isDefault": true
Expand Down
9 changes: 7 additions & 2 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ src/**
tsconfig.json
**/*.map
**/*.ts
.eslintrc.json
eslint.config.mjs
assets/icon-font-src/**
.fantasticonrc.js
fonts/*.json
Expand All @@ -16,4 +16,9 @@ scripts/**
test-workspace/**
bin/README.md
RELEASING.md
out/**/*.test.js

# The bundle (dist/extension.js) holds the code and every dependency it needs
# (scripts/bundle.mjs), so neither the dependencies nor the tsc output that the
# unit tests and the Flatpak e2e use ship.
node_modules/**
out/**
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,26 @@ All notable changes to the "comline-vscode" extension will be documented in this
`CHANGELOG.md`), and writes the `Comline Package` language alias as the
Marketplace tag `ComlinePackage`. It also takes the development-only advisories
held by vsce's old `markdown-it`, `linkify-it` and `uuid` with it.
- Linting moves to ESLint 10 with typescript-eslint 8. The configuration is now
the flat `eslint.config.mjs` (`.eslintrc.json` is gone) with the same rules as
before: `@typescript-eslint/naming-convention`, `curly`, `eqeqeq` and
`no-throw-literal`, all warnings. `@typescript-eslint/semi`, removed in
typescript-eslint 8, is `@stylistic/semi`. `yarn lint` is `eslint src`.
CI's lint step no longer ignores a failure: an error fails the job (the 24
existing naming-convention warnings do not).

### Fixed
- The extension is bundled (esbuild) into one file, `dist/extension.js`, and the
`.vsix` no longer carries `node_modules`. `vsce` had been copying the
top-level `node_modules/<name>` of each dependency, which is whichever copy
the development dependencies made most common, not the one the dependency
asked for: the packages held `minimatch` 3 and `brace-expansion` 2 for
`vscode-languageclient`, which wants `minimatch` ^5.1.0, whose own
`brace-expansion` is ^2. The bundle resolves every `require` from the file
that makes it, so `vscode-languageclient` gets its own `minimatch` 5.1.x. The
bundle targets Node 16, the extension host of VS Code 1.75, and CI loads it
on Node 16. `tsc` stays as the type check and builds `out/` for the unit
tests (`yarn bundle` makes the bundle).
- `comline.server.mode: "path"` never worked: the extension passed the bare
name `comline-lsp` to a file-existence check, which looks in the current
directory, not on `PATH`. The name is now looked up on `PATH` (with
Expand Down
7 changes: 4 additions & 3 deletions QUICKSTART.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ pinned language server for every platform, smoke-tests each binary, packages one

| Command | Description |
|---------|-------------|
| `yarn compile` | Compile TypeScript |
| `yarn watch` | Watch mode for development |
| `yarn compile` | Type-check with tsc (also builds `out/` for the tests) |
| `yarn bundle` | Bundle the extension into `dist/extension.js`, which the editor runs |
| `yarn watch` | Watch mode for tsc |
| `yarn lint` | Run ESLint |
| `yarn package` | Package extension for this machine |
| `yarn link-binary` | Run symlink helper script |
Expand All @@ -89,7 +90,7 @@ yarn compile

**Want to rebuild?**
```bash
yarn compile && code --install-extension *.vsix
yarn package && code --install-extension *.vsix
```

---
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,12 @@ yarn install
# see TESTING.md)
yarn link-binary <path-to-a-language-server-checkout>

# Compile TypeScript
# Type-check (tsc; also builds out/ for the unit tests)
yarn compile

# Bundle the extension into dist/extension.js (what the editor runs)
yarn bundle

# Package the extension
yarn package
```
Expand Down
31 changes: 31 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Flat config. It is .eslintrc.json translated rule for rule (no `extends`,
// so only the rules named here run), with `@typescript-eslint/semi`, which
// typescript-eslint 8 removed, replaced by `@stylistic/semi`.
import { defineConfig, globalIgnores } from 'eslint/config';
import tsPlugin from '@typescript-eslint/eslint-plugin';
import tsParser from '@typescript-eslint/parser';
import stylistic from '@stylistic/eslint-plugin';

export default defineConfig([
// node_modules is ignored by default.
globalIgnores(['out/**', '.vscode-test/**']),
{
files: ['**/*.ts'],
languageOptions: {
parser: tsParser,
ecmaVersion: 6,
sourceType: 'module',
},
plugins: {
'@typescript-eslint': tsPlugin,
'@stylistic': stylistic,
},
rules: {
'@typescript-eslint/naming-convention': 'warn',
'@stylistic/semi': 'warn',
curly: 'warn',
eqeqeq: 'warn',
'no-throw-literal': 'warn',
},
},
]);
16 changes: 10 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"workspaceContains:**/config.idp",
"workspaceContains:**/comline.toml"
],
"main": "./out/extension.js",
"main": "./dist/extension.js",
"contributes": {
"commands": [
{
Expand Down Expand Up @@ -267,23 +267,27 @@
}
},
"scripts": {
"vscode:prepublish": "yarn compile",
"vscode:prepublish": "yarn compile && yarn bundle:production",
"compile": "tsc -p ./",
"bundle": "node scripts/bundle.mjs",
"bundle:production": "node scripts/bundle.mjs --production --report",
"watch": "tsc -watch -p ./",
"pretest": "yarn compile",
"test": "node --test out/resolve.test.js out/coreRev.test.js out/idpSchema.test.js",
"lint": "eslint src --ext ts",
"lint": "eslint src",
"package": "bash scripts/package.sh",
"link-binary": "bash scripts/link-binary.sh",
"build:icon-font": "npx --yes fantasticon@^4.1.0"
},
"devDependencies": {
"@stylistic/eslint-plugin": "^6.0.0",
"@types/node": "^18.0.0",
"@types/vscode": "^1.75.0",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"@typescript-eslint/eslint-plugin": "^8.72.2",
"@typescript-eslint/parser": "^8.72.2",
"@vscode/vsce": "^4.1.1",
"eslint": "^8.0.0",
"esbuild": "0.28.2",
"eslint": "^10.15.0",
"typescript": "^5.0.0"
},
"dependencies": {
Expand Down
51 changes: 51 additions & 0 deletions scripts/bundle.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Bundles src/extension.ts into dist/extension.js: the one JavaScript file the
// .vsix carries (`main` in package.json), with every dependency resolved the
// way Node resolves it from the file that requires it, so
// vscode-languageclient gets the minimatch it asks for and no node_modules
// ships.
//
// node scripts/bundle.mjs development: unminified, with a source map
// node scripts/bundle.mjs --production minified, no map (what `vsce package` runs)
// node scripts/bundle.mjs --report also print every package in the bundle
//
// `tsc` (yarn compile) stays the type check and builds out/ for the unit tests
// and the Flatpak e2e; it does not produce what the editor runs.
import { build } from 'esbuild';
import { readFileSync } from 'node:fs';
import path from 'node:path';

const production = process.argv.includes('--production');
const report = process.argv.includes('--report');

const result = await build({
entryPoints: ['src/extension.ts'],
outfile: 'dist/extension.js',
bundle: true,
// The editor provides `vscode`.
external: ['vscode'],
format: 'cjs',
platform: 'node',
// The extension host of the oldest editor package.json allows (engines.vscode
// ^1.75.0) is Electron 19, Node 16.14.
target: 'node16',
minify: production,
sourcemap: !production,
metafile: true,
logLevel: 'info',
});

if (report) {
// name@version, and where it came from, for every package that went in.
const found = new Map();
for (const input of Object.keys(result.metafile.inputs)) {
const m = /^((?:.*\/)?node_modules\/(?:@[^/]+\/)?[^/]+)\//.exec(input);
if (m && !found.has(m[1])) {
const { name, version } = JSON.parse(readFileSync(path.join(m[1], 'package.json'), 'utf8'));
found.set(m[1], `${name}@${version}`);
}
}
console.log('Packages in the bundle:');
for (const [dir, id] of [...found].sort((a, b) => a[1].localeCompare(b[1]))) {
console.log(` ${id} (${dir})`);
}
}
40 changes: 40 additions & 0 deletions scripts/check-bundle.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Loads the bundled extension the way the editor does, with `vscode` stubbed,
// and checks it exports activate and deactivate. Run it under the oldest Node
// an editor the extension supports uses (16): a module the bundle needs but
// lacks, or syntax that Node cannot parse, fails here and not at a user's
// first activation.
//
// node scripts/check-bundle.cjs <directory the .vsix was unzipped into>
//
// It does not call activate(): that needs an editor.
'use strict';
const Module = require('module');
const path = require('path');

const dir = process.argv[2];
if (!dir) {
console.error('usage: check-bundle.cjs <unzipped .vsix directory>');
process.exit(2);
}
const file = path.resolve(dir, 'extension', 'dist', 'extension.js');

// Any property, call or construction on it answers with itself.
const stub = new Proxy(function () {}, {
get: (_t, prop) => (prop === 'then' || prop === '__esModule' ? undefined : prop === Symbol.toPrimitive ? () => '' : stub),
apply: () => stub,
construct: () => stub,
});
const load = Module._load;
Module._load = function (request, ...rest) {
return request === 'vscode' ? stub : load.call(this, request, ...rest);
};

console.log(`node ${process.version}: loading ${file}`);
const ext = require(file);
for (const name of ['activate', 'deactivate']) {
if (typeof ext[name] !== 'function') {
console.error(`::error::the bundle does not export ${name}()`);
process.exit(1);
}
}
console.log('loaded: exports activate() and deactivate()');
22 changes: 22 additions & 0 deletions scripts/check-package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
# Checks a .vsix is what the bundled build makes: the bundle, no node_modules,
# no compiled-for-the-tests out/. Usage: scripts/check-package.sh <file.vsix>
set -euo pipefail

vsix=${1:?usage: check-package.sh <file.vsix>}
entries=$(unzip -Z1 "$vsix")

fail() { echo "::error::$vsix: $1"; exit 1; }

grep -qx 'extension/dist/extension.js' <<<"$entries" || fail "extension/dist/extension.js is missing"
if grep -q '^extension/node_modules/' <<<"$entries"; then
fail "it holds node_modules: $(grep '^extension/node_modules/' <<<"$entries" | head -3 | tr '\n' ' ')..."
fi
if grep -q '^extension/out/' <<<"$entries"; then
fail "it holds out/, the tsc output for the tests"
fi
main=$(unzip -p "$vsix" extension/package.json | node -p 'JSON.parse(require("fs").readFileSync(0, "utf8")).main')
[ "$main" = "./dist/extension.js" ] || fail "main is $main, not ./dist/extension.js"

echo "$vsix: $(wc -l <<<"$entries") files, no node_modules, main is $main"
unzip -Zl "$vsix" | grep -E 'extension/dist/|extension/package.json' || true
2 changes: 1 addition & 1 deletion scripts/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fi

echo ""
echo "📦 Packaging extension..."
npx vsce package --yarn
npx vsce package --no-dependencies

VSIX_FILE=$(ls -t *.vsix 2>/dev/null | head -n1)
if [ -n "$VSIX_FILE" ]; then
Expand Down
Loading
Loading