@teambit/compiler 0.0.529 → 0.0.533

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.
@@ -84,10 +84,10 @@ export class CompilerMain {
84
84
  BuilderMain,
85
85
  UiMain
86
86
  ]) {
87
- const workspaceCompiler = new WorkspaceCompiler(workspace, envs, pubsub, aspectLoader, ui);
87
+ const logger = loggerMain.createLogger(CompilerAspect.id);
88
+ const workspaceCompiler = new WorkspaceCompiler(workspace, envs, pubsub, aspectLoader, ui, logger);
88
89
  envs.registerService(new CompilerService());
89
90
  const compilerMain = new CompilerMain(pubsub, workspaceCompiler, envs, builder);
90
- const logger = loggerMain.createLogger(CompilerAspect.id);
91
91
  cli.register(new CompileCmd(workspaceCompiler, logger, pubsub));
92
92
 
93
93
  ManyComponentsWriter.externalCompiler = compilerMain.compileOnWorkspace.bind(compilerMain);
@@ -239,10 +239,10 @@ class CompilerMain {
239
239
  }
240
240
 
241
241
  static async provider([cli, workspace, envs, loggerMain, pubsub, aspectLoader, builder, ui]) {
242
- const workspaceCompiler = new (_workspaceCompiler().WorkspaceCompiler)(workspace, envs, pubsub, aspectLoader, ui);
242
+ const logger = loggerMain.createLogger(_compiler().CompilerAspect.id);
243
+ const workspaceCompiler = new (_workspaceCompiler().WorkspaceCompiler)(workspace, envs, pubsub, aspectLoader, ui, logger);
243
244
  envs.registerService(new (_compiler3().CompilerService)());
244
245
  const compilerMain = new CompilerMain(pubsub, workspaceCompiler, envs, builder);
245
- const logger = loggerMain.createLogger(_compiler().CompilerAspect.id);
246
246
  cli.register(new (_compiler2().CompileCmd)(workspaceCompiler, logger, pubsub));
247
247
  _manyComponentsWriter().default.externalCompiler = compilerMain.compileOnWorkspace.bind(compilerMain);
248
248
  return compilerMain;
@@ -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","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,EAGD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K,QAAQ,CAAC,CAACC,GAAD,EAAMC,SAAN,EAAiB/B,IAAjB,EAAuBgC,UAAvB,EAAmClC,MAAnC,EAA2CmC,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"]}
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","logger","createLogger","WorkspaceCompiler","registerService","CompilerService","compilerMain","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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AAf,EAAkCoC,MAAlC,EAA0CrC,MAA1C,CAAb;AAEA6C,oCAAqBC,gBAArB,GAAwCJ,YAAY,CAACtC,kBAAb,CAAgC2C,IAAhC,CAAqCL,YAArC,CAAxC;AAEA,WAAOA,YAAP;AACD;;AA1EuB;;;gCAAb5C,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 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\n ManyComponentsWriter.externalCompiler = compilerMain.compileOnWorkspace.bind(compilerMain);\n\n return compilerMain;\n }\n}\n\nCompilerAspect.addRuntime(CompilerMain);\n"]}
package/dist/index.js CHANGED
@@ -12,10 +12,10 @@ var _exportNames = {
12
12
  TranspileFileParams: true,
13
13
  TranspileComponentParams: true
14
14
  };
