Skip to content

Commit 543f3ba

Browse files
chore: proper ESM build with Babel (#90)
1 parent 7a9d5ae commit 543f3ba

File tree

7 files changed

+916
-794
lines changed

7 files changed

+916
-794
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
uses: ./.github/actions/setup
5454

5555
- name: Build package
56-
run: yarn prepare
56+
run: yarn build
5757

5858
test-website:
5959
runs-on: ubuntu-latest

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ buck-out/
2828
# Turborepo
2929
.turbo/
3030

31-
# generated by bob
32-
lib/
31+
# Build process
32+
dist/
3333

3434
/.idea
3535
coverage/

babel.config.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
11
module.exports = {
2-
presets: ['@babel/preset-env', '@babel/preset-typescript'],
2+
presets: [['@babel/preset-env', { targets: { node: 'current' } }], '@babel/preset-typescript'],
3+
4+
env: {
5+
cjs: {
6+
presets: [['@babel/preset-env', { targets: { node: 'current' }, modules: 'commonjs' }]],
7+
plugins: [
8+
['@babel/plugin-transform-modules-commonjs', { strict: true }],
9+
['babel-plugin-add-import-extension', { extension: 'js' }],
10+
],
11+
ignore: ['**/__tests__/*', '**/test.ts', '**/*.d.ts'],
12+
},
13+
14+
esm: {
15+
presets: [['@babel/preset-env', { targets: { node: 'current' }, modules: false }]],
16+
plugins: [['babel-plugin-add-import-extension', { extension: 'mjs' }]],
17+
ignore: ['**/__tests__/*', '**/test.ts', '**/*.d.ts'],
18+
},
19+
},
320
};

package.json

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,42 @@
11
{
22
"name": "ts-regex-builder",
3-
"version": "1.6.0",
3+
"version": "1.6.1-beta.3",
44
"description": "Maintainable regular expressions for TypeScript and JavaScript.",
5-
"main": "lib/commonjs/index.js",
6-
"module": "lib/module/index.js",
7-
"types": "lib/typescript/src/index.d.ts",
8-
"source": "src/index",
5+
"main": "dist/commonjs/index.js",
6+
"module": "dist/esm/index.js",
7+
"types": "dist/types/src/index.d.ts",
8+
"source": "src/index.ts",
99
"sideEffects": false,
1010
"files": [
11-
"src",
12-
"lib",
11+
"dist",
1312
"!**/__tests__",
1413
"!**/__fixtures__",
1514
"!**/__mocks__",
1615
"!**/.*"
1716
],
1817
"exports": {
1918
".": {
20-
"require": "./lib/commonjs/index.js",
21-
"import": "./lib/module/index.js",
22-
"types": "./lib/typescript/src/index.d.ts"
19+
"require": "./dist/commonjs/index.js",
20+
"import": "./dist/esm/index.mjs",
21+
"types": "./dist/types/index.d.ts"
2322
},
2423
"./patterns": {
25-
"require": "./lib/commonjs/patterns/index.js",
26-
"import": "./lib/module/patterns/index.js",
27-
"types": "./lib/typescript/src/patterns/index.d.ts"
24+
"require": "./dist/commonjs/patterns/index.js",
25+
"import": "./dist/esm/patterns/index.mjs",
26+
"types": "./dist/types/patterns/index.d.ts"
2827
}
2928
},
3029
"scripts": {
3130
"test": "jest",
3231
"typecheck": "tsc --noEmit",
3332
"lint": "eslint \"**/*.{js,ts,tsx}\"",
34-
"clean": "del-cli lib",
35-
"prepare": "bob build",
36-
"release": "release-it"
33+
"clean": "del-cli dist",
34+
"release": "release-it",
35+
"release:beta": "release-it --preRelease=beta",
36+
"build": "yarn clean && yarn build:commonjs && yarn build:esm && yarn build:typescript",
37+
"build:commonjs": "BABEL_ENV=cjs babel src --out-dir \"dist/commonjs\" --extensions .js,.ts --out-file-extension .js --source-maps --no-comments",
38+
"build:esm": "BABEL_ENV=esm babel src --out-dir \"dist/esm\" --extensions .js,.ts --out-file-extension .mjs --source-maps --no-comments",
39+
"build:typescript": "tsc --project tsconfig.release.json --outDir \"dist/types\""
3740
},
3841
"keywords": [
3942
"regex",
@@ -50,11 +53,18 @@
5053
"registry": "https://registry.npmjs.org/"
5154
},
5255
"devDependencies": {
56+
"@babel/cli": "^7.22.10",
57+
"@babel/core": "^7.22.10",
58+
"@babel/plugin-syntax-flow": "^7.24.1",
59+
"@babel/plugin-transform-react-jsx": "^7.23.4",
60+
"@babel/preset-env": "^7.22.10",
61+
"@babel/preset-typescript": "^7.22.5",
5362
"@callstack/eslint-config": "^14.1.0",
5463
"@commitlint/config-conventional": "^17.0.2",
5564
"@evilmartians/lefthook": "^1.5.0",
5665
"@release-it/conventional-changelog": "^5.0.0",
5766
"@types/jest": "^28.1.2",
67+
"babel-plugin-add-import-extension": "^1.6.0",
5868
"commitlint": "^17.0.2",
5969
"del-cli": "^5.0.0",
6070
"eslint": "^8.56.0",
@@ -64,7 +74,6 @@
6474
"eslint-plugin-prettier": "^4.0.0",
6575
"jest": "^28.1.1",
6676
"prettier": "^2.0.5",
67-
"react-native-builder-bob": "^0.20.0",
6877
"release-it": "^15.0.0",
6978
"typescript": "^5.0.2"
7079
},
@@ -80,7 +89,7 @@
8089
"src/**/*.{js,jsx,ts,tsx}"
8190
],
8291
"modulePathIgnorePatterns": [
83-
"<rootDir>/lib/"
92+
"<rootDir>/dist/"
8493
]
8594
},
8695
"commitlint": {
@@ -137,7 +146,7 @@
137146
},
138147
"eslintIgnore": [
139148
"node_modules/",
140-
"lib/",
149+
"dist/",
141150
"coverage/",
142151
"website/"
143152
],
@@ -147,19 +156,5 @@
147156
"tabWidth": 2,
148157
"trailingComma": "all",
149158
"useTabs": false
150-
},
151-
"react-native-builder-bob": {
152-
"source": "src",
153-
"output": "lib",
154-
"targets": [
155-
"commonjs",
156-
"module",
157-
[
158-
"typescript",
159-
{
160-
"project": "tsconfig.build.json"
161-
}
162-
]
163-
]
164159
}
165160
}

tsconfig.build.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

tsconfig.release.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "./tsconfig",
3+
"compilerOptions": {
4+
"declaration": true,
5+
"emitDeclarationOnly": true,
6+
"rootDir": "src"
7+
},
8+
"include": ["src/**/*.ts"],
9+
"exclude": ["**/__tests__**", "**/test.ts"]
10+
}

0 commit comments

Comments
 (0)