Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions packages/create-twenty-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
"name": "create-twenty-app",
"version": "0.1.0",
"description": "Command-line interface to create Twenty application",
"main": "dist/cli.js",
"bin": "dist/cli.js",
"main": "dist/cli.cjs",
"bin": "dist/cli.cjs",
"files": [
"dist/**/*"
],
"scripts": {
"build": "echo 'use npx nx build'",
"dev": "tsx src/cli.ts",
"start": "node dist/cli.js"
"build": "npx rimraf dist && npx vite build"
},
"keywords": [
"twenty",
Expand All @@ -19,6 +17,13 @@
"application",
"development"
],
"exports": {
".": {
"types": "./dist/cli.d.ts",
"import": "./dist/cli.mjs",
"require": "./dist/cli.cjs"
}
},
"license": "AGPL-3.0",
"dependencies": {
"@genql/cli": "^3.0.3",
Expand All @@ -37,7 +42,10 @@
"@types/lodash.camelcase": "^4.3.7",
"@types/lodash.kebabcase": "^4.1.7",
"@types/lodash.startcase": "^4",
"@types/node": "^20.0.0"
"@types/node": "^20.0.0",
"vite": "^7.0.0",
"vite-plugin-dts": "3.8.1",
"vite-tsconfig-paths": "^4.2.1"
},
"engines": {
"node": "^24.5.0",
Expand Down
24 changes: 3 additions & 21 deletions packages/create-twenty-app/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,9 @@
"projectType": "library",
"tags": ["scope:create-app"],
"targets": {
"before-build": {
"executor": "nx:run-commands",
"cache": true,
"options": {
"cwd": "packages/create-twenty-app",
"commands": ["rimraf dist", "tsc --project tsconfig.json"]
},
"dependsOn": ["^build", "typecheck"]
},
"build": {
"executor": "nx:run-commands",
"cache": true,
"options": {
"cwd": "packages/create-twenty-app",
"commands": [
"mkdir -p dist/constants/base-application",
"cp -R src/constants/base-application dist/constants",
"cp -R ../../.yarn/releases dist/constants/base-application/.yarn"
]
},
"dependsOn": ["before-build"]
"dependsOn": ["^build"],
"outputs": ["{projectRoot}/dist"]
},
"dev": {
"executor": "nx:run-commands",
Expand All @@ -39,7 +21,7 @@
"dependsOn": ["build"],
"options": {
"cwd": "packages/create-twenty-app",
"command": "node dist/cli.js"
"command": "node dist/cli.cjs"
}
},
"typecheck": {},
Expand Down
Binary file not shown.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"experimentalDecorators": true,
"importHelpers": true,
"allowUnreachableCode": false,
"strictNullChecks": true,
"strict": true,
"alwaysStrict": true,
"noImplicitAny": true,
"strictBindCallApply": false,
Expand All @@ -22,6 +22,5 @@
"skipDefaultLibCheck": true,
"resolveJsonModule": true,
},

"exclude": ["node_modules", "dist", "**/*.test.ts", "**/*.spec.ts"]
}
2 changes: 1 addition & 1 deletion packages/create-twenty-app/src/utils/app-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const copyBaseApplicationProject = async ({
appDescription: string;
appDirectory: string;
}) => {
await fs.copy(join(__dirname, '../constants/base-application'), appDirectory);
await fs.copy(join(__dirname, './constants/base-application'), appDirectory);

await createPackageJson({ appName, appDirectory });

Expand Down
42 changes: 21 additions & 21 deletions packages/create-twenty-app/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src",
"target": "es2022",
"module": "commonjs",
"moduleResolution": "node",
"strict": true,
"esModuleInterop": true,
"allowJs": false,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"declaration": false,
"sourceMap": true
"strictNullChecks": true,
"alwaysStrict": true,
"noImplicitAny": true,
"strictBindCallApply": false,
"noEmit": true,
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["src"],
"exclude": [
"node_modules",
"dist",
"**/*.test.ts",
"**/*.spec.ts",
"**/__tests__/**"
]
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
],
"extends": "../../tsconfig.base.json"
}
23 changes: 23 additions & 0 deletions packages/create-twenty-app/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"declaration": false,
"sourceMap": true
},
"include": ["src"],
"exclude": [
"node_modules",
"dist",
"**/*.test.ts",
"**/*.spec.ts",
"**/__tests__/**"
]
}
15 changes: 15 additions & 0 deletions packages/create-twenty-app/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"types": ["jest", "node"]
},
"include": [
"**/__mocks__/**/*",
"jest.config.mjs",
"src/**/*.d.ts",
"src/**/*.spec.ts",
"src/**/*.spec.tsx",
"src/**/*.test.ts",
"src/**/*.test.tsx"
]
}
85 changes: 85 additions & 0 deletions packages/create-twenty-app/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import fs from 'fs-extra';
import path from 'path';
import { defineConfig } from 'vite';
import dts from 'vite-plugin-dts';
import tsconfigPaths from 'vite-tsconfig-paths';
import packageJson from './package.json';

