The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Skip empty built files on upload and report a rejected batch once (#25568)
Weikoc3955d525937
diff --git a/packages/twenty-apps/fixtures/invalid-app/yarn.lock b/packages/twenty-apps/fixtures/invalid-app/yarn.lockindex e69de29bb2d..671bba063ac 100644--- a/packages/twenty-apps/fixtures/invalid-app/yarn.lock+++ b/packages/twenty-apps/fixtures/invalid-app/yarn.lock@@ -0,0 +1,6 @@+# This file is generated by running "yarn install" inside your project.+# Manual changes might be lost - proceed with caution!++__metadata:+ version: 8+ cacheKey: 10c0diff --git a/packages/twenty-apps/fixtures/minimal-app/yarn.lock b/packages/twenty-apps/fixtures/minimal-app/yarn.lockindex e69de29bb2d..671bba063ac 100644--- a/packages/twenty-apps/fixtures/minimal-app/yarn.lock+++ b/packages/twenty-apps/fixtures/minimal-app/yarn.lock@@ -0,0 +1,6 @@+# This file is generated by running "yarn install" inside your project.+# Manual changes might be lost - proceed with caution!++__metadata:+ version: 8+ cacheKey: 10c0diff --git a/packages/twenty-apps/fixtures/rich-app/yarn.lock b/packages/twenty-apps/fixtures/rich-app/yarn.lockindex e69de29bb2d..671bba063ac 100644--- a/packages/twenty-apps/fixtures/rich-app/yarn.lock+++ b/packages/twenty-apps/fixtures/rich-app/yarn.lock@@ -0,0 +1,6 @@+# This file is generated by running "yarn install" inside your project.+# Manual changes might be lost - proceed with caution!++__metadata:+ version: 8+ cacheKey: 10c0diff --git a/packages/twenty-apps/fixtures/shared-dependencies-app/yarn.lock b/packages/twenty-apps/fixtures/shared-dependencies-app/yarn.lockindex e69de29bb2d..671bba063ac 100644--- a/packages/twenty-apps/fixtures/shared-dependencies-app/yarn.lock+++ b/packages/twenty-apps/fixtures/shared-dependencies-app/yarn.lock@@ -0,0 +1,6 @@+# This file is generated by running "yarn install" inside your project.+# Manual changes might be lost - proceed with caution!++__metadata:+ version: 8+ cacheKey: 10c0diff --git a/packages/twenty-docs/developers/extend/apps/getting-started/troubleshooting.mdx b/packages/twenty-docs/developers/extend/apps/getting-started/troubleshooting.mdxindex 796a1401290..45929798447 100644--- a/packages/twenty-docs/developers/extend/apps/getting-started/troubleshooting.mdx+++ b/packages/twenty-docs/developers/extend/apps/getting-started/troubleshooting.mdx@@ -8,6 +8,7 @@ icon: "wrench"- **Wrong Node version** — Need 24.5+ (`engines.node: ^24.5.0`). Check with `node -v`.- **Yarn 4 missing** — Run `corepack enable`.- **Dependencies broken** — `rm -rf node_modules && yarn install`.+- **Empty `yarn.lock`** — The build fails with "yarn.lock is empty" when the lockfile exists but has no content; run `yarn install` to regenerate it.- **`twenty-sdk` errors after upgrading to v2.8.0** — It moved from `dependencies` to `devDependencies` in v2.8.0. See [Project Structure → Dependencies](/developers/extend/apps/getting-started/project-structure#dependencies).- **`twenty dev:build` warns about `twenty-client-sdk` under `dependencies`** — It is provided at runtime by Twenty, so it should be moved to `devDependencies` alongside `twenty-sdk`. See [Project Structure → Dependencies](/developers/extend/apps/getting-started/project-structure#dependencies).diff --git a/packages/twenty-sdk/src/cli/__tests__/apps/rich-app/__integration__/app-dev/expected-manifest.ts b/packages/twenty-sdk/src/cli/__tests__/apps/rich-app/__integration__/app-dev/expected-manifest.tsindex f70c3997920..5179ec3489f 100644--- a/packages/twenty-sdk/src/cli/__tests__/apps/rich-app/__integration__/app-dev/expected-manifest.ts+++ b/packages/twenty-sdk/src/cli/__tests__/apps/rich-app/__integration__/app-dev/expected-manifest.ts@@ -256,7 +256,7 @@ export const EXPECTED_MANIFEST: Manifest = {galleryImages: [],defaultRoleUniversalIdentifier: 'b648f87b-1d26-4961-b974-0908fd991061',universalIdentifier: '4ec0391d-18d5-411c-b2f3-266ddc1c3ef7',- yarnLockChecksum: 'd41d8cd98f00b204e9800998ecf8427e',+ yarnLockChecksum: '375f53c8fcdc373d081ba4523f7bb3b4',packageJsonChecksum: '2851d0e2c3621a57e1fd103a245b6fde',requiredServerVersionRange: null,},diff --git a/packages/twenty-sdk/src/cli/operations/dev-once.ts b/packages/twenty-sdk/src/cli/operations/dev-once.tsindex 55541c4890b..ba605f52110 100644--- a/packages/twenty-sdk/src/cli/operations/dev-once.ts+++ b/packages/twenty-sdk/src/cli/operations/dev-once.ts@@ -28,6 +28,7 @@ import { getSyncErrorRecoveryHint } from '@/cli/utilities/error/get-sync-error-rimport { getGraphQLErrorMessage } from '@/cli/utilities/error/parse-server-error';import { serializeError } from '@/cli/utilities/error/serialize-error';import { FileUploader } from '@/cli/utilities/file/file-uploader';+import { formatUploadFailures } from '@/cli/utilities/file/format-upload-failures';import { runSafe } from '@/cli/utilities/run-safe';import {APP_ERROR_CODES,@@ -338,12 +339,7 @@ const innerAppDevOnce = async (success: false,error: {code: APP_ERROR_CODES.SYNC_FAILED,- message: uploadFailures- .map(- (failure) =>- `Failed to upload ${failure.builtPath}: ${failure.error}`,- )- .join('\n'),+ message: formatUploadFailures(uploadFailures).join('\n'),},};}diff --git a/packages/twenty-sdk/src/cli/utilities/build/manifest/build-and-validate-manifest.ts b/packages/twenty-sdk/src/cli/utilities/build/manifest/build-and-validate-manifest.tsindex eb7dfca3ed8..71ab125b60f 100644--- a/packages/twenty-sdk/src/cli/utilities/build/manifest/build-and-validate-manifest.ts+++ b/packages/twenty-sdk/src/cli/utilities/build/manifest/build-and-validate-manifest.ts@@ -2,6 +2,7 @@ import { type EntityFilePaths } from '@/cli/utilities/build/manifest/manifest-eximport { buildManifest } from '@/cli/utilities/build/manifest/manifest-build';import { manifestValidate } from '@/cli/utilities/build/manifest/manifest-validate';import { validatePackageJsonDependencies } from '@/cli/utilities/build/manifest/utils/validate-package-json-dependencies';+import { validateYarnLock } from '@/cli/utilities/build/manifest/utils/validate-yarn-lock';import { type Manifest } from 'twenty-shared/application';export type BuildAndValidateManifestSuccess = {@@ -44,6 +45,15 @@ export const buildAndValidateManifest = async (};}+ const yarnLockErrors = await validateYarnLock(appPath);++ if (yarnLockErrors.length > 0) {+ return {+ success: false,+ errors: yarnLockErrors,+ };+ }+const packageJsonWarnings = await validatePackageJsonDependencies(appPath);return {diff --git a/packages/twenty-sdk/src/cli/utilities/build/manifest/utils/__tests__/validate-yarn-lock.spec.ts b/packages/twenty-sdk/src/cli/utilities/build/manifest/utils/__tests__/validate-yarn-lock.spec.tsnew file mode 100644index 00000000000..d8370e687f1--- /dev/null+++ b/packages/twenty-sdk/src/cli/utilities/build/manifest/utils/__tests__/validate-yarn-lock.spec.ts@@ -0,0 +1,50 @@+import {+ validateYarnLock,+ validateYarnLockFile,+} from '@/cli/utilities/build/manifest/utils/validate-yarn-lock';+import { mkdtemp, rm, writeFile } from 'node:fs/promises';+import { tmpdir } from 'node:os';+import { join } from 'node:path';+import { afterEach, beforeEach, describe, expect, it } from 'vitest';++describe('validateYarnLock', () => {+ let appPath: string;++ beforeEach(async () => {+ appPath = await mkdtemp(join(tmpdir(), 'validate-yarn-lock-'));+ });++ afterEach(async () => {+ await rm(appPath, { recursive: true, force: true });+ });++ it('should accept a project without a lockfile', async () => {+ expect(await validateYarnLock(appPath)).toEqual([]);+ });++ it('should accept a lockfile with content', async () => {+ await writeFile(join(appPath, 'yarn.lock'), '__metadata:\n version: 8\n');++ expect(await validateYarnLock(appPath)).toEqual([]);+ });++ it('should check the file it is given rather than the project lockfile', async () => {+ await writeFile(join(appPath, 'yarn.lock'), '__metadata:\n version: 8\n');+ await writeFile(join(appPath, 'copy.lock'), '');++ expect(await validateYarnLock(appPath)).toEqual([]);+ expect(await validateYarnLockFile(join(appPath, 'copy.lock'))).toHaveLength(+ 1,+ );+ });++ it('should refuse an empty lockfile and say how to regenerate it', async () => {+ await writeFile(join(appPath, 'yarn.lock'), '');++ const errors = await validateYarnLock(appPath);++ expect(errors).toHaveLength(1);+ expect(errors[0]).toMatch(/^yarn\.lock is empty\./);+ expect(errors[0]).toContain('yarn install');+ });+});diff --git a/packages/twenty-sdk/src/cli/utilities/build/manifest/utils/validate-yarn-lock.ts b/packages/twenty-sdk/src/cli/utilities/build/manifest/utils/validate-yarn-lock.tsnew file mode 100644index 00000000000..60bdcee864b--- /dev/null+++ b/packages/twenty-sdk/src/cli/utilities/build/manifest/utils/validate-yarn-lock.ts@@ -0,0 +1,20 @@+import { pathExists } from '@/cli/utilities/file/fs-utils';+import { stat } from 'node:fs/promises';+import path from 'path';++export const validateYarnLockFile = async (+ yarnLockPath: string,+): Promise<string[]> => {+ if (!(await pathExists(yarnLockPath))) {+ return [];+ }++ return (await stat(yarnLockPath)).size === 0+ ? [+ 'yarn.lock is empty. Run "yarn install" to regenerate it before building.',+ ]+ : [];+};++export const validateYarnLock = (appPath: string): Promise<string[]> =>+ validateYarnLockFile(path.join(appPath, 'yarn.lock'));diff --git a/packages/twenty-sdk/src/cli/utilities/dev/orchestrator/steps/start-watchers-orchestrator-step.ts b/packages/twenty-sdk/src/cli/utilities/dev/orchestrator/steps/start-watchers-orchestrator-step.tsindex 2180fdd8371..6ee5bf357f7 100644--- a/packages/twenty-sdk/src/cli/utilities/dev/orchestrator/steps/start-watchers-orchestrator-step.ts+++ b/packages/twenty-sdk/src/cli/utilities/dev/orchestrator/steps/start-watchers-orchestrator-step.ts@@ -3,6 +3,7 @@ import {type EsbuildWatcher,} from '@/cli/utilities/build/common/esbuild-watcher';import { FileUploadWatcher } from '@/cli/utilities/build/common/file-upload-watcher';+import { validateYarnLockFile } from '@/cli/utilities/build/manifest/utils/validate-yarn-lock';import { FrontComponentsWatcher } from '@/cli/utilities/build/common/front-component-build/front-components-watcher';import { TscWatcher } from '@/cli/utilities/build/common/tsc-watcher';import { type TypecheckError } from '@/cli/utilities/build/common/typecheck-plugin';@@ -16,6 +17,7 @@ import {type FrontComponentSharedDependenciesManifest,} from 'twenty-shared/application';import { FileFolder } from 'twenty-shared/types';+import { join } from 'node:path';export type FileBuiltEvent = {fileFolder: FileFolder;@@ -239,12 +241,29 @@ export class StartWatchersOrchestratorStep {appPath: this.state.appPath,fileFolder: FileFolder.Dependencies,watchPaths: ['package.json', 'yarn.lock'],- handleFileBuilt: this.handleFileBuilt.bind(this),+ handleFileBuilt: (event) => {+ void this.handleDependencyFileBuilt(event);+ },});this.dependencyWatcher.start();}+ private async handleDependencyFileBuilt(+ event: FileBuiltEvent,+ ): Promise<void> {+ const isEmptyLockfileCopy =+ event.sourcePath === 'yarn.lock' &&+ (await validateYarnLockFile(join(this.state.appPath, event.builtPath)))+ .length > 0;++ if (isEmptyLockfileCopy) {+ return;+ }++ this.handleFileBuilt(event);+ }+private async startTscWatcher(): Promise<void> {this.tscWatcher = new TscWatcher({appPath: this.state.appPath,diff --git a/packages/twenty-sdk/src/cli/utilities/dev/orchestrator/steps/upload-files-orchestrator-step.ts b/packages/twenty-sdk/src/cli/utilities/dev/orchestrator/steps/upload-files-orchestrator-step.tsindex 721be8f6f54..bc4f52c9351 100644--- a/packages/twenty-sdk/src/cli/utilities/dev/orchestrator/steps/upload-files-orchestrator-step.ts+++ b/packages/twenty-sdk/src/cli/utilities/dev/orchestrator/steps/upload-files-orchestrator-step.ts@@ -3,6 +3,7 @@ import {type OrchestratorStateBuiltFileInfo,} from '@/cli/utilities/dev/orchestrator/dev-mode-orchestrator-state';import { FileUploader } from '@/cli/utilities/file/file-uploader';+import { formatUploadFailures } from '@/cli/utilities/file/format-upload-failures';import { type FileFolder } from 'twenty-shared/types';import { isDefined } from 'twenty-shared/utils';@@ -147,12 +148,10 @@ export class UploadFilesOrchestratorStep {files.map(({ builtPath, fileFolder }) => ({ builtPath, fileFolder })),).then((failures) => {- for (const failure of failures) {- this.failedCount++;- this.state.addEvent({- message: `Failed to upload ${failure.builtPath}: ${failure.error}`,- status: 'error',- });+ this.failedCount += failures.length;++ for (const message of formatUploadFailures(failures)) {+ this.state.addEvent({ message, status: 'error' });}for (const { builtPath, sourcePath } of files) {diff --git a/packages/twenty-sdk/src/cli/utilities/file/__tests__/format-upload-failures.spec.ts b/packages/twenty-sdk/src/cli/utilities/file/__tests__/format-upload-failures.spec.tsnew file mode 100644index 00000000000..603b95f9c4d--- /dev/null+++ b/packages/twenty-sdk/src/cli/utilities/file/__tests__/format-upload-failures.spec.ts@@ -0,0 +1,55 @@+import { formatUploadFailures } from '@/cli/utilities/file/format-upload-failures';+import { describe, expect, it } from 'vitest';++describe('formatUploadFailures', () => {+ it('should keep the one-line form for a failure with its own message', () => {+ expect(+ formatUploadFailures([+ { builtPath: '.twenty/output/src/a.mjs', error: 'too large' },+ ]),+ ).toEqual(['Failed to upload .twenty/output/src/a.mjs: too large']);+ });++ it('should collapse failures sharing a message into a count followed by their paths', () => {+ expect(+ formatUploadFailures([+ {+ builtPath: '.twenty/output/src/a.mjs',+ error: 'size must not be less than 1',+ },+ {+ builtPath: '.twenty/output/src/b.mjs',+ error: 'size must not be less than 1',+ },+ {+ builtPath: '.twenty/output/yarn.lock',+ error: 'size must not be less than 1',+ },+ ]),+ ).toEqual([+ 'Failed to upload 3 files: size must not be less than 1',+ ' .twenty/output/src/a.mjs',+ ' .twenty/output/src/b.mjs',+ ' .twenty/output/yarn.lock',+ ]);+ });++ it('should keep failures with distinct messages apart', () => {+ expect(+ formatUploadFailures([+ { builtPath: '.twenty/output/src/a.mjs', error: 'too large' },+ { builtPath: '.twenty/output/src/b.mjs', error: 'expired' },+ { builtPath: '.twenty/output/src/c.mjs', error: 'too large' },+ ]),+ ).toEqual([+ 'Failed to upload 2 files: too large',+ ' .twenty/output/src/a.mjs',+ ' .twenty/output/src/c.mjs',+ 'Failed to upload .twenty/output/src/b.mjs: expired',+ ]);+ });++ it('should return nothing for no failures', () => {+ expect(formatUploadFailures([])).toEqual([]);+ });+});diff --git a/packages/twenty-sdk/src/cli/utilities/file/format-upload-failures.ts b/packages/twenty-sdk/src/cli/utilities/file/format-upload-failures.tsnew file mode 100644index 00000000000..5b859158699--- /dev/null+++ b/packages/twenty-sdk/src/cli/utilities/file/format-upload-failures.ts@@ -0,0 +1,23 @@+import { type FileUploadFailure } from '@/cli/utilities/file/file-uploader';++export const formatUploadFailures = (+ failures: FileUploadFailure[],+): string[] => {+ const builtPathsByError = new Map<string, string[]>();++ for (const { builtPath, error } of failures) {+ builtPathsByError.set(error, [+ ...(builtPathsByError.get(error) ?? []),+ builtPath,+ ]);+ }++ return [...builtPathsByError.entries()].flatMap(([error, builtPaths]) =>+ builtPaths.length === 1+ ? [`Failed to upload ${builtPaths[0]}: ${error}`]+ : [+ `Failed to upload ${builtPaths.length} files: ${error}`,+ ...builtPaths.map((builtPath) => ` ${builtPath}`),+ ],+ );+};