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 authored Jul 23, 2024
2 parents a202424 + 2a62bed commit 72c5efe
Show file tree
Hide file tree
Showing 16 changed files with 101 additions and 64 deletions.
6 changes: 6 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [0.1.1](https:/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:/callstack/react-native-builder-bob/commit/0c5582bb66f5581693e8e9913f80d2fd40d4d7c5)) - by @

# [0.1.0](https:/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.1.1",
"private": true,
"description": "Documentation for react-native-builder-bob",
"scripts": {
Expand Down
12 changes: 5 additions & 7 deletions docs/pages/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ yarn add --dev react-native-builder-bob

```json
"source": "./src/index.tsx",
"main": "./lib/commonjs/index.cjs",
"module": "./lib/module/index.mjs",
"main": "./lib/commonjs/index.js",
"module": "./lib/module/index.js",
"types": "./lib/typescript/src/index.d.ts",
"exports": {
".": {
"types": "./typescript/src/index.d.ts",
"import": "./module/index.mjs",
"require": "./commonjs/index.cjs"
"import": "./module/index.js",
"require": "./commonjs/index.js"
}
},
"files": [
Expand All @@ -101,8 +101,6 @@ yarn add --dev react-native-builder-bob

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,7 +166,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.
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.

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

Expand Down
20 changes: 20 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,26 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

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

### Bug Fixes

- add correct script on Android ([#596](https:/callstack/react-native-builder-bob/issues/596)) ([bf38b29](https:/callstack/react-native-builder-bob/commit/bf38b29fba5a40130615a3cbc82a40155b0ef251)) - by @szymonrybczak
- exclude output folder from typescript ([7e00f2b](https:/callstack/react-native-builder-bob/commit/7e00f2bb5d0f59a02b65cb53a700ed19f0de5393)) - by @satya164

## [0.38.3](https:/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:/callstack/react-native-builder-bob/issues/594)) ([ac95039](https:/callstack/react-native-builder-bob/commit/ac9503965015ea5c65d9b7c95e7345fd4ef586ac)) - by @szymonrybczak

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

### Bug Fixes

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

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

### Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion 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.38.4",
"description": "CLI to scaffold React Native libraries",
"keywords": [
"react-native",
Expand Down
11 changes: 7 additions & 4 deletions packages/create-react-native-library/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { spawn } from './utils/spawn';
import { version } from '../package.json';
import { patchExampleAppCodegen } from './utils/patchExampleAppCodegen';

const FALLBACK_BOB_VERSION = '0.25.0';
const FALLBACK_BOB_VERSION = '0.26.0';

const BINARIES = [
/(gradlew|\.(jar|keystore|png|jpg|gif))$/,
Expand Down Expand Up @@ -472,7 +472,10 @@ async function create(_argv: yargs.Arguments<any>) {
});
},
},
{
];

if (!local) {
questions.push({
type: 'select',
name: 'example',
message: 'What type of example app do you want to create?',
Expand All @@ -487,8 +490,8 @@ async function create(_argv: yargs.Arguments<any>) {
return true;
});
},
},
];
});
}

const validate = (answers: Answers) => {
for (const [key, value] of Object.entries(answers)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export default async function generateExampleApp({
const iosBuild = [
'npm run mkdist',
'react-native bundle --entry-file index.js --platform ios --dev true --bundle-output dist/main.ios.jsbundle --assets-dest dist',
SCRIPTS_TO_ADD['build:android'],
SCRIPTS_TO_ADD['build:ios'],
].join(' && ');

Object.assign(scripts, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
"version": "0.1.0",
"description": "<%- project.description %>",
"source": "./src/index.tsx",
"main": "./lib/commonjs/index.cjs",
"module": "./lib/module/index.mjs",
"main": "./lib/commonjs/index.js",
"module": "./lib/module/index.js",
"types": "./lib/typescript/src/index.d.ts",
"exports": {
".": {
"types": "./lib/typescript/src/index.d.ts",
"import": "./lib/module/index.mjs",
"require": "./lib/commonjs/index.cjs"
"import": "./lib/module/index.js",
"require": "./lib/commonjs/index.js"
}
},
"files": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": "./tsconfig",
"exclude": ["example"]
"exclude": ["example", "lib"]
}
10 changes: 10 additions & 0 deletions packages/react-native-builder-bob/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

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

### Bug Fixes

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

### Features

- support ESM config for bob ([9b41a62](https:/callstack/react-native-builder-bob/commit/9b41a626cf661a9967b20a5290515c4690d493b7)) - by @

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

### Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-builder-bob/babel-preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module.exports = function (api, options, cwd) {
[
require.resolve('./lib/babel'),
{
extension: options.esm ? (cjs ? 'cjs' : 'mjs') : undefined,
extension: options.esm ? 'js' : undefined,
},
],
],
Expand Down
4 changes: 2 additions & 2 deletions packages/react-native-builder-bob/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-builder-bob",
"version": "0.25.0",
"version": "0.26.0",
"description": "CLI to build JavaScript files for React Native libraries",
"keywords": [
"react-native",
Expand Down Expand Up @@ -50,7 +50,7 @@
"@babel/preset-react": "^7.17.12",
"@babel/preset-typescript": "^7.17.12",
"browserslist": "^4.20.4",
"cosmiconfig": "^7.0.1",
"cosmiconfig": "^9.0.0",
"cross-spawn": "^7.0.3",
"dedent": "^0.7.0",
"del": "^6.1.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-builder-bob/src/babel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Options = {
* NodeJS requires explicit extension for esm
* The `cjs` extension avoids disambiguity when package.json has "type": "module"
*/
extension?: 'cjs' | 'mjs';
extension?: 'js' | 'cjs' | 'mjs';
/**
* Out of tree platforms to support
* For `import './file'`, we skip adding extension if `file.${platform}.ts` exists
Expand Down
20 changes: 13 additions & 7 deletions packages/react-native-builder-bob/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fs from 'fs-extra';
import kleur from 'kleur';
import dedent from 'dedent';
import yargs from 'yargs';
import { cosmiconfigSync } from 'cosmiconfig';
import { cosmiconfig } from 'cosmiconfig';
import isGitDirty from 'is-git-dirty';
import prompts, { type PromptObject } from './utils/prompts';
import * as logger from './utils/logger';
Expand All @@ -27,8 +27,14 @@ const args: Record<ArgName, yargs.Options> = {
const { name, version } = require('../package.json');

const root = process.cwd();
const explorer = cosmiconfigSync(name, {
searchPlaces: ['package.json', `bob.config.js`, 'bob.config.cjs'],
const explorer = cosmiconfig(name, {
stopDir: root,
searchPlaces: [
'package.json',
'bob.config.mjs',
'bob.config.cjs',
'bob.config.js',
],
});

const FLOW_PRGAMA_REGEX = /\*?\s*@(flow)\b/m;
Expand Down Expand Up @@ -57,7 +63,7 @@ yargs
}

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

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

if (targets.includes('commonjs')) {
entries.main = `./${path.join(output, 'commonjs', 'index.cjs')}`;
entries.main = `./${path.join(output, 'commonjs', 'index.js')}`;
}

entries.module = `./${path.join(output, 'module', 'index.mjs')}`;
entries.module = `./${path.join(output, 'module', 'index.js')}`;
} else if (targets.includes('commonjs')) {
entries.main = `./${path.join(output, 'commonjs', 'index.js')}`;
} else {
Expand Down Expand Up @@ -424,7 +430,7 @@ yargs
);
})
.command('build', 'build files for publishing', args, async (argv) => {
const result = explorer.search();
const result = await explorer.search();

if (!result?.config) {
logger.exit(
Expand Down
14 changes: 9 additions & 5 deletions packages/react-native-builder-bob/src/utils/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,15 @@ export default async function compile({
}
}

const outputExtension = esm
? modules === 'commonjs'
? '.cjs'
: '.mjs'
: '.js';
await fs.mkdirp(output);

if (esm) {
await fs.writeJSON(path.join(output, 'package.json'), {
type: modules === 'commonjs' ? 'commonjs' : 'module',
});
}

const outputExtension = '.js';

await Promise.all(
files.map(async (filepath) => {
Expand Down
48 changes: 19 additions & 29 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3885,13 +3885,6 @@ __metadata:
languageName: node
linkType: hard

"@types/parse-json@npm:^4.0.0":
version: 4.0.0
resolution: "@types/parse-json@npm:4.0.0"
checksum: fd6bce2b674b6efc3db4c7c3d336bd70c90838e8439de639b909ce22f3720d21344f52427f1d9e57b265fcb7f6c018699b99e5e0c208a1a4823014269a6bf35b
languageName: node
linkType: hard

"@types/prompts@npm:^2.0.14":
version: 2.4.4
resolution: "@types/prompts@npm:2.4.4"
Expand Down Expand Up @@ -5630,19 +5623,6 @@ __metadata:
languageName: node
linkType: hard

"cosmiconfig@npm:^7.0.1":
version: 7.1.0
resolution: "cosmiconfig@npm:7.1.0"
dependencies:
"@types/parse-json": ^4.0.0
import-fresh: ^3.2.1
parse-json: ^5.0.0
path-type: ^4.0.0
yaml: ^1.10.0
checksum: c53bf7befc1591b2651a22414a5e786cd5f2eeaa87f3678a3d49d6069835a9d8d1aef223728e98aa8fec9a95bf831120d245096db12abe019fecb51f5696c96f
languageName: node
linkType: hard

"cosmiconfig@npm:^8.0.0":
version: 8.3.6
resolution: "cosmiconfig@npm:8.3.6"
Expand All @@ -5660,6 +5640,23 @@ __metadata:
languageName: node
linkType: hard

"cosmiconfig@npm:^9.0.0":
version: 9.0.0
resolution: "cosmiconfig@npm:9.0.0"
dependencies:
env-paths: ^2.2.1
import-fresh: ^3.3.0
js-yaml: ^4.1.0
parse-json: ^5.2.0
peerDependencies:
typescript: ">=4.9.5"
peerDependenciesMeta:
typescript:
optional: true
checksum: a30c424b53d442ea0bdd24cb1b3d0d8687c8dda4a17ab6afcdc439f8964438801619cdb66e8e79f63b9caa3e6586b60d8bab9ce203e72df6c5e80179b971fe8f
languageName: node
linkType: hard

"create-jest@npm:^29.7.0":
version: 29.7.0
resolution: "create-jest@npm:29.7.0"
Expand Down Expand Up @@ -6598,7 +6595,7 @@ __metadata:
languageName: node
linkType: hard

"env-paths@npm:^2.2.0":
"env-paths@npm:^2.2.0, env-paths@npm:^2.2.1":
version: 2.2.1
resolution: "env-paths@npm:2.2.1"
checksum: 65b5df55a8bab92229ab2b40dad3b387fad24613263d103a97f91c9fe43ceb21965cd3392b1ccb5d77088021e525c4e0481adb309625d0cb94ade1d1fb8dc17e
Expand Down Expand Up @@ -12866,7 +12863,7 @@ __metadata:
"@types/yargs": ^17.0.10
browserslist: ^4.20.4
concurrently: ^7.2.2
cosmiconfig: ^7.0.1
cosmiconfig: ^9.0.0
cross-spawn: ^7.0.3
dedent: ^0.7.0
del: ^6.1.1
Expand Down Expand Up @@ -15456,13 +15453,6 @@ __metadata:
languageName: node
linkType: hard

"yaml@npm:^1.10.0":
version: 1.10.2
resolution: "yaml@npm:1.10.2"
checksum: ce4ada136e8a78a0b08dc10b4b900936912d15de59905b2bf415b4d33c63df1d555d23acb2a41b23cf9fb5da41c256441afca3d6509de7247daa062fd2c5ea5f
languageName: node
linkType: hard

"yargs-parser@npm:^20.2.2, yargs-parser@npm:^20.2.3":
version: 20.2.9
resolution: "yargs-parser@npm:20.2.9"
Expand Down

0 comments on commit 72c5efe

Please sign in to comment.