@teambit/multi-compiler 0.0.651 → 0.0.654

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.
@@ -1 +1 @@
1
- export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.compilation_multi-compiler@0.0.651/dist/multi-compiler.docs.mdx')]
1
+ export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.compilation_multi-compiler@0.0.654/dist/multi-compiler.docs.mdx')]
@@ -1,4 +1,4 @@
1
- import { Compiler, CompilerOptions, TranspileFileOutput, TranspileFileParams } from '@teambit/compiler';
1
+ import { Compiler, CompilerOptions, TranspileComponentParams, TranspileFileOutput, TranspileFileParams } from '@teambit/compiler';
2
2
  import { BuiltTaskResult, BuildContext, TaskResultsList } from '@teambit/builder';
3
3
  export declare type MultiCompilerOptions = {
4
4
  targetExtension?: string;
@@ -23,6 +23,7 @@ export declare class MultiCompiler implements Compiler {
23
23
  * the multi-compiler applies all applicable defined compilers on given content.
24
24
  */
25
25
  transpileFile(fileContent: string, options: TranspileFileParams): TranspileFileOutput;
26
+ transpileComponent(params: TranspileComponentParams): Promise<void>;
26
27
  build(context: BuildContext): Promise<BuiltTaskResult>;
27
28
  preBuild(context: BuildContext): Promise<void>;
28
29
  postBuild(context: BuildContext, taskResults: TaskResultsList): Promise<void>;
@@ -93,6 +93,10 @@ class MultiCompiler {
93
93
 
94
94
  transpileFile(fileContent, options) {
95
95
  const outputs = this.compilers.reduce((files, compiler) => {
96
+ if (!compiler.transpileFile) {
97
+ return files;
98
+ }
99
+
96
100
  return files === null || files === void 0 ? void 0 : files.flatMap(file => {
97
101
  var _compiler$transpileFi;
98
102
 
@@ -111,6 +115,14 @@ class MultiCompiler {
111
115
  return outputs;
112
116
  }
113
117
 
118
+ async transpileComponent(params) {
119
+ await Promise.all(this.compilers.map(compiler => {
120
+ var _compiler$transpileCo;
121
+
122
+ return (_compiler$transpileCo = compiler.transpileComponent) === null || _compiler$transpileCo === void 0 ? void 0 : _compiler$transpileCo.call(compiler, params);
123
+ }));
124
+ }
125
+
114
126
  async build(context) {
115
127
  const builds = await (0, _pMapSeries().default)(this.compilers, async compiler => {
116
128
  const buildResult = await compiler.build(context);
@@ -1 +1 @@
1
- {"version":3,"sources":["multi-compiler.compiler.ts"],"names":["MultiCompiler","constructor","id","compilers","compilerOptions","options","shouldCopyNonSupportedFiles","getArtifactDefinition","generatedBy","name","artifactName","globPatterns","distGlobPatterns","distDir","getOptions","defaultOpts","targetExtension","Object","assign","displayConfig","map","compiler","displayName","join","transpileFile","fileContent","outputs","reduce","files","flatMap","file","isFileSupported","outputPath","params","filePath","compiledContent","outputText","build","context","builds","buildResult","componentsResults","artifacts","preBuild","Promise","all","postBuild","taskResults","firstMatchedCompiler","find","getDistPathBySrcPath","srcPath","matchedCompiler","version"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAMO,MAAMA,aAAN,CAAwC;AAS7CC,EAAAA,WAAW,CACAC,EADA,EAEAC,SAFA,EAGAC,eAAyC,GAAG,EAH5C,EAIAC,OAA6B,GAAG,EAJhC,EAKT;AAAA,SAJSH,EAIT,GAJSA,EAIT;AAAA,SAHSC,SAGT,GAHSA,SAGT;AAAA,SAFSC,eAET,GAFSA,eAET;AAAA,SADSC,OACT,GADSA,OACT;AAAA,yDAbY,gBAaZ;AAAA,yEAVA,OAAO,KAAKD,eAAL,CAAqBE,2BAA5B,KAA4D,SAA5D,GACI,KAAKF,eAAL,CAAqBE,2BADzB,GAEI,IAQJ;AAAA,qDAPQ,MAOR;AAAE;;AAEJC,EAAAA,qBAAqB,GAAG;AACtB,WAAO,CACL;AAC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oB,CAACd,QAAD,EAAyC;AACnE,WAAO,KAAK/B,SAAL,CAAe8C,IAAf,CAAqB5B,QAAD,IAAcA,QAAQ,CAACU,eAAT,CAAyBG,QAAzB,CAAlC,CAAP;AACD;AAED;AACF;AACA;AACA;;;AACEgB,EAAAA,oBAAoB,CAACC,OAAD,EAA0B;AAC5C,UAAMC,eAAe,GAAG,KAAKJ,oBAAL,CAA0BG,OAA1B,CAAxB;;AACA,QAAI,CAACC,eAAL,EAAsB;AACpB,aAAO,kBAAK,KAAKvC,OAAV,EAAmBsC,OAAnB,CAAP;AACD;;AAED,WAAOC,eAAe,CAACF,oBAAhB,CAAqCC,OAArC,CAAP;AACD;AAED;AACF;AACA;;;AACEpB,EAAAA,eAAe,CAACG,QAAD,EAA4B;AACzC,WAAO,CAAC,CAAC,KAAKc,oBAAL,CAA0Bd,QAA1B,CAAT;AACD;AAED;AACF;AACA;;;AACEmB,EAAAA,OAAO,GAAW;AAChB,WAAO,KAAKlD,SAAL,CACJiB,GADI,CACCC,QAAD,IAAc;AACjB,aAAQ,GAAEA,QAAQ,CAACC,WAAY,IAAGD,QAAQ,CAACgC,OAAT,EAAmB,EAArD;AACD,KAHI,EAIJ9B,IAJI,CAIC,IAJD,CAAP;AAKD;;AAnI4C","sourcesContent":["import { join } from 'path';\nimport pMapSeries from 'p-map-series';\nimport { Compiler, CompilerOptions, TranspileFileOutput, TranspileFileParams } from '@teambit/compiler';\nimport { BuiltTaskResult, BuildContext, TaskResultsList } from '@teambit/builder';\nimport { mergeComponentResults } from '@teambit/pipelines.modules.merge-component-results';\n\nexport type MultiCompilerOptions = {\n targetExtension?: string;\n};\n\nexport class MultiCompiler implements Compiler {\n displayName = 'Multi compiler';\n\n shouldCopyNonSupportedFiles =\n typeof this.compilerOptions.shouldCopyNonSupportedFiles === 'boolean'\n ? this.compilerOptions.shouldCopyNonSupportedFiles\n : true;\n distDir = 'dist';\n\n constructor(\n readonly id: string,\n readonly compilers: Compiler[],\n readonly compilerOptions: Partial<CompilerOptions> = {},\n readonly options: MultiCompilerOptions = {}\n ) {}\n\n getArtifactDefinition() {\n return [\n {\n generatedBy: this.id,\n name: this.compilerOptions.artifactName || 'dist',\n globPatterns: this.compilerOptions.distGlobPatterns || [\n `${this.distDir}/**`,\n `!${this.distDir}/tsconfig.tsbuildinfo`,\n ],\n },\n ];\n }\n\n private getOptions() {\n const defaultOpts = {\n targetExtension: '.js',\n };\n\n return Object.assign(defaultOpts, this.options);\n }\n\n displayConfig() {\n return this.compilers\n .map((compiler) => {\n return `${compiler.displayName}\\n${compiler.displayConfig}\\n`;\n })\n .join('\\n');\n }\n\n /**\n * the multi-compiler applies all applicable defined compilers on given content.\n */\n transpileFile(fileContent: string, options: TranspileFileParams): TranspileFileOutput {\n const outputs = this.compilers.reduce<any>(\n (files, compiler) => {\n return files?.flatMap((file) => {\n if (!compiler.isFileSupported(file?.outputPath)) return [file];\n const params = Object.assign({}, options, {\n filePath: file.outputPath,\n });\n const compiledContent = compiler.transpileFile?.(file.outputText, params);\n if (!compiledContent) return null;\n\n return compiledContent;\n });\n },\n [{ outputText: fileContent, outputPath: options.filePath }]\n );\n\n return outputs;\n }\n\n async build(context: BuildContext): Promise<BuiltTaskResult> {\n const builds = await pMapSeries(this.compilers, async (compiler) => {\n const buildResult = await compiler.build(context);\n return buildResult.componentsResults;\n });\n\n return {\n componentsResults: mergeComponentResults(builds),\n artifacts: this.getArtifactDefinition(),\n };\n }\n\n async preBuild(context: BuildContext) {\n await Promise.all(\n this.compilers.map(async (compiler) => {\n if (!compiler.preBuild) return;\n await compiler.preBuild(context);\n })\n );\n }\n\n async postBuild(context: BuildContext, taskResults: TaskResultsList) {\n await Promise.all(\n this.compilers.map(async (compiler) => {\n if (!compiler.postBuild) return;\n await compiler.postBuild(context, taskResults);\n })\n );\n }\n\n private firstMatchedCompiler(filePath: string): Compiler | undefined {\n return this.compilers.find((compiler) => compiler.isFileSupported(filePath));\n }\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 const matchedCompiler = this.firstMatchedCompiler(srcPath);\n if (!matchedCompiler) {\n return join(this.distDir, srcPath);\n }\n\n return matchedCompiler.getDistPathBySrcPath(srcPath);\n }\n\n /**\n * only supported files matching get compiled. others, are copied to the dist dir.\n */\n isFileSupported(filePath: string): boolean {\n return !!this.firstMatchedCompiler(filePath);\n }\n\n /**\n * returns the version of the current compiler instance (e.g. '4.0.1').\n */\n version(): string {\n return this.compilers\n .map((compiler) => {\n return `${compiler.displayName}@${compiler.version()}`;\n })\n .join('\\n');\n }\n}\n"]}
1
+ {"version":3,"sources":["multi-compiler.compiler.ts"],"names":["MultiCompiler","constructor","id","compilers","compilerOptions","options","shouldCopyNonSupportedFiles","getArtifactDefinition","generatedBy","name","artifactName","globPatterns","distGlobPatterns","distDir","getOptions","defaultOpts","targetExtension","Object","assign","displayConfig","map","compiler","displayName","join","transpileFile","fileContent","outputs","reduce","files","flatMap","file","isFileSupported","outputPath","params","filePath","compiledContent","outputText","transpileComponent","Promise","all","build","context","builds","buildResult","componentsResults","artifacts","preBuild","postBuild","taskResults","firstMatchedCompiler","find","getDistPathBySrcPath","srcPath","matchedCompiler","version"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AASA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAMO,MAAMA,aAAN,CAAwC;AAS7CC,EAAAA,WAAW,CACAC,EADA,EAEAC,SAFA,EAGAC,eAAyC,GAAG,EAH5C,EAIAC,OAA6B,GAAG,EAJhC,EAKT;AAAA,SAJSH,EAIT,GAJSA,EAIT;AAAA,SAHSC,SAGT,GAHSA,SAGT;AAAA,SAFSC,eAET,GAFSA,eAET;AAAA,SADSC,OACT,GADSA,OACT;AAAA,yDAbY,gB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B,EAArD;AACD,KAHI,EAIJ/B,IAJI,CAIC,IAJD,CAAP;AAKD;;AA9I4C","sourcesContent":["import { join } from 'path';\nimport pMapSeries from 'p-map-series';\nimport {\n Compiler,\n CompilerOptions,\n TranspileComponentParams,\n TranspileFileOutput,\n TranspileFileParams,\n} from '@teambit/compiler';\nimport { BuiltTaskResult, BuildContext, TaskResultsList } from '@teambit/builder';\nimport { mergeComponentResults } from '@teambit/pipelines.modules.merge-component-results';\n\nexport type MultiCompilerOptions = {\n targetExtension?: string;\n};\n\nexport class MultiCompiler implements Compiler {\n displayName = 'Multi compiler';\n\n shouldCopyNonSupportedFiles =\n typeof this.compilerOptions.shouldCopyNonSupportedFiles === 'boolean'\n ? this.compilerOptions.shouldCopyNonSupportedFiles\n : true;\n distDir = 'dist';\n\n constructor(\n readonly id: string,\n readonly compilers: Compiler[],\n readonly compilerOptions: Partial<CompilerOptions> = {},\n readonly options: MultiCompilerOptions = {}\n ) {}\n\n getArtifactDefinition() {\n return [\n {\n generatedBy: this.id,\n name: this.compilerOptions.artifactName || 'dist',\n globPatterns: this.compilerOptions.distGlobPatterns || [\n `${this.distDir}/**`,\n `!${this.distDir}/tsconfig.tsbuildinfo`,\n ],\n },\n ];\n }\n\n private getOptions() {\n const defaultOpts = {\n targetExtension: '.js',\n };\n\n return Object.assign(defaultOpts, this.options);\n }\n\n displayConfig() {\n return this.compilers\n .map((compiler) => {\n return `${compiler.displayName}\\n${compiler.displayConfig}\\n`;\n })\n .join('\\n');\n }\n\n /**\n * the multi-compiler applies all applicable defined compilers on given content.\n */\n transpileFile(fileContent: string, options: TranspileFileParams): TranspileFileOutput {\n const outputs = this.compilers.reduce<any>(\n (files, compiler) => {\n if (!compiler.transpileFile) {\n return files;\n }\n return files?.flatMap((file) => {\n if (!compiler.isFileSupported(file?.outputPath)) return [file];\n const params = Object.assign({}, options, {\n filePath: file.outputPath,\n });\n const compiledContent = compiler.transpileFile?.(file.outputText, params);\n if (!compiledContent) return null;\n\n return compiledContent;\n });\n },\n [{ outputText: fileContent, outputPath: options.filePath }]\n );\n\n return outputs;\n }\n\n async transpileComponent(params: TranspileComponentParams): Promise<void> {\n await Promise.all(\n this.compilers.map((compiler) => {\n return compiler.transpileComponent?.(params);\n })\n );\n }\n\n async build(context: BuildContext): Promise<BuiltTaskResult> {\n const builds = await pMapSeries(this.compilers, async (compiler) => {\n const buildResult = await compiler.build(context);\n return buildResult.componentsResults;\n });\n\n return {\n componentsResults: mergeComponentResults(builds),\n artifacts: this.getArtifactDefinition(),\n };\n }\n\n async preBuild(context: BuildContext) {\n await Promise.all(\n this.compilers.map(async (compiler) => {\n if (!compiler.preBuild) return;\n await compiler.preBuild(context);\n })\n );\n }\n\n async postBuild(context: BuildContext, taskResults: TaskResultsList) {\n await Promise.all(\n this.compilers.map(async (compiler) => {\n if (!compiler.postBuild) return;\n await compiler.postBuild(context, taskResults);\n })\n );\n }\n\n private firstMatchedCompiler(filePath: string): Compiler | undefined {\n return this.compilers.find((compiler) => compiler.isFileSupported(filePath));\n }\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 const matchedCompiler = this.firstMatchedCompiler(srcPath);\n if (!matchedCompiler) {\n return join(this.distDir, srcPath);\n }\n\n return matchedCompiler.getDistPathBySrcPath(srcPath);\n }\n\n /**\n * only supported files matching get compiled. others, are copied to the dist dir.\n */\n isFileSupported(filePath: string): boolean {\n return !!this.firstMatchedCompiler(filePath);\n }\n\n /**\n * returns the version of the current compiler instance (e.g. '4.0.1').\n */\n version(): string {\n return this.compilers\n .map((compiler) => {\n return `${compiler.displayName}@${compiler.version()}`;\n })\n .join('\\n');\n }\n}\n"]}
package/package.json CHANGED
@@ -1,22 +1,22 @@
1
1
  {
2
2
  "name": "@teambit/multi-compiler",
3
- "version": "0.0.651",
3
+ "version": "0.0.654",
4
4
  "homepage": "https://bit.dev/teambit/compilation/multi-compiler",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.compilation",
8
8
  "name": "multi-compiler",
9
- "version": "0.0.651"
9
+ "version": "0.0.654"
10
10
  },
11
11
  "dependencies": {
12
12
  "@teambit/harmony": "0.2.11",
13
13
  "p-map-series": "2.1.0",
14
14
  "@babel/runtime": "7.12.18",
15
15
  "core-js": "^3.0.0",
16
- "@teambit/builder": "0.0.651",
17
- "@teambit/compiler": "0.0.651",
16
+ "@teambit/builder": "0.0.654",
17
+ "@teambit/compiler": "0.0.654",
18
18
  "@teambit/pipelines.modules.merge-component-results": "0.0.485",
19
- "@teambit/cli": "0.0.445"
19
+ "@teambit/cli": "0.0.446"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@types/mocha": "9.1.0",
@@ -28,7 +28,7 @@
28
28
  "@teambit/compilation.aspect-docs.multi-compiler": "0.0.132"
29
29
  },
30
30
  "peerDependencies": {
31
- "@teambit/legacy": "1.0.223",
31
+ "@teambit/legacy": "1.0.225",
32
32
  "react-dom": "^16.8.0 || ^17.0.0",
33
33
  "react": "^16.8.0 || ^17.0.0"
34
34
  },
@@ -56,7 +56,7 @@
56
56
  "react": "-"
57
57
  },
58
58
  "peerDependencies": {
59
- "@teambit/legacy": "1.0.223",
59
+ "@teambit/legacy": "1.0.225",
60
60
  "react-dom": "^16.8.0 || ^17.0.0",
61
61
  "react": "^16.8.0 || ^17.0.0"
62
62
  }