Skip to content

Commit ef37512

Browse files
authored
feat(bob): add exclude option to config (callstack#450)
### Summary This adds the possibility to pass custom ignore patterns while working with builder bob. ### Test plan 1. Create a new library using `create-react-native-library`. You can select `Native module`, and `Kotlin & Swift` options. 2. Go to `package.json`, and find the `react-native-builder-bob` section 3. Replace `commonjs` target as following: ```json { "exclude": "**/ignore_me/**" "targets": [ "commonjs", "module", [ "typescript", { "project": "tsconfig.build.json" } ] ] } ``` 4. Create a new folder named `src/ignore_me` and put `.ts` files inside it 5. Build the library and make sure the files inside the `ignore_me` aren't included in the `commonjs` and `module` targets.
1 parent 19396ce commit ef37512

File tree

6 files changed

+29
-1
lines changed

6 files changed

+29
-1
lines changed

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,20 @@ The name of the folder with the source code which should be compiled. The folder
141141

142142
The name of the folder where the compiled files should be output to. It will contain separate folder for each target.
143143

144+
#### `exclude`
145+
146+
Glob pattern to be used while filtering the unnecessary files. Defaults to `'**/{__tests__,__fixtures__,__mocks__}/**'` if you don't specify it.
147+
148+
> This option only works with `commonjs` and `module` targets. To exclude files while building `typescript`, please see [the tsconfig exclude field](https://www.typescriptlang.org/tsconfig#exclude).
149+
150+
Example:
151+
152+
```json
153+
{
154+
"exclude": "ignore_me/**"
155+
}
156+
```
157+
144158
#### `targets`
145159

146160
Various targets to build for. The available targets are:

packages/react-native-builder-bob/src/index.ts

+5
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,9 @@ yargs
390390
);
391391
}
392392

393+
const exclude =
394+
options.exclude ?? '**/{__tests__,__fixtures__,__mocks__}/**';
395+
393396
const report = {
394397
info: logger.info,
395398
warn: logger.warn,
@@ -418,6 +421,7 @@ yargs
418421
root,
419422
source: path.resolve(root, source as string),
420423
output: path.resolve(root, output as string, 'commonjs'),
424+
exclude,
421425
options: targetOptions,
422426
report,
423427
});
@@ -427,6 +431,7 @@ yargs
427431
root,
428432
source: path.resolve(root, source as string),
429433
output: path.resolve(root, output as string, 'module'),
434+
exclude,
430435
options: targetOptions,
431436
report,
432437
});

packages/react-native-builder-bob/src/targets/commonjs.ts

+3
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ type Options = Input & {
1111
sourceMaps?: boolean;
1212
copyFlow?: boolean;
1313
};
14+
exclude: string;
1415
};
1516

1617
export default async function build({
1718
root,
1819
source,
1920
output,
21+
exclude,
2022
options,
2123
report,
2224
}: Options) {
@@ -31,6 +33,7 @@ export default async function build({
3133
root,
3234
source,
3335
output,
36+
exclude,
3437
modules: 'commonjs',
3538
report,
3639
field: 'main',

packages/react-native-builder-bob/src/targets/module.ts

+3
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ type Options = Input & {
1111
sourceMaps?: boolean;
1212
copyFlow?: boolean;
1313
};
14+
exclude: string;
1415
};
1516

1617
export default async function build({
1718
root,
1819
source,
1920
output,
21+
exclude,
2022
options,
2123
report,
2224
}: Options) {
@@ -31,6 +33,7 @@ export default async function build({
3133
root,
3234
source,
3335
output,
36+
exclude,
3437
modules: false,
3538
report,
3639
field: 'module',

packages/react-native-builder-bob/src/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ export type Options = {
1919
source?: string;
2020
output?: string;
2121
targets?: (Target | [Target, object])[];
22+
exclude?: string;
2223
};

packages/react-native-builder-bob/src/utils/compile.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type Options = Input & {
1313
copyFlow?: boolean;
1414
modules: 'commonjs' | false;
1515
field: 'main' | 'module';
16+
exclude: string;
1617
};
1718

1819
export default async function compile({
@@ -21,6 +22,7 @@ export default async function compile({
2122
output,
2223
babelrc = false,
2324
configFile = false,
25+
exclude,
2426
modules,
2527
copyFlow,
2628
sourceMaps = true,
@@ -31,7 +33,7 @@ export default async function compile({
3133
cwd: source,
3234
absolute: true,
3335
nodir: true,
34-
ignore: '**/{__tests__,__fixtures__,__mocks__}/**',
36+
ignore: exclude,
3537
});
3638

3739
report.info(

0 commit comments

Comments
 (0)