Skip to content

Commit 4e81570

Browse files
authored
feat: enhance manifest and import functionality (#207)
- Update manifest JSON handling and validation - Improve import map utilities and serialization - Add enhanced module configuration support - Update related tests and type definitions
1 parent 18a524f commit 4e81570

File tree

6 files changed

+44
-353
lines changed

6 files changed

+44
-353
lines changed

packages/core/src/manifest-json.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ export interface ManifestJson {
99
* Module name
1010
*/
1111
name: string;
12-
/**
13-
* Import mappings
14-
*/
15-
imports: Record<string, string>;
1612
/**
1713
* Scope-specific import mappings
1814
* Type: Record<scope name, import mappings within that scope>

packages/core/src/module-config.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,37 @@ describe('Module Config Parser', () => {
313313
expect(emptyScope.existing).toBe('existing-value');
314314
expect(emptyScope.lodash).toBe('test-module/lodash');
315315
});
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+
});
316347
});
317348

318349
describe('addPackageExportsToScopes', () => {

packages/core/src/module-config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,13 @@ export function getEnvironments(
145145
): ParsedModuleConfigEnvironment {
146146
const imports = getEnvironmentImports(env, config.imports);
147147
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+
});
149155
addPackageExportsToScopes(exports, scopes, moduleName);
150156
return {
151157
imports,

0 commit comments

Comments
 (0)