vite-plugin-taro 0.6.0 → 0.6.2

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 (68) hide show
  1. package/README.en.md +1 -1
  2. package/README.md +1 -1
  3. package/dist/node/plugins/h5/transform-app.js +1 -1
  4. package/dist/node/plugins/wx/dev/plugins.js +1 -1
  5. package/dist/node/plugins/wx/dev/wx-dev-options.js +22 -1
  6. package/dist/node/plugins/wx/module/chunk-path.d.ts +8 -0
  7. package/dist/node/plugins/wx/module/chunk-path.js +18 -0
  8. package/dist/node/plugins/wx/{module.js → module/module.js} +2 -2
  9. package/dist/node/plugins/wx/native/create-native-component-output.d.ts +3 -1
  10. package/dist/node/plugins/wx/native/create-native-component-output.js +3 -5
  11. package/dist/node/plugins/wx/output/files.d.ts +3 -2
  12. package/dist/node/plugins/wx/output/files.js +2 -2
  13. package/dist/node/plugins/wx/output/json.d.ts +1 -1
  14. package/dist/node/plugins/wx/output/json.js +1 -1
  15. package/dist/node/plugins/wx/placer/placement.d.ts +51 -0
  16. package/dist/node/plugins/wx/placer/placement.js +245 -0
  17. package/dist/node/plugins/wx/placer/placer.d.ts +76 -0
  18. package/dist/node/plugins/wx/placer/placer.js +147 -0
  19. package/dist/node/plugins/wx/plugins.js +17 -17
  20. package/dist/node/plugins/wx/render/capsule.d.ts +35 -3
  21. package/dist/node/plugins/wx/render/capsule.js +53 -12
  22. package/dist/node/plugins/wx/render/native.d.ts +20 -2
  23. package/dist/node/plugins/wx/render/native.js +539 -35
  24. package/dist/node/plugins/wx/render/system-js/string-editor.d.ts +24 -0
  25. package/dist/node/plugins/wx/render/system-js/string-editor.js +93 -0
  26. package/dist/node/plugins/wx/render/system-js/system-js.d.ts +23 -0
  27. package/dist/node/plugins/wx/render/system-js/system-js.js +602 -0
  28. package/dist/node/plugins/wx/render/transport.d.ts +7 -3
  29. package/dist/node/plugins/wx/render/transport.js +19 -10
  30. package/dist/node/plugins/wx/resolve/resolver.js +1 -1
  31. package/dist/node/plugins/wx/resolve/specialize-bootstrap.js +1 -1
  32. package/dist/node/plugins/wx/resolve/specialize-page-capsule.js +1 -1
  33. package/dist/node/utils/modules.d.ts +0 -2
  34. package/dist/node/utils/modules.js +0 -7
  35. package/dist/node/utils/transform.d.ts +0 -3
  36. package/dist/node/utils/transform.js +0 -23
  37. package/package.json +8 -6
  38. package/src/node/plugins/h5/transform-app.ts +1 -1
  39. package/src/node/plugins/wx/dev/plugins.ts +1 -1
  40. package/src/node/plugins/wx/dev/wx-dev-options.ts +22 -1
  41. package/src/node/plugins/wx/module/chunk-path.ts +22 -0
  42. package/src/node/plugins/wx/{module.ts → module/module.ts} +2 -2
  43. package/src/node/plugins/wx/native/create-native-component-output.ts +6 -5
  44. package/src/node/plugins/wx/output/files.ts +5 -3
  45. package/src/node/plugins/wx/output/json.ts +1 -2
  46. package/src/node/plugins/wx/placer/placement.ts +364 -0
  47. package/src/node/plugins/wx/placer/placer.ts +179 -0
  48. package/src/node/plugins/wx/plugins.ts +19 -19
  49. package/src/node/plugins/wx/render/capsule.ts +53 -17
  50. package/src/node/plugins/wx/render/native.ts +670 -55
  51. package/src/node/plugins/wx/render/system-js/string-editor.ts +115 -0
  52. package/src/node/plugins/wx/render/system-js/system-js.ts +831 -0
  53. package/src/node/plugins/wx/render/transport.ts +25 -9
  54. package/src/node/plugins/wx/resolve/resolver.ts +1 -1
  55. package/src/node/plugins/wx/resolve/specialize-bootstrap.ts +1 -1
  56. package/src/node/plugins/wx/resolve/specialize-page-capsule.ts +1 -1
  57. package/src/node/utils/modules.ts +0 -8
  58. package/src/node/utils/transform.ts +0 -30
  59. package/dist/node/plugins/wx/placement/placer.d.ts +0 -78
  60. package/dist/node/plugins/wx/placement/placer.js +0 -158
  61. package/dist/node/plugins/wx/placement/plan.d.ts +0 -46
  62. package/dist/node/plugins/wx/placement/plan.js +0 -210
  63. package/dist/node/plugins/wx/render/capsule-wrapper.d.ts +0 -3
  64. package/dist/node/plugins/wx/render/capsule-wrapper.js +0 -64
  65. package/src/node/plugins/wx/placement/placer.ts +0 -187
  66. package/src/node/plugins/wx/placement/plan.ts +0 -306
  67. package/src/node/plugins/wx/render/capsule-wrapper.ts +0 -86
  68. /package/dist/node/plugins/wx/{module.d.ts → module/module.d.ts} +0 -0
