@teambit/compiler 0.0.566 → 0.0.570

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,47 @@
1
+ import React from 'react';
2
+ import { Text, Newline } from 'ink';
3
+ import { EnvService, EnvDefinition } from '@teambit/envs';
4
+ import highlight from 'cli-highlight';
5
+
6
+ export type CompilerDescriptor = {
7
+ id: string;
8
+ icon?: string;
9
+ config?: string;
10
+ };
11
+
12
+ export class CompilerService implements EnvService<{}, CompilerDescriptor> {
13
+ name = 'Compile';
14
+
15
+ render(env: EnvDefinition) {
16
+ const descriptor = this.getDescriptor(env);
17
+
18
+ return (
19
+ <Text key={descriptor?.id}>
20
+ <Text color="cyan">configured compiler: </Text>
21
+ <Text>
22
+ {descriptor?.id} ({descriptor?.displayName} @ {descriptor?.version})
23
+ </Text>
24
+ <Newline />
25
+ <Text color="cyan">compiler config:</Text>
26
+ <Newline />
27
+ <Text>
28
+ {descriptor?.config && highlight(descriptor?.config, { language: 'javascript', ignoreIllegals: true })}
29
+ </Text>
30
+ <Newline />
31
+ </Text>
32
+ );
33
+ }
34
+
35
+ getDescriptor(env: EnvDefinition) {
36
+ if (!env.env.getCompiler) return undefined;
37
+ const compiler = env.env.getCompiler();
38
+
39
+ return {
40
+ id: compiler.id,
41
+ icon: compiler.icon,
42
+ config: compiler.displayConfig ? compiler.displayConfig() : undefined,
43
+ version: compiler.version ? compiler.version() : '?',
44
+ displayName: compiler.displayName ? compiler.displayName : '?',
45
+ };
46
+ }
47
+ }
@@ -0,0 +1,14 @@
1
+ /* eslint-disable max-classes-per-file */
2
+ import { BitBaseEvent } from '@teambit/pubsub';
3
+
4
+ class CompilerErrorEventData {
5
+ constructor(readonly error: any) {}
6
+ }
7
+
8
+ export class CompilerErrorEvent extends BitBaseEvent<CompilerErrorEventData> {
9
+ static readonly TYPE = 'compiler-error';
10
+
11
+ constructor(readonly error, readonly timestamp = Date.now()) {
12
+ super(CompilerErrorEvent.TYPE, '0.0.1', timestamp, new CompilerErrorEventData(error));
13
+ }
14
+ }
@@ -0,0 +1,30 @@
1
+ /* eslint-disable max-classes-per-file */
2
+ import { BitBaseEvent } from '@teambit/pubsub';
3
+ import type ConsumerComponent from '@teambit/legacy/dist/consumer/component';
4
+ import { CompileError } from '../workspace-compiler';
5
+
6
+ class ComponentCompilationOnDoneEventData {
7
+ constructor(
8
+ readonly errors: Array<CompileError>,
9
+ readonly component: ConsumerComponent,
10
+ readonly buildResults: string[]
11
+ ) {}
12
+ }
13
+
14
+ export class ComponentCompilationOnDoneEvent extends BitBaseEvent<ComponentCompilationOnDoneEventData> {
15
+ static readonly TYPE = 'component-compilation-on-done';
16
+
17
+ constructor(
18
+ readonly errors: Array<CompileError>,
19
+ readonly component: ConsumerComponent,
20
+ readonly buildResults: string[],
21
+ readonly timestamp = Date.now()
22
+ ) {
23
+ super(
24
+ ComponentCompilationOnDoneEvent.TYPE,
25
+ '0.0.1',
26
+ timestamp,
27
+ new ComponentCompilationOnDoneEventData(errors, component, buildResults)
28
+ );
29
+ }
30
+ }
@@ -0,0 +1,2 @@
1
+ export * from './compiler-error';
2
+ export * from './component-compilation-on-done';
@@ -0,0 +1,8 @@
1
+ import { ComponentID } from '@teambit/component';
2
+ import { BitError } from '@teambit/bit-error';
3
+
4
+ export class DistArtifactNotFound extends BitError {
5
+ constructor(readonly componentId: ComponentID) {
6
+ super(`dist artifact for component ${componentId.toString()} was not found`);
7
+ }
8
+ }
@@ -0,0 +1 @@
1
+ export { DistArtifactNotFound } from './dist-artifact-not-found';
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/compiler",
3
- "version": "0.0.566",
3
+ "version": "0.0.570",
4
4
  "homepage": "https://bit.dev/teambit/compilation/compiler",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.compilation",
