vite-plugin-taro 0.6.1 → 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/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 +1 -1
- package/dist/node/plugins/wx/{module.js → module/module.js} +2 -2
- package/dist/node/plugins/wx/placer/placement.d.ts +1 -0
- package/dist/node/plugins/wx/placer/placement.js +1 -1
- package/dist/node/plugins/wx/placer/placer.d.ts +17 -1
- package/dist/node/plugins/wx/placer/placer.js +25 -1
- package/dist/node/plugins/wx/plugins.js +1 -1
- 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.js +3 -3
- 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/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 +1 -1
- package/src/node/plugins/wx/{module.ts → module/module.ts} +2 -2
- package/src/node/plugins/wx/placer/placement.ts +1 -1
- package/src/node/plugins/wx/placer/placer.ts +27 -2
- package/src/node/plugins/wx/plugins.ts +1 -1
- 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 +3 -3
- 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/transform.ts +0 -30
- 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/render/capsule-wrapper.ts +0 -86
- /package/dist/node/plugins/wx/{chunk-path.d.ts → module/chunk-path.d.ts} +0 -0
- /package/dist/node/plugins/wx/{chunk-path.js → module/chunk-path.js} +0 -0
- /package/dist/node/plugins/wx/{module.d.ts → module/module.d.ts} +0 -0
- /package/src/node/plugins/wx/{chunk-path.ts → module/chunk-path.ts} +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
|
-
import
|
|
2
|
+
import * as types from '@babel/types'
|
|
3
3
|
import type { Rolldown } from 'vite'
|
|
4
4
|
import { type AstTransformResult, replaceWithAst } from '../../../utils/transform.ts'
|
|
5
|
-
import { toLogicalChunkId } from '../chunk-path.ts'
|
|
6
|
-
import { getWxExecutionKind } from '../module.ts'
|
|
5
|
+
import { toLogicalChunkId } from '../module/chunk-path.ts'
|
|
6
|
+
import { getWxExecutionKind } from '../module/module.ts'
|
|
7
7
|
|
|
8
8
|
const transportPlaceholder = '__VPT_TRANSPORT__'
|
|
9
9
|
const moduleIdParameter = 'moduleId'
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
pageShellPath,
|
|
18
18
|
transportPath,
|
|
19
19
|
vitePreloadId
|
|
20
|
-
} from '../module.ts'
|
|
20
|
+
} from '../module/module.ts'
|
|
21
21
|
import { specializeBootstrap } from './specialize-bootstrap.ts'
|
|
22
22
|
import { specializePageCapsule } from './specialize-page-capsule.ts'
|
|
23
23
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { type PluginItem, transformSync } from '@babel/core'
|
|
2
1
|
import { generate } from '@babel/generator'
|
|
3
2
|
import { type Rolldown, transformWithOxc } from 'vite'
|
|
4
3
|
import { esTarget } from './constant.ts'
|
|
@@ -51,32 +50,3 @@ function requireOnePlaceholder(code: string, placeholder: string): void {
|
|
|
51
50
|
throw new Error(`Expected one placeholder ${placeholder}, found ${replacementCount}`)
|
|
52
51
|
}
|
|
53
52
|
}
|
|
54
|
-
|
|
55
|
-
/** Transforms one module with Babel's shared parser and source-map configuration. */
|
|
56
|
-
export function transformWithBabel(
|
|
57
|
-
code: string,
|
|
58
|
-
filename: string,
|
|
59
|
-
plugins: PluginItem[],
|
|
60
|
-
sourcemap = true
|
|
61
|
-
): AstTransformResult {
|
|
62
|
-
const transformed = transformSync(code, {
|
|
63
|
-
babelrc: false,
|
|
64
|
-
compact: true,
|
|
65
|
-
minified: true,
|
|
66
|
-
comments: false,
|
|
67
|
-
configFile: false,
|
|
68
|
-
filename,
|
|
69
|
-
plugins,
|
|
70
|
-
sourceFileName: filename,
|
|
71
|
-
sourceMaps: sourcemap,
|
|
72
|
-
sourceType: 'module'
|
|
73
|
-
})
|
|
74
|
-
if (!transformed?.code || (sourcemap && !transformed.map)) {
|
|
75
|
-
throw new Error(`Failed to transform ${filename} with Babel`)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return {
|
|
79
|
-
code: transformed.code,
|
|
80
|
-
map: sourcemap ? (transformed.map as Rolldown.ExistingRawSourceMap) : null
|
|
81
|
-
}
|
|
82
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { types } from '@babel/core';
|
|
2
|
-
import { resolveLogicalChunkReference } from '../chunk-path.js';
|
|
3
|
-
/** Wraps System.register as an inert CommonJS capsule tuple with canonical final dependency IDs. */
|
|
4
|
-
export function wrapCapsulePlugin(fileName) {
|
|
5
|
-
return {
|
|
6
|
-
name: 'vpt:wrap-capsule',
|
|
7
|
-
visitor: {},
|
|
8
|
-
post(file) {
|
|
9
|
-
const program = file.ast.program;
|
|
10
|
-
const [statement] = program.body;
|
|
11
|
-
const registration = statement && types.isExpressionStatement(statement) ? statement.expression : undefined;
|
|
12
|
-
if (program.body.length !== 1 ||
|
|
13
|
-
!types.isCallExpression(registration) ||
|
|
14
|
-
!types.isMemberExpression(registration.callee) ||
|
|
15
|
-
registration.callee.computed ||
|
|
16
|
-
!types.isIdentifier(registration.callee.object, { name: 'System' }) ||
|
|
17
|
-
!types.isIdentifier(registration.callee.property, { name: 'register' })) {
|
|
18
|
-
throw new Error(`Expected one anonymous System.register call in ${fileName}`);
|
|
19
|
-
}
|
|
20
|
-
const [dependencies, declaration] = registration.arguments;
|
|
21
|
-
if (registration.arguments.length !== 2 ||
|
|
22
|
-
!types.isArrayExpression(dependencies) ||
|
|
23
|
-
!types.isFunctionExpression(declaration)) {
|
|
24
|
-
throw new Error(`Expected System.register(dependencies, declaration) in ${fileName}`);
|
|
25
|
-
}
|
|
26
|
-
dependencies.elements.forEach((dependency) => {
|
|
27
|
-
canonicalizeStaticReference(dependency, fileName);
|
|
28
|
-
});
|
|
29
|
-
const context = declaration.params[1];
|
|
30
|
-
if (types.isIdentifier(context)) {
|
|
31
|
-
file.path.traverse({
|
|
32
|
-
CallExpression(callPath) {
|
|
33
|
-
const callee = callPath.node.callee;
|
|
34
|
-
if (!types.isMemberExpression(callee) ||
|
|
35
|
-
callee.computed ||
|
|
36
|
-
!types.isIdentifier(callee.object, { name: context.name }) ||
|
|
37
|
-
!types.isIdentifier(callee.property, { name: 'import' })) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
const [dependency] = callPath.node.arguments;
|
|
41
|
-
canonicalizeDynamicReference(dependency, fileName);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
program.directives = [];
|
|
46
|
-
program.body = [
|
|
47
|
-
types.expressionStatement(types.assignmentExpression('=', types.memberExpression(types.identifier('module'), types.identifier('exports')), types.arrayExpression([dependencies, declaration])))
|
|
48
|
-
];
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
/** Resolves one generated static reference while the final importing chunk filename is known. */
|
|
53
|
-
function canonicalizeStaticReference(reference, fileName) {
|
|
54
|
-
if (!types.isStringLiteral(reference)) {
|
|
55
|
-
throw new Error(`Expected a literal System.register dependency in ${fileName}`);
|
|
56
|
-
}
|
|
57
|
-
reference.value = resolveLogicalChunkReference(fileName, reference.value);
|
|
58
|
-
}
|
|
59
|
-
/** Resolves application literals while preserving runtime-computed IDs injected by the development runtime. */
|
|
60
|
-
function canonicalizeDynamicReference(reference, fileName) {
|
|
61
|
-
if (types.isStringLiteral(reference) && (reference.value.startsWith('./') || reference.value.startsWith('../'))) {
|
|
62
|
-
reference.value = resolveLogicalChunkReference(fileName, reference.value);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { type PluginObj, types } from '@babel/core'
|
|
2
|
-
import { resolveLogicalChunkReference } from '../chunk-path.ts'
|
|
3
|
-
|
|
4
|
-
/** Wraps System.register as an inert CommonJS capsule tuple with canonical final dependency IDs. */
|
|
5
|
-
export function wrapCapsulePlugin(fileName: string): PluginObj {
|
|
6
|
-
return {
|
|
7
|
-
name: 'vpt:wrap-capsule',
|
|
8
|
-
visitor: {},
|
|
9
|
-
|
|
10
|
-
post(file) {
|
|
11
|
-
const program = file.ast.program
|
|
12
|
-
const [statement] = program.body
|
|
13
|
-
const registration = statement && types.isExpressionStatement(statement) ? statement.expression : undefined
|
|
14
|
-
|
|
15
|
-
if (
|
|
16
|
-
program.body.length !== 1 ||
|
|
17
|
-
!types.isCallExpression(registration) ||
|
|
18
|
-
!types.isMemberExpression(registration.callee) ||
|
|
19
|
-
registration.callee.computed ||
|
|
20
|
-
!types.isIdentifier(registration.callee.object, { name: 'System' }) ||
|
|
21
|
-
!types.isIdentifier(registration.callee.property, { name: 'register' })
|
|
22
|
-
) {
|
|
23
|
-
throw new Error(`Expected one anonymous System.register call in ${fileName}`)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const [dependencies, declaration] = registration.arguments
|
|
27
|
-
if (
|
|
28
|
-
registration.arguments.length !== 2 ||
|
|
29
|
-
!types.isArrayExpression(dependencies) ||
|
|
30
|
-
!types.isFunctionExpression(declaration)
|
|
31
|
-
) {
|
|
32
|
-
throw new Error(`Expected System.register(dependencies, declaration) in ${fileName}`)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
dependencies.elements.forEach((dependency) => {
|
|
36
|
-
canonicalizeStaticReference(dependency, fileName)
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
const context = declaration.params[1]
|
|
40
|
-
if (types.isIdentifier(context)) {
|
|
41
|
-
file.path.traverse({
|
|
42
|
-
CallExpression(callPath) {
|
|
43
|
-
const callee = callPath.node.callee
|
|
44
|
-
if (
|
|
45
|
-
!types.isMemberExpression(callee) ||
|
|
46
|
-
callee.computed ||
|
|
47
|
-
!types.isIdentifier(callee.object, { name: context.name }) ||
|
|
48
|
-
!types.isIdentifier(callee.property, { name: 'import' })
|
|
49
|
-
) {
|
|
50
|
-
return
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const [dependency] = callPath.node.arguments
|
|
54
|
-
canonicalizeDynamicReference(dependency, fileName)
|
|
55
|
-
}
|
|
56
|
-
})
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
program.directives = []
|
|
60
|
-
program.body = [
|
|
61
|
-
types.expressionStatement(
|
|
62
|
-
types.assignmentExpression(
|
|
63
|
-
'=',
|
|
64
|
-
types.memberExpression(types.identifier('module'), types.identifier('exports')),
|
|
65
|
-
types.arrayExpression([dependencies, declaration])
|
|
66
|
-
)
|
|
67
|
-
)
|
|
68
|
-
]
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/** Resolves one generated static reference while the final importing chunk filename is known. */
|
|
74
|
-
function canonicalizeStaticReference(reference: types.Node | null | undefined, fileName: string): void {
|
|
75
|
-
if (!types.isStringLiteral(reference)) {
|
|
76
|
-
throw new Error(`Expected a literal System.register dependency in ${fileName}`)
|
|
77
|
-
}
|
|
78
|
-
reference.value = resolveLogicalChunkReference(fileName, reference.value)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/** Resolves application literals while preserving runtime-computed IDs injected by the development runtime. */
|
|
82
|
-
function canonicalizeDynamicReference(reference: types.Node | null | undefined, fileName: string): void {
|
|
83
|
-
if (types.isStringLiteral(reference) && (reference.value.startsWith('./') || reference.value.startsWith('../'))) {
|
|
84
|
-
reference.value = resolveLogicalChunkReference(fileName, reference.value)
|
|
85
|
-
}
|
|
86
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|