vite-plugin-taro 0.7.4 → 0.7.5-beta.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.
Files changed (48) 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/react-refresh.d.ts +3 -3
  8. package/dist/node/plugins/mini/global/create-mini-global-plugin.d.ts +4 -0
  9. package/dist/node/plugins/mini/module/module.d.ts +8 -4
  10. package/dist/node/plugins/mini/native/create-mini-native-component-plugin.d.ts +3 -0
  11. package/dist/node/plugins/mini/placer/placement.d.ts +2 -1
  12. package/dist/node/plugins/mini/placer/placer.d.ts +1 -1
  13. package/dist/node/plugins/mini/polyfill/create-mini-polyfill-plugin.d.ts +2 -2
  14. package/dist/node/plugins/mini/polyfill/mini-browser-bindings.d.ts +1 -2
  15. package/dist/node/plugins/mini/render/capsule.d.ts +2 -2
  16. package/dist/node/plugins/mini/render/native.d.ts +4 -2
  17. package/dist/node/plugins/mini/render/system-js/string-editor.d.ts +23 -11
  18. package/dist/node/plugins/mini/render/transport.d.ts +16 -4
  19. package/dist/node/plugins/mini/resolve/resolver.d.ts +1 -1
  20. package/dist/node/plugins/mini/resolve/specialize-app-capsule.d.ts +1 -1
  21. package/dist/node/plugins/mini/resolve/specialize-page-capsule.d.ts +1 -1
  22. package/dist/node/plugins/mini/skeleton/recursive-page-templates.d.ts +6 -0
  23. package/dist/node/plugins/mini/styles/plugins.d.ts +12 -27
  24. package/dist/node/plugins/tt/create-tt-skeleton.d.ts +14 -0
  25. package/dist/node/plugins/tt/create-tt-template.d.ts +3 -0
  26. package/dist/node/plugins/tt/plugins.d.ts +7 -0
  27. package/dist/node/utils/transform.d.ts +7 -4
  28. package/dist/options.d.ts +13 -11
  29. package/dist/runtime/global/vpt-global.d.ts +5 -0
  30. package/dist/runtime/global/vpt-global.js +62 -0
  31. package/dist/runtime/mini/amphibious/bootstrap.d.ts +1 -1
  32. package/dist/runtime/mini/amphibious/bootstrap.js +12 -9
  33. package/dist/runtime/mini/dev/modes/devtools/devtools-runtime.d.ts +1 -1
  34. package/dist/runtime/mini/dev/modes/devtools/devtools-runtime.js +4 -6
  35. package/dist/runtime/mini/dev/modes/interpreter/interpreter-runtime.js +2 -0
  36. package/dist/runtime/mini/systemjs/system-core.d.ts +1 -0
  37. package/dist/runtime/mini/systemjs/system-core.js +1 -1
  38. package/dist/runtime/tt/dev/connect-tt-socket.d.ts +3 -0
  39. package/dist/runtime/tt/dev/connect-tt-socket.js +2 -0
  40. package/dist/runtime/tt/dev/devtools-runtime.d.ts +1 -0
  41. package/dist/runtime/tt/dev/devtools-runtime.js +4 -0
  42. package/dist/runtime/tt/dev/interpreter-runtime.d.ts +1 -0
  43. package/dist/runtime/tt/dev/interpreter-runtime.js +4 -0
  44. package/dist/runtime/tt/taro-runtime.d.ts +1 -0
  45. package/dist/runtime/tt/taro-runtime.js +15 -0
  46. package/package.json +4 -4
  47. /package/dist/node/plugins/{mini/skeleton/platform → wx}/create-wx-template.d.ts +0 -0
  48. /package/dist/node/plugins/{mini/skeleton/platform → zfb}/create-zfb-template.d.ts +0 -0
@@ -10,5 +10,5 @@ export declare function createModuleResolver(options: VptOptions): {
10
10
  id: string;
11
11
  projectRoot: string;
12
12
  sourcemap?: boolean;
13
- }): Promise<import("../../../utils/transform.ts").AstTransformResult> | undefined;
13
+ }): import("../../../utils/transform.ts").AstTransformResult | undefined;
14
14
  };
@@ -1,10 +1,10 @@
1
1
  import type { VptOptions } from '../../../options.ts';
2
2
  import { type AstTransformResult } from '../../utils/transform.ts';
