@vite-hub/bundle 0.0.0-stage → 0.3.0

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.
@@ -0,0 +1,163 @@
1
+ import "nostics";
2
+ //#region ../internal/src/host-credentials.d.ts
3
+ interface HostCliRunResult {
4
+ exitCode: number | null;
5
+ stdout: string;
6
+ }
7
+ /** Runs a host CLI with an argument array and no shell, and returns its stdout. */
8
+ type HostCliRun = (command: string, args: readonly string[], options: {
9
+ cwd?: string;
10
+ env: NodeJS.ProcessEnv;
11
+ signal?: AbortSignal;
12
+ }) => Promise<HostCliRunResult>;
13
+ //#endregion
14
+ //#region ../internal/src/provision.d.ts
15
+ type ProvisionProvider = "cloudflare" | "vercel";
16
+ interface ProvisionLogger {
17
+ log: (message: string) => void;
18
+ warn: (message: string) => void;
19
+ }
20
+ interface ProvisionContext {
21
+ env: Record<string, string | undefined>;
22
+ fetch: typeof globalThis.fetch;
23
+ logger: ProvisionLogger;
24
+ markPlanUnchecked?: () => void;
25
+ }
26
+ interface ProvisionState {
27
+ cloudflare?: Record<string, Record<string, string>>;
28
+ vercel?: Record<string, Record<string, string>>;
29
+ }
30
+ interface ProvisionResult {
31
+ ids?: ProvisionState;
32
+ }
33
+ interface ProvisionAction {
34
+ kind: string;
35
+ name: string;
36
+ exists: boolean;
37
+ pending?: boolean;
38
+ /** Describes the change that `apply()` makes to an existing resource, for example `read replication: disabled -> auto`. */
39
+ update?: string;
40
+ apply: () => Promise<ProvisionResult>;
41
+ }
42
+ /** One Provision State category that a step records, with the keys that current Definitions use. */
43
+ interface ProvisionStateCategory {
44
+ category: string;
45
+ declared: readonly string[];
46
+ /** Provider resource identity for shared-resource checks. Return undefined when the recorded id lacks enough information. Defaults to the recorded id. */
47
+ resourceIdentity?: (entry: {
48
+ id: string;
49
+ key: string;
50
+ }) => string | undefined;
51
+ /** Identity expected by current config for a declared key. Omit when it cannot be established without provider access. */
52
+ declaredResourceIdentity?: (key: string) => string | undefined;
53
+ /** Tells a developer how to delete the resource of a recorded entry that no Definition declares. ViteHub never runs it. */
54
+ deleteHint: (entry: {
55
+ id: string;
56
+ key: string;
57
+ }) => string;
58
+ }
59
+ interface ProvisionStep {
60
+ id: string;
61
+ provider: ProvisionProvider;
62
+ plan: (context: ProvisionContext) => Promise<ProvisionAction[]>;
63
+ /** Describes the Provision State this step records. Runs without network access, also without credentials. */
64
+ recordedState?: (context: Pick<ProvisionContext, "env">) => ProvisionStateCategory[];
65
+ }
66
+ //#endregion
67
+ //#region ../internal/src/cli.d.ts
68
+ interface ViteHubCliStreams {
69
+ stderr: {
70
+ write: (chunk: string | Uint8Array, encoding?: BufferEncoding | StdoutWriteCallback, callback?: StdoutWriteCallback) => unknown;
71
+ };
72
+ stdout: {
73
+ write: (chunk: string | Uint8Array) => unknown;
74
+ };
75
+ }
76
+ interface ViteHubCliSpawnResult {
77
+ exitCode: number | null;
78
+ signal?: NodeJS.Signals | null;
79
+ /** The output of the child when `stdout` is `pipe`. */
80
+ stdout?: string;
81
+ }
82
+ interface ViteHubCliSpawnOptions {
83
+ cwd?: string;
84
+ env?: NodeJS.ProcessEnv;
85
+ stderr?: "inherit" | "pipe";
86
+ /** `ignore` gives the child no terminal input, so a tool that asks questions on a terminal does not ask. */
87
+ stdin?: "ignore" | "inherit";
88
+ /** `stderr` sends the child's stdout to the parent's stderr, so the parent's stdout keeps only its own output. */
89
+ stdout?: "inherit" | "pipe" | "stderr";
90
+ }
91
+ type ViteHubCliSpawn = (command: string, args: string[], options?: ViteHubCliSpawnOptions) => Promise<ViteHubCliSpawnResult>;
92
+ interface ViteHubCliContext extends ViteHubCliStreams {
93
+ cwd: string;
94
+ env: NodeJS.ProcessEnv;
95
+ /** Replaces `fetch` for commands that call a running app, so tests need no server. */
96
+ fetch?: typeof fetch;
97
+ /**
98
+ * Loads the project config for a build on `host` and returns the Provision Steps of its plugins, with the config root
99
+ * that holds `.vitehub/provision.json`. Setup commands, such as `vitehub deploy`, call it only when they need the
100
+ * steps, so they still run on a config that throws.
101
+ */
102
+ loadProvision?: (host: ProvisionProvider) => Promise<ViteHubCliProvision>;
103
+ /** The deployed app's public origin from `vitehub({ publicUrl })`, when it is one string. */
104
+ publicUrl?: string;
105
+ rootDir: string;
106
+ /** Replaces the host CLI runner, such as for `wrangler auth token`, so tests need no real host CLI. */
107
+ runHostCli?: HostCliRun;
108
+ spawn: ViteHubCliSpawn;
109
+ }
110
+ interface ViteHubCliProvision {
111
+ rootDir: string;
112
+ steps: readonly ProvisionStep[];
113
+ }
114
+ interface ViteHubCliFeature {
115
+ description?: string;
116
+ name: string;
117
+ run: (args: string[], context: ViteHubCliContext) => Promise<number | void> | number | void;
118
+ usage?: string;
119
+ }
120
+ interface ViteHubCliCommandNamespace {
121
+ /** The feature that `vitehub <name>` runs when the next argument names no other feature. It gets every argument after `<name>`. */
122
+ defaultFeature?: string;
123
+ description?: string;
124
+ features: ViteHubCliFeature[];
125
+ name: string;
126
+ }
127
+ /** The flags of `vitehub seed` that every seed gets. */
128
+ interface ViteHubCliSeedOptions {
129
+ /** `--database <name>`: seed only this Database. Only the Database seed runs. */
130
+ database?: string;
131
+ /** The process environment with the env files of `--stage`. */
132
+ env: NodeJS.ProcessEnv;
133
+ /** `--remote`: write the deployed stores. Without it, a seed writes only local data. */
134
+ remote: boolean;
135
+ /** `--timeout <ms>` of each call to the app. */
136
+ timeout?: number;
137
+ /** The deployed app with `--remote`: `--url`, or `vitehub({ publicUrl })`. */
138
+ url?: string;
139
+ }
140
+ /** The seed files of one primitive, which `vitehub seed` writes. */
141
+ interface ViteHubCliSeed {
142
+ /** Where the seed files are, such as `server/seed/kv/`. `vitehub seed` names it when it finds no seed files. */
143
+ files: string;
144
+ /** The primitive, such as `database` or `kv`. `vitehub seed <name>` runs only this seed. */
145
+ name: string;
146
+ /** Writes the seed files and returns the exit code, or `undefined` when the project has no seed files for this primitive. */
147
+ run: (options: ViteHubCliSeedOptions, context: ViteHubCliContext) => Promise<number | undefined>;
148
+ }
149
+ interface ViteHubCliContributor {
150
+ namespaces: ViteHubCliCommandNamespace[];
151
+ provision?: ProvisionStep[];
152
+ /** The seed files that `vitehub seed` writes. */
153
+ seeds?: ViteHubCliSeed[];
154
+ /** The deployed app's public origin. Commands receive it as `context.publicUrl`. */
155
+ publicUrl?: string;
156
+ }
157
+ type ViteHubCliContributorFactory = () => ViteHubCliContributor | undefined | Promise<ViteHubCliContributor | undefined>;
158
+ interface ViteHubCliPluginMetadata {
159
+ cli?: ViteHubCliContributor | ViteHubCliContributorFactory;
160
+ }
161
+ type StdoutWriteCallback = (error?: Error | null) => void;
162
+ //#endregion
163
+ export { ViteHubCliPluginMetadata as n, ViteHubCliContributor as t };
package/dist/cli.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { t as ViteHubCliContributor } from "./cli-ubYJpAL_.js";
2
+ //#region src/bytes.d.ts
3
+ /** `1234567` becomes `1.23 MB`, like Vite's build output. */
4
+ export declare function formatBytes(bytes: number): string;
5
+ //#endregion
6
+ //#region src/cli.d.ts
7
+ /** The `vitehub bundle` commands. They read `.vitehub/bundle/` and need no dev server. */
8
+ export declare const bundleCliContributor: ViteHubCliContributor;
9
+ //#endregion
package/dist/cli.js ADDED
@@ -0,0 +1,3 @@
1
+ import { u as formatBytes } from "./compare-B-xpyN4Y.js";
2
+ import { t as bundleCliContributor } from "./cli-DdzHN8li.js";
3
+ export { bundleCliContributor, formatBytes };