vite-plugin-taro 0.7.4 → 0.7.5-beta.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.
Files changed (53) hide show
  1. package/README.en.md +2 -2
  2. package/README.md +2 -2
  3. package/dist/index.js +93 -101
  4. package/dist/node/plugins/h5/resolver/module-resolver.d.ts +1 -1
  5. package/dist/node/plugins/h5/transform-app.d.ts +2 -2
  6. package/dist/node/plugins/mini/dev/modes/devtools/devtools-hmr-mode.d.ts +1 -0
  7. package/dist/node/plugins/mini/dev/plugins.d.ts +1 -1
  8. package/dist/node/plugins/mini/dev/react-refresh.d.ts +3 -3
  9. package/dist/node/plugins/mini/global/create-mini-global-plugin.d.ts +4 -0
  10. package/dist/node/plugins/mini/mini-contract.d.ts +0 -1
  11. package/dist/node/plugins/mini/module/module.d.ts +16 -17
  12. package/dist/node/plugins/mini/native/create-mini-native-component-plugin.d.ts +3 -0
  13. package/dist/node/plugins/mini/output/create-transport-output.d.ts +29 -0
  14. package/dist/node/plugins/mini/placer/placement.d.ts +2 -2
  15. package/dist/node/plugins/mini/placer/placer.d.ts +4 -5
  16. package/dist/node/plugins/mini/polyfill/create-mini-polyfill-plugin.d.ts +2 -2
  17. package/dist/node/plugins/mini/polyfill/mini-browser-bindings.d.ts +1 -2
  18. package/dist/node/plugins/mini/render/capsule.d.ts +2 -2
  19. package/dist/node/plugins/mini/render/native.d.ts +4 -2
  20. package/dist/node/plugins/mini/render/system-js/string-editor.d.ts +23 -11
  21. package/dist/node/plugins/mini/resolve/resolver.d.ts +3 -2
  22. package/dist/node/plugins/mini/resolve/specialize-app-capsule.d.ts +1 -1
  23. package/dist/node/plugins/mini/resolve/specialize-page-capsule.d.ts +1 -1
  24. package/dist/node/plugins/mini/skeleton/recursive-page-templates.d.ts +6 -0
  25. package/dist/node/plugins/mini/styles/plugins.d.ts +12 -27
  26. package/dist/node/plugins/tt/create-tt-skeleton.d.ts +14 -0
  27. package/dist/node/plugins/tt/create-tt-template.d.ts +3 -0
  28. package/dist/node/plugins/tt/plugins.d.ts +7 -0
  29. package/dist/node/utils/transform.d.ts +7 -4
  30. package/dist/options.d.ts +13 -11
  31. package/dist/runtime/global/vpt-global.d.ts +5 -0
  32. package/dist/runtime/global/vpt-global.js +62 -0
  33. package/dist/runtime/mini/amphibious/bootstrap.d.ts +1 -1
  34. package/dist/runtime/mini/amphibious/bootstrap.js +13 -10
  35. package/dist/runtime/mini/dev/modes/devtools/devtools-runtime.d.ts +1 -1
  36. package/dist/runtime/mini/dev/modes/devtools/devtools-runtime.js +4 -6
  37. package/dist/runtime/mini/dev/modes/interpreter/interpreter-runtime.js +2 -0
  38. package/dist/runtime/mini/systemjs/system-core.d.ts +1 -0
  39. package/dist/runtime/mini/systemjs/system-core.js +1 -1
  40. package/dist/runtime/tt/dev/connect-tt-socket.d.ts +3 -0
  41. package/dist/runtime/tt/dev/connect-tt-socket.js +2 -0
  42. package/dist/runtime/tt/dev/devtools-runtime.d.ts +1 -0
  43. package/dist/runtime/tt/dev/devtools-runtime.js +4 -0
  44. package/dist/runtime/tt/dev/interpreter-runtime.d.ts +1 -0
  45. package/dist/runtime/tt/dev/interpreter-runtime.js +4 -0
  46. package/dist/runtime/tt/taro-runtime.d.ts +1 -0
  47. package/dist/runtime/tt/taro-runtime.js +15 -0
  48. package/package.json +4 -4
  49. package/dist/node/plugins/mini/render/transport.d.ts +0 -23
  50. package/dist/runtime/mini/amphibious/transport.d.ts +0 -2
  51. package/dist/runtime/mini/amphibious/transport.js +0 -4
  52. /package/dist/node/plugins/{mini/skeleton/platform → wx}/create-wx-template.d.ts +0 -0
  53. /package/dist/node/plugins/{mini/skeleton/platform → zfb}/create-zfb-template.d.ts +0 -0
