vite-plugin-taro 0.7.8 → 0.7.10-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.
- package/dist/index.js +604 -344
- package/dist/node/plugins/mini/dev/create-hmr-results-stream.d.ts +10 -8
- package/dist/node/plugins/mini/dev/hmr-files.d.ts +2 -2
- package/dist/node/plugins/mini/dev/hmr-mode.d.ts +2 -2
- package/dist/node/plugins/mini/dev/inject-dev-page-component.d.ts +11 -0
- package/dist/node/plugins/mini/dev/mini-dev-options.d.ts +9 -15
- package/dist/node/plugins/mini/dev/modes/devtools/devtools-hmr-mode.d.ts +1 -2
- package/dist/node/plugins/mini/dev/modes/interpreter/interpreter-hmr-mode.d.ts +1 -2
- package/dist/node/plugins/mini/dev/modes/rebuild/rebuild-hmr-mode.d.ts +1 -2
- package/dist/node/plugins/mini/dev/plugins.d.ts +1 -1
- package/dist/node/plugins/mini/dev/replace-vite-transform-plugin.d.ts +6 -0
- package/dist/node/plugins/mini/mini-contract.d.ts +7 -14
- package/dist/node/plugins/mini/module/module.d.ts +20 -11
- package/dist/node/plugins/mini/output/create-transport-output.d.ts +1 -3
- package/dist/node/plugins/mini/placer/placer.d.ts +3 -5
- package/dist/node/plugins/mini/render/native.d.ts +1 -4
- package/dist/node/plugins/mini/resolve/resolver.d.ts +15 -2
- package/dist/node/plugins/mini/styles/minify-mini-stylesheet.d.ts +1 -1
- package/dist/node/plugins/mini/styles/plugins.d.ts +58 -45
- package/dist/node/plugins/mini/styles/project-mini-styles.d.ts +52 -0
- package/dist/node/plugins/mini/watch/create-mini-watch-plugin.d.ts +5 -2
- package/dist/node/tests/create-mini-style-entries.d.ts +3 -0
- package/dist/node/tests/create-native-dev-runtime.d.ts +7 -0
- package/dist/node/utils/packages.d.ts +3 -3
- package/dist/runtime/mini/dev/hmr-protocol.d.ts +2 -2
- package/dist/runtime/mini/dev/hmr-protocol.js +1 -1
- package/dist/runtime/mini/dev/mini-hmr-runtime.d.ts +8 -6
- package/dist/runtime/mini/dev/mini-hmr-runtime.js +35 -10
- package/dist/runtime/mini/dev/modes/devtools/devtools-runtime.js +1 -1
- package/dist/runtime/mini/dev/modes/interpreter/interpreter-runtime.d.ts +1 -1
- package/dist/runtime/mini/dev/modes/interpreter/interpreter-runtime.js +1 -1
- package/dist/runtime/mini/systemjs/system-core.js +1 -1
- package/package.json +5 -5
|
@@ -3,13 +3,15 @@ import { type SchedulerLike, Subject } from 'rxjs';
|
|
|
3
3
|
type HmrUpdatesResult = Parameters<NonNullable<DevOptions['onHmrUpdates']>>[0];
|
|
4
4
|
type HmrUpdates = Exclude<HmrUpdatesResult, Error>;
|
|
5
5
|
/**
|
|
6
|
-
* Adapts Rolldown's non-awaited HMR callback into lossless
|
|
6
|
+
* Adapts Rolldown's non-awaited HMR callback into lossless fixed-duration batch publications.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
* patches
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
8
|
+
* Applying auditTime to the result stream itself would retain only the final callback and lose incremental patch factories
|
|
9
|
+
* that later patches do not reproduce. Instead, it only closes `buffer`: the first meaningful callback starts one timed window,
|
|
10
|
+
* and later callbacks join without postponing its deadline. No timer runs while idle. `publish` and `reportError` remain
|
|
11
|
+
* synchronous admission callbacks so the dev host can enqueue both through its existing serialized writer.
|
|
12
|
+
*
|
|
13
|
+
* Empty and Noop-only callbacks are excluded from both the buffer and its closing notifier, so they cannot delay meaningful
|
|
14
|
+
* work or enqueue empty publications. Mixed callbacks remain intact; the host still owns per-update selection.
|
|
13
15
|
*
|
|
14
16
|
* DevEngine failures are values, not Observable errors. They represent transient editor generations and carry no executable
|
|
15
17
|
* patch, so the stream reports the final error but otherwise removes them. Successful callbacks on either side remain ordered
|
|
@@ -17,7 +19,7 @@ type HmrUpdates = Exclude<HmrUpdatesResult, Error>;
|
|
|
17
19
|
* Completing the returned Subject flushes its current buffer synchronously, allowing host shutdown to await the resulting
|
|
18
20
|
* serialized task rather than silently dropping an admitted patch.
|
|
19
21
|
*
|
|
20
|
-
* Complexity is O(updates + changed files) per emitted window, with one retained reference per callback until
|
|
22
|
+
* Complexity is O(updates + changed files) per emitted window, with one retained reference per callback until its closing edge.
|
|
21
23
|
*/
|
|
22
|
-
export declare function createHmrResultsStream(
|
|
24
|
+
export declare function createHmrResultsStream(batchMilliseconds: number, scheduler: SchedulerLike, publish: (result: HmrUpdates) => void, reportError: (error: Error) => void): Subject<HmrUpdatesResult>;
|
|
23
25
|
export {};
|
|
@@ -2,7 +2,7 @@ import type { HmrInfo } from './hmr-protocol.ts';
|
|
|
2
2
|
export declare const hmrInfoFileName = "hmr/info.js";
|
|
3
3
|
/**
|
|
4
4
|
* Renders immutable CommonJS metadata because App startup must initialize the runtime synchronously before any entry capsule.
|
|
5
|
-
* Freezing also prevents application code from accidentally changing the build identity or socket endpoint
|
|
5
|
+
* Freezing also prevents application code from accidentally changing the running App's build identity or socket endpoint.
|
|
6
6
|
*/
|
|
7
7
|
export declare function renderHmrInfo(info: HmrInfo): string;
|
|
8
8
|
/**
|
|
@@ -10,7 +10,7 @@ export declare function renderHmrInfo(info: HmrInfo): string;
|
|
|
10
10
|
*
|
|
11
11
|
* Imported global CSS can change while the entry remains byte-identical. DevTools may then reuse an older persistent compile
|
|
12
12
|
* cache after it restarts. Tying this inert comment to the build identity invalidates that cache once per complete build,
|
|
13
|
-
* while incremental style updates continue changing only the imported file and therefore
|
|
13
|
+
* while incremental style updates continue changing only the imported file and therefore keep the App running.
|
|
14
14
|
*/
|
|
15
15
|
export declare function renderDevelopmentAppStyle(globalStyleFileName: string, buildId: string): string;
|
|
16
16
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Plugin } from 'vite';
|
|
2
|
-
import type { MiniHmrOptions,
|
|
2
|
+
import type { MiniHmrOptions, RuntimeContract } from '../mini-contract.ts';
|
|
3
3
|
import type { PatchPublication } from './hmr-protocol.ts';
|
|
4
4
|
/** One mode-selected effect executed by the development host. */
|
|
5
5
|
export type MiniHmrAction = Readonly<{
|
|
@@ -29,4 +29,4 @@ export type MiniHmrMode = Readonly<{
|
|
|
29
29
|
}>) => string;
|
|
30
30
|
}>;
|
|
31
31
|
/** Resolves exactly one implementation before the Mini Program development host is created. */
|
|
32
|
-
export declare function createMiniHmrMode(options: MiniHmrOptions,
|
|
32
|
+
export declare function createMiniHmrMode(options: MiniHmrOptions, runtime: RuntimeContract): MiniHmrMode;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AstTransformResult } from '../../../utils/transform.ts';
|
|
2
|
+
/**
|
|
3
|
+
* In serve, a native Page may load its original physical capsule after HMR has already installed a newer component factory.
|
|
4
|
+
* Taro captures the component at createPageConfig() time; without this lookup, that Page first mounts with stale source even
|
|
5
|
+
* though the patch was acknowledged. Replace only the component argument, leaving the production capsule untouched.
|
|
6
|
+
*/
|
|
7
|
+
export declare function injectDevPageComponent({ capsuleCode, componentId, capsuleId }: {
|
|
8
|
+
capsuleCode: string;
|
|
9
|
+
componentId: string;
|
|
10
|
+
capsuleId: string;
|
|
11
|
+
}): AstTransformResult;
|
|
@@ -1,31 +1,25 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { OutputOptions, RolldownOptions } from 'rolldown';
|
|
2
2
|
import { type DevEngine } from 'rolldown/experimental';
|
|
3
3
|
import type { ViteDevServer } from 'vite';
|
|
4
4
|
import type { MiniContract } from '../mini-contract.ts';
|
|
5
5
|
import type { MiniHmrMode } from './hmr-mode.ts';
|
|
6
|
-
type BundledDevRolldownOptions = InputOptions & {
|
|
7
|
-
experimental?: {
|
|
8
|
-
[key: string]: unknown;
|
|
9
|
-
devMode?: boolean | Record<string, unknown>;
|
|
10
|
-
};
|
|
11
|
-
output?: OutputOptions | OutputOptions[];
|
|
12
|
-
};
|
|
13
6
|
export type BundledDev = {
|
|
14
7
|
_devEngine?: DevEngine;
|
|
15
|
-
getRolldownOptions(): Promise<
|
|
8
|
+
getRolldownOptions(): Promise<RolldownOptions>;
|
|
16
9
|
listen(): Promise<void>;
|
|
17
10
|
triggerBundleRegenerationIfStale(): Promise<boolean>;
|
|
18
11
|
};
|
|
19
12
|
/**
|
|
20
|
-
*
|
|
13
|
+
* Applies physical Mini Program output and runtime conventions through Rolldown's public options hook.
|
|
21
14
|
* Build completion deliberately remains outside this options adapter: DevEngine onOutput is the single lifecycle authority.
|
|
22
15
|
*/
|
|
23
|
-
export declare function
|
|
24
|
-
bundledDev: BundledDev;
|
|
16
|
+
export declare function createMiniDevOptionsPlugin({ server, contract, hmrMode }: {
|
|
25
17
|
server: ViteDevServer;
|
|
26
18
|
contract: Pick<MiniContract, 'options'>;
|
|
27
19
|
hmrMode: MiniHmrMode;
|
|
28
|
-
}):
|
|
20
|
+
}): {
|
|
21
|
+
name: string;
|
|
22
|
+
options(rolldownOptions: RolldownOptions): Promise<RolldownOptions>;
|
|
23
|
+
};
|
|
29
24
|
/** Returns the configured output after rejecting states unsupported by the physical Mini Program engine. */
|
|
30
|
-
export declare function requireSingleOutput(rolldownOptions:
|
|
31
|
-
export {};
|
|
25
|
+
export declare function requireSingleOutput(rolldownOptions: RolldownOptions): OutputOptions;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { RuntimeModulesContract } from '../../../mini-contract.ts';
|
|
2
1
|
import type { MiniHmrMode } from '../../hmr-mode.ts';
|
|
3
2
|
import type { PatchUpdate } from '../../hmr-protocol.ts';
|
|
4
3
|
export declare const devtoolsPatchesFileName = "hmr/patches.js";
|
|
@@ -9,7 +8,7 @@ export declare const devtoolsPatchesFileName = "hmr/patches.js";
|
|
|
9
8
|
* DevTools observes a changed Page dependency, re-executes the Page shell, and that shell synchronously gives the cumulative
|
|
10
9
|
* native factory payload to the persistent App runtime. Mixing any one of these pieces with another mode would break that chain.
|
|
11
10
|
*/
|
|
12
|
-
export declare function createDevtoolsHmrMode(
|
|
11
|
+
export declare function createDevtoolsHmrMode(runtimeFile: string): MiniHmrMode;
|
|
13
12
|
/** Provides a valid, inert CommonJS dependency before the host has a patch range to publish. */
|
|
14
13
|
export declare function renderInitialDevtoolsPatches(): string;
|
|
15
14
|
/**
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { RuntimeModulesContract } from '../../../mini-contract.ts';
|
|
2
1
|
import type { MiniHmrMode } from '../../hmr-mode.ts';
|
|
3
2
|
/** Creates the pure interpreter adapter whose events are dispatched by the shared development host. */
|
|
4
|
-
export declare function createInterpreterHmrMode(
|
|
3
|
+
export declare function createInterpreterHmrMode(runtimeFile: string): MiniHmrMode;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { RuntimeModulesContract } from '../../../mini-contract.ts';
|
|
2
1
|
import type { MiniHmrMode } from '../../hmr-mode.ts';
|
|
3
2
|
/** Selects complete-output replacement without installing a patch transport or native Page handoff. */
|
|
4
|
-
export declare function createRebuildHmrMode(
|
|
3
|
+
export declare function createRebuildHmrMode(runtimeFile: string): MiniHmrMode;
|
|
@@ -29,7 +29,7 @@ export declare function createMiniDevelopmentPlugin(contract: MiniContract, styl
|
|
|
29
29
|
* but removes the prior physical App stylesheet; recovery builds do not clean. The host publishes the stylesheet once afterward.
|
|
30
30
|
* Patch modes first reset delivery and publish matching `hmr/info.js`; rebuild mode has no patch state and writes a fresh marker
|
|
31
31
|
* directly. Incremental HMR never enters this complete-output hook and changes only the imported global stylesheet; rewriting
|
|
32
|
-
* the App root would reload the
|
|
32
|
+
* the App root would reload the runtime while a JavaScript patch is awaiting acknowledgement. The serve-only plugin leaves
|
|
33
33
|
* production output unchanged.
|
|
34
34
|
*/
|
|
35
35
|
export declare function removeDevelopmentAppStyle(bundle: Record<string, unknown>, appStyleFileName: string): void;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { RolldownPluginOption } from 'rolldown';
|
|
2
|
+
import type { DevEnvironment } from 'vite';
|
|
3
|
+
type TransformConfig = Pick<DevEnvironment['config'], 'root' | 'tsconfig' | 'consumer' | 'oxc'>;
|
|
4
|
+
/** Reconstructs Vite's native transform through its exported factory, without reading or mutating builtin internals. */
|
|
5
|
+
export declare function replaceViteTransformPlugin(pluginOption: RolldownPluginOption, config: TransformConfig): Promise<RolldownPluginOption>;
|
|
6
|
+
export {};
|
|
@@ -6,23 +6,11 @@ export type TaroContract = {
|
|
|
6
6
|
componentsReactPath: string;
|
|
7
7
|
targetRuntimePath: string;
|
|
8
8
|
};
|
|
9
|
-
/**
|
|
10
|
-
export type
|
|
11
|
-
bootstrap: string;
|
|
12
|
-
appShell: string;
|
|
13
|
-
appCapsule: string;
|
|
14
|
-
componentShell: string;
|
|
15
|
-
componentCapsule: string;
|
|
16
|
-
customWrapperShell: string;
|
|
17
|
-
pageShell: string;
|
|
18
|
-
pageCapsule: string;
|
|
9
|
+
/** Target-specific development runtimes; shared Mini entry IDs live beside their source modules. */
|
|
10
|
+
export type RuntimeContract = {
|
|
19
11
|
devtoolsHmrRuntime: string;
|
|
20
12
|
interpreterHmrRuntime: string;
|
|
21
13
|
};
|
|
22
|
-
/** Physical runtime selection for one Mini Program target. */
|
|
23
|
-
export type RuntimeContract = {
|
|
24
|
-
modules: RuntimeModulesContract;
|
|
25
|
-
};
|
|
26
14
|
/** Style output names selected by one Mini Program target. */
|
|
27
15
|
export type StyleContract = {
|
|
28
16
|
appFileName: string;
|
|
@@ -51,6 +39,10 @@ export type OutputContract = {
|
|
|
51
39
|
projectPrivateConfigFilename: string;
|
|
52
40
|
generateProjectSkeleton(input: MiniProjectSkeletonInput, contract: MiniContract): Rolldown.EmittedAsset[];
|
|
53
41
|
};
|
|
42
|
+
/** Native project config fields overridden only in physical build-watch output. */
|
|
43
|
+
export type WatchContract = {
|
|
44
|
+
override: Readonly<Record<string, VptJsonObject>>;
|
|
45
|
+
};
|
|
54
46
|
/** Complete input consumed by the shared Mini Program pipeline. */
|
|
55
47
|
export type MiniContract = {
|
|
56
48
|
options: VptOptions;
|
|
@@ -58,6 +50,7 @@ export type MiniContract = {
|
|
|
58
50
|
runtime: RuntimeContract;
|
|
59
51
|
styles: StyleContract;
|
|
60
52
|
output: OutputContract;
|
|
53
|
+
watch: WatchContract;
|
|
61
54
|
};
|
|
62
55
|
/** Application JSON represented by the current Mini Program contract. */
|
|
63
56
|
export type MiniJsonObject = VptJsonObject;
|
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
import { type Rolldown } from 'vite';
|
|
2
|
-
|
|
3
|
-
export declare const
|
|
2
|
+
/** Installs SystemJS, transport, and polyfills before native entries load capsules. */
|
|
3
|
+
export declare const miniBootstrapId: string;
|
|
4
|
+
/** Registers the native App using its generated configuration capsule. */
|
|
5
|
+
export declare const miniAppShellId: string;
|
|
6
|
+
/** Builds the App configuration and activates its React runtime. */
|
|
7
|
+
export declare const miniAppCapsuleId: string;
|
|
8
|
+
/** Registers the recursive native Component from its capsule configuration. */
|
|
9
|
+
export declare const miniComponentShellId: string;
|
|
10
|
+
/** Supplies the recursive Component and CustomWrapper configurations. */
|
|
11
|
+
export declare const miniComponentCapsuleId: string;
|
|
12
|
+
/** Registers the native CustomWrapper from the shared component capsule. */
|
|
13
|
+
export declare const miniCustomWrapperShellId: string;
|
|
14
|
+
/** Registers each route's native Page using its route-qualified capsule. */
|
|
15
|
+
export declare const miniPageShellId: string;
|
|
16
|
+
/** Specializes each route's Page configuration and component import. */
|
|
17
|
+
export declare const miniPageCapsuleId: string;
|
|
18
|
+
export declare const miniTaroRuntimeId: string;
|
|
4
19
|
/** Identifies Rolldown's generated helper module independently of its unstable output filename. */
|
|
5
20
|
export declare const rolldownRuntimeId = "\0rolldown/runtime.js";
|
|
6
21
|
/** Identifies the virtual binding shared by native files, SystemJS capsules and HMR factories. */
|
|
@@ -9,7 +24,7 @@ export declare const vptGlobalBindingId = "\0vpt:global-binding";
|
|
|
9
24
|
export declare const miniPolyfillsId = "\0vpt:mini-polyfills";
|
|
10
25
|
/** External bootstrap dependency emitted only after the bundled graph is finalized. */
|
|
11
26
|
export declare const miniTransportId = "\0vpt:mini-transport";
|
|
12
|
-
export declare const
|
|
27
|
+
export declare const miniTransportOutputPath = "common/vpt/transport.js";
|
|
13
28
|
/** Resolves the shared Taro facade's target initialization side effect. */
|
|
14
29
|
export declare const taroTargetRuntimeId = "\0vpt:taro-target-runtime";
|
|
15
30
|
/** Redirects Vite's injected browser preload helper to the bootstrap identity loader. */
|
|
@@ -27,17 +42,11 @@ export declare const pageCapsuleId = "\0vpt:page-capsule";
|
|
|
27
42
|
export type MiniChunk = Rolldown.PreRenderedChunk | Rolldown.RenderedChunk;
|
|
28
43
|
/** Distinguishes native shells, lifecycle entry capsules, ordinary capsules, and shared native/SystemJS infrastructure. */
|
|
29
44
|
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
45
|
/** Native hook filter for the physical core-js graph; the generated import-only entry needs no host rewriting. */
|
|
33
46
|
export declare const miniPolyfillSourceFilter: RegExp;
|
|
34
47
|
/** Keeps the global binding and core-js in the pre-bootstrap native chunk, outside the recursive framework group. */
|
|
35
48
|
export declare function isMiniPolyfillModule(moduleId: string): boolean;
|
|
36
49
|
/** Groups framework modules by resolved package roots; Rolldown includes their dependencies. */
|
|
37
50
|
export declare function isMiniFrameworkVendorModule(moduleId: string): boolean;
|
|
38
|
-
/**
|
|
39
|
-
|
|
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.
|
|
42
|
-
*/
|
|
43
|
-
export declare function createMiniModuleClassifier(modules: RuntimeModulesContract): MiniModuleClassifier;
|
|
51
|
+
/** Classifies each chunk by its compiler-owned modules; ordinary application chunks are normal capsules. O(M) time. */
|
|
52
|
+
export declare function classifyMiniModule(chunk: MiniChunk): MiniChunkKind;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Rolldown } from 'vite';
|
|
2
|
-
import { type MiniModuleClassifier } from '../module/module.ts';
|
|
3
2
|
import type { PackageLocation } from '../placer/placement.ts';
|
|
4
3
|
/**
|
|
5
4
|
* Emits the closed transport table in generateBundle, after placement and content-hash resolution. Each switch case has two
|
|
@@ -18,9 +17,8 @@ import type { PackageLocation } from '../placer/placement.ts';
|
|
|
18
17
|
* paths. Fixed compact syntax and JSON-encoded IDs need no AST or quote-repair pass, while application chunks retain full
|
|
19
18
|
* compression, mangling, and whitespace removal.
|
|
20
19
|
*/
|
|
21
|
-
export declare function createTransportOutput({ bundle,
|
|
20
|
+
export declare function createTransportOutput({ bundle, getPackageLocation }: {
|
|
22
21
|
bundle: Rolldown.OutputBundle;
|
|
23
|
-
classifyModule: MiniModuleClassifier;
|
|
24
22
|
getPackageLocation(chunk: Rolldown.OutputChunk): PackageLocation;
|
|
25
23
|
}): {
|
|
26
24
|
type: "asset";
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import type { Plugin, Rolldown } from 'vite';
|
|
2
|
-
import
|
|
3
|
-
import { isMiniPolyfillModule, type MiniChunkKind, type MiniModuleClassifier } from '../module/module.ts';
|
|
2
|
+
import { isMiniPolyfillModule } from '../module/module.ts';
|
|
4
3
|
import { type GeneratedSubpackage, type PackageLocation } from './placement.ts';
|
|
5
4
|
export type { GeneratedSubpackage, Placement } from './placement.ts';
|
|
6
5
|
/** Placement services consumed by the later Mini Program rendering and output hooks. */
|
|
7
6
|
export type MiniPlacementPlugin = Plugin & Readonly<{
|
|
8
|
-
classifyChunk(chunk: Rolldown.PreRenderedChunk | Rolldown.RenderedChunk): MiniChunkKind;
|
|
9
7
|
getPackageLocation(chunk: Rolldown.RenderedChunk | Rolldown.OutputChunk): PackageLocation;
|
|
10
8
|
getPhysicalChunkId(chunk: Rolldown.RenderedChunk | string): string;
|
|
11
9
|
getSubpackages(): readonly GeneratedSubpackage[];
|
|
@@ -14,7 +12,7 @@ export type MiniPlacementPlugin = Plugin & Readonly<{
|
|
|
14
12
|
* Rolldown options owned by Mini Program placement. Every field enforces a distinct output invariant. The plugin returns this object
|
|
15
13
|
* from its config hook, while direct Rolldown integration tests reuse the same value to exercise the identical lifecycle.
|
|
16
14
|
*/
|
|
17
|
-
export declare function createPlacementRolldownOptions(
|
|
15
|
+
export declare function createPlacementRolldownOptions(): {
|
|
18
16
|
/**
|
|
19
17
|
* Rolldown owns shared chunk names and collision handling. LTHP adds physical package prefixes
|
|
20
18
|
* to those names later without copying or replacing the chunks.
|
|
@@ -62,4 +60,4 @@ export declare function createPlacementRolldownOptions(classifyChunk: MiniModule
|
|
|
62
60
|
* performs one whole-state transition, so stale graph state, duplicate planning, and partially reset generations are
|
|
63
61
|
* unrepresentable.
|
|
64
62
|
*/
|
|
65
|
-
export declare function createMiniPlacementPlugin(
|
|
63
|
+
export declare function createMiniPlacementPlugin(): MiniPlacementPlugin;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Rolldown } from 'vite';
|
|
2
2
|
import type { AstTransformResult } from '../../../utils/transform.ts';
|
|
3
|
-
import type { MiniModuleClassifier } from '../module/module.ts';
|
|
4
3
|
/**
|
|
5
4
|
* Materializes one final native/amphibious Rolldown chunk as executable Mini Program CommonJS.
|
|
6
5
|
*
|
|
@@ -22,12 +21,10 @@ import type { MiniModuleClassifier } from '../module/module.ts';
|
|
|
22
21
|
* source identifier. Source maps use the same range edits when requested; Mini Program development disables them and keeps this path
|
|
23
22
|
* focused on startup latency.
|
|
24
23
|
*/
|
|
25
|
-
export declare function renderNative({ code, chunk, chunks,
|
|
24
|
+
export declare function renderNative({ code, chunk, chunks, getPhysicalChunkId, sourcemap }: {
|
|
26
25
|
code: string;
|
|
27
26
|
chunk: Rolldown.RenderedChunk;
|
|
28
27
|
chunks: Readonly<Record<string, Rolldown.RenderedChunk>>;
|
|
29
|
-
bootstrapModuleId: string;
|
|
30
28
|
getPhysicalChunkId: (chunk: Rolldown.RenderedChunk | string) => string;
|
|
31
|
-
classifyModule: MiniModuleClassifier;
|
|
32
29
|
sourcemap: boolean;
|
|
33
30
|
}): AstTransformResult;
|
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
import { type Rolldown } from 'vite';
|
|
2
2
|
import type { MiniContract } from '../mini-contract.ts';
|
|
3
3
|
/** Creates the resolver and source specializer for one Mini Program module graph. */
|
|
4
|
-
export declare function createResolver(contract: Pick<MiniContract, 'options' | '
|
|
4
|
+
export declare function createResolver(contract: Pick<MiniContract, 'options' | 'taro'>): {
|
|
5
5
|
resolveId(id: string, importer: string | undefined, projectRoot: string): string | Rolldown.PartialResolvedId | undefined;
|
|
6
6
|
specialize(code: string, id: string, sourcemap?: boolean): import("../../../utils/transform.ts").AstTransformResult | undefined;
|
|
7
|
-
|
|
7
|
+
entries: {
|
|
8
|
+
appEntries: {
|
|
9
|
+
capsuleId: string;
|
|
10
|
+
capsuleName: string;
|
|
11
|
+
shellId: string;
|
|
12
|
+
shellName: string;
|
|
13
|
+
};
|
|
14
|
+
pageEntries: {
|
|
15
|
+
capsuleId: string;
|
|
16
|
+
capsuleName: string;
|
|
17
|
+
shellId: string;
|
|
18
|
+
shellName: string;
|
|
19
|
+
}[];
|
|
20
|
+
};
|
|
8
21
|
input: any;
|
|
9
22
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BuildOptions } from 'vite';
|
|
2
|
-
/** Minifies
|
|
2
|
+
/** Minifies one completed native stylesheet, without another browser compatibility or preprocessing pass. */
|
|
3
3
|
export declare function minifyMiniStylesheet(css: string, options: Readonly<{
|
|
4
4
|
filename: string;
|
|
5
5
|
minify: BuildOptions['cssMinify'];
|
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
import { type Plugin } from 'vite';
|
|
2
2
|
import type { MiniContract } from '../mini-contract.ts';
|
|
3
|
+
import type { createResolver } from '../resolve/resolver.ts';
|
|
3
4
|
/** JavaScript code plus the physical filename required by the Mini Program class-name transformer. */
|
|
4
5
|
type JavaScriptArtifact = Readonly<{
|
|
5
6
|
code: string;
|
|
6
7
|
filename: string;
|
|
7
8
|
}>;
|
|
8
|
-
/** Vite plugin
|
|
9
|
+
/** Vite plugin that finalizes native CSS and JavaScript without discarding HMR patches on CSS errors. */
|
|
9
10
|
export type MiniStylePlugin = Plugin & Readonly<{
|
|
10
|
-
/**
|
|
11
|
-
finalizeUpdate: <Artifact extends JavaScriptArtifact>(artifacts: readonly Artifact[], writeStylesheet: (
|
|
11
|
+
/** Publishes valid native CSS before JavaScript; CSS failures only log errors and retain the last valid styles. */
|
|
12
|
+
finalizeUpdate: <Artifact extends JavaScriptArtifact>(artifacts: readonly Artifact[], writeStylesheet: (fileName: string, source: string) => Promise<void>) => Promise<readonly Artifact[]>;
|
|
12
13
|
}>;
|
|
13
14
|
/**
|
|
14
|
-
* Creates the single owner of
|
|
15
|
+
* Creates the single owner of App/Page native-style compilation, graph projection, class rewriting, and publication.
|
|
15
16
|
*
|
|
16
17
|
* ## Architectural invariant
|
|
17
18
|
*
|
|
18
|
-
*
|
|
19
|
-
* names can be escaped—for example, `py-5.5` becomes `py-5_d5`—so
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
19
|
+
* Successful Mini Program updates expose JavaScript and native CSS produced from one class-identity snapshot. Tailwind utility
|
|
20
|
+
* names can be escaped—for example, `py-5.5` becomes `py-5_d5`—so both sides share the current candidate union. Complete builds
|
|
21
|
+
* reject any conversion failure. HMR instead logs native CSS errors and retains the last valid stylesheet for each failed file.
|
|
22
|
+
* Failed CSS is never published. Valid JavaScript still arrives with its assigned patch sequence; dropping that sequence would
|
|
23
|
+
* force the running client to rebuild and lose state. Separate build/update finalizers share conversion and caching.
|
|
23
24
|
*
|
|
24
25
|
* ## Ownership boundaries
|
|
25
26
|
*
|
|
@@ -33,12 +34,12 @@ export type MiniStylePlugin = Plugin & Readonly<{
|
|
|
33
34
|
* `vite:css-post` hook only after the original hook succeeds; it never rereads source files or repeats CSS preprocessing.
|
|
34
35
|
* 4. The fixed Mini transformer owns selector conversion and Oxc-based JavaScript class-string conversion. One retained
|
|
35
36
|
* transformer and one projected candidate set drive both operations without loading a framework project context.
|
|
36
|
-
* 5. VPT owns physical
|
|
37
|
-
* removed before VPT emits the
|
|
37
|
+
* 5. VPT owns physical App/Page CSS and patch publication. Vite's browser CSS asset is only an intermediate carrier and is
|
|
38
|
+
* removed before VPT emits the App stylesheet and each native Page companion.
|
|
38
39
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
40
|
+
* Opaque native-component styles stay outside this pipeline and are emitted by later native output hooks. The requested
|
|
41
|
+
* `build.cssCodeSplit` controls native projection. Vite's intermediate browser carrier remains unsplit after that request
|
|
42
|
+
* is captured, preventing browser CSS-loading code from leaking into native output.
|
|
42
43
|
*
|
|
43
44
|
* ## Compilation phases
|
|
44
45
|
*
|
|
@@ -61,72 +62,84 @@ export type MiniStylePlugin = Plugin & Readonly<{
|
|
|
61
62
|
*
|
|
62
63
|
* `configResolved` wraps the concrete `vite:css-post` transform while preserving its hook metadata, filter, ordering, and
|
|
63
64
|
* plugin context. The original Vite hook executes first, which preserves CSS Module exports and Vite's internal extraction
|
|
64
|
-
* state. Only a successful transform updates `styleByModuleId`;
|
|
65
|
-
*
|
|
65
|
+
* state. Only a successful transform updates `styleByModuleId`; Vite processing errors leave the last successful CSS available.
|
|
66
|
+
* Native conversion may still reject CSS accepted by this hook. Query modes such as `?raw`, `?url`, and `?inline` represent
|
|
66
67
|
* values rather than graph-owned stylesheets.
|
|
67
68
|
*
|
|
68
69
|
* ### 3. Live-graph projection
|
|
69
70
|
*
|
|
70
|
-
*
|
|
71
|
-
* in dependency-first post-order.
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
71
|
+
* The resolver supplies App/Page entry records; capsule resolution preserves those records and their native output paths.
|
|
72
|
+
* Each capsule traverses Rolldown's current static and dynamic import edges in dependency-first post-order. Root-local visited
|
|
73
|
+
* sets terminate cycles and deduplicate physical styles without suppressing another Page's independent cascade. App-reachable
|
|
74
|
+
* styles belong to the App and are excluded from every Page projection; styles shared only by Pages remain in each consumer.
|
|
75
|
+
* With splitting disabled, one traversal visits App then configured Pages and collects all reachable CSS into the App file,
|
|
76
|
+
* deduplicating shared styles and leaving Page companions empty. A retained stylesheet contributes only while reachable,
|
|
77
|
+
* so import removals prune CSS and candidates without a topology cache. Candidate sets contain only surviving Tailwind roots.
|
|
78
|
+
*
|
|
79
|
+
* App CSS is emitted at the contract's global filename; Page CSS is emitted beside each native Page shell. Only the App file
|
|
80
|
+
* receives HTML display defaults. JavaScript rewriting uses the union of all surviving App/Page Tailwind candidates.
|
|
75
81
|
*
|
|
76
82
|
* ### 4. Shared native-style finalization
|
|
77
83
|
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
84
|
+
* Both output finalizers convert and optionally minify each entry's CSS, then transform every JavaScript artifact using
|
|
85
|
+
* the shared candidate union. Builds and HMR follow `build.cssMinify`, defaulting to `build.minify`, using Lightning CSS.
|
|
86
|
+
* Vite's intermediate CSS minification
|
|
81
87
|
* remains disabled so only final native bytes are optimized. The function returns data without bundle mutation or filesystem
|
|
82
|
-
* publication.
|
|
83
|
-
*
|
|
88
|
+
* publication. Complete builds reject conversion or minification failures. HMR logs CSS errors and reuses the affected file's
|
|
89
|
+
* last valid output, if any; neither invalid CSS nor partially processed CSS is published. JavaScript conversion stays strict
|
|
90
|
+
* and uses current candidates, even with stale CSS. It is skipped when the projection contains no Tailwind candidates,
|
|
91
|
+
* preserving ordinary bundle bytes.
|
|
84
92
|
*
|
|
85
|
-
* `createFinalizeOutput()`
|
|
86
|
-
* candidate identity. Every transaction supplies a fresh live-graph projection, but byte-identical CSS skips
|
|
87
|
-
* Lightning CSS. Equal candidate contents reuse the same set and replacement table even when
|
|
88
|
-
* set. Changed candidates never reuse stale replacements
|
|
93
|
+
* `createFinalizeOutput()` composes a strict build converter and an HMR-only recovery wrapper. Both retain the same latest
|
|
94
|
+
* successful conversion per file and candidate identity. Every transaction supplies a fresh live-graph projection, but byte-identical CSS skips PostCSS and
|
|
95
|
+
* Lightning CSS independently for each file. Equal candidate contents reuse the same set and replacement table even when
|
|
96
|
+
* the projection allocated a new set. Changed candidates never reuse stale replacements. Invalid CSS is never cached; rejected
|
|
97
|
+
* transactions do not advance the snapshot.
|
|
89
98
|
*
|
|
90
99
|
* ### 5a. Complete-build commit
|
|
91
100
|
*
|
|
92
101
|
* The post-order `generateBundle` hook gathers all JavaScript chunks, finalizes them as one operation, and only then mutates the
|
|
93
102
|
* bundle. It assigns converted code, clears invalid source maps, removes Vite's intermediate browser stylesheet, and always
|
|
94
|
-
* emits the
|
|
95
|
-
*
|
|
103
|
+
* emits the App stylesheet with HTML defaults and every Page stylesheet, including empty Pages. Native output hooks run
|
|
104
|
+
* afterward without Page-style placeholders; opaque native-component styles remain independently owned.
|
|
96
105
|
*
|
|
97
106
|
* ### 5b. Development commit
|
|
98
107
|
*
|
|
99
108
|
* The development host calls `finalizeUpdate()` after Rolldown produces patch factories or a complete-output notification.
|
|
100
|
-
* Finalization uses the `PluginContext` captured by `buildStart`, so it observes the same current graph as the compiler.
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
109
|
+
* Finalization uses the `PluginContext` captured by `buildStart`, so it observes the same current graph as the compiler. The host's
|
|
110
|
+
* atomic writer publishes valid native CSS before `finalizeUpdate()` returns converted patch factories. CSS conversion errors
|
|
111
|
+
* retain only the affected file's last valid styles; they do not block valid patches or healthy stylesheets. Captured Vite CSS
|
|
112
|
+
* literals are emptied first; factories, exports, changed IDs, and sequences remain intact.
|
|
113
|
+
* Each file's publication frontier advances only after its atomic write succeeds. A failed later write blocks JavaScript
|
|
114
|
+
* delivery; retry skips files already made durable. Empty Page CSS overwrites stale styles after import removal.
|
|
105
115
|
*
|
|
106
116
|
* ## Retained state and lifecycle
|
|
107
117
|
*
|
|
108
118
|
* Each plugin instance owns the following bounded state and transformation services:
|
|
109
119
|
*
|
|
110
|
-
* - `
|
|
111
|
-
* - `
|
|
120
|
+
* - `cssCodeSplit`: requested native-style ownership policy captured before disabling Vite's browser-only splitting;
|
|
121
|
+
* - `cssMinify`: requested native-style minification captured before disabling Vite's intermediate pass, then resolved once;
|
|
122
|
+
* - `resolvedEntries`: App/Page metadata with graph-exact capsule identities resolved at the start of each build;
|
|
112
123
|
* - `graphContext`: the active Rolldown graph reader needed by host calls made outside plugin hooks;
|
|
113
124
|
* - `styleByModuleId`: the latest successful Vite CSS plus optional Tailwind state at one normalized module identity;
|
|
114
|
-
* - `
|
|
115
|
-
* - `finalizeOutput`: resolved output options, the fixed
|
|
125
|
+
* - `publishedStylesheets`: the last durably published bytes per development stylesheet for unchanged-write suppression;
|
|
126
|
+
* - `finalizeOutput`: resolved output options, the fixed transformer, and the latest successful per-file CSS/candidate snapshot.
|
|
116
127
|
*
|
|
117
|
-
* The state owners remain scoped to one plugin instance; `
|
|
128
|
+
* The state owners remain scoped to one plugin instance; `resolvedEntries` is atomically replaced after each complete resolution.
|
|
118
129
|
* A development watcher retains them across updates; build and watcher shutdown clear the complete style store.
|
|
119
130
|
*
|
|
120
131
|
* ## Cost model
|
|
121
132
|
*
|
|
122
|
-
*
|
|
133
|
+
* Split projection is `O(sum(Vᵢ + Eᵢ + Bᵢ + Cᵢ))` across App/Page roots for reachable modules, import edges, projected CSS
|
|
134
|
+
* bytes, and candidate insertions. Combined projection is `O(V + E + B + C + P)` with one traversal and P Page companions.
|
|
135
|
+
* Candidate unioning needs no extra graph traversal.
|
|
123
136
|
* Building one exact candidate precheck costs `O(C)` candidate bytes and testing a chunk costs `O(J)` source bytes. Matching
|
|
124
137
|
* chunks then parse and walk in `O(J)`; replacing `Kᵢ` candidate tokens in literal `i` costs `O(LᵢKᵢ)` while preserving
|
|
125
138
|
* untouched bytes through Rolldown's native editor. Comparing candidate sets costs `O(C)` without sorting. Retained memory
|
|
126
139
|
* is `O(B + C + D + F)` for latest CSS, candidate sets, compiler dependencies, and watched file identities; no second application
|
|
127
140
|
* graph is retained. The Tailwind generator stays alive across candidate edits to avoid repeating source normalization and
|
|
128
|
-
* compiler initialization.
|
|
141
|
+
* compiler initialization. Successful native CSS conversions are reused while projected CSS is unchanged; failures retry;
|
|
129
142
|
* no extra source reads or graph traversals are needed.
|
|
130
143
|
*/
|
|
131
|
-
export declare function createMiniStylePlugin(contract: Pick<MiniContract, 'styles'>,
|
|
144
|
+
export declare function createMiniStylePlugin(contract: Pick<MiniContract, 'styles'>, entries: ReturnType<typeof createResolver>['entries']): MiniStylePlugin;
|
|
132
145
|
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { createResolver } from '../resolve/resolver.ts';
|
|
2
|
+
type MiniEntries = ReturnType<typeof createResolver>['entries'];
|
|
3
|
+
/** Projection needs captured CSS and candidates, not the retained compiler or its invalidation state. */
|
|
4
|
+
type StyleSource = Readonly<{
|
|
5
|
+
css: string | undefined;
|
|
6
|
+
tailwind: Readonly<{
|
|
7
|
+
classSet: ReadonlySet<string>;
|
|
8
|
+
}> | undefined;
|
|
9
|
+
}>;
|
|
10
|
+
/** Read only current import edges while retaining the caller's graph context. */
|
|
11
|
+
type ModuleGraph = Readonly<{
|
|
12
|
+
getModuleInfo: (id: string) => Readonly<{
|
|
13
|
+
importedIds: readonly string[];
|
|
14
|
+
dynamicallyImportedIds: readonly string[];
|
|
15
|
+
}> | null;
|
|
16
|
+
}>;
|
|
17
|
+
/**
|
|
18
|
+
* Projects native CSS according to build.cssCodeSplit. Split output preserves each Page's dependency-first cascade;
|
|
19
|
+
* combined output traverses App then configured Pages once, deduplicating shared CSS in the global stylesheet.
|
|
20
|
+
* Page companions stay empty in combined output. Both policies share one union of surviving Tailwind candidates.
|
|
21
|
+
*
|
|
22
|
+
* Split work is O(sum(Vᵢ + Eᵢ + Bᵢ + Cᵢ)) across roots. Combined work is O(V + E + B + C + P), where P is the Page count.
|
|
23
|
+
* All visited/style collections are transaction-local, so cycles terminate and graph removals need no retained cache.
|
|
24
|
+
*/
|
|
25
|
+
export declare function projectMiniStyles(entries: MiniEntries, styleByModuleId: ReadonlyMap<string, StyleSource>, context: ModuleGraph, cssCodeSplit: boolean): {
|
|
26
|
+
appEntries: {
|
|
27
|
+
capsuleId: string;
|
|
28
|
+
capsuleName: string;
|
|
29
|
+
shellId: string;
|
|
30
|
+
shellName: string;
|
|
31
|
+
styles: ReadonlyMap<string, Readonly<{
|
|
32
|
+
css: string;
|
|
33
|
+
classSet: ReadonlySet<string> | undefined;
|
|
34
|
+
}>>;
|
|
35
|
+
css: string;
|
|
36
|
+
classSet: Set<string>;
|
|
37
|
+
};
|
|
38
|
+
pageEntries: {
|
|
39
|
+
capsuleId: string;
|
|
40
|
+
capsuleName: string;
|
|
41
|
+
shellId: string;
|
|
42
|
+
shellName: string;
|
|
43
|
+
styles: ReadonlyMap<string, Readonly<{
|
|
44
|
+
css: string;
|
|
45
|
+
classSet: ReadonlySet<string> | undefined;
|
|
46
|
+
}>>;
|
|
47
|
+
css: string;
|
|
48
|
+
classSet: Set<string>;
|
|
49
|
+
}[];
|
|
50
|
+
classSet: Set<string>;
|
|
51
|
+
};
|
|
52
|
+
export {};
|