@lark-apaas/fullstack-cli 1.1.62-alpha.20260824233147 → 1.1.62-alpha.20260825053208

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/fullstack-cli",
3
- "version": "1.1.62-alpha.20260824233147",
3
+ "version": "1.1.62-alpha.20260825053208",
4
4
  "description": "CLI tool for fullstack template management",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -0,0 +1,63 @@
1
+ import { randomBytes } from 'node:crypto';
2
+
3
+ export const bundledDevMaterializationHeader =
4
+ 'x-miaoda-bundled-dev-materialization';
5
+
6
+ function requestHeader(request, name) {
7
+ const value = request.headers?.[name];
8
+ if (Array.isArray(value)) return value[0] || '';
9
+ return String(value || '');
10
+ }
11
+
12
+ export function createBundledDevMaterializationToken() {
13
+ return randomBytes(24).toString('base64url');
14
+ }
15
+
16
+ export function isBundledDevNavigationRequest(request) {
17
+ const method = String(request.method || 'GET').toUpperCase();
18
+ if (method !== 'GET' && method !== 'HEAD') return false;
19
+ const destination = requestHeader(request, 'sec-fetch-dest')
20
+ .toLowerCase()
21
+ .trim();
22
+ const accept = requestHeader(request, 'accept').toLowerCase();
23
+ return (
24
+ destination === 'document' ||
25
+ destination === 'iframe' ||
26
+ accept.includes('text/html')
27
+ );
28
+ }
29
+
30
+ export function createBundledDevNavigationGate(
31
+ materializationPromise,
32
+ bypassToken
33
+ ) {
34
+ return (request, _response, next) => {
35
+ try {
36
+ if (
37
+ requestHeader(request, bundledDevMaterializationHeader) ===
38
+ bypassToken ||
39
+ !isBundledDevNavigationRequest(request)
40
+ ) {
41
+ next();
42
+ return;
43
+ }
44
+ Promise.resolve(materializationPromise).then(
45
+ () => next(),
46
+ error => next(error)
47
+ );
48
+ } catch (error) {
49
+ next(error);
50
+ }
51
+ };
52
+ }
53
+
54
+ export function waitWithTimeout(promise, timeoutMs, timeoutMessage) {
55
+ let timeout;
56
+ const timeoutPromise = new Promise((_, reject) => {
57
+ timeout = setTimeout(() => reject(new Error(timeoutMessage)), timeoutMs);
58
+ timeout.unref?.();
59
+ });
60
+ return Promise.race([Promise.resolve(promise), timeoutPromise]).finally(() =>
61
+ clearTimeout(timeout)
62
+ );
63
+ }
@@ -3,6 +3,12 @@ import { createRequire } from 'node:module';
3
3
  import path from 'node:path';
4
4
  import { pathToFileURL } from 'node:url';
5
5
  import { defineConfig, mergeConfig } from 'vite';
6
+ import {
7
+ bundledDevMaterializationHeader,
8
+ createBundledDevMaterializationToken,
9
+ createBundledDevNavigationGate,
10
+ waitWithTimeout,
11
+ } from './vite-bundled-dev-navigation-gate.mjs';
6
12
  import workspaceConfig from '../vite.config.ts';
7
13
 
