@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.
- package/dist/api.d.ts +1 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/assets.d.ts +1 -0
- package/dist/assets.d.ts.map +1 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/context.d.ts +1 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/index.browser.d.ts +1 -0
- package/dist/index.browser.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -12
- package/dist/index.worker.d.ts +2 -1
- package/dist/index.worker.d.ts.map +1 -0
- package/dist/integration/svelte/build.d.ts +1 -0
- package/dist/integration/svelte/build.d.ts.map +1 -0
- package/dist/integration/svelte/config.d.ts +1 -0
- package/dist/integration/svelte/config.d.ts.map +1 -0
- package/dist/integration/svelte/index.d.ts +1 -0
- package/dist/integration/svelte/index.d.ts.map +1 -0
- package/dist/integration/svelte/index.js +1 -19
- package/dist/integration/svelte/types.d.ts +1 -0
- package/dist/integration/svelte/types.d.ts.map +1 -0
- package/dist/log.d.ts +1 -0
- package/dist/log.d.ts.map +1 -0
- package/dist/main.js +15 -87
- package/dist/modules.d.ts +1 -0
- package/dist/modules.d.ts.map +1 -0
- package/dist/options.d.ts +1 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/plugins/build.d.ts +1 -0
- package/dist/plugins/build.d.ts.map +1 -0
- package/dist/plugins/dev.d.ts +1 -0
- package/dist/plugins/dev.d.ts.map +1 -0
- package/dist/plugins/main.d.ts +1 -0
- package/dist/plugins/main.d.ts.map +1 -0
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils-types.d.ts +1 -0
- package/dist/utils-types.d.ts.map +1 -0
- package/dist/utils.d.ts +2 -1
- package/dist/utils.d.ts.map +1 -0
- package/package.json +38 -34
- package/src/api.ts +38 -0
- package/src/assets.ts +76 -0
- package/src/constants.ts +2 -0
- package/src/context.ts +45 -0
- package/src/index.browser.ts +8 -0
- package/src/index.ts +25 -0
- package/src/index.worker.ts +95 -0
- package/src/integration/svelte/build.ts +21 -0
- package/src/integration/svelte/config.ts +141 -0
- package/src/integration/svelte/index.ts +27 -0
- package/src/integration/svelte/types.ts +26 -0
- package/src/log.ts +25 -0
- package/src/modules.ts +174 -0
- package/src/options.ts +90 -0
- package/src/plugins/build.ts +31 -0
- package/src/plugins/dev.ts +61 -0
- package/src/plugins/main.ts +49 -0
- package/src/rollup.js +46 -0
- package/src/types.ts +207 -0
- package/src/utils-types.ts +1 -0
- package/src/utils.ts +69 -0
- 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
|
+
};
|