@hybridly/vite 0.0.1-alpha.2 → 0.0.1-alpha.21
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.cjs +86 -54
- package/dist/index.d.ts +5 -1
- package/dist/index.mjs +86 -54
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -16,40 +16,62 @@ const path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
|
16
16
|
const makeDebugger__default = /*#__PURE__*/_interopDefaultLegacy(makeDebugger);
|
|
17
17
|
const fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
18
18
|
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
19
|
+
const ROUTING_PLUGIN_NAME = "vite:hybridly:routing";
|
|
20
|
+
const ROUTING_HMR_UPDATE_ROUTING = "hybridly:routing:update";
|
|
21
|
+
const ROUTING_HMR_QUERY_UPDATE_ROUTING = "hybridly:routing:pls-update";
|
|
22
|
+
const ROUTING_VIRTUAL_MODULE_ID = "virtual:hybridly/router";
|
|
23
|
+
const RESOLVED_ROUTING_VIRTUAL_MODULE_ID = `\0${ROUTING_VIRTUAL_MODULE_ID}`;
|
|
23
24
|
const LAYOUT_PLUGIN_NAME = "vite:hybridly:layout";
|
|
24
25
|
|
|
25
26
|
const debug = {
|
|
26
|
-
router: makeDebugger__default(
|
|
27
|
+
router: makeDebugger__default(ROUTING_PLUGIN_NAME),
|
|
27
28
|
layout: makeDebugger__default(LAYOUT_PLUGIN_NAME)
|
|
28
29
|
};
|
|
29
30
|
|
|
30
|
-
const TEMPLATE_LAYOUT_REGEX = /<template +layout(?: *= *['"](
|
|
31
|
+
const TEMPLATE_LAYOUT_REGEX = /<template +layout(?: *= *['"]((?:[\w\/\-_,:](?:,\ )?)+)['"] *)?>/;
|
|
31
32
|
const TYPESCRIPT_REGEX = /lang=['"]ts['"]/;
|
|
32
33
|
const layout = (options = {}) => {
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
|
|
34
|
+
const defaultLayoutName = options?.defaultLayoutName?.replace(".vue", "") ?? "default";
|
|
35
|
+
const layoutsDirectory = options?.directory ?? path__default.resolve(process.cwd(), "resources", "views", "layouts");
|
|
36
|
+
const templateRegExp = options?.templateRegExp ?? TEMPLATE_LAYOUT_REGEX;
|
|
37
|
+
const resolveLayoutPath = (layoutName) => {
|
|
38
|
+
const [domain, layout] = layoutName.includes(":") ? layoutName.split(":") : [void 0, layoutName];
|
|
39
|
+
const resolve = options?.resolve ?? ((layout2, domain2) => {
|
|
40
|
+
if (!domain2) {
|
|
41
|
+
return path__default.resolve(layoutsDirectory, `${layout2}.vue`);
|
|
42
|
+
}
|
|
43
|
+
return path__default.resolve(process.cwd(), "resources", "domains", domain2, "layouts", `${layout2}.vue`);
|
|
44
|
+
});
|
|
45
|
+
return vite.normalizePath(resolve(layout, domain)).replaceAll("\\", "/");
|
|
46
|
+
};
|
|
47
|
+
debug.layout("Resolved options:", {
|
|
48
|
+
defaultLayoutName,
|
|
49
|
+
layoutsDirectory
|
|
50
|
+
});
|
|
36
51
|
return {
|
|
37
52
|
name: LAYOUT_PLUGIN_NAME,
|
|
38
53
|
transform: (code, id) => {
|
|
39
|
-
if (!
|
|
54
|
+
if (!templateRegExp.test(code)) {
|
|
40
55
|
return;
|
|
41
56
|
}
|
|
42
|
-
return code.replace(
|
|
57
|
+
return code.replace(templateRegExp, (_, layoutName) => {
|
|
43
58
|
const isTypeScript = TYPESCRIPT_REGEX.test(code);
|
|
44
|
-
const
|
|
45
|
-
|
|
59
|
+
const layouts = layoutName?.toString()?.replaceAll(" ", "").split(",") ?? [defaultLayoutName];
|
|
60
|
+
const importName = (i) => `__hybridly_layout_${i}`;
|
|
61
|
+
const exports = layouts.map((_2, i) => importName(i));
|
|
62
|
+
const imports = layouts.reduce((imports2, layoutName2, i) => `
|
|
63
|
+
${imports2}
|
|
64
|
+
import ${importName(i)} from '${resolveLayoutPath(layoutName2)}';
|
|
65
|
+
`, "").trim();
|
|
66
|
+
debug.layout(`Resolved layouts "${layouts.join(", ")}":`, {
|
|
46
67
|
sourceFile: id,
|
|
47
|
-
|
|
68
|
+
layouts,
|
|
69
|
+
imports
|
|
48
70
|
});
|
|
49
71
|
return `
|
|
50
72
|
<script${isTypeScript ? ' lang="ts"' : ""}>
|
|
51
|
-
|
|
52
|
-
export default { layout }
|
|
73
|
+
${imports}
|
|
74
|
+
export default { layout: [${exports.join(", ")}] }
|
|
53
75
|
<\/script>
|
|
54
76
|
<template>
|
|
55
77
|
`;
|
|
@@ -58,42 +80,45 @@ const layout = (options = {}) => {
|
|
|
58
80
|
};
|
|
59
81
|
};
|
|
60
82
|
|
|
61
|
-
function getClientCode(
|
|
83
|
+
function getClientCode(routing) {
|
|
62
84
|
return `
|
|
63
85
|
if (typeof window !== 'undefined') {
|
|
64
86
|
window.hybridly = {
|
|
65
|
-
|
|
87
|
+
routing: ${JSON.stringify(routing)}
|
|
66
88
|
}
|
|
67
|
-
|
|
89
|
+
|
|
68
90
|
if (import.meta.hot) {
|
|
69
|
-
import.meta.hot.on('${
|
|
70
|
-
window.dispatchEvent(
|
|
71
|
-
new CustomEvent('hybridly:routes', { detail: routes })
|
|
72
|
-
)
|
|
91
|
+
import.meta.hot.on('${ROUTING_HMR_UPDATE_ROUTING}', (routing) => {
|
|
92
|
+
window.dispatchEvent(new CustomEvent('hybridly:routing', { detail: routing }))
|
|
73
93
|
})
|
|
94
|
+
|
|
95
|
+
import.meta.hot.send('${ROUTING_HMR_QUERY_UPDATE_ROUTING}')
|
|
74
96
|
}
|
|
75
97
|
}
|
|
76
98
|
`;
|
|
77
99
|
}
|
|
78
100
|
|
|
79
101
|
const shell = node_util.promisify(node_child_process.exec);
|
|
80
|
-
async function
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
102
|
+
async function fetchRoutingFromArtisan(options) {
|
|
103
|
+
try {
|
|
104
|
+
const php = options.php ?? "php";
|
|
105
|
+
const result = await shell(`${php} artisan hybridly:routes`);
|
|
106
|
+
const routing = JSON.parse(result.stdout);
|
|
107
|
+
write(options, routing);
|
|
108
|
+
return routing;
|
|
109
|
+
} catch {
|
|
110
|
+
}
|
|
86
111
|
}
|
|
87
112
|
|
|
88
113
|
const write = throttleDebounce.debounce(1e3, writeDefinitions, { atBegin: true });
|
|
89
|
-
async function writeDefinitions(options,
|
|
90
|
-
|
|
91
|
-
if (options.dts === false) {
|
|
114
|
+
async function writeDefinitions(options, routing) {
|
|
115
|
+
routing ?? (routing = await fetchRoutingFromArtisan(options));
|
|
116
|
+
if (options.dts === false || !routing) {
|
|
92
117
|
return;
|
|
93
118
|
}
|
|
94
|
-
debug.router("Writing types for
|
|
119
|
+
debug.router("Writing types for routing:", routing);
|
|
95
120
|
const target = path__default.resolve(options.dts ?? "resources/types/routes.d.ts");
|
|
96
|
-
const routes = Object.fromEntries(Object.entries(
|
|
121
|
+
const routes = Object.fromEntries(Object.entries(routing.routes).map(([key, route]) => {
|
|
97
122
|
const bindings = route.bindings ? Object.fromEntries(Object.entries(route.bindings).map(([key2]) => [key2, "__key_placeholder__"])) : void 0;
|
|
98
123
|
return [key, {
|
|
99
124
|
...route.uri ? { uri: route.uri } : {},
|
|
@@ -102,7 +127,8 @@ async function writeDefinitions(options, collection) {
|
|
|
102
127
|
...route.bindings ? { bindings } : {}
|
|
103
128
|
}];
|
|
104
129
|
}));
|
|
105
|
-
const definitions = generateDefinitions().replace("__URL__",
|
|
130
|
+
const definitions = generateDefinitions().replace("__URL__", routing?.url ?? "").replace("__ROUTES__", JSON.stringify(routes).replaceAll('"__key_placeholder__"', "any"));
|
|
131
|
+
fs__default.mkdirSync(path__default.dirname(target), { recursive: true });
|
|
106
132
|
fs__default.writeFileSync(target, definitions, { encoding: "utf-8" });
|
|
107
133
|
}
|
|
108
134
|
function generateDefinitions() {
|
|
@@ -111,7 +137,7 @@ function generateDefinitions() {
|
|
|
111
137
|
// Modifications will be discarded
|
|
112
138
|
// It is recommended to add it in your .gitignore
|
|
113
139
|
|
|
114
|
-
declare module 'hybridly
|
|
140
|
+
declare module 'hybridly' {
|
|
115
141
|
export interface GlobalRouteCollection {
|
|
116
142
|
url: '__URL__'
|
|
117
143
|
routes: __ROUTES__
|
|
@@ -130,37 +156,43 @@ const router = (options = {}) => {
|
|
|
130
156
|
],
|
|
131
157
|
...options
|
|
132
158
|
};
|
|
133
|
-
let
|
|
159
|
+
let routingBeforeUpdate;
|
|
160
|
+
async function sendRoutingUpdate(server, force = false) {
|
|
161
|
+
const routing = await fetchRoutingFromArtisan(resolved) ?? routingBeforeUpdate;
|
|
162
|
+
if (force || JSON.stringify(routing) !== JSON.stringify(routingBeforeUpdate)) {
|
|
163
|
+
debug.router("Updating routes via HMR:", routing);
|
|
164
|
+
server.ws.send({
|
|
165
|
+
type: "custom",
|
|
166
|
+
event: ROUTING_HMR_UPDATE_ROUTING,
|
|
167
|
+
data: routing
|
|
168
|
+
});
|
|
169
|
+
write(resolved);
|
|
170
|
+
routingBeforeUpdate = routing;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
134
173
|
return {
|
|
135
|
-
name:
|
|
174
|
+
name: ROUTING_PLUGIN_NAME,
|
|
136
175
|
configureServer(server) {
|
|
137
176
|
write(resolved);
|
|
177
|
+
server.ws.on(ROUTING_HMR_QUERY_UPDATE_ROUTING, () => {
|
|
178
|
+
sendRoutingUpdate(server, true);
|
|
179
|
+
});
|
|
138
180
|
server.watcher.on("change", async (path) => {
|
|
139
181
|
if (!resolved.watch.some((regex) => regex.test(path))) {
|
|
140
182
|
return;
|
|
141
183
|
}
|
|
142
|
-
|
|
143
|
-
if (JSON.stringify(routes) !== JSON.stringify(previousRoutes)) {
|
|
144
|
-
debug.router("Updating routes via HMR:", routes);
|
|
145
|
-
server.ws.send({
|
|
146
|
-
type: "custom",
|
|
147
|
-
event: ROUTER_HMR_UPDATE_ROUTE,
|
|
148
|
-
data: routes
|
|
149
|
-
});
|
|
150
|
-
write(resolved);
|
|
151
|
-
previousRoutes = routes;
|
|
152
|
-
}
|
|
184
|
+
sendRoutingUpdate(server);
|
|
153
185
|
});
|
|
154
186
|
},
|
|
155
187
|
resolveId(id) {
|
|
156
|
-
if (id ===
|
|
157
|
-
return
|
|
188
|
+
if (id === ROUTING_VIRTUAL_MODULE_ID) {
|
|
189
|
+
return RESOLVED_ROUTING_VIRTUAL_MODULE_ID;
|
|
158
190
|
}
|
|
159
191
|
},
|
|
160
192
|
async load(id) {
|
|
161
|
-
if (id ===
|
|
162
|
-
const
|
|
163
|
-
return getClientCode(
|
|
193
|
+
if (id === RESOLVED_ROUTING_VIRTUAL_MODULE_ID) {
|
|
194
|
+
const routing = await fetchRoutingFromArtisan(resolved);
|
|
195
|
+
return getClientCode(routing);
|
|
164
196
|
}
|
|
165
197
|
},
|
|
166
198
|
async handleHotUpdate(ctx) {
|
package/dist/index.d.ts
CHANGED
|
@@ -7,10 +7,14 @@ interface Options {
|
|
|
7
7
|
router?: false | RouterOptions;
|
|
8
8
|
}
|
|
9
9
|
interface LayoutOptions {
|
|
10
|
+
/** Name of the layout used when no argument is provided to `layout`. */
|
|
11
|
+
defaultLayoutName?: string;
|
|
12
|
+
/** Custom RegExp for parsing the template string. */
|
|
13
|
+
templateRegExp?: RegExp;
|
|
10
14
|
/** The directory in which layouts are stored. */
|
|
11
15
|
directory?: string;
|
|
12
16
|
/** Function that resolves the layout path given its name. */
|
|
13
|
-
resolve?: (layout: string) => string;
|
|
17
|
+
resolve?: (layout: string, domain?: string) => string;
|
|
14
18
|
}
|
|
15
19
|
interface RouterOptions {
|
|
16
20
|
/** Path to the PHP executable. */
|
package/dist/index.mjs
CHANGED
|
@@ -6,40 +6,62 @@ import { debounce } from 'throttle-debounce';
|
|
|
6
6
|
import { exec } from 'node:child_process';
|
|
7
7
|
import { promisify } from 'node:util';
|
|
8
8
|
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
9
|
+
const ROUTING_PLUGIN_NAME = "vite:hybridly:routing";
|
|
10
|
+
const ROUTING_HMR_UPDATE_ROUTING = "hybridly:routing:update";
|
|
11
|
+
const ROUTING_HMR_QUERY_UPDATE_ROUTING = "hybridly:routing:pls-update";
|
|
12
|
+
const ROUTING_VIRTUAL_MODULE_ID = "virtual:hybridly/router";
|
|
13
|
+
const RESOLVED_ROUTING_VIRTUAL_MODULE_ID = `\0${ROUTING_VIRTUAL_MODULE_ID}`;
|
|
13
14
|
const LAYOUT_PLUGIN_NAME = "vite:hybridly:layout";
|
|
14
15
|
|
|
15
16
|
const debug = {
|
|
16
|
-
router: makeDebugger(
|
|
17
|
+
router: makeDebugger(ROUTING_PLUGIN_NAME),
|
|
17
18
|
layout: makeDebugger(LAYOUT_PLUGIN_NAME)
|
|
18
19
|
};
|
|
19
20
|
|
|
20
|
-
const TEMPLATE_LAYOUT_REGEX = /<template +layout(?: *= *['"](
|
|
21
|
+
const TEMPLATE_LAYOUT_REGEX = /<template +layout(?: *= *['"]((?:[\w\/\-_,:](?:,\ )?)+)['"] *)?>/;
|
|
21
22
|
const TYPESCRIPT_REGEX = /lang=['"]ts['"]/;
|
|
22
23
|
const layout = (options = {}) => {
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
|
|
24
|
+
const defaultLayoutName = options?.defaultLayoutName?.replace(".vue", "") ?? "default";
|
|
25
|
+
const layoutsDirectory = options?.directory ?? path.resolve(process.cwd(), "resources", "views", "layouts");
|
|
26
|
+
const templateRegExp = options?.templateRegExp ?? TEMPLATE_LAYOUT_REGEX;
|
|
27
|
+
const resolveLayoutPath = (layoutName) => {
|
|
28
|
+
const [domain, layout] = layoutName.includes(":") ? layoutName.split(":") : [void 0, layoutName];
|
|
29
|
+
const resolve = options?.resolve ?? ((layout2, domain2) => {
|
|
30
|
+
if (!domain2) {
|
|
31
|
+
return path.resolve(layoutsDirectory, `${layout2}.vue`);
|
|
32
|
+
}
|
|
33
|
+
return path.resolve(process.cwd(), "resources", "domains", domain2, "layouts", `${layout2}.vue`);
|
|
34
|
+
});
|
|
35
|
+
return normalizePath(resolve(layout, domain)).replaceAll("\\", "/");
|
|
36
|
+
};
|
|
37
|
+
debug.layout("Resolved options:", {
|
|
38
|
+
defaultLayoutName,
|
|
39
|
+
layoutsDirectory
|
|
40
|
+
});
|
|
26
41
|
return {
|
|
27
42
|
name: LAYOUT_PLUGIN_NAME,
|
|
28
43
|
transform: (code, id) => {
|
|
29
|
-
if (!
|
|
44
|
+
if (!templateRegExp.test(code)) {
|
|
30
45
|
return;
|
|
31
46
|
}
|
|
32
|
-
return code.replace(
|
|
47
|
+
return code.replace(templateRegExp, (_, layoutName) => {
|
|
33
48
|
const isTypeScript = TYPESCRIPT_REGEX.test(code);
|
|
34
|
-
const
|
|
35
|
-
|
|
49
|
+
const layouts = layoutName?.toString()?.replaceAll(" ", "").split(",") ?? [defaultLayoutName];
|
|
50
|
+
const importName = (i) => `__hybridly_layout_${i}`;
|
|
51
|
+
const exports = layouts.map((_2, i) => importName(i));
|
|
52
|
+
const imports = layouts.reduce((imports2, layoutName2, i) => `
|
|
53
|
+
${imports2}
|
|
54
|
+
import ${importName(i)} from '${resolveLayoutPath(layoutName2)}';
|
|
55
|
+
`, "").trim();
|
|
56
|
+
debug.layout(`Resolved layouts "${layouts.join(", ")}":`, {
|
|
36
57
|
sourceFile: id,
|
|
37
|
-
|
|
58
|
+
layouts,
|
|
59
|
+
imports
|
|
38
60
|
});
|
|
39
61
|
return `
|
|
40
62
|
<script${isTypeScript ? ' lang="ts"' : ""}>
|
|
41
|
-
|
|
42
|
-
export default { layout }
|
|
63
|
+
${imports}
|
|
64
|
+
export default { layout: [${exports.join(", ")}] }
|
|
43
65
|
<\/script>
|
|
44
66
|
<template>
|
|
45
67
|
`;
|
|
@@ -48,42 +70,45 @@ const layout = (options = {}) => {
|
|
|
48
70
|
};
|
|
49
71
|
};
|
|
50
72
|
|
|
51
|
-
function getClientCode(
|
|
73
|
+
function getClientCode(routing) {
|
|
52
74
|
return `
|
|
53
75
|
if (typeof window !== 'undefined') {
|
|
54
76
|
window.hybridly = {
|
|
55
|
-
|
|
77
|
+
routing: ${JSON.stringify(routing)}
|
|
56
78
|
}
|
|
57
|
-
|
|
79
|
+
|
|
58
80
|
if (import.meta.hot) {
|
|
59
|
-
import.meta.hot.on('${
|
|
60
|
-
window.dispatchEvent(
|
|
61
|
-
new CustomEvent('hybridly:routes', { detail: routes })
|
|
62
|
-
)
|
|
81
|
+
import.meta.hot.on('${ROUTING_HMR_UPDATE_ROUTING}', (routing) => {
|
|
82
|
+
window.dispatchEvent(new CustomEvent('hybridly:routing', { detail: routing }))
|
|
63
83
|
})
|
|
84
|
+
|
|
85
|
+
import.meta.hot.send('${ROUTING_HMR_QUERY_UPDATE_ROUTING}')
|
|
64
86
|
}
|
|
65
87
|
}
|
|
66
88
|
`;
|
|
67
89
|
}
|
|
68
90
|
|
|
69
91
|
const shell = promisify(exec);
|
|
70
|
-
async function
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
92
|
+
async function fetchRoutingFromArtisan(options) {
|
|
93
|
+
try {
|
|
94
|
+
const php = options.php ?? "php";
|
|
95
|
+
const result = await shell(`${php} artisan hybridly:routes`);
|
|
96
|
+
const routing = JSON.parse(result.stdout);
|
|
97
|
+
write(options, routing);
|
|
98
|
+
return routing;
|
|
99
|
+
} catch {
|
|
100
|
+
}
|
|
76
101
|
}
|
|
77
102
|
|
|
78
103
|
const write = debounce(1e3, writeDefinitions, { atBegin: true });
|
|
79
|
-
async function writeDefinitions(options,
|
|
80
|
-
|
|
81
|
-
if (options.dts === false) {
|
|
104
|
+
async function writeDefinitions(options, routing) {
|
|
105
|
+
routing ?? (routing = await fetchRoutingFromArtisan(options));
|
|
106
|
+
if (options.dts === false || !routing) {
|
|
82
107
|
return;
|
|
83
108
|
}
|
|
84
|
-
debug.router("Writing types for
|
|
109
|
+
debug.router("Writing types for routing:", routing);
|
|
85
110
|
const target = path.resolve(options.dts ?? "resources/types/routes.d.ts");
|
|
86
|
-
const routes = Object.fromEntries(Object.entries(
|
|
111
|
+
const routes = Object.fromEntries(Object.entries(routing.routes).map(([key, route]) => {
|
|
87
112
|
const bindings = route.bindings ? Object.fromEntries(Object.entries(route.bindings).map(([key2]) => [key2, "__key_placeholder__"])) : void 0;
|
|
88
113
|
return [key, {
|
|
89
114
|
...route.uri ? { uri: route.uri } : {},
|
|
@@ -92,7 +117,8 @@ async function writeDefinitions(options, collection) {
|
|
|
92
117
|
...route.bindings ? { bindings } : {}
|
|
93
118
|
}];
|
|
94
119
|
}));
|
|
95
|
-
const definitions = generateDefinitions().replace("__URL__",
|
|
120
|
+
const definitions = generateDefinitions().replace("__URL__", routing?.url ?? "").replace("__ROUTES__", JSON.stringify(routes).replaceAll('"__key_placeholder__"', "any"));
|
|
121
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
96
122
|
fs.writeFileSync(target, definitions, { encoding: "utf-8" });
|
|
97
123
|
}
|
|
98
124
|
function generateDefinitions() {
|
|
@@ -101,7 +127,7 @@ function generateDefinitions() {
|
|
|
101
127
|
// Modifications will be discarded
|
|
102
128
|
// It is recommended to add it in your .gitignore
|
|
103
129
|
|
|
104
|
-
declare module 'hybridly
|
|
130
|
+
declare module 'hybridly' {
|
|
105
131
|
export interface GlobalRouteCollection {
|
|
106
132
|
url: '__URL__'
|
|
107
133
|
routes: __ROUTES__
|
|
@@ -120,37 +146,43 @@ const router = (options = {}) => {
|
|
|
120
146
|
],
|
|
121
147
|
...options
|
|
122
148
|
};
|
|
123
|
-
let
|
|
149
|
+
let routingBeforeUpdate;
|
|
150
|
+
async function sendRoutingUpdate(server, force = false) {
|
|
151
|
+
const routing = await fetchRoutingFromArtisan(resolved) ?? routingBeforeUpdate;
|
|
152
|
+
if (force || JSON.stringify(routing) !== JSON.stringify(routingBeforeUpdate)) {
|
|
153
|
+
debug.router("Updating routes via HMR:", routing);
|
|
154
|
+
server.ws.send({
|
|
155
|
+
type: "custom",
|
|
156
|
+
event: ROUTING_HMR_UPDATE_ROUTING,
|
|
157
|
+
data: routing
|
|
158
|
+
});
|
|
159
|
+
write(resolved);
|
|
160
|
+
routingBeforeUpdate = routing;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
124
163
|
return {
|
|
125
|
-
name:
|
|
164
|
+
name: ROUTING_PLUGIN_NAME,
|
|
126
165
|
configureServer(server) {
|
|
127
166
|
write(resolved);
|
|
167
|
+
server.ws.on(ROUTING_HMR_QUERY_UPDATE_ROUTING, () => {
|
|
168
|
+
sendRoutingUpdate(server, true);
|
|
169
|
+
});
|
|
128
170
|
server.watcher.on("change", async (path) => {
|
|
129
171
|
if (!resolved.watch.some((regex) => regex.test(path))) {
|
|
130
172
|
return;
|
|
131
173
|
}
|
|
132
|
-
|
|
133
|
-
if (JSON.stringify(routes) !== JSON.stringify(previousRoutes)) {
|
|
134
|
-
debug.router("Updating routes via HMR:", routes);
|
|
135
|
-
server.ws.send({
|
|
136
|
-
type: "custom",
|
|
137
|
-
event: ROUTER_HMR_UPDATE_ROUTE,
|
|
138
|
-
data: routes
|
|
139
|
-
});
|
|
140
|
-
write(resolved);
|
|
141
|
-
previousRoutes = routes;
|
|
142
|
-
}
|
|
174
|
+
sendRoutingUpdate(server);
|
|
143
175
|
});
|
|
144
176
|
},
|
|
145
177
|
resolveId(id) {
|
|
146
|
-
if (id ===
|
|
147
|
-
return
|
|
178
|
+
if (id === ROUTING_VIRTUAL_MODULE_ID) {
|
|
179
|
+
return RESOLVED_ROUTING_VIRTUAL_MODULE_ID;
|
|
148
180
|
}
|
|
149
181
|
},
|
|
150
182
|
async load(id) {
|
|
151
|
-
if (id ===
|
|
152
|
-
const
|
|
153
|
-
return getClientCode(
|
|
183
|
+
if (id === RESOLVED_ROUTING_VIRTUAL_MODULE_ID) {
|
|
184
|
+
const routing = await fetchRoutingFromArtisan(resolved);
|
|
185
|
+
return getClientCode(routing);
|
|
154
186
|
}
|
|
155
187
|
},
|
|
156
188
|
async handleHotUpdate(ctx) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hybridly/vite",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.21",
|
|
4
4
|
"description": "A solution to develop server-driven, client-rendered applications",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"hybridly",
|
|
@@ -36,16 +36,16 @@
|
|
|
36
36
|
"module": "dist/index.mjs",
|
|
37
37
|
"types": "dist/index.d.ts",
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"vue": "^3.2.
|
|
39
|
+
"vue": "^3.2.45"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"
|
|
43
|
-
"
|
|
42
|
+
"throttle-debounce": "^5.0.0",
|
|
43
|
+
"@hybridly/core": "0.0.1-alpha.21"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"rollup": "^
|
|
47
|
-
"vite": "^
|
|
48
|
-
"vue": "^3.2.
|
|
46
|
+
"rollup": "^3.9.1",
|
|
47
|
+
"vite": "^4.0.4",
|
|
48
|
+
"vue": "^3.2.45"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"build": "unbuild",
|