@zharp/esbuild-plugin 0.0.0-stage → 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Zharp
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,26 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # @zharp/esbuild-plugin
2
+
3
+ Readable stack traces for an esbuild build in [Zharp](https://zharp.io): it emits external source maps (unless `sourcemap` is set), injects debug IDs into the written JS files and their maps, uploads them, and deletes the maps from the output.
4
+
5
+ ```bash
6
+ npm install --save-dev @zharp/esbuild-plugin
7
+ ```
8
+
9
+ ```js
10
+ import * as esbuild from 'esbuild';
11
+ import { zharpEsbuildPlugin } from '@zharp/esbuild-plugin';
12
+
13
+ await esbuild.build({
14
+ entryPoints: ['src/app.ts'],
15
+ bundle: true,
16
+ minify: true,
17
+ outdir: 'dist',
18
+ plugins: [zharpEsbuildPlugin({ app: 42 })],
19
+ });
20
+ ```
21
+
22
+ The plugin turns on `metafile` to know which files the build wrote, and does nothing with `write: false`. It runs on every build; use `disabled` to limit it.
23
+
24
+ Options: see the [bundler plugins overview](../README.md#options).
25
+
26
+ MIT © [Zharp](https://zharp.io)
@@ -0,0 +1,28 @@
1
+ import { ZharpPluginOptions } from '@zharp/cli';
2
+ export { ZharpPluginOptions } from '@zharp/cli';
3
+
4
+ /** The parts of esbuild's plugin API this plugin uses (no dependency on esbuild's types). */
5
+ interface BuildOptions {
6
+ sourcemap?: boolean | 'linked' | 'inline' | 'external' | 'both';
7
+ metafile?: boolean;
8
+ write?: boolean;
9
+ outdir?: string;
10
+ outfile?: string;
11
+ absWorkingDir?: string;
12
+ }
13
+ interface BuildResult {
14
+ errors: unknown[];
15
+ metafile?: {
16
+ outputs: Record<string, unknown>;
17
+ };
18
+ }
19
+ interface PluginBuild {
20
+ initialOptions: BuildOptions;
21
+ onEnd(callback: (result: BuildResult) => void | Promise<void>): void;
22
+ }
23
+ declare function zharpEsbuildPlugin(options?: ZharpPluginOptions): {
24
+ name: string;
25
+ setup(build: PluginBuild): void;
26
+ };
27
+
28
+ export { zharpEsbuildPlugin as default, zharpEsbuildPlugin };
@@ -0,0 +1,28 @@
1
+ import { ZharpPluginOptions } from '@zharp/cli';
2
+ export { ZharpPluginOptions } from '@zharp/cli';
3
+
4
+ /** The parts of esbuild's plugin API this plugin uses (no dependency on esbuild's types). */
5
+ interface BuildOptions {
6
+ sourcemap?: boolean | 'linked' | 'inline' | 'external' | 'both';
7
+ metafile?: boolean;
8
+ write?: boolean;
9
+ outdir?: string;
10
+ outfile?: string;
11
+ absWorkingDir?: string;
12
+ }
13
+ interface BuildResult {
14
+ errors: unknown[];
15
+ metafile?: {
16
+ outputs: Record<string, unknown>;
17
+ };
18
+ }
19
+ interface PluginBuild {
20
+ initialOptions: BuildOptions;
21
+ onEnd(callback: (result: BuildResult) => void | Promise<void>): void;
22
+ }
23
+ declare function zharpEsbuildPlugin(options?: ZharpPluginOptions): {
24
+ name: string;
25
+ setup(build: PluginBuild): void;
26
+ };
27
+
28
+ export { zharpEsbuildPlugin as default, zharpEsbuildPlugin };
package/dist/index.js ADDED
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ default: () => index_default,
24
+ zharpEsbuildPlugin: () => zharpEsbuildPlugin
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+ var import_node_path = require("path");
28
+ var import_cli = require("@zharp/cli");
29
+ var JS = /\.(?:js|mjs|cjs)$/;
30
+ function zharpEsbuildPlugin(options = {}) {
31
+ return {
32
+ name: "zharp",
33
+ setup(build) {
34
+ if (options.disabled) return;
35
+ const initial = build.initialOptions;
36
+ if (!initial.sourcemap) initial.sourcemap = "external";
37
+ initial.metafile = true;
38
+ const logger = (0, import_cli.pluginLogger)("zharp", options);
39
+ build.onEnd(async (result) => {
40
+ if (result.errors.length || initial.write === false || !result.metafile) return;
41
+ const cwd = initial.absWorkingDir ?? process.cwd();
42
+ const dir = (0, import_node_path.resolve)(cwd, initial.outdir ?? (initial.outfile ? (0, import_node_path.dirname)(initial.outfile) : "."));
43
+ const files = Object.keys(result.metafile.outputs).filter((name) => JS.test(name)).map((name) => (0, import_node_path.resolve)(cwd, name));
44
+ await (0, import_cli.processBuildOutput)(dir, options, { files, logger });
45
+ });
46
+ }
47
+ };
48
+ }
49
+ var index_default = zharpEsbuildPlugin;
50
+ // Annotate the CommonJS export names for ESM import in node:
51
+ 0 && (module.exports = {
52
+ zharpEsbuildPlugin
53
+ });
54
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\r\n * @zharp/esbuild-plugin: after esbuild writes its output, inject debug IDs into the JS files and\r\n * their source maps, upload them to Zharp, and delete the maps from the output.\r\n *\r\n * await esbuild.build({ entryPoints: ['src/app.ts'], bundle: true, outdir: 'dist',\r\n * plugins: [zharpEsbuildPlugin({ app: 42 })] });\r\n */\r\nimport { dirname, resolve } from 'node:path';\r\nimport { pluginLogger, processBuildOutput, type ZharpPluginOptions } from '@zharp/cli';\r\n\r\nexport type { ZharpPluginOptions } from '@zharp/cli';\r\n\r\n/** The parts of esbuild's plugin API this plugin uses (no dependency on esbuild's types). */\r\ninterface BuildOptions {\r\n sourcemap?: boolean | 'linked' | 'inline' | 'external' | 'both';\r\n metafile?: boolean;\r\n write?: boolean;\r\n outdir?: string;\r\n outfile?: string;\r\n absWorkingDir?: string;\r\n}\r\ninterface BuildResult {\r\n errors: unknown[];\r\n metafile?: { outputs: Record<string, unknown> };\r\n}\r\ninterface PluginBuild {\r\n initialOptions: BuildOptions;\r\n onEnd(callback: (result: BuildResult) => void | Promise<void>): void;\r\n}\r\n\r\nconst JS = /\\.(?:js|mjs|cjs)$/;\r\n\r\nexport function zharpEsbuildPlugin(options: ZharpPluginOptions = {}) {\r\n return {\r\n name: 'zharp',\r\n setup(build: PluginBuild): void {\r\n if (options.disabled) return;\r\n const initial = build.initialOptions;\r\n // External maps: written next to the files, not referenced from them.\r\n if (!initial.sourcemap) initial.sourcemap = 'external';\r\n // The metafile is how the plugin knows which files this build wrote.\r\n initial.metafile = true;\r\n const logger = pluginLogger('zharp', options);\r\n build.onEnd(async (result) => {\r\n if (result.errors.length || initial.write === false || !result.metafile) return;\r\n const cwd = initial.absWorkingDir ?? process.cwd();\r\n const dir = resolve(cwd, initial.outdir ?? (initial.outfile ? dirname(initial.outfile) : '.'));\r\n const files = Object.keys(result.metafile.outputs)\r\n .filter((name) => JS.test(name))\r\n .map((name) => resolve(cwd, name));\r\n await processBuildOutput(dir, options, { files, logger });\r\n });\r\n },\r\n };\r\n}\r\n\r\nexport default zharpEsbuildPlugin;\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,uBAAiC;AACjC,iBAA0E;AAsB1E,IAAM,KAAK;AAEJ,SAAS,mBAAmB,UAA8B,CAAC,GAAG;AACnE,SAAO;AAAA,IACL,MAAM;AAAA,IACN,MAAM,OAA0B;AAC9B,UAAI,QAAQ,SAAU;AACtB,YAAM,UAAU,MAAM;AAEtB,UAAI,CAAC,QAAQ,UAAW,SAAQ,YAAY;AAE5C,cAAQ,WAAW;AACnB,YAAM,aAAS,yBAAa,SAAS,OAAO;AAC5C,YAAM,MAAM,OAAO,WAAW;AAC5B,YAAI,OAAO,OAAO,UAAU,QAAQ,UAAU,SAAS,CAAC,OAAO,SAAU;AACzE,cAAM,MAAM,QAAQ,iBAAiB,QAAQ,IAAI;AACjD,cAAM,UAAM,0BAAQ,KAAK,QAAQ,WAAW,QAAQ,cAAU,0BAAQ,QAAQ,OAAO,IAAI,IAAI;AAC7F,cAAM,QAAQ,OAAO,KAAK,OAAO,SAAS,OAAO,EAC9C,OAAO,CAAC,SAAS,GAAG,KAAK,IAAI,CAAC,EAC9B,IAAI,CAAC,aAAS,0BAAQ,KAAK,IAAI,CAAC;AACnC,kBAAM,+BAAmB,KAAK,SAAS,EAAE,OAAO,OAAO,CAAC;AAAA,MAC1D,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;","names":[]}
package/dist/index.mjs ADDED
@@ -0,0 +1,29 @@
1
+ // src/index.ts
2
+ import { dirname, resolve } from "path";
3
+ import { pluginLogger, processBuildOutput } from "@zharp/cli";
4
+ var JS = /\.(?:js|mjs|cjs)$/;
5
+ function zharpEsbuildPlugin(options = {}) {
6
+ return {
7
+ name: "zharp",
8
+ setup(build) {
9
+ if (options.disabled) return;
10
+ const initial = build.initialOptions;
11
+ if (!initial.sourcemap) initial.sourcemap = "external";
12
+ initial.metafile = true;
13
+ const logger = pluginLogger("zharp", options);
14
+ build.onEnd(async (result) => {
15
+ if (result.errors.length || initial.write === false || !result.metafile) return;
16
+ const cwd = initial.absWorkingDir ?? process.cwd();
17
+ const dir = resolve(cwd, initial.outdir ?? (initial.outfile ? dirname(initial.outfile) : "."));
18
+ const files = Object.keys(result.metafile.outputs).filter((name) => JS.test(name)).map((name) => resolve(cwd, name));
19
+ await processBuildOutput(dir, options, { files, logger });
20
+ });
21
+ }
22
+ };
23
+ }
24
+ var index_default = zharpEsbuildPlugin;
25
+ export {
26
+ index_default as default,
27
+ zharpEsbuildPlugin
28
+ };
29
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\r\n * @zharp/esbuild-plugin: after esbuild writes its output, inject debug IDs into the JS files and\r\n * their source maps, upload them to Zharp, and delete the maps from the output.\r\n *\r\n * await esbuild.build({ entryPoints: ['src/app.ts'], bundle: true, outdir: 'dist',\r\n * plugins: [zharpEsbuildPlugin({ app: 42 })] });\r\n */\r\nimport { dirname, resolve } from 'node:path';\r\nimport { pluginLogger, processBuildOutput, type ZharpPluginOptions } from '@zharp/cli';\r\n\r\nexport type { ZharpPluginOptions } from '@zharp/cli';\r\n\r\n/** The parts of esbuild's plugin API this plugin uses (no dependency on esbuild's types). */\r\ninterface BuildOptions {\r\n sourcemap?: boolean | 'linked' | 'inline' | 'external' | 'both';\r\n metafile?: boolean;\r\n write?: boolean;\r\n outdir?: string;\r\n outfile?: string;\r\n absWorkingDir?: string;\r\n}\r\ninterface BuildResult {\r\n errors: unknown[];\r\n metafile?: { outputs: Record<string, unknown> };\r\n}\r\ninterface PluginBuild {\r\n initialOptions: BuildOptions;\r\n onEnd(callback: (result: BuildResult) => void | Promise<void>): void;\r\n}\r\n\r\nconst JS = /\\.(?:js|mjs|cjs)$/;\r\n\r\nexport function zharpEsbuildPlugin(options: ZharpPluginOptions = {}) {\r\n return {\r\n name: 'zharp',\r\n setup(build: PluginBuild): void {\r\n if (options.disabled) return;\r\n const initial = build.initialOptions;\r\n // External maps: written next to the files, not referenced from them.\r\n if (!initial.sourcemap) initial.sourcemap = 'external';\r\n // The metafile is how the plugin knows which files this build wrote.\r\n initial.metafile = true;\r\n const logger = pluginLogger('zharp', options);\r\n build.onEnd(async (result) => {\r\n if (result.errors.length || initial.write === false || !result.metafile) return;\r\n const cwd = initial.absWorkingDir ?? process.cwd();\r\n const dir = resolve(cwd, initial.outdir ?? (initial.outfile ? dirname(initial.outfile) : '.'));\r\n const files = Object.keys(result.metafile.outputs)\r\n .filter((name) => JS.test(name))\r\n .map((name) => resolve(cwd, name));\r\n await processBuildOutput(dir, options, { files, logger });\r\n });\r\n },\r\n };\r\n}\r\n\r\nexport default zharpEsbuildPlugin;\r\n"],"mappings":";AAOA,SAAS,SAAS,eAAe;AACjC,SAAS,cAAc,0BAAmD;AAsB1E,IAAM,KAAK;AAEJ,SAAS,mBAAmB,UAA8B,CAAC,GAAG;AACnE,SAAO;AAAA,IACL,MAAM;AAAA,IACN,MAAM,OAA0B;AAC9B,UAAI,QAAQ,SAAU;AACtB,YAAM,UAAU,MAAM;AAEtB,UAAI,CAAC,QAAQ,UAAW,SAAQ,YAAY;AAE5C,cAAQ,WAAW;AACnB,YAAM,SAAS,aAAa,SAAS,OAAO;AAC5C,YAAM,MAAM,OAAO,WAAW;AAC5B,YAAI,OAAO,OAAO,UAAU,QAAQ,UAAU,SAAS,CAAC,OAAO,SAAU;AACzE,cAAM,MAAM,QAAQ,iBAAiB,QAAQ,IAAI;AACjD,cAAM,MAAM,QAAQ,KAAK,QAAQ,WAAW,QAAQ,UAAU,QAAQ,QAAQ,OAAO,IAAI,IAAI;AAC7F,cAAM,QAAQ,OAAO,KAAK,OAAO,SAAS,OAAO,EAC9C,OAAO,CAAC,SAAS,GAAG,KAAK,IAAI,CAAC,EAC9B,IAAI,CAAC,SAAS,QAAQ,KAAK,IAAI,CAAC;AACnC,cAAM,mBAAmB,KAAK,SAAS,EAAE,OAAO,OAAO,CAAC;AAAA,MAC1D,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,58 @@
1
1
  {
2
2
  "name": "@zharp/esbuild-plugin",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Zharp esbuild plugin: inject debug IDs and upload source maps",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": {
11
+ "types": "./dist/index.d.mts",
12
+ "default": "./dist/index.mjs"
13
+ },
14
+ "require": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.js"
17
+ }
18
+ },
19
+ "./package.json": "./package.json"
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "engines": {
25
+ "node": ">=18.18.0"
26
+ },
27
+ "keywords": [
28
+ "zharp",
29
+ "sourcemaps",
30
+ "debug-id",
31
+ "error-tracking",
32
+ "esbuild",
33
+ "esbuild-plugin"
34
+ ],
35
+ "license": "MIT",
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "git+https://github.com/zharp-io/zharp-javascript-lib.git",
39
+ "directory": "packages/bundler-plugins/esbuild"
40
+ },
41
+ "homepage": "https://zharp.io/docs/sourcemaps",
42
+ "bugs": "https://github.com/zharp-io/zharp-javascript-lib/issues",
43
+ "publishConfig": {
44
+ "access": "public"
45
+ },
46
+ "dependencies": {
47
+ "@zharp/cli": "0.1.0"
48
+ },
49
+ "devDependencies": {
50
+ "@types/node": "^25.9.3",
51
+ "tsup": "^8.5.1",
52
+ "typescript": "^5.9.3"
53
+ },
54
+ "scripts": {
55
+ "build": "tsup",
56
+ "typecheck": "tsc --noEmit"
57
+ }
6
58
  }