15
- Object.defineProperty(exports, "CompilerAspect", {
15
+ Object.defineProperty(exports, "CompilationInitiator", {
16
16
  enumerable: true,
17
17
  get: function () {
18
- return _compiler().CompilerAspect;
18
+ return _types().CompilationInitiator;
19
19
  }
20
20
  });
21
21
  Object.defineProperty(exports, "Compiler", {
@@ -24,16 +24,22 @@ Object.defineProperty(exports, "Compiler", {
24
24
  return _types().Compiler;
25
25
  }
26
26
  });
27
+ Object.defineProperty(exports, "CompilerAspect", {
28
+ enumerable: true,
29
+ get: function () {
30
+ return _compiler().CompilerAspect;
31
+ }
32
+ });
27
33
  Object.defineProperty(exports, "CompilerOptions", {
28
34
  enumerable: true,
29
35
  get: function () {
30
36
  return _types().CompilerOptions;
31
37
  }
32
38
  });
33
- Object.defineProperty(exports, "CompilationInitiator", {
39
+ Object.defineProperty(exports, "TranspileComponentParams", {
34
40
  enumerable: true,
35
41
  get: function () {
36
- return _types().CompilationInitiator;
42
+ return _types().TranspileComponentParams;
37
43
  }
38
44
  });
39
45
  Object.defineProperty(exports, "TranspileFileOutput", {
@@ -48,12 +54,6 @@ Object.defineProperty(exports, "TranspileFileParams", {
48
54
  return _types().TranspileFileParams;
49
55
  }
50
56
  });
51
- Object.defineProperty(exports, "TranspileComponentParams", {
52
- enumerable: true,
53
- get: function () {
54
- return _types().TranspileComponentParams;
55
- }
56
- });
57
57
 
58
58
  function _compiler() {
59
59
  const data = require("./compiler.aspect");
package/dist/types.d.ts CHANGED
@@ -9,10 +9,11 @@ export declare enum CompilationInitiator {
9
9
  CmdReport = 0,
10
10
  CmdJson = 1,
11
11
  PreStart = 2,
12
- Start = 3,
13
- ComponentChanged = 4,
14
- AspectLoadFail = 5,
15
- ComponentAdded = 6
12
+ PreWatch = 3,
13
+ Start = 4,
14
+ ComponentChanged = 5,
15
+ AspectLoadFail = 6,
16
+ ComponentAdded = 7
16
17
  }
17
18
  export declare type TranspileComponentParams = {
18
19
  component: ConsumerComponent;
package/dist/types.js CHANGED
@@ -11,10 +11,11 @@ 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["Start"] = 3] = "Start";
15
- CompilationInitiator[CompilationInitiator["ComponentChanged"] = 4] = "ComponentChanged";
16
- CompilationInitiator[CompilationInitiator["AspectLoadFail"] = 5] = "AspectLoadFail";
17
- CompilationInitiator[CompilationInitiator["ComponentAdded"] = 6] = "ComponentAdded";
14
+ CompilationInitiator[CompilationInitiator["PreWatch"] = 3] = "PreWatch";
15
+ CompilationInitiator[CompilationInitiator["Start"] = 4] = "Start";
16
+ CompilationInitiator[CompilationInitiator["ComponentChanged"] = 5] = "ComponentChanged";
17
+ CompilationInitiator[CompilationInitiator["AspectLoadFail"] = 6] = "AspectLoadFail";
18
+ CompilationInitiator[CompilationInitiator["ComponentAdded"] = 7] = "ComponentAdded";
18
19
  })(CompilationInitiator || (exports.CompilationInitiator = CompilationInitiator = {}));
19
20
 
20
21
  //# 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;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"]}
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;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 PreWatch,\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"]}
@@ -1,8 +1,9 @@
1
1
  import { Component, ComponentID } from '@teambit/component';
2
2
  import { EnvsMain } from '@teambit/envs';
3
3
  import type { PubsubMain } from '@teambit/pubsub';
4
- import { SerializableResults, Workspace } from '@teambit/workspace';
4
+ import { SerializableResults, Workspace, WatchOptions } from '@teambit/workspace';
5
5
  import { BitId } from '@teambit/legacy-bit-id';
6
+ import { Logger } from '@teambit/logger';
6
7
  import ConsumerComponent from '@teambit/legacy/dist/consumer/component';
7
8
  import { Dist } from '@teambit/legacy/dist/consumer/component/sources';
8
9
  import { AspectLoaderMain } from '@teambit/aspect-loader';
@@ -29,9 +30,10 @@ export declare class ComponentCompiler {
29
30
  private component;
30
31
  private compilerInstance;
31
32
  private compilerId;
33
+ private logger;
32
34
  private dists;
33
35
  private compileErrors;
34
- constructor(pubsub: PubsubMain, workspace: Workspace, component: ConsumerComponent, compilerInstance: Compiler, compilerId: string, dists?: Dist[], compileErrors?: CompileError[]);
36
+ constructor(pubsub: PubsubMain, workspace: Workspace, component: ConsumerComponent, compilerInstance: Compiler, compilerId: string, logger: Logger, dists?: Dist[], compileErrors?: CompileError[]);
35
37
  compile(noThrow: boolean | undefined, options: CompileOptions): Promise<BuildResult>;
36
38
  private throwOnCompileErrors;
37
39
  private get distDir();
@@ -45,12 +47,14 @@ export declare class WorkspaceCompiler {
45
47
  private pubsub;
46
48
  private aspectLoader;
47
49
  private ui;
48
- constructor(workspace: Workspace, envs: EnvsMain, pubsub: PubsubMain, aspectLoader: AspectLoaderMain, ui: UiMain);
50
+ private logger;
51
+ constructor(workspace: Workspace, envs: EnvsMain, pubsub: PubsubMain, aspectLoader: AspectLoaderMain, ui: UiMain, logger: Logger);
49
52
  onPreStart(preStartOpts: PreStartOpts): Promise<void>;
50
53
  onAspectLoadFail(err: Error & {
51
54
  code?: string;
52
55
  }, id: ComponentID): Promise<boolean>;
53
- onComponentChange(component: Component, initiator?: CompilationInitiator): Promise<SerializableResults>;
56
+ onComponentChange(component: Component, files: string[], initiator?: CompilationInitiator): Promise<SerializableResults>;
57
+ onPreWatch(components: Component[], watchOpts: WatchOptions): Promise<void>;
54
58
  compileComponents(componentsIds: string[] | BitId[], options: CompileOptions, noThrow?: boolean): Promise<BuildResult[]>;
55
59
  private getIdsToCompile;
56
60
  }
@@ -91,16 +91,6 @@ function _exceptions() {
91
91
  return data;
92
92
  }
93
93
 
94
- function _logger() {
95
- const data = _interopRequireDefault(require("@teambit/legacy/dist/logger/logger"));
96
-
97
- _logger = function () {
98
- return data;
99
- };
100
-
101
- return data;
102
- }
103
-
104
94
  function _componentIdToPackageName() {
105
95
  const data = _interopRequireDefault(require("@teambit/legacy/dist/utils/bit/component-id-to-package-name"));
106
96
 
@@ -153,12 +143,13 @@ function _types() {
153
143
 
154
144
  /* eslint-disable max-classes-per-file */
155
145
  class ComponentCompiler {
156
- constructor(pubsub, workspace, component, compilerInstance, compilerId, dists = [], compileErrors = []) {
146
+ constructor(pubsub, workspace, component, compilerInstance, compilerId, logger, dists = [], compileErrors = []) {
157
147
  this.pubsub = pubsub;
158
148
  this.workspace = workspace;
159
149
  this.component = component;
160
150
  this.compilerInstance = compilerInstance;
161
151
  this.compilerId = compilerId;
152
+ this.logger = logger;
162
153
  this.dists = dists;
163
154
  this.compileErrors = compileErrors;
164
155
  }
@@ -200,7 +191,7 @@ class ComponentCompiler {
200
191
  throwOnCompileErrors(noThrow = true) {
201
192
  if (this.compileErrors.length) {
202
193
  this.compileErrors.forEach(errorItem => {
203
- _logger().default.error(`compilation error at ${errorItem.path}`, errorItem.error);
194
+ this.logger.error(`compilation error at ${errorItem.path}`, errorItem.error);
204
195
  });
205
196
 
206
197
  const formatError = errorItem => `${errorItem.path}\n${errorItem.error}`;
@@ -213,7 +204,7 @@ ${this.compileErrors.map(formatError).join('\n')}`);
213
204
  throw err;
214
205
  }
215
206
 
216
- _logger().default.console(err.message);
207
+ this.logger.console(err.message);
217
208
  }
218
209
  }
219
210
 
@@ -314,16 +305,18 @@ ${this.compileErrors.map(formatError).join('\n')}`);
314
305
  exports.ComponentCompiler = ComponentCompiler;
315
306
 
316
307
  class WorkspaceCompiler {
317
- constructor(workspace, envs, pubsub, aspectLoader, ui) {
308
+ constructor(workspace, envs, pubsub, aspectLoader, ui, logger) {
318
309
  this.workspace = workspace;
319
310
  this.envs = envs;
320
311
  this.pubsub = pubsub;
321
312
  this.aspectLoader = aspectLoader;
322
313
  this.ui = ui;
314
+ this.logger = logger;
323
315
 
324
316
  if (this.workspace) {
325
317
  this.workspace.registerOnComponentChange(this.onComponentChange.bind(this));
326
318
  this.workspace.registerOnComponentAdd(this.onComponentChange.bind(this));
319
+ this.workspace.registerOnPreWatch(this.onPreWatch.bind(this));
327
320
  this.ui.registerPreStart(this.onPreStart.bind(this));
328
321
  }
329
322
 
@@ -356,7 +349,7 @@ class WorkspaceCompiler {
356
349
  return false;
357
350
  }
358
351
 
359
- async onComponentChange(component, initiator) {
352
+ async onComponentChange(component, files, initiator) {
360
353
  const buildResults = await this.compileComponents([component.id.toString()], {
361
354
  initiator: initiator || _types().CompilationInitiator.ComponentChanged
362
355
  }, true);
@@ -372,6 +365,18 @@ class WorkspaceCompiler {
372
365
  };
373
366
  }
374
367
 
368
+ async onPreWatch(components, watchOpts) {
369
+ if (watchOpts.preCompile) {
370
+ const start = Date.now();
371
+ this.logger.console(`compiling ${components.length} components`);
372
+ await this.compileComponents(components.map(c => c.id._legacy), {
373
+ initiator: _types().CompilationInitiator.PreWatch
374
+ });
375
+ const end = Date.now() - start;
376
+ this.logger.consoleSuccess(`compiled ${components.length} components successfully (${end / 1000} sec)`);
377
+ }
378
+ }
379
+
375
380
  async compileComponents(componentsIds, // when empty, it compiles new+modified (unless options.all is set),
376
381
  options, noThrow) {
377
382
  if (!this.workspace) throw new (_exceptions().ConsumerNotFound)();
@@ -388,7 +393,7 @@ class WorkspaceCompiler {
388
393
 
389
394
  if (compilerInstance && (_c$state$_consumer$co = c.state._consumer.componentMap) !== null && _c$state$_consumer$co !== void 0 && _c$state$_consumer$co.getComponentDir()) {
390
395
  const compilerName = compilerInstance.constructor.name || 'compiler';
391
- componentsAndNewCompilers.push(new ComponentCompiler(this.pubsub, this.workspace, c.state._consumer, compilerInstance, compilerName));
396
+ componentsAndNewCompilers.push(new ComponentCompiler(this.pubsub, this.workspace, c.state._consumer, compilerInstance, compilerName, this.logger));
392
397
  }
393
398
  });
394
399
  const newCompilersResultOnWorkspace = await (0, _pMapSeries().default)(componentsAndNewCompilers, componentAndNewCompilers => componentAndNewCompilers.compile(noThrow, options));
@@ -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","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,MAAMA,iBAAN,CAAwB;AAC7BC,EAAAA,WAAW,CACDC,MADC,EAEDC,SAFC,EAGDC,SAHC,EAIDC,gBAJC,EAKDC,UALC,EAMDC,KAAa,GAAG,E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AXD;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"]}
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;;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AgF;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 // 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 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"]}
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/compiler",
3
- "version": "0.0.529",
3
+ "version": "0.0.533",
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.529"
9
+ "version": "0.0.533"
10
10
  },
11
11
  "dependencies": {
12
12
  "@teambit/harmony": "0.2.11",
@@ -19,16 +19,16 @@
19
19
  "@babel/runtime": "7.12.18",
20
20
  "core-js": "^3.0.0",
21
21
  "@teambit/cli": "0.0.380",
22
- "@teambit/logger": "0.0.453",
23
- "@teambit/pubsub": "0.0.529",
24
- "@teambit/aspect-loader": "0.0.529",
25
- "@teambit/builder": "0.0.529",
26
- "@teambit/component": "0.0.529",
27
- "@teambit/envs": "0.0.529",
22
+ "@teambit/logger": "0.0.456",
23
+ "@teambit/pubsub": "0.0.533",
24
+ "@teambit/aspect-loader": "0.0.533",
25
+ "@teambit/builder": "0.0.533",
26
+ "@teambit/component": "0.0.533",
27
+ "@teambit/envs": "0.0.533",
28
28
  "@teambit/legacy-bit-id": "0.0.369",
29
- "@teambit/ui": "0.0.529",
30
- "@teambit/workspace": "0.0.529",
31
- "@teambit/isolator": "0.0.529",
29
+ "@teambit/ui": "0.0.533",
30
+ "@teambit/workspace": "0.0.533",
31
+ "@teambit/isolator": "0.0.533",
32
32
  "@teambit/bit-error": "0.0.366"
33
33
  },
34
34
  "devDependencies": {
@@ -39,7 +39,7 @@
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.89"
42
+ "@teambit/compilation.aspect-docs.compiler": "0.0.92"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "@teambit/legacy": "1.0.76",
package/types.ts CHANGED
@@ -11,6 +11,7 @@ export enum CompilationInitiator {
11
11
  CmdReport,
12
12
  CmdJson,
13
13
  PreStart,
14
+ PreWatch,
14
15
  Start,
15
16
  ComponentChanged,
16
17
  AspectLoadFail,
@@ -3,9 +3,10 @@ import mapSeries from 'p-map-series';
3
3
  import { Component, ComponentID } from '@teambit/component';
4
4
  import { EnvsMain } from '@teambit/envs';
5
5
  import type { PubsubMain } from '@teambit/pubsub';
6
- import { SerializableResults, Workspace } from '@teambit/workspace';
6
+ import { SerializableResults, Workspace, WatchOptions } from '@teambit/workspace';
7
7
  import path from 'path';
8
8
  import { BitId } from '@teambit/legacy-bit-id';
9
+ import { Logger } from '@teambit/logger';
9
10
  import loader from '@teambit/legacy/dist/cli/loader';
10
11
  import { DEFAULT_DIST_DIRNAME } from '@teambit/legacy/dist/constants';
11
12
  import ConsumerComponent from '@teambit/legacy/dist/consumer/component';
@@ -13,7 +14,6 @@ import { Dist, SourceFile } from '@teambit/legacy/dist/consumer/component/source
13
14
  import DataToPersist from '@teambit/legacy/dist/consumer/component/sources/data-to-persist';
14
15
  import { AspectLoaderMain } from '@teambit/aspect-loader';
15
16
  import { ConsumerNotFound } from '@teambit/legacy/dist/consumer/exceptions';
16
- import logger from '@teambit/legacy/dist/logger/logger';
17
17
  import componentIdToPackageName from '@teambit/legacy/dist/utils/bit/component-id-to-package-name';
18
18
  import RemovePath from '@teambit/legacy/dist/consumer/component/sources/remove-path';
19
19
  import { UiMain } from '@teambit/ui';
@@ -46,6 +46,7 @@ export class ComponentCompiler {
46
46
  private component: ConsumerComponent,
47
47
  private compilerInstance: Compiler,
48
48
  private compilerId: string,
49
+ private logger: Logger,
49
50
  private dists: Dist[] = [],
50
51
  private compileErrors: CompileError[] = []
51
52
  ) {}
@@ -91,7 +92,7 @@ export class ComponentCompiler {
91
92
  private throwOnCompileErrors(noThrow = true) {
92
93
  if (this.compileErrors.length) {
93
94
  this.compileErrors.forEach((errorItem) => {
94
- logger.error(`compilation error at ${errorItem.path}`, errorItem.error);
95
+ this.logger.error(`compilation error at ${errorItem.path}`, errorItem.error);
95
96
  });
96
97
  const formatError = (errorItem) => `${errorItem.path}\n${errorItem.error}`;
97
98
  const err = new Error(`compilation failed. see the following errors from the compiler
@@ -103,7 +104,7 @@ ${this.compileErrors.map(formatError).join('\n')}`);
103
104
  throw err;
104
105
  }
105
106
 
106
- logger.console(err.message);
107
+ this.logger.console(err.message);
107
108
  }
108
109
  }
109
110
 
@@ -191,11 +192,13 @@ export class WorkspaceCompiler {
191
192
  private envs: EnvsMain,
192
193
  private pubsub: PubsubMain,
193
194
  private aspectLoader: AspectLoaderMain,
194
- private ui: UiMain
195
+ private ui: UiMain,
196
+ private logger: Logger
195
197
  ) {
196
198
  if (this.workspace) {
197
199
  this.workspace.registerOnComponentChange(this.onComponentChange.bind(this));
198
200
  this.workspace.registerOnComponentAdd(this.onComponentChange.bind(this));
201
+ this.workspace.registerOnPreWatch(this.onPreWatch.bind(this));
199
202
  this.ui.registerPreStart(this.onPreStart.bind(this));
200
203
  }
201
204
  if (this.aspectLoader) {
@@ -223,7 +226,11 @@ export class WorkspaceCompiler {
223
226
  return false;
224
227
  }
225
228
 
226
- async onComponentChange(component: Component, initiator?: CompilationInitiator): Promise<SerializableResults> {
229
+ async onComponentChange(
230
+ component: Component,
231
+ files: string[],
232
+ initiator?: CompilationInitiator
233
+ ): Promise<SerializableResults> {
227
234
  const buildResults = await this.compileComponents(
228
235
  [component.id.toString()],
229
236
  { initiator: initiator || CompilationInitiator.ComponentChanged },
@@ -237,6 +244,19 @@ export class WorkspaceCompiler {
237
244
  };
238
245
  }
239
246
 
247
+ async onPreWatch(components: Component[], watchOpts: WatchOptions) {
248
+ if (watchOpts.preCompile) {
249
+ const start = Date.now();
250
+ this.logger.console(`compiling ${components.length} components`);
251
+ await this.compileComponents(
252
+ components.map((c) => c.id._legacy),
253
+ { initiator: CompilationInitiator.PreWatch }
254
+ );
255
+ const end = Date.now() - start;
256
+ this.logger.consoleSuccess(`compiled ${components.length} components successfully (${end / 1000} sec)`);
257
+ }
258
+ }
259
+
240
260
  async compileComponents(
241
261
  componentsIds: string[] | BitId[], // when empty, it compiles new+modified (unless options.all is set),
242
262
  options: CompileOptions,
@@ -256,7 +276,14 @@ export class WorkspaceCompiler {
256
276
  if (compilerInstance && c.state._consumer.componentMap?.getComponentDir()) {
257
277
  const compilerName = compilerInstance.constructor.name || 'compiler';
258
278
  componentsAndNewCompilers.push(
259
- new ComponentCompiler(this.pubsub, this.workspace, c.state._consumer, compilerInstance, compilerName)
279
+ new ComponentCompiler(
280
+ this.pubsub,
281
+ this.workspace,
282
+ c.state._consumer,
283
+ compilerInstance,
284
+ compilerName,
285
+ this.logger
286
+ )
260
287
  );
261
288
  }
262
289
  });