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
@@ -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
  /**
@@ -10,7 +10,7 @@ export declare function isMiniClientEnvironment(environment: Readonly<{
10
10
  * Refresh adaptation transforms.
11
11
  *
12
12
  * The shared style pipeline already owns the resolver's ordered App/Page cascade policy, so the host does not reconstruct it
13
- * from unrelated Rolldown shell and transport entries.
13
+ * from unrelated Rolldown shell and bootstrap entries.
14
14
  */
15
15
  export declare function createMiniDevelopmentPlugin(contract: Pick<MiniContract, 'options' | 'runtime' | 'styles'>, styles: MiniStylePlugin): PluginOption[];
16
16
  /**
@@ -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[];
@@ -9,7 +9,6 @@ export type TaroContract = {
9
9
  /** Physical runtime modules selected by one Mini Program target. */
10
10
  export type RuntimeModulesContract = {
11
11
  bootstrap: string;
12
- transport: string;
13
12
  appShell: string;
14
13
  appCapsule: string;
15
14
  componentShell: string;
@@ -3,8 +3,13 @@ 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";
10
+ /** External bootstrap dependency emitted only after the bundled graph is finalized. */
11
+ export declare const miniTransportId = "\0vpt:mini-transport";
12
+ export declare const miniTransportFileName = "common/vpt/transport.js";
8
13
  /** Resolves the shared Taro facade's target initialization side effect. */
9
14
  export declare const taroTargetRuntimeId = "\0vpt:taro-target-runtime";
10
15
  /** Redirects Vite's injected browser preload helper to the bootstrap identity loader. */
@@ -20,25 +25,19 @@ export declare const pageComponentId = "\0vpt:page-component";
20
25
  /** Gives every Page shell one private capsule target that can be resolved using its route. */
21
26
  export declare const pageCapsuleId = "\0vpt:page-capsule";
22
27
  export type MiniChunk = Rolldown.PreRenderedChunk | Rolldown.RenderedChunk;
23
- /** Build-graph role of an explicit native lifecycle entry. */
24
- export type MiniEntryRole = 'shell' | 'capsule';
25
- /** Runtime domain in which one final Mini Program JavaScript chunk executes. */
26
- export type MiniExecutionKind = 'native' | 'capsule' | 'amphibious';
27
- /** Complete execution classification derived from one pass over a chunk's module IDs. */
28
- export type MiniChunkClassification = Readonly<{
29
- entryRole: MiniEntryRole | undefined;
30
- executionKind: MiniExecutionKind;
31
- isTransport: boolean;
32
- }>;
33
- /** Classifies chunks by runtime roles and framework vendor membership. */
34
- export type MiniModuleClassifier = (chunk: MiniChunk) => MiniChunkClassification;
35
- /** Groups the generated entry and core-js into common/polyfills.js. */
28
+ /** Distinguishes native shells, lifecycle entry capsules, ordinary capsules, and shared native/SystemJS infrastructure. */
29
+ export type MiniChunkKind = 'native' | 'entry-capsule' | 'normal-capsule' | 'amphibious';
30
+ /** Classifies chunks by their compiler-owned modules; ordinary application chunks are normal capsules. */
31
+ export type MiniModuleClassifier = (chunk: MiniChunk) => MiniChunkKind;
32
+ /** Native hook filter for the physical core-js graph; the generated import-only entry needs no host rewriting. */
33
+ export declare const miniPolyfillSourceFilter: RegExp;
34
+ /** Keeps the global binding and core-js in the pre-bootstrap native chunk, outside the recursive framework group. */
36
35
  export declare function isMiniPolyfillModule(moduleId: string): boolean;
37
- /** Uses the same resolved roots for vendor grouping and amphibious execution; Rolldown includes their dependencies. */
36
+ /** Groups framework modules by resolved package roots; Rolldown includes their dependencies. */
38
37
  export declare function isMiniFrameworkVendorModule(moduleId: string): boolean;
39
38
  /**
40
- * Classifies runtime entries and framework vendor chunks in one module-ID scan.
41
- * Amphibious chunks share bootstrap's bridge so native and SystemJS callers reuse the same exports.
42
- * Construction is O(1); each lookup is O(M), where M is the number of modules in the chunk.
39
+ * The Mini graph separates lifecycle entries from bootstrap/polyfill/runtime infrastructure. A compiler-owned module
40
+ * identifies its chunk's kind; chunks containing only application or framework modules are normal capsules.
41
+ * One scan stops at the first known identity: O(M) worst-case time and O(1) extra space, without per-chunk collections.
43
42
  */
44
43
  export declare function createMiniModuleClassifier(modules: RuntimeModulesContract): MiniModuleClassifier;
@@ -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;
@@ -0,0 +1,29 @@
1
+ import type { Rolldown } from 'vite';
2
+ import { type MiniModuleClassifier } from '../module/module.ts';
3
+ import type { PackageLocation } from '../placer/placement.ts';
4
+ /**
5
+ * Emits the closed transport table in generateBundle, after placement and content-hash resolution. Each switch case has two
6
+ * identities: the package-neutral final filename is the SystemJS registration ID, while the package-qualified filename
7
+ * supplies the literal native require path. Preliminary hash placeholders must not escape into this late-generated file.
8
+ *
9
+ * Transport itself executes only as native CommonJS in common/vpt/, separate from the bundled chunk namespace. Together
10
+ * with bootstrap it publishes native namespaces to SystemJS without re-evaluating their module bodies.
11
+ *
12
+ * Do not generate this table in renderChunk: that hook runs before Rolldown's final minifier/code generator, which can rewrite
13
+ * require.async("path") into require.async(`path`). TikTok (tt) misses these template-literal dependencies in its static scan,
14
+ * causing "Can't find module" even when the referenced subpackage file exists. This is a dependency-discovery issue, not a
15
+ * difference in JavaScript string values.
16
+ *
17
+ * Emit the finished CommonJS as an asset in generateBundle so Rolldown writes it without minifying or reprinting its quoted
18
+ * paths. Fixed compact syntax and JSON-encoded IDs need no AST or quote-repair pass, while application chunks retain full
19
+ * compression, mangling, and whitespace removal.
20
+ */
21
+ export declare function createTransportOutput({ bundle, classifyModule, getPackageLocation }: {
22
+ bundle: Rolldown.OutputBundle;
23
+ classifyModule: MiniModuleClassifier;
24
+ getPackageLocation(chunk: Rolldown.OutputChunk): PackageLocation;
25
+ }): {
26
+ type: "asset";
27
+ fileName: string;
28
+ source: string;
29
+ };
@@ -16,8 +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;
20
- getLoadMode(chunk: Rolldown.RenderedChunk): 'sync' | 'async';
19
+ /** Resolves a rendered chunk or its exact entry module ID to its planned physical path. */
20
+ getPhysicalChunkId(chunk: Rolldown.RenderedChunk | string): string;
21
21
  finalize(bundle: Rolldown.OutputBundle): readonly GeneratedSubpackage[];
22
22
  }>;
