@teambit/babel 0.0.555 → 0.0.556

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/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/babel",
3
- "version": "0.0.555",
3
+ "version": "0.0.556",
4
4
  "homepage": "https://bit.dev/teambit/compilation/babel",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.compilation",
8
8
  "name": "babel",
9
- "version": "0.0.555"
9
+ "version": "0.0.556"
10
10
  },
11
11
  "dependencies": {
12
12
  "@teambit/harmony": "0.2.11",
@@ -15,12 +15,12 @@
15
15
  "p-map-series": "2.1.0",
16
16
  "@babel/runtime": "7.12.18",
17
17
  "core-js": "^3.0.0",
18
- "@teambit/builder": "0.0.555",
19
- "@teambit/compilation.modules.babel-compiler": "0.0.101",
20
- "@teambit/compiler": "0.0.555",
21
- "@teambit/isolator": "0.0.555",
22
- "@teambit/logger": "0.0.471",
23
- "@teambit/cli": "0.0.386"
18
+ "@teambit/builder": "0.0.556",
19
+ "@teambit/compilation.modules.babel-compiler": "0.0.102",
20
+ "@teambit/compiler": "0.0.556",
21
+ "@teambit/isolator": "0.0.556",
22
+ "@teambit/logger": "0.0.472",
23
+ "@teambit/cli": "0.0.387"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@types/fs-extra": "9.0.7",
@@ -30,10 +30,10 @@
30
30
  "@types/jest": "^26.0.0",
31
31
  "@types/react-dom": "^17.0.5",
32
32
  "@types/node": "12.20.4",
33
- "@teambit/compilation.aspect-docs.babel": "0.0.105"
33
+ "@teambit/compilation.aspect-docs.babel": "0.0.106"
34
34
  },
35
35
  "peerDependencies": {
36
- "@teambit/legacy": "1.0.172",
36
+ "@teambit/legacy": "1.0.173",
37
37
  "react-dom": "^16.8.0 || ^17.0.0",
38
38
  "react": "^16.8.0 || ^17.0.0"
39
39
  },
@@ -61,12 +61,18 @@
61
61
  "react": "-"
62
62
  },
63
63
  "peerDependencies": {
64
- "@teambit/legacy": "1.0.172",
64
+ "@teambit/legacy": "1.0.173",
65
65
  "react-dom": "^16.8.0 || ^17.0.0",
66
66
  "react": "^16.8.0 || ^17.0.0"
67
67
  }
68
68
  }
69
69
  },
70
+ "files": [
71
+ "dist",
72
+ "!dist/tsconfig.tsbuildinfo",
73
+ "README.md",
74
+ "README.mdx"
75
+ ],
70
76
  "private": false,