3
- /** Specializes the physical H5 App for one configured project. */
3
+ /** Specializes only the reserved expressions in VPT's physical H5 App; Vite lowers its TypeScript once afterward. */
4
4
  export declare function transformH5App({ code, id, options, projectRoot, sourcemap }: {
5
5
  code: string;
6
6
  id: string;
7
7
  options: VptOptions;
8
8
  projectRoot: string;
9
9
  sourcemap?: boolean;
10
- }): Promise<AstTransformResult>;
10
+ }): AstTransformResult;
@@ -18,6 +18,7 @@ export declare function renderInitialDevtoolsPatches(): string;
18
18
  * DevTools re-executes a live Page because this physical dependency changed. The Page banner passes the exported payload to the
19
19
  * persistent App runtime before importing its capsule. Keeping the module inert—rather than applying factories at top level—
20
20
  * makes that ordering explicit, lets the runtime reject stale build IDs, and makes replay by several live Pages safe.
21
+ * The caller-supplied parameter binds every generated runtime reference, including closures retained for lazy modules.
21
22
  */
22
23
  export declare function renderDevtoolsPatches(buildId: string, patches: readonly PatchUpdate[]): string;
23
24
  /**
@@ -2,13 +2,13 @@ import { type Plugin } from 'vite';
2
2
  /**
3
3
  * Installs the missing HTML preamble inside the Refresh runtime. Boundary modules import that runtime before evaluating
4
4
  * their preamble guards, including during incremental updates. Reconciler also imports it before registering its renderer.
5
- * The shared Rolldown injection binds free `window` references to the same Taro window in the preamble and boundaries.
5
+ * Development defines route Refresh's globals to globalThis; ordinary window lookups stay native.
6
6
  */
7
7
  export declare function createMiniReactRefreshTransforms(): Plugin[];
8
8
  /**
9
9
  * Reproduces the browser preamble at runtime evaluation, after its declarations initialize.
10
- * The renderer hook belongs to the real global used by Reconciler. The no-op registration and identity signature belong
11
- * to the injected Taro window, satisfying upstream guards without replacing module-local Refresh registration.
10
+ * The renderer hook, no-op registration and identity signature share Reconciler's real global. Development defines point
11
+ * upstream guards at these same properties without replacing module-local Refresh registration.
12
12
  * These shared protocol properties are initialized once per runtime module evaluation, not for each updated boundary.
13
13
  */
