vite-plugin-tanstack-start-zephyr 0.0.0-canary.23

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/.eslintrc.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "extends": ["../../.eslintrc.json"],
3
+ "ignorePatterns": ["!**/*"],
4
+ "overrides": [
5
+ {
6
+ "files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7
+ "rules": {}
8
+ },
9
+ {
10
+ "files": ["*.ts", "*.tsx"],
11
+ "rules": {}
12
+ },
13
+ {
14
+ "files": ["*.js", "*.jsx"],
15
+ "rules": {}
16
+ }
17
+ ]
18
+ }
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [Zephyr Cloud Inc] [Dmitriy Shekhovtsov, Zackary Chapple, Zack Jackson]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,132 @@
1
+ # vite-plugin-tanstack-start-zephyr
2
+
3
+ Vite plugin for deploying TanStack Start applications to Zephyr with SSR support.
4
+
5
+ ## Overview
6
+
7
+ This plugin automatically bundles and uploads your TanStack Start application to Zephyr's edge network during the build process. It supports server-side rendering (SSR) and enables multiple versions of your application to run simultaneously.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ pnpm add vite-plugin-tanstack-start-zephyr
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ Add the plugin to your `vite.config.ts`:
18
+
19
+ ```typescript
20
+ import { defineConfig } from 'vite';
21
+ import { TanStackStartVite } from '@tanstack/start/vite';
22
+ import { withZephyrTanstackStart } from 'vite-plugin-tanstack-start-zephyr';
23
+
24
+ export default defineConfig({
25
+ plugins: [
26
+ TanStackStartVite(),
27
+ withZephyrTanstackStart({
28
+ appUid: 'my-app-uid',
29
+ environment: 'production',
30
+ apiEndpoint: 'https://api.zephyrcloud.app',
31
+ apiKey: process.env.ZEPHYR_API_KEY,
32
+ }),
33
+ ],
34
+ });
35
+ ```
36
+
37
+ ## Configuration
38
+
39
+ ### Options
40
+
41
+ | Option | Type | Required | Description |
42
+ | ------------- | -------- | -------- | ---------------------------------------------- |
43
+ | `appUid` | `string` | Yes | Your application's unique identifier |
44
+ | `environment` | `string` | No | Deployment environment (default: 'production') |
45
+ | `apiEndpoint` | `string` | No | Zephyr API endpoint |
46
+ | `apiKey` | `string` | No | API key for authentication |
47
+
48
+ ### Environment Variables
49
+
50
+ You can also configure the plugin using environment variables:
51
+
52
+ - `ZE_APP_UID` - Application UID
53
+ - `ZE_API_ENDPOINT` - API endpoint
54
+ - `ZE_API_KEY` - API key
55
+ - `ZE_ENVIRONMENT` - Deployment environment
56
+
57
+ ## How It Works
58
+
59
+ 1. **Build**: TanStack Start builds your app to `.output/` directory
60
+ 2. **Extract**: Plugin collects server modules and client assets
61
+ 3. **Bundle**: Server code is bundled with all dependencies
62
+ 4. **Upload**: Both server and client files are uploaded to Zephyr
63
+ 5. **Deploy**: Files are stored in content-addressable KV storage
64
+ 6. **Run**: Orchestration worker loads and runs your app on the edge
65
+
66
+ ## Build Output
67
+
68
+ The plugin processes TanStack Start's build output:
69
+
70
+ ```
71
+ .output/
72
+ ├── server/ # Server-side code
73
+ │ ├── index.js # Main entry point
74
+ │ └── assets/ # Server bundles
75
+ └── client/ # Client-side assets
76
+ └── assets/ # Client bundles
77
+ ```
78
+
79
+ ## Deployment Architecture
80
+
81
+ Your app runs in Cloudflare's orchestration worker using dynamic worker loaders:
82
+
83
+ ```
84
+ Request → Orchestration Worker → Load Your App (Isolate) → Response
85
+ ```
86
+
87
+ Features:
88
+
89
+ - ✅ Multiple versions live simultaneously
90
+ - ✅ Content-addressable storage (efficient caching)
91
+ - ✅ SSR and API routes support
92
+ - ✅ Hot swapping without redeployment
93
+ - ✅ Per-version isolation
94
+
95
+ ## Development
96
+
97
+ ### Build Plugin
98
+
99
+ ```bash
100
+ cd libs/vite-plugin-tanstack-start-zephyr
101
+ pnpm build
102
+ ```
103
+
104
+ ### Run Tests
105
+
106
+ ```bash
107
+ pnpm test
108
+ ```
109
+
110
+ ### Link Locally
111
+
112
+ ```bash
113
+ pnpm link --global
114
+ # In your project
115
+ pnpm link --global vite-plugin-tanstack-start-zephyr
116
+ ```
117
+
118
+ ## Requirements
119
+
120
+ - Node.js 18+
121
+ - TanStack Start 1.0+
122
+ - Vite 5+
123
+
124
+ ## License
125
+
126
+ MIT
127
+
128
+ ## Related
129
+
130
+ - [@tanstack/start](https://tanstack.com/start) - TanStack Start framework
131
+ - [zephyr-agent](../zephyr-agent) - Core Zephyr upload library
132
+ - [vite-plugin-zephyr](../vite-plugin-zephyr) - Static site Vite plugin
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Vite-plugin-tanstack-start-zephyr
3
+ *
4
+ * Vite plugin for deploying TanStack Start applications to Zephyr with SSR support
5
+ *
6
+ * Configuration is automatically detected from:
7
+ *
8
+ * - Package.json (app name, version)
9
+ * - Git info (org, project, branch)
10
+ * - Zephyr auth (via `ze login`)
11
+ */
12
+ export { withZephyrTanstackStart, type TanStackStartZephyrOptions, } from './lib/vite-plugin-tanstack-start-zephyr';
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ /**
3
+ * Vite-plugin-tanstack-start-zephyr
4
+ *
5
+ * Vite plugin for deploying TanStack Start applications to Zephyr with SSR support
6
+ *
7
+ * Configuration is automatically detected from:
8
+ *
9
+ * - Package.json (app name, version)
10
+ * - Git info (org, project, branch)
11
+ * - Zephyr auth (via `ze login`)
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.withZephyrTanstackStart = void 0;
15
+ var vite_plugin_tanstack_start_zephyr_1 = require("./lib/vite-plugin-tanstack-start-zephyr");
16
+ Object.defineProperty(exports, "withZephyrTanstackStart", { enumerable: true, get: function () { return vite_plugin_tanstack_start_zephyr_1.withZephyrTanstackStart; } });
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AAEH,6FAGiD;AAF/C,4IAAA,uBAAuB,OAAA"}
@@ -0,0 +1,16 @@
1
+ /** Loads TanStack Start build output from .output directory */
2
+ import type { OutputBundle } from 'rollup';
3
+ /** Load files from directory into Rollup OutputBundle format */
4
+ export declare function loadFilesFromDirectory(dir: string): Promise<OutputBundle>;
5
+ /**
6
+ * Load TanStack Start build output preserving full directory structure This loads ALL
7
+ * files from the output directory root, maintaining their natural paths (e.g.,
8
+ * server/index.js, client/assets/main.js, favicon.ico)
9
+ */
10
+ export declare function loadTanStackOutput(outputDir: string): Promise<OutputBundle>;
11
+ /** @deprecated Use loadTanStackOutput instead - this preserves the full structure */
12
+ export declare function loadServerOutput(outputDir: string): Promise<OutputBundle>;
13
+ /** @deprecated Use loadTanStackOutput instead - this preserves the full structure */
14
+ export declare function loadClientOutput(outputDir: string): Promise<OutputBundle>;
15
+ /** Check if TanStack Start output directory exists and is valid */
16
+ export declare function validateTanStackOutput(outputDir: string): Promise<boolean>;
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ /** Loads TanStack Start build output from .output directory */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.loadFilesFromDirectory = loadFilesFromDirectory;
5
+ exports.loadTanStackOutput = loadTanStackOutput;
6
+ exports.loadServerOutput = loadServerOutput;
7
+ exports.loadClientOutput = loadClientOutput;
8
+ exports.validateTanStackOutput = validateTanStackOutput;
9
+ const tslib_1 = require("tslib");
10
+ const fs = tslib_1.__importStar(require("fs/promises"));
11
+ const path = tslib_1.__importStar(require("path"));
12
+ /** Recursively get all files in a directory */
13
+ async function getAllFiles(dir, baseDir) {
14
+ baseDir = baseDir || dir;
15
+ const entries = await fs.readdir(dir, { withFileTypes: true });
16
+ const files = await Promise.all(entries.map(async (entry) => {
17
+ const fullPath = path.join(dir, entry.name);
18
+ if (entry.isDirectory()) {
19
+ return getAllFiles(fullPath, baseDir);
20
+ }
21
+ else {
22
+ return [fullPath];
23
+ }
24
+ }));
25
+ return files.flat();
26
+ }
27
+ /** Load files from directory into Rollup OutputBundle format */
28
+ async function loadFilesFromDirectory(dir) {
29
+ const bundle = {};
30
+ try {
31
+ const files = await getAllFiles(dir);
32
+ for (const filePath of files) {
33
+ const relativePath = path.relative(dir, filePath);
34
+ const content = await fs.readFile(filePath);
35
+ const ext = path.extname(filePath);
36
+ // Determine if this is a code chunk or asset
37
+ const isCode = ext === '.js' || ext === '.mjs' || ext === '.cjs';
38
+ if (isCode) {
39
+ // Create OutputChunk for code files
40
+ const chunk = {
41
+ type: 'chunk',
42
+ fileName: relativePath,
43
+ name: path.basename(relativePath, ext),
44
+ code: content.toString('utf-8'),
45
+ isEntry: relativePath === 'index.js' || relativePath.includes('index'),
46
+ isDynamicEntry: false,
47
+ facadeModuleId: null,
48
+ moduleIds: [],
49
+ exports: [],
50
+ imports: [],
51
+ dynamicImports: [],
52
+ implicitlyLoadedBefore: [],
53
+ importedBindings: {},
54
+ referencedFiles: [],
55
+ modules: {},
56
+ map: null,
57
+ sourcemapFileName: null,
58
+ preliminaryFileName: relativePath,
59
+ isImplicitEntry: false,
60
+ };
61
+ bundle[relativePath] = chunk;
62
+ }
63
+ else {
64
+ // Create OutputAsset for non-code files
65
+ const asset = {
66
+ type: 'asset',
67
+ fileName: relativePath,
68
+ name: relativePath,
69
+ needsCodeReference: false,
70
+ source: content,
71
+ names: [],
72
+ originalFileName: null,
73
+ originalFileNames: [],
74
+ };
75
+ bundle[relativePath] = asset;
76
+ }
77
+ }
78
+ return bundle;
79
+ }
80
+ catch (error) {
81
+ console.error(`Error loading files from ${dir}:`, error);
82
+ throw error;
83
+ }
84
+ }
85
+ /**
86
+ * Load TanStack Start build output preserving full directory structure This loads ALL
87
+ * files from the output directory root, maintaining their natural paths (e.g.,
88
+ * server/index.js, client/assets/main.js, favicon.ico)
89
+ */
90
+ async function loadTanStackOutput(outputDir) {
91
+ // Load from the root output directory to preserve natural structure
92
+ return loadFilesFromDirectory(outputDir);
93
+ }
94
+ /** @deprecated Use loadTanStackOutput instead - this preserves the full structure */
95
+ async function loadServerOutput(outputDir) {
96
+ const serverDir = path.join(outputDir, 'server');
97
+ return loadFilesFromDirectory(serverDir);
98
+ }
99
+ /** @deprecated Use loadTanStackOutput instead - this preserves the full structure */
100
+ async function loadClientOutput(outputDir) {
101
+ const clientDir = path.join(outputDir, 'client');
102
+ return loadFilesFromDirectory(clientDir);
103
+ }
104
+ /** Check if TanStack Start output directory exists and is valid */
105
+ async function validateTanStackOutput(outputDir) {
106
+ try {
107
+ const serverDir = path.join(outputDir, 'server');
108
+ const clientDir = path.join(outputDir, 'client');
109
+ const [serverExists, clientExists] = await Promise.all([
110
+ fs
111
+ .access(serverDir)
112
+ .then(() => true)
113
+ .catch(() => false),
114
+ fs
115
+ .access(clientDir)
116
+ .then(() => true)
117
+ .catch(() => false),
118
+ ]);
119
+ if (!serverExists) {
120
+ console.error(`Server output directory not found: ${serverDir}`);
121
+ return false;
122
+ }
123
+ if (!clientExists) {
124
+ console.warn(`Client output directory not found: ${clientDir}`);
125
+ // Client is optional, might be API-only
126
+ }
127
+ return true;
128
+ }
129
+ catch (error) {
130
+ console.error('Error validating TanStack output:', error);
131
+ return false;
132
+ }
133
+ }
134
+ //# sourceMappingURL=load-tanstack-output.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load-tanstack-output.js","sourceRoot":"","sources":["../../../../src/lib/internal/extract/load-tanstack-output.ts"],"names":[],"mappings":";AAAA,+DAA+D;;AAwB/D,wDA2DC;AAOD,gDAGC;AAGD,4CAGC;AAGD,4CAGC;AAGD,wDA+BC;;AAzID,wDAAkC;AAClC,mDAA6B;AAG7B,+CAA+C;AAC/C,KAAK,UAAU,WAAW,CAAC,GAAW,EAAE,OAAgB;IACtD,OAAO,GAAG,OAAO,IAAI,GAAG,CAAC;IACzB,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE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AChE,wCAAwC;QAC1C,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,mCAAmC,EAAE,KAAK,CAAC,CAAC;QAC1D,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
@@ -0,0 +1,23 @@
1
+ /** Vite plugin for deploying TanStack Start applications to Zephyr */
2
+ import type { Plugin } from 'vite';
3
+ /**
4
+ * Plugin options for TanStack Start Zephyr deployment All configuration is handled
5
+ * automatically by ZephyrEngine via package.json and git info
6
+ */
7
+ export interface TanStackStartZephyrOptions {
8
+ /**
9
+ * Optional output directory override Defaults to 'dist' relative to project root
10
+ * (TanStack Start default)
11
+ */
12
+ outputDir?: string;
13
+ }
14
+ /**
15
+ * Main Vite plugin for TanStack Start Zephyr deployment
16
+ *
17
+ * Configuration is automatically detected from:
18
+ *
19
+ * - Package.json (app name, version)
20
+ * - Git info (org, project, branch)
21
+ * - Zephyr auth (via ze login)
22
+ */
23
+ export declare function withZephyrTanstackStart(options?: TanStackStartZephyrOptions): Plugin;
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ /** Vite plugin for deploying TanStack Start applications to Zephyr */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.withZephyrTanstackStart = withZephyrTanstackStart;
5
+ const tslib_1 = require("tslib");
6
+ const path = tslib_1.__importStar(require("path"));
7
+ const zephyr_agent_1 = require("zephyr-agent");
8
+ const load_tanstack_output_1 = require("./internal/extract/load-tanstack-output");
9
+ /** Extract buffer from Rollup output */
10
+ function extractBuffer(item) {
11
+ if (item.type === 'chunk') {
12
+ return Buffer.from(item.code, 'utf-8');
13
+ }
14
+ else if (item.type === 'asset') {
15
+ if (typeof item.source === 'string') {
16
+ return Buffer.from(item.source, 'utf-8');
17
+ }
18
+ else if (Buffer.isBuffer(item.source)) {
19
+ return item.source;
20
+ }
21
+ else {
22
+ return Buffer.from(item.source);
23
+ }
24
+ }
25
+ return Buffer.from('');
26
+ }
27
+ /** Get asset type from Rollup output item */
28
+ function getAssetType(item) {
29
+ const fileName = item.fileName || item.name || '';
30
+ const ext = path.extname(fileName).toLowerCase();
31
+ const typeMap = {
32
+ '.js': 'application/javascript',
33
+ '.mjs': 'application/javascript',
34
+ '.css': 'text/css',
35
+ '.html': 'text/html',
36
+ '.json': 'application/json',
37
+ };
38
+ return typeMap[ext] || 'application/octet-stream';
39
+ }
40
+ /**
41
+ * Main Vite plugin for TanStack Start Zephyr deployment
42
+ *
43
+ * Configuration is automatically detected from:
44
+ *
45
+ * - Package.json (app name, version)
46
+ * - Git info (org, project, branch)
47
+ * - Zephyr auth (via ze login)
48
+ */
49
+ function withZephyrTanstackStart(options = {}) {
50
+ const { zephyr_engine_defer, zephyr_defer_create } = zephyr_agent_1.ZephyrEngine.defer_create();
51
+ let config;
52
+ let outputDir;
53
+ let uploadCompleted = false; // Guard to ensure we only upload once
54
+ return {
55
+ name: 'vite-plugin-tanstack-start-zephyr',
56
+ enforce: 'post', // Run after TanStack Start plugin
57
+ configResolved(resolvedConfig) {
58
+ config = resolvedConfig;
59
+ // For TanStack Start, always use the root dist directory (contains server/ and client/)
60
+ // Don't use config.build.outDir as it points to dist/server/ during SSR build
61
+ outputDir = options.outputDir || path.join(config.root, 'dist');
62
+ console.log(`[TanStack Zephyr] Output directory: ${outputDir}`);
63
+ },
64
+ async buildApp(builder) {
65
+ // Guard: Only process upload once, even if buildApp is called multiple times
66
+ if (uploadCompleted) {
67
+ return;
68
+ }
69
+ // Initialize ZephyrEngine in buildApp (runs once) instead of configResolved (runs per environment)
70
+ // This ensures the engine is only created once, and start_new_build() is only called once
71
+ // NOTE: ZephyrEngine.create() automatically calls start_new_build()
72
+ const engineOptions = {
73
+ builder: 'vite',
74
+ context: config.root,
75
+ };
76
+ zephyr_defer_create(engineOptions);
77
+ const zephyr_engine = await zephyr_engine_defer;
78
+ // Log all environments and their build status for debugging
79
+ const environments = Object.entries(builder.environments);
80
+ console.log(`[TanStack Zephyr] buildApp hook called with ${environments.length} environment(s):`);
81
+ for (const [name, env] of environments) {
82
+ console.log(` - ${name}: isBuilt=${env.isBuilt}`);
83
+ }
84
+ // Wait for all environments to be built (not just specific ones)
85
+ // This ensures we have all build outputs before uploading
86
+ const notBuilt = Object.entries(builder.environments)
87
+ .filter(([, env]) => !env.isBuilt)
88
+ .map(([name]) => name);
89
+ if (notBuilt.length > 0) {
90
+ console.log(`[TanStack Zephyr] Building environments that aren't built yet: ${notBuilt.join(', ')}`);
91
+ for (const envName of notBuilt) {
92
+ const env = builder.environments[envName];
93
+ if (env) {
94
+ await builder.build(env);
95
+ }
96
+ }
97
+ }
98
+ // Verify all environments are now built
99
+ const allBuilt = Object.values(builder.environments).every((env) => env.isBuilt);
100
+ if (!allBuilt) {
101
+ const stillNotBuilt = Object.entries(builder.environments)
102
+ .filter(([, env]) => !env.isBuilt)
103
+ .map(([name]) => name);
104
+ throw new zephyr_agent_1.ZephyrError(zephyr_agent_1.ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
105
+ message: `Some environments are still not built: ${stillNotBuilt.join(', ')}`,
106
+ });
107
+ }
108
+ console.log('[TanStack Zephyr] All environments built, processing output...');
109
+ try {
110
+ // Engine is already initialized above, and ZephyrEngine.create() automatically calls start_new_build()
111
+ // So we don't need to call start_new_build() again here
112
+ // Load ALL build output preserving directory structure
113
+ // This includes server/, client/, and any root files (favicon.ico, etc.)
114
+ const bundle = await (0, load_tanstack_output_1.loadTanStackOutput)(outputDir);
115
+ const assetsMap = (0, zephyr_agent_1.buildAssetsMap)(bundle, extractBuffer, getAssetType);
116
+ console.log(`[TanStack Zephyr] Uploading ${Object.keys(assetsMap).length} assets...`);
117
+ // Upload assets with SSR snapshot type
118
+ await zephyr_engine.upload_assets({
119
+ assetsMap,
120
+ buildStats: await (0, zephyr_agent_1.zeBuildDashData)(zephyr_engine),
121
+ snapshotType: 'ssr',
122
+ });
123
+ // Finish build
124
+ await zephyr_engine.build_finished();
125
+ // Mark upload as completed to prevent multiple calls
126
+ uploadCompleted = true;
127
+ console.log('[TanStack Zephyr] Deployment successful!');
128
+ }
129
+ catch (error) {
130
+ console.error('[TanStack Zephyr] Deployment failed:', error);
131
+ throw error;
132
+ }
133
+ },
134
+ };
135
+ }
136
+ //# sourceMappingURL=vite-plugin-tanstack-start-zephyr.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-plugin-tanstack-start-zephyr.js","sourceRoot":"","sources":["../../src/lib/vite-plugin-tanstack-start-zephyr.ts"],"names":[],"mappings":";AAAA,sEAAsE;;AAiEtE,0DA+GC;;AA7KD,mDAA6B;AAC7B,+CAOsB;AACtB,kFAA6E;AAE7E,wCAAwC;AACxC,SAAS,aAAa,CAAC,IAAS;IAC9B,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QAC1B,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACzC,CAAC;SAAM,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QACjC,IAAI,OAAO,IAAI,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;YACpC,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC3C,CAAC;aAAM,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;YACxC,OAAO,IAAI,CAAC,MAAM,CAAC;QACrB,CAAC;aAAM,CAAC;YACN,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACzB,CAAC;AAED,6CAA6C;AAC7C,SAAS,YAAY,CAAC,IAA0C;IAC9D,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,IAAI,IAA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,CAAC;gBAC7D,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "vite-plugin-tanstack-start-zephyr",
3
+ "version": "0.1.0",
4
+ "description": "Vite plugin for Zephyr with TanStack Start support",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/ZephyrCloudIO/zephyr-packages.git",
8
+ "directory": "libs/vite-plugin-tanstack-start-zephyr"
9
+ },
10
+ "license": "Apache-2.0",
11
+ "author": {
12
+ "name": "ZephyrCloudIO",
13
+ "url": "https://github.com/ZephyrCloudIO"
14
+ },
15
+ "type": "commonjs",
16
+ "main": "dist/index.js",
17
+ "types": "dist/index.d.ts",
18
+ "scripts": {
19
+ "build": "nx run vite-plugin-tanstack-start-zephyr:build",
20
+ "patch-version": "pnpm version"
21
+ },
22
+ "dependencies": {
23
+ "rollup": "catalog:rollup4",
24
+ "vite": "catalog:vite7",
25
+ "zephyr-agent": "workspace:*"
26
+ },
27
+ "peerDependencies": {
28
+ "@tanstack/start": "^1.0.0"
29
+ },
30
+ "devDependencies": {
31
+ "@types/node": "catalog:typescript"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public",
35
+ "provenance": true
36
+ }
37
+ }
@@ -0,0 +1 @@
1
+ {"version":"5.8.3"}
package/jest.config.ts ADDED
@@ -0,0 +1,10 @@
1
+ export default {
2
+ displayName: 'vite-plugin-tanstack-start-zephyr',
3
+ preset: '../../jest.preset.js',
4
+ testEnvironment: 'node',
5
+ transform: {
6
+ '^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
7
+ },
8
+ moduleFileExtensions: ['ts', 'js', 'html'],
9
+ coverageDirectory: '../../coverage/libs/vite-plugin-tanstack-start-zephyr',
10
+ };
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "vite-plugin-tanstack-start-zephyr",
3
+ "version": "0.0.0-canary.23",
4
+ "description": "Vite plugin for Zephyr with TanStack Start support",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/ZephyrCloudIO/zephyr-packages.git",
8
+ "directory": "libs/vite-plugin-tanstack-start-zephyr"
9
+ },
10
+ "license": "Apache-2.0",
11
+ "author": {
12
+ "name": "ZephyrCloudIO",
13
+ "url": "https://github.com/ZephyrCloudIO"
14
+ },
15
+ "type": "commonjs",
16
+ "main": "dist/index.js",
17
+ "types": "dist/index.d.ts",
18
+ "dependencies": {
19
+ "rollup": "^4.36.0",
20
+ "vite": "^7.1.11",
21
+ "zephyr-agent": "0.0.0-canary.23"
22
+ },
23
+ "peerDependencies": {
24
+ "@tanstack/start": "^1.0.0"
25
+ },
26
+ "devDependencies": {
27
+ "@types/node": "^22.13.11"
28
+ },
29
+ "publishConfig": {
30
+ "access": "public",
31
+ "provenance": true
32
+ },
33
+ "scripts": {
34
+ "build": "nx run vite-plugin-tanstack-start-zephyr:build",
35
+ "patch-version": "pnpm version"
36
+ }
37
+ }
package/project.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "vite-plugin-tanstack-start-zephyr",
3
+ "$schema": "../../node_modules/nx/schemas/project-schema.json",
4
+ "sourceRoot": "libs/vite-plugin-tanstack-start-zephyr/src",
5
+ "projectType": "library",
6
+ "tags": [],
7
+ "implicitDependencies": ["zephyr-agent"],
8
+ "targets": {
9
+ "build": {
10
+ "executor": "@nx/js:tsc",
11
+ "outputs": ["{options.outputPath}"],
12
+ "options": {
13
+ "rootDir": "libs/vite-plugin-tanstack-start-zephyr/src",
14
+ "outputPath": "libs/vite-plugin-tanstack-start-zephyr/dist",
15
+ "tsConfig": "libs/vite-plugin-tanstack-start-zephyr/tsconfig.lib.json",
16
+ "main": "libs/vite-plugin-tanstack-start-zephyr/src/index.ts"
17
+ }
18
+ },
19
+ "nx-release-publish": {
20
+ "options": {
21
+ "packageRoot": "dist\\{projectRoot}"
22
+ }
23
+ },
24
+ "lint": {
25
+ "executor": "@nx/eslint:lint"
26
+ },
27
+ "test": {
28
+ "executor": "@nx/jest:jest",
29
+ "outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
30
+ "options": {
31
+ "jestConfig": "libs/vite-plugin-tanstack-start-zephyr/jest.config.ts"
32
+ }
33
+ }
34
+ }
35
+ }
package/src/index.ts ADDED
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Vite-plugin-tanstack-start-zephyr
3
+ *
4
+ * Vite plugin for deploying TanStack Start applications to Zephyr with SSR support
5
+ *
6
+ * Configuration is automatically detected from:
7
+ *
8
+ * - Package.json (app name, version)
9
+ * - Git info (org, project, branch)
10
+ * - Zephyr auth (via `ze login`)
11
+ */
12
+
13
+ export {
14
+ withZephyrTanstackStart,
15
+ type TanStackStartZephyrOptions,
16
+ } from './lib/vite-plugin-tanstack-start-zephyr';
@@ -0,0 +1,140 @@
1
+ /** Loads TanStack Start build output from .output directory */
2
+
3
+ import * as fs from 'fs/promises';
4
+ import * as path from 'path';
5
+ import type { OutputBundle, OutputAsset, OutputChunk } from 'rollup';
6
+
7
+ /** Recursively get all files in a directory */
8
+ async function getAllFiles(dir: string, baseDir?: string): Promise<string[]> {
9
+ baseDir = baseDir || dir;
10
+ const entries = await fs.readdir(dir, { withFileTypes: true });
11
+ const files = await Promise.all(
12
+ entries.map(async (entry) => {
13
+ const fullPath = path.join(dir, entry.name);
14
+ if (entry.isDirectory()) {
15
+ return getAllFiles(fullPath, baseDir);
16
+ } else {
17
+ return [fullPath];
18
+ }
19
+ })
20
+ );
21
+ return files.flat();
22
+ }
23
+
24
+ /** Load files from directory into Rollup OutputBundle format */
25
+ export async function loadFilesFromDirectory(dir: string): Promise<OutputBundle> {
26
+ const bundle: OutputBundle = {};
27
+
28
+ try {
29
+ const files = await getAllFiles(dir);
30
+
31
+ for (const filePath of files) {
32
+ const relativePath = path.relative(dir, filePath);
33
+ const content = await fs.readFile(filePath);
34
+ const ext = path.extname(filePath);
35
+
36
+ // Determine if this is a code chunk or asset
37
+ const isCode = ext === '.js' || ext === '.mjs' || ext === '.cjs';
38
+
39
+ if (isCode) {
40
+ // Create OutputChunk for code files
41
+ const chunk: OutputChunk = {
42
+ type: 'chunk',
43
+ fileName: relativePath,
44
+ name: path.basename(relativePath, ext),
45
+ code: content.toString('utf-8'),
46
+ isEntry: relativePath === 'index.js' || relativePath.includes('index'),
47
+ isDynamicEntry: false,
48
+ facadeModuleId: null,
49
+ moduleIds: [],
50
+ exports: [],
51
+ imports: [],
52
+ dynamicImports: [],
53
+ implicitlyLoadedBefore: [],
54
+ importedBindings: {},
55
+ referencedFiles: [],
56
+ modules: {},
57
+ map: null,
58
+ sourcemapFileName: null,
59
+ preliminaryFileName: relativePath,
60
+ isImplicitEntry: false,
61
+ };
62
+ bundle[relativePath] = chunk;
63
+ } else {
64
+ // Create OutputAsset for non-code files
65
+ const asset: OutputAsset = {
66
+ type: 'asset',
67
+ fileName: relativePath,
68
+ name: relativePath,
69
+ needsCodeReference: false,
70
+ source: content,
71
+ names: [],
72
+ originalFileName: null,
73
+ originalFileNames: [],
74
+ };
75
+ bundle[relativePath] = asset;
76
+ }
77
+ }
78
+
79
+ return bundle;
80
+ } catch (error) {
81
+ console.error(`Error loading files from ${dir}:`, error);
82
+ throw error;
83
+ }
84
+ }
85
+
86
+ /**
87
+ * Load TanStack Start build output preserving full directory structure This loads ALL
88
+ * files from the output directory root, maintaining their natural paths (e.g.,
89
+ * server/index.js, client/assets/main.js, favicon.ico)
90
+ */
91
+ export async function loadTanStackOutput(outputDir: string): Promise<OutputBundle> {
92
+ // Load from the root output directory to preserve natural structure
93
+ return loadFilesFromDirectory(outputDir);
94
+ }
95
+
96
+ /** @deprecated Use loadTanStackOutput instead - this preserves the full structure */
97
+ export async function loadServerOutput(outputDir: string): Promise<OutputBundle> {
98
+ const serverDir = path.join(outputDir, 'server');
99
+ return loadFilesFromDirectory(serverDir);
100
+ }
101
+
102
+ /** @deprecated Use loadTanStackOutput instead - this preserves the full structure */
103
+ export async function loadClientOutput(outputDir: string): Promise<OutputBundle> {
104
+ const clientDir = path.join(outputDir, 'client');
105
+ return loadFilesFromDirectory(clientDir);
106
+ }
107
+
108
+ /** Check if TanStack Start output directory exists and is valid */
109
+ export async function validateTanStackOutput(outputDir: string): Promise<boolean> {
110
+ try {
111
+ const serverDir = path.join(outputDir, 'server');
112
+ const clientDir = path.join(outputDir, 'client');
113
+
114
+ const [serverExists, clientExists] = await Promise.all([
115
+ fs
116
+ .access(serverDir)
117
+ .then(() => true)
118
+ .catch(() => false),
119
+ fs
120
+ .access(clientDir)
121
+ .then(() => true)
122
+ .catch(() => false),
123
+ ]);
124
+
125
+ if (!serverExists) {
126
+ console.error(`Server output directory not found: ${serverDir}`);
127
+ return false;
128
+ }
129
+
130
+ if (!clientExists) {
131
+ console.warn(`Client output directory not found: ${clientDir}`);
132
+ // Client is optional, might be API-only
133
+ }
134
+
135
+ return true;
136
+ } catch (error) {
137
+ console.error('Error validating TanStack output:', error);
138
+ return false;
139
+ }
140
+ }
@@ -0,0 +1,177 @@
1
+ /** Vite plugin for deploying TanStack Start applications to Zephyr */
2
+
3
+ import type { Plugin, ResolvedConfig } from 'vite';
4
+ import * as path from 'path';
5
+ import {
6
+ ZephyrEngine,
7
+ type ZephyrEngineOptions,
8
+ zeBuildDashData,
9
+ buildAssetsMap,
10
+ ZeErrors,
11
+ ZephyrError,
12
+ } from 'zephyr-agent';
13
+ import { loadTanStackOutput } from './internal/extract/load-tanstack-output';
14
+
15
+ /** Extract buffer from Rollup output */
16
+ function extractBuffer(item: any): Buffer {
17
+ if (item.type === 'chunk') {
18
+ return Buffer.from(item.code, 'utf-8');
19
+ } else if (item.type === 'asset') {
20
+ if (typeof item.source === 'string') {
21
+ return Buffer.from(item.source, 'utf-8');
22
+ } else if (Buffer.isBuffer(item.source)) {
23
+ return item.source;
24
+ } else {
25
+ return Buffer.from(item.source);
26
+ }
27
+ }
28
+ return Buffer.from('');
29
+ }
30
+
31
+ /** Get asset type from Rollup output item */
32
+ function getAssetType(item: { fileName?: string; name?: string }): string {
33
+ const fileName = item.fileName || item.name || '';
34
+ const ext = path.extname(fileName).toLowerCase();
35
+ const typeMap: Record<string, string> = {
36
+ '.js': 'application/javascript',
37
+ '.mjs': 'application/javascript',
38
+ '.css': 'text/css',
39
+ '.html': 'text/html',
40
+ '.json': 'application/json',
41
+ };
42
+ return typeMap[ext] || 'application/octet-stream';
43
+ }
44
+
45
+ /**
46
+ * Plugin options for TanStack Start Zephyr deployment All configuration is handled
47
+ * automatically by ZephyrEngine via package.json and git info
48
+ */
49
+ export interface TanStackStartZephyrOptions {
50
+ /**
51
+ * Optional output directory override Defaults to 'dist' relative to project root
52
+ * (TanStack Start default)
53
+ */
54
+ outputDir?: string;
55
+ }
56
+
57
+ /**
58
+ * Main Vite plugin for TanStack Start Zephyr deployment
59
+ *
60
+ * Configuration is automatically detected from:
61
+ *
62
+ * - Package.json (app name, version)
63
+ * - Git info (org, project, branch)
64
+ * - Zephyr auth (via ze login)
65
+ */
66
+ export function withZephyrTanstackStart(
67
+ options: TanStackStartZephyrOptions = {}
68
+ ): Plugin {
69
+ const { zephyr_engine_defer, zephyr_defer_create } = ZephyrEngine.defer_create();
70
+ let config: ResolvedConfig;
71
+ let outputDir: string;
72
+ let uploadCompleted = false; // Guard to ensure we only upload once
73
+
74
+ return {
75
+ name: 'vite-plugin-tanstack-start-zephyr',
76
+ enforce: 'post', // Run after TanStack Start plugin
77
+
78
+ configResolved(resolvedConfig) {
79
+ config = resolvedConfig;
80
+
81
+ // For TanStack Start, always use the root dist directory (contains server/ and client/)
82
+ // Don't use config.build.outDir as it points to dist/server/ during SSR build
83
+ outputDir = options.outputDir || path.join(config.root, 'dist');
84
+
85
+ console.log(`[TanStack Zephyr] Output directory: ${outputDir}`);
86
+ },
87
+
88
+ async buildApp(builder) {
89
+ // Guard: Only process upload once, even if buildApp is called multiple times
90
+ if (uploadCompleted) {
91
+ return;
92
+ }
93
+
94
+ // Initialize ZephyrEngine in buildApp (runs once) instead of configResolved (runs per environment)
95
+ // This ensures the engine is only created once, and start_new_build() is only called once
96
+ // NOTE: ZephyrEngine.create() automatically calls start_new_build()
97
+ const engineOptions: ZephyrEngineOptions = {
98
+ builder: 'vite',
99
+ context: config.root,
100
+ };
101
+ zephyr_defer_create(engineOptions);
102
+ const zephyr_engine = await zephyr_engine_defer;
103
+ // Log all environments and their build status for debugging
104
+ const environments = Object.entries(builder.environments);
105
+ console.log(
106
+ `[TanStack Zephyr] buildApp hook called with ${environments.length} environment(s):`
107
+ );
108
+ for (const [name, env] of environments) {
109
+ console.log(` - ${name}: isBuilt=${env.isBuilt}`);
110
+ }
111
+
112
+ // Wait for all environments to be built (not just specific ones)
113
+ // This ensures we have all build outputs before uploading
114
+ const notBuilt = Object.entries(builder.environments)
115
+ .filter(([, env]) => !env.isBuilt)
116
+ .map(([name]) => name);
117
+
118
+ if (notBuilt.length > 0) {
119
+ console.log(
120
+ `[TanStack Zephyr] Building environments that aren't built yet: ${notBuilt.join(', ')}`
121
+ );
122
+ for (const envName of notBuilt) {
123
+ const env = builder.environments[envName];
124
+ if (env) {
125
+ await builder.build(env);
126
+ }
127
+ }
128
+ }
129
+
130
+ // Verify all environments are now built
131
+ const allBuilt = Object.values(builder.environments).every((env) => env.isBuilt);
132
+ if (!allBuilt) {
133
+ const stillNotBuilt = Object.entries(builder.environments)
134
+ .filter(([, env]) => !env.isBuilt)
135
+ .map(([name]) => name);
136
+ throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
137
+ message: `Some environments are still not built: ${stillNotBuilt.join(', ')}`,
138
+ });
139
+ }
140
+
141
+ console.log('[TanStack Zephyr] All environments built, processing output...');
142
+
143
+ try {
144
+ // Engine is already initialized above, and ZephyrEngine.create() automatically calls start_new_build()
145
+ // So we don't need to call start_new_build() again here
146
+
147
+ // Load ALL build output preserving directory structure
148
+ // This includes server/, client/, and any root files (favicon.ico, etc.)
149
+ const bundle = await loadTanStackOutput(outputDir);
150
+
151
+ const assetsMap = buildAssetsMap(bundle, extractBuffer, getAssetType);
152
+
153
+ console.log(
154
+ `[TanStack Zephyr] Uploading ${Object.keys(assetsMap).length} assets...`
155
+ );
156
+
157
+ // Upload assets with SSR snapshot type
158
+ await zephyr_engine.upload_assets({
159
+ assetsMap,
160
+ buildStats: await zeBuildDashData(zephyr_engine),
161
+ snapshotType: 'ssr',
162
+ });
163
+
164
+ // Finish build
165
+ await zephyr_engine.build_finished();
166
+
167
+ // Mark upload as completed to prevent multiple calls
168
+ uploadCompleted = true;
169
+
170
+ console.log('[TanStack Zephyr] Deployment successful!');
171
+ } catch (error) {
172
+ console.error('[TanStack Zephyr] Deployment failed:', error);
173
+ throw error;
174
+ }
175
+ },
176
+ };
177
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "module": "commonjs",
5
+ "forceConsistentCasingInFileNames": true,
6
+ "strict": true,
7
+ "noImplicitOverride": true,
8
+ "noPropertyAccessFromIndexSignature": true,
9
+ "noImplicitReturns": true,
10
+ "noFallthroughCasesInSwitch": true
11
+ },
12
+ "files": [],
13
+ "include": [],
14
+ "references": [
15
+ {
16
+ "path": "./tsconfig.lib.json"
17
+ },
18
+ {
19
+ "path": "./tsconfig.spec.json"
20
+ }
21
+ ]
22
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "module": "commonjs",
5
+ "outDir": "../../dist/out-tsc",
6
+ "declaration": true,
7
+ "types": ["node"]
8
+ },
9
+ "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"],
10
+ "include": ["src/**/*.ts"]
11
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../dist/out-tsc",
5
+ "module": "commonjs",
6
+ "types": ["jest", "node"]
7
+ },
8
+ "include": [
9
+ "jest.config.ts",
10
+ "src/**/*.test.ts",
11
+ "src/**/*.spec.ts",
12
+ "src/**/*.d.ts"
13
+ ]
14
+ }