@opentray/vite-plugin 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/README.md +23 -0
- package/dist/index.d.mts +38 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +56 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +44 -0
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# @opentray/vite-plugin
|
|
2
|
+
|
|
3
|
+
Vite adapter for the OpenTray runtime artifact packaging contract.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { openTrayVitePlugin } from "@opentray/vite-plugin";
|
|
7
|
+
|
|
8
|
+
export default {
|
|
9
|
+
plugins: [
|
|
10
|
+
openTrayVitePlugin({
|
|
11
|
+
app: { id: "com.example.build", name: "Build" },
|
|
12
|
+
runtimeHost: { source: "target/release/build-tray-host" },
|
|
13
|
+
nativeArtifacts: {
|
|
14
|
+
"darwin-arm64": { source: "target/release/libbuild_tray.dylib" },
|
|
15
|
+
},
|
|
16
|
+
}),
|
|
17
|
+
],
|
|
18
|
+
};
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The adapter stages artifacts during Vite build output and writes the same
|
|
22
|
+
manifest shape as `@opentray/packaging`. It does not own tray lifecycle,
|
|
23
|
+
sessions, backend selection, or extension dispatch.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { OpenTrayArtifactInput, OpenTrayPackageManifest, OpenTrayPackageResult, OpenTrayPackagingApp } from "@opentray/packaging";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
interface OpenTrayVitePluginOptions {
|
|
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
|
+
interface ViteResolvedConfigLike {
|
|
13
|
+
readonly root: string;
|
|
14
|
+
readonly mode: string;
|
|
15
|
+
readonly build: {
|
|
16
|
+
readonly outDir: string;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
interface ViteOutputChunkLike {
|
|
20
|
+
readonly type?: string;
|
|
21
|
+
readonly isEntry?: boolean;
|
|
22
|
+
readonly fileName?: string;
|
|
23
|
+
readonly facadeModuleId?: string | null;
|
|
24
|
+
readonly name?: string;
|
|
25
|
+
}
|
|
26
|
+
type ViteBundleLike = Readonly<Record<string, unknown>>;
|
|
27
|
+
interface OpenTrayVitePlugin {
|
|
28
|
+
readonly name: "opentray-packaging";
|
|
29
|
+
readonly apply: "build";
|
|
30
|
+
configResolved(config: ViteResolvedConfigLike): void;
|
|
31
|
+
writeBundle(options: unknown, bundle: ViteBundleLike): Promise<void>;
|
|
32
|
+
readonly getLastResult: () => OpenTrayPackageResult | undefined;
|
|
33
|
+
}
|
|
34
|
+
declare const openTrayVitePlugin: (options: OpenTrayVitePluginOptions) => OpenTrayVitePlugin;
|
|
35
|
+
declare const resolveViteEntry: (bundle: ViteBundleLike) => string;
|
|
36
|
+
//#endregion
|
|
37
|
+
export { type OpenTrayPackageManifest, type OpenTrayPackageResult, OpenTrayVitePlugin, OpenTrayVitePluginOptions, ViteBundleLike, ViteOutputChunkLike, ViteResolvedConfigLike, openTrayVitePlugin, resolveViteEntry };
|
|
38
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;UAUiB,yBAAA;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;AAAA;AAAA,UAGM,sBAAA;EAAA,SACN,IAAA;EAAA,SACA,IAAA;EAAA,SACA,KAAA;IAAA,SACE,MAAA;EAAA;AAAA;AAAA,UAII,mBAAA;EAAA,SACN,IAAA;EAAA,SACA,OAAA;EAAA,SACA,QAAA;EAAA,SACA,cAAA;EAAA,SACA,IAAA;AAAA;AAAA,KAGC,cAAA,GAAiB,QAAQ,CAAC,MAAA;AAAA,UAErB,kBAAA;EAAA,SACN,IAAA;EAAA,SACA,KAAA;EACT,cAAA,CAAe,MAAA,EAAQ,sBAAA;EACvB,WAAA,CAAY,OAAA,WAAkB,MAAA,EAAQ,cAAA,GAAiB,OAAA;EAAA,SAC9C,aAAA,QAAqB,qBAAA;AAAA;AAAA,cAGnB,kBAAA,GACX,OAAA,EAAS,yBAAA,KACR,kBAiCF;AAAA,cAEY,gBAAA,GAAoB,MAAsB,EAAd,cAAc"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { stageOpenTrayPackage } from "@opentray/packaging";
|
|
3
|
+
//#region src/index.ts
|
|
4
|
+
const openTrayVitePlugin = (options) => {
|
|
5
|
+
let config;
|
|
6
|
+
let lastResult;
|
|
7
|
+
return {
|
|
8
|
+
name: "opentray-packaging",
|
|
9
|
+
apply: "build",
|
|
10
|
+
configResolved(resolvedConfig) {
|
|
11
|
+
config = resolvedConfig;
|
|
12
|
+
},
|
|
13
|
+
async writeBundle(_options, bundle) {
|
|
14
|
+
const resolvedConfig = config ?? {
|
|
15
|
+
root: process.cwd(),
|
|
16
|
+
mode: "production",
|
|
17
|
+
build: { outDir: "dist" }
|
|
18
|
+
};
|
|
19
|
+
lastResult = await stageOpenTrayPackage({
|
|
20
|
+
app: options.app,
|
|
21
|
+
outDir: resolve(resolvedConfig.root, resolvedConfig.build.outDir),
|
|
22
|
+
entry: options.entry ?? resolveViteEntry(bundle),
|
|
23
|
+
adapter: {
|
|
24
|
+
name: "vite",
|
|
25
|
+
mode: resolvedConfig.mode
|
|
26
|
+
},
|
|
27
|
+
runtimeHost: options.runtimeHost,
|
|
28
|
+
...options.nativeArtifacts === void 0 ? {} : { nativeArtifacts: options.nativeArtifacts },
|
|
29
|
+
...options.companionAssets === void 0 ? {} : { companionAssets: options.companionAssets },
|
|
30
|
+
...options.manifestPath === void 0 ? {} : { manifestPath: options.manifestPath }
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
getLastResult: () => lastResult
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
const resolveViteEntry = (bundle) => {
|
|
37
|
+
const entry = Object.values(bundle).map(asOutputChunk).find((chunk) => chunk?.isEntry === true);
|
|
38
|
+
const identity = entry?.facadeModuleId ?? entry?.fileName ?? entry?.name;
|
|
39
|
+
if (identity === void 0 || identity.length === 0) throw new Error("OpenTray Vite packaging requires a Vite entry chunk or explicit entry option");
|
|
40
|
+
return identity;
|
|
41
|
+
};
|
|
42
|
+
const asOutputChunk = (value) => {
|
|
43
|
+
if (typeof value !== "object" || value === null) return;
|
|
44
|
+
const record = value;
|
|
45
|
+
return {
|
|
46
|
+
...record.type === "chunk" ? { type: "chunk" } : {},
|
|
47
|
+
...typeof record.isEntry === "boolean" ? { isEntry: record.isEntry } : {},
|
|
48
|
+
...typeof record.fileName === "string" ? { fileName: record.fileName } : {},
|
|
49
|
+
...typeof record.facadeModuleId === "string" || record.facadeModuleId === null ? { facadeModuleId: record.facadeModuleId } : {},
|
|
50
|
+
...typeof record.name === "string" ? { name: record.name } : {}
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
//#endregion
|
|
54
|
+
export { openTrayVitePlugin, resolveViteEntry };
|
|
55
|
+
|
|
56
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { 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 OpenTrayVitePluginOptions {\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\nexport interface ViteResolvedConfigLike {\n readonly root: string;\n readonly mode: string;\n readonly build: {\n readonly outDir: string;\n };\n}\n\nexport interface ViteOutputChunkLike {\n readonly type?: string;\n readonly isEntry?: boolean;\n readonly fileName?: string;\n readonly facadeModuleId?: string | null;\n readonly name?: string;\n}\n\nexport type ViteBundleLike = Readonly<Record<string, unknown>>;\n\nexport interface OpenTrayVitePlugin {\n readonly name: \"opentray-packaging\";\n readonly apply: \"build\";\n configResolved(config: ViteResolvedConfigLike): void;\n writeBundle(options: unknown, bundle: ViteBundleLike): Promise<void>;\n readonly getLastResult: () => OpenTrayPackageResult | undefined;\n}\n\nexport const openTrayVitePlugin = (\n options: OpenTrayVitePluginOptions,\n): OpenTrayVitePlugin => {\n let config: ViteResolvedConfigLike | undefined;\n let lastResult: OpenTrayPackageResult | undefined;\n\n return {\n name: \"opentray-packaging\",\n apply: \"build\",\n configResolved(resolvedConfig) {\n config = resolvedConfig;\n },\n async writeBundle(_options, bundle) {\n const resolvedConfig = config ?? {\n root: process.cwd(),\n mode: \"production\",\n build: { outDir: \"dist\" },\n };\n lastResult = await stageOpenTrayPackage({\n app: options.app,\n outDir: resolve(resolvedConfig.root, resolvedConfig.build.outDir),\n entry: options.entry ?? resolveViteEntry(bundle),\n adapter: { name: \"vite\", mode: resolvedConfig.mode },\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 getLastResult: () => lastResult,\n };\n};\n\nexport const resolveViteEntry = (bundle: ViteBundleLike): string => {\n const entry = Object.values(bundle)\n .map(asOutputChunk)\n .find((chunk): chunk is ViteOutputChunkLike => chunk?.isEntry === true);\n const identity = entry?.facadeModuleId ?? entry?.fileName ?? entry?.name;\n if (identity === undefined || identity.length === 0) {\n throw new Error(\"OpenTray Vite packaging requires a Vite entry chunk or explicit entry option\");\n }\n return identity;\n};\n\nconst asOutputChunk = (value: unknown): ViteOutputChunkLike | undefined => {\n if (typeof value !== \"object\" || value === null) {\n return undefined;\n }\n const record = value as Record<string, unknown>;\n return {\n ...(record.type === \"chunk\" ? { type: \"chunk\" } : {}),\n ...(typeof record.isEntry === \"boolean\" ? { isEntry: record.isEntry } : {}),\n ...(typeof record.fileName === \"string\" ? { fileName: record.fileName } : {}),\n ...(typeof record.facadeModuleId === \"string\" || record.facadeModuleId === null\n ? { facadeModuleId: record.facadeModuleId }\n : {}),\n ...(typeof record.name === \"string\" ? { name: record.name } : {}),\n };\n};\n\nexport type { OpenTrayPackageManifest, OpenTrayPackageResult };\n"],"mappings":";;;AA6CA,MAAa,sBACX,YACuB;CACvB,IAAI;CACJ,IAAI;CAEJ,OAAO;EACL,MAAM;EACN,OAAO;EACP,eAAe,gBAAgB;GAC7B,SAAS;EACX;EACA,MAAM,YAAY,UAAU,QAAQ;GAClC,MAAM,iBAAiB,UAAU;IAC/B,MAAM,QAAQ,IAAI;IAClB,MAAM;IACN,OAAO,EAAE,QAAQ,OAAO;GAC1B;GACA,aAAa,MAAM,qBAAqB;IACtC,KAAK,QAAQ;IACb,QAAQ,QAAQ,eAAe,MAAM,eAAe,MAAM,MAAM;IAChE,OAAO,QAAQ,SAAS,iBAAiB,MAAM;IA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Vite adapter for the OpenTray runtime artifact packaging contract.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/jixoai/opentray"
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.mts",
|
|
14
|
+
"import": "./dist/index.mjs"
|
|
15
|
+
},
|
|
16
|
+
"./package.json": "./package.json"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md"
|
|
21
|
+
],
|
|
22
|
+
"sideEffects": false,
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@opentray/packaging": "0.1.0"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"vite": ">=5"
|
|
28
|
+
},
|
|
29
|
+
"peerDependenciesMeta": {
|
|
30
|
+
"vite": {
|
|
31
|
+
"optional": true
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"tsdown": "^0.22.1",
|
|
36
|
+
"typescript": "^6.0.3",
|
|
37
|
+
"vitest": "^4.1.7"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsdown src/index.ts --format esm --dts",
|
|
41
|
+
"test": "vitest run --config vitest.config.ts",
|
|
42
|
+
"typecheck": "tsc --noEmit"
|
|
43
|
+
}
|
|
44
|
+
}
|