@blocklet/pages-kit 0.6.6 → 0.6.8

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.
@@ -76,6 +76,8 @@ function injectGlobalComponents() {
76
76
  };
77
77
  }
78
78
  win[builtin_1.RelativeModulesGlobalVariableName] = {};
79
+ win.React = react;
80
+ win.ReactDOM = reactDOM;
79
81
  // create module map
80
82
  const modules = {
81
83
  React: react,
@@ -45,9 +45,7 @@ ${script.script}
45
45
  ${injectScripts.join('\n')}
46
46
 
47
47
  <script>
48
-
49
48
  window.${types_1.PreloadComponentsStateGlobalVariableName} = ${safeJSONStringify(injectState)}
50
-
51
49
  </script>
52
50
  `,
53
51
  };
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createWellKnownChunksTransformer = exports.createBuiltinModuleTransformer = exports.isBuiltinModule = exports.isAsyncModule = exports.isRelativeModule = void 0;
4
- const path_1 = require("path");
3
+ exports.createBuiltinModuleTransformer = exports.isBuiltinModule = exports.isAsyncModule = exports.isRelativeModule = void 0;
5
4
  const builtin_1 = require("../../types/builtin");
6
5
  const isRelativeModule = (moduleSpecifier) => {
7
6
  if (!moduleSpecifier) {
@@ -91,21 +90,25 @@ const createBuiltinModuleTransformer = (ts) => (context) => (file) => {
91
90
  return factory.updateSourceFile(file, statements);
92
91
  };
93
92
  exports.createBuiltinModuleTransformer = createBuiltinModuleTransformer;
94
- const createWellKnownChunksTransformer = (ts) => (context) => (file) => {
95
- const { factory } = context;
96
- // 转换所有导入声明
97
- const transformedStatements = file.statements.map((node) => {
98
- if (ts.isImportDeclaration(node) &&
99
- ts.isStringLiteral(node.moduleSpecifier) &&
100
- (0, exports.isRelativeModule)(node.moduleSpecifier.text)) {
101
- const moduleSpecifier = node.moduleSpecifier.text;
102
- const fileName = (0, path_1.basename)(moduleSpecifier);
103
- const newPath = `/.well-known/chunks/${fileName}`;
104
- // 创建新的导入声明
105
- return factory.createImportDeclaration(node.modifiers, node.importClause, factory.createStringLiteral(newPath));
106
- }
107
- return node;
108
- });
109
- return factory.updateSourceFile(file, transformedStatements);
110
- };
111
- exports.createWellKnownChunksTransformer = createWellKnownChunksTransformer;
93
+ // export const createWellKnownChunksTransformer =
94
+ // (ts: typeof import('typescript')): TransformerFactory<SourceFile> =>
95
+ // (context) =>
96
+ // (file) => {
97
+ // const { factory } = context;
98
+ // // 转换所有导入声明
99
+ // const transformedStatements = file.statements.map((node) => {
100
+ // if (
101
+ // ts.isImportDeclaration(node) &&
102
+ // ts.isStringLiteral(node.moduleSpecifier) &&
103
+ // isRelativeModule(node.moduleSpecifier.text)
104
+ // ) {
105
+ // const moduleSpecifier = node.moduleSpecifier.text;
106
+ // const fileName = basename(moduleSpecifier);
107
+ // const newPath = `/.well-known/chunks/${fileName}`;
108
+ // // 创建新的导入声明
109
+ // return factory.createImportDeclaration(node.modifiers, node.importClause, factory.createStringLiteral(newPath));
110
+ // }
111
+ // return node;
112
+ // });
113
+ // return factory.updateSourceFile(file, transformedStatements);
114
+ // };
@@ -1,11 +1,17 @@
1
1
  import { joinURL } from 'ufo';
2
2
  export { joinURL, withQuery, getQuery } from 'ufo';
3
3
  export function getComponentMountPoint(name) {
4
+ let mountPoints = globalThis.blocklet?.componentMountPoints || [];
5
+ // 如果是在 server 端,则从环境变量中获取 mount points
4
6
  if (typeof window === 'undefined') {
5
- // eslint-disable-next-line global-require
6
- return require('@blocklet/sdk/lib/component').getComponentMountPoint(name);
7
+ try {
8
+ mountPoints = JSON.parse(process.env.BLOCKLET_MOUNT_POINTS || '[]');
9
+ }
10
+ catch (error) {
11
+ // ignore error
12
+ }
7
13
  }
8
- return globalThis.blocklet?.componentMountPoints.find((i) => i.name === name || i.did === name)?.mountPoint;
14
+ return mountPoints?.find((i) => i.name === name || i.did === name)?.mountPoint || '';
9
15
  }
10
16
  export function getMediaKitAbsoluteUrl(url) {
11
17
  if (url && url.startsWith('mediakit://') && typeof window !== 'undefined') {