@@ -0,0 +1,62 @@
1
+ /** Use the native object when available; otherwise recover it with the ungap/global-this getter technique. */
2
+ function getGlobalThis() {
3
+ // This provider is bundled independently, without global injection or HMR instrumentation.
4
+ if (typeof globalThis === 'object' && globalThis) {
5
+ return globalThis;
6
+ }
7
+ // worker
8
+ if (typeof self === 'object' && self) {
9
+ return self;
10
+ }
11
+ // browser
12
+ if (typeof window === 'object' && window) {
13
+ return window;
14
+ }
15
+ if (typeof this === 'object' && this) {
16
+ return this;
17
+ }
18
+ // https://mathiasbynens.be/notes/globalthis
19
+ // This fallback requires a host that inherits Object.prototype and permits its temporary modification.
20
+ // Both paths assign this local result so the return follows cleanup, avoiding an unreachable V8 coverage branch.
21
+ let resolved;
22
+ try {
23
+ Object.defineProperty(Object.prototype, '__vpt_global__', {
24
+ get() {
25
+ return this || self;
26
+ },
27
+ configurable: true
28
+ });
29
+ resolved = __vpt_global__;
30
+ }
31
+ catch (cause) {
32
+ console.error('Unable to resolve globalThis', cause);
33
+ resolved = getOrCreateFakeGlobal();
34
+ }
35
+ finally {
36
+ delete Object.prototype.__vpt_global__;
37
+ }
38
+ return resolved;
39
+ }
40
+ function getOrCreateFakeGlobal() {
41
+ // Separately bundled copies share one mutable fallback through this realm's Object constructor, not its possibly
42
+ // locked prototype. The non-enumerable, immutable cache slot is created only after the first failed discovery.
43
+ const key = typeof Symbol === 'function' && typeof Symbol.for === 'function'
44
+ ? Symbol.for('vpt.fake.global')
45
+ : 'vpt.fake.global';
46
+ const cached = Reflect.get(Object, key);
47
+ if (cached) {
48
+ return cached;
49
+ }
50
+ const fakeGlobal = {
51
+ Object: Object
52
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
53
+ };
54
+ fakeGlobal.globalThis = fakeGlobal;
55
+ Object.defineProperty(Object, key, { value: fakeGlobal });
56
+ return fakeGlobal;
57
+ }
58
+ /**
59
+ * One shared host object.
60
+ * This must be same instance even if the file is copied.
61
+ * */
62
+ export const vptGlobal = getGlobalThis();
@@ -1,3 +1,3 @@
1
1
  import '\0vpt:mini-polyfills';
2
- import '../systemjs/system-core.js';
2
+ export declare const System: any;
3
3
  export declare const __vitePreload: <Value>(load: () => Value) => Value;
@@ -1,17 +1,20 @@
1
+ import { vptGlobal } from '\0vpt:global-binding';
2
+ // This file must not have any raw reference to the `globalThis` free binding.
3
+ // biome-ignore lint/suspicious/noShadowRestrictedNames: intentional shadow
4
+ const globalThis = vptGlobal;
1
5
  // Install the selected polyfills before the runtime or application uses them.
2
6
  // @ts-expect-error: The Mini build resolves this private polyfills entry.
3
7
  import '\0vpt:mini-polyfills';
8
+ import { transport } from '\0vpt:mini-transport';
4
9
  // Install the minimal SystemJS loader and its synchronous-import extension before any native entry requests a capsule.
5
- import '../systemjs/system-core.js';
6
- import { transport } from './transport.js';
10
+ import { System as createdSystem } from '../systemjs/system-core.js';
11
+ // install the System on globalThis
12
+ globalThis.System = createdSystem;
13
+ // Publish the installed loader as an explicit native dependency; callers need no ambient globalThis binding.
14
+ export const System = createdSystem;
15
+ // Transport returns synchronous registrations for main-package capsules and amphibious modules, and promise-like
16
+ // registrations only for capsules that physically live in generated subpackages.
17
+ System.instantiate = transport;
7
18
  // Mini Program hosts have no modulepreload transport. Application import() boundaries retain System.import() and may load
8
19
  // asynchronous subpackage or top-level-await graphs through this identity wrapper.
9
20
  export const __vitePreload = (load) => load();
10
- // SystemJS installs on the language global before this dependent module evaluates.
11
- const installedSystem = globalThis.System;
12
- if (!installedSystem) {
13
- throw new Error('SystemJS failed to initialize in the Mini Program runtime');
14
- }
15
- // Transport returns synchronous registrations for main-package capsules and amphibious modules, and promise-like
16
- // registrations only for capsules that physically live in generated subpackages.
17
- installedSystem.instantiate = transport;
@@ -5,7 +5,7 @@ import { injectPageHmr as injectDevtoolsPageHmr } from './page-hmr.ts';
5
5
  * factories but does not execute application modules, allowing the shared runtime to install a complete batch before one render.