23
23
  /**
@@ -1,14 +1,13 @@
1
1
  import type { Plugin, Rolldown } from 'vite';
2
2
  import type { RuntimeModulesContract } from '../mini-contract.ts';
3
- import { isMiniPolyfillModule, type MiniChunkClassification, type MiniModuleClassifier } from '../module/module.ts';
3
+ import { isMiniPolyfillModule, type MiniChunkKind, type MiniModuleClassifier } from '../module/module.ts';
4
4
  import { type GeneratedSubpackage, type PackageLocation } from './placement.ts';
5
5
  export type { GeneratedSubpackage, Placement } from './placement.ts';
6
6
  /** Placement services consumed by the later Mini Program rendering and output hooks. */
7
7
  export type MiniPlacementPlugin = Plugin & Readonly<{
8
- classifyChunk(chunk: Rolldown.PreRenderedChunk | Rolldown.RenderedChunk): MiniChunkClassification;
8
+ classifyChunk(chunk: Rolldown.PreRenderedChunk | Rolldown.RenderedChunk): MiniChunkKind;
9
9
  getPackageLocation(chunk: Rolldown.RenderedChunk | Rolldown.OutputChunk): PackageLocation;
10
- getPhysicalChunkId(chunk: Rolldown.RenderedChunk): string;
11
- getLoadMode(chunk: Rolldown.RenderedChunk): 'sync' | 'async';
10
+ getPhysicalChunkId(chunk: Rolldown.RenderedChunk | string): string;
12
11
  getSubpackages(): readonly GeneratedSubpackage[];
13
12
  }>;
14
13
  /**
@@ -56,7 +55,7 @@ export declare function createPlacementRolldownOptions(classifyChunk: MiniModule
56
55
  * 1. Its config hook installs package-neutral Rolldown names and entry-signature semantics.
57
56
  * 2. `renderStart` atomically starts a generation in `awaiting-chunks`; no stale placement remains reachable.
58
57
  * 3. Its first pre-order `renderChunk` creates one immutable LTHP placement from the complete tree-shaken graph.
59
- * 4. `vpt:mini` asks this plugin only for package ownership, physical relocation, and native loading mode.
58
+ * 4. `vpt:mini` asks this plugin only for package ownership and physical relocation.
60
59
  * 5. Its pre-order `generateBundle` assigns each OutputChunk its package-qualified filename and publishes app.json declarations.
61
60
  *
62
61
  * The discriminated state is the only generation-local mutation: `idle → awaiting-chunks → planned → finalized`. Each hook
@@ -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,8 +1,9 @@
1
+ import { type Rolldown } from 'vite';
1
2
  import type { MiniContract } from '../mini-contract.ts';
2
3
  /** Creates the resolver and source specializer for one Mini Program module graph. */
3
4
  export declare function createResolver(contract: Pick<MiniContract, 'options' | 'runtime' | 'taro'>): {
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
+ resolveId(id: string, importer: string | undefined, projectRoot: string): string | Rolldown.PartialResolvedId | undefined;
6
+ specialize(code: string, id: string, sourcemap?: boolean): import("../../../utils/transform.ts").AstTransformResult | undefined;
6
7
  applicationEntryIds: string[];
7
8
  input: any;
8
9
  };
@@ -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;