@teambit/compiler 0.0.521 → 0.0.525

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/compiler.cmd.ts CHANGED
@@ -40,7 +40,7 @@ export class CompileCmd implements Command {
40
40
  let outputString = '';
41
41
  await this.compile.compileComponents(components, {
42
42
  ...compilerOptions,
43
- origin: CompilationInitiator.CmdReport,
43
+ initiator: CompilationInitiator.CmdReport,
44
44
  deleteDistDir: true,
45
45
  });
46
46
  const compileTimeLength = process.hrtime(startTimestamp);
@@ -65,7 +65,7 @@ export class CompileCmd implements Command {
65
65
  // @ts-ignore
66
66
  const compileResults = await this.compile.compileComponents(components, {
67
67
  ...compilerOptions,
68
- origin: CompilationInitiator.CmdJson,
68
+ initiator: CompilationInitiator.CmdJson,
69
69
  deleteDistDir: true,
70
70
  });
71
71
  return {
@@ -32,7 +32,7 @@ export class CompilerMain {
32
32
  */
33
33
  compileOnWorkspace(
34
34
  componentsIds: string[] | BitId[] = [], // when empty, it compiles all
35
- options: CompileOptions = { origin: CompilationInitiator.ComponentAdded }
35
+ options: CompileOptions = { initiator: CompilationInitiator.ComponentAdded }
36
36
  ) {
37
37
  return this.workspaceCompiler.compileComponents(componentsIds, options);
38
38
  }
@@ -104,7 +104,7 @@ class CompileCmd {
104
104
  this.pubsub.sub(_compiler().CompilerAspect.id, this.onComponentCompilationDone.bind(this));
105
105
  let outputString = '';
106
106
  await this.compile.compileComponents(components, _objectSpread(_objectSpread({}, compilerOptions), {}, {
107
- origin: _types().CompilationInitiator.CmdReport,
107
+ initiator: _types().CompilationInitiator.CmdReport,
108
108
  deleteDistDir: true
109
109
  }));
110
110
  const compileTimeLength = process.hrtime(startTimestamp);
@@ -124,7 +124,7 @@ class CompileCmd {
124
124
  compilerOptions.deleteDistDir = true; // @ts-ignore
125
125
 
126
126
  const compileResults = await this.compile.compileComponents(components, _objectSpread(_objectSpread({}, compilerOptions), {}, {
127
- origin: _types().CompilationInitiator.CmdJson,
127
+ initiator: _types().CompilationInitiator.CmdJson,
128
128
  deleteDistDir: true
129
129
  }));
130
130
  return {
@@ -1 +1 @@
1
- {"version":3,"sources":["compiler.cmd.ts"],"names":["CompileCmd","constructor","compile","logger","pubsub","report","components","compilerOptions","startTimestamp","process","hrtime","setStatusLine","sub","CompilerAspect","id","onComponentCompilationDone","bind","outputString","compileComponents","origin","CompilationInitiator","CmdReport","deleteDistDir","compileTimeLength","chalk","underline","componentsStatus","verbose","getStatusLine","clearStatusLine","data","code","getExitCode","json","compileResults","CmdJson","failedComponents","filter","component","errors","length","getSummaryIcon","green","red","yellow","numberOfComponents","numberOfFailingComponents","numberOfSuccessfulComponents","icon","summaryLine","event","type","ComponentCompilationOnDoneEvent","TYPE","push"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;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;;;;;;AAQO,MAAMA,UAAN,CAAoC;AAYzCC,EAAAA,WAAW,CAASC,OAAT,EAA6CC,MAA7C,EAAqEC,MAArE,EAAyF;AAAA,SAAhFF,OAAgF,GAAhFA,OAAgF;AAAA,SAA5CC,MAA4C,GAA5CA,MAA4C;AAAA,SAApBC,MAAoB,GAApBA,MAAoB;AAAA,8DAXxD,EAWwD;AAAA,kDAV7F,wBAU6F;AAAA,yDATtF,iDASsF;AAAA,mDAR5F,EAQ4F;AAAA,mDAP5F,aAO4F;AAAA,qDAN1F,CACR,CAAC,GAAD,EAAM,SAAN,EAAiB,0CAAjB,CADQ,EAER,CAAC,GAAD,EAAM,SAAN,EAAiB,qCAAjB,CAFQ,EAGR,CAAC,GAAD,E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oBf,gBAApB,CAAb;AACA,UAAMuB,WAAW,GAAGH,yBAAyB,GACxC,GAAEE,IAAK,IAAGF,yBAA0B,IAAGD,kBAAmB,gCADlB,GAExC,GAAEG,IAAK,IAAGD,4BAA6B,IAAGF,kBAAmB,oCAFlE;AAIA,WAAQ,GAAEI,WAAY,gBAAe,2BAAW1B,iBAAX,CAA8B,GAAnE;AACD;;AAEOR,EAAAA,0BAA0B,CAACmC,KAAD,EAA2B;AAC3D,QAAIA,KAAK,CAACC,IAAN,KAAeC,0CAAgCC,IAAnD,EAAyD;AACvD,WAAK3B,gBAAL,CAAsB4B,IAAtB,CAA2BJ,KAAK,CAACpB,IAAjC;AACD;AACF;;AA7FwC","sourcesContent":["import { Command, CommandOptions } from '@teambit/cli';\nimport { Logger } from '@teambit/logger';\nimport type { PubsubMain, BitBaseEvent } from '@teambit/pubsub';\nimport chalk from 'chalk';\nimport prettyTime from 'pretty-time';\nimport type ConsumerComponent from '@teambit/legacy/dist/consumer/component';\nimport { formatCompileResults } from './output-formatter';\nimport { CompileError, WorkspaceCompiler, CompileOptions } from './workspace-compiler';\nimport { CompilationInitiator } from './types';\n\n// IDs & events\nimport { CompilerAspect } from './compiler.aspect';\nimport { ComponentCompilationOnDoneEvent } from './events';\n\ntype ComponentsStatus = {\n buildResults: string[];\n component: Array<ConsumerComponent>;\n errors: Array<CompileError>;\n};\n\nexport class CompileCmd implements Command {\n componentsStatus: Array<ComponentsStatus> = [];\n name = 'compile [component...]';\n description = 'compile components in the development workspace';\n alias = '';\n group = 'development';\n options = [\n ['c', 'changed', 'compile only new and modified components'],\n ['v', 'verbose', 'show more data, such as, dist paths'],\n ['j', 'json', 'return the compile results in json format'],\n ] as CommandOptions;\n\n constructor(private compile: WorkspaceCompiler, private logger: Logger, private pubsub: PubsubMain) {}\n\n async report([components = []]: [string[]], compilerOptions: CompileOptions) {\n const startTimestamp = process.hrtime();\n this.logger.setStatusLine('Compiling your components, hold tight.');\n this.pubsub.sub(CompilerAspect.id, this.onComponentCompilationDone.bind(this));\n\n let outputString = '';\n await this.compile.compileComponents(components, {\n ...compilerOptions,\n origin: CompilationInitiator.CmdReport,\n deleteDistDir: true,\n });\n const compileTimeLength = process.hrtime(startTimestamp);\n\n outputString += '\\n';\n outputString += ` ${chalk.underline('STATUS')}\\t${chalk.underline('COMPONENT ID')}\\n`;\n outputString += formatCompileResults(this.componentsStatus, compilerOptions.verbose);\n outputString += '\\n';\n\n outputString += this.getStatusLine(this.componentsStatus, compileTimeLength);\n\n this.logger.clearStatusLine();\n\n return {\n data: outputString,\n code: this.getExitCode(this.componentsStatus),\n };\n }\n\n async json([components]: [string[]], compilerOptions: CompileOptions) {\n compilerOptions.deleteDistDir = true;\n // @ts-ignore\n const compileResults = await this.compile.compileComponents(components, {\n ...compilerOptions,\n origin: CompilationInitiator.CmdJson,\n deleteDistDir: true,\n });\n return {\n data: compileResults,\n // @todo: fix the code once compile is ready.\n code: 0,\n };\n }\n\n private failedComponents(componentsStatus: ComponentsStatus[]): ComponentsStatus[] {\n return componentsStatus.filter((component) => component.errors.length);\n }\n\n private getSummaryIcon(componentsStatus: ComponentsStatus[]) {\n switch (this.failedComponents(componentsStatus).length) {\n case 0:\n return chalk.green('✔');\n case componentsStatus.length:\n return chalk.red('✗');\n default:\n return chalk.yellow('⍻');\n }\n }\n\n private getExitCode(componentsStatus: ComponentsStatus[]) {\n return this.failedComponents(componentsStatus).length ? 1 : 0;\n }\n\n private getStatusLine(componentsStatus: ComponentsStatus[], compileTimeLength) {\n const numberOfComponents = componentsStatus.length;\n const numberOfFailingComponents = this.failedComponents(componentsStatus).length;\n const numberOfSuccessfulComponents = componentsStatus.filter((component) => !component.errors.length).length;\n\n const icon = this.getSummaryIcon(componentsStatus);\n const summaryLine = numberOfFailingComponents\n ? `${icon} ${numberOfFailingComponents}/${numberOfComponents} components failed to compile.`\n : `${icon} ${numberOfSuccessfulComponents}/${numberOfComponents} components compiled successfully.`;\n\n return `${summaryLine}\\nFinished. (${prettyTime(compileTimeLength)})`;\n }\n\n private onComponentCompilationDone(event: BitBaseEvent<any>) {\n if (event.type === ComponentCompilationOnDoneEvent.TYPE) {\n this.componentsStatus.push(event.data);\n }\n }\n}\n"]}
1
+ {"version":3,"sources":["compiler.cmd.ts"],"names":["CompileCmd","constructor","compile","logger","pubsub","report","components","compilerOptions","startTimestamp","process","hrtime","setStatusLine","sub","CompilerAspect","id","onComponentCompilationDone","bind","outputString","compileComponents","initiator","CompilationInitiator","CmdReport","deleteDistDir","compileTimeLength","chalk","underline","componentsStatus","verbose","getStatusLine","clearStatusLine","data","code","getExitCode","json","compileResults","CmdJson","failedComponents","filter","component","errors","length","getSummaryIcon","green","red","yellow","numberOfComponents","numberOfFailingComponents","numberOfSuccessfulComponents","icon","summaryLine","event","type","ComponentCompilationOnDoneEvent","TYPE","push"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;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;;;;;;AAQO,MAAMA,UAAN,CAAoC;AAYzCC,EAAAA,WAAW,CAASC,OAAT,EAA6CC,MAA7C,EAAqEC,MAArE,EAAyF;AAAA,SAAhFF,OAAgF,GAAhFA,OAAgF;AAAA,SAA5CC,MAA4C,GAA5CA,MAA4C;AAAA,SAApBC,MAAoB,GAApBA,MAAoB;AAAA,8DAXxD,EAWwD;AAAA,kDAV7F,wBAU6F;AAAA,yDATtF,iDASsF;AAAA,mDAR5F,EAQ4F;AAAA,mDAP5F,aAO4F;AAAA,qDAN1F,CACR,CAAC,GAAD,EAAM,SAAN,EAAiB,0CAAjB,CADQ,EAER,CAAC,GAAD,EAAM,SAAN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AAEA,UAAMQ,IAAI,GAAG,KAAKP,cAAL,CAAoBf,gBAApB,CAAb;AACA,UAAMuB,WAAW,GAAGH,yBAAyB,GACxC,GAAEE,IAAK,IAAGF,yBAA0B,IAAGD,kBAAmB,gCADlB,GAExC,GAAEG,IAAK,IAAGD,4BAA6B,IAAGF,kBAAmB,oCAFlE;AAIA,WAAQ,GAAEI,WAAY,gBAAe,2BAAW1B,iBAAX,CAA8B,GAAnE;AACD;;AAEOR,EAAAA,0BAA0B,CAACmC,KAAD,EAA2B;AAC3D,QAAIA,KAAK,CAACC,IAAN,KAAeC,0CAAgCC,IAAnD,EAAyD;AACvD,WAAK3B,gBAAL,CAAsB4B,IAAtB,CAA2BJ,KAAK,CAACpB,IAAjC;AACD;AACF;;AA7FwC","sourcesContent":["import { Command, CommandOptions } from '@teambit/cli';\nimport { Logger } from '@teambit/logger';\nimport type { PubsubMain, BitBaseEvent } from '@teambit/pubsub';\nimport chalk from 'chalk';\nimport prettyTime from 'pretty-time';\nimport type ConsumerComponent from '@teambit/legacy/dist/consumer/component';\nimport { formatCompileResults } from './output-formatter';\nimport { CompileError, WorkspaceCompiler, CompileOptions } from './workspace-compiler';\nimport { CompilationInitiator } from './types';\n\n// IDs & events\nimport { CompilerAspect } from './compiler.aspect';\nimport { ComponentCompilationOnDoneEvent } from './events';\n\ntype ComponentsStatus = {\n buildResults: string[];\n component: Array<ConsumerComponent>;\n errors: Array<CompileError>;\n};\n\nexport class CompileCmd implements Command {\n componentsStatus: Array<ComponentsStatus> = [];\n name = 'compile [component...]';\n description = 'compile components in the development workspace';\n alias = '';\n group = 'development';\n options = [\n ['c', 'changed', 'compile only new and modified components'],\n ['v', 'verbose', 'show more data, such as, dist paths'],\n ['j', 'json', 'return the compile results in json format'],\n ] as CommandOptions;\n\n constructor(private compile: WorkspaceCompiler, private logger: Logger, private pubsub: PubsubMain) {}\n\n async report([components = []]: [string[]], compilerOptions: CompileOptions) {\n const startTimestamp = process.hrtime();\n this.logger.setStatusLine('Compiling your components, hold tight.');\n this.pubsub.sub(CompilerAspect.id, this.onComponentCompilationDone.bind(this));\n\n let outputString = '';\n await this.compile.compileComponents(components, {\n ...compilerOptions,\n initiator: CompilationInitiator.CmdReport,\n deleteDistDir: true,\n });\n const compileTimeLength = process.hrtime(startTimestamp);\n\n outputString += '\\n';\n outputString += ` ${chalk.underline('STATUS')}\\t${chalk.underline('COMPONENT ID')}\\n`;\n outputString += formatCompileResults(this.componentsStatus, compilerOptions.verbose);\n outputString += '\\n';\n\n outputString += this.getStatusLine(this.componentsStatus, compileTimeLength);\n\n this.logger.clearStatusLine();\n\n return {\n data: outputString,\n code: this.getExitCode(this.componentsStatus),\n };\n }\n\n async json([components]: [string[]], compilerOptions: CompileOptions) {\n compilerOptions.deleteDistDir = true;\n // @ts-ignore\n const compileResults = await this.compile.compileComponents(components, {\n ...compilerOptions,\n initiator: CompilationInitiator.CmdJson,\n deleteDistDir: true,\n });\n return {\n data: compileResults,\n // @todo: fix the code once compile is ready.\n code: 0,\n };\n }\n\n private failedComponents(componentsStatus: ComponentsStatus[]): ComponentsStatus[] {\n return componentsStatus.filter((component) => component.errors.length);\n }\n\n private getSummaryIcon(componentsStatus: ComponentsStatus[]) {\n switch (this.failedComponents(componentsStatus).length) {\n case 0:\n return chalk.green('✔');\n case componentsStatus.length:\n return chalk.red('✗');\n default:\n return chalk.yellow('⍻');\n }\n }\n\n private getExitCode(componentsStatus: ComponentsStatus[]) {\n return this.failedComponents(componentsStatus).length ? 1 : 0;\n }\n\n private getStatusLine(componentsStatus: ComponentsStatus[], compileTimeLength) {\n const numberOfComponents = componentsStatus.length;\n const numberOfFailingComponents = this.failedComponents(componentsStatus).length;\n const numberOfSuccessfulComponents = componentsStatus.filter((component) => !component.errors.length).length;\n\n const icon = this.getSummaryIcon(componentsStatus);\n const summaryLine = numberOfFailingComponents\n ? `${icon} ${numberOfFailingComponents}/${numberOfComponents} components failed to compile.`\n : `${icon} ${numberOfSuccessfulComponents}/${numberOfComponents} components compiled successfully.`;\n\n return `${summaryLine}\\nFinished. (${prettyTime(compileTimeLength)})`;\n }\n\n private onComponentCompilationDone(event: BitBaseEvent<any>) {\n if (event.type === ComponentCompilationOnDoneEvent.TYPE) {\n this.componentsStatus.push(event.data);\n }\n }\n}\n"]}
@@ -205,7 +205,7 @@ class CompilerMain {
205
205
 
206
206
  compileOnWorkspace(componentsIds = [], // when empty, it compiles all
207
207
  options = {
208
- origin: _types().CompilationInitiator.ComponentAdded
208
+ initiator: _types().CompilationInitiator.ComponentAdded
209
209
  }) {
210
210
  return this.workspaceCompiler.compileComponents(componentsIds, options);
211
211
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["compiler.main.runtime.ts"],"names":["CompilerMain","constructor","pubsub","workspaceCompiler","envs","builder","compileOnWorkspace","componentsIds","options","origin","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","WorkspaceCompiler","registerService","CompilerService","compilerMain","logger","createLogger","register","CompileCmd","ManyComponentsWriter","externalCompiler","bind","MainRuntime","CLIAspect","WorkspaceAspect","EnvsAspect","LoggerAspect","PubsubAspect","AspectLoaderAspect","BuilderAspect","UIAspect","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;A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,CAAqCP,YAArC,CAAxC;AAEA,WAAOA,YAAP;AACD;;AA1EuB;;;gCAAb1C,Y,aA0CMkD,kB;gCA1CNlD,Y,kBA4CW,CACpBmD,gBADoB,EAEpBC,4BAFoB,EAGpBC,kBAHoB,EAIpBC,sBAJoB,EAKpBC,sBALoB,EAMpBC,uBANoB,EAOpBC,wBAPoB,EAQpBC,aARoB,C;;AAiCxBzC,2BAAe0C,UAAf,CAA0B3D,YAA1B","sourcesContent":["import AspectLoaderAspect, { AspectLoaderMain } from '@teambit/aspect-loader';\nimport { BuilderAspect, BuilderMain } from '@teambit/builder';\nimport { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';\nimport { Component } 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 { 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';\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[] = [], // when empty, it compiles all\n options: CompileOptions = { origin: 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 ];\n\n static async provider([cli, workspace, envs, loggerMain, pubsub, aspectLoader, builder, ui]: [\n CLIMain,\n Workspace,\n EnvsMain,\n LoggerMain,\n PubsubMain,\n AspectLoaderMain,\n BuilderMain,\n UiMain\n ]) {\n const workspaceCompiler = new WorkspaceCompiler(workspace, envs, pubsub, aspectLoader, ui);\n envs.registerService(new CompilerService());\n const compilerMain = new CompilerMain(pubsub, workspaceCompiler, envs, builder);\n const logger = loggerMain.createLogger(CompilerAspect.id);\n cli.register(new CompileCmd(workspaceCompiler, logger, pubsub));\n\n ManyComponentsWriter.externalCompiler = compilerMain.compileOnWorkspace.bind(compilerMain);\n\n return compilerMain;\n }\n}\n\nCompilerAspect.addRuntime(CompilerMain);\n"]}
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","WorkspaceCompiler","registerService","CompilerService","compilerMain","logger","createLogger","register","CompileCmd","ManyComponentsWriter","externalCompiler","bind","MainRuntime","CLIAspect","WorkspaceAspect","EnvsAspect","LoggerAspect","PubsubAspect","AspectLoaderAspect","BuilderAspect","UIAspect","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;;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;AA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C,YAA3C,EAAyDhC,OAAzD,EAAkEiC,EAAlE,CAAD,EASlB;AACD,UAAMnC,iBAAiB,GAAG,KAAIoC,sCAAJ,EAAsBJ,SAAtB,EAAiC/B,IAAjC,EAAuCF,MAAvC,EAA+CmC,YAA/C,EAA6DC,EAA7D,CAA1B;AACAlC,IAAAA,IAAI,CAACoC,eAAL,CAAqB,KAAIC,4BAAJ,GAArB;AACA,UAAMC,YAAY,GAAG,IAAI1C,YAAJ,CAAiBE,MAAjB,EAAyBC,iBAAzB,EAA4CC,IAA5C,EAAkDC,OAAlD,CAArB;AACA,UAAMsC,MAAM,GAAGP,UAAU,CAACQ,YAAX,CAAwB3B,2BAAeC,EAAvC,CAAf;AACAgB,IAAAA,GAAG,CAACW,QAAJ,CAAa,KAAIC,uBAAJ,EAAe3C,iBAAf,EAAkCwC,MAAlC,EAA0CzC,MAA1C,CAAb;AAEA6C,oCAAqBC,gBAArB,GAAwCN,YAAY,CAACpC,kBAAb,CAAgC2C,IAAhC,CAAqCP,YAArC,CAAxC;AAEA,WAAOA,YAAP;AACD;;AA1EuB;;;gCAAb1C,Y,aA0CMkD,kB;gCA1CNlD,Y,kBA4CW,CACpBmD,gBADoB,EAEpBC,4BAFoB,EAGpBC,kBAHoB,EAIpBC,sBAJoB,EAKpBC,sBALoB,EAMpBC,uBANoB,EAOpBC,wBAPoB,EAQpBC,aARoB,C;;AAiCxBzC,2BAAe0C,UAAf,CAA0B3D,YAA1B","sourcesContent":["import AspectLoaderAspect, { AspectLoaderMain } from '@teambit/aspect-loader';\nimport { BuilderAspect, BuilderMain } from '@teambit/builder';\nimport { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';\nimport { Component } 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 { 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';\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[] = [], // 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 ];\n\n static async provider([cli, workspace, envs, loggerMain, pubsub, aspectLoader, builder, ui]: [\n CLIMain,\n Workspace,\n EnvsMain,\n LoggerMain,\n PubsubMain,\n AspectLoaderMain,\n BuilderMain,\n UiMain\n ]) {\n const workspaceCompiler = new WorkspaceCompiler(workspace, envs, pubsub, aspectLoader, ui);\n envs.registerService(new CompilerService());\n const compilerMain = new CompilerMain(pubsub, workspaceCompiler, envs, builder);\n const logger = loggerMain.createLogger(CompilerAspect.id);\n cli.register(new CompileCmd(workspaceCompiler, logger, pubsub));\n\n ManyComponentsWriter.externalCompiler = compilerMain.compileOnWorkspace.bind(compilerMain);\n\n return compilerMain;\n }\n}\n\nCompilerAspect.addRuntime(CompilerMain);\n"]}
package/dist/types.d.ts CHANGED
@@ -9,15 +9,16 @@ export declare enum CompilationInitiator {
9
9
  CmdReport = 0,
10
10
  CmdJson = 1,
11
11
  PreStart = 2,
12
- ComponentChanged = 3,
13
- AspectLoadFail = 4,
14
- ComponentAdded = 5
12
+ Start = 3,
13
+ ComponentChanged = 4,
14
+ AspectLoadFail = 5,
15
+ ComponentAdded = 6
15
16
  }
16
17
  export declare type TranspileComponentParams = {
17
18
  component: ConsumerComponent;
18
19
  componentDir: string;
19
20
  outputDir: string;
20
- origin: CompilationInitiator;
21
+ initiator: CompilationInitiator;
21
22
  };
22
23
  export declare type TranspileFileOutput = {
23
24
  outputText: string;
package/dist/types.js CHANGED
@@ -11,9 +11,10 @@ exports.CompilationInitiator = CompilationInitiator;
11
11
  CompilationInitiator[CompilationInitiator["CmdReport"] = 0] = "CmdReport";
12
12
  CompilationInitiator[CompilationInitiator["CmdJson"] = 1] = "CmdJson";
13
13
  CompilationInitiator[CompilationInitiator["PreStart"] = 2] = "PreStart";
14
- CompilationInitiator[CompilationInitiator["ComponentChanged"] = 3] = "ComponentChanged";
15
- CompilationInitiator[CompilationInitiator["AspectLoadFail"] = 4] = "AspectLoadFail";
16
- CompilationInitiator[CompilationInitiator["ComponentAdded"] = 5] = "ComponentAdded";
14
+ CompilationInitiator[CompilationInitiator["Start"] = 3] = "Start";
15
+ CompilationInitiator[CompilationInitiator["ComponentChanged"] = 4] = "ComponentChanged";
16
+ CompilationInitiator[CompilationInitiator["AspectLoadFail"] = 5] = "AspectLoadFail";
17
+ CompilationInitiator[CompilationInitiator["ComponentAdded"] = 6] = "ComponentAdded";
17
18
  })(CompilationInitiator || (exports.CompilationInitiator = CompilationInitiator = {}));
18
19
 
19
20
  //# sourceMappingURL=types.js.map
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["types.ts"],"names":["CompilationInitiator"],"mappings":";;;;;;IASYA,oB;;;WAAAA,oB;AAAAA,EAAAA,oB,CAAAA,oB;AAAAA,EAAAA,oB,CAAAA,oB;AAAAA,EAAAA,oB,CAAAA,oB;AAAAA,EAAAA,oB,CAAAA,oB;AAAAA,EAAAA,oB,CAAAA,oB;AAAAA,EAAAA,oB,CAAAA,oB;GAAAA,oB,oCAAAA,oB","sourcesContent":["import { BuildContext, BuildTask, BuiltTaskResult, TaskResultsList } from '@teambit/builder';\nimport ConsumerComponent from '@teambit/legacy/dist/consumer/component';\nimport type { Component } from '@teambit/component';\n\nexport type TranspileFileParams = {\n componentDir: string; // absolute path of the component's root directory\n filePath: string; // relative path of the file inside the component directory\n};\n\nexport enum CompilationInitiator {\n CmdReport,\n CmdJson,\n PreStart,\n ComponentChanged,\n AspectLoadFail,\n ComponentAdded,\n}\n\nexport type TranspileComponentParams = {\n component: ConsumerComponent;\n componentDir: string; // absolute path of the component's root directory\n outputDir: string; // absolute path of the component's output directory\n origin: CompilationInitiator; // origin of the compilation's request\n};\n\nexport type TranspileFileOutput =\n | {\n outputText: string;\n outputPath: string;\n }[]\n | null;\n\nexport interface CompilerOptions {\n /**\n * name of the compiler.\n */\n name?: string;\n\n /**\n * relative path of the dist directory inside the capsule. e.g. \"dist\".\n */\n distDir: string;\n\n /**\n * determines which ones of the generated files will be saved in the bit objects when tagging.\n * e.g. distGlobPatterns = [`${this.distDir}/**`, `!${this.distDir}/tsconfig.tsbuildinfo`];\n * see https://github.com/mrmlnc/fast-glob for the supported glob patters syntax.\n */\n distGlobPatterns?: string[];\n\n /**\n * whether or not unsupported files (such as assets) should be copied into the dist directory\n */\n shouldCopyNonSupportedFiles?: boolean;\n\n /**\n * optional. default to \"dist\".\n * useful when the build pipeline has multiple compiler tasks of the same compiler.\n * e.g. using the same Babel compiler for two different tasks, one for creating \"es5\" files, and\n * the second for creating \"esm\". the artifact names would be \"es5\" and \"esm\" accordingly.\n */\n artifactName?: string;\n}\n\nexport interface Compiler extends CompilerOptions {\n /**\n * id of the compiler.\n */\n id: string;\n\n /**\n * serialized config of the compiler.\n */\n displayConfig?(): string;\n\n /**\n * transpile a single file that gets saved into the workspace, used by `bit compile` and during\n * development\n */\n transpileFile?: (fileContent: string, params: TranspileFileParams) => TranspileFileOutput;\n\n /**\n * transpile all the files of a component, use this when you can't use `transpileFile`\n */\n transpileComponent?: (params: TranspileComponentParams) => Promise<void>;\n\n /**\n * compile components inside isolated capsules. this being used during tag for the release.\n * meaning, the final package of the component has the dists generated by this method.\n */\n build(context: BuildContext): Promise<BuiltTaskResult>;\n\n /**\n * given a source file, return its parallel in the dists. e.g. \"index.ts\" => \"dist/index.js\"\n * both, the return path and the given path are relative paths.\n */\n getDistPathBySrcPath(srcPath: string): string;\n\n /**\n * given a component, returns the path to the source folder to use for the preview, uses the one\n * in node_modules by default\n */\n getPreviewComponentRootPath?(component: Component): string;\n\n /**\n * only supported files matching get compiled. others, are copied to the dist dir.\n */\n isFileSupported(filePath: string): boolean;\n\n /**\n * sugar to create a Compiler task via the concrete compiler\n */\n createTask?(name?: string): BuildTask;\n\n /**\n * run before the build pipeline has started. this is useful when some preparation are needed to\n * be done on all envs before the build starts.\n */\n preBuild?(context: BuildContext): Promise<void>;\n\n /**\n * run after the build pipeline completed for all envs. useful for some cleanups\n */\n postBuild?(context: BuildContext, tasksResults: TaskResultsList): Promise<void>;\n\n /**\n * returns the version of the current compiler instance (e.g. '4.0.1').\n */\n version(): string;\n\n /**\n * returns the display name of the current compiler instance (e.g. 'TypeScript')\n */\n displayName: string;\n}\n"]}
1
+ {"version":3,"sources":["types.ts"],"names":["CompilationInitiator"],"mappings":";;;;;;IASYA,oB;;;WAAAA,oB;AAAAA,EAAAA,oB,CAAAA,oB;AAAAA,EAAAA,oB,CAAAA,oB;AAAAA,EAAAA,oB,CAAAA,oB;AAAAA,EAAAA,oB,CAAAA,oB;AAAAA,EAAAA,oB,CAAAA,oB;AAAAA,EAAAA,oB,CAAAA,oB;AAAAA,EAAAA,oB,CAAAA,oB;GAAAA,oB,oCAAAA,oB","sourcesContent":["import { BuildContext, BuildTask, BuiltTaskResult, TaskResultsList } from '@teambit/builder';\nimport ConsumerComponent from '@teambit/legacy/dist/consumer/component';\nimport type { Component } from '@teambit/component';\n\nexport type TranspileFileParams = {\n componentDir: string; // absolute path of the component's root directory\n filePath: string; // relative path of the file inside the component directory\n};\n\nexport enum CompilationInitiator {\n CmdReport,\n CmdJson,\n PreStart,\n Start,\n ComponentChanged,\n AspectLoadFail,\n ComponentAdded,\n}\n\nexport type TranspileComponentParams = {\n component: ConsumerComponent;\n componentDir: string; // absolute path of the component's root directory\n outputDir: string; // absolute path of the component's output directory\n initiator: CompilationInitiator; // origin of the compilation's request\n};\n\nexport type TranspileFileOutput =\n | {\n outputText: string;\n outputPath: string;\n }[]\n | null;\n\nexport interface CompilerOptions {\n /**\n * name of the compiler.\n */\n name?: string;\n\n /**\n * relative path of the dist directory inside the capsule. e.g. \"dist\".\n */\n distDir: string;\n\n /**\n * determines which ones of the generated files will be saved in the bit objects when tagging.\n * e.g. distGlobPatterns = [`${this.distDir}/**`, `!${this.distDir}/tsconfig.tsbuildinfo`];\n * see https://github.com/mrmlnc/fast-glob for the supported glob patters syntax.\n */\n distGlobPatterns?: string[];\n\n /**\n * whether or not unsupported files (such as assets) should be copied into the dist directory\n */\n shouldCopyNonSupportedFiles?: boolean;\n\n /**\n * optional. default to \"dist\".\n * useful when the build pipeline has multiple compiler tasks of the same compiler.\n * e.g. using the same Babel compiler for two different tasks, one for creating \"es5\" files, and\n * the second for creating \"esm\". the artifact names would be \"es5\" and \"esm\" accordingly.\n */\n artifactName?: string;\n}\n\nexport interface Compiler extends CompilerOptions {\n /**\n * id of the compiler.\n */\n id: string;\n\n /**\n * serialized config of the compiler.\n */\n displayConfig?(): string;\n\n /**\n * transpile a single file that gets saved into the workspace, used by `bit compile` and during\n * development\n */\n transpileFile?: (fileContent: string, params: TranspileFileParams) => TranspileFileOutput;\n\n /**\n * transpile all the files of a component, use this when you can't use `transpileFile`\n */\n transpileComponent?: (params: TranspileComponentParams) => Promise<void>;\n\n /**\n * compile components inside isolated capsules. this being used during tag for the release.\n * meaning, the final package of the component has the dists generated by this method.\n */\n build(context: BuildContext): Promise<BuiltTaskResult>;\n\n /**\n * given a source file, return its parallel in the dists. e.g. \"index.ts\" => \"dist/index.js\"\n * both, the return path and the given path are relative paths.\n */\n getDistPathBySrcPath(srcPath: string): string;\n\n /**\n * given a component, returns the path to the source folder to use for the preview, uses the one\n * in node_modules by default\n */\n getPreviewComponentRootPath?(component: Component): string;\n\n /**\n * only supported files matching get compiled. others, are copied to the dist dir.\n */\n isFileSupported(filePath: string): boolean;\n\n /**\n * sugar to create a Compiler task via the concrete compiler\n */\n createTask?(name?: string): BuildTask;\n\n /**\n * run before the build pipeline has started. this is useful when some preparation are needed to\n * be done on all envs before the build starts.\n */\n preBuild?(context: BuildContext): Promise<void>;\n\n /**\n * run after the build pipeline completed for all envs. useful for some cleanups\n */\n postBuild?(context: BuildContext, tasksResults: TaskResultsList): Promise<void>;\n\n /**\n * returns the version of the current compiler instance (e.g. '4.0.1').\n */\n version(): string;\n\n /**\n * returns the display name of the current compiler instance (e.g. 'TypeScript')\n */\n displayName: string;\n}\n"]}
@@ -17,7 +17,7 @@ export declare type CompileOptions = {
17
17
  changed?: boolean;
18
18
  verbose?: boolean;
19
19
  deleteDistDir?: boolean;
20
- origin: CompilationInitiator;
20
+ initiator: CompilationInitiator;
21
21
  };
22
22
  export declare type CompileError = {
23
23
  path: string;
@@ -50,7 +50,7 @@ export declare class WorkspaceCompiler {
50
50
  onAspectLoadFail(err: Error & {
51
51
  code?: string;
52
52
  }, id: ComponentID): Promise<boolean>;
53
- onComponentChange(component: Component): Promise<SerializableResults>;
53
+ onComponentChange(component: Component, initiator?: CompilationInitiator): Promise<SerializableResults>;
54
54
  compileComponents(componentsIds: string[] | BitId[], options: CompileOptions, noThrow?: boolean): Promise<BuildResult[]>;
55
55
  private getIdsToCompile;
56
56
  }
@@ -174,9 +174,9 @@ class ComponentCompiler {
174
174
  }
175
175
 
176
176
  if (this.compilerInstance.transpileFile) {
177
- await Promise.all(this.component.files.map(file => this.compileOneFileWithNewCompiler(file, options.origin)));
177
+ await Promise.all(this.component.files.map(file => this.compileOneFileWithNewCompiler(file, options.initiator)));
178
178
  } else if (this.compilerInstance.transpileComponent) {
179
- await this.compileAllFilesWithNewCompiler(this.component, options.origin);
179
+ await this.compileAllFilesWithNewCompiler(this.component, options.initiator);
180
180
  } else {
181
181
  throw new Error(`compiler ${this.compilerId.toString()} doesn't implement either "transpileFile" or "transpileComponent" methods`);
182
182
  }
@@ -231,11 +231,11 @@ ${this.compileErrors.map(formatError).join('\n')}`);
231
231
  return this.workspace.componentDir(new (_component().ComponentID)(this.component.id));
232
232
  }
233
233
 
234
- async compileOneFileWithNewCompiler(file, origin) {
234
+ async compileOneFileWithNewCompiler(file, initiator) {
235
235
  const options = {
236
236
  componentDir: this.componentDir,
237
237
  filePath: file.relative,
238
- origin
238
+ initiator
239
239
  };
240
240
  const isFileSupported = this.compilerInstance.isFileSupported(file.path);
241
241
  let compileResults;
@@ -272,7 +272,7 @@ ${this.compileErrors.map(formatError).join('\n')}`);
272
272
  }
273
273
  }
274
274
 
275
- async compileAllFilesWithNewCompiler(component, origin) {
275
+ async compileAllFilesWithNewCompiler(component, initiator) {
276
276
  const base = this.distDir;
277
277
  const filesToCompile = [];
278
278
  component.files.forEach(file => {
@@ -298,7 +298,7 @@ ${this.compileErrors.map(formatError).join('\n')}`);
298
298
  component,
299
299
  componentDir: this.componentDir,
300
300
  outputDir: this.workspace.getComponentPackagePath(component),
301
- origin
301
+ initiator
302
302
  }));
303
303
  } catch (error) {
304
304
  this.compileErrors.push({
@@ -341,14 +341,14 @@ class WorkspaceCompiler {
341
341
  changed: true,
342
342
  verbose: false,
343
343
  deleteDistDir: false,
344
- origin: _types().CompilationInitiator.PreStart
344
+ initiator: _types().CompilationInitiator.PreStart
345
345
  });
346
346
  }
347
347
 
348
348
  async onAspectLoadFail(err, id) {
349
349
  if (err.code && err.code === 'MODULE_NOT_FOUND' && this.workspace) {
350
350
  await this.compileComponents([id.toString()], {
351
- origin: _types().CompilationInitiator.AspectLoadFail
351
+ initiator: _types().CompilationInitiator.AspectLoadFail
352
352
  }, true);
353
353
  return true;
354
354
  }
@@ -356,9 +356,9 @@ class WorkspaceCompiler {
356
356
  return false;
357
357
  }
358
358
 
359
- async onComponentChange(component) {
359
+ async onComponentChange(component, initiator) {
360
360
  const buildResults = await this.compileComponents([component.id.toString()], {
361
- origin: _types().CompilationInitiator.ComponentChanged
361
+ initiator: initiator || _types().CompilationInitiator.ComponentChanged
362
362
  }, true);
363
363
  return {
364
364
  results: buildResults,
@@ -1 +1 @@
1
- {"version":3,"sources":["workspace-compiler.ts"],"names":["ComponentCompiler","constructor","pubsub","workspace","component","compilerInstance","compilerId","dists","compileErrors","compile","noThrow","options","dataToPersist","deleteDistDir","DataToPersist","removePath","RemovePath","distDir","addBasePath","path","persistAllToFS","transpileFile","Promise","all","files","map","file","compileOneFileWithNewCompiler","origin","transpileComponent","compileAllFilesWithNewCompiler","Error","toString","throwOnCompileErrors","addManyFiles","buildResults","distFile","compiler","loader","succeed","pub","CompilerAspect","id","ComponentCompilationOnDoneEvent","length","forEach","errorItem","logger","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","registerPreStart","onPreStart","registerOnAspectLoadErrorSlot","onAspectLoadFail","preStartOpts","skipCompilation","compileComponents","changed","verbose","CompilationInitiator","PreStart","code","AspectLoadFail","ComponentChanged","results","componentsIds","ConsumerNotFound","isLegacy","componentIds","getIdsToCompile","components","getMany","componentsAndNewCompilers","c","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;;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;;AAEA;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;;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,gBA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;AACF,KAXD;AAYA,UAAME,6BAA6B,GAAG,MAAM,2BAAUZ,yBAAV,EAAsCa,wBAAD,IAC/EA,wBAAwB,CAAChH,OAAzB,CAAiCC,OAAjC,EAA0CC,OAA1C,CAD0C,CAA5C;AAIA,WAAO6G,6BAAP;AACD;;AAE4B,QAAff,eAAe,CAACJ,aAAD,EAAuCR,OAAO,GAAG,KAAjD,EAAgF;AAC3G,QAAIQ,aAAa,CAACzD,MAAlB,EAA0B;AACxB,aAAO,KAAKzC,SAAL,CAAeuH,2BAAf,CAA2CrB,aAA3C,CAAP;AACD;;AACD,QAAIR,OAAJ,EAAa;AACX,aAAO,KAAK1F,SAAL,CAAewH,oBAAf,EAAP;AACD;;AACD,WAAO,KAAKxH,SAAL,CAAeyH,kBAAf,EAAP;AACD;;AA1F4B","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 } from '@teambit/workspace';\nimport path from 'path';\nimport { BitId } from '@teambit/legacy-bit-id';\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 logger from '@teambit/legacy/dist/logger/logger';\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 origin: 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 dists: Dist[] = [],\n private compileErrors: CompileError[] = []\n ) {}\n\n async compile(noThrow = true, options: CompileOptions): Promise<BuildResult> {\n let dataToPersist;\n // delete dist folder before transpilation (because some compilers (like ngPackagr) can generate files there during the compilation process)\n if (options.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.origin))\n );\n } else if (this.compilerInstance.transpileComponent) {\n await this.compileAllFilesWithNewCompiler(this.component, options.origin);\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 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 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, origin: CompilationInitiator): Promise<void> {\n const options = { componentDir: this.componentDir, filePath: file.relative, origin };\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 origin: 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 origin,\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 ) {\n if (this.workspace) {\n this.workspace.registerOnComponentChange(this.onComponentChange.bind(this));\n this.workspace.registerOnComponentAdd(this.onComponentChange.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 origin: 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()], { origin: CompilationInitiator.AspectLoadFail }, true);\n return true;\n }\n return false;\n }\n\n async onComponentChange(component: Component): Promise<SerializableResults> {\n const buildResults = await this.compileComponents(\n [component.id.toString()],\n { origin: 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 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(this.pubsub, this.workspace, c.state._consumer, compilerInstance, compilerName)\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","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","logger","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","registerPreStart","onPreStart","registerOnAspectLoadErrorSlot","onAspectLoadFail","preStartOpts","skipCompilation","compileComponents","changed","verbose","CompilationInitiator","PreStart","code","AspectLoadFail","ComponentChanged","results","componentsIds","ConsumerNotFound","isLegacy","componentIds","getIdsToCompile","components","getMany","componentsAndNewCompilers","c","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;;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;;AAEA;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;;AAIA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAvBA;AAyCO,MA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E,MAA3B,EAAmC,KAAKC,SAAxC,EAAmD0G,CAAC,CAACK,KAAF,CAAQC,SAA3D,EAAsE9G,gBAAtE,EAAwFiH,YAAxF,CADF;AAGD;AACF,KAXD;AAYA,UAAME,6BAA6B,GAAG,MAAM,2BAAUZ,yBAAV,EAAsCa,wBAAD,IAC/EA,wBAAwB,CAAChH,OAAzB,CAAiCC,OAAjC,EAA0CC,OAA1C,CAD0C,CAA5C;AAIA,WAAO6G,6BAAP;AACD;;AAE4B,QAAff,eAAe,CAACJ,aAAD,EAAuCR,OAAO,GAAG,KAAjD,EAAgF;AAC3G,QAAIQ,aAAa,CAACzD,MAAlB,EAA0B;AACxB,aAAO,KAAKzC,SAAL,CAAeuH,2BAAf,CAA2CrB,aAA3C,CAAP;AACD;;AACD,QAAIR,OAAJ,EAAa;AACX,aAAO,KAAK1F,SAAL,CAAewH,oBAAf,EAAP;AACD;;AACD,WAAO,KAAKxH,SAAL,CAAeyH,kBAAf,EAAP;AACD;;AA1F4B","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 } from '@teambit/workspace';\nimport path from 'path';\nimport { BitId } from '@teambit/legacy-bit-id';\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 logger from '@teambit/legacy/dist/logger/logger';\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 dists: Dist[] = [],\n private compileErrors: CompileError[] = []\n ) {}\n\n async compile(noThrow = true, options: CompileOptions): Promise<BuildResult> {\n let dataToPersist;\n // delete dist folder before transpilation (because some compilers (like ngPackagr) can generate files there during the compilation process)\n if (options.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 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 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 ) {\n if (this.workspace) {\n this.workspace.registerOnComponentChange(this.onComponentChange.bind(this));\n this.workspace.registerOnComponentAdd(this.onComponentChange.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(component: Component, initiator?: CompilationInitiator): 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 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(this.pubsub, this.workspace, c.state._consumer, compilerInstance, compilerName)\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"]}
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/compiler",
3
- "version": "0.0.521",
3
+ "version": "0.0.525",
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.521"
9
+ "version": "0.0.525"
10
10
  },
11
11
  "dependencies": {
12
12
  "@teambit/harmony": "0.2.11",
@@ -18,18 +18,18 @@
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.379",
22
- "@teambit/logger": "0.0.449",
23
- "@teambit/pubsub": "0.0.521",
24
- "@teambit/aspect-loader": "0.0.521",
25
- "@teambit/builder": "0.0.521",
26
- "@teambit/component": "0.0.521",
27
- "@teambit/envs": "0.0.521",
28
- "@teambit/legacy-bit-id": "0.0.368",
29
- "@teambit/ui": "0.0.521",
30
- "@teambit/workspace": "0.0.521",
31
- "@teambit/isolator": "0.0.521",
32
- "@teambit/bit-error": "0.0.365"
21
+ "@teambit/cli": "0.0.380",
22
+ "@teambit/logger": "0.0.451",
23
+ "@teambit/pubsub": "0.0.525",
24
+ "@teambit/aspect-loader": "0.0.525",
25
+ "@teambit/builder": "0.0.525",
26
+ "@teambit/component": "0.0.525",
27
+ "@teambit/envs": "0.0.525",
28
+ "@teambit/legacy-bit-id": "0.0.369",
29
+ "@teambit/ui": "0.0.525",
30
+ "@teambit/workspace": "0.0.525",
31
+ "@teambit/isolator": "0.0.525",
32
+ "@teambit/bit-error": "0.0.366"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@types/react": "^17.0.8",
@@ -39,14 +39,14 @@
39
39
  "@types/jest": "^26.0.0",
40
40
  "@types/react-dom": "^17.0.5",
41
41
  "@types/node": "12.20.4",
42
- "@teambit/compilation.aspect-docs.compiler": "0.0.85"
42
+ "@teambit/compilation.aspect-docs.compiler": "0.0.87"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "@teambit/legacy": "1.0.76",
46
46
  "react-dom": "^16.8.0 || ^17.0.0",
47
47
  "react": "^16.8.0 || ^17.0.0"
48
48
  },
49
- "license": "SEE LICENSE IN LICENSE",
49
+ "license": "Apache-2.0",
50
50
  "bit": {
51
51
  "bindingPrefix": "@teambit",
52
52
  "env": {},
package/types.ts CHANGED
@@ -11,6 +11,7 @@ export enum CompilationInitiator {
11
11
  CmdReport,
12
12
  CmdJson,
13
13
  PreStart,
14
+ Start,
14
15
  ComponentChanged,
15
16
  AspectLoadFail,
16
17
  ComponentAdded,
@@ -20,7 +21,7 @@ export type TranspileComponentParams = {
20
21
  component: ConsumerComponent;
21
22
  componentDir: string; // absolute path of the component's root directory
22
23
  outputDir: string; // absolute path of the component's output directory
23
- origin: CompilationInitiator; // origin of the compilation's request
24
+ initiator: CompilationInitiator; // origin of the compilation's request
24
25
  };
25
26
 
26
27
  export type TranspileFileOutput =
@@ -34,7 +34,7 @@ export type CompileOptions = {
34
34
  * start` to avoid webpack "EINTR" error.
35
35
  */
36
36
  deleteDistDir?: boolean;
37
- origin: CompilationInitiator; // describes where the compilation is coming from
37
+ initiator: CompilationInitiator; // describes where the compilation is coming from
38
38
  };
39
39
 
40
40
  export type CompileError = { path: string; error: Error };
@@ -62,10 +62,10 @@ export class ComponentCompiler {
62
62
 
63
63
  if (this.compilerInstance.transpileFile) {
64
64
  await Promise.all(
65
- this.component.files.map((file: SourceFile) => this.compileOneFileWithNewCompiler(file, options.origin))
65
+ this.component.files.map((file: SourceFile) => this.compileOneFileWithNewCompiler(file, options.initiator))
66
66
  );
67
67
  } else if (this.compilerInstance.transpileComponent) {
68
- await this.compileAllFilesWithNewCompiler(this.component, options.origin);
68
+ await this.compileAllFilesWithNewCompiler(this.component, options.initiator);
69
69
  } else {
70
70
  throw new Error(
71
71
  `compiler ${this.compilerId.toString()} doesn't implement either "transpileFile" or "transpileComponent" methods`
@@ -118,8 +118,8 @@ ${this.compileErrors.map(formatError).join('\n')}`);
118
118
  return this.workspace.componentDir(new ComponentID(this.component.id));
119
119
  }
120
120
 
121
- private async compileOneFileWithNewCompiler(file: SourceFile, origin: CompilationInitiator): Promise<void> {
122
- const options = { componentDir: this.componentDir, filePath: file.relative, origin };
121
+ private async compileOneFileWithNewCompiler(file: SourceFile, initiator: CompilationInitiator): Promise<void> {
122
+ const options = { componentDir: this.componentDir, filePath: file.relative, initiator };
123
123
  const isFileSupported = this.compilerInstance.isFileSupported(file.path);
124
124
  let compileResults;
125
125
  if (isFileSupported) {
@@ -150,7 +150,7 @@ ${this.compileErrors.map(formatError).join('\n')}`);
150
150
 
151
151
  private async compileAllFilesWithNewCompiler(
152
152
  component: ConsumerComponent,
153
- origin: CompilationInitiator
153
+ initiator: CompilationInitiator
154
154
  ): Promise<void> {
155
155
  const base = this.distDir;
156
156
  const filesToCompile: SourceFile[] = [];
@@ -176,7 +176,7 @@ ${this.compileErrors.map(formatError).join('\n')}`);
176
176
  component,
177
177
  componentDir: this.componentDir,
178
178
  outputDir: this.workspace.getComponentPackagePath(component),
179
- origin,
179
+ initiator,
180
180
  });
181
181
  } catch (error: any) {
182
182
  this.compileErrors.push({ path: this.componentDir, error });
@@ -211,22 +211,22 @@ export class WorkspaceCompiler {
211
211
  changed: true,
212
212
  verbose: false,
213
213
  deleteDistDir: false,
214
- origin: CompilationInitiator.PreStart,
214
+ initiator: CompilationInitiator.PreStart,
215
215
  });
216
216
  }
217
217
 
218
218
  async onAspectLoadFail(err: Error & { code?: string }, id: ComponentID): Promise<boolean> {
219
219
  if (err.code && err.code === 'MODULE_NOT_FOUND' && this.workspace) {
220
- await this.compileComponents([id.toString()], { origin: CompilationInitiator.AspectLoadFail }, true);
220
+ await this.compileComponents([id.toString()], { initiator: CompilationInitiator.AspectLoadFail }, true);
221
221
  return true;
222
222
  }
223
223
  return false;
224
224
  }
225
225
 
226
- async onComponentChange(component: Component): Promise<SerializableResults> {
226
+ async onComponentChange(component: Component, initiator?: CompilationInitiator): Promise<SerializableResults> {
227
227
  const buildResults = await this.compileComponents(
228
228
  [component.id.toString()],
229
- { origin: CompilationInitiator.ComponentChanged },
229
+ { initiator: initiator || CompilationInitiator.ComponentChanged },
230
230
  true
231
231
  );
232
232
  return {