@serwist/vite 8.4.4 → 9.0.0-preview.1

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.
Files changed (66) hide show
  1. package/dist/api.d.ts +1 -0
  2. package/dist/api.d.ts.map +1 -0
  3. package/dist/assets.d.ts +1 -0
  4. package/dist/assets.d.ts.map +1 -0
  5. package/dist/constants.d.ts +1 -0
  6. package/dist/constants.d.ts.map +1 -0
  7. package/dist/context.d.ts +1 -0
  8. package/dist/context.d.ts.map +1 -0
  9. package/dist/index.browser.d.ts +1 -0
  10. package/dist/index.browser.d.ts.map +1 -0
  11. package/dist/index.d.ts +1 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +2 -12
  14. package/dist/index.worker.d.ts +2 -1
  15. package/dist/index.worker.d.ts.map +1 -0
  16. package/dist/integration/svelte/build.d.ts +1 -0
  17. package/dist/integration/svelte/build.d.ts.map +1 -0
  18. package/dist/integration/svelte/config.d.ts +1 -0
  19. package/dist/integration/svelte/config.d.ts.map +1 -0
  20. package/dist/integration/svelte/index.d.ts +1 -0
  21. package/dist/integration/svelte/index.d.ts.map +1 -0
  22. package/dist/integration/svelte/index.js +1 -19
  23. package/dist/integration/svelte/types.d.ts +1 -0
  24. package/dist/integration/svelte/types.d.ts.map +1 -0
  25. package/dist/log.d.ts +1 -0
  26. package/dist/log.d.ts.map +1 -0
  27. package/dist/main.js +15 -87
  28. package/dist/modules.d.ts +1 -0
  29. package/dist/modules.d.ts.map +1 -0
  30. package/dist/options.d.ts +1 -0
  31. package/dist/options.d.ts.map +1 -0
  32. package/dist/plugins/build.d.ts +1 -0
  33. package/dist/plugins/build.d.ts.map +1 -0
  34. package/dist/plugins/dev.d.ts +1 -0
  35. package/dist/plugins/dev.d.ts.map +1 -0
  36. package/dist/plugins/main.d.ts +1 -0
  37. package/dist/plugins/main.d.ts.map +1 -0
  38. package/dist/types.d.ts +1 -0
  39. package/dist/types.d.ts.map +1 -0
  40. package/dist/utils-types.d.ts +1 -0
  41. package/dist/utils-types.d.ts.map +1 -0
  42. package/dist/utils.d.ts +2 -1
  43. package/dist/utils.d.ts.map +1 -0
  44. package/package.json +38 -34
  45. package/src/api.ts +38 -0
  46. package/src/assets.ts +76 -0
  47. package/src/constants.ts +2 -0
  48. package/src/context.ts +45 -0
  49. package/src/index.browser.ts +8 -0
  50. package/src/index.ts +25 -0
  51. package/src/index.worker.ts +95 -0
  52. package/src/integration/svelte/build.ts +21 -0
  53. package/src/integration/svelte/config.ts +141 -0
  54. package/src/integration/svelte/index.ts +27 -0
  55. package/src/integration/svelte/types.ts +26 -0
  56. package/src/log.ts +25 -0
  57. package/src/modules.ts +174 -0
  58. package/src/options.ts +90 -0
  59. package/src/plugins/build.ts +31 -0
  60. package/src/plugins/dev.ts +61 -0
  61. package/src/plugins/main.ts +49 -0
  62. package/src/rollup.js +46 -0
  63. package/src/types.ts +207 -0
  64. package/src/utils-types.ts +1 -0
  65. package/src/utils.ts +69 -0
  66. package/src/virtual.d.ts +5 -0
package/src/utils.ts ADDED
@@ -0,0 +1,69 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+
4
+ export const slash = (str: string) => {
5
+ return str.replace(/\\/g, "/");
6
+ };
7
+
8
+ export const resolveBasePath = (base: string) => {
9
+ if (isAbsolute(base)) return base;
10
+ return !base.startsWith("/") && !base.startsWith("./") ? `/${base}` : base;
11
+ };
12
+
13
+ export const isAbsolute = (url: string) => {
14
+ return url.match(/^(?:[a-z]+:)?\/\//i);
15
+ };
16
+
17
+ export const normalizePath = (path: string) => {
18
+ return path.replace(/\\/g, "/");
19
+ };
20
+
21
+ // Source: https://github.com/sveltejs/kit/blob/6419d3eaa7bf1b0a756b28f06a73f71fe042de0a/packages/kit/src/utils/filesystem.js
22
+ // License: MIT
23
+ /**
24
+ * Internal function used by `@serwist/vite`.
25
+ * Resolves a file path without extension. Also handles `/index` if the path
26
+ * actually points to a directory.
27
+ * @internal
28
+ * @param ctx
29
+ * @param api
30
+ * @returns
31
+ */
32
+ export const resolveEntry = (entry: string): string | null => {
33
+ if (fs.existsSync(entry)) {
34
+ const stats = fs.statSync(entry);
35
+ if (stats.isDirectory()) {
36
+ return resolveEntry(path.join(entry, "index"));
37
+ }
38
+
39
+ return entry;
40
+ }
41
+ const dir = path.dirname(entry);
42
+
43
+ if (fs.existsSync(dir)) {
44
+ const base = path.basename(entry);
45
+ const files = fs.readdirSync(dir);
46
+
47
+ const found = files.find((file) => file.replace(/\.[^.]+$/, "") === base);
48
+
49
+ if (found) return path.join(dir, found);
50
+ }
51
+
52
+ return null;
53
+ };
54
+
55
+ // Source: https://github.com/sveltejs/kit/blob/6419d3eaa7bf1b0a756b28f06a73f71fe042de0a/packages/kit/src/utils/filesystem.js
56
+ // License: MIT
57
+ /**
58
+ * Internal function used by `@serwist/vite`.
59
+ * Converts a filesystem path to a Vite `@fs` URL.
60
+ * @internal
61
+ * @param ctx
62
+ * @param api
63
+ * @returns
64
+ */
65
+ export const toFs = (str: string) => {
66
+ str = str.replace(/\\/g, "/");
67
+ // Windows/Linux separation - Windows starts with a drive letter, we need a / in front there
68
+ return `/@fs${str.startsWith("/") ? "" : "/"}${str}`;
69
+ };
@@ -0,0 +1,5 @@
1
+ declare module "virtual:internal-serwist" {
2
+ export const swUrl: string;
3
+ export const swScope: string;
4
+ export const swType: WorkerType;
5
+ }