vite-plugin-taro 0.3.2 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +44 -0
- package/README.md +22 -497
- package/client.d.ts +9 -0
- package/dist/node/plugins/client/client-taro.d.ts +4 -0
- package/dist/node/plugins/client/client-taro.js +19 -0
- package/dist/node/plugins/client/constant.d.ts +4 -0
- package/dist/node/plugins/client/constant.js +4 -0
- package/dist/node/plugins/conditional/conditional-directives.d.ts +4 -0
- package/dist/node/plugins/{conditional-directives.js → conditional/conditional-directives.js} +27 -11
- package/dist/node/plugins/css/plugins.d.ts +4 -0
- package/dist/node/plugins/css/plugins.js +84 -0
- package/dist/node/plugins/h5/constant.d.ts +2 -0
- package/dist/node/plugins/h5/constant.js +3 -0
- package/dist/node/plugins/h5/plugins.d.ts +4 -0
- package/dist/node/plugins/h5/plugins.js +161 -0
- package/dist/node/plugins/h5/resolver/module-resolver.d.ts +14 -0
- package/dist/node/plugins/h5/resolver/module-resolver.js +19 -0
- package/dist/node/plugins/h5/transform-app.d.ts +10 -0
- package/dist/node/plugins/h5/transform-app.js +48 -0
- package/dist/node/plugins/wx/dev/dev-host.d.ts +15 -0
- package/dist/node/plugins/wx/dev/dev-host.js +352 -0
- package/dist/node/plugins/wx/dev/hmr-files.d.ts +28 -0
- package/dist/node/plugins/wx/dev/hmr-files.js +34 -0
- package/dist/node/plugins/wx/dev/patch-publisher.d.ts +22 -0
- package/dist/node/plugins/wx/dev/patch-publisher.js +40 -0
- package/dist/node/plugins/wx/dev/plugin.d.ts +7 -0
- package/dist/node/plugins/wx/dev/plugin.js +73 -0
- package/dist/node/plugins/wx/dev/react-refresh.d.ts +20 -0
- package/dist/node/plugins/wx/dev/react-refresh.js +198 -0
- package/dist/node/plugins/wx/module.d.ts +45 -0
- package/dist/node/plugins/wx/module.js +67 -0
- package/dist/node/plugins/wx/native/compile-native-component-interface.d.ts +21 -0
- package/dist/node/plugins/wx/native/compile-native-component-interface.js +29 -0
- package/dist/node/plugins/wx/native/create-native-component-output.d.ts +15 -0
- package/dist/node/plugins/wx/native/create-native-component-output.js +39 -0
- package/dist/node/plugins/wx/native/native-component-assets.d.ts +26 -0
- package/dist/node/plugins/wx/native/native-component-assets.js +76 -0
- package/dist/node/plugins/wx/native/native-component-interface.d.ts +12 -0
- package/dist/node/plugins/wx/native/native-component-interface.js +201 -0
- package/dist/node/plugins/wx/output/files.d.ts +12 -0
- package/dist/node/plugins/wx/output/files.js +12 -0
- package/dist/node/plugins/wx/output/json.d.ts +14 -0
- package/dist/node/plugins/wx/output/json.js +52 -0
- package/dist/node/plugins/wx/output/relative-root.d.ts +2 -0
- package/dist/node/plugins/wx/output/relative-root.js +6 -0
- package/dist/node/plugins/wx/output/templates.d.ts +7 -0
- package/dist/node/plugins/wx/output/templates.js +100 -0
- package/dist/node/plugins/wx/placement/placer.d.ts +78 -0
- package/dist/node/plugins/wx/placement/placer.js +145 -0
- package/dist/node/plugins/wx/placement/plan.d.ts +46 -0
- package/dist/node/plugins/wx/placement/plan.js +210 -0
- package/dist/node/plugins/wx/plugins.d.ts +4 -0
- package/dist/node/plugins/wx/plugins.js +137 -0
- package/dist/node/plugins/wx/render/capsule-wrapper.d.ts +3 -0
- package/dist/node/plugins/wx/render/capsule-wrapper.js +64 -0
- package/dist/node/plugins/wx/render/capsule.d.ts +4 -0
- package/dist/node/plugins/wx/render/capsule.js +13 -0
- package/dist/node/plugins/wx/render/native.d.ts +9 -0
- package/dist/node/plugins/wx/render/native.js +45 -0
- package/dist/node/plugins/wx/render/transport.d.ts +17 -0
- package/dist/node/plugins/wx/render/transport.js +94 -0
- package/dist/node/plugins/wx/resolve/resolver.d.ts +7 -0
- package/dist/node/plugins/wx/resolve/resolver.js +86 -0
- package/dist/node/plugins/wx/resolve/specialize-bootstrap.d.ts +9 -0
- package/dist/node/plugins/wx/resolve/specialize-bootstrap.js +9 -0
- package/dist/node/plugins/wx/resolve/specialize-page-capsule.d.ts +9 -0
- package/dist/node/plugins/wx/resolve/specialize-page-capsule.js +11 -0
- package/dist/node/utils/constant.d.ts +1 -0
- package/dist/node/utils/constant.js +1 -0
- package/dist/node/utils/memoize.d.ts +122 -0
- package/dist/node/utils/memoize.js +86 -0
- package/dist/node/utils/modules.d.ts +20 -24
- package/dist/node/utils/modules.js +21 -34
- package/dist/node/utils/once.d.ts +10 -0
- package/dist/node/utils/once.js +20 -0
- package/dist/node/utils/packages.d.ts +1 -0
- package/dist/node/utils/packages.js +3 -2
- package/dist/node/utils/project-config.d.ts +3 -0
- package/dist/node/utils/project-config.js +8 -0
- package/dist/node/utils/serialized-task-queue.d.ts +9 -0
- package/dist/node/utils/serialized-task-queue.js +17 -0
- package/dist/node/utils/transform.d.ts +11 -0
- package/dist/node/utils/transform.js +58 -0
- package/dist/node/vite-plugin.d.ts +1 -1
- package/dist/node/vite-plugin.js +11 -27
- package/dist/options.d.ts +3 -4
- package/dist/runtime/{taro → client/taro}/api.d.ts +0 -1
- package/dist/runtime/client/taro/api.js +9 -0
- package/dist/runtime/client/taro/component.d.ts +1 -0
- package/dist/runtime/client/taro/component.js +1 -0
- package/dist/runtime/client/taro/define-native-component.d.ts +7 -0
- package/dist/runtime/client/taro/define-native-component.js +4 -0
- package/dist/runtime/h5/app.d.ts +2 -0
- package/dist/runtime/h5/app.js +15 -0
- package/dist/runtime/h5/taro-runtime.d.ts +1 -1
- package/dist/runtime/h5/taro-runtime.js +1 -4
- package/dist/runtime/wx/amphibious/bootstrap.d.ts +4 -0
- package/dist/runtime/wx/amphibious/bootstrap.js +16 -0
- package/dist/runtime/wx/amphibious/transport.d.ts +2 -0
- package/dist/runtime/wx/amphibious/transport.js +4 -0
- package/dist/runtime/wx/capsule/app.d.ts +2 -0
- package/dist/runtime/wx/capsule/app.js +7 -0
- package/dist/runtime/wx/capsule/component.d.ts +3 -0
- package/dist/runtime/wx/capsule/component.js +4 -0
- package/dist/runtime/wx/capsule/page.d.ts +3 -0
- package/dist/runtime/wx/capsule/page.js +68 -0
- package/dist/runtime/wx/capsule/taro-runtime.d.ts +6 -0
- package/dist/runtime/wx/capsule/taro-runtime.js +6 -0
- package/dist/runtime/wx/dev/dev-runtime.d.ts +1 -0
- package/dist/runtime/wx/dev/dev-runtime.js +246 -0
- package/dist/runtime/wx/native/app.d.ts +1 -0
- package/dist/runtime/wx/native/app.js +3 -0
- package/dist/runtime/wx/native/component.d.ts +1 -0
- package/dist/runtime/wx/native/component.js +3 -0
- package/dist/runtime/wx/native/page.d.ts +1 -0
- package/dist/runtime/wx/native/page.js +4 -0
- package/dist/runtime/wx/systemjs/system-core.d.ts +4 -0
- package/dist/runtime/wx/systemjs/system-core.js +331 -0
- package/package.json +21 -14
- package/src/node/plugins/client/client-taro.ts +23 -0
- package/src/node/plugins/client/constant.ts +5 -0
- package/src/node/plugins/{conditional-directives.ts → conditional/conditional-directives.ts} +33 -13
- package/src/node/plugins/css/plugins.ts +96 -0
- package/src/node/plugins/h5/constant.ts +4 -0
- package/src/node/plugins/h5/plugins.ts +197 -0
- package/src/node/plugins/h5/resolver/module-resolver.ts +32 -0
- package/src/node/plugins/h5/transform-app.ts +90 -0
- package/src/node/plugins/wx/dev/dev-host.ts +448 -0
- package/src/node/plugins/wx/dev/hmr-files.ts +55 -0
- package/src/node/plugins/wx/dev/patch-publisher.ts +49 -0
- package/src/node/plugins/wx/dev/plugin.ts +82 -0
- package/src/node/plugins/wx/dev/react-refresh.ts +227 -0
- package/src/node/plugins/wx/module.ts +98 -0
- package/src/node/plugins/wx/native/compile-native-component-interface.ts +47 -0
- package/src/node/plugins/wx/native/create-native-component-output.ts +57 -0
- package/src/node/plugins/wx/native/native-component-assets.ts +114 -0
- package/src/node/plugins/wx/native/native-component-interface.ts +265 -0
- package/src/node/plugins/wx/output/files.ts +27 -0
- package/src/node/plugins/wx/output/json.ts +79 -0
- package/src/node/plugins/wx/output/relative-root.ts +7 -0
- package/src/node/plugins/wx/output/templates.ts +141 -0
- package/src/node/plugins/wx/placement/placer.ts +172 -0
- package/src/node/plugins/wx/placement/plan.ts +306 -0
- package/src/node/plugins/wx/plugins.ts +165 -0
- package/src/node/plugins/wx/render/capsule-wrapper.ts +86 -0
- package/src/node/plugins/wx/render/capsule.ts +21 -0
- package/src/node/plugins/wx/render/native.ts +84 -0
- package/src/node/plugins/wx/render/transport.ts +157 -0
- package/src/node/plugins/wx/resolve/resolver.ts +125 -0
- package/src/node/plugins/wx/resolve/specialize-bootstrap.ts +27 -0
- package/src/node/plugins/wx/resolve/specialize-page-capsule.ts +29 -0
- package/src/node/utils/constant.ts +1 -0
- package/src/node/utils/memoize.ts +149 -0
- package/src/node/utils/modules.ts +36 -38
- package/src/node/utils/once.ts +21 -0
- package/src/node/utils/packages.ts +3 -2
- package/src/node/utils/project-config.ts +10 -0
- package/src/node/utils/serialized-task-queue.ts +20 -0
- package/src/node/utils/transform.ts +82 -0
- package/src/node/vite-plugin.ts +12 -32
- package/src/options.ts +3 -4
- package/src/runtime/client/taro/api.ts +11 -0
- package/src/runtime/client/taro/component.ts +1 -0
- package/src/runtime/client/taro/define-native-component.ts +15 -0
- package/src/runtime/h5/app.ts +25 -0
- package/src/runtime/h5/taro-runtime.ts +1 -4
- package/src/runtime/wx/amphibious/bootstrap.ts +22 -0
- package/src/runtime/wx/amphibious/transport.ts +10 -0
- package/src/runtime/wx/capsule/app.ts +9 -0
- package/src/runtime/wx/capsule/component.ts +6 -0
- package/src/runtime/wx/capsule/page.ts +96 -0
- package/src/runtime/wx/capsule/taro-runtime.ts +14 -0
- package/src/runtime/wx/dev/dev-runtime.ts +317 -0
- package/src/runtime/wx/native/app.ts +4 -0
- package/src/runtime/wx/native/component.ts +4 -0
- package/src/runtime/wx/native/page.ts +6 -0
- package/src/runtime/wx/systemjs/LICENSE +10 -0
- package/src/runtime/wx/systemjs/system-core.js +370 -0
- package/src/runtime/wx/systemjs/system.d.ts +55 -0
- package/src/runtime/wx/wechat.d.ts +52 -0
- package/README.zh.md +0 -521
- package/dist/node/build-context.d.ts +0 -25
- package/dist/node/build-context.js +0 -47
- package/dist/node/css/css-pipeline.d.ts +0 -35
- package/dist/node/css/css-pipeline.js +0 -154
- package/dist/node/plugins/conditional-directives.d.ts +0 -3
- package/dist/node/plugins/taro-runtime.d.ts +0 -5
- package/dist/node/plugins/taro-runtime.js +0 -18
- package/dist/node/targets/h5/plugin.d.ts +0 -6
- package/dist/node/targets/h5/plugin.js +0 -117
- package/dist/node/targets/h5/virtual-modules.d.ts +0 -5
- package/dist/node/targets/h5/virtual-modules.js +0 -60
- package/dist/node/targets/wx/companion-assets.d.ts +0 -19
- package/dist/node/targets/wx/companion-assets.js +0 -129
- package/dist/node/targets/wx/dev-server/development-session.d.ts +0 -32
- package/dist/node/targets/wx/dev-server/development-session.js +0 -215
- package/dist/node/targets/wx/dev-server/full-build-scheduler.d.ts +0 -14
- package/dist/node/targets/wx/dev-server/full-build-scheduler.js +0 -60
- package/dist/node/targets/wx/dev-server/js-utils.d.ts +0 -5
- package/dist/node/targets/wx/dev-server/js-utils.js +0 -28
- package/dist/node/targets/wx/dev-server/output.d.ts +0 -19
- package/dist/node/targets/wx/dev-server/output.js +0 -44
- package/dist/node/targets/wx/dev-server/rolldown-runtime-source.d.ts +0 -8
- package/dist/node/targets/wx/dev-server/rolldown-runtime-source.js +0 -95
- package/dist/node/targets/wx/dev-server/update-server-state.d.ts +0 -65
- package/dist/node/targets/wx/dev-server/update-server-state.js +0 -116
- package/dist/node/targets/wx/dev-server/update-transport.d.ts +0 -28
- package/dist/node/targets/wx/dev-server/update-transport.js +0 -212
- package/dist/node/targets/wx/dev-server/vite-bundled-dev-adapter.d.ts +0 -44
- package/dist/node/targets/wx/dev-server/vite-bundled-dev-adapter.js +0 -145
- package/dist/node/targets/wx/development-files.d.ts +0 -8
- package/dist/node/targets/wx/development-files.js +0 -8
- package/dist/node/targets/wx/plugin.d.ts +0 -6
- package/dist/node/targets/wx/plugin.js +0 -144
- package/dist/node/targets/wx/react-refresh.d.ts +0 -4
- package/dist/node/targets/wx/react-refresh.js +0 -38
- package/dist/node/targets/wx/virtual-modules.d.ts +0 -16
- package/dist/node/targets/wx/virtual-modules.js +0 -120
- package/dist/node/utils/async.d.ts +0 -8
- package/dist/node/utils/async.js +0 -16
- package/dist/node/utils/filesystem.d.ts +0 -13
- package/dist/node/utils/filesystem.js +0 -43
- package/dist/runtime/taro/api.js +0 -11
- package/dist/runtime/taro/components.d.ts +0 -2
- package/dist/runtime/taro/components.js +0 -2
- package/dist/runtime/wx/page-update.d.ts +0 -6
- package/dist/runtime/wx/page-update.js +0 -157
- package/dist/runtime/wx/taro-runtime.d.ts +0 -5
- package/dist/runtime/wx/taro-runtime.js +0 -6
- package/dist/runtime/wx/update-client-state.d.ts +0 -68
- package/dist/runtime/wx/update-client-state.js +0 -84
- package/dist/runtime/wx/update-client.d.ts +0 -1
- package/dist/runtime/wx/update-client.js +0 -171
- package/src/node/build-context.ts +0 -62
- package/src/node/css/css-pipeline.ts +0 -171
- package/src/node/plugins/taro-runtime.ts +0 -22
- package/src/node/targets/h5/plugin.ts +0 -135
- package/src/node/targets/h5/virtual-modules.ts +0 -71
- package/src/node/targets/wx/companion-assets.ts +0 -174
- package/src/node/targets/wx/dev-server/development-session.ts +0 -271
- package/src/node/targets/wx/dev-server/full-build-scheduler.ts +0 -62
- package/src/node/targets/wx/dev-server/js-utils.ts +0 -33
- package/src/node/targets/wx/dev-server/output.ts +0 -56
- package/src/node/targets/wx/dev-server/rolldown-runtime-source.ts +0 -95
- package/src/node/targets/wx/dev-server/update-server-state.ts +0 -183
- package/src/node/targets/wx/dev-server/update-transport.ts +0 -261
- package/src/node/targets/wx/dev-server/vite-bundled-dev-adapter.ts +0 -203
- package/src/node/targets/wx/development-files.ts +0 -11
- package/src/node/targets/wx/plugin.ts +0 -164
- package/src/node/targets/wx/react-refresh.ts +0 -51
- package/src/node/targets/wx/virtual-modules.ts +0 -152
- package/src/node/utils/async.ts +0 -19
- package/src/node/utils/filesystem.ts +0 -45
- package/src/runtime/taro/api.ts +0 -13
- package/src/runtime/taro/components.ts +0 -2
- package/src/runtime/wx/page-update.ts +0 -230
- package/src/runtime/wx/react-refresh.d.ts +0 -20
- package/src/runtime/wx/taro-runtime.ts +0 -7
- package/src/runtime/wx/update-client-state.ts +0 -138
- package/src/runtime/wx/update-client.ts +0 -223
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Top-level owner of one WX development lifecycle.
|
|
3
|
-
*
|
|
4
|
-
* It serializes every output write, connects DevEngine patches to the update transport, and coalesces conservative full
|
|
5
|
-
* rebuilds. No other module writes plugin-generated WX development files directly.
|
|
6
|
-
*/
|
|
7
|
-
import fs from 'node:fs/promises';
|
|
8
|
-
import path from 'node:path';
|
|
9
|
-
import colors from 'picocolors';
|
|
10
|
-
import { SerializedTaskQueue } from '../../../utils/async.js';
|
|
11
|
-
import { copyDirectoryIfExists, copyFileOrRemove, writeFileAtomically, writeFilesAtomically } from '../../../utils/filesystem.js';
|
|
12
|
-
import { wxDevelopmentDirectory, wxUpdateControlFile, wxUpdateFile } from '../development-files.js';
|
|
13
|
-
import { FullBuildScheduler } from './full-build-scheduler.js';
|
|
14
|
-
import { transformWxCompatibleJavaScript, transformWxOutputChunks } from './js-utils.js';
|
|
15
|
-
import { isWxFullBuildOutput, normalizeWxBundleStyles, setWxAppStyles } from './output.js';
|
|
16
|
-
import { WxUpdateTransport } from './update-transport.js';
|
|
17
|
-
import { ViteBundledDevAdapter } from './vite-bundled-dev-adapter.js';
|
|
18
|
-
const maxRetainedDeltaCount = 1_000;
|
|
19
|
-
const maxRetainedDeltaBytes = 16 * 1024 * 1024;
|
|
20
|
-
const fullBuildDebounceDelay = 100;
|
|
21
|
-
/** Owns one WX bundled-development graph and all writes to its fixed output directory. */
|
|
22
|
-
export class WxDevelopmentSession {
|
|
23
|
-
context;
|
|
24
|
-
server;
|
|
25
|
-
adapter;
|
|
26
|
-
updateTransport;
|
|
27
|
-
outDir;
|
|
28
|
-
initialBundle = Promise.withResolvers();
|
|
29
|
-
outputQueue;
|
|
30
|
-
fullBuildScheduler;
|
|
31
|
-
originalPrintUrls;
|
|
32
|
-
snapshot = { lifecycle: 'open', outputPhase: 'starting', latestAppStyles: '' };
|
|
33
|
-
constructor(context, server) {
|
|
34
|
-
this.context = context;
|
|
35
|
-
this.server = server;
|
|
36
|
-
const config = context.vite;
|
|
37
|
-
this.outDir = path.resolve(config.root, config.build.outDir);
|
|
38
|
-
this.outputQueue = new SerializedTaskQueue((error) => this.reportOutputError(error));
|
|
39
|
-
this.updateTransport = new WxUpdateTransport(server, () => this.requestFullBuild(), (buildId, source) => this.outputQueue.enqueue(async () => {
|
|
40
|
-
// A full build queued before this write invalidates the old batch instead of letting it overwrite
|
|
41
|
-
// the new build's empty update.js.
|
|
42
|
-
if (!this.updateTransport.isCurrentBuild(buildId))
|
|
43
|
-
return;
|
|
44
|
-
await writeFileAtomically(path.join(this.outDir, wxUpdateFile), source);
|
|
45
|
-
}));
|
|
46
|
-
this.adapter = new ViteBundledDevAdapter(config, server, {
|
|
47
|
-
onOutput: (output) => this.handleBundleOutput(output),
|
|
48
|
-
onPatch: (files, output) => this.handlePatch(files, output),
|
|
49
|
-
onError: (message) => this.handleError(message),
|
|
50
|
-
waitForInitialBundle: () => this.waitForInitialBundle()
|
|
51
|
-
});
|
|
52
|
-
this.fullBuildScheduler = new FullBuildScheduler(fullBuildDebounceDelay, () => this.adapter.rebuild(), (error) => this.reportRebuildError(error));
|
|
53
|
-
}
|
|
54
|
-
get config() {
|
|
55
|
-
return this.context.vite;
|
|
56
|
-
}
|
|
57
|
-
install() {
|
|
58
|
-
this.updateTransport.install();
|
|
59
|
-
this.server.httpServer?.once('listening', this.handleHttpListening);
|
|
60
|
-
this.adapter.install();
|
|
61
|
-
this.originalPrintUrls = this.server.printUrls.bind(this.server);
|
|
62
|
-
this.server.printUrls = this.printUrls;
|
|
63
|
-
if (this.config.publicDir)
|
|
64
|
-
this.server.watcher.add(this.config.publicDir);
|
|
65
|
-
this.server.watcher.on('change', this.handleWatchedFile);
|
|
66
|
-
this.server.watcher.on('add', this.handleWatchedFile);
|
|
67
|
-
this.server.watcher.on('unlink', this.handleWatchedFile);
|
|
68
|
-
}
|
|
69
|
-
async close() {
|
|
70
|
-
if (this.snapshot.lifecycle === 'closed')
|
|
71
|
-
return;
|
|
72
|
-
this.snapshot = { ...this.snapshot, lifecycle: 'closed' };
|
|
73
|
-
this.server.watcher.off('change', this.handleWatchedFile);
|
|
74
|
-
this.server.watcher.off('add', this.handleWatchedFile);
|
|
75
|
-
this.server.watcher.off('unlink', this.handleWatchedFile);
|
|
76
|
-
this.server.httpServer?.off('listening', this.handleHttpListening);
|
|
77
|
-
if (this.server.printUrls === this.printUrls && this.originalPrintUrls) {
|
|
78
|
-
this.server.printUrls = this.originalPrintUrls;
|
|
79
|
-
}
|
|
80
|
-
this.updateTransport.close();
|
|
81
|
-
await this.fullBuildScheduler.close();
|
|
82
|
-
await this.outputQueue.waitForIdle();
|
|
83
|
-
}
|
|
84
|
-
printUrls = () => {
|
|
85
|
-
this.originalPrintUrls?.();
|
|
86
|
-
const projectDirectory = relativeToViteConfig(this.outDir, this.config.configFile, this.config.root);
|
|
87
|
-
this.server.config.logger.info(` ${colors.green('➜')} ${colors.bold('WeChat DevTools')}: ${colors.cyan(projectDirectory)}`);
|
|
88
|
-
};
|
|
89
|
-
handleHttpListening = () => {
|
|
90
|
-
this.outputQueue.enqueue(() => writeFileAtomically(path.join(this.outDir, wxUpdateControlFile), this.updateTransport.createControlSource()));
|
|
91
|
-
};
|
|
92
|
-
handleWatchedFile = (file) => {
|
|
93
|
-
if (isFileInside(file, this.config.publicDir)) {
|
|
94
|
-
const destination = path.join(this.outDir, path.relative(this.config.publicDir, file));
|
|
95
|
-
this.outputQueue.enqueue(() => copyFileOrRemove(file, destination));
|
|
96
|
-
this.requestFullBuild();
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
handleBundleOutput(output) {
|
|
100
|
-
const appStyles = normalizeWxBundleStyles(output);
|
|
101
|
-
const fullBuild = isWxFullBuildOutput(output);
|
|
102
|
-
if (!fullBuild) {
|
|
103
|
-
this.outputQueue.enqueue(async () => {
|
|
104
|
-
await this.finalizeAppStyles(output, appStyles, false);
|
|
105
|
-
await transformWxOutputChunks(output);
|
|
106
|
-
await writeDevelopmentOutput(this.outDir, output);
|
|
107
|
-
});
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
const buildId = this.updateTransport.createBuildId();
|
|
111
|
-
setDevelopmentAsset(output, wxUpdateControlFile, this.updateTransport.createControlSource(buildId));
|
|
112
|
-
setDevelopmentAsset(output, wxUpdateFile, 'void 0;\n');
|
|
113
|
-
this.outputQueue.enqueue(async () => {
|
|
114
|
-
await this.finalizeAppStyles(output, appStyles, true);
|
|
115
|
-
await transformWxOutputChunks(output);
|
|
116
|
-
if (this.snapshot.outputPhase === 'starting') {
|
|
117
|
-
// The directory is plugin-owned; clearing it once removes stale files from previous protocol designs.
|
|
118
|
-
await fs.rm(path.join(this.outDir, wxDevelopmentDirectory), { recursive: true, force: true });
|
|
119
|
-
}
|
|
120
|
-
// Invalidate old HTTP reports before writing the new build epoch into the fixed DevTools directory.
|
|
121
|
-
this.updateTransport.commitFullBuild(buildId);
|
|
122
|
-
await writeDevelopmentOutput(this.outDir, output);
|
|
123
|
-
await copyDirectoryIfExists(this.config.publicDir, this.outDir);
|
|
124
|
-
await this.context.css.captureFullBuild();
|
|
125
|
-
const moduleCount = this.adapter.registerBundleModules(output);
|
|
126
|
-
this.snapshot = { ...this.snapshot, outputPhase: 'ready' };
|
|
127
|
-
this.initialBundle.resolve();
|
|
128
|
-
this.server.config.logger.info(`[vite-plugin-taro] WX bundle ready (${moduleCount} modules, ${output.length} files)`);
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
async finalizeAppStyles(output, source, fullBuild) {
|
|
132
|
-
if (source !== undefined) {
|
|
133
|
-
const transformed = await this.context.css.transformWxss(source);
|
|
134
|
-
this.snapshot = { ...this.snapshot, latestAppStyles: transformed };
|
|
135
|
-
setWxAppStyles(output, transformed);
|
|
136
|
-
}
|
|
137
|
-
else if (fullBuild && this.snapshot.latestAppStyles) {
|
|
138
|
-
setWxAppStyles(output, this.snapshot.latestAppStyles);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
handlePatch(files, output) {
|
|
142
|
-
if (!isSafeJavaScriptPatch(files, output)) {
|
|
143
|
-
this.requestFullBuild();
|
|
144
|
-
return false;
|
|
145
|
-
}
|
|
146
|
-
this.adapter.registerPatchModules(output.code);
|
|
147
|
-
this.outputQueue.enqueue(async () => {
|
|
148
|
-
const transformed = await this.context.css.transformNativePatch(output.code, output.filename, files);
|
|
149
|
-
if ('requiresFullBuild' in transformed) {
|
|
150
|
-
this.requestFullBuild();
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
const compatibleCode = await transformWxCompatibleJavaScript(transformed.code, output.filename);
|
|
154
|
-
if (this.updateTransport.retainedDeltaCount >= maxRetainedDeltaCount ||
|
|
155
|
-
this.updateTransport.retainedDeltaBytes + Buffer.byteLength(compatibleCode) >= maxRetainedDeltaBytes) {
|
|
156
|
-
this.requestFullBuild();
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
this.updateTransport.addDelta(compatibleCode);
|
|
160
|
-
});
|
|
161
|
-
return true;
|
|
162
|
-
}
|
|
163
|
-
handleError(message) {
|
|
164
|
-
this.server.config.logger.error('[vite-plugin-taro] WX update failed', { error: new Error(message) });
|
|
165
|
-
}
|
|
166
|
-
requestFullBuild() {
|
|
167
|
-
this.fullBuildScheduler.request();
|
|
168
|
-
}
|
|
169
|
-
async waitForInitialBundle() {
|
|
170
|
-
await this.initialBundle.promise;
|
|
171
|
-
await this.outputQueue.waitForIdle();
|
|
172
|
-
}
|
|
173
|
-
reportOutputError(error) {
|
|
174
|
-
const normalizedError = error instanceof Error ? error : new Error(String(error));
|
|
175
|
-
this.server.config.logger.error(`[vite-plugin-taro] WX development output failed: ${normalizedError.stack ?? normalizedError.message}`);
|
|
176
|
-
}
|
|
177
|
-
reportRebuildError(error) {
|
|
178
|
-
const normalizedError = error instanceof Error ? error : new Error(String(error));
|
|
179
|
-
this.server.config.logger.error('[vite-plugin-taro] WX rebuild failed', { error: normalizedError });
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
function writeDevelopmentOutput(outDir, output) {
|
|
183
|
-
return writeFilesAtomically(output.map((item) => ({
|
|
184
|
-
file: path.join(outDir, item.fileName),
|
|
185
|
-
source: item.type === 'chunk' ? item.code : item.source
|
|
186
|
-
})));
|
|
187
|
-
}
|
|
188
|
-
function setDevelopmentAsset(output, fileName, source) {
|
|
189
|
-
const index = output.findIndex((item) => item.type === 'asset' && item.fileName === fileName);
|
|
190
|
-
const asset = { type: 'asset', fileName, source };
|
|
191
|
-
if (index >= 0)
|
|
192
|
-
output[index] = asset;
|
|
193
|
-
else
|
|
194
|
-
output.push(asset);
|
|
195
|
-
}
|
|
196
|
-
function relativeToViteConfig(outDir, configFile, root) {
|
|
197
|
-
const configDirectory = configFile ? path.dirname(configFile) : root;
|
|
198
|
-
const relativePath = path.relative(configDirectory, outDir).replaceAll('\\', '/');
|
|
199
|
-
if (!relativePath)
|
|
200
|
-
return '.';
|
|
201
|
-
return relativePath.startsWith('.') ? relativePath : `./${relativePath}`;
|
|
202
|
-
}
|
|
203
|
-
function isFileInside(file, directory) {
|
|
204
|
-
if (!directory)
|
|
205
|
-
return false;
|
|
206
|
-
const relative = path.relative(directory, file);
|
|
207
|
-
return relative !== '' && !relative.startsWith('..') && !path.isAbsolute(relative);
|
|
208
|
-
}
|
|
209
|
-
function isSafeJavaScriptPatch(files, output) {
|
|
210
|
-
if (output.type !== 'Patch' || output.hmrBoundaries.length === 0)
|
|
211
|
-
return false;
|
|
212
|
-
if (output.code.includes('__vite__updateStyle') || output.code.includes('.updateStyle('))
|
|
213
|
-
return false;
|
|
214
|
-
return files.every((file) => /\.[cm]?[jt]sx?$/.test(file));
|
|
215
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/** Full-build scheduling owned by one WX development session. */
|
|
2
|
-
/** Coalesces trailing-edge requests while guaranteeing one full build at a time. */
|
|
3
|
-
export declare class FullBuildScheduler {
|
|
4
|
-
private readonly delay;
|
|
5
|
-
private readonly runBuild;
|
|
6
|
-
private readonly reportError;
|
|
7
|
-
private phase;
|
|
8
|
-
private timer;
|
|
9
|
-
private work;
|
|
10
|
-
constructor(delay: number, runBuild: () => Promise<void>, reportError: (error: unknown) => void);
|
|
11
|
-
request(): void;
|
|
12
|
-
close(): Promise<void>;
|
|
13
|
-
private start;
|
|
14
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/** Full-build scheduling owned by one WX development session. */
|
|
2
|
-
/** Coalesces trailing-edge requests while guaranteeing one full build at a time. */
|
|
3
|
-
export class FullBuildScheduler {
|
|
4
|
-
delay;
|
|
5
|
-
runBuild;
|
|
6
|
-
reportError;
|
|
7
|
-
phase = 'idle';
|
|
8
|
-
timer;
|
|
9
|
-
work;
|
|
10
|
-
constructor(delay, runBuild, reportError) {
|
|
11
|
-
this.delay = delay;
|
|
12
|
-
this.runBuild = runBuild;
|
|
13
|
-
this.reportError = reportError;
|
|
14
|
-
}
|
|
15
|
-
request() {
|
|
16
|
-
switch (this.phase) {
|
|
17
|
-
case 'closed':
|
|
18
|
-
return;
|
|
19
|
-
case 'building':
|
|
20
|
-
this.phase = 'building-with-pending-request';
|
|
21
|
-
return;
|
|
22
|
-
case 'building-with-pending-request':
|
|
23
|
-
return;
|
|
24
|
-
case 'idle':
|
|
25
|
-
case 'scheduled':
|
|
26
|
-
if (this.timer)
|
|
27
|
-
clearTimeout(this.timer);
|
|
28
|
-
this.phase = 'scheduled';
|
|
29
|
-
this.timer = setTimeout(() => this.start(), this.delay);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
async close() {
|
|
33
|
-
if (this.phase === 'closed') {
|
|
34
|
-
await this.work;
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
this.phase = 'closed';
|
|
38
|
-
if (this.timer)
|
|
39
|
-
clearTimeout(this.timer);
|
|
40
|
-
this.timer = undefined;
|
|
41
|
-
await this.work;
|
|
42
|
-
}
|
|
43
|
-
start() {
|
|
44
|
-
if (this.phase !== 'scheduled')
|
|
45
|
-
return;
|
|
46
|
-
this.timer = undefined;
|
|
47
|
-
this.phase = 'building';
|
|
48
|
-
this.work = this.runBuild()
|
|
49
|
-
.catch(this.reportError)
|
|
50
|
-
.finally(() => {
|
|
51
|
-
this.work = undefined;
|
|
52
|
-
if (this.phase === 'closed')
|
|
53
|
-
return;
|
|
54
|
-
const repeat = this.phase === 'building-with-pending-request';
|
|
55
|
-
this.phase = 'idle';
|
|
56
|
-
if (repeat)
|
|
57
|
-
this.request();
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { WxOutputFile } from './output.ts';
|
|
2
|
-
/** Lowers generated JavaScript syntax that WeChat's upload parser does not accept. */
|
|
3
|
-
export declare function transformWxCompatibleJavaScript(code: string, filename: string): Promise<string>;
|
|
4
|
-
/** Applies the compatibility transform to every JavaScript chunk in a DevEngine output batch. */
|
|
5
|
-
export declare function transformWxOutputChunks(output: WxOutputFile[]): Promise<void>;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { transformWithOxc } from 'vite';
|
|
2
|
-
const wxJavaScriptTarget = 'es2018';
|
|
3
|
-
/** Lowers generated JavaScript syntax that WeChat's upload parser does not accept. */
|
|
4
|
-
export async function transformWxCompatibleJavaScript(code, filename) {
|
|
5
|
-
const result = await transformWithOxc(code, filename, {
|
|
6
|
-
lang: 'js',
|
|
7
|
-
target: wxJavaScriptTarget,
|
|
8
|
-
sourcemap: false,
|
|
9
|
-
assumptions: {
|
|
10
|
-
// Avoid external Oxc helpers when lowering public class fields in already-bundled chunks.
|
|
11
|
-
setPublicClassFields: true
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
return result.code;
|
|
15
|
-
}
|
|
16
|
-
/** Applies the compatibility transform to every JavaScript chunk in a DevEngine output batch. */
|
|
17
|
-
export async function transformWxOutputChunks(output) {
|
|
18
|
-
await Promise.all(output.map(async (item, index) => {
|
|
19
|
-
if (item.type !== 'chunk')
|
|
20
|
-
return;
|
|
21
|
-
output[index] = {
|
|
22
|
-
type: 'chunk',
|
|
23
|
-
fileName: item.fileName,
|
|
24
|
-
modules: item.modules,
|
|
25
|
-
code: await transformWxCompatibleJavaScript(item.code, item.fileName)
|
|
26
|
-
};
|
|
27
|
-
}));
|
|
28
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Normalizes private DevEngine output before the development session writes it to the fixed WX project directory.
|
|
3
|
-
* DevEngine rebuilds may be partial, so these helpers mutate only files present in the current output.
|
|
4
|
-
*/
|
|
5
|
-
/** File shape emitted by Vite's private bundled-development engine. */
|
|
6
|
-
export type WxOutputFile = {
|
|
7
|
-
type: 'chunk';
|
|
8
|
-
fileName: string;
|
|
9
|
-
code: string;
|
|
10
|
-
modules?: Record<string, unknown>;
|
|
11
|
-
} | {
|
|
12
|
-
type: 'asset';
|
|
13
|
-
fileName: string;
|
|
14
|
-
source: string | Uint8Array;
|
|
15
|
-
};
|
|
16
|
-
/** Extracts Vite's development CSS payloads and materializes them as app.wxss. */
|
|
17
|
-
export declare function normalizeWxBundleStyles(output: WxOutputFile[]): string | undefined;
|
|
18
|
-
export declare function setWxAppStyles(output: WxOutputFile[], source: string): void;
|
|
19
|
-
export declare function isWxFullBuildOutput(output: WxOutputFile[]): boolean;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Normalizes private DevEngine output before the development session writes it to the fixed WX project directory.
|
|
3
|
-
* DevEngine rebuilds may be partial, so these helpers mutate only files present in the current output.
|
|
4
|
-
*/
|
|
5
|
-
/** Extracts Vite's development CSS payloads and materializes them as app.wxss. */
|
|
6
|
-
export function normalizeWxBundleStyles(output) {
|
|
7
|
-
const styles = [];
|
|
8
|
-
for (let index = output.length - 1; index >= 0; index--) {
|
|
9
|
-
const item = output[index];
|
|
10
|
-
if (!item)
|
|
11
|
-
continue;
|
|
12
|
-
if (item.type === 'asset' && item.fileName.endsWith('.css')) {
|
|
13
|
-
styles.unshift(typeof item.source === 'string' ? item.source : new TextDecoder().decode(item.source));
|
|
14
|
-
output.splice(index, 1);
|
|
15
|
-
}
|
|
16
|
-
else if (item.type === 'chunk') {
|
|
17
|
-
styles.push(...collectEmbeddedStyles(item.code));
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
if (styles.length === 0)
|
|
21
|
-
return;
|
|
22
|
-
const source = styles.join('\n');
|
|
23
|
-
setWxAppStyles(output, source);
|
|
24
|
-
return source;
|
|
25
|
-
}
|
|
26
|
-
export function setWxAppStyles(output, source) {
|
|
27
|
-
const index = output.findIndex((item) => item.type === 'asset' && item.fileName === 'app.wxss');
|
|
28
|
-
const appStyle = { type: 'asset', fileName: 'app.wxss', source };
|
|
29
|
-
if (index >= 0)
|
|
30
|
-
output[index] = appStyle;
|
|
31
|
-
else
|
|
32
|
-
output.push(appStyle);
|
|
33
|
-
}
|
|
34
|
-
export function isWxFullBuildOutput(output) {
|
|
35
|
-
return output.some((item) => item.fileName === 'app.js');
|
|
36
|
-
}
|
|
37
|
-
function collectEmbeddedStyles(code) {
|
|
38
|
-
const styles = [];
|
|
39
|
-
for (const match of code.matchAll(/__vite__css(?:\$\d+)?\s*=\s*("(?:\\.|[^"\\])*");/g)) {
|
|
40
|
-
if (match[1])
|
|
41
|
-
styles.push(JSON.parse(match[1]));
|
|
42
|
-
}
|
|
43
|
-
return styles;
|
|
44
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Self-contained source injected into Rolldown's DevEngine as the WX module bootstrap runtime.
|
|
3
|
-
*
|
|
4
|
-
* This TypeScript module runs in Node and only exports source text. The exported JavaScript becomes
|
|
5
|
-
* `runtime.js`, executes before every application module, and therefore cannot import Taro, React,
|
|
6
|
-
* or any module that depends on the runtime it is creating.
|
|
7
|
-
*/
|
|
8
|
-
export declare const wxRolldownRuntimeSource = "\nvar BaseDevRuntime = DevRuntime;\nclass WxHotContext {\n callbacks = [];\n data = {};\n _internal = { updateStyle() {}, removeStyle() {} };\n constructor(moduleId) { this.moduleId = moduleId; }\n accept(...args) {\n if (args.length === 0) {\n this.callbacks.push({ deps: this.moduleId, callback: undefined });\n } else if (args.length === 1 && typeof args[0] === 'function') {\n this.callbacks.push({ deps: this.moduleId, callback: args[0] });\n } else if (args.length === 1) {\n this.callbacks.push({ deps: args[0], callback: undefined });\n } else {\n this.callbacks.push({ deps: args[0], callback: args[1] });\n }\n }\n acceptExports(_exports, callback) { this.accept(callback); }\n dispose() {}\n prune() {}\n invalidate() {}\n on() {}\n off() {}\n send() {}\n}\nclass WxRolldownRuntime extends BaseDevRuntime {\n contexts = new Map();\n patchedModules = new Set();\n applyingPatch = false;\n\n createEsmInitializer = (id, initialize, _deduplicate, result) => () => {\n if (!initialize) return result;\n if (!this.applyingPatch && this.patchedModules.has(id)) {\n initialize = undefined;\n return result;\n }\n const callback = initialize;\n initialize = undefined;\n result = callback(id);\n if (this.applyingPatch) this.patchedModules.add(id);\n return result;\n };\n\n createCjsInitializer = (id, initialize, _deduplicate, module) => () => {\n if (module) return module.exports;\n if (!this.applyingPatch && this.patchedModules.has(id)) return this.loadExports(id);\n module = { exports: {} };\n initialize(module.exports, module, id);\n if (this.applyingPatch) this.patchedModules.add(id);\n return module.exports;\n };\n\n createModuleHotContext(moduleId) {\n const previous = this.contexts.get(moduleId);\n const context = new WxHotContext(moduleId);\n if (previous) {\n context.callbacks = previous.callbacks;\n context.data = previous.data;\n }\n this.contexts.set(moduleId, context);\n return context;\n }\n\n beginPatch() { this.applyingPatch = true; }\n endPatch() { this.applyingPatch = false; }\n\n applyUpdates(boundaries) {\n for (const [boundary, acceptedVia] of boundaries) {\n const context = this.contexts.get(boundary);\n if (!context) continue;\n const callbacks = [...context.callbacks];\n if (boundary === acceptedVia) context.callbacks = [];\n for (const { deps, callback } of callbacks) {\n if (!callback) continue;\n if (Array.isArray(deps)) {\n if (deps.includes(acceptedVia)) callback(deps.map((id) => this.loadExports(id)));\n } else if (deps === acceptedVia) {\n callback(this.loadExports(acceptedVia));\n }\n }\n }\n }\n}\n// A full DevEngine runtime starts a new page-update generation before any application chunk executes.\nglobalThis.__VITE_PLUGIN_TARO_WX_PAGE_UPDATE__ = { ready: false };\nglobalThis.__rolldown_runtime__ = new WxRolldownRuntime(undefined, 'vite-plugin-taro-wx');\n";
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Self-contained source injected into Rolldown's DevEngine as the WX module bootstrap runtime.
|
|
3
|
-
*
|
|
4
|
-
* This TypeScript module runs in Node and only exports source text. The exported JavaScript becomes
|
|
5
|
-
* `runtime.js`, executes before every application module, and therefore cannot import Taro, React,
|
|
6
|
-
* or any module that depends on the runtime it is creating.
|
|
7
|
-
*/
|
|
8
|
-
export const wxRolldownRuntimeSource = `
|
|
9
|
-
var BaseDevRuntime = DevRuntime;
|
|
10
|
-
class WxHotContext {
|
|
11
|
-
callbacks = [];
|
|
12
|
-
data = {};
|
|
13
|
-
_internal = { updateStyle() {}, removeStyle() {} };
|
|
14
|
-
constructor(moduleId) { this.moduleId = moduleId; }
|
|
15
|
-
accept(...args) {
|
|
16
|
-
if (args.length === 0) {
|
|
17
|
-
this.callbacks.push({ deps: this.moduleId, callback: undefined });
|
|
18
|
-
} else if (args.length === 1 && typeof args[0] === 'function') {
|
|
19
|
-
this.callbacks.push({ deps: this.moduleId, callback: args[0] });
|
|
20
|
-
} else if (args.length === 1) {
|
|
21
|
-
this.callbacks.push({ deps: args[0], callback: undefined });
|
|
22
|
-
} else {
|
|
23
|
-
this.callbacks.push({ deps: args[0], callback: args[1] });
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
acceptExports(_exports, callback) { this.accept(callback); }
|
|
27
|
-
dispose() {}
|
|
28
|
-
prune() {}
|
|
29
|
-
invalidate() {}
|
|
30
|
-
on() {}
|
|
31
|
-
off() {}
|
|
32
|
-
send() {}
|
|
33
|
-
}
|
|
34
|
-
class WxRolldownRuntime extends BaseDevRuntime {
|
|
35
|
-
contexts = new Map();
|
|
36
|
-
patchedModules = new Set();
|
|
37
|
-
applyingPatch = false;
|
|
38
|
-
|
|
39
|
-
createEsmInitializer = (id, initialize, _deduplicate, result) => () => {
|
|
40
|
-
if (!initialize) return result;
|
|
41
|
-
if (!this.applyingPatch && this.patchedModules.has(id)) {
|
|
42
|
-
initialize = undefined;
|
|
43
|
-
return result;
|
|
44
|
-
}
|
|
45
|
-
const callback = initialize;
|
|
46
|
-
initialize = undefined;
|
|
47
|
-
result = callback(id);
|
|
48
|
-
if (this.applyingPatch) this.patchedModules.add(id);
|
|
49
|
-
return result;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
createCjsInitializer = (id, initialize, _deduplicate, module) => () => {
|
|
53
|
-
if (module) return module.exports;
|
|
54
|
-
if (!this.applyingPatch && this.patchedModules.has(id)) return this.loadExports(id);
|
|
55
|
-
module = { exports: {} };
|
|
56
|
-
initialize(module.exports, module, id);
|
|
57
|
-
if (this.applyingPatch) this.patchedModules.add(id);
|
|
58
|
-
return module.exports;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
createModuleHotContext(moduleId) {
|
|
62
|
-
const previous = this.contexts.get(moduleId);
|
|
63
|
-
const context = new WxHotContext(moduleId);
|
|
64
|
-
if (previous) {
|
|
65
|
-
context.callbacks = previous.callbacks;
|
|
66
|
-
context.data = previous.data;
|
|
67
|
-
}
|
|
68
|
-
this.contexts.set(moduleId, context);
|
|
69
|
-
return context;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
beginPatch() { this.applyingPatch = true; }
|
|
73
|
-
endPatch() { this.applyingPatch = false; }
|
|
74
|
-
|
|
75
|
-
applyUpdates(boundaries) {
|
|
76
|
-
for (const [boundary, acceptedVia] of boundaries) {
|
|
77
|
-
const context = this.contexts.get(boundary);
|
|
78
|
-
if (!context) continue;
|
|
79
|
-
const callbacks = [...context.callbacks];
|
|
80
|
-
if (boundary === acceptedVia) context.callbacks = [];
|
|
81
|
-
for (const { deps, callback } of callbacks) {
|
|
82
|
-
if (!callback) continue;
|
|
83
|
-
if (Array.isArray(deps)) {
|
|
84
|
-
if (deps.includes(acceptedVia)) callback(deps.map((id) => this.loadExports(id)));
|
|
85
|
-
} else if (deps === acceptedVia) {
|
|
86
|
-
callback(this.loadExports(acceptedVia));
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
// A full DevEngine runtime starts a new page-update generation before any application chunk executes.
|
|
93
|
-
globalThis.__VITE_PLUGIN_TARO_WX_PAGE_UPDATE__ = { ready: false };
|
|
94
|
-
globalThis.__rolldown_runtime__ = new WxRolldownRuntime(undefined, 'vite-plugin-taro-wx');
|
|
95
|
-
`;
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pure host-side stop-and-wait protocol state machine.
|
|
3
|
-
*
|
|
4
|
-
* It retains versioned Rolldown deltas and selects one missing range for the active App Service. HTTP and filesystem
|
|
5
|
-
* effects are represented as commands and handled by update-transport.ts.
|
|
6
|
-
*/
|
|
7
|
-
type WxUpdateDelta = {
|
|
8
|
-
version: number;
|
|
9
|
-
code: string;
|
|
10
|
-
};
|
|
11
|
-
export type WxUpdateBatch = {
|
|
12
|
-
buildId: string;
|
|
13
|
-
sessionId: string;
|
|
14
|
-
fromVersion: number;
|
|
15
|
-
targetVersion: number;
|
|
16
|
-
deltas: WxUpdateDelta[];
|
|
17
|
-
};
|
|
18
|
-
type WxUpdateServerState = {
|
|
19
|
-
buildId: string;
|
|
20
|
-
hostVersion: number;
|
|
21
|
-
retainedDeltaBytes: number;
|
|
22
|
-
deltas: WxUpdateDelta[];
|
|
23
|
-
activeSessionId?: string;
|
|
24
|
-
retiredSessionIds: string[];
|
|
25
|
-
inFlight?: Pick<WxUpdateBatch, 'sessionId' | 'fromVersion' | 'targetVersion'>;
|
|
26
|
-
};
|
|
27
|
-
type WxUpdateServerEvent = {
|
|
28
|
-
type: 'delta-added';
|
|
29
|
-
code: string;
|
|
30
|
-
bytes?: number;
|
|
31
|
-
} | {
|
|
32
|
-
type: 'client-registered';
|
|
33
|
-
buildId: string;
|
|
34
|
-
sessionId: string;
|
|
35
|
-
version: number;
|
|
36
|
-
} | {
|
|
37
|
-
type: 'client-reported';
|
|
38
|
-
buildId: string;
|
|
39
|
-
sessionId: string;
|
|
40
|
-
version: number;
|
|
41
|
-
} | {
|
|
42
|
-
type: 'batch-publish-failed';
|
|
43
|
-
sessionId: string;
|
|
44
|
-
targetVersion: number;
|
|
45
|
-
} | {
|
|
46
|
-
type: 'full-build-committed';
|
|
47
|
-
buildId: string;
|
|
48
|
-
};
|
|
49
|
-
export type WxUpdateServerCommand = {
|
|
50
|
-
type: 'publish-batch';
|
|
51
|
-
batch: WxUpdateBatch;
|
|
52
|
-
} | {
|
|
53
|
-
type: 'request-full-build';
|
|
54
|
-
reason: 'client-version-ahead' | 'invalid-client-version';
|
|
55
|
-
} | {
|
|
56
|
-
type: 'ignore-client';
|
|
57
|
-
reason: 'stale-build' | 'retired-session' | 'unknown-session';
|
|
58
|
-
};
|
|
59
|
-
type WxUpdateServerTransition = {
|
|
60
|
-
state: WxUpdateServerState;
|
|
61
|
-
commands: WxUpdateServerCommand[];
|
|
62
|
-
};
|
|
63
|
-
export declare function createWxUpdateServerState(buildId: string): WxUpdateServerState;
|
|
64
|
-
export declare function transitionWxUpdateServer(state: WxUpdateServerState, event: WxUpdateServerEvent): WxUpdateServerTransition;
|
|
65
|
-
export {};
|