@peachy/plugin-runner 0.0.8 → 0.0.10
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 +18 -9
- package/dist/index.mjs +48 -31
- package/package.json +4 -3
package/dist/index.d.mts
CHANGED
|
@@ -4,21 +4,30 @@ import { Plugin } from "rolldown";
|
|
|
4
4
|
declare function gjsRunner({
|
|
5
5
|
sendMessage,
|
|
6
6
|
debug,
|
|
7
|
-
setReloadHandler
|
|
7
|
+
setReloadHandler,
|
|
8
|
+
options: runnerOptions
|
|
8
9
|
}: ReactGJSPluginOptions): Plugin;
|
|
10
|
+
type ReloadHandler = () => Promise<void>;
|
|
9
11
|
interface ReactGJSPluginOptions {
|
|
10
12
|
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
* Whether to print debug messages
|
|
14
|
+
*/
|
|
13
15
|
debug?: boolean;
|
|
14
16
|
/**
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
* Broadcast message to all connected clients
|
|
18
|
+
*/
|
|
17
19
|
sendMessage: (message: HMRMessage) => void;
|
|
18
20
|
/**
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
setReloadHandler: (handler:
|
|
21
|
+
* Called when a reload handler is needed
|
|
22
|
+
*/
|
|
23
|
+
setReloadHandler: (handler: ReloadHandler) => void;
|
|
24
|
+
/**
|
|
25
|
+
* Runner options
|
|
26
|
+
*/
|
|
27
|
+
options: RunnerOptions;
|
|
28
|
+
}
|
|
29
|
+
interface RunnerOptions {
|
|
30
|
+
env: Record<string, string>;
|
|
22
31
|
}
|
|
23
32
|
interface HMRUpdate {
|
|
24
33
|
type: "update";
|
|
@@ -30,4 +39,4 @@ interface HMRMessage {
|
|
|
30
39
|
updates: HMRUpdate[];
|
|
31
40
|
}
|
|
32
41
|
//#endregion
|
|
33
|
-
export { ReactGJSPluginOptions, gjsRunner };
|
|
42
|
+
export { ReactGJSPluginOptions, ReloadHandler, RunnerOptions, gjsRunner };
|
package/dist/index.mjs
CHANGED
|
@@ -2,57 +2,74 @@ import { spawn } from "node:child_process";
|
|
|
2
2
|
import { join, resolve } from "node:path";
|
|
3
3
|
|
|
4
4
|
//#region src/index.ts
|
|
5
|
-
let gjs = null;
|
|
6
|
-
async function spawnConsole(entry, debug = false) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
5
|
+
let gjs = null, restarting = false;
|
|
6
|
+
async function spawnConsole(entry, debug = false, env) {
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
if (!restarting) reject();
|
|
9
|
+
gjs = spawn("gjs", ["-m", entry], {
|
|
10
|
+
stdio: "inherit",
|
|
11
|
+
env: {
|
|
12
|
+
...process.env,
|
|
13
|
+
G_MESSAGES_DEBUG: debug ? "all" : void 0,
|
|
14
|
+
...env
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
gjs.on("close", (code) => {
|
|
18
|
+
if (!restarting) return process.exit(code ?? 0);
|
|
19
|
+
if (code !== null && code !== 0) console.error(`\n[HMR] GJS exited with error code ${code}`);
|
|
20
|
+
gjs = null;
|
|
21
|
+
});
|
|
22
|
+
gjs.once("spawn", () => {
|
|
23
|
+
resolve();
|
|
24
|
+
});
|
|
17
25
|
});
|
|
18
26
|
}
|
|
19
|
-
function killConsole() {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
27
|
+
async function killConsole() {
|
|
28
|
+
return new Promise((resolve) => {
|
|
29
|
+
if (!gjs || gjs.killed) return resolve();
|
|
30
|
+
gjs.once("exit", () => {
|
|
31
|
+
gjs = null;
|
|
32
|
+
resolve();
|
|
33
|
+
});
|
|
34
|
+
console.log("[HMR] Restarting the application");
|
|
35
|
+
if (!gjs.kill()) gjs.kill("SIGKILL");
|
|
36
|
+
});
|
|
24
37
|
}
|
|
25
|
-
function reloadConsole(...args) {
|
|
26
|
-
|
|
27
|
-
|
|
38
|
+
async function reloadConsole(...args) {
|
|
39
|
+
try {
|
|
40
|
+
restarting = true;
|
|
41
|
+
await killConsole();
|
|
42
|
+
await spawnConsole(...args);
|
|
43
|
+
restarting = false;
|
|
44
|
+
} catch {}
|
|
28
45
|
}
|
|
29
|
-
function gjsRunner({ sendMessage, debug, setReloadHandler }) {
|
|
30
|
-
|
|
46
|
+
function gjsRunner({ sendMessage, debug, setReloadHandler, options: runnerOptions }) {
|
|
47
|
+
let firstRun = true;
|
|
31
48
|
return {
|
|
32
49
|
name: "@peachy/plugin-runner",
|
|
33
|
-
watchChange(id) {
|
|
34
|
-
changedFiles.add(id);
|
|
35
|
-
},
|
|
36
50
|
writeBundle(options, bundle) {
|
|
37
51
|
const entryName = Object.keys(bundle)[0];
|
|
38
52
|
const entry = options.file || resolve(options.dir || "dist", entryName);
|
|
39
53
|
setReloadHandler(() => {
|
|
40
|
-
reloadConsole(entry, debug);
|
|
54
|
+
return reloadConsole(entry, debug, runnerOptions.env);
|
|
41
55
|
});
|
|
42
|
-
if (!this.meta.watchMode ||
|
|
43
|
-
reloadConsole(entry, debug);
|
|
56
|
+
if (!this.meta.watchMode || firstRun) {
|
|
57
|
+
reloadConsole(entry, debug, runnerOptions.env);
|
|
58
|
+
firstRun = false;
|
|
44
59
|
return;
|
|
45
60
|
}
|
|
46
61
|
const inputToOutput = getInputToOutputMap(bundle);
|
|
47
62
|
sendMessage({
|
|
48
63
|
type: "hmr",
|
|
49
|
-
updates: Array.from(
|
|
64
|
+
updates: Array.from(inputToOutput.entries()).filter(([id]) => {
|
|
65
|
+
if (!id.startsWith(process.cwd()) || !id.match(/\.[tj]sx?$/) || id.includes("node_modules") || id.startsWith("gi://*") || id === join(process.cwd(), "src", "index.tsx") || this.getModuleInfo(id)?.isEntry) return false;
|
|
66
|
+
return true;
|
|
67
|
+
}).map(([id, outputPath]) => ({
|
|
50
68
|
type: "update",
|
|
51
69
|
id,
|
|
52
|
-
url: resolve(
|
|
70
|
+
url: resolve(options.dir || ".", outputPath)
|
|
53
71
|
}))
|
|
54
72
|
});
|
|
55
|
-
changedFiles.clear();
|
|
56
73
|
}
|
|
57
74
|
};
|
|
58
75
|
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peachy/plugin-runner",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Run your GJS applications",
|
|
6
6
|
"main": "./dist/index.mjs",
|
|
7
7
|
"author": "",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"devDependencies": {
|
|
10
|
-
"
|
|
11
|
-
"
|
|
10
|
+
"@types/node": "^25.2.2",
|
|
11
|
+
"rolldown": "1.0.0-rc.3",
|
|
12
|
+
"tsdown": "0.20.3",
|
|
12
13
|
"typescript": "^5.9.3"
|
|
13
14
|
},
|
|
14
15
|
"peerDependencies": {
|