From e3f7cec82f2f738f43028597f105fe10b0294ce7 Mon Sep 17 00:00:00 2001 From: Charles Bochet Date: Mon, 20 Jan 2025 23:10:39 +0100 Subject: [PATCH] Fix import twenty-shared (#9754) In this PR: - removing rootDir / baseUrl from any tsconfig.json - we need to keep it in tsconfig.spec.json and also specify rootDir in jest.config.ts moduleMapper because of the way nx jest executor works (automatically moving back to root) - we need to explictly specify the depencies to twenty-shared / twenty-emails (built packages) in packages package.json to help nx understand dependencies --- packages/twenty-chrome-extension/tsconfig.json | 4 ++-- packages/twenty-front/jest.config.ts | 4 +++- packages/twenty-front/package.json | 3 ++- .../hooks/useWorkflowRunRecordActions.tsx | 1 - .../workflow-steps/components/WorkflowStepHeader.tsx | 2 +- packages/twenty-front/tsconfig.json | 8 ++++---- packages/twenty-front/tsconfig.spec.json | 9 +++++---- packages/twenty-server/package.json | 2 ++ packages/twenty-server/tsconfig.json | 6 +++--- packages/twenty-ui/jest.config.ts | 4 +++- packages/twenty-ui/package.json | 3 +++ packages/twenty-ui/src/theme/provider/ThemeProvider.tsx | 2 +- packages/twenty-ui/tsconfig.json | 2 +- packages/twenty-ui/tsconfig.spec.json | 6 +++++- tsconfig.base.json | 8 +------- yarn.lock | 9 +++++++-- 16 files changed, 43 insertions(+), 30 deletions(-) diff --git a/packages/twenty-chrome-extension/tsconfig.json b/packages/twenty-chrome-extension/tsconfig.json index 840e10a78..d9bd2f66b 100644 --- a/packages/twenty-chrome-extension/tsconfig.json +++ b/packages/twenty-chrome-extension/tsconfig.json @@ -9,8 +9,8 @@ "skipLibCheck": true, "esModuleInterop": true, "paths": { - "@/*": ["packages/twenty-chrome-extension/src/options/modules/*"], - "~/*": ["packages/twenty-chrome-extension/src/*"] + "@/*": ["./src/options/modules/*"], + "~/*": ["./src/*"] }, /* Bundler mode */ diff --git a/packages/twenty-front/jest.config.ts b/packages/twenty-front/jest.config.ts index 7ff96a178..7c3777ae4 100644 --- a/packages/twenty-front/jest.config.ts +++ b/packages/twenty-front/jest.config.ts @@ -27,7 +27,9 @@ const jestConfig: JestConfigWithTsJest = { '\\.(jpg|jpeg|png|gif|webp|svg|svg\\?react)$': '/__mocks__/imageMock.js', '\\.css$': '/__mocks__/styleMock.js', - ...pathsToModuleNameMapper(tsConfig.compilerOptions.paths), + ...pathsToModuleNameMapper(tsConfig.compilerOptions.paths, { + prefix: '/../../', + }), }, moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], extensionsToTreatAsEsm: ['.ts', '.tsx'], diff --git a/packages/twenty-front/package.json b/packages/twenty-front/package.json index 1ee424dfe..0815aa19c 100644 --- a/packages/twenty-front/package.json +++ b/packages/twenty-front/package.json @@ -49,7 +49,8 @@ "docx": "^9.1.0", "file-saver": "^2.0.5", "recoil-sync": "^0.2.0", - "transliteration": "^2.3.5" + "transliteration": "^2.3.5", + "twenty-shared": "workspace:*" }, "devDependencies": { "@types/file-saver": "^2" diff --git a/packages/twenty-front/src/modules/action-menu/actions/record-actions/workflow-run-record-actions/hooks/useWorkflowRunRecordActions.tsx b/packages/twenty-front/src/modules/action-menu/actions/record-actions/workflow-run-record-actions/hooks/useWorkflowRunRecordActions.tsx index c46f2d291..a341ea839 100644 --- a/packages/twenty-front/src/modules/action-menu/actions/record-actions/workflow-run-record-actions/hooks/useWorkflowRunRecordActions.tsx +++ b/packages/twenty-front/src/modules/action-menu/actions/record-actions/workflow-run-record-actions/hooks/useWorkflowRunRecordActions.tsx @@ -13,7 +13,6 @@ import { useRunWorkflowVersion } from '@/workflow/hooks/useRunWorkflowVersion'; import { useRecoilValue } from 'recoil'; import { capitalize } from 'twenty-shared'; import { IconSettingsAutomation, isDefined } from 'twenty-ui'; - export const useWorkflowRunRecordActions = ({ objectMetadataItem, }: { diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/components/WorkflowStepHeader.tsx b/packages/twenty-front/src/modules/workflow/workflow-steps/components/WorkflowStepHeader.tsx index 6bd8f30fd..d0db052fd 100644 --- a/packages/twenty-front/src/modules/workflow/workflow-steps/components/WorkflowStepHeader.tsx +++ b/packages/twenty-front/src/modules/workflow/workflow-steps/components/WorkflowStepHeader.tsx @@ -1,8 +1,8 @@ import { TextInput } from '@/ui/field/input/components/TextInput'; import { useTheme } from '@emotion/react'; import styled from '@emotion/styled'; -import { IconComponent } from 'packages/twenty-ui'; import { useState } from 'react'; +import { IconComponent } from 'twenty-ui'; import { useDebouncedCallback } from 'use-debounce'; const StyledHeader = styled.div` diff --git a/packages/twenty-front/tsconfig.json b/packages/twenty-front/tsconfig.json index 48b5bf381..4d00fbc3e 100644 --- a/packages/twenty-front/tsconfig.json +++ b/packages/twenty-front/tsconfig.json @@ -21,10 +21,10 @@ "forceConsistentCasingInFileNames": true, "outDir": "../../.cache/tsc", "paths": { - "@/*": ["packages/twenty-front/src/modules/*"], - "~/*": ["packages/twenty-front/src/*"], - "twenty-ui": ["packages/twenty-ui/src/index.ts"], - "@ui/*": ["packages/twenty-ui/src/*"] + "@/*": ["./src/modules/*"], + "~/*": ["./src/*"], + "twenty-ui": ["../twenty-ui/src/index.ts"], + "@ui/*": ["../twenty-ui/src/*"] } }, "files": [], diff --git a/packages/twenty-front/tsconfig.spec.json b/packages/twenty-front/tsconfig.spec.json index 445de2e32..026604daa 100644 --- a/packages/twenty-front/tsconfig.spec.json +++ b/packages/twenty-front/tsconfig.spec.json @@ -2,11 +2,12 @@ "extends": "./tsconfig.json", "compilerOptions": { "types": ["jest", "node"], + "baseUrl": "../..", "paths": { - "@/*": ["packages/twenty-front/src/modules/*"], - "~/*": ["packages/twenty-front/src/*"], - "twenty-ui": ["packages/twenty-ui/src/index.ts"], - "@ui/*": ["packages/twenty-ui/src/*"] + "@/*": ["./packages/twenty-front/src/modules/*"], + "~/*": ["./packages/twenty-front/src/*"], + "twenty-ui": ["./packages/twenty-ui/src/index.ts"], + "@ui/*": ["./packages/twenty-ui/src/*"] } }, "include": [ diff --git a/packages/twenty-server/package.json b/packages/twenty-server/package.json index b13e67651..4e5a0087a 100644 --- a/packages/twenty-server/package.json +++ b/packages/twenty-server/package.json @@ -74,6 +74,8 @@ "@types/react": "^18.2.39", "@types/unzipper": "^0", "rimraf": "^5.0.5", + "twenty-emails": "workspace:*", + "twenty-shared": "workspace:*", "typescript": "5.3.3" }, "engines": { diff --git a/packages/twenty-server/tsconfig.json b/packages/twenty-server/tsconfig.json index 272cbdde6..542780732 100644 --- a/packages/twenty-server/tsconfig.json +++ b/packages/twenty-server/tsconfig.json @@ -25,9 +25,9 @@ "resolveJsonModule": true, "types": ["jest", "node"], "paths": { - "src/*": ["packages/twenty-server/src/*"], - "test/*": ["packages/twenty-server/test/*"], - "twenty-emails": ["packages/twenty-emails/dist"] + "src/*": ["./src/*"], + "test/*": ["./test/*"], + "twenty-emails": ["../twenty-emails/dist"] } }, "ts-node": { diff --git a/packages/twenty-ui/jest.config.ts b/packages/twenty-ui/jest.config.ts index 9d295020e..e3b09b8ae 100644 --- a/packages/twenty-ui/jest.config.ts +++ b/packages/twenty-ui/jest.config.ts @@ -23,7 +23,9 @@ const jestConfig: JestConfigWithTsJest = { moduleNameMapper: { '\\.(jpg|jpeg|png|gif|webp|svg|svg\\?react)$': '/__mocks__/imageMock.js', - ...pathsToModuleNameMapper(tsConfig.compilerOptions.paths), + ...pathsToModuleNameMapper(tsConfig.compilerOptions.paths, { + prefix: '/', + }), }, moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], extensionsToTreatAsEsm: ['.ts', '.tsx'], diff --git a/packages/twenty-ui/package.json b/packages/twenty-ui/package.json index 8db94d4d9..7d30345aa 100644 --- a/packages/twenty-ui/package.json +++ b/packages/twenty-ui/package.json @@ -10,6 +10,9 @@ "require": "./dist/index.cjs" } }, + "dependencies": { + "twenty-shared": "workspace:*" + }, "scripts": { "build": "npx vite build" } diff --git a/packages/twenty-ui/src/theme/provider/ThemeProvider.tsx b/packages/twenty-ui/src/theme/provider/ThemeProvider.tsx index 3b513f34e..e8cdc3b7e 100644 --- a/packages/twenty-ui/src/theme/provider/ThemeProvider.tsx +++ b/packages/twenty-ui/src/theme/provider/ThemeProvider.tsx @@ -1,5 +1,5 @@ -import { ReactNode } from 'react'; import { ThemeProvider as EmotionThemeProvider } from '@emotion/react'; +import { ReactNode } from 'react'; import { ThemeContextProvider } from '@ui/theme/provider/ThemeContextProvider'; diff --git a/packages/twenty-ui/tsconfig.json b/packages/twenty-ui/tsconfig.json index 31fca817a..52b04f0ce 100644 --- a/packages/twenty-ui/tsconfig.json +++ b/packages/twenty-ui/tsconfig.json @@ -10,7 +10,7 @@ "types": ["node"], "outDir": "../../.cache/tsc", "paths": { - "@ui/*": ["packages/twenty-ui/src/*"] + "@ui/*": ["./src/*"] } }, "files": [], diff --git a/packages/twenty-ui/tsconfig.spec.json b/packages/twenty-ui/tsconfig.spec.json index 4175fe1fb..12bcba742 100644 --- a/packages/twenty-ui/tsconfig.spec.json +++ b/packages/twenty-ui/tsconfig.spec.json @@ -2,7 +2,11 @@ "extends": "./tsconfig.json", "compilerOptions": { "module": "commonjs", - "types": ["jest", "node"] + "types": ["jest", "node"], + "baseUrl": "../..", + "paths": { + "@ui/*": ["./packages/twenty-ui/src/*"] + } }, "include": [ "vite.config.ts", diff --git a/tsconfig.base.json b/tsconfig.base.json index 070d6c360..1214a784e 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -13,13 +13,7 @@ "lib": ["es2020", "dom"], "skipLibCheck": true, "skipDefaultLibCheck": true, - "resolveJsonModule": true, - "baseUrl": ".", - "paths": { - "twenty-emails": ["packages/twenty-emails/src/index.ts"], - "twenty-ui": ["packages/twenty-ui/src/index.ts"], - "twenty-shared": ["packages/twenty-shared/dist"] - } + "resolveJsonModule": true }, "exclude": ["node_modules", "tmp"] } diff --git a/yarn.lock b/yarn.lock index bff715694..db22733ff 100644 --- a/yarn.lock +++ b/yarn.lock @@ -45581,7 +45581,7 @@ __metadata: languageName: unknown linkType: soft -"twenty-emails@workspace:packages/twenty-emails": +"twenty-emails@workspace:*, twenty-emails@workspace:packages/twenty-emails": version: 0.0.0-use.local resolution: "twenty-emails@workspace:packages/twenty-emails" languageName: unknown @@ -45612,6 +45612,7 @@ __metadata: file-saver: "npm:^2.0.5" recoil-sync: "npm:^0.2.0" transliteration: "npm:^2.3.5" + twenty-shared: "workspace:*" languageName: unknown linkType: soft @@ -45673,6 +45674,8 @@ __metadata: rimraf: "npm:^5.0.5" ts-morph: "npm:^24.0.0" tsconfig-paths: "npm:^4.2.0" + twenty-emails: "workspace:*" + twenty-shared: "workspace:*" typeorm: "patch:typeorm@0.3.20#./patches/typeorm+0.3.20.patch" typescript: "npm:5.3.3" unzipper: "npm:^0.12.3" @@ -45680,7 +45683,7 @@ __metadata: languageName: unknown linkType: soft -"twenty-shared@workspace:packages/twenty-shared": +"twenty-shared@workspace:*, twenty-shared@workspace:packages/twenty-shared": version: 0.0.0-use.local resolution: "twenty-shared@workspace:packages/twenty-shared" languageName: unknown @@ -45689,6 +45692,8 @@ __metadata: "twenty-ui@workspace:packages/twenty-ui": version: 0.0.0-use.local resolution: "twenty-ui@workspace:packages/twenty-ui" + dependencies: + twenty-shared: "workspace:*" languageName: unknown linkType: soft