Skip to content

Commit 4811c69

Browse files
committed
refactor: move to ES modules
1 parent 664d3db commit 4811c69

Some content is hidden

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

47 files changed

+338
-444
lines changed

docs/tsconfig.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
{
22
"extends": "../tsconfig.json",
33
"compilerOptions": {
4-
"moduleResolution": "bundler"
4+
"module": "preserve",
5+
"moduleResolution": "bundler",
6+
"rewriteRelativeImportExtensions": false,
7+
"noEmit": false
58
},
69
"include": ["**/*"],
710
"mdx": {

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: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@
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+
".": {
29+
"default": "./lib/src/index.js"
30+
}
31+
},
2732
"bin": "bin/create-react-native-library",
2833
"files": [
2934
"lib",
@@ -37,7 +42,7 @@
3742
"registry": "https://registry.npmjs.org/"
3843
},
3944
"scripts": {
40-
"prepare": "babel --extensions .ts,.tsx src --out-dir lib --ignore '**/__tests__/**' --source-maps --delete-dir-on-start"
45+
"prepare": "tsc"
4146
},
4247
"dependencies": {
4348
"cross-spawn": "^7.0.6",
@@ -49,13 +54,10 @@
4954
"kleur": "^4.1.5",
5055
"ora": "^9.3.0",
5156
"pigment": "^0.4.3",
57+
"typescript": "^5.8.3",
5258
"validate-npm-package-name": "^7.0.2"
5359
},
5460
"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",
5961
"@commitlint/config-conventional": "^20.5.0",
6062
"@types/cross-spawn": "^6.0.6",
6163
"@types/dedent": "^0.7.2",

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import path from 'path';
1+
import path from 'node:path';
22
import dedent from 'dedent';
3-
import type { TemplateConfiguration } from './template';
43
import kleur from 'kleur';
4+
import type { TemplateConfiguration } from './template.ts';
55

66
export function printNonLocalLibNextSteps(config: TemplateConfiguration) {
77
const platforms = {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import fs from 'node:fs';
22
import path from 'node:path';
3+
import githubUsername from 'github-username';
34
import { create } from 'pigment';
45
import validateNpmPackage from 'validate-npm-package-name';
5-
import { spawn } from './utils/spawn';
6-
import githubUsername from 'github-username';
7-
import { AVAILABLE_TOOLS } from './utils/configureTools';
6+
import { AVAILABLE_TOOLS } from './utils/configureTools.ts';
7+
import { spawn } from './utils/spawn.ts';
88

99
export type Answers = NonNullable<Awaited<ReturnType<typeof prompt.show>>>;
1010

0 commit comments

Comments
 (0)