Skip to content

Commit 0dbd604

Browse files
committed
fix: Improve type-leaks test
Was missing some node deps still in devDeps Signed-off-by: Gordon Smith <GordonJSmith@gmail.com>
1 parent 0dc9787 commit 0dbd604

15 files changed

Lines changed: 445 additions & 206 deletions

File tree

eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export default [
5252
max: 1
5353
}
5454
],
55-
"no-console": [1, {
55+
"no-console": ["error", {
5656
"allow": ["info", "warn", "error"]
5757
}],
5858
"func-call-spacing": ["error", "never"],

package-lock.json

Lines changed: 37 additions & 73 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"update-major": "run-p update-major-workspaces update-major root"
3636
},
3737
"devDependencies": {
38+
"@types/esbuild-copy-static-files": "0.1.4",
3839
"@typescript-eslint/eslint-plugin": "8.29.0",
3940
"@typescript-eslint/parser": "8.29.0",
4041
"@vitest/browser": "3.2.4",

packages/comms/esbuild.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import { nodeTpl, nodeBoth } from "@hpcc-js/esbuild-plugins";
22

33
// config ---
44
await Promise.all([
5-
nodeBoth("src/index.node.ts", "dist/node/index"),
5+
nodeBoth("src/index.node.ts", "dist/node/index", { packages: "bundle" }),
66
nodeTpl("utils/index.ts", "lib-esm/index")
77
]);

packages/comms/src/clienttools/eclMeta.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as fs from "fs";
2-
import * as path from "path";
1+
import * as fs from "node:fs";
2+
import * as path from "node:path";
33

44
import { Dictionary, DictionaryNoCase, find, SAXStackParser, scopedLogger, XMLNode } from "@hpcc-js/util";
55
import { ClientTools, locateClientTools } from "./eclcc.ts";

packages/comms/src/clienttools/eclcc.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import * as cp from "child_process";
2-
import * as fs from "fs";
3-
import * as os from "os";
4-
import * as path from "path";
1+
import * as cp from "node:child_process";
2+
import * as fs from "node:fs";
3+
import * as os from "node:os";
4+
import * as path from "node:path";
55
import * as tmp from "tmp";
66

77
import { exists, scopedLogger, xml2json, XMLNode } from "@hpcc-js/util";

packages/comms/src/ecl/scope.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import { StateObject, StringAnyMap } from "@hpcc-js/util";
2-
// import { utcFormat, utcParse } from "d3-time-format";
32
import { WsWorkunits } from "../services/wsWorkunits.ts";
43
import { Workunit } from "./workunit.ts";
54

6-
// const formatter = utcFormat("%Y-%m-%dT%H:%M:%S.%LZ");
7-
// const parser = utcParse("%Y-%m-%dT%H:%M:%S.%LZ");
8-
95
export interface AttributeEx extends WsWorkunits.Property {
106
FormattedEnd?: string;
117
}

packages/comms/src/index.node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ root.DOMParser = DOMParser;
66
// fetch polyfill ---
77
import fetch, { Headers, Request, Response, } from "node-fetch";
88

9-
import * as https from "https";
9+
import * as https from "node:https";
1010
import { Agent, setGlobalDispatcher } from "undici";
1111

1212
if (typeof root.fetch === "undefined") {

packages/esbuild-plugins/src/build.ts

Lines changed: 84 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@ import * as path from "path";
44
import * as esbuild from "esbuild";
55
import type { BuildOptions, Format, Loader, Plugin } from "esbuild";
66
import { umdWrapper } from "esbuild-plugin-umd-wrapper";
7+
import * as copyStaticFiles from "esbuild-copy-static-files";
78
import { inlineCSS } from "./inline-css.ts";
89
import { rebuildLogger } from "./rebuild-logger.ts";
910

10-
//@ts-ignore
11-
import _copyStaticFiles from "esbuild-copy-static-files";
12-
export const copyStaticFiles: Plugin = _copyStaticFiles;
11+
export { copyStaticFiles };
1312

1413
export const pkg = JSON.parse(readFileSync(path.join(process.cwd(), "./package.json"), "utf8"));
1514
export const NODE_MJS = pkg.type === "module" ? "js" : "mjs";
1615
export const NODE_CJS = pkg.type === "module" ? "cjs" : "js";
1716

18-
export async function buildWatch(input: string, format: Format | "umd" = "esm", external: string[] = [], config: BuildOptions, isDevelopment: boolean = process.argv.includes("--development"), isWatch: boolean = process.argv.includes("--watch")): Promise<void> {
17+
export async function buildWatch(inputs: string[] | Record<string, string> | { in: string, out: string }[], config: BuildOptions): Promise<void> {
18+
const isDevelopment = process.argv.includes("--development");
19+
const isWatch = process.argv.includes("--watch");
1920
const isProduction = !isDevelopment;
21+
2022
if (isProduction && existsSync(path.join(process.cwd(), "../../package.json"))) {
2123
const rootPkg = JSON.parse(readFileSync(path.join(process.cwd(), "../../package.json"), "utf8"));
2224
writeFileSync(path.join(process.cwd(), "src/__package__.ts"), `\
@@ -26,20 +28,38 @@ export const BUILD_VERSION = "${rootPkg.version}";
2628
`, "utf8");
2729
}
2830

29-
const ctx = await esbuild.context({
30-
entryPoints: [input],
31-
format: format as Format,
31+
config = {
32+
entryPoints: inputs,
33+
format: "esm",
3234
bundle: true,
3335
minify: isProduction,
3436
sourcemap: true,
35-
external,
37+
external: [
38+
...config.external ?? []
39+
],
3640
...config,
41+
loader: {
42+
...config.loader
43+
},
44+
outExtension: {
45+
...config.outExtension
46+
},
47+
banner: {
48+
...config.banner
49+
},
50+
footer: {
51+
...config.footer
52+
},
3753
plugins: [
3854
...(isWatch ? [rebuildLogger(config)] : []),
39-
...(config.plugins ?? []),
55+
...config.plugins ?? [],
4056
inlineCSS()
57+
],
58+
nodePaths: [
59+
...config.nodePaths ?? []
4160
]
42-
});
61+
};
62+
const ctx = await esbuild.context(config);
4363

4464
if (isWatch) {
4565
await ctx.watch();
@@ -68,35 +88,54 @@ export type TplOptions = {
6888
supported?: Record<string, boolean>;
6989
alias?: Record<string, string>;
7090
define?: { [key: string]: string };
91+
packages?: "bundle" | "external" | "auto";
7192
};
7293

73-
export function browserTpl(input: string, output: string, { format = "esm", globalName, libraryName, keepNames, external = [], plugins = [], alias = {}, define = {}, loader = {} }: TplOptions = {}) {
74-
return buildWatch(input, format, external, {
75-
outfile: `${output}.${format === "esm" ? "js" : `${format}.js`}`,
94+
function autoExternal(external?: string[]): string[] {
95+
return [
96+
...pkg.dependencies ? Object.keys(pkg.dependencies) : [], ...pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : [],
97+
...external ?? []
98+
];
99+
}
100+
101+
export function browserTpl(input: string, output: string, options: TplOptions = {}) {
102+
options.format = options.format ?? "esm";
103+
104+
return buildWatch([input], {
105+
format: options.format === "umd" ? "esm" : options.format,
106+
external: options.external ?? [],
107+
outfile: `${output}.${options.format === "esm" ? "js" : `${options.format}.js`}`,
76108
platform: "browser",
77109
target: "es2022",
78-
globalName,
79-
keepNames,
80-
plugins: format === "umd" ? [umdWrapper({ libraryName }), ...plugins] : [...plugins],
81-
alias,
82-
define,
83-
loader
84-
} as BuildOptions);
110+
globalName: options.globalName,
111+
keepNames: options.keepNames,
112+
plugins: options.format === "umd" ? [umdWrapper({ libraryName: options.libraryName }), ...options.plugins ?? []] : [...options.plugins ?? []],
113+
alias: options.alias,
114+
define: options.define,
115+
loader: options.loader,
116+
});
85117
}
86118

87-
export function nodeTpl(input: string, output: string, { format = "esm", external = [], supported = {} }: TplOptions = {}) {
88-
return buildWatch(input, format, external, {
89-
outfile: `${output}.${format === "esm" ? NODE_MJS : NODE_CJS}`,
119+
export function nodeTpl(input: string, output: string, options: TplOptions = {}) {
120+
options.packages = options.packages ?? "external";
121+
if (options.packages === "auto") {
122+
options.external = autoExternal(options.external);
123+
}
124+
125+
return buildWatch([input], {
126+
format: options.format === "umd" ? "esm" : options.format,
127+
outfile: `${output}.${options.format === "esm" ? NODE_MJS : NODE_CJS}`,
90128
platform: "node",
91-
target: "node20",
92-
packages: "external",
93-
supported
129+
target: "node22",
130+
packages: options.packages === "auto" ? "bundle" : options.packages,
94131
});
95132
}
96133

97-
export function neutralTpl(input: string, output: string, { format = "esm", globalName, libraryName, keepNames, external = [] }: TplOptions = {}) {
134+
export function neutralTpl(input: string, output: string, options: TplOptions = {}) {
135+
options.format = options.format ?? "esm";
136+
98137
let postfix = "";
99-
switch (format) {
138+
switch (options.format) {
100139
case "iife":
101140
postfix = "iife.js";
102141
break;
@@ -110,35 +149,36 @@ export function neutralTpl(input: string, output: string, { format = "esm", glob
110149
postfix = "umd.js";
111150
break;
112151
default:
113-
throw new Error(`Unknown format: ${format}`);
152+
throw new Error(`Unknown format: ${options.format}`);
114153
}
115-
return buildWatch(input, format, external, {
116-
outfile: `${output}.${format === "esm" ? "js" : `${format}.js`}`,
154+
return buildWatch([input], {
155+
format: options.format === "umd" ? "esm" : options.format,
156+
outfile: `${output}.${options.format === "esm" ? "js" : `${options.format}.js`}`,
117157
platform: "neutral",
118158
target: "es2022",
119-
globalName,
120-
keepNames,
121-
plugins: format === "umd" ? [umdWrapper({ libraryName })] : [] as Plugin[]
122-
} as BuildOptions);
159+
globalName: options.globalName,
160+
keepNames: options.keepNames,
161+
plugins: options.format === "umd" ? [umdWrapper({ libraryName: options.libraryName })] : [] as Plugin[]
162+
});
123163
}
124164

125-
export function browserBoth(input: string, output: string, globalName?: string, libraryName?: string, external: string[] = []) {
165+
export function browserBoth(input: string, output: string, options: TplOptions = {}) {
126166
return Promise.all([
127-
browserTpl(input, output, { format: "esm", globalName, libraryName, external }),
128-
browserTpl(input, output, { format: "umd", globalName, libraryName, external })
167+
browserTpl(input, output, { format: "esm", ...options }),
168+
browserTpl(input, output, { format: "umd", ...options })
129169
]);
130170
}
131171

132-
export function nodeBoth(input: string, output: string, external: string[] = []) {
172+
export function nodeBoth(input: string, output: string, options: TplOptions = {}) {
133173
return Promise.all([
134-
nodeTpl(input, output, { format: "esm", external }),
135-
nodeTpl(input, output, { format: "cjs", external })
174+
nodeTpl(input, output, { format: "esm", ...options }),
175+
nodeTpl(input, output, { format: "cjs", ...options })
136176
]);
137177
}
138178

139-
export function bothTpl(input: string, output: string, globalName?: string, libraryName?: string, external: string[] = []) {
179+
export function bothTpl(input: string, output: string, options: TplOptions = {}) {
140180
return Promise.all([
141-
browserBoth(input, output, globalName, libraryName, external),
142-
nodeTpl(input, output, { format: "cjs", external })
181+
browserBoth(input, output, { ...options }),
182+
nodeTpl(input, output, { format: "cjs", ...options })
143183
]);
144184
}
Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
import { nodeTpl } from "@hpcc-js/esbuild-plugins";
2+
import pkg from "./package.json" with { type: "json" };
23

34
// config ---
45
await Promise.all([
5-
nodeTpl("src/loader.ts", "dist/loader.node", { supported: { "dynamic-import": true } }),
6-
nodeTpl("src/ecl-lang/index.ts", "dist/ecl-lang"),
6+
nodeTpl("src/loader.ts", "dist/loader.node", {
7+
packages: "bundle",
8+
supported: { "dynamic-import": true },
9+
external: [
10+
...Object.keys(pkg.dependencies || {}),
11+
...Object.keys(pkg.peerDependencies || {})
12+
]
13+
}),
14+
nodeTpl("src/ecl-lang/index.ts", "dist/ecl-lang", {
15+
packages: "bundle",
16+
external: [
17+
...Object.keys(pkg.dependencies || {}),
18+
...Object.keys(pkg.peerDependencies || {})
19+
]
20+
}),
721
]);

0 commit comments

Comments
 (0)