Skip to content

The open alternative to Salesforce, designed for AI.

Tell pull users their project cannot build what pull just wrote (#25747)

Weiko123f463eea75
diff --git a/packages/twenty-sdk/src/cli/commands/dev/pull.ts b/packages/twenty-sdk/src/cli/commands/dev/pull.ts
index da92c206f94..68a71ca63dd 100644
--- a/packages/twenty-sdk/src/cli/commands/dev/pull.ts
+++ b/packages/twenty-sdk/src/cli/commands/dev/pull.ts
@@ -62,6 +62,20 @@ export class AppPullCommand {
),
);
console.log(chalk.gray(`Base recorded in ${PULL_BASE_FILE_PATH}`));
- console.log(chalk.gray('Next: yarn twenty plan --no-delete'));
+
+ if (result.data.isSdkResolvable) {
+ console.log(chalk.gray('Next: yarn twenty plan --no-delete'));
+ } else {
+ console.log(
+ chalk.yellow(
+ 'twenty-sdk is not installed here, so the written files cannot build yet.',
+ ),
+ );
+ console.log(
+ chalk.gray(
+ 'Next: install your dependencies, then yarn twenty plan --no-delete',
+ ),
+ );
+ }
}
}
diff --git a/packages/twenty-sdk/src/cli/operations/pull.ts b/packages/twenty-sdk/src/cli/operations/pull.ts
index 5f4567ef616..a75038bd906 100644
--- a/packages/twenty-sdk/src/cli/operations/pull.ts
+++ b/packages/twenty-sdk/src/cli/operations/pull.ts
@@ -22,6 +22,7 @@ import {
writePullBaseManifest,
} from '@/cli/utilities/pull/pull-base-file';
import { getApplicationMismatchMessage } from '@/cli/utilities/pull/get-application-mismatch-message';
+import { isSdkResolvable } from '@/cli/utilities/pull/is-sdk-resolvable';
import { scanProjectSourceFiles } from '@/cli/utilities/pull/scan-project-source-files';
import { runSafe } from '@/cli/utilities/run-safe';
import { join } from 'node:path';
@@ -45,6 +46,7 @@ export type AppPullResult = {
unreadableRelativePaths: string[];
compiledTranslationEntryCountByLocale: Record<string, number>;
hadBase: boolean;
+ isSdkResolvable: boolean;
};
const EXPORT_REFUSAL_SUB_CODES = [
@@ -228,6 +230,7 @@ const innerAppPull = async (
compiledTranslationEntryCountByLocale:
translationPlan.compiledEntryCountByLocale,
hadBase: isDefined(baseManifest),
+ isSdkResolvable: isSdkResolvable(appPath),
},
};
};
diff --git a/packages/twenty-sdk/src/cli/utilities/pull/__tests__/is-sdk-resolvable.spec.ts b/packages/twenty-sdk/src/cli/utilities/pull/__tests__/is-sdk-resolvable.spec.ts
new file mode 100644
index 00000000000..e6938890e07
--- /dev/null
+++ b/packages/twenty-sdk/src/cli/utilities/pull/__tests__/is-sdk-resolvable.spec.ts
@@ -0,0 +1,42 @@
+import { mkdtemp, mkdir, writeFile, rm } from 'node:fs/promises';
+import { join } from 'node:path';
+import { tmpdir } from 'node:os';
+
+import { isSdkResolvable } from '@/cli/utilities/pull/is-sdk-resolvable';
+
+describe('isSdkResolvable', () => {
+ let appPath: string;
+
+ beforeEach(async () => {
+ appPath = await mkdtemp(join(tmpdir(), 'is-sdk-resolvable-'));
+ await writeFile(
+ join(appPath, 'package.json'),
+ JSON.stringify({ name: 'app', version: '1.0.0', private: true }),
+ );
+ });
+
+ afterEach(async () => {
+ await rm(appPath, { recursive: true, force: true });
+ });
+
+ it('should be false when the project has no twenty-sdk installed', () => {
+ expect(isSdkResolvable(appPath)).toBe(false);
+ });
+
+ it('should be true when twenty-sdk exposes its define entry point', async () => {
+ const sdkPath = join(appPath, 'node_modules', 'twenty-sdk');
+
+ await mkdir(sdkPath, { recursive: true });
+ await writeFile(
+ join(sdkPath, 'package.json'),
+ JSON.stringify({
+ name: 'twenty-sdk',
+ version: '0.0.0',
+ exports: { './define': './define.js' },
+ }),
+ );
+ await writeFile(join(sdkPath, 'define.js'), 'module.exports = {};\n');
+
+ expect(isSdkResolvable(appPath)).toBe(true);
+ });
+});
diff --git a/packages/twenty-sdk/src/cli/utilities/pull/is-sdk-resolvable.ts b/packages/twenty-sdk/src/cli/utilities/pull/is-sdk-resolvable.ts
new file mode 100644
index 00000000000..65335f086e7
--- /dev/null
+++ b/packages/twenty-sdk/src/cli/utilities/pull/is-sdk-resolvable.ts
@@ -0,0 +1,12 @@
+import { createRequire } from 'node:module';
+import { join } from 'node:path';
+
+export const isSdkResolvable = (appPath: string): boolean => {
+ try {
+ createRequire(join(appPath, 'package.json')).resolve('twenty-sdk/define');
+
+ return true;
+ } catch {
+ return false;
+ }
+};