@@ -1,21 +1,57 @@
1
- import type { PluginTarget } from '@babel/core'
2
- import transformDynamicImport from '@babel/plugin-transform-dynamic-import'
3
- import transformModulesSystemjs from '@babel/plugin-transform-modules-systemjs'
4
1
  import type { Rolldown } from 'vite'
5
- import { type AstTransformResult, transformWithBabel } from '../../../utils/transform.ts'
6
- import { wrapCapsulePlugin } from './capsule-wrapper.ts'
2
+ import type { AstTransformResult } from '../../../utils/transform.ts'
3
+ import { resolveLogicalChunkReference } from '../module/chunk-path.ts'
4
+ import { type SystemJsReferenceKind, transformSystemJs } from './system-js/system-js.ts'
7
5
 
8
- /** Renders one ESM chunk as an inert SystemJS capsule. */
9
- export function renderCapsule(code: string, chunk: Rolldown.RenderedChunk, sourcemap = true): AstTransformResult {
10
- return transformWithBabel(
6
+ /**
7
+ * Converts one final Rolldown ESM chunk into the inert registration consumed by the WX module runtime.
8
+ *
9
+ * Why this boundary exists:
10
+ *
11
+ * - Rolldown produces an ESM chunk graph, but a Mini Program loads emitted JavaScript through native `require` and
12
+ * `require.async`; it does not provide the browser ESM loader that normally links Vite chunks.
13
+ * - Native App, Page, and Component shells must start through WeChat's synchronous lifecycle APIs, while their application
14
+ * graph still needs ESM linking semantics such as cycles, live exports, dynamic imports, `import.meta`, and top-level await.
15
+ * - The plugin therefore keeps native lifecycle shells as CommonJS and executes application "capsules" through the bundled
16
+ * SystemJS runtime. Native shells enter that graph with `global.System.importSync`, and genuine asynchronous boundaries use
17
+ * the same runtime through `System.import`.
18
+ *
19
+ * What this renderer emits:
20
+ *
21
+ * The result is CommonJS source whose `module.exports` is a SystemJS registration tuple:
22
+ * `[logicalDependencyIds, declaration]`. Requiring a capsule only returns this inert tuple; it does not execute application
23
+ * code or call a global `System.register`. The generated transport can consequently load the physical file from either the
24
+ * main package or a subpackage, then hand its registration to the loader. The loader owns linking, setter invocation,
25
+ * execution order, cycle handling, and export publication.
26
+ *
27
+ * Why references are rewritten:
28
+ *
29
+ * Rolldown imports name physical output files whose relative paths include placement directories and content hashes. The
30
+ * SystemJS registry instead uses package-neutral logical chunk IDs. Canonicalizing both static and literal dynamic references
31
+ * here lets transport independently map a stable module identity to the physical `require` path selected by WX placement.
32
+ * Runtime-computed dynamic IDs cannot be canonicalized and are intentionally preserved.
33
+ *
34
+ * This function runs on final Rolldown output rather than arbitrary source modules. `transformSystemJs` accepts only the
35
+ * normalized final-chunk grammar required by this pipeline and fails the build on unsupported forms instead of risking a
36
+ * partial or semantically incorrect capsule. Source maps remain optional because WX development output deliberately disables
37
+ * them on this startup-critical path.
38
+ */
39
+ export function renderCapsule(code: string, chunk: Rolldown.RenderedChunk, sourcemap: boolean): AstTransformResult {
40
+ return transformSystemJs({
11
41
  code,
12
- chunk.fileName,
13
- [
14
- transformDynamicImport,
15
- // Erase Babel's internal plugin pass type.
16
- transformModulesSystemjs as PluginTarget,
17
- wrapCapsulePlugin(chunk.fileName) as PluginTarget
18
- ],
19
- sourcemap
20
- )
42
+ filename: chunk.fileName,
43
+ // Native require must return registration data without executing or globally registering the capsule.
44
+ format: 'commonjs-registration',
45
+ sourcemap,
46
+ // Bind every compile-time chunk edge to the same logical identity understood by transport and SystemJS.
47
+ resolveReference(reference, kind) {
48
+ return resolveCapsuleReference(chunk.fileName, reference, kind)
49
+ }
50
+ })
51
+ }
52
+
53
+ /** Canonicalizes physical chunk paths while preserving runtime-computed and package-like dynamic IDs. */
54
+ function resolveCapsuleReference(fileName: string, reference: string, kind: SystemJsReferenceKind): string {
55
+ if (kind === 'dynamic' && !reference.startsWith('./') && !reference.startsWith('../')) return reference
56
+ return resolveLogicalChunkReference(fileName, reference)
21
57
  }