vite-plugin-taro 0.6.18 → 0.6.19

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 (133) hide show
  1. package/client.d.ts +2 -3
  2. package/dist/index.js +213574 -0
  3. package/dist/node/plugins/wx/dev/react-refresh.d.ts +14 -13
  4. package/dist/node/utils/packages.d.ts +2 -0
  5. package/package.json +26 -26
  6. package/dist/node/plugins/client/client-taro.js +0 -59
  7. package/dist/node/plugins/client/constant.js +0 -4
  8. package/dist/node/plugins/client/inject-taro-framework-apis.js +0 -9
  9. package/dist/node/plugins/conditional/conditional-directives.js +0 -76
  10. package/dist/node/plugins/h5/constant.js +0 -3
  11. package/dist/node/plugins/h5/create-stencil-client-adapter.js +0 -94
  12. package/dist/node/plugins/h5/plugins.js +0 -179
  13. package/dist/node/plugins/h5/resolver/module-resolver.js +0 -20
  14. package/dist/node/plugins/h5/transform-app.js +0 -48
  15. package/dist/node/plugins/tailwind/tailwind-css.js +0 -3
  16. package/dist/node/plugins/wx/dev/create-hmr-results-stream.js +0 -57
  17. package/dist/node/plugins/wx/dev/dev-host.js +0 -361
  18. package/dist/node/plugins/wx/dev/hmr-files.js +0 -56
  19. package/dist/node/plugins/wx/dev/host-actions.js +0 -58
  20. package/dist/node/plugins/wx/dev/patch-publisher.js +0 -77
  21. package/dist/node/plugins/wx/dev/plugins.js +0 -164
  22. package/dist/node/plugins/wx/dev/react-refresh.js +0 -231
  23. package/dist/node/plugins/wx/dev/runtime-reports.js +0 -45
  24. package/dist/node/plugins/wx/dev/wx-dev-options.js +0 -178
  25. package/dist/node/plugins/wx/module/chunk-path.js +0 -18
  26. package/dist/node/plugins/wx/module/module.js +0 -79
  27. package/dist/node/plugins/wx/native/compile-native-component-interface.js +0 -30
  28. package/dist/node/plugins/wx/native/create-native-component-output.js +0 -39
  29. package/dist/node/plugins/wx/native/native-component-assets.js +0 -76
  30. package/dist/node/plugins/wx/native/native-component-interface.js +0 -203
  31. package/dist/node/plugins/wx/output/files.js +0 -21
  32. package/dist/node/plugins/wx/output/relative-root.js +0 -6
  33. package/dist/node/plugins/wx/output/templates.js +0 -358
  34. package/dist/node/plugins/wx/placer/placement.js +0 -245
  35. package/dist/node/plugins/wx/placer/placer.js +0 -147
  36. package/dist/node/plugins/wx/plugins.js +0 -152
  37. package/dist/node/plugins/wx/render/capsule.js +0 -54
  38. package/dist/node/plugins/wx/render/native.js +0 -543
  39. package/dist/node/plugins/wx/render/system-js/string-editor.js +0 -94
  40. package/dist/node/plugins/wx/render/system-js/system-js.js +0 -588
  41. package/dist/node/plugins/wx/render/transport.js +0 -103
  42. package/dist/node/plugins/wx/resolve/resolver.js +0 -102
  43. package/dist/node/plugins/wx/resolve/specialize-app-capsule.js +0 -9
  44. package/dist/node/plugins/wx/resolve/specialize-page-capsule.js +0 -11
  45. package/dist/node/plugins/wx/styles/plugins.js +0 -459
  46. package/dist/node/utils/constant.js +0 -1
  47. package/dist/node/utils/memoize.js +0 -86
  48. package/dist/node/utils/modules.js +0 -22
  49. package/dist/node/utils/once.js +0 -20
  50. package/dist/node/utils/oxc-transform.js +0 -57
  51. package/dist/node/utils/packages.js +0 -9
  52. package/dist/node/utils/project-config.js +0 -8
  53. package/dist/node/utils/transform.js +0 -32
  54. package/dist/node/utils/vite.js +0 -10
  55. package/dist/node/vpt.js +0 -15
  56. package/dist/options.js +0 -1
  57. package/dist/vite.js +0 -1
  58. package/src/node/plugins/client/client-taro.ts +0 -71
  59. package/src/node/plugins/client/constant.ts +0 -5
  60. package/src/node/plugins/client/inject-taro-framework-apis.ts +0 -11
  61. package/src/node/plugins/conditional/conditional-directives.ts +0 -94
  62. package/src/node/plugins/h5/constant.ts +0 -4
  63. package/src/node/plugins/h5/create-stencil-client-adapter.ts +0 -111
  64. package/src/node/plugins/h5/plugins.ts +0 -194
  65. package/src/node/plugins/h5/resolver/module-resolver.ts +0 -33
  66. package/src/node/plugins/h5/transform-app.ts +0 -90
  67. package/src/node/plugins/tailwind/tailwind-css.ts +0 -4
  68. package/src/node/plugins/wx/dev/create-hmr-results-stream.ts +0 -71
  69. package/src/node/plugins/wx/dev/dev-host.ts +0 -453
  70. package/src/node/plugins/wx/dev/hmr-files.ts +0 -80
  71. package/src/node/plugins/wx/dev/host-actions.ts +0 -88
  72. package/src/node/plugins/wx/dev/patch-publisher.ts +0 -92
  73. package/src/node/plugins/wx/dev/plugins.ts +0 -176
  74. package/src/node/plugins/wx/dev/react-refresh.ts +0 -253
  75. package/src/node/plugins/wx/dev/runtime-reports.ts +0 -70
  76. package/src/node/plugins/wx/dev/wx-dev-options.ts +0 -226
  77. package/src/node/plugins/wx/module/chunk-path.ts +0 -22
  78. package/src/node/plugins/wx/module/module.ts +0 -110
  79. package/src/node/plugins/wx/native/compile-native-component-interface.ts +0 -48
  80. package/src/node/plugins/wx/native/create-native-component-output.ts +0 -60
  81. package/src/node/plugins/wx/native/native-component-assets.ts +0 -113
  82. package/src/node/plugins/wx/native/native-component-interface.ts +0 -267
  83. package/src/node/plugins/wx/output/files.ts +0 -40
  84. package/src/node/plugins/wx/output/relative-root.ts +0 -7
  85. package/src/node/plugins/wx/output/templates.ts +0 -448
  86. package/src/node/plugins/wx/placer/placement.ts +0 -364
  87. package/src/node/plugins/wx/placer/placer.ts +0 -180
  88. package/src/node/plugins/wx/plugins.ts +0 -183
  89. package/src/node/plugins/wx/render/capsule.ts +0 -57
  90. package/src/node/plugins/wx/render/native.ts +0 -694
  91. package/src/node/plugins/wx/render/system-js/string-editor.ts +0 -116
  92. package/src/node/plugins/wx/render/system-js/system-js.ts +0 -821
  93. package/src/node/plugins/wx/render/transport.ts +0 -173
  94. package/src/node/plugins/wx/resolve/resolver.ts +0 -145
  95. package/src/node/plugins/wx/resolve/specialize-app-capsule.ts +0 -27
  96. package/src/node/plugins/wx/resolve/specialize-page-capsule.ts +0 -29
  97. package/src/node/plugins/wx/styles/plugins.ts +0 -595
  98. package/src/node/utils/constant.ts +0 -1
  99. package/src/node/utils/memoize.ts +0 -149
  100. package/src/node/utils/modules.ts +0 -37
  101. package/src/node/utils/once.ts +0 -21
  102. package/src/node/utils/oxc-transform.ts +0 -76
  103. package/src/node/utils/packages.ts +0 -11
  104. package/src/node/utils/project-config.ts +0 -10
  105. package/src/node/utils/transform.ts +0 -48
  106. package/src/node/utils/vite.ts +0 -22
  107. package/src/node/vpt.ts +0 -18
  108. package/src/options.ts +0 -82
  109. package/src/runtime/client/taro/api.ts +0 -11
  110. package/src/runtime/client/taro/component.ts +0 -1
  111. package/src/runtime/client/taro/define-native-component.ts +0 -15
  112. package/src/runtime/h5/app.ts +0 -25
  113. package/src/runtime/h5/taro-css.d.ts +0 -3
  114. package/src/runtime/h5/taro-runtime.ts +0 -7
  115. package/src/runtime/wx/amphibious/bootstrap.ts +0 -17
  116. package/src/runtime/wx/amphibious/transport.ts +0 -8
  117. package/src/runtime/wx/capsule/app.ts +0 -12
  118. package/src/runtime/wx/capsule/component.ts +0 -7
  119. package/src/runtime/wx/capsule/page.ts +0 -29
  120. package/src/runtime/wx/capsule/taro-runtime.ts +0 -8
  121. package/src/runtime/wx/dev/dev-runtime.ts +0 -464
  122. package/src/runtime/wx/native/app.ts +0 -4
  123. package/src/runtime/wx/native/component.ts +0 -4
  124. package/src/runtime/wx/native/custom-wrapper.ts +0 -4
  125. package/src/runtime/wx/native/page.ts +0 -6
  126. package/src/runtime/wx/systemjs/LICENSE +0 -10
  127. package/src/runtime/wx/systemjs/system-core.js +0 -370
  128. package/src/runtime/wx/systemjs/system.d.ts +0 -55
  129. package/src/runtime/wx/wechat.d.ts +0 -56
  130. package/src/vite.ts +0 -2
  131. /package/dist/{vite.d.ts → index.d.ts} +0 -0
  132. /package/dist/runtime/client/taro/{define-native-component.d.ts → native.d.ts} +0 -0
  133. /package/dist/runtime/client/taro/{define-native-component.js → native.js} +0 -0
