@teambit/compiler 0.0.516 → 0.0.520

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
@@ -6,6 +6,7 @@ import prettyTime from 'pretty-time';
6
6
  import type ConsumerComponent from '@teambit/legacy/dist/consumer/component';
7
7
  import { formatCompileResults } from './output-formatter';
8
8
  import { CompileError, WorkspaceCompiler, CompileOptions } from './workspace-compiler';
9
+ import { CompilationInitiator } from './types';
9
10
 
10
11
  // IDs & events
11
12
  import { CompilerAspect } from './compiler.aspect';
@@ -37,8 +38,11 @@ export class CompileCmd implements Command {
37
38
  this.pubsub.sub(CompilerAspect.id, this.onComponentCompilationDone.bind(this));
38
39
 
39
40
  let outputString = '';
40
- compilerOptions.deleteDistDir = true;
41
- await this.compile.compileComponents(components, compilerOptions);
41
+ await this.compile.compileComponents(components, {
42
+ ...compilerOptions,
43
+ origin: CompilationInitiator.CmdReport,
44
+ deleteDistDir: true,
45
+ });
42
46
  const compileTimeLength = process.hrtime(startTimestamp);
43
47
 
44
48
  outputString += '\n';
@@ -59,7 +63,11 @@ export class CompileCmd implements Command {
59
63
  async json([components]: [string[]], compilerOptions: CompileOptions) {
60
64
  compilerOptions.deleteDistDir = true;
61
65
  // @ts-ignore
62
- const compileResults = await this.compile.compileComponents(components, compilerOptions);
66
+ const compileResults = await this.compile.compileComponents(components, {
67
+ ...compilerOptions,
68
+ origin: CompilationInitiator.CmdJson,
69
+ deleteDistDir: true,
70
+ });
63
71
  return {
64
72
  data: compileResults,
65
73
  // @todo: fix the code once compile is ready.
@@ -1,23 +1,23 @@
1
- import { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';
2
- import { EnvsAspect, EnvsMain } from '@teambit/envs';
3
- import { LoggerAspect, LoggerMain } from '@teambit/logger';
4
- import { Workspace, WorkspaceAspect } from '@teambit/workspace';
5
- import { PubsubAspect, PubsubMain } from '@teambit/pubsub';
6
1
  import AspectLoaderAspect, { AspectLoaderMain } from '@teambit/aspect-loader';
2
+ import { BuilderAspect, BuilderMain } from '@teambit/builder';
3
+ import { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';
7
4
  import { Component } from '@teambit/component';
5
+ import { EnvsAspect, EnvsMain } from '@teambit/envs';
8
6
  import { BitId } from '@teambit/legacy-bit-id';
9
- import { BuilderAspect, BuilderMain } from '@teambit/builder';
10
- import UIAspect, { UiMain } from '@teambit/ui';
11
7
 
12
8
  import ManyComponentsWriter from '@teambit/legacy/dist/consumer/component-ops/many-components-writer';
13
- import { CompilerService } from './compiler.service';
9
+ import { LoggerAspect, LoggerMain } from '@teambit/logger';
10
+ import { PubsubAspect, PubsubMain } from '@teambit/pubsub';
11
+ import UIAspect, { UiMain } from '@teambit/ui';
12
+ import { Workspace, WorkspaceAspect } from '@teambit/workspace';
14
13
  import { CompilerAspect } from './compiler.aspect';
15
14
  import { CompileCmd } from './compiler.cmd';
15
+ import { CompilerService } from './compiler.service';
16
16
  import { CompilerTask } from './compiler.task';
17
- import { Compiler } from './types';
18
- import { CompileOptions, WorkspaceCompiler } from './workspace-compiler';
19
17
  import { DistArtifact } from './dist-artifact';
20
18
  import { DistArtifactNotFound } from './exceptions';
19
+ import { CompilationInitiator, Compiler } from './types';
20
+ import { CompileOptions, WorkspaceCompiler } from './workspace-compiler';
21
21
 
22
22
  export class CompilerMain {
23
23
  constructor(
@@ -27,9 +27,12 @@ export class CompilerMain {
27
27
  private builder: BuilderMain
28
28
  ) {}
29
29
 
30
+ /**
31
+ * Run compilation on `bit new` and when new components are imported
32
+ */
30
33
  compileOnWorkspace(
31
34
  componentsIds: string[] | BitId[] = [], // when empty, it compiles all
32
- options: CompileOptions = {}
35
+ options: CompileOptions = { origin: CompilationInitiator.ComponentAdded }
33
36
  ) {
34
37
  return this.workspaceCompiler.compileComponents(componentsIds, options);
35
38
  }
@@ -51,6 +51,16 @@ function _outputFormatter() {
51
51
  return data;
52
52
  }
53
53
 
54
+ function _types() {
55
+ const data = require("./types");
56
+
57
+ _types = function () {
58
+ return data;
59
+ };
60
+
61
+ return data;
62
+ }
63
+
54
64
  function _compiler() {
55
65
  const data = require("./compiler.aspect");
56
66
 
@@ -71,7 +81,10 @@ function _events() {
71
81
  return data;
72
82
  }
73
83
 
74
- // IDs & events
84
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
85
+
86
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2().default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
87
+
75
88
  class CompileCmd {
76
89
  constructor(compile, logger, pubsub) {
77
90
  this.compile = compile;
@@ -90,8 +103,10 @@ class CompileCmd {
90
103
  this.logger.setStatusLine('Compiling your components, hold tight.');
91
104
  this.pubsub.sub(_compiler().CompilerAspect.id, this.onComponentCompilationDone.bind(this));
92
105
  let outputString = '';
93
- compilerOptions.deleteDistDir = true;
94
- await this.compile.compileComponents(components, compilerOptions);
106
+ await this.compile.compileComponents(components, _objectSpread(_objectSpread({}, compilerOptions), {}, {
107
+ origin: _types().CompilationInitiator.CmdReport,
108
+ deleteDistDir: true
109
+ }));
95
110
  const compileTimeLength = process.hrtime(startTimestamp);
96
111
  outputString += '\n';
97
112
  outputString += ` ${_chalk().default.underline('STATUS')}\t${_chalk().default.underline('COMPONENT ID')}\n`;
@@ -108,7 +123,10 @@ class CompileCmd {
108
123
  async json([components], compilerOptions) {
109
124
  compilerOptions.deleteDistDir = true; // @ts-ignore
110
125
 
111
- const compileResults = await this.compile.compileComponents(components, compilerOptions);
126
+ const compileResults = await this.compile.compileComponents(components, _objectSpread(_objectSpread({}, compilerOptions), {}, {
127
+ origin: _types().CompilationInitiator.CmdJson,
128
+ deleteDistDir: true
129
+ }));
112
130
  return {
113
131
  data: compileResults,
114
132
  // @todo: fix the code once compile is ready.
@@ -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","deleteDistDir","compileComponents","compileTimeLength","chalk","underline","componentsStatus","verbose","getStatusLine","clearStatusLine","data","code","getExitCode","json","compileResults","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;;AAIA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAFA;AAUO,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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AAW,GAAGH,yBAAyB,GACxC,GAAEE,IAAK,IAAGF,yBAA0B,IAAGD,kBAAmB,gCADlB,GAExC,GAAEG,IAAK,IAAGD,4BAA6B,IAAGF,kBAAmB,oCAFlE;AAIA,WAAQ,GAAEI,WAAY,gBAAe,2BAAWzB,iBAAX,CAA8B,GAAnE;AACD;;AAEOL,EAAAA,0BAA0B,CAAC+B,KAAD,EAA2B;AAC3D,QAAIA,KAAK,CAACC,IAAN,KAAeC,0CAAgCC,IAAnD,EAAyD;AACvD,WAAK1B,gBAAL,CAAsB2B,IAAtB,CAA2BJ,KAAK,CAACnB,IAAjC;AACD;AACF;;AAtFwC","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';\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 compilerOptions.deleteDistDir = true;\n await this.compile.compileComponents(components, compilerOptions);\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, compilerOptions);\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","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,EAAM,MAAN,EAAc,2CAAd,CAHQ,CAM0F;AAAE;;AAE1F,QAANC,MAAM,CAAC,CAACC,UAAU,G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0B,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,17 +1,17 @@
1
+ import { AspectLoaderMain } from '@teambit/aspect-loader';
2
+ import { BuilderMain } from '@teambit/builder';
1
3
  import { CLIMain } from '@teambit/cli';
4
+ import { Component } from '@teambit/component';
2
5
  import { EnvsMain } from '@teambit/envs';
6
+ import { BitId } from '@teambit/legacy-bit-id';
3
7
  import { LoggerMain } from '@teambit/logger';
4
- import { Workspace } from '@teambit/workspace';
5
8
  import { PubsubMain } from '@teambit/pubsub';
6
- import { AspectLoaderMain } from '@teambit/aspect-loader';
7
- import { Component } from '@teambit/component';
8
- import { BitId } from '@teambit/legacy-bit-id';
9
- import { BuilderMain } from '@teambit/builder';
10
9
  import { UiMain } from '@teambit/ui';
10
+ import { Workspace } from '@teambit/workspace';
11
11
  import { CompilerTask } from './compiler.task';
12
+ import { DistArtifact } from './dist-artifact';
12
13
  import { Compiler } from './types';
13
14
  import { CompileOptions, WorkspaceCompiler } from './workspace-compiler';
14
- import { DistArtifact } from './dist-artifact';
15
15
  export declare class CompilerMain {
16
16
  private pubsub;
17
17
  private workspaceCompiler;
@@ -21,70 +21,70 @@ function _defineProperty2() {
21
21
  return data;
22
22
  }
23
23
 
24
- function _cli() {
25
- const data = require("@teambit/cli");
24
+ function _aspectLoader() {
25
+ const data = _interopRequireDefault(require("@teambit/aspect-loader"));
26
26
 
27
- _cli = function () {
27
+ _aspectLoader = function () {
28
28
  return data;
29
29
  };
30
30
 
31
31
  return data;
32
32
  }
33
33
 
34
- function _envs() {
35
- const data = require("@teambit/envs");
34
+ function _builder() {
35
+ const data = require("@teambit/builder");
36
36
 
37
- _envs = function () {
37
+ _builder = function () {
38
38
  return data;
39
39
  };
40
40
 
41
41
  return data;
42
42
  }
43
43
 
44
- function _logger() {
45
- const data = require("@teambit/logger");
44
+ function _cli() {
45
+ const data = require("@teambit/cli");
46
46
 
47
- _logger = function () {
47
+ _cli = function () {
48
48
  return data;
49
49
  };
50
50
 
51
51
  return data;
52
52
  }
53
53
 
54
- function _workspace() {
55
- const data = require("@teambit/workspace");
54
+ function _envs() {
55
+ const data = require("@teambit/envs");
56
56
 
57
- _workspace = function () {
57
+ _envs = function () {
58
58
  return data;
59
59
  };
60
60
 
61
61
  return data;
62
62
  }
63
63
 
64
- function _pubsub() {
65
- const data = require("@teambit/pubsub");
64
+ function _manyComponentsWriter() {
65
+ const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/component-ops/many-components-writer"));
66
66
 
67
- _pubsub = function () {
67
+ _manyComponentsWriter = function () {
68
68
  return data;
69
69
  };
70
70
 
71
71
  return data;
72
72
  }
73
73
 
74
- function _aspectLoader() {
75
- const data = _interopRequireDefault(require("@teambit/aspect-loader"));
74
+ function _logger() {
75
+ const data = require("@teambit/logger");
76
76
 
77
- _aspectLoader = function () {
77
+ _logger = function () {
78
78
  return data;
79
79
  };
80
80
 
81
81
  return data;
82
82
  }
83
83
 
84
- function _builder() {
85
- const data = require("@teambit/builder");
84
+ function _pubsub() {
85
+ const data = require("@teambit/pubsub");
86
86
 
87
- _builder = function () {
87
+ _pubsub = function () {
88
88
  return data;
89
89
  };
90
90
 
@@ -101,10 +101,10 @@ function _ui() {
101
101
  return data;
102
102
  }
103
103
 
104
- function _manyComponentsWriter() {
105
- const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/component-ops/many-components-writer"));
104
+ function _workspace() {
105
+ const data = require("@teambit/workspace");
106
106
 
107
- _manyComponentsWriter = function () {
107
+ _workspace = function () {
108
108
  return data;
109
109
  };
110
110
 
@@ -112,7 +112,7 @@ function _manyComponentsWriter() {
112
112
  }
113
113
 
114
114
  function _compiler() {
115
- const data = require("./compiler.service");
115
+ const data = require("./compiler.aspect");
116
116
 
117
117
  _compiler = function () {
118
118
  return data;
@@ -122,7 +122,7 @@ function _compiler() {
122
122
  }
123
123
 
124
124
  function _compiler2() {
125
- const data = require("./compiler.aspect");
125
+ const data = require("./compiler.cmd");
126
126
 
127
127
  _compiler2 = function () {
128
128
  return data;
@@ -132,7 +132,7 @@ function _compiler2() {
132
132
  }
133
133
 
134
134
  function _compiler3() {
135
- const data = require("./compiler.cmd");
135
+ const data = require("./compiler.service");
136
136
 
137
137
  _compiler3 = function () {
138
138
  return data;
@@ -151,30 +151,40 @@ function _compiler4() {
151
151
  return data;
152
152
  }
153
153
 
154
- function _workspaceCompiler() {
155
- const data = require("./workspace-compiler");
154
+ function _distArtifact() {
155
+ const data = require("./dist-artifact");
156
156
 
157
- _workspaceCompiler = function () {
157
+ _distArtifact = function () {
158
158
  return data;
159
159
  };
160
160
 
161
161
  return data;
162
162
  }
163
163
 
164
- function _distArtifact() {
165
- const data = require("./dist-artifact");
164
+ function _exceptions() {
165
+ const data = require("./exceptions");
166
166
 
167
- _distArtifact = function () {
167
+ _exceptions = function () {
168
168
  return data;
169
169
  };
170
170
 
171
171
  return data;
172
172
  }
173
173
 
174
- function _exceptions() {
175
- const data = require("./exceptions");
174
+ function _types() {
175
+ const data = require("./types");
176
176
 
177
- _exceptions = function () {
177
+ _types = function () {
178
+ return data;
179
+ };
180
+
181
+ return data;
182
+ }
183
+
184
+ function _workspaceCompiler() {
185
+ const data = require("./workspace-compiler");
186
+
187
+ _workspaceCompiler = function () {
178
188
  return data;
179
189
  };
180
190
 
@@ -188,9 +198,15 @@ class CompilerMain {
188
198
  this.envs = envs;
189
199
  this.builder = builder;
190
200
  }
201
+ /**
202
+ * Run compilation on `bit new` and when new components are imported
203
+ */
204
+
191
205
 
192
206
  compileOnWorkspace(componentsIds = [], // when empty, it compiles all
193
- options = {}) {
207
+ options = {
208
+ origin: _types().CompilationInitiator.ComponentAdded
209
+ }) {
194
210
  return this.workspaceCompiler.compileComponents(componentsIds, options);
195
211
  }
196
212
  /**
@@ -200,7 +216,7 @@ class CompilerMain {
200
216
 
201
217
 
202
218
  createTask(name, compiler) {
203
- return new (_compiler4().CompilerTask)(_compiler2().CompilerAspect.id, name, compiler);
219
+ return new (_compiler4().CompilerTask)(_compiler().CompilerAspect.id, name, compiler);
204
220
  }
205
221
  /**
206
222
  * find the compiler configured on the workspace and ask for the dist path.
@@ -217,17 +233,17 @@ class CompilerMain {
217
233
  }
218
234
 
219
235
  async getDistsFiles(component) {
220
- const artifacts = await this.builder.getArtifactsVinylByExtension(component, _compiler2().CompilerAspect.id);
236
+ const artifacts = await this.builder.getArtifactsVinylByExtension(component, _compiler().CompilerAspect.id);
221
237
  if (!artifacts.length) throw new (_exceptions().DistArtifactNotFound)(component.id);
222
238
  return new (_distArtifact().DistArtifact)(artifacts);
223
239
  }
224
240
 
225
241
  static async provider([cli, workspace, envs, loggerMain, pubsub, aspectLoader, builder, ui]) {
226
242
  const workspaceCompiler = new (_workspaceCompiler().WorkspaceCompiler)(workspace, envs, pubsub, aspectLoader, ui);
227
- envs.registerService(new (_compiler().CompilerService)());
243
+ envs.registerService(new (_compiler3().CompilerService)());
228
244
  const compilerMain = new CompilerMain(pubsub, workspaceCompiler, envs, builder);
229
- const logger = loggerMain.createLogger(_compiler2().CompilerAspect.id);
230
- cli.register(new (_compiler3().CompileCmd)(workspaceCompiler, logger, pubsub));
245
+ const logger = loggerMain.createLogger(_compiler().CompilerAspect.id);
246
+ cli.register(new (_compiler2().CompileCmd)(workspaceCompiler, logger, pubsub));
231
247
  _manyComponentsWriter().default.externalCompiler = compilerMain.compileOnWorkspace.bind(compilerMain);
232
248
  return compilerMain;
233
249
  }
@@ -238,6 +254,6 @@ exports.CompilerMain = CompilerMain;
238
254
  (0, _defineProperty2().default)(CompilerMain, "runtime", _cli().MainRuntime);
239
255
  (0, _defineProperty2().default)(CompilerMain, "dependencies", [_cli().CLIAspect, _workspace().WorkspaceAspect, _envs().EnvsAspect, _logger().LoggerAspect, _pubsub().PubsubAspect, _aspectLoader().default, _builder().BuilderAspect, _ui().default]);
240
256
 
241
- _compiler2().CompilerAspect.addRuntime(CompilerMain);
257
+ _compiler().CompilerAspect.addRuntime(CompilerMain);
242
258
 
243
259
  //# sourceMappingURL=compiler.main.runtime.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["compiler.main.runtime.ts"],"names":["CompilerMain","constructor","pubsub","workspaceCompiler","envs","builder","compileOnWorkspace","componentsIds","options","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;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;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;;AACA;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;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,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AeoB,eAARK,QAAQ,CAAC,CAACC,GAAD,EAAMC,SAAN,EAAiB5B,IAAjB,EAAuB6B,UAAvB,EAAmC/B,MAAnC,EAA2CgC,YAA3C,EAAyD7B,OAAzD,EAAkE8B,EAAlE,CAAD,EASlB;AACD,UAAMhC,iBAAiB,GAAG,KAAIiC,sCAAJ,EAAsBJ,SAAtB,EAAiC5B,IAAjC,EAAuCF,MAAvC,EAA+CgC,YAA/C,EAA6DC,EAA7D,CAA1B;AACA/B,IAAAA,IAAI,CAACiC,eAAL,CAAqB,KAAIC,2BAAJ,GAArB;AACA,UAAMC,YAAY,GAAG,IAAIvC,YAAJ,CAAiBE,MAAjB,EAAyBC,iBAAzB,EAA4CC,IAA5C,EAAkDC,OAAlD,CAArB;AACA,UAAMmC,MAAM,GAAGP,UAAU,CAACQ,YAAX,CAAwB3B,4BAAeC,EAAvC,CAAf;AACAgB,IAAAA,GAAG,CAACW,QAAJ,CAAa,KAAIC,uBAAJ,EAAexC,iBAAf,EAAkCqC,MAAlC,EAA0CtC,MAA1C,CAAb;AAEA0C,oCAAqBC,gBAArB,GAAwCN,YAAY,CAACjC,kBAAb,CAAgCwC,IAAhC,CAAqCP,YAArC,CAAxC;AAEA,WAAOA,YAAP;AACD;;AAvEuB;;;gCAAbvC,Y,aAuCM+C,kB;gCAvCN/C,Y,kBAyCW,CACpBgD,gBADoB,EAEpBC,4BAFoB,EAGpBC,kBAHoB,EAIpBC,sBAJoB,EAKpBC,sBALoB,EAMpBC,uBANoB,EAOpBC,wBAPoB,EAQpBC,aARoB,C;;AAiCxBzC,4BAAe0C,UAAf,CAA0BxD,YAA1B","sourcesContent":["import { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';\nimport { EnvsAspect, EnvsMain } from '@teambit/envs';\nimport { LoggerAspect, LoggerMain } from '@teambit/logger';\nimport { Workspace, WorkspaceAspect } from '@teambit/workspace';\nimport { PubsubAspect, PubsubMain } from '@teambit/pubsub';\nimport AspectLoaderAspect, { AspectLoaderMain } from '@teambit/aspect-loader';\nimport { Component } from '@teambit/component';\nimport { BitId } from '@teambit/legacy-bit-id';\nimport { BuilderAspect, BuilderMain } from '@teambit/builder';\nimport UIAspect, { UiMain } from '@teambit/ui';\n\nimport ManyComponentsWriter from '@teambit/legacy/dist/consumer/component-ops/many-components-writer';\nimport { CompilerService } from './compiler.service';\nimport { CompilerAspect } from './compiler.aspect';\nimport { CompileCmd } from './compiler.cmd';\nimport { CompilerTask } from './compiler.task';\nimport { Compiler } from './types';\nimport { CompileOptions, WorkspaceCompiler } from './workspace-compiler';\nimport { DistArtifact } from './dist-artifact';\nimport { DistArtifactNotFound } from './exceptions';\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 compileOnWorkspace(\n componentsIds: string[] | BitId[] = [], // when empty, it compiles all\n options: CompileOptions = {}\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","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;AA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AAwCN,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 = { 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"]}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export type { CompilerMain } from './compiler.main.runtime';
2
2
  export { CompilerAspect } from './compiler.aspect';
3
- export { Compiler, CompilerOptions, TranspileFileOutput, TranspileFileParams, TranspileComponentParams } from './types';
3
+ export { Compiler, CompilerOptions, CompilationInitiator, TranspileFileOutput, TranspileFileParams, TranspileComponentParams, } from './types';
4
4
  export * from './events';
package/dist/index.js CHANGED
@@ -7,6 +7,7 @@ var _exportNames = {
7
7
  CompilerAspect: true,
8
8
  Compiler: true,
9
9
  CompilerOptions: true,
10
+ CompilationInitiator: true,
10
11
  TranspileFileOutput: true,
11
12
  TranspileFileParams: true,
12
13
  TranspileComponentParams: true
@@ -29,6 +30,12 @@ Object.defineProperty(exports, "CompilerOptions", {
29
30
  return _types().CompilerOptions;
30
31
  }
31
32
  });
33
+ Object.defineProperty(exports, "CompilationInitiator", {
34
+ enumerable: true,
35
+ get: function () {
36
+ return _types().CompilationInitiator;
37
+ }
38
+ });
32
39
  Object.defineProperty(exports, "TranspileFileOutput", {
33
40
  enumerable: true,
34
41
  get: function () {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export type { CompilerMain } from './compiler.main.runtime';\nexport { CompilerAspect } from './compiler.aspect';\nexport { Compiler, CompilerOptions, TranspileFileOutput, TranspileFileParams, TranspileComponentParams } from './types';\nexport * from './events';\n"]}
1
+ {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAQA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export type { CompilerMain } from './compiler.main.runtime';\nexport { CompilerAspect } from './compiler.aspect';\nexport {\n Compiler,\n CompilerOptions,\n CompilationInitiator,\n TranspileFileOutput,\n TranspileFileParams,\n TranspileComponentParams,\n} from './types';\nexport * from './events';\n"]}
package/dist/types.d.ts CHANGED
@@ -1,13 +1,23 @@
1
1
  import { BuildContext, BuildTask, BuiltTaskResult, TaskResultsList } from '@teambit/builder';
2
2
  import ConsumerComponent from '@teambit/legacy/dist/consumer/component';
3
+ import type { Component } from '@teambit/component';
3
4
  export declare type TranspileFileParams = {
4
5
  componentDir: string;
5
6
  filePath: string;
6
7
  };
8
+ export declare enum CompilationInitiator {
9
+ CmdReport = 0,
10
+ CmdJson = 1,
11
+ PreStart = 2,
12
+ ComponentChanged = 3,
13
+ AspectLoadFail = 4,
14
+ ComponentAdded = 5
15
+ }
7
16
  export declare type TranspileComponentParams = {
8
17
  component: ConsumerComponent;
9
18
  componentDir: string;
10
19
  outputDir: string;
20
+ origin: CompilationInitiator;
11
21
  };
12
22
  export declare type TranspileFileOutput = {
13
23
  outputText: string;
@@ -27,6 +37,7 @@ export interface Compiler extends CompilerOptions {
27
37
  transpileComponent?: (params: TranspileComponentParams) => Promise<void>;
28
38
  build(context: BuildContext): Promise<BuiltTaskResult>;
29
39
  getDistPathBySrcPath(srcPath: string): string;
40
+ getPreviewComponentRootPath?(component: Component): string;
30
41
  isFileSupported(filePath: string): boolean;
31
42
  createTask?(name?: string): BuildTask;
32
43
  preBuild?(context: BuildContext): Promise<void>;
package/dist/types.js CHANGED
@@ -1,3 +1,19 @@
1
1
  "use strict";
2
2
 
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CompilationInitiator = void 0;
7
+ let CompilationInitiator;
8
+ exports.CompilationInitiator = CompilationInitiator;
9
+
10
+ (function (CompilationInitiator) {
11
+ CompilationInitiator[CompilationInitiator["CmdReport"] = 0] = "CmdReport";
12
+ CompilationInitiator[CompilationInitiator["CmdJson"] = 1] = "CmdJson";
13
+ CompilationInitiator[CompilationInitiator["PreStart"] = 2] = "PreStart";
14
+ CompilationInitiator[CompilationInitiator["ComponentChanged"] = 3] = "ComponentChanged";
15
+ CompilationInitiator[CompilationInitiator["AspectLoadFail"] = 4] = "AspectLoadFail";
16
+ CompilationInitiator[CompilationInitiator["ComponentAdded"] = 5] = "ComponentAdded";
17
+ })(CompilationInitiator || (exports.CompilationInitiator = CompilationInitiator = {}));
18
+
3
19
  //# sourceMappingURL=types.js.map
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
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"]}
@@ -8,7 +8,7 @@ import { Dist } from '@teambit/legacy/dist/consumer/component/sources';
8
8
  import { AspectLoaderMain } from '@teambit/aspect-loader';
9
9
  import { UiMain } from '@teambit/ui';
10
10
  import type { PreStartOpts } from '@teambit/ui';
11
- import { Compiler } from './types';
11
+ import { Compiler, CompilationInitiator } from './types';
12
12
  export declare type BuildResult = {
13
13
  component: string;
14
14
  buildResults: string[] | null | undefined;
@@ -17,6 +17,7 @@ export declare type CompileOptions = {
17
17
  changed?: boolean;
18
18
  verbose?: boolean;
19
19
  deleteDistDir?: boolean;
20
+ origin: CompilationInitiator;
20
21
  };
21
22
  export declare type CompileError = {
22
23
  path: string;
@@ -141,6 +141,16 @@ function _events() {
141
141
  return data;
142
142
  }
143
143
 
144
+ function _types() {
145
+ const data = require("./types");
146
+
147
+ _types = function () {
148
+ return data;
149
+ };
150
+
151
+ return data;
152
+ }
153
+
144
154
  /* eslint-disable max-classes-per-file */
145
155
  class ComponentCompiler {
146
156
  constructor(pubsub, workspace, component, compilerInstance, compilerId, dists = [], compileErrors = []) {
@@ -164,9 +174,9 @@ class ComponentCompiler {
164
174
  }
165
175
 
166
176
  if (this.compilerInstance.transpileFile) {
167
- await Promise.all(this.component.files.map(file => this.compileOneFileWithNewCompiler(file)));
177
+ await Promise.all(this.component.files.map(file => this.compileOneFileWithNewCompiler(file, options.origin)));
168
178
  } else if (this.compilerInstance.transpileComponent) {
169
- await this.compileAllFilesWithNewCompiler(this.component);
179
+ await this.compileAllFilesWithNewCompiler(this.component, options.origin);
170
180
  } else {
171
181
  throw new Error(`compiler ${this.compilerId.toString()} doesn't implement either "transpileFile" or "transpileComponent" methods`);
172
182
  }
@@ -221,10 +231,11 @@ ${this.compileErrors.map(formatError).join('\n')}`);
221
231
  return this.workspace.componentDir(new (_component().ComponentID)(this.component.id));
222
232
  }
223
233
 
224
- async compileOneFileWithNewCompiler(file) {
234
+ async compileOneFileWithNewCompiler(file, origin) {
225
235
  const options = {
226
236
  componentDir: this.componentDir,
227
- filePath: file.relative
237
+ filePath: file.relative,
238
+ origin
228
239
  };
229
240
  const isFileSupported = this.compilerInstance.isFileSupported(file.path);
230
241
  let compileResults;
@@ -261,7 +272,7 @@ ${this.compileErrors.map(formatError).join('\n')}`);
261
272
  }
262
273
  }
263
274
 
264
- async compileAllFilesWithNewCompiler(component) {
275
+ async compileAllFilesWithNewCompiler(component, origin) {
265
276
  const base = this.distDir;
266
277
  const filesToCompile = [];
267
278
  component.files.forEach(file => {
@@ -286,7 +297,8 @@ ${this.compileErrors.map(formatError).join('\n')}`);
286
297
  await ((_this$compilerInstanc3 = (_this$compilerInstanc4 = this.compilerInstance).transpileComponent) === null || _this$compilerInstanc3 === void 0 ? void 0 : _this$compilerInstanc3.call(_this$compilerInstanc4, {
287
298
  component,
288
299
  componentDir: this.componentDir,
289
- outputDir: this.workspace.getComponentPackagePath(component)
300
+ outputDir: this.workspace.getComponentPackagePath(component),
301
+ origin
290
302
  }));
291
303
  } catch (error) {
292
304
  this.compileErrors.push({
@@ -328,13 +340,16 @@ class WorkspaceCompiler {
328
340
  await this.compileComponents([], {
329
341
  changed: true,
330
342
  verbose: false,
331
- deleteDistDir: false
343
+ deleteDistDir: false,
344
+ origin: _types().CompilationInitiator.PreStart
332
345
  });
333
346
  }
334
347
 
335
348
  async onAspectLoadFail(err, id) {
336
349
  if (err.code && err.code === 'MODULE_NOT_FOUND' && this.workspace) {
337
- await this.compileComponents([id.toString()], {}, true);
350
+ await this.compileComponents([id.toString()], {
351
+ origin: _types().CompilationInitiator.AspectLoadFail
352
+ }, true);
338
353
  return true;
339
354
  }
340
355
 
@@ -342,7 +357,9 @@ class WorkspaceCompiler {
342
357
  }
343
358
 
344
359
  async onComponentChange(component) {
345
- const buildResults = await this.compileComponents([component.id.toString()], {}, true);
360
+ const buildResults = await this.compileComponents([component.id.toString()], {
361
+ origin: _types().CompilationInitiator.ComponentChanged
362
+ }, true);
346
363
  return {
347
364
  results: buildResults,
348
365
 
@@ -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","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","code","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;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B,CAA6BiH,IAA7B,IAAqC,UAA1D;AACAX,QAAAA,yBAAyB,CAACtC,IAA1B,CACE,IAAIjE,iBAAJ,CAAsB,KAAKE,MAA3B,EAAmC,KAAKC,SAAxC,EAAmDqG,CAAC,CAACK,KAAF,CAAQC,SAA3D,EAAsEzG,gBAAtE,EAAwF4G,YAAxF,CADF;AAGD;AACF,KAXD;AAYA,UAAME,6BAA6B,GAAG,MAAM,2BAAUZ,yBAAV,EAAsCa,wBAAD,IAC/EA,wBAAwB,CAAC3G,OAAzB,CAAiCC,OAAjC,EAA0CC,OAA1C,CAD0C,CAA5C;AAIA,WAAOwG,6BAAP;AACD;;AAE4B,QAAff,eAAe,CAACJ,aAAD,EAAuCJ,OAAO,GAAG,KAAjD,EAAgF;AAC3G,QAAII,aAAa,CAACrD,MAAlB,EAA0B;AACxB,aAAO,KAAKxC,SAAL,CAAekH,2BAAf,CAA2CrB,aAA3C,CAAP;AACD;;AACD,QAAIJ,OAAJ,EAAa;AACX,aAAO,KAAKzF,SAAL,CAAemH,oBAAf,EAAP;AACD;;AACD,WAAO,KAAKnH,SAAL,CAAeoH,kBAAf,EAAP;AACD;;AAjF4B","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 } 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};\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(this.component.files.map((file: SourceFile) => this.compileOneFileWithNewCompiler(file)));\n } else if (this.compilerInstance.transpileComponent) {\n await this.compileAllFilesWithNewCompiler(this.component);\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): Promise<void> {\n const options = { componentDir: this.componentDir, filePath: file.relative };\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(component: ConsumerComponent): 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 });\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([], { changed: true, verbose: false, deleteDistDir: false });\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()], {}, true);\n return true;\n }\n return false;\n }\n\n async onComponentChange(component: Component): Promise<SerializableResults> {\n const buildResults = await this.compileComponents([component.id.toString()], {}, true);\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","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;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A3B,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 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"]}
package/index.ts CHANGED
@@ -1,4 +1,11 @@
1
1
  export type { CompilerMain } from './compiler.main.runtime';
2
2
  export { CompilerAspect } from './compiler.aspect';
3
- export { Compiler, CompilerOptions, TranspileFileOutput, TranspileFileParams, TranspileComponentParams } from './types';
3
+ export {
4
+ Compiler,
5
+ CompilerOptions,
6
+ CompilationInitiator,
7
+ TranspileFileOutput,
8
+ TranspileFileParams,
9
+ TranspileComponentParams,
10
+ } from './types';
4
11
  export * from './events';
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/compiler",
3
- "version": "0.0.516",
3
+ "version": "0.0.520",
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.516"
9
+ "version": "0.0.520"
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.379",
22
- "@teambit/logger": "0.0.447",
23
- "@teambit/pubsub": "0.0.516",
24
- "@teambit/aspect-loader": "0.0.516",
25
- "@teambit/builder": "0.0.516",
26
- "@teambit/component": "0.0.516",
27
- "@teambit/envs": "0.0.516",
22
+ "@teambit/logger": "0.0.449",
23
+ "@teambit/pubsub": "0.0.520",
24
+ "@teambit/aspect-loader": "0.0.520",
25
+ "@teambit/builder": "0.0.520",
26
+ "@teambit/component": "0.0.520",
27
+ "@teambit/envs": "0.0.520",
28
28
  "@teambit/legacy-bit-id": "0.0.368",
29
- "@teambit/ui": "0.0.516",
30
- "@teambit/workspace": "0.0.516",
31
- "@teambit/isolator": "0.0.516",
29
+ "@teambit/ui": "0.0.520",
30
+ "@teambit/workspace": "0.0.520",
31
+ "@teambit/isolator": "0.0.520",
32
32
  "@teambit/bit-error": "0.0.365"
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.83"
42
+ "@teambit/compilation.aspect-docs.compiler": "0.0.85"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "@teambit/legacy": "1.0.76",
package/types.ts CHANGED
@@ -1,15 +1,26 @@
1
1
  import { BuildContext, BuildTask, BuiltTaskResult, TaskResultsList } from '@teambit/builder';
2
2
  import ConsumerComponent from '@teambit/legacy/dist/consumer/component';
3
+ import type { Component } from '@teambit/component';
3
4
 
4
5
  export type TranspileFileParams = {
5
6
  componentDir: string; // absolute path of the component's root directory
6
7
  filePath: string; // relative path of the file inside the component directory
7
8
  };
8
9
 
10
+ export enum CompilationInitiator {
11
+ CmdReport,
12
+ CmdJson,
13
+ PreStart,
14
+ ComponentChanged,
15
+ AspectLoadFail,
16
+ ComponentAdded,
17
+ }
18
+
9
19
  export type TranspileComponentParams = {
10
20
  component: ConsumerComponent;
11
21
  componentDir: string; // absolute path of the component's root directory
12
22
  outputDir: string; // absolute path of the component's output directory
23
+ origin: CompilationInitiator; // origin of the compilation's request
13
24
  };
14
25
 
15
26
  export type TranspileFileOutput =
@@ -85,6 +96,12 @@ export interface Compiler extends CompilerOptions {
85
96
  */
86
97
  getDistPathBySrcPath(srcPath: string): string;
87
98
 
99
+ /**
100
+ * given a component, returns the path to the source folder to use for the preview, uses the one
101
+ * in node_modules by default
102
+ */
103
+ getPreviewComponentRootPath?(component: Component): string;
104
+
88
105
  /**
89
106
  * only supported files matching get compiled. others, are copied to the dist dir.
90
107
  */
@@ -21,7 +21,7 @@ import type { PreStartOpts } from '@teambit/ui';
21
21
  import { PathOsBasedAbsolute, PathOsBasedRelative } from '@teambit/legacy/dist/utils/path';
22
22
  import { CompilerAspect } from './compiler.aspect';
23
23
  import { CompilerErrorEvent, ComponentCompilationOnDoneEvent } from './events';
24
- import { Compiler } from './types';
24
+ import { Compiler, CompilationInitiator } from './types';
25
25
 
26
26
  export type BuildResult = { component: string; buildResults: string[] | null | undefined };
27
27
 
@@ -34,6 +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
38
  };
38
39
 
39
40
  export type CompileError = { path: string; error: Error };
@@ -60,9 +61,11 @@ export class ComponentCompiler {
60
61
  }
61
62
 
62
63
  if (this.compilerInstance.transpileFile) {
63
- await Promise.all(this.component.files.map((file: SourceFile) => this.compileOneFileWithNewCompiler(file)));
64
+ await Promise.all(
65
+ this.component.files.map((file: SourceFile) => this.compileOneFileWithNewCompiler(file, options.origin))
66
+ );
64
67
  } else if (this.compilerInstance.transpileComponent) {
65
- await this.compileAllFilesWithNewCompiler(this.component);
68
+ await this.compileAllFilesWithNewCompiler(this.component, options.origin);
66
69
  } else {
67
70
  throw new Error(
68
71
  `compiler ${this.compilerId.toString()} doesn't implement either "transpileFile" or "transpileComponent" methods`
@@ -115,8 +118,8 @@ ${this.compileErrors.map(formatError).join('\n')}`);
115
118
  return this.workspace.componentDir(new ComponentID(this.component.id));
116
119
  }
117
120
 
118
- private async compileOneFileWithNewCompiler(file: SourceFile): Promise<void> {
119
- const options = { componentDir: this.componentDir, filePath: file.relative };
121
+ private async compileOneFileWithNewCompiler(file: SourceFile, origin: CompilationInitiator): Promise<void> {
122
+ const options = { componentDir: this.componentDir, filePath: file.relative, origin };
120
123
  const isFileSupported = this.compilerInstance.isFileSupported(file.path);
121
124
  let compileResults;
122
125
  if (isFileSupported) {
@@ -145,7 +148,10 @@ ${this.compileErrors.map(formatError).join('\n')}`);
145
148
  }
146
149
  }
147
150
 
148
- private async compileAllFilesWithNewCompiler(component: ConsumerComponent): Promise<void> {
151
+ private async compileAllFilesWithNewCompiler(
152
+ component: ConsumerComponent,
153
+ origin: CompilationInitiator
154
+ ): Promise<void> {
149
155
  const base = this.distDir;
150
156
  const filesToCompile: SourceFile[] = [];
151
157
  component.files.forEach((file: SourceFile) => {
@@ -170,6 +176,7 @@ ${this.compileErrors.map(formatError).join('\n')}`);
170
176
  component,
171
177
  componentDir: this.componentDir,
172
178
  outputDir: this.workspace.getComponentPackagePath(component),
179
+ origin,
173
180
  });
174
181
  } catch (error: any) {
175
182
  this.compileErrors.push({ path: this.componentDir, error });
@@ -200,19 +207,28 @@ export class WorkspaceCompiler {
200
207
  if (preStartOpts.skipCompilation) {
201
208
  return;
202
209
  }
203
- await this.compileComponents([], { changed: true, verbose: false, deleteDistDir: false });
210
+ await this.compileComponents([], {
211
+ changed: true,
212
+ verbose: false,
213
+ deleteDistDir: false,
214
+ origin: CompilationInitiator.PreStart,
215
+ });
204
216
  }
205
217
 
206
218
  async onAspectLoadFail(err: Error & { code?: string }, id: ComponentID): Promise<boolean> {
207
219
  if (err.code && err.code === 'MODULE_NOT_FOUND' && this.workspace) {
208
- await this.compileComponents([id.toString()], {}, true);
220
+ await this.compileComponents([id.toString()], { origin: CompilationInitiator.AspectLoadFail }, true);
209
221
  return true;
210
222
  }
211
223
  return false;
212
224
  }
213
225
 
214
226
  async onComponentChange(component: Component): Promise<SerializableResults> {
215
- const buildResults = await this.compileComponents([component.id.toString()], {}, true);
227
+ const buildResults = await this.compileComponents(
228
+ [component.id.toString()],
229
+ { origin: CompilationInitiator.ComponentChanged },
230
+ true
231
+ );
216
232
  return {
217
233
  results: buildResults,
218
234
  toString() {