14
14
  export declare function transformRefreshRuntime(code: string): {
@@ -0,0 +1,4 @@
1
+ import { type Plugin } from 'vite';
2
+ import type { MiniPlacementPlugin } from '../placer/placer.ts';
3
+ /** Shares one standalone native provider between the application's virtual binding and the wrapped HMR runtime. */
4
+ export declare function createMiniGlobalPlugin(placement: Pick<MiniPlacementPlugin, 'getPhysicalChunkId'>): Plugin[];
@@ -3,6 +3,8 @@ import type { RuntimeModulesContract } from '../mini-contract.ts';
3
3
  export declare const miniRuntimeId: string;
4
4
  /** Identifies Rolldown's generated helper module independently of its unstable output filename. */
5
5
  export declare const rolldownRuntimeId = "\0rolldown/runtime.js";
6
+ /** Identifies the virtual binding shared by native files, SystemJS capsules and HMR factories. */
7
+ export declare const vptGlobalBindingId = "\0vpt:global-binding";
6
8
  /** Generates the selected core-js imports as one independently executable output entry. */
7
9
  export declare const miniPolyfillsId = "\0vpt:mini-polyfills";
8
10
  /** Resolves the shared Taro facade's target initialization side effect. */
@@ -30,14 +32,16 @@ export type MiniChunkClassification = Readonly<{
30
32
  executionKind: MiniExecutionKind;
31
33
  isTransport: boolean;
32
34
  }>;
33
- /** Classifies chunks by runtime roles and framework vendor membership. */
35
+ /** Classifies chunks by explicit runtime roles. */
34
36
  export type MiniModuleClassifier = (chunk: MiniChunk) => MiniChunkClassification;
35
- /** Groups the generated entry and core-js into common/polyfills.js. */
37
+ /** Native hook filter for the physical core-js graph; the generated import-only entry needs no host rewriting. */
38
+ export declare const miniPolyfillSourceFilter: RegExp;
39
+ /** Keeps the global binding and core-js in the pre-bootstrap native chunk, outside the recursive framework group. */
36
40
  export declare function isMiniPolyfillModule(moduleId: string): boolean;
37
- /** Uses the same resolved roots for vendor grouping and amphibious execution; Rolldown includes their dependencies. */
41
+ /** Groups framework modules by resolved package roots; Rolldown includes their dependencies. */
38
42
  export declare function isMiniFrameworkVendorModule(moduleId: string): boolean;
39
43
  /**
40
- * Classifies runtime entries and framework vendor chunks in one module-ID scan.
44
+ * Classifies explicit runtime entries in one module-ID scan; framework vendor remains a capsule.
41
45
  * Amphibious chunks share bootstrap's bridge so native and SystemJS callers reuse the same exports.
42
46
  * Construction is O(1); each lookup is O(M), where M is the number of modules in the chunk.
43
47
  */
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from 'vite';
2
+ /** Expands native interfaces before Vite erases their TypeScript field declarations. */
3
+ export declare function createMiniNativeComponentPlugin(): Plugin;
@@ -16,7 +16,8 @@ export type GeneratedSubpackage = MiniGeneratedSubpackage;
16
16
  /** Immutable ownership and materialization operations for one complete final-chunk graph. */
17
17
  export type Placement = Readonly<{
18
18
  getPackageLocation(chunk: Rolldown.RenderedChunk | Rolldown.OutputChunk): PackageLocation;
19
- getPhysicalChunkId(chunk: Rolldown.RenderedChunk): string;
19
+ /** Resolves a rendered chunk or its exact entry module ID to its planned physical path. */
20
+ getPhysicalChunkId(chunk: Rolldown.RenderedChunk | string): string;
20
21
  getLoadMode(chunk: Rolldown.RenderedChunk): 'sync' | 'async';
21
22
  finalize(bundle: Rolldown.OutputBundle): readonly GeneratedSubpackage[];
22
23
  }>;
@@ -7,7 +7,7 @@ export type { GeneratedSubpackage, Placement } from './placement.ts';
7
7
  export type MiniPlacementPlugin = Plugin & Readonly<{
8
8
  classifyChunk(chunk: Rolldown.PreRenderedChunk | Rolldown.RenderedChunk): MiniChunkClassification;
9
9
  getPackageLocation(chunk: Rolldown.RenderedChunk | Rolldown.OutputChunk): PackageLocation;
10
- getPhysicalChunkId(chunk: Rolldown.RenderedChunk): string;
10
+ getPhysicalChunkId(chunk: Rolldown.RenderedChunk | string): string;
11
11
  getLoadMode(chunk: Rolldown.RenderedChunk): 'sync' | 'async';
12
12
  getSubpackages(): readonly GeneratedSubpackage[];
13
13
  }>;
@@ -1,4 +1,4 @@
1
- import type { Plugin } from 'vite';
1
+ import { type Plugin } from 'vite';
2
2
  import type { MiniContract } from '../mini-contract.ts';
3
- /** Loads a standalone polyfills entry before bootstrap and retains Taro's renderer bindings. */
3
+ /** Loads selected polyfills before bootstrap and retains Taro's renderer bindings. */
4
4
  export declare function createMiniPolyfillPlugin(contract: Pick<MiniContract, 'options'>): Plugin;
@@ -1,6 +1,5 @@
1
- /** Taro's renderer-owned browser bindings; portable APIs use native globals or explicit polyfills. */
1
+ /** Taro's renderer-owned bindings. window stays native; portable APIs use native globals or explicit polyfills. */
2
2
  export declare const miniBrowserBindings: {
3
- window: [string, string];
4
3
  document: [string, string];
5
4
  navigator: [string, string];
6
5
  requestAnimationFrame: [string, string];
@@ -10,8 +10,8 @@ import type { AstTransformResult } from '../../../utils/transform.ts';
10
10
  * - Native App, Page, and Component shells must start through the host's synchronous lifecycle APIs, while their application
11
11
  * graph still needs ESM linking semantics such as cycles, live exports, dynamic imports, `import.meta`, and top-level await.
12
12
  * - The plugin therefore keeps native lifecycle shells as CommonJS and executes application "capsules" through the bundled
13
- * SystemJS runtime. Native shells enter that graph through the language-global `System.importSync`, and asynchronous boundaries use
14
- * the same runtime through `System.import`.
13
+ * SystemJS runtime. Native shells enter that graph through bootstrap's exported `System.importSync`, and asynchronous
14
+ * boundaries use the same runtime through `System.import`.
15
15
  *
16
16
  * What this renderer emits:
17
17
  *
@@ -9,7 +9,7 @@ import type { MiniModuleClassifier } from '../module/module.ts';
9
9
  * 1. Static ESM imports are hoisted into source-order `require` calls. Named imports remain property reads from the required
10
10
  * namespace so they observe current values. Default and namespace imports receive Babel-compatible CommonJS interop.
11
11
  * 2. An import whose target owns a capsule entry is not passed to native `require`. It becomes
12
- * the language-global `System.importSync(logicalChunkId)`, synchronously linking the capsule before the native lifecycle call.
12
+ * bootstrap's `System.importSync(logicalChunkId)`, synchronously linking the capsule before the native lifecycle call.
13
13
  * 3. Local exports are published at declaration and mutation points. Imported re-exports use getters, while assignments and
14
14
  * updates notify every alias without changing expression completion values or accidentally matching shadowed bindings.
15
15
  * 4. ESM top-level `this` becomes `undefined`. Direct imported calls and tags are explicitly unbound so converting an import
@@ -22,10 +22,12 @@ import type { MiniModuleClassifier } from '../module/module.ts';
22
22
  * source identifier. Source maps use the same range edits when requested; Mini Program development disables them and keeps this path
23
23
  * focused on startup latency.
24
24
  */
25
- export declare function renderNative({ code, chunk, chunks, classifyModule, sourcemap }: {
25
+ export declare function renderNative({ code, chunk, chunks, bootstrapModuleId, getPhysicalChunkId, classifyModule, sourcemap }: {
26
26
  code: string;
27
27
  chunk: Rolldown.RenderedChunk;
28
28
  chunks: Readonly<Record<string, Rolldown.RenderedChunk>>;
29
+ bootstrapModuleId: string;
30
+ getPhysicalChunkId: (chunk: Rolldown.RenderedChunk | string) => string;
29
31
  classifyModule: MiniModuleClassifier;
30
32
  sourcemap: boolean;
31
33
  }): AstTransformResult;
@@ -1,24 +1,36 @@
1
+ /** One half-open source range; omitted ranges also own insertions at both boundaries. */
2
+ type SourceRange = Readonly<{
3
+ start: number;
4
+ end: number;
5
+ }>;
1
6
  /**
2
- * Records non-overlapping range edits and renders them in one source-order pass.
7
+ * Collects range edits, then compiles one immutable, source-ordered plan for every rendered view.
3
8
  *
4
- * Final Mini Program development chunks do not request source maps. RolldownMagicString's repeated relocation of hoisted
5
- * functions is considerably more expensive than the semantic analysis itself, so this editor keeps the same range operations
6
- * while avoiding a mutable chunk graph when no mappings can be observed.
9
+ * Final Mini Program development chunks do not request source maps. Hoisted functions and the remaining module body
10
+ * are disjoint views of the same plan, rather than repeated scans/sorts followed by destructive function removals.
11
+ *
12
+ * For E edits and F hoisted functions, compilation costs O(E log E) plus insertion text assembly. Each view uses binary
13
+ * searches followed by forward-only cursors over its edits. Rendering all functions and the remaining body costs
14
+ * O(E + F log E + output characters); views never scan the complete insertion journal per replacement or function.
15
+ * Storage is O(E + inserted text) plus rendered output, owned by this compilation only.
7
16
  */
8
17
  export declare class StringEditor {
9
18
  #private;
10
19
  readonly original: string;
11
20
  constructor(original: string);
12
- /** Records a half-open replacement; semantic passes guarantee ranges are nested or disjoint. */
21
+ /** Records a replacement, including empty replacements for removed import declarations. */
13
22
  overwrite(start: number, end: number, content: string): void;
14
- /** Removes a range and discards insertions that were owned only by that removed source. */
15
- remove(start: number, end: number): void;
16
- /** Inserts before prior insertions at a boundary, matching MagicString's prependLeft ordering. */
23
+ /** Records prepend order in O(1), avoiding unshift's repeated movement of earlier insertions. */
17
24
  prependLeft(position: number, content: string): void;
18
- /** Inserts after prior insertions at the left side of a boundary. */
19
25
  appendLeft(position: number, content: string): void;
20
26
  /** Matches the subset of appendRight ordering used by the capsule compiler. */
21
27
  appendRight(position: number, content: string): void;
22
- /** Materializes one source slice without mutating its edit journal, allowing functions to be rendered before relocation. */
23
- render(start: number, end: number): string;
28
+ /** Sorts once after semantic edits finish; all function/body views share this immutable snapshot. */
29
+ compile(): {
30
+ /** Includes boundary insertions so relocated functions keep every edit they own. */
31
+ render: (start: number, end: number) => string;
32
+ /** Ranges must be disjoint and in source order, as direct Program function declarations are. */
33
+ renderOutside: (ranges: readonly SourceRange[]) => string;
34
+ };
24
35
  }
36
+ export {};
@@ -1,12 +1,13 @@
1
1
  import type { Rolldown } from 'vite';
2
2
  import { type AstTransformResult } from '../../../utils/transform.ts';
3
3
  import type { MiniModuleClassifier } from '../module/module.ts';
4
+ export declare const transportPlaceholder = "__VPT_TRANSPORT__";
4
5
  /**
5
6
  * 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.
7
+ * two IDs: the normalized preliminary filename becomes the SystemJS registration identity, while the LTHP-selected
8
+ * assets/package-qualified filename becomes the literal native require path. Rolldown
9
+ * substitutes both hashes after this transform, so the generated transport code and its own content hash describe the exact
10
+ * files that `generateBundle` later materializes.
10
11
  *
11
12
  * This intentionally creates broad hash invalidation: changing one capsule can rename transport, then bootstrap, then
12
13
  * chunks that import bootstrap. A Mini Program ships one application package rather than independently cached HTTP
@@ -21,3 +22,14 @@ export declare function materializeTransport({ code, transportChunk, chunks, cla
21
22
  getPhysicalChunkId?: (chunk: Rolldown.RenderedChunk) => string;
22
23
  sourcemap?: boolean;
23
24
  }): Promise<AstTransformResult>;
25
+ /**
26
+ * Generates the closed transport expression from fixed ES2018-compatible syntax and JSON-encoded IDs and paths.
27
+ * All require arguments stay literal; inserting this expression needs neither Babel AST construction nor another Oxc pass.
28
+ */
29
+ export declare function createTransportExpression({ transportChunk, chunks, classifyModule, getLoadMode, getPhysicalChunkId }: {
30
+ transportChunk: Rolldown.RenderedChunk;
31
+ chunks: Readonly<Record<string, Rolldown.RenderedChunk>>;
32
+ classifyModule: MiniModuleClassifier;
33
+ getLoadMode(chunk: Rolldown.RenderedChunk): 'sync' | 'async';
34
+ getPhysicalChunkId(chunk: Rolldown.RenderedChunk): string;
35
+ }): string;
@@ -2,7 +2,7 @@ import type { MiniContract } from '../mini-contract.ts';
2
2
  /** Creates the resolver and source specializer for one Mini Program module graph. */
3
3
  export declare function createResolver(contract: Pick<MiniContract, 'options' | 'runtime' | 'taro'>): {
4
4
  resolveId(id: string, importer: string | undefined, projectRoot: string): string | undefined;
5
- specialize(code: string, id: string, sourcemap?: boolean): Promise<import("../../../utils/transform.ts").AstTransformResult> | undefined;
5
+ specialize(code: string, id: string, sourcemap?: boolean): import("../../../utils/transform.ts").AstTransformResult | undefined;
6
6
  applicationEntryIds: string[];
7
7
  input: any;
8
8
  };
@@ -6,4 +6,4 @@ export declare function specializeAppCapsule({ code, id, appConfig, sourcemap }:
6
6
  id: string;
7
7
  appConfig: MiniJsonObject;
8
8
  sourcemap?: boolean;
9
- }): Promise<AstTransformResult>;
9
+ }): AstTransformResult;
@@ -6,4 +6,4 @@ export declare function specializePageCapsule({ code, id, page, sourcemap }: {
6
6
  id: string;
7
7
  page: MiniPage;
8
8
  sourcemap?: boolean;
9
- }): Promise<AstTransformResult>;
9
+ }): AstTransformResult;
@@ -0,0 +1,6 @@
1
+ /** Threads a Page root through recursive template scopes without serializing it into the App's compact tree. */
2
+ export declare function buildRecursiveBaseTemplate(source: string, directive: 'a' | 'tt'): string;
3
+ /** Starts the recursive App host with both independent native data roots. */
4
+ export declare function buildRecursiveComponentTemplate(source: string): string;
5
+ /** Keeps the independent Page root when App rendering crosses CustomWrapper. */
6
+ export declare function buildRecursiveCustomWrapperTemplate(source: string): string;
@@ -1,13 +1,10 @@
1
1
  import { type Plugin } from 'vite';
