-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
18870c1
commit 94dd8b0
Showing
14 changed files
with
183 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
module.exports = { | ||
preset: 'react-native', | ||
transform: { | ||
'^.+\\.(tsx?|jsx?)$': '@react-native-esbuild/jest', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# preset | ||
jest-preset.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# `@react-native-esbuild/jest` | ||
|
||
> react-native preset for jest powered by @react-native-esbuild | ||
## Usage | ||
|
||
```js | ||
exports.default = { | ||
preset: 'react-native', | ||
transform: { | ||
'^.+\\.(jsx?|tsx?)$': '@react-native-esbuild/jest', | ||
}, | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const esbuild = require('esbuild'); | ||
const { getEsbuildBaseOptions } = require('../../../shared'); | ||
|
||
const buildOptions = getEsbuildBaseOptions(__dirname); | ||
|
||
esbuild.build(buildOptions).catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type { TransformerFactory } from '@jest/transform'; | ||
import { ReactNativeEsbuildJestTransformer } from './transformer'; | ||
|
||
const factory: TransformerFactory<ReactNativeEsbuildJestTransformer> = { | ||
createTransformer() { | ||
return new ReactNativeEsbuildJestTransformer(); | ||
}, | ||
}; | ||
|
||
export default factory; |
44 changes: 44 additions & 0 deletions
44
packages/jest/lib/transformer/ReactNativeEsbuildJestTransformer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import type { TransformOptions, TransformedSource } from '@jest/transform'; | ||
import { ReactNativeEsbuildBundler } from '@react-native-esbuild/core'; | ||
import { SyncTransformPipeline } from '@react-native-esbuild/transformer'; | ||
import { getReactNativeInitializeCore } from '@react-native-esbuild/internal'; | ||
import type { JestTransformer } from '../types'; | ||
|
||
const DUMMY_ESBUILD_VALUE = ''; | ||
|
||
ReactNativeEsbuildBundler.bootstrap(); | ||
|
||
export class ReactNativeEsbuildJestTransformer implements JestTransformer { | ||
private root = process.cwd(); | ||
private transformPipeline: SyncTransformPipeline; | ||
public canInstrument = false; | ||
|
||
constructor() { | ||
const { transformer } = ReactNativeEsbuildBundler.getConfig(); | ||
this.transformPipeline = new SyncTransformPipeline.builder(this.root, '') | ||
.setInjectScripts([getReactNativeInitializeCore(this.root)]) | ||
.setFullyTransformPackages(transformer?.fullyTransformPackageNames ?? []) | ||
.setStripFlowPackages(transformer?.stripFlowPackageNames ?? []) | ||
.setAdditionalBabelTransformRules( | ||
transformer?.additionalTransformRules?.babel ?? [], | ||
) | ||
.setAdditionalSwcTransformRules( | ||
transformer?.additionalTransformRules?.swc ?? [], | ||
) | ||
.build(); | ||
} | ||
|
||
process( | ||
code: string, | ||
path: string, | ||
_options: TransformOptions, | ||
): TransformedSource { | ||
const transformResult = this.transformPipeline.transform(code, { | ||
path, | ||
pluginData: DUMMY_ESBUILD_VALUE, | ||
namespace: DUMMY_ESBUILD_VALUE, | ||
suffix: DUMMY_ESBUILD_VALUE, | ||
}); | ||
return { code: transformResult.code }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './ReactNativeEsbuildJestTransformer'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import type { SyncTransformer } from '@jest/transform'; | ||
import type { Config } from '@react-native-esbuild/core'; | ||
|
||
export type JestTransformer = SyncTransformer<Config>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{ | ||
"name": "@react-native-esbuild/jest", | ||
"version": "0.1.0-beta.9", | ||
"description": "react-native preset for jest powered by @react-native-esbuild", | ||
"keywords": [ | ||
"react-native", | ||
"esbuild", | ||
"jest" | ||
], | ||
"author": "leegeunhyeok <[email protected]>", | ||
"homepage": "https://github.com/leegeunhyeok/react-native-esbuild#readme", | ||
"license": "MIT", | ||
"type": "commonjs", | ||
"module": "lib/index.ts", | ||
"main": "dist/index.js", | ||
"types": "dist/lib/index.d.ts", | ||
"exports": { | ||
".": "./dist/index.js", | ||
"./preset": "./jest-preset.js" | ||
}, | ||
"directories": { | ||
"lib": "lib", | ||
"test": "__tests__" | ||
}, | ||
"files": [ | ||
"lib", | ||
"dist", | ||
"jest-preset.js" | ||
], | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/leegeunhyeok/react-native-esbuild.git" | ||
}, | ||
"scripts": { | ||
"prepack": "yarn cleanup && yarn build", | ||
"cleanup": "rimraf ./dist", | ||
"build": "node build/index.js && tsc" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/leegeunhyeok/react-native-esbuild/issues" | ||
}, | ||
"peerDependencies": { | ||
"react-native": "*" | ||
}, | ||
"dependencies": { | ||
"@react-native-esbuild/core": "workspace:*", | ||
"@react-native-esbuild/internal": "workspace:^", | ||
"@react-native-esbuild/transformer": "workspace:*" | ||
}, | ||
"devDependencies": { | ||
"@jest/transform": "^29.7.0", | ||
"esbuild": "^0.19.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": ".", | ||
"outDir": "./dist", | ||
"declaration": true, | ||
"emitDeclarationOnly": true | ||
}, | ||
"include": ["./lib"], | ||
"exclude": ["./dist"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94dd8b0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage report
Test suite run success
83 tests passing in 10 suites.
Report generated by 🧪jest coverage report action from 94dd8b0