@teambit/compiler 0.0.880 → 0.0.882

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.
Files changed (46) hide show
  1. package/dist/compiler.aspect.js +0 -5
  2. package/dist/compiler.aspect.js.map +1 -1
  3. package/dist/compiler.cmd.js +2 -40
  4. package/dist/compiler.cmd.js.map +1 -1
  5. package/dist/compiler.composition.js +0 -6
  6. package/dist/compiler.composition.js.map +1 -1
  7. package/dist/compiler.main.runtime.js +8 -107
  8. package/dist/compiler.main.runtime.js.map +1 -1
  9. package/dist/compiler.service.js +0 -18
  10. package/dist/compiler.service.js.map +1 -1
  11. package/dist/compiler.task.js +1 -30
  12. package/dist/compiler.task.js.map +1 -1
  13. package/dist/dist-artifact.js +0 -7
  14. package/dist/dist-artifact.js.map +1 -1
  15. package/dist/events/compiler-error.js +1 -12
  16. package/dist/events/compiler-error.js.map +1 -1
  17. package/dist/events/component-compilation-on-done.js +1 -12
  18. package/dist/events/component-compilation-on-done.js.map +1 -1
  19. package/dist/events/index.js +0 -4
  20. package/dist/events/index.js.map +1 -1
  21. package/dist/exceptions/dist-artifact-not-found.js +0 -6
  22. package/dist/exceptions/dist-artifact-not-found.js.map +1 -1
  23. package/dist/exceptions/index.js +0 -3
  24. package/dist/exceptions/index.js.map +1 -1
  25. package/dist/index.js +0 -8
  26. package/dist/index.js.map +1 -1
  27. package/dist/output-formatter.js +0 -9
  28. package/dist/output-formatter.js.map +1 -1
  29. package/dist/templates/compiler/files/aspect-file.js +0 -1
  30. package/dist/templates/compiler/files/aspect-file.js.map +1 -1
  31. package/dist/templates/compiler/files/compiler-file.js +0 -1
  32. package/dist/templates/compiler/files/compiler-file.js.map +1 -1
  33. package/dist/templates/compiler/files/index-file.js +0 -1
  34. package/dist/templates/compiler/files/index-file.js.map +1 -1
  35. package/dist/templates/compiler/files/main-runtime-file.js +0 -1
  36. package/dist/templates/compiler/files/main-runtime-file.js.map +1 -1
  37. package/dist/templates/compiler/index.js +0 -13
  38. package/dist/templates/compiler/index.js.map +1 -1
  39. package/dist/types.js +0 -1
  40. package/dist/types.js.map +1 -1
  41. package/dist/workspace-compiler.js +9 -97
  42. package/dist/workspace-compiler.js.map +1 -1
  43. package/package-tar/teambit-compiler-0.0.882.tgz +0 -0
  44. package/package.json +16 -16
  45. package/{preview-1666312873430.js → preview-1666496165706.js} +2 -2
  46. package/package-tar/teambit-compiler-0.0.880.tgz +0 -0
@@ -1,22 +1,17 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.formatCompileResults = void 0;
9
-
10
8
  function _chalk() {
11
9
  const data = _interopRequireDefault(require("chalk"));
12
-
13
10
  _chalk = function () {
14
11
  return data;
15
12
  };
16
-
17
13
  return data;
18
14
  }
