Skip to content

Commit

Permalink
misc: bundle and compile with esbuild
Browse files Browse the repository at this point in the history
  • Loading branch information
71 committed Jun 17, 2023
1 parent 24efcfb commit 590a4b6
Show file tree
Hide file tree
Showing 20 changed files with 258 additions and 730 deletions.
24 changes: 11 additions & 13 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
.github/**
.vscode/**
.vscode-test*/**
assets/dance.afdesign
src/**
test/**
.gitignore
**/tsconfig.json
**/tslint.json
**/*.map
**/*.ts
**/*.lock
out/**/*.build.js
*
*/
assets/*
out/*

!LICENSE
!README.md
!package.json
!assets/*.{svg,png}
!out/extension.js
!out/web-extension.js
8 changes: 4 additions & 4 deletions meta.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as assert from "assert";
import * as fs from "fs/promises";
import * as G from "glob";
import * as path from "path";
import assert from "assert";
import G from "glob";
import * as fs from "fs/promises";
import * as path from "path";

const verbose = process.argv.includes("--verbose");

Expand Down
31 changes: 20 additions & 11 deletions package.build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { availableClipboardRegisters } from "./src/utils/constants";
// Shared values
// ============================================================================

const esbuildBase = "esbuild src/extension.ts --bundle --external:vscode --external:child_process --target=es2021 --format=cjs --minify --keep-names";
const esbuildNode = `${esbuildBase} --outfile=out/extension.js`;
const esbuildWeb = `${esbuildBase} --outfile=out/web-extension.js --define:process.platform=\\"web\\" --define:process.env={}`;

const commandType = {
type: "array",
items: {
Expand Down Expand Up @@ -78,7 +82,7 @@ const selectionDecorationType = {
// ============================================================================

const version = "0.5.12",
preRelease = 3;
preRelease = 4;

export const pkg = (modules: Builder.ParsedModule[]) => ({

Expand All @@ -100,24 +104,29 @@ export const pkg = (modules: Builder.ParsedModule[]) => ({
url: "https://github.com/71/dance.git",
},

main: "./out/src/extension.js",
browser: "./out/web/extension.js",
main: "./out/extension.js",
browser: "./out/web-extension.js",

engines: {
vscode: "^1.63.0",
},

scripts: {
"check": "eslint . && depcruise -v .dependency-cruiser.js src",
"check": "tsc -p ./ && eslint . && depcruise -v .dependency-cruiser.js src",
"format": "eslint . --fix",

"generate": "ts-node ./meta.ts",
"generate:watch": "ts-node ./meta.ts --watch",

"compile": esbuildNode,
"compile:watch": `${esbuildNode} --watch --sourcemap`,
"compile-web": esbuildWeb,
"compile-web:watch": `${esbuildWeb} --watch --sourcemap`,
"compile-tests": "glob-exec {src,test}/**/*.ts -- \"esbuild {{files.join(' ')}} --target=es2021 --format=cjs --outdir=out --outbase=. --sourcemap\"",

"test": "yarn run compile --sourcemap && yarn run compile-tests && node ./out/test/run.js",

