@freshpack/runtime 1.0.0 → 1.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/CHANGELOG.md +20 -0
- package/LICENSE +13 -12
- package/client-hmr.d.ts +1 -0
- package/{client-hmr.ts → client-hmr.js} +13 -38
- package/client-hmr.js.map +1 -0
- package/internal.d.ts +2 -0
- package/internal.js +5 -0
- package/internal.js.map +1 -0
- package/mod.d.ts +1 -0
- package/{mod.ts → mod.js} +3 -4
- package/mod.js.map +1 -0
- package/package.json +35 -9
- package/server-middleware.d.ts +4 -0
- package/{server-middleware.ts → server-middleware.js} +25 -42
- package/server-middleware.js.map +1 -0
- package/internal.ts +0 -5
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# @freshpack/runtime
|
|
2
|
+
|
|
3
|
+
## 1.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- workaround for webpack 112 bug
|
|
8
|
+
|
|
9
|
+
- Updated dependencies:
|
|
10
|
+
- @freshpack/webpack@1.0.2
|
|
11
|
+
|
|
12
|
+
## 1.0.1
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- prepack
|
|
17
|
+
|
|
18
|
+
- Updated dependencies:
|
|
19
|
+
- @freshpack/core@3.0.2
|
|
20
|
+
- @freshpack/webpack@1.0.1
|
package/LICENSE
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2026
|
|
3
|
+
Copyright (c) 2026 Yaroslav Bolyukin <iam@lach.pw>
|
|
4
4
|
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
the Software without restriction, including without limitation the rights
|
|
8
|
-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
the Software, and to permit persons to whom the Software is
|
|
10
|
-
subject to the following conditions:
|
|
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
11
|
|
|
12
12
|
The above copyright notice and this permission notice shall be included in all
|
|
13
13
|
copies or substantial portions of the Software.
|
|
14
14
|
|
|
15
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
|
-
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
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/client-hmr.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,26 +1,16 @@
|
|
|
1
1
|
/// <reference types="webpack/module" />
|
|
2
2
|
|
|
3
|
-
let lastHash
|
|
3
|
+
let lastHash;
|
|
4
4
|
function upToDate() {
|
|
5
|
-
return lastHash
|
|
5
|
+
return lastHash.indexOf(__webpack_hash__) >= 0;
|
|
6
6
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
updatedModules: (string | number)[],
|
|
10
|
-
renewedModules: (string | number)[] | null,
|
|
11
|
-
) {
|
|
12
|
-
const unacceptedModules = updatedModules.filter((moduleId) => {
|
|
7
|
+
function logUpdate(updatedModules, renewedModules) {
|
|
8
|
+
const unacceptedModules = updatedModules.filter(moduleId => {
|
|
13
9
|
return renewedModules && renewedModules.indexOf(moduleId) < 0;
|
|
14
10
|
});
|
|
15
|
-
|
|
16
11
|
if (unacceptedModules.length > 0) {
|
|
17
|
-
console.warn(
|
|
18
|
-
"[HMR]",
|
|
19
|
-
"The following modules couldn't be hot updated: (They would need a full reload!)",
|
|
20
|
-
unacceptedModules,
|
|
21
|
-
);
|
|
12
|
+
console.warn("[HMR]", "The following modules couldn't be hot updated: (They would need a full reload!)", unacceptedModules);
|
|
22
13
|
}
|
|
23
|
-
|
|
24
14
|
if (!renewedModules || renewedModules.length === 0) {
|
|
25
15
|
console.info("[HMR]", "Nothing hot updated.");
|
|
26
16
|
} else {
|
|
@@ -34,39 +24,28 @@ function logUpdate(
|
|
|
34
24
|
console.info("[HMR]", "-", moduleId);
|
|
35
25
|
}
|
|
36
26
|
});
|
|
37
|
-
const numberIds = renewedModules.every(
|
|
27
|
+
const numberIds = renewedModules.every(moduleId => {
|
|
38
28
|
return typeof moduleId === "number";
|
|
39
29
|
});
|
|
40
30
|
if (numberIds) {
|
|
41
|
-
console.info(
|
|
42
|
-
"[HMR]",
|
|
43
|
-
'Consider using the optimization.moduleIds: "named" for module names.',
|
|
44
|
-
);
|
|
31
|
+
console.info("[HMR]", 'Consider using the optimization.moduleIds: "named" for module names.');
|
|
45
32
|
}
|
|
46
33
|
}
|
|
47
34
|
}
|
|
48
|
-
|
|
49
35
|
async function checkUpdates(fromUpdate = false) {
|
|
50
36
|
try {
|
|
51
37
|
const updatedModules = await import.meta.webpackHot.check();
|
|
52
38
|
if (!updatedModules) {
|
|
53
|
-
if (fromUpdate) console.info("[HMR]", "Update applied");
|
|
54
|
-
else console.warn("[HMR]", "Promised update was not found");
|
|
39
|
+
if (fromUpdate) console.info("[HMR]", "Update applied");else console.warn("[HMR]", "Promised update was not found");
|
|
55
40
|
return;
|
|
56
41
|
}
|
|
57
42
|
const renewedModules = await import.meta.webpackHot.apply({
|
|
58
43
|
ignoreUnaccepted: true,
|
|
59
44
|
onUnaccepted(data) {
|
|
60
|
-
console.warn(
|
|
61
|
-
|
|
62
|
-
"Update was not accepted:",
|
|
63
|
-
data.chain.join(" => "),
|
|
64
|
-
);
|
|
65
|
-
},
|
|
45
|
+
console.warn("[HMR]", "Update was not accepted:", data.chain.join(" => "));
|
|
46
|
+
}
|
|
66
47
|
});
|
|
67
|
-
|
|
68
48
|
logUpdate(updatedModules, renewedModules);
|
|
69
|
-
|
|
70
49
|
if (!upToDate()) {
|
|
71
50
|
await checkUpdates(true);
|
|
72
51
|
}
|
|
@@ -79,24 +58,19 @@ async function checkUpdates(fromUpdate = false) {
|
|
|
79
58
|
}
|
|
80
59
|
}
|
|
81
60
|
}
|
|
82
|
-
|
|
83
61
|
async function signalled() {
|
|
84
62
|
if (import.meta.webpackHot.status() !== "idle") {
|
|
85
|
-
console.warn(
|
|
86
|
-
"[HMR]",
|
|
87
|
-
`Bundle update, but state is not idle: ${import.meta.webpackHot.status()}`,
|
|
88
|
-
);
|
|
63
|
+
console.warn("[HMR]", `Bundle update, but state is not idle: ${import.meta.webpackHot.status()}`);
|
|
89
64
|
return;
|
|
90
65
|
}
|
|
91
66
|
await checkUpdates();
|
|
92
67
|
}
|
|
93
|
-
|
|
94
68
|
if (import.meta.webpackHot) {
|
|
95
69
|
const ws = new WebSocket("/_freshpack_hmr");
|
|
96
70
|
ws.addEventListener("open", () => {
|
|
97
71
|
console.info("[HMR]", "opened");
|
|
98
72
|
});
|
|
99
|
-
ws.addEventListener("message",
|
|
73
|
+
ws.addEventListener("message", msg => {
|
|
100
74
|
const data = JSON.parse(msg.data);
|
|
101
75
|
if (data === "invalid") {
|
|
102
76
|
console.info("[HMR]", "webpack is working...");
|
|
@@ -111,3 +85,4 @@ if (import.meta.webpackHot) {
|
|
|
111
85
|
console.info("[HMR]", "closed");
|
|
112
86
|
});
|
|
113
87
|
}
|
|
88
|
+
//# sourceMappingURL=client-hmr.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["client-hmr.ts"],"sourcesContent":["/// <reference types=\"webpack/module\" />\n\nlet lastHash: string | undefined;\nfunction upToDate() {\n return lastHash!.indexOf(__webpack_hash__) >= 0;\n}\n\nfunction logUpdate(\n updatedModules: (string | number)[],\n renewedModules: (string | number)[] | null,\n) {\n const unacceptedModules = updatedModules.filter((moduleId) => {\n return renewedModules && renewedModules.indexOf(moduleId) < 0;\n });\n\n if (unacceptedModules.length > 0) {\n console.warn(\n \"[HMR]\",\n \"The following modules couldn't be hot updated: (They would need a full reload!)\",\n unacceptedModules,\n );\n }\n\n if (!renewedModules || renewedModules.length === 0) {\n console.info(\"[HMR]\", \"Nothing hot updated.\");\n } else {\n console.info(\"[HMR]\", \"Updated modules:\");\n renewedModules.forEach(function (moduleId) {\n if (typeof moduleId === \"string\" && moduleId.indexOf(\"!\") !== -1) {\n const parts = moduleId.split(\"!\");\n console.info(\"[HMR]\", \"-\", parts.pop());\n console.info(\"[HMR]\", \" \", \"-\", moduleId);\n } else {\n console.info(\"[HMR]\", \"-\", moduleId);\n }\n });\n const numberIds = renewedModules.every((moduleId) => {\n return typeof moduleId === \"number\";\n });\n if (numberIds) {\n console.info(\n \"[HMR]\",\n 'Consider using the optimization.moduleIds: \"named\" for module names.',\n );\n }\n }\n}\n\nasync function checkUpdates(fromUpdate = false) {\n try {\n const updatedModules = await import.meta.webpackHot.check();\n if (!updatedModules) {\n if (fromUpdate) console.info(\"[HMR]\", \"Update applied\");\n else console.warn(\"[HMR]\", \"Promised update was not found\");\n return;\n }\n const renewedModules = await import.meta.webpackHot.apply({\n ignoreUnaccepted: true,\n onUnaccepted(data) {\n console.warn(\n \"[HMR]\",\n \"Update was not accepted:\",\n data.chain.join(\" => \"),\n );\n },\n });\n\n logUpdate(updatedModules, renewedModules);\n\n if (!upToDate()) {\n await checkUpdates(true);\n }\n } catch (e) {\n const status = import.meta.webpackHot.status();\n if ([\"abort\", \"fail\"].indexOf(status) >= 0) {\n console.warn(\"[HMR]\", \"Can't apply update, restart required!\", e);\n } else {\n console.warn(\"[HMR]\", \"Update failed\", e);\n }\n }\n}\n\nasync function signalled() {\n if (import.meta.webpackHot.status() !== \"idle\") {\n console.warn(\n \"[HMR]\",\n `Bundle update, but state is not idle: ${import.meta.webpackHot.status()}`,\n );\n return;\n }\n await checkUpdates();\n}\n\nif (import.meta.webpackHot) {\n const ws = new WebSocket(\"/_freshpack_hmr\");\n ws.addEventListener(\"open\", () => {\n console.info(\"[HMR]\", \"opened\");\n });\n ws.addEventListener(\"message\", (msg) => {\n const data = JSON.parse(msg.data);\n if (data === \"invalid\") {\n console.info(\"[HMR]\", \"webpack is working...\");\n } else if (\"done\" in data) {\n const hash = data.done.hash;\n lastHash = hash;\n console.info(\"[HMR]\", \"webpack rebuilt\", hash);\n signalled();\n }\n });\n ws.addEventListener(\"close\", () => {\n console.info(\"[HMR]\", \"closed\");\n });\n}\n"],"mappings":"AAAA;;AAEA,IAAI,QAA4B;AAChC,SAAS,QAAQ,GAAG;EAClB,OAAO,QAAQ,CAAE,OAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC;AACjD;AAEA,SAAS,SAAS,CAChB,cAAmC,EACnC,cAA0C,EAC1C;EACA,MAAM,iBAAiB,GAAG,cAAc,CAAC,MAAM,CAAE,QAAQ,IAAK;IAC5D,OAAO,cAAc,I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MAAM,CAAC,IAAI,CAAC,UAAU,EAAE;EAC1B,MAAM,EAAE,GAAG,IAAI,SAAS,CAAC,iBAAiB,CAAC;EAC3C,EAAE,CAAC,gBAAgB,CAAC,MAAM,EAAE,MAAM;IAChC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC;EACjC,CAAC,CAAC;EACF,EAAE,CAAC,gBAAgB,CAAC,SAAS,EAAG,GAAG,IAAK;IACtC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC;IACjC,IAAI,IAAI,KAAK,SAAS,EAAE;MACtB,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,uBAAuB,CAAC;IAChD,CAAC,MAAM,IAAI,MAAM,IAAI,IAAI,EAAE;MACzB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI;MAC3B,QAAQ,GAAG,IAAI;MACf,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,iBAAiB,EAAE,IAAI,CAAC;MAC9C,SAAS,CAAC,CAAC;IACb;EACF,CAAC,CAAC;EACF,EAAE,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM;IACjC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC;EACjC,CAAC,CAAC;AACJ","ignoreList":[]}
|
package/internal.d.ts
ADDED
package/internal.js
ADDED
package/internal.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["internal.ts"],"sourcesContent":["export let unmapping: Record<string, URL | string> | undefined = undefined;\n\nexport function setUnmapping(newUnmapping: Record<string, URL | string>) {\n unmapping = newUnmapping;\n}\n"],"mappings":"AAAA,OAAO,IAAI,SAAmD,GAAG,SAAS;AAE1E,OAAO,SAAS,YAAY,CAAC,YAA0C,EAAE;EACvE,SAAS,GAAG,YAAY;AAC1B","ignoreList":[]}
|
package/mod.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function unmap(name: string, url: URL): string;
|
package/{mod.ts → mod.js}
RENAMED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { unmapping } from "./internal.
|
|
2
|
-
|
|
1
|
+
import { unmapping } from "./internal.js";
|
|
3
2
|
const IS_BROWSER = typeof document !== "undefined";
|
|
4
|
-
|
|
5
|
-
export function unmap(name: string, url: URL): string {
|
|
3
|
+
export function unmap(name, url) {
|
|
6
4
|
if (IS_BROWSER) {
|
|
7
5
|
console.error("browser unmapping should be done using webpack plugin");
|
|
8
6
|
return url.href;
|
|
@@ -18,3 +16,4 @@ export function unmap(name: string, url: URL): string {
|
|
|
18
16
|
}
|
|
19
17
|
return unmapped.toString();
|
|
20
18
|
}
|
|
19
|
+
//# sourceMappingURL=mod.js.map
|
package/mod.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["mod.ts"],"sourcesContent":["import { unmapping } from \"./internal.ts\";\n\nconst IS_BROWSER = typeof document !== \"undefined\";\n\nexport function unmap(name: string, url: URL): string {\n if (IS_BROWSER) {\n console.error(\"browser unmapping should be done using webpack plugin\");\n return url.href;\n }\n if (!unmapping) {\n console.error(\"missing unmapping registration\");\n return url.href;\n }\n const unmapped = unmapping[name];\n if (!unmapped) {\n console.error(\"missing unmapping registration for\", name);\n return url.href;\n }\n return unmapped.toString();\n}\n"],"mappings":"AAAA,SAAS,SAAS,QAAQ,eAAe;AAEzC,MAAM,UAAU,GAAG,OAAO,QAAQ,KAAK,WAAW;AAElD,OAAO,SAAS,KAAK,CAAC,IAAY,EAAE,GAAQ,EAAU;EACpD,IAAI,UAAU,EAAE;IACd,OAAO,CAAC,KAAK,CAAC,uDAAuD,CAAC;IACtE,OAAO,GAAG,CAAC,IAAI;EACjB;EACA,IAAI,CAAC,SAAS,EAAE;IACd,OAAO,CAAC,KAAK,CAAC,gCAAgC,CAAC;IAC/C,OAAO,GAAG,CAAC,IAAI;EACjB;EACA,MAAM,QAAQ,GAAG,SAAS,CAAC,IAAI,CAAC;EAChC,IAAI,CAAC,QAAQ,EAAE;IACb,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,IAAI,CAAC;IACzD,OAAO,GAAG,CAAC,IAAI;EACjB;EACA,OAAO,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAC5B","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,17 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@freshpack/runtime",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
|
-
".":
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./mod.d.ts",
|
|
8
|
+
"default": "./mod.js"
|
|
9
|
+
},
|
|
10
|
+
"./internal": {
|
|
11
|
+
"types": "./internal.d.ts",
|
|
12
|
+
"default": "./internal.js"
|
|
13
|
+
},
|
|
14
|
+
"./client-hmr": {
|
|
15
|
+
"types": "./client-hmr.d.ts",
|
|
16
|
+
"default": "./client-hmr.js"
|
|
17
|
+
},
|
|
18
|
+
"./server-middleware": {
|
|
19
|
+
"types": "./server-middleware.d.ts",
|
|
20
|
+
"default": "./server-middleware.js"
|
|
21
|
+
}
|
|
10
22
|
},
|
|
11
23
|
"dependencies": {
|
|
12
|
-
"@freshpack/core": "3.0.
|
|
13
|
-
"@freshpack/webpack": "1.0.
|
|
24
|
+
"@freshpack/core": "3.0.2",
|
|
25
|
+
"@freshpack/webpack": "1.0.2",
|
|
14
26
|
"memfs": "^4.80.0",
|
|
15
|
-
"webpack": "^5.
|
|
16
|
-
}
|
|
27
|
+
"webpack": "^5.112.0"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"client-hmr.d.ts",
|
|
31
|
+
"client-hmr.js",
|
|
32
|
+
"client-hmr.js.map",
|
|
33
|
+
"internal.d.ts",
|
|
34
|
+
"internal.js",
|
|
35
|
+
"internal.js.map",
|
|
36
|
+
"mod.d.ts",
|
|
37
|
+
"mod.js",
|
|
38
|
+
"mod.js.map",
|
|
39
|
+
"server-middleware.d.ts",
|
|
40
|
+
"server-middleware.js",
|
|
41
|
+
"server-middleware.js.map"
|
|
42
|
+
]
|
|
17
43
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { App, Context, Middleware } from "@freshpack/core";
|
|
2
|
+
import type Webpack from "webpack";
|
|
3
|
+
export declare function webpackHandler<State>(app: App<State>, compiler: Webpack.Compiler): (ctx: Context<State>) => Promise<Response | Middleware<State>>;
|
|
4
|
+
export declare function mkCompilingWaiter(compiler: Webpack.Compiler): () => Promise<void>;
|
|
@@ -1,28 +1,18 @@
|
|
|
1
|
-
import type { App, Context, Middleware } from "@freshpack/core";
|
|
2
1
|
import { setBuildCache } from "@freshpack/core/internal";
|
|
3
|
-
import type Webpack from "webpack";
|
|
4
2
|
import { assertFreshCompilation } from "@freshpack/webpack/fresh";
|
|
5
3
|
import { assertUnmapCompilation } from "@freshpack/webpack/unmap";
|
|
6
|
-
import { setUnmapping } from "./internal.
|
|
4
|
+
import { setUnmapping } from "./internal.js";
|
|
7
5
|
import * as memfs from "memfs";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
): (ctx: Context<State>) => Promise<Response | Middleware<State>> {
|
|
13
|
-
compiler.outputFileSystem = memfs.createFsFromVolume(
|
|
14
|
-
new memfs.Volume(),
|
|
15
|
-
) as any;
|
|
16
|
-
|
|
17
|
-
const hmrWatchers = new Set<WebSocket>();
|
|
18
|
-
const broadcast = (v: unknown) => {
|
|
6
|
+
export function webpackHandler(app, compiler) {
|
|
7
|
+
compiler.outputFileSystem = memfs.createFsFromVolume(new memfs.Volume());
|
|
8
|
+
const hmrWatchers = new Set();
|
|
9
|
+
const broadcast = v => {
|
|
19
10
|
const json = JSON.stringify(v);
|
|
20
11
|
for (const watcher of hmrWatchers) {
|
|
21
12
|
watcher.send(json);
|
|
22
13
|
}
|
|
23
14
|
};
|
|
24
|
-
|
|
25
|
-
compiler.hooks.failed.tap("FreshpackHMR", (e) => {
|
|
15
|
+
compiler.hooks.failed.tap("FreshpackHMR", e => {
|
|
26
16
|
console.error("webpack failed", e);
|
|
27
17
|
});
|
|
28
18
|
compiler.hooks.invalid.tap("FreshpackHMR", () => {
|
|
@@ -32,40 +22,37 @@ export function webpackHandler<State>(
|
|
|
32
22
|
// deno-ignore: require-await
|
|
33
23
|
compiler.hooks.done.tapPromise({
|
|
34
24
|
name: "FreshpackHMR",
|
|
35
|
-
before: "FreshpackCompilingWait"
|
|
36
|
-
}, async
|
|
25
|
+
before: "FreshpackCompilingWait"
|
|
26
|
+
}, async stats => {
|
|
37
27
|
console.info(stats.toString(compiler.options.stats));
|
|
38
|
-
|
|
39
28
|
assertFreshCompilation(stats.compilation);
|
|
40
29
|
assertUnmapCompilation(stats.compilation);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
stats.compilation.prodBuildCache,
|
|
45
|
-
// development cache works not the way we want to
|
|
46
|
-
"production",
|
|
47
|
-
);
|
|
30
|
+
setBuildCache(app, stats.compilation.prodBuildCache,
|
|
31
|
+
// development cache works not the way we want to
|
|
32
|
+
"production");
|
|
48
33
|
setUnmapping(stats.compilation.unmapping);
|
|
49
|
-
broadcast({
|
|
34
|
+
broadcast({
|
|
35
|
+
done: {
|
|
36
|
+
hash: stats.hash
|
|
37
|
+
}
|
|
38
|
+
});
|
|
50
39
|
});
|
|
51
|
-
|
|
52
40
|
if (compiler.options.watch) {
|
|
53
41
|
compiler.watch(compiler.options.watchOptions, () => {
|
|
54
42
|
// Failure/success is handled by hooks
|
|
55
43
|
});
|
|
56
44
|
} else {
|
|
57
|
-
console.warn(
|
|
58
|
-
"watching is disabled, server won't be reloaded automatically!",
|
|
59
|
-
);
|
|
45
|
+
console.warn("watching is disabled, server won't be reloaded automatically!");
|
|
60
46
|
compiler.compile(() => {
|
|
61
47
|
// Failure/success is handled by hooks
|
|
62
48
|
});
|
|
63
49
|
}
|
|
64
|
-
|
|
65
|
-
return (ctx) => {
|
|
50
|
+
return ctx => {
|
|
66
51
|
if (ctx.url.pathname.endsWith("/_freshpack_hmr")) {
|
|
67
|
-
const {
|
|
68
|
-
|
|
52
|
+
const {
|
|
53
|
+
response,
|
|
54
|
+
socket
|
|
55
|
+
} = Deno.upgradeWebSocket(ctx.req);
|
|
69
56
|
socket.addEventListener("open", () => {
|
|
70
57
|
hmrWatchers.add(socket);
|
|
71
58
|
});
|
|
@@ -80,12 +67,8 @@ export function webpackHandler<State>(
|
|
|
80
67
|
return ctx.next();
|
|
81
68
|
};
|
|
82
69
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
compiler: Webpack.Compiler,
|
|
86
|
-
): () => Promise<void> {
|
|
87
|
-
let waiter = Promise.withResolvers<void>();
|
|
88
|
-
|
|
70
|
+
export function mkCompilingWaiter(compiler) {
|
|
71
|
+
let waiter = Promise.withResolvers();
|
|
89
72
|
compiler.hooks.failed.tap("FreshpackCompilingWait", () => {
|
|
90
73
|
waiter.resolve();
|
|
91
74
|
});
|
|
@@ -95,6 +78,6 @@ export function mkCompilingWaiter(
|
|
|
95
78
|
compiler.hooks.done.tap("FreshpackCompilingWait", () => {
|
|
96
79
|
waiter.resolve();
|
|
97
80
|
});
|
|
98
|
-
|
|
99
81
|
return () => waiter.promise;
|
|
100
82
|
}
|
|
83
|
+
//# sourceMappingURL=server-middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["server-middleware.ts"],"sourcesContent":["import type { App, Context, Middleware } from \"@freshpack/core\";\nimport { setBuildCache } from \"@freshpack/core/internal\";\nimport type Webpack from \"webpack\";\nimport { assertFreshCompilation } from \"@freshpack/webpack/fresh\";\nimport { assertUnmapCompilation } from \"@freshpack/webpack/unmap\";\nimport { setUnmapping } from \"./internal.ts\";\nimport * as memfs from \"memfs\";\n\nexport function webpackHandler<State>(\n app: App<State>,\n compiler: Webpack.Compiler,\n): (ctx: Context<State>) => Promise<Response | Middleware<State>> {\n compiler.outputFileSystem = memfs.createFsFromVolume(\n new memfs.Volume(),\n ) as any;\n\n const hmrWatchers = new Set<WebSocket>();\n const broadcast = (v: unknown) => {\n const json = JSON.stringify(v);\n for (const watcher of hmrWatchers) {\n watcher.send(json);\n }\n };\n\n compiler.hooks.failed.tap(\"FreshpackHMR\", (e) => {\n console.error(\"webpack failed\", e);\n });\n compiler.hooks.invalid.tap(\"FreshpackHMR\", () => {\n console.error(\"webpack invalid\");\n broadcast(\"invalid\");\n });\n // deno-ignore: require-await\n compiler.hooks.done.tapPromise({\n name: \"FreshpackHMR\",\n before: \"FreshpackCompilingWait\",\n }, async (stats) => {\n console.info(stats.toString(compiler.options.stats));\n\n assertFreshCompilation(stats.compilation);\n assertUnmapCompilation(stats.compilation);\n\n setBuildCache(\n app as App<unknown>,\n stats.compilation.prodBuildCache,\n // development cache works not the way we want to\n \"production\",\n );\n setUnmapping(stats.compilation.unmapping);\n broadcast({ done: { hash: stats.hash } });\n });\n\n if (compiler.options.watch) {\n compiler.watch(compiler.options.watchOptions, () => {\n // Failure/success is handled by hooks\n });\n } else {\n console.warn(\n \"watching is disabled, server won't be reloaded automatically!\",\n );\n compiler.compile(() => {\n // Failure/success is handled by hooks\n });\n }\n\n return (ctx) => {\n if (ctx.url.pathname.endsWith(\"/_freshpack_hmr\")) {\n const { response, socket } = Deno.upgradeWebSocket(ctx.req);\n\n socket.addEventListener(\"open\", () => {\n hmrWatchers.add(socket);\n });\n socket.addEventListener(\"close\", () => {\n hmrWatchers.delete(socket);\n });\n return Promise.resolve(response);\n }\n if (ctx.req.method !== \"GET\" && ctx.req.method !== \"HEAD\") {\n return ctx.next();\n }\n return ctx.next();\n };\n}\n\nexport function mkCompilingWaiter(\n compiler: Webpack.Compiler,\n): () => Promise<void> {\n let waiter = Promise.withResolvers<void>();\n\n compiler.hooks.failed.tap(\"FreshpackCompilingWait\", () => {\n waiter.resolve();\n });\n compiler.hooks.invalid.tap(\"FreshpackCompilingWait\", () => {\n waiter = Promise.withResolvers();\n });\n compiler.hooks.done.tap(\"FreshpackCompilingWait\", () => {\n waiter.resolve();\n });\n\n return () => waiter.promise;\n}\n"],"mappings":"AACA,SAAS,aAAa,QAAQ,0BAA0B;AAExD,SAAS,sBAAsB,QAAQ,0BAA0B;AACjE,SAAS,sBAAsB,QAAQ,0BAA0B;AACjE,SAAS,YAAY,QAAQ,eAAe;AAC5C,OAAO,KAAK,KAAK,MAAM,OAAO;AAE9B,OAAO,SAAS,cAAc,CAC5B,GAAe,EACf,QAA0B,EACsC;EAChE,QAAQ,CAAC,gBAAgB,GAAG,KAAK,CAAC,kBAAkB,CAClD,IAAI,KAAK,CAAC,MAAM,CAAC,CACnB,CAAQ;EAER,MAAM,WAAW,GAAG,IAAI,GAAG,CAAY,CAAC;EACxC,MAAM,SAAS,GAAI,CAAU,IAAK;IAChC,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IAC9B,KAAK,MAAM,OAAO,IAAI,WAAW,EAAE;MACjC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;IACpB;EACF,CAAC;EAED,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,cAAc,EAAG,CAAC,IAAK;IAC/C,OAAO,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAC,CAAC;EACpC,CAAC,CAAC;EACF,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,MAAM;IAC/C,OAAO,CAAC,KAAK,CAAC,iBAAiB,CAAC;IAChC,SAAS,CAAC,SAAS,CAAC;EACtB,CAAC,CAAC;EACF;EACA,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC;IAC7B,IAAI,EAAE,cAAc;IACpB,MAAM,EAAE;EACV,CAAC,EAAE,MAAO,KAAK,IAAK;IAClB,OAAO,CAAC,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