@teambit/babel 0.0.651 → 0.0.654
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/{__preview-1645365357220.js → __preview-1645586567752.js} +2 -2
- package/dist/babel.compiler.d.ts +1 -0
- package/dist/babel.compiler.js +49 -21
- package/dist/babel.compiler.js.map +1 -1
- package/dist/compiler-options.d.ts +6 -0
- package/package-tar/teambit-babel-0.0.654.tgz +0 -0
- package/package.json +12 -9
- package/package-tar/teambit-babel-0.0.651.tgz +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.compilation_babel@0.0.
|
|
2
|
-
export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.compilation_babel@0.0.
|
|
1
|
+
export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.compilation_babel@0.0.654/dist/babel.composition.js')]
|
|
2
|
+
export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.compilation_babel@0.0.654/dist/babel.docs.mdx')]
|
package/dist/babel.compiler.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export declare class BabelCompiler implements Compiler {
|
|
|
13
13
|
distGlobPatterns: string[];
|
|
14
14
|
shouldCopyNonSupportedFiles: boolean;
|
|
15
15
|
artifactName: string;
|
|
16
|
+
supportedFilesGlobPatterns: string[] | null;
|
|
16
17
|
constructor(id: string, logger: Logger, compiler: CompilerMain, options: BabelCompilerOptions, babelModule?: typeof babel);
|
|
17
18
|
displayName: string;
|
|
18
19
|
deleteDistDir: boolean;
|
package/dist/babel.compiler.js
CHANGED
|
@@ -31,6 +31,26 @@ function babel() {
|
|
|
31
31
|
return data;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
function _multimatch() {
|
|
35
|
+
const data = _interopRequireDefault(require("multimatch"));
|
|
36
|
+
|
|
37
|
+
_multimatch = function () {
|
|
38
|
+
return data;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
return data;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function _lodash() {
|
|
45
|
+
const data = require("lodash");
|
|
46
|
+
|
|
47
|
+
_lodash = function () {
|
|
48
|
+
return data;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
return data;
|
|
52
|
+
}
|
|
53
|
+
|
|
34
54
|
function _pMapSeries() {
|
|
35
55
|
const data = _interopRequireDefault(require("p-map-series"));
|
|
36
56
|
|
|
@@ -90,12 +110,14 @@ class BabelCompiler {
|
|
|
90
110
|
(0, _defineProperty2().default)(this, "distGlobPatterns", void 0);
|
|
91
111
|
(0, _defineProperty2().default)(this, "shouldCopyNonSupportedFiles", void 0);
|
|
92
112
|
(0, _defineProperty2().default)(this, "artifactName", void 0);
|
|
113
|
+
(0, _defineProperty2().default)(this, "supportedFilesGlobPatterns", void 0);
|
|
93
114
|
(0, _defineProperty2().default)(this, "displayName", 'Babel');
|
|
94
115
|
(0, _defineProperty2().default)(this, "deleteDistDir", false);
|
|
95
116
|
this.distDir = options.distDir || 'dist';
|
|
96
117
|
this.distGlobPatterns = options.distGlobPatterns || [`${this.distDir}/**`, `!${this.distDir}/tsconfig.tsbuildinfo`];
|
|
97
118
|
this.shouldCopyNonSupportedFiles = typeof options.shouldCopyNonSupportedFiles === 'boolean' ? options.shouldCopyNonSupportedFiles : true;
|
|
98
119
|
this.artifactName = options.artifactName || 'dist';
|
|
120
|
+
this.supportedFilesGlobPatterns = options.supportedFilesGlobPatterns ? (0, _lodash().flatten)(options.supportedFilesGlobPatterns) : null;
|
|
99
121
|
}
|
|
100
122
|
|
|
101
123
|
version() {
|
|
@@ -156,35 +178,37 @@ class BabelCompiler {
|
|
|
156
178
|
const sourceFiles = capsule.component.filesystem.files.map(file => file.relative);
|
|
157
179
|
await _fsExtra().default.ensureDir(_path().default.join(capsule.path, this.distDir));
|
|
158
180
|
await Promise.all(sourceFiles.map(async filePath => {
|
|
159
|
-
|
|
181
|
+
if (this.isFileSupported(filePath)) {
|
|
182
|
+
var _this$options;
|
|
160
183
|
|
|
161
|
-
|
|
184
|
+
const absoluteFilePath = _path().default.join(capsule.path, filePath);
|
|
162
185
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
186
|
+
(_this$options = this.options).babelTransformOptions || (_this$options.babelTransformOptions = {});
|
|
187
|
+
this.options.babelTransformOptions.sourceFileName = _path().default.basename(filePath);
|
|
188
|
+
this.options.babelTransformOptions.filename = _path().default.basename(filePath);
|
|
166
189
|
|
|
167
|
-
|
|
168
|
-
|
|
190
|
+
try {
|
|
191
|
+
const result = await (0, _compilationModules().transpileFilePathAsync)(absoluteFilePath, this.options.babelTransformOptions || {}, this.babelModule);
|
|
169
192
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
193
|
+
if (!result || !result.length) {
|
|
194
|
+
this.logger.debug(`getting an empty response from Babel for the file ${filePath}. it might be configured to be ignored`);
|
|
195
|
+
return;
|
|
196
|
+
} // Make sure to get only the relative path of the dist because we want to add the dist dir.
|
|
197
|
+
// If we use the result outputPath we will get an absolute path here
|
|
175
198
|
|
|
176
199
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
200
|
+
const distPath = this.replaceFileExtToJs(filePath);
|
|
201
|
+
const distPathMap = `${distPath}.map`;
|
|
202
|
+
await _fsExtra().default.outputFile(_path().default.join(capsule.path, this.distDir, distPath), result[0].outputText);
|
|
180
203
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
204
|
+
if (result.length > 1) {
|
|
205
|
+
await _fsExtra().default.outputFile(_path().default.join(capsule.path, this.distDir, distPathMap), result[1].outputText);
|
|
206
|
+
}
|
|
207
|
+
} catch (err) {
|
|
208
|
+
var _componentResult$erro;
|
|
186
209
|
|
|
187
|
-
|
|
210
|
+
(_componentResult$erro = componentResult.errors) === null || _componentResult$erro === void 0 ? void 0 : _componentResult$erro.push(err);
|
|
211
|
+
}
|
|
188
212
|
}
|
|
189
213
|
}));
|
|
190
214
|
componentResult.endTime = Date.now();
|
|
@@ -212,6 +236,10 @@ class BabelCompiler {
|
|
|
212
236
|
|
|
213
237
|
|
|
214
238
|
isFileSupported(filePath) {
|
|
239
|
+
if (this.supportedFilesGlobPatterns) {
|
|
240
|
+
return (0, _compilationModules().isFileSupported)(filePath) && !!(0, _multimatch().default)(filePath, this.supportedFilesGlobPatterns).length;
|
|
241
|
+
}
|
|
242
|
+
|
|
215
243
|
return (0, _compilationModules().isFileSupported)(filePath);
|
|
216
244
|
}
|
|
217
245
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["babel.compiler.ts"],"names":["BabelCompiler","constructor","id","logger","compiler","options","babelModule","babel","distDir","distGlobPatterns","shouldCopyNonSupportedFiles","artifactName","version","transpileFile","fileContent","supportedExtensions","fileExtension","path","extname","filePath","includes","endsWith","transformOptions","babelTransformOptions","context","rootDir","componentDir","outputFiles","build","capsules","capsuleNetwork","seedersCapsules","componentsResults","longProcessLogger","createLongProcessLogger","length","capsule","currentComponentResult","errors","component","logProgress","toString","buildOneCapsule","push","artifacts","getArtifactDefinition","createTask","name","componentResult","startTime","Date","now","sourceFiles","filesystem","files","map","file","relative","fs","ensureDir","join","Promise","all","absoluteFilePath","sourceFileName","basename","filename","result","debug","distPath","replaceFileExtToJs","distPathMap","outputFile","outputText","err","endTime","generatedBy","globPatterns","getDistPathBySrcPath","srcPath","fileWithJSExtIfNeeded","isFileSupported","displayConfig","JSON","stringify"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;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ACd,WAAOC,IAAI,CAACC,SAAL,CAAe,KAAK/E,OAAL,CAAakB,qBAAb,IAAsC,EAArD,EAAyD,IAAzD,EAA+D,CAA/D,CAAP;AACD;;AAEO+C,EAAAA,kBAAkB,CAACnD,QAAD,EAA2B;AACnD,QAAI,CAAC,KAAK8D,eAAL,CAAqB9D,QAArB,CAAL,EAAqC,OAAOA,QAAP;AACrC,WAAO,8CAAmBA,QAAnB,CAAP;AACD;;AA7I4C","sourcesContent":["import * as babel from '@babel/core';\nimport mapSeries from 'p-map-series';\nimport fs from 'fs-extra';\nimport { BuildContext, BuiltTaskResult, ComponentResult } from '@teambit/builder';\nimport { Compiler, CompilerMain, TranspileFileParams, TranspileFileOutput } from '@teambit/compiler';\nimport { Capsule } from '@teambit/isolator';\nimport { Logger } from '@teambit/logger';\nimport path from 'path';\nimport {\n isFileSupported,\n transpileFileContent,\n transpileFilePathAsync,\n replaceFileExtToJs,\n TranspileContext,\n} from '@teambit/compilation.modules.babel-compiler';\nimport { BabelCompilerOptions } from './compiler-options';\n\nexport class BabelCompiler implements Compiler {\n distDir: string;\n distGlobPatterns: string[];\n shouldCopyNonSupportedFiles: boolean;\n artifactName: string;\n constructor(\n readonly id: string,\n private logger: Logger,\n private compiler: CompilerMain,\n private options: BabelCompilerOptions,\n private babelModule = babel\n ) {\n this.distDir = options.distDir || 'dist';\n this.distGlobPatterns = options.distGlobPatterns || [`${this.distDir}/**`, `!${this.distDir}/tsconfig.tsbuildinfo`];\n this.shouldCopyNonSupportedFiles =\n typeof options.shouldCopyNonSupportedFiles === 'boolean' ? options.shouldCopyNonSupportedFiles : true;\n this.artifactName = options.artifactName || 'dist';\n }\n\n displayName = 'Babel';\n deleteDistDir = false;\n\n version() {\n return this.babelModule.version;\n }\n\n /**\n * compile one file on the workspace\n */\n transpileFile(fileContent: string, options: TranspileFileParams): TranspileFileOutput {\n const supportedExtensions = ['.ts', '.tsx', '.js', '.jsx'];\n const fileExtension = path.extname(options.filePath);\n if (!supportedExtensions.includes(fileExtension) || options.filePath.endsWith('.d.ts')) {\n return null; // file is not supported\n }\n const transformOptions = this.options.babelTransformOptions || {};\n const context: TranspileContext = {\n filePath: options.filePath,\n rootDir: options.componentDir,\n };\n const outputFiles = transpileFileContent(fileContent, context, transformOptions, this.babelModule);\n return outputFiles;\n }\n\n /**\n * compile multiple components on the capsules\n */\n async build(context: BuildContext): Promise<BuiltTaskResult> {\n const capsules = context.capsuleNetwork.seedersCapsules;\n const componentsResults: ComponentResult[] = [];\n const longProcessLogger = this.logger.createLongProcessLogger('compile babel components', capsules.length);\n await mapSeries(capsules, async (capsule) => {\n const currentComponentResult: ComponentResult = {\n errors: [],\n component: capsule.component,\n };\n longProcessLogger.logProgress(capsule.component.id.toString());\n await this.buildOneCapsule(capsule, currentComponentResult);\n componentsResults.push({ ...currentComponentResult });\n });\n\n return {\n artifacts: this.getArtifactDefinition(),\n componentsResults,\n };\n }\n\n createTask(name = 'BabelCompiler') {\n return this.compiler.createTask(name, this);\n }\n\n private async buildOneCapsule(capsule: Capsule, componentResult: ComponentResult) {\n componentResult.startTime = Date.now();\n const sourceFiles = capsule.component.filesystem.files.map((file) => file.relative);\n await fs.ensureDir(path.join(capsule.path, this.distDir));\n await Promise.all(\n sourceFiles.map(async (filePath) => {\n const absoluteFilePath = path.join(capsule.path, filePath);\n this.options.babelTransformOptions ||= {};\n this.options.babelTransformOptions.sourceFileName = path.basename(filePath);\n this.options.babelTransformOptions.filename = path.basename(filePath);\n try {\n const result = await transpileFilePathAsync(\n absoluteFilePath,\n this.options.babelTransformOptions || {},\n this.babelModule\n );\n if (!result || !result.length) {\n this.logger.debug(\n `getting an empty response from Babel for the file ${filePath}. it might be configured to be ignored`\n );\n return;\n }\n // Make sure to get only the relative path of the dist because we want to add the dist dir.\n // If we use the result outputPath we will get an absolute path here\n const distPath = this.replaceFileExtToJs(filePath);\n const distPathMap = `${distPath}.map`;\n await fs.outputFile(path.join(capsule.path, this.distDir, distPath), result[0].outputText);\n if (result.length > 1) {\n await fs.outputFile(path.join(capsule.path, this.distDir, distPathMap), result[1].outputText);\n }\n } catch (err: any) {\n componentResult.errors?.push(err);\n }\n })\n );\n componentResult.endTime = Date.now();\n }\n\n getArtifactDefinition() {\n return [\n {\n generatedBy: this.id,\n name: this.artifactName,\n globPatterns: this.distGlobPatterns,\n },\n ];\n }\n\n /**\n * given a source file, return its parallel in the dists. e.g. index.ts => dist/index.js\n */\n getDistPathBySrcPath(srcPath: string) {\n const fileWithJSExtIfNeeded = this.replaceFileExtToJs(srcPath);\n return path.join(this.distDir, fileWithJSExtIfNeeded);\n }\n\n /**\n * whether babel is able to compile the given path\n */\n isFileSupported(filePath: string): boolean {\n return isFileSupported(filePath);\n }\n\n displayConfig() {\n return JSON.stringify(this.options.babelTransformOptions || {}, null, 2);\n }\n\n private replaceFileExtToJs(filePath: string): string {\n if (!this.isFileSupported(filePath)) return filePath;\n return replaceFileExtToJs(filePath);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["babel.compiler.ts"],"names":["BabelCompiler","constructor","id","logger","compiler","options","babelModule","babel","distDir","distGlobPatterns","shouldCopyNonSupportedFiles","artifactName","supportedFilesGlobPatterns","version","transpileFile","fileContent","supportedExtensions","fileExtension","path","extname","filePath","includes","endsWith","transformOptions","babelTransformOptions","context","rootDir","componentDir","outputFiles","build","capsules","capsuleNetwork","seedersCapsules","componentsResults","longProcessLogger","createLongProcessLogger","length","capsule","currentComponentResult","errors","component","logProgress","toString","buildOneCapsule","push","artifacts","getArtifactDefinition","createTask","name","componentResult","startTime","Date","now","sourceFiles","filesystem","files","map","file","relative","fs","ensureDir","join","Promise","all","isFileSupported","absoluteFilePath","sourceFileName","basename","filename","result","debug","distPath","replaceFileExtToJs","distPathMap","outputFile","outputText","err","endTime","generatedBy","globPatterns","getDistPathBySrcPath","srcPath","fileWithJSExtIfNeeded","displayConfig","JSON","stringify"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA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OD;AAED;AACF;AACA;;;AACEuE,EAAAA,oBAAoB,CAACC,OAAD,EAAkB;AACpC,UAAMC,qBAAqB,GAAG,KAAKV,kBAAL,CAAwBS,OAAxB,CAA9B;AACA,WAAO/D,gBAAK2C,IAAL,CAAU,KAAKrD,OAAf,EAAwB0E,qBAAxB,CAAP;AACD;AAED;AACF;AACA;;;AACElB,EAAAA,eAAe,CAAC5C,QAAD,EAA4B;AACzC,QAAI,KAAKR,0BAAT,EAAqC;AACnC,aAAO,2CAAgBQ,QAAhB,KAA6B,CAAC,CAAC,2BAAWA,QAAX,EAAqB,KAAKR,0BAA1B,EAAsDwB,MAA5F;AACD;;AACD,WAAO,2CAAgBhB,QAAhB,CAAP;AACD;;AAED+D,EAAAA,aAAa,GAAG;AACd,WAAOC,IAAI,CAACC,SAAL,CAAe,KAAKhF,OAAL,CAAamB,qBAAb,IAAsC,EAArD,EAAyD,IAAzD,EAA+D,CAA/D,CAAP;AACD;;AAEOgD,EAAAA,kBAAkB,CAACpD,QAAD,EAA2B;AACnD,QAAI,CAAC,KAAK4C,eAAL,CAAqB5C,QAArB,CAAL,EAAqC,OAAOA,QAAP;AACrC,WAAO,8CAAmBA,QAAnB,CAAP;AACD;;AAtJ4C","sourcesContent":["import * as babel from '@babel/core';\nimport multimatch from 'multimatch';\nimport { flatten } from 'lodash';\nimport mapSeries from 'p-map-series';\nimport fs from 'fs-extra';\nimport { BuildContext, BuiltTaskResult, ComponentResult } from '@teambit/builder';\nimport { Compiler, CompilerMain, TranspileFileParams, TranspileFileOutput } from '@teambit/compiler';\nimport { Capsule } from '@teambit/isolator';\nimport { Logger } from '@teambit/logger';\nimport path from 'path';\nimport {\n isFileSupported,\n transpileFileContent,\n transpileFilePathAsync,\n replaceFileExtToJs,\n TranspileContext,\n} from '@teambit/compilation.modules.babel-compiler';\nimport { BabelCompilerOptions } from './compiler-options';\n\nexport class BabelCompiler implements Compiler {\n distDir: string;\n distGlobPatterns: string[];\n shouldCopyNonSupportedFiles: boolean;\n artifactName: string;\n supportedFilesGlobPatterns: string[] | null;\n constructor(\n readonly id: string,\n private logger: Logger,\n private compiler: CompilerMain,\n private options: BabelCompilerOptions,\n private babelModule = babel\n ) {\n this.distDir = options.distDir || 'dist';\n this.distGlobPatterns = options.distGlobPatterns || [`${this.distDir}/**`, `!${this.distDir}/tsconfig.tsbuildinfo`];\n this.shouldCopyNonSupportedFiles =\n typeof options.shouldCopyNonSupportedFiles === 'boolean' ? options.shouldCopyNonSupportedFiles : true;\n this.artifactName = options.artifactName || 'dist';\n this.supportedFilesGlobPatterns = options.supportedFilesGlobPatterns\n ? flatten(options.supportedFilesGlobPatterns)\n : null;\n }\n\n displayName = 'Babel';\n deleteDistDir = false;\n\n version() {\n return this.babelModule.version;\n }\n\n /**\n * compile one file on the workspace\n */\n transpileFile(fileContent: string, options: TranspileFileParams): TranspileFileOutput {\n const supportedExtensions = ['.ts', '.tsx', '.js', '.jsx'];\n const fileExtension = path.extname(options.filePath);\n if (!supportedExtensions.includes(fileExtension) || options.filePath.endsWith('.d.ts')) {\n return null; // file is not supported\n }\n const transformOptions = this.options.babelTransformOptions || {};\n const context: TranspileContext = {\n filePath: options.filePath,\n rootDir: options.componentDir,\n };\n const outputFiles = transpileFileContent(fileContent, context, transformOptions, this.babelModule);\n return outputFiles;\n }\n\n /**\n * compile multiple components on the capsules\n */\n async build(context: BuildContext): Promise<BuiltTaskResult> {\n const capsules = context.capsuleNetwork.seedersCapsules;\n const componentsResults: ComponentResult[] = [];\n const longProcessLogger = this.logger.createLongProcessLogger('compile babel components', capsules.length);\n await mapSeries(capsules, async (capsule) => {\n const currentComponentResult: ComponentResult = {\n errors: [],\n component: capsule.component,\n };\n longProcessLogger.logProgress(capsule.component.id.toString());\n await this.buildOneCapsule(capsule, currentComponentResult);\n componentsResults.push({ ...currentComponentResult });\n });\n\n return {\n artifacts: this.getArtifactDefinition(),\n componentsResults,\n };\n }\n\n createTask(name = 'BabelCompiler') {\n return this.compiler.createTask(name, this);\n }\n\n private async buildOneCapsule(capsule: Capsule, componentResult: ComponentResult) {\n componentResult.startTime = Date.now();\n const sourceFiles = capsule.component.filesystem.files.map((file) => file.relative);\n await fs.ensureDir(path.join(capsule.path, this.distDir));\n await Promise.all(\n sourceFiles.map(async (filePath) => {\n if (this.isFileSupported(filePath)) {\n const absoluteFilePath = path.join(capsule.path, filePath);\n this.options.babelTransformOptions ||= {};\n this.options.babelTransformOptions.sourceFileName = path.basename(filePath);\n this.options.babelTransformOptions.filename = path.basename(filePath);\n try {\n const result = await transpileFilePathAsync(\n absoluteFilePath,\n this.options.babelTransformOptions || {},\n this.babelModule\n );\n if (!result || !result.length) {\n this.logger.debug(\n `getting an empty response from Babel for the file ${filePath}. it might be configured to be ignored`\n );\n return;\n }\n // Make sure to get only the relative path of the dist because we want to add the dist dir.\n // If we use the result outputPath we will get an absolute path here\n const distPath = this.replaceFileExtToJs(filePath);\n const distPathMap = `${distPath}.map`;\n await fs.outputFile(path.join(capsule.path, this.distDir, distPath), result[0].outputText);\n if (result.length > 1) {\n await fs.outputFile(path.join(capsule.path, this.distDir, distPathMap), result[1].outputText);\n }\n } catch (err: any) {\n componentResult.errors?.push(err);\n }\n }\n })\n );\n componentResult.endTime = Date.now();\n }\n\n getArtifactDefinition() {\n return [\n {\n generatedBy: this.id,\n name: this.artifactName,\n globPatterns: this.distGlobPatterns,\n },\n ];\n }\n\n /**\n * given a source file, return its parallel in the dists. e.g. index.ts => dist/index.js\n */\n getDistPathBySrcPath(srcPath: string) {\n const fileWithJSExtIfNeeded = this.replaceFileExtToJs(srcPath);\n return path.join(this.distDir, fileWithJSExtIfNeeded);\n }\n\n /**\n * whether babel is able to compile the given path\n */\n isFileSupported(filePath: string): boolean {\n if (this.supportedFilesGlobPatterns) {\n return isFileSupported(filePath) && !!multimatch(filePath, this.supportedFilesGlobPatterns).length;\n }\n return isFileSupported(filePath);\n }\n\n displayConfig() {\n return JSON.stringify(this.options.babelTransformOptions || {}, null, 2);\n }\n\n private replaceFileExtToJs(filePath: string): string {\n if (!this.isFileSupported(filePath)) return filePath;\n return replaceFileExtToJs(filePath);\n }\n}\n"]}
|
|
@@ -11,4 +11,10 @@ export declare type BabelCompilerOptions = {
|
|
|
11
11
|
* ```
|
|
12
12
|
*/
|
|
13
13
|
babelTransformOptions?: TransformOptions;
|
|
14
|
+
/**
|
|
15
|
+
* Determines which files should be compiled by the Babel compiler.
|
|
16
|
+
* It only works with the file types supported by Babel (.ts, .tsx, .js, .jsx, .d.ts).
|
|
17
|
+
* See https://github.com/mrmlnc/fast-glob for the supported glob patters syntax.
|
|
18
|
+
*/
|
|
19
|
+
supportedFilesGlobPatterns?: string[];
|
|
14
20
|
} & Partial<CompilerOptions>;
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,29 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/babel",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.654",
|
|
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.
|
|
9
|
+
"version": "0.0.654"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@teambit/harmony": "0.2.11",
|
|
13
13
|
"@babel/core": "7.12.17",
|
|
14
14
|
"fs-extra": "10.0.0",
|
|
15
|
+
"lodash": "4.17.21",
|
|
16
|
+
"multimatch": "5.0.0",
|
|
15
17
|
"p-map-series": "2.1.0",
|
|
16
18
|
"@babel/runtime": "7.12.18",
|
|
17
19
|
"core-js": "^3.0.0",
|
|
18
|
-
"@teambit/builder": "0.0.
|
|
20
|
+
"@teambit/builder": "0.0.654",
|
|
19
21
|
"@teambit/compilation.modules.babel-compiler": "0.0.124",
|
|
20
|
-
"@teambit/compiler": "0.0.
|
|
21
|
-
"@teambit/isolator": "0.0.
|
|
22
|
-
"@teambit/logger": "0.0.
|
|
23
|
-
"@teambit/cli": "0.0.
|
|
22
|
+
"@teambit/compiler": "0.0.654",
|
|
23
|
+
"@teambit/isolator": "0.0.654",
|
|
24
|
+
"@teambit/logger": "0.0.536",
|
|
25
|
+
"@teambit/cli": "0.0.446"
|
|
24
26
|
},
|
|
25
27
|
"devDependencies": {
|
|
26
28
|
"@types/fs-extra": "9.0.7",
|
|
29
|
+
"@types/lodash": "4.14.165",
|
|
27
30
|
"@types/react": "^17.0.8",
|
|
28
31
|
"@types/mocha": "9.1.0",
|
|
29
32
|
"@types/testing-library__jest-dom": "5.9.5",
|
|
@@ -33,7 +36,7 @@
|
|
|
33
36
|
"@teambit/compilation.aspect-docs.babel": "0.0.132"
|
|
34
37
|
},
|
|
35
38
|
"peerDependencies": {
|
|
36
|
-
"@teambit/legacy": "1.0.
|
|
39
|
+
"@teambit/legacy": "1.0.225",
|
|
37
40
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
38
41
|
"react": "^16.8.0 || ^17.0.0"
|
|
39
42
|
},
|
|
@@ -61,7 +64,7 @@
|
|
|
61
64
|
"react": "-"
|
|
62
65
|
},
|
|
63
66
|
"peerDependencies": {
|
|
64
|
-
"@teambit/legacy": "1.0.
|
|
67
|
+
"@teambit/legacy": "1.0.225",
|
|
65
68
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
66
69
|
"react": "^16.8.0 || ^17.0.0"
|
|
67
70
|
}
|
|
Binary file
|