"vscode:prepublish": "yarn run generate && yarn run compile && yarn run compile-web",
"compile": "tsc -p ./",
"compile:watch": "tsc -watch -p ./",
"compile-web": "webpack --mode production --devtool hidden-source-map --config ./webpack.web.config.js",
"compile-web:watch": "webpack --watch --config ./webpack.web.config.js",
"test": "yarn run compile && node ./out/test/run.js",
"package": "vsce package --allow-star-activation",
"publish": "vsce publish --allow-star-activation",
"package:pre": `vsce package --allow-star-activation --pre-release --no-git-tag-version --no-update-package-json ${version.replace(/\d+$/, "$&" + preRelease.toString().padStart(3, "0"))}`,
Expand All @@ -134,8 +143,10 @@ export const pkg = (modules: Builder.ParsedModule[]) => ({
"@vscode/test-electron": "^2.1.3",
"chokidar": "^3.5.3",
"dependency-cruiser": "^11.7.0",
"esbuild": "^0.18.4",
"eslint": "^8.15.0",
"glob": "^8.0.3",
"glob-exec": "^0.1.1",
"mocha": "^10.0.0",
"source-map-support": "^0.5.21",
"ts-loader": "^9.3.1",
Expand All @@ -144,8 +155,6 @@ export const pkg = (modules: Builder.ParsedModule[]) => ({
"unexpected": "^13.0.0",
"vsce": "^2.7.0",
"web-tree-sitter": "^0.20.8",
"webpack": "^5.72.1",
"webpack-cli": "^4.9.2",
"yaml": "^2.1.1",
},

Expand Down
25 changes: 13 additions & 12 deletions package.json

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

4 changes: 3 additions & 1 deletion src/api/edit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export function insert(
);
}

export declare namespace insert {
export /* enum */ namespace insert {
/**
* Insertion flags for {@link insert}.
*/
Expand Down Expand Up @@ -218,7 +218,9 @@ export declare namespace insert {
*/
Extend = 0b10_00_1,
}
}

export declare namespace insert {
/**
* The result of a callback passed to {@link insert} or
* {@link insertByIndex}.
Expand Down
2 changes: 1 addition & 1 deletion src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export class CommandDescriptor<Flags extends CommandDescriptor.Flags = CommandDe
}
}

export declare namespace CommandDescriptor {
export /* enum */ namespace CommandDescriptor {
/**
* Flags describing the behavior of some commands.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/commands/load-all.build.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as assert from "assert";
import assert from "assert";
import { Builder, unindent } from "../../meta";

export async function build(builder: Builder) {
Expand Down
2 changes: 1 addition & 1 deletion src/state/modes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ export declare namespace Mode {
readonly type: vscode.TextEditorDecorationType;
}

export namespace Configuration {
export /* enum */ namespace Configuration {
/**
* A valid cursor style value in a `Mode.Configuration`.
*/
Expand Down
16 changes: 9 additions & 7 deletions src/state/registers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export abstract class Register {
}
}

export declare namespace Register {
export /* enum */ namespace Register {
/**
* Flags describing the capabilities of a `Register`.
*/
Expand All @@ -197,6 +197,14 @@ export declare namespace Register {
CanReadWriteMacros = 16,
}

export const enum ChangeKind {
Contents,
Selections,
Recording,
}
}

export declare namespace Register {
/**
* Given an array of `Flags` types, returns what interfaces correspond to
* these flags.
Expand Down Expand Up @@ -237,12 +245,6 @@ export declare namespace Register {
getRecording(): Recording | undefined;
setRecording(recording: Recording): void;
}

export const enum ChangeKind {
Contents,
Selections,
Recording,
}
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/utils/disposables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,15 @@ export class AutoDisposable implements vscode.Disposable {
}
}

export declare namespace AutoDisposable {
export /* enum */ namespace AutoDisposable {
export const enum EventType {
OnEditorWasClosed = "editor-was-closed",
OnModeDidChange = "mode-did-change",
OnSelectionsDidChange = "selections-did-change",
}
}

export declare namespace AutoDisposable {
export type Event = EventType
| readonly [EventType.OnModeDidChange,
{ except?: string | string[]; include?: string | string[] }];
Expand Down
2 changes: 1 addition & 1 deletion src/utils/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export class CancellationError extends Error {
}
}

export declare namespace CancellationError {
export /* enum */ namespace CancellationError {
export const enum Reason {
CancellationToken = "cancellation token was used",
PressedEscape = "user pressed <escape>",
Expand Down
2 changes: 1 addition & 1 deletion test/suite/api.test.build.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as assert from "assert";
import assert from "assert";

import { Builder, unindent } from "../../meta";
import { stringifyExpectedDocument } from "./build-utils";
Expand Down
1 change: 0 additions & 1 deletion test/suite/api.test.ts

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

2 changes: 1 addition & 1 deletion test/suite/build-utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as assert from "assert";
import assert from "assert";

export function stringifyExpectedDocument(code: string, codeIndent: number) {
code = code.replace(/`/g, "\\`").replace(/^/gm, " ".repeat(codeIndent + 2));
Expand Down
6 changes: 3 additions & 3 deletions test/suite/commands.build.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as assert from "assert";
import * as fs from "fs/promises";
import * as path from "path";
import assert from "assert";
import * as fs from "fs/promises";
import path from "path";

import { unindent } from "../../meta";
import { execAll, stringifyExpectedDocument } from "./build-utils";
Expand Down
8 changes: 4 additions & 4 deletions test/suite/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as glob from "glob";
import * as Mocha from "mocha";
import * as path from "path";
import { promises as fs } from "fs";
import glob from "glob";
import Mocha from "mocha";
import * as path from "path";
import * as fs from "fs/promises";

export async function run(testsRoot: string) {
// Create the mocha test.
Expand Down
2 changes: 1 addition & 1 deletion test/suite/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import "source-map-support/register";

import * as assert from "assert";
import * as Mocha from "mocha";
import Mocha from "mocha";
import * as path from "path";
// @ts-expect-error
import * as unexpected from "unexpected";
Expand Down
7 changes: 4 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"compilerOptions": {
"module": "CommonJS",
"target": "ES2018",
"outDir": "out",
"lib": ["ES2020", "ESNext.WeakRef"],
"target": "ES2021",
"lib": ["ESNext.WeakRef"],
"noEmit": true,
"sourceMap": true,
"strict": true,
"noImplicitReturns": true,
Expand All @@ -12,6 +12,7 @@
"preserveConstEnums": true,
"strictNullChecks": true,
"noImplicitAny": true,
"esModuleInterop": true,
},
"exclude": ["node_modules", ".vscode-test"],
}
49 changes: 0 additions & 49 deletions webpack.web.config.js

This file was deleted.

Loading

0 comments on commit 590a4b6

Please sign in to comment.