@blocklet/pages-kit 0.6.46 → 0.6.47
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.
|
@@ -13,8 +13,6 @@ const isAsyncModule = (moduleSpecifier) => {
|
|
|
13
13
|
if (!moduleSpecifier) {
|
|
14
14
|
return false;
|
|
15
15
|
}
|
|
16
|
-
// return ['@blocklet/pages-kit/builtin/async/ai-runtime'].includes(moduleSpecifier);
|
|
17
|
-
// FIXME 看起来原来的条件像是有问题,目前已经没有 ai-runtime 了,暂时先注释掉,直接返回 false
|
|
18
16
|
return false;
|
|
19
17
|
};
|
|
20
18
|
exports.isAsyncModule = isAsyncModule;
|
|
@@ -30,8 +28,23 @@ const createBuiltinModuleTransformer = (ts) => (context) => (file) => {
|
|
|
30
28
|
const { factory } = context;
|
|
31
29
|
// 统一的模块导入收集器
|
|
32
30
|
const imports = [];
|
|
31
|
+
// Transform dynamic imports in expressions
|
|
32
|
+
const transformNode = (node) => {
|
|
33
|
+
// Handle import() calls
|
|
34
|
+
if (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword) {
|
|
35
|
+
const arg = node.arguments[0];
|
|
36
|
+
if (arg && ts.isStringLiteral(arg) && ((0, exports.isBuiltinModule)(arg.text) || (0, exports.isRelativeModule)(arg.text))) {
|
|
37
|
+
const requireCall = factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier(builtin_1.BuiltinModulesGlobalVariableName), 'require'), undefined, [factory.createStringLiteral(arg.text)]);
|
|
38
|
+
// For dynamic imports, we don't add await - they should return Promise
|
|
39
|
+
// The calling code (like .then()) will handle the Promise
|
|
40
|
+
return requireCall;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return ts.visitEachChild(node, transformNode, context);
|
|
44
|
+
};
|
|
33
45
|
// filter and collect the import statements that need to be processed
|
|
34
|
-
const statements = file.statements
|
|
46
|
+
const statements = file.statements
|
|
47
|
+
.filter((s) => {
|
|
35
48
|
if (ts.isImportDeclaration(s) &&
|
|
36
49
|
ts.isStringLiteral(s.moduleSpecifier) &&
|
|
37
50
|
((0, exports.isBuiltinModule)(s.moduleSpecifier.text) || (0, exports.isRelativeModule)(s.moduleSpecifier.text))) {
|
|
@@ -59,10 +72,12 @@ const createBuiltinModuleTransformer = (ts) => (context) => (file) => {
|
|
|
59
72
|
return false;
|
|
60
73
|
}
|
|
61
74
|
return true;
|
|
62
|
-
})
|
|
75
|
+
})
|
|
76
|
+
.map((statement) => transformNode(statement)); // Transform dynamic imports in remaining statements
|
|
63
77
|
statements.unshift(...imports.flatMap((importInfo) => {
|
|
64
78
|
// call inject-global-components require method
|
|
65
79
|
const requireCall = factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier(builtin_1.BuiltinModulesGlobalVariableName), 'require'), undefined, [factory.createStringLiteral(importInfo.moduleName)]);
|
|
80
|
+
// Only static imports should be async, dynamic imports return Promise
|
|
66
81
|
const isAsync = (0, exports.isRelativeModule)(importInfo.moduleName) || (0, exports.isAsyncModule)(importInfo.moduleName);
|
|
67
82
|
// create await expression if the module is ../ or ./
|
|
68
83
|
const mod = isAsync ? factory.createAwaitExpression(requireCall) : requireCall;
|