From 298780c187a75212a318a4a03c67d1774fc72799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Gu=CC=88ner?= Date: Thu, 24 Aug 2023 16:58:11 +0300 Subject: [PATCH 1/4] feat(bob): add ignore pattern to config --- README.md | 2 ++ packages/react-native-builder-bob/src/targets/commonjs.ts | 1 + packages/react-native-builder-bob/src/targets/module.ts | 1 + packages/react-native-builder-bob/src/utils/compile.ts | 4 +++- 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7670324b4..42cb15f7f 100644 --- a/README.md +++ b/README.md @@ -153,6 +153,8 @@ In addition, the following options are supported: - `sourceMaps` (`boolean`): Sourcemaps are generated by default alongside the compiled files. You can disable them by setting the `sourceMaps` option to `false`. +- `ignorePattern` (`string`): Glob pattern to be used while filtering the unnecessary files. Defaults to `'**/{__tests__,__fixtures__,__mocks__}/**'` if you don't specify it. + Example: ```json diff --git a/packages/react-native-builder-bob/src/targets/commonjs.ts b/packages/react-native-builder-bob/src/targets/commonjs.ts index 67a9cd493..c71dd30ad 100644 --- a/packages/react-native-builder-bob/src/targets/commonjs.ts +++ b/packages/react-native-builder-bob/src/targets/commonjs.ts @@ -10,6 +10,7 @@ type Options = Input & { configFile?: string | false | null; sourceMaps?: boolean; copyFlow?: boolean; + ignorePattern?: string; }; }; diff --git a/packages/react-native-builder-bob/src/targets/module.ts b/packages/react-native-builder-bob/src/targets/module.ts index 3f71414c6..ffb72901a 100644 --- a/packages/react-native-builder-bob/src/targets/module.ts +++ b/packages/react-native-builder-bob/src/targets/module.ts @@ -10,6 +10,7 @@ type Options = Input & { configFile?: string | false | null; sourceMaps?: boolean; copyFlow?: boolean; + ignorePattern?: string; }; }; diff --git a/packages/react-native-builder-bob/src/utils/compile.ts b/packages/react-native-builder-bob/src/utils/compile.ts index 588dc2ec7..41a042a77 100644 --- a/packages/react-native-builder-bob/src/utils/compile.ts +++ b/packages/react-native-builder-bob/src/utils/compile.ts @@ -11,6 +11,7 @@ type Options = Input & { configFile?: string | false | null; sourceMaps?: boolean; copyFlow?: boolean; + ignorePattern?: string; modules: 'commonjs' | false; field: 'main' | 'module'; }; @@ -21,6 +22,7 @@ export default async function compile({ output, babelrc = false, configFile = false, + ignorePattern = '**/{__tests__,__fixtures__,__mocks__}/**', modules, copyFlow, sourceMaps = true, @@ -31,7 +33,7 @@ export default async function compile({ cwd: source, absolute: true, nodir: true, - ignore: '**/{__tests__,__fixtures__,__mocks__}/**', + ignore: ignorePattern, }); report.info( From 3af641b6dbf58a88acfb10a3a0c8012480952f40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Gu=CC=88ner?= Date: Fri, 15 Sep 2023 14:21:39 +0300 Subject: [PATCH 2/4] feat: make exclude a global option --- README.md | 16 ++++++++++++++-- packages/react-native-builder-bob/src/index.ts | 4 ++-- .../src/targets/commonjs.ts | 2 +- .../src/targets/module.ts | 2 +- packages/react-native-builder-bob/src/types.ts | 1 + .../src/utils/compile.ts | 6 +++--- 6 files changed, 22 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index ab8757a4f..1b259c6c2 100644 --- a/README.md +++ b/README.md @@ -137,6 +137,20 @@ The options can be specified in the `package.json` file under the `react-native- The name of the folder with the source code which should be compiled. The folder should include an `index` file. +#### `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/**" +} +``` + #### `output` The name of the folder where the compiled files should be output to. It will contain separate folder for each target. @@ -161,8 +175,6 @@ In addition, the following options are supported: - `sourceMaps` (`boolean`): Sourcemaps are generated by default alongside the compiled files. You can disable them by setting the `sourceMaps` option to `false`. -- `ignorePattern` (`string`): Glob pattern to be used while filtering the unnecessary files. Defaults to `'**/{__tests__,__fixtures__,__mocks__}/**'` if you don't specify it. - Example: ```json diff --git a/packages/react-native-builder-bob/src/index.ts b/packages/react-native-builder-bob/src/index.ts index df2be360e..0faaca902 100644 --- a/packages/react-native-builder-bob/src/index.ts +++ b/packages/react-native-builder-bob/src/index.ts @@ -418,7 +418,7 @@ yargs root, source: path.resolve(root, source as string), output: path.resolve(root, output as string, 'commonjs'), - options: targetOptions, + options: { ...targetOptions, exclude: options.exclude }, report, }); break; @@ -427,7 +427,7 @@ yargs root, source: path.resolve(root, source as string), output: path.resolve(root, output as string, 'module'), - options: targetOptions, + options: { ...targetOptions, exclude: options.exclude }, report, }); break; diff --git a/packages/react-native-builder-bob/src/targets/commonjs.ts b/packages/react-native-builder-bob/src/targets/commonjs.ts index c71dd30ad..8307b022f 100644 --- a/packages/react-native-builder-bob/src/targets/commonjs.ts +++ b/packages/react-native-builder-bob/src/targets/commonjs.ts @@ -10,7 +10,7 @@ type Options = Input & { configFile?: string | false | null; sourceMaps?: boolean; copyFlow?: boolean; - ignorePattern?: string; + exclude?: string; }; }; diff --git a/packages/react-native-builder-bob/src/targets/module.ts b/packages/react-native-builder-bob/src/targets/module.ts index ffb72901a..cc80b7aa4 100644 --- a/packages/react-native-builder-bob/src/targets/module.ts +++ b/packages/react-native-builder-bob/src/targets/module.ts @@ -10,7 +10,7 @@ type Options = Input & { configFile?: string | false | null; sourceMaps?: boolean; copyFlow?: boolean; - ignorePattern?: string; + exclude?: string; }; }; diff --git a/packages/react-native-builder-bob/src/types.ts b/packages/react-native-builder-bob/src/types.ts index 4d71052ef..3215129c5 100644 --- a/packages/react-native-builder-bob/src/types.ts +++ b/packages/react-native-builder-bob/src/types.ts @@ -19,4 +19,5 @@ export type Options = { source?: string; output?: string; targets?: (Target | [Target, object])[]; + exclude?: string; }; diff --git a/packages/react-native-builder-bob/src/utils/compile.ts b/packages/react-native-builder-bob/src/utils/compile.ts index 6e2b50f96..1f2655827 100644 --- a/packages/react-native-builder-bob/src/utils/compile.ts +++ b/packages/react-native-builder-bob/src/utils/compile.ts @@ -11,7 +11,7 @@ type Options = Input & { configFile?: string | false | null; sourceMaps?: boolean; copyFlow?: boolean; - ignorePattern?: string; + exclude?: string; modules: 'commonjs' | false; field: 'main' | 'module'; }; @@ -22,7 +22,7 @@ export default async function compile({ output, babelrc = false, configFile = false, - ignorePattern = '**/{__tests__,__fixtures__,__mocks__}/**', + exclude = '**/{__tests__,__fixtures__,__mocks__}/**', modules, copyFlow, sourceMaps = true, @@ -33,7 +33,7 @@ export default async function compile({ cwd: source, absolute: true, nodir: true, - ignore: ignorePattern, + ignore: exclude, }); report.info( From 876a19a7984e66be45d956249828d712ca7fb1ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Gu=CC=88ner?= Date: Fri, 15 Sep 2023 14:36:16 +0300 Subject: [PATCH 3/4] docs: move exclude on readme --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1b259c6c2..1ae9bf496 100644 --- a/README.md +++ b/README.md @@ -137,6 +137,10 @@ The options can be specified in the `package.json` file under the `react-native- The name of the folder with the source code which should be compiled. The folder should include an `index` file. +#### `output` + +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. @@ -151,10 +155,6 @@ Example: } ``` -#### `output` - -The name of the folder where the compiled files should be output to. It will contain separate folder for each target. - #### `targets` Various targets to build for. The available targets are: From 950cc596c2e1c7b0b37cfec8c0aee14cd4d982a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Gu=CC=88ner?= Date: Fri, 15 Sep 2023 14:41:34 +0300 Subject: [PATCH 4/4] refactor: pass exclude as a top level param --- packages/react-native-builder-bob/src/index.ts | 9 +++++++-- .../react-native-builder-bob/src/targets/commonjs.ts | 4 +++- packages/react-native-builder-bob/src/targets/module.ts | 4 +++- packages/react-native-builder-bob/src/utils/compile.ts | 4 ++-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/react-native-builder-bob/src/index.ts b/packages/react-native-builder-bob/src/index.ts index 0faaca902..981a7dec8 100644 --- a/packages/react-native-builder-bob/src/index.ts +++ b/packages/react-native-builder-bob/src/index.ts @@ -390,6 +390,9 @@ yargs ); } + const exclude = + options.exclude ?? '**/{__tests__,__fixtures__,__mocks__}/**'; + const report = { info: logger.info, warn: logger.warn, @@ -418,7 +421,8 @@ yargs root, source: path.resolve(root, source as string), output: path.resolve(root, output as string, 'commonjs'), - options: { ...targetOptions, exclude: options.exclude }, + exclude, + options: targetOptions, report, }); break; @@ -427,7 +431,8 @@ yargs root, source: path.resolve(root, source as string), output: path.resolve(root, output as string, 'module'), - options: { ...targetOptions, exclude: options.exclude }, + exclude, + options: targetOptions, report, }); break; diff --git a/packages/react-native-builder-bob/src/targets/commonjs.ts b/packages/react-native-builder-bob/src/targets/commonjs.ts index 8307b022f..2092906cd 100644 --- a/packages/react-native-builder-bob/src/targets/commonjs.ts +++ b/packages/react-native-builder-bob/src/targets/commonjs.ts @@ -10,14 +10,15 @@ type Options = Input & { configFile?: string | false | null; sourceMaps?: boolean; copyFlow?: boolean; - exclude?: string; }; + exclude: string; }; export default async function build({ root, source, output, + exclude, options, report, }: Options) { @@ -32,6 +33,7 @@ export default async function build({ root, source, output, + exclude, modules: 'commonjs', report, field: 'main', diff --git a/packages/react-native-builder-bob/src/targets/module.ts b/packages/react-native-builder-bob/src/targets/module.ts index cc80b7aa4..e6cee46c7 100644 --- a/packages/react-native-builder-bob/src/targets/module.ts +++ b/packages/react-native-builder-bob/src/targets/module.ts @@ -10,14 +10,15 @@ type Options = Input & { configFile?: string | false | null; sourceMaps?: boolean; copyFlow?: boolean; - exclude?: string; }; + exclude: string; }; export default async function build({ root, source, output, + exclude, options, report, }: Options) { @@ -32,6 +33,7 @@ export default async function build({ root, source, output, + exclude, modules: false, report, field: 'module', diff --git a/packages/react-native-builder-bob/src/utils/compile.ts b/packages/react-native-builder-bob/src/utils/compile.ts index 1f2655827..4d089f6b3 100644 --- a/packages/react-native-builder-bob/src/utils/compile.ts +++ b/packages/react-native-builder-bob/src/utils/compile.ts @@ -11,9 +11,9 @@ type Options = Input & { configFile?: string | false | null; sourceMaps?: boolean; copyFlow?: boolean; - exclude?: string; modules: 'commonjs' | false; field: 'main' | 'module'; + exclude: string; }; export default async function compile({ @@ -22,7 +22,7 @@ export default async function compile({ output, babelrc = false, configFile = false, - exclude = '**/{__tests__,__fixtures__,__mocks__}/**', + exclude, modules, copyFlow, sourceMaps = true,