Skip to content

Commit 72c5efe

Browse files
authored
Merge branch 'main' into @atlj/ship-codegen-specs
2 parents a202424 + 2a62bed commit 72c5efe

File tree

16 files changed

+101
-64
lines changed

16 files changed

+101
-64
lines changed

docs/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

6+
## [0.1.1](https://github.com/callstack/react-native-builder-bob/compare/docs@0.1.0...docs@0.1.1) (2024-07-11)
7+
8+
### Bug Fixes
9+
10+
- use an alternative approach to support ESM ([0c5582b](https://github.com/callstack/react-native-builder-bob/commit/0c5582bb66f5581693e8e9913f80d2fd40d4d7c5)) - by @
11+
612
# [0.1.0](https://github.com/callstack/react-native-builder-bob/compare/docs@0.0.6...docs@0.1.0) (2024-07-05)
713

814
### Bug Fixes

docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "docs",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"private": true,
55
"description": "Documentation for react-native-builder-bob",
66
"scripts": {

docs/pages/build.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ yarn add --dev react-native-builder-bob
7474

7575
```json
7676
"source": "./src/index.tsx",
77-
"main": "./lib/commonjs/index.cjs",
78-
"module": "./lib/module/index.mjs",
77+
"main": "./lib/commonjs/index.js",
78+
"module": "./lib/module/index.js",
7979
"types": "./lib/typescript/src/index.d.ts",
8080
"exports": {
8181
".": {
8282
"types": "./typescript/src/index.d.ts",
83-
"import": "./module/index.mjs",
84-
"require": "./commonjs/index.cjs"
83+
"import": "./module/index.js",
84+
"require": "./commonjs/index.js"
8585
}
8686
},
8787
"files": [
@@ -101,8 +101,6 @@ yarn add --dev react-native-builder-bob
101101

102102
Make sure to change specify correct files according to the targets you have enabled.
103103

104-
> The `exports` field also requires the `esm` option to be enabled for the [`commonjs`](#commonjs) and [`module`](#module) targets. In addition, the file extensions of the generated files will be `.js` instead of `.cjs` and `.mjs` if the `esm` option is not enabled.
105-
106104
> 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).
107105
108106
1. Add the output directory to `.gitignore` and `.eslintignore`
@@ -168,7 +166,7 @@ In addition, the following options are supported:
168166

169167
Setting this option to `true` will output ES modules compatible code for Node.js 12+, modern browsers and other tools that support `package.json`'s `exports` field.
170168

171-
This mainly adds file extensions to the imports and exports. Note that file extensions are not added when importing a file that may have platform-specific extensions (e.g. `.android.ts`) to avoid breaking tools. In addition, the generated files will have `.cjs` (CommonJS) and `.mjs` (ES modules) extensions instead of `.js` - this is necessary to disambiguate between the two formats.
169+
This mainly adds file extensions to the imports and exports. Note that file extensions are not added when importing a file that may have platform-specific extensions (e.g. `.android.ts`) to avoid breaking tools.
172170

173171
If you use TypeScript, also make sure to set `"moduleResolution": "Bundler"` in your `tsconfig.json` file.
174172

packages/create-react-native-library/CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,26 @@
33
All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

6+
## [0.38.4](https://github.com/callstack/react-native-builder-bob/compare/create-react-native-library@0.38.3...create-react-native-library@0.38.4) (2024-07-23)
7+
8+
### Bug Fixes
9+
10+
- add correct script on Android ([#596](https://github.com/callstack/react-native-builder-bob/issues/596)) ([bf38b29](https://github.com/callstack/react-native-builder-bob/commit/bf38b29fba5a40130615a3cbc82a40155b0ef251)) - by @szymonrybczak
11+
- exclude output folder from typescript ([7e00f2b](https://github.com/callstack/react-native-builder-bob/commit/7e00f2bb5d0f59a02b65cb53a700ed19f0de5393)) - by @satya164
12+
13+
## [0.38.3](https://github.com/callstack/react-native-builder-bob/compare/create-react-native-library@0.38.2...create-react-native-library@0.38.3) (2024-07-22)
14+
15+
### Bug Fixes
16+
17+
- hide select example question when creating local library ([#594](https://github.com/callstack/react-native-builder-bob/issues/594)) ([ac95039](https://github.com/callstack/react-native-builder-bob/commit/ac9503965015ea5c65d9b7c95e7345fd4ef586ac)) - by @szymonrybczak
18+
19+
## [0.38.2](https://github.com/callstack/react-native-builder-bob/compare/create-react-native-library@0.38.1...create-react-native-library@0.38.2) (2024-07-11)
20+
21+
### Bug Fixes
22+
23+
- bump fallback bob version ([42efae5](https://github.com/callstack/react-native-builder-bob/commit/42efae5f63af05c6564021bbc907ce6d5a7dcc05)) - by @
24+
- use an alternative approach to support ESM ([0c5582b](https://github.com/callstack/react-native-builder-bob/commit/0c5582bb66f5581693e8e9913f80d2fd40d4d7c5)) - by @
25+
626
## [0.38.1](https://github.com/callstack/react-native-builder-bob/compare/create-react-native-library@0.38.0...create-react-native-library@0.38.1) (2024-07-05)
727

828
### Bug Fixes

packages/create-react-native-library/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-react-native-library",
3-
"version": "0.38.1",
3+
"version": "0.38.4",
44
"description": "CLI to scaffold React Native libraries",
55
"keywords": [
66
"react-native",

packages/create-react-native-library/src/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { spawn } from './utils/spawn';
1515
import { version } from '../package.json';
1616
import { patchExampleAppCodegen } from './utils/patchExampleAppCodegen';
1717

18-
const FALLBACK_BOB_VERSION = '0.25.0';
18+
const FALLBACK_BOB_VERSION = '0.26.0';
1919

2020
const BINARIES = [
2121
/(gradlew|\.(jar|keystore|png|jpg|gif))$/,
@@ -472,7 +472,10 @@ async function create(_argv: yargs.Arguments<any>) {
472472
});
473473
},
474474
},
475-
{
475+
];
476+
477+
if (!local) {
478+
questions.push({
476479
type: 'select',
477480
name: 'example',
478481
message: 'What type of example app do you want to create?',
@@ -487,8 +490,8 @@ async function create(_argv: yargs.Arguments<any>) {
487490
return true;
488491
});
489492
},
490-
},
491-
];
493+
});
494+
}
492495

493496
const validate = (answers: Answers) => {
494497
for (const [key, value] of Object.entries(answers)) {

packages/create-react-native-library/src/utils/generateExampleApp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export default async function generateExampleApp({
163163
const iosBuild = [
164164
'npm run mkdist',
165165
'react-native bundle --entry-file index.js --platform ios --dev true --bundle-output dist/main.ios.jsbundle --assets-dest dist',
166-
SCRIPTS_TO_ADD['build:android'],
166+
SCRIPTS_TO_ADD['build:ios'],
167167
].join(' && ');
168168

169169
Object.assign(scripts, {

packages/create-react-native-library/templates/common/$package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
"version": "0.1.0",
44
"description": "<%- project.description %>",
55
"source": "./src/index.tsx",
6-
"main": "./lib/commonjs/index.cjs",
7-
"module": "./lib/module/index.mjs",
6+
"main": "./lib/commonjs/index.js",
7+
"module": "./lib/module/index.js",
88
"types": "./lib/typescript/src/index.d.ts",
99
"exports": {
1010
".": {
1111
"types": "./lib/typescript/src/index.d.ts",
12-
"import": "./lib/module/index.mjs",
13-
"require": "./lib/commonjs/index.cjs"
12+
"import": "./lib/module/index.js",
13+
"require": "./lib/commonjs/index.js"
1414
}
1515
},
1616
"files": [
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"extends": "./tsconfig",
3-
"exclude": ["example"]
3+
"exclude": ["example", "lib"]
44
}

packages/react-native-builder-bob/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

6+
# [0.26.0](https://github.com/callstack/react-native-builder-bob/compare/react-native-builder-bob@0.25.0...react-native-builder-bob@0.26.0) (2024-07-11)
7+
8+
### Bug Fixes
9+
10+
- use an alternative approach to support ESM ([0c5582b](https://github.com/callstack/react-native-builder-bob/commit/0c5582bb66f5581693e8e9913f80d2fd40d4d7c5)) - by @
11+
12+
### Features
13+
14+
- support ESM config for bob ([9b41a62](https://github.com/callstack/react-native-builder-bob/commit/9b41a626cf661a9967b20a5290515c4690d493b7)) - by @
15+
616
# [0.25.0](https://github.com/callstack/react-native-builder-bob/compare/react-native-builder-bob@0.24.0...react-native-builder-bob@0.25.0) (2024-07-05)
717

818
### Bug Fixes

packages/react-native-builder-bob/babel-preset.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ module.exports = function (api, options, cwd) {
4747
[
4848
require.resolve('./lib/babel'),
4949
{
50-
extension: options.esm ? (cjs ? 'cjs' : 'mjs') : undefined,
50+
extension: options.esm ? 'js' : undefined,
5151
},
5252
],
5353
],

packages/react-native-builder-bob/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-builder-bob",
3-
"version": "0.25.0",
3+
"version": "0.26.0",
44
"description": "CLI to build JavaScript files for React Native libraries",
55
"keywords": [
66
"react-native",
@@ -50,7 +50,7 @@
5050
"@babel/preset-react": "^7.17.12",
5151
"@babel/preset-typescript": "^7.17.12",
5252
"browserslist": "^4.20.4",
53-
"cosmiconfig": "^7.0.1",
53+
"cosmiconfig": "^9.0.0",
5454
"cross-spawn": "^7.0.3",
5555
"dedent": "^0.7.0",
5656
"del": "^6.1.1",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type Options = {
1414
* NodeJS requires explicit extension for esm
1515
* The `cjs` extension avoids disambiguity when package.json has "type": "module"
1616
*/
17-
extension?: 'cjs' | 'mjs';
17+
extension?: 'js' | 'cjs' | 'mjs';
1818
/**
1919
* Out of tree platforms to support
2020
* For `import './file'`, we skip adding extension if `file.${platform}.ts` exists

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import fs from 'fs-extra';
33
import kleur from 'kleur';
44
import dedent from 'dedent';
55
import yargs from 'yargs';
6-
import { cosmiconfigSync } from 'cosmiconfig';
6+
import { cosmiconfig } from 'cosmiconfig';
77
import isGitDirty from 'is-git-dirty';
88
import prompts, { type PromptObject } from './utils/prompts';
99
import * as logger from './utils/logger';
@@ -27,8 +27,14 @@ const args: Record<ArgName, yargs.Options> = {
2727
const { name, version } = require('../package.json');
2828

2929
const root = process.cwd();
30-
const explorer = cosmiconfigSync(name, {
31-
searchPlaces: ['package.json', `bob.config.js`, 'bob.config.cjs'],
30+
const explorer = cosmiconfig(name, {
31+
stopDir: root,
32+
searchPlaces: [
33+
'package.json',
34+
'bob.config.mjs',
35+
'bob.config.cjs',
36+
'bob.config.js',
37+
],
3238
});
3339

3440
const FLOW_PRGAMA_REGEX = /\*?\s*@(flow)\b/m;
@@ -57,7 +63,7 @@ yargs
5763
}
5864

5965
const pkg = JSON.parse(await fs.readFile(pak, 'utf-8'));
60-
const result = explorer.search();
66+
const result = await explorer.search();
6167

6268
if (result?.config && pkg.devDependencies && name in pkg.devDependencies) {
6369
const { shouldContinue } = await prompts({
@@ -170,10 +176,10 @@ yargs
170176
esm = true;
171177

172178
if (targets.includes('commonjs')) {
173-
entries.main = `./${path.join(output, 'commonjs', 'index.cjs')}`;
179+
entries.main = `./${path.join(output, 'commonjs', 'index.js')}`;
174180
}
175181

176-
entries.module = `./${path.join(output, 'module', 'index.mjs')}`;
182+
entries.module = `./${path.join(output, 'module', 'index.js')}`;
177183
} else if (targets.includes('commonjs')) {
178184
entries.main = `./${path.join(output, 'commonjs', 'index.js')}`;
179185
} else {
@@ -424,7 +430,7 @@ yargs
424430
);
425431
})
426432
.command('build', 'build files for publishing', args, async (argv) => {
427-
const result = explorer.search();
433+
const result = await explorer.search();
428434

429435
if (!result?.config) {
430436
logger.exit(

packages/react-native-builder-bob/src/utils/compile.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,15 @@ export default async function compile({
6565
}
6666
}
6767

68-
const outputExtension = esm
69-
? modules === 'commonjs'
70-
? '.cjs'
71-
: '.mjs'
72-
: '.js';
68+
await fs.mkdirp(output);
69+
70+
if (esm) {
71+
await fs.writeJSON(path.join(output, 'package.json'), {
72+
type: modules === 'commonjs' ? 'commonjs' : 'module',
73+
});
74+
}
75+
76+
const outputExtension = '.js';
7377

7478
await Promise.all(
7579
files.map(async (filepath) => {

yarn.lock

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3885,13 +3885,6 @@ __metadata:
38853885
languageName: node
38863886
linkType: hard
38873887

3888-
"@types/parse-json@npm:^4.0.0":
3889-
version: 4.0.0
3890-
resolution: "@types/parse-json@npm:4.0.0"
3891-
checksum: fd6bce2b674b6efc3db4c7c3d336bd70c90838e8439de639b909ce22f3720d21344f52427f1d9e57b265fcb7f6c018699b99e5e0c208a1a4823014269a6bf35b
3892-
languageName: node
3893-
linkType: hard
3894-
38953888
"@types/prompts@npm:^2.0.14":
38963889
version: 2.4.4
38973890
resolution: "@types/prompts@npm:2.4.4"
@@ -5630,19 +5623,6 @@ __metadata:
56305623
languageName: node
56315624
linkType: hard
56325625

5633-
"cosmiconfig@npm:^7.0.1":
5634-
version: 7.1.0
5635-
resolution: "cosmiconfig@npm:7.1.0"
5636-
dependencies:
5637-
"@types/parse-json": ^4.0.0
5638-
import-fresh: ^3.2.1
5639-
parse-json: ^5.0.0
5640-
path-type: ^4.0.0
5641-
yaml: ^1.10.0
5642-
checksum: c53bf7befc1591b2651a22414a5e786cd5f2eeaa87f3678a3d49d6069835a9d8d1aef223728e98aa8fec9a95bf831120d245096db12abe019fecb51f5696c96f
5643-
languageName: node
5644-
linkType: hard
5645-
56465626
"cosmiconfig@npm:^8.0.0":
56475627
version: 8.3.6
56485628
resolution: "cosmiconfig@npm:8.3.6"
@@ -5660,6 +5640,23 @@ __metadata:
56605640
languageName: node
56615641
linkType: hard
56625642

5643+
"cosmiconfig@npm:^9.0.0":
5644+
version: 9.0.0
5645+
resolution: "cosmiconfig@npm:9.0.0"
5646+
dependencies:
5647+
env-paths: ^2.2.1
5648+
import-fresh: ^3.3.0
5649+
js-yaml: ^4.1.0
5650+
parse-json: ^5.2.0
5651+
peerDependencies:
5652+
typescript: ">=4.9.5"
5653+
peerDependenciesMeta:
5654+
typescript:
5655+
optional: true
5656+
checksum: a30c424b53d442ea0bdd24cb1b3d0d8687c8dda4a17ab6afcdc439f8964438801619cdb66e8e79f63b9caa3e6586b60d8bab9ce203e72df6c5e80179b971fe8f
5657+
languageName: node
5658+
linkType: hard
5659+
56635660
"create-jest@npm:^29.7.0":
56645661
version: 29.7.0
56655662
resolution: "create-jest@npm:29.7.0"
@@ -6598,7 +6595,7 @@ __metadata:
65986595
languageName: node
65996596
linkType: hard
66006597

6601-
"env-paths@npm:^2.2.0":
6598+
"env-paths@npm:^2.2.0, env-paths@npm:^2.2.1":
66026599
version: 2.2.1
66036600
resolution: "env-paths@npm:2.2.1"
66046601
checksum: 65b5df55a8bab92229ab2b40dad3b387fad24613263d103a97f91c9fe43ceb21965cd3392b1ccb5d77088021e525c4e0481adb309625d0cb94ade1d1fb8dc17e
@@ -12866,7 +12863,7 @@ __metadata:
1286612863
"@types/yargs": ^17.0.10
1286712864
browserslist: ^4.20.4
1286812865
concurrently: ^7.2.2
12869-
cosmiconfig: ^7.0.1
12866+
cosmiconfig: ^9.0.0
1287012867
cross-spawn: ^7.0.3
1287112868
dedent: ^0.7.0
1287212869
del: ^6.1.1
@@ -15456,13 +15453,6 @@ __metadata:
1545615453
languageName: node
1545715454
linkType: hard
1545815455

15459-
"yaml@npm:^1.10.0":
15460-
version: 1.10.2
15461-
resolution: "yaml@npm:1.10.2"
15462-
checksum: ce4ada136e8a78a0b08dc10b4b900936912d15de59905b2bf415b4d33c63df1d555d23acb2a41b23cf9fb5da41c256441afca3d6509de7247daa062fd2c5ea5f
15463-
languageName: node
15464-
linkType: hard
15465-
1546615456
"yargs-parser@npm:^20.2.2, yargs-parser@npm:^20.2.3":
1546715457
version: 20.2.9
1546815458
resolution: "yargs-parser@npm:20.2.9"

0 commit comments

Comments
 (0)