fix: collection importer has incorrect reference (#1495)

* fix: collection importer has incorrect reference

* test: reimport test
This commit is contained in:
ChengLei Shao 2023-02-24 17:50:08 +08:00 committed by GitHub
parent 1bf0e0ac72
commit c9572fc9f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View File

@ -7,7 +7,19 @@ describe('collection importer', () => {
const reader = new ImporterReader(path.resolve(__dirname, './fixtures/collections'));
const modules = await reader.read();
expect(modules).toBeDefined();
const posts = modules.find((m) => m.name === 'posts');
expect(posts).toMatchObject({
name: 'posts',
fields: [{ type: 'string', name: 'title' }],
});
posts.schema = 'test';
const modules2 = await reader.read();
const posts2 = modules2.find((m) => m.name === 'posts');
expect(posts2.schema).toBeFalsy();
});
test('extend', async () => {

View File

@ -1,6 +1,6 @@
import path from 'path';
import { readdir } from 'fs/promises';
import { isPlainObject } from 'lodash';
import { cloneDeep, isPlainObject } from 'lodash';
import { requireModule } from '@nocobase/utils';
export type ImportFileExtension = 'js' | 'ts' | 'json';
@ -36,6 +36,6 @@ export class ImporterReader {
return typeof mod === 'function' ? mod() : mod;
});
return (await Promise.all(modules)).filter((module) => isPlainObject(module));
return (await Promise.all(modules)).filter((module) => isPlainObject(module)).map((module) => cloneDeep(module));
}
}