Skip to content

Commit a6b84a2

Browse files
committed
WIP
1 parent 03e6ce5 commit a6b84a2

11 files changed

+221
-88
lines changed

.vscode/tasks.json

+18-6
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"tasks": [
66
{
77
"type": "npm",
8-
"label": "Compile Types Watch",
9-
"script": "compile-types-watch",
8+
"label": "gen-extension-watch",
9+
"script": "gen-extension-watch",
1010
"problemMatcher": [
1111
"$tsc-watch"
1212
],
@@ -16,8 +16,19 @@
1616
},
1717
{
1818
"type": "npm",
19-
"label": "Compile TypeScript Watch",
20-
"script": "compile-ts-watch",
19+
"label": "gen-webview-watch",
20+
"script": "gen-webview-watch",
21+
"problemMatcher": [
22+
"$tsc-watch"
23+
],
24+
"presentation": {
25+
"group": "group-build"
26+
}
27+
},
28+
{
29+
"type": "npm",
30+
"label": "build-ts-watch",
31+
"script": "build-ts-watch",
2132
"problemMatcher": [],
2233
"presentation": {
2334
"group": "group-build"
@@ -26,8 +37,9 @@
2637
{
2738
"label": "build",
2839
"dependsOn": [
29-
"Compile Types Watch",
30-
"Compile TypeScript Watch"
40+
"gen-extension-watch",
41+
"gen-webview-watch",
42+
"build-ts-watch"
3143
],
3244
"group": {
3345
"kind": "build",

esbuild.mjs

+131-39
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,65 @@
1-
import { writeFileSync } from "fs";
2-
import { buildWatch, isProduction } from "@hpcc-js/esbuild-plugins";
3-
import { aliasPath } from "esbuild-plugin-alias-path";
1+
import * as esbuild from "esbuild";
2+
import copyStaticFiles from "esbuild-copy-static-files";
3+
import process from "node:process";
4+
import path from "node:path";
5+
import { writeFileSync } from "node:fs";
46

5-
export function nodeTpl(input, output, format = "esm", external = []) {
6-
return buildWatch({
7-
entryPoints: [input],
8-
outfile: `${output}.js`,
9-
platform: "node",
10-
target: "node20",
11-
format,
7+
const outputDirectory = "dist";
8+
const production = process.argv.includes("--production");
9+
const watch = process.argv.includes("--watch");
10+
11+
async function main(entryPoint, platform, format, plugins = []) {
12+
const ctx = await esbuild.context({
13+
entryPoints: [entryPoint],
14+
outdir: outputDirectory,
1215
bundle: true,
13-
minify: isProduction,
14-
sourcemap: "linked",
15-
external
16+
format,
17+
minify: production,
18+
sourcemap: !production ? "linked" : false,
19+
platform,
20+
target: platform === "node" ? "node20" : "es2022",
21+
external: ["vscode", "fs", "path", "os"],
22+
// mainFields: platform === "node" ? ["main", "module"] : undefined, // https://github.com/microsoft/node-jsonc-parser/issues/57
23+
logLevel: production ? "silent" : "info",
24+
write: !plugins.some(p => p.name === "replace-after-transform"),
25+
plugins: [
26+
...plugins,
27+
esbuildProblemMatcherPlugin,
28+
],
1629
});
30+
if (watch) {
31+
await ctx.watch();
32+
} else {
33+
await ctx.rebuild();
34+
await ctx.dispose();
35+
}
1736
}
1837

38+
const esbuildProblemMatcherPlugin = {
39+
name: "esbuild-problem-matcher",
40+
41+
setup(build) {
42+
build.onStart(() => {
43+
console.log("[watch] build started");
44+
});
45+
build.onEnd((result) => {
46+
result.errors.forEach(({ text, location }) => {
47+
console.error(`✘ [ERROR] ${text}`);
48+
console.error(` ${location.file}:${location.line}:${location.column}:`);
49+
});
50+
console.log("[watch] build finished");
51+
});
52+
},
53+
};
54+
1955
function replaceAfterTransform() {
2056
return {
2157
name: "replace-after-transform",
2258
setup(build) {
2359
build.onEnd((result) => {
60+
console.log("replace-after-transform");
2461
result?.outputFiles?.forEach(file => {
62+
console.log(file.path);
2563
if (file.path.endsWith(".js")) {
2664
const contents = file.text.replace(/"use strict";/g, "");
2765
if (contents.indexOf("use strict") >= 0) {
@@ -37,34 +75,88 @@ function replaceAfterTransform() {
3775
};
3876
}
3977

40-
export function browserTpl(input, output, format = "esm", globalName = undefined, external = []) {
41-
return buildWatch({
42-
entryPoints: [input],
43-
outfile: `${output}.js`,
44-
platform: "browser",
45-
target: "es2022",
46-
format,
47-
globalName,
48-
bundle: true,
49-
minify: isProduction,
50-
sourcemap: "linked",
51-
external,
52-
write: false,
53-
plugins: [replaceAfterTransform()],
54-
});
55-
}
78+
Promise.all([
79+
main("./src/extension.ts", "node", "cjs", [
80+
copyStaticFiles({
81+
src: "./node_modules/@hpcc-js/ddl-shim/schema/v2.json",
82+
dest: path.join(outputDirectory, "v2.json"),
83+
})
84+
]),
85+
main("./src/notebook/renderers/wuRenderer.tsx", "node", "cjs"),
86+
main("./src/notebook/renderers/ojsRenderer.ts", "node", "cjs"),
87+
main("./src/eclwatch.tsx", "browser", "iife", [replaceAfterTransform()])
88+
]).catch((e) => {
89+
console.error(e);
90+
process.exit(1);
91+
});
92+
93+
// import { writeFileSync } from "fs";
94+
// import { buildWatch, isProduction } from "@hpcc-js/esbuild-plugins";
95+
// import { aliasPath } from "esbuild-plugin-alias-path";
96+
97+
// export function nodeTpl(input, output, format = "esm", external = []) {
98+
// return buildWatch({
99+
// entryPoints: [input],
100+
// outfile: `${output}.js`,
101+
// platform: "node",
102+
// target: "node20",
103+
// format,
104+
// bundle: true,
105+
// minify: isProduction,
106+
// sourcemap: "linked",
107+
// external
108+
// });
109+
// }
56110

57-
// config ---
58-
nodeTpl("src/extension.ts", "dist/extension", "cjs", ["vscode", "fs"]);
59-
nodeTpl("src/notebook/renderers/wuRenderer.tsx", "dist/notebook/renderers/wuRenderer", "cjs", ["vscode", "fs", "path", "os"]);
60-
nodeTpl("src/notebook/renderers/ojsRenderer.ts", "dist/notebook/renderers/ojsRenderer", "cjs", ["vscode", "fs", "path", "os"]);
61-
nodeTpl("src/debugger.ts", "dist/debugger", "cjs", ["vscode"]);
111+
// function replaceAfterTransform() {
112+
// return {
113+
// name: "replace-after-transform",
114+
// setup(build) {
115+
// build.onEnd((result) => {
116+
// result?.outputFiles?.forEach(file => {
117+
// if (file.path.endsWith(".js")) {
118+
// const contents = file.text.replace(/"use strict";/g, "");
119+
// if (contents.indexOf("use strict") >= 0) {
120+
// console.error("use strict: ", file.path);
121+
// }
122+
// writeFileSync(file.path, contents, { encoding: "utf8" });
123+
// } else {
124+
// writeFileSync(file.path, file.contents, { encoding: "binary" });
125+
// }
126+
// });
127+
// });
128+
// }
129+
// };
130+
// }
62131

63-
const ctx = await browserTpl("src/eclwatch.tsx", "dist/eclwatch", "iife");
64-
// if (isServe) {
65-
// ctx.serve({ servedir: "." }).then(({ host, port }) => {
66-
// console.log(`http://localhost:${port}`);
132+
// export function browserTpl(input, output, format = "esm", globalName = undefined, external = []) {
133+
// return buildWatch({
134+
// entryPoints: [input],
135+
// outfile: `${output}.js`,
136+
// platform: "browser",
137+
// target: "es2022",
138+
// format,
139+
// globalName,
140+
// bundle: true,
141+
// minify: isProduction,
142+
// sourcemap: "linked",
143+
// external,
144+
// write: false,
145+
// plugins: [replaceAfterTransform()],
67146
// });
68147
// }
69-
// browserTpl("src/web-extension.ts", "dist-web/extension", "esm", undefined, ["vscode", "fs", "path", "os"]);
148+
149+
// // config ---
150+
// nodeTpl("src/extension.ts", "dist/extension", "cjs", ["vscode", "fs"]);
151+
// nodeTpl("src/notebook/renderers/wuRenderer.tsx", "dist/notebook/renderers/wuRenderer", "cjs", ["vscode", "fs", "path", "os"]);
152+
// nodeTpl("src/notebook/renderers/ojsRenderer.ts", "dist/notebook/renderers/ojsRenderer", "cjs", ["vscode", "fs", "path", "os"]);
153+
// nodeTpl("src/debugger.ts", "dist/debugger", "cjs", ["vscode"]);
154+
155+
// const ctx = await browserTpl("src/eclwatch.tsx", "dist/eclwatch", "iife");
156+
// // if (isServe) {
157+
// // ctx.serve({ servedir: "." }).then(({ host, port }) => {
158+
// // console.log(`http://localhost:${port}`);
159+
// // });
160+
// // }
161+
// // browserTpl("src/web-extension.ts", "dist-web/extension", "esm", undefined, ["vscode", "fs", "path", "os"]);
70162

package-lock.json

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

package.json

+12-11
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,24 @@
1616
"browser": "./dist-web/extension",
1717
"scripts": {
1818
"clean": "rimraf --glob out lib* dist* types hpcc-systems.ecl.vsix",
19-
"copy-res": "copyfiles -f ./node_modules/@hpcc-js/ddl-shim/schema/v2.json ./dist",
2019
"gen-grammar": "wsl -e ./scripts/grammar-generate.sh",
2120
"gen-nls": "node ./lib-util/generate.js",
2221
"merge-nls": "node ./lib-util/merge.js",
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",
22+
"gen-extension-types": "tsc --project tsconfig.extension.json --emitDeclarationOnly",
23+
"gen-extension-watch": "npm run gen-extension-types -- -w",
24+
"gen-webview-types": "tsc --project tsconfig.webview.json --emitDeclarationOnly",
25+
"gen-webview-watch": "npm run gen-webview-types -- -w",
26+
"gen-types": "run-p gen-extension-types gen-webview-types",
2827
"compile-util": "tsc --project ./tsconfig.util.json",
2928
"compile-util-watch": "npm run compile-util -- -w",
30-
"compile": "run-p compile-types compile-ts",
31-
"build": "run-s copy-res compile",
32-
"watch": "run-p compile-esbuild-watch bundle-esbuild-dev-watch",
29+
"build-ts": "node esbuild.mjs --production",
30+
"build-ts-dev": "node esbuild.mjs",
31+
"build-ts-watch": "node esbuild.mjs --watch",
32+
"build": "run-p gen-types build-ts",
33+
"watch": "run-p gen-types-watch build-ts-watch",
3334
"lint": "eslint ./src",
3435
"lint-fix": "npm run lint -- --fix",
35-
"test": "npm run compile",
36+
"test": "npm run build",
3637
"standard-version": "standard-version",
3738
"vscode:prepublish": "run-s clean build",
3839
"git-push": "git push --follow-tags upstream trunk",
@@ -88,7 +89,7 @@
8889
"csv-writer": "1.6.0",
8990
"diff": "5.2.0",
9091
"esbuild": "0.23.0",
91-
"esbuild-plugin-alias-path": "^2.0.2",
92+
"esbuild-copy-static-files": "0.1.0",
9293
"esbuild-plugin-text-replace": "1.3.0",
9394
"esbuild-plugin-umd-wrapper": "3.0.0",
9495
"eslint": "8.57.0",

src/ecl/chatPlay.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ export class PlayPrompt extends PromptElement<PromptProps, PromptState> {
1717
}
1818

1919
render(state: PromptState, sizing: PromptSizing): Promise<PromptPiece | undefined> | PromptPiece | undefined {
20-
return (
20+
21+
const retVal = (
2122
<>
2223
<AssistantMessage>
2324
You are an ECL expert.<br />
@@ -32,5 +33,6 @@ export class PlayPrompt extends PromptElement<PromptProps, PromptState> {
3233
</UserMessage>
3334
</>
3435
);
36+
return retVal;
3537
}
3638
}

0 commit comments

Comments
 (0)