@teambit/multi-compiler 0.0.679 → 0.0.682

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,5 +1,6 @@
1
1
  import { Compiler, CompilerOptions, TranspileComponentParams, TranspileFileOutput, TranspileFileParams } from '@teambit/compiler';
2
2
  import { BuiltTaskResult, BuildContext, TaskResultsList } from '@teambit/builder';
3
+ import { Component } from '@teambit/component';
3
4
  export declare type MultiCompilerOptions = {
4
5
  targetExtension?: string;
5
6
  };
@@ -28,6 +29,7 @@ export declare class MultiCompiler implements Compiler {
28
29
  preBuild(context: BuildContext): Promise<void>;
29
30
  postBuild(context: BuildContext, taskResults: TaskResultsList): Promise<void>;
30
31
  private firstMatchedCompiler;
32
+ getPreviewComponentRootPath(component: Component): string;
31
33
  /**
32
34
  * given a source file, return its parallel in the dists. e.g. "index.ts" => "dist/index.js"
33
35
  * both, the return path and the given path are relative paths.
@@ -151,6 +151,16 @@ class MultiCompiler {
151
151
  firstMatchedCompiler(filePath) {
152
152
  return this.compilers.find(compiler => compiler.isFileSupported(filePath));
153
153
  }
154
+
155
+ getPreviewComponentRootPath(component) {
156
+ const matchedCompiler = this.compilers.find(compiler => typeof compiler.getPreviewComponentRootPath !== 'undefined');
157
+
158
+ if (!matchedCompiler) {
159
+ return '';
160
+ }
161
+
162
+ return matchedCompiler.getPreviewComponentRootPath(component);
163
+ }
154
164
  /**
155
165
  * given a source file, return its parallel in the dists. e.g. "index.ts" => "dist/index.js"
156
166
  * both, the return path and the given path are relative paths.
@@ -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","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,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;AACEC,MAAAA,WAAW,EAAE,KAAKN,EADpB;AAEEO,MAAAA,IAAI,EAAE,KAAKL,eAAL,CAAqBM,YAArB,IAAqC,MAF7C;AAGEC,MAAAA,YAAY,EAAE,KAAKP,eAAL,CAAqBQ,gBAArB,IAAyC,CACpD,GAAE,KAAKC,OAAQ,KADqC,EAEpD,IAAG,KAAKA,OAAQ,uBAFoC;AAHzD,KADK,CAAP;AAUD;;AAEOC,EAAAA,UAAU,GAAG;AACnB,UAAMC,WAAW,GAAG;AAClBC,MAAAA,eAAe,EAAE;AADC,KAApB;AAIA,WAAOC,MAAM,CAACC,MAAP,CAAcH,WAAd,EAA2B,KAAKV,OAAhC,CAAP;AACD;;AAEDc,EAAAA,aAAa,GAAG;AACd,WAAO,KAAKhB,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AACA;AACA;;;AACEiB,EAAAA,oBAAoB,CAACC,OAAD,EAA0B;AAC5C,UAAMC,eAAe,GAAG,KAAKJ,oBAAL,CAA0BG,OAA1B,CAAxB;;AACA,QAAI,CAACC,eAAL,EAAsB;AACpB,aAAO,kBAAK,KAAKxC,OAAV,EAAmBuC,OAAnB,CAAP;AACD;;AAED,WAAOC,eAAe,CAACF,oBAAhB,CAAqCC,OAArC,CAAP;AACD;AAED;AACF;AACA;;;AACErB,EAAAA,eAAe,CAACG,QAAD,EAA4B;AACzC,WAAO,CAAC,CAAC,KAAKe,oBAAL,CAA0Bf,QAA1B,CAAT;AACD;AAED;AACF;AACA;;;AACEoB,EAAAA,OAAO,GAAW;AAChB,WAAO,KAAKnD,SAAL,CACJiB,GADI,CACCC,QAAD,IAAc;AACjB,aAAQ,GAAEA,QAAQ,CAACC,WAAY,IAAGD,QAAQ,CAACiC,OAAT,EAAmB,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"]}
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","getPreviewComponentRootPath","component","matchedCompiler","getDistPathBySrcPath","srcPath","version"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AASA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAOO,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,GAD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AArC,CAAP;AACD;AAED;AACF;AACA;;;AACExB,EAAAA,eAAe,CAACG,QAAD,EAA4B;AACzC,WAAO,CAAC,CAAC,KAAKe,oBAAL,CAA0Bf,QAA1B,CAAT;AACD;AAED;AACF;AACA;;;AACEsB,EAAAA,OAAO,GAAW;AAChB,WAAO,KAAKrD,SAAL,CACJiB,GADI,CACCC,QAAD,IAAc;AACjB,aAAQ,GAAEA,QAAQ,CAACC,WAAY,IAAGD,QAAQ,CAACmC,OAAT,EAAmB,EAArD;AACD,KAHI,EAIJjC,IAJI,CAIC,IAJD,CAAP;AAKD;;AAzJ4C","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';\nimport { Component } from '@teambit/component';\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 getPreviewComponentRootPath(component: Component): string {\n const matchedCompiler = this.compilers.find(\n (compiler) => typeof compiler.getPreviewComponentRootPath !== 'undefined'\n );\n if (!matchedCompiler) {\n return '';\n }\n\n return matchedCompiler.getPreviewComponentRootPath!(component);\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,23 @@
1
1
  {
2
2
  "name": "@teambit/multi-compiler",
3
- "version": "0.0.679",
3
+ "version": "0.0.682",
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.679"
9
+ "version": "0.0.682"
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.679",
17
- "@teambit/compiler": "0.0.679",
16
+ "@teambit/builder": "0.0.682",
17
+ "@teambit/compiler": "0.0.682",
18
+ "@teambit/component": "0.0.682",
18
19
  "@teambit/pipelines.modules.merge-component-results": "0.0.485",
19
- "@teambit/cli": "0.0.454"
20
+ "@teambit/cli": "0.0.456"
20
21
  },
21
22
  "devDependencies": {
22
23
  "@types/mocha": "9.1.0",
@@ -28,7 +29,7 @@
28
29
  "@teambit/compilation.aspect-docs.multi-compiler": "0.0.134"
29
30
  },
30
31
  "peerDependencies": {
31
- "@teambit/legacy": "1.0.233",
32
+ "@teambit/legacy": "1.0.235",
32
33
  "react-dom": "^16.8.0 || ^17.0.0",
33
34
  "react": "^16.8.0 || ^17.0.0"
34
35
  },
@@ -56,7 +57,7 @@
56
57
  "react": "-"
57
58
  },
58
59
  "peerDependencies": {
59
- "@teambit/legacy": "1.0.233",
60
+ "@teambit/legacy": "1.0.235",
60
61
  "react-dom": "^16.8.0 || ^17.0.0",
61
62
  "react": "^16.8.0 || ^17.0.0"
62
63
  }
@@ -1 +1 @@
1
- export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.compilation_multi-compiler@0.0.679/dist/multi-compiler.docs.mdx')]
1
+ export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.compilation_multi-compiler@0.0.682/dist/multi-compiler.docs.mdx')]