@hpcc-js/esbuild-plugins 1.0.6 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,64 +1,63 @@
1
- {
2
- "name": "@hpcc-js/esbuild-plugins",
3
- "version": "1.0.6",
4
- "description": "Various esbuild plugins",
5
- "type": "module",
6
- "exports": {
7
- ".": {
8
- "types": "./types/index.d.ts",
9
- "default": "./dist/index.js"
10
- },
11
- "./sfx-wrapper": {
12
- "types": "./types/sfx-wrapper.d.ts",
13
- "default": "./dist/sfx-wrapper.js"
14
- }
15
- },
16
- "main": "./dist/index.js",
17
- "types": "./types/index.d.ts",
18
- "files": [
19
- "dist/**/*",
20
- "src/**/*",
21
- "types/**/*"
22
- ],
23
- "scripts": {
24
- "clean": "rimraf ./dist ./types",
25
- "build-types": "tsc --project tsconfig.json --emitDeclarationOnly",
26
- "build-types-watch": "npm run build-types -- --watch",
27
- "build-ts-dev": "esbuild ./src/index.ts --platform=node --format=esm --bundle --sourcemap --outfile=./dist/index.js",
28
- "build-ts": "npm run build-ts-dev -- --minify",
29
- "build-ts-watch": "npm run build-ts-dev -- --watch",
30
- "build-dev": "run-p build-types build-ts-dev",
31
- "build-sfx-wrapper-dev": "esbuild ./src/sfx-wrapper.ts --platform=node --format=esm --bundle --sourcemap --outfile=./dist/sfx-wrapper.js",
32
- "build-sfx-wrapper": "npm run build-sfx-wrapper-dev -- --minify",
33
- "build": "run-p build-types build-ts build-sfx-wrapper",
34
- "lint-skypack": "npx -y @skypack/package-check",
35
- "lint-eslint": "eslint src/**/*.ts",
36
- "lint": "run-p lint-eslint lint-skypack",
37
- "test-cli": "npx . -v",
38
- "test-cli-help": "npx .",
39
- "test-node": "npx . -v",
40
- "update": "npx --yes npm-check-updates -u -t minor"
41
- },
42
- "dependencies": {
43
- "yargs": "17.7.2",
44
- "fzstd": "0.1.1"
45
- },
46
- "devDependencies": {
47
- "@hpcc-js/wasm-base91": "1.0.1",
48
- "@hpcc-js/wasm-zstd": "1.0.1"
49
- },
50
- "keywords": [
51
- "esbuild",
52
- "plugins",
53
- "WebAssembly",
54
- "wasm",
55
- "sfx"
56
- ],
57
- "author": "hpcc-systems",
58
- "repository": {
59
- "type": "git",
60
- "url": "git+https://github.com/hpcc-systems/hpcc-js-wasm.git"
61
- },
62
- "homepage": "https://hpcc-systems.github.io/hpcc-js-wasm/",
63
- "license": "Apache-2.0"
1
+ {
2
+ "name": "@hpcc-js/esbuild-plugins",
3
+ "version": "1.0.8",
4
+ "description": "Various esbuild plugins",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./types/index.d.ts",
9
+ "default": "./dist/index.js"
10
+ },
11
+ "./sfx-wrapper": {
12
+ "types": "./types/sfx-wrapper.d.ts",
13
+ "default": "./dist/sfx-wrapper.js"
14
+ }
15
+ },
16
+ "main": "./dist/index.js",
17
+ "types": "./types/index.d.ts",
18
+ "files": [
19
+ "dist/**/*",
20
+ "src/**/*",
21
+ "types/**/*"
22
+ ],
23
+ "scripts": {
24
+ "clean": "rimraf ./dist ./types",
25
+ "build-types": "tsc --project tsconfig.json --emitDeclarationOnly",
26
+ "build-types-watch": "npm run build-types -- --watch",
27
+ "build-ts-dev": "esbuild ./src/index.ts --platform=node --format=esm --bundle --packages=external --sourcemap --outfile=./dist/index.js",
28
+ "build-ts": "npm run build-ts-dev -- --minify",
29
+ "build-ts-watch": "npm run build-ts-dev -- --watch",
30
+ "build-dev": "run-p build-types build-ts-dev",
31
+ "build-sfx-wrapper-dev": "esbuild ./src/sfx-wrapper.ts --platform=node --format=esm --bundle --packages=external --sourcemap --outfile=./dist/sfx-wrapper.js",
32
+ "build-sfx-wrapper": "npm run build-sfx-wrapper-dev -- --minify",
33
+ "build": "run-p build-types build-ts build-sfx-wrapper",
34
+ "lint-skypack": "npx -y @skypack/package-check",
35
+ "lint-eslint": "eslint src/**/*.ts",
36
+ "lint": "run-p lint-eslint lint-skypack",
37
+ "test-cli": "npx . -v",
38
+ "test-cli-help": "npx .",
39
+ "test-node": "npx . -v",
40
+ "update": "npx --yes npm-check-updates -u -t minor"
41
+ },
42
+ "dependencies": {
43
+ "@hpcc-js/wasm-base91": "1.0.1",
44
+ "@hpcc-js/wasm-zstd": "1.0.1",
45
+ "yargs": "17.7.2",
46
+ "fzstd": "0.1.1"
47
+ },
48
+ "devDependencies": {},
49
+ "keywords": [
50
+ "esbuild",
51
+ "plugins",
52
+ "WebAssembly",
53
+ "wasm",
54
+ "sfx"
55
+ ],
56
+ "author": "hpcc-systems",
57
+ "repository": {
58
+ "type": "git",
59
+ "url": "git+https://github.com/hpcc-systems/hpcc-js-wasm.git"
60
+ },
61
+ "homepage": "https://hpcc-systems.github.io/hpcc-js-wasm/",
62
+ "license": "Apache-2.0"
64
63
  }
