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.
- package/README.en.md +1 -1
- package/README.md +1 -1
- package/dist/node/plugins/h5/transform-app.js +1 -1
- package/dist/node/plugins/wx/dev/plugins.js +1 -1
- package/dist/node/plugins/wx/dev/wx-dev-options.js +22 -1
- package/dist/node/plugins/wx/module/chunk-path.d.ts +8 -0
- package/dist/node/plugins/wx/module/chunk-path.js +18 -0
- package/dist/node/plugins/wx/{module.js → module/module.js} +2 -2
- package/dist/node/plugins/wx/native/create-native-component-output.d.ts +3 -1
- package/dist/node/plugins/wx/native/create-native-component-output.js +3 -5
- package/dist/node/plugins/wx/output/files.d.ts +3 -2
- package/dist/node/plugins/wx/output/files.js +2 -2
- package/dist/node/plugins/wx/output/json.d.ts +1 -1
- package/dist/node/plugins/wx/output/json.js +1 -1
- package/dist/node/plugins/wx/placer/placement.d.ts +51 -0
- package/dist/node/plugins/wx/placer/placement.js +245 -0
- package/dist/node/plugins/wx/placer/placer.d.ts +76 -0
- package/dist/node/plugins/wx/placer/placer.js +147 -0
- package/dist/node/plugins/wx/plugins.js +17 -17
- package/dist/node/plugins/wx/render/capsule.d.ts +35 -3
- package/dist/node/plugins/wx/render/capsule.js +53 -12
- package/dist/node/plugins/wx/render/native.d.ts +20 -2
- package/dist/node/plugins/wx/render/native.js +539 -35
- package/dist/node/plugins/wx/render/system-js/string-editor.d.ts +24 -0
- package/dist/node/plugins/wx/render/system-js/string-editor.js +93 -0
- package/dist/node/plugins/wx/render/system-js/system-js.d.ts +23 -0
- package/dist/node/plugins/wx/render/system-js/system-js.js +602 -0
- package/dist/node/plugins/wx/render/transport.d.ts +7 -3
- package/dist/node/plugins/wx/render/transport.js +19 -10
- package/dist/node/plugins/wx/resolve/resolver.js +1 -1
- package/dist/node/plugins/wx/resolve/specialize-bootstrap.js +1 -1
- package/dist/node/plugins/wx/resolve/specialize-page-capsule.js +1 -1
- package/dist/node/utils/modules.d.ts +0 -2
- package/dist/node/utils/modules.js +0 -7
- package/dist/node/utils/transform.d.ts +0 -3
- package/dist/node/utils/transform.js +0 -23
- package/package.json +8 -6
- package/src/node/plugins/h5/transform-app.ts +1 -1
- package/src/node/plugins/wx/dev/plugins.ts +1 -1
- package/src/node/plugins/wx/dev/wx-dev-options.ts +22 -1
- package/src/node/plugins/wx/module/chunk-path.ts +22 -0
- package/src/node/plugins/wx/{module.ts → module/module.ts} +2 -2
- package/src/node/plugins/wx/native/create-native-component-output.ts +6 -5
- package/src/node/plugins/wx/output/files.ts +5 -3
- package/src/node/plugins/wx/output/json.ts +1 -2
- package/src/node/plugins/wx/placer/placement.ts +364 -0
- package/src/node/plugins/wx/placer/placer.ts +179 -0
- package/src/node/plugins/wx/plugins.ts +19 -19
- package/src/node/plugins/wx/render/capsule.ts +53 -17
- package/src/node/plugins/wx/render/native.ts +670 -55
- package/src/node/plugins/wx/render/system-js/string-editor.ts +115 -0
- package/src/node/plugins/wx/render/system-js/system-js.ts +831 -0
- package/src/node/plugins/wx/render/transport.ts +25 -9
- package/src/node/plugins/wx/resolve/resolver.ts +1 -1
- package/src/node/plugins/wx/resolve/specialize-bootstrap.ts +1 -1
- package/src/node/plugins/wx/resolve/specialize-page-capsule.ts +1 -1
- package/src/node/utils/modules.ts +0 -8
- package/src/node/utils/transform.ts +0 -30
- package/dist/node/plugins/wx/placement/placer.d.ts +0 -78
- package/dist/node/plugins/wx/placement/placer.js +0 -158
- package/dist/node/plugins/wx/placement/plan.d.ts +0 -46
- package/dist/node/plugins/wx/placement/plan.js +0 -210
- package/dist/node/plugins/wx/render/capsule-wrapper.d.ts +0 -3
- package/dist/node/plugins/wx/render/capsule-wrapper.js +0 -64
- package/src/node/plugins/wx/placement/placer.ts +0 -187
- package/src/node/plugins/wx/placement/plan.ts +0 -306
- package/src/node/plugins/wx/render/capsule-wrapper.ts +0 -86
- /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 {
|
|
6
|
-
import {
|
|
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
|
-
/**
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
}
|