@hybridly/vite 0.7.7 → 0.7.8
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 +56 -13
- package/dist/index.mjs +56 -13
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -8,10 +8,10 @@ const colors = require('picocolors');
|
|
|
8
8
|
const vite = require('vite');
|
|
9
9
|
require('node:url');
|
|
10
10
|
const os = require('node:os');
|
|
11
|
-
const makeDebugger = require('debug');
|
|
12
|
-
const localPkg = require('local-pkg');
|
|
13
11
|
const node_child_process = require('node:child_process');
|
|
14
12
|
const node_util = require('node:util');
|
|
13
|
+
const makeDebugger = require('debug');
|
|
14
|
+
const localPkg = require('local-pkg');
|
|
15
15
|
const MagicString = require('magic-string');
|
|
16
16
|
const run = require('vite-plugin-run');
|
|
17
17
|
const utils = require('@hybridly/utils');
|
|
@@ -38,6 +38,41 @@ const iconsResolver__default = /*#__PURE__*/_interopDefaultCompat(iconsResolver)
|
|
|
38
38
|
const icons__default = /*#__PURE__*/_interopDefaultCompat(icons);
|
|
39
39
|
const vue__default = /*#__PURE__*/_interopDefaultCompat(vue);
|
|
40
40
|
|
|
41
|
+
let phpExecutable;
|
|
42
|
+
let devEnvironment;
|
|
43
|
+
function getEnv() {
|
|
44
|
+
return { ...process.env, ...vite.loadEnv("mock", process.cwd(), "") };
|
|
45
|
+
}
|
|
46
|
+
async function getPhpExecutable() {
|
|
47
|
+
if (phpExecutable) {
|
|
48
|
+
return phpExecutable;
|
|
49
|
+
}
|
|
50
|
+
const env = getEnv();
|
|
51
|
+
const php = (env.PHP_EXECUTABLE_PATH ?? "php").split(" ");
|
|
52
|
+
if (!env.PHP_EXECUTABLE_PATH) {
|
|
53
|
+
const devEnvironment2 = await determineDevEnvironment();
|
|
54
|
+
if (devEnvironment2 === "ddev") {
|
|
55
|
+
php.unshift("ddev");
|
|
56
|
+
} else if (devEnvironment2 === "lando") {
|
|
57
|
+
php.unshift("lando");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return phpExecutable = php;
|
|
61
|
+
}
|
|
62
|
+
async function determineDevEnvironment() {
|
|
63
|
+
if (devEnvironment) {
|
|
64
|
+
return devEnvironment;
|
|
65
|
+
}
|
|
66
|
+
if (fs__default.existsSync(`${process.cwd()}/.ddev`)) {
|
|
67
|
+
devEnvironment = "ddev";
|
|
68
|
+
} else if (fs__default.existsSync(`${process.cwd()}/.lando.yml`)) {
|
|
69
|
+
devEnvironment = "lando";
|
|
70
|
+
} else {
|
|
71
|
+
devEnvironment = "native";
|
|
72
|
+
}
|
|
73
|
+
return devEnvironment;
|
|
74
|
+
}
|
|
75
|
+
|
|
41
76
|
function isIpv6(address) {
|
|
42
77
|
return address.family === "IPv6" || address.family === 6;
|
|
43
78
|
}
|
|
@@ -164,12 +199,12 @@ function laravel(options, hybridlyConfig) {
|
|
|
164
199
|
configureServer(server) {
|
|
165
200
|
const envDir = resolvedConfig.envDir || process.cwd();
|
|
166
201
|
const appUrl = vite.loadEnv(resolvedConfig.mode, envDir, "APP_URL").APP_URL ?? "undefined";
|
|
167
|
-
server.httpServer?.once("listening", () => {
|
|
202
|
+
server.httpServer?.once("listening", async () => {
|
|
168
203
|
const address = server.httpServer?.address();
|
|
169
204
|
const isAddressInfo = (x) => typeof x === "object";
|
|
170
205
|
if (isAddressInfo(address)) {
|
|
171
206
|
viteDevServerUrl = resolveDevServerUrl(address, server.config, userConfig);
|
|
172
|
-
fs__default.writeFileSync(hotFile, viteDevServerUrl);
|
|
207
|
+
fs__default.writeFileSync(hotFile, `${viteDevServerUrl}${server.config.base.replace(/\/$/, "")}`);
|
|
173
208
|
if (!hybridlyConfig.versions) {
|
|
174
209
|
return;
|
|
175
210
|
}
|
|
@@ -181,12 +216,16 @@ function laravel(options, hybridlyConfig) {
|
|
|
181
216
|
let version = `${colors__default.yellow(`v${hybridlyConfig.versions.composer}`)} ${colors__default.dim("(composer)")}, `;
|
|
182
217
|
version += `${colors__default.yellow(`v${hybridlyConfig.versions.npm}`)} ${colors__default.dim("(npm)")}`;
|
|
183
218
|
version += ` \u2014 ${colors__default.yellow("this may lead to undefined behavior")}`;
|
|
219
|
+
const devEnvironment = await determineDevEnvironment();
|
|
184
220
|
setTimeout(() => {
|
|
185
221
|
server.config.logger.info(`
|
|
186
222
|
${colors__default.magenta(`${colors__default.bold("HYBRIDLY")} v${hybridlyConfig.versions.composer}`)} ${latest}`);
|
|
187
223
|
server.config.logger.info("");
|
|
188
224
|
server.config.logger.info(` ${colors__default.green("\u279C")} ${colors__default.bold("URL")}: ${colors__default.cyan(hybridlyConfig.routing.url)}`);
|
|
189
225
|
server.config.logger.info(` ${colors__default.green("\u279C")} ${colors__default.bold("Registered")}: ${registered}`);
|
|
226
|
+
if (devEnvironment !== "native") {
|
|
227
|
+
server.config.logger.info(` ${colors__default.green("\u279C")} ${colors__default.bold("Development environment")}: ${colors__default.cyan(devEnvironment)}`);
|
|
228
|
+
}
|
|
190
229
|
if (hybridlyConfig.versions.composer !== hybridlyConfig.versions.npm) {
|
|
191
230
|
server.config.logger.info(` ${colors__default.yellow("\u279C")} ${colors__default.bold("Version mismatch")}: ${version}`);
|
|
192
231
|
}
|
|
@@ -255,6 +294,7 @@ const CONFIG_PLUGIN_NAME = "vite:hybridly:config";
|
|
|
255
294
|
const CONFIG_VIRTUAL_MODULE_ID = "virtual:hybridly/config";
|
|
256
295
|
const RESOLVED_CONFIG_VIRTUAL_MODULE_ID = `\0${CONFIG_VIRTUAL_MODULE_ID}`;
|
|
257
296
|
|
|
297
|
+
const execSync = node_util.promisify(node_child_process.exec);
|
|
258
298
|
const debug = {
|
|
259
299
|
config: makeDebugger__default(CONFIG_PLUGIN_NAME),
|
|
260
300
|
layout: makeDebugger__default(LAYOUT_PLUGIN_NAME)
|
|
@@ -403,15 +443,18 @@ function write(data, filename) {
|
|
|
403
443
|
});
|
|
404
444
|
}
|
|
405
445
|
|
|
406
|
-
const execSync = node_util.promisify(node_child_process.exec);
|
|
407
446
|
async function loadConfiguration() {
|
|
408
447
|
try {
|
|
409
|
-
const
|
|
410
|
-
const php = env.PHP_EXECUTABLE_PATH ?? "php";
|
|
448
|
+
const php = (await getPhpExecutable()).join(" ");
|
|
411
449
|
const { stdout } = await execSync(`${php} artisan hybridly:config`);
|
|
412
450
|
return JSON.parse(stdout);
|
|
413
451
|
} catch (e) {
|
|
414
|
-
console.error("Could not load configuration from [php artisan].");
|
|
452
|
+
console.error("Could not load configuration from [php artisan hybridly:config].");
|
|
453
|
+
if (await determineDevEnvironment() === "ddev") {
|
|
454
|
+
console.error("This is possibly caused by not starting ddev first.");
|
|
455
|
+
} else if (await determineDevEnvironment() === "lando") {
|
|
456
|
+
console.error("This is possibly caused by not starting lando first.");
|
|
457
|
+
}
|
|
415
458
|
throw e;
|
|
416
459
|
}
|
|
417
460
|
}
|
|
@@ -559,15 +602,15 @@ function resolveLayoutImportPath(name, config) {
|
|
|
559
602
|
return `~/${path}`;
|
|
560
603
|
}
|
|
561
604
|
|
|
562
|
-
function getRunOptions(options) {
|
|
605
|
+
async function getRunOptions(options) {
|
|
563
606
|
if (options.run === false) {
|
|
564
607
|
return [];
|
|
565
608
|
}
|
|
566
|
-
const php =
|
|
609
|
+
const php = await getPhpExecutable();
|
|
567
610
|
return [
|
|
568
611
|
{
|
|
569
612
|
name: "Generate TypeScript types",
|
|
570
|
-
run: [php, "artisan", "hybridly:types", options.allowTypeGenerationFailures !== false ? "--allow-failures" : ""].filter(Boolean),
|
|
613
|
+
run: [...php, "artisan", "hybridly:types", options.allowTypeGenerationFailures !== false ? "--allow-failures" : ""].filter(Boolean),
|
|
571
614
|
pattern: [
|
|
572
615
|
"+(app|src)/**/*Data.php",
|
|
573
616
|
"+(app|src)/**/Enums/*.php",
|
|
@@ -576,7 +619,7 @@ function getRunOptions(options) {
|
|
|
576
619
|
},
|
|
577
620
|
{
|
|
578
621
|
name: "Generate i18n",
|
|
579
|
-
run: [php, "artisan", "hybridly:i18n"],
|
|
622
|
+
run: [...php, "artisan", "hybridly:i18n"],
|
|
580
623
|
pattern: "lang/**/*.php"
|
|
581
624
|
},
|
|
582
625
|
...options.run ?? []
|
|
@@ -900,7 +943,7 @@ async function plugin(options = {}) {
|
|
|
900
943
|
initialize(resolvedOptions, config),
|
|
901
944
|
layout(resolvedOptions, config),
|
|
902
945
|
resolvedOptions.laravel !== false && laravel(resolvedOptions, config),
|
|
903
|
-
resolvedOptions.run !== false && run__default(getRunOptions(resolvedOptions)),
|
|
946
|
+
resolvedOptions.run !== false && run__default(await getRunOptions(resolvedOptions)),
|
|
904
947
|
resolvedOptions.vueComponents !== false && vueComponents__default(await getVueComponentsOptions(resolvedOptions, config)),
|
|
905
948
|
resolvedOptions.autoImports !== false && autoimport__default(getAutoImportsOptions(resolvedOptions, config)),
|
|
906
949
|
resolvedOptions.icons !== false && icons__default(getIconsOptions(resolvedOptions, config)),
|
package/dist/index.mjs
CHANGED
|
@@ -4,10 +4,10 @@ import colors from 'picocolors';
|
|
|
4
4
|
import { loadEnv } from 'vite';
|
|
5
5
|
import 'node:url';
|
|
6
6
|
import os from 'node:os';
|
|
7
|
-
import makeDebugger from 'debug';
|
|
8
|
-
import { isPackageExists, resolveModule, importModule } from 'local-pkg';
|
|
9
7
|
import { exec } from 'node:child_process';
|
|
10
8
|
import { promisify } from 'node:util';
|
|
9
|
+
import makeDebugger from 'debug';
|
|
10
|
+
import { isPackageExists, resolveModule, importModule } from 'local-pkg';
|
|
11
11
|
import MagicString from 'magic-string';
|
|
12
12
|
import run from 'vite-plugin-run';
|
|
13
13
|
import { merge } from '@hybridly/utils';
|
|
@@ -19,6 +19,41 @@ import icons from 'unplugin-icons/vite';
|
|
|
19
19
|
import { FileSystemIconLoader } from 'unplugin-icons/loaders';
|
|
20
20
|
import vue from '@vitejs/plugin-vue';
|
|
21
21
|
|
|
22
|
+
let phpExecutable;
|
|
23
|
+
let devEnvironment;
|
|
24
|
+
function getEnv() {
|
|
25
|
+
return { ...process.env, ...loadEnv("mock", process.cwd(), "") };
|
|
26
|
+
}
|
|
27
|
+
async function getPhpExecutable() {
|
|
28
|
+
if (phpExecutable) {
|
|
29
|
+
return phpExecutable;
|
|
30
|
+
}
|
|
31
|
+
const env = getEnv();
|
|
32
|
+
const php = (env.PHP_EXECUTABLE_PATH ?? "php").split(" ");
|
|
33
|
+
if (!env.PHP_EXECUTABLE_PATH) {
|
|
34
|
+
const devEnvironment2 = await determineDevEnvironment();
|
|
35
|
+
if (devEnvironment2 === "ddev") {
|
|
36
|
+
php.unshift("ddev");
|
|
37
|
+
} else if (devEnvironment2 === "lando") {
|
|
38
|
+
php.unshift("lando");
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return phpExecutable = php;
|
|
42
|
+
}
|
|
43
|
+
async function determineDevEnvironment() {
|
|
44
|
+
if (devEnvironment) {
|
|
45
|
+
return devEnvironment;
|
|
46
|
+
}
|
|
47
|
+
if (fs.existsSync(`${process.cwd()}/.ddev`)) {
|
|
48
|
+
devEnvironment = "ddev";
|
|
49
|
+
} else if (fs.existsSync(`${process.cwd()}/.lando.yml`)) {
|
|
50
|
+
devEnvironment = "lando";
|
|
51
|
+
} else {
|
|
52
|
+
devEnvironment = "native";
|
|
53
|
+
}
|
|
54
|
+
return devEnvironment;
|
|
55
|
+
}
|
|
56
|
+
|
|
22
57
|
function isIpv6(address) {
|
|
23
58
|
return address.family === "IPv6" || address.family === 6;
|
|
24
59
|
}
|
|
@@ -145,12 +180,12 @@ function laravel(options, hybridlyConfig) {
|
|
|
145
180
|
configureServer(server) {
|
|
146
181
|
const envDir = resolvedConfig.envDir || process.cwd();
|
|
147
182
|
const appUrl = loadEnv(resolvedConfig.mode, envDir, "APP_URL").APP_URL ?? "undefined";
|
|
148
|
-
server.httpServer?.once("listening", () => {
|
|
183
|
+
server.httpServer?.once("listening", async () => {
|
|
149
184
|
const address = server.httpServer?.address();
|
|
150
185
|
const isAddressInfo = (x) => typeof x === "object";
|
|
151
186
|
if (isAddressInfo(address)) {
|
|
152
187
|
viteDevServerUrl = resolveDevServerUrl(address, server.config, userConfig);
|
|
153
|
-
fs.writeFileSync(hotFile, viteDevServerUrl);
|
|
188
|
+
fs.writeFileSync(hotFile, `${viteDevServerUrl}${server.config.base.replace(/\/$/, "")}`);
|
|
154
189
|
if (!hybridlyConfig.versions) {
|
|
155
190
|
return;
|
|
156
191
|
}
|
|
@@ -162,12 +197,16 @@ function laravel(options, hybridlyConfig) {
|
|
|
162
197
|
let version = `${colors.yellow(`v${hybridlyConfig.versions.composer}`)} ${colors.dim("(composer)")}, `;
|
|
163
198
|
version += `${colors.yellow(`v${hybridlyConfig.versions.npm}`)} ${colors.dim("(npm)")}`;
|
|
164
199
|
version += ` \u2014 ${colors.yellow("this may lead to undefined behavior")}`;
|
|
200
|
+
const devEnvironment = await determineDevEnvironment();
|
|
165
201
|
setTimeout(() => {
|
|
166
202
|
server.config.logger.info(`
|
|
167
203
|
${colors.magenta(`${colors.bold("HYBRIDLY")} v${hybridlyConfig.versions.composer}`)} ${latest}`);
|
|
168
204
|
server.config.logger.info("");
|
|
169
205
|
server.config.logger.info(` ${colors.green("\u279C")} ${colors.bold("URL")}: ${colors.cyan(hybridlyConfig.routing.url)}`);
|
|
170
206
|
server.config.logger.info(` ${colors.green("\u279C")} ${colors.bold("Registered")}: ${registered}`);
|
|
207
|
+
if (devEnvironment !== "native") {
|
|
208
|
+
server.config.logger.info(` ${colors.green("\u279C")} ${colors.bold("Development environment")}: ${colors.cyan(devEnvironment)}`);
|
|
209
|
+
}
|
|
171
210
|
if (hybridlyConfig.versions.composer !== hybridlyConfig.versions.npm) {
|
|
172
211
|
server.config.logger.info(` ${colors.yellow("\u279C")} ${colors.bold("Version mismatch")}: ${version}`);
|
|
173
212
|
}
|
|
@@ -236,6 +275,7 @@ const CONFIG_PLUGIN_NAME = "vite:hybridly:config";
|
|
|
236
275
|
const CONFIG_VIRTUAL_MODULE_ID = "virtual:hybridly/config";
|
|
237
276
|
const RESOLVED_CONFIG_VIRTUAL_MODULE_ID = `\0${CONFIG_VIRTUAL_MODULE_ID}`;
|
|
238
277
|
|
|
278
|
+
const execSync = promisify(exec);
|
|
239
279
|
const debug = {
|
|
240
280
|
config: makeDebugger(CONFIG_PLUGIN_NAME),
|
|
241
281
|
layout: makeDebugger(LAYOUT_PLUGIN_NAME)
|
|
@@ -384,15 +424,18 @@ function write(data, filename) {
|
|
|
384
424
|
});
|
|
385
425
|
}
|
|
386
426
|
|
|
387
|
-
const execSync = promisify(exec);
|
|
388
427
|
async function loadConfiguration() {
|
|
389
428
|
try {
|
|
390
|
-
const
|
|
391
|
-
const php = env.PHP_EXECUTABLE_PATH ?? "php";
|
|
429
|
+
const php = (await getPhpExecutable()).join(" ");
|
|
392
430
|
const { stdout } = await execSync(`${php} artisan hybridly:config`);
|
|
393
431
|
return JSON.parse(stdout);
|
|
394
432
|
} catch (e) {
|
|
395
|
-
console.error("Could not load configuration from [php artisan].");
|
|
433
|
+
console.error("Could not load configuration from [php artisan hybridly:config].");
|
|
434
|
+
if (await determineDevEnvironment() === "ddev") {
|
|
435
|
+
console.error("This is possibly caused by not starting ddev first.");
|
|
436
|
+
} else if (await determineDevEnvironment() === "lando") {
|
|
437
|
+
console.error("This is possibly caused by not starting lando first.");
|
|
438
|
+
}
|
|
396
439
|
throw e;
|
|
397
440
|
}
|
|
398
441
|
}
|
|
@@ -540,15 +583,15 @@ function resolveLayoutImportPath(name, config) {
|
|
|
540
583
|
return `~/${path}`;
|
|
541
584
|
}
|
|
542
585
|
|
|
543
|
-
function getRunOptions(options) {
|
|
586
|
+
async function getRunOptions(options) {
|
|
544
587
|
if (options.run === false) {
|
|
545
588
|
return [];
|
|
546
589
|
}
|
|
547
|
-
const php =
|
|
590
|
+
const php = await getPhpExecutable();
|
|
548
591
|
return [
|
|
549
592
|
{
|
|
550
593
|
name: "Generate TypeScript types",
|
|
551
|
-
run: [php, "artisan", "hybridly:types", options.allowTypeGenerationFailures !== false ? "--allow-failures" : ""].filter(Boolean),
|
|
594
|
+
run: [...php, "artisan", "hybridly:types", options.allowTypeGenerationFailures !== false ? "--allow-failures" : ""].filter(Boolean),
|
|
552
595
|
pattern: [
|
|
553
596
|
"+(app|src)/**/*Data.php",
|
|
554
597
|
"+(app|src)/**/Enums/*.php",
|
|
@@ -557,7 +600,7 @@ function getRunOptions(options) {
|
|
|
557
600
|
},
|
|
558
601
|
{
|
|
559
602
|
name: "Generate i18n",
|
|
560
|
-
run: [php, "artisan", "hybridly:i18n"],
|
|
603
|
+
run: [...php, "artisan", "hybridly:i18n"],
|
|
561
604
|
pattern: "lang/**/*.php"
|
|
562
605
|
},
|
|
563
606
|
...options.run ?? []
|
|
@@ -881,7 +924,7 @@ async function plugin(options = {}) {
|
|
|
881
924
|
initialize(resolvedOptions, config),
|
|
882
925
|
layout(resolvedOptions, config),
|
|
883
926
|
resolvedOptions.laravel !== false && laravel(resolvedOptions, config),
|
|
884
|
-
resolvedOptions.run !== false && run(getRunOptions(resolvedOptions)),
|
|
927
|
+
resolvedOptions.run !== false && run(await getRunOptions(resolvedOptions)),
|
|
885
928
|
resolvedOptions.vueComponents !== false && vueComponents(await getVueComponentsOptions(resolvedOptions, config)),
|
|
886
929
|
resolvedOptions.autoImports !== false && autoimport(getAutoImportsOptions(resolvedOptions, config)),
|
|
887
930
|
resolvedOptions.icons !== false && icons(getIconsOptions(resolvedOptions, config)),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hybridly/vite",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.8",
|
|
4
4
|
"description": "Vite plugin for Hybridly",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"hybridly",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"unplugin-icons": "^0.18.5",
|
|
56
56
|
"unplugin-vue-components": "^0.26.0",
|
|
57
57
|
"vite-plugin-run": "^0.5.1",
|
|
58
|
-
"@hybridly/core": "0.7.
|
|
58
|
+
"@hybridly/core": "0.7.8"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@iconify/json": "^2.2.203",
|