6
6
  */
7
7
  type DevtoolsPatch = RuntimePatch & {
8
- readonly factory: () => void;
8
+ readonly factory: (runtime: MiniHmrRuntime) => void;
9
9
  };
10
10
  type HmrPageConfig = Parameters<typeof injectDevtoolsPageHmr>[0];
11
11
  /** Adapts physical DevTools patch modules and Page replacement onto the shared Mini Program HMR runtime. */
@@ -11,19 +11,17 @@ class DevtoolsHmrRuntime extends MiniHmrRuntime {
11
11
  applyPatches(payload) {
12
12
  // The initial physical dependency exports undefined until the host has a patch range. Once present, apply synchronously:
13
13
  // imports below the Page banner must resolve against the new registry during this same native Page evaluation.
14
- if (!payload)
14
+ if (!payload) {
15
15
  return;
16
- this.applyPatchPayload(payload, installDevtoolsPatch);
16
+ }
17
+ // The wrapper's lexical parameter replaces the generated patch's assumption of a host-global runtime binding.
18
+ this.applyPatchPayload(payload, (patch) => patch.factory(this));
17
19
  }
18
20
  /** Preserves the mounted Page connection while DevTools re-registers its static config. */
19
21
  injectPageHmr(config) {
20
22
  return injectDevtoolsPageHmr(config);
21
23
  }
22
24
  }
23
- /** Executes only the native registration program; graph application remains owned by `MiniHmrRuntime`. */
24
- function installDevtoolsPatch(patch) {
25
- patch.factory();
26
- }
27
25
  /** Creates one platform-connected adapter for installation by a thin target runtime entry. */
28
26
  export function createDevtoolsHmrRuntime(connectSocket) {
29
27
  return new DevtoolsHmrRuntime(connectSocket);
@@ -14,6 +14,8 @@ class InterpreterHmrRuntime extends MiniHmrRuntime {
14
14
  // Trusted application patches share live host globals, including APIs installed during app startup, rather than Sval's
15
15
  // module-time sandbox snapshot. A function scope keeps patch-local declarations isolated, as in native HMR factories.
16
16
  const interpreter = new Sval({ sandBox: false });
17
+ // Bind this interpreter's runtime once; Sval also publishes the same singleton on its selected global object.
18
+ interpreter.import({ __rolldown_runtime__: this });
17
19
  this.installPatch = (patch) => interpreter.run(`(() => {\n${patch.code}\n})();`);
18
20
  }
19
21
  onSocketEvent(info, event, data) {
@@ -2,3 +2,4 @@ export { REGISTRY, systemJSPrototype };
2
2
  declare var REGISTRY: string | symbol;
3
3
  declare var systemJSPrototype: any;
4
4
  export declare function getOrCreateLoad(loader: any, id: any, firstParentUrl: any, meta: any): any;
5
+ export declare const System: any;
@@ -326,5 +326,5 @@ function postOrderExec(loader, load, seen) {
326
326
  }
327
327
  }
328
328
  }
329
- globalThis.System = new SystemJS();
329
+ export const System = new SystemJS();
330
330
  // biome-ignore-end lint: vendored SystemJS core
@@ -0,0 +1,3 @@
1
+ import type { ConnectMiniSocket } from '../../mini/dev/mini-hmr-runtime.ts';
2
+ /** TT's task-scoped socket uses the shared { data } message/send contract. */
3
+ export declare const connectTtSocket: ConnectMiniSocket;
@@ -0,0 +1,2 @@
1
+ /** TT's task-scoped socket uses the shared { data } message/send contract. */
2
+ export const connectTtSocket = (endpoint) => tt.connectSocket({ url: endpoint, protocols: ['vite-hmr'] });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ import { createDevtoolsHmrRuntime } from '../../mini/dev/modes/devtools/devtools-runtime.js';
2
+ import { connectTtSocket } from './connect-tt-socket.js';
3
+ // The language-global singleton retains Rolldown's module graph across native Page shell execution.
4
+ Reflect.set(globalThis, '__rolldown_runtime__', createDevtoolsHmrRuntime(connectTtSocket));
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ import { createInterpreterHmrRuntime } from '../../mini/dev/modes/interpreter/interpreter-runtime.js';
2
+ import { connectTtSocket } from './connect-tt-socket.js';
3
+ // One retained runtime owns the socket, interpreted factories, module cache, and Refresh boundaries.
4
+ Reflect.set(globalThis, '__rolldown_runtime__', createInterpreterHmrRuntime(connectTtSocket));
@@ -0,0 +1 @@
1
+ import 'vite-plugin-taro-runtime/plugin-platform-tt/runtime';
@@ -0,0 +1,15 @@
1
+ import { mergeReconciler } from '@tarojs/shared';
2
+ import 'vite-plugin-taro-runtime/plugin-platform-tt/runtime';
3
+ // TT requires declared native properties. Retain the stock lifecycle/events/options and add the independent Page root
4
+ // to both comp and CustomWrapper; recursive TTML forwards p without placing Page nodes inside the shared App tree.
5
+ mergeReconciler({
6
+ modifyRecursiveComponentConfig(config) {
7
+ return {
8
+ ...config,
9
+ properties: {
10
+ ...config.properties,
11
+ p: { type: Object, value: { cn: [] } }
12
+ }
13
+ };
14
+ }
15
+ });
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "vite-plugin-taro",
3
- "version": "0.7.4",
3
+ "version": "0.7.5-beta.1",
4
4
  "author": "sep2",
