@electron-spark/vite-plugin-electron-main 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 François Germain
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/dist/index.cjs ADDED
@@ -0,0 +1,106 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ // \0rolldown/runtime.js
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
+ get: ((k) => from[k]).bind(null, key),
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
20
+ value: mod,
21
+ enumerable: true
22
+ }) : target, mod));
23
+ let node_child_process = require("node:child_process");
24
+ let node_module = require("node:module");
25
+ let node_path = require("node:path");
26
+ node_path = __toESM(node_path, 1);
27
+ let _electron_spark_vite_plugin_build_on_serve = require("@electron-spark/vite-plugin-build-on-serve");
28
+ // src/index.ts
29
+ /** Build and restart only the configured Electron main environment in dev. */
30
+ function electronMain(environmentName = "electron") {
31
+ return [{
32
+ name: "@electron-spark/vite-plugin-electron-main",
33
+ enforce: "pre",
34
+ applyToEnvironment: (environment) => environment.name === environmentName,
35
+ resolveId(id) {
36
+ if (id === "electron" || id === "electron/main" || id === "electron/common") return {
37
+ id,
38
+ external: true
39
+ };
40
+ return null;
41
+ }
42
+ }, (0, _electron_spark_vite_plugin_build_on_serve.buildOnServe)(environmentName, { session(server) {
43
+ const session = createSession(server);
44
+ return {
45
+ ...session,
46
+ plugins: [session.launch]
47
+ };
48
+ } })];
49
+ }
50
+ function createSession(server) {
51
+ const executable = (0, node_module.createRequire)(node_path.default.resolve(server.config.root, "package.json"))("electron");
52
+ let child;
53
+ let closed = false;
54
+ let pending = Promise.resolve();
55
+ let entry;
56
+ async function stop() {
57
+ const previous = child;
58
+ child = void 0;
59
+ if (!previous?.pid || previous.exitCode !== null || previous.signalCode !== null) return;
60
+ await new Promise((resolve) => {
61
+ const timeout = setTimeout(() => previous.kill("SIGKILL"), 3e3);
62
+ previous.once("exit", () => {
63
+ clearTimeout(timeout);
64
+ resolve();
65
+ });
66
+ previous.kill("SIGTERM");
67
+ });
68
+ }
69
+ return {
70
+ close: async () => {
71
+ closed = true;
72
+ await pending;
73
+ await stop();
74
+ },
75
+ buildStart() {
76
+ entry = void 0;
77
+ },
78
+ buildSuccess() {
79
+ const builtEntry = entry;
80
+ if (!builtEntry || closed) return pending;
81
+ pending = pending.then(async () => {
82
+ await stop();
83
+ if (closed) return;
84
+ const env = { ...process.env };
85
+ delete env.ELECTRON_RUN_AS_NODE;
86
+ child = (0, node_child_process.spawn)(executable, [builtEntry], {
87
+ stdio: "inherit",
88
+ env
89
+ });
90
+ child.on("error", (error) => server.config.logger.error(error.message));
91
+ }).catch((error) => {
92
+ server.config.logger.error(String(error));
93
+ });
94
+ return pending;
95
+ },
96
+ launch: {
97
+ name: "electron-main-launch",
98
+ writeBundle(options, bundle) {
99
+ const entries = Object.values(bundle).filter((output) => output.type === "chunk" && output.isEntry);
100
+ if (entries.length !== 1) throw new Error("Electron main requires exactly one entry point.");
101
+ entry ??= node_path.default.resolve(options.dir ?? node_path.default.dirname(options.file), entries[0].fileName);
102
+ }
103
+ }
104
+ };
105
+ }
106
+ exports.electronMain = electronMain;
@@ -0,0 +1,4 @@
1
+ import { Plugin } from "vite";
2
+ /** Build and restart only the configured Electron main environment in dev. */
3
+ export declare function electronMain(environmentName?: string): Plugin[];
4
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"mappings":";;wBAQgB,aAAa,2BAA+B"}
@@ -0,0 +1,4 @@
1
+ import { Plugin } from "vite";
2
+ /** Build and restart only the configured Electron main environment in dev. */
3
+ export declare function electronMain(environmentName?: string): Plugin[];
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;wBAQgB,aAAa,2BAA+B"}
package/dist/index.js ADDED
@@ -0,0 +1,85 @@
1
+ import { spawn } from "node:child_process";
2
+ import { createRequire } from "node:module";
3
+ import path from "node:path";
4
+ import { buildOnServe } from "@electron-spark/vite-plugin-build-on-serve";
5
+ // src/index.ts
6
+ /** Build and restart only the configured Electron main environment in dev. */
7
+ function electronMain(environmentName = "electron") {
8
+ return [{
9
+ name: "@electron-spark/vite-plugin-electron-main",
10
+ enforce: "pre",
11
+ applyToEnvironment: (environment) => environment.name === environmentName,
12
+ resolveId(id) {
13
+ if (id === "electron" || id === "electron/main" || id === "electron/common") return {
14
+ id,
15
+ external: true
16
+ };
17
+ return null;
18
+ }
19
+ }, buildOnServe(environmentName, { session(server) {
20
+ const session = createSession(server);
21
+ return {
22
+ ...session,
23
+ plugins: [session.launch]
24
+ };
25
+ } })];
26
+ }
27
+ function createSession(server) {
28
+ const executable = createRequire(path.resolve(server.config.root, "package.json"))("electron");
29
+ let child;
30
+ let closed = false;
31
+ let pending = Promise.resolve();
32
+ let entry;
33
+ async function stop() {
34
+ const previous = child;
35
+ child = void 0;
36
+ if (!previous?.pid || previous.exitCode !== null || previous.signalCode !== null) return;
37
+ await new Promise((resolve) => {
38
+ const timeout = setTimeout(() => previous.kill("SIGKILL"), 3e3);
39
+ previous.once("exit", () => {
40
+ clearTimeout(timeout);
41
+ resolve();
42
+ });
43
+ previous.kill("SIGTERM");
44
+ });
45
+ }
46
+ return {
47
+ close: async () => {
48
+ closed = true;
49
+ await pending;
50
+ await stop();
51
+ },
52
+ buildStart() {
53
+ entry = void 0;
54
+ },
55
+ buildSuccess() {
56
+ const builtEntry = entry;
57
+ if (!builtEntry || closed) return pending;
58
+ pending = pending.then(async () => {
59
+ await stop();
60
+ if (closed) return;
61
+ const env = { ...process.env };
62
+ delete env.ELECTRON_RUN_AS_NODE;
63
+ child = spawn(executable, [builtEntry], {
64
+ stdio: "inherit",
65
+ env
66
+ });
67
+ child.on("error", (error) => server.config.logger.error(error.message));
68
+ }).catch((error) => {
69
+ server.config.logger.error(String(error));
70
+ });
71
+ return pending;
72
+ },
73
+ launch: {
74
+ name: "electron-main-launch",
75
+ writeBundle(options, bundle) {
76
+ const entries = Object.values(bundle).filter((output) => output.type === "chunk" && output.isEntry);
77
+ if (entries.length !== 1) throw new Error("Electron main requires exactly one entry point.");
78
+ entry ??= path.resolve(options.dir ?? path.dirname(options.file), entries[0].fileName);
79
+ }
80
+ }
81
+ };
82
+ }
83
+ export { electronMain };
84
+
85
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { spawn, type ChildProcess } from \"node:child_process\";\nimport { createRequire } from \"node:module\";\nimport path from \"node:path\";\n\nimport { buildOnServe } from \"@electron-spark/vite-plugin-build-on-serve\";\nimport type { Plugin, ViteDevServer } from \"vite\";\n\n/** Build and restart only the configured Electron main environment in dev. */\nexport function electronMain(environmentName = \"electron\"): Plugin[] {\n return [\n {\n name: \"@electron-spark/vite-plugin-electron-main\",\n enforce: \"pre\",\n applyToEnvironment: (environment) => environment.name === environmentName,\n resolveId(id) {\n if (id === \"electron\" || id === \"electron/main\" || id === \"electron/common\") {\n return { id, external: true };\n }\n return null;\n },\n },\n buildOnServe(environmentName, {\n session(server) {\n const session = createSession(server);\n return { ...session, plugins: [session.launch] };\n },\n }),\n ];\n}\n\nfunction createSession(server: ViteDevServer) {\n const require = createRequire(path.resolve(server.config.root, \"package.json\"));\n const executable: string = require(\"electron\");\n let child: ChildProcess | undefined;\n let closed = false;\n let pending = Promise.resolve();\n let entry: string | undefined;\n\n async function stop() {\n const previous = child;\n child = undefined;\n if (!previous?.pid || previous.exitCode !== null || previous.signalCode !== null) return;\n await new Promise<void>((resolve) => {\n const timeout = setTimeout(() => previous.kill(\"SIGKILL\"), 3000);\n previous.once(\"exit\", () => {\n clearTimeout(timeout);\n resolve();\n });\n previous.kill(\"SIGTERM\");\n });\n }\n\n return {\n close: async () => {\n closed = true;\n await pending;\n await stop();\n },\n buildStart() {\n entry = undefined;\n },\n buildSuccess() {\n const builtEntry = entry;\n if (!builtEntry || closed) return pending;\n pending = pending\n .then(async () => {\n await stop();\n if (closed) return;\n const env = { ...process.env };\n delete env.ELECTRON_RUN_AS_NODE;\n child = spawn(executable, [builtEntry], { stdio: \"inherit\", env });\n child.on(\"error\", (error) => server.config.logger.error(error.message));\n })\n .catch((error: unknown) => {\n server.config.logger.error(String(error));\n });\n return pending;\n },\n launch: {\n name: \"electron-main-launch\",\n writeBundle(options, bundle) {\n const entries = Object.values(bundle).filter(\n (output) => output.type === \"chunk\" && output.isEntry,\n );\n if (entries.length !== 1) {\n throw new Error(\"Electron main requires exactly one entry point.\");\n }\n // Use the first written output, but only launch after the whole cycle succeeds.\n entry ??= path.resolve(options.dir ?? path.dirname(options.file!), entries[0].fileName);\n },\n } satisfies Plugin,\n };\n}\n"],"mappings":";;;;;;AAQA,SAAgB,aAAa,kBAAkB,YAAsB;CACnE,OAAO,CACL;EACE,MAAM;EACN,SAAS;EACT,qBAAqB,gBAAgB,YAAY,SAAS;EAC1D,UAAU,IAAI;GACZ,IAAI,OAAO,cAAc,OAAO,mBAAmB,OAAO,mBACxD,OAAO;IAAE;IAAI,UAAU;GAAK;GAE9B,OAAO;EACT;CACF,GACA,aAAa,iBAAiB,EAC5B,QAAQ,QAAQ;EACd,MAAM,UAAU,cAAc,MAAM;EACpC,OAAO;GAAE,GAAG;GAAS,SAAS,CAAC,QAAQ,MAAM;EAAE;CACjD,EACF,CAAC,CACH;AACF;AAEA,SAAS,cAAc,QAAuB;CAE5C,MAAM,aADU,cAAc,KAAK,QAAQ,OAAO,OAAO,MAAM,cAAc,CAC5C,CAAC,CAAC,UAAU;CAC7C,IAAI;CACJ,IAAI,SAAS;CACb,IAAI,UAAU,QAAQ,QAAQ;CAC9B,IAAI;CAEJ,eAAe,OAAO;EACpB,MAAM,WAAW;EACjB,QAAQ,KAAA;EACR,IAAI,CAAC,UAAU,OAAO,SAAS,aAAa,QAAQ,SAAS,eAAe,MAAM;EAClF,MAAM,IAAI,SAAe,YAAY;GACnC,MAAM,UAAU,iBAAiB,SAAS,KAAK,SAAS,GAAG,GAAI;GAC/D,SAAS,KAAK,cAAc;IAC1B,aAAa,OAAO;IACpB,QAAQ;GACV,CAAC;GACD,SAAS,KAAK,SAAS;EACzB,CAAC;CACH;CAEA,OAAO;EACL,OAAO,YAAY;GACjB,SAAS;GACT,MAAM;GACN,MAAM,KAAK;EACb;EACA,aAAa;GACX,QAAQ,KAAA;EACV;EACA,eAAe;GACb,MAAM,aAAa;GACnB,IAAI,CAAC,cAAc,QAAQ,OAAO;GAClC,UAAU,QACP,KAAK,YAAY;IAChB,MAAM,KAAK;IACX,IAAI,QAAQ;IACZ,MAAM,MAAM,EAAE,GAAG,QAAQ,IAAI;IAC7B,OAAO,IAAI;IACX,QAAQ,MAAM,YAAY,CAAC,UAAU,GAAG;KAAE,OAAO;KAAW;IAAI,CAAC;IACjE,MAAM,GAAG,UAAU,UAAU,OAAO,OAAO,OAAO,MAAM,MAAM,OAAO,CAAC;GACxE,CAAC,CAAC,CACD,OAAO,UAAmB;IACzB,OAAO,OAAO,OAAO,MAAM,OAAO,KAAK,CAAC;GAC1C,CAAC;GACH,OAAO;EACT;EACA,QAAQ;GACN,MAAM;GACN,YAAY,SAAS,QAAQ;IAC3B,MAAM,UAAU,OAAO,OAAO,MAAM,CAAC,CAAC,QACnC,WAAW,OAAO,SAAS,WAAW,OAAO,OAChD;IACA,IAAI,QAAQ,WAAW,GACrB,MAAM,IAAI,MAAM,iDAAiD;IAGnE,UAAU,KAAK,QAAQ,QAAQ,OAAO,KAAK,QAAQ,QAAQ,IAAK,GAAG,QAAQ,EAAE,CAAC,QAAQ;GACxF;EACF;CACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,53 @@
1
1
  {
2
2
  "name": "@electron-spark/vite-plugin-electron-main",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "license": "MIT",
5
+ "author": {
6
+ "name": "François Germain (Cahnory)",
7
+ "email": "cahnory@gmail.com",
8
+ "url": "https://github.com/cahnory"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/cahnory/electron-spark.git",
13
+ "directory": "libs/vite-plugin-electron-main"
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "type": "module",
19
+ "main": "./dist/index.cjs",
20
+ "module": "./dist/index.js",
21
+ "types": "./dist/index.d.cts",
22
+ "exports": {
23
+ ".": {
24
+ "import": "./dist/index.js",
25
+ "require": "./dist/index.cjs"
26
+ },
27
+ "./package.json": "./package.json"
28
+ },
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "dependencies": {
33
+ "@electron-spark/vite-plugin-build-on-serve": "0.1.0"
34
+ },
35
+ "devDependencies": {
36
+ "electron": "^45.0.0",
37
+ "tsdown": "^0.23.2",
38
+ "vite": "^8.3.5"
39
+ },
40
+ "peerDependencies": {
41
+ "electron": "^45.0.0",
42
+ "vite": "^8.3.5"
43
+ },
44
+ "scripts": {
45
+ "build": "tsdown",
46
+ "check": "concurrently --names format,lint,test,types --group \"pnpm check:format\" \"pnpm check:lint\" \"pnpm check:test\" \"pnpm check:types\"",
47
+ "check:format": "oxfmt --check .",
48
+ "check:lint": "oxlint --deny-warnings .",
49
+ "check:test": "node --test --test-reporter=../../scripts/test-reporter.mjs tests/*.test.mjs",
50
+ "check:types": "tsc --noEmit -p tsconfig.json",
51
+ "test": "pnpm check:test"
52
+ }
6
53
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
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.