plgg-bundle 0.0.1 → 0.0.2
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/package.json +1 -4
- package/dist/Dev/fixtures/devPoc.spec.d.ts +0 -2
- package/dist/Dev/fixtures/devPoc.spec.d.ts.map +0 -1
- package/dist/Dev/fixtures/devPoc.spec.js +0 -145
- package/dist/Dev/fixtures/devPoc.spec.js.map +0 -1
- package/dist/Dev/model/Fetch.d.ts +0 -20
- package/dist/Dev/model/Fetch.d.ts.map +0 -1
- package/dist/Dev/model/Fetch.js +0 -8
- package/dist/Dev/model/Fetch.js.map +0 -1
- package/dist/Dev/model/ModuleGraph.d.ts +0 -27
- package/dist/Dev/model/ModuleGraph.d.ts.map +0 -1
- package/dist/Dev/model/ModuleGraph.js +0 -2
- package/dist/Dev/model/ModuleGraph.js.map +0 -1
- package/dist/Dev/model/Protocol.d.ts +0 -22
- package/dist/Dev/model/Protocol.d.ts.map +0 -1
- package/dist/Dev/model/Protocol.js +0 -31
- package/dist/Dev/model/Protocol.js.map +0 -1
- package/dist/Dev/node/devServer.d.ts +0 -21
- package/dist/Dev/node/devServer.d.ts.map +0 -1
- package/dist/Dev/node/devServer.js +0 -298
- package/dist/Dev/node/devServer.js.map +0 -1
- package/dist/Dev/node/httpAdapter.d.ts +0 -19
- package/dist/Dev/node/httpAdapter.d.ts.map +0 -1
- package/dist/Dev/node/httpAdapter.js +0 -76
- package/dist/Dev/node/httpAdapter.js.map +0 -1
- package/dist/Dev/node/scanGraph.d.ts +0 -21
- package/dist/Dev/node/scanGraph.d.ts.map +0 -1
- package/dist/Dev/node/scanGraph.js +0 -145
- package/dist/Dev/node/scanGraph.js.map +0 -1
- package/dist/Dev/node/watch.d.ts +0 -10
- package/dist/Dev/node/watch.d.ts.map +0 -1
- package/dist/Dev/node/watch.js +0 -44
- package/dist/Dev/node/watch.js.map +0 -1
- package/dist/Dev/usecase/allowedHost.d.ts +0 -16
- package/dist/Dev/usecase/allowedHost.d.ts.map +0 -1
- package/dist/Dev/usecase/allowedHost.js +0 -33
- package/dist/Dev/usecase/allowedHost.js.map +0 -1
- package/dist/Dev/usecase/allowedHost.spec.d.ts +0 -2
- package/dist/Dev/usecase/allowedHost.spec.d.ts.map +0 -1
- package/dist/Dev/usecase/allowedHost.spec.js +0 -13
- package/dist/Dev/usecase/allowedHost.spec.js.map +0 -1
- package/dist/Dev/usecase/buildGraph.d.ts +0 -12
- package/dist/Dev/usecase/buildGraph.d.ts.map +0 -1
- package/dist/Dev/usecase/buildGraph.js +0 -24
- package/dist/Dev/usecase/buildGraph.js.map +0 -1
- package/dist/Dev/usecase/buildGraph.spec.d.ts +0 -2
- package/dist/Dev/usecase/buildGraph.spec.d.ts.map +0 -1
- package/dist/Dev/usecase/buildGraph.spec.js +0 -16
- package/dist/Dev/usecase/buildGraph.spec.js.map +0 -1
- package/dist/Dev/usecase/decorateDevHtml.d.ts +0 -12
- package/dist/Dev/usecase/decorateDevHtml.d.ts.map +0 -1
- package/dist/Dev/usecase/decorateDevHtml.js +0 -15
- package/dist/Dev/usecase/decorateDevHtml.js.map +0 -1
- package/dist/Dev/usecase/decorateDevHtml.spec.d.ts +0 -2
- package/dist/Dev/usecase/decorateDevHtml.spec.d.ts.map +0 -1
- package/dist/Dev/usecase/decorateDevHtml.spec.js +0 -19
- package/dist/Dev/usecase/decorateDevHtml.spec.js.map +0 -1
- package/dist/Dev/usecase/invalidate.d.ts +0 -17
- package/dist/Dev/usecase/invalidate.d.ts.map +0 -1
- package/dist/Dev/usecase/invalidate.js +0 -57
- package/dist/Dev/usecase/invalidate.js.map +0 -1
- package/dist/Dev/usecase/invalidate.spec.d.ts +0 -2
- package/dist/Dev/usecase/invalidate.spec.d.ts.map +0 -1
- package/dist/Dev/usecase/invalidate.spec.js +0 -64
- package/dist/Dev/usecase/invalidate.spec.js.map +0 -1
- package/dist/Dev/usecase/parseImports.d.ts +0 -24
- package/dist/Dev/usecase/parseImports.d.ts.map +0 -1
- package/dist/Dev/usecase/parseImports.js +0 -40
- package/dist/Dev/usecase/parseImports.js.map +0 -1
- package/dist/Dev/usecase/parseImports.spec.d.ts +0 -2
- package/dist/Dev/usecase/parseImports.spec.d.ts.map +0 -1
- package/dist/Dev/usecase/parseImports.spec.js +0 -24
- package/dist/Dev/usecase/parseImports.spec.js.map +0 -1
- package/dist/Dev/usecase/reloadDecision.d.ts +0 -20
- package/dist/Dev/usecase/reloadDecision.d.ts.map +0 -1
- package/dist/Dev/usecase/reloadDecision.js +0 -52
- package/dist/Dev/usecase/reloadDecision.js.map +0 -1
- package/dist/Dev/usecase/reloadDecision.spec.d.ts +0 -2
- package/dist/Dev/usecase/reloadDecision.spec.d.ts.map +0 -1
- package/dist/Dev/usecase/reloadDecision.spec.js +0 -17
- package/dist/Dev/usecase/reloadDecision.spec.js.map +0 -1
- package/dist/domain/model/BundleConfig.d.ts +0 -136
- package/dist/domain/model/BundleConfig.d.ts.map +0 -1
- package/dist/domain/model/BundleConfig.js +0 -18
- package/dist/domain/model/BundleConfig.js.map +0 -1
- package/dist/domain/model/BundleConfig.spec.d.ts +0 -2
- package/dist/domain/model/BundleConfig.spec.d.ts.map +0 -1
- package/dist/domain/model/BundleConfig.spec.js +0 -8
- package/dist/domain/model/BundleConfig.spec.js.map +0 -1
- package/dist/domain/usecase/asBundleConfig.d.ts +0 -17
- package/dist/domain/usecase/asBundleConfig.d.ts.map +0 -1
- package/dist/domain/usecase/asBundleConfig.js +0 -179
- package/dist/domain/usecase/asBundleConfig.js.map +0 -1
- package/dist/domain/usecase/asBundleConfig.spec.d.ts +0 -2
- package/dist/domain/usecase/asBundleConfig.spec.d.ts.map +0 -1
- package/dist/domain/usecase/asBundleConfig.spec.js +0 -119
- package/dist/domain/usecase/asBundleConfig.spec.js.map +0 -1
- package/dist/domain/usecase/build.d.ts +0 -14
- package/dist/domain/usecase/build.d.ts.map +0 -1
- package/dist/domain/usecase/build.js +0 -177
- package/dist/domain/usecase/build.js.map +0 -1
- package/dist/domain/usecase/collectModules.d.ts +0 -53
- package/dist/domain/usecase/collectModules.d.ts.map +0 -1
- package/dist/domain/usecase/collectModules.js +0 -118
- package/dist/domain/usecase/collectModules.js.map +0 -1
- package/dist/domain/usecase/deriveExternal.d.ts +0 -25
- package/dist/domain/usecase/deriveExternal.d.ts.map +0 -1
- package/dist/domain/usecase/deriveExternal.js +0 -79
- package/dist/domain/usecase/deriveExternal.js.map +0 -1
- package/dist/domain/usecase/deriveExternal.spec.d.ts +0 -2
- package/dist/domain/usecase/deriveExternal.spec.d.ts.map +0 -1
- package/dist/domain/usecase/deriveExternal.spec.js +0 -56
- package/dist/domain/usecase/deriveExternal.spec.js.map +0 -1
- package/dist/domain/usecase/discoverWorkspace.d.ts +0 -27
- package/dist/domain/usecase/discoverWorkspace.d.ts.map +0 -1
- package/dist/domain/usecase/discoverWorkspace.js +0 -116
- package/dist/domain/usecase/discoverWorkspace.js.map +0 -1
- package/dist/domain/usecase/discoverWorkspace.spec.d.ts +0 -2
- package/dist/domain/usecase/discoverWorkspace.spec.d.ts.map +0 -1
- package/dist/domain/usecase/discoverWorkspace.spec.js +0 -23
- package/dist/domain/usecase/discoverWorkspace.spec.js.map +0 -1
- package/dist/domain/usecase/emitBundle.d.ts +0 -43
- package/dist/domain/usecase/emitBundle.d.ts.map +0 -1
- package/dist/domain/usecase/emitBundle.js +0 -157
- package/dist/domain/usecase/emitBundle.js.map +0 -1
- package/dist/domain/usecase/emitBundle.spec.d.ts +0 -2
- package/dist/domain/usecase/emitBundle.spec.d.ts.map +0 -1
- package/dist/domain/usecase/emitBundle.spec.js +0 -80
- package/dist/domain/usecase/emitBundle.spec.js.map +0 -1
- package/dist/domain/usecase/emitDts.d.ts +0 -32
- package/dist/domain/usecase/emitDts.d.ts.map +0 -1
- package/dist/domain/usecase/emitDts.js +0 -99
- package/dist/domain/usecase/emitDts.js.map +0 -1
- package/dist/domain/usecase/isExternal.d.ts +0 -12
- package/dist/domain/usecase/isExternal.d.ts.map +0 -1
- package/dist/domain/usecase/isExternal.js +0 -16
- package/dist/domain/usecase/isExternal.js.map +0 -1
- package/dist/domain/usecase/isExternal.spec.d.ts +0 -2
- package/dist/domain/usecase/isExternal.spec.d.ts.map +0 -1
- package/dist/domain/usecase/isExternal.spec.js +0 -16
- package/dist/domain/usecase/isExternal.spec.js.map +0 -1
- package/dist/domain/usecase/resolveSpecifier.d.ts +0 -35
- package/dist/domain/usecase/resolveSpecifier.d.ts.map +0 -1
- package/dist/domain/usecase/resolveSpecifier.js +0 -83
- package/dist/domain/usecase/resolveSpecifier.js.map +0 -1
- package/dist/domain/usecase/resolveSpecifier.spec.d.ts +0 -2
- package/dist/domain/usecase/resolveSpecifier.spec.d.ts.map +0 -1
- package/dist/domain/usecase/resolveSpecifier.spec.js +0 -44
- package/dist/domain/usecase/resolveSpecifier.spec.js.map +0 -1
- package/dist/domain/usecase/resolveWorkspaceSpecifier.d.ts +0 -29
- package/dist/domain/usecase/resolveWorkspaceSpecifier.d.ts.map +0 -1
- package/dist/domain/usecase/resolveWorkspaceSpecifier.js +0 -89
- package/dist/domain/usecase/resolveWorkspaceSpecifier.js.map +0 -1
- package/dist/domain/usecase/resolveWorkspaceSpecifier.spec.d.ts +0 -2
- package/dist/domain/usecase/resolveWorkspaceSpecifier.spec.d.ts.map +0 -1
- package/dist/domain/usecase/resolveWorkspaceSpecifier.spec.js +0 -27
- package/dist/domain/usecase/resolveWorkspaceSpecifier.spec.js.map +0 -1
- package/dist/domain/usecase/rewriteDtsAliases.d.ts +0 -25
- package/dist/domain/usecase/rewriteDtsAliases.d.ts.map +0 -1
- package/dist/domain/usecase/rewriteDtsAliases.js +0 -71
- package/dist/domain/usecase/rewriteDtsAliases.js.map +0 -1
- package/dist/domain/usecase/rewriteDtsAliases.spec.d.ts +0 -2
- package/dist/domain/usecase/rewriteDtsAliases.spec.d.ts.map +0 -1
- package/dist/domain/usecase/rewriteDtsAliases.spec.js +0 -35
- package/dist/domain/usecase/rewriteDtsAliases.spec.js.map +0 -1
- package/dist/entrypoints/cli.d.ts +0 -2
- package/dist/entrypoints/cli.d.ts.map +0 -1
- package/dist/entrypoints/cli.js +0 -79
- package/dist/entrypoints/cli.js.map +0 -1
- package/dist/index.d.ts +0 -21
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -28
- package/dist/index.js.map +0 -1
- package/dist/vendors/runner.d.ts +0 -20
- package/dist/vendors/runner.d.ts.map +0 -1
- package/dist/vendors/runner.js +0 -60
- package/dist/vendors/runner.js.map +0 -1
- package/dist/vendors/runner.spec.d.ts +0 -2
- package/dist/vendors/runner.spec.d.ts.map +0 -1
- package/dist/vendors/runner.spec.js +0 -20
- package/dist/vendors/runner.spec.js.map +0 -1
- package/dist/vendors/transpiler.d.ts +0 -19
- package/dist/vendors/transpiler.d.ts.map +0 -1
- package/dist/vendors/transpiler.js +0 -42
- package/dist/vendors/transpiler.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "plgg-bundle",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "In-house minimal library bundler for the plgg monorepo (ESM+CJS dual output, per-file .d.ts tree), zero new dependencies — reuses the project's own TypeScript, no native binding.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
|
-
"dist",
|
|
8
7
|
"src",
|
|
9
8
|
"bin"
|
|
10
9
|
],
|
|
11
10
|
"bin": {
|
|
12
11
|
"plgg-bundle": "bin/plgg-bundle.mjs"
|
|
13
12
|
},
|
|
14
|
-
"main": "dist/index.js",
|
|
15
|
-
"types": "dist/index.d.ts",
|
|
16
13
|
"scripts": {
|
|
17
14
|
"build": "tsc",
|
|
18
15
|
"tsc": "tsc --noEmit",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"devPoc.spec.d.ts","sourceRoot":"","sources":["../../../src/Dev/fixtures/devPoc.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import { test, check, all, toBe, } from "plgg-test";
|
|
2
|
-
import { spawn } from "node:child_process";
|
|
3
|
-
import { mkdtempSync, writeFileSync, } from "node:fs";
|
|
4
|
-
import { tmpdir } from "node:os";
|
|
5
|
-
import { join } from "node:path";
|
|
6
|
-
import { fileURLToPath } from "node:url";
|
|
7
|
-
// The end-to-end hot-reload PoC (ticket 041500). It runs
|
|
8
|
-
// the REAL toolchain — `node bin/plgg-bundle.mjs dev` on a
|
|
9
|
-
// throwaway fixture app — then edits a *deep* source module
|
|
10
|
-
// mid-run and proves the served output changes with NO
|
|
11
|
-
// process restart, and that the SSE reload channel opens.
|
|
12
|
-
// This is the fidelity oracle for the whole chain: bin +
|
|
13
|
-
// loader-hook version propagation + module-runner re-import
|
|
14
|
-
// + node:http serve + fs.watch + SSE.
|
|
15
|
-
/** This spec's dir → the package's bin/plgg-bundle.mjs. */
|
|
16
|
-
const BIN = join(fileURLToPath(import.meta.url), "..", "..", "..", "..", "bin", "plgg-bundle.mjs");
|
|
17
|
-
/** A dev entry that renders a deep child's message as HTML. */
|
|
18
|
-
const ENTRY_SRC = [
|
|
19
|
-
`import { message } from "./child.ts";`,
|
|
20
|
-
`export default () =>`,
|
|
21
|
-
` (_request) =>`,
|
|
22
|
-
` Promise.resolve(`,
|
|
23
|
-
` new Response(`,
|
|
24
|
-
' `<html><body>${message()}</body></html>`,',
|
|
25
|
-
` { headers: { "content-type": "text/html" } },`,
|
|
26
|
-
` ),`,
|
|
27
|
-
` );`,
|
|
28
|
-
].join("\n");
|
|
29
|
-
/** The deep child module the edit targets. */
|
|
30
|
-
const childSrc = (word) => `export const message = () => "${word}";\n`;
|
|
31
|
-
/** A minimal dev-only bundle config for the fixture app. */
|
|
32
|
-
const configSrc = (root) => `export default ${JSON.stringify({
|
|
33
|
-
root,
|
|
34
|
-
rootDir: ".",
|
|
35
|
-
outDir: "dist",
|
|
36
|
-
fileNamePattern: "[name].[format].js",
|
|
37
|
-
entries: [],
|
|
38
|
-
formats: ["es"],
|
|
39
|
-
alias: { prefix: "fixture", srcRoot: "." },
|
|
40
|
-
dev: {
|
|
41
|
-
entry: "entry.ts",
|
|
42
|
-
// Port 0 → ephemeral; the real port is read from
|
|
43
|
-
// the server's ready line.
|
|
44
|
-
port: 0,
|
|
45
|
-
watch: [root],
|
|
46
|
-
allowedHosts: [],
|
|
47
|
-
},
|
|
48
|
-
}, null, 2)};\n`;
|
|
49
|
-
/** Lay down the fixture app in a fresh temp dir. */
|
|
50
|
-
const writeFixture = () => {
|
|
51
|
-
const dir = mkdtempSync(join(tmpdir(), "plgg-dev-poc-"));
|
|
52
|
-
writeFileSync(join(dir, "child.ts"), childSrc("ALPHA"));
|
|
53
|
-
writeFileSync(join(dir, "entry.ts"), ENTRY_SRC);
|
|
54
|
-
writeFileSync(join(dir, "bundle.config.ts"), configSrc(dir));
|
|
55
|
-
return dir;
|
|
56
|
-
};
|
|
57
|
-
/** Sleep (test-only pacing for the watch/reload loop). */
|
|
58
|
-
const wait = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
59
|
-
/**
|
|
60
|
-
* Spawn `plgg-bundle dev` on the fixture and resolve the
|
|
61
|
-
* served URL once the ready line is printed.
|
|
62
|
-
*/
|
|
63
|
-
const startDev = (dir) => new Promise((resolve, reject) => {
|
|
64
|
-
const proc = spawn(process.execPath, [BIN, "dev", "bundle.config.ts"], { cwd: dir });
|
|
65
|
-
let out = "";
|
|
66
|
-
const onData = (chunk) => {
|
|
67
|
-
out += chunk.toString();
|
|
68
|
-
const m = out.match(/http:\/\/localhost:\d+\//);
|
|
69
|
-
if (m) {
|
|
70
|
-
proc.stdout?.off("data", onData);
|
|
71
|
-
resolve({ proc, url: m[0] });
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
proc.stdout?.on("data", onData);
|
|
75
|
-
proc.on("error", reject);
|
|
76
|
-
setTimeout(() => reject(new Error(`dev server did not start; output:\n${out}`)), 8000);
|
|
77
|
-
});
|
|
78
|
-
/** Fetch a URL's body text. */
|
|
79
|
-
const body = (url) => fetch(url).then((r) => r.text());
|
|
80
|
-
/**
|
|
81
|
-
* Poll `body(url)` until it contains `needle`, or throw on
|
|
82
|
-
* timeout. Proves the served output actually changed after
|
|
83
|
-
* the edit (not a fixed sleep guess).
|
|
84
|
-
*/
|
|
85
|
-
const pollFor = async (url, needle) => {
|
|
86
|
-
const deadline = 6000;
|
|
87
|
-
const step = 60;
|
|
88
|
-
for (let waited = 0; waited < deadline;) {
|
|
89
|
-
if ((await body(url)).includes(needle)) {
|
|
90
|
-
return true;
|
|
91
|
-
}
|
|
92
|
-
await wait(step);
|
|
93
|
-
waited += step;
|
|
94
|
-
}
|
|
95
|
-
return false;
|
|
96
|
-
};
|
|
97
|
-
test("plgg-bundle dev hot-reloads a deep source edit with no restart", async () => {
|
|
98
|
-
const dir = writeFixture();
|
|
99
|
-
const { proc, url } = await startDev(dir);
|
|
100
|
-
try {
|
|
101
|
-
const first = await body(url);
|
|
102
|
-
// Rewrite the DEEP child (not the entry) mid-run.
|
|
103
|
-
writeFileSync(join(dir, "child.ts"), childSrc("BETA"));
|
|
104
|
-
const reloaded = await pollFor(url, "BETA");
|
|
105
|
-
const stillAlive = proc.exitCode === null;
|
|
106
|
-
return all([
|
|
107
|
-
// Initial render came from the child module.
|
|
108
|
-
check(first.includes("ALPHA"), toBe(true)),
|
|
109
|
-
// The dev server injected its live-reload client.
|
|
110
|
-
check(first.includes("EventSource"), toBe(true)),
|
|
111
|
-
// The deep edit re-evaluated and is now served …
|
|
112
|
-
check(reloaded, toBe(true)),
|
|
113
|
-
// … by the SAME process (no restart).
|
|
114
|
-
check(stillAlive, toBe(true)),
|
|
115
|
-
]);
|
|
116
|
-
}
|
|
117
|
-
finally {
|
|
118
|
-
proc.kill();
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
test("plgg-bundle dev opens an SSE reload channel", async () => {
|
|
122
|
-
const dir = writeFixture();
|
|
123
|
-
const { proc, url } = await startDev(dir);
|
|
124
|
-
try {
|
|
125
|
-
const res = await fetch(`${url}__plgg_reload`);
|
|
126
|
-
const contentType = res.headers.get("content-type") ?? "";
|
|
127
|
-
// Read the opener frame, then release the stream.
|
|
128
|
-
const reader = res.body?.getReader();
|
|
129
|
-
const firstChunk = reader
|
|
130
|
-
? await reader.read()
|
|
131
|
-
: { value: undefined };
|
|
132
|
-
await reader?.cancel();
|
|
133
|
-
const text = firstChunk.value
|
|
134
|
-
? new TextDecoder().decode(firstChunk.value)
|
|
135
|
-
: "";
|
|
136
|
-
return all([
|
|
137
|
-
check(contentType.includes("text/event-stream"), toBe(true)),
|
|
138
|
-
check(text.includes("connected"), toBe(true)),
|
|
139
|
-
]);
|
|
140
|
-
}
|
|
141
|
-
finally {
|
|
142
|
-
proc.kill();
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
//# sourceMappingURL=devPoc.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"devPoc.spec.js","sourceRoot":"","sources":["../../../src/Dev/fixtures/devPoc.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,KAAK,EACL,GAAG,EACH,IAAI,GACL,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EACL,WAAW,EACX,aAAa,GACd,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,yDAAyD;AACzD,2DAA2D;AAC3D,4DAA4D;AAC5D,uDAAuD;AACvD,0DAA0D;AAC1D,yDAAyD;AACzD,4DAA4D;AAC5D,sCAAsC;AAEtC,2DAA2D;AAC3D,MAAM,GAAG,GAAG,IAAI,CACd,aAAa,CAAC,MAAM,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,CAAC,EAAE,CAAC;QACP,OAAO,GAAG,CAAC;YACT,KAAK,CACH,WAAW,CAAC,QAAQ,CAClB,mBAAmB,CACpB,EACD,IAAI,CAAC,IAAI,CAAC,CACX;YACD,KAAK,CACH,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,EAC1B,IAAI,CAAC,IAAI,CAAC,CACX;SACF,CAAC,CAAC;IACL,CAAC;YAAS,CAAC;QACT,IAAI,CAAC,IAAI,EAAE,CAAC;IACd,CAAC;AACH,CAAC,CAAC,CAAC"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The Web-standard request handler an app hands the dev
|
|
3
|
-
* server: `Request => Promise<Response>`. This is the same
|
|
4
|
-
* shape plgg-server's `toFetch` produces, reproduced here
|
|
5
|
-
* as a bare structural type so the toolchain never imports
|
|
6
|
-
* a plgg package.
|
|
7
|
-
*/
|
|
8
|
-
export type Fetch = (request: Request) => Promise<Response>;
|
|
9
|
-
/**
|
|
10
|
-
* The app⇄dev-server contract. An app's **dev entry**
|
|
11
|
-
* module default-exports a factory that builds its
|
|
12
|
-
* {@link Fetch}. The dev server calls it once on start and
|
|
13
|
-
* again after every hot-reload — a cache-busted re-import
|
|
14
|
-
* of the entry re-runs the factory over freshly
|
|
15
|
-
* re-evaluated source, which is how a code edit takes
|
|
16
|
-
* effect with no process restart. The factory may be
|
|
17
|
-
* async (config load, route discovery).
|
|
18
|
-
*/
|
|
19
|
-
export type FetchFactory = () => Fetch | Promise<Fetch>;
|
|
20
|
-
//# sourceMappingURL=Fetch.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Fetch.d.ts","sourceRoot":"","sources":["../../../src/Dev/model/Fetch.ts"],"names":[],"mappings":"AAOA;;;;;;GAMG;AACH,MAAM,MAAM,KAAK,GAAG,CAClB,OAAO,EAAE,OAAO,KACb,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEvB;;;;;;;;;GASG;AACH,MAAM,MAAM,YAAY,GAAG,MACvB,KAAK,GACL,OAAO,CAAC,KAAK,CAAC,CAAC"}
|
package/dist/Dev/model/Fetch.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
// Plain-TS build tool: plgg-bundle is a foundation
|
|
2
|
-
// bundler and must not depend on the libraries it builds
|
|
3
|
-
// (plgg / plgg-server). So the dev server speaks the
|
|
4
|
-
// Web-standard request/response contract directly rather
|
|
5
|
-
// than plgg-server's branded `Fetch`. See the package
|
|
6
|
-
// README and the ticket's hard constraints.
|
|
7
|
-
export {};
|
|
8
|
-
//# sourceMappingURL=Fetch.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Fetch.js","sourceRoot":"","sources":["../../../src/Dev/model/Fetch.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,yDAAyD;AACzD,qDAAqD;AACrD,yDAAyD;AACzD,sDAAsD;AACtD,4CAA4C"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The dev server's view of the app's local module graph:
|
|
3
|
-
* a map from each source file (absolute path) to the
|
|
4
|
-
* absolute paths of the local files it imports. Only
|
|
5
|
-
* workspace-local edges are recorded — `node:*` and
|
|
6
|
-
* `node_modules` specifiers are not part of the watched
|
|
7
|
-
* graph (they do not change during a dev session).
|
|
8
|
-
*
|
|
9
|
-
* Built fresh from disk on each change by the node adapter
|
|
10
|
-
* (scan → resolve), then consumed by the pure
|
|
11
|
-
* {@link transitiveImporters} / reload-decision logic. The
|
|
12
|
-
* graph is what lets the server ignore a save to a file
|
|
13
|
-
* the app does not import, and report exactly which
|
|
14
|
-
* modules a change invalidates.
|
|
15
|
-
*/
|
|
16
|
-
export type ModuleGraph = ReadonlyMap<string, ReadonlyArray<string>>;
|
|
17
|
-
/**
|
|
18
|
-
* One resolved import edge: `from` imports `to` (both
|
|
19
|
-
* absolute paths). The adapter produces these by scanning
|
|
20
|
-
* a file's import specifiers and resolving the local ones;
|
|
21
|
-
* {@link buildGraph} folds them into a {@link ModuleGraph}.
|
|
22
|
-
*/
|
|
23
|
-
export type Edge = Readonly<{
|
|
24
|
-
from: string;
|
|
25
|
-
to: string;
|
|
26
|
-
}>;
|
|
27
|
-
//# sourceMappingURL=ModuleGraph.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ModuleGraph.d.ts","sourceRoot":"","sources":["../../../src/Dev/model/ModuleGraph.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,WAAW,GAAG,WAAW,CACnC,MAAM,EACN,aAAa,CAAC,MAAM,CAAC,CACtB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,IAAI,GAAG,QAAQ,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ModuleGraph.js","sourceRoot":"","sources":["../../../src/Dev/model/ModuleGraph.ts"],"names":[],"mappings":""}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/** The dev-only Server-Sent-Events live-reload route. */
|
|
2
|
-
export declare const RELOAD_PATH = "/__plgg_reload";
|
|
3
|
-
/**
|
|
4
|
-
* The SSE opener frame. A comment line keeps the stream
|
|
5
|
-
* from idling before the first reload is pushed.
|
|
6
|
-
*/
|
|
7
|
-
export declare const SSE_PRELUDE = ": connected\n\n";
|
|
8
|
-
/**
|
|
9
|
-
* A default-event SSE frame the injected client's
|
|
10
|
-
* `onmessage` handler reacts to by reloading the page.
|
|
11
|
-
*/
|
|
12
|
-
export declare const RELOAD_FRAME = "data: reload\n\n";
|
|
13
|
-
/**
|
|
14
|
-
* The dev-only live-reload client: a constant `<script>`
|
|
15
|
-
* opening an `EventSource` to {@link RELOAD_PATH} that
|
|
16
|
-
* reloads the page on every pushed frame. This literal is
|
|
17
|
-
* string-appended onto rendered HTML output ONLY (see
|
|
18
|
-
* `decorateDevHtml`) — it never enters a typed render
|
|
19
|
-
* tree, so a production build can never emit it.
|
|
20
|
-
*/
|
|
21
|
-
export declare const LIVE_RELOAD_SCRIPT: string;
|
|
22
|
-
//# sourceMappingURL=Protocol.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Protocol.d.ts","sourceRoot":"","sources":["../../../src/Dev/model/Protocol.ts"],"names":[],"mappings":"AAQA,yDAAyD;AACzD,eAAO,MAAM,WAAW,mBAAmB,CAAC;AAE5C;;;GAGG;AACH,eAAO,MAAM,WAAW,oBAAoB,CAAC;AAE7C;;;GAGG;AACH,eAAO,MAAM,YAAY,qBAAqB,CAAC;AAE/C;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,QAGiB,CAAC"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
// The dev-only live-reload wire protocol: the SSE route
|
|
2
|
-
// the injected client script connects to, and the frames
|
|
3
|
-
// pushed over it. Kept as pure constants/string builders
|
|
4
|
-
// (no `node:*`, no sockets) so the transport shape is
|
|
5
|
-
// unit-testable and the node adapter only owns the socket
|
|
6
|
-
// registry. Mirrors plggpress's hand-rolled SSE reload,
|
|
7
|
-
// reproduced here plgg-free in the toolchain.
|
|
8
|
-
/** The dev-only Server-Sent-Events live-reload route. */
|
|
9
|
-
export const RELOAD_PATH = "/__plgg_reload";
|
|
10
|
-
/**
|
|
11
|
-
* The SSE opener frame. A comment line keeps the stream
|
|
12
|
-
* from idling before the first reload is pushed.
|
|
13
|
-
*/
|
|
14
|
-
export const SSE_PRELUDE = ": connected\n\n";
|
|
15
|
-
/**
|
|
16
|
-
* A default-event SSE frame the injected client's
|
|
17
|
-
* `onmessage` handler reacts to by reloading the page.
|
|
18
|
-
*/
|
|
19
|
-
export const RELOAD_FRAME = "data: reload\n\n";
|
|
20
|
-
/**
|
|
21
|
-
* The dev-only live-reload client: a constant `<script>`
|
|
22
|
-
* opening an `EventSource` to {@link RELOAD_PATH} that
|
|
23
|
-
* reloads the page on every pushed frame. This literal is
|
|
24
|
-
* string-appended onto rendered HTML output ONLY (see
|
|
25
|
-
* `decorateDevHtml`) — it never enters a typed render
|
|
26
|
-
* tree, so a production build can never emit it.
|
|
27
|
-
*/
|
|
28
|
-
export const LIVE_RELOAD_SCRIPT = "<script>new EventSource('" +
|
|
29
|
-
RELOAD_PATH +
|
|
30
|
-
"').onmessage=()=>location.reload();</script>";
|
|
31
|
-
//# sourceMappingURL=Protocol.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Protocol.js","sourceRoot":"","sources":["../../../src/Dev/model/Protocol.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yDAAyD;AACzD,yDAAyD;AACzD,sDAAsD;AACtD,0DAA0D;AAC1D,wDAAwD;AACxD,8CAA8C;AAE9C,yDAAyD;AACzD,MAAM,CAAC,MAAM,WAAW,GAAG,gBAAgB,CAAC;AAE5C;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,iBAAiB,CAAC;AAE7C;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,kBAAkB,CAAC;AAE/C;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAC7B,2BAA2B;IAC3B,WAAW;IACX,8CAA8C,CAAC"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { type BundleConfig } from "plgg-bundle/domain/model/BundleConfig";
|
|
2
|
-
/**
|
|
3
|
-
* A running dev server: the URL it is reachable at and a
|
|
4
|
-
* `close` that stops the listener + watchers. The CLI
|
|
5
|
-
* ignores `close` (the server runs for the process
|
|
6
|
-
* lifetime); a test uses it to shut the server down so the
|
|
7
|
-
* process can exit.
|
|
8
|
-
*/
|
|
9
|
-
export type DevServer = Readonly<{
|
|
10
|
-
url: string;
|
|
11
|
-
close: () => void;
|
|
12
|
-
}>;
|
|
13
|
-
/**
|
|
14
|
-
* Start the dev server for a config's `dev` section: load
|
|
15
|
-
* the app Fetch, serve it over node:http, watch the source
|
|
16
|
-
* roots, and hot-reload on every relevant code/content
|
|
17
|
-
* edit. Resolves once the listener is up, with the
|
|
18
|
-
* reachable URL and a `close` handle.
|
|
19
|
-
*/
|
|
20
|
-
export declare const runDevServer: (config: BundleConfig) => Promise<DevServer>;
|
|
21
|
-
//# sourceMappingURL=devServer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"devServer.d.ts","sourceRoot":"","sources":["../../../src/Dev/node/devServer.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,uCAAuC,CAAC;AA8W1E;;;;;;GAMG;AACH,MAAM,MAAM,SAAS,GAAG,QAAQ,CAAC;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB,CAAC,CAAC;AAeH;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,GACvB,QAAQ,YAAY,KACnB,OAAO,CAAC,SAAS,CAmFnB,CAAC"}
|
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-
import { resolve, isAbsolute, join, } from "node:path";
|
|
2
|
-
import { existsSync } from "node:fs";
|
|
3
|
-
import { pathToFileURL } from "node:url";
|
|
4
|
-
import { register } from "node:module";
|
|
5
|
-
import {} from "node:http";
|
|
6
|
-
import {} from "plgg-bundle/Dev/model/Fetch";
|
|
7
|
-
import {} from "plgg-bundle/Dev/model/ModuleGraph";
|
|
8
|
-
import { RELOAD_PATH, SSE_PRELUDE, RELOAD_FRAME, } from "plgg-bundle/Dev/model/Protocol";
|
|
9
|
-
import { isAllowedHost } from "plgg-bundle/Dev/usecase/allowedHost";
|
|
10
|
-
import { shouldReload } from "plgg-bundle/Dev/usecase/reloadDecision";
|
|
11
|
-
import { decorateDevHtml } from "plgg-bundle/Dev/usecase/decorateDevHtml";
|
|
12
|
-
import {} from "plgg-bundle/domain/model/BundleConfig";
|
|
13
|
-
import { serveFetch, } from "plgg-bundle/Dev/node/httpAdapter";
|
|
14
|
-
import { watchRoots } from "plgg-bundle/Dev/node/watch";
|
|
15
|
-
import { scanGraph, } from "plgg-bundle/Dev/node/scanGraph";
|
|
16
|
-
/** UTF-8 encode at call time (never at module top level). */
|
|
17
|
-
const encodeUtf8 = (text) => new TextEncoder().encode(text);
|
|
18
|
-
/** Whether a value is a non-null object. */
|
|
19
|
-
const isRecord = (v) => typeof v === "object" && v !== null;
|
|
20
|
-
/**
|
|
21
|
-
* The dev-entry factory to invoke: the module's `default`
|
|
22
|
-
* export, or the module itself when it has none. Stays
|
|
23
|
-
* `unknown` — {@link callFactory} does the callable check.
|
|
24
|
-
*/
|
|
25
|
-
const defaultExport = (mod) => isRecord(mod) && "default" in mod
|
|
26
|
-
? mod["default"]
|
|
27
|
-
: mod;
|
|
28
|
-
/**
|
|
29
|
-
* Invoke a dev-entry factory and normalise its result to a
|
|
30
|
-
* {@link Fetch}. The imported value is `unknown`, so the
|
|
31
|
-
* boundary is validated at runtime (`typeof`/`instanceof`)
|
|
32
|
-
* and wrapped into a correctly-typed `Fetch` — no `as`, no
|
|
33
|
-
* `any` annotation. Calling a value narrowed only to
|
|
34
|
-
* `Function` yields `any`; feeding it through the
|
|
35
|
-
* `unknown`-typed {@link normalizeFetch} re-establishes
|
|
36
|
-
* the type at the seam.
|
|
37
|
-
*/
|
|
38
|
-
const callFactory = (factory) => {
|
|
39
|
-
if (typeof factory !== "function") {
|
|
40
|
-
throw new Error("dev entry must default-export a () => Fetch factory");
|
|
41
|
-
}
|
|
42
|
-
return Promise.resolve(factory()).then(normalizeFetch);
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* Validate that a factory's result is a callable and wrap
|
|
46
|
-
* it as a {@link Fetch} that checks each answer is a
|
|
47
|
-
* `Response`.
|
|
48
|
-
*/
|
|
49
|
-
const normalizeFetch = (value) => {
|
|
50
|
-
if (typeof value !== "function") {
|
|
51
|
-
throw new Error("dev entry factory must return a Fetch (a function)");
|
|
52
|
-
}
|
|
53
|
-
return (request) => Promise.resolve(value(request)).then(asResponse);
|
|
54
|
-
};
|
|
55
|
-
/** Assert a Fetch answer is a Web `Response`. */
|
|
56
|
-
const asResponse = (value) => {
|
|
57
|
-
if (value instanceof Response) {
|
|
58
|
-
return value;
|
|
59
|
-
}
|
|
60
|
-
throw new Error("dev entry Fetch must resolve to a Response");
|
|
61
|
-
};
|
|
62
|
-
/** An Error's message, or a stringified non-Error. */
|
|
63
|
-
const msg = (e) => e instanceof Error ? e.message : String(e);
|
|
64
|
-
/** dev-server console output — a deliberate side effect. */
|
|
65
|
-
const log = (message) => {
|
|
66
|
-
process.stdout.write(`${message}\n`);
|
|
67
|
-
};
|
|
68
|
-
/**
|
|
69
|
-
* Cache-busting re-import of the dev entry at `version`,
|
|
70
|
-
* then run its factory to get a fresh {@link Fetch}. The
|
|
71
|
-
* loader hook propagates `?v=<version>` down the local
|
|
72
|
-
* import graph, so the whole affected subgraph
|
|
73
|
-
* re-evaluates — real code hot-reload.
|
|
74
|
-
*/
|
|
75
|
-
const load = async (entryUrl, version) => {
|
|
76
|
-
const mod = await import(`${entryUrl}?v=${version}`);
|
|
77
|
-
return callFactory(defaultExport(mod));
|
|
78
|
-
};
|
|
79
|
-
/** The 403 a disallowed Host gets. */
|
|
80
|
-
const forbidden = () => new Response("Forbidden", {
|
|
81
|
-
status: 403,
|
|
82
|
-
headers: {
|
|
83
|
-
"content-type": "text/plain; charset=utf-8",
|
|
84
|
-
},
|
|
85
|
-
});
|
|
86
|
-
/**
|
|
87
|
-
* The DEV-ONLY SSE endpoint: an open `text/event-stream`
|
|
88
|
-
* whose controller joins the client registry and is
|
|
89
|
-
* removed on disconnect; a reload enqueues a frame onto it.
|
|
90
|
-
*/
|
|
91
|
-
const sseResponse = (clients) => {
|
|
92
|
-
// Bridge seam: capture the controller so `start` can
|
|
93
|
-
// register it and `cancel` can remove the same one.
|
|
94
|
-
let registered;
|
|
95
|
-
return new Response(new ReadableStream({
|
|
96
|
-
start: (controller) => {
|
|
97
|
-
registered = controller;
|
|
98
|
-
clients.add(controller);
|
|
99
|
-
controller.enqueue(encodeUtf8(SSE_PRELUDE));
|
|
100
|
-
},
|
|
101
|
-
cancel: () => {
|
|
102
|
-
if (registered !== undefined) {
|
|
103
|
-
clients.delete(registered);
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
}), {
|
|
107
|
-
status: 200,
|
|
108
|
-
headers: {
|
|
109
|
-
"content-type": "text/event-stream",
|
|
110
|
-
"cache-control": "no-cache",
|
|
111
|
-
connection: "keep-alive",
|
|
112
|
-
},
|
|
113
|
-
});
|
|
114
|
-
};
|
|
115
|
-
/** Push a reload frame to every open live-reload stream. */
|
|
116
|
-
const notifyReload = (clients) => clients.forEach((controller) => controller.enqueue(encodeUtf8(RELOAD_FRAME)));
|
|
117
|
-
/** Whether a response carries an HTML body. */
|
|
118
|
-
const isHtml = (response) => {
|
|
119
|
-
const ct = response.headers.get("content-type");
|
|
120
|
-
return ct !== null && ct.includes("text/html");
|
|
121
|
-
};
|
|
122
|
-
/**
|
|
123
|
-
* Dev HTML headers: drop `content-length` (the appended
|
|
124
|
-
* script grew the body) and force `no-store` so a tunnel/
|
|
125
|
-
* CDN never serves stale inlined styles after an edit.
|
|
126
|
-
*/
|
|
127
|
-
const devHtmlHeaders = (headers) => {
|
|
128
|
-
const next = new Headers([...headers].filter(([key]) => {
|
|
129
|
-
const lower = key.toLowerCase();
|
|
130
|
-
return (lower !== "content-length" &&
|
|
131
|
-
lower !== "cache-control");
|
|
132
|
-
}));
|
|
133
|
-
next.set("cache-control", "no-store");
|
|
134
|
-
return next;
|
|
135
|
-
};
|
|
136
|
-
/** Append the live-reload script to an HTML response. */
|
|
137
|
-
const decorateHtmlResponse = (response) => isHtml(response)
|
|
138
|
-
? response
|
|
139
|
-
.text()
|
|
140
|
-
.then((html) => new Response(decorateDevHtml(html), {
|
|
141
|
-
status: response.status,
|
|
142
|
-
headers: devHtmlHeaders(response.headers),
|
|
143
|
-
}))
|
|
144
|
-
: Promise.resolve(response);
|
|
145
|
-
/**
|
|
146
|
-
* The wrapping dev handler: 403 a disallowed Host, answer
|
|
147
|
-
* the SSE route, otherwise run the live app Fetch and
|
|
148
|
-
* append the live-reload script to its HTML.
|
|
149
|
-
*/
|
|
150
|
-
const devHandler = (state, allowedHosts) => (request) => {
|
|
151
|
-
const url = new URL(request.url);
|
|
152
|
-
if (!isAllowedHost(allowedHosts)(url.host)) {
|
|
153
|
-
return Promise.resolve(forbidden());
|
|
154
|
-
}
|
|
155
|
-
if (url.pathname === RELOAD_PATH) {
|
|
156
|
-
return Promise.resolve(sseResponse(state.clients));
|
|
157
|
-
}
|
|
158
|
-
return state
|
|
159
|
-
.appFetch(request)
|
|
160
|
-
.then(decorateHtmlResponse);
|
|
161
|
-
};
|
|
162
|
-
/** Resolve a config value that may be absolute or root-relative. */
|
|
163
|
-
const under = (root, path) => isAbsolute(path)
|
|
164
|
-
? path
|
|
165
|
-
: resolve(root, path);
|
|
166
|
-
/**
|
|
167
|
-
* Register the dev-only cross-package source resolver
|
|
168
|
-
* (`bin/appAliasHook.mjs`) with the alias rules, so a
|
|
169
|
-
* dependency's `<prefix>/*` imports load from source and
|
|
170
|
-
* hot-reload. Registered later than the package's own hook
|
|
171
|
-
* so it runs first and short-circuits on an alias hit.
|
|
172
|
-
*/
|
|
173
|
-
const registerSourceAliases = (aliases) => {
|
|
174
|
-
const hookUrl = new URL("../../../bin/appAliasHook.mjs", import.meta.url).href;
|
|
175
|
-
register(hookUrl, import.meta.url, {
|
|
176
|
-
data: {
|
|
177
|
-
aliases: aliases.map((a) => ({
|
|
178
|
-
prefix: a.prefix,
|
|
179
|
-
srcDir: a.srcDir,
|
|
180
|
-
})),
|
|
181
|
-
},
|
|
182
|
-
});
|
|
183
|
-
};
|
|
184
|
-
/**
|
|
185
|
-
* Map an fs.watch filename (relative to some watched root)
|
|
186
|
-
* to an absolute path by probing each root, or null when
|
|
187
|
-
* it matches none (a deletion) — the reload decision then
|
|
188
|
-
* reloads conservatively.
|
|
189
|
-
*/
|
|
190
|
-
const toChanged = (roots, filename) => {
|
|
191
|
-
for (const root of roots) {
|
|
192
|
-
const abs = resolve(root, filename);
|
|
193
|
-
if (existsSync(abs)) {
|
|
194
|
-
return abs;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
return null;
|
|
198
|
-
};
|
|
199
|
-
/**
|
|
200
|
-
* A single hot-reload cycle: refresh the graph, decide
|
|
201
|
-
* whether the change is relevant, then bump the version,
|
|
202
|
-
* re-import the entry (re-evaluating the changed
|
|
203
|
-
* subgraph), swap the live Fetch, and notify browsers. A
|
|
204
|
-
* failed re-import keeps the last good Fetch so a
|
|
205
|
-
* mid-edit save never crashes the loop.
|
|
206
|
-
*/
|
|
207
|
-
const reload = async (state, entryUrl, watchAbs, aliases, filename) => {
|
|
208
|
-
state.graph = scanGraph(watchAbs, aliases);
|
|
209
|
-
const changed = toChanged(watchAbs, filename);
|
|
210
|
-
if (changed !== null &&
|
|
211
|
-
!shouldReload(state.graph, changed)) {
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
state.version += 1;
|
|
215
|
-
try {
|
|
216
|
-
state.appFetch = await load(entryUrl, state.version);
|
|
217
|
-
}
|
|
218
|
-
catch (e) {
|
|
219
|
-
log(`plgg-bundle dev: reload failed (${msg(e)}) — keeping last good build`);
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
notifyReload(state.clients);
|
|
223
|
-
log(`plgg-bundle dev: hot-reloaded (${filename})`);
|
|
224
|
-
};
|
|
225
|
-
/** The URL the dev server is reachable at. */
|
|
226
|
-
const devUrl = (port) => `http://localhost:${port}/`;
|
|
227
|
-
/** The port a listening server actually bound (honours port 0). */
|
|
228
|
-
const boundPort = (server, fallback) => {
|
|
229
|
-
const addr = server.address();
|
|
230
|
-
return typeof addr === "object" &&
|
|
231
|
-
addr !== null &&
|
|
232
|
-
typeof addr.port === "number"
|
|
233
|
-
? addr.port
|
|
234
|
-
: fallback;
|
|
235
|
-
};
|
|
236
|
-
/**
|
|
237
|
-
* Start the dev server for a config's `dev` section: load
|
|
238
|
-
* the app Fetch, serve it over node:http, watch the source
|
|
239
|
-
* roots, and hot-reload on every relevant code/content
|
|
240
|
-
* edit. Resolves once the listener is up, with the
|
|
241
|
-
* reachable URL and a `close` handle.
|
|
242
|
-
*/
|
|
243
|
-
export const runDevServer = async (config) => {
|
|
244
|
-
const dev = config.dev;
|
|
245
|
-
if (dev === undefined) {
|
|
246
|
-
throw new Error("plgg-bundle dev: config has no `dev` section");
|
|
247
|
-
}
|
|
248
|
-
const entryUrl = pathToFileURL(under(config.root, dev.entry)).href;
|
|
249
|
-
const watchAbs = dev.watch.map((w) => under(config.root, w));
|
|
250
|
-
// The app's own self-alias (source), plus any
|
|
251
|
-
// cross-package `sourceAliases` — the resolution rules for
|
|
252
|
-
// both the module graph AND the loader hook.
|
|
253
|
-
const aliases = [
|
|
254
|
-
{
|
|
255
|
-
prefix: config.alias.prefix,
|
|
256
|
-
srcDir: join(config.root, config.alias.srcRoot),
|
|
257
|
-
},
|
|
258
|
-
...dev.sourceAliases.map((a) => ({
|
|
259
|
-
prefix: a.prefix,
|
|
260
|
-
srcDir: under(config.root, a.srcDir),
|
|
261
|
-
})),
|
|
262
|
-
];
|
|
263
|
-
// Register the cross-package source resolver BEFORE the
|
|
264
|
-
// first entry import, so a dependency's `<prefix>/*`
|
|
265
|
-
// loads from source and hot-reloads. Only needed when the
|
|
266
|
-
// app pulls another package's source (a self-contained
|
|
267
|
-
// app resolves everything relatively / via its own hook).
|
|
268
|
-
if (dev.sourceAliases.length > 0) {
|
|
269
|
-
registerSourceAliases(aliases);
|
|
270
|
-
}
|
|
271
|
-
const state = {
|
|
272
|
-
version: 1,
|
|
273
|
-
appFetch: await load(entryUrl, 1),
|
|
274
|
-
graph: scanGraph(watchAbs, aliases),
|
|
275
|
-
clients: new Set(),
|
|
276
|
-
};
|
|
277
|
-
const handler = devHandler(state, dev.allowedHosts);
|
|
278
|
-
const options = {
|
|
279
|
-
port: dev.port,
|
|
280
|
-
};
|
|
281
|
-
const server = await new Promise((ready) => {
|
|
282
|
-
const s = serveFetch(options, () => handler, () => ready(s))();
|
|
283
|
-
});
|
|
284
|
-
const url = devUrl(boundPort(server, dev.port));
|
|
285
|
-
log(`plgg-bundle dev on ${url}`);
|
|
286
|
-
const watchers = watchRoots(watchAbs, (filename) => {
|
|
287
|
-
void reload(state, entryUrl, watchAbs, aliases, filename);
|
|
288
|
-
});
|
|
289
|
-
return {
|
|
290
|
-
url,
|
|
291
|
-
close: () => {
|
|
292
|
-
server.closeAllConnections();
|
|
293
|
-
server.close();
|
|
294
|
-
watchers.forEach((w) => w.close());
|
|
295
|
-
},
|
|
296
|
-
};
|
|
297
|
-
};
|
|
298
|
-
//# sourceMappingURL=devServer.js.map
|