8
8
  "name": "compiler",
9
- "version": "0.0.566"
9
+ "version": "0.0.570"
10
10
  },
11
11
  "dependencies": {
12
12
  "@teambit/harmony": "0.2.11",
@@ -18,19 +18,19 @@
18
18
  "p-map-series": "2.1.0",
19
19
  "@babel/runtime": "7.12.18",
20
20
  "core-js": "^3.0.0",
21
- "@teambit/cli": "0.0.393",
22
- "@teambit/logger": "0.0.478",
23
- "@teambit/pubsub": "0.0.566",
24
- "@teambit/aspect-loader": "0.0.566",
25
- "@teambit/builder": "0.0.566",
26
- "@teambit/component": "0.0.566",
27
- "@teambit/envs": "0.0.566",
28
- "@teambit/generator": "0.0.566",
29
- "@teambit/legacy-bit-id": "0.0.382",
30
- "@teambit/ui": "0.0.566",
31
- "@teambit/workspace": "0.0.566",
32
- "@teambit/isolator": "0.0.566",
33
- "@teambit/bit-error": "0.0.379"
21
+ "@teambit/cli": "0.0.395",
22
+ "@teambit/logger": "0.0.482",
23
+ "@teambit/pubsub": "0.0.570",
24
+ "@teambit/aspect-loader": "0.0.570",
25
+ "@teambit/builder": "0.0.570",
26
+ "@teambit/component": "0.0.570",
27
+ "@teambit/envs": "0.0.570",
28
+ "@teambit/generator": "0.0.570",
29
+ "@teambit/legacy-bit-id": "0.0.384",
30
+ "@teambit/ui": "0.0.570",
31
+ "@teambit/workspace": "0.0.570",
32
+ "@teambit/isolator": "0.0.570",
33
+ "@teambit/bit-error": "0.0.381"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/react": "^17.0.8",
@@ -40,10 +40,10 @@
40
40
  "@types/jest": "^26.0.0",
41
41
  "@types/react-dom": "^17.0.5",
42
42
  "@types/node": "12.20.4",
43
- "@teambit/compilation.aspect-docs.compiler": "0.0.112"
43
+ "@teambit/compilation.aspect-docs.compiler": "0.0.116"
44
44
  },
45
45
  "peerDependencies": {
46
- "@teambit/legacy": "1.0.179",
46
+ "@teambit/legacy": "1.0.181",
47
47
  "react-dom": "^16.8.0 || ^17.0.0",
48
48
  "react": "^16.8.0 || ^17.0.0"
49
49
  },
@@ -71,27 +71,12 @@
71
71
  "react": "-"
72
72
  },
73
73
  "peerDependencies": {
74
- "@teambit/legacy": "1.0.179",
74
+ "@teambit/legacy": "1.0.181",
75
75
  "react-dom": "^16.8.0 || ^17.0.0",
76
76
  "react": "^16.8.0 || ^17.0.0"
77
77
  }
78
78
  }
79
79
  },
80
- "files": [
81
- "dist",
82
- "!dist/tsconfig.tsbuildinfo",
83
- "**/*.md",
84
- "**/*.mdx",
85
- "**/*.js",
86
- "**/*.json",
87
- "**/*.sass",
88
- "**/*.scss",
89
- "**/*.less",
90
- "**/*.css",
91
- "**/*.css",
92
- "**/*.jpeg",
93
- "**/*.gif"
94
- ],
95
80
  "private": false,
