@vite-hub/workspace 0.0.0 → 0.0.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/README.md +89 -1
- package/dist/ai-Bk3LLnit.js +352 -0
- package/dist/ai.d.ts +86 -0
- package/dist/ai.js +2 -0
- package/dist/asset-registry-CMuQbyvl.js +14 -0
- package/dist/chunk-DrSxFLj_.js +14 -0
- package/dist/cloudflare-env-DL94Uvpz.js +12 -0
- package/dist/config-CvS-7sre.js +49 -0
- package/dist/errors-BUL8SoFS.js +21 -0
- package/dist/files-DbsIjBya.js +50 -0
- package/dist/index.d.ts +150 -0
- package/dist/index.js +656 -0
- package/dist/lifecycle-uD82JeGh.js +92 -0
- package/dist/loader.d.ts +17 -0
- package/dist/loader.js +22 -0
- package/dist/module-8LZUMEXC.js +922 -0
- package/dist/nitro.d.ts +31 -0
- package/dist/nitro.js +2 -0
- package/dist/path-BVv9OXhg.js +63 -0
- package/dist/provider-BZuKAV4e.js +494 -0
- package/dist/providers/cloudflare/artifacts-store.d.ts +6 -0
- package/dist/providers/cloudflare/artifacts-store.js +384 -0
- package/dist/providers/vercel/blob-store.d.ts +6 -0
- package/dist/providers/vercel/blob-store.js +176 -0
- package/dist/publish.d.ts +34 -0
- package/dist/publish.js +206 -0
- package/dist/registry-Cnr0NoKv.js +932 -0
- package/dist/registry-D4Qzq26I.d.ts +10 -0
- package/dist/runtime/assets.d.ts +11 -0
- package/dist/runtime/assets.js +138 -0
- package/dist/runtime/empty-assets-registry.d.ts +6 -0
- package/dist/runtime/empty-assets-registry.js +4 -0
- package/dist/runtime/empty-registry.d.ts +6 -0
- package/dist/runtime/empty-registry.js +4 -0
- package/dist/runtime/nitro-plugin.d.ts +6 -0
- package/dist/runtime/nitro-plugin.js +14 -0
- package/dist/runtime/state.d.ts +21 -0
- package/dist/runtime/state.js +12 -0
- package/dist/sandbox-DtGXCWRq.js +198 -0
- package/dist/search-DtaEyjpO.js +39 -0
- package/dist/test.d.ts +2 -0
- package/dist/test.js +2 -0
- package/dist/types-CwNcWTdt.d.ts +378 -0
- package/dist/utils-BtAm_K5P.js +51 -0
- package/dist/vite.d.ts +22 -0
- package/dist/vite.js +131 -0
- package/package.json +101 -5
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { t as __exportAll } from "./chunk-DrSxFLj_.js";
|
|
2
|
+
import { o as normalizeWorkspacePath } from "./path-BVv9OXhg.js";
|
|
3
|
+
import { r as normalizeWorkspaceSources, t as createSourceContext } from "./config-CvS-7sre.js";
|
|
4
|
+
import { t as files } from "./files-DbsIjBya.js";
|
|
5
|
+
//#region src/lifecycle.ts
|
|
6
|
+
var lifecycle_exports = /* @__PURE__ */ __exportAll({
|
|
7
|
+
publishWorkspaceSnapshot: () => publishWorkspaceSnapshot,
|
|
8
|
+
syncWorkspaceDefinition: () => syncWorkspaceDefinition
|
|
9
|
+
});
|
|
10
|
+
const buildSourcesMetaKey = "workspace:build-sources";
|
|
11
|
+
async function publishWorkspaceSnapshot(definition, store, snapshot) {
|
|
12
|
+
for (const publisher of definition.publish || []) await publisher.publish({
|
|
13
|
+
workspace: definition,
|
|
14
|
+
store,
|
|
15
|
+
rootDir: definition.rootDir || process.cwd(),
|
|
16
|
+
snapshot
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
async function syncWorkspaceDefinition(definition, store) {
|
|
20
|
+
const loaders = definition.loaders?.length ? definition.loaders : [files()];
|
|
21
|
+
const hasExplicitLoaders = !!definition.loaders?.length;
|
|
22
|
+
const ctxSource = createSourceContext(definition);
|
|
23
|
+
const buildSources = normalizeWorkspaceSources(definition.sources).filter((source) => source.materialize === "build");
|
|
24
|
+
if (!await reconcileBuildSourceMounts(store, buildSources) && !hasExplicitLoaders) return;
|
|
25
|
+
const normalizedSources = buildSources.map((source) => createMountedBuildSource(source));
|
|
26
|
+
const ctx = {
|
|
27
|
+
workspace: definition.name,
|
|
28
|
+
rootDir: ctxSource.rootDir,
|
|
29
|
+
sourceRootDir: ctxSource.sourceRootDir,
|
|
30
|
+
sources: normalizedSources,
|
|
31
|
+
store,
|
|
32
|
+
parseData: async (input) => input.data,
|
|
33
|
+
generateDigest: (input) => JSON.stringify(input),
|
|
34
|
+
logger: console
|
|
35
|
+
};
|
|
36
|
+
for (const loader of loaders) await loader.load(ctx);
|
|
37
|
+
await publishWorkspaceSnapshot(definition, store, await store.snapshot({ name: "sync" }));
|
|
38
|
+
}
|
|
39
|
+
async function reconcileBuildSourceMounts(store, currentSources) {
|
|
40
|
+
const previousSources = await readSyncedBuildSources(store);
|
|
41
|
+
const hasBuildSourceState = previousSources.length > 0 || currentSources.length > 0;
|
|
42
|
+
const resetPaths = [...new Set([...previousSources.map((source) => source.mountPath), ...currentSources.map((source) => source.mountPath)])];
|
|
43
|
+
for (const mountPath of resetPaths.filter(Boolean).sort((a, b) => b.length - a.length)) await store.rm(mountPath, {
|
|
44
|
+
recursive: true,
|
|
45
|
+
force: true
|
|
46
|
+
});
|
|
47
|
+
for (const source of [...previousSources, ...currentSources].filter((source) => !source.mountPath)) await removeRootBuildSourceFiles(store, source);
|
|
48
|
+
for (const mountPath of [...new Set(currentSources.map((source) => source.mountPath))].filter(Boolean).sort((a, b) => a.length - b.length)) await store.mkdir(mountPath, { recursive: true });
|
|
49
|
+
await store.setMeta?.(buildSourcesMetaKey, currentSources.map(({ key, mountPath }) => ({
|
|
50
|
+
key,
|
|
51
|
+
mountPath
|
|
52
|
+
})));
|
|
53
|
+
return hasBuildSourceState;
|
|
54
|
+
}
|
|
55
|
+
async function readSyncedBuildSources(store) {
|
|
56
|
+
const value = await store.getMeta?.(buildSourcesMetaKey);
|
|
57
|
+
if (!Array.isArray(value)) return [];
|
|
58
|
+
return value.filter(isSyncedBuildSource);
|
|
59
|
+
}
|
|
60
|
+
async function removeRootBuildSourceFiles(store, source) {
|
|
61
|
+
const entries = await store.list("", { recursive: true });
|
|
62
|
+
await Promise.all(entries.map(async (entry) => {
|
|
63
|
+
if (entry.type !== "file") return;
|
|
64
|
+
if ((await store.readFile(entry.path))?.metadata?.source === source.key) await store.rm(entry.path, { force: true });
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
function isSyncedBuildSource(value) {
|
|
68
|
+
return !!value && typeof value === "object" && typeof value.key === "string" && typeof value.mountPath === "string";
|
|
69
|
+
}
|
|
70
|
+
function createMountedBuildSource(source) {
|
|
71
|
+
return {
|
|
72
|
+
...source.source,
|
|
73
|
+
key: source.key,
|
|
74
|
+
async getKeys(ctx) {
|
|
75
|
+
return await source.source.getKeys(ctx);
|
|
76
|
+
},
|
|
77
|
+
async getItem(key, ctx) {
|
|
78
|
+
const item = await source.source.getItem(key, ctx);
|
|
79
|
+
const path = normalizeWorkspacePath(`${source.mountPath}/${item.path || item.key}`);
|
|
80
|
+
return {
|
|
81
|
+
...item,
|
|
82
|
+
path,
|
|
83
|
+
metadata: {
|
|
84
|
+
...item.metadata,
|
|
85
|
+
source: source.key
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
//#endregion
|
|
92
|
+
export { syncWorkspaceDefinition as n, lifecycle_exports as t };
|
package/dist/loader.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { D as WorkspaceContent, I as WorkspaceLoader, rt as WorkspaceSourceItem } from "./types-CwNcWTdt.js";
|
|
2
|
+
|
|
3
|
+
//#region src/loaders/files.d.ts
|
|
4
|
+
interface FilesLoaderOptions {
|
|
5
|
+
include?: string | string[];
|
|
6
|
+
exclude?: string | string[];
|
|
7
|
+
transform?: (item: WorkspaceSourceItem) => WorkspaceContent | WorkspaceSourceItem | Promise<WorkspaceContent | WorkspaceSourceItem>;
|
|
8
|
+
}
|
|
9
|
+
declare function files(options?: FilesLoaderOptions): WorkspaceLoader;
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/loaders/json.d.ts
|
|
12
|
+
declare function json(options?: FilesLoaderOptions): WorkspaceLoader;
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/loaders/text.d.ts
|
|
15
|
+
declare function text(options?: FilesLoaderOptions): WorkspaceLoader;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { type FilesLoaderOptions, files, json, text };
|
package/dist/loader.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { t as files } from "./files-DbsIjBya.js";
|
|
2
|
+
//#region src/loaders/json.ts
|
|
3
|
+
function json(options = {}) {
|
|
4
|
+
return files({
|
|
5
|
+
...options,
|
|
6
|
+
transform: async (item) => {
|
|
7
|
+
const transformed = options.transform ? await options.transform(item) : item;
|
|
8
|
+
if (typeof transformed === "string" || transformed instanceof Uint8Array) return transformed;
|
|
9
|
+
return {
|
|
10
|
+
...transformed,
|
|
11
|
+
mediaType: transformed.mediaType || "application/json"
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/loaders/text.ts
|
|
18
|
+
function text(options = {}) {
|
|
19
|
+
return files(options);
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { files, json, text };
|