Skip to content

The open alternative to Salesforce, designed for AI.

Ship the yarn.lock in published app packages and store it at install (#28998)

Paul Rastoin111d7d15b5d9
diff --git a/packages/twenty-apps/fixtures/function-execute-app/yarn.lock b/packages/twenty-apps/fixtures/function-execute-app/yarn.lock
new file mode 100644
index 00000000000..4a5801883d1
--- /dev/null
+++ b/packages/twenty-apps/fixtures/function-execute-app/yarn.lock
@@ -0,0 +1,2 @@
+# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
+# yarn lockfile v1
diff --git a/packages/twenty-cli/docs/commands.md b/packages/twenty-cli/docs/commands.md
index a39ce81ca51..a0ffd83552a 100644
--- a/packages/twenty-cli/docs/commands.md
+++ b/packages/twenty-cli/docs/commands.md
@@ -603,7 +603,7 @@ Builds and typechecks the app, packs that exact build, then publishes the packag
Install npm and authenticate with the intended registry first. npm runs from the app directory, so its project/user configuration and environment credentials apply. `--tag` sets the npm dist-tag. GitHub Actions jobs with OIDC request provenance automatically; set `TWENTY_APP_PUBLISH_DISABLE_PROVENANCE=true` to opt out, for example when publishing from a private source repository.
-Packing and publishing skip npm lifecycle scripts because the CLI already built the app. npm's package-file selection still applies. If `package.json` has a `files` field, it must include `manifest.json` and the generated app files; the command rejects an incomplete package before publication. npm excludes the root `yarn.lock` from packages. Temporary packages and build snapshots are removed after completion or failure.
+Packing and publishing skip npm lifecycle scripts because the CLI already built the app. npm's package-file selection still applies. If `package.json` has a `files` field, it must include `manifest.json` and the generated app files; the command rejects an incomplete package before publication. npm excludes the root `yarn.lock` from packages, so the CLI also packs it as `dependencies/yarn.lock`, where Twenty reads it at install. Temporary packages and build snapshots are removed after completion or failure.
Human mode displays npm output and supports interactive authentication when a terminal is available. JSON mode returns one CLI envelope and does not prompt; configure an automation token or npm’s `npm_config_otp` environment option before running it. Failed npm commands return `PUBLISH_FAILED` with the subprocess exit code and captured output. If publication is interrupted after sending the package, check the registry before retrying, since the version may already have been published.
diff --git a/packages/twenty-cli/scripts/test-app-lifecycle.mjs b/packages/twenty-cli/scripts/test-app-lifecycle.mjs
index d05db15a738..1908b21bdc6 100644
--- a/packages/twenty-cli/scripts/test-app-lifecycle.mjs
+++ b/packages/twenty-cli/scripts/test-app-lifecycle.mjs
@@ -89,7 +89,10 @@ await test(
});
const prepareDependencies = async (appPath) => {
// These fixtures use dependencies from the checkout.
- await rm(join(appPath, 'yarn.lock'), { force: true });
+ await writeFile(
+ join(appPath, 'yarn.lock'),
+ '__metadata:\n version: 8\n',
+ );
const modules = join(appPath, 'node_modules');
await mkdir(modules);
for (const name of [
diff --git a/packages/twenty-cli/src/app/bundles/build-application.ts b/packages/twenty-cli/src/app/bundles/build-application.ts
index d3850f3107e..b2ac2494376 100644
--- a/packages/twenty-cli/src/app/bundles/build-application.ts
+++ b/packages/twenty-cli/src/app/bundles/build-application.ts
@@ -25,12 +25,7 @@ import { buildSharedDependenciesBundle } from '@/app/bundles/front-component-bui
import { type SharedDependenciesBuildContext } from '@/app/bundles/front-component-build/shared-dependencies-build/types/shared-dependencies-build-context.type';
import { type EntityFilePaths } from '@/app/manifest/types/entity-file-paths.type';
import { loadFrontComponentTranslationCatalogs } from '@/app/translations/load-front-component-translation-catalogs';
-import {
- emptyDir,
- ensureDir,
- pathExists,
- pathExistsSync,
-} from '@/app/fs-utils';
+import { emptyDir, ensureDir, pathExists } from '@/app/fs-utils';
import { FRONT_COMPONENT_TRANSLATIONS_KEY } from '@/app/bundles/constants/front-component-translations-key';
export type AppBuildOptions = {
@@ -171,9 +166,7 @@ export const buildApplication = async (
await copyStaticFiles({
appPath: options.appPath,
fileFolder: FileFolder.Dependencies,
- filePaths: ['package.json', 'yarn.lock'].filter((filePath) =>
- pathExistsSync(join(options.appPath, filePath)),
- ),
+ filePaths: ['package.json', 'yarn.lock'],
collectFileBuilt,
outputDir: relativeOutputDir,
dereferenceSymlinks: options.dereferenceSymlinks,
diff --git a/packages/twenty-cli/src/app/manifest/__tests__/manifest-fixtures.spec.ts b/packages/twenty-cli/src/app/manifest/__tests__/manifest-fixtures.spec.ts
index 02912074e99..b1ed7c6464d 100644
--- a/packages/twenty-cli/src/app/manifest/__tests__/manifest-fixtures.spec.ts
+++ b/packages/twenty-cli/src/app/manifest/__tests__/manifest-fixtures.spec.ts
@@ -14,6 +14,7 @@ import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { stop } from 'esbuild';
+import { EMPTY_YARN_LOCK_CONTENT } from 'twenty-shared/application';
import {
afterAll,
afterEach,
@@ -252,7 +253,7 @@ describe('CLI manifest fixtures and worker transport', () => {
signal: new AbortController().signal,
});
await symlink(join(root, 'node_modules'), join(appPath, 'node_modules'));
- await rm(join(appPath, 'yarn.lock'));
+ await writeFile(join(appPath, 'yarn.lock'), EMPTY_YARN_LOCK_CONTENT);
const result = await compareManifest(appPath);
const packageJson = JSON.parse(
await readFile(join(appPath, 'package.json'), 'utf8'),
diff --git a/packages/twenty-cli/src/app/manifest/utils/__tests__/validate-yarn-lock.spec.ts b/packages/twenty-cli/src/app/manifest/utils/__tests__/validate-yarn-lock.spec.ts
index 7ed46c8373c..a3098483305 100644
--- a/packages/twenty-cli/src/app/manifest/utils/__tests__/validate-yarn-lock.spec.ts
+++ b/packages/twenty-cli/src/app/manifest/utils/__tests__/validate-yarn-lock.spec.ts
@@ -5,6 +5,7 @@ import {
import { mkdtemp, rm, writeFile } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
+import { EMPTY_YARN_LOCK_CONTENT } from 'twenty-shared/application';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
describe('validateYarnLock', () => {
@@ -18,18 +19,22 @@ describe('validateYarnLock', () => {
await rm(appPath, { recursive: true, force: true });
});
- it('should accept a project without a lockfile', async () => {
- expect(await validateYarnLock(appPath)).toEqual([]);
+ it('should refuse a project without a lockfile and say how to generate it', async () => {
+ const errors = await validateYarnLock(appPath);
+
+ expect(errors).toHaveLength(1);
+ expect(errors[0]).toMatch(/^yarn\.lock not found\./);
+ expect(errors[0]).toContain('yarn install');
});
it('should accept a lockfile with content', async () => {
- await writeFile(join(appPath, 'yarn.lock'), '__metadata:\n version: 8\n');
+ await writeFile(join(appPath, 'yarn.lock'), EMPTY_YARN_LOCK_CONTENT);
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, 'yarn.lock'), EMPTY_YARN_LOCK_CONTENT);
await writeFile(join(appPath, 'copy.lock'), '');
expect(await validateYarnLock(appPath)).toEqual([]);
diff --git a/packages/twenty-cli/src/app/manifest/utils/validate-yarn-lock.ts b/packages/twenty-cli/src/app/manifest/utils/validate-yarn-lock.ts
index c0c76630c57..3419ec1c1d9 100644
--- a/packages/twenty-cli/src/app/manifest/utils/validate-yarn-lock.ts
+++ b/packages/twenty-cli/src/app/manifest/utils/validate-yarn-lock.ts
@@ -6,7 +6,9 @@ export const validateYarnLockFile = async (
yarnLockPath: string,
): Promise<string[]> => {
if (!(await pathExists(yarnLockPath))) {
- return [];
+ return [
+ 'yarn.lock not found. Run "yarn install" to generate it before building.',
+ ];
}
return (await stat(yarnLockPath)).size === 0
diff --git a/packages/twenty-cli/src/app/publish/__tests__/copy-yarn-lock-into-package.spec.ts b/packages/twenty-cli/src/app/publish/__tests__/copy-yarn-lock-into-package.spec.ts
new file mode 100644
index 00000000000..902e6141828
--- /dev/null
+++ b/packages/twenty-cli/src/app/publish/__tests__/copy-yarn-lock-into-package.spec.ts
@@ -0,0 +1,43 @@
+import { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import {
+ APPLICATION_PACKAGE_YARN_LOCK_PATH,
+ EMPTY_YARN_LOCK_CONTENT,
+} from 'twenty-shared/application';
+import { afterEach, beforeEach, describe, expect, it } from 'vitest';
+import { copyYarnLockIntoPackage } from '@/app/publish/copy-yarn-lock-into-package';
+
+describe('copyYarnLockIntoPackage', () => {
+ let snapshotDirectory: string;
+
+ beforeEach(async () => {
+ snapshotDirectory = await mkdtemp(join(tmpdir(), 'packed-yarn-lock-'));
+ });
+
+ afterEach(async () => {
+ await rm(snapshotDirectory, { recursive: true, force: true });
+ });
+
+ it('copies the yarn.lock to a path npm keeps in the package', async () => {
+ await writeFile(
+ join(snapshotDirectory, 'yarn.lock'),
+ EMPTY_YARN_LOCK_CONTENT,
+ );
+
+ await copyYarnLockIntoPackage(snapshotDirectory);
+
+ expect(
+ await readFile(
+ join(snapshotDirectory, APPLICATION_PACKAGE_YARN_LOCK_PATH),
+ 'utf8',
+ ),
+ ).toBe(EMPTY_YARN_LOCK_CONTENT);
+ });
+
+ it('fails when the build has no yarn.lock', async () => {
+ await expect(copyYarnLockIntoPackage(snapshotDirectory)).rejects.toThrow(
+ 'ENOENT',
+ );
+ });
+});
diff --git a/packages/twenty-cli/src/app/publish/copy-yarn-lock-into-package.ts b/packages/twenty-cli/src/app/publish/copy-yarn-lock-into-package.ts
new file mode 100644
index 00000000000..3cbf844ab6b
--- /dev/null
+++ b/packages/twenty-cli/src/app/publish/copy-yarn-lock-into-package.ts
@@ -0,0 +1,15 @@
+import { copyFile, mkdir } from 'node:fs/promises';
+import { dirname, join } from 'node:path';
+import { APPLICATION_PACKAGE_YARN_LOCK_PATH } from 'twenty-shared/application';
+
+export const copyYarnLockIntoPackage = async (
+ snapshotDirectory: string,
+): Promise<void> => {
+ const packagedYarnLockPath = join(
+ snapshotDirectory,
+ APPLICATION_PACKAGE_YARN_LOCK_PATH,
+ );
+
+ await mkdir(dirname(packagedYarnLockPath), { recursive: true });
+ await copyFile(join(snapshotDirectory, 'yarn.lock'), packagedYarnLockPath);
+};
diff --git a/packages/twenty-cli/src/app/publish/with-packed-app.ts b/packages/twenty-cli/src/app/publish/with-packed-app.ts
index 39218c46685..25f22292025 100644
--- a/packages/twenty-cli/src/app/publish/with-packed-app.ts
+++ b/packages/twenty-cli/src/app/publish/with-packed-app.ts
@@ -1,8 +1,10 @@
import { mkdtemp, rm } from 'node:fs/promises';
import { dirname, join } from 'node:path';
+import { APPLICATION_PACKAGE_YARN_LOCK_PATH } from 'twenty-shared/application';
import { readSnapshotFile } from '@/app/deployment/read-snapshot-file';
import { resolveSnapshotDirectory } from '@/app/deployment/resolve-snapshot-directory';
+import { copyYarnLockIntoPackage } from '@/app/publish/copy-yarn-lock-into-package';
import { parseNpmPackOutputOrThrow } from '@/app/publish/parse-npm-pack-output-or-throw';
import { runNpmCommand } from '@/app/publish/run-npm-command';
import { type PackedApp } from '@/app/publish/types/packed-app.type';
@@ -30,6 +32,8 @@ export const withPackedApp = async <TResult>({
await readSnapshotFile({ snapshotDirectory, artifact });
}
+ await copyYarnLockIntoPackage(snapshotDirectory);
+
const packageDirectory = await mkdtemp(
join(dirname(snapshotDirectory), 'package-'),
);
@@ -57,6 +61,7 @@ export const withPackedApp = async <TResult>({
...build.files
.map((file) => file.path)
.filter((path) => path !== 'yarn.lock'),
+ APPLICATION_PACKAGE_YARN_LOCK_PATH,
];
const missingPaths = [...new Set(requiredPaths)].filter(
(path) => !includedPaths.has(path),
diff --git a/packages/twenty-cli/src/app/snapshots/__tests__/snapshot-artifacts.spec.ts b/packages/twenty-cli/src/app/snapshots/__tests__/snapshot-artifacts.spec.ts
index 934cfcb73b1..8f57d8342e1 100644
--- a/packages/twenty-cli/src/app/snapshots/__tests__/snapshot-artifacts.spec.ts
+++ b/packages/twenty-cli/src/app/snapshots/__tests__/snapshot-artifacts.spec.ts
@@ -16,6 +16,7 @@ import { dirname, join, resolve } from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
import { stop } from 'esbuild';
+import { EMPTY_YARN_LOCK_CONTENT } from 'twenty-shared/application';
import { isPlainObject } from 'twenty-shared/utils';
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest';
@@ -393,7 +394,7 @@ describe('CLI snapshots produce repeatable artifacts', () => {
signal: new AbortController().signal,
});
await symlink(join(root, 'node_modules'), join(appPath, 'node_modules'));
- await rm(join(appPath, 'yarn.lock'));
+ await writeFile(join(appPath, 'yarn.lock'), EMPTY_YARN_LOCK_CONTENT);
const configPath = join(appPath, 'tsconfig.json');
const config = JSON.parse(await readFile(configPath, 'utf8'));
config.exclude.push('vitest*.config.ts');
diff --git a/packages/twenty-cli/src/commands/app/__tests__/app-publish.spec.ts b/packages/twenty-cli/src/commands/app/__tests__/app-publish.spec.ts
index 87097c71538..81fa2c08031 100644
--- a/packages/twenty-cli/src/commands/app/__tests__/app-publish.spec.ts
+++ b/packages/twenty-cli/src/commands/app/__tests__/app-publish.spec.ts
@@ -84,7 +84,7 @@ if (process.env.PUBLISH_TEST_HANG === args[0]) {
const destination = args[args.indexOf('--pack-destination') + 1];
const filename = 'test-billing-1.2.3.tgz';
fs.writeFileSync(path.join(destination, filename), 'packed bytes');
- const files = ['package.json', 'manifest.json', 'src/main.mjs'].filter(file => file !== process.env.PUBLISH_TEST_OMIT);
+ const files = ['package.json', 'manifest.json', 'src/main.mjs', 'dependencies/yarn.lock'].filter(file => file !== process.env.PUBLISH_TEST_OMIT);
console.log(JSON.stringify([{ name: '@test/billing', version: '1.2.3', filename, files: files.map(path => ({ path })) }]));
} else {
console.log('npm output must not corrupt the CLI JSON');
diff --git a/packages/twenty-server/src/engine/core-modules/application/application-install/application-install.service.ts b/packages/twenty-server/src/engine/core-modules/application/application-install/application-install.service.ts
index c78d5421fe8..de91700d435 100644
--- a/packages/twenty-server/src/engine/core-modules/application/application-install/application-install.service.ts
+++ b/packages/twenty-server/src/engine/core-modules/application/application-install/application-install.service.ts
@@ -850,7 +850,12 @@ export class ApplicationInstallService {
): Promise<void> {
const filesToWrite = buildApplicationFileList(manifest);
- for (const { relativePath, fileFolder, isRequired } of filesToWrite) {
+ for (const {
+ relativePath,
+ resourcePath,
+ fileFolder,
+ isRequired,
+ } of filesToWrite) {
const absolutePath = this.resolveWithinDirOrThrow(
extractedDir,
relativePath,
@@ -861,14 +866,9 @@ export class ApplicationInstallService {
try {
content = await fs.readFile(absolutePath);
} catch (error) {
- if (
- !isRequired &&
- error instanceof Error &&
- 'code' in error &&
- error.code === 'ENOENT'
- ) {
+ if (!isRequired && (error as NodeJS.ErrnoException).code === 'ENOENT') {
this.logger.warn(
- `Source file not found in package: ${relativePath}; skipping for backward compatibility`,
+ `Optional file not found in package: ${relativePath}; skipping for backward compatibility`,
);
continue;
@@ -885,7 +885,7 @@ export class ApplicationInstallService {
fileFolder,
applicationUniversalIdentifier,
workspaceId,
- resourcePath: relativePath,
+ resourcePath: resourcePath ?? relativePath,
settings: { isTemporaryFile: false, toDelete: false },
});
}
diff --git a/packages/twenty-server/src/engine/core-modules/application/application-install/utils/__tests__/build-application-file-list.util.spec.ts b/packages/twenty-server/src/engine/core-modules/application/application-install/utils/__tests__/build-application-file-list.util.spec.ts
index df6a2d6117e..12fa431d169 100644
--- a/packages/twenty-server/src/engine/core-modules/application/application-install/utils/__tests__/build-application-file-list.util.spec.ts
+++ b/packages/twenty-server/src/engine/core-modules/application/application-install/utils/__tests__/build-application-file-list.util.spec.ts
@@ -28,6 +28,12 @@ describe('buildApplicationFileList', () => {
fileFolder: FileFolder.Dependencies,
isRequired: true,
},
+ {
+ relativePath: 'dependencies/yarn.lock',
+ resourcePath: 'yarn.lock',
+ fileFolder: FileFolder.Dependencies,
+ isRequired: false,
+ },
{
relativePath: 'manifest.json',
fileFolder: FileFolder.Source,
@@ -61,6 +67,17 @@ describe('buildApplicationFileList', () => {
]);
});
+ it('stores the packaged yarn.lock as the application yarn.lock', () => {
+ expect(
+ buildApplicationFileList({ application: {} } as Manifest),
+ ).toContainEqual({
+ relativePath: 'dependencies/yarn.lock',
+ resourcePath: 'yarn.lock',
+ fileFolder: FileFolder.Dependencies,
+ isRequired: false,
+ });
+ });
+
it('includes the shared dependencies bundle when the application declares one', () => {
const manifest = {
application: {
diff --git a/packages/twenty-server/src/engine/core-modules/application/application-install/utils/build-application-file-list.util.ts b/packages/twenty-server/src/engine/core-modules/application/application-install/utils/build-application-file-list.util.ts
index 8dcc2faf885..0f94cdedc9b 100644
--- a/packages/twenty-server/src/engine/core-modules/application/application-install/utils/build-application-file-list.util.ts
+++ b/packages/twenty-server/src/engine/core-modules/application/application-install/utils/build-application-file-list.util.ts
@@ -1,9 +1,13 @@
-import { type Manifest } from 'twenty-shared/application';
+import {
+ APPLICATION_PACKAGE_YARN_LOCK_PATH,
+ type Manifest,
+} from 'twenty-shared/application';
import { FileFolder } from 'twenty-shared/types';
import { isDefined } from 'twenty-shared/utils';
export type ApplicationFileToStore = {
relativePath: string;
+ resourcePath?: string;
fileFolder: FileFolder;
isRequired: boolean;
};
@@ -17,6 +21,12 @@ export const buildApplicationFileList = (
fileFolder: FileFolder.Dependencies,
isRequired: true,
},
+ {
+ relativePath: APPLICATION_PACKAGE_YARN_LOCK_PATH,
+ resourcePath: 'yarn.lock',
+ fileFolder: FileFolder.Dependencies,
+ isRequired: false,
+ },
{
relativePath: 'manifest.json',
fileFolder: FileFolder.Source,
diff --git a/packages/twenty-server/src/engine/core-modules/logic-function/logic-function-drivers/drivers/lambda/services/lambda-layer-manager.service.ts b/packages/twenty-server/src/engine/core-modules/logic-function/logic-function-drivers/drivers/lambda/services/lambda-layer-manager.service.ts
index 61ed0445d58..68f5dbc3806 100644
--- a/packages/twenty-server/src/engine/core-modules/logic-function/logic-function-drivers/drivers/lambda/services/lambda-layer-manager.service.ts
+++ b/packages/twenty-server/src/engine/core-modules/logic-function/logic-function-drivers/drivers/lambda/services/lambda-layer-manager.service.ts
@@ -7,6 +7,7 @@ import {
ResourceNotFoundException,
} from '@aws-sdk/client-lambda';
import { Logger } from '@nestjs/common';
+import { EMPTY_YARN_LOCK_CONTENT } from 'twenty-shared/application';
import { isDefined } from 'twenty-shared/utils';
import { type ApplicationDependencyFilesService } from 'src/engine/core-modules/application/application-package/application-dependency-files.service';
@@ -25,7 +26,6 @@ import { type LambdaDriverOptions } from 'src/engine/core-modules/logic-function
import { getLambdaDepsLayerName } from 'src/engine/core-modules/logic-function/logic-function-drivers/drivers/lambda/utils/get-lambda-deps-layer-name.util';
import { getLambdaSdkLayerName } from 'src/engine/core-modules/logic-function/logic-function-drivers/drivers/lambda/utils/get-lambda-sdk-layer-name.util';
import { reprefixLambdaZipEntries } from 'src/engine/core-modules/logic-function/logic-function-drivers/drivers/lambda/utils/reprefix-lambda-zip-entries.util';
-import { EMPTY_YARN_LOCK_CONTENT } from 'src/engine/core-modules/logic-function/logic-function-resource/constants/empty-yarn-lock-content.constant';
import { sanitizeApplicationPackageJson } from 'src/engine/core-modules/logic-function/logic-function-resource/utils/sanitize-application-package-json.util';
import { type SdkClientArchiveService } from 'src/engine/core-modules/sdk-client/sdk-client-archive.service';
import { type WorkspaceCacheService } from 'src/engine/workspace-cache/services/workspace-cache.service';
diff --git a/packages/twenty-server/src/engine/core-modules/logic-function/logic-function-resource/logic-function-resource.service.ts b/packages/twenty-server/src/engine/core-modules/logic-function/logic-function-resource/logic-function-resource.service.ts
index 5d247a4cc41..2b2513fb25f 100644
--- a/packages/twenty-server/src/engine/core-modules/logic-function/logic-function-resource/logic-function-resource.service.ts
+++ b/packages/twenty-server/src/engine/core-modules/logic-function/logic-function-resource/logic-function-resource.service.ts
@@ -3,6 +3,7 @@ import { Injectable } from '@nestjs/common';
import crypto from 'crypto';
import { promises as fs } from 'fs';
import { dirname, join } from 'path';
+import { EMPTY_YARN_LOCK_CONTENT } from 'twenty-shared/application';
import { FileFolder } from 'twenty-shared/types';
import { isDefined } from 'twenty-shared/utils';
import { type QueryRunner } from 'typeorm';
@@ -10,7 +11,6 @@ import { type QueryRunner } from 'typeorm';
import { FileStorageExceptionCode } from 'src/engine/core-modules/file-storage/interfaces/file-storage-exception';
import { FileStorageService } from 'src/engine/core-modules/file-storage/services/file-storage.service';
-import { EMPTY_YARN_LOCK_CONTENT } from 'src/engine/core-modules/logic-function/logic-function-resource/constants/empty-yarn-lock-content.constant';
import {
getLogicFunctionSeedProjectFiles,
LogicFunctionSeedProjectFile,
diff --git a/packages/twenty-server/test/integration/metadata/suites/application/successful-app-installation-packaged-yarn-lock.integration-spec.ts b/packages/twenty-server/test/integration/metadata/suites/application/successful-app-installation-packaged-yarn-lock.integration-spec.ts
new file mode 100644
index 00000000000..e4ed11e4ea0
--- /dev/null
+++ b/packages/twenty-server/test/integration/metadata/suites/application/successful-app-installation-packaged-yarn-lock.integration-spec.ts
@@ -0,0 +1,77 @@
+import { buildBaseManifest } from 'test/integration/metadata/suites/application/utils/build-base-manifest.util';
+import { cleanupApplicationAndAppRegistration } from 'test/integration/metadata/suites/application/utils/cleanup-application-and-app-registration.util';
+import { createAppTarball } from 'test/integration/metadata/suites/application/utils/create-app-tarball.util';
+import { installApplication } from 'test/integration/metadata/suites/application/utils/install-application.util';
+import { uploadAppTarball } from 'test/integration/metadata/suites/application/utils/upload-app-tarball.util';
+import {
+ APPLICATION_PACKAGE_YARN_LOCK_PATH,
+ computeDependencyFileChecksum,
+} from 'twenty-shared/application';
+import { v4 as uuidv4 } from 'uuid';
+
+import { SEED_APPLE_WORKSPACE_ID } from 'src/engine/workspace-manager/dev-seeder/core/constants/seeder-workspaces.constant';
+
+jest.setTimeout(120000);
+
+const PACKAGED_YARN_LOCK = `# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
+# yarn lockfile v1
+`;
+
+describe('Install application with a packaged yarn.lock', () => {
+ let universalIdentifier: string;
+
+ beforeAll(() => {
+ jest.useRealTimers();
+ });
+
+ beforeEach(() => {
+ universalIdentifier = uuidv4();
+ });
+
+ afterEach(async () => {
+ await cleanupApplicationAndAppRegistration({
+ applicationUniversalIdentifier: universalIdentifier,
+ });
+ });
+
+ afterAll(() => {
+ jest.useFakeTimers();
+ });
+
+ it('stores the packaged yarn.lock as the application yarn.lock', async () => {
+ const tarball = await createAppTarball({
+ 'manifest.json': JSON.stringify(
+ buildBaseManifest({ appId: universalIdentifier, roleId: uuidv4() }),
+ ),
+ 'package.json': JSON.stringify({
+ name: `test-install-packaged-yarn-lock-${universalIdentifier}`,
+ version: '1.0.0',
+ }),
+ [APPLICATION_PACKAGE_YARN_LOCK_PATH]: PACKAGED_YARN_LOCK,
+ });
+
+ const uploadResult = await uploadAppTarball({
+ tarballBuffer: tarball,
+ universalIdentifier,
+ });
+
+ expect(uploadResult.errors).toBeUndefined();
+
+ const { errors } = await installApplication({
+ input: { universalIdentifier },
+ expectToFail: false,
+ });
+
+ expect(errors).toBeUndefined();
+
+ const [application] = await global.testDataSource.query(
+ `SELECT "yarnLockChecksum" FROM core."application"
+ WHERE "universalIdentifier" = $1 AND "workspaceId" = $2`,
+ [universalIdentifier, SEED_APPLE_WORKSPACE_ID],
+ );
+
+ expect(application.yarnLockChecksum).toBe(
+ computeDependencyFileChecksum(PACKAGED_YARN_LOCK),
+ );
+ });
+});
diff --git a/packages/twenty-server/test/integration/metadata/suites/application/utils/create-app-tarball.util.ts b/packages/twenty-server/test/integration/metadata/suites/application/utils/create-app-tarball.util.ts
index 16beaa751f3..8358a111268 100644
--- a/packages/twenty-server/test/integration/metadata/suites/application/utils/create-app-tarball.util.ts
+++ b/packages/twenty-server/test/integration/metadata/suites/application/utils/create-app-tarball.util.ts
@@ -5,6 +5,7 @@ import { join } from 'path';
import * as tar from 'tar';
import {
+ APPLICATION_PACKAGE_YARN_LOCK_PATH,
computeDependencyFileChecksum,
computePackageJsonChecksum,
} from 'twenty-shared/application';
@@ -28,7 +29,8 @@ const declareDependencyChecksums = (
return files;
}
- const yarnLockContent = files['yarn.lock'];
+ const yarnLockContent =
+ files[APPLICATION_PACKAGE_YARN_LOCK_PATH] ?? files['yarn.lock'];
return {
...files,
diff --git a/packages/twenty-shared/src/application/constants/ApplicationPackageYarnLockPath.ts b/packages/twenty-shared/src/application/constants/ApplicationPackageYarnLockPath.ts
new file mode 100644
index 00000000000..f0191dbe35c
--- /dev/null
+++ b/packages/twenty-shared/src/application/constants/ApplicationPackageYarnLockPath.ts
@@ -0,0 +1,2 @@
+// npm never packs a root yarn.lock, so app packages carry it at this path
+export const APPLICATION_PACKAGE_YARN_LOCK_PATH = 'dependencies/yarn.lock';
diff --git a/packages/twenty-server/src/engine/core-modules/logic-function/logic-function-resource/constants/empty-yarn-lock-content.constant.ts b/packages/twenty-shared/src/application/constants/EmptyYarnLockContent.ts
similarity index 100%
rename from packages/twenty-server/src/engine/core-modules/logic-function/logic-function-resource/constants/empty-yarn-lock-content.constant.ts
rename to packages/twenty-shared/src/application/constants/EmptyYarnLockContent.ts
diff --git a/packages/twenty-shared/src/application/index.ts b/packages/twenty-shared/src/application/index.ts
index 500df2d5756..f1ae4d10f80 100644
--- a/packages/twenty-shared/src/application/index.ts
+++ b/packages/twenty-shared/src/application/index.ts
@@ -85,10 +85,12 @@ export { AGENT_TRIGGER_EVENT_NAME_PATTERN } from './constants/AgentTriggerEventN
export { AGENT_TRIGGER_LIMITS } from './constants/AgentTriggerLimits';
export { AGENT_TRIGGER_TYPES } from './constants/AgentTriggerTypes';
export { APPLICATION_FILE_UPLOAD_BATCH_SIZE } from './constants/ApplicationFileUploadBatchSize';
+export { APPLICATION_PACKAGE_YARN_LOCK_PATH } from './constants/ApplicationPackageYarnLockPath';
export { ASSETS_DIR } from './constants/AssetDirectory';
export { CONNECTION_PROVIDER_SCOPES } from './constants/ConnectionProviderScopes';
export { DEFAULT_CONNECTION_PROVIDER_SCOPE } from './constants/DefaultConnectionProviderScope';
export { DEFAULT_SETTINGS_MENU_ITEM_POSITION } from './constants/DefaultSettingsMenuItemPosition';
+export { EMPTY_YARN_LOCK_CONTENT } from './constants/EmptyYarnLockContent';
export { FRONT_COMPONENT_SHARED_DEPENDENCIES_BUILT_PATH } from './constants/FrontComponentSharedDependenciesBuiltPath';
export { FRONT_COMPONENT_SHARED_DEPENDENCIES_IMPORT_SPECIFIER } from './constants/FrontComponentSharedDependenciesImportSpecifier';
export { FRONT_COMPONENT_WIDGET_PAGE_LAYOUT_TYPES } from './constants/FrontComponentWidgetPageLayoutTypes';