vite-plugin-taro 0.3.2 → 0.4.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/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 +66 -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 +1 -1
- 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 +97 -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 +1 -1
- 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,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pure App-side stop-and-wait protocol state machine.
|
|
3
|
-
*
|
|
4
|
-
* It knows build versions and sequencing only; wx.request, literal code execution, and page lifecycle effects live in
|
|
5
|
-
* update-client.ts and page-update.ts.
|
|
6
|
-
*/
|
|
7
|
-
type WxUpdateClientPhase = 'stopped' | 'registering' | 'polling' | 'applying' | 'refreshing' | 'relaunching';
|
|
8
|
-
type WxUpdateClientState = {
|
|
9
|
-
buildId: string;
|
|
10
|
-
version: number;
|
|
11
|
-
phase: WxUpdateClientPhase;
|
|
12
|
-
targetVersion?: number;
|
|
13
|
-
pendingBatch?: {
|
|
14
|
-
fromVersion: number;
|
|
15
|
-
targetVersion: number;
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
export type WxUpdateClientEvent = {
|
|
19
|
-
type: 'started';
|
|
20
|
-
} | {
|
|
21
|
-
type: 'registration-completed';
|
|
22
|
-
} | {
|
|
23
|
-
type: 'poll-completed';
|
|
24
|
-
} | {
|
|
25
|
-
type: 'batch-observed';
|
|
26
|
-
buildId: string;
|
|
27
|
-
fromVersion: number;
|
|
28
|
-
targetVersion: number;
|
|
29
|
-
} | {
|
|
30
|
-
type: 'batch-executed';
|
|
31
|
-
targetVersion: number;
|
|
32
|
-
} | {
|
|
33
|
-
type: 'batch-failed';
|
|
34
|
-
} | {
|
|
35
|
-
type: 'refresh-completed';
|
|
36
|
-
stale: boolean;
|
|
37
|
-
} | {
|
|
38
|
-
type: 'route-ready';
|
|
39
|
-
} | {
|
|
40
|
-
type: 'transport-failed';
|
|
41
|
-
};
|
|
42
|
-
export type WxUpdateClientCommand = {
|
|
43
|
-
type: 'register';
|
|
44
|
-
version: number;
|
|
45
|
-
} | {
|
|
46
|
-
type: 'poll';
|
|
47
|
-
version: number;
|
|
48
|
-
} | {
|
|
49
|
-
type: 'apply-batch';
|
|
50
|
-
fromVersion: number;
|
|
51
|
-
targetVersion: number;
|
|
52
|
-
} | {
|
|
53
|
-
type: 'report-version';
|
|
54
|
-
version: number;
|
|
55
|
-
reason: 'applied' | 'batch-mismatch';
|
|
56
|
-
} | {
|
|
57
|
-
type: 'request-full-build';
|
|
58
|
-
reason: 'batch-execution-failed';
|
|
59
|
-
} | {
|
|
60
|
-
type: 'retry-transport';
|
|
61
|
-
};
|
|
62
|
-
type WxUpdateClientTransition = {
|
|
63
|
-
state: WxUpdateClientState;
|
|
64
|
-
commands: WxUpdateClientCommand[];
|
|
65
|
-
};
|
|
66
|
-
export declare function createWxUpdateClientState(buildId: string): WxUpdateClientState;
|
|
67
|
-
export declare function transitionWxUpdateClient(state: WxUpdateClientState, event: WxUpdateClientEvent): WxUpdateClientTransition;
|
|
68
|
-
export {};
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
export function createWxUpdateClientState(buildId) {
|
|
2
|
-
return { buildId, version: 0, phase: 'stopped' };
|
|
3
|
-
}
|
|
4
|
-
export function transitionWxUpdateClient(state, event) {
|
|
5
|
-
switch (event.type) {
|
|
6
|
-
case 'started':
|
|
7
|
-
if (state.phase !== 'stopped')
|
|
8
|
-
return transition(state);
|
|
9
|
-
return command({ ...state, phase: 'registering' }, { type: 'register', version: state.version });
|
|
10
|
-
case 'registration-completed': {
|
|
11
|
-
if (state.phase !== 'registering')
|
|
12
|
-
return transition(state);
|
|
13
|
-
const pending = state.pendingBatch;
|
|
14
|
-
if (!pending)
|
|
15
|
-
return command({ ...state, phase: 'polling' }, { type: 'poll', version: state.version });
|
|
16
|
-
return command({ ...state, phase: 'applying', targetVersion: pending.targetVersion, pendingBatch: undefined }, { type: 'apply-batch', ...pending });
|
|
17
|
-
}
|
|
18
|
-
case 'poll-completed':
|
|
19
|
-
if (state.phase !== 'polling')
|
|
20
|
-
return transition(state);
|
|
21
|
-
return command(state, { type: 'poll', version: state.version });
|
|
22
|
-
case 'batch-observed':
|
|
23
|
-
return observeBatch(state, event);
|
|
24
|
-
case 'batch-executed':
|
|
25
|
-
if (state.phase !== 'applying' || state.targetVersion !== event.targetVersion) {
|
|
26
|
-
return command(state, { type: 'report-version', version: state.version, reason: 'batch-mismatch' });
|
|
27
|
-
}
|
|
28
|
-
return transition({ ...state, phase: 'refreshing', version: event.targetVersion });
|
|
29
|
-
case 'batch-failed':
|
|
30
|
-
return command({ ...state, phase: 'polling', targetVersion: undefined }, { type: 'request-full-build', reason: 'batch-execution-failed' });
|
|
31
|
-
case 'refresh-completed':
|
|
32
|
-
if (state.phase !== 'refreshing')
|
|
33
|
-
return transition(state);
|
|
34
|
-
if (event.stale)
|
|
35
|
-
return transition({ ...state, phase: 'relaunching' });
|
|
36
|
-
return applied(state);
|
|
37
|
-
case 'route-ready':
|
|
38
|
-
if (state.phase !== 'relaunching')
|
|
39
|
-
return transition(state);
|
|
40
|
-
return applied(state);
|
|
41
|
-
case 'transport-failed':
|
|
42
|
-
return command(state, { type: 'retry-transport' });
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
function observeBatch(state, batch) {
|
|
46
|
-
const valid = batch.buildId === state.buildId &&
|
|
47
|
-
Number.isInteger(batch.fromVersion) &&
|
|
48
|
-
Number.isInteger(batch.targetVersion) &&
|
|
49
|
-
batch.fromVersion >= 0 &&
|
|
50
|
-
batch.targetVersion > batch.fromVersion;
|
|
51
|
-
if (state.phase === 'registering') {
|
|
52
|
-
if (!valid || batch.fromVersion !== state.version || batch.targetVersion <= state.version) {
|
|
53
|
-
return transition(state);
|
|
54
|
-
}
|
|
55
|
-
return transition({
|
|
56
|
-
...state,
|
|
57
|
-
pendingBatch: { fromVersion: batch.fromVersion, targetVersion: batch.targetVersion }
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
if (!valid) {
|
|
61
|
-
return command(state, { type: 'report-version', version: state.version, reason: 'batch-mismatch' });
|
|
62
|
-
}
|
|
63
|
-
if (batch.targetVersion <= state.version) {
|
|
64
|
-
return command(state, { type: 'report-version', version: state.version, reason: 'applied' });
|
|
65
|
-
}
|
|
66
|
-
if (state.phase !== 'polling' || batch.fromVersion !== state.version) {
|
|
67
|
-
return command(state, { type: 'report-version', version: state.version, reason: 'batch-mismatch' });
|
|
68
|
-
}
|
|
69
|
-
return command({ ...state, phase: 'applying', targetVersion: batch.targetVersion }, {
|
|
70
|
-
type: 'apply-batch',
|
|
71
|
-
fromVersion: batch.fromVersion,
|
|
72
|
-
targetVersion: batch.targetVersion
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
function applied(state) {
|
|
76
|
-
const appliedState = { ...state, phase: 'polling', targetVersion: undefined };
|
|
77
|
-
return command(appliedState, { type: 'report-version', version: state.version, reason: 'applied' });
|
|
78
|
-
}
|
|
79
|
-
function transition(state) {
|
|
80
|
-
return { state, commands: [] };
|
|
81
|
-
}
|
|
82
|
-
function command(state, value) {
|
|
83
|
-
return { state, commands: [value] };
|
|
84
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function startWxUpdateClient(): void;
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* App-owned adapter for the WX update protocol.
|
|
3
|
-
*
|
|
4
|
-
* It transports metadata with wx.request and executes literal batches delivered through update.js. React/Taro page
|
|
5
|
-
* preservation is delegated to page-update.ts so the App never depends on the mutable update file.
|
|
6
|
-
*/
|
|
7
|
-
import { createWxUpdateClientState, transitionWxUpdateClient } from './update-client-state.js';
|
|
8
|
-
const wxClientGlobal = globalThis;
|
|
9
|
-
const transportRetryDelay = 500;
|
|
10
|
-
const rebuildPollDelay = 1_000;
|
|
11
|
-
const updateFileWatchdogDelay = 2_000;
|
|
12
|
-
export function startWxUpdateClient() {
|
|
13
|
-
if (wxClientGlobal.__VITE_PLUGIN_TARO_WX_UPDATE_CLIENT__)
|
|
14
|
-
return;
|
|
15
|
-
const control = wxClientGlobal.__VITE_PLUGIN_TARO_WX_CONTROL__;
|
|
16
|
-
if (!control)
|
|
17
|
-
throw new Error('vite-plugin-taro could not find its WX update control configuration.');
|
|
18
|
-
let state = createWxUpdateClientState(control.buildId);
|
|
19
|
-
const sessionId = createSessionId();
|
|
20
|
-
let requestGeneration = 0;
|
|
21
|
-
let activeRequest;
|
|
22
|
-
let scheduledRequest;
|
|
23
|
-
let pendingBatchApply;
|
|
24
|
-
const dispatch = (event, apply) => {
|
|
25
|
-
const transition = transitionWxUpdateClient(state, event);
|
|
26
|
-
state = transition.state;
|
|
27
|
-
for (const command of transition.commands)
|
|
28
|
-
execute(command, apply);
|
|
29
|
-
};
|
|
30
|
-
const send = (action, version) => {
|
|
31
|
-
if (scheduledRequest)
|
|
32
|
-
clearTimeout(scheduledRequest);
|
|
33
|
-
scheduledRequest = undefined;
|
|
34
|
-
activeRequest?.abort();
|
|
35
|
-
const generation = ++requestGeneration;
|
|
36
|
-
activeRequest = wxClientGlobal.wx.request({
|
|
37
|
-
url: control.url,
|
|
38
|
-
method: 'POST',
|
|
39
|
-
data: {
|
|
40
|
-
token: control.token,
|
|
41
|
-
action,
|
|
42
|
-
buildId: state.buildId,
|
|
43
|
-
sessionId,
|
|
44
|
-
version
|
|
45
|
-
},
|
|
46
|
-
timeout: 30_000,
|
|
47
|
-
success(result) {
|
|
48
|
-
if (generation !== requestGeneration)
|
|
49
|
-
return;
|
|
50
|
-
activeRequest = undefined;
|
|
51
|
-
const response = parseResponse(result.data);
|
|
52
|
-
if (action === 'register' && response.type === 'registered') {
|
|
53
|
-
dispatch({ type: 'registration-completed' });
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
if (action === 'poll' && (response.type === 'idle' || response.type === 'changed')) {
|
|
57
|
-
dispatch({ type: 'poll-completed' });
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
if (response.type === 'batch-published') {
|
|
61
|
-
// If DevTools misses the update.js event, report the unchanged version and republish with a new nonce.
|
|
62
|
-
scheduleRequest(updateFileWatchdogDelay);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
if (response.type === 'rebuilding') {
|
|
66
|
-
scheduleRequest(rebuildPollDelay);
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
dispatch({ type: 'transport-failed' });
|
|
70
|
-
},
|
|
71
|
-
fail() {
|
|
72
|
-
if (generation !== requestGeneration)
|
|
73
|
-
return;
|
|
74
|
-
activeRequest = undefined;
|
|
75
|
-
dispatch({ type: 'transport-failed' });
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
};
|
|
79
|
-
/** Keeps exactly one delayed metadata request and discards it when protocol state advances. */
|
|
80
|
-
const scheduleRequest = (delay) => {
|
|
81
|
-
if (scheduledRequest)
|
|
82
|
-
clearTimeout(scheduledRequest);
|
|
83
|
-
const expectedPhase = state.phase;
|
|
84
|
-
const expectedVersion = state.version;
|
|
85
|
-
scheduledRequest = setTimeout(() => {
|
|
86
|
-
scheduledRequest = undefined;
|
|
87
|
-
if (state.phase !== expectedPhase || state.version !== expectedVersion)
|
|
88
|
-
return;
|
|
89
|
-
send(state.phase === 'registering' ? 'register' : 'poll', state.version);
|
|
90
|
-
}, delay);
|
|
91
|
-
};
|
|
92
|
-
const execute = (command, apply) => {
|
|
93
|
-
switch (command.type) {
|
|
94
|
-
case 'register':
|
|
95
|
-
send('register', command.version);
|
|
96
|
-
return;
|
|
97
|
-
case 'poll':
|
|
98
|
-
case 'report-version':
|
|
99
|
-
send('poll', command.version);
|
|
100
|
-
return;
|
|
101
|
-
case 'apply-batch': {
|
|
102
|
-
const batchApply = apply ?? pendingBatchApply;
|
|
103
|
-
pendingBatchApply = undefined;
|
|
104
|
-
if (!batchApply) {
|
|
105
|
-
dispatch({ type: 'batch-failed' });
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
const applyUpdate = () => {
|
|
109
|
-
const bridge = wxClientGlobal.__VITE_PLUGIN_TARO_WX_PAGE_UPDATE__;
|
|
110
|
-
if (!bridge) {
|
|
111
|
-
dispatch({ type: 'batch-failed' });
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
bridge.beginUpdate?.();
|
|
115
|
-
try {
|
|
116
|
-
batchApply();
|
|
117
|
-
dispatch({ type: 'batch-executed', targetVersion: command.targetVersion });
|
|
118
|
-
}
|
|
119
|
-
catch (error) {
|
|
120
|
-
console.error('[vite-plugin-taro] WX update execution failed', error);
|
|
121
|
-
dispatch({ type: 'batch-failed' });
|
|
122
|
-
}
|
|
123
|
-
finally {
|
|
124
|
-
bridge.endUpdate?.();
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
const bridge = wxClientGlobal.__VITE_PLUGIN_TARO_WX_PAGE_UPDATE__;
|
|
128
|
-
if (bridge?.ready)
|
|
129
|
-
applyUpdate();
|
|
130
|
-
else if (bridge)
|
|
131
|
-
bridge.pendingUpdate = applyUpdate;
|
|
132
|
-
else
|
|
133
|
-
dispatch({ type: 'batch-failed' });
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
case 'request-full-build':
|
|
137
|
-
send('rebuild', state.version);
|
|
138
|
-
return;
|
|
139
|
-
case 'retry-transport':
|
|
140
|
-
scheduleRequest(transportRetryDelay);
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
wxClientGlobal.__VITE_PLUGIN_TARO_WX_UPDATE_CLIENT__ = {
|
|
144
|
-
receiveBatch(metadata, apply) {
|
|
145
|
-
dispatch({ type: 'batch-observed', ...metadata }, apply);
|
|
146
|
-
if (state.pendingBatch?.fromVersion === metadata.fromVersion &&
|
|
147
|
-
state.pendingBatch.targetVersion === metadata.targetVersion) {
|
|
148
|
-
pendingBatchApply = apply;
|
|
149
|
-
}
|
|
150
|
-
else if (!state.pendingBatch && state.phase !== 'applying') {
|
|
151
|
-
pendingBatchApply = undefined;
|
|
152
|
-
}
|
|
153
|
-
},
|
|
154
|
-
refreshCompleted(stale) {
|
|
155
|
-
dispatch({ type: 'refresh-completed', stale });
|
|
156
|
-
},
|
|
157
|
-
routeReady() {
|
|
158
|
-
dispatch({ type: 'route-ready' });
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
dispatch({ type: 'started' });
|
|
162
|
-
}
|
|
163
|
-
function createSessionId() {
|
|
164
|
-
return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
165
|
-
}
|
|
166
|
-
function parseResponse(value) {
|
|
167
|
-
if (typeof value !== 'object' || value === null || !('type' in value) || typeof value.type !== 'string') {
|
|
168
|
-
return { type: 'invalid' };
|
|
169
|
-
}
|
|
170
|
-
return { type: value.type };
|
|
171
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
import type { ConfigEnv, ResolvedConfig } from 'vite'
|
|
3
|
-
import type { JsonObject, VitePluginTaroOptions, VitePluginTaroPageOption, VitePluginTaroTarget } from '../options.ts'
|
|
4
|
-
import { CssPipeline } from './css/css-pipeline.ts'
|
|
5
|
-
|
|
6
|
-
type ProjectContext = Readonly<{
|
|
7
|
-
target: VitePluginTaroTarget
|
|
8
|
-
appComponentFile: string
|
|
9
|
-
pages: readonly VitePluginTaroPageOption[]
|
|
10
|
-
appConfig: JsonObject
|
|
11
|
-
projectConfigJson: JsonObject
|
|
12
|
-
projectPrivateConfigJson?: JsonObject
|
|
13
|
-
sitemapJson: JsonObject
|
|
14
|
-
}>
|
|
15
|
-
|
|
16
|
-
/** Owns the shared project, Vite lifecycle state, and cross-target services for one build. */
|
|
17
|
-
export class BuildContext {
|
|
18
|
-
readonly project: ProjectContext
|
|
19
|
-
readonly css: CssPipeline
|
|
20
|
-
private developmentMode: boolean | undefined
|
|
21
|
-
private resolvedViteConfig: ResolvedConfig | undefined
|
|
22
|
-
|
|
23
|
-
constructor(options: VitePluginTaroOptions) {
|
|
24
|
-
this.css = new CssPipeline(options.target)
|
|
25
|
-
this.project = {
|
|
26
|
-
target: options.target,
|
|
27
|
-
appComponentFile: path.resolve(options.app),
|
|
28
|
-
pages: options.pages,
|
|
29
|
-
appConfig: {
|
|
30
|
-
...options.appJson,
|
|
31
|
-
pages: options.pages.map((page) => page.path)
|
|
32
|
-
},
|
|
33
|
-
projectConfigJson: options.projectConfigJson,
|
|
34
|
-
projectPrivateConfigJson: options.projectPrivateConfigJson,
|
|
35
|
-
sitemapJson: options.sitemapJson
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
configure(environment: ConfigEnv): void {
|
|
40
|
-
if (this.developmentMode !== undefined)
|
|
41
|
-
throw new Error('vite-plugin-taro build context was already configured.')
|
|
42
|
-
this.developmentMode = environment.command === 'serve'
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
resolve(config: ResolvedConfig): void {
|
|
46
|
-
if (this.developmentMode === undefined) {
|
|
47
|
-
throw new Error('vite-plugin-taro build context resolved before it was configured.')
|
|
48
|
-
}
|
|
49
|
-
if (this.resolvedViteConfig) throw new Error('vite-plugin-taro build context was already resolved.')
|
|
50
|
-
this.resolvedViteConfig = config
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
get development(): boolean {
|
|
54
|
-
if (this.developmentMode === undefined) throw new Error('vite-plugin-taro build context is not configured.')
|
|
55
|
-
return this.developmentMode
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
get vite(): ResolvedConfig {
|
|
59
|
-
if (!this.resolvedViteConfig) throw new Error('vite-plugin-taro build context is not resolved.')
|
|
60
|
-
return this.resolvedViteConfig
|
|
61
|
-
}
|
|
62
|
-
}
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs/promises'
|
|
2
|
-
import path from 'node:path'
|
|
3
|
-
import { extractSourceCandidates } from '@tailwindcss-mangle/engine'
|
|
4
|
-
import type { PluginOption, ResolvedConfig } from 'vite'
|
|
5
|
-
import { createContext } from 'weapp-tailwindcss/core'
|
|
6
|
-
import {
|
|
7
|
-
createWeappTailwindcssGenerator,
|
|
8
|
-
resolveTailwindV4Source,
|
|
9
|
-
type WeappTailwindcssGenerator
|
|
10
|
-
} from 'weapp-tailwindcss/generator'
|
|
11
|
-
import { WeappTailwindcss } from 'weapp-tailwindcss/vite'
|
|
12
|
-
import type { VitePluginTaroTarget } from '../../options.ts'
|
|
13
|
-
import { normalizeModuleId } from '../utils/modules.ts'
|
|
14
|
-
import { resolvePackageFile } from '../utils/packages.ts'
|
|
15
|
-
|
|
16
|
-
const wxStyleOptions = {
|
|
17
|
-
cssCalc: false,
|
|
18
|
-
autoprefixer: false,
|
|
19
|
-
rem2rpx: true,
|
|
20
|
-
px2rpx: true
|
|
21
|
-
} as const
|
|
22
|
-
|
|
23
|
-
type WxContext = ReturnType<typeof createContext>
|
|
24
|
-
type CssEntry = { source: string; generator: WeappTailwindcssGenerator }
|
|
25
|
-
type PatchResult = { code: string } | { requiresFullBuild: true }
|
|
26
|
-
|
|
27
|
-
/** Owns Tailwind's Vite integration and native WX patch synchronization. */
|
|
28
|
-
export class CssPipeline {
|
|
29
|
-
readonly plugins: PluginOption[]
|
|
30
|
-
// Each Tailwind CSS entry can define a different design system, so additions must pass every relevant validator.
|
|
31
|
-
private readonly entries = new Map<string, CssEntry>()
|
|
32
|
-
// Vite can report the same source more than once; avoid repeating extraction and validation.
|
|
33
|
-
private readonly sourceCache = new Map<string, string>()
|
|
34
|
-
// Upstream owns WX JavaScript escaping; this context is deliberately reused between patches.
|
|
35
|
-
private wxContext: WxContext | undefined
|
|
36
|
-
// CSS transforms arrive after configResolved, so the Vite root is retained for source and module resolution.
|
|
37
|
-
private root: string | undefined
|
|
38
|
-
// Only classes represented by a completed WX build are safe to publish in a JavaScript-only patch.
|
|
39
|
-
private builtClassSet = new Set<string>()
|
|
40
|
-
|
|
41
|
-
/** Composes the upstream web/WX plugins and adds candidate tracking only for native WX patches. */
|
|
42
|
-
constructor(target: VitePluginTaroTarget) {
|
|
43
|
-
const pipeline = this
|
|
44
|
-
|
|
45
|
-
const wx = target === 'wx'
|
|
46
|
-
|
|
47
|
-
this.plugins = [
|
|
48
|
-
wx
|
|
49
|
-
? {
|
|
50
|
-
name: 'vite-plugin-taro:wx-tailwind-pipeline',
|
|
51
|
-
enforce: 'pre',
|
|
52
|
-
configResolved(config) {
|
|
53
|
-
pipeline.resolveWx(config)
|
|
54
|
-
},
|
|
55
|
-
async transform(code, id) {
|
|
56
|
-
if (!isTailwindCssEntry(code, id)) return
|
|
57
|
-
await pipeline.registerCssEntry(id, code)
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
: undefined,
|
|
61
|
-
...(WeappTailwindcss({
|
|
62
|
-
appType: 'taro',
|
|
63
|
-
// Route split Tailwind imports around Vite's unresolved production CSS package imports.
|
|
64
|
-
rewriteCssImports: true,
|
|
65
|
-
generator: { target: wx ? 'weapp' : 'web' },
|
|
66
|
-
...(wx ? wxStyleOptions : {}),
|
|
67
|
-
logLevel: 'silent'
|
|
68
|
-
}) ?? [])
|
|
69
|
-
]
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/** Records every utility guaranteed to exist after a successful full WX build. */
|
|
73
|
-
async captureFullBuild(): Promise<void> {
|
|
74
|
-
this.sourceCache.clear()
|
|
75
|
-
// Preserve removed development CSS, matching upstream's append-only HMR default.
|
|
76
|
-
for (const { generator } of this.entries.values()) {
|
|
77
|
-
const result = await generator.generate({ scanSources: true })
|
|
78
|
-
for (const candidate of result.classSet) this.builtClassSet.add(candidate)
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/** Applies upstream mini-program compatibility transforms to Taro's fully materialized WXSS. */
|
|
83
|
-
async transformWxss(code: string): Promise<string> {
|
|
84
|
-
return (await this.getWxContext().transformWxss(code)).css
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/** Escapes a JavaScript-only WX patch, or rejects it when its utilities require new WXSS. */
|
|
88
|
-
async transformNativePatch(code: string, filename: string, files: string[]): Promise<PatchResult> {
|
|
89
|
-
if (await this.hasAddedCandidates(files)) return { requiresFullBuild: true }
|
|
90
|
-
const result = await this.getWxContext().transformJs(code, {
|
|
91
|
-
runtimeSet: this.builtClassSet,
|
|
92
|
-
filename,
|
|
93
|
-
generateMap: false
|
|
94
|
-
})
|
|
95
|
-
return { code: result.code }
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/** Retains Vite's root for resolving later CSS transforms and changed-file notifications. */
|
|
99
|
-
private resolveWx(config: ResolvedConfig): void {
|
|
100
|
-
this.root = config.root
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/** Creates one validator per Tailwind entry and refreshes the shared upstream WX transformer. */
|
|
104
|
-
private async registerCssEntry(id: string, source: string): Promise<void> {
|
|
105
|
-
const file = resolveFile(id, this.getRoot())
|
|
106
|
-
if (this.entries.get(file)?.source === source) return
|
|
107
|
-
const base = path.dirname(file)
|
|
108
|
-
const resolved = await resolveTailwindV4Source({
|
|
109
|
-
projectRoot: this.getRoot(),
|
|
110
|
-
cwd: this.getRoot(),
|
|
111
|
-
base,
|
|
112
|
-
baseFallbacks: [resolvePackageFile()],
|
|
113
|
-
css: source,
|
|
114
|
-
cssSources: [{ file, base, css: source, dependencies: [file] }]
|
|
115
|
-
})
|
|
116
|
-
this.entries.set(file, { source, generator: createWeappTailwindcssGenerator(resolved) })
|
|
117
|
-
this.wxContext = createContext({
|
|
118
|
-
appType: 'taro',
|
|
119
|
-
cssEntries: [...this.entries.keys()],
|
|
120
|
-
tailwindcssBasedir: this.getRoot(),
|
|
121
|
-
generator: { target: 'weapp' },
|
|
122
|
-
...wxStyleOptions,
|
|
123
|
-
logLevel: 'silent'
|
|
124
|
-
})
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/** Incrementally checks changed source files for utilities absent from the completed WX build. */
|
|
128
|
-
private async hasAddedCandidates(files: string[]): Promise<boolean> {
|
|
129
|
-
for (const input of files) {
|
|
130
|
-
const file = resolveFile(input, this.getRoot())
|
|
131
|
-
if (!/\.[cm]?[jt]sx?$/.test(file)) continue
|
|
132
|
-
const source = await fs.readFile(file, 'utf8')
|
|
133
|
-
if (this.sourceCache.get(file) === source) continue
|
|
134
|
-
this.sourceCache.set(file, source)
|
|
135
|
-
const extracted = await extractSourceCandidates(source, path.extname(file).slice(1))
|
|
136
|
-
for (const { generator } of this.entries.values()) {
|
|
137
|
-
const candidates = await generator.validateCandidates(extracted)
|
|
138
|
-
// Native WX patches bypass Vite; a new utility therefore requires synchronized WXSS first.
|
|
139
|
-
for (const candidate of candidates) if (!this.builtClassSet.has(candidate)) return true
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
return false
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/** Returns the initialized WX transformer and detects invalid lifecycle ordering. */
|
|
146
|
-
private getWxContext(): WxContext {
|
|
147
|
-
if (!this.wxContext) throw new Error('WX CSS pipeline was used before Vite resolved.')
|
|
148
|
-
return this.wxContext
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/** Returns the resolved project root and detects use before Vite configuration. */
|
|
152
|
-
private getRoot(): string {
|
|
153
|
-
if (!this.root) throw new Error('WX CSS pipeline was used before Vite resolved.')
|
|
154
|
-
return this.root
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/** Identifies style modules that establish a Tailwind design system. */
|
|
159
|
-
function isTailwindCssEntry(code: string, id: string): boolean {
|
|
160
|
-
return (
|
|
161
|
-
/\.(?:css|scss|sass|less|styl|stylus)(?:$|[?#])/.test(id) &&
|
|
162
|
-
/@(?:import|reference)\s+(?:url\(\s*)?["']tailwindcss(?:\/[^"']*)?["']/.test(code)
|
|
163
|
-
)
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/** Converts Vite IDs, including /@fs/ IDs and query strings, into normalized absolute paths. */
|
|
167
|
-
function resolveFile(id: string, root: string): string {
|
|
168
|
-
const normalized = normalizeModuleId(id).replace(/[?#].*$/, '')
|
|
169
|
-
const file = normalized.startsWith('/@fs/') ? normalized.slice('/@fs'.length) : normalized
|
|
170
|
-
return normalizeModuleId(path.resolve(root, file))
|
|
171
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { Plugin } from 'vite'
|
|
2
|
-
import { resolvePackageFile } from '../utils/packages.ts'
|
|
3
|
-
|
|
4
|
-
/** Public IDs used by Taro's API transform and generated target modules. */
|
|
5
|
-
export const virtualTaroApiId = 'virtual:taro/api'
|
|
6
|
-
const virtualTaroComponentsId = 'virtual:taro/components'
|
|
7
|
-
|
|
8
|
-
const runtimeModules = new Map([
|
|
9
|
-
[virtualTaroApiId, resolvePackageFile('dist/runtime/taro/api.js')],
|
|
10
|
-
[virtualTaroComponentsId, resolvePackageFile('dist/runtime/taro/components.js')]
|
|
11
|
-
])
|
|
12
|
-
|
|
13
|
-
/** Resolves target-neutral Taro shims once instead of duplicating this concern in every target plugin. */
|
|
14
|
-
export function createTaroRuntimePlugin(): Plugin {
|
|
15
|
-
return {
|
|
16
|
-
name: 'vite-plugin-taro:runtime',
|
|
17
|
-
enforce: 'pre',
|
|
18
|
-
resolveId(id) {
|
|
19
|
-
return runtimeModules.get(id)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|