vite-plugin-tanstack-start-zephyr 0.0.0 → 0.1.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.
- package/.eslintrc.json +18 -0
- package/LICENSE +201 -0
- package/README.md +132 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/internal/extract/load-tanstack-output.d.ts +16 -0
- package/dist/lib/internal/extract/load-tanstack-output.js +126 -0
- package/dist/lib/internal/extract/load-tanstack-output.js.map +1 -0
- package/dist/lib/vite-plugin-tanstack-start-zephyr.d.ts +32 -0
- package/dist/lib/vite-plugin-tanstack-start-zephyr.js +156 -0
- package/dist/lib/vite-plugin-tanstack-start-zephyr.js.map +1 -0
- package/dist/package.json +37 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/jest.config.ts +10 -0
- package/package.json +26 -12
- package/project.json +35 -0
- package/src/index.ts +16 -0
- package/src/lib/internal/extract/load-tanstack-output.ts +131 -0
- package/src/lib/vite-plugin-tanstack-start-zephyr.ts +208 -0
- package/tsconfig.json +22 -0
- package/tsconfig.lib.json +11 -0
- package/tsconfig.spec.json +14 -0
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
|
package/dist/index.d.ts
ADDED
|
@@ -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,126 @@
|
|
|
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 using Node.js native recursive option */
|
|
13
|
+
async function getAllFiles(dir) {
|
|
14
|
+
const entries = await fs.readdir(dir, { recursive: true, withFileTypes: true });
|
|
15
|
+
return entries
|
|
16
|
+
.filter((entry) => entry.isFile())
|
|
17
|
+
.map((entry) => { var _a; return path.join((_a = entry.parentPath) !== null && _a !== void 0 ? _a : entry.path, entry.name); });
|
|
18
|
+
}
|
|
19
|
+
/** Load files from directory into Rollup OutputBundle format */
|
|
20
|
+
async function loadFilesFromDirectory(dir) {
|
|
21
|
+
const bundle = {};
|
|
22
|
+
try {
|
|
23
|
+
const files = await getAllFiles(dir);
|
|
24
|
+
for (const filePath of files) {
|
|
25
|
+
const relativePath = path.relative(dir, filePath);
|
|
26
|
+
const content = await fs.readFile(filePath);
|
|
27
|
+
const ext = path.extname(filePath);
|
|
28
|
+
// Determine if this is a code chunk or asset
|
|
29
|
+
const isCode = ext === '.js' || ext === '.mjs' || ext === '.cjs';
|
|
30
|
+
if (isCode) {
|
|
31
|
+
// Create OutputChunk for code files
|
|
32
|
+
const chunk = {
|
|
33
|
+
type: 'chunk',
|
|
34
|
+
fileName: relativePath,
|
|
35
|
+
name: path.basename(relativePath, ext),
|
|
36
|
+
code: content.toString('utf-8'),
|
|
37
|
+
isEntry: relativePath === 'index.js' || relativePath.includes('index'),
|
|
38
|
+
isDynamicEntry: false,
|
|
39
|
+
facadeModuleId: null,
|
|
40
|
+
moduleIds: [],
|
|
41
|
+
exports: [],
|
|
42
|
+
imports: [],
|
|
43
|
+
dynamicImports: [],
|
|
44
|
+
implicitlyLoadedBefore: [],
|
|
45
|
+
importedBindings: {},
|
|
46
|
+
referencedFiles: [],
|
|
47
|
+
modules: {},
|
|
48
|
+
map: null,
|
|
49
|
+
sourcemapFileName: null,
|
|
50
|
+
preliminaryFileName: relativePath,
|
|
51
|
+
isImplicitEntry: false,
|
|
52
|
+
};
|
|
53
|
+
bundle[relativePath] = chunk;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
// Create OutputAsset for non-code files
|
|
57
|
+
const asset = {
|
|
58
|
+
type: 'asset',
|
|
59
|
+
fileName: relativePath,
|
|
60
|
+
name: relativePath,
|
|
61
|
+
needsCodeReference: false,
|
|
62
|
+
source: content,
|
|
63
|
+
names: [],
|
|
64
|
+
originalFileName: null,
|
|
65
|
+
originalFileNames: [],
|
|
66
|
+
};
|
|
67
|
+
bundle[relativePath] = asset;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return bundle;
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
console.error(`Error loading files from ${dir}:`, error);
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Load TanStack Start build output preserving full directory structure This loads ALL
|
|
79
|
+
* files from the output directory root, maintaining their natural paths (e.g.,
|
|
80
|
+
* server/index.js, client/assets/main.js, favicon.ico)
|
|
81
|
+
*/
|
|
82
|
+
async function loadTanStackOutput(outputDir) {
|
|
83
|
+
// Load from the root output directory to preserve natural structure
|
|
84
|
+
return loadFilesFromDirectory(outputDir);
|
|
85
|
+
}
|
|
86
|
+
/** @deprecated Use loadTanStackOutput instead - this preserves the full structure */
|
|
87
|
+
async function loadServerOutput(outputDir) {
|
|
88
|
+
const serverDir = path.join(outputDir, 'server');
|
|
89
|
+
return loadFilesFromDirectory(serverDir);
|
|
90
|
+
}
|
|
91
|
+
/** @deprecated Use loadTanStackOutput instead - this preserves the full structure */
|
|
92
|
+
async function loadClientOutput(outputDir) {
|
|
93
|
+
const clientDir = path.join(outputDir, 'client');
|
|
94
|
+
return loadFilesFromDirectory(clientDir);
|
|
95
|
+
}
|
|
96
|
+
/** Check if TanStack Start output directory exists and is valid */
|
|
97
|
+
async function validateTanStackOutput(outputDir) {
|
|
98
|
+
try {
|
|
99
|
+
const serverDir = path.join(outputDir, 'server');
|
|
100
|
+
const clientDir = path.join(outputDir, 'client');
|
|
101
|
+
const [serverExists, clientExists] = await Promise.all([
|
|
102
|
+
fs
|
|
103
|
+
.access(serverDir)
|
|
104
|
+
.then(() => true)
|
|
105
|
+
.catch(() => false),
|
|
106
|
+
fs
|
|
107
|
+
.access(clientDir)
|
|
108
|
+
.then(() => true)
|
|
109
|
+
.catch(() => false),
|
|
110
|
+
]);
|
|
111
|
+
if (!serverExists) {
|
|
112
|
+
console.error(`Server output directory not found: ${serverDir}`);
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
if (!clientExists) {
|
|
116
|
+
console.warn(`Client output directory not found: ${clientDir}`);
|
|
117
|
+
// Client is optional, might be API-only
|
|
118
|
+
}
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
console.error('Error validating TanStack output:', error);
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
//# 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;;AAe/D,wDA2DC;AAOD,gDAGC;AAGD,4CAGC;AAGD,4CAGC;AAGD,wDA+BC;;AAhID,wDAAkC;AAClC,mDAA6B;AAG7B,qFAAqF;AACrF,KAAK,UAAU,WAAW,CAAC,GAAW;IACpC,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;IAChF,OAAO,OAAO;SACX,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;SACjC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,WAAC,OAAA,IAAI,CAAC,IAAI,CAAC,MAAA,KAAK,CAAC,UAAU,mCAAI,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,CAAA,EAAA,CAAC,CAAC;AAC3E,CAAC;AAED,gEAAgE;AACzD,KAAK,UAAU,sBAAsB,CAAC,GAAW;IACtD,MAAM,MAAM,GAAiB,EAAE,CAAC;IAEhC,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,MAAM,WAAW,CAAC,GAAG,CAAC,CAAC;QAErC,KAAK,MAAM,QAAQ,IAAI,KAAK,EAAE,CAAC;YAC7B,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,C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,GAAG,EAAE,CAAC,IAAI,CAAC;iBAChB,KAAK,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC;YACrB,EAAE;iBACC,MAAM,CAAC,SAAS,CAAC;iBACjB,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC;iBAChB,KAAK,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC;SACtB,CAAC,CAAC;QAEH,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,OAAO,CAAC,KAAK,CAAC,sCAAsC,SAAS,EAAE,CAAC,CAAC;YACjE,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,OAAO,CAAC,IAAI,CAAC,sCAAsC,SAAS,EAAE,CAAC,CAAC;YAChE,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,32 @@
|
|
|
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
|
+
* Server entry file path for SSR.
|
|
15
|
+
*
|
|
16
|
+
* This should be a path **relative to the TanStack Start output directory** (usually
|
|
17
|
+
* `dist/`). For example: `server/index.js`.
|
|
18
|
+
*
|
|
19
|
+
* Defaults to `server/index.js`.
|
|
20
|
+
*/
|
|
21
|
+
entrypoint?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Main Vite plugin for TanStack Start Zephyr deployment
|
|
25
|
+
*
|
|
26
|
+
* Configuration is automatically detected from:
|
|
27
|
+
*
|
|
28
|
+
* - Package.json (app name, version)
|
|
29
|
+
* - Git info (org, project, branch)
|
|
30
|
+
* - Zephyr auth (via ze login)
|
|
31
|
+
*/
|
|
32
|
+
export declare function withZephyrTanstackStart(options?: TanStackStartZephyrOptions): Plugin;
|
|
@@ -0,0 +1,156 @@
|
|
|
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
|
+
// Note: .cjs is intentionally excluded as workers don't support CommonJS
|
|
32
|
+
const typeMap = {
|
|
33
|
+
'.js': 'application/javascript',
|
|
34
|
+
'.mjs': 'application/javascript',
|
|
35
|
+
'.css': 'text/css',
|
|
36
|
+
'.html': 'text/html',
|
|
37
|
+
'.json': 'application/json',
|
|
38
|
+
};
|
|
39
|
+
return typeMap[ext] || 'application/octet-stream';
|
|
40
|
+
}
|
|
41
|
+
function normalizeEntrypoint(entrypoint) {
|
|
42
|
+
let normalized = entrypoint.trim();
|
|
43
|
+
// Normalize separators to match snapshot asset keys (posix-style).
|
|
44
|
+
normalized = normalized.split('\\').join('/');
|
|
45
|
+
// Remove common leading prefixes users may provide.
|
|
46
|
+
while (normalized.startsWith('./')) {
|
|
47
|
+
normalized = normalized.slice(2);
|
|
48
|
+
}
|
|
49
|
+
while (normalized.startsWith('/')) {
|
|
50
|
+
normalized = normalized.slice(1);
|
|
51
|
+
}
|
|
52
|
+
if (normalized.startsWith('dist/')) {
|
|
53
|
+
normalized = normalized.slice('dist/'.length);
|
|
54
|
+
}
|
|
55
|
+
return normalized;
|
|
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
|
+
function withZephyrTanstackStart(options = {}) {
|
|
67
|
+
const { zephyr_engine_defer, zephyr_defer_create } = zephyr_agent_1.ZephyrEngine.defer_create();
|
|
68
|
+
let config;
|
|
69
|
+
let outputDir;
|
|
70
|
+
let entrypoint;
|
|
71
|
+
let uploadCompleted = false; // Guard to ensure we only upload once
|
|
72
|
+
return {
|
|
73
|
+
name: 'vite-plugin-tanstack-start-zephyr',
|
|
74
|
+
enforce: 'post', // Run after TanStack Start plugin
|
|
75
|
+
configResolved(resolvedConfig) {
|
|
76
|
+
config = resolvedConfig;
|
|
77
|
+
// For TanStack Start, always use the root dist directory (contains server/ and client/)
|
|
78
|
+
// Don't use config.build.outDir as it points to dist/server/ during SSR build
|
|
79
|
+
outputDir = options.outputDir || path.join(config.root, 'dist');
|
|
80
|
+
entrypoint = normalizeEntrypoint(options.entrypoint || 'server/index.js');
|
|
81
|
+
},
|
|
82
|
+
async buildApp(builder) {
|
|
83
|
+
// Guard: Only process upload once, even if buildApp is called multiple times
|
|
84
|
+
if (uploadCompleted) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
// Initialize ZephyrEngine in buildApp (runs once) instead of configResolved (runs per environment)
|
|
88
|
+
// This ensures the engine is only created once, and start_new_build() is only called once
|
|
89
|
+
// NOTE: ZephyrEngine.create() automatically calls start_new_build()
|
|
90
|
+
const engineOptions = {
|
|
91
|
+
builder: 'vite',
|
|
92
|
+
context: config.root,
|
|
93
|
+
};
|
|
94
|
+
zephyr_defer_create(engineOptions);
|
|
95
|
+
const zephyr_engine = await zephyr_engine_defer;
|
|
96
|
+
// Log all environments and their build status for debugging
|
|
97
|
+
const environments = Object.entries(builder.environments);
|
|
98
|
+
zephyr_agent_1.ze_log.init(`buildApp hook called with ${environments.length} environment(s): ${environments.map(([name, env]) => `${name}(isBuilt=${env.isBuilt})`).join(', ')}`);
|
|
99
|
+
// Wait for all environments to be built (not just specific ones)
|
|
100
|
+
// This ensures we have all build outputs before uploading
|
|
101
|
+
const notBuilt = Object.entries(builder.environments)
|
|
102
|
+
.filter(([, env]) => !env.isBuilt)
|
|
103
|
+
.map(([name]) => name);
|
|
104
|
+
if (notBuilt.length > 0) {
|
|
105
|
+
zephyr_agent_1.ze_log.init(`Building environments that aren't built yet: ${notBuilt.join(', ')}`);
|
|
106
|
+
for (const envName of notBuilt) {
|
|
107
|
+
const env = builder.environments[envName];
|
|
108
|
+
if (env) {
|
|
109
|
+
await builder.build(env);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// Verify all environments are now built
|
|
114
|
+
const allBuilt = Object.values(builder.environments).every((env) => env.isBuilt);
|
|
115
|
+
if (!allBuilt) {
|
|
116
|
+
const stillNotBuilt = Object.entries(builder.environments)
|
|
117
|
+
.filter(([, env]) => !env.isBuilt)
|
|
118
|
+
.map(([name]) => name);
|
|
119
|
+
throw new zephyr_agent_1.ZephyrError(zephyr_agent_1.ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
120
|
+
message: `Some environments are still not built: ${stillNotBuilt.join(', ')}`,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
zephyr_agent_1.ze_log.upload('All environments built, processing output...');
|
|
124
|
+
try {
|
|
125
|
+
// Engine is already initialized above, and ZephyrEngine.create() automatically calls start_new_build()
|
|
126
|
+
// So we don't need to call start_new_build() again here
|
|
127
|
+
// Load ALL build output preserving directory structure
|
|
128
|
+
// This includes server/, client/, and any root files (favicon.ico, etc.)
|
|
129
|
+
// Note: We read from disk here (via loadTanStackOutput) rather than using Vite's
|
|
130
|
+
// generateBundle hook because TanStack Start uses multiple Vite environments
|
|
131
|
+
// (client, server, etc.) that build separately. The buildApp hook runs after
|
|
132
|
+
// all environments are complete, making disk reading the simplest approach
|
|
133
|
+
// that's consistent with vite-plugin-zephyr's loadStaticAssets pattern.
|
|
134
|
+
const bundle = await (0, load_tanstack_output_1.loadTanStackOutput)(outputDir);
|
|
135
|
+
const assetsMap = (0, zephyr_agent_1.buildAssetsMap)(bundle, extractBuffer, getAssetType);
|
|
136
|
+
zephyr_agent_1.ze_log.upload(`Uploading ${Object.keys(assetsMap).length} assets...`);
|
|
137
|
+
// Upload assets with SSR snapshot type
|
|
138
|
+
await zephyr_engine.upload_assets({
|
|
139
|
+
assetsMap,
|
|
140
|
+
buildStats: await (0, zephyr_agent_1.zeBuildDashData)(zephyr_engine),
|
|
141
|
+
snapshotType: 'ssr',
|
|
142
|
+
entrypoint,
|
|
143
|
+
});
|
|
144
|
+
// Finish build
|
|
145
|
+
await zephyr_engine.build_finished();
|
|
146
|
+
// Mark upload as completed to prevent multiple calls
|
|
147
|
+
uploadCompleted = true;
|
|
148
|
+
zephyr_agent_1.ze_log.upload('Deployment successful!');
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
(0, zephyr_agent_1.handleGlobalError)(error);
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
//# 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;;AAgGtE,0DA+GC;;AA5MD,mDAA6B;AAC7B,+CASsB;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;AA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,CAAC;YAED,qBAAM,CAAC,MAAM,CAAC,8CAA8C,CAAC,CAAC;YAE9D,IAAI,CAAC;gBACH,uGAAuG;gBACvG,wDAAwD;gBAExD,uDAAuD;gBACvD,yEAAyE;gBACzE,iFAAiF;gBACjF,6EAA6E;gBAC7E,6EAA6E;gBAC7E,2EAA2E;gBAC3E,wEAAwE;gBACxE,MAAM,MAAM,GAAG,MAAM,IAAA,yCAAkB,EAAC,SAAS,CAAC,CAAC;gBAEnD,MAAM,SAAS,GAAG,IAAA,6BAAc,EAAC,MAAM,EAAE,aAAa,EAAE,YAAY,CAAC,CAAC;gBAEtE,qBAAM,CAAC,MAAM,CAAC,aAAa,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM,YAAY,CAAC,CAAC;gBAEtE,uCAAuC;gBACvC,MAAM,aAAa,CAAC,aAAa,CAAC;oBAChC,SAAS;oBACT,UAAU,EAAE,MAAM,IAAA,8BAAe,EAAC,aAAa,CAAC;oBAChD,YAAY,EAAE,KAAK;oBACnB,UAAU;iBACX,CAAC,CAAC;gBAEH,eAAe;gBACf,MAAM,aAAa,CAAC,cAAc,EAAE,CAAC;gBAErC,qDAAqD;gBACrD,eAAe,GAAG,IAAI,CAAC;gBAEvB,qBAAM,CAAC,MAAM,CAAC,wBAAwB,CAAC,CAAC;YAC1C,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAA,gCAAiB,EAAC,KAAK,CAAC,CAAC;YAC3B,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/react-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.9.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
CHANGED
|
@@ -1,23 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-tanstack-start-zephyr",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
5
|
-
"homepage": "https://github.com/ZephyrCloudIO/zephyr-packages#readme",
|
|
6
|
-
"bugs": {
|
|
7
|
-
"url": "https://github.com/ZephyrCloudIO/zephyr-packages/issues"
|
|
8
|
-
},
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Vite plugin for Zephyr with TanStack Start support",
|
|
9
5
|
"repository": {
|
|
10
6
|
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/ZephyrCloudIO/zephyr-packages.git"
|
|
7
|
+
"url": "git+https://github.com/ZephyrCloudIO/zephyr-packages.git",
|
|
8
|
+
"directory": "libs/vite-plugin-tanstack-start-zephyr"
|
|
12
9
|
},
|
|
13
10
|
"license": "Apache-2.0",
|
|
14
|
-
"author":
|
|
11
|
+
"author": {
|
|
12
|
+
"name": "ZephyrCloudIO",
|
|
13
|
+
"url": "https://github.com/ZephyrCloudIO"
|
|
14
|
+
},
|
|
15
15
|
"type": "commonjs",
|
|
16
|
-
"main": "index.js",
|
|
17
|
-
"
|
|
18
|
-
|
|
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.1.3"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"@tanstack/react-start": "^1.0.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "^22.13.11"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public",
|
|
31
|
+
"provenance": true
|
|
19
32
|
},
|
|
20
33
|
"scripts": {
|
|
21
|
-
"
|
|
34
|
+
"build": "nx run vite-plugin-tanstack-start-zephyr:build",
|
|
35
|
+
"patch-version": "pnpm version"
|
|
22
36
|
}
|
|
23
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,131 @@
|
|
|
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 using Node.js native recursive option */
|
|
8
|
+
async function getAllFiles(dir: string): Promise<string[]> {
|
|
9
|
+
const entries = await fs.readdir(dir, { recursive: true, withFileTypes: true });
|
|
10
|
+
return entries
|
|
11
|
+
.filter((entry) => entry.isFile())
|
|
12
|
+
.map((entry) => path.join(entry.parentPath ?? entry.path, entry.name));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Load files from directory into Rollup OutputBundle format */
|
|
16
|
+
export async function loadFilesFromDirectory(dir: string): Promise<OutputBundle> {
|
|
17
|
+
const bundle: OutputBundle = {};
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
const files = await getAllFiles(dir);
|
|
21
|
+
|
|
22
|
+
for (const filePath of files) {
|
|
23
|
+
const relativePath = path.relative(dir, filePath);
|
|
24
|
+
const content = await fs.readFile(filePath);
|
|
25
|
+
const ext = path.extname(filePath);
|
|
26
|
+
|
|
27
|
+
// Determine if this is a code chunk or asset
|
|
28
|
+
const isCode = ext === '.js' || ext === '.mjs' || ext === '.cjs';
|
|
29
|
+
|
|
30
|
+
if (isCode) {
|
|
31
|
+
// Create OutputChunk for code files
|
|
32
|
+
const chunk: OutputChunk = {
|
|
33
|
+
type: 'chunk',
|
|
34
|
+
fileName: relativePath,
|
|
35
|
+
name: path.basename(relativePath, ext),
|
|
36
|
+
code: content.toString('utf-8'),
|
|
37
|
+
isEntry: relativePath === 'index.js' || relativePath.includes('index'),
|
|
38
|
+
isDynamicEntry: false,
|
|
39
|
+
facadeModuleId: null,
|
|
40
|
+
moduleIds: [],
|
|
41
|
+
exports: [],
|
|
42
|
+
imports: [],
|
|
43
|
+
dynamicImports: [],
|
|
44
|
+
implicitlyLoadedBefore: [],
|
|
45
|
+
importedBindings: {},
|
|
46
|
+
referencedFiles: [],
|
|
47
|
+
modules: {},
|
|
48
|
+
map: null,
|
|
49
|
+
sourcemapFileName: null,
|
|
50
|
+
preliminaryFileName: relativePath,
|
|
51
|
+
isImplicitEntry: false,
|
|
52
|
+
};
|
|
53
|
+
bundle[relativePath] = chunk;
|
|
54
|
+
} else {
|
|
55
|
+
// Create OutputAsset for non-code files
|
|
56
|
+
const asset: OutputAsset = {
|
|
57
|
+
type: 'asset',
|
|
58
|
+
fileName: relativePath,
|
|
59
|
+
name: relativePath,
|
|
60
|
+
needsCodeReference: false,
|
|
61
|
+
source: content,
|
|
62
|
+
names: [],
|
|
63
|
+
originalFileName: null,
|
|
64
|
+
originalFileNames: [],
|
|
65
|
+
};
|
|
66
|
+
bundle[relativePath] = asset;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return bundle;
|
|
71
|
+
} catch (error) {
|
|
72
|
+
console.error(`Error loading files from ${dir}:`, error);
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Load TanStack Start build output preserving full directory structure This loads ALL
|
|
79
|
+
* files from the output directory root, maintaining their natural paths (e.g.,
|
|
80
|
+
* server/index.js, client/assets/main.js, favicon.ico)
|
|
81
|
+
*/
|
|
82
|
+
export async function loadTanStackOutput(outputDir: string): Promise<OutputBundle> {
|
|
83
|
+
// Load from the root output directory to preserve natural structure
|
|
84
|
+
return loadFilesFromDirectory(outputDir);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** @deprecated Use loadTanStackOutput instead - this preserves the full structure */
|
|
88
|
+
export async function loadServerOutput(outputDir: string): Promise<OutputBundle> {
|
|
89
|
+
const serverDir = path.join(outputDir, 'server');
|
|
90
|
+
return loadFilesFromDirectory(serverDir);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** @deprecated Use loadTanStackOutput instead - this preserves the full structure */
|
|
94
|
+
export async function loadClientOutput(outputDir: string): Promise<OutputBundle> {
|
|
95
|
+
const clientDir = path.join(outputDir, 'client');
|
|
96
|
+
return loadFilesFromDirectory(clientDir);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Check if TanStack Start output directory exists and is valid */
|
|
100
|
+
export async function validateTanStackOutput(outputDir: string): Promise<boolean> {
|
|
101
|
+
try {
|
|
102
|
+
const serverDir = path.join(outputDir, 'server');
|
|
103
|
+
const clientDir = path.join(outputDir, 'client');
|
|
104
|
+
|
|
105
|
+
const [serverExists, clientExists] = await Promise.all([
|
|
106
|
+
fs
|
|
107
|
+
.access(serverDir)
|
|
108
|
+
.then(() => true)
|
|
109
|
+
.catch(() => false),
|
|
110
|
+
fs
|
|
111
|
+
.access(clientDir)
|
|
112
|
+
.then(() => true)
|
|
113
|
+
.catch(() => false),
|
|
114
|
+
]);
|
|
115
|
+
|
|
116
|
+
if (!serverExists) {
|
|
117
|
+
console.error(`Server output directory not found: ${serverDir}`);
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (!clientExists) {
|
|
122
|
+
console.warn(`Client output directory not found: ${clientDir}`);
|
|
123
|
+
// Client is optional, might be API-only
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return true;
|
|
127
|
+
} catch (error) {
|
|
128
|
+
console.error('Error validating TanStack output:', error);
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
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
|
+
ze_log,
|
|
13
|
+
handleGlobalError,
|
|
14
|
+
} from 'zephyr-agent';
|
|
15
|
+
import { loadTanStackOutput } from './internal/extract/load-tanstack-output';
|
|
16
|
+
|
|
17
|
+
/** Extract buffer from Rollup output */
|
|
18
|
+
function extractBuffer(item: any): Buffer {
|
|
19
|
+
if (item.type === 'chunk') {
|
|
20
|
+
return Buffer.from(item.code, 'utf-8');
|
|
21
|
+
} else if (item.type === 'asset') {
|
|
22
|
+
if (typeof item.source === 'string') {
|
|
23
|
+
return Buffer.from(item.source, 'utf-8');
|
|
24
|
+
} else if (Buffer.isBuffer(item.source)) {
|
|
25
|
+
return item.source;
|
|
26
|
+
} else {
|
|
27
|
+
return Buffer.from(item.source);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return Buffer.from('');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Get asset type from Rollup output item */
|
|
34
|
+
function getAssetType(item: { fileName?: string; name?: string }): string {
|
|
35
|
+
const fileName = item.fileName || item.name || '';
|
|
36
|
+
const ext = path.extname(fileName).toLowerCase();
|
|
37
|
+
// Note: .cjs is intentionally excluded as workers don't support CommonJS
|
|
38
|
+
const typeMap: Record<string, string> = {
|
|
39
|
+
'.js': 'application/javascript',
|
|
40
|
+
'.mjs': 'application/javascript',
|
|
41
|
+
'.css': 'text/css',
|
|
42
|
+
'.html': 'text/html',
|
|
43
|
+
'.json': 'application/json',
|
|
44
|
+
};
|
|
45
|
+
return typeMap[ext] || 'application/octet-stream';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Plugin options for TanStack Start Zephyr deployment All configuration is handled
|
|
50
|
+
* automatically by ZephyrEngine via package.json and git info
|
|
51
|
+
*/
|
|
52
|
+
export interface TanStackStartZephyrOptions {
|
|
53
|
+
/**
|
|
54
|
+
* Optional output directory override Defaults to 'dist' relative to project root
|
|
55
|
+
* (TanStack Start default)
|
|
56
|
+
*/
|
|
57
|
+
outputDir?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Server entry file path for SSR.
|
|
60
|
+
*
|
|
61
|
+
* This should be a path **relative to the TanStack Start output directory** (usually
|
|
62
|
+
* `dist/`). For example: `server/index.js`.
|
|
63
|
+
*
|
|
64
|
+
* Defaults to `server/index.js`.
|
|
65
|
+
*/
|
|
66
|
+
entrypoint?: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function normalizeEntrypoint(entrypoint: string): string {
|
|
70
|
+
let normalized = entrypoint.trim();
|
|
71
|
+
// Normalize separators to match snapshot asset keys (posix-style).
|
|
72
|
+
normalized = normalized.split('\\').join('/');
|
|
73
|
+
|
|
74
|
+
// Remove common leading prefixes users may provide.
|
|
75
|
+
while (normalized.startsWith('./')) {
|
|
76
|
+
normalized = normalized.slice(2);
|
|
77
|
+
}
|
|
78
|
+
while (normalized.startsWith('/')) {
|
|
79
|
+
normalized = normalized.slice(1);
|
|
80
|
+
}
|
|
81
|
+
if (normalized.startsWith('dist/')) {
|
|
82
|
+
normalized = normalized.slice('dist/'.length);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return normalized;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Main Vite plugin for TanStack Start Zephyr deployment
|
|
90
|
+
*
|
|
91
|
+
* Configuration is automatically detected from:
|
|
92
|
+
*
|
|
93
|
+
* - Package.json (app name, version)
|
|
94
|
+
* - Git info (org, project, branch)
|
|
95
|
+
* - Zephyr auth (via ze login)
|
|
96
|
+
*/
|
|
97
|
+
export function withZephyrTanstackStart(
|
|
98
|
+
options: TanStackStartZephyrOptions = {}
|
|
99
|
+
): Plugin {
|
|
100
|
+
const { zephyr_engine_defer, zephyr_defer_create } = ZephyrEngine.defer_create();
|
|
101
|
+
let config: ResolvedConfig;
|
|
102
|
+
let outputDir: string;
|
|
103
|
+
let entrypoint: string;
|
|
104
|
+
let uploadCompleted = false; // Guard to ensure we only upload once
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
name: 'vite-plugin-tanstack-start-zephyr',
|
|
108
|
+
enforce: 'post', // Run after TanStack Start plugin
|
|
109
|
+
|
|
110
|
+
configResolved(resolvedConfig) {
|
|
111
|
+
config = resolvedConfig;
|
|
112
|
+
|
|
113
|
+
// For TanStack Start, always use the root dist directory (contains server/ and client/)
|
|
114
|
+
// Don't use config.build.outDir as it points to dist/server/ during SSR build
|
|
115
|
+
outputDir = options.outputDir || path.join(config.root, 'dist');
|
|
116
|
+
entrypoint = normalizeEntrypoint(options.entrypoint || 'server/index.js');
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
async buildApp(builder) {
|
|
120
|
+
// Guard: Only process upload once, even if buildApp is called multiple times
|
|
121
|
+
if (uploadCompleted) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Initialize ZephyrEngine in buildApp (runs once) instead of configResolved (runs per environment)
|
|
126
|
+
// This ensures the engine is only created once, and start_new_build() is only called once
|
|
127
|
+
// NOTE: ZephyrEngine.create() automatically calls start_new_build()
|
|
128
|
+
const engineOptions: ZephyrEngineOptions = {
|
|
129
|
+
builder: 'vite',
|
|
130
|
+
context: config.root,
|
|
131
|
+
};
|
|
132
|
+
zephyr_defer_create(engineOptions);
|
|
133
|
+
const zephyr_engine = await zephyr_engine_defer;
|
|
134
|
+
// Log all environments and their build status for debugging
|
|
135
|
+
const environments = Object.entries(builder.environments);
|
|
136
|
+
ze_log.init(
|
|
137
|
+
`buildApp hook called with ${environments.length} environment(s): ${environments.map(([name, env]) => `${name}(isBuilt=${env.isBuilt})`).join(', ')}`
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
// Wait for all environments to be built (not just specific ones)
|
|
141
|
+
// This ensures we have all build outputs before uploading
|
|
142
|
+
const notBuilt = Object.entries(builder.environments)
|
|
143
|
+
.filter(([, env]) => !env.isBuilt)
|
|
144
|
+
.map(([name]) => name);
|
|
145
|
+
|
|
146
|
+
if (notBuilt.length > 0) {
|
|
147
|
+
ze_log.init(
|
|
148
|
+
`Building environments that aren't built yet: ${notBuilt.join(', ')}`
|
|
149
|
+
);
|
|
150
|
+
for (const envName of notBuilt) {
|
|
151
|
+
const env = builder.environments[envName];
|
|
152
|
+
if (env) {
|
|
153
|
+
await builder.build(env);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Verify all environments are now built
|
|
159
|
+
const allBuilt = Object.values(builder.environments).every((env) => env.isBuilt);
|
|
160
|
+
if (!allBuilt) {
|
|
161
|
+
const stillNotBuilt = Object.entries(builder.environments)
|
|
162
|
+
.filter(([, env]) => !env.isBuilt)
|
|
163
|
+
.map(([name]) => name);
|
|
164
|
+
throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
165
|
+
message: `Some environments are still not built: ${stillNotBuilt.join(', ')}`,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
ze_log.upload('All environments built, processing output...');
|
|
170
|
+
|
|
171
|
+
try {
|
|
172
|
+
// Engine is already initialized above, and ZephyrEngine.create() automatically calls start_new_build()
|
|
173
|
+
// So we don't need to call start_new_build() again here
|
|
174
|
+
|
|
175
|
+
// Load ALL build output preserving directory structure
|
|
176
|
+
// This includes server/, client/, and any root files (favicon.ico, etc.)
|
|
177
|
+
// Note: We read from disk here (via loadTanStackOutput) rather than using Vite's
|
|
178
|
+
// generateBundle hook because TanStack Start uses multiple Vite environments
|
|
179
|
+
// (client, server, etc.) that build separately. The buildApp hook runs after
|
|
180
|
+
// all environments are complete, making disk reading the simplest approach
|
|
181
|
+
// that's consistent with vite-plugin-zephyr's loadStaticAssets pattern.
|
|
182
|
+
const bundle = await loadTanStackOutput(outputDir);
|
|
183
|
+
|
|
184
|
+
const assetsMap = buildAssetsMap(bundle, extractBuffer, getAssetType);
|
|
185
|
+
|
|
186
|
+
ze_log.upload(`Uploading ${Object.keys(assetsMap).length} assets...`);
|
|
187
|
+
|
|
188
|
+
// Upload assets with SSR snapshot type
|
|
189
|
+
await zephyr_engine.upload_assets({
|
|
190
|
+
assetsMap,
|
|
191
|
+
buildStats: await zeBuildDashData(zephyr_engine),
|
|
192
|
+
snapshotType: 'ssr',
|
|
193
|
+
entrypoint,
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
// Finish build
|
|
197
|
+
await zephyr_engine.build_finished();
|
|
198
|
+
|
|
199
|
+
// Mark upload as completed to prevent multiple calls
|
|
200
|
+
uploadCompleted = true;
|
|
201
|
+
|
|
202
|
+
ze_log.upload('Deployment successful!');
|
|
203
|
+
} catch (error) {
|
|
204
|
+
handleGlobalError(error);
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
}
|
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
|
+
}
|