@teambit/typescript 0.0.738 → 0.0.741
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/exceptions/transformer-not-found.d.ts +2 -1
- package/dist/exceptions/transformer-not-found.js +3 -2
- package/dist/exceptions/transformer-not-found.js.map +1 -1
- package/dist/schema-extractor-context.d.ts +8 -7
- package/dist/schema-extractor-context.js +49 -21
- package/dist/schema-extractor-context.js.map +1 -1
- package/dist/transformers/class-deceleration.js +9 -1
- package/dist/transformers/class-deceleration.js.map +1 -1
- package/dist/transformers/enum-declaration.d.ts +10 -0
- package/dist/transformers/enum-declaration.js +60 -0
- package/dist/transformers/enum-declaration.js.map +1 -0
- package/dist/transformers/export-declaration.js +9 -2
- package/dist/transformers/export-declaration.js.map +1 -1
- package/dist/transformers/index.d.ts +1 -0
- package/dist/transformers/index.js +16 -0
- package/dist/transformers/index.js.map +1 -1
- package/dist/transformers/property-signature.js +5 -20
- package/dist/transformers/property-signature.js.map +1 -1
- package/dist/transformers/type-alias.js +2 -5
- package/dist/transformers/type-alias.js.map +1 -1
- package/dist/transformers/utils/get-params.js +53 -7
- package/dist/transformers/utils/get-params.js.map +1 -1
- package/dist/transformers/utils/parse-type-from-quick-info.d.ts +1 -0
- package/dist/transformers/utils/parse-type-from-quick-info.js +12 -3
- package/dist/transformers/utils/parse-type-from-quick-info.js.map +1 -1
- package/dist/transformers/utils/type-node-to-schema.js +52 -6
- package/dist/transformers/utils/type-node-to-schema.js.map +1 -1
- package/dist/typescript.extractor.d.ts +7 -1
- package/dist/typescript.extractor.js +30 -9
- package/dist/typescript.extractor.js.map +1 -1
- package/dist/typescript.main.runtime.d.ts +11 -2
- package/dist/typescript.main.runtime.js +17 -6
- package/dist/typescript.main.runtime.js.map +1 -1
- package/exceptions/transformer-not-found.ts +4 -2
- package/package-tar/teambit-typescript-0.0.741.tgz +0 -0
- package/package.json +16 -15
- package/{preview-1653227849497.js → preview-1653494536947.js} +2 -2
- package/transformers/class-deceleration.ts +4 -1
- package/transformers/enum-declaration.ts +20 -0
- package/transformers/export-declaration.ts +7 -2
- package/transformers/index.ts +1 -0
- package/transformers/property-signature.ts +2 -8
- package/transformers/type-alias.ts +2 -3
- package/transformers/utils/get-params.ts +53 -9
- package/transformers/utils/parse-type-from-quick-info.ts +9 -1
- package/transformers/utils/type-node-to-schema.ts +57 -6
- package/package-tar/teambit-typescript-0.0.738.tgz +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["TypeScriptExtractor","constructor","tsconfig","schemaTransformerSlot","tsMain","rootPath","undefined","parseSourceFile","file","ts","createSourceFile","path","contents","toString","ScriptTarget","Latest","compilerOptions","extract","component","tsserver","getTsServer","mainFile","mainAst","context","createContext","exportNames","computeExportedIdentifiers","setExports","ExportList","moduleSchema","computeSchema","flatExportsRecursively","apiScheme","location","getLocation","APISchema","node","transformer","getTransformer","getIdentifiers","TransformerNotFound","SchemaExtractorContext","getTsserverClient","initTsserverClient","transform","transformers","flatten","values","find","singleTransformer","predicate"],"sources":["typescript.extractor.ts"],"sourcesContent":["import ts, { Node } from 'typescript';\nimport { SchemaExtractor } from '@teambit/schema';\nimport { TsserverClient } from '@teambit/ts-server';\nimport { SchemaNode, APISchema, Module } from '@teambit/semantics.entities.semantic-schema';\nimport { Component } from '@teambit/component';\
|
|
1
|
+
{"version":3,"names":["TypeScriptExtractor","constructor","tsconfig","schemaTransformerSlot","tsMain","rootPath","depResolver","workspace","undefined","parseSourceFile","file","ts","createSourceFile","path","contents","toString","ScriptTarget","Latest","compilerOptions","extract","component","tsserver","getTsServer","mainFile","mainAst","context","createContext","exportNames","computeExportedIdentifiers","setExports","ExportList","moduleSchema","computeSchema","flatExportsRecursively","apiScheme","location","getLocation","APISchema","node","transformer","getTransformer","getIdentifiers","TransformerNotFound","componentDeps","getComponentDeps","SchemaExtractorContext","deps","getDependencies","getComponentDependencies","getTsserverClient","initTsserverClient","transform","getComponentIDByPath","getComponentIdByPath","transformers","flatten","values","find","singleTransformer","predicate"],"sources":["typescript.extractor.ts"],"sourcesContent":["import ts, { Node } from 'typescript';\nimport { SchemaExtractor } from '@teambit/schema';\nimport { TsserverClient } from '@teambit/ts-server';\nimport type { Workspace } from '@teambit/workspace';\nimport { ComponentDependency, DependencyResolverMain } from '@teambit/dependency-resolver';\nimport { SchemaNode, APISchema, Module } from '@teambit/semantics.entities.semantic-schema';\nimport { Component } from '@teambit/component';\nimport { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport { flatten } from 'lodash';\nimport { TypescriptMain, SchemaTransformerSlot } from './typescript.main.runtime';\nimport { TransformerNotFound } from './exceptions';\nimport { SchemaExtractorContext } from './schema-extractor-context';\nimport { ExportList } from './export-list';\n\nexport class TypeScriptExtractor implements SchemaExtractor {\n constructor(\n private tsconfig: any,\n private schemaTransformerSlot: SchemaTransformerSlot,\n private tsMain: TypescriptMain,\n private rootPath: string,\n private depResolver: DependencyResolverMain,\n private workspace: Workspace | undefined\n ) {}\n\n parseSourceFile(file: AbstractVinyl) {\n return ts.createSourceFile(\n file.path,\n file.contents.toString('utf8'),\n ts.ScriptTarget.Latest,\n true,\n this.tsconfig.compilerOptions\n );\n }\n\n /**\n * extract a component schema.\n */\n async extract(component: Component): Promise<APISchema> {\n const tsserver = await this.getTsServer();\n const mainFile = component.mainFile;\n const mainAst = this.parseSourceFile(mainFile);\n const context = await this.createContext(tsserver, component);\n const exportNames = await this.computeExportedIdentifiers(mainAst, context);\n context.setExports(new ExportList(exportNames));\n const moduleSchema = (await this.computeSchema(mainAst, context)) as Module;\n moduleSchema.flatExportsRecursively();\n const apiScheme = moduleSchema;\n const location = context.getLocation(mainAst);\n\n return new APISchema(location, apiScheme);\n }\n\n async computeExportedIdentifiers(node: Node, context: SchemaExtractorContext) {\n const transformer = this.getTransformer(node, context);\n if (!transformer || !transformer.getIdentifiers) {\n throw new TransformerNotFound(node, context.component, context.getLocation(node));\n }\n return transformer.getIdentifiers(node, context);\n }\n\n private async createContext(tsserver: TsserverClient, component: Component): Promise<SchemaExtractorContext> {\n const componentDeps = await this.getComponentDeps(component);\n return new SchemaExtractorContext(tsserver, component, this, componentDeps);\n }\n\n private async getComponentDeps(component: Component): Promise<ComponentDependency[]> {\n const deps = await this.depResolver.getDependencies(component);\n const componentDeps = deps.getComponentDependencies();\n return componentDeps;\n }\n\n private tsserver: TsserverClient | undefined = undefined;\n\n private async getTsServer() {\n if (!this.tsserver) {\n const tsserver = this.tsMain.getTsserverClient();\n if (tsserver) {\n this.tsserver = tsserver;\n return tsserver;\n }\n\n this.tsserver = await this.tsMain.initTsserverClient(this.rootPath);\n return this.tsserver;\n }\n\n return this.tsserver;\n }\n\n async computeSchema(node: Node, context: SchemaExtractorContext): Promise<SchemaNode> {\n const transformer = this.getTransformer(node, context);\n // leave the next line commented out, it is used for debugging\n // console.log('transformer', transformer.constructor.name, node.getText());\n return transformer.transform(node, context);\n }\n\n async getComponentIDByPath(file: string) {\n if (!this.workspace) {\n return null;\n }\n return this.workspace.getComponentIdByPath(file);\n }\n\n /**\n * select the correct transformer for a node.\n */\n private getTransformer(node: Node, context: SchemaExtractorContext) {\n const transformers = flatten(this.schemaTransformerSlot.values());\n const transformer = transformers.find((singleTransformer) => singleTransformer.predicate(node));\n\n if (!transformer) throw new TransformerNotFound(node, context.component, context.getLocation(node));\n\n return transformer;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAKA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEO,MAAMA,mBAAN,CAAqD;EAC1DC,WAAW,CACDC,QADC,EAEDC,qBAFC,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B,MAAbW,aAAa,CAACM,IAAD,EAAab,OAAb,EAAmE;IACpF,MAAMc,WAAW,GAAG,KAAKC,cAAL,CAAoBF,IAApB,EAA0Bb,OAA1B,CAApB,CADoF,CAEpF;IACA;;IACA,OAAOc,WAAW,CAACY,SAAZ,CAAsBb,IAAtB,EAA4Bb,OAA5B,CAAP;EACD;;EAEyB,MAApB2B,oBAAoB,CAAC1C,IAAD,EAAe;IACvC,IAAI,CAAC,KAAKH,SAAV,EAAqB;MACnB,OAAO,IAAP;IACD;;IACD,OAAO,KAAKA,SAAL,CAAe8C,oBAAf,CAAoC3C,IAApC,CAAP;EACD;EAED;AACF;AACA;;;EACU8B,cAAc,CAACF,IAAD,EAAab,OAAb,EAA8C;IAClE,MAAM6B,YAAY,GAAG,IAAAC,iBAAA,EAAQ,KAAKpD,qBAAL,CAA2BqD,MAA3B,EAAR,CAArB;IACA,MAAMjB,WAAW,GAAGe,YAAY,CAACG,IAAb,CAAmBC,iBAAD,IAAuBA,iBAAiB,CAACC,SAAlB,CAA4BrB,IAA5B,CAAzC,CAApB;IAEA,IAAI,CAACC,WAAL,EAAkB,MAAM,KAAIG,iCAAJ,EAAwBJ,IAAxB,EAA8Bb,OAAO,CAACL,SAAtC,EAAiDK,OAAO,CAACW,WAAR,CAAoBE,IAApB,CAAjD,CAAN;IAElB,OAAOC,WAAP;EACD;;AAlGyD"}
|
|
@@ -7,6 +7,7 @@ import { SchemaExtractor, SchemaMain } from '@teambit/schema';
|
|
|
7
7
|
import { PackageJsonProps } from '@teambit/pkg';
|
|
8
8
|
import { TypescriptConfigMutator } from '@teambit/typescript.modules.ts-config-mutator';
|
|
9
9
|
import type { Workspace } from '@teambit/workspace';
|
|
10
|
+
import { DependencyResolverMain } from '@teambit/dependency-resolver';
|
|
10
11
|
import { TsserverClient, TsserverClientOpts } from '@teambit/ts-server';
|
|
11
12
|
import { AspectLoaderMain } from '@teambit/aspect-loader';
|
|
12
13
|
import type { Component } from '@teambit/component';
|
|
@@ -20,7 +21,8 @@ export declare class TypescriptMain {
|
|
|
20
21
|
private logger;
|
|
21
22
|
private schemaTransformerSlot;
|
|
22
23
|
private workspace;
|
|
23
|
-
|
|
24
|
+
private depResolver;
|
|
25
|
+
constructor(logger: Logger, schemaTransformerSlot: SchemaTransformerSlot, workspace: Workspace, depResolver: DependencyResolverMain);
|
|
24
26
|
private tsServer;
|
|
25
27
|
/**
|
|
26
28
|
* create a new compiler.
|
|
@@ -91,6 +93,13 @@ export declare class TypescriptMain {
|
|
|
91
93
|
static runtime: import("@teambit/harmony").RuntimeDefinition;
|
|
92
94
|
static dependencies: import("@teambit/harmony").Aspect[];
|
|
93
95
|
static slots: ((registerFn: () => string) => SlotRegistry<SchemaTransformer[]>)[];
|
|
94
|
-
static provider([schema, loggerExt, aspectLoader, workspace, cli
|
|
96
|
+
static provider([schema, loggerExt, aspectLoader, workspace, cli, depResolver]: [
|
|
97
|
+
SchemaMain,
|
|
98
|
+
LoggerMain,
|
|
99
|
+
AspectLoaderMain,
|
|
100
|
+
Workspace,
|
|
101
|
+
CLIMain,
|
|
102
|
+
DependencyResolverMain
|
|
103
|
+
], config: any, [schemaTransformerSlot]: [SchemaTransformerSlot]): Promise<TypescriptMain>;
|
|
95
104
|
}
|
|
96
105
|
export declare function runTransformersWithContext(config: TypescriptConfigMutator, transformers: TsConfigTransformer[] | undefined, context: TsConfigTransformContext): TypescriptConfigMutator;
|
|
@@ -96,6 +96,16 @@ function _workspace() {
|
|
|
96
96
|
return data;
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
+
function _dependencyResolver() {
|
|
100
|
+
const data = require("@teambit/dependency-resolver");
|
|
101
|
+
|
|
102
|
+
_dependencyResolver = function () {
|
|
103
|
+
return data;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
return data;
|
|
107
|
+
}
|
|
108
|
+
|
|
99
109
|
function _pMapSeries() {
|
|
100
110
|
const data = _interopRequireDefault(require("p-map-series"));
|
|
101
111
|
|
|
@@ -197,10 +207,11 @@ function _checkTypes() {
|
|
|
197
207
|
}
|
|
198
208
|
|
|
199
209
|
class TypescriptMain {
|
|
200
|
-
constructor(logger, schemaTransformerSlot, workspace) {
|
|
210
|
+
constructor(logger, schemaTransformerSlot, workspace, depResolver) {
|
|
201
211
|
this.logger = logger;
|
|
202
212
|
this.schemaTransformerSlot = schemaTransformerSlot;
|
|
203
213
|
this.workspace = workspace;
|
|
214
|
+
this.depResolver = depResolver;
|
|
204
215
|
(0, _defineProperty2().default)(this, "tsServer", void 0);
|
|
205
216
|
}
|
|
206
217
|
|
|
@@ -308,7 +319,7 @@ class TypescriptMain {
|
|
|
308
319
|
|
|
309
320
|
|
|
310
321
|
createSchemaExtractor(tsconfig, path) {
|
|
311
|
-
return new (_typescript2().TypeScriptExtractor)(tsconfig, this.schemaTransformerSlot, this, path || this.workspace.path);
|
|
322
|
+
return new (_typescript2().TypeScriptExtractor)(tsconfig, this.schemaTransformerSlot, this, path || this.workspace.path, this.depResolver, this.workspace);
|
|
312
323
|
}
|
|
313
324
|
/**
|
|
314
325
|
* add the default package json properties to the component
|
|
@@ -375,12 +386,12 @@ class TypescriptMain {
|
|
|
375
386
|
};
|
|
376
387
|
}
|
|
377
388
|
|
|
378
|
-
static async provider([schema, loggerExt, aspectLoader, workspace, cli], config, [schemaTransformerSlot]) {
|
|
389
|
+
static async provider([schema, loggerExt, aspectLoader, workspace, cli, depResolver], config, [schemaTransformerSlot]) {
|
|
379
390
|
schema.registerParser(new (_typescript5().TypeScriptParser)());
|
|
380
391
|
const logger = loggerExt.createLogger(_typescript3().TypescriptAspect.id);
|
|
381
392
|
aspectLoader.registerPlugins([new (_schemaTransformer().SchemaTransformerPlugin)(schemaTransformerSlot)]);
|
|
382
|
-
const tsMain = new TypescriptMain(logger, schemaTransformerSlot, workspace);
|
|
383
|
-
schemaTransformerSlot.register([new (_transformers().ExportDeclaration)(), new (_transformers().FunctionDeclaration)(), new (_transformers().MethodDeclaration)(), new (_transformers().PropertyDeclaration)(), new (_transformers().VariableStatementTransformer)(), new (_transformers().VariableDeclaration)(), new (_transformers().Constructor)(), new (_transformers().SourceFileTransformer)(), new (_transformers().TypeAliasTransformer)(), new (_transformers().ClassDecelerationTransformer)(), new (_transformers().PropertySignature)(), new (_transformers().LiteralTypeTransformer)(), new (_transformers().IndexSignature)(), new (_transformers().InterfaceDeclarationTransformer)(), new (_transformers().MethodSignatureTransformer)()]);
|
|
393
|
+
const tsMain = new TypescriptMain(logger, schemaTransformerSlot, workspace, depResolver);
|
|
394
|
+
schemaTransformerSlot.register([new (_transformers().ExportDeclaration)(), new (_transformers().FunctionDeclaration)(), new (_transformers().MethodDeclaration)(), new (_transformers().PropertyDeclaration)(), new (_transformers().VariableStatementTransformer)(), new (_transformers().VariableDeclaration)(), new (_transformers().Constructor)(), new (_transformers().SourceFileTransformer)(), new (_transformers().TypeAliasTransformer)(), new (_transformers().ClassDecelerationTransformer)(), new (_transformers().PropertySignature)(), new (_transformers().LiteralTypeTransformer)(), new (_transformers().IndexSignature)(), new (_transformers().InterfaceDeclarationTransformer)(), new (_transformers().MethodSignatureTransformer)(), new (_transformers().EnumDeclarationTransformer)()]);
|
|
384
395
|
|
|
385
396
|
if (workspace) {
|
|
386
397
|
workspace.registerOnPreWatch(tsMain.onPreWatch.bind(this));
|
|
@@ -397,7 +408,7 @@ class TypescriptMain {
|
|
|
397
408
|
|
|
398
409
|
exports.TypescriptMain = TypescriptMain;
|
|
399
410
|
(0, _defineProperty2().default)(TypescriptMain, "runtime", _cli().MainRuntime);
|
|
400
|
-
(0, _defineProperty2().default)(TypescriptMain, "dependencies", [_schema().SchemaAspect, _logger().LoggerAspect, _aspectLoader().default, _workspace().WorkspaceAspect, _cli().CLIAspect]);
|
|
411
|
+
(0, _defineProperty2().default)(TypescriptMain, "dependencies", [_schema().SchemaAspect, _logger().LoggerAspect, _aspectLoader().default, _workspace().WorkspaceAspect, _cli().CLIAspect, _dependencyResolver().DependencyResolverAspect]);
|
|
401
412
|
(0, _defineProperty2().default)(TypescriptMain, "slots", [_harmony().Slot.withType()]);
|
|
402
413
|
|
|
403
414
|
_typescript3().TypescriptAspect.addRuntime(TypescriptMain);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["TypescriptMain","constructor","logger","schemaTransformerSlot","workspace","createCompiler","options","transformers","tsModule","ts","configMutator","TypescriptConfigMutator","transformerContext","afterMutation","runTransformersWithContext","clone","TypescriptCompiler","TypescriptAspect","id","raw","getTsserverClient","tsServer","initTsserverClient","projectPath","files","TsserverClient","init","initTsserverClientFromWorkspace","Error","path","createCjsCompiler","getCjsTransformer","createEsmCompiler","getEsmTransformer","cjsTransformer","config","setModule","esmTransformer","createSchemaExtractor","tsconfig","TypeScriptExtractor","getCjsPackageJsonProps","main","types","getEsmPackageJsonProps","type","getSupportedFilesForTsserver","components","map","c","filesystem","flat","f","filter","endsWith","onPreWatch","watchOpts","spawnTSServer","verbose","checkTypes","printTypeErrors","Boolean","onComponentChange","component","results","pMapSeries","file","onFileChange","provider","schema","loggerExt","aspectLoader","cli","registerParser","TypeScriptParser","createLogger","registerPlugins","SchemaTransformerPlugin","tsMain","register","ExportDeclaration","FunctionDeclaration","MethodDeclaration","PropertyDeclaration","VariableStatementTransformer","VariableDeclaration","Constructor","SourceFileTransformer","TypeAliasTransformer","ClassDecelerationTransformer","PropertySignature","LiteralTypeTransformer","IndexSignature","InterfaceDeclarationTransformer","MethodSignatureTransformer","registerOnPreWatch","bind","registerOnComponentChange","registerOnComponentAdd","checkTypesCmd","CheckTypesCmd","MainRuntime","SchemaAspect","LoggerAspect","AspectLoaderAspect","WorkspaceAspect","CLIAspect","Slot","withType","addRuntime","context","Array","isArray","newConfig","reduce","acc","transformer"],"sources":["typescript.main.runtime.ts"],"sourcesContent":["import ts from 'typescript';\nimport { Slot, SlotRegistry } from '@teambit/harmony';\nimport { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';\nimport { Compiler } from '@teambit/compiler';\nimport { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';\nimport { SchemaAspect, SchemaExtractor, SchemaMain } from '@teambit/schema';\nimport { PackageJsonProps } from '@teambit/pkg';\nimport { TypescriptConfigMutator } from '@teambit/typescript.modules.ts-config-mutator';\nimport { WorkspaceAspect } from '@teambit/workspace';\nimport type { WatchOptions, Workspace } from '@teambit/workspace';\nimport pMapSeries from 'p-map-series';\nimport { TsserverClient, TsserverClientOpts } from '@teambit/ts-server';\nimport AspectLoaderAspect, { AspectLoaderMain } from '@teambit/aspect-loader';\nimport type { Component } from '@teambit/component';\nimport { TypeScriptExtractor } from './typescript.extractor';\nimport { TypeScriptCompilerOptions } from './compiler-options';\nimport { TypescriptAspect } from './typescript.aspect';\nimport { TypescriptCompiler } from './typescript.compiler';\nimport { TypeScriptParser } from './typescript.parser';\nimport { SchemaTransformer } from './schema-transformer';\nimport { SchemaTransformerPlugin } from './schema-transformer.plugin';\nimport {\n ExportDeclaration,\n TypeAliasTransformer,\n FunctionDeclaration,\n MethodDeclaration,\n PropertyDeclaration,\n VariableStatementTransformer,\n VariableDeclaration,\n SourceFileTransformer,\n ClassDecelerationTransformer,\n Constructor,\n PropertySignature,\n LiteralTypeTransformer,\n IndexSignature,\n InterfaceDeclarationTransformer,\n MethodSignatureTransformer,\n} from './transformers';\nimport { CheckTypesCmd } from './cmds/check-types.cmd';\n\nexport type TsMode = 'build' | 'dev';\n\nexport type SchemaTransformerSlot = SlotRegistry<SchemaTransformer[]>;\n\nexport type TsConfigTransformContext = {\n // mode: TsMode;\n};\n\nexport type TsConfigTransformer = (\n config: TypescriptConfigMutator,\n context: TsConfigTransformContext\n) => TypescriptConfigMutator;\n\nexport class TypescriptMain {\n constructor(\n private logger: Logger,\n private schemaTransformerSlot: SchemaTransformerSlot,\n private workspace: Workspace\n ) {}\n\n private tsServer: TsserverClient;\n /**\n * create a new compiler.\n */\n createCompiler(\n options: TypeScriptCompilerOptions,\n transformers: TsConfigTransformer[] = [],\n tsModule = ts\n ): Compiler {\n const configMutator = new TypescriptConfigMutator(options);\n const transformerContext: TsConfigTransformContext = {};\n const afterMutation = runTransformersWithContext(configMutator.clone(), transformers, transformerContext);\n return new TypescriptCompiler(TypescriptAspect.id, this.logger, afterMutation.raw, tsModule);\n }\n\n /**\n * get TsserverClient instance if initiated already, otherwise, return undefined.\n */\n getTsserverClient(): TsserverClient | undefined {\n return this.tsServer;\n }\n\n /**\n * starts a tsserver process to communicate with its API.\n * @param projectPath absolute path of the project root directory\n * @param options TsserverClientOpts\n * @param files optionally, if check-types is enabled, provide files to open and type check.\n * @returns TsserverClient\n */\n async initTsserverClient(\n projectPath: string,\n options: TsserverClientOpts = {},\n files: string[] = []\n ): Promise<TsserverClient> {\n this.tsServer = new TsserverClient(projectPath, this.logger, options, files);\n this.tsServer.init();\n return this.tsServer;\n }\n\n /**\n * starts a tsserver process to communicate with its API. use only when running on the workspace.\n * @param options TsserverClientOpts\n * @param files optionally, if check-types is enabled, provide files to open and type check.\n * @returns TsserverClient\n */\n async initTsserverClientFromWorkspace(\n options: TsserverClientOpts = {},\n files: string[] = []\n ): Promise<TsserverClient> {\n if (!this.workspace) {\n throw new Error(`initTsserverClientFromWorkspace: workspace was not found`);\n }\n return this.initTsserverClient(this.workspace.path, options, files);\n }\n\n /**\n * Create a compiler instance and run the cjs transformer for it\n * @param options\n * @param transformers\n * @param tsModule\n * @returns\n */\n createCjsCompiler(options: TypeScriptCompilerOptions, transformers: TsConfigTransformer[] = [], tsModule = ts) {\n return this.createCompiler(options, [this.getCjsTransformer(), ...transformers], tsModule);\n }\n\n /**\n * Create a compiler instance and run the esm transformer for it\n * @param options\n * @param transformers\n * @param tsModule\n * @returns\n */\n createEsmCompiler(options: TypeScriptCompilerOptions, transformers: TsConfigTransformer[] = [], tsModule = ts) {\n return this.createCompiler(options, [this.getEsmTransformer(), ...transformers], tsModule);\n }\n\n /**\n * Create a transformer that change the ts module to CommonJS\n * @returns\n */\n getCjsTransformer(): TsConfigTransformer {\n const cjsTransformer = (config: TypescriptConfigMutator) => {\n config.setModule('CommonJS');\n return config;\n };\n return cjsTransformer;\n }\n\n /**\n * Create a transformer that change the ts module to ES2020\n * @returns\n */\n getEsmTransformer(): TsConfigTransformer {\n const esmTransformer = (config: TypescriptConfigMutator) => {\n config.setModule('ES2020');\n return config;\n };\n return esmTransformer;\n }\n\n /**\n * create an instance of a typescript semantic schema extractor.\n */\n createSchemaExtractor(tsconfig: any, path?: string): SchemaExtractor {\n return new TypeScriptExtractor(tsconfig, this.schemaTransformerSlot, this, path || this.workspace.path);\n }\n\n /**\n * add the default package json properties to the component\n * :TODO @gilad why do we need this DSL? can't I just get the args here.\n */\n getCjsPackageJsonProps(): PackageJsonProps {\n return {\n main: 'dist/{main}.js',\n types: '{main}.ts',\n };\n }\n\n /**\n * add type: module to the package.json props and the default props\n * :TODO @gilad why do we need this DSL? can't I just get the args here.\n */\n getEsmPackageJsonProps(): PackageJsonProps {\n return {\n // main: 'dist-esm/{main}.js',\n main: 'dist/{main}.js',\n type: 'module',\n types: '{main}.ts',\n };\n }\n\n public getSupportedFilesForTsserver(components: Component[]): string[] {\n const files = components\n .map((c) => c.filesystem.files)\n .flat()\n .map((f) => f.path);\n return files.filter((f) => f.endsWith('.ts') || f.endsWith('.tsx'));\n }\n\n private async onPreWatch(components: Component[], watchOpts: WatchOptions) {\n const workspace = this.workspace;\n if (!workspace || !watchOpts.spawnTSServer) {\n return;\n }\n const { verbose, checkTypes } = watchOpts;\n const files = checkTypes ? this.getSupportedFilesForTsserver(components) : [];\n const printTypeErrors = Boolean(checkTypes);\n await this.initTsserverClientFromWorkspace({ verbose, checkTypes, printTypeErrors }, files);\n }\n\n private async onComponentChange(component: Component, files: string[]) {\n if (!this.tsServer) {\n return {\n results: 'N/A',\n };\n }\n await pMapSeries(files, (file) => this.tsServer.onFileChange(file));\n return {\n results: 'succeed',\n };\n }\n\n static runtime = MainRuntime;\n static dependencies = [SchemaAspect, LoggerAspect, AspectLoaderAspect, WorkspaceAspect, CLIAspect];\n static slots = [Slot.withType<SchemaTransformer[]>()];\n\n static async provider(\n [schema, loggerExt, aspectLoader, workspace, cli]: [SchemaMain, LoggerMain, AspectLoaderMain, Workspace, CLIMain],\n config,\n [schemaTransformerSlot]: [SchemaTransformerSlot]\n ) {\n schema.registerParser(new TypeScriptParser());\n const logger = loggerExt.createLogger(TypescriptAspect.id);\n aspectLoader.registerPlugins([new SchemaTransformerPlugin(schemaTransformerSlot)]);\n const tsMain = new TypescriptMain(logger, schemaTransformerSlot, workspace);\n schemaTransformerSlot.register([\n new ExportDeclaration(),\n new FunctionDeclaration(),\n new MethodDeclaration(),\n new PropertyDeclaration(),\n new VariableStatementTransformer(),\n new VariableDeclaration(),\n new Constructor(),\n new SourceFileTransformer(),\n new TypeAliasTransformer(),\n new ClassDecelerationTransformer(),\n new PropertySignature(),\n new LiteralTypeTransformer(),\n new IndexSignature(),\n new InterfaceDeclarationTransformer(),\n new MethodSignatureTransformer(),\n ]);\n\n if (workspace) {\n workspace.registerOnPreWatch(tsMain.onPreWatch.bind(this));\n workspace.registerOnComponentChange(tsMain.onComponentChange.bind(this));\n workspace.registerOnComponentAdd(tsMain.onComponentChange.bind(this));\n }\n\n const checkTypesCmd = new CheckTypesCmd(tsMain, workspace, logger);\n cli.register(checkTypesCmd);\n\n return tsMain;\n }\n}\n\nTypescriptAspect.addRuntime(TypescriptMain);\n\nexport function runTransformersWithContext(\n config: TypescriptConfigMutator,\n transformers: TsConfigTransformer[] = [],\n context: TsConfigTransformContext\n): TypescriptConfigMutator {\n if (!Array.isArray(transformers)) return config;\n const newConfig = transformers.reduce((acc, transformer) => {\n return transformer(acc, context);\n }, config);\n return newConfig;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAA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,0BAAT,CACLqB,MADK,EAEL5B,YAAmC,GAAG,EAFjC,EAGLuG,OAHK,EAIoB;EACzB,IAAI,CAACC,KAAK,CAACC,OAAN,CAAczG,YAAd,CAAL,EAAkC,OAAO4B,MAAP;EAClC,MAAM8E,SAAS,GAAG1G,YAAY,CAAC2G,MAAb,CAAoB,CAACC,GAAD,EAAMC,WAAN,KAAsB;IAC1D,OAAOA,WAAW,CAACD,GAAD,EAAML,OAAN,CAAlB;EACD,CAFiB,EAEf3E,MAFe,CAAlB;EAGA,OAAO8E,SAAP;AACD"}
|
|
1
|
+
{"version":3,"names":["TypescriptMain","constructor","logger","schemaTransformerSlot","workspace","depResolver","createCompiler","options","transformers","tsModule","ts","configMutator","TypescriptConfigMutator","transformerContext","afterMutation","runTransformersWithContext","clone","TypescriptCompiler","TypescriptAspect","id","raw","getTsserverClient","tsServer","initTsserverClient","projectPath","files","TsserverClient","init","initTsserverClientFromWorkspace","Error","path","createCjsCompiler","getCjsTransformer","createEsmCompiler","getEsmTransformer","cjsTransformer","config","setModule","esmTransformer","createSchemaExtractor","tsconfig","TypeScriptExtractor","getCjsPackageJsonProps","main","types","getEsmPackageJsonProps","type","getSupportedFilesForTsserver","components","map","c","filesystem","flat","f","filter","endsWith","onPreWatch","watchOpts","spawnTSServer","verbose","checkTypes","printTypeErrors","Boolean","onComponentChange","component","results","pMapSeries","file","onFileChange","provider","schema","loggerExt","aspectLoader","cli","registerParser","TypeScriptParser","createLogger","registerPlugins","SchemaTransformerPlugin","tsMain","register","ExportDeclaration","FunctionDeclaration","MethodDeclaration","PropertyDeclaration","VariableStatementTransformer","VariableDeclaration","Constructor","SourceFileTransformer","TypeAliasTransformer","ClassDecelerationTransformer","PropertySignature","LiteralTypeTransformer","IndexSignature","InterfaceDeclarationTransformer","MethodSignatureTransformer","EnumDeclarationTransformer","registerOnPreWatch","bind","registerOnComponentChange","registerOnComponentAdd","checkTypesCmd","CheckTypesCmd","MainRuntime","SchemaAspect","LoggerAspect","AspectLoaderAspect","WorkspaceAspect","CLIAspect","DependencyResolverAspect","Slot","withType","addRuntime","context","Array","isArray","newConfig","reduce","acc","transformer"],"sources":["typescript.main.runtime.ts"],"sourcesContent":["import ts from 'typescript';\nimport { Slot, SlotRegistry } from '@teambit/harmony';\nimport { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';\nimport { Compiler } from '@teambit/compiler';\nimport { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';\nimport { SchemaAspect, SchemaExtractor, SchemaMain } from '@teambit/schema';\nimport { PackageJsonProps } from '@teambit/pkg';\nimport { TypescriptConfigMutator } from '@teambit/typescript.modules.ts-config-mutator';\nimport { WorkspaceAspect } from '@teambit/workspace';\nimport type { WatchOptions, Workspace } from '@teambit/workspace';\nimport { DependencyResolverAspect, DependencyResolverMain } from '@teambit/dependency-resolver';\nimport pMapSeries from 'p-map-series';\nimport { TsserverClient, TsserverClientOpts } from '@teambit/ts-server';\nimport AspectLoaderAspect, { AspectLoaderMain } from '@teambit/aspect-loader';\nimport type { Component } from '@teambit/component';\nimport { TypeScriptExtractor } from './typescript.extractor';\nimport { TypeScriptCompilerOptions } from './compiler-options';\nimport { TypescriptAspect } from './typescript.aspect';\nimport { TypescriptCompiler } from './typescript.compiler';\nimport { TypeScriptParser } from './typescript.parser';\nimport { SchemaTransformer } from './schema-transformer';\nimport { SchemaTransformerPlugin } from './schema-transformer.plugin';\nimport {\n ExportDeclaration,\n TypeAliasTransformer,\n FunctionDeclaration,\n MethodDeclaration,\n PropertyDeclaration,\n VariableStatementTransformer,\n VariableDeclaration,\n SourceFileTransformer,\n ClassDecelerationTransformer,\n Constructor,\n PropertySignature,\n LiteralTypeTransformer,\n IndexSignature,\n InterfaceDeclarationTransformer,\n MethodSignatureTransformer,\n EnumDeclarationTransformer,\n} from './transformers';\nimport { CheckTypesCmd } from './cmds/check-types.cmd';\n\nexport type TsMode = 'build' | 'dev';\n\nexport type SchemaTransformerSlot = SlotRegistry<SchemaTransformer[]>;\n\nexport type TsConfigTransformContext = {\n // mode: TsMode;\n};\n\nexport type TsConfigTransformer = (\n config: TypescriptConfigMutator,\n context: TsConfigTransformContext\n) => TypescriptConfigMutator;\n\nexport class TypescriptMain {\n constructor(\n private logger: Logger,\n private schemaTransformerSlot: SchemaTransformerSlot,\n private workspace: Workspace,\n private depResolver: DependencyResolverMain\n ) {}\n\n private tsServer: TsserverClient;\n /**\n * create a new compiler.\n */\n createCompiler(\n options: TypeScriptCompilerOptions,\n transformers: TsConfigTransformer[] = [],\n tsModule = ts\n ): Compiler {\n const configMutator = new TypescriptConfigMutator(options);\n const transformerContext: TsConfigTransformContext = {};\n const afterMutation = runTransformersWithContext(configMutator.clone(), transformers, transformerContext);\n return new TypescriptCompiler(TypescriptAspect.id, this.logger, afterMutation.raw, tsModule);\n }\n\n /**\n * get TsserverClient instance if initiated already, otherwise, return undefined.\n */\n getTsserverClient(): TsserverClient | undefined {\n return this.tsServer;\n }\n\n /**\n * starts a tsserver process to communicate with its API.\n * @param projectPath absolute path of the project root directory\n * @param options TsserverClientOpts\n * @param files optionally, if check-types is enabled, provide files to open and type check.\n * @returns TsserverClient\n */\n async initTsserverClient(\n projectPath: string,\n options: TsserverClientOpts = {},\n files: string[] = []\n ): Promise<TsserverClient> {\n this.tsServer = new TsserverClient(projectPath, this.logger, options, files);\n this.tsServer.init();\n return this.tsServer;\n }\n\n /**\n * starts a tsserver process to communicate with its API. use only when running on the workspace.\n * @param options TsserverClientOpts\n * @param files optionally, if check-types is enabled, provide files to open and type check.\n * @returns TsserverClient\n */\n async initTsserverClientFromWorkspace(\n options: TsserverClientOpts = {},\n files: string[] = []\n ): Promise<TsserverClient> {\n if (!this.workspace) {\n throw new Error(`initTsserverClientFromWorkspace: workspace was not found`);\n }\n return this.initTsserverClient(this.workspace.path, options, files);\n }\n\n /**\n * Create a compiler instance and run the cjs transformer for it\n * @param options\n * @param transformers\n * @param tsModule\n * @returns\n */\n createCjsCompiler(options: TypeScriptCompilerOptions, transformers: TsConfigTransformer[] = [], tsModule = ts) {\n return this.createCompiler(options, [this.getCjsTransformer(), ...transformers], tsModule);\n }\n\n /**\n * Create a compiler instance and run the esm transformer for it\n * @param options\n * @param transformers\n * @param tsModule\n * @returns\n */\n createEsmCompiler(options: TypeScriptCompilerOptions, transformers: TsConfigTransformer[] = [], tsModule = ts) {\n return this.createCompiler(options, [this.getEsmTransformer(), ...transformers], tsModule);\n }\n\n /**\n * Create a transformer that change the ts module to CommonJS\n * @returns\n */\n getCjsTransformer(): TsConfigTransformer {\n const cjsTransformer = (config: TypescriptConfigMutator) => {\n config.setModule('CommonJS');\n return config;\n };\n return cjsTransformer;\n }\n\n /**\n * Create a transformer that change the ts module to ES2020\n * @returns\n */\n getEsmTransformer(): TsConfigTransformer {\n const esmTransformer = (config: TypescriptConfigMutator) => {\n config.setModule('ES2020');\n return config;\n };\n return esmTransformer;\n }\n\n /**\n * create an instance of a typescript semantic schema extractor.\n */\n createSchemaExtractor(tsconfig: any, path?: string): SchemaExtractor {\n return new TypeScriptExtractor(\n tsconfig,\n this.schemaTransformerSlot,\n this,\n path || this.workspace.path,\n this.depResolver,\n this.workspace\n );\n }\n\n /**\n * add the default package json properties to the component\n * :TODO @gilad why do we need this DSL? can't I just get the args here.\n */\n getCjsPackageJsonProps(): PackageJsonProps {\n return {\n main: 'dist/{main}.js',\n types: '{main}.ts',\n };\n }\n\n /**\n * add type: module to the package.json props and the default props\n * :TODO @gilad why do we need this DSL? can't I just get the args here.\n */\n getEsmPackageJsonProps(): PackageJsonProps {\n return {\n // main: 'dist-esm/{main}.js',\n main: 'dist/{main}.js',\n type: 'module',\n types: '{main}.ts',\n };\n }\n\n public getSupportedFilesForTsserver(components: Component[]): string[] {\n const files = components\n .map((c) => c.filesystem.files)\n .flat()\n .map((f) => f.path);\n return files.filter((f) => f.endsWith('.ts') || f.endsWith('.tsx'));\n }\n\n private async onPreWatch(components: Component[], watchOpts: WatchOptions) {\n const workspace = this.workspace;\n if (!workspace || !watchOpts.spawnTSServer) {\n return;\n }\n const { verbose, checkTypes } = watchOpts;\n const files = checkTypes ? this.getSupportedFilesForTsserver(components) : [];\n const printTypeErrors = Boolean(checkTypes);\n await this.initTsserverClientFromWorkspace({ verbose, checkTypes, printTypeErrors }, files);\n }\n\n private async onComponentChange(component: Component, files: string[]) {\n if (!this.tsServer) {\n return {\n results: 'N/A',\n };\n }\n await pMapSeries(files, (file) => this.tsServer.onFileChange(file));\n return {\n results: 'succeed',\n };\n }\n\n static runtime = MainRuntime;\n static dependencies = [\n SchemaAspect,\n LoggerAspect,\n AspectLoaderAspect,\n WorkspaceAspect,\n CLIAspect,\n DependencyResolverAspect,\n ];\n static slots = [Slot.withType<SchemaTransformer[]>()];\n\n static async provider(\n [schema, loggerExt, aspectLoader, workspace, cli, depResolver]: [\n SchemaMain,\n LoggerMain,\n AspectLoaderMain,\n Workspace,\n CLIMain,\n DependencyResolverMain\n ],\n config,\n [schemaTransformerSlot]: [SchemaTransformerSlot]\n ) {\n schema.registerParser(new TypeScriptParser());\n const logger = loggerExt.createLogger(TypescriptAspect.id);\n aspectLoader.registerPlugins([new SchemaTransformerPlugin(schemaTransformerSlot)]);\n const tsMain = new TypescriptMain(logger, schemaTransformerSlot, workspace, depResolver);\n schemaTransformerSlot.register([\n new ExportDeclaration(),\n new FunctionDeclaration(),\n new MethodDeclaration(),\n new PropertyDeclaration(),\n new VariableStatementTransformer(),\n new VariableDeclaration(),\n new Constructor(),\n new SourceFileTransformer(),\n new TypeAliasTransformer(),\n new ClassDecelerationTransformer(),\n new PropertySignature(),\n new LiteralTypeTransformer(),\n new IndexSignature(),\n new InterfaceDeclarationTransformer(),\n new MethodSignatureTransformer(),\n new EnumDeclarationTransformer(),\n ]);\n\n if (workspace) {\n workspace.registerOnPreWatch(tsMain.onPreWatch.bind(this));\n workspace.registerOnComponentChange(tsMain.onComponentChange.bind(this));\n workspace.registerOnComponentAdd(tsMain.onComponentChange.bind(this));\n }\n\n const checkTypesCmd = new CheckTypesCmd(tsMain, workspace, logger);\n cli.register(checkTypesCmd);\n\n return tsMain;\n }\n}\n\nTypescriptAspect.addRuntime(TypescriptMain);\n\nexport function runTransformersWithContext(\n config: TypescriptConfigMutator,\n transformers: TsConfigTransformer[] = [],\n context: TsConfigTransformContext\n): TypescriptConfigMutator {\n if (!Array.isArray(transformers)) return config;\n const newConfig = transformers.reduce((acc, transformer) => {\n return transformer(acc, context);\n }, config);\n return newConfig;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAkBA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAeO,MAAMA,cAAN,CAAqB;EAC1BC,WAAW,CACDC,MADC,EAEDC,qBAFC,EAGDC,SAHC,EAIDC,WAJC,EAKT;IAAA,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CAAkB0C,IAAlB,CAAuB,IAAvB,CAA7B;MACA9F,SAAS,CAAC+F,yBAAV,CAAoCpB,MAAM,CAAChB,iBAAP,CAAyBmC,IAAzB,CAA8B,IAA9B,CAApC;MACA9F,SAAS,CAACgG,sBAAV,CAAiCrB,MAAM,CAAChB,iBAAP,CAAyBmC,IAAzB,CAA8B,IAA9B,CAAjC;IACD;;IAED,MAAMG,aAAa,GAAG,KAAIC,2BAAJ,EAAkBvB,MAAlB,EAA0B3E,SAA1B,EAAqCF,MAArC,CAAtB;IACAuE,GAAG,CAACO,QAAJ,CAAaqB,aAAb;IAEA,OAAOtB,MAAP;EACD;;AA1OyB;;;gCAAf/E,c,aAkLMuG,kB;gCAlLNvG,c,kBAmLW,CACpBwG,sBADoB,EAEpBC,sBAFoB,EAGpBC,uBAHoB,EAIpBC,4BAJoB,EAKpBC,gBALoB,EAMpBC,8CANoB,C;gCAnLX7G,c,WA2LI,CAAC8G,eAAA,CAAKC,QAAL,EAAD,C;;AAkDjB7F,+BAAA,CAAiB8F,UAAjB,CAA4BhH,cAA5B;;AAEO,SAASe,0BAAT,CACLqB,MADK,EAEL5B,YAAmC,GAAG,EAFjC,EAGLyG,OAHK,EAIoB;EACzB,IAAI,CAACC,KAAK,CAACC,OAAN,CAAc3G,YAAd,CAAL,EAAkC,OAAO4B,MAAP;EAClC,MAAMgF,SAAS,GAAG5G,YAAY,CAAC6G,MAAb,CAAoB,CAACC,GAAD,EAAMC,WAAN,KAAsB;IAC1D,OAAOA,WAAW,CAACD,GAAD,EAAML,OAAN,CAAlB;EACD,CAFiB,EAEf7E,MAFe,CAAlB;EAGA,OAAOgF,SAAP;AACD"}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import ts, { Node } from 'typescript';
|
|
2
2
|
import { Component } from '@teambit/component';
|
|
3
|
+
import { Location } from '@teambit/semantics.entities.semantic-schema';
|
|
3
4
|
|
|
4
5
|
export class TransformerNotFound extends Error {
|
|
5
|
-
constructor(readonly node: Node, readonly component: Component) {
|
|
6
|
+
constructor(readonly node: Node, readonly component: Component, location: Location) {
|
|
6
7
|
super(
|
|
7
8
|
`typescript: could not find schema transformer for node of kind ${node.kind} (${
|
|
8
9
|
ts.SyntaxKind[node.kind]
|
|
9
10
|
}) in component ${component.id.toString()}.
|
|
10
|
-
|
|
11
|
+
location: ${location.file}, line: ${location.line}, character: ${location.character}.
|
|
12
|
+
node-text: ${node.getText()}`
|
|
11
13
|
);
|
|
12
14
|
}
|
|
13
15
|
}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/typescript",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.741",
|
|
4
4
|
"homepage": "https://bit.dev/teambit/typescript/typescript",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.typescript",
|
|
8
8
|
"name": "typescript",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.741"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"lodash": "4.17.21",
|
|
@@ -18,20 +18,21 @@
|
|
|
18
18
|
"@babel/runtime": "7.12.18",
|
|
19
19
|
"core-js": "^3.0.0",
|
|
20
20
|
"@teambit/harmony": "0.3.3",
|
|
21
|
-
"@teambit/compiler": "0.0.
|
|
21
|
+
"@teambit/compiler": "0.0.741",
|
|
22
22
|
"@teambit/typescript.modules.ts-config-mutator": "0.0.68",
|
|
23
|
-
"@teambit/component": "0.0.
|
|
24
|
-
"@teambit/
|
|
23
|
+
"@teambit/component": "0.0.741",
|
|
24
|
+
"@teambit/dependency-resolver": "0.0.741",
|
|
25
|
+
"@teambit/semantics.entities.semantic-schema": "0.0.14",
|
|
25
26
|
"@teambit/ts-server": "0.0.32",
|
|
26
|
-
"@teambit/aspect-loader": "0.0.
|
|
27
|
+
"@teambit/aspect-loader": "0.0.741",
|
|
27
28
|
"@teambit/bit-error": "0.0.394",
|
|
28
|
-
"@teambit/builder": "0.0.
|
|
29
|
-
"@teambit/isolator": "0.0.
|
|
30
|
-
"@teambit/logger": "0.0.
|
|
31
|
-
"@teambit/schema": "0.0.
|
|
32
|
-
"@teambit/
|
|
33
|
-
"@teambit/
|
|
34
|
-
"@teambit/
|
|
29
|
+
"@teambit/builder": "0.0.741",
|
|
30
|
+
"@teambit/isolator": "0.0.741",
|
|
31
|
+
"@teambit/logger": "0.0.584",
|
|
32
|
+
"@teambit/schema": "0.0.741",
|
|
33
|
+
"@teambit/workspace": "0.0.741",
|
|
34
|
+
"@teambit/cli": "0.0.492",
|
|
35
|
+
"@teambit/pkg": "0.0.741"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
38
|
"@types/lodash": "4.14.165",
|
|
@@ -47,7 +48,7 @@
|
|
|
47
48
|
"@teambit/typescript.aspect-docs.typescript": "0.0.137"
|
|
48
49
|
},
|
|
49
50
|
"peerDependencies": {
|
|
50
|
-
"@teambit/legacy": "1.0.
|
|
51
|
+
"@teambit/legacy": "1.0.272",
|
|
51
52
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
52
53
|
"react": "^16.8.0 || ^17.0.0"
|
|
53
54
|
},
|
|
@@ -75,7 +76,7 @@
|
|
|
75
76
|
"react": "-"
|
|
76
77
|
},
|
|
77
78
|
"peerDependencies": {
|
|
78
|
-
"@teambit/legacy": "1.0.
|
|
79
|
+
"@teambit/legacy": "1.0.272",
|
|
79
80
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
80
81
|
"react": "^16.8.0 || ^17.0.0"
|
|
81
82
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.
|
|
2
|
-
export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.
|
|
1
|
+
export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.741/dist/typescript.composition.js')]
|
|
2
|
+
export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.741/dist/typescript.docs.mdx')]
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import pMapSeries from 'p-map-series';
|
|
2
2
|
import { compact } from 'lodash';
|
|
3
3
|
import { ClassSchema, GetAccessorSchema, SetAccessorSchema } from '@teambit/semantics.entities.semantic-schema';
|
|
4
|
-
import ts, { Node, ClassDeclaration } from 'typescript';
|
|
4
|
+
import ts, { Node, ClassDeclaration, isSemicolonClassElement } from 'typescript';
|
|
5
5
|
import { SchemaTransformer } from '../schema-transformer';
|
|
6
6
|
import { SchemaExtractorContext } from '../schema-extractor-context';
|
|
7
7
|
import { ExportIdentifier } from '../export-identifier';
|
|
@@ -29,6 +29,9 @@ export class ClassDecelerationTransformer implements SchemaTransformer {
|
|
|
29
29
|
if (isPrivate) {
|
|
30
30
|
return null;
|
|
31
31
|
}
|
|
32
|
+
if (isSemicolonClassElement(member)) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
32
35
|
switch (member.kind) {
|
|
33
36
|
case ts.SyntaxKind.GetAccessor: {
|
|
34
37
|
const getter = member as ts.GetAccessorDeclaration;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import ts, { Node, EnumDeclaration } from 'typescript';
|
|
2
|
+
import { EnumSchema } from '@teambit/semantics.entities.semantic-schema';
|
|
3
|
+
import { SchemaTransformer } from '../schema-transformer';
|
|
4
|
+
import { SchemaExtractorContext } from '../schema-extractor-context';
|
|
5
|
+
import { ExportIdentifier } from '../export-identifier';
|
|
6
|
+
|
|
7
|
+
export class EnumDeclarationTransformer implements SchemaTransformer {
|
|
8
|
+
predicate(node: Node) {
|
|
9
|
+
return node.kind === ts.SyntaxKind.EnumDeclaration;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async getIdentifiers(node: EnumDeclaration): Promise<ExportIdentifier[]> {
|
|
13
|
+
return [new ExportIdentifier(node.name.getText(), node.getSourceFile().fileName)];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async transform(enumDec: EnumDeclaration, context: SchemaExtractorContext) {
|
|
17
|
+
const members = enumDec.members.map((member) => member.name.getText());
|
|
18
|
+
return new EnumSchema(context.getLocation(enumDec), enumDec.name.getText(), members);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -53,9 +53,14 @@ export class ExportDeclaration implements SchemaTransformer {
|
|
|
53
53
|
if (exportClause?.kind === SyntaxKind.NamespaceExport) {
|
|
54
54
|
exportClause as NamespaceExport;
|
|
55
55
|
const namespace = exportClause.name.getText();
|
|
56
|
-
const
|
|
56
|
+
const filePath = await context.getFilePathByNode(exportClause.name);
|
|
57
|
+
if (!filePath) {
|
|
58
|
+
throw new Error(`unable to find the file-path for "${namespace}"`);
|
|
59
|
+
}
|
|
60
|
+
const sourceFile = context.getSourceFileInsideComponent(filePath);
|
|
57
61
|
if (!sourceFile) {
|
|
58
|
-
|
|
62
|
+
// it's a namespace from another component or an external package.
|
|
63
|
+
return context.getTypeRefForExternalPath(namespace, filePath, context.getLocation(node));
|
|
59
64
|
}
|
|
60
65
|
const result = await context.computeSchema(sourceFile);
|
|
61
66
|
if (!(result instanceof Module)) {
|
package/transformers/index.ts
CHANGED
|
@@ -13,3 +13,4 @@ export { LiteralTypeTransformer } from './literal-type';
|
|
|
13
13
|
export { IndexSignature } from './index-signature';
|
|
14
14
|
export { InterfaceDeclarationTransformer } from './interface-declaration';
|
|
15
15
|
export { MethodSignatureTransformer } from './method-signature';
|
|
16
|
+
export { EnumDeclarationTransformer } from './enum-declaration';
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { SchemaNode, VariableSchema } from '@teambit/semantics.entities.semantic-schema';
|
|
2
|
-
import ts, {
|
|
2
|
+
import ts, { isComputedPropertyName, Node, PropertySignature as PropertySignatureNode } from 'typescript';
|
|
3
3
|
import { SchemaTransformer } from '../schema-transformer';
|
|
4
4
|
import { SchemaExtractorContext } from '../schema-extractor-context';
|
|
5
5
|
import { parseTypeFromQuickInfo } from './utils/parse-type-from-quick-info';
|
|
6
|
-
import { typeNodeToSchema } from './utils/type-node-to-schema';
|
|
7
6
|
|
|
8
7
|
export class PropertySignature implements SchemaTransformer {
|
|
9
8
|
predicate(node: Node) {
|
|
@@ -20,13 +19,8 @@ export class PropertySignature implements SchemaTransformer {
|
|
|
20
19
|
|
|
21
20
|
async transform(prop: PropertySignatureNode, context: SchemaExtractorContext): Promise<SchemaNode> {
|
|
22
21
|
const name = this.getName(prop);
|
|
23
|
-
const info = await context.getQuickInfo(prop.name);
|
|
22
|
+
const info = isComputedPropertyName(prop.name) ? undefined : await context.getQuickInfo(prop.name);
|
|
24
23
|
const displaySig = info?.body?.displayString || '';
|
|
25
|
-
if (prop.type?.kind === ts.SyntaxKind.FunctionType) {
|
|
26
|
-
// e.g. `propertySig: () => void;` inside interface
|
|
27
|
-
const propType = prop.type as FunctionTypeNode;
|
|
28
|
-
return typeNodeToSchema(propType, context);
|
|
29
|
-
}
|
|
30
24
|
const typeStr = parseTypeFromQuickInfo(info);
|
|
31
25
|
const type = await context.resolveType(prop, typeStr);
|
|
32
26
|
return new VariableSchema(context.getLocation(prop), name, displaySig, type);
|
|
@@ -20,8 +20,7 @@ export class TypeAliasTransformer implements SchemaTransformer {
|
|
|
20
20
|
|
|
21
21
|
async transform(typeAlias: TypeAliasDeclaration, context: SchemaExtractorContext) {
|
|
22
22
|
const type = await typeNodeToSchema(typeAlias.type, context);
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
return new TypeSchema(context.getLocation(typeAlias), this.getName(typeAlias), type, displaySig || '');
|
|
23
|
+
const displaySig = await context.getQuickInfoDisplayString(typeAlias.name);
|
|
24
|
+
return new TypeSchema(context.getLocation(typeAlias), this.getName(typeAlias), type, displaySig);
|
|
26
25
|
}
|
|
27
26
|
}
|
|
@@ -1,6 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
InferenceTypeSchema,
|
|
3
|
+
ParameterSchema,
|
|
4
|
+
TupleTypeSchema,
|
|
5
|
+
TypeLiteralSchema,
|
|
6
|
+
SchemaNode,
|
|
7
|
+
} from '@teambit/semantics.entities.semantic-schema';
|
|
2
8
|
import pMapSeries from 'p-map-series';
|
|
3
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
SyntaxKind,
|
|
11
|
+
ParameterDeclaration,
|
|
12
|
+
NodeArray,
|
|
13
|
+
isIdentifier,
|
|
14
|
+
BindingElement,
|
|
15
|
+
ArrayBindingElement,
|
|
16
|
+
} from 'typescript';
|
|
4
17
|
import { SchemaExtractorContext } from '../../schema-extractor-context';
|
|
5
18
|
import { parseTypeFromQuickInfo } from './parse-type-from-quick-info';
|
|
6
19
|
import { typeNodeToSchema } from './type-node-to-schema';
|
|
@@ -12,22 +25,53 @@ export async function getParams(
|
|
|
12
25
|
return pMapSeries(parameterNodes, async (param) => {
|
|
13
26
|
return new ParameterSchema(
|
|
14
27
|
context.getLocation(param),
|
|
15
|
-
param
|
|
28
|
+
getParamName(param),
|
|
16
29
|
await getParamType(param, context),
|
|
17
30
|
param.initializer ? param.initializer.getText() : undefined
|
|
18
31
|
);
|
|
19
32
|
});
|
|
20
33
|
}
|
|
21
34
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
35
|
+
function getParamName(param: ParameterDeclaration): string {
|
|
36
|
+
if (isIdentifier(param.name)) {
|
|
37
|
+
return param.name.getText();
|
|
38
|
+
}
|
|
39
|
+
// it's binding pattern, either an array or an object
|
|
40
|
+
const elements = param.name.elements.map((elem) => elem.getText());
|
|
41
|
+
const elementsStr = elements.join(', ');
|
|
42
|
+
if (param.name.kind === SyntaxKind.ArrayBindingPattern) {
|
|
43
|
+
return `[ ${elementsStr} ]`;
|
|
44
|
+
}
|
|
45
|
+
// it's an object binding
|
|
46
|
+
return `{ ${elementsStr} }`;
|
|
47
|
+
}
|
|
48
|
+
|
|
25
49
|
async function getParamType(param: ParameterDeclaration, context: SchemaExtractorContext): Promise<SchemaNode> {
|
|
26
50
|
if (param.type) {
|
|
27
51
|
const type = param.type;
|
|
28
52
|
return typeNodeToSchema(type, context);
|
|
29
53
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
54
|
+
if (isIdentifier(param.name)) {
|
|
55
|
+
const info = await context.getQuickInfo(param.name);
|
|
56
|
+
const parsed = parseTypeFromQuickInfo(info);
|
|
57
|
+
return new InferenceTypeSchema(context.getLocation(param), parsed);
|
|
58
|
+
}
|
|
59
|
+
// it's binding pattern, either an array or an object
|
|
60
|
+
if (param.name.kind === SyntaxKind.ArrayBindingPattern) {
|
|
61
|
+
const elements = await pMapSeries(param.name.elements, async (elem: ArrayBindingElement) => {
|
|
62
|
+
const info = await context.getQuickInfo(elem);
|
|
63
|
+
const parsed = parseTypeFromQuickInfo(info);
|
|
64
|
+
return new InferenceTypeSchema(context.getLocation(param), parsed);
|
|
65
|
+
});
|
|
66
|
+
return new TupleTypeSchema(context.getLocation(param), elements);
|
|
67
|
+
}
|
|
68
|
+
if (param.name.kind === SyntaxKind.ObjectBindingPattern) {
|
|
69
|
+
const elements = await pMapSeries(param.name.elements, async (elem: BindingElement) => {
|
|
70
|
+
const info = await context.getQuickInfo(elem.name);
|
|
71
|
+
const parsed = parseTypeFromQuickInfo(info);
|
|
72
|
+
return new InferenceTypeSchema(context.getLocation(param), parsed, elem.name.getText());
|
|
73
|
+
});
|
|
74
|
+
return new TypeLiteralSchema(context.getLocation(param), elements);
|
|
75
|
+
}
|
|
76
|
+
throw new Error(`unknown param type`);
|
|
33
77
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// eslint-disable-next-line import/no-unresolved
|
|
2
2
|
import protocol from 'typescript/lib/protocol';
|
|
3
3
|
|
|
4
|
+
export const UNRESOLVED = '<<unresolved>>';
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* try to parse the type from the quickinfo.
|
|
6
8
|
* this is an error-prone process, we do our best here.
|
|
@@ -49,7 +51,13 @@ export function parseTypeFromQuickInfo(quickInfo: protocol.QuickInfoResponse | u
|
|
|
49
51
|
case 'function': {
|
|
50
52
|
const split = displayString.split('): ');
|
|
51
53
|
if (split.length !== 2) {
|
|
52
|
-
|
|
54
|
+
// it's hard to determine where the return-type is. so it's better to show unresolved.
|
|
55
|
+
// maybe, in the UI, in this case, it's best to show the signature.
|
|
56
|
+
// e.g.
|
|
57
|
+
// (method) IssuesList.getIssue<T extends ComponentIssue>(IssueClass: {
|
|
58
|
+
// new (): T;
|
|
59
|
+
// }): T | undefined
|
|
60
|
+
return UNRESOLVED;
|
|
53
61
|
}
|
|
54
62
|
return split[1].trim();
|
|
55
63
|
}
|