Skip to content

Commit ef5f6db

Browse files
authored
feat(builder-bob): dont use npm bin to get tsc path (#435)
## Summary Closes #434 The builder bob typescript build phase uses `yarn bin` and `npm bin` commands to locate the `tsc`. However, the `npm bin` command is removed with npm 9.0. Please see: https://github.blog/changelog/2022-10-24-npm-v9-0-0-released/ ## Test plan > Both of the test cases start with the following steps: 1. Clone the repo and cd into `packages/react-native-builder-bob` 2. Run `yarn prepack` to build the builder bob. 3. Run `npm link` 4. Create a new project with `npx create-react-native-library@latest my-awesome-project`. You can select `javascript` as the type. 5. Run `npm link react-native-builder-bob` to link the project. ### Resolve `tsc` automatically 1. Run `npm run prepack` to verify the typescript compilation step works properly. 2. Run `yarn prepack` to verify the typescript compilation step works properly. 3. Run `pnpm prepack` to verify the typescript compilation step works properly. ### Resolve `tsc` using the builder bob config 1. Go to the `package.json` file of the project you've generated. 2. Go to the `react-native-builder-bob` section and specify the tsc binary as following: (the `tsc` line needs to be added.) ```json "react-native-builder-bob": { "source": "src", "output": "lib", "targets": [ "commonjs", "module", [ "typescript", { "project": "tsconfig.build.json", "tsc": "./node_modules/.bin/tsc" } ] ] } ``` 3. Run `npm run prepack` to verify the typescript compilation step works properly. 4. Run `yarn prepack` to verify the typescript compilation step works properly. 5. Run `pnpm prepack` to verify the typescript compilation step works properly.
1 parent 6650bc1 commit ef5f6db

File tree

1 file changed

+1
-24
lines changed

1 file changed

+1
-24
lines changed

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

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -94,30 +94,7 @@ export default async function build({
9494
);
9595
}
9696
} else {
97-
const execpath = process.env.npm_execpath;
98-
const cli = execpath?.split('/').pop()?.includes('yarn') ? 'yarn' : 'npm';
99-
100-
try {
101-
if (cli === 'yarn') {
102-
const result = spawn.sync('yarn', ['bin', 'tsc'], {
103-
stdio: 'pipe',
104-
encoding: 'utf-8',
105-
cwd: root,
106-
});
107-
108-
tsc = result.stdout.trim();
109-
} else {
110-
const result = spawn.sync('npm', ['bin'], {
111-
stdio: 'pipe',
112-
encoding: 'utf-8',
113-
cwd: root,
114-
});
115-
116-
tsc = path.resolve(result.stdout.trim(), 'tsc');
117-
}
118-
} catch (e) {
119-
tsc = path.resolve(root, 'node_modules', '.bin', 'tsc');
120-
}
97+
tsc = path.resolve(root, 'node_modules', '.bin', 'tsc');
12198

12299
if (platform() === 'win32' && !tsc.endsWith('.cmd')) {
123100
tsc += '.cmd';

0 commit comments

Comments
 (0)