Skip to content

Commit a2672a4

Browse files
committed
WIP
1 parent a5b5409 commit a2672a4

21 files changed

+1144
-707
lines changed

.eslintrc.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ module.exports = {
33
root: true,
44
parser: "@typescript-eslint/parser",
55
plugins: [
6-
"@typescript-eslint",
6+
"@typescript-eslint"
77
],
88
extends: [
99
"eslint:recommended",
1010
"plugin:@typescript-eslint/recommended",
11+
"plugin:react-hooks/recommended"
1112
],
1213
env: {
1314
"browser": true,
@@ -20,7 +21,7 @@ module.exports = {
2021
"debugConfig": "readonly",
2122
"Promise": "readonly"
2223
},
23-
ignorePatterns: ["src/grammar"],
24+
ignorePatterns: ["src/grammar/**/*"],
2425
rules: {
2526
"no-redeclare": "off",
2627
"no-empty": "off",
@@ -92,6 +93,7 @@ module.exports = {
9293
],
9394
"@typescript-eslint/no-non-null-assertion": "off",
9495
"@typescript-eslint/no-namespace": "off",
95-
"@typescript-eslint/no-var-require": "off"
96+
"@typescript-eslint/no-var-require": "off",
97+
"@typescript-eslint/no-unsafe-declaration-merging": "off",
9698
}
97-
};
99+
};

.vscode/launch.json

+16
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@
6666
"${workspaceFolder}/dist/**/*.js"
6767
]
6868
},
69+
{
70+
"name": "Launch esbuild.mjs",
71+
"type": "node",
72+
"request": "launch",
73+
"program": "${workspaceFolder}/esbuild.mjs",
74+
"args": [
75+
"--mode=development"
76+
],
77+
},
6978
{
7079
"name": "Launch Server Adapter",
7180
"type": "node",
@@ -91,6 +100,13 @@
91100
],
92101
"webRoot": "${workspaceRoot}"
93102
},
103+
{
104+
"name": "http://webview-test",
105+
"type": "msedge",
106+
"request": "launch",
107+
"url": "http://localhost:8000/webview-test.html",
108+
"webRoot": "${workspaceRoot}"
109+
},
94110
{
95111
"name": "index",
96112
"type": "msedge",

esbuild.mjs

+47-135
Original file line numberDiff line numberDiff line change
@@ -1,157 +1,69 @@
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";
1+
import { writeFileSync } from "fs";
2+
import { buildWatch, isProduction } from "@hpcc-js/esbuild-plugins";
73

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;
32-
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 }) => ({
50-
name: "esbuild-problem-matcher",
51-
52-
setup(build) {
53-
build.onStart(() => {
54-
console.log("[watch] build started");
55-
});
56-
build.onEnd((result) => {
57-
result.errors.forEach(({ text, location }) => {
58-
console.error(`✘ [ERROR] ${text}`);
59-
console.error(` ${location.file}:${location.line}:${location.column}:`);
60-
});
61-
console.log("[watch] build finished");
62-
});
63-
},
64-
});
65-
66-
// helpers ---
67-
function build(config) {
68-
isDevelopment && console.log("Start: ", config.entryPoints[0], config.outfile);
69-
return esbuild.build({
70-
...config,
4+
export function nodeTpl(input, output, format = "esm", external = []) {
5+
return buildWatch({
6+
entryPoints: [input],
7+
outfile: `${output}.js`,
8+
platform: "node",
9+
target: "node20",
10+
format,
11+
bundle: true,
12+
minify: isProduction,
7113
sourcemap: "linked",
72-
plugins: [
73-
...config.plugins ?? [],
74-
]
75-
}).then(() => {
76-
isDevelopment && console.log("Stop: ", config.entryPoints[0], config.outfile);
14+
external
7715
});
7816
}
7917

80-
function watch(config) {
81-
return esbuild.context({
82-
...config,
83-
sourcemap: "linked",
84-
plugins: [
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();
97-
});
18+
function replaceAfterTransform() {
19+
return {
20+
name: "replace-after-transform",
21+
setup(build) {
22+
build.onEnd((result) => {
23+
result?.outputFiles?.forEach(file => {
24+
if (file.path.endsWith(".js")) {
25+
const contents = file.text.replace(/"use strict";/g, "");
26+
if (contents.indexOf("use strict") >= 0) {
27+
console.error("use strict: ", file.path);
28+
}
29+
writeFileSync(file.path, contents, { encoding: "utf8" });
30+
} else {
31+
writeFileSync(file.path, file.contents, { encoding: "binary" });
32+
}
33+
});
34+
});
35+
}
36+
};
9837
}
9938

100-
function browserTpl(input, output, format, globalName = "", external = []) {
101-
return (isWatch ? watch : build)({
39+
export function browserTpl(input, output, format = "esm", globalName = undefined, external = []) {
40+
return buildWatch({
10241
entryPoints: [input],
103-
outfile: `${output}.${format === "esm" ? "js" : "umd.js"}`,
42+
outfile: `${output}.js`,
10443
platform: "browser",
10544
target: "es2022",
10645
format,
10746
globalName,
10847
bundle: true,
10948
minify: isProduction,
49+
sourcemap: "linked",
11050
external,
111-
plugins: format === "umd" ? [umdWrapper()] : []
51+
write: false,
52+
plugins: [replaceAfterTransform()],
11253
});
11354
}
11455

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
132-
});
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-
14956
// config ---
15057
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-
58+
nodeTpl("src/notebook/renderers/wuRenderer.tsx", "dist/notebook/renderers/wuRenderer", "cjs", ["vscode", "fs", "path", "os"]);
59+
nodeTpl("src/notebook/renderers/ojsRenderer.ts", "dist/notebook/renderers/ojsRenderer", "cjs", ["vscode", "fs", "path", "os"]);
15460
nodeTpl("src/debugger.ts", "dist/debugger", "cjs", ["vscode"]);
15561

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"]);
62+
const ctx = await browserTpl("src/eclwatch.tsx", "dist/eclwatch", "iife");
63+
// if (isServe) {
64+
// ctx.serve({ servedir: "." }).then(({ host, port }) => {
65+
// console.log(`http://localhost:${port}`);
66+
// });
67+
// }
68+
// browserTpl("src/web-extension.ts", "dist-web/extension", "esm", undefined, ["vscode", "fs", "path", "os"]);
69+

0 commit comments

Comments
 (0)