71
77
  "engines": {
72
78
  "node": ">=12.22.0"
package/babel.aspect.ts DELETED
@@ -1,5 +0,0 @@
1
- import { Aspect } from '@teambit/harmony';
2
-
3
- export const BabelAspect = Aspect.create({
4
- id: 'teambit.compilation/babel',
5
- });
package/babel.compiler.ts DELETED
@@ -1,159 +0,0 @@
1
- import * as babel from '@babel/core';
2
- import mapSeries from 'p-map-series';
3
- import fs from 'fs-extra';
4
- import { BuildContext, BuiltTaskResult, ComponentResult } from '@teambit/builder';
5
- import { Compiler, CompilerMain, TranspileFileParams, TranspileFileOutput } from '@teambit/compiler';
6
- import { Capsule } from '@teambit/isolator';
7
- import { Logger } from '@teambit/logger';
8
- import path from 'path';
9
- import {
10
- isFileSupported,
11
- transpileFileContent,
12
- transpileFilePathAsync,
13
- replaceFileExtToJs,
14
- TranspileContext,
15
- } from '@teambit/compilation.modules.babel-compiler';
16
- import { BabelCompilerOptions } from './compiler-options';
17
-
18
- export class BabelCompiler implements Compiler {
19
- distDir: string;
20
- distGlobPatterns: string[];
21
- shouldCopyNonSupportedFiles: boolean;
22
- artifactName: string;
23
- constructor(
24
- readonly id: string,
25
- private logger: Logger,
26
- private compiler: CompilerMain,
27
- private options: BabelCompilerOptions,
28
- private babelModule = babel
29
- ) {
30
- this.distDir = options.distDir || 'dist';
31
- this.distGlobPatterns = options.distGlobPatterns || [`${this.distDir}/**`, `!${this.distDir}/tsconfig.tsbuildinfo`];
32
- this.shouldCopyNonSupportedFiles =
33
- typeof options.shouldCopyNonSupportedFiles === 'boolean' ? options.shouldCopyNonSupportedFiles : true;
34
- this.artifactName = options.artifactName || 'dist';
35
- }
36
-
37
- displayName = 'Babel';
38
-
39
- version() {
40
- return this.babelModule.version;
41
- }
42
-
43
- /**
44
- * compile one file on the workspace
45
- */
46
- transpileFile(fileContent: string, options: TranspileFileParams): TranspileFileOutput {
47
- const supportedExtensions = ['.ts', '.tsx', '.js', '.jsx'];
48
- const fileExtension = path.extname(options.filePath);
49
- if (!supportedExtensions.includes(fileExtension) || options.filePath.endsWith('.d.ts')) {
50
- return null; // file is not supported
51
- }
52
- const transformOptions = this.options.babelTransformOptions || {};
53
- const context: TranspileContext = {
54
- filePath: options.filePath,
55
- rootDir: options.componentDir,
56
- };
57
- const outputFiles = transpileFileContent(fileContent, context, transformOptions, this.babelModule);
58
- return outputFiles;
59
- }
60
-
61
- /**
62
- * compile multiple components on the capsules
63
- */
64
- async build(context: BuildContext): Promise<BuiltTaskResult> {
65
- const capsules = context.capsuleNetwork.seedersCapsules;
66
- const componentsResults: ComponentResult[] = [];
67
- const longProcessLogger = this.logger.createLongProcessLogger('compile babel components', capsules.length);
68
- await mapSeries(capsules, async (capsule) => {
69
- const currentComponentResult: ComponentResult = {
70
- errors: [],
71
- component: capsule.component,
72
- };
73
- longProcessLogger.logProgress(capsule.component.id.toString());
74
- await this.buildOneCapsule(capsule, currentComponentResult);
75
- componentsResults.push({ ...currentComponentResult });
76
- });
77
-
78
- return {
79
- artifacts: this.getArtifactDefinition(),
80
- componentsResults,
81
- };
82
- }
83
-
84
- createTask(name = 'BabelCompiler') {
85
- return this.compiler.createTask(name, this);
86
- }
87
-
88
- private async buildOneCapsule(capsule: Capsule, componentResult: ComponentResult) {
89
- componentResult.startTime = Date.now();
90
- const sourceFiles = capsule.component.filesystem.files.map((file) => file.relative);
91
- await fs.ensureDir(path.join(capsule.path, this.distDir));
92
- await Promise.all(
93
- sourceFiles.map(async (filePath) => {
94
- const absoluteFilePath = path.join(capsule.path, filePath);
95
- this.options.babelTransformOptions ||= {};
96
- this.options.babelTransformOptions.sourceFileName = path.basename(filePath);
97
- this.options.babelTransformOptions.filename = path.basename(filePath);
98
- try {
99
- const result = await transpileFilePathAsync(
100
- absoluteFilePath,
101
- this.options.babelTransformOptions || {},
102
- this.babelModule
103
- );
104
- if (!result || !result.length) {
105
- this.logger.debug(
106
- `getting an empty response from Babel for the file ${filePath}. it might be configured to be ignored`
107
- );
108
- return;
109
- }
110
- // Make sure to get only the relative path of the dist because we want to add the dist dir.
111
- // If we use the result outputPath we will get an absolute path here
112
- const distPath = this.replaceFileExtToJs(filePath);
113
- const distPathMap = `${distPath}.map`;
114
- await fs.outputFile(path.join(capsule.path, this.distDir, distPath), result[0].outputText);
115
- if (result.length > 1) {
116
- await fs.outputFile(path.join(capsule.path, this.distDir, distPathMap), result[1].outputText);
117
- }
118
- } catch (err: any) {
119
- componentResult.errors?.push(err);
120
- }
121
- })
122
- );
123
- componentResult.endTime = Date.now();
124
- }
125
-
126
- getArtifactDefinition() {
127
- return [
128
- {
129
- generatedBy: this.id,
130
- name: this.artifactName,
131
- globPatterns: this.distGlobPatterns,
132
- },
133
- ];
134
- }
135
-
136
- /**
137
- * given a source file, return its parallel in the dists. e.g. index.ts => dist/index.js
138
- */
139
- getDistPathBySrcPath(srcPath: string) {
140
- const fileWithJSExtIfNeeded = this.replaceFileExtToJs(srcPath);
141
- return path.join(this.distDir, fileWithJSExtIfNeeded);
142
- }
143
-
144
- /**
145
- * whether babel is able to compile the given path
146
- */
147
- isFileSupported(filePath: string): boolean {
148
- return isFileSupported(filePath);
149
- }
150
-
151
- displayConfig() {
152
- return JSON.stringify(this.options.babelTransformOptions || {}, null, 2);
153
- }
154
-
155
- private replaceFileExtToJs(filePath: string): string {
156
- if (!this.isFileSupported(filePath)) return filePath;
157
- return replaceFileExtToJs(filePath);
158
- }
159
- }
@@ -1,7 +0,0 @@
1
- import React from 'react';
2
-
3
- export const Logo = () => (
4
- <div style={{ height: '100%', display: 'flex', justifyContent: 'center' }}>
5
- <img style={{ width: 70 }} src="https://static.bit.dev/brands/logo-babbel.svg" />
6
- </div>
7
- );
package/babel.docs.mdx DELETED
@@ -1,8 +0,0 @@
1
- ---
2
- description: Babel compilation for Bit components
3
- labels: ['babel', 'compiler', 'bit', 'extension', 'aspect']
4
- ---
5
-
6
- import { Babel } from '@teambit/compilation.aspect-docs.babel';
7
-
8
- <Babel />
@@ -1,31 +0,0 @@
1
- import { MainRuntime } from '@teambit/cli';
2
- import { CompilerAspect, CompilerMain } from '@teambit/compiler';
3
- import { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';
4
- import * as babel from '@babel/core';
5
- import { BabelCompilerOptions } from './compiler-options';
6
- import { BabelAspect } from './babel.aspect';
7
- import { BabelCompiler } from './babel.compiler';
8
-
9
- export class BabelMain {
10
- constructor(private logger: Logger, private compiler: CompilerMain) {}
11
-
12
- createCompiler(options: BabelCompilerOptions, babelModule = babel): BabelCompiler {
13
- return new BabelCompiler(BabelAspect.id, this.logger, this.compiler, options, babelModule);
14
- }
15
-
16
- getPackageJsonProps() {
17
- return {
18
- main: 'dist/{main}.js',
19
- };
20
- }
21
-
22
- static runtime = MainRuntime;
23
- static dependencies = [LoggerAspect, CompilerAspect];
24
-
25
- static async provider([loggerExt, compiler]: [LoggerMain, CompilerMain]) {
26
- const logger = loggerExt.createLogger(BabelAspect.id);
27
- return new BabelMain(logger, compiler);
28
- }
29
- }
30
-
31
- BabelAspect.addRuntime(BabelMain);
@@ -1,15 +0,0 @@
1
- import type { TransformOptions } from '@babel/core';
2
- import { CompilerOptions } from '@teambit/compiler';
3
-
4
- export type BabelCompilerOptions = {
5
- /**
6
- * TransformOptions of Babel. @see https://babeljs.io/docs/en/options
7
- *
8
- * `babel.config.json` and `.babelrc.json` use the same options, so you can require the json file
9
- * and pass it as the option parameter. e.g.
10
- * ```
11
- * createCompiler({ babelTransformOptions: require('./babel.config.json') });
12
- * ```
13
- */
14
- babelTransformOptions?: TransformOptions;
15
- } & Partial<CompilerOptions>;
package/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export { BabelCompiler } from './babel.compiler';
2
- export type { BabelMain } from './babel.main.runtime';
3
- export { BabelAspect } from './babel.aspect';
package/tsconfig.json DELETED
@@ -1,34 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "lib": [
4
- "es2019",
5
- "DOM",
6
- "ES6",
7
- "DOM.Iterable",
8
- "ScriptHost"
9
- ],
10
- "target": "es2015",
11
- "module": "commonjs",
12
- "jsx": "react",
13
- "declaration": true,
14
- "sourceMap": true,
15
- "skipLibCheck": true,
16
- "moduleResolution": "node",
17
- "esModuleInterop": true,
18
- "outDir": "dist",
19
- "composite": true,
20
- "emitDeclarationOnly": true,
21
- "experimentalDecorators": true,
22
- "emitDecoratorMetadata": true,
23
- "allowSyntheticDefaultImports": true,
24
- "strictPropertyInitialization": false,
25
- "strict": true,
26
- "noImplicitAny": false,
27
- "rootDir": ".",
28
- "preserveConstEnums": true,
29
- "resolveJsonModule": true
30
- },
31
- "exclude": [
32
- "dist"
33
- ]
34
- }
package/types/asset.d.ts DELETED
@@ -1,29 +0,0 @@
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
- }
package/types/style.d.ts DELETED
@@ -1,42 +0,0 @@
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
- }