@teambit/compiler 0.0.653 → 0.0.656
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/{__preview-1645393132004.js → __preview-1645673006381.js} +1 -1
- package/dist/compiler.cmd.d.ts +5 -6
- package/dist/compiler.cmd.js +1 -1
- package/dist/compiler.cmd.js.map +1 -1
- package/dist/events/component-compilation-on-done.d.ts +5 -5
- package/dist/events/component-compilation-on-done.js.map +1 -1
- package/dist/output-formatter.d.ts +2 -1
- package/dist/output-formatter.js +1 -1
- package/dist/output-formatter.js.map +1 -1
- package/dist/types.d.ts +1 -2
- package/dist/types.js.map +1 -1
- package/dist/workspace-compiler.d.ts +3 -4
- package/dist/workspace-compiler.js +23 -25
- package/dist/workspace-compiler.js.map +1 -1
- package/events/component-compilation-on-done.ts +3 -7
- package/package-tar/teambit-compiler-0.0.656.tgz +0 -0
- package/package.json +16 -15
- package/package-tar/teambit-compiler-0.0.653.tgz +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.compilation_compiler@0.0.
|
|
1
|
+
export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.compilation_compiler@0.0.656/dist/compiler.docs.mdx')]
|
package/dist/compiler.cmd.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { Command, CommandOptions } from '@teambit/cli';
|
|
2
2
|
import { Logger } from '@teambit/logger';
|
|
3
3
|
import type { PubsubMain } from '@teambit/pubsub';
|
|
4
|
-
import
|
|
4
|
+
import { Component } from '@teambit/component';
|
|
5
5
|
import { CompileError, WorkspaceCompiler, CompileOptions } from './workspace-compiler';
|
|
6
|
-
declare type ComponentsStatus = {
|
|
6
|
+
export declare type ComponentsStatus = {
|
|
7
7
|
buildResults: string[];
|
|
8
|
-
component:
|
|
9
|
-
errors:
|
|
8
|
+
component: Component;
|
|
9
|
+
errors: CompileError[];
|
|
10
10
|
};
|
|
11
11
|
export declare class CompileCmd implements Command {
|
|
12
12
|
private compile;
|
|
13
13
|
private logger;
|
|
14
14
|
private pubsub;
|
|
15
|
-
componentsStatus:
|
|
15
|
+
componentsStatus: ComponentsStatus[];
|
|
16
16
|
name: string;
|
|
17
17
|
description: string;
|
|
18
18
|
alias: string;
|
|
@@ -33,4 +33,3 @@ export declare class CompileCmd implements Command {
|
|
|
33
33
|
private getStatusLine;
|
|
34
34
|
private onComponentCompilationDone;
|
|
35
35
|
}
|
|
36
|
-
export {};
|
package/dist/compiler.cmd.js
CHANGED
|
@@ -109,7 +109,7 @@ class CompileCmd {
|
|
|
109
109
|
const compileTimeLength = process.hrtime(startTimestamp);
|
|
110
110
|
outputString += '\n';
|
|
111
111
|
outputString += ` ${_chalk().default.underline('STATUS')}\t${_chalk().default.underline('COMPONENT ID')}\n`;
|
|
112
|
-
outputString += (0, _outputFormatter().formatCompileResults)(this.componentsStatus, compilerOptions.verbose);
|
|
112
|
+
outputString += (0, _outputFormatter().formatCompileResults)(this.componentsStatus, !!compilerOptions.verbose);
|
|
113
113
|
outputString += '\n';
|
|
114
114
|
outputString += this.getStatusLine(this.componentsStatus, compileTimeLength);
|
|
115
115
|
this.logger.clearStatusLine();
|
package/dist/compiler.cmd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["compiler.cmd.ts"],"names":["CompileCmd","constructor","compile","logger","pubsub","report","components","compilerOptions","startTimestamp","process","hrtime","setStatusLine","sub","CompilerAspect","id","onComponentCompilationDone","bind","outputString","compileComponents","initiator","CompilationInitiator","CmdReport","compileTimeLength","chalk","underline","componentsStatus","verbose","getStatusLine","clearStatusLine","data","code","getExitCode","json","deleteDistDir","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;AAazCC,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,
|
|
1
|
+
{"version":3,"sources":["compiler.cmd.ts"],"names":["CompileCmd","constructor","compile","logger","pubsub","report","components","compilerOptions","startTimestamp","process","hrtime","setStatusLine","sub","CompilerAspect","id","onComponentCompilationDone","bind","outputString","compileComponents","initiator","CompilationInitiator","CmdReport","compileTimeLength","chalk","underline","componentsStatus","verbose","getStatusLine","clearStatusLine","data","code","getExitCode","json","deleteDistDir","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;A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Ob,EAAAA,WAAW,CAACN,gBAAD,EAAuC;AACxD,WAAO,KAAKW,gBAAL,CAAsBX,gBAAtB,EAAwCe,MAAxC,GAAiD,CAAjD,GAAqD,CAA5D;AACD;;AAEOb,EAAAA,aAAa,CAACF,gBAAD,EAAuCH,iBAAvC,EAA0D;AAC7E,UAAMuB,kBAAkB,GAAGpB,gBAAgB,CAACe,MAA5C;AACA,UAAMM,yBAAyB,GAAG,KAAKV,gBAAL,CAAsBX,gBAAtB,EAAwCe,MAA1E;AACA,UAAMO,4BAA4B,GAAGtB,gBAAgB,CAACY,MAAjB,CAAyBC,SAAD,IAAe,CAACA,SAAS,CAACC,MAAV,CAAiBC,MAAzD,EAAiEA,MAAtG;AAEA,UAAMQ,IAAI,GAAG,KAAKP,cAAL,CAAoBhB,gBAApB,CAAb;AACA,UAAMwB,WAAW,GAAGH,yBAAyB,GACxC,GAAEE,IAAK,IAAGF,yBAA0B,IAAGD,kBAAmB,gCADlB,GAExC,GAAEG,IAAK,IAAGD,4BAA6B,IAAGF,kBAAmB,oCAFlE;AAIA,WAAQ,GAAEI,WAAY,gBAAe,2BAAW3B,iBAAX,CAA8B,GAAnE;AACD;;AAEOP,EAAAA,0BAA0B,CAACmC,KAAD,EAA2B;AAC3D,QAAIA,KAAK,CAACC,IAAN,KAAeC,0CAAgCC,IAAnD,EAAyD;AACvD,WAAK5B,gBAAL,CAAsB6B,IAAtB,CAA2BJ,KAAK,CAACrB,IAAjC;AACD;AACF;;AA5FwC","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 { Component } from '@teambit/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\nexport type ComponentsStatus = {\n buildResults: string[];\n component: Component;\n errors: CompileError[];\n};\n\nexport class CompileCmd implements Command {\n componentsStatus: 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 ['d', 'delete-dist-dir', 'delete existing dist folder before writing new compiled files'],\n ] as CommandOptions;\n\n constructor(private compile: WorkspaceCompiler, private logger: Logger, private pubsub: PubsubMain) {}\n\n async report([components = []]: [string[]], compilerOptions: CompileOptions) {\n const startTimestamp = process.hrtime();\n this.logger.setStatusLine('Compiling your components, hold tight.');\n this.pubsub.sub(CompilerAspect.id, this.onComponentCompilationDone.bind(this));\n\n let outputString = '';\n await this.compile.compileComponents(components, {\n ...compilerOptions,\n initiator: CompilationInitiator.CmdReport,\n });\n const compileTimeLength = process.hrtime(startTimestamp);\n\n outputString += '\\n';\n outputString += ` ${chalk.underline('STATUS')}\\t${chalk.underline('COMPONENT ID')}\\n`;\n outputString += formatCompileResults(this.componentsStatus, !!compilerOptions.verbose);\n outputString += '\\n';\n\n outputString += this.getStatusLine(this.componentsStatus, compileTimeLength);\n\n this.logger.clearStatusLine();\n\n return {\n data: outputString,\n code: this.getExitCode(this.componentsStatus),\n };\n }\n\n async json([components]: [string[]], compilerOptions: CompileOptions) {\n compilerOptions.deleteDistDir = true;\n // @ts-ignore\n const compileResults = await this.compile.compileComponents(components, {\n ...compilerOptions,\n initiator: CompilationInitiator.CmdJson,\n });\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,18 +1,18 @@
|
|
|
1
1
|
import { BitBaseEvent } from '@teambit/pubsub';
|
|
2
|
-
import
|
|
2
|
+
import { Component } from '@teambit/component';
|
|
3
3
|
import { CompileError } from '../workspace-compiler';
|
|
4
4
|
declare class ComponentCompilationOnDoneEventData {
|
|
5
5
|
readonly errors: Array<CompileError>;
|
|
6
|
-
readonly component:
|
|
6
|
+
readonly component: Component;
|
|
7
7
|
readonly buildResults: string[];
|
|
8
|
-
constructor(errors: Array<CompileError>, component:
|
|
8
|
+
constructor(errors: Array<CompileError>, component: Component, buildResults: string[]);
|
|
9
9
|
}
|
|
10
10
|
export declare class ComponentCompilationOnDoneEvent extends BitBaseEvent<ComponentCompilationOnDoneEventData> {
|
|
11
11
|
readonly errors: Array<CompileError>;
|
|
12
|
-
readonly component:
|
|
12
|
+
readonly component: Component;
|
|
13
13
|
readonly buildResults: string[];
|
|
14
14
|
readonly timestamp: number;
|
|
15
15
|
static readonly TYPE = "component-compilation-on-done";
|
|
16
|
-
constructor(errors: Array<CompileError>, component:
|
|
16
|
+
constructor(errors: Array<CompileError>, component: Component, buildResults: string[], timestamp?: number);
|
|
17
17
|
}
|
|
18
18
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["component-compilation-on-done.ts"],"names":["ComponentCompilationOnDoneEventData","constructor","errors","component","buildResults","ComponentCompilationOnDoneEvent","BitBaseEvent","timestamp","Date","now","TYPE"],"mappings":";;;;;;;;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AADA;AAKA,MAAMA,mCAAN,CAA0C;AACxCC,EAAAA,WAAW,
|
|
1
|
+
{"version":3,"sources":["component-compilation-on-done.ts"],"names":["ComponentCompilationOnDoneEventData","constructor","errors","component","buildResults","ComponentCompilationOnDoneEvent","BitBaseEvent","timestamp","Date","now","TYPE"],"mappings":";;;;;;;;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AADA;AAKA,MAAMA,mCAAN,CAA0C;AACxCC,EAAAA,WAAW,CAAUC,MAAV,EAAgDC,SAAhD,EAA+EC,YAA/E,EAAuG;AAAA,SAA7FF,MAA6F,GAA7FA,MAA6F;AAAA,SAAvDC,SAAuD,GAAvDA,SAAuD;AAAA,SAAxBC,YAAwB,GAAxBA,YAAwB;AAAE;;AAD5E;;AAInC,MAAMC,+BAAN,SAA8CC,sBAA9C,CAAgG;AAGrGL,EAAAA,WAAW,CACAC,MADA,EAEAC,SAFA,EAGAC,YAHA,EAIAG,SAAS,GAAGC,IAAI,CAACC,GAAL,EAJZ,EAKT;AACA,UACEJ,+BAA+B,CAACK,IADlC,EAEE,OAFF,EAGEH,SAHF,EAIE,IAAIP,mCAAJ,CAAwCE,MAAxC,EAAgDC,SAAhD,EAA2DC,YAA3D,CAJF;AADA,SAJSF,MAIT,GAJSA,MAIT;AAAA,SAHSC,SAGT,GAHSA,SAGT;AAAA,SAFSC,YAET,GAFSA,YAET;AAAA,SADSG,SACT,GADSA,SACT;AAOD;;AAfoG;;;gCAA1FF,+B,UACY,+B","sourcesContent":["/* eslint-disable max-classes-per-file */\nimport { BitBaseEvent } from '@teambit/pubsub';\nimport { Component } from '@teambit/component';\nimport { CompileError } from '../workspace-compiler';\n\nclass ComponentCompilationOnDoneEventData {\n constructor(readonly errors: Array<CompileError>, readonly component: Component, readonly buildResults: string[]) {}\n}\n\nexport class ComponentCompilationOnDoneEvent extends BitBaseEvent<ComponentCompilationOnDoneEventData> {\n static readonly TYPE = 'component-compilation-on-done';\n\n constructor(\n readonly errors: Array<CompileError>,\n readonly component: Component,\n readonly buildResults: string[],\n readonly timestamp = Date.now()\n ) {\n super(\n ComponentCompilationOnDoneEvent.TYPE,\n '0.0.1',\n timestamp,\n new ComponentCompilationOnDoneEventData(errors, component, buildResults)\n );\n }\n}\n"]}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { ComponentsStatus } from './compiler.cmd';
|
|
2
|
+
export declare const formatCompileResults: (compileResults: ComponentsStatus[], verbose: boolean) => string;
|
package/dist/output-formatter.js
CHANGED
|
@@ -18,7 +18,7 @@ function _chalk() {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
const formatCompileResults = (compileResults, verbose) => compileResults.map(componentResult => ({
|
|
21
|
-
componentId: componentResult.component.
|
|
21
|
+
componentId: componentResult.component.id.fullName,
|
|
22
22
|
files: componentResult.buildResults,
|
|
23
23
|
status: componentResult.errors.length ? 'FAILURE' : 'SUCCESS',
|
|
24
24
|
icon: componentResult.errors.length ? _chalk().default.red('✗') : _chalk().default.green('✔')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["output-formatter.ts"],"names":["formatCompileResults","compileResults","verbose","map","componentResult","componentId","component","
|
|
1
|
+
{"version":3,"sources":["output-formatter.ts"],"names":["formatCompileResults","compileResults","verbose","map","componentResult","componentId","component","id","fullName","files","buildResults","status","errors","length","icon","chalk","red","green","reduce","outputString","result","fileList","file"],"mappings":";;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGO,MAAMA,oBAAoB,GAAG,CAACC,cAAD,EAAqCC,OAArC,KAClCD,cAAc,CACXE,GADH,CACQC,eAAD,KAAwC;AAC3CC,EAAAA,WAAW,EAAED,eAAe,CAACE,SAAhB,CAA0BC,EAA1B,CAA6BC,QADC;AAE3CC,EAAAA,KAAK,EAAEL,eAAe,CAACM,YAFoB;AAG3CC,EAAAA,MAAM,EAAEP,eAAe,CAACQ,MAAhB,CAAuBC,MAAvB,GAAgC,SAAhC,GAA4C,SAHT;AAI3CC,EAAAA,IAAI,EAAEV,eAAe,CAACQ,MAAhB,CAAuBC,MAAvB,GAAgCE,iBAAMC,GAAN,CAAU,GAAV,CAAhC,GAAiDD,iBAAME,KAAN,CAAY,GAAZ;AAJZ,CAAxC,CADP,EAOGC,MAPH,CAOU,CAACC,YAAD,EAAeC,MAAf,KAA0B;AAChCD,EAAAA,YAAY,IAAK,GAAEC,MAAM,CAACN,IAAK,IAAGM,MAAM,CAACT,MAAO,KAAIS,MAAM,CAACf,WAAY,EAAvE;;AACA,MAAIH,OAAJ,EAAa;AAAA;;AACXiB,IAAAA,YAAY,IAAI,GAAhB;AACAA,IAAAA,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;AACD;;AACDH,EAAAA,YAAY,IAAI,IAAhB;AACA,SAAOA,YAAP;AACD,CAfH,EAeK,EAfL,CADK","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"]}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { BuildContext, BuildTask, BuiltTaskResult, TaskResultsList } from '@teambit/builder';
|
|
2
|
-
import ConsumerComponent from '@teambit/legacy/dist/consumer/component';
|
|
3
2
|
import type { Component } from '@teambit/component';
|
|
4
3
|
export declare type TranspileFileParams = {
|
|
5
4
|
componentDir: string;
|
|
@@ -16,7 +15,7 @@ export declare enum CompilationInitiator {
|
|
|
16
15
|
ComponentAdded = 7
|
|
17
16
|
}
|
|
18
17
|
export declare type TranspileComponentParams = {
|
|
19
|
-
component:
|
|
18
|
+
component: Component;
|
|
20
19
|
componentDir: string;
|
|
21
20
|
outputDir: string;
|
|
22
21
|
initiator: CompilationInitiator;
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["types.ts"],"names":["CompilationInitiator"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"sources":["types.ts"],"names":["CompilationInitiator"],"mappings":";;;;;;IAQYA,oB;;;WAAAA,oB;AAAAA,EAAAA,oB,CAAAA,oB;AAAAA,EAAAA,oB,CAAAA,oB;AAAAA,EAAAA,oB,CAAAA,oB;AAAAA,EAAAA,oB,CAAAA,oB;AAAAA,EAAAA,oB,CAAAA,oB;AAAAA,EAAAA,oB,CAAAA,oB;AAAAA,EAAAA,oB,CAAAA,oB;AAAAA,EAAAA,oB,CAAAA,oB;GAAAA,oB,oCAAAA,oB","sourcesContent":["import { BuildContext, BuildTask, BuiltTaskResult, TaskResultsList } from '@teambit/builder';\nimport type { Component } from '@teambit/component';\n\nexport type TranspileFileParams = {\n componentDir: string; // absolute path of the component's root directory\n filePath: string; // relative path of the file inside the component directory\n};\n\nexport enum CompilationInitiator {\n CmdReport,\n CmdJson,\n PreStart,\n PreWatch,\n Start,\n ComponentChanged,\n AspectLoadFail,\n ComponentAdded,\n}\n\nexport type TranspileComponentParams = {\n component: 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 * 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"]}
|
|
@@ -4,7 +4,6 @@ import type { PubsubMain } from '@teambit/pubsub';
|
|
|
4
4
|
import { SerializableResults, Workspace, WatchOptions } from '@teambit/workspace';
|
|
5
5
|
import { BitId } from '@teambit/legacy-bit-id';
|
|
6
6
|
import { Logger } from '@teambit/logger';
|
|
7
|
-
import ConsumerComponent from '@teambit/legacy/dist/consumer/component';
|
|
8
7
|
import { Dist } from '@teambit/legacy/dist/consumer/component/sources';
|
|
9
8
|
import { AspectLoaderMain } from '@teambit/aspect-loader';
|
|
10
9
|
import { UiMain } from '@teambit/ui';
|
|
@@ -38,13 +37,13 @@ export declare class ComponentCompiler {
|
|
|
38
37
|
private logger;
|
|
39
38
|
private dists;
|
|
40
39
|
private compileErrors;
|
|
41
|
-
constructor(pubsub: PubsubMain, workspace: Workspace, component:
|
|
40
|
+
constructor(pubsub: PubsubMain, workspace: Workspace, component: Component, compilerInstance: Compiler, compilerId: string, logger: Logger, dists?: Dist[], compileErrors?: CompileError[]);
|
|
42
41
|
compile(noThrow: boolean | undefined, options: CompileOptions): Promise<BuildResult>;
|
|
43
42
|
private throwOnCompileErrors;
|
|
44
43
|
private get distDir();
|
|
45
44
|
private get componentDir();
|
|
46
|
-
private
|
|
47
|
-
private
|
|
45
|
+
private compileOneFile;
|
|
46
|
+
private compileAllFiles;
|
|
48
47
|
}
|
|
49
48
|
export declare class WorkspaceCompiler {
|
|
50
49
|
private workspace;
|
|
@@ -21,16 +21,6 @@ function _pMapSeries() {
|
|
|
21
21
|
return data;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
function _component() {
|
|
25
|
-
const data = require("@teambit/component");
|
|
26
|
-
|
|
27
|
-
_component = function () {
|
|
28
|
-
return data;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
return data;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
24
|
function _path() {
|
|
35
25
|
const data = _interopRequireDefault(require("path"));
|
|
36
26
|
|
|
@@ -167,11 +157,19 @@ class ComponentCompiler {
|
|
|
167
157
|
await dataToPersist.persistAllToFS();
|
|
168
158
|
}
|
|
169
159
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
160
|
+
const compilers = this.compilerInstance.compilers ? this.compilerInstance.compilers : [this.compilerInstance];
|
|
161
|
+
const canTranspileFile = compilers.find(c => c.transpileFile);
|
|
162
|
+
const canTranspileComponent = compilers.find(c => c.transpileComponent);
|
|
163
|
+
|
|
164
|
+
if (canTranspileFile) {
|
|
165
|
+
await Promise.all(this.component.filesystem.files.map(file => this.compileOneFile(file, options.initiator)));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (canTranspileComponent) {
|
|
169
|
+
await this.compileAllFiles(this.component, options.initiator);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (!canTranspileFile && !canTranspileComponent) {
|
|
175
173
|
throw new Error(`compiler ${this.compilerId.toString()} doesn't implement either "transpileFile" or "transpileComponent" methods`);
|
|
176
174
|
}
|
|
177
175
|
|
|
@@ -183,7 +181,7 @@ class ComponentCompiler {
|
|
|
183
181
|
dataToPersist.addBasePath(this.workspace.path);
|
|
184
182
|
await dataToPersist.persistAllToFS();
|
|
185
183
|
const buildResults = this.dists.map(distFile => distFile.path);
|
|
186
|
-
if (this.component.compiler) _loader().default.succeed();
|
|
184
|
+
if (this.component.state._consumer.compiler) _loader().default.succeed();
|
|
187
185
|
this.pubsub.pub(_compiler().CompilerAspect.id, new (_events().ComponentCompilationOnDoneEvent)(this.compileErrors, this.component, buildResults));
|
|
188
186
|
return {
|
|
189
187
|
component: this.component.id.toString(),
|
|
@@ -212,7 +210,7 @@ ${this.compileErrors.map(formatError).join('\n')}`);
|
|
|
212
210
|
}
|
|
213
211
|
|
|
214
212
|
get distDir() {
|
|
215
|
-
const packageName = (0, _componentIdToPackageName().default)(this.component);
|
|
213
|
+
const packageName = (0, _componentIdToPackageName().default)(this.component.state._consumer);
|
|
216
214
|
|
|
217
215
|
const packageDir = _path().default.join('node_modules', packageName);
|
|
218
216
|
|
|
@@ -222,10 +220,10 @@ ${this.compileErrors.map(formatError).join('\n')}`);
|
|
|
222
220
|
}
|
|
223
221
|
|
|
224
222
|
get componentDir() {
|
|
225
|
-
return this.workspace.componentDir(
|
|
223
|
+
return this.workspace.componentDir(this.component.id);
|
|
226
224
|
}
|
|
227
225
|
|
|
228
|
-
async
|
|
226
|
+
async compileOneFile(file, initiator) {
|
|
229
227
|
const options = {
|
|
230
228
|
componentDir: this.componentDir,
|
|
231
229
|
filePath: file.relative,
|
|
@@ -266,10 +264,10 @@ ${this.compileErrors.map(formatError).join('\n')}`);
|
|
|
266
264
|
}
|
|
267
265
|
}
|
|
268
266
|
|
|
269
|
-
async
|
|
267
|
+
async compileAllFiles(component, initiator) {
|
|
270
268
|
const base = this.distDir;
|
|
271
269
|
const filesToCompile = [];
|
|
272
|
-
component.files.forEach(file => {
|
|
270
|
+
component.filesystem.files.forEach(file => {
|
|
273
271
|
const isFileSupported = this.compilerInstance.isFileSupported(file.path);
|
|
274
272
|
|
|
275
273
|
if (isFileSupported) {
|
|
@@ -386,7 +384,7 @@ class WorkspaceCompiler {
|
|
|
386
384
|
if (this.workspace.isLegacy) throw new Error('workspace-compiler should work for Harmony workspace only');
|
|
387
385
|
const componentIds = await this.getIdsToCompile(componentsIds, options.changed);
|
|
388
386
|
const components = await this.workspace.getMany(componentIds);
|
|
389
|
-
const
|
|
387
|
+
const componentsCompilers = [];
|
|
390
388
|
components.forEach(c => {
|
|
391
389
|
var _environment$getCompi, _c$state$_consumer$co;
|
|
392
390
|
|
|
@@ -396,11 +394,11 @@ class WorkspaceCompiler {
|
|
|
396
394
|
|
|
397
395
|
if (compilerInstance && (_c$state$_consumer$co = c.state._consumer.componentMap) !== null && _c$state$_consumer$co !== void 0 && _c$state$_consumer$co.getComponentDir()) {
|
|
398
396
|
const compilerName = compilerInstance.constructor.name || 'compiler';
|
|
399
|
-
|
|
397
|
+
componentsCompilers.push(new ComponentCompiler(this.pubsub, this.workspace, c, compilerInstance, compilerName, this.logger));
|
|
400
398
|
}
|
|
401
399
|
});
|
|
402
|
-
const
|
|
403
|
-
return
|
|
400
|
+
const resultOnWorkspace = await (0, _pMapSeries().default)(componentsCompilers, componentCompiler => componentCompiler.compile(noThrow, options));
|
|
401
|
+
return resultOnWorkspace;
|
|
404
402
|
}
|
|
405
403
|
|
|
406
404
|
async getIdsToCompile(componentsIds, changed = false) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["workspace-compiler.ts"],"names":["ComponentCompiler","constructor","pubsub","workspace","component","compilerInstance","compilerId","logger","dists","compileErrors","compile","noThrow","options","dataToPersist","deleteDistDir","DataToPersist","removePath","RemovePath","distDir","addBasePath","path","persistAllToFS","transpileFile","Promise","all","files","map","file","compileOneFileWithNewCompiler","initiator","transpileComponent","compileAllFilesWithNewCompiler","Error","toString","throwOnCompileErrors","addManyFiles","buildResults","distFile","compiler","loader","succeed","pub","CompilerAspect","id","ComponentCompilationOnDoneEvent","length","forEach","errorItem","error","formatError","err","join","CompilerErrorEvent","console","message","packageName","packageDir","distDirName","DEFAULT_DIST_DIRNAME","componentDir","ComponentID","filePath","relative","isFileSupported","compileResults","contents","push","base","result","Dist","outputPath","Buffer","from","outputText","shouldCopyNonSupportedFiles","filesToCompile","outputDir","getComponentPackagePath","WorkspaceCompiler","envs","aspectLoader","ui","registerOnComponentChange","onComponentChange","bind","registerOnComponentAdd","registerOnPreWatch","onPreWatch","registerPreStart","onPreStart","registerOnAspectLoadErrorSlot","onAspectLoadFail","preStartOpts","skipCompilation","compileComponents","changed","verbose","CompilationInitiator","PreStart","code","AspectLoadFail","ComponentChanged","results","components","watchOpts","preCompile","start","Date","now","c","_legacy","PreWatch","end","consoleSuccess","componentsIds","ConsumerNotFound","isLegacy","componentIds","getIdsToCompile","getMany","componentsAndNewCompilers","environment","getEnv","env","getCompiler","state","_consumer","componentMap","getComponentDir","compilerName","name","newCompilersResultOnWorkspace","componentAndNewCompilers","resolveMultipleComponentIds","getNewAndModifiedIds","getAllComponentIds"],"mappings":";;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAIA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAIA;AAAA;;AAAA;AAAA;AAAA;;AAAA;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OAAzB,CAAiCC,OAAjC,EAA0CC,OAA1C,CAD0C,CAA5C;AAIA,WAAOuH,6BAAP;AACD;;AAE4B,QAAfb,eAAe,CAC3BJ,aAD2B,EAE3BnB,OAAO,GAAG,KAFiB,EAGH;AACxB,QAAImB,aAAa,CAACrE,MAAlB,EAA0B;AACxB,aAAO,KAAK1C,SAAL,CAAekI,2BAAf,CAA2CnB,aAA3C,CAAP;AACD;;AACD,QAAInB,OAAJ,EAAa;AACX,aAAO,KAAK5F,SAAL,CAAemI,oBAAf,EAAP;AACD;;AACD,WAAO,KAAKnI,SAAL,CAAeoI,kBAAf,EAAP;AACD;;AAvH4B","sourcesContent":["/* eslint-disable max-classes-per-file */\nimport mapSeries from 'p-map-series';\nimport { Component, ComponentID } from '@teambit/component';\nimport { EnvsMain } from '@teambit/envs';\nimport type { PubsubMain } from '@teambit/pubsub';\nimport { SerializableResults, Workspace, WatchOptions } from '@teambit/workspace';\nimport path from 'path';\nimport { BitId } from '@teambit/legacy-bit-id';\nimport { Logger } from '@teambit/logger';\nimport loader from '@teambit/legacy/dist/cli/loader';\nimport { DEFAULT_DIST_DIRNAME } from '@teambit/legacy/dist/constants';\nimport ConsumerComponent from '@teambit/legacy/dist/consumer/component';\nimport { Dist, SourceFile } from '@teambit/legacy/dist/consumer/component/sources';\nimport DataToPersist from '@teambit/legacy/dist/consumer/component/sources/data-to-persist';\nimport { AspectLoaderMain } from '@teambit/aspect-loader';\nimport { ConsumerNotFound } from '@teambit/legacy/dist/consumer/exceptions';\nimport componentIdToPackageName from '@teambit/legacy/dist/utils/bit/component-id-to-package-name';\nimport RemovePath from '@teambit/legacy/dist/consumer/component/sources/remove-path';\nimport { UiMain } from '@teambit/ui';\nimport type { PreStartOpts } from '@teambit/ui';\nimport { PathOsBasedAbsolute, PathOsBasedRelative } from '@teambit/legacy/dist/utils/path';\nimport { CompilerAspect } from './compiler.aspect';\nimport { CompilerErrorEvent, ComponentCompilationOnDoneEvent } from './events';\nimport { Compiler, CompilationInitiator } from './types';\n\nexport type BuildResult = { component: string; buildResults: string[] | null | undefined };\n\nexport type CompileOptions = {\n changed?: boolean; // compile only new and modified components\n verbose?: boolean; // show more data, such as, dist paths\n /**\n * whether the dist root dir should be deleted before writing new dists.\n * defaults to true for `bit compile` and false everywhere else, such as `bit watch` and `bit\n * start` to avoid webpack \"EINTR\" error.\n */\n deleteDistDir?: boolean;\n initiator: CompilationInitiator; // describes where the compilation is coming from\n};\n\nexport type CompileError = { path: string; error: Error };\n\nexport class ComponentCompiler {\n constructor(\n private pubsub: PubsubMain,\n private workspace: Workspace,\n private component: ConsumerComponent,\n private compilerInstance: Compiler,\n private compilerId: string,\n private logger: Logger,\n private dists: Dist[] = [],\n private compileErrors: CompileError[] = []\n ) {}\n\n async compile(noThrow = true, options: CompileOptions): Promise<BuildResult> {\n let dataToPersist;\n const deleteDistDir = options.deleteDistDir ?? this.compilerInstance.deleteDistDir;\n // delete dist folder before transpilation (because some compilers (like ngPackagr) can generate files there during the compilation process)\n if (deleteDistDir) {\n dataToPersist = new DataToPersist();\n dataToPersist.removePath(new RemovePath(this.distDir));\n dataToPersist.addBasePath(this.workspace.path);\n await dataToPersist.persistAllToFS();\n }\n\n if (this.compilerInstance.transpileFile) {\n await Promise.all(\n this.component.files.map((file: SourceFile) => this.compileOneFileWithNewCompiler(file, options.initiator))\n );\n } else if (this.compilerInstance.transpileComponent) {\n await this.compileAllFilesWithNewCompiler(this.component, options.initiator);\n } else {\n throw new Error(\n `compiler ${this.compilerId.toString()} doesn't implement either \"transpileFile\" or \"transpileComponent\" methods`\n );\n }\n this.throwOnCompileErrors(noThrow);\n\n // writing the dists with `component.setDists(dists); component.dists.writeDists` is tricky\n // as it uses other base-paths and doesn't respect the new node-modules base path.\n dataToPersist = new DataToPersist();\n dataToPersist.addManyFiles(this.dists);\n dataToPersist.addBasePath(this.workspace.path);\n await dataToPersist.persistAllToFS();\n const buildResults = this.dists.map((distFile) => distFile.path);\n if (this.component.compiler) loader.succeed();\n this.pubsub.pub(\n CompilerAspect.id,\n new ComponentCompilationOnDoneEvent(this.compileErrors, this.component, buildResults)\n );\n return { component: this.component.id.toString(), buildResults };\n }\n\n private throwOnCompileErrors(noThrow = true) {\n if (this.compileErrors.length) {\n this.compileErrors.forEach((errorItem) => {\n this.logger.error(`compilation error at ${errorItem.path}`, errorItem.error);\n });\n const formatError = (errorItem) => `${errorItem.path}\\n${errorItem.error}`;\n const err = new Error(`compilation failed. see the following errors from the compiler\n${this.compileErrors.map(formatError).join('\\n')}`);\n\n this.pubsub.pub(CompilerAspect.id, new CompilerErrorEvent(err));\n\n if (!noThrow) {\n throw err;\n }\n\n this.logger.console(err.message);\n }\n }\n\n private get distDir(): PathOsBasedRelative {\n const packageName = componentIdToPackageName(this.component);\n const packageDir = path.join('node_modules', packageName);\n const distDirName = DEFAULT_DIST_DIRNAME;\n return path.join(packageDir, distDirName);\n }\n\n private get componentDir(): PathOsBasedAbsolute {\n return this.workspace.componentDir(new ComponentID(this.component.id));\n }\n\n private async compileOneFileWithNewCompiler(file: SourceFile, initiator: CompilationInitiator): Promise<void> {\n const options = { componentDir: this.componentDir, filePath: file.relative, initiator };\n const isFileSupported = this.compilerInstance.isFileSupported(file.path);\n let compileResults;\n if (isFileSupported) {\n try {\n compileResults = this.compilerInstance.transpileFile?.(file.contents.toString(), options);\n } catch (error: any) {\n this.compileErrors.push({ path: file.path, error });\n return;\n }\n }\n const base = this.distDir;\n if (isFileSupported && compileResults) {\n this.dists.push(\n ...compileResults.map(\n (result) =>\n new Dist({\n base,\n path: path.join(base, result.outputPath),\n contents: Buffer.from(result.outputText),\n })\n )\n );\n } else if (this.compilerInstance.shouldCopyNonSupportedFiles) {\n // compiler doesn't support this file type. copy the file as is to the dist dir.\n this.dists.push(new Dist({ base, path: path.join(base, file.relative), contents: file.contents }));\n }\n }\n\n private async compileAllFilesWithNewCompiler(\n component: ConsumerComponent,\n initiator: CompilationInitiator\n ): Promise<void> {\n const base = this.distDir;\n const filesToCompile: SourceFile[] = [];\n component.files.forEach((file: SourceFile) => {\n const isFileSupported = this.compilerInstance.isFileSupported(file.path);\n if (isFileSupported) {\n filesToCompile.push(file);\n } else if (this.compilerInstance.shouldCopyNonSupportedFiles) {\n // compiler doesn't support this file type. copy the file as is to the dist dir.\n this.dists.push(\n new Dist({\n base,\n path: path.join(base, file.relative),\n contents: file.contents,\n })\n );\n }\n });\n\n if (filesToCompile.length) {\n try {\n await this.compilerInstance.transpileComponent?.({\n component,\n componentDir: this.componentDir,\n outputDir: this.workspace.getComponentPackagePath(component),\n initiator,\n });\n } catch (error: any) {\n this.compileErrors.push({ path: this.componentDir, error });\n }\n }\n }\n}\n\nexport class WorkspaceCompiler {\n constructor(\n private workspace: Workspace,\n private envs: EnvsMain,\n private pubsub: PubsubMain,\n private aspectLoader: AspectLoaderMain,\n private ui: UiMain,\n private logger: Logger\n ) {\n if (this.workspace) {\n this.workspace.registerOnComponentChange(this.onComponentChange.bind(this));\n this.workspace.registerOnComponentAdd(this.onComponentChange.bind(this));\n this.workspace.registerOnPreWatch(this.onPreWatch.bind(this));\n this.ui.registerPreStart(this.onPreStart.bind(this));\n }\n if (this.aspectLoader) {\n this.aspectLoader.registerOnAspectLoadErrorSlot(this.onAspectLoadFail.bind(this));\n }\n }\n\n async onPreStart(preStartOpts: PreStartOpts): Promise<void> {\n if (preStartOpts.skipCompilation) {\n return;\n }\n await this.compileComponents([], {\n changed: true,\n verbose: false,\n deleteDistDir: false,\n initiator: CompilationInitiator.PreStart,\n });\n }\n\n async onAspectLoadFail(err: Error & { code?: string }, id: ComponentID): Promise<boolean> {\n if (err.code && err.code === 'MODULE_NOT_FOUND' && this.workspace) {\n await this.compileComponents([id.toString()], { initiator: CompilationInitiator.AspectLoadFail }, true);\n return true;\n }\n return false;\n }\n\n async onComponentChange(\n component: Component,\n files: string[],\n initiator?: CompilationInitiator\n ): Promise<SerializableResults> {\n const buildResults = await this.compileComponents(\n [component.id.toString()],\n { initiator: initiator || CompilationInitiator.ComponentChanged },\n true\n );\n return {\n results: buildResults,\n toString() {\n return `${buildResults[0]?.buildResults?.join('\\n\\t')}`;\n },\n };\n }\n\n async onPreWatch(components: Component[], watchOpts: WatchOptions) {\n if (watchOpts.preCompile) {\n const start = Date.now();\n this.logger.console(`compiling ${components.length} components`);\n await this.compileComponents(\n components.map((c) => c.id._legacy),\n { initiator: CompilationInitiator.PreWatch }\n );\n const end = Date.now() - start;\n this.logger.consoleSuccess(`compiled ${components.length} components successfully (${end / 1000} sec)`);\n }\n }\n\n async compileComponents(\n componentsIds: string[] | BitId[] | ComponentID[], // when empty, it compiles new+modified (unless options.all is set),\n options: CompileOptions,\n noThrow?: boolean\n ): Promise<BuildResult[]> {\n if (!this.workspace) throw new ConsumerNotFound();\n if (this.workspace.isLegacy) throw new Error('workspace-compiler should work for Harmony workspace only');\n const componentIds = await this.getIdsToCompile(componentsIds, options.changed);\n const components = await this.workspace.getMany(componentIds);\n\n const componentsAndNewCompilers: ComponentCompiler[] = [];\n components.forEach((c) => {\n const environment = this.envs.getEnv(c).env;\n const compilerInstance = environment.getCompiler?.();\n // if there is no componentDir (e.g. author that added files, not dir), then we can't write the dists\n // inside the component dir.\n if (compilerInstance && c.state._consumer.componentMap?.getComponentDir()) {\n const compilerName = compilerInstance.constructor.name || 'compiler';\n componentsAndNewCompilers.push(\n new ComponentCompiler(\n this.pubsub,\n this.workspace,\n c.state._consumer,\n compilerInstance,\n compilerName,\n this.logger\n )\n );\n }\n });\n const newCompilersResultOnWorkspace = await mapSeries(componentsAndNewCompilers, (componentAndNewCompilers) =>\n componentAndNewCompilers.compile(noThrow, options)\n );\n\n return newCompilersResultOnWorkspace;\n }\n\n private async getIdsToCompile(\n componentsIds: Array<string | ComponentID | BitId>,\n changed = false\n ): Promise<ComponentID[]> {\n if (componentsIds.length) {\n return this.workspace.resolveMultipleComponentIds(componentsIds);\n }\n if (changed) {\n return this.workspace.getNewAndModifiedIds();\n }\n return this.workspace.getAllComponentIds();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["workspace-compiler.ts"],"names":["ComponentCompiler","constructor","pubsub","workspace","component","compilerInstance","compilerId","logger","dists","compileErrors","compile","noThrow","options","dataToPersist","deleteDistDir","DataToPersist","removePath","RemovePath","distDir","addBasePath","path","persistAllToFS","compilers","canTranspileFile","find","c","transpileFile","canTranspileComponent","transpileComponent","Promise","all","filesystem","files","map","file","compileOneFile","initiator","compileAllFiles","Error","toString","throwOnCompileErrors","addManyFiles","buildResults","distFile","state","_consumer","compiler","loader","succeed","pub","CompilerAspect","id","ComponentCompilationOnDoneEvent","length","forEach","errorItem","error","formatError","err","join","CompilerErrorEvent","console","message","packageName","packageDir","distDirName","DEFAULT_DIST_DIRNAME","componentDir","filePath","relative","isFileSupported","compileResults","contents","push","base","result","Dist","outputPath","Buffer","from","outputText","shouldCopyNonSupportedFiles","filesToCompile","outputDir","getComponentPackagePath","WorkspaceCompiler","envs","aspectLoader","ui","registerOnComponentChange","onComponentChange","bind","registerOnComponentAdd","registerOnPreWatch","onPreWatch","registerPreStart","onPreStart","registerOnAspectLoadErrorSlot","onAspectLoadFail","preStartOpts","skipCompilation","compileComponents","changed","verbose","CompilationInitiator","PreStart","code","AspectLoadFail","ComponentChanged","results","components","watchOpts","preCompile","start","Date","now","_legacy","PreWatch","end","consoleSuccess","componentsIds","ConsumerNotFound","isLegacy","componentIds","getIdsToCompile","getMany","componentsCompilers","environment","getEnv","env","getCompiler","componentMap","getComponentDir","compilerName","name","resultOnWorkspace","componentCompiler","resolveMultipleComponentIds","getNewAndModifiedIds","getAllComponentIds"],"mappings":";;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAKA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA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AgB,4BAAG0H,WAAW,CAACG,WAAf,0DAAG,2BAAAH,WAAW,CAApC,CAFwB,CAGxB;AACA;;AACA,UAAI1H,gBAAgB,6BAAIoB,CAAC,CAACmB,KAAF,CAAQC,SAAR,CAAkBsF,YAAtB,kDAAI,sBAAgCC,eAAhC,EAAxB,EAA2E;AACzE,cAAMC,YAAY,GAAGhI,gBAAgB,CAACJ,WAAjB,CAA6BqI,IAA7B,IAAqC,UAA1D;AACAR,QAAAA,mBAAmB,CAACrD,IAApB,CACE,IAAIzE,iBAAJ,CAAsB,KAAKE,MAA3B,EAAmC,KAAKC,SAAxC,EAAmDsB,CAAnD,EAAsDpB,gBAAtD,EAAwEgI,YAAxE,EAAsF,KAAK9H,MAA3F,CADF;AAGD;AACF,KAXD;AAYA,UAAMgI,iBAAiB,GAAG,MAAM,2BAAUT,mBAAV,EAAgCU,iBAAD,IAC7DA,iBAAiB,CAAC9H,OAAlB,CAA0BC,OAA1B,EAAmCC,OAAnC,CAD8B,CAAhC;AAIA,WAAO2H,iBAAP;AACD;;AAE4B,QAAfX,eAAe,CAC3BJ,aAD2B,EAE3BlB,OAAO,GAAG,KAFiB,EAGH;AACxB,QAAIkB,aAAa,CAACnE,MAAlB,EAA0B;AACxB,aAAO,KAAKlD,SAAL,CAAesI,2BAAf,CAA2CjB,aAA3C,CAAP;AACD;;AACD,QAAIlB,OAAJ,EAAa;AACX,aAAO,KAAKnG,SAAL,CAAeuI,oBAAf,EAAP;AACD;;AACD,WAAO,KAAKvI,SAAL,CAAewI,kBAAf,EAAP;AACD;;AAhH4B","sourcesContent":["/* eslint-disable max-classes-per-file */\nimport mapSeries from 'p-map-series';\nimport { Component, ComponentID } from '@teambit/component';\nimport { EnvsMain } from '@teambit/envs';\nimport type { PubsubMain } from '@teambit/pubsub';\nimport { SerializableResults, Workspace, WatchOptions } from '@teambit/workspace';\nimport path from 'path';\nimport { BitId } from '@teambit/legacy-bit-id';\nimport { Logger } from '@teambit/logger';\nimport loader from '@teambit/legacy/dist/cli/loader';\nimport { DEFAULT_DIST_DIRNAME } from '@teambit/legacy/dist/constants';\nimport { AbstractVinyl, Dist } from '@teambit/legacy/dist/consumer/component/sources';\nimport DataToPersist from '@teambit/legacy/dist/consumer/component/sources/data-to-persist';\nimport { AspectLoaderMain } from '@teambit/aspect-loader';\nimport { ConsumerNotFound } from '@teambit/legacy/dist/consumer/exceptions';\nimport componentIdToPackageName from '@teambit/legacy/dist/utils/bit/component-id-to-package-name';\nimport RemovePath from '@teambit/legacy/dist/consumer/component/sources/remove-path';\nimport { UiMain } from '@teambit/ui';\nimport type { PreStartOpts } from '@teambit/ui';\nimport { PathOsBasedAbsolute, PathOsBasedRelative } from '@teambit/legacy/dist/utils/path';\nimport { MultiCompiler } from '@teambit/multi-compiler';\nimport { CompilerAspect } from './compiler.aspect';\nimport { CompilerErrorEvent, ComponentCompilationOnDoneEvent } from './events';\nimport { Compiler, CompilationInitiator } from './types';\n\nexport type BuildResult = { component: string; buildResults: string[] | null | undefined };\n\nexport type CompileOptions = {\n changed?: boolean; // compile only new and modified components\n verbose?: boolean; // show more data, such as, dist paths\n /**\n * whether the dist root dir should be deleted before writing new dists.\n * defaults to true for `bit compile` and false everywhere else, such as `bit watch` and `bit\n * start` to avoid webpack \"EINTR\" error.\n */\n deleteDistDir?: boolean;\n initiator: CompilationInitiator; // describes where the compilation is coming from\n};\n\nexport type CompileError = { path: string; error: Error };\n\nexport class ComponentCompiler {\n constructor(\n private pubsub: PubsubMain,\n private workspace: Workspace,\n private component: Component,\n private compilerInstance: Compiler,\n private compilerId: string,\n private logger: Logger,\n private dists: Dist[] = [],\n private compileErrors: CompileError[] = []\n ) {}\n\n async compile(noThrow = true, options: CompileOptions): Promise<BuildResult> {\n let dataToPersist;\n const deleteDistDir = options.deleteDistDir ?? this.compilerInstance.deleteDistDir;\n // delete dist folder before transpilation (because some compilers (like ngPackagr) can generate files there during the compilation process)\n if (deleteDistDir) {\n dataToPersist = new DataToPersist();\n dataToPersist.removePath(new RemovePath(this.distDir));\n dataToPersist.addBasePath(this.workspace.path);\n await dataToPersist.persistAllToFS();\n }\n\n const compilers: Compiler[] = (this.compilerInstance as MultiCompiler).compilers\n ? (this.compilerInstance as MultiCompiler).compilers\n : [this.compilerInstance];\n const canTranspileFile = compilers.find((c) => c.transpileFile);\n const canTranspileComponent = compilers.find((c) => c.transpileComponent);\n\n if (canTranspileFile) {\n await Promise.all(\n this.component.filesystem.files.map((file: AbstractVinyl) => this.compileOneFile(file, options.initiator))\n );\n }\n\n if (canTranspileComponent) {\n await this.compileAllFiles(this.component, options.initiator);\n }\n\n if (!canTranspileFile && !canTranspileComponent) {\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.state._consumer.compiler) loader.succeed();\n this.pubsub.pub(\n CompilerAspect.id,\n new ComponentCompilationOnDoneEvent(this.compileErrors, this.component, buildResults)\n );\n return { component: this.component.id.toString(), buildResults };\n }\n\n private throwOnCompileErrors(noThrow = true) {\n if (this.compileErrors.length) {\n this.compileErrors.forEach((errorItem) => {\n this.logger.error(`compilation error at ${errorItem.path}`, errorItem.error);\n });\n const formatError = (errorItem) => `${errorItem.path}\\n${errorItem.error}`;\n const err = new Error(`compilation failed. see the following errors from the compiler\n${this.compileErrors.map(formatError).join('\\n')}`);\n\n this.pubsub.pub(CompilerAspect.id, new CompilerErrorEvent(err));\n\n if (!noThrow) {\n throw err;\n }\n\n this.logger.console(err.message);\n }\n }\n\n private get distDir(): PathOsBasedRelative {\n const packageName = componentIdToPackageName(this.component.state._consumer);\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(this.component.id);\n }\n\n private async compileOneFile(file: AbstractVinyl, initiator: CompilationInitiator): Promise<void> {\n const options = { componentDir: this.componentDir, filePath: file.relative, initiator };\n const isFileSupported = this.compilerInstance.isFileSupported(file.path);\n let compileResults;\n if (isFileSupported) {\n try {\n compileResults = this.compilerInstance.transpileFile?.(file.contents.toString(), options);\n } catch (error: any) {\n this.compileErrors.push({ path: file.path, error });\n return;\n }\n }\n const base = this.distDir;\n if (isFileSupported && compileResults) {\n this.dists.push(\n ...compileResults.map(\n (result) =>\n new Dist({\n base,\n path: path.join(base, result.outputPath),\n contents: Buffer.from(result.outputText),\n })\n )\n );\n } else if (this.compilerInstance.shouldCopyNonSupportedFiles) {\n // compiler doesn't support this file type. copy the file as is to the dist dir.\n this.dists.push(new Dist({ base, path: path.join(base, file.relative), contents: file.contents }));\n }\n }\n\n private async compileAllFiles(component: Component, initiator: CompilationInitiator): Promise<void> {\n const base = this.distDir;\n const filesToCompile: AbstractVinyl[] = [];\n component.filesystem.files.forEach((file: AbstractVinyl) => {\n const isFileSupported = this.compilerInstance.isFileSupported(file.path);\n if (isFileSupported) {\n filesToCompile.push(file);\n } else if (this.compilerInstance.shouldCopyNonSupportedFiles) {\n // compiler doesn't support this file type. copy the file as is to the dist dir.\n this.dists.push(\n new Dist({\n base,\n path: path.join(base, file.relative),\n contents: file.contents,\n })\n );\n }\n });\n\n if (filesToCompile.length) {\n try {\n await this.compilerInstance.transpileComponent?.({\n component,\n componentDir: this.componentDir,\n outputDir: this.workspace.getComponentPackagePath(component),\n initiator,\n });\n } catch (error: any) {\n this.compileErrors.push({ path: this.componentDir, error });\n }\n }\n }\n}\n\nexport class WorkspaceCompiler {\n constructor(\n private workspace: Workspace,\n private envs: EnvsMain,\n private pubsub: PubsubMain,\n private aspectLoader: AspectLoaderMain,\n private ui: UiMain,\n private logger: Logger\n ) {\n if (this.workspace) {\n this.workspace.registerOnComponentChange(this.onComponentChange.bind(this));\n this.workspace.registerOnComponentAdd(this.onComponentChange.bind(this));\n this.workspace.registerOnPreWatch(this.onPreWatch.bind(this));\n this.ui.registerPreStart(this.onPreStart.bind(this));\n }\n if (this.aspectLoader) {\n this.aspectLoader.registerOnAspectLoadErrorSlot(this.onAspectLoadFail.bind(this));\n }\n }\n\n async onPreStart(preStartOpts: PreStartOpts): Promise<void> {\n if (preStartOpts.skipCompilation) {\n return;\n }\n await this.compileComponents([], {\n changed: true,\n verbose: false,\n deleteDistDir: false,\n initiator: CompilationInitiator.PreStart,\n });\n }\n\n async onAspectLoadFail(err: Error & { code?: string }, id: ComponentID): Promise<boolean> {\n if (err.code && err.code === 'MODULE_NOT_FOUND' && this.workspace) {\n await this.compileComponents([id.toString()], { initiator: CompilationInitiator.AspectLoadFail }, true);\n return true;\n }\n return false;\n }\n\n async onComponentChange(\n component: Component,\n files: string[],\n initiator?: CompilationInitiator\n ): Promise<SerializableResults> {\n const buildResults = await this.compileComponents(\n [component.id.toString()],\n { initiator: initiator || CompilationInitiator.ComponentChanged },\n true\n );\n return {\n results: buildResults,\n toString() {\n return `${buildResults[0]?.buildResults?.join('\\n\\t')}`;\n },\n };\n }\n\n async onPreWatch(components: Component[], watchOpts: WatchOptions) {\n if (watchOpts.preCompile) {\n const start = Date.now();\n this.logger.console(`compiling ${components.length} components`);\n await this.compileComponents(\n components.map((c) => c.id._legacy),\n { initiator: CompilationInitiator.PreWatch }\n );\n const end = Date.now() - start;\n this.logger.consoleSuccess(`compiled ${components.length} components successfully (${end / 1000} sec)`);\n }\n }\n\n async compileComponents(\n componentsIds: string[] | BitId[] | ComponentID[], // when empty, it compiles new+modified (unless options.all is set),\n options: CompileOptions,\n noThrow?: boolean\n ): Promise<BuildResult[]> {\n if (!this.workspace) throw new ConsumerNotFound();\n if (this.workspace.isLegacy) throw new Error('workspace-compiler should work for Harmony workspace only');\n const componentIds = await this.getIdsToCompile(componentsIds, options.changed);\n const components = await this.workspace.getMany(componentIds);\n\n const componentsCompilers: 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 componentsCompilers.push(\n new ComponentCompiler(this.pubsub, this.workspace, c, compilerInstance, compilerName, this.logger)\n );\n }\n });\n const resultOnWorkspace = await mapSeries(componentsCompilers, (componentCompiler) =>\n componentCompiler.compile(noThrow, options)\n );\n\n return resultOnWorkspace;\n }\n\n private async getIdsToCompile(\n componentsIds: Array<string | ComponentID | BitId>,\n changed = false\n ): Promise<ComponentID[]> {\n if (componentsIds.length) {\n return this.workspace.resolveMultipleComponentIds(componentsIds);\n }\n if (changed) {\n return this.workspace.getNewAndModifiedIds();\n }\n return this.workspace.getAllComponentIds();\n }\n}\n"]}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
/* eslint-disable max-classes-per-file */
|
|
2
2
|
import { BitBaseEvent } from '@teambit/pubsub';
|
|
3
|
-
import
|
|
3
|
+
import { Component } from '@teambit/component';
|
|
4
4
|
import { CompileError } from '../workspace-compiler';
|
|
5
5
|
|
|
6
6
|
class ComponentCompilationOnDoneEventData {
|
|
7
|
-
constructor(
|
|
8
|
-
readonly errors: Array<CompileError>,
|
|
9
|
-
readonly component: ConsumerComponent,
|
|
10
|
-
readonly buildResults: string[]
|
|
11
|
-
) {}
|
|
7
|
+
constructor(readonly errors: Array<CompileError>, readonly component: Component, readonly buildResults: string[]) {}
|
|
12
8
|
}
|
|
13
9
|
|
|
14
10
|
export class ComponentCompilationOnDoneEvent extends BitBaseEvent<ComponentCompilationOnDoneEventData> {
|
|
@@ -16,7 +12,7 @@ export class ComponentCompilationOnDoneEvent extends BitBaseEvent<ComponentCompi
|
|
|
16
12
|
|
|
17
13
|
constructor(
|
|
18
14
|
readonly errors: Array<CompileError>,
|
|
19
|
-
readonly component:
|
|
15
|
+
readonly component: Component,
|
|
20
16
|
readonly buildResults: string[],
|
|
21
17
|
readonly timestamp = Date.now()
|
|
22
18
|
) {
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/compiler",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.656",
|
|
4
4
|
"homepage": "https://bit.dev/teambit/compilation/compiler",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.compilation",
|
|
8
8
|
"name": "compiler",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.656"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@teambit/harmony": "0.2.11",
|
|
@@ -18,18 +18,19 @@
|
|
|
18
18
|
"p-map-series": "2.1.0",
|
|
19
19
|
"@babel/runtime": "7.12.18",
|
|
20
20
|
"core-js": "^3.0.0",
|
|
21
|
-
"@teambit/cli": "0.0.
|
|
22
|
-
"@teambit/
|
|
23
|
-
"@teambit/
|
|
24
|
-
"@teambit/
|
|
25
|
-
"@teambit/
|
|
26
|
-
"@teambit/
|
|
27
|
-
"@teambit/envs": "0.0.
|
|
28
|
-
"@teambit/generator": "0.0.
|
|
21
|
+
"@teambit/cli": "0.0.447",
|
|
22
|
+
"@teambit/component": "0.0.656",
|
|
23
|
+
"@teambit/logger": "0.0.537",
|
|
24
|
+
"@teambit/pubsub": "0.0.656",
|
|
25
|
+
"@teambit/aspect-loader": "0.0.656",
|
|
26
|
+
"@teambit/builder": "0.0.656",
|
|
27
|
+
"@teambit/envs": "0.0.656",
|
|
28
|
+
"@teambit/generator": "0.0.656",
|
|
29
29
|
"@teambit/legacy-bit-id": "0.0.398",
|
|
30
|
-
"@teambit/ui": "0.0.
|
|
31
|
-
"@teambit/workspace": "0.0.
|
|
32
|
-
"@teambit/isolator": "0.0.
|
|
30
|
+
"@teambit/ui": "0.0.656",
|
|
31
|
+
"@teambit/workspace": "0.0.656",
|
|
32
|
+
"@teambit/isolator": "0.0.656",
|
|
33
|
+
"@teambit/multi-compiler": "0.0.656",
|
|
33
34
|
"@teambit/bit-error": "0.0.394"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
@@ -43,7 +44,7 @@
|
|
|
43
44
|
"@teambit/compilation.aspect-docs.compiler": "0.0.132"
|
|
44
45
|
},
|
|
45
46
|
"peerDependencies": {
|
|
46
|
-
"@teambit/legacy": "1.0.
|
|
47
|
+
"@teambit/legacy": "1.0.226",
|
|
47
48
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
48
49
|
"react": "^16.8.0 || ^17.0.0"
|
|
49
50
|
},
|
|
@@ -71,7 +72,7 @@
|
|
|
71
72
|
"react": "-"
|
|
72
73
|
},
|
|
73
74
|
"peerDependencies": {
|
|
74
|
-
"@teambit/legacy": "1.0.
|
|
75
|
+
"@teambit/legacy": "1.0.226",
|
|
75
76
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
76
77
|
"react": "^16.8.0 || ^17.0.0"
|
|
77
78
|
}
|
|
Binary file
|