Skip to content

Commit

Permalink
feat(bob): add exclude option to config (#450)
Browse files Browse the repository at this point in the history
### 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.
  • Loading branch information
atlj authored Sep 15, 2023
1 parent 19396ce commit ef37512
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 1 deletion.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,20 @@ The name of the folder with the source code which should be compiled. The folder

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

#### `exclude`

Glob pattern to be used while filtering the unnecessary files. Defaults to `'**/{__tests__,__fixtures__,__mocks__}/**'` if you don't specify it.

> 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).
Example:

```json
{
"exclude": "ignore_me/**"
}
```

#### `targets`

Various targets to build for. The available targets are:
Expand Down
5 changes: 5 additions & 0 deletions packages/react-native-builder-bob/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,9 @@ yargs
);
}

const exclude =
options.exclude ?? '**/{__tests__,__fixtures__,__mocks__}/**';

const report = {
info: logger.info,
warn: logger.warn,
Expand Down Expand Up @@ -418,6 +421,7 @@ yargs
root,
source: path.resolve(root, source as string),
output: path.resolve(root, output as string, 'commonjs'),
exclude,
options: targetOptions,
report,
});
Expand All @@ -427,6 +431,7 @@ yargs
root,
source: path.resolve(root, source as string),
output: path.resolve(root, output as string, 'module'),
exclude,
options: targetOptions,
report,
});
Expand Down
3 changes: 3 additions & 0 deletions packages/react-native-builder-bob/src/targets/commonjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ type Options = Input & {
sourceMaps?: boolean;
copyFlow?: boolean;
};
exclude: string;
};

export default async function build({
root,
source,
output,
exclude,
options,
report,
}: Options) {
Expand All @@ -31,6 +33,7 @@ export default async function build({
root,
source,
output,
exclude,
modules: 'commonjs',
report,
field: 'main',
Expand Down
3 changes: 3 additions & 0 deletions packages/react-native-builder-bob/src/targets/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ type Options = Input & {
sourceMaps?: boolean;
copyFlow?: boolean;
};
exclude: string;
};

export default async function build({
root,
source,
output,
exclude,
options,
report,
}: Options) {
Expand All @@ -31,6 +33,7 @@ export default async function build({
root,
source,
output,
exclude,
modules: false,
report,
field: 'module',
Expand Down
1 change: 1 addition & 0 deletions packages/react-native-builder-bob/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ export type Options = {
source?: string;
output?: string;
targets?: (Target | [Target, object])[];
exclude?: string;
};
4 changes: 3 additions & 1 deletion packages/react-native-builder-bob/src/utils/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Options = Input & {
copyFlow?: boolean;
modules: 'commonjs' | false;
field: 'main' | 'module';
exclude: string;
};

export default async function compile({
Expand All @@ -21,6 +22,7 @@ export default async function compile({
output,
babelrc = false,
configFile = false,
exclude,
modules,
copyFlow,
sourceMaps = true,
Expand All @@ -31,7 +33,7 @@ export default async function compile({
cwd: source,
absolute: true,
nodir: true,
ignore: '**/{__tests__,__fixtures__,__mocks__}/**',
ignore: exclude,
});

report.info(
Expand Down

0 comments on commit ef37512

Please sign in to comment.