5
- "description": "Vite 8 plugin for building one React/Taro codebase for WeChat, Alipay, and H5 targets.",
5
+ "description": "Vite 8 plugin for building one React/Taro codebase for WeChat, Alipay, TikTok, and H5 targets.",
6
6
  "type": "module",
7
7
  "repository": {
8
8
  "type": "git",
@@ -43,6 +43,7 @@
43
43
  "taro",
44
44
  "wechat",
45
45
  "alipay",
46
+ "tiktok",
46
47
  "mini-program",
47
48
  "react"
48
49
  ],
@@ -65,7 +66,7 @@
65
66
  "rolldown": "1.2.8",
66
67
  "sval": "0.6.12",
67
68
  "tailwindcss": "^4.3.3",
68
- "vite-plugin-taro-runtime": "0.7.4"
69
+ "vite-plugin-taro-runtime": "0.7.5-beta.1"
69
70
  },
70
71
  "peerDependencies": {
71
72
  "react": "^19.3.0",
@@ -78,7 +79,6 @@
78
79
  "@babel/plugin-transform-dynamic-import": "^8.0.1",
79
80
  "@babel/plugin-transform-modules-commonjs": "^8.0.1",
80
81
  "@babel/plugin-transform-modules-systemjs": "^8.0.1",
81
- "@babel/types": "^8.0.5",
82
82
  "@oxc-project/types": "0.149.0",
83
83
  "@tailwindcss-mangle/engine": "0.2.0",
84
84
  "@types/node": "^26.5.1",
@@ -1,23 +0,0 @@
1
- import type { Rolldown } from 'vite';
2
- import { type AstTransformResult } from '../../../utils/transform.ts';
3
- import type { MiniModuleClassifier } from '../module/module.ts';
4
- /**
5
- * Materializes transport while Rolldown's preliminary hash placeholders are still active. Each switch case deliberately has
6
- * two IDs: the package-neutral preliminary filename without its `assets/` directory becomes the SystemJS registration
7
- * identity, while the LTHP-selected assets/package-qualified filename becomes the literal native require path. Rolldown
8
- * substitutes both hashes after this transform, so the
9
- * generated transport code and its own content hash describe the exact files that `generateBundle` later materializes.
10
- *
11
- * This intentionally creates broad hash invalidation: changing one capsule can rename transport, then bootstrap, then
12
- * chunks that import bootstrap. A Mini Program ships one application package rather than independently cached HTTP
13
- * chunks, so honest content hashes and automatic graph linking are more valuable than minimizing that hash fan-out.
14
- */
15
- export declare function materializeTransport({ code, transportChunk, chunks, classifyModule, getLoadMode, getPhysicalChunkId, sourcemap }: {
16
- code: string;
17
- transportChunk: Rolldown.RenderedChunk;
18
- chunks: Readonly<Record<string, Rolldown.RenderedChunk>>;
19
- classifyModule: MiniModuleClassifier;
20
- getLoadMode(chunk: Rolldown.RenderedChunk): 'sync' | 'async';
21
- getPhysicalChunkId?: (chunk: Rolldown.RenderedChunk) => string;
22
- sourcemap?: boolean;
23
- }): Promise<AstTransformResult>;
@@ -1,2 +0,0 @@
1
- /** Dispatches to one generated literal require and bridges amphibious CommonJS namespaces inline. */
2
- export declare const transport: (moduleId: string) => System.Registration | PromiseLike<System.Registration>;
@@ -1,4 +0,0 @@
1
- // Transport itself executes only as native CommonJS. It lives beside bootstrap because together they implement the
2
- // amphibious boundary that publishes native namespaces to SystemJS without re-evaluating their module bodies.
3
- /** Dispatches to one generated literal require and bridges amphibious CommonJS namespaces inline. */
4
- export const transport = __VPT_TRANSPORT__;