From b7f592d5f777851cd7ff403e0228faaada8c92a9 Mon Sep 17 00:00:00 2001 From: florianbgt Date: Mon, 25 Nov 2024 14:04:38 +0100 Subject: [PATCH] more cleanup --- packages/cli/src/annotationManager.ts | 2 +- packages/cli/src/api/sync.ts | 2 +- .../dependencyManager/dependencyManager.ts | 2 +- .../languages/javascript/annotations.test.ts | 99 ---------------- .../src/languages/javascript/annotations.ts | 3 - .../src/languages/javascript/exports.test.ts | 99 ---------------- .../src/languages/javascript/imports.test.ts | 108 ------------------ .../languages/typescript/annotations.test.ts | 102 ----------------- .../src/languages/typescript/annotations.ts | 8 -- .../src/languages/typescript/exports.test.ts | 105 ----------------- .../src/languages/typescript/imports.test.ts | 108 ------------------ .../{languages => languagesPlugins}/index.ts | 0 .../javascript.ts | 0 .../{languages => languagesPlugins}/types.ts | 0 .../typescript.ts | 0 packages/cli/src/splitRunner/splitRunner.ts | 2 +- 16 files changed, 4 insertions(+), 636 deletions(-) delete mode 100644 packages/cli/src/languages/javascript/annotations.test.ts delete mode 100644 packages/cli/src/languages/javascript/annotations.ts delete mode 100644 packages/cli/src/languages/javascript/exports.test.ts delete mode 100644 packages/cli/src/languages/javascript/imports.test.ts delete mode 100644 packages/cli/src/languages/typescript/annotations.test.ts delete mode 100644 packages/cli/src/languages/typescript/annotations.ts delete mode 100644 packages/cli/src/languages/typescript/exports.test.ts delete mode 100644 packages/cli/src/languages/typescript/imports.test.ts rename packages/cli/src/{languages => languagesPlugins}/index.ts (100%) rename packages/cli/src/{languages => languagesPlugins}/javascript.ts (100%) rename packages/cli/src/{languages => languagesPlugins}/types.ts (100%) rename packages/cli/src/{languages => languagesPlugins}/typescript.ts (100%) diff --git a/packages/cli/src/annotationManager.ts b/packages/cli/src/annotationManager.ts index c0e7454..fb89a52 100644 --- a/packages/cli/src/annotationManager.ts +++ b/packages/cli/src/annotationManager.ts @@ -1,5 +1,5 @@ import { Group } from "./dependencyManager/types"; -import { LanguagePlugin } from "./languages/types"; +import { LanguagePlugin } from "./languagesPlugins/types"; class AnnotationManager { private nanoapiRegex: RegExp; diff --git a/packages/cli/src/api/sync.ts b/packages/cli/src/api/sync.ts index c8abd9b..bd9eea9 100644 --- a/packages/cli/src/api/sync.ts +++ b/packages/cli/src/api/sync.ts @@ -3,7 +3,7 @@ import { syncSchema } from "./helpers/validation"; import fs from "fs"; import DependencyTreeManager from "../dependencyManager/dependencyManager"; import AnnotationManager from "../annotationManager"; -import { getLanguagePluginFromFilePath } from "../languages"; +import { getLanguagePluginFromFilePath } from "../languagesPlugins"; import { replaceIndexesFromSourceCode } from "../helper/file"; export function sync(payload: z.infer) { diff --git a/packages/cli/src/dependencyManager/dependencyManager.ts b/packages/cli/src/dependencyManager/dependencyManager.ts index e2456bb..c6e6617 100644 --- a/packages/cli/src/dependencyManager/dependencyManager.ts +++ b/packages/cli/src/dependencyManager/dependencyManager.ts @@ -3,7 +3,7 @@ import fs from "fs"; import { resolveFilePath } from "../helper/file"; import { DependencyTree, Group, Endpoint } from "./types"; import AnnotationManager from "../annotationManager"; -import { getLanguagePluginFromFilePath } from "../languages"; +import { getLanguagePluginFromFilePath } from "../languagesPlugins"; class DependencyTreeManager { dependencyTree: DependencyTree; diff --git a/packages/cli/src/languages/javascript/annotations.test.ts b/packages/cli/src/languages/javascript/annotations.test.ts deleted file mode 100644 index 456c69e..0000000 --- a/packages/cli/src/languages/javascript/annotations.test.ts +++ /dev/null @@ -1,99 +0,0 @@ -import { describe, it, expect } from "vitest"; -import Parser from "tree-sitter"; -import Javascript from "tree-sitter-javascript"; -import { getJavascriptAnnotationNodes } from "./annotations"; - -describe("Should extract annotations from the source code", () => { - it("Should extract final endpoints annotations", () => { - const parser = new Parser(); - parser.setLanguage(Javascript); - - const sourceCode = ` -import { Controller, Get, Res, HttpStatus } from '@nestjs/common'; - -@Controller() -export class AppController { - constructor(private readonly appService) {} - - // @nanoapi method:GET path:/ - @Get() - getHello() { - return this.appService.getHello(); - } - - // @nanoapi method:GET path:/liveness - @Get('/liveness') - getLiveness() { - return 'OK'; - } - - // @nanoapi method:GET path:/readiness - @Get('/readiness') - async getReadiness(@Res() res) { - // const isDbConnected = await this.prisma.checkDatabaseConnection(); - // if (isDbConnected) { - // return res.status(HttpStatus.OK).json({ status: 'ok', database: 'up' }); - // } else { - // return res.status(HttpStatus.SERVICE_UNAVAILABLE).json({ status: 'error', database: 'down' }); - // } - return res.status(HttpStatus.OK).json({ status: 'ok' }); - } -} - `; - - const tree = parser.parse(sourceCode); - - const annotationsNodes = getJavascriptAnnotationNodes( - parser, - tree.rootNode, - ); - - expect(annotationsNodes.length).toBe(3); - expect(annotationsNodes[0].text).toBe("// @nanoapi method:GET path:/"); - expect(annotationsNodes[1].text).toBe( - "// @nanoapi method:GET path:/liveness", - ); - expect(annotationsNodes[2].text).toBe( - "// @nanoapi method:GET path:/readiness", - ); - }); - - it("Should extract group annotations", () => { - const parser = new Parser(); - parser.setLanguage(Javascript); - - const sourceCode = ` -import { Module } from '@nestjs/common'; -import { MongooseModule } from '@nestjs/mongoose'; -import { CharactersController } from './characters.controller'; -import { CharactersService } from './characters.service'; -import { Character, CharacterSchema } from './characters.schema'; -import { FileService } from 'src/file.service'; - -// @nanoapi path:/api/v1/characters -@Module({ - imports: [ - MongooseModule.forFeature([ - { name: Character.name, schema: CharacterSchema }, - ]), - ], - controllers: [CharactersController], - providers: [CharactersService, FileService], - exports: [CharactersService], -}) -export class CharactersModule {} - `; - - const tree = parser.parse(sourceCode); - - const annotationsNodes = getJavascriptAnnotationNodes( - parser, - tree.rootNode, - ); - - expect(annotationsNodes.length).toBe(1); - expect(annotationsNodes[0].text).toBe( - "// @nanoapi path:/api/v1/characters", - ); - }); -}); diff --git a/packages/cli/src/languages/javascript/annotations.ts b/packages/cli/src/languages/javascript/annotations.ts deleted file mode 100644 index 91a972d..0000000 --- a/packages/cli/src/languages/javascript/annotations.ts +++ /dev/null @@ -1,3 +0,0 @@ -export const javascriptCommentPrefix = "// "; - -export const javascriptAnnotationRegex = /\/\/( *)@nanoapi/; diff --git a/packages/cli/src/languages/javascript/exports.test.ts b/packages/cli/src/languages/javascript/exports.test.ts deleted file mode 100644 index 3bf901b..0000000 --- a/packages/cli/src/languages/javascript/exports.test.ts +++ /dev/null @@ -1,99 +0,0 @@ -import { describe, it, expect } from "vitest"; -import Parser from "tree-sitter"; -import Javascript from "tree-sitter-javascript"; -import { getJavascriptExports } from "./exports"; - -describe("Should extract export from the source code", () => { - it("Should extract named export with decorator", () => { - const parser = new Parser(); - parser.setLanguage(Javascript); - - const tree = parser.parse(` -import { Controller, Get, Res, HttpStatus } from '@nestjs/common'; - -@Controller() -export class AppController { - constructor(private readonly appService) {} - - // @nanoapi method:GET path:/ - @Get() - getHello() { - return this.appService.getHello(); - } - - // @nanoapi method:GET path:/liveness - @Get('/liveness') - getLiveness() { - return 'OK'; - } - - // @nanoapi method:GET path:/readiness - @Get('/readiness') - async getReadiness(@Res() res) { - // const isDbConnected = await this.prisma.checkDatabaseConnection(); - // if (isDbConnected) { - // return res.status(HttpStatus.OK).json({ status: 'ok', database: 'up' }); - // } else { - // return res.status(HttpStatus.SERVICE_UNAVAILABLE).json({ status: 'error', database: 'down' }); - // } - return res.status(HttpStatus.OK).json({ status: 'ok' }); - } -} - `); - - const exportNodes = getJavascriptExports(parser, tree.rootNode); - - expect(exportNodes.defaultExport).toBe(undefined); - - expect(exportNodes.namedExports.length).toBe(1); - expect(exportNodes.namedExports[0].exportNode.text).toBe(`AppController`); - }); - - it("Should extract multiple named exports of different types", () => { - const parser = new Parser(); - parser.setLanguage(Javascript); - - const tree = parser.parse(` -export function a() { - return 1; -} - -export class b {}; - -export const c = 1; - -export let d = 1; - -export var e = 1; - `); - - const exportNodes = getJavascriptExports(parser, tree.rootNode); - - expect(exportNodes.defaultExport).toBe(undefined); - - expect(exportNodes.namedExports.length).toBe(5); - expect(exportNodes.namedExports[0].exportNode.text).toBe("a"); - expect(exportNodes.namedExports[1].exportNode.text).toBe("b"); - expect(exportNodes.namedExports[2].exportNode.text).toBe("c"); - expect(exportNodes.namedExports[3].exportNode.text).toBe("d"); - expect(exportNodes.namedExports[4].exportNode.text).toBe("e"); - }); - - it("Should extract default export", () => { - const parser = new Parser(); - parser.setLanguage(Javascript); - - const tree = parser.parse(` -export default function a() { - return 1; -} - `); - - const exportNodes = getJavascriptExports(parser, tree.rootNode); - - expect(exportNodes.defaultExport).not.toBe(undefined); - expect(exportNodes.defaultExport?.text).toBe(`export default function a() { - return 1; -}`); - }); -}); diff --git a/packages/cli/src/languages/javascript/imports.test.ts b/packages/cli/src/languages/javascript/imports.test.ts deleted file mode 100644 index e426691..0000000 --- a/packages/cli/src/languages/javascript/imports.test.ts +++ /dev/null @@ -1,108 +0,0 @@ -import { describe, it, expect } from "vitest"; -import Parser from "tree-sitter"; -import Javascript from "tree-sitter-javascript"; -import { getJavascriptImports } from "./imports"; - -describe("Should extract imports identifiers from the source code", () => { - it("Should extract import specifier", () => { - const parser = new Parser(); - parser.setLanguage(Javascript); - - const tree = parser.parse(` -import { Controller, Get } from '@nestjs/common'; -import { test1, test2 } from './test'; - `); - - const imports = getJavascriptImports(parser, tree.rootNode); - - expect(imports.length).toBe(2); - - expect(imports[0].source).toBe("@nestjs/common"); - expect(imports[0].importIdentifier).toBe(undefined); - expect(imports[0].importSpecifierIdentifiers.length).toBe(2); - expect(imports[0].importSpecifierIdentifiers[0].text).toBe("Controller"); - expect(imports[0].importSpecifierIdentifiers[1].text).toBe("Get"); - - expect(imports[1].source).toBe("./test"); - expect(imports[1].importIdentifier).toBe(undefined); - expect(imports[1].importSpecifierIdentifiers.length).toBe(2); - expect(imports[1].importSpecifierIdentifiers[0].text).toBe("test1"); - expect(imports[1].importSpecifierIdentifiers[1].text).toBe("test2"); - }); - - it("Should extract import identifier and namespace import", () => { - const parser = new Parser(); - parser.setLanguage(Javascript); - - const tree = parser.parse(` -import common from '@nestjs/common'; -import * as test from './test'; -`); - - const imports = getJavascriptImports(parser, tree.rootNode); - - expect(imports.length).toBe(2); - - expect(imports[0].source).toBe("@nestjs/common"); - expect(imports[0].importIdentifier).not.toBe(undefined); - expect(imports[0].importIdentifier?.text).toBe("common"); - expect(imports[0].namespaceImport).toBe(undefined); - expect(imports[0].importSpecifierIdentifiers.length).toBe(0); - - expect(imports[1].source).toBe("./test"); - expect(imports[1].importIdentifier).toBe(undefined); - expect(imports[1].namespaceImport).not.toBe(undefined); - expect(imports[1].namespaceImport?.text).toBe("test"); - expect(imports[1].importSpecifierIdentifiers.length).toBe(0); - }); - - // it("Should work with require import", () => { - // const parser = new Parser(); - // parser.setLanguage(Javascript); - - // const tree = parser.parse(` - // const { test1, test2 } = require('@nestjs/common'); - // const test = require('./test'); - // `); - - // const imports = getJavascriptImports(parser, tree.rootNode); - - // expect(imports.length).toBe(2); - - // expect(imports[0].source).toBe("@nestjs/common"); - // expect(imports[0].importIdentifier).toBe(undefined); - // expect(imports[0].importSpecifierIdentifiers.length).toBe(2); - // expect(imports[0].importSpecifierIdentifiers[0].text).toBe("test1"); - // expect(imports[0].importSpecifierIdentifiers[1].text).toBe("test2"); - - // expect(imports[1].source).toBe("./test"); - // expect(imports[1].importIdentifier).not.toBe(undefined); - // expect(imports[1].importIdentifier?.text).toBe("test"); - // expect(imports[1].importSpecifierIdentifiers.length).toBe(0); - // }); - - // it("Should work with dynamic import", () => { - // const parser = new Parser(); - // parser.setLanguage(Javascript); - - // const tree = parser.parse(` - // const { test1, test2 } = import('@nestjs/common'); - // const test = import('./test'); - // `); - - // const imports = getJavascriptImports(parser, tree.rootNode); - - // expect(imports.length).toBe(2); - - // expect(imports[0].source).toBe("@nestjs/common"); - // expect(imports[0].importIdentifier).toBe(undefined); - // expect(imports[0].importSpecifierIdentifiers.length).toBe(2); - // expect(imports[0].importSpecifierIdentifiers[0].text).toBe("test1"); - // expect(imports[0].importSpecifierIdentifiers[1].text).toBe("test2"); - - // expect(imports[1].source).toBe("./test"); - // expect(imports[1].importIdentifier).not.toBe(undefined); - // expect(imports[1].importIdentifier?.text).toBe("test"); - // expect(imports[1].importSpecifierIdentifiers.length).toBe(0); - // }); -}); diff --git a/packages/cli/src/languages/typescript/annotations.test.ts b/packages/cli/src/languages/typescript/annotations.test.ts deleted file mode 100644 index 15d5e7c..0000000 --- a/packages/cli/src/languages/typescript/annotations.test.ts +++ /dev/null @@ -1,102 +0,0 @@ -import { describe, it, expect } from "vitest"; -import Parser from "tree-sitter"; -import Typescript from "tree-sitter-typescript"; -import { getTypescriptAnnotationNodes } from "./annotations"; - -describe("Should extract annotations from the source code", () => { - it("Should extract final endpoints annotations", () => { - const parser = new Parser(); - parser.setLanguage(Typescript.typescript); - - const sourceCode = ` -import { Controller, Get, Res, HttpStatus } from '@nestjs/common'; -import { Response } from 'express'; -import { AppService } from './app.service'; - -@Controller() -export class AppController { - constructor(private readonly appService: AppService) {} - - // @nanoapi method:GET path:/ - @Get() - getHello(): string { - return this.appService.getHello(); - } - - // @nanoapi method:GET path:/liveness - @Get('/liveness') - getLiveness(): string { - return 'OK'; - } - - // @nanoapi method:GET path:/readiness - @Get('/readiness') - async getReadiness(@Res() res: Response): Promise { - // const isDbConnected = await this.prisma.checkDatabaseConnection(); - // if (isDbConnected) { - // return res.status(HttpStatus.OK).json({ status: 'ok', database: 'up' }); - // } else { - // return res.status(HttpStatus.SERVICE_UNAVAILABLE).json({ status: 'error', database: 'down' }); - // } - return res.status(HttpStatus.OK).json({ status: 'ok' }); - } -} - `; - - const tree = parser.parse(sourceCode); - - const annotationsNodes = getTypescriptAnnotationNodes( - parser, - tree.rootNode, - ); - - expect(annotationsNodes.length).toBe(3); - expect(annotationsNodes[0].text).toBe("// @nanoapi method:GET path:/"); - expect(annotationsNodes[1].text).toBe( - "// @nanoapi method:GET path:/liveness", - ); - expect(annotationsNodes[2].text).toBe( - "// @nanoapi method:GET path:/readiness", - ); - }); - - it("Should extract group annotations", () => { - const parser = new Parser(); - parser.setLanguage(Typescript.typescript); - - const sourceCode = ` -import { Module } from '@nestjs/common'; -import { MongooseModule } from '@nestjs/mongoose'; -import { CharactersController } from './characters.controller'; -import { CharactersService } from './characters.service'; -import { Character, CharacterSchema } from './characters.schema'; -import { FileService } from 'src/file.service'; - -// @nanoapi path:/api/v1/characters -@Module({ - imports: [ - MongooseModule.forFeature([ - { name: Character.name, schema: CharacterSchema }, - ]), - ], - controllers: [CharactersController], - providers: [CharactersService, FileService], - exports: [CharactersService], -}) -export class CharactersModule {} - - `; - - const tree = parser.parse(sourceCode); - - const annotationsNodes = getTypescriptAnnotationNodes( - parser, - tree.rootNode, - ); - - expect(annotationsNodes.length).toBe(1); - expect(annotationsNodes[0].text).toBe( - "// @nanoapi path:/api/v1/characters", - ); - }); -}); diff --git a/packages/cli/src/languages/typescript/annotations.ts b/packages/cli/src/languages/typescript/annotations.ts deleted file mode 100644 index ec904ad..0000000 --- a/packages/cli/src/languages/typescript/annotations.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { - javascriptAnnotationRegex, - javascriptCommentPrefix, -} from "../javascript/annotations"; - -export const typescriptCommentPrefix = javascriptCommentPrefix; - -export const typscriptAnnotationRegex = javascriptAnnotationRegex; diff --git a/packages/cli/src/languages/typescript/exports.test.ts b/packages/cli/src/languages/typescript/exports.test.ts deleted file mode 100644 index a4fa888..0000000 --- a/packages/cli/src/languages/typescript/exports.test.ts +++ /dev/null @@ -1,105 +0,0 @@ -import { describe, it, expect } from "vitest"; -import Parser from "tree-sitter"; -import Typescript from "tree-sitter-typescript"; -import { getTypescriptExports } from "./exports"; - -describe("Should extract export from the source code", () => { - it("Should extract named export with decorator", () => { - const parser = new Parser(); - parser.setLanguage(Typescript.typescript); - - const tree = parser.parse(` -import { Controller, Get, Res, HttpStatus } from '@nestjs/common'; -import { Response } from 'express'; -import { AppService } from './app.service'; - -@Controller() -export class AppController { - constructor(private readonly appService: AppService) {} - - // @nanoapi method:GET path:/ - @Get() - getHello(): string { - return this.appService.getHello(); - } - - // @nanoapi method:GET path:/liveness - @Get('/liveness') - getLiveness(): string { - return 'OK'; - } - - // @nanoapi method:GET path:/readiness - @Get('/readiness') - async getReadiness(@Res() res: Response): Promise { - // const isDbConnected = await this.prisma.checkDatabaseConnection(); - // if (isDbConnected) { - // return res.status(HttpStatus.OK).json({ status: 'ok', database: 'up' }); - // } else { - // return res.status(HttpStatus.SERVICE_UNAVAILABLE).json({ status: 'error', database: 'down' }); - // } - return res.status(HttpStatus.OK).json({ status: 'ok' }); - } -} - `); - - const exportNodes = getTypescriptExports(parser, tree.rootNode); - - expect(exportNodes.defaultExport).toBe(undefined); - - expect(exportNodes.namedExports.length).toBe(1); - expect(exportNodes.namedExports[0].exportNode.text).toBe(`AppController`); - }); - - it("Should extract multiple named exports of different types", () => { - const parser = new Parser(); - parser.setLanguage(Typescript.typescript); - - const tree = parser.parse(` -export function a(): number { - return 1; -} - -export class b {}; - -export const c: number = 1; - -export let d: number = 1; - -export var e: number = 1; - -export type f = number; - `); - - const exportNodes = getTypescriptExports(parser, tree.rootNode); - - expect(exportNodes.defaultExport).toBe(undefined); - - expect(exportNodes.namedExports.length).toBe(6); - expect(exportNodes.namedExports[0].exportNode.text).toBe("a"); - expect(exportNodes.namedExports[1].exportNode.text).toBe("b"); - expect(exportNodes.namedExports[2].exportNode.text).toBe("c"); - expect(exportNodes.namedExports[3].exportNode.text).toBe("d"); - expect(exportNodes.namedExports[4].exportNode.text).toBe("e"); - expect(exportNodes.namedExports[5].exportNode.text).toBe("f"); - }); - - it("Should extract default export", () => { - const parser = new Parser(); - parser.setLanguage(Typescript.typescript); - - const tree = parser.parse(` -export default function a(): number { - return 1; -} - `); - - const exportNodes = getTypescriptExports(parser, tree.rootNode); - - expect(exportNodes.defaultExport).not.toBe(undefined); - expect(exportNodes.defaultExport?.text) - .toBe(`export default function a(): number { - return 1; -}`); - }); -}); diff --git a/packages/cli/src/languages/typescript/imports.test.ts b/packages/cli/src/languages/typescript/imports.test.ts deleted file mode 100644 index 9c2c20d..0000000 --- a/packages/cli/src/languages/typescript/imports.test.ts +++ /dev/null @@ -1,108 +0,0 @@ -import { describe, it, expect } from "vitest"; -import Parser from "tree-sitter"; -import Typescript from "tree-sitter-typescript"; -import { getTypescriptImports } from "./imports"; - -describe("Should extract imports identifiers from the source code", () => { - it("Should extract import specifier", () => { - const parser = new Parser(); - parser.setLanguage(Typescript.typescript); - - const tree = parser.parse(` -import { type Controller, Get } from '@nestjs/common'; -import { type test1, test2 } from './test'; - `); - - const imports = getTypescriptImports(parser, tree.rootNode); - - expect(imports.length).toBe(2); - - expect(imports[0].source).toBe("@nestjs/common"); - expect(imports[0].importIdentifier).toBe(undefined); - expect(imports[0].importSpecifierIdentifiers.length).toBe(2); - expect(imports[0].importSpecifierIdentifiers[0].text).toBe("Controller"); - expect(imports[0].importSpecifierIdentifiers[1].text).toBe("Get"); - - expect(imports[1].source).toBe("./test"); - expect(imports[1].importIdentifier).toBe(undefined); - expect(imports[1].importSpecifierIdentifiers.length).toBe(2); - expect(imports[1].importSpecifierIdentifiers[0].text).toBe("test1"); - expect(imports[1].importSpecifierIdentifiers[1].text).toBe("test2"); - }); - - it("Should extract import identifier", () => { - const parser = new Parser(); - parser.setLanguage(Typescript.typescript); - - const tree = parser.parse(` -import common from '@nestjs/common'; -import * as test from './test'; -`); - - const imports = getTypescriptImports(parser, tree.rootNode); - - expect(imports.length).toBe(2); - - expect(imports[0].source).toBe("@nestjs/common"); - expect(imports[0].importIdentifier).not.toBe(undefined); - expect(imports[0].importIdentifier?.text).toBe("common"); - expect(imports[0].namespaceImport).toBe(undefined); - expect(imports[0].importSpecifierIdentifiers.length).toBe(0); - - expect(imports[1].source).toBe("./test"); - expect(imports[1].importIdentifier).toBe(undefined); - expect(imports[1].namespaceImport).not.toBe(undefined); - expect(imports[1].namespaceImport?.text).toBe("test"); - expect(imports[1].importSpecifierIdentifiers.length).toBe(0); - }); - - // it("Should work with require import", () => { - // const parser = new Parser(); - // parser.setLanguage(Typescript.typescript); - - // const tree = parser.parse(` - // const { type test1, test2 } = require('@nestjs/common'); - // const test = require('./test'); - // `); - - // const imports = getTypescriptImports(parser, tree.rootNode); - - // expect(imports.length).toBe(2); - - // expect(imports[0].source).toBe("@nestjs/common"); - // expect(imports[0].importIdentifier).toBe(undefined); - // expect(imports[0].importSpecifierIdentifiers.length).toBe(2); - // expect(imports[0].importSpecifierIdentifiers[0].text).toBe("test1"); - // expect(imports[0].importSpecifierIdentifiers[1].text).toBe("test2"); - - // expect(imports[1].source).toBe("./test"); - // expect(imports[1].importIdentifier).not.toBe(undefined); - // expect(imports[1].importIdentifier?.text).toBe("test"); - // expect(imports[1].importSpecifierIdentifiers.length).toBe(0); - // }); - - // it("Should work with dynamic import", () => { - // const parser = new Parser(); - // parser.setLanguage(Typescript.typescript); - - // const tree = parser.parse(` - // const { type test1, test2 } = import('@nestjs/common'); - // const test = import('./test'); - // `); - - // const imports = getTypescriptImports(parser, tree.rootNode); - - // expect(imports.length).toBe(2); - - // expect(imports[0].source).toBe("@nestjs/common"); - // expect(imports[0].importIdentifier).toBe(undefined); - // expect(imports[0].importSpecifierIdentifiers.length).toBe(2); - // expect(imports[0].importSpecifierIdentifiers[0].text).toBe("test1"); - // expect(imports[0].importSpecifierIdentifiers[1].text).toBe("test2"); - - // expect(imports[1].source).toBe("./test"); - // expect(imports[1].importIdentifier).not.toBe(undefined); - // expect(imports[1].importIdentifier?.text).toBe("test"); - // expect(imports[1].importSpecifierIdentifiers.length).toBe(0); - // }); -}); diff --git a/packages/cli/src/languages/index.ts b/packages/cli/src/languagesPlugins/index.ts similarity index 100% rename from packages/cli/src/languages/index.ts rename to packages/cli/src/languagesPlugins/index.ts diff --git a/packages/cli/src/languages/javascript.ts b/packages/cli/src/languagesPlugins/javascript.ts similarity index 100% rename from packages/cli/src/languages/javascript.ts rename to packages/cli/src/languagesPlugins/javascript.ts diff --git a/packages/cli/src/languages/types.ts b/packages/cli/src/languagesPlugins/types.ts similarity index 100% rename from packages/cli/src/languages/types.ts rename to packages/cli/src/languagesPlugins/types.ts diff --git a/packages/cli/src/languages/typescript.ts b/packages/cli/src/languagesPlugins/typescript.ts similarity index 100% rename from packages/cli/src/languages/typescript.ts rename to packages/cli/src/languagesPlugins/typescript.ts diff --git a/packages/cli/src/splitRunner/splitRunner.ts b/packages/cli/src/splitRunner/splitRunner.ts index 819aa99..1d4963c 100644 --- a/packages/cli/src/splitRunner/splitRunner.ts +++ b/packages/cli/src/splitRunner/splitRunner.ts @@ -5,7 +5,7 @@ import { ExportMap, File } from "./types"; import Parser from "tree-sitter"; import assert from "assert"; import { resolveFilePath } from "../helper/file"; -import { getLanguagePluginFromFilePath } from "../languages"; +import { getLanguagePluginFromFilePath } from "../languagesPlugins"; class SplitRunner { private dependencyTreeManager: DependencyTreeManager;