const moduleEntries = Object.keys((packageJson as any).exports || {})
.filter(
(key) => key !== './style.css' && key !== '.' && !key.startsWith('./src/'),
)
.map((module) => `src/${module.replace(/^\.\//, '')}/index.ts`);

const entries = ['src/cli.ts', ...moduleEntries];

const entryFileNames = (chunk: any, extension: 'cjs' | 'mjs') => {
if (!chunk.isEntry) {
throw new Error(
`Should never occurs, encountered a non entry chunk ${chunk.facadeModuleId}`,
);
}

const splitFaceModuleId = chunk.facadeModuleId?.split('/');
if (splitFaceModuleId === undefined) {
throw new Error(
`Should never occurs splitFaceModuleId is undefined ${chunk.facadeModuleId}`,
);
}

const moduleDirectory = splitFaceModuleId[splitFaceModuleId?.length - 2];
if (moduleDirectory === 'src') {
return `${chunk.name}.${extension}`;
}
return `${moduleDirectory}.${extension}`;
};

export default defineConfig(() => {
const tsConfigPath = path.resolve(__dirname, './tsconfig.lib.json');

return {
root: __dirname,
cacheDir: '../../node_modules/.vite/packages/create-twenty-app',
plugins: [
tsconfigPaths({
root: __dirname,
}),
dts({ entryRoot: './src', tsconfigPath: tsConfigPath }),
{
name: 'copy-assets',
closeBundle: async () => {
await fs.copy(
path.resolve(__dirname, 'src/constants/base-application'),
path.resolve(__dirname, 'dist/constants/base-application'),
);
},
},
],
build: {
outDir: 'dist',
lib: { entry: entries, name: 'create-twenty-app' },
rollupOptions: {
external: [
...Object.keys((packageJson as any).dependencies || {}),
'path',
'fs',
'child_process',
],
output: [
{
format: 'es',
entryFileNames: (chunk) => entryFileNames(chunk, 'mjs'),
},
Comment on lines +68 to +72
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: ES module output cli.mjs uses __dirname, which is undefined in ESM, causing ReferenceError on import.
Severity: CRITICAL | Confidence: High

🔍 Detailed Analysis

The vite.config.ts generates an ES module output (cli.mjs) that includes references to __dirname. In ES module contexts, __dirname is not defined, leading to a ReferenceError: __dirname is not defined when cli.mjs is imported. This makes the ES module version of the package unusable for consumers using ES module syntax, despite the CommonJS version working correctly.

💡 Suggested Fix

Configure Vite/Rollup to either polyfill __dirname for ES module output, or use import.meta.url for path resolution in cli.mjs and app-template.ts. Alternatively, remove the ES module export if it's not intended for ES module consumption.

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: packages/create-twenty-app/vite.config.ts#L68-L72

Potential issue: The `vite.config.ts` generates an ES module output (`cli.mjs`) that
includes references to `__dirname`. In ES module contexts, `__dirname` is not defined,
leading to a `ReferenceError: __dirname is not defined` when `cli.mjs` is imported. This
makes the ES module version of the package unusable for consumers using ES module
syntax, despite the CommonJS version working correctly.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 5129230

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use import.meta.dirname

{
format: 'cjs',
interop: 'auto',
esModule: true,
exports: 'named',
entryFileNames: (chunk) => entryFileNames(chunk, 'cjs'),
},
],
},
},
logLevel: 'warn',
};
});
5 changes: 4 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -30875,8 +30875,11 @@ __metadata:
lodash.kebabcase: "npm:^4.1.1"
lodash.startcase: "npm:^4.4.0"
uuid: "npm:^13.0.0"
vite: "npm:^7.0.0"
vite-plugin-dts: "npm:3.8.1"
vite-tsconfig-paths: "npm:^4.2.1"
bin:
create-twenty-app: dist/cli.js
create-twenty-app: dist/cli.cjs
languageName: unknown
linkType: soft

Expand Down
Loading