19
-
20
15
  const formatCompileResults = (compileResults, verbose) => compileResults.map(componentResult => ({
21
16
  componentId: componentResult.component.id.fullName,
22
17
  files: componentResult.buildResults,
@@ -24,18 +19,14 @@ const formatCompileResults = (compileResults, verbose) => compileResults.map(com
24
19
  icon: componentResult.errors.length ? _chalk().default.red('✗') : _chalk().default.green('✔')
25
20
  })).reduce((outputString, result) => {
26
21
  outputString += `${result.icon} ${result.status}\t${result.componentId}`;
27
-
28
22
  if (verbose) {
29
23
  var _result$files;
30
-
31
24
  outputString += ':';
32
25
  outputString += result === null || result === void 0 ? void 0 : (_result$files = result.files) === null || _result$files === void 0 ? void 0 : _result$files.reduce((fileList, file) => `${fileList}\t\t - ${file}\n`, '\n');
33
26
  }
34
-
35
27
  outputString += '\n';
36
28
  return outputString;
37
29
  }, '');
38
-
39
30
  exports.formatCompileResults = formatCompileResults;
40
31
 
41
32
  //# sourceMappingURL=output-formatter.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["formatCompileResults","compileResults","verbose","map","componentResult","componentId","component","id","fullName","files","buildResults","status","errors","length","icon","chalk","red","green","reduce","outputString","result","fileList","file"],"sources":["output-formatter.ts"],"sourcesContent":["import chalk from 'chalk';\nimport { ComponentsStatus } from './compiler.cmd';\n\nexport const formatCompileResults = (compileResults: ComponentsStatus[], verbose: boolean) =>\n compileResults\n .map((componentResult: ComponentsStatus) => ({\n componentId: componentResult.component.id.fullName,\n files: componentResult.buildResults,\n status: componentResult.errors.length ? 'FAILURE' : 'SUCCESS',\n icon: componentResult.errors.length ? chalk.red('✗') : chalk.green('✔'),\n }))\n .reduce((outputString, result) => {\n outputString += `${result.icon} ${result.status}\\t${result.componentId}`;\n if (verbose) {\n outputString += ':';\n outputString += result?.files?.reduce((fileList, file) => `${fileList}\\t\\t - ${file}\\n`, '\\n');\n }\n outputString += '\\n';\n return outputString;\n }, '');\n"],"mappings":";;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGO,MAAMA,oBAAoB,GAAG,CAACC,cAAD,EAAqCC,OAArC,KAClCD,cAAc,CACXE,GADH,CACQC,eAAD,KAAwC;EAC3CC,WAAW,EAAED,eAAe,CAACE,SAAhB,CAA0BC,EAA1B,CAA6BC,QADC;EAE3CC,KAAK,EAAEL,eAAe,CAACM,YAFoB;EAG3CC,MAAM,EAAEP,eAAe,CAACQ,MAAhB,CAAuBC,MAAvB,GAAgC,SAAhC,GAA4C,SAHT;EAI3CC,IAAI,EAAEV,eAAe,CAACQ,MAAhB,CAAuBC,MAAvB,GAAgCE,gBAAA,CAAMC,GAAN,CAAU,GAAV,CAAhC,GAAiDD,gBAAA,CAAME,KAAN,CAAY,GAAZ;AAJZ,CAAxC,CADP,EAOGC,MAPH,CAOU,CAACC,YAAD,EAAeC,MAAf,KAA0B;EAChCD,YAAY,IAAK,GAAEC,MAAM,CAACN,IAAK,IAAGM,MAAM,CAACT,MAAO,KAAIS,MAAM,CAACf,WAAY,EAAvE;;EACA,IAAIH,OAAJ,EAAa;IAAA;;IACXiB,YAAY,IAAI,GAAhB;IACAA,YAAY,IAAIC,MAAJ,aAAIA,MAAJ,wCAAIA,MAAM,CAAEX,KAAZ,kDAAI,cAAeS,MAAf,CAAsB,CAACG,QAAD,EAAWC,IAAX,KAAqB,GAAED,QAAS,UAASC,IAAK,IAApE,EAAyE,IAAzE,CAAhB;EACD;;EACDH,YAAY,IAAI,IAAhB;EACA,OAAOA,YAAP;AACD,CAfH,EAeK,EAfL,CADK"}
1
+ {"version":3,"names":["formatCompileResults","compileResults","verbose","map","componentResult","componentId","component","id","fullName","files","buildResults","status","errors","length","icon","chalk","red","green","reduce","outputString","result","fileList","file"],"sources":["output-formatter.ts"],"sourcesContent":["import chalk from 'chalk';\nimport { ComponentsStatus } from './compiler.cmd';\n\nexport const formatCompileResults = (compileResults: ComponentsStatus[], verbose: boolean) =>\n compileResults\n .map((componentResult: ComponentsStatus) => ({\n componentId: componentResult.component.id.fullName,\n files: componentResult.buildResults,\n status: componentResult.errors.length ? 'FAILURE' : 'SUCCESS',\n icon: componentResult.errors.length ? chalk.red('✗') : chalk.green('✔'),\n }))\n .reduce((outputString, result) => {\n outputString += `${result.icon} ${result.status}\\t${result.componentId}`;\n if (verbose) {\n outputString += ':';\n outputString += result?.files?.reduce((fileList, file) => `${fileList}\\t\\t - ${file}\\n`, '\\n');\n }\n outputString += '\\n';\n return outputString;\n }, '');\n"],"mappings":";;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGO,MAAMA,oBAAoB,GAAG,CAACC,cAAkC,EAAEC,OAAgB,KACvFD,cAAc,CACXE,GAAG,CAAEC,eAAiC,KAAM;EAC3CC,WAAW,EAAED,eAAe,CAACE,SAAS,CAACC,EAAE,CAACC,QAAQ;EAClDC,KAAK,EAAEL,eAAe,CAACM,YAAY;EACnCC,MAAM,EAAEP,eAAe,CAACQ,MAAM,CAACC,MAAM,GAAG,SAAS,GAAG,SAAS;EAC7DC,IAAI,EAAEV,eAAe,CAACQ,MAAM,CAACC,MAAM,GAAGE,gBAAK,CAACC,GAAG,CAAC,GAAG,CAAC,GAAGD,gBAAK,CAACE,KAAK,CAAC,GAAG;AACxE,CAAC,CAAC,CAAC,CACFC,MAAM,CAAC,CAACC,YAAY,EAAEC,MAAM,KAAK;EAChCD,YAAY,IAAK,GAAEC,MAAM,CAACN,IAAK,IAAGM,MAAM,CAACT,MAAO,KAAIS,MAAM,CAACf,WAAY,EAAC;EACxE,IAAIH,OAAO,EAAE;IAAA;IACXiB,YAAY,IAAI,GAAG;IACnBA,YAAY,IAAIC,MAAM,aAANA,MAAM,wCAANA,MAAM,CAAEX,KAAK,kDAAb,cAAeS,MAAM,CAAC,CAACG,QAAQ,EAAEC,IAAI,KAAM,GAAED,QAAS,UAASC,IAAK,IAAG,EAAE,IAAI,CAAC;EAChG;EACAH,YAAY,IAAI,IAAI;EACpB,OAAOA,YAAY;AACrB,CAAC,EAAE,EAAE,CAAC;AAAC"}
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.aspectFile = aspectFile;
7
-
8
7
  function aspectFile({
9
8
  namePascalCase,
10
9
  componentId
@@ -1 +1 @@
1
- {"version":3,"names":["aspectFile","namePascalCase","componentId"],"sources":["aspect-file.ts"],"sourcesContent":["import { ComponentContext } from '@teambit/generator';\n\nexport function aspectFile({ namePascalCase, componentId }: ComponentContext) {\n return `import { Aspect } from '@teambit/harmony';\n\nexport const ${namePascalCase}Aspect = Aspect.create({\n id: '${componentId}',\n});\n `;\n}\n"],"mappings":";;;;;;;AAEO,SAASA,UAAT,CAAoB;EAAEC,cAAF;EAAkBC;AAAlB,CAApB,EAAuE;EAC5E,OAAQ;AACV;AACA,eAAeD,cAAe;AAC9B,SAASC,WAAY;AACrB;AACA,GALE;AAMD"}
1
+ {"version":3,"names":["aspectFile","namePascalCase","componentId"],"sources":["aspect-file.ts"],"sourcesContent":["import { ComponentContext } from '@teambit/generator';\n\nexport function aspectFile({ namePascalCase, componentId }: ComponentContext) {\n return `import { Aspect } from '@teambit/harmony';\n\nexport const ${namePascalCase}Aspect = Aspect.create({\n id: '${componentId}',\n});\n `;\n}\n"],"mappings":";;;;;;AAEO,SAASA,UAAU,CAAC;EAAEC,cAAc;EAAEC;AAA8B,CAAC,EAAE;EAC5E,OAAQ;AACV;AACA,eAAeD,cAAe;AAC9B,SAASC,WAAY;AACrB;AACA,GAAG;AACH"}
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.compilerFile = compilerFile;
7
-
8
7
  function compilerFile({
9
8
  namePascalCase
10
9
  }) {
@@ -1 +1 @@
1
- {"version":3,"names":["compilerFile","namePascalCase"],"sources":["compiler-file.ts"],"sourcesContent":["import { ComponentContext } from '@teambit/generator';\n\nexport function compilerFile({ namePascalCase }: ComponentContext) {\n return `import {\n BuildContext,\n BuiltTaskResult,\n ComponentResult,\n} from '@teambit/builder';\nimport {\n Compiler,\n CompilerMain,\n TranspileFileParams,\n TranspileFileOutput,\n} from '@teambit/compiler';\n\nexport class ${namePascalCase} implements Compiler {\n\n constructor(readonly id: string, readonly distDir, private compiler: CompilerMain) {}\n\n /**\n * Detemines whether unsupported files (such as assets)\n * should be copied by Compiler aspect into the 'dist' directory\n */\n shouldCopyNonSupportedFiles = true;\n\n /* The name of the compiler being used. For example, TypeScript, Babel, etc. */\n displayName = '';\n\n /* The version of the compiler being used. For example '1.0.0' */\n version(): string {};\n\n /**\n * Use this for compilation in the workspace.\n * This will compile one file content at a time (alternatively, use 'transpileComponent') */\n transpileFile( fileContent: string, transpileFileParams: TranspileFileParams): TranspileFileOutput {}\n\n\n async build(context: BuildContext): Promise<BuiltTaskResult> {\n let componentsResults: ComponentResult[] = [];\n return {\n /* Sets the files to persist as the Component's artifacts,\n and describes them. */\n artifacts: [\n {\n generatedBy: this.id,\n name: 'compilation output',\n globPatterns: [\\`\\${this.distDir}/**\\`],\n },\n ],\n componentsResults,\n };\n }\n\n /* This is optional but recommended.\n Not using it will require consumers of your compiler to use two APIs and have two depndencies\n to their Envs - your compiler\n */\n createTask() {\n return this.compiler.createTask('${namePascalCase}', this);\n }\n\n /**\n * Given a source file, return its parallel in the dists. e.g. index.ts => dist/index.js.\n * Needed by aspects such as Pkg to determine the main prop.\n */\n getDistPathBySrcPath(srcPath: string): string {}\n\n /**\n * Returns a boolean indicating whether a file is supported by the compiler or not.\n * For example, this API is used by Compiler aspect to copy unsupported files to the dist directory.\n */\n isFileSupported(filePath: string): boolean {}\n}\n `;\n}\n"],"mappings":";;;;;;;AAEO,SAASA,YAAT,CAAsB;EAAEC;AAAF,CAAtB,EAA4D;EACjE,OAAQ;AACV;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAeA,cAAe;AAC9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,2CAA2CA,cAAe;AAC1D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAtEE;AAuED"}
1
+ {"version":3,"names":["compilerFile","namePascalCase"],"sources":["compiler-file.ts"],"sourcesContent":["import { ComponentContext } from '@teambit/generator';\n\nexport function compilerFile({ namePascalCase }: ComponentContext) {\n return `import {\n BuildContext,\n BuiltTaskResult,\n ComponentResult,\n} from '@teambit/builder';\nimport {\n Compiler,\n CompilerMain,\n TranspileFileParams,\n TranspileFileOutput,\n} from '@teambit/compiler';\n\nexport class ${namePascalCase} implements Compiler {\n\n constructor(readonly id: string, readonly distDir, private compiler: CompilerMain) {}\n\n /**\n * Detemines whether unsupported files (such as assets)\n * should be copied by Compiler aspect into the 'dist' directory\n */\n shouldCopyNonSupportedFiles = true;\n\n /* The name of the compiler being used. For example, TypeScript, Babel, etc. */\n displayName = '';\n\n /* The version of the compiler being used. For example '1.0.0' */\n version(): string {};\n\n /**\n * Use this for compilation in the workspace.\n * This will compile one file content at a time (alternatively, use 'transpileComponent') */\n transpileFile( fileContent: string, transpileFileParams: TranspileFileParams): TranspileFileOutput {}\n\n\n async build(context: BuildContext): Promise<BuiltTaskResult> {\n let componentsResults: ComponentResult[] = [];\n return {\n /* Sets the files to persist as the Component's artifacts,\n and describes them. */\n artifacts: [\n {\n generatedBy: this.id,\n name: 'compilation output',\n globPatterns: [\\`\\${this.distDir}/**\\`],\n },\n ],\n componentsResults,\n };\n }\n\n /* This is optional but recommended.\n Not using it will require consumers of your compiler to use two APIs and have two depndencies\n to their Envs - your compiler\n */\n createTask() {\n return this.compiler.createTask('${namePascalCase}', this);\n }\n\n /**\n * Given a source file, return its parallel in the dists. e.g. index.ts => dist/index.js.\n * Needed by aspects such as Pkg to determine the main prop.\n */\n getDistPathBySrcPath(srcPath: string): string {}\n\n /**\n * Returns a boolean indicating whether a file is supported by the compiler or not.\n * For example, this API is used by Compiler aspect to copy unsupported files to the dist directory.\n */\n isFileSupported(filePath: string): boolean {}\n}\n `;\n}\n"],"mappings":";;;;;;AAEO,SAASA,YAAY,CAAC;EAAEC;AAAiC,CAAC,EAAE;EACjE,OAAQ;AACV;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAeA,cAAe;AAC9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,2CAA2CA,cAAe;AAC1D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH"}
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.indexFile = indexFile;
7
-
8
7
  function indexFile({
9
8
  namePascalCase,
10
9
  name
@@ -1 +1 @@
1
- {"version":3,"names":["indexFile","namePascalCase","name"],"sources":["index-file.ts"],"sourcesContent":["import { ComponentContext } from '@teambit/generator';\n\nexport function indexFile({ namePascalCase, name }: ComponentContext) {\n return `import { ${namePascalCase}Aspect } from './${name}.aspect';\n\nexport type { ${namePascalCase}Main } from './${name}.main.runtime';\nexport default ${namePascalCase}Aspect;\nexport { ${namePascalCase}Aspect };\n`;\n}\n"],"mappings":";;;;;;;AAEO,SAASA,SAAT,CAAmB;EAAEC,cAAF;EAAkBC;AAAlB,CAAnB,EAA+D;EACpE,OAAQ,YAAWD,cAAe,oBAAmBC,IAAK;AAC5D;AACA,gBAAgBD,cAAe,kBAAiBC,IAAK;AACrD,iBAAiBD,cAAe;AAChC,WAAWA,cAAe;AAC1B,CALE;AAMD"}
1
+ {"version":3,"names":["indexFile","namePascalCase","name"],"sources":["index-file.ts"],"sourcesContent":["import { ComponentContext } from '@teambit/generator';\n\nexport function indexFile({ namePascalCase, name }: ComponentContext) {\n return `import { ${namePascalCase}Aspect } from './${name}.aspect';\n\nexport type { ${namePascalCase}Main } from './${name}.main.runtime';\nexport default ${namePascalCase}Aspect;\nexport { ${namePascalCase}Aspect };\n`;\n}\n"],"mappings":";;;;;;AAEO,SAASA,SAAS,CAAC;EAAEC,cAAc;EAAEC;AAAuB,CAAC,EAAE;EACpE,OAAQ,YAAWD,cAAe,oBAAmBC,IAAK;AAC5D;AACA,gBAAgBD,cAAe,kBAAiBC,IAAK;AACrD,iBAAiBD,cAAe;AAChC,WAAWA,cAAe;AAC1B,CAAC;AACD"}
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.mainRuntimeFile = mainRuntimeFile;
7
-
8
7
  function mainRuntimeFile({
9
8
  name,
10
9
  namePascalCase
@@ -1 +1 @@
1
- {"version":3,"names":["mainRuntimeFile","name","namePascalCase"],"sources":["main-runtime-file.ts"],"sourcesContent":["import { ComponentContext } from '@teambit/generator';\n\nexport function mainRuntimeFile({ name, namePascalCase }: ComponentContext) {\n return `import { MainRuntime } from '@teambit/cli';\nimport { CompilerAspect, CompilerMain } from '@teambit/compiler';\nimport { ${namePascalCase} } from './${name}.compiler';\nimport { ${namePascalCase}Aspect } from './${name}.aspect';\n\nexport class ${namePascalCase}Main {\n constructor(private compiler: CompilerMain) {}\n\n static slots = [];\n static dependencies = [CompilerAspect];\n static runtime = MainRuntime;\n\n distDir = 'dist';\n\n /* Set the main property of the component's package with\n the relative output path for the main file */\n getPackageJsonProps() {\n return {\n main: '\\${this.distDir}/{main}.js',\n };\n }\n\n createCompiler(): ${namePascalCase} {\n return new ${namePascalCase}(${namePascalCase}Aspect.id, this.distDir, this.compiler);\n }\n\n static async provider([compiler]: [CompilerMain]) {\n return new ${namePascalCase}Main(compiler);\n }\n}\n\n${namePascalCase}Aspect.addRuntime(${namePascalCase}Main);\n`;\n}\n"],"mappings":";;;;;;;AAEO,SAASA,eAAT,CAAyB;EAAEC,IAAF;EAAQC;AAAR,CAAzB,EAAqE;EAC1E,OAAQ;AACV;AACA,WAAWA,cAAe,cAAaD,IAAK;AAC5C,WAAWC,cAAe,oBAAmBD,IAAK;AAClD;AACA,eAAeC,cAAe;AAC9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsBA,cAAe;AACrC,iBAAiBA,cAAe,IAAGA,cAAe;AAClD;AACA;AACA;AACA,iBAAiBA,cAAe;AAChC;AACA;AACA;AACA,EAAEA,cAAe,qBAAoBA,cAAe;AACpD,CAhCE;AAiCD"}
1
+ {"version":3,"names":["mainRuntimeFile","name","namePascalCase"],"sources":["main-runtime-file.ts"],"sourcesContent":["import { ComponentContext } from '@teambit/generator';\n\nexport function mainRuntimeFile({ name, namePascalCase }: ComponentContext) {\n return `import { MainRuntime } from '@teambit/cli';\nimport { CompilerAspect, CompilerMain } from '@teambit/compiler';\nimport { ${namePascalCase} } from './${name}.compiler';\nimport { ${namePascalCase}Aspect } from './${name}.aspect';\n\nexport class ${namePascalCase}Main {\n constructor(private compiler: CompilerMain) {}\n\n static slots = [];\n static dependencies = [CompilerAspect];\n static runtime = MainRuntime;\n\n distDir = 'dist';\n\n /* Set the main property of the component's package with\n the relative output path for the main file */\n getPackageJsonProps() {\n return {\n main: '\\${this.distDir}/{main}.js',\n };\n }\n\n createCompiler(): ${namePascalCase} {\n return new ${namePascalCase}(${namePascalCase}Aspect.id, this.distDir, this.compiler);\n }\n\n static async provider([compiler]: [CompilerMain]) {\n return new ${namePascalCase}Main(compiler);\n }\n}\n\n${namePascalCase}Aspect.addRuntime(${namePascalCase}Main);\n`;\n}\n"],"mappings":";;;;;;AAEO,SAASA,eAAe,CAAC;EAAEC,IAAI;EAAEC;AAAiC,CAAC,EAAE;EAC1E,OAAQ;AACV;AACA,WAAWA,cAAe,cAAaD,IAAK;AAC5C,WAAWC,cAAe,oBAAmBD,IAAK;AAClD;AACA,eAAeC,cAAe;AAC9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsBA,cAAe;AACrC,iBAAiBA,cAAe,IAAGA,cAAe;AAClD;AACA;AACA;AACA,iBAAiBA,cAAe;AAChC;AACA;AACA;AACA,EAAEA,cAAe,qBAAoBA,cAAe;AACpD,CAAC;AACD"}
@@ -4,47 +4,34 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.compilerTemplate = void 0;
7
-
8
7
  function _indexFile() {
9
8
  const data = require("./files/index-file");
10
-
11
9
  _indexFile = function () {
12
10
  return data;
13
11
  };
14
-
15
12
  return data;
16
13
  }
17
-
18
14
  function _aspectFile() {
19
15
  const data = require("./files/aspect-file");
20
-
21
16
  _aspectFile = function () {
22
17
  return data;
23
18
  };
24
-
25
19
  return data;
26
20
  }
27
-
28
21
  function _mainRuntimeFile() {
29
22
  const data = require("./files/main-runtime-file");
30
-
31
23
  _mainRuntimeFile = function () {
32
24
  return data;
33
25
  };
34
-
35
26
  return data;
36
27
  }
37
-
38
28
  function _compilerFile() {
39
29
  const data = require("./files/compiler-file");
40
-
41
30
  _compilerFile = function () {
42
31
  return data;
43
32
  };
44
-
45
33
  return data;
46
34
  }
47
-
48
35
  const compilerTemplate = {
49
36
  name: 'compiler',
50
37
  description: 'A compiler implementation',
@@ -1 +1 @@
1
- {"version":3,"names":["compilerTemplate","name","description","hidden","generateFiles","context","relativePath","content","indexFile","isMain","aspectFile","compilerFile","mainRuntimeFile"],"sources":["index.ts"],"sourcesContent":["import { ComponentContext, ComponentTemplate } from '@teambit/generator';\nimport { indexFile } from './files/index-file';\nimport { aspectFile } from './files/aspect-file';\nimport { mainRuntimeFile } from './files/main-runtime-file';\nimport { compilerFile } from './files/compiler-file';\n\nexport const compilerTemplate: ComponentTemplate = {\n name: 'compiler',\n description: 'A compiler implementation',\n hidden: true,\n generateFiles: (context: ComponentContext) => {\n return [\n {\n relativePath: 'index.ts',\n content: indexFile(context),\n isMain: true,\n },\n {\n relativePath: `${context.name}.aspect.ts`,\n content: aspectFile(context),\n },\n {\n relativePath: `${context.name}.compiler.ts`,\n content: compilerFile(context),\n },\n {\n relativePath: `${context.name}.main.runtime.ts`,\n content: mainRuntimeFile(context),\n },\n ];\n },\n};\n"],"mappings":";;;;;;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEO,MAAMA,gBAAmC,GAAG;EACjDC,IAAI,EAAE,UAD2C;EAEjDC,WAAW,EAAE,2BAFoC;EAGjDC,MAAM,EAAE,IAHyC;EAIjDC,aAAa,EAAGC,OAAD,IAA+B;IAC5C,OAAO,CACL;MACEC,YAAY,EAAE,UADhB;MAEEC,OAAO,EAAE,IAAAC,sBAAA,EAAUH,OAAV,CAFX;MAGEI,MAAM,EAAE;IAHV,CADK,EAML;MACEH,YAAY,EAAG,GAAED,OAAO,CAACJ,IAAK,YADhC;MAEEM,OAAO,EAAE,IAAAG,wBAAA,EAAWL,OAAX;IAFX,CANK,EAUL;MACEC,YAAY,EAAG,GAAED,OAAO,CAACJ,IAAK,cADhC;MAEEM,OAAO,EAAE,IAAAI,4BAAA,EAAaN,OAAb;IAFX,CAVK,EAcL;MACEC,YAAY,EAAG,GAAED,OAAO,CAACJ,IAAK,kBADhC;MAEEM,OAAO,EAAE,IAAAK,kCAAA,EAAgBP,OAAhB;IAFX,CAdK,CAAP;EAmBD;AAxBgD,CAA5C"}
1
+ {"version":3,"names":["compilerTemplate","name","description","hidden","generateFiles","context","relativePath","content","indexFile","isMain","aspectFile","compilerFile","mainRuntimeFile"],"sources":["index.ts"],"sourcesContent":["import { ComponentContext, ComponentTemplate } from '@teambit/generator';\nimport { indexFile } from './files/index-file';\nimport { aspectFile } from './files/aspect-file';\nimport { mainRuntimeFile } from './files/main-runtime-file';\nimport { compilerFile } from './files/compiler-file';\n\nexport const compilerTemplate: ComponentTemplate = {\n name: 'compiler',\n description: 'A compiler implementation',\n hidden: true,\n generateFiles: (context: ComponentContext) => {\n return [\n {\n relativePath: 'index.ts',\n content: indexFile(context),\n isMain: true,\n },\n {\n relativePath: `${context.name}.aspect.ts`,\n content: aspectFile(context),\n },\n {\n relativePath: `${context.name}.compiler.ts`,\n content: compilerFile(context),\n },\n {\n relativePath: `${context.name}.main.runtime.ts`,\n content: mainRuntimeFile(context),\n },\n ];\n },\n};\n"],"mappings":";;;;;;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,MAAMA,gBAAmC,GAAG;EACjDC,IAAI,EAAE,UAAU;EAChBC,WAAW,EAAE,2BAA2B;EACxCC,MAAM,EAAE,IAAI;EACZC,aAAa,EAAGC,OAAyB,IAAK;IAC5C,OAAO,CACL;MACEC,YAAY,EAAE,UAAU;MACxBC,OAAO,EAAE,IAAAC,sBAAS,EAACH,OAAO,CAAC;MAC3BI,MAAM,EAAE;IACV,CAAC,EACD;MACEH,YAAY,EAAG,GAAED,OAAO,CAACJ,IAAK,YAAW;MACzCM,OAAO,EAAE,IAAAG,wBAAU,EAACL,OAAO;IAC7B,CAAC,EACD;MACEC,YAAY,EAAG,GAAED,OAAO,CAACJ,IAAK,cAAa;MAC3CM,OAAO,EAAE,IAAAI,4BAAY,EAACN,OAAO;IAC/B,CAAC,EACD;MACEC,YAAY,EAAG,GAAED,OAAO,CAACJ,IAAK,kBAAiB;MAC/CM,OAAO,EAAE,IAAAK,kCAAe,EAACP,OAAO;IAClC,CAAC,CACF;EACH;AACF,CAAC;AAAC"}
package/dist/types.js CHANGED
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.CompilationInitiator = void 0;
7
7
  let CompilationInitiator;
8
8
  exports.CompilationInitiator = CompilationInitiator;
9
-
10
9
  (function (CompilationInitiator) {
11
10
  CompilationInitiator[CompilationInitiator["CmdReport"] = 0] = "CmdReport";
12
11
  CompilationInitiator[CompilationInitiator["CmdJson"] = 1] = "CmdJson";
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["CompilationInitiator"],"sources":["types.ts"],"sourcesContent":["import { BuildContext, BuildTask, BuiltTaskResult, TaskResultsList } from '@teambit/builder';\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 Install,\n}\n\nexport type TranspileComponentParams = {\n component: Component;\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 * Delete dist folder before writing the new compiled files\n */\n deleteDistDir?: boolean;\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 * return the dist dir of the compiled files (relative path from the component root dir)\n */\n getDistDir?(): string;\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"],"mappings":";;;;;;IAQYA,oB;;;WAAAA,oB;EAAAA,oB,CAAAA,oB;EAAAA,oB,CAAAA,oB;EAAAA,oB,CAAAA,oB;EAAAA,oB,CAAAA,oB;EAAAA,oB,CAAAA,oB;EAAAA,oB,CAAAA,oB;EAAAA,oB,CAAAA,oB;EAAAA,oB,CAAAA,oB;EAAAA,oB,CAAAA,oB;GAAAA,oB,oCAAAA,oB"}
1
+ {"version":3,"names":["CompilationInitiator"],"sources":["types.ts"],"sourcesContent":["import { BuildContext, BuildTask, BuiltTaskResult, TaskResultsList } from '@teambit/builder';\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 Install,\n}\n\nexport type TranspileComponentParams = {\n component: Component;\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 * Delete dist folder before writing the new compiled files\n */\n deleteDistDir?: boolean;\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 * return the dist dir of the compiled files (relative path from the component root dir)\n */\n getDistDir?(): string;\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"],"mappings":";;;;;;IAQYA,oBAAoB;AAAA;AAAA,WAApBA,oBAAoB;EAApBA,oBAAoB,CAApBA,oBAAoB;EAApBA,oBAAoB,CAApBA,oBAAoB;EAApBA,oBAAoB,CAApBA,oBAAoB;EAApBA,oBAAoB,CAApBA,oBAAoB;EAApBA,oBAAoB,CAApBA,oBAAoB;EAApBA,oBAAoB,CAApBA,oBAAoB;EAApBA,oBAAoB,CAApBA,oBAAoB;EAApBA,oBAAoB,CAApBA,oBAAoB;EAApBA,oBAAoB,CAApBA,oBAAoB;AAAA,GAApBA,oBAAoB,oCAApBA,oBAAoB"}
@@ -1,137 +1,98 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  require("core-js/modules/es.array.iterator.js");
6
-
7
5
  require("core-js/modules/es.promise.js");
8
-
9
6
  Object.defineProperty(exports, "__esModule", {
10
7
  value: true
11
8
  });
12
9
  exports.WorkspaceCompiler = exports.ComponentCompiler = void 0;
13
-
14
10
  function _pMapSeries() {
15
11
  const data = _interopRequireDefault(require("p-map-series"));
16
-
17
12
  _pMapSeries = function () {
18
13
  return data;
19
14
  };
20
-
21
15
  return data;
22
16
  }
23
-
24
17
  function _path() {
25
18
  const data = _interopRequireDefault(require("path"));
26
-
27
19
  _path = function () {
28
20
  return data;
29
21
  };
30
-
31
22
  return data;
32
23
  }
33
-
34
24
  function _loader() {
35
25
  const data = _interopRequireDefault(require("@teambit/legacy/dist/cli/loader"));
36
-
37
26
  _loader = function () {
38
27
  return data;
39
28
  };
40
-
41
29
  return data;
42
30
  }
43
-
44
31
  function _constants() {
45
32
  const data = require("@teambit/legacy/dist/constants");
46
-
47
33
  _constants = function () {
48
34
  return data;
49
35
  };
50
-
51
36
  return data;
52
37
  }
53
-
54
38
  function _sources() {
55
39
  const data = require("@teambit/legacy/dist/consumer/component/sources");
56
-
57
40
  _sources = function () {
58
41
  return data;
59
42
  };
60
-
61
43
  return data;
62
44
  }
63
-
64
45
  function _dataToPersist() {
65
46
  const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/component/sources/data-to-persist"));
66
-
67
47
  _dataToPersist = function () {
68
48
  return data;
69
49
  };
70
-
71
50
  return data;
72
51
  }
73
-
74
52
  function _exceptions() {
75
53
  const data = require("@teambit/legacy/dist/consumer/exceptions");
76
-
77
54
  _exceptions = function () {
78
55
  return data;
79
56
  };
80
-
81
57
  return data;
82
58
  }
83
-
84
59
  function _componentIdToPackageName() {
85
60
  const data = _interopRequireDefault(require("@teambit/legacy/dist/utils/bit/component-id-to-package-name"));
86
-
87
61
  _componentIdToPackageName = function () {
88
62
  return data;
89
63
  };
90
-
91
64
  return data;
92
65
  }
93
-
94
66
  function _removePath() {
95
67
  const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/component/sources/remove-path"));
96
-
97
68
  _removePath = function () {
98
69
  return data;
99
70
  };
100
-
101
71
  return data;
102
72
  }
103
-
104
73
  function _compiler() {
105
74
  const data = require("./compiler.aspect");
106
-
107
75
  _compiler = function () {
108
76
  return data;
109
77
  };
110
-
111
78
  return data;
112
79
  }
113
-
114
80
  function _events() {
115
81
  const data = require("./events");
116
-
117
82
  _events = function () {
118
83
  return data;
119
84
  };
120
-
121
85
  return data;
122
86
  }
123
-
124
87
  function _types() {
125
88
  const data = require("./types");
126
-
127
89
  _types = function () {
128
90
  return data;
129
91
  };
130
-
131
92
  return data;
132
93
  }
133
-
134
94
  /* eslint-disable max-classes-per-file */
95
+
135
96
  class ComponentCompiler {
136
97
  constructor(pubsub, workspace, component, compilerInstance, compilerId, logger, dependencyResolver, dists = [], compileErrors = []) {
137
98
  this.pubsub = pubsub;
@@ -144,43 +105,35 @@ class ComponentCompiler {
144
105
  this.dists = dists;
145
106
  this.compileErrors = compileErrors;
146
107
  }
147
-
148
108
  async compile(noThrow = true, options) {
149
109
  var _options$deleteDistDi;
150
-
151
110
  let dataToPersist;
152
- const deleteDistDir = (_options$deleteDistDi = options.deleteDistDir) !== null && _options$deleteDistDi !== void 0 ? _options$deleteDistDi : this.compilerInstance.deleteDistDir; // delete dist folder before transpilation (because some compilers (like ngPackagr) can generate files there during the compilation process)
153
-
111
+ const deleteDistDir = (_options$deleteDistDi = options.deleteDistDir) !== null && _options$deleteDistDi !== void 0 ? _options$deleteDistDi : this.compilerInstance.deleteDistDir;
112
+ // delete dist folder before transpilation (because some compilers (like ngPackagr) can generate files there during the compilation process)
154
113
  if (deleteDistDir) {
155
114
  dataToPersist = new (_dataToPersist().default)();
156
-
157
115
  for (const distDir of await this.distDirs()) {
158
116
  dataToPersist.removePath(new (_removePath().default)(distDir));
159
117
  }
160
-
161
118
  dataToPersist.addBasePath(this.workspace.path);
162
119
  await dataToPersist.persistAllToFS();
163
120
  }
164
-
165
121
  const compilers = this.compilerInstance.compilers ? this.compilerInstance.compilers : [this.compilerInstance];
166
122
  const canTranspileFile = compilers.find(c => c.transpileFile);
167
123
  const canTranspileComponent = compilers.find(c => c.transpileComponent);
168
-
169
124
  if (canTranspileFile) {
170
125
  await Promise.all(this.component.filesystem.files.map(file => this.compileOneFile(file, options.initiator)));
171
126
  }
172
-
173
127
  if (canTranspileComponent) {
174
128
  await this.compileAllFiles(this.component, options.initiator);
175
129
  }
176
-
177
130
  if (!canTranspileFile && !canTranspileComponent) {
178
131
  throw new Error(`compiler ${this.compilerId.toString()} doesn't implement either "transpileFile" or "transpileComponent" methods`);
179
132
  }
133
+ this.throwOnCompileErrors(noThrow);
180
134
 
181
- this.throwOnCompileErrors(noThrow); // writing the dists with `component.setDists(dists); component.dists.writeDists` is tricky
135
+ // writing the dists with `component.setDists(dists); component.dists.writeDists` is tricky
182
136
  // as it uses other base-paths and doesn't respect the new node-modules base path.
183
-
184
137
  dataToPersist = new (_dataToPersist().default)();
185
138
  dataToPersist.addManyFiles(this.dists);
186
139
  dataToPersist.addBasePath(this.workspace.path);
@@ -193,51 +146,38 @@ class ComponentCompiler {
193
146
  buildResults
194
147
  };
195
148
  }
196
-
197
149
  throwOnCompileErrors(noThrow = true) {
198
150
  if (this.compileErrors.length) {
199
151
  this.compileErrors.forEach(errorItem => {
200
152
  this.logger.error(`compilation error at ${errorItem.path}`, errorItem.error);
201
153
  });
202
-
203
154
  const formatError = errorItem => `${errorItem.path}\n${errorItem.error}`;
204
-
205
155
  const err = new Error(`compilation failed. see the following errors from the compiler
206
156
  ${this.compileErrors.map(formatError).join('\n')}`);
207
157
  this.pubsub.pub(_compiler().CompilerAspect.id, new (_events().CompilerErrorEvent)(err));
208
-
209
158
  if (!noThrow) {
210
159
  throw err;
211
160
  }
212
-
213
161
  this.logger.console(err.message);
214
162
  }
215
163
  }
216
-
217
164
  async distDirs() {
218
165
  var _this$compilerInstanc, _this$compilerInstanc2;
219
-
220
166
  const packageName = (0, _componentIdToPackageName().default)(this.component.state._consumer);
221
-
222
167
  const packageDir = _path().default.join('node_modules', packageName);
223
-
224
168
  const distDirName = ((_this$compilerInstanc = (_this$compilerInstanc2 = this.compilerInstance).getDistDir) === null || _this$compilerInstanc === void 0 ? void 0 : _this$compilerInstanc.call(_this$compilerInstanc2)) || _constants().DEFAULT_DIST_DIRNAME;
225
-
226
169
  const injectedDirs = await this.getInjectedDirs(packageName);
227
170
  return [packageDir, ...injectedDirs].map(dist => _path().default.join(dist, distDirName));
228
171
  }
229
-
230
172
  async getInjectedDirs(packageName) {
231
173
  const relativeCompDir = this.workspace.componentDir(this.component.id, undefined, {
232
174
  relative: true
233
175
  });
234
176
  return this.dependencyResolver.getInjectedDirs(this.workspace.path, relativeCompDir, packageName);
235
177
  }
236
-
237
178
  get componentDir() {
238
179
  return this.workspace.componentDir(this.component.id);
239
180
  }
240
-
241
181
  async compileOneFile(file, initiator) {
242
182
  const options = {
243
183
  componentDir: this.componentDir,
@@ -246,11 +186,9 @@ ${this.compileErrors.map(formatError).join('\n')}`);
246
186
  };
247
187
  const isFileSupported = this.compilerInstance.isFileSupported(file.path);
248
188
  let compileResults;
249
-
250
189
  if (isFileSupported) {
251
190
  try {
252
191
  var _this$compilerInstanc3, _this$compilerInstanc4;
253
-
254
192
  compileResults = (_this$compilerInstanc3 = (_this$compilerInstanc4 = this.compilerInstance).transpileFile) === null || _this$compilerInstanc3 === void 0 ? void 0 : _this$compilerInstanc3.call(_this$compilerInstanc4, file.contents.toString(), options);
255
193
  } catch (error) {
256
194
  this.compileErrors.push({
@@ -260,7 +198,6 @@ ${this.compileErrors.map(formatError).join('\n')}`);
260
198
  return;
261
199
  }
262
200
  }
263
-
264
201
  for (const base of await this.distDirs()) {
265
202
  if (isFileSupported && compileResults) {
266
203
  this.dists.push(...compileResults.map(result => new (_sources().Dist)({
@@ -278,14 +215,11 @@ ${this.compileErrors.map(formatError).join('\n')}`);
278
215
  }
279
216
  }
280
217
  }
281
-
282
218
  async compileAllFiles(component, initiator) {
283
219
  const filesToCompile = [];
284
-
285
220
  for (const base of await this.distDirs()) {
286
221
  component.filesystem.files.forEach(file => {
287
222
  const isFileSupported = this.compilerInstance.isFileSupported(file.path);
288
-
289
223
  if (isFileSupported) {
290
224
  filesToCompile.push(file);
291
225
  } else if (this.compilerInstance.shouldCopyNonSupportedFiles) {
@@ -298,11 +232,9 @@ ${this.compileErrors.map(formatError).join('\n')}`);
298
232
  }
299
233
  });
300
234
  }
301
-
302
235
  if (filesToCompile.length) {
303
236
  try {
304
237
  var _this$compilerInstanc5, _this$compilerInstanc6;
305
-
306
238
  await ((_this$compilerInstanc5 = (_this$compilerInstanc6 = this.compilerInstance).transpileComponent) === null || _this$compilerInstanc5 === void 0 ? void 0 : _this$compilerInstanc5.call(_this$compilerInstanc6, {
307
239
  component,
308
240
  componentDir: this.componentDir,
@@ -317,11 +249,8 @@ ${this.compileErrors.map(formatError).join('\n')}`);
317
249
  }
318
250
  }
319
251
  }
320
-
321
252
  }
322
-
323
253
  exports.ComponentCompiler = ComponentCompiler;
324
-
325
254
  class WorkspaceCompiler {
326
255
  constructor(workspace, envs, pubsub, aspectLoader, ui, logger, dependencyResolver) {
327
256
  this.workspace = workspace;
@@ -331,24 +260,20 @@ class WorkspaceCompiler {
331
260
  this.ui = ui;
332
261
  this.logger = logger;
333
262
  this.dependencyResolver = dependencyResolver;
334
-
335
263
  if (this.workspace) {
336
264
  this.workspace.registerOnComponentChange(this.onComponentChange.bind(this));
337
265
  this.workspace.registerOnComponentAdd(this.onComponentChange.bind(this));
338
266
  this.workspace.registerOnPreWatch(this.onPreWatch.bind(this));
339
267
  this.ui.registerPreStart(this.onPreStart.bind(this));
340
268
  }
341
-
342
269
  if (this.aspectLoader) {
343
270
  this.aspectLoader.registerOnAspectLoadErrorSlot(this.onAspectLoadFail.bind(this));
344
271
  }
345
272
  }
346
-
347
273
  async onPreStart(preStartOpts) {
348
274
  if (preStartOpts.skipCompilation) {
349
275
  return;
350
276
  }
351
-
352
277
  await this.compileComponents([], {
353
278
  changed: true,
354
279
  verbose: false,
@@ -356,7 +281,6 @@ class WorkspaceCompiler {
356
281
  initiator: _types().CompilationInitiator.PreStart
357
282
  });
358
283
  }
359
-
360
284
  async onAspectLoadFail(err, id) {
361
285
  if (err.code && err.code === 'MODULE_NOT_FOUND' && this.workspace) {
362
286
  await this.compileComponents([id.toString()], {
@@ -364,26 +288,20 @@ class WorkspaceCompiler {
364
288
  }, true);
365
289
  return true;
366
290
  }
367
-
368
291
  return false;
369
292
  }
370
-
371
293
  async onComponentChange(component, files, initiator) {
372
294
  const buildResults = await this.compileComponents([component.id.toString()], {
373
295
  initiator: initiator || _types().CompilationInitiator.ComponentChanged
374
296
  }, true);
375
297
  return {
376
298
  results: buildResults,
377
-
378
299
  toString() {
379
300
  var _buildResults$, _buildResults$$buildR;
380
-
381
301
  return `${(_buildResults$ = buildResults[0]) === null || _buildResults$ === void 0 ? void 0 : (_buildResults$$buildR = _buildResults$.buildResults) === null || _buildResults$$buildR === void 0 ? void 0 : _buildResults$$buildR.join('\n\t')}`;
382
302
  }
383
-
384
303
  };
385
304
  }
386
-
387
305
  async onPreWatch(components, watchOpts) {
388
306
  if (watchOpts.preCompile) {
389
307
  const start = Date.now();
@@ -395,8 +313,8 @@ class WorkspaceCompiler {
395
313
  this.logger.consoleSuccess(`compiled ${components.length} components successfully (${end / 1000} sec)`);
396
314
  }
397
315
  }
398
-
399
- async compileComponents(componentsIds, // when empty, it compiles new+modified (unless options.all is set),
316
+ async compileComponents(componentsIds,
317
+ // when empty, it compiles new+modified (unless options.all is set),
400
318
  options, noThrow) {
401
319
  if (!this.workspace) throw new (_exceptions().ConsumerNotFound)();
402
320
  const componentIds = await this.getIdsToCompile(componentsIds, options.changed);
@@ -404,11 +322,10 @@ class WorkspaceCompiler {
404
322
  const componentsCompilers = [];
405
323
  components.forEach(c => {
406
324
  var _environment$getCompi, _c$state$_consumer$co;
407
-
408
325
  const environment = this.envs.getEnv(c).env;
409
- const compilerInstance = (_environment$getCompi = environment.getCompiler) === null || _environment$getCompi === void 0 ? void 0 : _environment$getCompi.call(environment); // if there is no componentDir (e.g. author that added files, not dir), then we can't write the dists
326
+ const compilerInstance = (_environment$getCompi = environment.getCompiler) === null || _environment$getCompi === void 0 ? void 0 : _environment$getCompi.call(environment);
327
+ // if there is no componentDir (e.g. author that added files, not dir), then we can't write the dists
410
328
  // inside the component dir.
411
-
412
329
  if (compilerInstance && (_c$state$_consumer$co = c.state._consumer.componentMap) !== null && _c$state$_consumer$co !== void 0 && _c$state$_consumer$co.getComponentDir()) {
413
330
  const compilerName = compilerInstance.constructor.name || 'compiler';
414
331
  componentsCompilers.push(new ComponentCompiler(this.pubsub, this.workspace, c, compilerInstance, compilerName, this.logger, this.dependencyResolver));
@@ -417,21 +334,16 @@ class WorkspaceCompiler {
417
334
  const resultOnWorkspace = await (0, _pMapSeries().default)(componentsCompilers, componentCompiler => componentCompiler.compile(noThrow, options));
418
335
  return resultOnWorkspace;
419
336
  }
420
-
421
337
  async getIdsToCompile(componentsIds, changed = false) {
422
338
  if (componentsIds.length) {
423
339
  return this.workspace.resolveMultipleComponentIds(componentsIds);
424
340
  }
425
-
426
341
  if (changed) {
427
342
  return this.workspace.getNewAndModifiedIds();
428
343
  }
429
-
430
344
  return this.workspace.getAllComponentIds();
431
345
  }
432
-
433
346
  }
434
-
435
347
  exports.WorkspaceCompiler = WorkspaceCompiler;
436
348
 
437
349
  //# sourceMappingURL=workspace-compiler.js.map