Skip to content

Commit a5b5409

Browse files
committed
WIP
1 parent df80cae commit a5b5409

File tree

10 files changed

+166
-124
lines changed

10 files changed

+166
-124
lines changed

.vscode/tasks.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"tasks": [
66
{
77
"type": "npm",
8-
"label": "compile watch",
9-
"script": "compile-esbuild-watch",
8+
"label": "Compile Types Watch",
9+
"script": "compile-types-watch",
1010
"problemMatcher": [
1111
"$tsc-watch"
1212
],
@@ -16,8 +16,8 @@
1616
},
1717
{
1818
"type": "npm",
19-
"label": "bundle-esbuild-dev watch",
20-
"script": "bundle-esbuild-dev-watch",
19+
"label": "Compile TypeScript Watch",
20+
"script": "compile-ts-watch",
2121
"problemMatcher": [],
2222
"presentation": {
2323
"group": "group-build"
@@ -26,8 +26,8 @@
2626
{
2727
"label": "build",
2828
"dependsOn": [
29-
"compile watch",
30-
"bundle-esbuild-dev watch"
29+
"Compile Types Watch",
30+
"Compile TypeScript Watch"
3131
],
3232
"group": {
3333
"kind": "build",

esbuild.mjs

+127-86
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,52 @@
1-
import { context } from "esbuild";
2-
import process from "process";
1+
import * as esbuild from "esbuild";
2+
import * as process from "process";
3+
import { readFileSync } from "fs";
4+
import { umdWrapper } from "esbuild-plugin-umd-wrapper";
5+
import yargs from "yargs";
6+
import { hideBin } from "yargs/helpers";
37

4-
const production = process.argv.includes("--production");
5-
const watch = process.argv.includes("--watch");
8+
const myYargs = yargs(hideBin(process.argv));
9+
myYargs
10+
.usage("Usage: node esbuild.mjs [options]")
11+
.demandCommand(0, 0)
12+
.example("node esbuild.mjs --watch", "Bundle and watch for changes")
13+
.option("mode", {
14+
alias: "m",
15+
describe: "Build mode",
16+
choices: ["development", "production"],
17+
default: "production"
18+
})
19+
.option("w", {
20+
alias: "watch",
21+
describe: "Watch for changes",
22+
type: "boolean"
23+
})
24+
.help("h")
25+
.alias("h", "help")
26+
.epilog("https://github.com/hpcc-systems/hpcc-js-wasm")
27+
;
28+
const argv = await myYargs.argv;
29+
const isDevelopment = argv.mode === "development";
30+
const isProduction = !isDevelopment;
31+
const isWatch = argv.watch;
632

7-
/**
8-
* @type {import('esbuild').Plugin}
9-
*/
10-
const esbuildProblemMatcherPlugin = {
33+
// plugins ---
34+
const excludeSourceMapPlugin = ({ filter }) => ({
35+
name: 'excludeSourceMapPlugin',
36+
37+
setup(build) {
38+
build.onLoad({ filter }, (args) => {
39+
return {
40+
contents:
41+
readFileSync(args.path, 'utf8') +
42+
'\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==',
43+
loader: 'default',
44+
};
45+
});
46+
},
47+
});
48+
49+
const esbuildProblemMatcherPlugin = ({ filter }) => ({
1150
name: "esbuild-problem-matcher",
1251

1352
setup(build) {
@@ -22,95 +61,97 @@ const esbuildProblemMatcherPlugin = {
2261
console.log("[watch] build finished");
2362
});
2463
},
25-
};
64+
});
2665

27-
async function extension() {
28-
const ctx = await context({
29-
entryPoints: [
30-
"src/extension.ts",
31-
"src/debugger.ts"
32-
],
33-
bundle: true,
34-
format: "cjs",
35-
minify: production,
36-
sourcemap: !production,
37-
sourcesContent: false,
38-
platform: "node",
39-
outdir: "dist",
40-
external: ["vscode"],
41-
// logLevel: "silent",
66+
// helpers ---
67+
function build(config) {
68+
isDevelopment && console.log("Start: ", config.entryPoints[0], config.outfile);
69+
return esbuild.build({
70+
...config,
71+
sourcemap: "linked",
4272
plugins: [
43-
/* add to the end of plugins array */
44-
esbuildProblemMatcherPlugin,
45-
],
73+
...config.plugins ?? [],
74+
]
75+
}).then(() => {
76+
isDevelopment && console.log("Stop: ", config.entryPoints[0], config.outfile);
4677
});
47-
if (watch) {
48-
await ctx.watch();
49-
} else {
50-
await ctx.rebuild();
51-
await ctx.dispose();
52-
}
5378
}
5479

55-
async function notebook() {
56-
const ctx = await context({
57-
entryPoints: [
58-
"src/eclwatch.tsx",
59-
"src/notebook/renderers/wuRenderer.tsx",
60-
"src/notebook/renderers/ojsRenderer.ts"
61-
],
62-
bundle: true,
63-
format: "esm",
64-
minify: true,
65-
sourcemap: !production,
66-
sourcesContent: false,
67-
platform: "browser",
68-
outdir: "dist",
69-
external: ["vscode", "fs", "path", "os"],
70-
// logLevel: "silent",
80+
function watch(config) {
81+
return esbuild.context({
82+
...config,
83+
sourcemap: "linked",
7184
plugins: [
72-
/* add to the end of plugins array */
73-
esbuildProblemMatcherPlugin,
74-
],
85+
...config.plugins ?? [],
86+
{
87+
name: "rebuild-notify",
88+
setup(build) {
89+
build.onEnd(result => {
90+
console.log(`Built ${config.outfile}`);
91+
});
92+
},
93+
}
94+
]
95+
}).then(ctx => {
96+
return ctx.watch();
7597
});
76-
if (watch) {
77-
await ctx.watch();
78-
} else {
79-
await ctx.rebuild();
80-
await ctx.dispose();
81-
}
8298
}
8399

84-
async function web_extension() {
85-
const ctx = await context({
86-
entryPoints: [
87-
"src/web-extension.ts"
88-
],
89-
bundle: true,
90-
format: "esm",
91-
minify: production,
92-
sourcemap: !production,
93-
sourcesContent: false,
100+
function browserTpl(input, output, format, globalName = "", external = []) {
101+
return (isWatch ? watch : build)({
102+
entryPoints: [input],
103+
outfile: `${output}.${format === "esm" ? "js" : "umd.js"}`,
94104
platform: "browser",
95-
outfile: "dist-web/extension.js",
96-
external: ["vscode", "fs", "path", "os"],
97-
// logLevel: "silent",
98-
plugins: [
99-
/* add to the end of plugins array */
100-
esbuildProblemMatcherPlugin,
101-
],
105+
target: "es2022",
106+
format,
107+
globalName,
108+
bundle: true,
109+
minify: isProduction,
110+
external,
111+
plugins: format === "umd" ? [umdWrapper()] : []
102112
});
103-
if (watch) {
104-
await ctx.watch();
105-
} else {
106-
await ctx.rebuild();
107-
await ctx.dispose();
108-
}
109113
}
110114

111-
Promise.all([extension(), notebook(), web_extension()])
112-
.then(() => {
113-
}).catch(e => {
114-
console.error(e);
115-
process.exit(1);
115+
function browserBoth(input, output, globalName = undefined, external = []) {
116+
return Promise.all([
117+
browserTpl(input, output, "esm", globalName, external),
118+
browserTpl(input, output, "umd", globalName, external)
119+
]);
120+
}
121+
122+
function nodeTpl(input, output, format, external = []) {
123+
return (isWatch ? watch : build)({
124+
entryPoints: [input],
125+
outfile: `${output}.${format === "esm" ? "mjs" : "js"}`,
126+
platform: "node",
127+
target: "node20",
128+
format,
129+
bundle: true,
130+
minify: isProduction,
131+
external
116132
});
133+
}
134+
135+
function nodeBoth(input, output, external = []) {
136+
return Promise.all([
137+
nodeTpl(input, output, "esm", external),
138+
nodeTpl(input, output, "cjs", external)
139+
]);
140+
}
141+
142+
function bothTpl(input, output, globalName = undefined, external = []) {
143+
return Promise.all([
144+
browserBoth(input, output, globalName, external),
145+
nodeTpl(input, output, "cjs", external)
146+
]);
147+
}
148+
149+
// config ---
150+
nodeTpl("src/extension.ts", "dist/extension", "cjs", ["vscode"]);
151+
nodeTpl("src/notebook/renderers/wuRenderer.tsx", "dist/notebook/renderers", "cjs", ["vscode", "fs", "path", "os"]);
152+
nodeTpl("src/notebook/renderers/ojsRenderer.ts", "dist/notebook/renderers", "cjs", ["vscode", "fs", "path", "os"]);
153+
154+
nodeTpl("src/debugger.ts", "dist/debugger", "cjs", ["vscode"]);
155+
156+
browserTpl("src/eclwatch.tsx", "dist/eclwatch", "esm", undefined, ["vscode", "fs", "path", "os"]);
157+
browserTpl("src/web-extension.ts", "dist-web/extension.js", "esm", undefined, ["vscode", "fs", "path", "os"]);

package-lock.json

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+9-7
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,19 @@
1616
"browser": "./dist-web/extension",
1717
"scripts": {
1818
"clean": "rimraf --glob out lib* dist* types hpcc-systems.ecl.vsix",
19-
"copy-resources": "copyfiles -f ./node_modules/@hpcc-js/ddl-shim/schema/v2.json ./dist",
19+
"copy-res": "copyfiles -f ./node_modules/@hpcc-js/ddl-shim/schema/v2.json ./dist",
2020
"gen-grammar": "wsl -e ./scripts/grammar-generate.sh",
2121
"gen-nls": "node ./lib-util/generate.js",
2222
"merge-nls": "node ./lib-util/merge.js",
23-
"compile-esbuild": "tsc --noEmit --project tsconfig.json",
24-
"compile-esbuild-watch": "npm run compile-esbuild -- -w",
25-
"bundle-esbuild": "node esbuild.mjs --production",
26-
"bundle-esbuild-dev": "node esbuild.mjs",
27-
"bundle-esbuild-dev-watch": "npm run bundle-esbuild-dev -- --watch",
23+
"compile-types": "tsc --project tsconfig.json --emitDeclarationOnly",
24+
"compile-types-watch": "npm run compile-types -- --watch",
25+
"compile-ts": "node esbuild.mjs",
26+
"compile-ts-dev": "npm run compile-ts -- --mode=development",
27+
"compile-ts-watch": "npm run compile-ts-dev -- --watch",
2828
"compile-util": "tsc --project ./tsconfig.util.json",
2929
"compile-util-watch": "npm run compile-util -- -w",
30-
"build": "run-s copy-resources compile-esbuild bundle-esbuild",
30+
"compile": "run-p compile-types compile-ts",
31+
"build": "run-s copy-res compile",
3132
"watch": "run-p compile-esbuild-watch bundle-esbuild-dev-watch",
3233
"lint": "eslint src",
3334
"lint-fix": "npm run lint -- --fix",
@@ -84,6 +85,7 @@
8485
"csv-writer": "1.6.0",
8586
"diff": "5.2.0",
8687
"esbuild": "0.23.0",
88+
"esbuild-plugin-umd-wrapper": "3.0.0",
8789
"eslint": "8.57.0",
8890
"mocha": "10.6.0",
8991
"npm-run-all": "4.1.5",

src/ecl/eclWatchTree.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Item, Tree } from "./tree";
66
import { eclWatchPanelView } from "./eclWatchPanelView";
77
import { SaveData } from "./saveData";
88

9-
const PrevWeeks: string[] = ["Last Week", "Two Weeks Ago", "Three Weeks Ago", "Four Weeks Ago", "Five Weeks Ago", "Six Weeks Ago", "Seven Weeks Ago"].map(localize);
9+
const PrevWeeks: string[] = [localize("Last Week"), localize("Two Weeks Ago"), localize("Three Weeks Ago"), localize("Four Weeks Ago"), localize("Five Weeks Ago"), localize("Six Weeks Ago"), localize("Seven Weeks Ago")];
1010

1111
export let eclWatchTree: ECLWatchTree;
1212

src/extension.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ export function activate(context: vscode.ExtensionContext): void {
1010

1111
initialize().then(() => {
1212
return Promise.all([
13-
import("./ecl/main").then(({ activate }) => activate(context)),
14-
import("./kel/main").then(({ activate }) => activate(context)),
15-
import("./dashy/main").then(({ activate }) => activate(context))
13+
import("./ecl/main.js").then(({ activate }) => activate(context)),
14+
import("./kel/main.js").then(({ activate }) => activate(context)),
15+
import("./dashy/main.js").then(({ activate }) => activate(context))
1616
]);
1717
}).then(() => {
1818
reporter.sendTelemetryEvent("initialized");

src/hpccplatform/launchConfig.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ export class LaunchConfig implements LaunchRequestArguments {
324324
}
325325

326326
private ping(timeout: number = 5000): Promise<LaunchConfigState> {
327-
const timeoutPrommise = new Promise((resolve, reject) => {
327+
const timeoutPrommise = new Promise<string>((resolve, reject) => {
328328
setTimeout(() => {
329329
resolve("timeout");
330330
}, timeout);

src/notebook/controller/controller.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export class Controller {
140140
outputItem = vscode.NotebookCellOutputItem.json(ojsOutput, MIME);
141141
} catch (e) { }
142142
}
143-
} catch (e) {
143+
} catch (e: any) {
144144
if (e.message.indexOf("0003: Definition must contain EXPORT or SHARED value") >= 0) {
145145
outputItem = vscode.NotebookCellOutputItem.text("...no action...");
146146
} else {

src/web-extension.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { initialize } from "./util/localize";
33

44
export function activate(ctx: ExtensionContext): void {
55
initialize().then(() => {
6-
import("./ecl/main").then(({ activate }) => activate(ctx));
7-
import("./notebook").then(({ activate }) => activate(ctx));
6+
import("./ecl/main.js").then(({ activate }) => activate(ctx));
7+
import("./notebook/index.js").then(({ activate }) => activate(ctx));
88
});
99
}

0 commit comments

Comments
 (0)