Skip to content

Commit

Permalink
Merge branch 'main' into @atlj/ship-codegen-specs
Browse files Browse the repository at this point in the history
  • Loading branch information
atlj committed Aug 11, 2024
2 parents a202424 + 0d915f4 commit 7cc79da
Show file tree
Hide file tree
Showing 51 changed files with 2,227 additions and 2,094 deletions.
16 changes: 1 addition & 15 deletions .github/workflows/build-templates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,15 @@ jobs:
- view-mixed
- view-new
language:
- java-objc
- java-swift
- kotlin-objc
- kotlin-swift
exclude:
- os: macos-14
language: kotlin-objc
- os: macos-14
language: kotlin-swift
- type: module-new
language: java-swift
- type: module-new
language: kotlin-swift
- type: module-mixed
language: java-swift
- type: module-mixed
language: kotlin-swift
- type: view-new
language: java-swift
- type: view-new
language: kotlin-swift
- type: view-mixed
language: java-swift
- type: view-mixed
language: kotlin-swift
include:
Expand Down Expand Up @@ -161,7 +147,7 @@ jobs:
# Build iOS for only some matrices to skip redundant builds
if [[ ${{ matrix.os }} == macos-14 ]]; then
if [[ ${{ matrix.type }} == view-* && ${{ matrix.language }} == java-* ]] || [[ ${{ matrix.type }} == module-* && ${{ matrix.language }} == java-* ]] || [[ ${{ matrix.type }} == module-* && ${{ matrix.language }} == cpp ]]; then
if [[ ${{ matrix.type }} == view-* && ${{ matrix.language }} == kotlin-* ]] || [[ ${{ matrix.type }} == module-* && ${{ matrix.language }} == kotlin-* ]] || [[ ${{ matrix.type }} == module-* && ${{ matrix.language }} == cpp ]]; then
echo "ios_build=1" >> $GITHUB_ENV
fi
fi
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/pull-request-title.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Pull request title
on:
pull_request_target:
types:
- opened
- edited
- synchronize
- reopened

permissions:
pull-requests: read

jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18 changes: 18 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,24 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [0.2.0](https://github.com/callstack/react-native-builder-bob/compare/[email protected]@0.2.0) (2024-08-01)

### Features

- add esm build option for typescript ([#603](https://github.com/callstack/react-native-builder-bob/issues/603)) ([fd43167](https://github.com/callstack/react-native-builder-bob/commit/fd4316745303fd41036e392b9fa4747f1679bacf)) - by @satya164

## [0.1.2](https://github.com/callstack/react-native-builder-bob/compare/[email protected]@0.1.2) (2024-07-26)

### Bug Fixes

- always create package.json with type regardless of esm option ([#598](https://github.com/callstack/react-native-builder-bob/issues/598)) ([5b45554](https://github.com/callstack/react-native-builder-bob/commit/5b455542fec82fa9edfb41c0da0ddceb4e72c485)) - by @satya164

## [0.1.1](https://github.com/callstack/react-native-builder-bob/compare/[email protected]@0.1.1) (2024-07-11)

### Bug Fixes

- use an alternative approach to support ESM ([0c5582b](https://github.com/callstack/react-native-builder-bob/commit/0c5582bb66f5581693e8e9913f80d2fd40d4d7c5)) - by @

# [0.1.0](https://github.com/callstack/react-native-builder-bob/compare/[email protected]@0.1.0) (2024-07-05)

### Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "docs",
"version": "0.1.0",
"version": "0.2.0",
"private": true,
"description": "Documentation for react-native-builder-bob",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions docs/pages/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"index": "Introduction",
"create": "Scaffold a library",
"build": "Build a library",
"esm": "ESM support",
"faq": "FAQ"
}
37 changes: 22 additions & 15 deletions docs/pages/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ yarn add --dev react-native-builder-bob
"source": "src",
"output": "lib",
"targets": [
["commonjs", { "esm" : true }],
["module", { "esm" : true }],
"typescript",
["commonjs", { "esm": true }],
["module", { "esm": true }],
["typescript", { "esm": true }]
]
}
```
Expand Down Expand Up @@ -74,14 +74,19 @@ yarn add --dev react-native-builder-bob

```json
"source": "./src/index.tsx",
"main": "./lib/commonjs/index.cjs",
"module": "./lib/module/index.mjs",
"types": "./lib/typescript/src/index.d.ts",
"main": "./lib/commonjs/index.js",
"module": "./lib/module/index.js",
"types": "./lib/typescript/commonjs/src/index.d.ts",
"exports": {
".": {
"types": "./typescript/src/index.d.ts",
"import": "./module/index.mjs",
"require": "./commonjs/index.cjs"
"import": {
"types": "./lib/typescript/module/src/index.d.ts",
"default": "./lib/module/index.js"
},
"require": {
"types": "./lib/typescript/commonjs/src/index.d.ts",
"default": "./lib/commonjs/index.js"
}
}
},
"files": [
Expand All @@ -97,12 +102,10 @@ yarn add --dev react-native-builder-bob
- `module`: The entry point for the ES module build. This is used by bundlers such as webpack.
- `types`: The entry point for the TypeScript definitions. This is used by TypeScript to typecheck the code using your library.
- `files`: The files to include in the package when publishing with `npm`.
- `exports`: The entry points for tools that support the `exports` field in `package.json` - such as Node.js 12+ & modern browsers.
- `exports`: The entry points for tools that support the `exports` field in `package.json` - such as Node.js 12+ & modern browsers. See [the ESM support guide](./esm.md) for more details.

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

> 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.
> 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`
Expand Down Expand Up @@ -168,9 +171,7 @@ In addition, the following options are supported:

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.

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.

If you use TypeScript, also make sure to set `"moduleResolution": "Bundler"` in your `tsconfig.json` file.
See the [ESM support](./esm.md) guide for more details.

##### `configFile`

Expand Down Expand Up @@ -228,6 +229,12 @@ Example:

The output file should be referenced in the `types` field or `exports['.'].types` field of `package.json`.

##### `esm`

Setting this option to `true` will output 2 sets of type definitions: one for the CommonJS build and one for the ES module build.

See the [ESM support](./esm.md) guide for more details.

## Commands

The `bob` CLI exposes the following commands:
Expand Down
91 changes: 91 additions & 0 deletions docs/pages/esm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# ESM support

Libraries created with [`create-react-native-library`](./create.md) are pre-configured to work with ESM (ECMAScript Modules) out of the box.

You can verify whether ESM support is enabled by checking the configuration for [`react-native-builder-bob`](./build.md) in the `package.json` file of the library:

```json
"react-native-builder-bob": {
"source": "src",
"output": "lib",
"targets": [
["commonjs", { "esm": true }],
["module", { "esm": true }],
["typescript", { "esm": true }]
]
}
```

The `"esm": true` option enables ESM-compatible output by adding the `.js` extension to the import statements in the generated files. For TypeScript, it also generates 2 sets of type definitions: one for the CommonJS build and one for the ES module build.

It's recommended to specify `"moduleResolution": "Bundler"` in your `tsconfig.json` file as well:

```json
{
"compilerOptions": {
"moduleResolution": "Bundler"
}
}
```

This means that you don't need to specify the file extension in the import statements. They'll be automatically added when possible during the build process.

To make use of the output files, ensure that your `package.json` file contains the following fields:

```json
"main": "./lib/commonjs/index.js",
"module": "./lib/module/index.js",
"types": "./lib/typescript/commonjs/src/index.d.ts",
"exports": {
".": {
"import": {
"types": "./lib/typescript/module/src/index.d.ts",
"default": "./lib/module/index.js"
},
"require": {
"types": "./lib/typescript/commonjs/src/index.d.ts",
"default": "./lib/commonjs/index.js"
}
}
},
```

The `main`, `module` and `types` fields are for legacy setups that don't support the `exports` field. See the [Manual configuration](build.md#manual-configuration) guide for more information about those fields.

The `exports` field is used by modern tools and bundlers to determine the correct entry point. Here, we specify 2 conditions:

- `import`: Used when the library is imported with an `import` statement or a dynamic `import()`. It should point to the ESM build.
- `require`: Used when the library is required with a `require` call. It should point to the CommonJS build.

Each condition has a `types` field - necessary for TypeScript to provide the appropriate definitions for the module system. The type definitions have slightly different semantics for CommonJS and ESM, so it's important to specify them separately.

The `default` field is the fallback entry point for both conditions. It's used for the actual JS code when the library is imported or required.

You can also specify additional conditions for different scenarios, such as `react-native`, `browser`, `production`, `development` etc. Note that support for these conditions depends on the tooling you're using.

## Guidelines

There are still a few things to keep in mind if you want your library to be ESM-compatible:

- Avoid using default exports in your library. Named exports are recommended. Default exports produce a CommonJS module with a `default` property, which will work differently than the ESM build and can cause issues.
- If the library uses platform-specific extensions (e.g., `.ios.js` or `.android.js`), the ESM output will not be compatible with Node.js. It's necessary to omit file extensions from the imports to make platform-specific extensions work, however, Node.js requires file extensions to be present. Bundlers such as Webpack (with [`resolve.fullySpecified: false`](https://webpack.js.org/configuration/module/#resolvefullyspecified)) or Metro can handle this. It's still possible to `require` the CommonJS build directly in Node.js.
- Avoid using `.cjs`, `.mjs`, `.cts` or `.mts` extensions. Metro always requires file extensions in import statements when using `.cjs` or `.mjs` which breaks platform-specific extension resolution.
- Avoid using `"moduleResolution": "Node16"` or `"moduleResolution": "NodeNext"` in your `tsconfig.json` file. They require file extensions in import statements which breaks platform-specific extension resolution.
- If you specify a `react-native` condition in `exports`, make sure that it comes before `import` or `require`. The conditions should be ordered from the most specific to the least specific:

```json
"exports": {
".": {
"import": {
"types": "./lib/typescript/module/src/index.d.ts",
"react-native": "./lib/modules/index.native.js",
"default": "./lib/module/index.js"
},
"require": {
"types": "./lib/typescript/commonjs/src/index.d.ts",
"react-native": "./lib/commonjs/index.native.js",
"default": "./lib/commonjs/index.js"
}
}
}
```
42 changes: 42 additions & 0 deletions packages/create-react-native-library/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,48 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [0.40.0](https://github.com/callstack/react-native-builder-bob/compare/[email protected]@0.40.0) (2024-08-01)

### Bug Fixes

- update babel preset to include class transforms for hermes ([#606](https://github.com/callstack/react-native-builder-bob/issues/606)) ([f0a7a2f](https://github.com/callstack/react-native-builder-bob/commit/f0a7a2f998f7d803e1faf3bc162206f3ed16e9a8)), closes [#605](https://github.com/callstack/react-native-builder-bob/issues/605) - by @satya164

### Features

- add esm build option for typescript ([#603](https://github.com/callstack/react-native-builder-bob/issues/603)) ([fd43167](https://github.com/callstack/react-native-builder-bob/commit/fd4316745303fd41036e392b9fa4747f1679bacf)) - by @satya164

# [0.39.0](https://github.com/callstack/react-native-builder-bob/compare/[email protected]@0.39.0) (2024-07-26)

### Bug Fixes

- prefetch bob version in advance to reduce timeouts ([3a67f50](https://github.com/callstack/react-native-builder-bob/commit/3a67f50e29fee3352a7f83943e1384a37e5b9122)) - by @satya164
- sort dependencies in example package.json ([6bcb6c8](https://github.com/callstack/react-native-builder-bob/commit/6bcb6c86ce3fe77cda644aeb9de99023473caeef)) - by @satya164

### Features

- export babel and metro configs to reduce boilerplate ([#600](https://github.com/callstack/react-native-builder-bob/issues/600)) ([d6cb1ce](https://github.com/callstack/react-native-builder-bob/commit/d6cb1ce6c9ea15fe0c1e5623c84370bffb25878f)) - by @satya164
- use the bob preset for the library during dev ([#599](https://github.com/callstack/react-native-builder-bob/issues/599)) ([3a4e724](https://github.com/callstack/react-native-builder-bob/commit/3a4e7240e9cabcdf76f45724485dbffa79daa011)) - by @satya164

## [0.38.4](https://github.com/callstack/react-native-builder-bob/compare/[email protected]@0.38.4) (2024-07-23)

### Bug Fixes

- 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
- exclude output folder from typescript ([7e00f2b](https://github.com/callstack/react-native-builder-bob/commit/7e00f2bb5d0f59a02b65cb53a700ed19f0de5393)) - by @satya164

## [0.38.3](https://github.com/callstack/react-native-builder-bob/compare/[email protected]@0.38.3) (2024-07-22)

### Bug Fixes

- 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

## [0.38.2](https://github.com/callstack/react-native-builder-bob/compare/[email protected]@0.38.2) (2024-07-11)

### Bug Fixes

- bump fallback bob version ([42efae5](https://github.com/callstack/react-native-builder-bob/commit/42efae5f63af05c6564021bbc907ce6d5a7dcc05)) - by @
- use an alternative approach to support ESM ([0c5582b](https://github.com/callstack/react-native-builder-bob/commit/0c5582bb66f5581693e8e9913f80d2fd40d4d7c5)) - by @

## [0.38.1](https://github.com/callstack/react-native-builder-bob/compare/[email protected]@0.38.1) (2024-07-05)

### Bug Fixes
Expand Down
10 changes: 5 additions & 5 deletions packages/create-react-native-library/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-react-native-library",
"version": "0.38.1",
"version": "0.40.0",
"description": "CLI to scaffold React Native libraries",
"keywords": [
"react-native",
Expand Down Expand Up @@ -52,10 +52,10 @@
"yargs": "^17.5.1"
},
"devDependencies": {
"@babel/cli": "^7.17.10",
"@babel/core": "^7.18.5",
"@babel/preset-env": "^7.18.2",
"@babel/preset-typescript": "^7.17.12",
"@babel/cli": "^7.24.8",
"@babel/core": "^7.25.2",
"@babel/preset-env": "^7.25.2",
"@babel/preset-typescript": "^7.24.7",
"@commitlint/config-conventional": "^17.0.2",
"@types/cross-spawn": "^6.0.2",
"@types/dedent": "^0.7.0",
Expand Down
Loading

0 comments on commit 7cc79da

Please sign in to comment.