From f6225fd67cd23695c0f130a357106798bee342e1 Mon Sep 17 00:00:00 2001 From: Satyajit Sahoo Date: Thu, 14 Sep 2023 10:07:08 +0200 Subject: [PATCH] fix: add rootDir to tsconfig for consistent output folder structure (#460) --- README.md | 6 +++--- .../templates/common/$package.json | 2 +- .../templates/common/tsconfig.json | 2 +- packages/react-native-builder-bob/src/index.ts | 1 + tsconfig.json | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 7670324b4..aa59bf92e 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ yarn add --dev react-native-builder-bob "source": "src", "output": "lib", "targets": [ - ["commonjs", {"copyFlow": true}], + "commonjs", "module", "typescript", ] @@ -93,7 +93,7 @@ yarn add --dev react-native-builder-bob "main": "lib/commonjs/index.js", "module": "lib/module/index.js", "react-native": "src/index.ts", - "types": "lib/typescript/index.d.ts", + "types": "lib/typescript/src/index.d.ts", "files": [ "lib/", "src/" @@ -104,7 +104,7 @@ yarn add --dev react-native-builder-bob It's usually good to point to your source code with the `react-native` field to make debugging easier. Metro already supports compiling a lot of new syntaxes including JSX, Flow and TypeScript and it will use this field if present. - If you're building TypeScript definition files, also make sure that the `types` field points to a correct path. Depending on the project configuration, the path can be different for you than the example snippet (e.g. `lib/typescript/index.d.ts` if you have only the `src` directory). + If you're building TypeScript definition files, also make sure that the `types` field points to a correct path. Depending on the project configuration, the path can be different for you than the example snippet (e.g. `lib/typescript/index.d.ts` if you have only the `src` directory and `rootDir` is not set). 1. Add the output directory to `.gitignore` and `.eslintignore` diff --git a/packages/create-react-native-library/templates/common/$package.json b/packages/create-react-native-library/templates/common/$package.json index 92a3f2c1f..6283f9c81 100644 --- a/packages/create-react-native-library/templates/common/$package.json +++ b/packages/create-react-native-library/templates/common/$package.json @@ -4,7 +4,7 @@ "description": "<%- project.description %>", "main": "lib/commonjs/index", "module": "lib/module/index", - "types": "lib/typescript/index.d.ts", + "types": "lib/typescript/src/index.d.ts", "react-native": "src/index", "source": "src/index", "files": [ diff --git a/packages/create-react-native-library/templates/common/tsconfig.json b/packages/create-react-native-library/templates/common/tsconfig.json index e7560c127..cd3d623ba 100644 --- a/packages/create-react-native-library/templates/common/tsconfig.json +++ b/packages/create-react-native-library/templates/common/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "baseUrl": "./", + "rootDir": ".", "paths": { "<%- project.slug -%>": ["./src/index"] }, diff --git a/packages/react-native-builder-bob/src/index.ts b/packages/react-native-builder-bob/src/index.ts index 7a1ba2c06..f0a3f2e5b 100644 --- a/packages/react-native-builder-bob/src/index.ts +++ b/packages/react-native-builder-bob/src/index.ts @@ -182,6 +182,7 @@ yargs JSON.stringify( { compilerOptions: { + rootDir: '.', allowUnreachableCode: false, allowUnusedLabels: false, esModuleInterop: true, diff --git a/tsconfig.json b/tsconfig.json index e506eaa2d..3684c99c3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "baseUrl": ".", + "rootDir": ".", "paths": { "create-react-native-library": [ "./packages/create-react-native-library/src"