@teambit/compiler 1.0.108 → 1.0.110
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/artifacts/preview/teambit_compilation_compiler-preview.js +1 -0
- package/dist/{preview-1703647408454.js → preview-1703733956734.js} +2 -2
- package/package.json +27 -23
- package/compiler-env-type.ts +0 -9
- package/compiler.aspect.ts +0 -5
- package/compiler.cmd.ts +0 -121
- package/compiler.main.runtime.ts +0 -191
- package/compiler.task.ts +0 -104
- package/dist-artifact.ts +0 -12
- package/index.ts +0 -15
- package/output-formatter.ts +0 -20
- package/types.ts +0 -154
- package/workspace-compiler.ts +0 -398
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports["teambit.compilation/compiler-preview"]=n():e["teambit.compilation/compiler-preview"]=n()}(self,(()=>(()=>{"use strict";var e={73375:(e,n,t)=>{var o={id:"teambit.compilation/compiler@1.0.110",homepage:"https://bit.cloud/teambit/compilation/compiler",exported:!0};function i(){const e=r(t(87363));return i=function(){return e},e}function r(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(n,"__esModule",{value:!0}),n.Logo=void 0,i.__bit_component=o,r.__bit_component=o;const a=()=>i().default.createElement("div",{style:{height:"100%",display:"flex",justifyContent:"center"}},i().default.createElement("img",{style:{width:70},src:"https://static.bit.dev/extensions-icons/compiler.svg"}));a.__bit_component=o,n.Logo=a},36858:(e,n,t)=>{var o={id:"teambit.compilation/content/compiler-overview@1.95.0",homepage:"https://bit.dev/teambit/compilation/content/compiler-overview",exported:!0};Object.defineProperty(n,"__esModule",{value:!0}),n.default=u,p(t(87363));var i=t(40040),r=t(70500),a=["components"];function p(e){return e&&e.__esModule?e:{default:e}}function m(){return m=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},m.apply(this,arguments)}function l(e,n){if(null==e)return{};var t,o,i=d(e,n);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);for(o=0;o<r.length;o++)t=r[o],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(i[t]=e[t])}return i}function d(e,n){if(null==e)return{};var t,o,i={},r=Object.keys(e);for(o=0;o<r.length;o++)t=r[o],n.indexOf(t)>=0||(i[t]=e[t]);return i}p.__bit_component=o,m.__bit_component=o,l.__bit_component=o,d.__bit_component=o;var c={},s="wrapper";function u(e){var n=e.components,t=l(e,a);return(0,i.mdx)(s,m({},c,t,{components:n,mdxType:"MDXLayout"}),(0,i.mdx)(r.MDXScopeProvider,{components:{},mdxType:"MDXScopeProvider"},(0,i.mdx)("h1",null,"Compiler overview"),(0,i.mdx)("p",null,"The Compiler aspect provides a single interface for Component compilation, ",(0,i.mdx)("a",{parentName:"p",href:"/"},"during development")," and ",(0,i.mdx)("a",{parentName:"p",href:"/"},"during build"),".\nIt enables you to use the same commands and APIs to compile any Component, regardless of the specific compiler it uses."),(0,i.mdx)("div",{className:"admonition admonition-info alert alert--info"},(0,i.mdx)("div",{parentName:"div",className:"admonition-heading"},(0,i.mdx)("h5",{parentName:"div"},(0,i.mdx)("span",{parentName:"h5",className:"admonition-icon"},(0,i.mdx)("svg",{parentName:"span",xmlns:"http://www.w3.org/2000/svg",width:"14",height:"16",viewBox:"0 0 14 16"},(0,i.mdx)("path",{parentName:"svg",fillRule:"evenodd",d:"M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"}))),"info")),(0,i.mdx)("div",{parentName:"div",className:"admonition-content"},(0,i.mdx)("p",{parentName:"div"},"The specific compiler used by a Component (",(0,i.mdx)("a",{parentName:"p",href:"/"},"Babel"),", ",(0,i.mdx)("a",{parentName:"p",href:"/"},"TypeScript"),", and so on) is set by the Component's Env."))),(0,i.mdx)("h2",null,"Compiling during development"),(0,i.mdx)("p",null,"Run the following to compile all your Workspace Components:"),(0,i.mdx)("pre",null,(0,i.mdx)("code",{parentName:"pre",className:"language-bash"},"bit compile\n")),(0,i.mdx)("p",null,"The following output lists the compilation results in a single format:"),(0,i.mdx)("pre",null,(0,i.mdx)("code",{parentName:"pre",className:"language-bash"}," STATUS COMPONENT ID\n✔ SUCCESS apps/bit-dev\n✔ SUCCESS blocks/component/architecture-breakdown\n✔ SUCCESS blocks/footer\n✔ SUCCESS blocks/header\n✔ SUCCESS buttons/button\n✔ SUCCESS content/adding-components\n")),(0,i.mdx)("p",null,"To 'watch' Components for changes, and to auto-compile modified Components, run:"),(0,i.mdx)("pre",null,(0,i.mdx)("code",{parentName:"pre"},"bit watch\n")),(0,i.mdx)("p",null,"The compiled code is written into each Component's corresponding package, in the ",(0,i.mdx)("a",{parentName:"p",href:"/dependencies/node-modules"},(0,i.mdx)("inlineCode",{parentName:"a"},"node_modules")," directory")," of your workspace.\nFor example, the compiled code for ",(0,i.mdx)("inlineCode",{parentName:"p"},"company.scope/ui/text")," will be found in the ",(0,i.mdx)("inlineCode",{parentName:"p"},"./node_modules/@company/scope.ui.text/dist")," directory (inside your workspace)."),(0,i.mdx)("p",null,"To learn more about compilation in the Workspace, see ",(0,i.mdx)("a",{parentName:"p",href:"/"},"'Compiling during development'"),"."),(0,i.mdx)("h2",null,"Compiling during build"),(0,i.mdx)("p",null,"Run the following to compile Components as part of the ",(0,i.mdx)("a",{parentName:"p",href:"/"},"build pipeline")," (which prepares Components for distribution):"),(0,i.mdx)("pre",null,(0,i.mdx)("code",{parentName:"pre",className:"language-bash"},"bit build\n")),(0,i.mdx)("p",null,"The output to the terminal details the specific compilers being used, as well as the Envs that use them:"),(0,i.mdx)("pre",null,(0,i.mdx)("code",{parentName:"pre",className:"language-bash"},'...\n✔ env "teambit.harmony/aspect", task "teambit.compilation/compiler:BabelCompiler (compile components for artifact dist)" has completed successfully in 363ms\n✔ env "teambit.react/react", task "teambit.compilation/compiler:TSCompiler (compile components for artifact dist)" has completed successfully in 1s\n✔ env "teambit.mdx/mdx", task "teambit.compilation/compiler:MDXCompiler (compile components)" has completed successfully in 879ms\n...\nthe build has been completed. total: 19 tasks\n')),(0,i.mdx)("p",null,"The compiled code is written into the ",(0,i.mdx)("a",{parentName:"p",href:"/"},"Component's Capsule"),". Run ",(0,i.mdx)("a",{parentName:"p",href:"/"},(0,i.mdx)("inlineCode",{parentName:"a"},"bit snap"))," or ",(0,i.mdx)("a",{parentName:"p",href:"/"},(0,i.mdx)("inlineCode",{parentName:"a"},"bit tag"))," to execute the build pipeline (as well as other pipelines), and have the compiled code persisted in the ",(0,i.mdx)("a",{parentName:"p",href:"/"},"Component version"),", and included in the ",(0,i.mdx)("a",{parentName:"p",href:"/"},"Component's package"),"."),(0,i.mdx)("p",null,"To learn more about compilation in the Workspace, see ",(0,i.mdx)("a",{parentName:"p",href:"/"},"'Compiling during build'"),"."),(0,i.mdx)("h2",null,"Compilation strategies and standards"),(0,i.mdx)("p",null,"The Compiler aspect does not set specific compilation strategies as these are defined by the ",(0,i.mdx)("a",{parentName:"p",href:"/"},"specific compilers")," themselves (and are often configurable by the Envs that use them)."),(0,i.mdx)("p",null,"However, all official Bit compilers are configured to favor dev experience when compiling during development, and to favor runtime performance and code universality, when compiling for distribution (during build)."),(0,i.mdx)("p",null,"For example, Bit's ",(0,i.mdx)("a",{parentName:"p",href:"/"},"TypeScript compiler")," performs type-checking when compiling during build but skips it when compiling during development.\nThis enables faster compilation and better dev experience."),(0,i.mdx)("p",null,"To examine a Component's specific compiler config, run the following:"),(0,i.mdx)("pre",null,(0,i.mdx)("code",{parentName:"pre"},"bit env get COMPONENT_ID\n")),(0,i.mdx)("p",null,"For example:"),(0,i.mdx)("pre",null,(0,i.mdx)("code",{parentName:"pre"},"bit env get company.demo/ui/card\n")),(0,i.mdx)("p",null,"The output details the Component's env config which includes the compiler config:"),(0,i.mdx)("pre",null,(0,i.mdx)("code",{parentName:"pre",className:"language-bash"},'Environment: teambit.react/react\n...\nteambit.compilation/compiler\n\nconfigured compiler: teambit.typescript/typescript (TypeScript @ 4.4.2)\ncompiler config:\n{\n "compilerOptions": {\n "lib": [\n "es2019",\n "DOM",\n "ES6",\n "DOM.Iterable"\n ],\n "target": "es2015",\n "module": "commonjs",\n "jsx": "react",\n "declaration": true,\n "sourceMap": true,\n "skipLibCheck": true,\n "moduleResolution": "node",\n "esModuleInterop": true,\n "resolveJsonModule": true,\n "outDir": "dist"\n },\n "exclude": [\n "dist"\n ]\n}\n\n')),(0,i.mdx)("h2",null,"Setting a Component with a specific compiler"),(0,i.mdx)("p",null,"Specific compilers are applied on Components via the Components' Envs. For example, the ",(0,i.mdx)("inlineCode",{parentName:"p"},"company.demo/ui/card")," Component examined earlier, is applied with\nthe ",(0,i.mdx)("a",{parentName:"p",href:"/"},"TypeScript")," compiler by its Env, the React Env."),(0,i.mdx)("p",null,"To learn how to use a specific compiler, see ",(0,i.mdx)("a",{parentName:"p",href:"/"},"'Using compilers'"),".")))}u.__bit_component=o,u.isMDXComponent=!0},13681:(e,n,t)=>{Object.defineProperty(n,"ZP",{enumerable:!0,get:function(){return o.default}});var o=i(t(36858));function i(e){return e&&e.__esModule?e:{default:e}}i.__bit_component={id:"teambit.compilation/content/compiler-overview@1.95.0",homepage:"https://bit.dev/teambit/compilation/content/compiler-overview",exported:!0}},40040:e=>{e.exports=MdxJsReact},87363:e=>{e.exports=React},70500:e=>{e.exports=TeambitMdxUiMdxScopeContext}},n={};function t(o){var i=n[o];if(void 0!==i)return i.exports;var r=n[o]={exports:{}};return e[o](r,r.exports,t),r.exports}t.d=(e,n)=>{for(var o in n)t.o(n,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:n[o]})},t.o=(e,n)=>Object.prototype.hasOwnProperty.call(e,n),t.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return(()=>{t.r(o),t.d(o,{compositions:()=>s,compositions_metadata:()=>f,overview:()=>u});var e={};t.r(e),t.d(e,{default:()=>c});var n=t(73375),i=(t(87363),t(40040)),r=t(70500),a=t(13681),p=["components"];function m(){return m=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},m.apply(this,arguments)}var l={},d="wrapper";function c(e){var n=e.components,t=function(e,n){if(null==e)return{};var t,o,i=function(e,n){if(null==e)return{};var t,o,i={},r=Object.keys(e);for(o=0;o<r.length;o++)t=r[o],n.indexOf(t)>=0||(i[t]=e[t]);return i}(e,n);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);for(o=0;o<r.length;o++)t=r[o],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(i[t]=e[t])}return i}(e,p);return(0,i.mdx)(d,m({},l,t,{components:n,mdxType:"MDXLayout"}),(0,i.mdx)(r.MDXScopeProvider,{components:{CompilerOverview:a.ZP},mdxType:"MDXScopeProvider"},(0,i.mdx)(a.ZP,{mdxType:"CompilerOverview"})))}c.isMDXComponent=!0;const s=[n],u=[e],f={compositions:[{displayName:"Logo",identifier:"Logo"}]}})(),o})()));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.compilation_compiler@1.0.
|
|
2
|
-
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.compilation_compiler@1.0.
|
|
1
|
+
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.compilation_compiler@1.0.110/dist/compiler.composition.js';
|
|
2
|
+
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.compilation_compiler@1.0.110/dist/compiler.docs.mdx';
|
|
3
3
|
|
|
4
4
|
export const compositions = [compositions_0];
|
|
5
5
|
export const overview = [overview_0];
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/compiler",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.110",
|
|
4
4
|
"homepage": "https://bit.cloud/teambit/compilation/compiler",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.compilation",
|
|
8
8
|
"name": "compiler",
|
|
9
|
-
"version": "1.0.
|
|
9
|
+
"version": "1.0.110"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"chalk": "2.4.2",
|
|
@@ -20,24 +20,24 @@
|
|
|
20
20
|
"@teambit/component-id": "1.2.0",
|
|
21
21
|
"@teambit/bit-roots": "0.0.133",
|
|
22
22
|
"@teambit/bit-error": "0.0.404",
|
|
23
|
-
"@teambit/envs": "1.0.
|
|
24
|
-
"@teambit/cli": "0.0.
|
|
25
|
-
"@teambit/component": "1.0.
|
|
26
|
-
"@teambit/logger": "0.0.
|
|
27
|
-
"@teambit/pubsub": "1.0.
|
|
28
|
-
"@teambit/aspect-loader": "1.0.
|
|
29
|
-
"@teambit/builder": "1.0.
|
|
23
|
+
"@teambit/envs": "1.0.110",
|
|
24
|
+
"@teambit/cli": "0.0.842",
|
|
25
|
+
"@teambit/component": "1.0.110",
|
|
26
|
+
"@teambit/logger": "0.0.935",
|
|
27
|
+
"@teambit/pubsub": "1.0.110",
|
|
28
|
+
"@teambit/aspect-loader": "1.0.110",
|
|
29
|
+
"@teambit/builder": "1.0.110",
|
|
30
30
|
"@teambit/component-issues": "0.0.138",
|
|
31
|
-
"@teambit/dependency-resolver": "1.0.
|
|
32
|
-
"@teambit/generator": "1.0.
|
|
33
|
-
"@teambit/issues": "1.0.
|
|
34
|
-
"@teambit/ui": "1.0.
|
|
35
|
-
"@teambit/watcher": "1.0.
|
|
36
|
-
"@teambit/workspace": "1.0.
|
|
37
|
-
"@teambit/isolator": "1.0.
|
|
31
|
+
"@teambit/dependency-resolver": "1.0.110",
|
|
32
|
+
"@teambit/generator": "1.0.111",
|
|
33
|
+
"@teambit/issues": "1.0.110",
|
|
34
|
+
"@teambit/ui": "1.0.110",
|
|
35
|
+
"@teambit/watcher": "1.0.110",
|
|
36
|
+
"@teambit/workspace": "1.0.110",
|
|
37
|
+
"@teambit/isolator": "1.0.110",
|
|
38
38
|
"@teambit/toolbox.fs.hard-link-directory": "0.0.19",
|
|
39
|
-
"@teambit/multi-compiler": "1.0.
|
|
40
|
-
"@teambit/workspace.modules.node-modules-linker": "0.0.
|
|
39
|
+
"@teambit/multi-compiler": "1.0.110",
|
|
40
|
+
"@teambit/workspace.modules.node-modules-linker": "0.0.159"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/fs-extra": "9.0.7",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@types/jest": "^29.2.2",
|
|
47
47
|
"@types/testing-library__jest-dom": "^5.9.5",
|
|
48
48
|
"@teambit/compilation.content.compiler-overview": "1.95.0",
|
|
49
|
-
"@teambit/harmony.envs.core-aspect-env": "0.0.
|
|
49
|
+
"@teambit/harmony.envs.core-aspect-env": "0.0.15"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"react": "^17.0.0 || ^18.0.0",
|
|
@@ -57,11 +57,15 @@
|
|
|
57
57
|
"optionalDependencies": {},
|
|
58
58
|
"peerDependenciesMeta": {},
|
|
59
59
|
"exports": {
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
|
|
60
|
+
".": {
|
|
61
|
+
"node": {
|
|
62
|
+
"require": "./dist/index.js",
|
|
63
|
+
"import": "./dist/esm.mjs"
|
|
64
|
+
},
|
|
65
|
+
"default": "./dist/index.js"
|
|
63
66
|
},
|
|
64
|
-
"
|
|
67
|
+
"./dist/*": "./dist/*",
|
|
68
|
+
"./artifacts/*": "./artifacts/*"
|
|
65
69
|
},
|
|
66
70
|
"private": false,
|
|
67
71
|
"engines": {
|
package/compiler-env-type.ts
DELETED
package/compiler.aspect.ts
DELETED
package/compiler.cmd.ts
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { Command, CommandOptions } from '@teambit/cli';
|
|
2
|
-
import { Logger } from '@teambit/logger';
|
|
3
|
-
import type { PubsubMain, BitBaseEvent } from '@teambit/pubsub';
|
|
4
|
-
import chalk from 'chalk';
|
|
5
|
-
import prettyTime from 'pretty-time';
|
|
6
|
-
import { Component } from '@teambit/component';
|
|
7
|
-
import { formatCompileResults } from './output-formatter';
|
|
8
|
-
import { CompileError, WorkspaceCompiler, CompileOptions } from './workspace-compiler';
|
|
9
|
-
import { CompilationInitiator } from './types';
|
|
10
|
-
|
|
11
|
-
// IDs & events
|
|
12
|
-
import { CompilerAspect } from './compiler.aspect';
|
|
13
|
-
import { ComponentCompilationOnDoneEvent } from './events';
|
|
14
|
-
|
|
15
|
-
export type ComponentsStatus = {
|
|
16
|
-
buildResults: string[];
|
|
17
|
-
component: Component;
|
|
18
|
-
errors: CompileError[];
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export class CompileCmd implements Command {
|
|
22
|
-
componentsStatus: ComponentsStatus[] = [];
|
|
23
|
-
name = 'compile [component-names...]';
|
|
24
|
-
description = 'compile components in the workspace';
|
|
25
|
-
helpUrl = 'reference/compiling/compiler-overview';
|
|
26
|
-
arguments = [
|
|
27
|
-
{
|
|
28
|
-
name: 'component-names...',
|
|
29
|
-
description: 'a list of component names or component IDs (defaults to all components)',
|
|
30
|
-
},
|
|
31
|
-
];
|
|
32
|
-
alias = '';
|
|
33
|
-
group = 'development';
|
|
34
|
-
options = [
|
|
35
|
-
['c', 'changed', 'compile only new and modified components'],
|
|
36
|
-
['v', 'verbose', 'show more data, such as, dist paths'],
|
|
37
|
-
['j', 'json', 'return the compile results in json format'],
|
|
38
|
-
['d', 'delete-dist-dir', 'delete existing dist folder before writing new compiled files'],
|
|
39
|
-
] as CommandOptions;
|
|
40
|
-
|
|
41
|
-
constructor(private compile: WorkspaceCompiler, private logger: Logger, private pubsub: PubsubMain) {}
|
|
42
|
-
|
|
43
|
-
async report([components = []]: [string[]], compilerOptions: CompileOptions) {
|
|
44
|
-
const startTimestamp = process.hrtime();
|
|
45
|
-
this.logger.setStatusLine('Compiling your components, hold tight.');
|
|
46
|
-
this.pubsub.sub(CompilerAspect.id, this.onComponentCompilationDone.bind(this));
|
|
47
|
-
|
|
48
|
-
let outputString = '';
|
|
49
|
-
await this.compile.compileComponents(components, {
|
|
50
|
-
...compilerOptions,
|
|
51
|
-
initiator: CompilationInitiator.CmdReport,
|
|
52
|
-
});
|
|
53
|
-
const compileTimeLength = process.hrtime(startTimestamp);
|
|
54
|
-
|
|
55
|
-
outputString += '\n';
|
|
56
|
-
outputString += ` ${chalk.underline('STATUS')}\t${chalk.underline('COMPONENT ID')}\n`;
|
|
57
|
-
outputString += formatCompileResults(this.componentsStatus, !!compilerOptions.verbose);
|
|
58
|
-
outputString += '\n';
|
|
59
|
-
|
|
60
|
-
outputString += this.getStatusLine(this.componentsStatus, compileTimeLength);
|
|
61
|
-
|
|
62
|
-
this.logger.clearStatusLine();
|
|
63
|
-
|
|
64
|
-
return {
|
|
65
|
-
data: outputString,
|
|
66
|
-
code: this.getExitCode(this.componentsStatus),
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
async json([components]: [string[]], compilerOptions: CompileOptions) {
|
|
71
|
-
compilerOptions.deleteDistDir = true;
|
|
72
|
-
// @ts-ignore
|
|
73
|
-
const compileResults = await this.compile.compileComponents(components, {
|
|
74
|
-
...compilerOptions,
|
|
75
|
-
initiator: CompilationInitiator.CmdJson,
|
|
76
|
-
});
|
|
77
|
-
return {
|
|
78
|
-
data: compileResults,
|
|
79
|
-
// @todo: fix the code once compile is ready.
|
|
80
|
-
code: 0,
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
private failedComponents(componentsStatus: ComponentsStatus[]): ComponentsStatus[] {
|
|
85
|
-
return componentsStatus.filter((component) => component.errors.length);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
private getSummaryIcon(componentsStatus: ComponentsStatus[]) {
|
|
89
|
-
switch (this.failedComponents(componentsStatus).length) {
|
|
90
|
-
case 0:
|
|
91
|
-
return chalk.green('✔');
|
|
92
|
-
case componentsStatus.length:
|
|
93
|
-
return chalk.red('✗');
|
|
94
|
-
default:
|
|
95
|
-
return chalk.yellow('⍻');
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
private getExitCode(componentsStatus: ComponentsStatus[]) {
|
|
100
|
-
return this.failedComponents(componentsStatus).length ? 1 : 0;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
private getStatusLine(componentsStatus: ComponentsStatus[], compileTimeLength) {
|
|
104
|
-
const numberOfComponents = componentsStatus.length;
|
|
105
|
-
const numberOfFailingComponents = this.failedComponents(componentsStatus).length;
|
|
106
|
-
const numberOfSuccessfulComponents = componentsStatus.filter((component) => !component.errors.length).length;
|
|
107
|
-
|
|
108
|
-
const icon = this.getSummaryIcon(componentsStatus);
|
|
109
|
-
const summaryLine = numberOfFailingComponents
|
|
110
|
-
? `${icon} ${numberOfFailingComponents}/${numberOfComponents} components failed to compile.`
|
|
111
|
-
: `${icon} ${numberOfSuccessfulComponents}/${numberOfComponents} components compiled successfully.`;
|
|
112
|
-
|
|
113
|
-
return `${summaryLine}\nFinished. (${prettyTime(compileTimeLength)})`;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
private onComponentCompilationDone(event: BitBaseEvent<any>) {
|
|
117
|
-
if (event.type === ComponentCompilationOnDoneEvent.TYPE) {
|
|
118
|
-
this.componentsStatus.push(event.data);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
package/compiler.main.runtime.ts
DELETED
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import * as path from 'path';
|
|
2
|
-
import fs from 'fs-extra';
|
|
3
|
-
import AspectLoaderAspect, { AspectLoaderMain } from '@teambit/aspect-loader';
|
|
4
|
-
import { BuilderAspect, BuilderMain } from '@teambit/builder';
|
|
5
|
-
import { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';
|
|
6
|
-
import { IssuesClasses } from '@teambit/component-issues';
|
|
7
|
-
import IssuesAspect, { IssuesMain } from '@teambit/issues';
|
|
8
|
-
import { Component } from '@teambit/component';
|
|
9
|
-
import { DEFAULT_DIST_DIRNAME } from '@teambit/legacy/dist/constants';
|
|
10
|
-
import WatcherAspect, { WatcherMain } from '@teambit/watcher';
|
|
11
|
-
import { EnvsAspect, EnvsMain, ExecutionContext } from '@teambit/envs';
|
|
12
|
-
import { ComponentID } from '@teambit/component-id';
|
|
13
|
-
import { DependencyResolverAspect, DependencyResolverMain } from '@teambit/dependency-resolver';
|
|
14
|
-
import { LoggerAspect, LoggerMain } from '@teambit/logger';
|
|
15
|
-
import { GeneratorAspect, GeneratorMain } from '@teambit/generator';
|
|
16
|
-
import { PubsubAspect, PubsubMain } from '@teambit/pubsub';
|
|
17
|
-
import UIAspect, { UiMain } from '@teambit/ui';
|
|
18
|
-
import { Workspace, WorkspaceAspect } from '@teambit/workspace';
|
|
19
|
-
import { CompilerAspect } from './compiler.aspect';
|
|
20
|
-
import { CompileCmd } from './compiler.cmd';
|
|
21
|
-
import { CompilerService } from './compiler.service';
|
|
22
|
-
import { CompilerTask } from './compiler.task';
|
|
23
|
-
import { DistArtifact } from './dist-artifact';
|
|
24
|
-
import { DistArtifactNotFound } from './exceptions';
|
|
25
|
-
import { CompilationInitiator, Compiler } from './types';
|
|
26
|
-
import { CompileOptions, WorkspaceCompiler } from './workspace-compiler';
|
|
27
|
-
import { compilerTemplate } from './templates/compiler';
|
|
28
|
-
|
|
29
|
-
export class CompilerMain {
|
|
30
|
-
constructor(
|
|
31
|
-
private pubsub: PubsubMain,
|
|
32
|
-
private workspaceCompiler: WorkspaceCompiler,
|
|
33
|
-
private envs: EnvsMain,
|
|
34
|
-
private builder: BuilderMain,
|
|
35
|
-
private workspace: Workspace,
|
|
36
|
-
private dependencyResolver: DependencyResolverMain,
|
|
37
|
-
private compilerService: CompilerService
|
|
38
|
-
) {}
|
|
39
|
-
|
|
40
|
-
getCompiler(context: ExecutionContext): Compiler {
|
|
41
|
-
return this.compilerService.getCompiler(context);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Run compilation on `bit new` and when new components are imported
|
|
46
|
-
*/
|
|
47
|
-
compileOnWorkspace(
|
|
48
|
-
componentsIds: string[] | ComponentID[] | ComponentID[] = [], // when empty, it compiles all
|
|
49
|
-
options: CompileOptions = { initiator: CompilationInitiator.ComponentAdded }
|
|
50
|
-
) {
|
|
51
|
-
return this.workspaceCompiler.compileComponents(componentsIds, options);
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* API to create a new compiler task, it facilitates the usage of multiple compilers.
|
|
55
|
-
* with this method you can create any number of compilers and add them to the buildPipeline.
|
|
56
|
-
*/
|
|
57
|
-
createTask(name: string, compiler: Compiler): CompilerTask {
|
|
58
|
-
return new CompilerTask(CompilerAspect.id, name, compiler, this.dependencyResolver);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* find the compiler configured on the workspace and ask for the dist path.
|
|
63
|
-
*/
|
|
64
|
-
getDistPathBySrcPath(component: Component, srcPath: string): string | null {
|
|
65
|
-
const environment = this.envs.getEnv(component).env;
|
|
66
|
-
const compilerInstance = environment.getCompiler?.();
|
|
67
|
-
if (!compilerInstance) return null;
|
|
68
|
-
return compilerInstance.getDistPathBySrcPath(srcPath);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* find the compiler configured on the workspace and ask for the dist folder path.
|
|
73
|
-
*/
|
|
74
|
-
getRelativeDistFolder(component: Component): string {
|
|
75
|
-
const environment = this.envs.getOrCalculateEnv(component).env;
|
|
76
|
-
const compilerInstance: Compiler | undefined = environment.getCompiler?.();
|
|
77
|
-
if (!compilerInstance || !compilerInstance.getDistDir) return DEFAULT_DIST_DIRNAME;
|
|
78
|
-
return compilerInstance.getDistDir();
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Check if the dist folder (in the component package under node_modules) exist
|
|
83
|
-
* @param component
|
|
84
|
-
* @returns
|
|
85
|
-
*/
|
|
86
|
-
async isDistDirExists(component: Component): Promise<boolean> {
|
|
87
|
-
const packageDir = await this.workspace.getComponentPackagePath(component);
|
|
88
|
-
const distDir = this.getRelativeDistFolder(component);
|
|
89
|
-
const pathToCheck = path.join(packageDir, distDir);
|
|
90
|
-
return fs.existsSync(pathToCheck);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
async getDistsFiles(component: Component): Promise<DistArtifact> {
|
|
94
|
-
const artifacts = await this.builder.getArtifactsVinylByAspect(component, CompilerAspect.id);
|
|
95
|
-
if (!artifacts.length) throw new DistArtifactNotFound(component.id);
|
|
96
|
-
|
|
97
|
-
return new DistArtifact(artifacts);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
async addMissingDistsIssue(components: Component[], issuesToIgnore: string[]): Promise<void> {
|
|
101
|
-
if (issuesToIgnore.includes(IssuesClasses.MissingDists.name)) return;
|
|
102
|
-
await Promise.all(
|
|
103
|
-
components.map(async (component) => {
|
|
104
|
-
const exist = await this.isDistDirExists(component);
|
|
105
|
-
if (!exist) {
|
|
106
|
-
component.state.issues.getOrCreate(IssuesClasses.MissingDists).data = true;
|
|
107
|
-
}
|
|
108
|
-
})
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
static runtime = MainRuntime;
|
|
113
|
-
|
|
114
|
-
static dependencies = [
|
|
115
|
-
CLIAspect,
|
|
116
|
-
WorkspaceAspect,
|
|
117
|
-
EnvsAspect,
|
|
118
|
-
LoggerAspect,
|
|
119
|
-
PubsubAspect,
|
|
120
|
-
AspectLoaderAspect,
|
|
121
|
-
BuilderAspect,
|
|
122
|
-
UIAspect,
|
|
123
|
-
GeneratorAspect,
|
|
124
|
-
DependencyResolverAspect,
|
|
125
|
-
WatcherAspect,
|
|
126
|
-
IssuesAspect,
|
|
127
|
-
];
|
|
128
|
-
|
|
129
|
-
static async provider([
|
|
130
|
-
cli,
|
|
131
|
-
workspace,
|
|
132
|
-
envs,
|
|
133
|
-
loggerMain,
|
|
134
|
-
pubsub,
|
|
135
|
-
aspectLoader,
|
|
136
|
-
builder,
|
|
137
|
-
ui,
|
|
138
|
-
generator,
|
|
139
|
-
dependencyResolver,
|
|
140
|
-
watcher,
|
|
141
|
-
issues,
|
|
142
|
-
]: [
|
|
143
|
-
CLIMain,
|
|
144
|
-
Workspace,
|
|
145
|
-
EnvsMain,
|
|
146
|
-
LoggerMain,
|
|
147
|
-
PubsubMain,
|
|
148
|
-
AspectLoaderMain,
|
|
149
|
-
BuilderMain,
|
|
150
|
-
UiMain,
|
|
151
|
-
GeneratorMain,
|
|
152
|
-
DependencyResolverMain,
|
|
153
|
-
WatcherMain,
|
|
154
|
-
IssuesMain
|
|
155
|
-
]) {
|
|
156
|
-
const logger = loggerMain.createLogger(CompilerAspect.id);
|
|
157
|
-
const compilerService = new CompilerService();
|
|
158
|
-
|
|
159
|
-
const workspaceCompiler = new WorkspaceCompiler(
|
|
160
|
-
workspace,
|
|
161
|
-
envs,
|
|
162
|
-
pubsub,
|
|
163
|
-
aspectLoader,
|
|
164
|
-
ui,
|
|
165
|
-
logger,
|
|
166
|
-
dependencyResolver,
|
|
167
|
-
watcher
|
|
168
|
-
);
|
|
169
|
-
envs.registerService(compilerService);
|
|
170
|
-
const compilerMain = new CompilerMain(
|
|
171
|
-
pubsub,
|
|
172
|
-
workspaceCompiler,
|
|
173
|
-
envs,
|
|
174
|
-
builder,
|
|
175
|
-
workspace,
|
|
176
|
-
dependencyResolver,
|
|
177
|
-
compilerService
|
|
178
|
-
);
|
|
179
|
-
cli.register(new CompileCmd(workspaceCompiler, logger, pubsub));
|
|
180
|
-
if (issues) {
|
|
181
|
-
issues.registerAddComponentsIssues(compilerMain.addMissingDistsIssue.bind(compilerMain));
|
|
182
|
-
}
|
|
183
|
-
if (generator) generator.registerComponentTemplate([compilerTemplate]);
|
|
184
|
-
|
|
185
|
-
return compilerMain;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
CompilerAspect.addRuntime(CompilerMain);
|
|
190
|
-
|
|
191
|
-
export default CompilerMain;
|
package/compiler.task.ts
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { BuildContext, BuiltTaskResult, BuildTask, TaskResultsList } from '@teambit/builder';
|
|
2
|
-
import { Capsule } from '@teambit/isolator';
|
|
3
|
-
import { hardLinkDirectory } from '@teambit/toolbox.fs.hard-link-directory';
|
|
4
|
-
import { EnvContext, EnvHandler } from '@teambit/envs';
|
|
5
|
-
import { DependencyResolverMain } from '@teambit/dependency-resolver';
|
|
6
|
-
import fs from 'fs-extra';
|
|
7
|
-
import path from 'path';
|
|
8
|
-
import { Compiler } from './types';
|
|
9
|
-
import { CompilerAspect } from './compiler.aspect';
|
|
10
|
-
|
|
11
|
-
export type CompilerTaskOptions = {
|
|
12
|
-
/**
|
|
13
|
-
* instance of compiler to use.
|
|
14
|
-
*/
|
|
15
|
-
compiler: EnvHandler<Compiler>;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* name of compiler task
|
|
19
|
-
*/
|
|
20
|
-
name?: string;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* compiler build task. Allows to compile components during component build.
|
|
25
|
-
*/
|
|
26
|
-
export class CompilerTask implements BuildTask {
|
|
27
|
-
readonly description = 'compile components';
|
|
28
|
-
constructor(
|
|
29
|
-
readonly aspectId: string,
|
|
30
|
-
readonly name: string,
|
|
31
|
-
private compilerInstance: Compiler,
|
|
32
|
-
private dependencyResolver: DependencyResolverMain
|
|
33
|
-
) {
|
|
34
|
-
if (compilerInstance.artifactName) {
|
|
35
|
-
this.description += ` for artifact ${compilerInstance.artifactName}`;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async preBuild(context: BuildContext) {
|
|
40
|
-
await Promise.all(
|
|
41
|
-
context.capsuleNetwork.seedersCapsules.map((capsule) =>
|
|
42
|
-
this.copyNonSupportedFiles(capsule, this.compilerInstance)
|
|
43
|
-
)
|
|
44
|
-
);
|
|
45
|
-
if (!this.compilerInstance.preBuild) return;
|
|
46
|
-
await this.compilerInstance.preBuild(context);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async execute(context: BuildContext): Promise<BuiltTaskResult> {
|
|
50
|
-
const buildResults = await this.compilerInstance.build(context);
|
|
51
|
-
await this._hardLinkBuildArtifactsOnCapsules(context);
|
|
52
|
-
return buildResults;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* This function hard links the compiled artifacts to the `node_modules` of other component capsules.
|
|
57
|
-
* For instance, if we have a `button` component that is a dependency of the `card` component,
|
|
58
|
-
* then the `dist` folder of the `button` component will be copied to `<card_capsule>/node_modules/button/dist`.
|
|
59
|
-
*/
|
|
60
|
-
private async _hardLinkBuildArtifactsOnCapsules(context: BuildContext): Promise<void> {
|
|
61
|
-
await Promise.all(
|
|
62
|
-
context.capsuleNetwork.seedersCapsules.map(async (capsule) => {
|
|
63
|
-
const relCompDir = path.relative(context.capsuleNetwork.capsulesRootDir, capsule.path).replace(/\\/g, '/');
|
|
64
|
-
const injectedDirs = await this.dependencyResolver.getInjectedDirs(
|
|
65
|
-
context.capsuleNetwork.capsulesRootDir,
|
|
66
|
-
relCompDir,
|
|
67
|
-
this.dependencyResolver.getPackageName(capsule.component)
|
|
68
|
-
);
|
|
69
|
-
return hardLinkDirectory(
|
|
70
|
-
capsule.path,
|
|
71
|
-
injectedDirs.map((injectedDir) => path.join(context.capsuleNetwork.capsulesRootDir, injectedDir))
|
|
72
|
-
);
|
|
73
|
-
})
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
async postBuild?(context: BuildContext, tasksResults: TaskResultsList): Promise<void> {
|
|
78
|
-
if (!this.compilerInstance.postBuild) return;
|
|
79
|
-
await this.compilerInstance.postBuild(context, tasksResults);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
async copyNonSupportedFiles(capsule: Capsule, compiler: Compiler) {
|
|
83
|
-
if (!compiler.shouldCopyNonSupportedFiles) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
const component = capsule.component;
|
|
87
|
-
await Promise.all(
|
|
88
|
-
component.filesystem.files.map(async (file) => {
|
|
89
|
-
if (compiler.isFileSupported(file.path)) return;
|
|
90
|
-
const content = file.contents;
|
|
91
|
-
await fs.outputFile(path.join(capsule.path, compiler.distDir, file.relative), content);
|
|
92
|
-
})
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
static from(options: CompilerTaskOptions) {
|
|
97
|
-
return (context: EnvContext) => {
|
|
98
|
-
const aspectId = CompilerAspect.id;
|
|
99
|
-
const name = options.name || 'compiler-task';
|
|
100
|
-
const depResolve = context.getAspect<any>('teambit.dependencies/dependency-resolver');
|
|
101
|
-
return new CompilerTask(aspectId, name, options.compiler(context), depResolve);
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
}
|
package/dist-artifact.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';
|
|
2
|
-
import { pathNormalizeToLinux } from '@teambit/legacy/dist/utils';
|
|
3
|
-
|
|
4
|
-
export class DistArtifact {
|
|
5
|
-
constructor(private artifacts: AbstractVinyl[]) {}
|
|
6
|
-
|
|
7
|
-
getFile(path: string) {
|
|
8
|
-
return this.artifacts.find((file) => {
|
|
9
|
-
return pathNormalizeToLinux(file.relative) === path;
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
}
|
package/index.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export type { CompilerMain } from './compiler.main.runtime';
|
|
2
|
-
export type { CompilerTaskOptions } from './compiler.task';
|
|
3
|
-
export { CompilerTask } from './compiler.task';
|
|
4
|
-
export type { CompilerEnv } from './compiler-env-type';
|
|
5
|
-
export { CompilerAspect } from './compiler.aspect';
|
|
6
|
-
export { CompilationInitiator } from './types';
|
|
7
|
-
export type {
|
|
8
|
-
Compiler,
|
|
9
|
-
CompilerOptions,
|
|
10
|
-
TranspileFileOutput,
|
|
11
|
-
TranspileFileParams,
|
|
12
|
-
TranspileComponentParams,
|
|
13
|
-
TranspileFileOutputOneFile,
|
|
14
|
-
} from './types';
|
|
15
|
-
export * from './events';
|
package/output-formatter.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import { ComponentsStatus } from './compiler.cmd';
|
|
3
|
-
|
|
4
|
-
export const formatCompileResults = (compileResults: ComponentsStatus[], verbose: boolean) =>
|
|
5
|
-
compileResults
|
|
6
|
-
.map((componentResult: ComponentsStatus) => ({
|
|
7
|
-
componentId: componentResult.component.id.fullName,
|
|
8
|
-
files: componentResult.buildResults,
|
|
9
|
-
status: componentResult.errors.length ? 'FAILURE' : 'SUCCESS',
|
|
10
|
-
icon: componentResult.errors.length ? chalk.red('✗') : chalk.green('✔'),
|
|
11
|
-
}))
|
|
12
|
-
.reduce((outputString, result) => {
|
|
13
|
-
outputString += `${result.icon} ${result.status}\t${result.componentId}`;
|
|
14
|
-
if (verbose) {
|
|
15
|
-
outputString += ':';
|
|
16
|
-
outputString += result?.files?.reduce((fileList, file) => `${fileList}\t\t - ${file}\n`, '\n');
|
|
17
|
-
}
|
|
18
|
-
outputString += '\n';
|
|
19
|
-
return outputString;
|
|
20
|
-
}, '');
|
package/types.ts
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { BuildContext, BuildTask, BuiltTaskResult, TaskResultsList } from '@teambit/builder';
|
|
2
|
-
import type { Component } from '@teambit/component';
|
|
3
|
-
import { ServiceHandler } from '@teambit/envs';
|
|
4
|
-
|
|
5
|
-
export type TranspileFileParams = {
|
|
6
|
-
componentDir: string; // absolute path of the component's root directory
|
|
7
|
-
filePath: string; // relative path of the file inside the component directory
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export enum CompilationInitiator {
|
|
11
|
-
CmdReport,
|
|
12
|
-
CmdJson,
|
|
13
|
-
PreStart,
|
|
14
|
-
PreWatch,
|
|
15
|
-
Start,
|
|
16
|
-
ComponentChanged,
|
|
17
|
-
AspectLoadFail,
|
|
18
|
-
ComponentAdded,
|
|
19
|
-
Install,
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export type TranspileComponentParams = {
|
|
23
|
-
component: Component;
|
|
24
|
-
componentDir: string; // absolute path of the component's root directory
|
|
25
|
-
outputDir: string; // absolute path of the component's output directory
|
|
26
|
-
initiator: CompilationInitiator; // origin of the compilation's request
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export type TranspileFileOutputOneFile = {
|
|
30
|
-
outputText: string;
|
|
31
|
-
outputPath: string;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export type TranspileFileOutput = TranspileFileOutputOneFile[] | null;
|
|
35
|
-
|
|
36
|
-
export interface CompilerOptions {
|
|
37
|
-
/**
|
|
38
|
-
* name of the compiler.
|
|
39
|
-
*/
|
|
40
|
-
name?: string;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* relative path of the dist directory inside the capsule. e.g. "dist".
|
|
44
|
-
*/
|
|
45
|
-
distDir: string;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* determines which ones of the generated files will be saved in the bit objects when tagging.
|
|
49
|
-
* e.g. distGlobPatterns = [`${this.distDir}/**`, `!${this.distDir}/tsconfig.tsbuildinfo`];
|
|
50
|
-
* see https://github.com/mrmlnc/fast-glob for the supported glob patters syntax.
|
|
51
|
-
*/
|
|
52
|
-
distGlobPatterns?: string[];
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* whether or not unsupported files (such as assets) should be copied into the dist directory
|
|
56
|
-
*/
|
|
57
|
-
shouldCopyNonSupportedFiles?: boolean;
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* optional. default to "dist".
|
|
61
|
-
* useful when the build pipeline has multiple compiler tasks of the same compiler.
|
|
62
|
-
* e.g. using the same Babel compiler for two different tasks, one for creating "es5" files, and
|
|
63
|
-
* the second for creating "esm". the artifact names would be "es5" and "esm" accordingly.
|
|
64
|
-
*/
|
|
65
|
-
artifactName?: string;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export interface Compiler extends CompilerOptions, ServiceHandler {
|
|
69
|
-
/**
|
|
70
|
-
* id of the compiler.
|
|
71
|
-
*/
|
|
72
|
-
id: string;
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Delete dist folder before writing the new compiled files
|
|
76
|
-
*/
|
|
77
|
-
deleteDistDir?: boolean;
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* serialized config of the compiler.
|
|
81
|
-
*/
|
|
82
|
-
displayConfig?(): string;
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* transpile a single file that gets saved into the workspace, used by `bit compile` and during
|
|
86
|
-
* development
|
|
87
|
-
*/
|
|
88
|
-
transpileFile?: (
|
|
89
|
-
fileContent: string,
|
|
90
|
-
params: TranspileFileParams
|
|
91
|
-
) => TranspileFileOutput | Promise<TranspileFileOutput>;
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* transpile all the files of a component, use this when you can't use `transpileFile`
|
|
95
|
-
*/
|
|
96
|
-
transpileComponent?: (params: TranspileComponentParams) => Promise<void>;
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* compile components inside isolated capsules. this being used during tag for the release.
|
|
100
|
-
* meaning, the final package of the component has the dists generated by this method.
|
|
101
|
-
*
|
|
102
|
-
* no need to handle non-supported-files (e.g. assets) in this method because the compiler-aspect already copies them
|
|
103
|
-
* into the compiler.dist in the preBuild stage.
|
|
104
|
-
*/
|
|
105
|
-
build(context: BuildContext): Promise<BuiltTaskResult>;
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* return the dist dir of the compiled files (relative path from the component root dir)
|
|
109
|
-
*/
|
|
110
|
-
getDistDir?(): string;
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* given a source file, return its parallel in the dists. e.g. "index.ts" => "dist/index.js"
|
|
114
|
-
* both, the return path and the given path are relative paths.
|
|
115
|
-
*/
|
|
116
|
-
getDistPathBySrcPath(srcPath: string): string;
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* given a component, returns the path to the source folder to use for the preview, uses the one
|
|
120
|
-
* in node_modules by default
|
|
121
|
-
*/
|
|
122
|
-
getPreviewComponentRootPath?(component: Component): string;
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* only supported files matching get compiled. others, are copied to the dist dir.
|
|
126
|
-
*/
|
|
127
|
-
isFileSupported(filePath: string): boolean;
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* sugar to create a Compiler task via the concrete compiler
|
|
131
|
-
*/
|
|
132
|
-
createTask?(name?: string): BuildTask;
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* run before the build pipeline has started. this is useful when some preparation are needed to
|
|
136
|
-
* be done on all envs before the build starts.
|
|
137
|
-
*/
|
|
138
|
-
preBuild?(context: BuildContext): Promise<void>;
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* run after the build pipeline completed for all envs. useful for some cleanups
|
|
142
|
-
*/
|
|
143
|
-
postBuild?(context: BuildContext, tasksResults: TaskResultsList): Promise<void>;
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* returns the version of the current compiler instance (e.g. '4.0.1').
|
|
147
|
-
*/
|
|
148
|
-
version(): string;
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* returns the display name of the current compiler instance (e.g. 'TypeScript')
|
|
152
|
-
*/
|
|
153
|
-
displayName: string;
|
|
154
|
-
}
|
package/workspace-compiler.ts
DELETED
|
@@ -1,398 +0,0 @@
|
|
|
1
|
-
/* eslint-disable max-classes-per-file */
|
|
2
|
-
import mapSeries from 'p-map-series';
|
|
3
|
-
import { Component } from '@teambit/component';
|
|
4
|
-
import { EnvsMain } from '@teambit/envs';
|
|
5
|
-
import type { PubsubMain } from '@teambit/pubsub';
|
|
6
|
-
import { SerializableResults, Workspace, OutsideWorkspaceError } from '@teambit/workspace';
|
|
7
|
-
import { WatcherMain, WatchOptions } from '@teambit/watcher';
|
|
8
|
-
import path from 'path';
|
|
9
|
-
import { ComponentID } from '@teambit/component-id';
|
|
10
|
-
import { Logger } from '@teambit/logger';
|
|
11
|
-
import loader from '@teambit/legacy/dist/cli/loader';
|
|
12
|
-
import { DEFAULT_DIST_DIRNAME } from '@teambit/legacy/dist/constants';
|
|
13
|
-
import { AbstractVinyl, Dist } from '@teambit/legacy/dist/consumer/component/sources';
|
|
14
|
-
import DataToPersist from '@teambit/legacy/dist/consumer/component/sources/data-to-persist';
|
|
15
|
-
import {
|
|
16
|
-
linkToNodeModulesByComponents,
|
|
17
|
-
removeLinksFromNodeModules,
|
|
18
|
-
} from '@teambit/workspace.modules.node-modules-linker';
|
|
19
|
-
import { AspectLoaderMain } from '@teambit/aspect-loader';
|
|
20
|
-
import { DependencyResolverMain } from '@teambit/dependency-resolver';
|
|
21
|
-
import componentIdToPackageName from '@teambit/legacy/dist/utils/bit/component-id-to-package-name';
|
|
22
|
-
import RemovePath from '@teambit/legacy/dist/consumer/component/sources/remove-path';
|
|
23
|
-
import { UiMain } from '@teambit/ui';
|
|
24
|
-
import { readBitRootsDir } from '@teambit/bit-roots';
|
|
25
|
-
import { groupBy, uniq } from 'lodash';
|
|
26
|
-
import type { PreStartOpts } from '@teambit/ui';
|
|
27
|
-
import { PathOsBasedAbsolute, PathOsBasedRelative } from '@teambit/legacy/dist/utils/path';
|
|
28
|
-
import { MultiCompiler } from '@teambit/multi-compiler';
|
|
29
|
-
import { CompilerAspect } from './compiler.aspect';
|
|
30
|
-
import { CompilerErrorEvent, ComponentCompilationOnDoneEvent } from './events';
|
|
31
|
-
import { Compiler, CompilationInitiator } from './types';
|
|
32
|
-
|
|
33
|
-
export type BuildResult = { component: string; buildResults: string[] | null | undefined };
|
|
34
|
-
|
|
35
|
-
export type CompileOptions = {
|
|
36
|
-
changed?: boolean; // compile only new and modified components
|
|
37
|
-
verbose?: boolean; // show more data, such as, dist paths
|
|
38
|
-
/**
|
|
39
|
-
* whether the dist root dir should be deleted before writing new dists.
|
|
40
|
-
* defaults to true for `bit compile` and false everywhere else, such as `bit watch` and `bit
|
|
41
|
-
* start` to avoid webpack "EINTR" error.
|
|
42
|
-
*/
|
|
43
|
-
deleteDistDir?: boolean;
|
|
44
|
-
initiator: CompilationInitiator; // describes where the compilation is coming from
|
|
45
|
-
// should we create links in node_modules for the compiled components (default = true)
|
|
46
|
-
// this will link the source files, and create the package.json
|
|
47
|
-
linkComponents?: boolean;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export type CompileError = { path: string; error: Error };
|
|
51
|
-
|
|
52
|
-
export class ComponentCompiler {
|
|
53
|
-
constructor(
|
|
54
|
-
private pubsub: PubsubMain,
|
|
55
|
-
private workspace: Workspace,
|
|
56
|
-
private component: Component,
|
|
57
|
-
private compilerInstance: Compiler,
|
|
58
|
-
private compilerId: string,
|
|
59
|
-
private logger: Logger,
|
|
60
|
-
private dependencyResolver: DependencyResolverMain,
|
|
61
|
-
private dists: Dist[] = [],
|
|
62
|
-
private compileErrors: CompileError[] = []
|
|
63
|
-
) {}
|
|
64
|
-
|
|
65
|
-
async compile(noThrow = true, options: CompileOptions): Promise<BuildResult> {
|
|
66
|
-
let dataToPersist;
|
|
67
|
-
const deleteDistDir = options.deleteDistDir ?? this.compilerInstance.deleteDistDir;
|
|
68
|
-
// delete dist folder before transpilation (because some compilers (like ngPackagr) can generate files there during the compilation process)
|
|
69
|
-
if (deleteDistDir) {
|
|
70
|
-
dataToPersist = new DataToPersist();
|
|
71
|
-
for (const distDir of await this.distDirs()) {
|
|
72
|
-
dataToPersist.removePath(new RemovePath(distDir));
|
|
73
|
-
}
|
|
74
|
-
dataToPersist.addBasePath(this.workspace.path);
|
|
75
|
-
await dataToPersist.persistAllToFS();
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const compilers: Compiler[] = (this.compilerInstance as MultiCompiler).compilers
|
|
79
|
-
? (this.compilerInstance as MultiCompiler).compilers
|
|
80
|
-
: [this.compilerInstance];
|
|
81
|
-
const canTranspileFile = compilers.find((c) => c.transpileFile);
|
|
82
|
-
const canTranspileComponent = compilers.find((c) => c.transpileComponent);
|
|
83
|
-
|
|
84
|
-
if (canTranspileFile) {
|
|
85
|
-
await Promise.all(
|
|
86
|
-
this.component.filesystem.files.map((file: AbstractVinyl) => this.compileOneFile(file, options.initiator))
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (canTranspileComponent) {
|
|
91
|
-
await this.compileAllFiles(this.component, options.initiator);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (!canTranspileFile && !canTranspileComponent) {
|
|
95
|
-
throw new Error(
|
|
96
|
-
`compiler ${this.compilerId.toString()} doesn't implement either "transpileFile" or "transpileComponent" methods`
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
this.throwOnCompileErrors(noThrow);
|
|
100
|
-
|
|
101
|
-
// writing the dists with `component.setDists(dists); component.dists.writeDists` is tricky
|
|
102
|
-
// as it uses other base-paths and doesn't respect the new node-modules base path.
|
|
103
|
-
dataToPersist = new DataToPersist();
|
|
104
|
-
dataToPersist.addManyFiles(this.dists);
|
|
105
|
-
dataToPersist.addBasePath(this.workspace.path);
|
|
106
|
-
await dataToPersist.persistAllToFS();
|
|
107
|
-
const linkComponents = options.linkComponents ?? true;
|
|
108
|
-
if (linkComponents) {
|
|
109
|
-
await linkToNodeModulesByComponents([this.component], this.workspace);
|
|
110
|
-
}
|
|
111
|
-
const buildResults = this.dists.map((distFile) => distFile.path);
|
|
112
|
-
if (this.component.state._consumer.compiler) loader.succeed();
|
|
113
|
-
this.pubsub.pub(
|
|
114
|
-
CompilerAspect.id,
|
|
115
|
-
new ComponentCompilationOnDoneEvent(this.compileErrors, this.component, buildResults)
|
|
116
|
-
);
|
|
117
|
-
return { component: this.component.id.toString(), buildResults };
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
private throwOnCompileErrors(noThrow = true) {
|
|
121
|
-
if (this.compileErrors.length) {
|
|
122
|
-
this.compileErrors.forEach((errorItem) => {
|
|
123
|
-
this.logger.error(`compilation error at ${errorItem.path}`, errorItem.error);
|
|
124
|
-
});
|
|
125
|
-
const formatError = (errorItem) => `${errorItem.path}\n${errorItem.error}`;
|
|
126
|
-
const err = new Error(`compilation failed. see the following errors from the compiler
|
|
127
|
-
${this.compileErrors.map(formatError).join('\n')}`);
|
|
128
|
-
|
|
129
|
-
this.pubsub.pub(CompilerAspect.id, new CompilerErrorEvent(err));
|
|
130
|
-
|
|
131
|
-
if (!noThrow) {
|
|
132
|
-
throw err;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
this.logger.console(err.message);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
private async distDirs(): Promise<PathOsBasedRelative[]> {
|
|
140
|
-
const packageName = componentIdToPackageName(this.component.state._consumer);
|
|
141
|
-
const packageDir = path.join('node_modules', packageName);
|
|
142
|
-
const distDirName = this.compilerInstance.getDistDir?.() || DEFAULT_DIST_DIRNAME;
|
|
143
|
-
const injectedDirs = await this.getInjectedDirs(packageName);
|
|
144
|
-
return [packageDir, ...injectedDirs].map((dist) => path.join(dist, distDirName));
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
private async getInjectedDirs(packageName: string): Promise<string[]> {
|
|
148
|
-
const injectedDirs = await this.workspace.getInjectedDirs(this.component);
|
|
149
|
-
if (injectedDirs.length > 0) return injectedDirs;
|
|
150
|
-
|
|
151
|
-
const rootDirs = await readBitRootsDir(this.workspace.path);
|
|
152
|
-
return rootDirs.map((rootDir) => path.relative(this.workspace.path, path.join(rootDir, packageName)));
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
private get componentDir(): PathOsBasedAbsolute {
|
|
156
|
-
return this.workspace.componentDir(this.component.id);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
private async compileOneFile(file: AbstractVinyl, initiator: CompilationInitiator): Promise<void> {
|
|
160
|
-
const options = { componentDir: this.componentDir, filePath: file.relative, initiator };
|
|
161
|
-
const isFileSupported = this.compilerInstance.isFileSupported(file.path);
|
|
162
|
-
let compileResults;
|
|
163
|
-
if (isFileSupported) {
|
|
164
|
-
try {
|
|
165
|
-
compileResults = await this.compilerInstance.transpileFile?.(file.contents.toString(), options);
|
|
166
|
-
} catch (error: any) {
|
|
167
|
-
this.compileErrors.push({ path: file.path, error });
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
for (const base of await this.distDirs()) {
|
|
172
|
-
if (isFileSupported && compileResults) {
|
|
173
|
-
this.dists.push(
|
|
174
|
-
...compileResults.map(
|
|
175
|
-
(result) =>
|
|
176
|
-
new Dist({
|
|
177
|
-
base,
|
|
178
|
-
path: path.join(base, result.outputPath),
|
|
179
|
-
contents: Buffer.from(result.outputText),
|
|
180
|
-
})
|
|
181
|
-
)
|
|
182
|
-
);
|
|
183
|
-
} else if (this.compilerInstance.shouldCopyNonSupportedFiles) {
|
|
184
|
-
// compiler doesn't support this file type. copy the file as is to the dist dir.
|
|
185
|
-
this.dists.push(new Dist({ base, path: path.join(base, file.relative), contents: file.contents }));
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
private async compileAllFiles(component: Component, initiator: CompilationInitiator): Promise<void> {
|
|
191
|
-
const filesToCompile: AbstractVinyl[] = [];
|
|
192
|
-
for (const base of await this.distDirs()) {
|
|
193
|
-
component.filesystem.files.forEach((file: AbstractVinyl) => {
|
|
194
|
-
const isFileSupported = this.compilerInstance.isFileSupported(file.path);
|
|
195
|
-
if (isFileSupported) {
|
|
196
|
-
filesToCompile.push(file);
|
|
197
|
-
} else if (this.compilerInstance.shouldCopyNonSupportedFiles) {
|
|
198
|
-
// compiler doesn't support this file type. copy the file as is to the dist dir.
|
|
199
|
-
this.dists.push(
|
|
200
|
-
new Dist({
|
|
201
|
-
base,
|
|
202
|
-
path: path.join(base, file.relative),
|
|
203
|
-
contents: file.contents,
|
|
204
|
-
})
|
|
205
|
-
);
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
if (filesToCompile.length) {
|
|
211
|
-
try {
|
|
212
|
-
await this.compilerInstance.transpileComponent?.({
|
|
213
|
-
component,
|
|
214
|
-
componentDir: this.componentDir,
|
|
215
|
-
outputDir: await this.workspace.getComponentPackagePath(component),
|
|
216
|
-
initiator,
|
|
217
|
-
});
|
|
218
|
-
} catch (error: any) {
|
|
219
|
-
this.compileErrors.push({ path: this.componentDir, error });
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
export class WorkspaceCompiler {
|
|
226
|
-
constructor(
|
|
227
|
-
private workspace: Workspace,
|
|
228
|
-
private envs: EnvsMain,
|
|
229
|
-
private pubsub: PubsubMain,
|
|
230
|
-
private aspectLoader: AspectLoaderMain,
|
|
231
|
-
private ui: UiMain,
|
|
232
|
-
private logger: Logger,
|
|
233
|
-
private dependencyResolver: DependencyResolverMain,
|
|
234
|
-
private watcher: WatcherMain
|
|
235
|
-
) {
|
|
236
|
-
if (this.workspace) {
|
|
237
|
-
this.workspace.registerOnComponentChange(this.onComponentChange.bind(this));
|
|
238
|
-
this.workspace.registerOnComponentAdd(this.onComponentAdd.bind(this));
|
|
239
|
-
this.watcher.registerOnPreWatch(this.onPreWatch.bind(this));
|
|
240
|
-
}
|
|
241
|
-
this.ui.registerPreStart(this.onPreStart.bind(this));
|
|
242
|
-
if (this.aspectLoader) {
|
|
243
|
-
this.aspectLoader.registerOnAspectLoadErrorSlot(this.onAspectLoadFail.bind(this));
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
async onPreStart(preStartOpts: PreStartOpts): Promise<void> {
|
|
248
|
-
if (this.workspace) {
|
|
249
|
-
if (preStartOpts.skipCompilation) {
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
await this.compileComponents([], {
|
|
253
|
-
changed: true,
|
|
254
|
-
verbose: false,
|
|
255
|
-
deleteDistDir: false,
|
|
256
|
-
initiator: CompilationInitiator.PreStart,
|
|
257
|
-
});
|
|
258
|
-
} else {
|
|
259
|
-
await this.watcher.watchScopeInternalFiles();
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
async onAspectLoadFail(err: Error & { code?: string }, id: ComponentID): Promise<boolean> {
|
|
264
|
-
if (err.code && err.code === 'MODULE_NOT_FOUND' && this.workspace) {
|
|
265
|
-
await this.compileComponents([id.toString()], { initiator: CompilationInitiator.AspectLoadFail }, true);
|
|
266
|
-
return true;
|
|
267
|
-
}
|
|
268
|
-
return false;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
async onComponentAdd(component: Component, files: string[], watchOpts: WatchOptions) {
|
|
272
|
-
return this.onComponentChange(component, files, undefined, watchOpts);
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
async onComponentChange(
|
|
276
|
-
component: Component,
|
|
277
|
-
files: string[],
|
|
278
|
-
removedFiles: string[] = [],
|
|
279
|
-
watchOpts: WatchOptions
|
|
280
|
-
): Promise<SerializableResults | void> {
|
|
281
|
-
if (!watchOpts.compile) return undefined;
|
|
282
|
-
// when files are removed, we need to remove the dist directories and the old symlinks, otherwise, it has
|
|
283
|
-
// symlinks to non-exist files and the dist has stale files
|
|
284
|
-
const deleteDistDir = Boolean(removedFiles?.length);
|
|
285
|
-
if (removedFiles?.length) {
|
|
286
|
-
await removeLinksFromNodeModules(component, this.workspace, removedFiles);
|
|
287
|
-
}
|
|
288
|
-
const buildResults = await this.compileComponents(
|
|
289
|
-
[component.id.toString()],
|
|
290
|
-
{ initiator: watchOpts.initiator || CompilationInitiator.ComponentChanged, deleteDistDir },
|
|
291
|
-
true
|
|
292
|
-
);
|
|
293
|
-
// await linkToNodeModulesByComponents([component], this.workspace);
|
|
294
|
-
return {
|
|
295
|
-
results: buildResults,
|
|
296
|
-
toString() {
|
|
297
|
-
return `${buildResults[0]?.buildResults?.join('\n\t')}`;
|
|
298
|
-
},
|
|
299
|
-
};
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
async onPreWatch(componentIds: ComponentID[], watchOpts: WatchOptions) {
|
|
303
|
-
if (watchOpts.preCompile) {
|
|
304
|
-
const start = Date.now();
|
|
305
|
-
this.logger.console(`compiling ${componentIds.length} components`);
|
|
306
|
-
await this.compileComponents(
|
|
307
|
-
componentIds.map((id) => id),
|
|
308
|
-
{ initiator: CompilationInitiator.PreWatch }
|
|
309
|
-
);
|
|
310
|
-
const end = Date.now() - start;
|
|
311
|
-
this.logger.consoleSuccess(`compiled ${componentIds.length} components successfully (${end / 1000} sec)`);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
async compileComponents(
|
|
316
|
-
componentsIds: string[] | ComponentID[] | ComponentID[], // when empty, it compiles new+modified (unless options.all is set),
|
|
317
|
-
options: CompileOptions,
|
|
318
|
-
noThrow?: boolean
|
|
319
|
-
): Promise<BuildResult[]> {
|
|
320
|
-
if (!this.workspace) throw new OutsideWorkspaceError();
|
|
321
|
-
const componentIds = await this.getIdsToCompile(componentsIds, options.changed);
|
|
322
|
-
// In case the aspect failed to load, we want to compile it without try to re-load it again
|
|
323
|
-
const getManyOpts =
|
|
324
|
-
options.initiator === CompilationInitiator.AspectLoadFail ? { loadSeedersAsAspects: false } : undefined;
|
|
325
|
-
const components = await this.workspace.getMany(componentIds, getManyOpts);
|
|
326
|
-
|
|
327
|
-
const grouped = this.groupByIsEnv(components);
|
|
328
|
-
const envsResults = grouped.envs ? await this.runCompileComponents(grouped.envs, options, noThrow) : [];
|
|
329
|
-
const otherResults = grouped.other ? await this.runCompileComponents(grouped.other, options, noThrow) : [];
|
|
330
|
-
return [...envsResults, ...otherResults];
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
private async runCompileComponents(
|
|
334
|
-
components: Component[],
|
|
335
|
-
options: CompileOptions,
|
|
336
|
-
noThrow?: boolean
|
|
337
|
-
): Promise<BuildResult[]> {
|
|
338
|
-
const componentsCompilers: ComponentCompiler[] = [];
|
|
339
|
-
|
|
340
|
-
components.forEach((c) => {
|
|
341
|
-
const environment = this.envs.getEnv(c).env;
|
|
342
|
-
const compilerInstance = environment.getCompiler?.();
|
|
343
|
-
|
|
344
|
-
if (compilerInstance) {
|
|
345
|
-
const compilerName = compilerInstance.constructor.name || 'compiler';
|
|
346
|
-
componentsCompilers.push(
|
|
347
|
-
new ComponentCompiler(
|
|
348
|
-
this.pubsub,
|
|
349
|
-
this.workspace,
|
|
350
|
-
c,
|
|
351
|
-
compilerInstance,
|
|
352
|
-
compilerName,
|
|
353
|
-
this.logger,
|
|
354
|
-
this.dependencyResolver
|
|
355
|
-
)
|
|
356
|
-
);
|
|
357
|
-
} else {
|
|
358
|
-
this.logger.warn(`unable to find a compiler instance for ${c.id.toString()}`);
|
|
359
|
-
}
|
|
360
|
-
});
|
|
361
|
-
const resultOnWorkspace = await mapSeries(componentsCompilers, (componentCompiler) =>
|
|
362
|
-
componentCompiler.compile(noThrow, options)
|
|
363
|
-
);
|
|
364
|
-
|
|
365
|
-
return resultOnWorkspace;
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
/**
|
|
369
|
-
* This function get's a list of aspect ids and return them grouped by whether any of them is the env of other from the list
|
|
370
|
-
* @param ids
|
|
371
|
-
*/
|
|
372
|
-
groupByIsEnv(components: Component[]): { envs?: Component[]; other?: Component[] } {
|
|
373
|
-
const envsIds = uniq(
|
|
374
|
-
components
|
|
375
|
-
.map((component) => this.envs.getEnvId(component))
|
|
376
|
-
.filter((envId) => !this.aspectLoader.isCoreEnv(envId))
|
|
377
|
-
);
|
|
378
|
-
const grouped = groupBy(components, (component) => {
|
|
379
|
-
if (envsIds.includes(component.id.toString())) return 'envs';
|
|
380
|
-
return 'other';
|
|
381
|
-
});
|
|
382
|
-
return grouped as { envs: Component[]; other: Component[] };
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
private async getIdsToCompile(
|
|
386
|
-
componentsIds: Array<string | ComponentID | ComponentID>,
|
|
387
|
-
changed = false
|
|
388
|
-
): Promise<ComponentID[]> {
|
|
389
|
-
if (componentsIds.length) {
|
|
390
|
-
const componentIds = await this.workspace.resolveMultipleComponentIds(componentsIds);
|
|
391
|
-
return this.workspace.filterIds(componentIds);
|
|
392
|
-
}
|
|
393
|
-
if (changed) {
|
|
394
|
-
return this.workspace.getNewAndModifiedIds();
|
|
395
|
-
}
|
|
396
|
-
return this.workspace.listIds();
|
|
397
|
-
}
|
|
398
|
-
}
|