8
14
  const projectRoot = path.resolve(
@@ -43,7 +49,7 @@ const persistentCacheDir = path.resolve(
43
49
  );
44
50
  const ephemeralCacheDir = path.resolve(
45
51
  process.env.MIAODA_VITE_EPHEMERAL_CACHE_DIR ||
46
- '/tmp/miaoda-vite-deps-ephemeral'
52
+ path.join(projectRoot, 'node_modules', '.vite', 'miaoda-ephemeral')
47
53
  );
48
54
  const platformVitePresetEntry = path.resolve(
49
55
  process.env.MIAODA_PLATFORM_VITE_PRESET_ENTRY ||
@@ -122,15 +128,17 @@ function cpuMilliseconds(microseconds) {
122
128
 
123
129
  function bundledDevMaterializationPlugin() {
124
130
  let config;
131
+ const bundledDevMaterializationToken = createBundledDevMaterializationToken();
125
132
  return {
126
133
  name: 'miaoda-vite-bundled-dev-materialization',
134
+ enforce: 'pre',
127
135
  apply: 'serve',
128
136
  configResolved(resolvedConfig) {
129
137
  config = resolvedConfig;
130
138
  },
131
139
  configureServer(server) {
132
140
  if (!devBundleEnabled) return;
133
- void (async () => {
141
+ const bundledDevMaterializationPromise = (async () => {
134
142
  const materializationStartedAt = process.hrtime.bigint();
135
143
  const serverAddressWaitStartedAt = process.hrtime.bigint();
136
144
  const serverAddressWaitCpuStartedAt = process.cpuUsage();
@@ -153,7 +161,11 @@ function bundledDevMaterializationPlugin() {
153
161
  }
154
162
  const postListenInitialBuildStartedAt = process.hrtime.bigint();
155
163
  const postListenInitialBuildCpuStartedAt = process.cpuUsage();
156
- await bundledDev.waitForInitialBuildFinish();
164
+ await waitWithTimeout(
165
+ bundledDev.waitForInitialBuildFinish(),
166
+ 60_000,
167
+ 'MIAODA_VITE_BUNDLED_DEV_INITIAL_BUILD_TIMEOUT'
168
+ );
157
169
  const postListenInitialBuildWaitMs = elapsedMilliseconds(
158
170
  postListenInitialBuildStartedAt
159
171
  );
@@ -176,7 +188,12 @@ function bundledDevMaterializationPlugin() {
176
188
  const documentFetchStartedAt = process.hrtime.bigint();
177
189
  const response = await fetch(
178
190
  `http://127.0.0.1:${address.port}${documentPath}`,
179
- { headers: { 'sec-fetch-dest': 'document' } }
191
+ {
192
+ headers: {
193
+ 'sec-fetch-dest': 'document',
194
+ [bundledDevMaterializationHeader]: bundledDevMaterializationToken,
195
+ },
196
+ }
180
197
  );
181
198
  const documentFetchMs = elapsedMilliseconds(documentFetchStartedAt);
182
199
  if (!response.ok) {
@@ -224,7 +241,14 @@ function bundledDevMaterializationPlugin() {
224
241
  pluginConfigureToMaterializedMs,
225
242
  })}\n`
226
243
  );
227
- })().catch(error => {
244
+ })();
245
+ server.middlewares.use(
246
+ createBundledDevNavigationGate(
247
+ bundledDevMaterializationPromise,
248
+ bundledDevMaterializationToken
249
+ )
250
+ );
251
+ void bundledDevMaterializationPromise.catch(error => {
228
252
  process.stderr.write(
229
253
  `${JSON.stringify({
230
254
  event: 'miaoda_vite_bundled_dev_materialization_failed',
@@ -553,9 +577,9 @@ export default defineConfig(async configEnv => {
553
577
  mergeConfig(cachePolicy, warmupPolicy)
554
578
  );
555
579
  resolved.plugins = [
580
+ bundledDevMaterializationPlugin(),
556
581
  ...(await usePlatformBundledDevCompatibility(resolved.plugins || [])),
557
582
  activeWarmupPlugin(),
558
- bundledDevMaterializationPlugin(),
559
583
  cachePolicyEvidencePlugin(),
560
584
  runtimePolicyEvidencePlugin(),
561
585
  ];
@@ -48,7 +48,7 @@ const viteRuntimeConfig = path.join(
48
48
  );
49
49
  const viteEphemeralCacheDir =
50
50
  process.env.MIAODA_VITE_EPHEMERAL_CACHE_DIR ||
51
- '/tmp/miaoda-vite-deps-ephemeral';
51
+ path.join(projectRoot, 'node_modules', '.vite', 'miaoda-ephemeral');
52
52
  const bundledDevOutputFile = path.join(
53
53
  projectRoot,
54
54
  'dist',