package/src/build.ts CHANGED
@@ -1,140 +1,143 @@
1
- import * as process from "process";
2
- import { readFileSync } from "fs";
3
- import * as path from "path";
4
- import * as esbuild from "esbuild";
5
- import type { BuildOptions, Format } from "esbuild";
6
- import { umdWrapper } from "esbuild-plugin-umd-wrapper";
7
- import yargs from "yargs";
8
- import { hideBin } from "yargs/helpers";
9
- import { rebuildLogger } from "./rebuild-logger.ts";
10
- import { sfxWasm } from "./sfx-wrapper.ts";
11
-
12
- const pkg = JSON.parse(readFileSync(path.join(process.cwd(), "./package.json"), "utf8"));
13
- const NODE_MJS = pkg.type === "module" ? "js" : "mjs";
14
- const NODE_CJS = pkg.type === "module" ? "cjs" : "js";
15
-
16
- const myYargs = yargs(hideBin(process.argv));
17
- myYargs
18
- .usage("Usage: node esbuild.mjs [options]")
19
- .demandCommand(0, 0)
20
- .example("node esbuild.mjs --watch", "Bundle and watch for changes")
21
- .option("mode", {
22
- alias: "m",
23
- describe: "Build mode",
24
- choices: ["development", "production"],
25
- default: "production"
26
- })
27
- .option("w", {
28
- alias: "watch",
29
- describe: "Watch for changes",
30
- type: "boolean"
31
- })
32
- .help("h")
33
- .alias("h", "help")
34
- .epilog("https://github.com/hpcc-systems/hpcc-js-wasm")
35
- ;
36
- const argv = await myYargs.argv;
37
- const isDevelopment = argv.mode === "development";
38
- const isProduction = !isDevelopment;
39
- const isWatch = argv.watch;
40
-
41
- export function build(config: BuildOptions) {
42
- if (isDevelopment && Array.isArray(config.entryPoints)) {
43
- console.log("Start: ", config.entryPoints[0], config.outfile);
44
- }
45
- return esbuild.build({
46
- ...config,
47
- sourcemap: "linked",
48
- plugins: [
49
- ...(config.plugins ?? []),
50
- sfxWasm()
51
- ]
52
- }).finally(() => {
53
- if (isDevelopment && Array.isArray(config.entryPoints)) {
54
- console.log("Stop: ", config.entryPoints[0], config.outfile);
55
- }
56
- });
57
- }
58
-
59
- export async function watch(config: BuildOptions) {
60
- await build(config);
61
- return esbuild.context({
62
- ...config,
63
- sourcemap: "external",
64
- plugins: [
65
- ...(config.plugins ?? []),
66
- rebuildLogger(config),
67
- sfxWasm()
68
- ]
69
- }).then(ctx => {
70
- return ctx.watch();
71
- });
72
- }
73
-
74
- export function buildWatch(config: BuildOptions) {
75
- return isWatch ? watch(config) : build(config);
76
- }
77
-
78
- export function browserTpl(input: string, output: string, format: Format | "umd" = "esm", globalName?: string, external: string[] = []) {
79
- return buildWatch({
80
- entryPoints: [input],
81
- outfile: `${output}.${format === "esm" ? "js" : "umd.js"}`,
82
- platform: "browser",
83
- target: "es2022",
84
- format: format as Format,
85
- globalName,
86
- bundle: true,
87
- minify: isProduction,
88
- external,
89
- plugins: format === "umd" ? [umdWrapper()] : []
90
- });
91
- }
92
-
93
- export function browserBoth(input: string, output: string, globalName?: string, external: string[] = []) {
94
- return Promise.all([
95
- browserTpl(input, output, "esm", globalName, external),
96
- browserTpl(input, output, "umd", globalName, external)
97
- ]);
98
- }
99
-
100
- export function nodeTpl(input: string, output: string, format: Format | "umd" = "esm", external: string[] = []) {
101
- return buildWatch({
102
- entryPoints: [input],
103
- outfile: `${output}.${format === "esm" ? NODE_MJS : NODE_CJS}`,
104
- platform: "node",
105
- target: "node20",
106
- format: format as Format,
107
- bundle: true,
108
- minify: isProduction,
109
- external
110
- });
111
- }
112
-
113
- export function neutralTpl(input: string, output: string, format: Format | "umd" = "esm", globalName?: string, external: string[] = []) {
114
- return buildWatch({
115
- entryPoints: [input],
116
- outfile: `${output}.${format === "esm" ? "js" : "umd.js"}`,
117
- platform: "neutral",
118
- target: "es2022",
119
- format: format as Format,
120
- globalName,
121
- bundle: true,
122
- minify: isProduction,
123
- external,
124
- plugins: format === "umd" ? [umdWrapper()] : []
125
- });
126
- }
127
-
128
- export function nodeBoth(input: string, output: string, external: string[] = []) {
129
- return Promise.all([
130
- nodeTpl(input, output, "esm", external),
131
- nodeTpl(input, output, "cjs", external)
132
- ]);
133
- }
134
-
135
- export function bothTpl(input: string, output: string, globalName?: string, external: string[] = []) {
136
- return Promise.all([
137
- browserBoth(input, output, globalName, external),
138
- nodeTpl(input, output, "cjs", external)
139
- ]);
140
- }
1
+ import * as process from "process";
2
+ import { readFileSync } from "fs";
3
+ import * as path from "path";
4
+ import * as esbuild from "esbuild";
5
+ import type { BuildOptions, Format } from "esbuild";
6
+ import { umdWrapper } from "esbuild-plugin-umd-wrapper";
7
+ import yargs from "yargs";
8
+ import { hideBin } from "yargs/helpers";
9
+ import { rebuildLogger } from "./rebuild-logger.ts";
10
+ import { sfxWasm } from "./sfx-wrapper.ts";
11
+
12
+ const myYargs = yargs(hideBin(process.argv));
13
+ myYargs
14
+ .usage("Usage: node esbuild.mjs [options]")
15
+ .demandCommand(0, 0)
16
+ .example("node esbuild.mjs --watch", "Bundle and watch for changes")
17
+ .option("mode", {
18
+ alias: "m",
19
+ describe: "Build mode",
20
+ choices: ["development", "production"],
21
+ default: "production"
22
+ })
23
+ .option("w", {
24
+ alias: "watch",
25
+ describe: "Watch for changes",
26
+ type: "boolean"
27
+ })
28
+ .help("h")
29
+ .alias("h", "help")
30
+ .epilog("https://github.com/hpcc-systems/hpcc-js-wasm")
31
+ ;
32
+
33
+ export const pkg = JSON.parse(readFileSync(path.join(process.cwd(), "./package.json"), "utf8"));
34
+ export const NODE_MJS = pkg.type === "module" ? "js" : "mjs";
35
+ export const NODE_CJS = pkg.type === "module" ? "cjs" : "js";
36
+
37
+ export const argv = await myYargs.argv;
38
+ export const isDevelopment = argv.mode === "development";
39
+ export const isProduction = !isDevelopment;
40
+ export const isWatch = argv.watch;
41
+
42
+ export function build(config: BuildOptions) {
43
+ if (isDevelopment && Array.isArray(config.entryPoints)) {
44
+ // eslint-disable-next-line no-console
45
+ console.log("Start: ", config.entryPoints[0], config.outfile);
46
+ }
47
+ return esbuild.build({
48
+ sourcemap: "linked",
49
+ ...config,
50
+ plugins: [
51
+ ...(config.plugins ?? []),
52
+ sfxWasm()
53
+ ]
54
+ }).finally(() => {
55
+ if (isDevelopment && Array.isArray(config.entryPoints)) {
56
+ // eslint-disable-next-line no-console
57
+ console.log("Stop: ", config.entryPoints[0], config.outfile);
58
+ }
59
+ });
60
+ }
61
+
62
+ export async function watch(config: BuildOptions) {
63
+ await build(config);
64
+ return esbuild.context({
65
+ sourcemap: "external",
66
+ ...config,
67
+ plugins: [
68
+ ...(config.plugins ?? []),
69
+ rebuildLogger(config),
70
+ sfxWasm()
71
+ ]
72
+ }).then(ctx => {
73
+ return ctx.watch();
74
+ });
75
+ }
76
+
77
+ export function buildWatch(config: BuildOptions) {
78
+ return isWatch ? watch(config) : build(config);
79
+ }
80
+
81
+ export function browserTpl(input: string, output: string, format: Format | "umd" = "esm", globalName?: string, external: string[] = []) {
82
+ return buildWatch({
83
+ entryPoints: [input],
84
+ outfile: `${output}.${format === "esm" ? "js" : "umd.js"}`,
85
+ platform: "browser",
86
+ target: "es2022",
87
+ format: format as Format,
88
+ globalName,
89
+ bundle: true,
90
+ minify: isProduction,
91
+ external,
92
+ plugins: format === "umd" ? [umdWrapper({ libraryName: globalName })] : []
93
+ });
94
+ }
95
+
96
+ export function browserBoth(input: string, output: string, globalName?: string, external: string[] = []) {
97
+ return Promise.all([
98
+ browserTpl(input, output, "esm", globalName, external),
99
+ browserTpl(input, output, "umd", globalName, external)
100
+ ]);
101
+ }
102
+
103
+ export function nodeTpl(input: string, output: string, format: Format | "umd" = "esm", external: string[] = []) {
104
+ return buildWatch({
105
+ entryPoints: [input],
106
+ outfile: `${output}.${format === "esm" ? NODE_MJS : NODE_CJS}`,
107
+ platform: "node",
108
+ target: "node20",
109
+ format: format as Format,
110
+ bundle: true,
111
+ minify: isProduction,
112
+ external
113
+ });
114
+ }
115
+
116
+ export function neutralTpl(input: string, output: string, format: Format | "umd" = "esm", globalName?: string, external: string[] = []) {
117
+ return buildWatch({
118
+ entryPoints: [input],
119
+ outfile: `${output}.${format === "esm" ? "js" : "umd.js"}`,
120
+ platform: "neutral",
121
+ target: "es2022",
122
+ format: format as Format,
123
+ globalName,
124
+ bundle: true,
125
+ minify: isProduction,
126
+ external,
127
+ plugins: format === "umd" ? [umdWrapper()] : []
128
+ });
129
+ }
130
+
131
+ export function nodeBoth(input: string, output: string, external: string[] = []) {
132
+ return Promise.all([
133
+ nodeTpl(input, output, "esm", external),
134
+ nodeTpl(input, output, "cjs", external)
135
+ ]);
136
+ }
137
+
138
+ export function bothTpl(input: string, output: string, globalName?: string, external: string[] = []) {
139
+ return Promise.all([
140
+ browserBoth(input, output, globalName, external),
141
+ nodeTpl(input, output, "cjs", external)
142
+ ]);
143
+ }
@@ -1,20 +1,20 @@
1
- import { readFile } from "fs/promises";
2
- import type { PluginBuild, Plugin } from "esbuild";
3
-
4
- export interface ExcludeSourcemapOptions {
5
- filter: RegExp;
6
- }
7
- export function excludeSourcemap(opts: ExcludeSourcemapOptions): Plugin {
8
- return {
9
- name: "exclude-sourcemap",
10
-
11
- setup(build: PluginBuild) {
12
- build.onLoad({ filter: opts.filter }, async args => {
13
- return {
14
- contents: await readFile(args.path, "utf8") + "\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==",
15
- loader: "default",
16
- };
17
- });
18
- },
19
- };
20
- }
1
+ import { readFile } from "fs/promises";
2
+ import type { PluginBuild, Plugin } from "esbuild";
3
+
4
+ export interface ExcludeSourcemapOptions {
5
+ filter: RegExp;
6
+ }
7
+ export function excludeSourcemap(opts: ExcludeSourcemapOptions): Plugin {
8
+ return {
9
+ name: "exclude-sourcemap",
10
+
11
+ setup(build: PluginBuild) {
12
+ build.onLoad({ filter: opts.filter }, async args => {
13
+ return {
14
+ contents: await readFile(args.path, "utf8") + "\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==",
15
+ loader: "default",
16
+ };
17
+ });
18
+ },
19
+ };
20
+ }
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
- export * from "./build.ts";
2
- export * from "./exclude-sourcemap.ts";
3
- export * from "./problem-matcher.ts";
4
- export * from "./rebuild-logger.ts";
5
- export * from "./sfx-wrapper.ts";
1
+ export * from "./build.ts";
2
+ export * from "./exclude-sourcemap.ts";
3
+ export * from "./problem-matcher.ts";
4
+ export * from "./rebuild-logger.ts";
5
+ export * from "./sfx-wrapper.ts";
@@ -1,22 +1,24 @@
1
- import type { PluginBuild, Plugin } from "esbuild";
2
-
3
- export function problemMatcher(): Plugin {
4
- return {
5
- name: "problem-matcher",
6
-
7
- setup(build: PluginBuild) {
8
-
9
- build.onStart(() => {
10
- console.log("[watch] build started");
11
- });
12
-
13
- build.onEnd((result) => {
14
- result.errors.forEach(({ text, location }) => {
15
- console.error(`✘ [ERROR] ${text}`);
16
- console.error(` ${location?.file}:${location?.line}:${location?.column}:`);
17
- });
18
- console.log("[watch] build finished");
19
- });
20
- }
21
- };
22
- }
1
+ import type { PluginBuild, Plugin } from "esbuild";
2
+
3
+ export function problemMatcher(): Plugin {
4
+ return {
5
+ name: "problem-matcher",
6
+
7
+ setup(build: PluginBuild) {
8
+
9
+ build.onStart(() => {
10
+ // eslint-disable-next-line no-console
11
+ console.log("[watch] build started");
12
+ });
13
+
14
+ build.onEnd((result) => {
15
+ result.errors.forEach(({ text, location }) => {
16
+ console.error(`✘ [ERROR] ${text}`);
17
+ console.error(` ${location?.file}:${location?.line}:${location?.column}:`);
18
+ });
19
+ // eslint-disable-next-line no-console
20
+ console.log("[watch] build finished");
21
+ });
22
+ }
23
+ };
24
+ }
@@ -1,22 +1,24 @@
1
- import type { PluginBuild, Plugin } from "esbuild";
2
-
3
- export interface RebuildLoggerOptions {
4
- outfile?: string;
5
- }
6
-
7
- export function rebuildLogger(opts: RebuildLoggerOptions): Plugin {
8
- return {
9
- name: "rebuild-logger",
10
-
11
- setup(build: PluginBuild) {
12
-
13
- build.onStart(() => {
14
- console.log("[watch] build started");
15
- });
16
-
17
- build.onEnd(() => {
18
- console.log(`Rebuilt ${opts.outfile ?? "Unknown"}`);
19
- });
20
- }
21
- };
22
- }
1
+ import type { PluginBuild, Plugin } from "esbuild";
2
+
3
+ export interface RebuildLoggerOptions {
4
+ outfile?: string;
5
+ }
6
+
7
+ export function rebuildLogger(opts: RebuildLoggerOptions): Plugin {
8
+ return {
9
+ name: "rebuild-logger",
10
+
11
+ setup(build: PluginBuild) {
12
+
13
+ build.onStart(() => {
14
+ // eslint-disable-next-line no-console
15
+ console.log("[watch] build started");
16
+ });
17
+
18
+ build.onEnd(() => {
19
+ // eslint-disable-next-line no-console
20
+ console.log(`Rebuilt ${opts.outfile ?? "Unknown"}`);
21
+ });
22
+ }
23
+ };
24
+ }