Skip to content

Commit 55807ed

Browse files
authored
refactor: move to ES modules (#941)
1 parent 664d3db commit 55807ed

50 files changed

Lines changed: 336 additions & 480 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,4 @@ typings/
8989
lib/
9090
typescript/
9191
doc_build/
92+
*.tsbuildinfo

docs/pages/build.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ To configure your project manually, follow these steps:
6262
```
6363

6464
Note that there is a difference between `prepare` and `prepack` scripts:
65-
6665
- `prepare` is run when:
6766
- The package is published with Yarn 1 (`yarn publish`), npm (`npm publish`) or pnpm (`pnpm publish`)
6867
- The package is installed from a GIT URL with Yarn 1 (`yarn add <git-url>`), npm (`npm install <git-url>`) or pnpm (`pnpm add <git-url>`)
@@ -92,7 +91,6 @@ To configure your project manually, follow these steps:
9291
```
9392

9493
Here is what each of these fields mean:
95-
9694
- `main`: The entry point for legacy setups that don't support the `exports` field. See [Compatibility](./esm.md#compatibility) for more details.
9795
- `types`: The entry point for the TypeScript definitions for legacy setups with `moduleResolution: node10` or `moduleResolution: node`.
9896
- `exports`: The entry points for tools that support the `exports` field in `package.json` - such as Node.js 12+, modern browsers and tools. See [the ESM support guide](./esm.md) for more details.
@@ -171,7 +169,7 @@ See the [ESM support](./esm.md) guide for more details.
171169

172170
To customize the babel config used, you can pass the [`configFile`](https://babeljs.io/docs/en/options#configfile) option as `true` if you have a `babel.config.js` or a path to a custom config file. This will override the default configuration.
173171

174-
It is recommended that you extend the default configuration by using the [`react-native-builder-bob/babel-preset`](https://github.com/callstack/react-native-builder-bob/blob/main/packages/react-native-builder-bob/babel-preset.js) preset in your custom config file:
172+
It is recommended that you extend the default configuration by using the [`react-native-builder-bob/babel-preset`](https://github.com/callstack/react-native-builder-bob/blob/main/packages/react-native-builder-bob/src/configs/babel-preset.cjs) preset in your custom config file:
175173

176174
```js
177175
module.exports = {
@@ -310,7 +308,6 @@ If you want to ship codegen generated code with your library, you can do the fol
310308
```
311309

312310
4. Update imports in your ios code to use the new paths for the generated code:
313-
314311
- If you have a Turbo Module, replace `YourProjectNameSpec.h` with `YourProjectName/YourProjectNameSpec.h`:
315312

316313
```diff

docs/tsconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
{
22
"extends": "../tsconfig.json",
33
"compilerOptions": {
4+
"composite": true,
5+
"tsBuildInfoFile": ".tsbuildinfo",
6+
"module": "preserve",
47
"moduleResolution": "bundler"
58
},
69
"include": ["**/*"],
10+
"exclude": ["doc_build", "node_modules"],
711
"mdx": {
812
"checkMdx": true
913
}

eslint.config.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export default defineConfig(
2222
'@typescript-eslint/no-unsafe-member-access': 'off',
2323
'@typescript-eslint/no-unnecessary-condition': 'off',
2424
'@typescript-eslint/strict-boolean-expressions': 'off',
25+
26+
'import-x/extensions': ['error', 'ignorePackages'],
2527
},
2628
},
2729

packages/create-react-native-library/babel.config.js

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/usr/bin/env node
22

3-
require('../lib/index');
3+
import '../lib/src/index.js';

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
"url": "https://github.com/callstack/react-native-builder-bob/issues"
2424
},
2525
"homepage": "https://oss.callstack.com/react-native-builder-bob/create",
26-
"main": "lib/index.js",
26+
"type": "module",
27+
"exports": {
28+
".": "./lib/src/index.js"
29+
},
2730
"bin": "bin/create-react-native-library",
2831
"files": [
2932
"lib",
@@ -37,7 +40,7 @@
3740
"registry": "https://registry.npmjs.org/"
3841
},
3942
"scripts": {
40-
"prepare": "babel --extensions .ts,.tsx src --out-dir lib --ignore '**/__tests__/**' --source-maps --delete-dir-on-start"
43+
"prepare": "del-cli lib .tsbuildinfo && tsc"
4144
},
4245
"dependencies": {
4346
"cross-spawn": "^7.0.6",
@@ -48,19 +51,17 @@
4851
"github-username": "^9.0.0",
4952
"kleur": "^4.1.5",
5053
"ora": "^9.3.0",
51-
"pigment": "^0.4.3",
54+
"pigment": "^0.4.4",
55+
"typescript": "^5.8.3",
5256
"validate-npm-package-name": "^7.0.2"
5357
},
5458
"devDependencies": {
55-
"@babel/cli": "^7.28.6",
56-
"@babel/core": "^7.29.0",
57-
"@babel/preset-env": "^7.29.2",
58-
"@babel/preset-typescript": "^7.28.5",
5959
"@commitlint/config-conventional": "^20.5.0",
6060
"@types/cross-spawn": "^6.0.6",
6161
"@types/dedent": "^0.7.2",
6262
"@types/ejs": "^3.1.5",
6363
"@types/fs-extra": "^11.0.4",
64-
"@types/validate-npm-package-name": "^4.0.2"
64+
"@types/validate-npm-package-name": "^4.0.2",
65+
"del-cli": "^7.0.0"
6566
}
6667
}

packages/create-react-native-library/src/exampleApp/dependencies.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import path from 'path';
1+
import path from 'node:path';
22
import fs from 'fs-extra';
3-
import sortObjectKeys from '../utils/sortObjectKeys';
3+
import sortObjectKeys from '../utils/sortObjectKeys.ts';
44

55
type PackageJson = {
66
devDependencies?: Record<string, string>;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1+
import path from 'node:path';
12
import dedent from 'dedent';
23
import fs from 'fs-extra';
34
import { getLatestVersion } from 'get-latest-version';
45
import kleur from 'kleur';
5-
import path from 'path';
66
import {
77
SUPPORTED_EXPO_SDK_VERSION,
88
SUPPORTED_MONOREPO_CONFIG_VERSION,
99
SUPPORTED_REACT_NATIVE_VERSION,
10-
} from '../constants';
11-
import type { TemplateConfiguration } from '../template';
12-
import sortObjectKeys from '../utils/sortObjectKeys';
13-
import { spawn } from '../utils/spawn';
10+
} from '../constants.ts';
11+
import type { TemplateConfiguration } from '../template.ts';
12+
import sortObjectKeys from '../utils/sortObjectKeys.ts';
13+
import { spawn } from '../utils/spawn.ts';
1414

1515
const FILES_TO_DELETE = [
1616
'__tests__',

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
import pak from '../package.json';
1+
import path from 'node:path';
22
import fs from 'fs-extra';
33
import kleur from 'kleur';
44
import ora from 'ora';
5-
import path from 'path';
5+
import pak from '../package.json' with { type: 'json' };
66
import {
77
FALLBACK_BOB_VERSION,
88
FALLBACK_NITRO_MODULES_VERSION,
9-
} from './constants';
10-
import { alignDependencyVersionsWithExampleApp } from './exampleApp/dependencies';
11-
import generateExampleApp from './exampleApp/generateExampleApp';
12-
import { printLocalLibNextSteps, printNonLocalLibNextSteps } from './inform';
13-
import { prompt } from './prompt';
14-
import { applyTemplates, generateTemplateConfiguration } from './template';
15-
import { assertNpxExists } from './utils/assert';
16-
import { configureTools } from './utils/configureTools';
17-
import { createInitialGitCommit } from './utils/initialCommit';
9+
} from './constants.ts';
10+
import { alignDependencyVersionsWithExampleApp } from './exampleApp/dependencies.ts';
11+
import generateExampleApp from './exampleApp/generateExampleApp.ts';
12+
import { printLocalLibNextSteps, printNonLocalLibNextSteps } from './inform.ts';
13+
import { prompt } from './prompt.ts';
14+
import { applyTemplates, generateTemplateConfiguration } from './template.ts';
15+
import { assertNpxExists } from './utils/assert.ts';
16+
import { configureTools } from './utils/configureTools.ts';
17+
import { createMetadata } from './utils/createMetadata.ts';
18+
import { createInitialGitCommit } from './utils/initialCommit.ts';
1819
import {
1920
addNitroDependencyToLocalLibrary,
2021
linkLocalLibrary,
21-
} from './utils/local';
22-
import { determinePackageManager } from './utils/packageManager';
23-
import { resolveNpmPackageVersion } from './utils/resolveNpmPackageVersion';
24-
import { createMetadata } from './utils/createMetadata';
22+
} from './utils/local.ts';
23+
import { determinePackageManager } from './utils/packageManager.ts';
24+
import { resolveNpmPackageVersion } from './utils/resolveNpmPackageVersion.ts';
2525

2626
async function create() {
2727
// Prefetch bob version in background while asking questions

0 commit comments

Comments
 (0)