From c9572fc9f668adf093f350b9c3a6707df323e1e8 Mon Sep 17 00:00:00 2001 From: ChengLei Shao Date: Fri, 24 Feb 2023 17:50:08 +0800 Subject: [PATCH] fix: collection importer has incorrect reference (#1495) * fix: collection importer has incorrect reference * test: reimport test --- .../src/__tests__/collection-importer.test.ts | 14 +++++++++++++- packages/core/database/src/collection-importer.ts | 4 ++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/core/database/src/__tests__/collection-importer.test.ts b/packages/core/database/src/__tests__/collection-importer.test.ts index 0a9bcf8c8..e9d3c6399 100644 --- a/packages/core/database/src/__tests__/collection-importer.test.ts +++ b/packages/core/database/src/__tests__/collection-importer.test.ts @@ -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 () => { diff --git a/packages/core/database/src/collection-importer.ts b/packages/core/database/src/collection-importer.ts index 2dcae4e45..1d1a78a29 100644 --- a/packages/core/database/src/collection-importer.ts +++ b/packages/core/database/src/collection-importer.ts @@ -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)); } }