Skip to content

Commit db1213f

Browse files
committed
feat: remove cwd
1 parent f2f3bcc commit db1213f

File tree

4 files changed

+37
-43
lines changed

4 files changed

+37
-43
lines changed

docs/pages/build.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,11 @@ Define a custom build target. This is useful to call code generators during the
194194

195195
##### `script`
196196

197-
`bob` will run the script passed in the `script` option. The build process **will throw and exit** if the `build` target is defined without this option.
198-
199-
##### `cwd`
200-
201-
You can set the `cwd` (current working directory) option to specify where the command should be called from. This option accepts **a relative path**, and it will default to the path `build` was called from.
197+
Accepts a script name. `bob` will call the matching script defined under `package.json`'s `scripts` property. The build process **will throw and exit** if the target is defined without this option.
202198

203199
##### `clean`
204200

205-
You can pass a path to this option and `bob` will delete all the files on that path. The path is resolved relatively to the `cwd` option.
201+
You can pass a path to this option and `bob` will delete all the files on that path. The path is resolved relatively to where `build` was called from.
206202

207203
#### `commonjs`
208204

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ async function buildTarget(
592592
output: path.resolve(root, output, 'typescript'),
593593
report,
594594
root,
595-
})
595+
});
596596
break;
597597
default:
598598
logger.exit(`Invalid target ${kleur.blue(targetName)}.`);

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

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,57 +8,50 @@ import del from 'del';
88
type Options = Input & {
99
options?: {
1010
script?: string;
11-
cwd?: string;
1211
clean?: string;
13-
}
12+
};
1413
};
1514

16-
const NO_SCRIPT_ERROR_MESSAGE = dedent(
17-
`No script provided with the custom target.
18-
Example: ${kleur.green('{["custom", { "script": "yarn generateTypes" }}')}`
19-
)
20-
21-
export default async function customTarget({
22-
options,
23-
root,
24-
report
25-
}: Options) {
15+
export default async function customTarget({ options, root, report }: Options) {
2616
if (options?.script === undefined) {
2717
report.error(
28-
NO_SCRIPT_ERROR_MESSAGE
29-
)
30-
process.exit(1)
31-
}
32-
33-
const [scriptBinary, ...scriptParams] = options.script.split(" ");
34-
if (scriptBinary === undefined) {
35-
report.error(
36-
NO_SCRIPT_ERROR_MESSAGE
37-
)
38-
process.exit(1)
39-
}
40-
41-
let cwd = root
42-
if (options.cwd) {
43-
cwd = path.resolve(root, options.cwd)
18+
dedent(
19+
`No script was provided with the custom target.
20+
Example: ${kleur.green('{["custom", { "script": "generateTypes" }}')}`
21+
)
22+
);
23+
process.exit(1);
4424
}
4525

4626
if (options.clean) {
4727
report.info(
48-
`Cleaning up previous custom build at ${kleur.blue(path.relative(root, options.clean))}`
28+
`Cleaning up previous custom build at ${kleur.blue(
29+
path.relative(root, options.clean)
30+
)}`
4931
);
5032

51-
await del([path.resolve(cwd, options.clean)])
33+
await del([path.resolve(root, options.clean)]);
5234
}
5335

36+
const packageManager = process.env.npm_execpath ?? 'npm';
37+
const packageManagerArgs = ['run', options.script];
5438

39+
// usr/bin/yarn -> yarn
40+
const packageManagerName = path.basename(packageManager);
5541
report.info(
56-
`Running ${kleur.blue(options.script)} `
42+
`Calling ${kleur.blue(packageManagerName)} ${kleur.blue(
43+
packageManagerArgs.join(' ')
44+
)}`
5745
);
5846

59-
await spawn(scriptBinary, scriptParams, {
60-
cwd,
61-
})
47+
try {
48+
await spawn(packageManager, packageManagerArgs, {
49+
stdio: ['ignore', 'ignore', 'inherit'],
50+
});
51+
} catch (e) {
52+
report.error(`Couldn't run ${kleur.blue(options.script)} script`);
53+
process.exit(1);
54+
}
6255

63-
report.success(`Ran ${kleur.blue(options.script)} succesfully`)
56+
report.success(`Ran ${kleur.blue(options.script)} script succesfully`);
6457
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ export type Input = {
1313
report: Report;
1414
};
1515

16-
export type Target = 'commonjs' | 'module' | 'typescript' | 'codegen' | 'custom';
16+
export type Target =
17+
| 'commonjs'
18+
| 'module'
19+
| 'typescript'
20+
| 'codegen'
21+
| 'custom';
1722

1823
export type Options = {
1924
source?: string;

0 commit comments

Comments
 (0)