@esmx/core 3.0.0-rc.62 → 3.0.0-rc.64

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/package.json CHANGED
@@ -59,7 +59,7 @@
59
59
  "build": "unbuild"
60
60
  },
61
61
  "dependencies": {
62
- "@esmx/import": "3.0.0-rc.62",
62
+ "@esmx/import": "3.0.0-rc.64",
63
63
  "@types/serialize-javascript": "^5.0.4",
64
64
  "es-module-lexer": "^1.7.0",
65
65
  "find": "^0.3.0",
@@ -77,7 +77,7 @@
77
77
  "unbuild": "3.6.0",
78
78
  "vitest": "3.2.4"
79
79
  },
80
- "version": "3.0.0-rc.62",
80
+ "version": "3.0.0-rc.64",
81
81
  "type": "module",
82
82
  "private": false,
83
83
  "exports": {
@@ -100,5 +100,5 @@
100
100
  "template",
101
101
  "public"
102
102
  ],
103
- "gitHead": "e5a1e811403bf1db4437dff88c3ea8bc6b576f64"
103
+ "gitHead": "8c103750d1e623fa4fa23b6ed9149f39e4a9bd58"
104
104
  }
package/src/core.ts CHANGED
@@ -853,7 +853,7 @@ export class Esmx {
853
853
  const manifests = await this.getManifestList(env);
854
854
  let json: ImportMap = {};
855
855
  switch (env) {
856
- case 'client':
856
+ case 'client': {
857
857
  json = getImportMap({
858
858
  manifests,
859
859
  getScope(name, scope) {
@@ -864,6 +864,7 @@ export class Esmx {
864
864
  }
865
865
  });
866
866
  break;
867
+ }
867
868
  case 'server':
868
869
  json = getImportMap({
869
870
  manifests,
@@ -9,10 +9,6 @@ export interface ManifestJson {
9
9
  * Module name
10
10
  */
11
11
  name: string;
12
- /**
13
- * Import mappings
14
- */
15
- imports: Record<string, string>;
16
12
  /**
17
13
  * Scope-specific import mappings
18
14
  * Type: Record<scope name, import mappings within that scope>
@@ -313,6 +313,37 @@ describe('Module Config Parser', () => {
313
313
  expect(emptyScope.existing).toBe('existing-value');
314
314
  expect(emptyScope.lodash).toBe('test-module/lodash');
315
315
  });
316
+
317
+ it('should verify the specific scopes merging logic with imports', () => {
318
+ const config: ModuleConfig = {
319
+ imports: {
320
+ react: 'react',
321
+ vue: 'vue'
322
+ },
323
+ scopes: {
324
+ utils: {
325
+ lodash: 'lodash'
326
+ },
327
+ '': {
328
+ existing: 'existing-value'
329
+ }
330
+ }
331
+ };
332
+ const result = getEnvironments(config, 'client', 'test-module');
333
+
334
+ // 验证核心逻辑:imports 被合并到空字符串 scope 中
335
+ expect(result.scopes['']).toBeDefined();
336
+ expect(result.scopes[''].existing).toBe('existing-value'); // 保留现有内容
337
+ expect(result.scopes[''].react).toBe('react'); // 合并 imports
338
+ expect(result.scopes[''].vue).toBe('vue'); // 合并 imports
339
+
340
+ // 验证其他 scopes 不受影响
341
+ expect(result.scopes.utils.lodash).toBe('lodash');
342
+
343
+ // 验证 result.imports 也包含相同的 imports
344
+ expect(result.imports.react).toBe('react');
345
+ expect(result.imports.vue).toBe('vue');
346
+ });
316
347
  });
317
348
 
318
349
  describe('addPackageExportsToScopes', () => {
@@ -145,7 +145,13 @@ export function getEnvironments(
145
145
  ): ParsedModuleConfigEnvironment {
146
146
  const imports = getEnvironmentImports(env, config.imports);
147
147
  const exports = getEnvironmentExports(config, env);
148
- const scopes = getEnvironmentScopes(env, config.scopes);
148
+ const scopes = getEnvironmentScopes(env, {
149
+ ...config.scopes,
150
+ '': {
151
+ ...config.scopes?.[''],
152
+ ...imports
153
+ }
154
+ });
149
155
  addPackageExportsToScopes(exports, scopes, moduleName);
150
156
  return {
151
157
  imports,