@teambit/compiler 0.0.593 → 0.0.597
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/compiler.main.runtime.d.ts +2 -2
- package/dist/compiler.main.runtime.js.map +1 -1
- package/dist/workspace-compiler.d.ts +1 -1
- package/dist/workspace-compiler.js.map +1 -1
- package/package-tar/teambit-compiler-0.0.597.tgz +0 -0
- package/package.json +18 -18
- package/package-tar/teambit-compiler-0.0.593.tgz +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AspectLoaderMain } from '@teambit/aspect-loader';
|
|
2
2
|
import { BuilderMain } from '@teambit/builder';
|
|
3
3
|
import { CLIMain } from '@teambit/cli';
|
|
4
|
-
import { Component } from '@teambit/component';
|
|
4
|
+
import { Component, ComponentID } from '@teambit/component';
|
|
5
5
|
import { EnvsMain } from '@teambit/envs';
|
|
6
6
|
import { BitId } from '@teambit/legacy-bit-id';
|
|
7
7
|
import { LoggerMain } from '@teambit/logger';
|
|
@@ -22,7 +22,7 @@ export declare class CompilerMain {
|
|
|
22
22
|
/**
|
|
23
23
|
* Run compilation on `bit new` and when new components are imported
|
|
24
24
|
*/
|
|
25
|
-
compileOnWorkspace(componentsIds?: string[] | BitId[], // when empty, it compiles all
|
|
25
|
+
compileOnWorkspace(componentsIds?: string[] | BitId[] | ComponentID[], // when empty, it compiles all
|
|
26
26
|
options?: CompileOptions): Promise<import("./workspace-compiler").BuildResult[]>;
|
|
27
27
|
/**
|
|
28
28
|
* API to create a new compiler task, it facilitates the usage of multiple compilers.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["compiler.main.runtime.ts"],"names":["CompilerMain","constructor","pubsub","workspaceCompiler","envs","builder","compileOnWorkspace","componentsIds","options","initiator","CompilationInitiator","ComponentAdded","compileComponents","createTask","name","compiler","CompilerTask","CompilerAspect","id","getDistPathBySrcPath","component","srcPath","environment","getEnv","env","compilerInstance","getCompiler","getDistsFiles","artifacts","getArtifactsVinylByExtension","length","DistArtifactNotFound","DistArtifact","provider","cli","workspace","loggerMain","aspectLoader","ui","generator","logger","createLogger","WorkspaceCompiler","registerService","CompilerService","compilerMain","register","CompileCmd","registerComponentTemplate","compilerTemplate","ManyComponentsWriter","externalCompiler","bind","MainRuntime","CLIAspect","WorkspaceAspect","EnvsAspect","LoggerAspect","PubsubAspect","AspectLoaderAspect","BuilderAspect","UIAspect","GeneratorAspect","addRuntime"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,MAAMA,YAAN,CAAmB;AACxBC,EAAAA,WAAW,CACDC,MADC,EAEDC,iBAFC,EAGDC,IAHC,EAIDC,OAJC,EAKT;AAAA,SAJQH,MAIR,GAJQA,MAIR;AAAA,SAHQC,iBAGR,GAHQA,iBAGR;AAAA,SAFQC,IAER,GAFQA,IAER;AAAA,SADQC,OACR,GADQA,OACR;AAAE;AAEJ;AACF;AACA;;;AACEC,EAAAA,kBAAkB,CAChBC,
|
|
1
|
+
{"version":3,"sources":["compiler.main.runtime.ts"],"names":["CompilerMain","constructor","pubsub","workspaceCompiler","envs","builder","compileOnWorkspace","componentsIds","options","initiator","CompilationInitiator","ComponentAdded","compileComponents","createTask","name","compiler","CompilerTask","CompilerAspect","id","getDistPathBySrcPath","component","srcPath","environment","getEnv","env","compilerInstance","getCompiler","getDistsFiles","artifacts","getArtifactsVinylByExtension","length","DistArtifactNotFound","DistArtifact","provider","cli","workspace","loggerMain","aspectLoader","ui","generator","logger","createLogger","WorkspaceCompiler","registerService","CompilerService","compilerMain","register","CompileCmd","registerComponentTemplate","compilerTemplate","ManyComponentsWriter","externalCompiler","bind","MainRuntime","CLIAspect","WorkspaceAspect","EnvsAspect","LoggerAspect","PubsubAspect","AspectLoaderAspect","BuilderAspect","UIAspect","GeneratorAspect","addRuntime"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;A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B,GAAwCN,YAAY,CAACvC,kBAAb,CAAgC8C,IAAhC,CAAqCP,YAArC,CAAxC;AAEA,WAAOA,YAAP;AACD;;AA5EuB;;;gCAAb7C,Y,aA0CMqD,kB;gCA1CNrD,Y,kBA4CW,CACpBsD,gBADoB,EAEpBC,4BAFoB,EAGpBC,kBAHoB,EAIpBC,sBAJoB,EAKpBC,sBALoB,EAMpBC,uBANoB,EAOpBC,wBAPoB,EAQpBC,aARoB,EASpBC,4BAToB,C;;AAmCxB7C,2BAAe8C,UAAf,CAA0B/D,YAA1B","sourcesContent":["import AspectLoaderAspect, { AspectLoaderMain } from '@teambit/aspect-loader';\nimport { BuilderAspect, BuilderMain } from '@teambit/builder';\nimport { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';\nimport { Component, ComponentID } from '@teambit/component';\nimport { EnvsAspect, EnvsMain } from '@teambit/envs';\nimport { BitId } from '@teambit/legacy-bit-id';\n\nimport ManyComponentsWriter from '@teambit/legacy/dist/consumer/component-ops/many-components-writer';\nimport { LoggerAspect, LoggerMain } from '@teambit/logger';\nimport { GeneratorAspect, GeneratorMain } from '@teambit/generator';\nimport { PubsubAspect, PubsubMain } from '@teambit/pubsub';\nimport UIAspect, { UiMain } from '@teambit/ui';\nimport { Workspace, WorkspaceAspect } from '@teambit/workspace';\nimport { CompilerAspect } from './compiler.aspect';\nimport { CompileCmd } from './compiler.cmd';\nimport { CompilerService } from './compiler.service';\nimport { CompilerTask } from './compiler.task';\nimport { DistArtifact } from './dist-artifact';\nimport { DistArtifactNotFound } from './exceptions';\nimport { CompilationInitiator, Compiler } from './types';\nimport { CompileOptions, WorkspaceCompiler } from './workspace-compiler';\nimport { compilerTemplate } from './templates/compiler';\n\nexport class CompilerMain {\n constructor(\n private pubsub: PubsubMain,\n private workspaceCompiler: WorkspaceCompiler,\n private envs: EnvsMain,\n private builder: BuilderMain\n ) {}\n\n /**\n * Run compilation on `bit new` and when new components are imported\n */\n compileOnWorkspace(\n componentsIds: string[] | BitId[] | ComponentID[] = [], // when empty, it compiles all\n options: CompileOptions = { initiator: CompilationInitiator.ComponentAdded }\n ) {\n return this.workspaceCompiler.compileComponents(componentsIds, options);\n }\n /**\n * API to create a new compiler task, it facilitates the usage of multiple compilers.\n * with this method you can create any number of compilers and add them to the buildPipeline.\n */\n createTask(name: string, compiler: Compiler): CompilerTask {\n return new CompilerTask(CompilerAspect.id, name, compiler);\n }\n\n /**\n * find the compiler configured on the workspace and ask for the dist path.\n */\n getDistPathBySrcPath(component: Component, srcPath: string): string | null {\n const environment = this.envs.getEnv(component).env;\n const compilerInstance = environment.getCompiler?.();\n if (!compilerInstance) return null;\n return compilerInstance.getDistPathBySrcPath(srcPath);\n }\n\n async getDistsFiles(component: Component): Promise<DistArtifact> {\n const artifacts = await this.builder.getArtifactsVinylByExtension(component, CompilerAspect.id);\n if (!artifacts.length) throw new DistArtifactNotFound(component.id);\n\n return new DistArtifact(artifacts);\n }\n\n static runtime = MainRuntime;\n\n static dependencies = [\n CLIAspect,\n WorkspaceAspect,\n EnvsAspect,\n LoggerAspect,\n PubsubAspect,\n AspectLoaderAspect,\n BuilderAspect,\n UIAspect,\n GeneratorAspect,\n ];\n\n static async provider([cli, workspace, envs, loggerMain, pubsub, aspectLoader, builder, ui, generator]: [\n CLIMain,\n Workspace,\n EnvsMain,\n LoggerMain,\n PubsubMain,\n AspectLoaderMain,\n BuilderMain,\n UiMain,\n GeneratorMain\n ]) {\n const logger = loggerMain.createLogger(CompilerAspect.id);\n const workspaceCompiler = new WorkspaceCompiler(workspace, envs, pubsub, aspectLoader, ui, logger);\n envs.registerService(new CompilerService());\n const compilerMain = new CompilerMain(pubsub, workspaceCompiler, envs, builder);\n cli.register(new CompileCmd(workspaceCompiler, logger, pubsub));\n generator.registerComponentTemplate([compilerTemplate]);\n ManyComponentsWriter.externalCompiler = compilerMain.compileOnWorkspace.bind(compilerMain);\n\n return compilerMain;\n }\n}\n\nCompilerAspect.addRuntime(CompilerMain);\n"]}
|
|
@@ -60,7 +60,7 @@ export declare class WorkspaceCompiler {
|
|
|
60
60
|
}, id: ComponentID): Promise<boolean>;
|
|
61
61
|
onComponentChange(component: Component, files: string[], initiator?: CompilationInitiator): Promise<SerializableResults>;
|
|
62
62
|
onPreWatch(components: Component[], watchOpts: WatchOptions): Promise<void>;
|
|
63
|
-
compileComponents(componentsIds: string[] | BitId[], // when empty, it compiles new+modified (unless options.all is set),
|
|
63
|
+
compileComponents(componentsIds: string[] | BitId[] | ComponentID[], // when empty, it compiles new+modified (unless options.all is set),
|
|
64
64
|
options: CompileOptions, noThrow?: boolean): Promise<BuildResult[]>;
|
|
65
65
|
private getIdsToCompile;
|
|
66
66
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["workspace-compiler.ts"],"names":["ComponentCompiler","constructor","pubsub","workspace","component","compilerInstance","compilerId","logger","dists","compileErrors","compile","noThrow","options","dataToPersist","deleteDistDir","DataToPersist","removePath","RemovePath","distDir","addBasePath","path","persistAllToFS","transpileFile","Promise","all","files","map","file","compileOneFileWithNewCompiler","initiator","transpileComponent","compileAllFilesWithNewCompiler","Error","toString","throwOnCompileErrors","addManyFiles","buildResults","distFile","compiler","loader","succeed","pub","CompilerAspect","id","ComponentCompilationOnDoneEvent","length","forEach","errorItem","error","formatError","err","join","CompilerErrorEvent","console","message","packageName","packageDir","distDirName","DEFAULT_DIST_DIRNAME","componentDir","ComponentID","filePath","relative","isFileSupported","compileResults","contents","push","base","result","Dist","outputPath","Buffer","from","outputText","shouldCopyNonSupportedFiles","filesToCompile","outputDir","getComponentPackagePath","WorkspaceCompiler","envs","aspectLoader","ui","registerOnComponentChange","onComponentChange","bind","registerOnComponentAdd","registerOnPreWatch","onPreWatch","registerPreStart","onPreStart","registerOnAspectLoadErrorSlot","onAspectLoadFail","preStartOpts","skipCompilation","compileComponents","changed","verbose","CompilationInitiator","PreStart","code","AspectLoadFail","ComponentChanged","results","components","watchOpts","preCompile","start","Date","now","c","_legacy","PreWatch","end","consoleSuccess","componentsIds","ConsumerNotFound","isLegacy","componentIds","getIdsToCompile","getMany","componentsAndNewCompilers","environment","getEnv","env","getCompiler","state","_consumer","componentMap","getComponentDir","compilerName","name","newCompilersResultOnWorkspace","componentAndNewCompilers","resolveMultipleComponentIds","getNewAndModifiedIds","getAllComponentIds"],"mappings":";;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAIA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAIA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAvBA;AAyCO,MAAMA,iBAAN,CAAwB;AAC7BC,EAAAA,WAAW,CACDC,MADC,EAEDC,SAFC,EAGDC,SAHC,EAIDC,gBAJC,EAKDC,UALC,EAMDC,MANC,EAODC,KAAa,GAAG,EAPf,EAQDC,aAA6B,GAAG,EAR/B,EAST;AAAA,SARQP,MAQR,GARQA,MAQR;AAAA,SAPQC,SAOR,GAPQA,SAOR;AAAA,SANQC,SAMR,GANQA,SAMR;AAAA,SALQC,gBAKR,GALQA,gBAKR;AAAA,SAJQC,UAIR,GAJQA,UAIR;AAAA,SAHQC,MAGR,GAHQA,MAGR;AAAA,SAFQC,KAER,GAFQA,KAER;AAAA,SADQC,aACR,GADQ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+D,CAAD,IAAO;AAAA;;AACxB,YAAMY,WAAW,GAAG,KAAK1C,IAAL,CAAU2C,MAAV,CAAiBb,CAAjB,EAAoBc,GAAxC;AACA,YAAMtH,gBAAgB,4BAAGoH,WAAW,CAACG,WAAf,0DAAG,2BAAAH,WAAW,CAApC,CAFwB,CAGxB;AACA;;AACA,UAAIpH,gBAAgB,6BAAIwG,CAAC,CAACgB,KAAF,CAAQC,SAAR,CAAkBC,YAAtB,kDAAI,sBAAgCC,eAAhC,EAAxB,EAA2E;AACzE,cAAMC,YAAY,GAAG5H,gBAAgB,CAACJ,WAAjB,CAA6BiI,IAA7B,IAAqC,UAA1D;AACAV,QAAAA,yBAAyB,CAACtD,IAA1B,CACE,IAAIlE,iBAAJ,CACE,KAAKE,MADP,EAEE,KAAKC,SAFP,EAGE0G,CAAC,CAACgB,KAAF,CAAQC,SAHV,EAIEzH,gBAJF,EAKE4H,YALF,EAME,KAAK1H,MANP,CADF;AAUD;AACF,KAlBD;AAmBA,UAAM4H,6BAA6B,GAAG,MAAM,2BAAUX,yBAAV,EAAsCY,wBAAD,IAC/EA,wBAAwB,CAAC1H,OAAzB,CAAiCC,OAAjC,EAA0CC,OAA1C,CAD0C,CAA5C;AAIA,WAAOuH,6BAAP;AACD;;AAE4B,QAAfb,eAAe,CAACJ,aAAD,EAAuCnB,OAAO,GAAG,KAAjD,EAAgF;AAC3G,QAAImB,aAAa,CAACrE,MAAlB,EAA0B;AACxB,aAAO,KAAK1C,SAAL,CAAekI,2BAAf,CAA2CnB,aAA3C,CAAP;AACD;;AACD,QAAInB,OAAJ,EAAa;AACX,aAAO,KAAK5F,SAAL,CAAemI,oBAAf,EAAP;AACD;;AACD,WAAO,KAAKnI,SAAL,CAAeoI,kBAAf,EAAP;AACD;;AApH4B","sourcesContent":["/* eslint-disable max-classes-per-file */\nimport mapSeries from 'p-map-series';\nimport { Component, ComponentID } from '@teambit/component';\nimport { EnvsMain } from '@teambit/envs';\nimport type { PubsubMain } from '@teambit/pubsub';\nimport { SerializableResults, Workspace, WatchOptions } from '@teambit/workspace';\nimport path from 'path';\nimport { BitId } from '@teambit/legacy-bit-id';\nimport { Logger } from '@teambit/logger';\nimport loader from '@teambit/legacy/dist/cli/loader';\nimport { DEFAULT_DIST_DIRNAME } from '@teambit/legacy/dist/constants';\nimport ConsumerComponent from '@teambit/legacy/dist/consumer/component';\nimport { Dist, SourceFile } from '@teambit/legacy/dist/consumer/component/sources';\nimport DataToPersist from '@teambit/legacy/dist/consumer/component/sources/data-to-persist';\nimport { AspectLoaderMain } from '@teambit/aspect-loader';\nimport { ConsumerNotFound } from '@teambit/legacy/dist/consumer/exceptions';\nimport componentIdToPackageName from '@teambit/legacy/dist/utils/bit/component-id-to-package-name';\nimport RemovePath from '@teambit/legacy/dist/consumer/component/sources/remove-path';\nimport { UiMain } from '@teambit/ui';\nimport type { PreStartOpts } from '@teambit/ui';\nimport { PathOsBasedAbsolute, PathOsBasedRelative } from '@teambit/legacy/dist/utils/path';\nimport { CompilerAspect } from './compiler.aspect';\nimport { CompilerErrorEvent, ComponentCompilationOnDoneEvent } from './events';\nimport { Compiler, CompilationInitiator } from './types';\n\nexport type BuildResult = { component: string; buildResults: string[] | null | undefined };\n\nexport type CompileOptions = {\n changed?: boolean; // compile only new and modified components\n verbose?: boolean; // show more data, such as, dist paths\n /**\n * whether the dist root dir should be deleted before writing new dists.\n * defaults to true for `bit compile` and false everywhere else, such as `bit watch` and `bit\n * start` to avoid webpack \"EINTR\" error.\n */\n deleteDistDir?: boolean;\n initiator: CompilationInitiator; // describes where the compilation is coming from\n};\n\nexport type CompileError = { path: string; error: Error };\n\nexport class ComponentCompiler {\n constructor(\n private pubsub: PubsubMain,\n private workspace: Workspace,\n private component: ConsumerComponent,\n private compilerInstance: Compiler,\n private compilerId: string,\n private logger: Logger,\n private dists: Dist[] = [],\n private compileErrors: CompileError[] = []\n ) {}\n\n async compile(noThrow = true, options: CompileOptions): Promise<BuildResult> {\n let dataToPersist;\n const deleteDistDir = options.deleteDistDir ?? this.compilerInstance.deleteDistDir;\n // delete dist folder before transpilation (because some compilers (like ngPackagr) can generate files there during the compilation process)\n if (deleteDistDir) {\n dataToPersist = new DataToPersist();\n dataToPersist.removePath(new RemovePath(this.distDir));\n dataToPersist.addBasePath(this.workspace.path);\n await dataToPersist.persistAllToFS();\n }\n\n if (this.compilerInstance.transpileFile) {\n await Promise.all(\n this.component.files.map((file: SourceFile) => this.compileOneFileWithNewCompiler(file, options.initiator))\n );\n } else if (this.compilerInstance.transpileComponent) {\n await this.compileAllFilesWithNewCompiler(this.component, options.initiator);\n } else {\n throw new Error(\n `compiler ${this.compilerId.toString()} doesn't implement either \"transpileFile\" or \"transpileComponent\" methods`\n );\n }\n this.throwOnCompileErrors(noThrow);\n\n // writing the dists with `component.setDists(dists); component.dists.writeDists` is tricky\n // as it uses other base-paths and doesn't respect the new node-modules base path.\n dataToPersist = new DataToPersist();\n dataToPersist.addManyFiles(this.dists);\n dataToPersist.addBasePath(this.workspace.path);\n await dataToPersist.persistAllToFS();\n const buildResults = this.dists.map((distFile) => distFile.path);\n if (this.component.compiler) loader.succeed();\n this.pubsub.pub(\n CompilerAspect.id,\n new ComponentCompilationOnDoneEvent(this.compileErrors, this.component, buildResults)\n );\n return { component: this.component.id.toString(), buildResults };\n }\n\n private throwOnCompileErrors(noThrow = true) {\n if (this.compileErrors.length) {\n this.compileErrors.forEach((errorItem) => {\n this.logger.error(`compilation error at ${errorItem.path}`, errorItem.error);\n });\n const formatError = (errorItem) => `${errorItem.path}\\n${errorItem.error}`;\n const err = new Error(`compilation failed. see the following errors from the compiler\n${this.compileErrors.map(formatError).join('\\n')}`);\n\n this.pubsub.pub(CompilerAspect.id, new CompilerErrorEvent(err));\n\n if (!noThrow) {\n throw err;\n }\n\n this.logger.console(err.message);\n }\n }\n\n private get distDir(): PathOsBasedRelative {\n const packageName = componentIdToPackageName(this.component);\n const packageDir = path.join('node_modules', packageName);\n const distDirName = DEFAULT_DIST_DIRNAME;\n return path.join(packageDir, distDirName);\n }\n\n private get componentDir(): PathOsBasedAbsolute {\n return this.workspace.componentDir(new ComponentID(this.component.id));\n }\n\n private async compileOneFileWithNewCompiler(file: SourceFile, initiator: CompilationInitiator): Promise<void> {\n const options = { componentDir: this.componentDir, filePath: file.relative, initiator };\n const isFileSupported = this.compilerInstance.isFileSupported(file.path);\n let compileResults;\n if (isFileSupported) {\n try {\n compileResults = this.compilerInstance.transpileFile?.(file.contents.toString(), options);\n } catch (error: any) {\n this.compileErrors.push({ path: file.path, error });\n return;\n }\n }\n const base = this.distDir;\n if (isFileSupported && compileResults) {\n this.dists.push(\n ...compileResults.map(\n (result) =>\n new Dist({\n base,\n path: path.join(base, result.outputPath),\n contents: Buffer.from(result.outputText),\n })\n )\n );\n } else if (this.compilerInstance.shouldCopyNonSupportedFiles) {\n // compiler doesn't support this file type. copy the file as is to the dist dir.\n this.dists.push(new Dist({ base, path: path.join(base, file.relative), contents: file.contents }));\n }\n }\n\n private async compileAllFilesWithNewCompiler(\n component: ConsumerComponent,\n initiator: CompilationInitiator\n ): Promise<void> {\n const base = this.distDir;\n const filesToCompile: SourceFile[] = [];\n component.files.forEach((file: SourceFile) => {\n const isFileSupported = this.compilerInstance.isFileSupported(file.path);\n if (isFileSupported) {\n filesToCompile.push(file);\n } else if (this.compilerInstance.shouldCopyNonSupportedFiles) {\n // compiler doesn't support this file type. copy the file as is to the dist dir.\n this.dists.push(\n new Dist({\n base,\n path: path.join(base, file.relative),\n contents: file.contents,\n })\n );\n }\n });\n\n if (filesToCompile.length) {\n try {\n await this.compilerInstance.transpileComponent?.({\n component,\n componentDir: this.componentDir,\n outputDir: this.workspace.getComponentPackagePath(component),\n initiator,\n });\n } catch (error: any) {\n this.compileErrors.push({ path: this.componentDir, error });\n }\n }\n }\n}\n\nexport class WorkspaceCompiler {\n constructor(\n private workspace: Workspace,\n private envs: EnvsMain,\n private pubsub: PubsubMain,\n private aspectLoader: AspectLoaderMain,\n private ui: UiMain,\n private logger: Logger\n ) {\n if (this.workspace) {\n this.workspace.registerOnComponentChange(this.onComponentChange.bind(this));\n this.workspace.registerOnComponentAdd(this.onComponentChange.bind(this));\n this.workspace.registerOnPreWatch(this.onPreWatch.bind(this));\n this.ui.registerPreStart(this.onPreStart.bind(this));\n }\n if (this.aspectLoader) {\n this.aspectLoader.registerOnAspectLoadErrorSlot(this.onAspectLoadFail.bind(this));\n }\n }\n\n async onPreStart(preStartOpts: PreStartOpts): Promise<void> {\n if (preStartOpts.skipCompilation) {\n return;\n }\n await this.compileComponents([], {\n changed: true,\n verbose: false,\n deleteDistDir: false,\n initiator: CompilationInitiator.PreStart,\n });\n }\n\n async onAspectLoadFail(err: Error & { code?: string }, id: ComponentID): Promise<boolean> {\n if (err.code && err.code === 'MODULE_NOT_FOUND' && this.workspace) {\n await this.compileComponents([id.toString()], { initiator: CompilationInitiator.AspectLoadFail }, true);\n return true;\n }\n return false;\n }\n\n async onComponentChange(\n component: Component,\n files: string[],\n initiator?: CompilationInitiator\n ): Promise<SerializableResults> {\n const buildResults = await this.compileComponents(\n [component.id.toString()],\n { initiator: initiator || CompilationInitiator.ComponentChanged },\n true\n );\n return {\n results: buildResults,\n toString() {\n return `${buildResults[0]?.buildResults?.join('\\n\\t')}`;\n },\n };\n }\n\n async onPreWatch(components: Component[], watchOpts: WatchOptions) {\n if (watchOpts.preCompile) {\n const start = Date.now();\n this.logger.console(`compiling ${components.length} components`);\n await this.compileComponents(\n components.map((c) => c.id._legacy),\n { initiator: CompilationInitiator.PreWatch }\n );\n const end = Date.now() - start;\n this.logger.consoleSuccess(`compiled ${components.length} components successfully (${end / 1000} sec)`);\n }\n }\n\n async compileComponents(\n componentsIds: string[] | BitId[], // when empty, it compiles new+modified (unless options.all is set),\n options: CompileOptions,\n noThrow?: boolean\n ): Promise<BuildResult[]> {\n if (!this.workspace) throw new ConsumerNotFound();\n if (this.workspace.isLegacy) throw new Error('workspace-compiler should work for Harmony workspace only');\n const componentIds = await this.getIdsToCompile(componentsIds, options.changed);\n const components = await this.workspace.getMany(componentIds);\n\n const componentsAndNewCompilers: ComponentCompiler[] = [];\n components.forEach((c) => {\n const environment = this.envs.getEnv(c).env;\n const compilerInstance = environment.getCompiler?.();\n // if there is no componentDir (e.g. author that added files, not dir), then we can't write the dists\n // inside the component dir.\n if (compilerInstance && c.state._consumer.componentMap?.getComponentDir()) {\n const compilerName = compilerInstance.constructor.name || 'compiler';\n componentsAndNewCompilers.push(\n new ComponentCompiler(\n this.pubsub,\n this.workspace,\n c.state._consumer,\n compilerInstance,\n compilerName,\n this.logger\n )\n );\n }\n });\n const newCompilersResultOnWorkspace = await mapSeries(componentsAndNewCompilers, (componentAndNewCompilers) =>\n componentAndNewCompilers.compile(noThrow, options)\n );\n\n return newCompilersResultOnWorkspace;\n }\n\n private async getIdsToCompile(componentsIds: Array<string | BitId>, changed = false): Promise<ComponentID[]> {\n if (componentsIds.length) {\n return this.workspace.resolveMultipleComponentIds(componentsIds);\n }\n if (changed) {\n return this.workspace.getNewAndModifiedIds();\n }\n return this.workspace.getAllComponentIds();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["workspace-compiler.ts"],"names":["ComponentCompiler","constructor","pubsub","workspace","component","compilerInstance","compilerId","logger","dists","compileErrors","compile","noThrow","options","dataToPersist","deleteDistDir","DataToPersist","removePath","RemovePath","distDir","addBasePath","path","persistAllToFS","transpileFile","Promise","all","files","map","file","compileOneFileWithNewCompiler","initiator","transpileComponent","compileAllFilesWithNewCompiler","Error","toString","throwOnCompileErrors","addManyFiles","buildResults","distFile","compiler","loader","succeed","pub","CompilerAspect","id","ComponentCompilationOnDoneEvent","length","forEach","errorItem","error","formatError","err","join","CompilerErrorEvent","console","message","packageName","packageDir","distDirName","DEFAULT_DIST_DIRNAME","componentDir","ComponentID","filePath","relative","isFileSupported","compileResults","contents","push","base","result","Dist","outputPath","Buffer","from","outputText","shouldCopyNonSupportedFiles","filesToCompile","outputDir","getComponentPackagePath","WorkspaceCompiler","envs","aspectLoader","ui","registerOnComponentChange","onComponentChange","bind","registerOnComponentAdd","registerOnPreWatch","onPreWatch","registerPreStart","onPreStart","registerOnAspectLoadErrorSlot","onAspectLoadFail","preStartOpts","skipCompilation","compileComponents","changed","verbose","CompilationInitiator","PreStart","code","AspectLoadFail","ComponentChanged","results","components","watchOpts","preCompile","start","Date","now","c","_legacy","PreWatch","end","consoleSuccess","componentsIds","ConsumerNotFound","isLegacy","componentIds","getIdsToCompile","getMany","componentsAndNewCompilers","environment","getEnv","env","getCompiler","state","_consumer","componentMap","getComponentDir","compilerName","name","newCompilersResultOnWorkspace","componentAndNewCompilers","resolveMultipleComponentIds","getNewAndModifiedIds","getAllComponentIds"],"mappings":";;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAIA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAIA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAvBA;AAyCO,MAAMA,iBAAN,CAAwB;AAC7BC,EAAAA,WAAW,CACDC,MADC,EAEDC,SAFC,EAGDC,SAHC,EAIDC,gBAJC,EAKDC,UALC,EAMDC,MANC,EAODC,KAAa,GAAG,EAPf,EAQDC,aAA6B,GAAG,EAR/B,EAST;AAAA,SAR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AAO,KAAK5F,SAAL,CAAemI,oBAAf,EAAP;AACD;;AACD,WAAO,KAAKnI,SAAL,CAAeoI,kBAAf,EAAP;AACD;;AAvH4B","sourcesContent":["/* eslint-disable max-classes-per-file */\nimport mapSeries from 'p-map-series';\nimport { Component, ComponentID } from '@teambit/component';\nimport { EnvsMain } from '@teambit/envs';\nimport type { PubsubMain } from '@teambit/pubsub';\nimport { SerializableResults, Workspace, WatchOptions } from '@teambit/workspace';\nimport path from 'path';\nimport { BitId } from '@teambit/legacy-bit-id';\nimport { Logger } from '@teambit/logger';\nimport loader from '@teambit/legacy/dist/cli/loader';\nimport { DEFAULT_DIST_DIRNAME } from '@teambit/legacy/dist/constants';\nimport ConsumerComponent from '@teambit/legacy/dist/consumer/component';\nimport { Dist, SourceFile } from '@teambit/legacy/dist/consumer/component/sources';\nimport DataToPersist from '@teambit/legacy/dist/consumer/component/sources/data-to-persist';\nimport { AspectLoaderMain } from '@teambit/aspect-loader';\nimport { ConsumerNotFound } from '@teambit/legacy/dist/consumer/exceptions';\nimport componentIdToPackageName from '@teambit/legacy/dist/utils/bit/component-id-to-package-name';\nimport RemovePath from '@teambit/legacy/dist/consumer/component/sources/remove-path';\nimport { UiMain } from '@teambit/ui';\nimport type { PreStartOpts } from '@teambit/ui';\nimport { PathOsBasedAbsolute, PathOsBasedRelative } from '@teambit/legacy/dist/utils/path';\nimport { CompilerAspect } from './compiler.aspect';\nimport { CompilerErrorEvent, ComponentCompilationOnDoneEvent } from './events';\nimport { Compiler, CompilationInitiator } from './types';\n\nexport type BuildResult = { component: string; buildResults: string[] | null | undefined };\n\nexport type CompileOptions = {\n changed?: boolean; // compile only new and modified components\n verbose?: boolean; // show more data, such as, dist paths\n /**\n * whether the dist root dir should be deleted before writing new dists.\n * defaults to true for `bit compile` and false everywhere else, such as `bit watch` and `bit\n * start` to avoid webpack \"EINTR\" error.\n */\n deleteDistDir?: boolean;\n initiator: CompilationInitiator; // describes where the compilation is coming from\n};\n\nexport type CompileError = { path: string; error: Error };\n\nexport class ComponentCompiler {\n constructor(\n private pubsub: PubsubMain,\n private workspace: Workspace,\n private component: ConsumerComponent,\n private compilerInstance: Compiler,\n private compilerId: string,\n private logger: Logger,\n private dists: Dist[] = [],\n private compileErrors: CompileError[] = []\n ) {}\n\n async compile(noThrow = true, options: CompileOptions): Promise<BuildResult> {\n let dataToPersist;\n const deleteDistDir = options.deleteDistDir ?? this.compilerInstance.deleteDistDir;\n // delete dist folder before transpilation (because some compilers (like ngPackagr) can generate files there during the compilation process)\n if (deleteDistDir) {\n dataToPersist = new DataToPersist();\n dataToPersist.removePath(new RemovePath(this.distDir));\n dataToPersist.addBasePath(this.workspace.path);\n await dataToPersist.persistAllToFS();\n }\n\n if (this.compilerInstance.transpileFile) {\n await Promise.all(\n this.component.files.map((file: SourceFile) => this.compileOneFileWithNewCompiler(file, options.initiator))\n );\n } else if (this.compilerInstance.transpileComponent) {\n await this.compileAllFilesWithNewCompiler(this.component, options.initiator);\n } else {\n throw new Error(\n `compiler ${this.compilerId.toString()} doesn't implement either \"transpileFile\" or \"transpileComponent\" methods`\n );\n }\n this.throwOnCompileErrors(noThrow);\n\n // writing the dists with `component.setDists(dists); component.dists.writeDists` is tricky\n // as it uses other base-paths and doesn't respect the new node-modules base path.\n dataToPersist = new DataToPersist();\n dataToPersist.addManyFiles(this.dists);\n dataToPersist.addBasePath(this.workspace.path);\n await dataToPersist.persistAllToFS();\n const buildResults = this.dists.map((distFile) => distFile.path);\n if (this.component.compiler) loader.succeed();\n this.pubsub.pub(\n CompilerAspect.id,\n new ComponentCompilationOnDoneEvent(this.compileErrors, this.component, buildResults)\n );\n return { component: this.component.id.toString(), buildResults };\n }\n\n private throwOnCompileErrors(noThrow = true) {\n if (this.compileErrors.length) {\n this.compileErrors.forEach((errorItem) => {\n this.logger.error(`compilation error at ${errorItem.path}`, errorItem.error);\n });\n const formatError = (errorItem) => `${errorItem.path}\\n${errorItem.error}`;\n const err = new Error(`compilation failed. see the following errors from the compiler\n${this.compileErrors.map(formatError).join('\\n')}`);\n\n this.pubsub.pub(CompilerAspect.id, new CompilerErrorEvent(err));\n\n if (!noThrow) {\n throw err;\n }\n\n this.logger.console(err.message);\n }\n }\n\n private get distDir(): PathOsBasedRelative {\n const packageName = componentIdToPackageName(this.component);\n const packageDir = path.join('node_modules', packageName);\n const distDirName = DEFAULT_DIST_DIRNAME;\n return path.join(packageDir, distDirName);\n }\n\n private get componentDir(): PathOsBasedAbsolute {\n return this.workspace.componentDir(new ComponentID(this.component.id));\n }\n\n private async compileOneFileWithNewCompiler(file: SourceFile, initiator: CompilationInitiator): Promise<void> {\n const options = { componentDir: this.componentDir, filePath: file.relative, initiator };\n const isFileSupported = this.compilerInstance.isFileSupported(file.path);\n let compileResults;\n if (isFileSupported) {\n try {\n compileResults = this.compilerInstance.transpileFile?.(file.contents.toString(), options);\n } catch (error: any) {\n this.compileErrors.push({ path: file.path, error });\n return;\n }\n }\n const base = this.distDir;\n if (isFileSupported && compileResults) {\n this.dists.push(\n ...compileResults.map(\n (result) =>\n new Dist({\n base,\n path: path.join(base, result.outputPath),\n contents: Buffer.from(result.outputText),\n })\n )\n );\n } else if (this.compilerInstance.shouldCopyNonSupportedFiles) {\n // compiler doesn't support this file type. copy the file as is to the dist dir.\n this.dists.push(new Dist({ base, path: path.join(base, file.relative), contents: file.contents }));\n }\n }\n\n private async compileAllFilesWithNewCompiler(\n component: ConsumerComponent,\n initiator: CompilationInitiator\n ): Promise<void> {\n const base = this.distDir;\n const filesToCompile: SourceFile[] = [];\n component.files.forEach((file: SourceFile) => {\n const isFileSupported = this.compilerInstance.isFileSupported(file.path);\n if (isFileSupported) {\n filesToCompile.push(file);\n } else if (this.compilerInstance.shouldCopyNonSupportedFiles) {\n // compiler doesn't support this file type. copy the file as is to the dist dir.\n this.dists.push(\n new Dist({\n base,\n path: path.join(base, file.relative),\n contents: file.contents,\n })\n );\n }\n });\n\n if (filesToCompile.length) {\n try {\n await this.compilerInstance.transpileComponent?.({\n component,\n componentDir: this.componentDir,\n outputDir: this.workspace.getComponentPackagePath(component),\n initiator,\n });\n } catch (error: any) {\n this.compileErrors.push({ path: this.componentDir, error });\n }\n }\n }\n}\n\nexport class WorkspaceCompiler {\n constructor(\n private workspace: Workspace,\n private envs: EnvsMain,\n private pubsub: PubsubMain,\n private aspectLoader: AspectLoaderMain,\n private ui: UiMain,\n private logger: Logger\n ) {\n if (this.workspace) {\n this.workspace.registerOnComponentChange(this.onComponentChange.bind(this));\n this.workspace.registerOnComponentAdd(this.onComponentChange.bind(this));\n this.workspace.registerOnPreWatch(this.onPreWatch.bind(this));\n this.ui.registerPreStart(this.onPreStart.bind(this));\n }\n if (this.aspectLoader) {\n this.aspectLoader.registerOnAspectLoadErrorSlot(this.onAspectLoadFail.bind(this));\n }\n }\n\n async onPreStart(preStartOpts: PreStartOpts): Promise<void> {\n if (preStartOpts.skipCompilation) {\n return;\n }\n await this.compileComponents([], {\n changed: true,\n verbose: false,\n deleteDistDir: false,\n initiator: CompilationInitiator.PreStart,\n });\n }\n\n async onAspectLoadFail(err: Error & { code?: string }, id: ComponentID): Promise<boolean> {\n if (err.code && err.code === 'MODULE_NOT_FOUND' && this.workspace) {\n await this.compileComponents([id.toString()], { initiator: CompilationInitiator.AspectLoadFail }, true);\n return true;\n }\n return false;\n }\n\n async onComponentChange(\n component: Component,\n files: string[],\n initiator?: CompilationInitiator\n ): Promise<SerializableResults> {\n const buildResults = await this.compileComponents(\n [component.id.toString()],\n { initiator: initiator || CompilationInitiator.ComponentChanged },\n true\n );\n return {\n results: buildResults,\n toString() {\n return `${buildResults[0]?.buildResults?.join('\\n\\t')}`;\n },\n };\n }\n\n async onPreWatch(components: Component[], watchOpts: WatchOptions) {\n if (watchOpts.preCompile) {\n const start = Date.now();\n this.logger.console(`compiling ${components.length} components`);\n await this.compileComponents(\n components.map((c) => c.id._legacy),\n { initiator: CompilationInitiator.PreWatch }\n );\n const end = Date.now() - start;\n this.logger.consoleSuccess(`compiled ${components.length} components successfully (${end / 1000} sec)`);\n }\n }\n\n async compileComponents(\n componentsIds: string[] | BitId[] | ComponentID[], // when empty, it compiles new+modified (unless options.all is set),\n options: CompileOptions,\n noThrow?: boolean\n ): Promise<BuildResult[]> {\n if (!this.workspace) throw new ConsumerNotFound();\n if (this.workspace.isLegacy) throw new Error('workspace-compiler should work for Harmony workspace only');\n const componentIds = await this.getIdsToCompile(componentsIds, options.changed);\n const components = await this.workspace.getMany(componentIds);\n\n const componentsAndNewCompilers: ComponentCompiler[] = [];\n components.forEach((c) => {\n const environment = this.envs.getEnv(c).env;\n const compilerInstance = environment.getCompiler?.();\n // if there is no componentDir (e.g. author that added files, not dir), then we can't write the dists\n // inside the component dir.\n if (compilerInstance && c.state._consumer.componentMap?.getComponentDir()) {\n const compilerName = compilerInstance.constructor.name || 'compiler';\n componentsAndNewCompilers.push(\n new ComponentCompiler(\n this.pubsub,\n this.workspace,\n c.state._consumer,\n compilerInstance,\n compilerName,\n this.logger\n )\n );\n }\n });\n const newCompilersResultOnWorkspace = await mapSeries(componentsAndNewCompilers, (componentAndNewCompilers) =>\n componentAndNewCompilers.compile(noThrow, options)\n );\n\n return newCompilersResultOnWorkspace;\n }\n\n private async getIdsToCompile(\n componentsIds: Array<string | ComponentID | BitId>,\n changed = false\n ): Promise<ComponentID[]> {\n if (componentsIds.length) {\n return this.workspace.resolveMultipleComponentIds(componentsIds);\n }\n if (changed) {\n return this.workspace.getNewAndModifiedIds();\n }\n return this.workspace.getAllComponentIds();\n }\n}\n"]}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/compiler",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.597",
|
|
4
4
|
"homepage": "https://bit.dev/teambit/compilation/compiler",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.compilation",
|
|
8
8
|
"name": "compiler",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.597"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@teambit/harmony": "0.2.11",
|
|
@@ -18,19 +18,19 @@
|
|
|
18
18
|
"p-map-series": "2.1.0",
|
|
19
19
|
"@babel/runtime": "7.12.18",
|
|
20
20
|
"core-js": "^3.0.0",
|
|
21
|
-
"@teambit/cli": "0.0.
|
|
22
|
-
"@teambit/logger": "0.0.
|
|
23
|
-
"@teambit/pubsub": "0.0.
|
|
24
|
-
"@teambit/aspect-loader": "0.0.
|
|
25
|
-
"@teambit/builder": "0.0.
|
|
26
|
-
"@teambit/component": "0.0.
|
|
27
|
-
"@teambit/envs": "0.0.
|
|
28
|
-
"@teambit/generator": "0.0.
|
|
29
|
-
"@teambit/legacy-bit-id": "0.0.
|
|
30
|
-
"@teambit/ui": "0.0.
|
|
31
|
-
"@teambit/workspace": "0.0.
|
|
32
|
-
"@teambit/isolator": "0.0.
|
|
33
|
-
"@teambit/bit-error": "0.0.
|
|
21
|
+
"@teambit/cli": "0.0.410",
|
|
22
|
+
"@teambit/logger": "0.0.498",
|
|
23
|
+
"@teambit/pubsub": "0.0.597",
|
|
24
|
+
"@teambit/aspect-loader": "0.0.597",
|
|
25
|
+
"@teambit/builder": "0.0.597",
|
|
26
|
+
"@teambit/component": "0.0.597",
|
|
27
|
+
"@teambit/envs": "0.0.597",
|
|
28
|
+
"@teambit/generator": "0.0.597",
|
|
29
|
+
"@teambit/legacy-bit-id": "0.0.397",
|
|
30
|
+
"@teambit/ui": "0.0.597",
|
|
31
|
+
"@teambit/workspace": "0.0.597",
|
|
32
|
+
"@teambit/isolator": "0.0.597",
|
|
33
|
+
"@teambit/bit-error": "0.0.394"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/react": "^17.0.8",
|
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
"@types/jest": "^26.0.0",
|
|
41
41
|
"@types/react-dom": "^17.0.5",
|
|
42
42
|
"@types/node": "12.20.4",
|
|
43
|
-
"@teambit/compilation.aspect-docs.compiler": "0.0.
|
|
43
|
+
"@teambit/compilation.aspect-docs.compiler": "0.0.130"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"@teambit/legacy": "1.0.
|
|
46
|
+
"@teambit/legacy": "1.0.197",
|
|
47
47
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
48
48
|
"react": "^16.8.0 || ^17.0.0"
|
|
49
49
|
},
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"react": "-"
|
|
72
72
|
},
|
|
73
73
|
"peerDependencies": {
|
|
74
|
-
"@teambit/legacy": "1.0.
|
|
74
|
+
"@teambit/legacy": "1.0.197",
|
|
75
75
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
76
76
|
"react": "^16.8.0 || ^17.0.0"
|
|
77
77
|
}
|
|
Binary file
|