The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Name the local dependency folder after a hash of the yarn.lock checksum (#28995)
Paul Rastoin5e71fee09fdf
diff --git a/packages/twenty-server/src/engine/core-modules/logic-function/logic-function-drivers/drivers/local/utils/__tests__/get-local-deps-layer-path.util.spec.ts b/packages/twenty-server/src/engine/core-modules/logic-function/logic-function-drivers/drivers/local/utils/__tests__/get-local-deps-layer-path.util.spec.tsindex 4d55cd38baf..37f903ce222 100644--- a/packages/twenty-server/src/engine/core-modules/logic-function/logic-function-drivers/drivers/local/utils/__tests__/get-local-deps-layer-path.util.spec.ts+++ b/packages/twenty-server/src/engine/core-modules/logic-function/logic-function-drivers/drivers/local/utils/__tests__/get-local-deps-layer-path.util.spec.ts@@ -1,19 +1,84 @@+import { dirname, join } from 'path';+import { type FlatApplication } from 'src/engine/core-modules/application/types/flat-application.type';import { LOGIC_FUNCTION_EXECUTOR_TMPDIR_FOLDER } from 'src/engine/core-modules/logic-function/logic-function-drivers/constants/logic-function-executor-tmpdir-folder';import { getLocalDepsLayerPath } from 'src/engine/core-modules/logic-function/logic-function-drivers/drivers/local/utils/get-local-deps-layer-path.util';+const DEPS_FOLDER_PATH = join(LOGIC_FUNCTION_EXECUTOR_TMPDIR_FOLDER, 'deps');++const buildFlatApplication = (+ overrides: Partial<FlatApplication>,+): FlatApplication =>+ ({+ universalIdentifier: '3f9c2d1e-6b4a-4c8e-9f1d-2a7b5c3e8d01',+ yarnLockChecksum: 'yarn-lock-checksum',+ packageJsonChecksum: 'package-json-checksum',+ ...overrides,+ }) as FlatApplication;+describe('getLocalDepsLayerPath', () => {- it('joins the tmpdir folder, the deps segment and the yarnLockChecksum', () => {- expect(- getLocalDepsLayerPath({ yarnLockChecksum: 'abc123' } as FlatApplication),- ).toBe(`${LOGIC_FUNCTION_EXECUTOR_TMPDIR_FOLDER}/deps/abc123`);+ it('stays a direct child of the deps folder whatever the checksum holds', () => {+ const depsLayerPath = getLocalDepsLayerPath(+ buildFlatApplication({ yarnLockChecksum: '../../../../etc' }),+ );++ expect(dirname(depsLayerPath)).toBe(DEPS_FOLDER_PATH);+ });++ it('shares one folder between applications with the same yarn.lock', () => {+ expect(getLocalDepsLayerPath(buildFlatApplication({}))).toBe(+ getLocalDepsLayerPath(+ buildFlatApplication({+ universalIdentifier: '8a1e4b7c-2d5f-4e9a-b3c6-7d0f1e2a4b59',+ }),+ ),+ );+ });++ it('changes when the yarn.lock changes', () => {+ expect(getLocalDepsLayerPath(buildFlatApplication({}))).not.toBe(+ getLocalDepsLayerPath(+ buildFlatApplication({ yarnLockChecksum: 'other-yarn-lock-checksum' }),+ ),+ );+ });++ it('ignores the package.json when there is a yarn.lock', () => {+ expect(getLocalDepsLayerPath(buildFlatApplication({}))).toBe(+ getLocalDepsLayerPath(+ buildFlatApplication({+ packageJsonChecksum: 'other-package-json-checksum',+ }),+ ),+ );+ });++ it('shares one folder between applications without a yarn.lock and with the same package.json', () => {+ const depsLayerPath = getLocalDepsLayerPath(+ buildFlatApplication({ yarnLockChecksum: null }),+ );++ expect(dirname(depsLayerPath)).toBe(DEPS_FOLDER_PATH);+ expect(depsLayerPath).toBe(+ getLocalDepsLayerPath(+ buildFlatApplication({+ universalIdentifier: '8a1e4b7c-2d5f-4e9a-b3c6-7d0f1e2a4b59',+ yarnLockChecksum: null,+ }),+ ),+ );});- it('falls back to default when yarnLockChecksum is undefined', () => {+ it('changes with the package.json when there is no yarn.lock', () => {expect(- getLocalDepsLayerPath({- yarnLockChecksum: undefined,- } as unknown as FlatApplication),- ).toBe(`${LOGIC_FUNCTION_EXECUTOR_TMPDIR_FOLDER}/deps/default`);+ getLocalDepsLayerPath(buildFlatApplication({ yarnLockChecksum: null })),+ ).not.toBe(+ getLocalDepsLayerPath(+ buildFlatApplication({+ yarnLockChecksum: null,+ packageJsonChecksum: 'other-package-json-checksum',+ }),+ ),+ );});});diff --git a/packages/twenty-server/src/engine/core-modules/logic-function/logic-function-drivers/drivers/local/utils/get-local-deps-layer-path.util.ts b/packages/twenty-server/src/engine/core-modules/logic-function/logic-function-drivers/drivers/local/utils/get-local-deps-layer-path.util.tsindex 145613c943d..ad6535e44d0 100644--- a/packages/twenty-server/src/engine/core-modules/logic-function/logic-function-drivers/drivers/local/utils/get-local-deps-layer-path.util.ts+++ b/packages/twenty-server/src/engine/core-modules/logic-function/logic-function-drivers/drivers/local/utils/get-local-deps-layer-path.util.ts@@ -2,11 +2,16 @@ import { join } from 'path';import { type FlatApplication } from 'src/engine/core-modules/application/types/flat-application.type';import { LOGIC_FUNCTION_EXECUTOR_TMPDIR_FOLDER } from 'src/engine/core-modules/logic-function/logic-function-drivers/constants/logic-function-executor-tmpdir-folder';+import { logicFunctionCreateHash } from 'src/engine/metadata-modules/logic-function/utils/logic-function-create-hash.utils';export const getLocalDepsLayerPath = (flatApplication: FlatApplication,): string => {- const checksum = flatApplication.yarnLockChecksum ?? 'default';+ const folderName = logicFunctionCreateHash(+ flatApplication.yarnLockChecksum ??+ flatApplication.packageJsonChecksum ??+ 'default',+ );- return join(LOGIC_FUNCTION_EXECUTOR_TMPDIR_FOLDER, 'deps', checksum);+ return join(LOGIC_FUNCTION_EXECUTOR_TMPDIR_FOLDER, 'deps', folderName);};