2
2
  import type { MiniContract } from '../mini-contract.ts';
3
- import { createMiniTransformer } from './create-mini-transformer.ts';
4
- import { minifyMiniStylesheet } from './minify-mini-stylesheet.ts';
5
3
  /** JavaScript code plus the physical filename required by the Mini Program class-name transformer. */
6
4
  type JavaScriptArtifact = Readonly<{
7
5
  code: string;
8
6
  filename: string;
9
7
  }>;
10
- type MiniTransformer = ReturnType<typeof createMiniTransformer>;
11
8
  /** Vite plugin with the host operation that finalizes one coherent native-style/JavaScript transaction. */
12
9
  export type MiniStylePlugin = Plugin & Readonly<{
13
10
  /** Neutralizes browser CSS payloads and atomically publishes the matching global native stylesheet. */
@@ -85,6 +82,11 @@ export type MiniStylePlugin = Plugin & Readonly<{
85
82
  * publication. Any conversion or minification failure rejects before callers expose partial output. JavaScript conversion is
86
83
  * skipped when the projection contains no Tailwind candidates, preserving ordinary bundle bytes.
87
84
  *
85
+ * `createFinalizeOutput()` captures the resolved output policy once and retains only the latest successful CSS conversion and
86
+ * candidate identity. Every transaction supplies a fresh live-graph projection, but byte-identical CSS skips both PostCSS and
87
+ * Lightning CSS. Equal candidate contents reuse the same set and replacement table even when the projection allocated a new
88
+ * set. Changed candidates never reuse stale replacements; conversion failures do not advance the snapshot.
89
+ *
88
90
  * ### 5a. Complete-build commit
89
91
  *
90
92
  * The post-order `generateBundle` hook gathers all JavaScript chunks, finalizes them as one operation, and only then mutates the
@@ -103,14 +105,14 @@ export type MiniStylePlugin = Plugin & Readonly<{
103
105
  *
104
106
  * ## Retained state and lifecycle
105
107
  *
106
- * The factory retains five explicit mutable state owners plus one fixed transformation service:
108
+ * Each plugin instance owns the following bounded state and transformation services:
107
109
  *
108
110
  * - `cssMinify`: requested global-style minification captured before disabling Vite's intermediate pass, then resolved once;
109
111
  * - `entryIds`: graph-exact App/Page entry identities resolved at the start of each build;
110
112
  * - `graphContext`: the active Rolldown graph reader needed by host calls made outside plugin hooks;
111
113
  * - `styleByModuleId`: the latest successful Vite CSS plus optional Tailwind state at one normalized module identity;
112
114
  * - `publishedStylesheet`: the last durably published development stylesheet used for unchanged-write suppression;
113
- * - `miniTransformer`: fixed stylesheet options and escaped-class cache shared by CSS and JavaScript conversion.
115
+ * - `finalizeOutput`: resolved output options, the fixed Mini transformer, and the latest successful CSS/candidate snapshot.
114
116
  *
115
117
  * The state owners remain scoped to one plugin instance; `entryIds` is atomically replaced after each complete resolution.
116
118
  * A development watcher retains them across updates; build and watcher shutdown clear the complete style store.
@@ -120,28 +122,11 @@ export type MiniStylePlugin = Plugin & Readonly<{
120
122
  * Projection is `O(V + E + B + C)` for reachable modules, import edges, concatenated CSS bytes, and candidate insertions.
121
123
  * Building one exact candidate precheck costs `O(C)` candidate bytes and testing a chunk costs `O(J)` source bytes. Matching
122
124
  * chunks then parse and walk in `O(J)`; replacing `Kᵢ` candidate tokens in literal `i` costs `O(LᵢKᵢ)` while preserving
123
- * untouched bytes through Rolldown's native editor. Retained memory is `O(B + C + D + F)` for latest CSS, candidate sets,
124
- * compiler dependencies, and watched file identities; no second application graph is retained. The Tailwind generator stays
125
- * alive across candidate edits to avoid repeating source normalization and compiler initialization. Enabled minification parses
126
- * the one final global stylesheet in builds and HMR; no extra source reads or graph traversals are needed.
125
+ * untouched bytes through Rolldown's native editor. Comparing candidate sets costs `O(C)` without sorting. Retained memory
126
+ * is `O(B + C + D + F)` for latest CSS, candidate sets, compiler dependencies, and watched file identities; no second application
127
+ * graph is retained. The Tailwind generator stays alive across candidate edits to avoid repeating source normalization and
128
+ * compiler initialization. Native CSS conversion/minification runs only when projected CSS changes;
129
+ * no extra source reads or graph traversals are needed.
127
130
  */
128
131
  export declare function createMiniStylePlugin(contract: Pick<MiniContract, 'styles'>, applicationEntryIds: readonly string[]): MiniStylePlugin;
129
- /**
130
- * Produces native CSS and JavaScript from one live-graph projection.
131
- *
132
- * The function receives every stateful dependency explicitly so tests and both output modes execute the same algorithm. It
133
- * completes stylesheet conversion and optional minification before JavaScript conversion and returns bytes without publication.
134
- */
135
- export declare function finalizeOutput(entryIds: readonly string[], styleByModuleId: ReadonlyMap<string, Readonly<{
136
- css: string | undefined;
137
- tailwind: Readonly<{
138
- classSet: ReadonlySet<string>;
139
- }> | undefined;
140
- }>>, getModuleInfo: (moduleId: string) => Readonly<{
141
- importedIds: readonly string[];
142
- dynamicallyImportedIds: readonly string[];
143
- }> | null | undefined, miniTransformer: MiniTransformer, javaScript: readonly JavaScriptArtifact[], stylesheetOptions: Parameters<typeof minifyMiniStylesheet>[1]): Promise<{
144
- javaScript: string[];
145
- stylesheet: string;
146
- }>;
147
132
  export {};
@@ -0,0 +1,14 @@
1
+ import type { Rolldown } from 'vite';
2
+ import type { VptOptions } from '../../../options.ts';
3
+ import type { MiniProjectSkeletonInput } from '../mini/mini-contract.ts';
4
+ type TtSkeletonInput = MiniProjectSkeletonInput & Readonly<{
5
+ options: VptOptions;
6
+ componentsModulePath: string;
7
+ }>;
8
+ /**
9
+ * TT supports recursive named templates. Like Alipay, its App host carries the independent Page root as p through each
10
+ * template scope and CustomWrapper boundary. The TT runtime declares p as a native property on both generated components.
11
+ * This preserves the App → Page React tree without copying Page nodes into the shared App projection or adding layout nodes.
12
+ */
13
+ export declare function createTtSkeleton({ bundle, subpackages, nativeComponents, isProduction, options, componentsModulePath }: TtSkeletonInput): Rolldown.EmittedAsset[];
14
+ export {};
@@ -0,0 +1,3 @@
1
+ import { RecursiveTemplate } from '@tarojs/shared/dist/template.js';
2
+ /** Creates an isolated mutable component registry for one TT skeleton generation. */
3
+ export declare function createTtTemplate(): RecursiveTemplate;
@@ -0,0 +1,7 @@
1
+ import type { PluginOption } from 'vite';
2
+ import type { VptOptions } from '../../../options.ts';
3
+ import type { MiniContract } from '../mini/mini-contract.ts';
4
+ /** Adapts the shared Mini Program pipeline to TikTok. */
5
+ export declare function createTtMiniPlugins(options: VptOptions): PluginOption[];
6
+ /** Binds TT's runtime, native templates, styles, and socket transport to the shared compiler. */
7
+ export declare function createTtMiniContract(options: VptOptions): MiniContract;
@@ -1,8 +1,11 @@
1
- import { generate } from '@babel/generator';
2
- import { type Rolldown } from 'vite';
1
+ import type { Rolldown } from 'vite';
3
2
  export type AstTransformResult = {
4
3
  code: string;
5
4
  map: Rolldown.ExistingRawSourceMap | null;
6
5
  };
7
- /** Replaces each placeholder with a Babel AST expression while transforming the module through Oxc. */
8
- export declare function replaceWithAst(code: string, filename: string, replacement: Readonly<Record<string, Parameters<typeof generate>[0]>>, sourcemap?: boolean): Promise<AstTransformResult>;
6
+ /**
7
+ * Specializes compiler-owned templates by their unique reserved slots. This is not a JavaScript substitution API:
8
+ * the shipped templates own the expression positions, and their tests verify those positions. Values must already be
9
+ * serialized JavaScript expressions. Vite remains the sole owner of TypeScript/JSX lowering and syntax validation.
10
+ */
11
+ export declare function replaceTemplate(code: string, filename: string, replacement: Readonly<Record<string, string>>, sourcemap: boolean): AstTransformResult;
package/dist/options.d.ts CHANGED
@@ -9,7 +9,7 @@ export type VptAppConfig = VptJsonObject;
9
9
  /** Page configuration written in the selected target's native schema. */
10
10
  export type VptPageConfig = VptJsonObject;
11
11
  /** Build target handled by this plugin. */
12
- export type VptTarget = 'wx' | 'zfb' | 'h5';
12
+ export type VptTarget = 'wx' | 'zfb' | 'tt' | 'h5';
13
13
  /** Selects one implemented Mini Program development update mechanism. */
14
14
  export type VptHmrOptions = Readonly<{
15
15
  /**
@@ -30,9 +30,9 @@ export type VptPageOption = {
30
30
  /**
31
31
  * Optional native Page configuration for the selected target.
32
32
  *
33
- * Use Taro/WeChat keys for WX and H5, and Alipay keys for ZFB. The plugin preserves these fields in the Page runtime capsule
34
- * and `<path>.json`, adding generated native-component registrations separately. It does not translate configuration names
35
- * between platforms.
33
+ * Use WeChat keys for WX, Alipay keys for ZFB, TikTok keys for TT, and Taro/WeChat keys for H5. The plugin preserves these
34
+ * fields in the Page runtime capsule and `<path>.json`, adding generated native-component registrations separately.
35
+ * It does not translate configuration names between platforms.
36
36
  */
37
37
  config?: VptPageConfig;
38
38
  };
@@ -41,7 +41,7 @@ export interface VptOptions {
41
41
  /**
42
42
  * Platform produced by the current Vite invocation.
43
43
  *
44
- * Use `wx` to emit a WeChat Mini Program, `zfb` to emit an Alipay Mini Program, or `h5` to emit a browser application.
44
+ * Use `wx` for WeChat, `zfb` for Alipay, `tt` for TikTok Mini Programs, or `h5` for a browser application.
45
45
  * The selected target controls Taro module resolution, conditional compilation, runtime bootstrapping, style processing,
46
46
  * and output generation.
47
47
  */
@@ -63,8 +63,8 @@ export interface VptOptions {
63
63
  /**
64
64
  * Native application configuration for the selected target.
65
65
  *
66
- * Use Taro/WeChat keys for WX and H5, and Alipay keys for ZFB. The plugin otherwise preserves the supplied configuration for
67
- * runtime specialization and `app.json`; it does not translate configuration names between platforms. The plugin always
66
+ * Use WeChat keys for WX, Alipay keys for ZFB, TikTok keys for TT, and Taro/WeChat keys for H5. The plugin preserves the supplied
67
+ * configuration for runtime specialization and `app.json`; it does not translate configuration names between platforms. The plugin always
68
68
  * derives `pages` from {@link pages}; caller-provided `pages`, `subPackages`, and `subpackages` values are discarded because
69
69
  * the build pipeline owns page order and generated package placement.
70
70
  */
@@ -72,7 +72,7 @@ export interface VptOptions {
72
72
  /**
73
73
  * Native development-tool project configuration written without merging.
74
74
  *
75
- * WX emits this object as `project.config.json`; ZFB emits it as `mini.project.json`; H5 ignores it. Supply the schema
75
+ * WX emits `project.config.json`; ZFB emits `mini.project.json`; TT emits `project.config.json`; H5 ignores it. Supply the schema
76
76
  * expected by the selected target rather than sharing one project's platform-specific values across invocations. ZFB must
77
77
  * use format 2 with `compileOptions.globalObjectMode: 'enable'` because the upstream Taro runtime reads the platform `global`;
78
78
  * its Taro-style ES6 output also relies on `compileOptions.transpile` for the developer tool's final syntax conversion.
@@ -81,7 +81,8 @@ export interface VptOptions {
81
81
  /**
82
82
  * Local development-tool preferences written without merging.
83
83
  *
84
- * WX emits this object as `project.private.config.json`; ZFB emits it as `.mini-ide/project-ide.json`; H5 ignores it.
84
+ * WX emits `project.private.config.json`; ZFB emits `.mini-ide/project-ide.json`; TT emits `project.private.config.json`;
85
+ * H5 ignores it. TT private configuration requires TikTok DevTools 4.0.7+ and supports only its documented fields.
85
86
  * These files control local IDE behavior rather than portable application metadata. In particular, the ZFB file does not
86
87
  * associate the project with an Alipay App ID; Alipay Mini Program Studio keeps that selection in its workspace storage.
87
88
  */
@@ -89,7 +90,7 @@ export interface VptOptions {
89
90
  /**
90
91
  * WeChat Mini Program indexing rules written to `sitemap.json` without merging.
91
92
  *
92
- * The file is emitted only when this value is provided for a `wx` build. It is ignored for ZFB and H5.
93
+ * The file is emitted only when this value is provided for a `wx` build. It is ignored for ZFB, TT, and H5.
93
94
  */
94
95
  sitemapJson?: VptJsonObject;
95
96
  /**
@@ -109,7 +110,8 @@ export interface VptOptions {
109
110
  /**
110
111
  * Selects the Mini Program development update mode. Omission uses `devtools`.
111
112
  *
112
- * This option affects only `vite serve` for `wx` and `zfb` targets and never changes H5 or production output.
113
+ * This option affects only `vite serve` for `wx`, `zfb`, and `tt` targets and never changes H5 or production output.
114
+ * Prefer `interpreter` on TT; native DevTools patch execution has not been verified in TikTok DevTools.
113
115
  */
114
116
  hmr?: VptHmrOptions;
115
117
  }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * One shared host object.
3
+ * This must be same instance even if the file is copied.
4
+ * */
5
+ export declare const vptGlobal: typeof globalThis;
@@ -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';
4
8
  // Install the minimal SystemJS loader and its synchronous-import extension before any native entry requests a capsule.
5
- import '../systemjs/system-core.js';
9
+ import { System as createdSystem } from '../systemjs/system-core.js';
6
10
  import { transport } from './transport.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. */