Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
TypeScript agentic-aiagentsaiai-agentsaiagentsdeveloper-toolsfunction-callinggpt-4javascriptjsllmllmopsmcppythonremote-mcp-serverssetypescript
feat(ts/cli): "ts generate --transpiled" now emits .mjs files, rather than .js
jkomyno5ed674b19a55
diff --git a/ts/packages/cli/src/commands/ts/commands/ts.generate.cmd.ts b/ts/packages/cli/src/commands/ts/commands/ts.generate.cmd.tsindex 89cf7771a..22e1ea788 100644--- a/ts/packages/cli/src/commands/ts/commands/ts.generate.cmd.ts+++ b/ts/packages/cli/src/commands/ts/commands/ts.generate.cmd.ts@@ -211,7 +211,7 @@ export function generateTypescriptTypeStubs({outputDir,emitSingleFile: Boolean(compact), // Ensure boolean typebanner: BANNER,- importExtension: 'js',+ importExtension: 'mjs',})(index);// Write all generated filesdiff --git a/ts/packages/cli/src/generation/typescript/generate-index-source.ts b/ts/packages/cli/src/generation/typescript/generate-index-source.tsindex e7779021c..da313d77a 100644--- a/ts/packages/cli/src/generation/typescript/generate-index-source.ts+++ b/ts/packages/cli/src/generation/typescript/generate-index-source.ts@@ -32,7 +32,7 @@ const BARREL_OBJECT_NAME = 'Toolkits';export type GenerateTypeScriptIndexMapSourceParams = {banner: string;emitSingleFile: boolean;- importExtension: 'ts' | 'js';+ importExtension: 'ts' | 'mjs';};export function generateIndexSource(params: GenerateTypeScriptIndexMapSourceParams) {diff --git a/ts/packages/cli/src/generation/typescript/generate.ts b/ts/packages/cli/src/generation/typescript/generate.tsindex 9562d5fb2..67c5d37c6 100644--- a/ts/packages/cli/src/generation/typescript/generate.ts+++ b/ts/packages/cli/src/generation/typescript/generate.ts@@ -12,7 +12,7 @@ type GenerateTypeScriptSourcesParams = {banner: string;emitSingleFile: boolean;outputDir: string;- importExtension: 'ts' | 'js';+ importExtension: 'ts' | 'mjs';};export function generateTypeScriptSources(params: GenerateTypeScriptSourcesParams) {diff --git a/ts/packages/cli/src/generation/typescript/transpile.ts b/ts/packages/cli/src/generation/typescript/transpile.tsindex 4ef1ae94f..7668ba3d6 100644--- a/ts/packages/cli/src/generation/typescript/transpile.ts+++ b/ts/packages/cli/src/generation/typescript/transpile.ts@@ -27,7 +27,7 @@ export function transpileTypeScriptSources({ sources, outputDir }: TranspileTyperootDir: outputDir,declaration: true,emitDeclarationOnly: false,- noEmitOnError: true,+ noEmitOnError: false,} satisfies ts.CompilerOptions;const virtualFileMap = new Map(@@ -56,6 +56,13 @@ export function transpileTypeScriptSources({ sources, outputDir }: TranspileTypereturn ogGetSourceFile(filename, languageVersion, onError, shouldCreateNewSourceFile);};+ // Override writeFile to emit .mjs files directly instead of .js+ const ogWriteFile = tsHost.writeFile;+ tsHost.writeFile = (fileName, data, writeByteOrderMark, onError, sourceFiles, info) => {+ const mjsFileName = fileName.replace(/\.js$/, '.mjs');+ return ogWriteFile(mjsFileName, data, writeByteOrderMark, onError, sourceFiles, info);+ };+const program = ts.createProgram(virtualFileNames, compilerOptions, tsHost);const emitResult = program.emit();diff --git a/ts/packages/cli/test/__fixtures__/typescript-project-with-composio-core/src/index.js b/ts/packages/cli/test/__fixtures__/typescript-project-with-composio-core/src/index.mjssimilarity index 100%rename from ts/packages/cli/test/__fixtures__/typescript-project-with-composio-core/src/index.jsrename to ts/packages/cli/test/__fixtures__/typescript-project-with-composio-core/src/index.mjsdiff --git a/ts/packages/cli/test/__fixtures__/typescript-project/package.json b/ts/packages/cli/test/__fixtures__/typescript-project/package.jsonindex 63f91307b..67cc85399 100644--- a/ts/packages/cli/test/__fixtures__/typescript-project/package.json+++ b/ts/packages/cli/test/__fixtures__/typescript-project/package.json@@ -1,4 +1,5 @@{+ "type": "module","devDependencies": {"typescript": "^5.9.2"}diff --git a/ts/packages/cli/test/__utils__/typescript-compiler.ts b/ts/packages/cli/test/__utils__/typescript-compiler.tsindex 8cb386c90..a8cb1cab5 100644--- a/ts/packages/cli/test/__utils__/typescript-compiler.ts+++ b/ts/packages/cli/test/__utils__/typescript-compiler.ts@@ -90,8 +90,9 @@ export function assertTranspiledTypeScriptIsValid({));- expect(exitCode).toBe(0);expect(stderr).toBe('');+ expect(exitCode).toBe(0);+return stdout;});}diff --git a/ts/packages/cli/test/src/commands/ts/ts.generate.cmd.test.ts b/ts/packages/cli/test/src/commands/ts/ts.generate.cmd.test.tsindex af35c205b..a3d2be2b8 100644--- a/ts/packages/cli/test/src/commands/ts/ts.generate.cmd.test.ts+++ b/ts/packages/cli/test/src/commands/ts/ts.generate.cmd.test.ts@@ -191,8 +191,8 @@ describe('CLI: composio ts generate', () => {* Auto-generated by Composio CLI. Do not modify manually.*/- import { GMAIL } from "./gmail.js"- import { SLACK } from "./slack.js"+ import { GMAIL } from "./gmail.mjs"+ import { SLACK } from "./slack.mjs"/*** Map of Composio toolkits to actions.@@ -231,7 +231,7 @@ describe('CLI: composio ts generate', () => {},});- const testSourceCodePath = path.join(cwd, 'src', 'index.js');+ const testSourceCodePath = path.join(cwd, 'src', 'index.mjs');const testSourceCode = yield* fs.readFileString(testSourceCodePath);expect(testSourceCode).toMatchInlineSnapshot(`"import { Toolkits } from '@composio/core/generated';@@ -432,8 +432,8 @@ describe('CLI: composio ts generate', () => {* Auto-generated by Composio CLI. Do not modify manually.*/- import { GMAIL } from "./gmail.js"- import { SLACK } from "./slack.js"+ import { GMAIL } from "./gmail.mjs"+ import { SLACK } from "./slack.mjs"/*** Map of Composio toolkits to actions.@@ -472,7 +472,7 @@ describe('CLI: composio ts generate', () => {},});- const testSourceCodePath = path.join(cwd, 'src', 'index.js');+ const testSourceCodePath = path.join(cwd, 'src', 'index.mjs');const testSourceCode = yield* fs.readFileString(testSourceCodePath);expect(testSourceCode).toMatchInlineSnapshot(`"import { Toolkits } from '@composio/core/generated';@@ -638,8 +638,8 @@ describe('CLI: composio ts generate', () => {* Auto-generated by Composio CLI. Do not modify manually.*/- import { GMAIL } from "./gmail.js"- import { SLACK } from "./slack.js"+ import { GMAIL } from "./gmail.mjs"+ import { SLACK } from "./slack.mjs"/*** Map of Composio toolkits to actions.@@ -707,7 +707,7 @@ describe('CLI: composio ts generate', () => {}));- it.scoped('[Given] --transpiled [Then] it generates both .ts and .js files', () =>+ it.scoped('[Given] --transpiled [Then] it generates both .ts and .mjs files', () =>Effect.gen(function* () {const process = yield* NodeProcess;const cwd = process.cwd;@@ -723,11 +723,11 @@ describe('CLI: composio ts generate', () => {// Should have both .ts and .js filesconst tsFiles = fileNames.filter(name => name.endsWith('.ts'));- const jsFiles = fileNames.filter(name => name.endsWith('.js'));+ const mjsFiles = fileNames.filter(name => name.endsWith('.mjs'));const dtsFiles = fileNames.filter(name => name.endsWith('.d.ts'));expect(tsFiles.length).toBeGreaterThan(0);- expect(jsFiles.length).toBeGreaterThan(0);+ expect(mjsFiles.length).toBeGreaterThan(0);expect(dtsFiles.length).toBeGreaterThan(0);// Verify the files are valid TypeScript@@ -753,17 +753,17 @@ describe('CLI: composio ts generate', () => {const args = ['ts', 'generate'];yield* cli(args);- // Check if the output directory contains both .ts and .js files+ // Check if the output directory contains both .ts and .mjs filesconst files = yield* fs.readDirectory(generatedDir);const fileNames = files.map(file => path.basename(file));- // Should have both .ts and .js files since compiled is true by default for @composio/core/generated+ // Should have both .ts and .mjs files since compiled is true by default for @composio/core/generatedconst tsFiles = fileNames.filter(name => name.endsWith('.ts'));- const jsFiles = fileNames.filter(name => name.endsWith('.js'));+ const mjsFiles = fileNames.filter(name => name.endsWith('.mjs'));const dtsFiles = fileNames.filter(name => name.endsWith('.d.ts'));expect(tsFiles.length).toBeGreaterThan(0);- expect(jsFiles.length).toBeGreaterThan(0);+ expect(mjsFiles.length).toBeGreaterThan(0);expect(dtsFiles.length).toBeGreaterThan(0);}));@@ -784,12 +784,12 @@ describe('CLI: composio ts generate', () => {const files = yield* fs.readDirectory(outputDir);const fileNames = files.map(file => path.basename(file));- // Should have .ts files but no .js files+ // Should have .ts files but no .mjs filesconst tsFiles = fileNames.filter(name => name.endsWith('.ts'));- const jsFiles = fileNames.filter(name => name.endsWith('.js'));+ const mjsFiles = fileNames.filter(name => name.endsWith('.mjs'));expect(tsFiles.length).toBeGreaterThan(0);- expect(jsFiles.length).toBe(0);+ expect(mjsFiles.length).toBe(0);}));@@ -814,8 +814,8 @@ describe('CLI: composio ts generate', () => {* Auto-generated by Composio CLI. Do not modify manually.*/- import { GMAIL } from "./gmail.js"- import { SLACK } from "./slack.js"+ import { GMAIL } from "./gmail.mjs"+ import { SLACK } from "./slack.mjs"/*** Map of Composio toolkits to actions.