@@ -1,147 +0,0 @@
1
- import { normalizePath } from 'vite';
2
- import { getWxExecutionKind, isTransportModule } from '../module/module.js';
3
- import { getNativeComponentAssetBytes } from '../native/native-component-assets.js';
4
- import { createPlacement } from './placement.js';
5
- const pnpmFrameworkPackagePattern = /\/node_modules\/\.pnpm\/(?:@tarojs\+|vite-plugin-taro-runtime@|react(?:-dom|-reconciler)?@|scheduler@)/;
6
- const workspaceFrameworkPackagePattern = /\/packages\/(?:taro-react|taro-plugin-framework-react|taro-runtime)\//;
7
- /** Selects the explicit React/Taro roots whose complete dependency closure forms the framework vendor chunk. */
8
- export function isWxFrameworkVendorModule(moduleId) {
9
- const normalizedId = normalizePath(moduleId);
10
- return pnpmFrameworkPackagePattern.test(normalizedId) || workspaceFrameworkPackagePattern.test(normalizedId);
11
- }
12
- /**
13
- * Rolldown options owned by WX placement. Every field enforces a distinct output invariant. The plugin returns this object
14
- * from its config hook, while direct Rolldown integration tests reuse the same value to exercise the identical lifecycle.
15
- */
16
- export const placementRolldownOptions = {
17
- /**
18
- * Output-stage naming remains under Rolldown's ownership. These options establish physical candidates and hash
19
- * participation only; LTHP mutates the resulting OutputChunk filenames later without replacing the chunks.
20
- */
21
- output: {
22
- /**
23
- * React and Taro form one stable framework boundary shared by the App and every Page capsule. Keeping their complete
24
- * dependency closure together prevents application edits from invalidating framework chunk identity and makes later
25
- * development generations eligible to reuse the unchanged vendor. All remaining modules use Rolldown's automatic
26
- * chunking; physical WX package placement operates on those final chunks without imposing another split strategy.
27
- */
28
- codeSplitting: {
29
- groups: [
30
- {
31
- name: 'vendor',
32
- test: isWxFrameworkVendorModule,
33
- priority: 100,
34
- includeDependenciesRecursively: true
35
- }
36
- ]
37
- },
38
- /**
39
- * Native App/Page/Component shells are files addressed directly by WeChat and must retain the exact names configured
40
- * in `input`, such as `app.js` and `pages/home/index.js`. Transport is excluded even though it is CommonJS:
41
- * application chunks import its content-hashed path, so it belongs with hashed runtime/capsule entries. `[hash]`
42
- * remains a Rolldown placeholder here and is resolved only after renderChunk transforms finish.
43
- */
44
- entryFileNames(chunk) {
45
- return getWxExecutionKind(chunk) === 'native' && !isTransportModule(chunk)
46
- ? '[name]'
47
- : 'assets/[name]-[hash].js';
48
- },
49
- /**
50
- * Leaves chunk identity and collision handling entirely to Rolldown. This package-neutral physical pattern deliberately
51
- * contains no LTHP owner; generateBundle adds only the selected package root to the existing Rolldown filename.
52
- */
53
- chunkFileNames: 'assets/[name]-[hash].js',
54
- /**
55
- * Emits generic Rolldown assets under one collision-resistant hashed namespace. Native-component folders are not
56
- * governed by this option: createNativeComponentOutput preserves their required relative filenames and relocates the
57
- * complete folder beside its owning JavaScript chunk after LTHP finalization.
58
- */
59
- assetFileNames: 'assets/[name]-[hash][extname]'
60
- },
61
- /**
62
- * Keeps every native entry's required exports while allowing Rolldown to add cross-chunk bindings created by natural code
63
- * splitting. `strict` can reject those extensions; `exports-only` can merge away native boundaries; `allow-extension`
64
- * preserves the shell/capsule contract without forcing source-module placement groups.
65
- */
66
- preserveEntrySignatures: 'allow-extension'
67
- };
68
- /**
69
- * Creates the `vpt:wx-placer` lifecycle owner:
70
- *
71
- * 1. Its config hook installs package-neutral Rolldown names and entry-signature semantics.
72
- * 2. `renderStart` atomically starts a generation in `awaiting-chunks`; no stale placement remains reachable.
73
- * 3. Its first pre-order `renderChunk` creates one immutable LTHP placement from the complete tree-shaken graph.
74
- * 4. `vpt:wx` asks this plugin only for package ownership, physical relocation, and native loading mode.
75
- * 5. Its pre-order `generateBundle` assigns each OutputChunk its package-qualified filename and publishes app.json declarations.
76
- *
77
- * The discriminated state is the only generation-local mutation: `idle → awaiting-chunks → planned → finalized`. Each hook
78
- * performs one whole-state transition, so stale graph state, duplicate planning, and partially reset generations are
79
- * unrepresentable.
80
- */
81
- export function createWxPlacementPlugin() {
82
- // This one mutable cell is the output-generation state machine described above; hooks replace it atomically by phase.
83
- let state = { phase: 'idle' };
84
- function requirePlacement() {
85
- if (state.phase === 'idle' || state.phase === 'awaiting-chunks') {
86
- throw new Error('wx placement is unavailable before Rolldown exposes the final chunk graph');
87
- }
88
- return state.placement;
89
- }
90
- return {
91
- name: 'vpt:wx-placer',
92
- config() {
93
- return {
94
- build: {
95
- rolldownOptions: placementRolldownOptions
96
- }
97
- };
98
- },
99
- renderStart() {
100
- state = { phase: 'awaiting-chunks' };
101
- },
102
- renderChunk: {
103
- order: 'pre',
104
- handler(_code, _chunk, _outputOptions, meta) {
105
- if (state.phase === 'planned') {
106
- return;
107
- }
108
- if (state.phase !== 'awaiting-chunks') {
109
- throw new Error(`wx placement received final chunks during the ${state.phase} phase`);
110
- }
111
- state = {
112
- phase: 'planned',
113
- placement: createPlacement({
114
- chunks: meta.chunks,
115
- getAdditionalModuleBytes: (moduleId) => getNativeComponentAssetBytes(this.getModuleInfo(moduleId)?.meta)
116
- })
117
- };
118
- }
119
- },
120
- generateBundle: {
121
- order: 'pre',
122
- handler(_outputOptions, bundle) {
123
- const placement = requirePlacement();
124
- state = {
125
- phase: 'finalized',
126
- placement: placement,
127
- subpackages: placement.finalize(bundle)
128
- };
129
- }
130
- },
131
- getPackageLocation(chunk) {
132
- return requirePlacement().getPackageLocation(chunk);
133
- },
134
- getPhysicalChunkId(chunk) {
135
- return requirePlacement().getPhysicalChunkId(chunk);
136
- },
137
- getLoadMode(chunk) {
138
- return requirePlacement().getLoadMode(chunk);
139
- },
140
- getSubpackages() {
141
- if (state.phase !== 'finalized') {
142
- throw new Error('wx subpackages are unavailable before output finalization');
143
- }
144
- return state.subpackages;
145
- }
146
- };
147
- }
@@ -1,152 +0,0 @@
1
- import { esTarget } from '../../utils/constant.js';
2
- import { packageRequire } from '../../utils/packages.js';
3
- import { clientTaroNativeId } from '../client/constant.js';
4
- import { createWxDevelopmentPlugin } from './dev/plugins.js';
5
- import { getWxExecutionKind, isTransportModule } from './module/module.js';
6
- import { compileNativeComponentInterface } from './native/compile-native-component-interface.js';
7
- import { createOutputFiles } from './output/files.js';
8
- import { createWxPlacementPlugin } from './placer/placer.js';
9
- import { renderCapsule } from './render/capsule.js';
10
- import { renderNative } from './render/native.js';
11
- import { materializeTransport } from './render/transport.js';
12
- import { createResolver } from './resolve/resolver.js';
13
- import { createWxStylePlugin } from './styles/plugins.js';
14
- /** Creates the complete plugin set for the wx target. */
15
- export function createWxTargetPlugins(options) {
16
- const resolver = createResolver(options);
17
- // Reuse the resolver instance's ordered application subset. Rolldown's complete input also contains bootstrap, transport,
18
- // shell, and component entries; entry membership alone cannot recover which roots define the App/Page CSS cascade.
19
- const placement = createWxPlacementPlugin();
20
- const styles = createWxStylePlugin(resolver.applicationEntryIds);
21
- return [placement, styles, createWxPlugin(options, resolver, placement), createWxDevelopmentPlugin(options, styles)];
22
- }
23
- /** Configures the complete wx target build pipeline. */
24
- function createWxPlugin(options, resolver, placement) {
25
- return {
26
- name: 'vpt:wx',
27
- config(_config, _env) {
28
- return {
29
- define: createTaroDefines(),
30
- appType: 'custom',
31
- oxc: { target: esTarget },
32
- resolve: {
33
- alias: [
34
- {
35
- find: /^@tarojs\/runtime$/,
36
- replacement: packageRequire.resolve('@tarojs/runtime/dist/index.js')
37
- },
38
- {
39
- find: /^@tarojs\/components$/,
40
- replacement: packageRequire.resolve('@tarojs/plugin-platform-weapp/dist/components-react')
41
- }
42
- ]
43
- },
44
- build: {
45
- modulePreload: false,
46
- // Mini Program styles are intentionally global. This guarantees one compiler stylesheet for the CSS
47
- // finalizer; enabling splitting would require Page ownership and must not be silently flattened.
48
- cssCodeSplit: false,
49
- // Preserve readable source for the final WX compatibility pass; browser minification can emit syntax
50
- // unsupported by WeChat and would make the subsequent whole-file conversion harder to reason about.
51
- cssMinify: false,
52
- // No base64 assets: Taro warns on image srcs above ~2KB, and inlined
53
- // images bloat the JS bundle toward the mini program package limit.
54
- assetsInlineLimit: 0,
55
- target: esTarget,
56
- rolldownOptions: {
57
- // The dedicated vpt:wx-placer plugin owns output naming and entry-signature semantics. This plugin owns
58
- // only the closed named input set of native shells, lifecycle capsules, bootstrap, and transport entries.
59
- input: resolver.input
60
- }
61
- }
62
- };
63
- },
64
- resolveId(id, importer) {
65
- return resolver.resolveId(id, importer, this.environment.config.root);
66
- },
67
- transform: {
68
- order: 'pre',
69
- async handler(code, id) {
70
- const sourcemap = Boolean(this.environment.config.build.sourcemap);
71
- if (code.includes(clientTaroNativeId)) {
72
- return compileNativeComponentInterface({
73
- code,
74
- id,
75
- sourcemap,
76
- addWatchFile: (file) => this.addWatchFile(file)
77
- });
78
- }
79
- return resolver.specialize(code, id, sourcemap);
80
- }
81
- },
82
- renderChunk: {
83
- order: 'post',
84
- async handler(code, chunk, outputOptions, meta) {
85
- // vpt:wx-placer runs first and has already created immutable placement from this complete chunk graph.
86
- const executionKind = getWxExecutionKind(chunk);
87
- const sourcemap = Boolean(outputOptions.sourcemap);
88
- if (executionKind === 'capsule') {
89
- return renderCapsule(code, chunk, sourcemap);
90
- }
91
- // Native and amphibious modules share the CommonJS renderer. Amphibious transport exposure is a
92
- // separate concern materialized from final output paths after the physical transport itself is rendered.
93
- const native = renderNative({ code, chunk, chunks: meta.chunks, sourcemap });
94
- if (isTransportModule(chunk)) {
95
- return materializeTransport({
96
- code: native.code,
97
- transportChunk: chunk,
98
- chunks: meta.chunks,
99
- getLoadMode: placement.getLoadMode,
100
- getPhysicalChunkId: placement.getPhysicalChunkId,
101
- sourcemap
102
- });
103
- }
104
- return native;
105
- }
106
- },
107
- generateBundle: {
108
- /*
109
- * Registration after the style pipeline makes the compiler stylesheet final before native Page and component
110
- * companions are emitted. The style finalizer therefore cannot mistake native WXSS for application CSS.
111
- */
112
- order: 'post',
113
- async handler(_, bundle) {
114
- // LTHP joins OutputChunks to their preliminary logical IDs and assigns Rolldown-owned physical filenames.
115
- // createOutputFiles then observes those paths to relocate native component folders, emit placeholders, and
116
- // declare only surviving package roots in app.json. No JavaScript chunk is manually emitted or copied.
117
- const subpackages = placement.getSubpackages();
118
- const outputFiles = await createOutputFiles({
119
- bundle,
120
- options,
121
- subpackages,
122
- isProduction: this.environment.config.isProduction,
123
- getModuleInfo: (moduleId) => this.getModuleInfo(moduleId),
124
- getPackageLocation: placement.getPackageLocation
125
- });
126
- outputFiles.forEach((file) => {
127
- this.emitFile(file);
128
- });
129
- }
130
- }
131
- };
132
- }
133
- /** Creates the build-time constants required by Taro's legacy feature gates. */
134
- function createTaroDefines() {
135
- const taroVersion = String(packageRequire('@tarojs/taro/package.json').version);
136
- return {
137
- 'process.env.FRAMEWORK': JSON.stringify('react'),
138
- 'process.env.SUPPORT_TARO_POLYFILL': JSON.stringify('disabled'),
139
- 'process.env.TARO_ENV': JSON.stringify('weapp'),
140
- 'process.env.TARO_PLATFORM': JSON.stringify('mini'),
141
- 'process.env.TARO_VERSION': JSON.stringify(taroVersion),
142
- // React's development-only Suspense diagnostics call this browser API without guards.
143
- 'performance.now': 'Date.now',
144
- ENABLE_ADJACENT_HTML: 'false',
145
- ENABLE_CLONE_NODE: 'false',
146
- ENABLE_CONTAINS: 'false',
147
- ENABLE_INNER_HTML: 'false',
148
- ENABLE_MUTATION_OBSERVER: 'false',
149
- ENABLE_SIZE_APIS: 'false',
150
- ENABLE_TEMPLATE_CONTENT: 'false'
151
- };
152
- }
@@ -1,54 +0,0 @@
1
- import { resolveLogicalChunkReference } from '../module/chunk-path.js';
2
- import { transformSystemJs } from './system-js/system-js.js';
3
- /**
4
- * Converts one final Rolldown ESM chunk into the inert registration consumed by the WX module runtime.
5
- *
6
- * Why this boundary exists:
7
- *
8
- * - Rolldown produces an ESM chunk graph, but a Mini Program loads emitted JavaScript through native `require` and
9
- * `require.async`; it does not provide the browser ESM loader that normally links Vite chunks.
10
- * - Native App, Page, and Component shells must start through WeChat's synchronous lifecycle APIs, while their application
11
- * graph still needs ESM linking semantics such as cycles, live exports, dynamic imports, `import.meta`, and top-level await.
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 with `global.System.importSync`, and genuine asynchronous boundaries use
14
- * the same runtime through `System.import`.
15
- *
16
- * What this renderer emits:
17
- *
18
- * The result is CommonJS source whose `module.exports` is a SystemJS registration tuple:
19
- * `[logicalDependencyIds, declaration]`. Requiring a capsule only returns this inert tuple; it does not execute application
20
- * code or call a global `System.register`. The generated transport can consequently load the physical file from either the
21
- * main package or a subpackage, then hand its registration to the loader. The loader owns linking, setter invocation,
22
- * execution order, cycle handling, and export publication.
23
- *
24
- * Why references are rewritten:
25
- *
26
- * Rolldown imports name physical output files whose relative paths include placement directories and content hashes. The
27
- * SystemJS registry instead uses package-neutral logical chunk IDs. Canonicalizing both static and literal dynamic references
28
- * here lets transport independently map a stable module identity to the physical `require` path selected by WX placement.
29
- * Runtime-computed dynamic IDs cannot be canonicalized and are intentionally preserved.
30
- *
31
- * This function runs on final Rolldown output rather than arbitrary source modules. `transformSystemJs` accepts only the
32
- * normalized final-chunk grammar required by this pipeline and fails the build on unsupported forms instead of risking a
33
- * partial or semantically incorrect capsule. Source maps remain optional because WX development output deliberately disables
34
- * them on this startup-critical path.
35
- */
36
- export function renderCapsule(code, chunk, sourcemap) {
37
- return transformSystemJs({
38
- code,
39
- filename: chunk.fileName,
40
- // Native require must return registration data without executing or globally registering the capsule.
41
- format: 'commonjs-registration',
42
- sourcemap,
43
- // Bind every compile-time chunk edge to the same logical identity understood by transport and SystemJS.
44
- resolveReference(reference, kind) {
45
- return resolveCapsuleReference(chunk.fileName, reference, kind);
46
- }
47
- });
48
- }
49
- /** Canonicalizes physical chunk paths while preserving runtime-computed and package-like dynamic IDs. */
50
- function resolveCapsuleReference(fileName, reference, kind) {
51
- if (kind === 'dynamic' && !reference.startsWith('./') && !reference.startsWith('../'))
52
- return reference;
53
- return resolveLogicalChunkReference(fileName, reference);
54
- }