@teambit/babel 0.0.582 → 0.0.586

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.
@@ -15,6 +15,7 @@ export declare class BabelCompiler implements Compiler {
15
15
  artifactName: string;
16
16
  constructor(id: string, logger: Logger, compiler: CompilerMain, options: BabelCompilerOptions, babelModule?: typeof babel);
17
17
  displayName: string;
18
+ deleteDistDir: boolean;
18
19
  version(): string;
19
20
  /**
20
21
  * compile one file on the workspace
@@ -91,6 +91,7 @@ class BabelCompiler {
91
91
  (0, _defineProperty2().default)(this, "shouldCopyNonSupportedFiles", void 0);
92
92
  (0, _defineProperty2().default)(this, "artifactName", void 0);
93
93
  (0, _defineProperty2().default)(this, "displayName", 'Babel');
94
+ (0, _defineProperty2().default)(this, "deleteDistDir", false);
94
95
  this.distDir = options.distDir || 'dist';
95
96
  this.distGlobPatterns = options.distGlobPatterns || [`${this.distDir}/**`, `!${this.distDir}/tsconfig.tsbuildinfo`];
96
97
  this.shouldCopyNonSupportedFiles = typeof options.shouldCopyNonSupportedFiles === 'boolean' ? options.shouldCopyNonSupportedFiles : true;
@@ -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","file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E,qBAAxB,CAAP;AACD;AAED;AACF;AACA;;;AACEC,EAAAA,eAAe,CAAC9D,QAAD,EAA4B;AACzC,WAAO,2CAAgBA,QAAhB,CAAP;AACD;;AAED+D,EAAAA,aAAa,GAAG;AACd,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;;AA5I4C","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\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","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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AAKpD,OAAf,EAAwBwE,qBAAxB,CAAP;AACD;AAED;AACF;AACA;;;AACEC,EAAAA,eAAe,CAAC9D,QAAD,EAA4B;AACzC,WAAO,2CAAgBA,QAAhB,CAAP;AACD;;AAED+D,EAAAA,aAAa,GAAG;AACd,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"]}
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/babel",
3
- "version": "0.0.582",
3
+ "version": "0.0.586",
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.582"
9
+ "version": "0.0.586"
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.582",
19
- "@teambit/compilation.modules.babel-compiler": "0.0.115",
20
- "@teambit/compiler": "0.0.582",
21
- "@teambit/isolator": "0.0.582",
22
- "@teambit/logger": "0.0.488",
23
- "@teambit/cli": "0.0.400"
18
+ "@teambit/builder": "0.0.586",
19
+ "@teambit/compilation.modules.babel-compiler": "0.0.117",
20
+ "@teambit/compiler": "0.0.586",
21
+ "@teambit/isolator": "0.0.586",
22
+ "@teambit/logger": "0.0.490",
23
+ "@teambit/cli": "0.0.402"
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.122"
33
+ "@teambit/compilation.aspect-docs.babel": "0.0.124"
34
34
  },
35
35
  "peerDependencies": {
36
- "@teambit/legacy": "1.0.186",
36
+ "@teambit/legacy": "1.0.188",
37
37
  "react-dom": "^16.8.0 || ^17.0.0",
38
38
  "react": "^16.8.0 || ^17.0.0"
39
39
  },
@@ -61,7 +61,7 @@
61
61
  "react": "-"
62
62
  },
63
63
  "peerDependencies": {
64
- "@teambit/legacy": "1.0.186",
64
+ "@teambit/legacy": "1.0.188",
65
65
  "react-dom": "^16.8.0 || ^17.0.0",
66
66
  "react": "^16.8.0 || ^17.0.0"
67
67
  }
package/tsconfig.json CHANGED
@@ -15,6 +15,7 @@
15
15
  "skipLibCheck": true,
16
16
  "moduleResolution": "node",
17
17
  "esModuleInterop": true,
18
+ "resolveJsonModule": true,
18
19
  "composite": true,
19
20
  "emitDeclarationOnly": true,
20
21
  "outDir": "dist",
@@ -25,8 +26,7 @@
25
26
  "strict": true,
26
27
  "noImplicitAny": false,
27
28
  "rootDir": ".",
28
- "preserveConstEnums": true,
29
- "resolveJsonModule": true
29
+ "preserveConstEnums": true
30
30
  },
31
31
  "exclude": [
32
32
  "dist"