@hybridly/vite 0.10.0-beta.2 → 0.10.0-beta.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/THIRD-PARTY-LICENSES.md +131 -0
- package/dist/_chunks/libs/@clickbar/dot-diver.mjs +1 -0
- package/dist/_chunks/libs/debug.mjs +6 -12
- package/dist/_chunks/libs/deepmerge.mjs +3 -6
- package/dist/_chunks/libs/es-toolkit.mjs +9 -0
- package/dist/_chunks/rolldown-runtime.mjs +8 -14
- package/dist/index.d.mts +12 -12
- package/dist/index.mjs +440 -485
- package/package.json +9 -10
- package/dist/_chunks/libs/is-plain-object.mjs +0 -23
- package/dist/_chunks/libs/lodash.clonedeep.mjs +0 -1412
package/dist/index.mjs
CHANGED
|
@@ -1,277 +1,22 @@
|
|
|
1
1
|
import { r as __toESM } from "./_chunks/rolldown-runtime.mjs";
|
|
2
|
-
import { t as require_src } from "./_chunks/libs/debug.mjs";
|
|
3
2
|
import { t as require_cjs } from "./_chunks/libs/deepmerge.mjs";
|
|
4
|
-
import { t as isPlainObject } from "./_chunks/libs/
|
|
5
|
-
import
|
|
6
|
-
import
|
|
3
|
+
import { t as isPlainObject } from "./_chunks/libs/es-toolkit.mjs";
|
|
4
|
+
import "./_chunks/libs/@clickbar/dot-diver.mjs";
|
|
5
|
+
import { t as require_src } from "./_chunks/libs/debug.mjs";
|
|
7
6
|
import path from "node:path";
|
|
8
|
-
import
|
|
9
|
-
import { loadEnv } from "vite";
|
|
10
|
-
import "node:url";
|
|
11
|
-
import os from "node:os";
|
|
7
|
+
import fs from "node:fs";
|
|
12
8
|
import { exec } from "node:child_process";
|
|
13
9
|
import { promisify } from "node:util";
|
|
14
|
-
import "
|
|
15
|
-
import
|
|
16
|
-
import run from "vite-plugin-run";
|
|
10
|
+
import { loadEnv } from "vite";
|
|
11
|
+
import { run } from "vite-plugin-run";
|
|
17
12
|
import vue from "@vitejs/plugin-vue";
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
let devEnvironment;
|
|
22
|
-
/**
|
|
23
|
-
* Gets all environment variables, including `.env` ones.
|
|
24
|
-
*/
|
|
25
|
-
function getEnv() {
|
|
26
|
-
return {
|
|
27
|
-
...process.env,
|
|
28
|
-
...loadEnv("mock", process.cwd(), "")
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
async function getPhpExecutable() {
|
|
32
|
-
if (phpExecutable) return phpExecutable;
|
|
33
|
-
const env = getEnv();
|
|
34
|
-
const php = (env.PHP_EXECUTABLE_PATH ?? "php").split(" ");
|
|
35
|
-
if (!env.PHP_EXECUTABLE_PATH) {
|
|
36
|
-
const devEnvironment$1 = await determineDevEnvironment();
|
|
37
|
-
if (devEnvironment$1 === "ddev") php.unshift("ddev");
|
|
38
|
-
else if (devEnvironment$1 === "lando") php.unshift("lando");
|
|
39
|
-
}
|
|
40
|
-
return phpExecutable = php;
|
|
41
|
-
}
|
|
42
|
-
async function determineDevEnvironment() {
|
|
43
|
-
if (devEnvironment) return devEnvironment;
|
|
44
|
-
if (fs.existsSync(`${process.cwd()}/.ddev`)) devEnvironment = "ddev";
|
|
45
|
-
else if (fs.existsSync(`${process.cwd()}/.lando.yml`)) devEnvironment = "lando";
|
|
46
|
-
else devEnvironment = "native";
|
|
47
|
-
return devEnvironment;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
//#endregion
|
|
51
|
-
//#region src/laravel/utils.ts
|
|
52
|
-
function isIpv6(address) {
|
|
53
|
-
return address.family === "IPv6" || address.family === 6;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
//#endregion
|
|
57
|
-
//#region src/laravel/dev-env.ts
|
|
58
|
-
/**
|
|
59
|
-
* Resolves the path to the Herd or Valet configuration directory.
|
|
60
|
-
*/
|
|
61
|
-
function determineDevelopmentEnvironmentConfigPath() {
|
|
62
|
-
const herdConfigPath = path.resolve(os.homedir(), "Library", "Application Support", "Herd", "config", "valet");
|
|
63
|
-
if (fs.existsSync(herdConfigPath)) return herdConfigPath;
|
|
64
|
-
return path.resolve(os.homedir(), ".config", "valet");
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Resolves the Herd or Valet host for the current directory.
|
|
68
|
-
*/
|
|
69
|
-
function resolveDevelopmentEnvironmentHost(configPath) {
|
|
70
|
-
const configFile = path.resolve(configPath, "config.json");
|
|
71
|
-
if (!fs.existsSync(configFile)) return;
|
|
72
|
-
const config = JSON.parse(fs.readFileSync(configFile, "utf-8"));
|
|
73
|
-
return `${path.basename(process.cwd())}.${config.tld}`;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Resolves the Herd or Valet server config for the given host.
|
|
77
|
-
*/
|
|
78
|
-
function resolveDevelopmentEnvironmentServerConfig() {
|
|
79
|
-
const configPath = determineDevelopmentEnvironmentConfigPath();
|
|
80
|
-
const host = resolveDevelopmentEnvironmentHost(configPath);
|
|
81
|
-
if (!host) return;
|
|
82
|
-
const keyPath = path.resolve(configPath, "Certificates", `${host}.key`);
|
|
83
|
-
const certPath = path.resolve(configPath, "Certificates", `${host}.crt`);
|
|
84
|
-
if (!fs.existsSync(keyPath) || !fs.existsSync(certPath)) return;
|
|
85
|
-
return {
|
|
86
|
-
hmr: { host },
|
|
87
|
-
host,
|
|
88
|
-
https: {
|
|
89
|
-
key: fs.readFileSync(keyPath),
|
|
90
|
-
cert: fs.readFileSync(certPath)
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Resolves the server config from the environment.
|
|
96
|
-
*/
|
|
97
|
-
function resolveEnvironmentServerConfig(env) {
|
|
98
|
-
if (!env.VITE_DEV_SERVER_KEY && !env.VITE_DEV_SERVER_CERT) return;
|
|
99
|
-
if (!fs.existsSync(env.VITE_DEV_SERVER_KEY) || !fs.existsSync(env.VITE_DEV_SERVER_CERT)) throw new Error(`Unable to find the certificate files specified in your environment. Ensure you have correctly configured VITE_DEV_SERVER_KEY: [${env.VITE_DEV_SERVER_KEY}] and VITE_DEV_SERVER_CERT: [${env.VITE_DEV_SERVER_CERT}].`);
|
|
100
|
-
const host = resolveHostFromEnv(env);
|
|
101
|
-
return {
|
|
102
|
-
hmr: { host },
|
|
103
|
-
host,
|
|
104
|
-
https: {
|
|
105
|
-
key: fs.readFileSync(env.VITE_DEV_SERVER_KEY),
|
|
106
|
-
cert: fs.readFileSync(env.VITE_DEV_SERVER_CERT)
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Resolve the host name from the environment.
|
|
112
|
-
*/
|
|
113
|
-
function resolveHostFromEnv(env) {
|
|
114
|
-
if (env.VITE_DEV_SERVER_KEY) return env.VITE_DEV_SERVER_KEY;
|
|
115
|
-
try {
|
|
116
|
-
return new URL(env.APP_URL).host;
|
|
117
|
-
} catch {
|
|
118
|
-
throw new Error(`Unable to determine the host from the environment's APP_URL: [${env.APP_URL}].`);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
//#endregion
|
|
123
|
-
//#region src/laravel/index.ts
|
|
124
|
-
let exitHandlersBound = false;
|
|
125
|
-
function laravel(options, hybridlyConfig) {
|
|
126
|
-
let viteDevServerUrl;
|
|
127
|
-
let resolvedConfig;
|
|
128
|
-
let userConfig;
|
|
129
|
-
const publicDirectory = "public";
|
|
130
|
-
const buildDirectory = "build";
|
|
131
|
-
const hotFile = path.join(publicDirectory, "hot");
|
|
132
|
-
return {
|
|
133
|
-
name: "hybridly:laravel",
|
|
134
|
-
enforce: "post",
|
|
135
|
-
config: (config, { command, mode }) => {
|
|
136
|
-
userConfig = config;
|
|
137
|
-
const ssr = !!userConfig.build?.ssr;
|
|
138
|
-
const env = loadEnv(mode, userConfig.envDir || process.cwd(), "");
|
|
139
|
-
const assetUrl = env.ASSET_URL ?? "";
|
|
140
|
-
const base = `${assetUrl + (!assetUrl.endsWith("/") ? "/" : "") + buildDirectory}/`;
|
|
141
|
-
const serverConfig = command === "serve" ? resolveEnvironmentServerConfig(env) ?? resolveDevelopmentEnvironmentServerConfig() : void 0;
|
|
142
|
-
ensureCommandShouldRunInEnvironment(command, env);
|
|
143
|
-
return {
|
|
144
|
-
base: userConfig.base ?? (command === "build" ? base : ""),
|
|
145
|
-
publicDir: userConfig.publicDir ?? false,
|
|
146
|
-
build: {
|
|
147
|
-
manifest: ssr === true ? false : userConfig.build?.manifest ?? "manifest.json",
|
|
148
|
-
outDir: userConfig.build?.outDir ?? path.join(publicDirectory, buildDirectory),
|
|
149
|
-
rollupOptions: { input: resolveInput(config, hybridlyConfig, ssr) },
|
|
150
|
-
assetsInlineLimit: userConfig.build?.assetsInlineLimit ?? 0
|
|
151
|
-
},
|
|
152
|
-
server: {
|
|
153
|
-
origin: userConfig.server?.origin ?? "http://__laravel_vite_placeholder__.test",
|
|
154
|
-
cors: userConfig.server?.cors ?? { origin: userConfig.server?.origin ?? [
|
|
155
|
-
/^https?:\/\/(?:(?:[^:]+\.)?localhost|127\.0\.0\.1|\[::1\])(?::\d+)?$/,
|
|
156
|
-
...env.APP_URL ? [env.APP_URL] : [],
|
|
157
|
-
/^https?:\/\/.*\.test(:\d+)?$/
|
|
158
|
-
] },
|
|
159
|
-
...process.env.LARAVEL_SAIL ? {
|
|
160
|
-
host: userConfig.server?.host ?? "0.0.0.0",
|
|
161
|
-
port: userConfig.server?.port ?? (env.VITE_PORT ? Number.parseInt(env.VITE_PORT) : 5173),
|
|
162
|
-
strictPort: userConfig.server?.strictPort ?? true
|
|
163
|
-
} : void 0,
|
|
164
|
-
...serverConfig ? {
|
|
165
|
-
host: userConfig.server?.host ?? serverConfig.host,
|
|
166
|
-
hmr: userConfig.server?.hmr === false ? false : {
|
|
167
|
-
...serverConfig.hmr,
|
|
168
|
-
...userConfig.server?.hmr === true ? {} : userConfig.server?.hmr
|
|
169
|
-
},
|
|
170
|
-
https: userConfig.server?.https ?? serverConfig.https
|
|
171
|
-
} : void 0
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
},
|
|
175
|
-
configResolved(config) {
|
|
176
|
-
resolvedConfig = config;
|
|
177
|
-
},
|
|
178
|
-
transform(code) {
|
|
179
|
-
if (resolvedConfig.command === "serve") return code.replace(/http:\/\/__laravel_vite_placeholder__\.test/g, viteDevServerUrl);
|
|
180
|
-
},
|
|
181
|
-
configureServer(server) {
|
|
182
|
-
const envDir = resolvedConfig.envDir || process.cwd();
|
|
183
|
-
const appUrl = loadEnv(resolvedConfig.mode, envDir, "APP_URL").APP_URL ?? "undefined";
|
|
184
|
-
if (!["test", "ci"].includes(resolvedConfig.mode)) server.httpServer?.once("listening", async () => {
|
|
185
|
-
const address = server.httpServer?.address();
|
|
186
|
-
const isAddressInfo = (x) => typeof x === "object";
|
|
187
|
-
if (isAddressInfo(address)) {
|
|
188
|
-
viteDevServerUrl = resolveDevServerUrl(address, server.config, userConfig);
|
|
189
|
-
fs.writeFileSync(hotFile, `${viteDevServerUrl}${server.config.base.replace(/\/$/, "")}`);
|
|
190
|
-
if (!hybridlyConfig.versions) return;
|
|
191
|
-
let registered = `${colors.bold(hybridlyConfig.components.views.length)} ${colors.dim("views")}, `;
|
|
192
|
-
registered += `${colors.bold(hybridlyConfig.components.layouts.length)} ${colors.dim("layouts")}, `;
|
|
193
|
-
const latest = hybridlyConfig.versions.is_latest ? "" : colors.dim(`(${colors.yellow(`${hybridlyConfig.versions.latest} is available`)})`);
|
|
194
|
-
let version = `${colors.yellow(`v${hybridlyConfig.versions.composer}`)} ${colors.dim("(composer)")}, `;
|
|
195
|
-
version += `${colors.yellow(`v${hybridlyConfig.versions.npm}`)} ${colors.dim("(npm)")}`;
|
|
196
|
-
version += ` — ${colors.yellow("this may lead to undefined behavior")}`;
|
|
197
|
-
const devEnvironment$1 = await determineDevEnvironment();
|
|
198
|
-
setTimeout(() => {
|
|
199
|
-
server.config.logger.info(`\n ${colors.magenta(`${colors.bold("HYBRIDLY")} v${hybridlyConfig.versions.composer}`)} ${latest}`);
|
|
200
|
-
server.config.logger.info("");
|
|
201
|
-
server.config.logger.info(` ${colors.green("➜")} ${colors.bold("URL")}: ${colors.cyan(hybridlyConfig.routing.url)}`);
|
|
202
|
-
server.config.logger.info(` ${colors.green("➜")} ${colors.bold("Registered")}: ${registered}`);
|
|
203
|
-
if (devEnvironment$1 !== "native") server.config.logger.info(` ${colors.green("➜")} ${colors.bold("Development environment")}: ${colors.cyan(devEnvironment$1)}`);
|
|
204
|
-
if (hybridlyConfig.versions.composer !== hybridlyConfig.versions.npm) server.config.logger.info(` ${colors.yellow("➜")} ${colors.bold("Version mismatch")}: ${version}`);
|
|
205
|
-
}, 100);
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
if (!exitHandlersBound) {
|
|
209
|
-
function clean() {
|
|
210
|
-
if (fs.existsSync(hotFile)) fs.rmSync(hotFile);
|
|
211
|
-
}
|
|
212
|
-
process.on("exit", clean);
|
|
213
|
-
process.on("SIGINT", () => process.exit());
|
|
214
|
-
process.on("SIGTERM", () => process.exit());
|
|
215
|
-
process.on("SIGHUP", () => process.exit());
|
|
216
|
-
exitHandlersBound = true;
|
|
217
|
-
}
|
|
218
|
-
return () => server.middlewares.use((req, res, next) => {
|
|
219
|
-
if (req.url === "/index.html") {
|
|
220
|
-
res.writeHead(302, { Location: appUrl });
|
|
221
|
-
res.end();
|
|
222
|
-
}
|
|
223
|
-
next();
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Validates the command can run in the given environment.
|
|
230
|
-
*/
|
|
231
|
-
function ensureCommandShouldRunInEnvironment(command, env) {
|
|
232
|
-
if (command === "build" || env.LARAVEL_BYPASS_ENV_CHECK === "1" || !!env.TEST || !!env.VITEST) return;
|
|
233
|
-
if (typeof env.LARAVEL_VAPOR !== "undefined") throw new TypeError("You should not run the Vite HMR server on Vapor. You should build your assets for production instead. To disable this ENV check you may set LARAVEL_BYPASS_ENV_CHECK=1");
|
|
234
|
-
if (typeof env.LARAVEL_FORGE !== "undefined") throw new TypeError("You should not run the Vite HMR server in your Forge deployment script. You should build your assets for production instead. To disable this ENV check you may set LARAVEL_BYPASS_ENV_CHECK=1");
|
|
235
|
-
if (typeof env.LARAVEL_ENVOYER !== "undefined") throw new TypeError("You should not run the Vite HMR server in your Envoyer hook. You should build your assets for production instead. To disable this ENV check you may set LARAVEL_BYPASS_ENV_CHECK=1");
|
|
236
|
-
if (typeof env.CI !== "undefined") throw new TypeError("You should not run the Vite HMR server in CI environments. You should build your assets for production instead. To disable this ENV check you may set LARAVEL_BYPASS_ENV_CHECK=1");
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* Resolves input files.
|
|
240
|
-
*/
|
|
241
|
-
function resolveInput(userConfig, hybridlyConfig, _ssr) {
|
|
242
|
-
return userConfig.build?.rollupOptions?.input ?? hybridlyConfig.architecture.application_main_path;
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* Resolves the dev server URL from the server address and configuration.
|
|
246
|
-
*/
|
|
247
|
-
function resolveDevServerUrl(address, config, userConfig) {
|
|
248
|
-
const configHmrProtocol = typeof config.server.hmr === "object" ? config.server.hmr.protocol : null;
|
|
249
|
-
const clientProtocol = configHmrProtocol ? configHmrProtocol === "wss" ? "https" : "http" : null;
|
|
250
|
-
const serverProtocol = config.server.https ? "https" : "http";
|
|
251
|
-
const protocol = clientProtocol ?? serverProtocol;
|
|
252
|
-
const configHmrHost = typeof config.server.hmr === "object" ? config.server.hmr.host : null;
|
|
253
|
-
const configHost = typeof config.server.host === "string" ? config.server.host : null;
|
|
254
|
-
const sailHost = process.env.LARAVEL_SAIL && !userConfig.server?.host ? "localhost" : null;
|
|
255
|
-
const serverAddress = isIpv6(address) ? `[${address.address}]` : address.address;
|
|
256
|
-
return `${protocol}://${configHmrHost ?? sailHost ?? configHost ?? serverAddress}:${(typeof config.server.hmr === "object" ? config.server.hmr.clientPort : null) ?? address.port}`;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
//#endregion
|
|
13
|
+
import colors from "picocolors";
|
|
14
|
+
import os from "node:os";
|
|
15
|
+
import MagicString from "magic-string";
|
|
260
16
|
//#region src/constants.ts
|
|
261
17
|
const LAYOUT_PLUGIN_NAME = "vite:hybridly:layout";
|
|
262
18
|
const CONFIG_PLUGIN_NAME = "vite:hybridly:config";
|
|
263
|
-
const
|
|
264
|
-
const RESOLVED_CONFIG_VIRTUAL_MODULE_ID = `\0${CONFIG_VIRTUAL_MODULE_ID}`;
|
|
265
|
-
|
|
266
|
-
//#endregion
|
|
267
|
-
//#region src/utils.ts
|
|
268
|
-
var import_src = /* @__PURE__ */ __toESM(require_src(), 1);
|
|
269
|
-
const execSync = promisify(exec);
|
|
270
|
-
const debug$1 = {
|
|
271
|
-
config: (0, import_src.default)(CONFIG_PLUGIN_NAME),
|
|
272
|
-
layout: (0, import_src.default)(LAYOUT_PLUGIN_NAME)
|
|
273
|
-
};
|
|
274
|
-
|
|
19
|
+
const RESOLVED_CONFIG_VIRTUAL_MODULE_ID = `\0virtual:hybridly/config`;
|
|
275
20
|
//#endregion
|
|
276
21
|
//#region src/typegen/index.ts
|
|
277
22
|
function generateTsConfig(options, config) {
|
|
@@ -286,23 +31,27 @@ function generateTsConfig(options, config) {
|
|
|
286
31
|
sourceMap: true,
|
|
287
32
|
resolveJsonModule: true,
|
|
288
33
|
esModuleInterop: true,
|
|
34
|
+
rootDir: "../",
|
|
289
35
|
allowSyntheticDefaultImports: true,
|
|
290
|
-
lib: [
|
|
36
|
+
lib: [
|
|
37
|
+
"esnext",
|
|
38
|
+
"dom",
|
|
39
|
+
"dom.iterable"
|
|
40
|
+
],
|
|
291
41
|
types: [
|
|
292
42
|
"vite/client",
|
|
293
43
|
"hybridly/client",
|
|
294
44
|
...options.tsconfig?.types ?? []
|
|
295
45
|
],
|
|
296
|
-
baseUrl: "..",
|
|
297
46
|
paths: {
|
|
298
|
-
"#/*": ["
|
|
299
|
-
"~/*": ["
|
|
300
|
-
"@/*": [
|
|
47
|
+
"#/*": ["./*"],
|
|
48
|
+
"~/*": ["../*"],
|
|
49
|
+
"@/*": [`../${config.architecture.root_directory}/*`]
|
|
301
50
|
}
|
|
302
51
|
},
|
|
303
52
|
include: [
|
|
304
|
-
...config.components.views.map(({ path
|
|
305
|
-
...config.components.layouts.map(({ path
|
|
53
|
+
...config.components.views.map(({ path }) => `../${path}`),
|
|
54
|
+
...config.components.layouts.map(({ path }) => `../${path}`),
|
|
306
55
|
`../${config.architecture.root_directory}/**/*`,
|
|
307
56
|
"./**/*.d.ts",
|
|
308
57
|
...options.tsconfig?.include ?? []
|
|
@@ -350,41 +99,61 @@ declare module 'vue' {
|
|
|
350
99
|
}
|
|
351
100
|
`, "vue-extension.d.ts");
|
|
352
101
|
}
|
|
353
|
-
|
|
354
|
-
const
|
|
355
|
-
if (!
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
102
|
+
function write(data, filename) {
|
|
103
|
+
const hybridlyPath = path.resolve(process.cwd(), ".hybridly");
|
|
104
|
+
if (!fs.existsSync(hybridlyPath)) fs.mkdirSync(hybridlyPath);
|
|
105
|
+
fs.writeFileSync(path.resolve(hybridlyPath, filename), data, { encoding: "utf-8" });
|
|
106
|
+
}
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region src/config/client.ts
|
|
109
|
+
function getClientCode$1(config) {
|
|
110
|
+
const paths = config.components.views.map(({ path }) => `"~/${path}"`).join(",");
|
|
111
|
+
return `
|
|
112
|
+
import { initializeHybridly as init } from 'hybridly/vue'
|
|
113
|
+
|
|
114
|
+
export function initializeHybridly(config) {
|
|
115
|
+
return init({
|
|
116
|
+
...${JSON.stringify(config)},
|
|
117
|
+
imported: import.meta.glob([${paths}], { eager: ${config.components.eager ?? true} }),
|
|
118
|
+
...config,
|
|
119
|
+
})
|
|
120
|
+
}
|
|
121
|
+
`;
|
|
122
|
+
}
|
|
123
|
+
//#endregion
|
|
124
|
+
//#region src/utils.ts
|
|
125
|
+
const execSync = promisify(exec);
|
|
126
|
+
//#endregion
|
|
127
|
+
//#region src/config/env.ts
|
|
128
|
+
let phpExecutable;
|
|
129
|
+
let devEnvironment;
|
|
130
|
+
/**
|
|
131
|
+
* Gets all environment variables, including `.env` ones.
|
|
132
|
+
*/
|
|
133
|
+
function getEnv() {
|
|
134
|
+
return {
|
|
135
|
+
...process.env,
|
|
136
|
+
...loadEnv("mock", process.cwd(), "")
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
async function getPhpExecutable() {
|
|
140
|
+
if (phpExecutable) return phpExecutable;
|
|
141
|
+
const env = getEnv();
|
|
142
|
+
const php = (env.PHP_EXECUTABLE_PATH ?? "php").split(" ");
|
|
143
|
+
if (!env.PHP_EXECUTABLE_PATH) {
|
|
144
|
+
const devEnvironment = await determineDevEnvironment();
|
|
145
|
+
if (devEnvironment === "ddev") php.unshift("ddev");
|
|
146
|
+
else if (devEnvironment === "lando") php.unshift("lando");
|
|
147
|
+
}
|
|
148
|
+
return phpExecutable = php;
|
|
381
149
|
}
|
|
382
|
-
function
|
|
383
|
-
|
|
384
|
-
if (
|
|
385
|
-
fs.
|
|
150
|
+
async function determineDevEnvironment() {
|
|
151
|
+
if (devEnvironment) return devEnvironment;
|
|
152
|
+
if (fs.existsSync(`${process.cwd()}/.ddev`)) devEnvironment = "ddev";
|
|
153
|
+
else if (fs.existsSync(`${process.cwd()}/.lando.yml`)) devEnvironment = "lando";
|
|
154
|
+
else devEnvironment = "native";
|
|
155
|
+
return devEnvironment;
|
|
386
156
|
}
|
|
387
|
-
|
|
388
157
|
//#endregion
|
|
389
158
|
//#region src/config/load.ts
|
|
390
159
|
async function loadConfiguration() {
|
|
@@ -399,30 +168,11 @@ async function loadConfiguration() {
|
|
|
399
168
|
throw e;
|
|
400
169
|
}
|
|
401
170
|
}
|
|
402
|
-
|
|
403
|
-
//#endregion
|
|
404
|
-
//#region src/config/client.ts
|
|
405
|
-
function getClientCode$1(config) {
|
|
406
|
-
const paths = config.components.views.map(({ path: path$1 }) => `"~/${path$1}"`).join(",");
|
|
407
|
-
return `
|
|
408
|
-
import { initializeHybridly as init } from 'hybridly/vue'
|
|
409
|
-
|
|
410
|
-
export function initializeHybridly(config) {
|
|
411
|
-
return init({
|
|
412
|
-
...${JSON.stringify(config)},
|
|
413
|
-
imported: import.meta.glob([${paths}], { eager: ${config.components.eager ?? true} }),
|
|
414
|
-
...config,
|
|
415
|
-
})
|
|
416
|
-
}
|
|
417
|
-
`;
|
|
418
|
-
}
|
|
419
|
-
|
|
420
171
|
//#endregion
|
|
421
172
|
//#region src/config/index.ts
|
|
422
173
|
var config_default = (options, config) => {
|
|
423
174
|
generateTsConfig(options, config);
|
|
424
175
|
generateLaravelIdeaHelper(config);
|
|
425
|
-
generateRouteDefinitionFile(options, config);
|
|
426
176
|
generateVueExtensionFile();
|
|
427
177
|
return {
|
|
428
178
|
name: CONFIG_PLUGIN_NAME,
|
|
@@ -447,7 +197,6 @@ var config_default = (options, config) => {
|
|
|
447
197
|
}
|
|
448
198
|
async function handleFileChange(file) {
|
|
449
199
|
if (file.endsWith("config/hybridly.php")) return await forceRestart("Configuration file changed");
|
|
450
|
-
if (/routes\/.*\.php/.test(file) || /routes\.php/.test(file)) return await forceRestart("Routing changed");
|
|
451
200
|
if (/.*\.vue$/.test(file)) loadConfiguration().then((updatedConfig) => {
|
|
452
201
|
if (didViewsOrLayoutsChange(updatedConfig, config)) forceRestart("View or layout changed");
|
|
453
202
|
}).catch();
|
|
@@ -456,30 +205,362 @@ var config_default = (options, config) => {
|
|
|
456
205
|
server.watcher.on("change", handleFileChange);
|
|
457
206
|
server.watcher.on("unlink", handleFileChange);
|
|
458
207
|
},
|
|
459
|
-
resolveId(id) {
|
|
460
|
-
if (id ===
|
|
208
|
+
resolveId(id) {
|
|
209
|
+
if (id === "virtual:hybridly/config") return RESOLVED_CONFIG_VIRTUAL_MODULE_ID;
|
|
210
|
+
},
|
|
211
|
+
async load(id) {
|
|
212
|
+
if (id === RESOLVED_CONFIG_VIRTUAL_MODULE_ID) return getClientCode$1(config);
|
|
213
|
+
},
|
|
214
|
+
async handleHotUpdate(ctx) {
|
|
215
|
+
if (ctx.file.includes(".hybridly")) return [];
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
};
|
|
219
|
+
function didViewsOrLayoutsChange(updatedConfig, previousConfig) {
|
|
220
|
+
if (!previousConfig) return false;
|
|
221
|
+
return JSON.stringify(updatedConfig.components.views) !== JSON.stringify(previousConfig.components.views) || JSON.stringify(updatedConfig.components.layouts) !== JSON.stringify(previousConfig.components.layouts);
|
|
222
|
+
}
|
|
223
|
+
//#endregion
|
|
224
|
+
//#region src/integrations/run.ts
|
|
225
|
+
async function getRunOptions(options) {
|
|
226
|
+
if (options.run === false) return [];
|
|
227
|
+
const php = await getPhpExecutable();
|
|
228
|
+
return [
|
|
229
|
+
{
|
|
230
|
+
name: "Generate TypeScript definitions",
|
|
231
|
+
run: [
|
|
232
|
+
...php,
|
|
233
|
+
"artisan",
|
|
234
|
+
"hybridly:types",
|
|
235
|
+
options.allowTypeGenerationFailures !== false ? "--allow-failures" : ""
|
|
236
|
+
].filter(Boolean),
|
|
237
|
+
pattern: ["+(app|config|routes|src)/**/*.php"]
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
name: "Generate i18n",
|
|
241
|
+
run: [
|
|
242
|
+
...php,
|
|
243
|
+
"artisan",
|
|
244
|
+
"hybridly:i18n"
|
|
245
|
+
],
|
|
246
|
+
pattern: "lang/**/*.php"
|
|
247
|
+
},
|
|
248
|
+
...options.run ?? []
|
|
249
|
+
];
|
|
250
|
+
}
|
|
251
|
+
//#endregion
|
|
252
|
+
//#region src/integrations/unplugins.ts
|
|
253
|
+
/**
|
|
254
|
+
* Import map for auto-importing Hybridly utils.
|
|
255
|
+
*/
|
|
256
|
+
const hybridlyImports = {
|
|
257
|
+
"hybridly/vue": [
|
|
258
|
+
"useProperty",
|
|
259
|
+
"setProperty",
|
|
260
|
+
"useRefinements",
|
|
261
|
+
"useTable",
|
|
262
|
+
"useBulkSelect",
|
|
263
|
+
"useProperties",
|
|
264
|
+
"useBackForward",
|
|
265
|
+
"useContext",
|
|
266
|
+
"useForm",
|
|
267
|
+
"useDialog",
|
|
268
|
+
"useHistoryState",
|
|
269
|
+
"createPaginator",
|
|
270
|
+
"registerHook",
|
|
271
|
+
"useRoute",
|
|
272
|
+
"useQueryParameter",
|
|
273
|
+
"useQueryParameters"
|
|
274
|
+
],
|
|
275
|
+
"hybridly": [
|
|
276
|
+
"router",
|
|
277
|
+
"route",
|
|
278
|
+
"can",
|
|
279
|
+
"getRouterContext"
|
|
280
|
+
]
|
|
281
|
+
};
|
|
282
|
+
//#endregion
|
|
283
|
+
//#region ../utils/src/utils.ts
|
|
284
|
+
var import_cjs = /* @__PURE__ */ __toESM(require_cjs(), 1);
|
|
285
|
+
function merge(x, y, options = {}) {
|
|
286
|
+
return (0, import_cjs.default)(x, y, {
|
|
287
|
+
arrayMerge: typeof options?.arrayMerge === "function" ? options.arrayMerge : options?.overwriteArray !== false ? (_, s) => s : void 0,
|
|
288
|
+
isMergeableObject: options?.mergePlainObjects ? isPlainObject : void 0
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
//#endregion
|
|
292
|
+
//#region ../utils/src/debug.ts
|
|
293
|
+
var import_src = /* @__PURE__ */ __toESM(require_src(), 1);
|
|
294
|
+
const debug = {
|
|
295
|
+
router: (0, import_src.default)("hybridly:core:router"),
|
|
296
|
+
queue: (0, import_src.default)("hybridly:core:router:queue"),
|
|
297
|
+
history: (0, import_src.default)("hybridly:core:history"),
|
|
298
|
+
url: (0, import_src.default)("hybridly:core:url"),
|
|
299
|
+
context: (0, import_src.default)("hybridly:core:context"),
|
|
300
|
+
external: (0, import_src.default)("hybridly:core:external"),
|
|
301
|
+
scroll: (0, import_src.default)("hybridly:core:scroll"),
|
|
302
|
+
hook: (0, import_src.default)("hybridly:core:hook"),
|
|
303
|
+
layout: (0, import_src.default)("hybridly:plugin:layout"),
|
|
304
|
+
config: (0, import_src.default)("hybridly:vite:config"),
|
|
305
|
+
plugin: (name, ...args) => (0, import_src.default)("hybridly:plugin").extend(name.replace("hybridly:", ""))(args.shift(), ...args),
|
|
306
|
+
adapter: (name, ...args) => (0, import_src.default)("hybridly:adapter").extend(name)(args.shift(), ...args)
|
|
307
|
+
};
|
|
308
|
+
//#endregion
|
|
309
|
+
//#region src/integrations/vue.ts
|
|
310
|
+
function getVueOptions(options) {
|
|
311
|
+
if (options.vue === false) return {};
|
|
312
|
+
return merge({
|
|
313
|
+
template: {
|
|
314
|
+
transformAssetUrls: {
|
|
315
|
+
base: null,
|
|
316
|
+
includeAbsolute: false
|
|
317
|
+
},
|
|
318
|
+
...options.vue?.template
|
|
319
|
+
},
|
|
320
|
+
script: {
|
|
321
|
+
globalTypeFiles: [path.resolve(".hybridly/php-types.d.ts")],
|
|
322
|
+
defineModel: true,
|
|
323
|
+
...options.vue?.script
|
|
324
|
+
}
|
|
325
|
+
}, options.vue ?? {}, { overwriteArray: false });
|
|
326
|
+
}
|
|
327
|
+
//#endregion
|
|
328
|
+
//#region src/kill-switch.ts
|
|
329
|
+
function killSwitch() {
|
|
330
|
+
let _enabled = false;
|
|
331
|
+
return {
|
|
332
|
+
name: "hybridly:build:kill-switch",
|
|
333
|
+
config: ({ mode }) => {
|
|
334
|
+
if (mode === "build") _enabled = true;
|
|
335
|
+
},
|
|
336
|
+
buildEnd: (error) => {
|
|
337
|
+
if (!_enabled) return;
|
|
338
|
+
if (error) {
|
|
339
|
+
console.error("Error when bundling");
|
|
340
|
+
console.error(error);
|
|
341
|
+
process.exit(1);
|
|
342
|
+
}
|
|
343
|
+
},
|
|
344
|
+
closeBundle: () => {
|
|
345
|
+
if (!_enabled) return;
|
|
346
|
+
process.exit(0);
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
//#endregion
|
|
351
|
+
//#region src/laravel/utils.ts
|
|
352
|
+
function isIpv6(address) {
|
|
353
|
+
return address.family === "IPv6" || address.family === 6;
|
|
354
|
+
}
|
|
355
|
+
//#endregion
|
|
356
|
+
//#region src/laravel/dev-env.ts
|
|
357
|
+
/**
|
|
358
|
+
* Resolves the path to the Herd or Valet configuration directory.
|
|
359
|
+
*/
|
|
360
|
+
function determineDevelopmentEnvironmentConfigPath() {
|
|
361
|
+
const herdConfigPath = path.resolve(os.homedir(), "Library", "Application Support", "Herd", "config", "valet");
|
|
362
|
+
if (fs.existsSync(herdConfigPath)) return herdConfigPath;
|
|
363
|
+
return path.resolve(os.homedir(), ".config", "valet");
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Resolves the Herd or Valet host for the current directory.
|
|
367
|
+
*/
|
|
368
|
+
function resolveDevelopmentEnvironmentHost(configPath) {
|
|
369
|
+
const configFile = path.resolve(configPath, "config.json");
|
|
370
|
+
if (!fs.existsSync(configFile)) return;
|
|
371
|
+
const config = JSON.parse(fs.readFileSync(configFile, "utf-8"));
|
|
372
|
+
return `${path.basename(process.cwd())}.${config.tld}`;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Resolves the Herd or Valet server config for the given host.
|
|
376
|
+
*/
|
|
377
|
+
function resolveDevelopmentEnvironmentServerConfig() {
|
|
378
|
+
const configPath = determineDevelopmentEnvironmentConfigPath();
|
|
379
|
+
const host = resolveDevelopmentEnvironmentHost(configPath);
|
|
380
|
+
if (!host) return;
|
|
381
|
+
const keyPath = path.resolve(configPath, "Certificates", `${host}.key`);
|
|
382
|
+
const certPath = path.resolve(configPath, "Certificates", `${host}.crt`);
|
|
383
|
+
if (!fs.existsSync(keyPath) || !fs.existsSync(certPath)) return;
|
|
384
|
+
return {
|
|
385
|
+
hmr: { host },
|
|
386
|
+
host,
|
|
387
|
+
https: {
|
|
388
|
+
key: fs.readFileSync(keyPath),
|
|
389
|
+
cert: fs.readFileSync(certPath)
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Resolves the server config from the environment.
|
|
395
|
+
*/
|
|
396
|
+
function resolveEnvironmentServerConfig(env) {
|
|
397
|
+
if (!env.VITE_DEV_SERVER_KEY && !env.VITE_DEV_SERVER_CERT) return;
|
|
398
|
+
if (!fs.existsSync(env.VITE_DEV_SERVER_KEY) || !fs.existsSync(env.VITE_DEV_SERVER_CERT)) throw new Error(`Unable to find the certificate files specified in your environment. Ensure you have correctly configured VITE_DEV_SERVER_KEY: [${env.VITE_DEV_SERVER_KEY}] and VITE_DEV_SERVER_CERT: [${env.VITE_DEV_SERVER_CERT}].`);
|
|
399
|
+
const host = resolveHostFromEnv(env);
|
|
400
|
+
return {
|
|
401
|
+
hmr: { host },
|
|
402
|
+
host,
|
|
403
|
+
https: {
|
|
404
|
+
key: fs.readFileSync(env.VITE_DEV_SERVER_KEY),
|
|
405
|
+
cert: fs.readFileSync(env.VITE_DEV_SERVER_CERT)
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Resolve the host name from the environment.
|
|
411
|
+
*/
|
|
412
|
+
function resolveHostFromEnv(env) {
|
|
413
|
+
if (env.VITE_DEV_SERVER_KEY) return env.VITE_DEV_SERVER_KEY;
|
|
414
|
+
try {
|
|
415
|
+
return new URL(env.APP_URL).host;
|
|
416
|
+
} catch {
|
|
417
|
+
throw new Error(`Unable to determine the host from the environment's APP_URL: [${env.APP_URL}].`);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
//#endregion
|
|
421
|
+
//#region src/laravel/index.ts
|
|
422
|
+
let exitHandlersBound = false;
|
|
423
|
+
function laravel(options, hybridlyConfig) {
|
|
424
|
+
let viteDevServerUrl;
|
|
425
|
+
let resolvedConfig;
|
|
426
|
+
let userConfig;
|
|
427
|
+
const publicDirectory = "public";
|
|
428
|
+
const buildDirectory = "build";
|
|
429
|
+
const hotFile = path.join(publicDirectory, "hot");
|
|
430
|
+
return {
|
|
431
|
+
name: "hybridly:laravel",
|
|
432
|
+
enforce: "post",
|
|
433
|
+
config: (config, { command, mode }) => {
|
|
434
|
+
userConfig = config;
|
|
435
|
+
const ssr = !!userConfig.build?.ssr;
|
|
436
|
+
const env = loadEnv(mode, userConfig.envDir || process.cwd(), "");
|
|
437
|
+
const assetUrl = env.ASSET_URL ?? "";
|
|
438
|
+
const base = `${assetUrl + (!assetUrl.endsWith("/") ? "/" : "") + buildDirectory}/`;
|
|
439
|
+
const serverConfig = command === "serve" ? resolveEnvironmentServerConfig(env) ?? resolveDevelopmentEnvironmentServerConfig() : void 0;
|
|
440
|
+
ensureCommandShouldRunInEnvironment(command, env);
|
|
441
|
+
return {
|
|
442
|
+
base: userConfig.base ?? (command === "build" ? base : ""),
|
|
443
|
+
publicDir: userConfig.publicDir ?? false,
|
|
444
|
+
build: {
|
|
445
|
+
manifest: ssr === true ? false : userConfig.build?.manifest ?? "manifest.json",
|
|
446
|
+
outDir: userConfig.build?.outDir ?? path.join(publicDirectory, buildDirectory),
|
|
447
|
+
rollupOptions: { input: resolveInput(config, hybridlyConfig, ssr) },
|
|
448
|
+
assetsInlineLimit: userConfig.build?.assetsInlineLimit ?? 0
|
|
449
|
+
},
|
|
450
|
+
server: {
|
|
451
|
+
origin: userConfig.server?.origin ?? "http://__laravel_vite_placeholder__.test",
|
|
452
|
+
cors: userConfig.server?.cors ?? { origin: userConfig.server?.origin ?? [
|
|
453
|
+
/^https?:\/\/(?:(?:[^:]+\.)?localhost|127\.0\.0\.1|\[::1\])(?::\d+)?$/,
|
|
454
|
+
...env.APP_URL ? [env.APP_URL] : [],
|
|
455
|
+
/^https?:\/\/.*\.test(:\d+)?$/
|
|
456
|
+
] },
|
|
457
|
+
...process.env.LARAVEL_SAIL ? {
|
|
458
|
+
host: userConfig.server?.host ?? "0.0.0.0",
|
|
459
|
+
port: userConfig.server?.port ?? (env.VITE_PORT ? Number.parseInt(env.VITE_PORT) : 5173),
|
|
460
|
+
strictPort: userConfig.server?.strictPort ?? true
|
|
461
|
+
} : void 0,
|
|
462
|
+
...serverConfig ? {
|
|
463
|
+
host: userConfig.server?.host ?? serverConfig.host,
|
|
464
|
+
hmr: userConfig.server?.hmr === false ? false : {
|
|
465
|
+
...serverConfig.hmr,
|
|
466
|
+
...userConfig.server?.hmr === true ? {} : userConfig.server?.hmr
|
|
467
|
+
},
|
|
468
|
+
https: userConfig.server?.https ?? serverConfig.https
|
|
469
|
+
} : void 0
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
},
|
|
473
|
+
configResolved(config) {
|
|
474
|
+
resolvedConfig = config;
|
|
461
475
|
},
|
|
462
|
-
|
|
463
|
-
if (
|
|
476
|
+
transform(code) {
|
|
477
|
+
if (resolvedConfig.command === "serve") return code.replace(/http:\/\/__laravel_vite_placeholder__\.test/g, viteDevServerUrl);
|
|
464
478
|
},
|
|
465
|
-
|
|
466
|
-
|
|
479
|
+
configureServer(server) {
|
|
480
|
+
const envDir = resolvedConfig.envDir || process.cwd();
|
|
481
|
+
const appUrl = loadEnv(resolvedConfig.mode, envDir, "APP_URL").APP_URL ?? "undefined";
|
|
482
|
+
if (!["test", "ci"].includes(resolvedConfig.mode)) server.httpServer?.once("listening", async () => {
|
|
483
|
+
const address = server.httpServer?.address();
|
|
484
|
+
const isAddressInfo = (x) => typeof x === "object";
|
|
485
|
+
if (isAddressInfo(address)) {
|
|
486
|
+
viteDevServerUrl = resolveDevServerUrl(address, server.config, userConfig);
|
|
487
|
+
fs.writeFileSync(hotFile, `${viteDevServerUrl}${server.config.base.replace(/\/$/, "")}`);
|
|
488
|
+
if (!hybridlyConfig.versions) return;
|
|
489
|
+
let registered = `${colors.bold(hybridlyConfig.components.views.length)} ${colors.dim("views")}, `;
|
|
490
|
+
registered += `${colors.bold(hybridlyConfig.components.layouts.length)} ${colors.dim("layouts")}, `;
|
|
491
|
+
const latest = hybridlyConfig.versions.is_latest ? "" : colors.dim(`(${colors.yellow(`${hybridlyConfig.versions.latest} is available`)})`);
|
|
492
|
+
let version = `${colors.yellow(`v${hybridlyConfig.versions.composer}`)} ${colors.dim("(composer)")}, `;
|
|
493
|
+
version += `${colors.yellow(`v${hybridlyConfig.versions.npm}`)} ${colors.dim("(npm)")}`;
|
|
494
|
+
version += ` — ${colors.yellow("this may lead to undefined behavior")}`;
|
|
495
|
+
const devEnvironment = await determineDevEnvironment();
|
|
496
|
+
setTimeout(() => {
|
|
497
|
+
server.config.logger.info(`\n ${colors.magenta(`${colors.bold("HYBRIDLY")} v${hybridlyConfig.versions.composer}`)} ${latest}`);
|
|
498
|
+
server.config.logger.info("");
|
|
499
|
+
server.config.logger.info(` ${colors.green("➜")} ${colors.bold("URL")}: ${colors.cyan(hybridlyConfig.routing.url)}`);
|
|
500
|
+
server.config.logger.info(` ${colors.green("➜")} ${colors.bold("Registered")}: ${registered}`);
|
|
501
|
+
if (devEnvironment !== "native") server.config.logger.info(` ${colors.green("➜")} ${colors.bold("Development environment")}: ${colors.cyan(devEnvironment)}`);
|
|
502
|
+
if (hybridlyConfig.versions.composer !== hybridlyConfig.versions.npm) server.config.logger.info(` ${colors.yellow("➜")} ${colors.bold("Version mismatch")}: ${version}`);
|
|
503
|
+
}, 100);
|
|
504
|
+
}
|
|
505
|
+
});
|
|
506
|
+
if (!exitHandlersBound) {
|
|
507
|
+
function clean() {
|
|
508
|
+
if (fs.existsSync(hotFile)) fs.rmSync(hotFile);
|
|
509
|
+
}
|
|
510
|
+
process.on("exit", clean);
|
|
511
|
+
process.on("SIGINT", () => process.exit());
|
|
512
|
+
process.on("SIGTERM", () => process.exit());
|
|
513
|
+
process.on("SIGHUP", () => process.exit());
|
|
514
|
+
exitHandlersBound = true;
|
|
515
|
+
}
|
|
516
|
+
return () => server.middlewares.use((req, res, next) => {
|
|
517
|
+
if (req.url === "/index.html") {
|
|
518
|
+
res.writeHead(302, { Location: appUrl });
|
|
519
|
+
res.end();
|
|
520
|
+
}
|
|
521
|
+
next();
|
|
522
|
+
});
|
|
467
523
|
}
|
|
468
524
|
};
|
|
469
|
-
};
|
|
470
|
-
function didViewsOrLayoutsChange(updatedConfig, previousConfig) {
|
|
471
|
-
if (!previousConfig) return false;
|
|
472
|
-
return JSON.stringify(updatedConfig.components.views) !== JSON.stringify(previousConfig.components.views) || JSON.stringify(updatedConfig.components.layouts) !== JSON.stringify(previousConfig.components.layouts);
|
|
473
525
|
}
|
|
474
|
-
|
|
526
|
+
/**
|
|
527
|
+
* Validates the command can run in the given environment.
|
|
528
|
+
*/
|
|
529
|
+
function ensureCommandShouldRunInEnvironment(command, env) {
|
|
530
|
+
if (command === "build" || env.LARAVEL_BYPASS_ENV_CHECK === "1" || !!env.TEST || !!env.VITEST) return;
|
|
531
|
+
if (typeof env.LARAVEL_VAPOR !== "undefined") throw new TypeError("You should not run the Vite HMR server on Vapor. You should build your assets for production instead. To disable this ENV check you may set LARAVEL_BYPASS_ENV_CHECK=1");
|
|
532
|
+
if (typeof env.LARAVEL_FORGE !== "undefined") throw new TypeError("You should not run the Vite HMR server in your Forge deployment script. You should build your assets for production instead. To disable this ENV check you may set LARAVEL_BYPASS_ENV_CHECK=1");
|
|
533
|
+
if (typeof env.LARAVEL_ENVOYER !== "undefined") throw new TypeError("You should not run the Vite HMR server in your Envoyer hook. You should build your assets for production instead. To disable this ENV check you may set LARAVEL_BYPASS_ENV_CHECK=1");
|
|
534
|
+
if (typeof env.CI !== "undefined") throw new TypeError("You should not run the Vite HMR server in CI environments. You should build your assets for production instead. To disable this ENV check you may set LARAVEL_BYPASS_ENV_CHECK=1");
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* Resolves input files.
|
|
538
|
+
*/
|
|
539
|
+
function resolveInput(userConfig, hybridlyConfig, _ssr) {
|
|
540
|
+
return userConfig.build?.rollupOptions?.input ?? hybridlyConfig.architecture.application_main_path;
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Resolves the dev server URL from the server address and configuration.
|
|
544
|
+
*/
|
|
545
|
+
function resolveDevServerUrl(address, config, userConfig) {
|
|
546
|
+
const configHmrProtocol = typeof config.server.hmr === "object" ? config.server.hmr.protocol : null;
|
|
547
|
+
const clientProtocol = configHmrProtocol ? configHmrProtocol === "wss" ? "https" : "http" : null;
|
|
548
|
+
const serverProtocol = config.server.https ? "https" : "http";
|
|
549
|
+
const protocol = clientProtocol ?? serverProtocol;
|
|
550
|
+
const configHmrHost = typeof config.server.hmr === "object" ? config.server.hmr.host : null;
|
|
551
|
+
const configHost = typeof config.server.host === "string" ? config.server.host : null;
|
|
552
|
+
const sailHost = process.env.LARAVEL_SAIL && !userConfig.server?.host ? "localhost" : null;
|
|
553
|
+
const serverAddress = isIpv6(address) ? `[${address.address}]` : address.address;
|
|
554
|
+
return `${protocol}://${configHmrHost ?? sailHost ?? configHost ?? serverAddress}:${(typeof config.server.hmr === "object" ? config.server.hmr.clientPort : null) ?? address.port}`;
|
|
555
|
+
}
|
|
475
556
|
//#endregion
|
|
476
557
|
//#region src/layout/index.ts
|
|
477
|
-
const TEMPLATE_LAYOUT_REGEX = /<template +layout(?: *= *['"]((?:[\w\/\-_
|
|
558
|
+
const TEMPLATE_LAYOUT_REGEX = /<template +layout(?: *= *['"]((?:[\w\/\-_,:.](?:,\ )?)+)['"] *)?>/;
|
|
478
559
|
const LANG_REGEX = /lang=['"](\w+)['"]/;
|
|
479
560
|
var layout_default = (options, config) => {
|
|
480
|
-
const defaultLayoutName = options?.layout?.defaultLayoutName?.replace(".vue", "") ?? "default";
|
|
561
|
+
const defaultLayoutName = options?.layout?.defaultLayoutName?.replace(".layout.vue", "")?.replace(".vue", "") ?? "default";
|
|
481
562
|
const templateRegExp = options?.layout?.templateRegExp ?? TEMPLATE_LAYOUT_REGEX;
|
|
482
|
-
debug
|
|
563
|
+
debug.layout("Resolved options:", { defaultLayoutName });
|
|
483
564
|
return {
|
|
484
565
|
name: LAYOUT_PLUGIN_NAME,
|
|
485
566
|
enforce: "pre",
|
|
@@ -488,13 +569,22 @@ var layout_default = (options, config) => {
|
|
|
488
569
|
const updatedCode = new MagicString(code).replace(templateRegExp, (_, layoutName) => {
|
|
489
570
|
const [hasLang, lang] = code.match(LANG_REGEX) ?? [];
|
|
490
571
|
const layouts = layoutName?.toString()?.replaceAll(" ", "").split(",") ?? [defaultLayoutName];
|
|
572
|
+
if (layouts.length === 1 && layouts.at(0) === "false") {
|
|
573
|
+
debug.layout(`User opted out of layouts`, { layouts });
|
|
574
|
+
return `
|
|
575
|
+
<script${hasLang ? ` lang="${lang}"` : ""}>
|
|
576
|
+
export default { layout: [] }
|
|
577
|
+
<\/script>
|
|
578
|
+
<template>
|
|
579
|
+
`.replace(/^\s+/gm, "");
|
|
580
|
+
}
|
|
491
581
|
const importName = (i) => `__hybridly_layout_${i}`;
|
|
492
|
-
const exports = layouts.map((_
|
|
493
|
-
const imports = layouts.reduce((imports
|
|
494
|
-
${imports
|
|
495
|
-
import ${importName(i)} from '${resolveLayoutImportPath(layoutName
|
|
582
|
+
const exports = layouts.map((_, i) => importName(i));
|
|
583
|
+
const imports = layouts.reduce((imports, layoutName, i) => `
|
|
584
|
+
${imports}
|
|
585
|
+
import ${importName(i)} from '${resolveLayoutImportPath(layoutName, config)}';
|
|
496
586
|
`, "").trim();
|
|
497
|
-
debug
|
|
587
|
+
debug.layout(`Resolved layouts "${layouts.join(", ")}":`, {
|
|
498
588
|
sourceFile: id,
|
|
499
589
|
layouts,
|
|
500
590
|
imports
|
|
@@ -505,7 +595,7 @@ var layout_default = (options, config) => {
|
|
|
505
595
|
export default { layout: [${exports.join(", ")}] }
|
|
506
596
|
<\/script>
|
|
507
597
|
<template>
|
|
508
|
-
|
|
598
|
+
`.replace(/^\s+/gm, "");
|
|
509
599
|
});
|
|
510
600
|
return {
|
|
511
601
|
map: updatedCode.generateMap(),
|
|
@@ -518,110 +608,10 @@ var layout_default = (options, config) => {
|
|
|
518
608
|
* Resolves a layout by its name.
|
|
519
609
|
*/
|
|
520
610
|
function resolveLayoutImportPath(name, config) {
|
|
521
|
-
const { path
|
|
522
|
-
if (!path
|
|
523
|
-
return `~/${path
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
//#endregion
|
|
527
|
-
//#region src/integrations/run.ts
|
|
528
|
-
async function getRunOptions(options) {
|
|
529
|
-
if (options.run === false) return [];
|
|
530
|
-
const php = await getPhpExecutable();
|
|
531
|
-
return [
|
|
532
|
-
{
|
|
533
|
-
name: "Generate TypeScript types",
|
|
534
|
-
run: [
|
|
535
|
-
...php,
|
|
536
|
-
"artisan",
|
|
537
|
-
"hybridly:types",
|
|
538
|
-
options.allowTypeGenerationFailures !== false ? "--allow-failures" : ""
|
|
539
|
-
].filter(Boolean),
|
|
540
|
-
pattern: [
|
|
541
|
-
"+(app|src)/**/*Data.php",
|
|
542
|
-
"+(app|src)/**/Enums/*.php",
|
|
543
|
-
"+(app|src)/**/Middleware/HandleHybridRequests.php"
|
|
544
|
-
]
|
|
545
|
-
},
|
|
546
|
-
{
|
|
547
|
-
name: "Generate i18n",
|
|
548
|
-
run: [
|
|
549
|
-
...php,
|
|
550
|
-
"artisan",
|
|
551
|
-
"hybridly:i18n"
|
|
552
|
-
],
|
|
553
|
-
pattern: "lang/**/*.php"
|
|
554
|
-
},
|
|
555
|
-
...options.run ?? []
|
|
556
|
-
];
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
//#endregion
|
|
560
|
-
//#region ../utils/dist/index.mjs
|
|
561
|
-
var import_cjs = /* @__PURE__ */ __toESM(require_cjs(), 1);
|
|
562
|
-
var import_lodash = /* @__PURE__ */ __toESM(require_lodash(), 1);
|
|
563
|
-
function merge(x, y, options = {}) {
|
|
564
|
-
return (0, import_cjs.default)(x, y, {
|
|
565
|
-
arrayMerge: typeof options?.arrayMerge === "function" ? options.arrayMerge : options?.overwriteArray !== false ? (_, s) => s : void 0,
|
|
566
|
-
isMergeableObject: options?.mergePlainObjects ? isPlainObject : void 0
|
|
567
|
-
});
|
|
568
|
-
}
|
|
569
|
-
const debug = {
|
|
570
|
-
router: (0, import_src.default)("hybridly:core:router"),
|
|
571
|
-
history: (0, import_src.default)("hybridly:core:history"),
|
|
572
|
-
url: (0, import_src.default)("hybridly:core:url"),
|
|
573
|
-
context: (0, import_src.default)("hybridly:core:context"),
|
|
574
|
-
external: (0, import_src.default)("hybridly:core:external"),
|
|
575
|
-
scroll: (0, import_src.default)("hybridly:core:scroll"),
|
|
576
|
-
hook: (0, import_src.default)("hybridly:core:hook"),
|
|
577
|
-
plugin: (name, ...args) => (0, import_src.default)("hybridly:plugin").extend(name.replace("hybridly:", ""))(args.shift(), ...args),
|
|
578
|
-
adapter: (name, ...args) => (0, import_src.default)("hybridly:adapter").extend(name)(args.shift(), ...args)
|
|
579
|
-
};
|
|
580
|
-
|
|
581
|
-
//#endregion
|
|
582
|
-
//#region src/integrations/vue.ts
|
|
583
|
-
function getVueOptions(options) {
|
|
584
|
-
if (options.vue === false) return {};
|
|
585
|
-
return merge({
|
|
586
|
-
template: {
|
|
587
|
-
transformAssetUrls: {
|
|
588
|
-
base: null,
|
|
589
|
-
includeAbsolute: false
|
|
590
|
-
},
|
|
591
|
-
...options.vue?.template
|
|
592
|
-
},
|
|
593
|
-
script: {
|
|
594
|
-
globalTypeFiles: [path.resolve(".hybridly/php-types.d.ts")],
|
|
595
|
-
defineModel: true,
|
|
596
|
-
...options.vue?.script
|
|
597
|
-
}
|
|
598
|
-
}, options.vue ?? {}, { overwriteArray: false });
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
//#endregion
|
|
602
|
-
//#region src/kill-switch.ts
|
|
603
|
-
function killSwitch() {
|
|
604
|
-
let _enabled = false;
|
|
605
|
-
return {
|
|
606
|
-
name: "hybridly:build:kill-switch",
|
|
607
|
-
config: ({ mode }) => {
|
|
608
|
-
if (mode === "build") _enabled = true;
|
|
609
|
-
},
|
|
610
|
-
buildEnd: (error) => {
|
|
611
|
-
if (!_enabled) return;
|
|
612
|
-
if (error) {
|
|
613
|
-
console.error("Error when bundling");
|
|
614
|
-
console.error(error);
|
|
615
|
-
process.exit(1);
|
|
616
|
-
}
|
|
617
|
-
},
|
|
618
|
-
closeBundle: () => {
|
|
619
|
-
if (!_enabled) return;
|
|
620
|
-
process.exit(0);
|
|
621
|
-
}
|
|
622
|
-
};
|
|
611
|
+
const { path } = config.components.layouts.find((layout) => layout.identifier === name) ?? {};
|
|
612
|
+
if (!path) throw new Error(`Layout [${name}] could not be found.`);
|
|
613
|
+
return `~/${path}`;
|
|
623
614
|
}
|
|
624
|
-
|
|
625
615
|
//#endregion
|
|
626
616
|
//#region src/local-build/client.ts
|
|
627
617
|
function getClientCode() {
|
|
@@ -681,7 +671,6 @@ function getClientCode() {
|
|
|
681
671
|
})()
|
|
682
672
|
`;
|
|
683
673
|
}
|
|
684
|
-
|
|
685
674
|
//#endregion
|
|
686
675
|
//#region src/local-build/index.ts
|
|
687
676
|
const LOCAL_BUILD_VIRTUAL_ID = "virtual:hybridly/local-build";
|
|
@@ -705,45 +694,12 @@ function warnOnLocalBuilds() {
|
|
|
705
694
|
},
|
|
706
695
|
transform(code, id) {
|
|
707
696
|
if (!shouldDisplayWarning) return;
|
|
708
|
-
if (!id.endsWith(
|
|
697
|
+
if (!id.endsWith("virtual:hybridly/config")) return;
|
|
709
698
|
code = `${code}\nimport '${LOCAL_BUILD_VIRTUAL_ID}'`;
|
|
710
699
|
return code;
|
|
711
700
|
}
|
|
712
701
|
};
|
|
713
702
|
}
|
|
714
|
-
|
|
715
|
-
//#endregion
|
|
716
|
-
//#region src/integrations/unplugins.ts
|
|
717
|
-
/**
|
|
718
|
-
* Import map for auto-importing Hybridly utils.
|
|
719
|
-
*/
|
|
720
|
-
const hybridlyImports = {
|
|
721
|
-
"hybridly/vue": [
|
|
722
|
-
"useProperty",
|
|
723
|
-
"setProperty",
|
|
724
|
-
"useRefinements",
|
|
725
|
-
"useTable",
|
|
726
|
-
"useBulkSelect",
|
|
727
|
-
"useProperties",
|
|
728
|
-
"useBackForward",
|
|
729
|
-
"useContext",
|
|
730
|
-
"useForm",
|
|
731
|
-
"useDialog",
|
|
732
|
-
"useHistoryState",
|
|
733
|
-
"createPaginator",
|
|
734
|
-
"registerHook",
|
|
735
|
-
"useRoute",
|
|
736
|
-
"useQueryParameter",
|
|
737
|
-
"useQueryParameters"
|
|
738
|
-
],
|
|
739
|
-
"hybridly": [
|
|
740
|
-
"router",
|
|
741
|
-
"route",
|
|
742
|
-
"can",
|
|
743
|
-
"getRouterContext"
|
|
744
|
-
]
|
|
745
|
-
};
|
|
746
|
-
|
|
747
703
|
//#endregion
|
|
748
704
|
//#region src/index.ts
|
|
749
705
|
async function plugin(options = {}) {
|
|
@@ -759,6 +715,5 @@ async function plugin(options = {}) {
|
|
|
759
715
|
resolvedOptions.warnOnLocalBuilds !== false && warnOnLocalBuilds()
|
|
760
716
|
];
|
|
761
717
|
}
|
|
762
|
-
|
|
763
718
|
//#endregion
|
|
764
|
-
export { plugin as default, hybridlyImports, layout_default as layout };
|
|
719
|
+
export { plugin as default, hybridlyImports, layout_default as layout };
|