@teambit/multi-compiler 1.0.108 → 1.0.109

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.
@@ -0,0 +1 @@
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["teambit.compilation/multi-compiler-preview"]=t():e["teambit.compilation/multi-compiler-preview"]=t()}(self,(()=>(()=>{"use strict";var e={61515:(e,t,o)=>{var n={id:"teambit.compilation/multi-compiler@1.0.109",homepage:"https://bit.cloud/teambit/compilation/multi-compiler",exported:!0};function r(){const e=i(o(87363));return r=function(){return e},e}function i(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0}),t.Logo=void 0,r.__bit_component=n,i.__bit_component=n;const p=()=>r().default.createElement("div",{style:{height:"100%",display:"flex",justifyContent:"center"}},r().default.createElement("img",{style:{width:70},src:"https://static.bit.dev/extensions-icons/multi-complier.svg"}));p.__bit_component=n,t.Logo=p},6194:(e,t,o)=>{Object.defineProperty(t,"v",{enumerable:!0,get:function(){return n.default}});var n=r(o(2748));function r(e){return e&&e.__esModule?e:{default:e}}r.__bit_component={id:"teambit.compilation/aspect-docs/multi-compiler@0.0.167",homepage:"https://bit.cloud/teambit/compilation/aspect-docs/multi-compiler",exported:!0}},2748:(e,t,o)=>{var n={id:"teambit.compilation/aspect-docs/multi-compiler@0.0.167",homepage:"https://bit.cloud/teambit/compilation/aspect-docs/multi-compiler",exported:!0};Object.defineProperty(t,"__esModule",{value:!0}),t.default=s,p(o(87363));var r=o(40040),i=["components"];function p(e){return e&&e.__esModule?e:{default:e}}function l(){return l=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var n in o)Object.prototype.hasOwnProperty.call(o,n)&&(e[n]=o[n])}return e},l.apply(this,arguments)}function a(e,t){if(null==e)return{};var o,n,r=c(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)o=i[n],t.indexOf(o)>=0||Object.prototype.propertyIsEnumerable.call(e,o)&&(r[o]=e[o])}return r}function c(e,t){if(null==e)return{};var o,n,r={},i=Object.keys(e);for(n=0;n<i.length;n++)o=i[n],t.indexOf(o)>=0||(r[o]=e[o]);return r}p.__bit_component=n,l.__bit_component=n,a.__bit_component=n,c.__bit_component=n;var m={},u="wrapper";function s(e){var t=e.components,o=a(e,i);return(0,r.mdx)(u,l({},m,o,{components:t,mdxType:"MDXLayout"}),(0,r.mdx)("p",null,"The multi-compiler aspect allows the configuration of multiple compilers on a component. This determines which compiler to apply on a component file using the ",(0,r.mdx)("inlineCode",{parentName:"p"},"isFileSupported()")," compiler API."),(0,r.mdx)("ul",null,(0,r.mdx)("li",{parentName:"ul"},(0,r.mdx)("inlineCode",{parentName:"li"},"createCompiler(compilers: Compiler[], options: CompilerOptions)")," API to support the creation a Multi-compiler instance which can be used in the Env API (the ",(0,r.mdx)("inlineCode",{parentName:"li"},"overrideCompiler")," and ",(0,r.mdx)("inlineCode",{parentName:"li"},"getCompiler")," APIs)."),(0,r.mdx)("li",{parentName:"ul"},"Supports the creation of a multi-compiler build tasks.")),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-ts"},"// create a multi compiler instance.\nconst compiler = multiCompiler.createCompiler([createBabelCompiler(), createTsCompiler()]);\n\n// create a multi-compiler build task.\ncompiler.createTask('MultiCompiler', compiler);\n")))}s.__bit_component=n,s.isMDXComponent=!0},40040:e=>{e.exports=MdxJsReact},87363:e=>{e.exports=React}},t={};function o(n){var r=t[n];if(void 0!==r)return r.exports;var i=t[n]={exports:{}};return e[n](i,i.exports,o),i.exports}o.d=(e,t)=>{for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return(()=>{o.r(n),o.d(n,{compositions:()=>s,compositions_metadata:()=>f,overview:()=>d});var e={};o.r(e),o.d(e,{default:()=>u});var t=o(61515),r=(o(87363),o(40040));const i=TeambitMdxUiMdxScopeContext;var p=o(6194),l=["components"];function a(){return a=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var n in o)Object.prototype.hasOwnProperty.call(o,n)&&(e[n]=o[n])}return e},a.apply(this,arguments)}var c={},m="wrapper";function u(e){var t=e.components,o=function(e,t){if(null==e)return{};var o,n,r=function(e,t){if(null==e)return{};var o,n,r={},i=Object.keys(e);for(n=0;n<i.length;n++)o=i[n],t.indexOf(o)>=0||(r[o]=e[o]);return r}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)o=i[n],t.indexOf(o)>=0||Object.prototype.propertyIsEnumerable.call(e,o)&&(r[o]=e[o])}return r}(e,l);return(0,r.mdx)(m,a({},c,o,{components:t,mdxType:"MDXLayout"}),(0,r.mdx)(i.MDXScopeProvider,{components:{MultiCompiler:p.v},mdxType:"MDXScopeProvider"},(0,r.mdx)(p.v,{mdxType:"MultiCompiler"})))}u.isMDXComponent=!0;const s=[t],d=[e],f={compositions:[{displayName:"Logo",identifier:"Logo"}]}})(),n})()));
@@ -1,5 +1,5 @@
1
- import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.compilation_multi-compiler@1.0.108/dist/multi-compiler.composition.js';
2
- import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.compilation_multi-compiler@1.0.108/dist/multi-compiler.docs.mdx';
1
+ import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.compilation_multi-compiler@1.0.109/dist/multi-compiler.composition.js';
2
+ import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.compilation_multi-compiler@1.0.109/dist/multi-compiler.docs.mdx';
3
3
 
4
4
  export const compositions = [compositions_0];
5
5
  export const overview = [overview_0];
package/package.json CHANGED
@@ -1,27 +1,27 @@
1
1
  {
2
2
  "name": "@teambit/multi-compiler",
3
- "version": "1.0.108",
3
+ "version": "1.0.109",
4
4
  "homepage": "https://bit.cloud/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": "1.0.108"
9
+ "version": "1.0.109"
10
10
  },
11
11
  "dependencies": {
12
12
  "p-map-series": "2.1.0",
13
13
  "@teambit/harmony": "0.4.6",
14
- "@teambit/builder": "1.0.108",
15
- "@teambit/compiler": "1.0.108",
16
- "@teambit/component": "1.0.108",
14
+ "@teambit/builder": "1.0.109",
15
+ "@teambit/compiler": "1.0.109",
16
+ "@teambit/component": "1.0.109",
17
17
  "@teambit/pipelines.modules.merge-component-results": "0.0.496",
18
- "@teambit/cli": "0.0.840"
18
+ "@teambit/cli": "0.0.841"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@types/mocha": "9.1.0",
22
22
  "@types/jest": "^29.2.2",
23
23
  "@types/testing-library__jest-dom": "^5.9.5",
24
- "@teambit/harmony.envs.core-aspect-env": "0.0.13",
24
+ "@teambit/harmony.envs.core-aspect-env": "0.0.14",
25
25
  "@teambit/compilation.aspect-docs.multi-compiler": "0.0.167"
26
26
  },
27
27
  "peerDependencies": {
package/index.ts DELETED
@@ -1,6 +0,0 @@
1
- import { MultiCompilerAspect } from './multi-compiler.aspect';
2
-
3
- export { MultiCompilerAspect };
4
- export type { MultiCompilerMain } from './multi-compiler.main.runtime';
5
- export type { MultiCompiler } from './multi-compiler.compiler';
6
- export default MultiCompilerAspect;
@@ -1,5 +0,0 @@
1
- import { Aspect } from '@teambit/harmony';
2
-
3
- export const MultiCompilerAspect = Aspect.create({
4
- id: 'teambit.compilation/multi-compiler',
5
- });
@@ -1,183 +0,0 @@
1
- import { join } from 'path';
2
- import pMapSeries from 'p-map-series';
3
- import {
4
- Compiler,
5
- CompilerOptions,
6
- TranspileComponentParams,
7
- TranspileFileOutput,
8
- TranspileFileParams,
9
- } from '@teambit/compiler';
10
- import { BuiltTaskResult, BuildContext, TaskResultsList } from '@teambit/builder';
11
- import { mergeComponentResults } from '@teambit/pipelines.modules.merge-component-results';
12
- import { Component } from '@teambit/component';
13
-
14
- export type MultiCompilerOptions = {
15
- targetExtension?: string;
16
- };
17
-
18
- export class MultiCompiler implements Compiler {
19
- displayName = 'Multi compiler';
20
-
21
- shouldCopyNonSupportedFiles =
22
- typeof this.compilerOptions.shouldCopyNonSupportedFiles === 'boolean'
23
- ? this.compilerOptions.shouldCopyNonSupportedFiles
24
- : true;
25
- distDir = 'dist';
26
-
27
- constructor(
28
- readonly id: string,
29
- readonly compilers: Compiler[],
30
- readonly compilerOptions: Partial<CompilerOptions> = {},
31
- readonly options: MultiCompilerOptions = {}
32
- ) {}
33
-
34
- getDistDir() {
35
- return this.distDir;
36
- }
37
-
38
- getArtifactDefinition() {
39
- return [
40
- {
41
- generatedBy: this.id,
42
- name: this.compilerOptions.artifactName || 'dist',
43
- globPatterns: this.compilerOptions.distGlobPatterns || [
44
- `${this.distDir}/**`,
45
- `!${this.distDir}/tsconfig.tsbuildinfo`,
46
- ],
47
- },
48
- ];
49
- }
50
-
51
- private getOptions() {
52
- const defaultOpts = {
53
- targetExtension: '.js',
54
- };
55
-
56
- return Object.assign(defaultOpts, this.options);
57
- }
58
-
59
- displayConfig() {
60
- return this.compilers
61
- .map((compiler) => {
62
- return `${compiler.displayName}\n${compiler.displayConfig}\n`;
63
- })
64
- .join('\n');
65
- }
66
-
67
- /**
68
- * the multi-compiler applies all applicable defined compilers on given content.
69
- */
70
- async transpileFile(fileContent: string, options: TranspileFileParams): Promise<TranspileFileOutput> {
71
- const outputs: TranspileFileOutput = await this.compilers.reduce<Promise<TranspileFileOutput>>(
72
- async (files: Promise<TranspileFileOutput>, compiler: Compiler) => {
73
- if (!compiler.transpileFile) {
74
- return files;
75
- }
76
- const filesToTranspile = await files;
77
- if (!filesToTranspile) return null;
78
- const flatMap = (
79
- await pMapSeries(filesToTranspile, async (file) => {
80
- if (!compiler.isFileSupported(file?.outputPath)) return [file];
81
- if (!compiler.transpileFile) return [];
82
- const params = Object.assign({}, options, {
83
- filePath: file.outputPath,
84
- });
85
- const compiledContent = await compiler.transpileFile(file.outputText, params);
86
- if (compiledContent) {
87
- return compiledContent;
88
- }
89
- return [];
90
- })
91
- ).flat();
92
- return flatMap;
93
- },
94
- Promise.resolve([{ outputText: fileContent, outputPath: options.filePath }] as TranspileFileOutput)
95
- );
96
- return outputs;
97
- }
98
-
99
- async transpileComponent(params: TranspileComponentParams): Promise<void> {
100
- await Promise.all(
101
- this.compilers.map((compiler) => {
102
- return compiler.transpileComponent?.(params);
103
- })
104
- );
105
- }
106
-
107
- async build(context: BuildContext): Promise<BuiltTaskResult> {
108
- const builds = await pMapSeries(this.compilers, async (compiler) => {
109
- const buildResult = await compiler.build(context);
110
- return buildResult.componentsResults;
111
- });
112
-
113
- return {
114
- componentsResults: mergeComponentResults(builds),
115
- artifacts: this.getArtifactDefinition(),
116
- };
117
- }
118
-
119
- async preBuild(context: BuildContext) {
120
- await Promise.all(
121
- this.compilers.map(async (compiler) => {
122
- if (!compiler.preBuild) return;
123
- await compiler.preBuild(context);
124
- })
125
- );
126
- }
127
-
128
- async postBuild(context: BuildContext, taskResults: TaskResultsList) {
129
- await Promise.all(
130
- this.compilers.map(async (compiler) => {
131
- if (!compiler.postBuild) return;
132
- await compiler.postBuild(context, taskResults);
133
- })
134
- );
135
- }
136
-
137
- private firstMatchedCompiler(filePath: string): Compiler | undefined {
138
- return this.compilers.find((compiler) => compiler.isFileSupported(filePath));
139
- }
140
-
141
- getPreviewComponentRootPath(component: Component): string {
142
- const matchedCompiler = this.compilers.find(
143
- (compiler) => typeof compiler.getPreviewComponentRootPath !== 'undefined'
144
- );
145
- if (!matchedCompiler) {
146
- return '';
147
- }
148
-
149
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
150
- return matchedCompiler.getPreviewComponentRootPath!(component);
151
- }
152
-
153
- /**
154
- * given a source file, return its parallel in the dists. e.g. "index.ts" => "dist/index.js"
155
- * both, the return path and the given path are relative paths.
156
- */
157
- getDistPathBySrcPath(srcPath: string): string {
158
- const matchedCompiler = this.firstMatchedCompiler(srcPath);
159
- if (!matchedCompiler) {
160
- return join(this.distDir, srcPath);
161
- }
162
-
163
- return matchedCompiler.getDistPathBySrcPath(srcPath);
164
- }
165
-
166
- /**
167
- * only supported files matching get compiled. others, are copied to the dist dir.
168
- */
169
- isFileSupported(filePath: string): boolean {
170
- return !!this.firstMatchedCompiler(filePath);
171
- }
172
-
173
- /**
174
- * returns the version of the current compiler instance (e.g. '4.0.1').
175
- */
176
- version(): string {
177
- return this.compilers
178
- .map((compiler) => {
179
- return `${compiler.displayName}@${compiler.version()}`;
180
- })
181
- .join('\n');
182
- }
183
- }
@@ -1,22 +0,0 @@
1
- import { MainRuntime } from '@teambit/cli';
2
- import { Compiler, CompilerOptions } from '@teambit/compiler';
3
- import { MultiCompilerAspect } from './multi-compiler.aspect';
4
- import { MultiCompiler } from './multi-compiler.compiler';
5
-
6
- export class MultiCompilerMain {
7
- /**
8
- * create a multi-compiler `Compiler` instance.
9
- * @param compilers list of compilers to include.
10
- */
11
- createCompiler(compilers: Compiler[], options: Partial<CompilerOptions> = {}) {
12
- return new MultiCompiler(MultiCompilerAspect.id, compilers, options, {});
13
- }
14
-
15
- static runtime = MainRuntime;
16
-
17
- static async provider() {
18
- return new MultiCompilerMain();
19
- }
20
- }
21
-
22
- MultiCompilerAspect.addRuntime(MultiCompilerMain);