96
81
  "engines": {
97
82
  "node": ">=12.22.0"
@@ -0,0 +1,10 @@
1
+ import { ComponentContext } from '@teambit/generator';
2
+
3
+ export function aspectFile({ namePascalCase, componentId }: ComponentContext) {
4
+ return `import { Aspect } from '@teambit/harmony';
5
+
6
+ export const ${namePascalCase}Aspect = Aspect.create({
7
+ id: '${componentId}',
8
+ });
9
+ `;
10
+ }
@@ -0,0 +1,75 @@
1
+ import { ComponentContext } from '@teambit/generator';
2
+
3
+ export function compilerFile({ namePascalCase }: ComponentContext) {
4
+ return `import {
5
+ BuildContext,
6
+ BuiltTaskResult,
7
+ ComponentResult,
8
+ } from '@teambit/builder';
9
+ import {
10
+ Compiler,
11
+ CompilerMain,
12
+ TranspileFileParams,
13
+ TranspileFileOutput,
14
+ } from '@teambit/compiler';
15
+
16
+ export class ${namePascalCase} implements Compiler {
17
+
18
+ constructor(readonly id: string, readonly distDir, private compiler: CompilerMain) {}
19
+
20
+ /**
21
+ * Detemines whether unsupported files (such as assets)
22
+ * should be copied by Compiler aspect into the 'dist' directory
23
+ */
24
+ shouldCopyNonSupportedFiles = true;
25
+
26
+ /* The name of the compiler being used. For example, TypeScript, Babel, etc. */
27
+ displayName = '';
28
+
29
+ /* The version of the compiler being used. For example '1.0.0' */
30
+ version(): string {};
31
+
32
+ /**
33
+ * Use this for compilation in the workspace.
34
+ * This will compile one file content at a time (alternatively, use 'transpileComponent') */
35
+ transpileFile( fileContent: string, transpileFileParams: TranspileFileParams): TranspileFileOutput {}
36
+
37
+
38
+ async build(context: BuildContext): Promise<BuiltTaskResult> {
39
+ let componentsResults: ComponentResult[] = [];
40
+ return {
41
+ /* Sets the files to persist as the Component's artifacts,
42
+ and describes them. */
43
+ artifacts: [
44
+ {
45
+ generatedBy: this.id,
46
+ name: 'compilation output',
47
+ globPatterns: [\`\${this.distDir}/**\`],
48
+ },
49
+ ],
50
+ componentsResults,
51
+ };
52
+ }
53
+
54
+ /* This is optional but recommended.
55
+ Not using it will require consumers of your compiler to use two APIs and have two depndencies
56
+ to their Envs - your compiler
57
+ */
58
+ createTask() {
59
+ return this.compiler.createTask('${namePascalCase}', this);
60
+ }
61
+
62
+ /**
63
+ * Given a source file, return its parallel in the dists. e.g. index.ts => dist/index.js.
64
+ * Needed by aspects such as Pkg to determine the main prop.
65
+ */
66
+ getDistPathBySrcPath(srcPath: string): string {}
67
+
68
+ /**
69
+ * Returns a boolean indicating whether a file is supported by the compiler or not.
70
+ * For example, this API is used by Compiler aspect to copy unsupported files to the dist directory.
71
+ */
72
+ isFileSupported(filePath: string): boolean {}
73
+ }
74
+ `;
75
+ }
@@ -0,0 +1,10 @@
1
+ import { ComponentContext } from '@teambit/generator';
2
+
3
+ export function indexFile({ namePascalCase, name }: ComponentContext) {
4
+ return `import { ${namePascalCase}Aspect } from './${name}.aspect';
5
+
6
+ export type { ${namePascalCase}Main } from './${name}.main.runtime';
7
+ export default ${namePascalCase}Aspect;
8
+ export { ${namePascalCase}Aspect };
9
+ `;
10
+ }
@@ -0,0 +1,37 @@
1
+ import { ComponentContext } from '@teambit/generator';
2
+
3
+ export function mainRuntimeFile({ name, namePascalCase }: ComponentContext) {
4
+ return `import { MainRuntime } from '@teambit/cli';
5
+ import { CompilerAspect, CompilerMain } from '@teambit/compiler';
6
+ import { ${namePascalCase} } from './${name}.compiler';
7
+ import { ${namePascalCase}Aspect } from './${name}.aspect';
8
+
9
+ export class ${namePascalCase}Main {
10
+ constructor(private compiler: CompilerMain) {}
11
+
12
+ static slots = [];
13
+ static dependencies = [CompilerAspect];
14
+ static runtime = MainRuntime;
15
+
16
+ distDir = 'dist';
17
+
18
+ /* Set the main property of the component's package with
19
+ the relative output path for the main file */
20
+ getPackageJsonProps() {
21
+ return {
22
+ main: '\${this.distDir}/{main}.js',
23
+ };
24
+ }
25
+
26
+ createCompiler(): ${namePascalCase} {
27
+ return new ${namePascalCase}(${namePascalCase}Aspect.id, this.distDir, this.compiler);
28
+ }
29
+
30
+ static async provider([compiler]: [CompilerMain]) {
31
+ return new ${namePascalCase}Main(compiler);
32
+ }
33
+ }
34
+
35
+ ${namePascalCase}Aspect.addRuntime(${namePascalCase}Main);
36
+ `;
37
+ }
@@ -0,0 +1,32 @@
1
+ import { ComponentContext, ComponentTemplate } from '@teambit/generator';
2
+ import { indexFile } from './files/index-file';
3
+ import { aspectFile } from './files/aspect-file';
4
+ import { mainRuntimeFile } from './files/main-runtime-file';
5
+ import { compilerFile } from './files/compiler-file';
6
+
7
+ export const compilerTemplate: ComponentTemplate = {
8
+ name: 'compiler',
9
+ description: 'A compiler implementation',
10
+ hidden: true,
11
+ generateFiles: (context: ComponentContext) => {
12
+ return [
13
+ {
14
+ relativePath: 'index.ts',
15
+ content: indexFile(context),
16
+ isMain: true,
17
+ },
18
+ {
19
+ relativePath: `${context.name}.aspect.ts`,
20
+ content: aspectFile(context),
21
+ },
22
+ {
23
+ relativePath: `${context.name}.compiler.ts`,
24
+ content: compilerFile(context),
25
+ },
26
+ {
27
+ relativePath: `${context.name}.main.runtime.ts`,
28
+ content: mainRuntimeFile(context),
29
+ },
30
+ ];
31
+ },
32
+ };
@@ -0,0 +1,29 @@
1
+ declare module '*.png' {
2
+ const value: any;
3
+ export = value;
4
+ }
5
+ declare module '*.svg' {
6
+ import type { FunctionComponent, SVGProps } from 'react';
7
+
8
+ export const ReactComponent: FunctionComponent<SVGProps<SVGSVGElement> & { title?: string }>;
9
+ const src: string;
10
+ export default src;
11
+ }
12
+
13
+ // @TODO Gilad
14
+ declare module '*.jpg' {
15
+ const value: any;
16
+ export = value;
17
+ }
18
+ declare module '*.jpeg' {
19
+ const value: any;
20
+ export = value;
21
+ }
22
+ declare module '*.gif' {
23
+ const value: any;
24
+ export = value;
25
+ }
26
+ declare module '*.bmp' {
27
+ const value: any;
28
+ export = value;
29
+ }
@@ -0,0 +1,42 @@
1
+ declare module '*.module.css' {
2
+ const classes: { readonly [key: string]: string };
3
+ export default classes;
4
+ }
5
+ declare module '*.module.scss' {
6
+ const classes: { readonly [key: string]: string };
7
+ export default classes;
8
+ }
9
+ declare module '*.module.sass' {
10
+ const classes: { readonly [key: string]: string };
11
+ export default classes;
12
+ }
13
+
14
+ declare module '*.module.less' {
15
+ const classes: { readonly [key: string]: string };
16
+ export default classes;
17
+ }
18
+
19
+ declare module '*.less' {
20
+ const classes: { readonly [key: string]: string };
21
+ export default classes;
22
+ }
23
+
24
+ declare module '*.css' {
25
+ const classes: { readonly [key: string]: string };
26
+ export default classes;
27
+ }
28
+
29
+ declare module '*.sass' {
30
+ const classes: { readonly [key: string]: string };
31
+ export default classes;
32
+ }
33
+
34
+ declare module '*.scss' {
35
+ const classes: { readonly [key: string]: string };
36
+ export default classes;
37
+ }
38
+
39
+ declare module '*.mdx' {
40
+ const component: any;
41
+ export default component;
42
+ }