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