@opentray/esbuild-plugin 0.1.0 → 0.10.3
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/dist/index.d.mts +48 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +51 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +2 -2
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { OpenTrayArtifactInput, OpenTrayPackageManifest, OpenTrayPackageResult, OpenTrayPackagingApp } from "@opentray/packaging";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
interface OpenTrayEsbuildPluginOptions {
|
|
5
|
+
readonly app: OpenTrayPackagingApp;
|
|
6
|
+
readonly runtimeHost: OpenTrayArtifactInput;
|
|
7
|
+
readonly nativeArtifacts?: Readonly<Record<string, OpenTrayArtifactInput>>;
|
|
8
|
+
readonly companionAssets?: Readonly<Record<string, OpenTrayArtifactInput>>;
|
|
9
|
+
readonly entry?: string;
|
|
10
|
+
readonly manifestPath?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Explicit outDir override. When omitted, resolved from the esbuild
|
|
13
|
+
* `outdir`/`outfile` option or defaults to `dist`.
|
|
14
|
+
*/
|
|
15
|
+
readonly outDir?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Explicit mode override. Defaults to `production`.
|
|
18
|
+
*/
|
|
19
|
+
readonly mode?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Structural view of the esbuild initial options the adapter consumes. Only the
|
|
23
|
+
* staging-relevant fields are declared, so esbuild never has to be imported.
|
|
24
|
+
*/
|
|
25
|
+
interface EsbuildInitialOptionsLike {
|
|
26
|
+
readonly outdir?: string;
|
|
27
|
+
readonly outfile?: string;
|
|
28
|
+
readonly entryPoints?: readonly string[] | Readonly<Record<string, string>>;
|
|
29
|
+
readonly absWorkingDir?: string;
|
|
30
|
+
}
|
|
31
|
+
interface EsbuildBuildLike {
|
|
32
|
+
readonly initialOptions: EsbuildInitialOptionsLike;
|
|
33
|
+
onEnd(callback: (result: unknown) => Promise<void> | void): void;
|
|
34
|
+
}
|
|
35
|
+
interface EsbuildPlugin {
|
|
36
|
+
readonly name: string;
|
|
37
|
+
readonly setup: (build: EsbuildBuildLike) => void;
|
|
38
|
+
}
|
|
39
|
+
interface OpenTrayEsbuildPlugin extends EsbuildPlugin {
|
|
40
|
+
readonly name: "opentray-packaging";
|
|
41
|
+
/** Returns the last staging result. Only populated after `onEnd` runs. */
|
|
42
|
+
readonly getLastResult: () => OpenTrayPackageResult | undefined;
|
|
43
|
+
}
|
|
44
|
+
declare const openTrayEsbuildPlugin: (options: OpenTrayEsbuildPluginOptions) => OpenTrayEsbuildPlugin;
|
|
45
|
+
declare const resolveEsbuildEntry: (initialOptions: EsbuildInitialOptionsLike) => string;
|
|
46
|
+
//#endregion
|
|
47
|
+
export { EsbuildBuildLike, EsbuildInitialOptionsLike, EsbuildPlugin, OpenTrayEsbuildPlugin, OpenTrayEsbuildPluginOptions, type OpenTrayPackageManifest, type OpenTrayPackageResult, openTrayEsbuildPlugin, resolveEsbuildEntry };
|
|
48
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;UAUiB,4BAAA;EAAA,SACN,GAAA,EAAK,oBAAA;EAAA,SACL,WAAA,EAAa,qBAAA;EAAA,SACb,eAAA,GAAkB,QAAA,CAAS,MAAA,SAAe,qBAAA;EAAA,SAC1C,eAAA,GAAkB,QAAA,CAAS,MAAA,SAAe,qBAAA;EAAA,SAC1C,KAAA;EAAA,SACA,YAAA;EAH0C;;;;EAAA,SAQ1C,MAAA;EAPkB;;;EAAA,SAWlB,IAAA;AAAA;;;;;UAOM,yBAAA;EAAA,SACN,MAAA;EAAA,SACA,OAAA;EAAA,SACA,WAAA,uBAAkC,QAAQ,CAAC,MAAA;EAAA,SAC3C,aAAA;AAAA;AAAA,UAGM,gBAAA;EAAA,SACN,cAAA,EAAgB,yBAAA;EACzB,KAAA,CAAM,QAAA,GAAW,MAAA,cAAoB,OAAO;AAAA;AAAA,UAG7B,aAAA;EAAA,SACN,IAAA;EAAA,SACA,KAAA,GAAQ,KAAA,EAAO,gBAAgB;AAAA;AAAA,UAGzB,qBAAA,SAA8B,aAAa;EAAA,SACjD,IAAA;EAjBA;EAAA,SAmBA,aAAA,QAAqB,qBAAA;AAAA;AAAA,cAGnB,qBAAA,GACX,OAAA,EAAS,4BAAA,KACR,qBA+BF;AAAA,cAmBY,mBAAA,GAAuB,cAAyC,EAAzB,yBAAyB"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { dirname, resolve } from "node:path";
|
|
2
|
+
import { stageOpenTrayPackage } from "@opentray/packaging";
|
|
3
|
+
//#region src/index.ts
|
|
4
|
+
const openTrayEsbuildPlugin = (options) => {
|
|
5
|
+
let lastResult;
|
|
6
|
+
const plugin = {
|
|
7
|
+
name: "opentray-packaging",
|
|
8
|
+
setup(build) {
|
|
9
|
+
build.onEnd(async () => {
|
|
10
|
+
lastResult = await stageOpenTrayPackage({
|
|
11
|
+
app: options.app,
|
|
12
|
+
outDir: resolveEsbuildOutDir(options, build.initialOptions),
|
|
13
|
+
entry: options.entry ?? resolveEsbuildEntry(build.initialOptions),
|
|
14
|
+
adapter: {
|
|
15
|
+
name: "esbuild",
|
|
16
|
+
mode: options.mode ?? "production"
|
|
17
|
+
},
|
|
18
|
+
runtimeHost: options.runtimeHost,
|
|
19
|
+
...options.nativeArtifacts === void 0 ? {} : { nativeArtifacts: options.nativeArtifacts },
|
|
20
|
+
...options.companionAssets === void 0 ? {} : { companionAssets: options.companionAssets },
|
|
21
|
+
...options.manifestPath === void 0 ? {} : { manifestPath: options.manifestPath }
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
getLastResult: () => lastResult
|
|
26
|
+
};
|
|
27
|
+
Object.defineProperty(plugin, "getLastResult", { enumerable: false });
|
|
28
|
+
return plugin;
|
|
29
|
+
};
|
|
30
|
+
const resolveEsbuildOutDir = (options, initialOptions) => {
|
|
31
|
+
const cwd = initialOptions.absWorkingDir ?? process.cwd();
|
|
32
|
+
if (options.outDir !== void 0) return resolve(cwd, options.outDir);
|
|
33
|
+
if (initialOptions.outdir !== void 0 && initialOptions.outdir.length > 0) return resolve(cwd, initialOptions.outdir);
|
|
34
|
+
if (initialOptions.outfile !== void 0 && initialOptions.outfile.length > 0) return resolve(cwd, dirname(initialOptions.outfile));
|
|
35
|
+
return resolve(process.cwd(), "dist");
|
|
36
|
+
};
|
|
37
|
+
const resolveEsbuildEntry = (initialOptions) => {
|
|
38
|
+
const entryPoints = initialOptions.entryPoints;
|
|
39
|
+
if (entryPoints === void 0) throw new Error("OpenTray esbuild packaging requires esbuild entryPoints or an explicit entry option");
|
|
40
|
+
if (Array.isArray(entryPoints)) {
|
|
41
|
+
if (entryPoints.length === 0) throw new Error("OpenTray esbuild packaging requires esbuild entryPoints or an explicit entry option");
|
|
42
|
+
return entryPoints[0];
|
|
43
|
+
}
|
|
44
|
+
const first = Object.values(entryPoints)[0];
|
|
45
|
+
if (first === void 0) throw new Error("OpenTray esbuild packaging requires esbuild entryPoints or an explicit entry option");
|
|
46
|
+
return first;
|
|
47
|
+
};
|
|
48
|
+
//#endregion
|
|
49
|
+
export { openTrayEsbuildPlugin, resolveEsbuildEntry };
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { dirname, resolve } from \"node:path\";\n\nimport {\n stageOpenTrayPackage,\n type OpenTrayArtifactInput,\n type OpenTrayPackagingApp,\n type OpenTrayPackageManifest,\n type OpenTrayPackageResult,\n} from \"@opentray/packaging\";\n\nexport interface OpenTrayEsbuildPluginOptions {\n readonly app: OpenTrayPackagingApp;\n readonly runtimeHost: OpenTrayArtifactInput;\n readonly nativeArtifacts?: Readonly<Record<string, OpenTrayArtifactInput>>;\n readonly companionAssets?: Readonly<Record<string, OpenTrayArtifactInput>>;\n readonly entry?: string;\n readonly manifestPath?: string;\n /**\n * Explicit outDir override. When omitted, resolved from the esbuild\n * `outdir`/`outfile` option or defaults to `dist`.\n */\n readonly outDir?: string;\n /**\n * Explicit mode override. Defaults to `production`.\n */\n readonly mode?: string;\n}\n\n/**\n * Structural view of the esbuild initial options the adapter consumes. Only the\n * staging-relevant fields are declared, so esbuild never has to be imported.\n */\nexport interface EsbuildInitialOptionsLike {\n readonly outdir?: string;\n readonly outfile?: string;\n readonly entryPoints?: readonly string[] | Readonly<Record<string, string>>;\n readonly absWorkingDir?: string;\n}\n\nexport interface EsbuildBuildLike {\n readonly initialOptions: EsbuildInitialOptionsLike;\n onEnd(callback: (result: unknown) => Promise<void> | void): void;\n}\n\nexport interface EsbuildPlugin {\n readonly name: string;\n readonly setup: (build: EsbuildBuildLike) => void;\n}\n\nexport interface OpenTrayEsbuildPlugin extends EsbuildPlugin {\n readonly name: \"opentray-packaging\";\n /** Returns the last staging result. Only populated after `onEnd` runs. */\n readonly getLastResult: () => OpenTrayPackageResult | undefined;\n}\n\nexport const openTrayEsbuildPlugin = (\n options: OpenTrayEsbuildPluginOptions,\n): OpenTrayEsbuildPlugin => {\n let lastResult: OpenTrayPackageResult | undefined;\n\n // esbuild validates the enumerable own keys of a plugin object and rejects\n // anything beyond { name, setup }. Keep `getLastResult` non-enumerable so the\n // adapter can still expose the staging result to programmatic callers without\n // tripping esbuild's plugin validation.\n const plugin: OpenTrayEsbuildPlugin = {\n name: \"opentray-packaging\",\n setup(build) {\n build.onEnd(async () => {\n lastResult = await stageOpenTrayPackage({\n app: options.app,\n outDir: resolveEsbuildOutDir(options, build.initialOptions),\n entry: options.entry ?? resolveEsbuildEntry(build.initialOptions),\n adapter: { name: \"esbuild\", mode: options.mode ?? \"production\" },\n runtimeHost: options.runtimeHost,\n ...(options.nativeArtifacts === undefined\n ? {}\n : { nativeArtifacts: options.nativeArtifacts }),\n ...(options.companionAssets === undefined\n ? {}\n : { companionAssets: options.companionAssets }),\n ...(options.manifestPath === undefined ? {} : { manifestPath: options.manifestPath }),\n });\n });\n },\n getLastResult: () => lastResult,\n };\n Object.defineProperty(plugin, \"getLastResult\", { enumerable: false });\n return plugin;\n};\n\nconst resolveEsbuildOutDir = (\n options: OpenTrayEsbuildPluginOptions,\n initialOptions: EsbuildInitialOptionsLike,\n): string => {\n const cwd = initialOptions.absWorkingDir ?? process.cwd();\n if (options.outDir !== undefined) {\n return resolve(cwd, options.outDir);\n }\n if (initialOptions.outdir !== undefined && initialOptions.outdir.length > 0) {\n return resolve(cwd, initialOptions.outdir);\n }\n if (initialOptions.outfile !== undefined && initialOptions.outfile.length > 0) {\n return resolve(cwd, dirname(initialOptions.outfile));\n }\n return resolve(process.cwd(), \"dist\");\n};\n\nexport const resolveEsbuildEntry = (initialOptions: EsbuildInitialOptionsLike): string => {\n const entryPoints = initialOptions.entryPoints;\n if (entryPoints === undefined) {\n throw new Error(\n \"OpenTray esbuild packaging requires esbuild entryPoints or an explicit entry option\",\n );\n }\n if (Array.isArray(entryPoints)) {\n if (entryPoints.length === 0) {\n throw new Error(\n \"OpenTray esbuild packaging requires esbuild entryPoints or an explicit entry option\",\n );\n }\n return entryPoints[0] as string;\n }\n const first = Object.values(entryPoints)[0];\n if (first === undefined) {\n throw new Error(\n \"OpenTray esbuild packaging requires esbuild entryPoints or an explicit entry option\",\n );\n }\n return first;\n};\n\nexport type { OpenTrayPackageManifest, OpenTrayPackageResult };\n"],"mappings":";;;AAuDA,MAAa,yBACX,YAC0B;CAC1B,IAAI;CAMJ,MAAM,SAAgC;EACpC,MAAM;EACN,MAAM,OAAO;GACX,MAAM,MAAM,YAAY;IACtB,aAAa,MAAM,qBAAqB;KACtC,KAAK,QAAQ;KACb,QAAQ,q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,OAAO;AACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opentray/esbuild-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.3",
|
|
4
4
|
"description": "esbuild adapter for the OpenTray runtime artifact packaging contract.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
],
|
|
22
22
|
"sideEffects": false,
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@opentray/packaging": "0.
|
|
24
|
+
"@opentray/packaging": "0.10.3"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"esbuild": ">=0.20"
|