[REFACTOR] twenty-shared multi barrel and CJS/ESM build with preconstruct (#11083)
# Introduction In this PR we've migrated `twenty-shared` from a `vite` app [libary-mode](https://vite.dev/guide/build#library-mode) to a [preconstruct](https://preconstruct.tools/) "atomic" application ( in the future would like to introduce preconstruct to handle of all our atomic dependencies such as `twenty-emails` `twenty-ui` etc it will be integrated at the monorepo's root directly, would be to invasive in the first, starting incremental via `twenty-shared`) For more information regarding the motivations please refer to nor: - https://github.com/twentyhq/core-team-issues/issues/587 - https://github.com/twentyhq/core-team-issues/issues/281#issuecomment-2630949682 close https://github.com/twentyhq/core-team-issues/issues/589 close https://github.com/twentyhq/core-team-issues/issues/590 ## How to test In order to ease the review this PR will ship all the codegen at the very end, the actual meaning full diff is `+2,411 −114` In order to migrate existing dependent packages to `twenty-shared` multi barrel new arch you need to run in local: ```sh yarn tsx packages/twenty-shared/scripts/migrateFromSingleToMultiBarrelImport.ts && \ npx nx run-many -t lint --fix -p twenty-front twenty-ui twenty-server twenty-emails twenty-shared twenty-zapier ``` Note that `migrateFromSingleToMultiBarrelImport` is idempotent, it's atm included in the PR but should not be merged. ( such as codegen will be added before merging this script will be removed ) ## Misc - related opened issue preconstruct https://github.com/preconstruct/preconstruct/issues/617 ## Closed related PR - https://github.com/twentyhq/twenty/pull/11028 - https://github.com/twentyhq/twenty/pull/10993 - https://github.com/twentyhq/twenty/pull/10960 ## Upcoming enhancement: ( in others dedicated PRs ) - 1/ refactor generate barrel to export atomic module instead of `*` - 2/ generate barrel own package with several files and tests - 3/ Migration twenty-ui the same way - 4/ Use `preconstruct` at monorepo global level ## Conclusion As always any suggestions are welcomed !
This commit is contained in:
@ -3,7 +3,7 @@ import { ObjectMetadataItemIdentifier } from '@/object-metadata/types/ObjectMeta
|
||||
import { useCreateOneRecordInCache } from '@/object-record/cache/hooks/useCreateOneRecordInCache';
|
||||
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
|
||||
import { prefillRecord } from '@/object-record/utils/prefillRecord';
|
||||
import { isDefined } from 'twenty-shared';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
export const useCreateManyRecordsInCache = <T extends ObjectRecord>({
|
||||
objectNameSingular,
|
||||
|
||||
@ -10,7 +10,7 @@ import { getRecordNodeFromRecord } from '@/object-record/cache/utils/getRecordNo
|
||||
import { computeDepthOneRecordGqlFieldsFromRecord } from '@/object-record/graphql/utils/computeDepthOneRecordGqlFieldsFromRecord';
|
||||
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
|
||||
import { prefillRecord } from '@/object-record/utils/prefillRecord';
|
||||
import { capitalize } from 'twenty-shared';
|
||||
import { capitalize } from 'twenty-shared/utils';
|
||||
|
||||
export const useCreateOneRecordInCache = <T extends ObjectRecord>({
|
||||
objectMetadataItem,
|
||||
|
||||
@ -7,7 +7,7 @@ import { RecordGqlOperationFindManyResult } from '@/object-record/graphql/types/
|
||||
import { RecordGqlOperationVariables } from '@/object-record/graphql/types/RecordGqlOperationVariables';
|
||||
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
|
||||
import { generateFindManyRecordsQuery } from '@/object-record/utils/generateFindManyRecordsQuery';
|
||||
import { isDefined } from 'twenty-shared';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
export const useReadFindManyRecordsQueryInCache = ({
|
||||
objectMetadataItem,
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { getObjectTypename } from '@/object-record/cache/utils/getObjectTypename';
|
||||
import { capitalize } from 'twenty-shared';
|
||||
import { capitalize } from 'twenty-shared/utils';
|
||||
|
||||
export const getConnectionTypename = (objectNameSingular: string) => {
|
||||
return `${capitalize(getObjectTypename(objectNameSingular))}Connection`;
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { getObjectTypename } from '@/object-record/cache/utils/getObjectTypename';
|
||||
import { capitalize } from 'twenty-shared';
|
||||
import { capitalize } from 'twenty-shared/utils';
|
||||
|
||||
export const getEdgeTypename = (objectNameSingular: string) => {
|
||||
return `${capitalize(getObjectTypename(objectNameSingular))}Edge`;
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { getObjectTypename } from '@/object-record/cache/utils/getObjectTypename';
|
||||
import { capitalize } from 'twenty-shared';
|
||||
import { capitalize } from 'twenty-shared/utils';
|
||||
|
||||
export const getNodeTypename = (objectNameSingular: string) => {
|
||||
return capitalize(getObjectTypename(objectNameSingular));
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { capitalize } from 'twenty-shared';
|
||||
|
||||
import { capitalize } from 'twenty-shared/utils';
|
||||
export const getObjectTypename = (objectNameSingular: string) => {
|
||||
return capitalize(objectNameSingular);
|
||||
};
|
||||
|
||||
@ -6,9 +6,9 @@ import { getRecordFromRecordNode } from '@/object-record/cache/utils/getRecordFr
|
||||
import { RecordGqlFields } from '@/object-record/graphql/types/RecordGqlFields';
|
||||
import { generateDepthOneRecordGqlFields } from '@/object-record/graphql/utils/generateDepthOneRecordGqlFields';
|
||||
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
|
||||
import { capitalize } from 'twenty-shared';
|
||||
import { isEmptyObject } from '~/utils/isEmptyObject';
|
||||
import { isUndefinedOrNull } from '~/utils/isUndefinedOrNull';
|
||||
import { capitalize } from 'twenty-shared/utils';
|
||||
|
||||
export type GetRecordFromCacheArgs = {
|
||||
cache: ApolloCache<object>;
|
||||
|
||||
@ -3,8 +3,8 @@ import pick from 'lodash.pick';
|
||||
import { getRecordsFromRecordConnection } from '@/object-record/cache/utils/getRecordsFromRecordConnection';
|
||||
import { RecordGqlNode } from '@/object-record/graphql/types/RecordGqlNode';
|
||||
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
|
||||
import { isDefined } from 'twenty-shared';
|
||||
import { isUndefinedOrNull } from '~/utils/isUndefinedOrNull';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
export const getRecordFromRecordNode = <T extends ObjectRecord>({
|
||||
recordNode,
|
||||
|
||||
@ -7,12 +7,12 @@ import { getRecordConnectionFromRecords } from '@/object-record/cache/utils/getR
|
||||
import { getRefName } from '@/object-record/cache/utils/getRefName';
|
||||
import { RecordGqlNode } from '@/object-record/graphql/types/RecordGqlNode';
|
||||
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
|
||||
import { isDefined } from 'twenty-shared';
|
||||
import {
|
||||
FieldMetadataType,
|
||||
RelationDefinitionType,
|
||||
} from '~/generated-metadata/graphql';
|
||||
import { pascalCase } from '~/utils/string/pascalCase';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
export const getRecordNodeFromRecord = <T extends ObjectRecord>({
|
||||
objectMetadataItems,
|
||||
|
||||
@ -2,7 +2,7 @@ import { StoreValue } from '@apollo/client';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { RecordGqlRefConnection } from '@/object-record/cache/types/RecordGqlRefConnection';
|
||||
import { capitalize } from 'twenty-shared';
|
||||
import { capitalize } from 'twenty-shared/utils';
|
||||
|
||||
export const isObjectRecordConnectionWithRefs = (
|
||||
objectNameSingular: string,
|
||||
|
||||
@ -2,8 +2,8 @@ import { ApolloCache, Modifiers } from '@apollo/client/cache';
|
||||
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
|
||||
import { capitalize } from 'twenty-shared';
|
||||
import { isUndefinedOrNull } from '~/utils/isUndefinedOrNull';
|
||||
import { capitalize } from 'twenty-shared/utils';
|
||||
|
||||
export const modifyRecordFromCache = <
|
||||
CachedObjectRecord extends ObjectRecord = ObjectRecord,
|
||||
|
||||
@ -6,8 +6,8 @@ import { mapObjectMetadataToGraphQLQuery } from '@/object-metadata/utils/mapObje
|
||||
import { getRecordNodeFromRecord } from '@/object-record/cache/utils/getRecordNodeFromRecord';
|
||||
import { RecordGqlNode } from '@/object-record/graphql/types/RecordGqlNode';
|
||||
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
|
||||
import { capitalize } from 'twenty-shared';
|
||||
import { isUndefinedOrNull } from '~/utils/isUndefinedOrNull';
|
||||
import { capitalize } from 'twenty-shared/utils';
|
||||
|
||||
export const updateRecordFromCache = <T extends ObjectRecord>({
|
||||
objectMetadataItems,
|
||||
|
||||
Reference in New Issue
Block a user