@hybridly/vite 0.5.5 → 0.5.7

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 CHANGED
@@ -8,6 +8,7 @@ const fs = require('node:fs');
8
8
  const makeDebugger = require('debug');
9
9
  const localPkg = require('local-pkg');
10
10
  const node_child_process = require('node:child_process');
11
+ const MagicString = require('magic-string');
11
12
  const run = require('vite-plugin-run');
12
13
  const utils = require('@hybridly/utils');
13
14
  const autoimport = require('unplugin-auto-import/vite');
@@ -24,6 +25,7 @@ const laravel__default = /*#__PURE__*/_interopDefaultCompat(laravel);
24
25
  const path__default = /*#__PURE__*/_interopDefaultCompat(path);
25
26
  const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
26
27
  const makeDebugger__default = /*#__PURE__*/_interopDefaultCompat(makeDebugger);
28
+ const MagicString__default = /*#__PURE__*/_interopDefaultCompat(MagicString);
27
29
  const run__default = /*#__PURE__*/_interopDefaultCompat(run);
28
30
  const autoimport__default = /*#__PURE__*/_interopDefaultCompat(autoimport);
29
31
  const vueComponents__default = /*#__PURE__*/_interopDefaultCompat(vueComponents);
@@ -43,6 +45,14 @@ const debug = {
43
45
  function isPackageInstalled(name, paths = [process.cwd()]) {
44
46
  return localPkg.isPackageExists(name, { paths });
45
47
  }
48
+ function importPackage(name, paths = [process.cwd()]) {
49
+ const mod = localPkg.resolveModule(name, { paths });
50
+ if (!mod) {
51
+ console.warn(`Could not resolve package [${name}]`);
52
+ return;
53
+ }
54
+ return localPkg.importModule(mod);
55
+ }
46
56
  function toKebabCase(key) {
47
57
  const result = key.replace(/([A-Z])/g, " $1").trim();
48
58
  return result.split(" ").join("-").toLowerCase();
@@ -284,7 +294,8 @@ const layout = (options, config) => {
284
294
  if (!templateRegExp.test(code)) {
285
295
  return;
286
296
  }
287
- return code.replace(templateRegExp, (_, layoutName) => {
297
+ const source = new MagicString__default(code);
298
+ const updatedCode = source.replace(templateRegExp, (_, layoutName) => {
288
299
  const isTypeScript = TYPESCRIPT_REGEX.test(code);
289
300
  const layouts = layoutName?.toString()?.replaceAll(" ", "").split(",") ?? [defaultLayoutName];
290
301
  const importName = (i) => `__hybridly_layout_${i}`;
@@ -306,6 +317,10 @@ const layout = (options, config) => {
306
317
  <template>
307
318
  `;
308
319
  });
320
+ return {
321
+ map: updatedCode.generateMap(),
322
+ code: updatedCode.toString()
323
+ };
309
324
  }
310
325
  };
311
326
  };
@@ -364,7 +379,8 @@ const HybridlyImports = {
364
379
  "defineLayout",
365
380
  "defineLayoutProperties",
366
381
  "registerHook",
367
- "useRoute"
382
+ "useRoute",
383
+ "useQueryParameters"
368
384
  ],
369
385
  "hybridly": [
370
386
  "router",
@@ -376,7 +392,7 @@ function getAutoImportsOptions(options, config) {
376
392
  if (options.autoImports === false) {
377
393
  return;
378
394
  }
379
- const presets = ["@vueuse/core", "@vueuse/head", "vue-i18n"];
395
+ const presets = ["@vueuse/core", "vue-i18n"];
380
396
  const custom = {
381
397
  "@unhead/vue": [
382
398
  "useHead",
@@ -411,21 +427,7 @@ function getAutoImportsOptions(options, config) {
411
427
  );
412
428
  }
413
429
 
414
- function HybridlyResolver(linkName = "RouterLink") {
415
- return {
416
- type: "component",
417
- resolve: (name) => {
418
- if (name === linkName) {
419
- return {
420
- from: "hybridly/vue",
421
- name: "RouterLink",
422
- as: linkName
423
- };
424
- }
425
- }
426
- };
427
- }
428
- function getVueComponentsOptions(options, config) {
430
+ async function getVueComponentsOptions(options, config) {
429
431
  if (options.vueComponents === false) {
430
432
  return {};
431
433
  }
@@ -433,6 +435,7 @@ function getVueComponentsOptions(options, config) {
433
435
  const customCollections = Array.isArray(options.customIcons) ? options.customIcons : options.customIcons?.collections ?? [];
434
436
  const overrideResolvers = options.overrideResolvers ? Array.isArray(options.overrideResolvers) ? options.overrideResolvers : [options.overrideResolvers] : false;
435
437
  const hasHeadlessUI = isPackageInstalled("@headlessui/vue");
438
+ const hasRadix = isPackageInstalled("radix-vue");
436
439
  return utils.merge(
437
440
  {
438
441
  dirs: [
@@ -443,6 +446,7 @@ function getVueComponentsOptions(options, config) {
443
446
  resolvers: overrideResolvers || [
444
447
  ...hasIcons ? [iconsResolver__default({ customCollections })] : [],
445
448
  ...hasHeadlessUI ? [resolvers.HeadlessUiResolver({ prefix: options?.vueComponents?.headlessUiPrefix ?? "Headless" })] : [],
449
+ ...hasRadix ? [await RadixResolver(options?.vueComponents?.radixPrefix)] : [],
446
450
  ProvidedComponentListResolver(config),
447
451
  HybridlyResolver(options.vueComponents?.linkName)
448
452
  ]
@@ -451,6 +455,24 @@ function getVueComponentsOptions(options, config) {
451
455
  { overwriteArray: false }
452
456
  );
453
457
  }
458
+ async function RadixResolver(prefix = "Radix") {
459
+ const radix = await importPackage("radix-vue/resolver");
460
+ return radix.default({ prefix });
461
+ }
462
+ function HybridlyResolver(linkName = "RouterLink") {
463
+ return {
464
+ type: "component",
465
+ resolve: (name) => {
466
+ if (name === linkName) {
467
+ return {
468
+ from: "hybridly/vue",
469
+ name: "RouterLink",
470
+ as: linkName
471
+ };
472
+ }
473
+ }
474
+ };
475
+ }
454
476
  function ProvidedComponentListResolver(config) {
455
477
  function resolveComponentPath(name) {
456
478
  const kebabName = toKebabCase(name);
@@ -547,7 +569,7 @@ async function plugin(options = {}) {
547
569
  layout(options, config),
548
570
  options.laravel !== false && laravel__default(getLaravelOptions(options, config)),
549
571
  options.run !== false && run__default(getRunOptions(options)),
550
- options.vueComponents !== false && vueComponents__default(getVueComponentsOptions(options, config)),
572
+ options.vueComponents !== false && vueComponents__default(await getVueComponentsOptions(options, config)),
551
573
  options.autoImports !== false && autoimport__default(getAutoImportsOptions(options, config)),
552
574
  options.icons !== false && icons__default(getIconsOptions(options, config)),
553
575
  options.vue !== false && vue__default(getVueOptions(options)),
package/dist/index.d.cts CHANGED
@@ -31,6 +31,8 @@ type VueComponentsOptions = Parameters<typeof vueComponents>[0] & {
31
31
  linkName?: string;
32
32
  /** Custom prefix for Headless UI components. */
33
33
  headlessUiPrefix?: string;
34
+ /** Custom prefix for Radix components. */
35
+ radixPrefix?: string;
34
36
  };
35
37
  type CustomResolvers = ComponentResolver | ComponentResolver[];
36
38
  type CustomComponentsOptions = VueComponentsOptions;
package/dist/index.d.mts CHANGED
@@ -31,6 +31,8 @@ type VueComponentsOptions = Parameters<typeof vueComponents>[0] & {
31
31
  linkName?: string;
32
32
  /** Custom prefix for Headless UI components. */
33
33
  headlessUiPrefix?: string;
34
+ /** Custom prefix for Radix components. */
35
+ radixPrefix?: string;
34
36
  };
35
37
  type CustomResolvers = ComponentResolver | ComponentResolver[];
36
38
  type CustomComponentsOptions = VueComponentsOptions;
package/dist/index.d.ts CHANGED
@@ -31,6 +31,8 @@ type VueComponentsOptions = Parameters<typeof vueComponents>[0] & {
31
31
  linkName?: string;
32
32
  /** Custom prefix for Headless UI components. */
33
33
  headlessUiPrefix?: string;
34
+ /** Custom prefix for Radix components. */
35
+ radixPrefix?: string;
34
36
  };
35
37
  type CustomResolvers = ComponentResolver | ComponentResolver[];
36
38
  type CustomComponentsOptions = VueComponentsOptions;
package/dist/index.mjs CHANGED
@@ -2,8 +2,9 @@ import laravel from 'laravel-vite-plugin';
2
2
  import path from 'node:path';
3
3
  import fs from 'node:fs';
4
4
  import makeDebugger from 'debug';
5
- import { isPackageExists } from 'local-pkg';
5
+ import { isPackageExists, resolveModule, importModule } from 'local-pkg';
6
6
  import { execSync } from 'node:child_process';
7
+ import MagicString from 'magic-string';
7
8
  import run from 'vite-plugin-run';
8
9
  import { merge } from '@hybridly/utils';
9
10
  import autoimport from 'unplugin-auto-import/vite';
@@ -26,6 +27,14 @@ const debug = {
26
27
  function isPackageInstalled(name, paths = [process.cwd()]) {
27
28
  return isPackageExists(name, { paths });
28
29
  }
30
+ function importPackage(name, paths = [process.cwd()]) {
31
+ const mod = resolveModule(name, { paths });
32
+ if (!mod) {
33
+ console.warn(`Could not resolve package [${name}]`);
34
+ return;
35
+ }
36
+ return importModule(mod);
37
+ }
29
38
  function toKebabCase(key) {
30
39
  const result = key.replace(/([A-Z])/g, " $1").trim();
31
40
  return result.split(" ").join("-").toLowerCase();
@@ -267,7 +276,8 @@ const layout = (options, config) => {
267
276
  if (!templateRegExp.test(code)) {
268
277
  return;
269
278
  }
270
- return code.replace(templateRegExp, (_, layoutName) => {
279
+ const source = new MagicString(code);
280
+ const updatedCode = source.replace(templateRegExp, (_, layoutName) => {
271
281
  const isTypeScript = TYPESCRIPT_REGEX.test(code);
272
282
  const layouts = layoutName?.toString()?.replaceAll(" ", "").split(",") ?? [defaultLayoutName];
273
283
  const importName = (i) => `__hybridly_layout_${i}`;
@@ -289,6 +299,10 @@ const layout = (options, config) => {
289
299
  <template>
290
300
  `;
291
301
  });
302
+ return {
303
+ map: updatedCode.generateMap(),
304
+ code: updatedCode.toString()
305
+ };
292
306
  }
293
307
  };
294
308
  };
@@ -347,7 +361,8 @@ const HybridlyImports = {
347
361
  "defineLayout",
348
362
  "defineLayoutProperties",
349
363
  "registerHook",
350
- "useRoute"
364
+ "useRoute",
365
+ "useQueryParameters"
351
366
  ],
352
367
  "hybridly": [
353
368
  "router",
@@ -359,7 +374,7 @@ function getAutoImportsOptions(options, config) {
359
374
  if (options.autoImports === false) {
360
375
  return;
361
376
  }
362
- const presets = ["@vueuse/core", "@vueuse/head", "vue-i18n"];
377
+ const presets = ["@vueuse/core", "vue-i18n"];
363
378
  const custom = {
364
379
  "@unhead/vue": [
365
380
  "useHead",
@@ -394,21 +409,7 @@ function getAutoImportsOptions(options, config) {
394
409
  );
395
410
  }
396
411
 
397
- function HybridlyResolver(linkName = "RouterLink") {
398
- return {
399
- type: "component",
400
- resolve: (name) => {
401
- if (name === linkName) {
402
- return {
403
- from: "hybridly/vue",
404
- name: "RouterLink",
405
- as: linkName
406
- };
407
- }
408
- }
409
- };
410
- }
411
- function getVueComponentsOptions(options, config) {
412
+ async function getVueComponentsOptions(options, config) {
412
413
  if (options.vueComponents === false) {
413
414
  return {};
414
415
  }
@@ -416,6 +417,7 @@ function getVueComponentsOptions(options, config) {
416
417
  const customCollections = Array.isArray(options.customIcons) ? options.customIcons : options.customIcons?.collections ?? [];
417
418
  const overrideResolvers = options.overrideResolvers ? Array.isArray(options.overrideResolvers) ? options.overrideResolvers : [options.overrideResolvers] : false;
418
419
  const hasHeadlessUI = isPackageInstalled("@headlessui/vue");
420
+ const hasRadix = isPackageInstalled("radix-vue");
419
421
  return merge(
420
422
  {
421
423
  dirs: [
@@ -426,6 +428,7 @@ function getVueComponentsOptions(options, config) {
426
428
  resolvers: overrideResolvers || [
427
429
  ...hasIcons ? [iconsResolver({ customCollections })] : [],
428
430
  ...hasHeadlessUI ? [HeadlessUiResolver({ prefix: options?.vueComponents?.headlessUiPrefix ?? "Headless" })] : [],
431
+ ...hasRadix ? [await RadixResolver(options?.vueComponents?.radixPrefix)] : [],
429
432
  ProvidedComponentListResolver(config),
430
433
  HybridlyResolver(options.vueComponents?.linkName)
431
434
  ]
@@ -434,6 +437,24 @@ function getVueComponentsOptions(options, config) {
434
437
  { overwriteArray: false }
435
438
  );
436
439
  }
440
+ async function RadixResolver(prefix = "Radix") {
441
+ const radix = await importPackage("radix-vue/resolver");
442
+ return radix.default({ prefix });
443
+ }
444
+ function HybridlyResolver(linkName = "RouterLink") {
445
+ return {
446
+ type: "component",
447
+ resolve: (name) => {
448
+ if (name === linkName) {
449
+ return {
450
+ from: "hybridly/vue",
451
+ name: "RouterLink",
452
+ as: linkName
453
+ };
454
+ }
455
+ }
456
+ };
457
+ }
437
458
  function ProvidedComponentListResolver(config) {
438
459
  function resolveComponentPath(name) {
439
460
  const kebabName = toKebabCase(name);
@@ -530,7 +551,7 @@ async function plugin(options = {}) {
530
551
  layout(options, config),
531
552
  options.laravel !== false && laravel(getLaravelOptions(options, config)),
532
553
  options.run !== false && run(getRunOptions(options)),
533
- options.vueComponents !== false && vueComponents(getVueComponentsOptions(options, config)),
554
+ options.vueComponents !== false && vueComponents(await getVueComponentsOptions(options, config)),
534
555
  options.autoImports !== false && autoimport(getAutoImportsOptions(options, config)),
535
556
  options.icons !== false && icons(getIconsOptions(options, config)),
536
557
  options.vue !== false && vue(getVueOptions(options)),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hybridly/vite",
3
- "version": "0.5.5",
3
+ "version": "0.5.7",
4
4
  "description": "Vite plugin for Hybridly",
5
5
  "keywords": [
6
6
  "hybridly",
@@ -40,22 +40,23 @@
40
40
  "vue": "^3.2.45"
41
41
  },
42
42
  "dependencies": {
43
- "@vitejs/plugin-vue": "^4.3.4",
43
+ "@vitejs/plugin-vue": "^4.4.0",
44
44
  "fast-glob": "^3.3.1",
45
45
  "laravel-vite-plugin": "^0.8.1",
46
46
  "local-pkg": "^0.4.3",
47
+ "magic-string": "^0.30.5",
47
48
  "throttle-debounce": "^5.0.0",
48
49
  "unplugin-auto-import": "^0.16.6",
49
- "unplugin-icons": "^0.17.0",
50
+ "unplugin-icons": "^0.17.1",
50
51
  "unplugin-vue-components": "^0.25.2",
51
52
  "vite-plugin-run": "^0.5.1",
52
- "@hybridly/core": "0.5.5"
53
+ "@hybridly/core": "0.5.7"
53
54
  },
54
55
  "devDependencies": {
55
- "@iconify/json": "^2.2.120",
56
- "rollup": "^3.29.3",
57
- "vite": "^4.4.9",
58
- "vue": "^3.3.4"
56
+ "@iconify/json": "^2.2.133",
57
+ "rollup": "^3.29.4",
58
+ "vite": "^4.5.0",
59
+ "vue": "^3.3.7"
59
60
  },
60
61
  "scripts": {
61
62
  "build": "unbuild",