Skip to content

Commit 8204129

Browse files
committed
Inject pkg. ver. before publish to reduce a bundle size
To test: 1. Run `npm publish --dry-run` 2. Check index.js
1 parent f432de3 commit 8204129

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

.circleci/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ commands:
109109
name: Yarn Install
110110
command: |
111111
yarn install --frozen-lockfile --no-progress --non-interactive --cache-folder ~/.cache/yarn
112+
yarn prepublishOnly
113+
112114
install-detox:
113115
steps:
114116
- restore-cache-detox-env

index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import './js/ios10Fix';
22

3-
import packageJson from './package.json';
4-
53
export * from './js/URL';
64
export * from './js/URLSearchParams';
75

86
export function setupURLPolyfill() {
9-
globalThis.REACT_NATIVE_URL_POLYFILL = `${packageJson.name}@${packageJson.version}`;
7+
globalThis.REACT_NATIVE_URL_POLYFILL = '<INJECT_VERSION>';
108

119
globalThis.URL = require('./js/URL').URL;
1210
globalThis.URLSearchParams = require('./js/URLSearchParams').URLSearchParams;

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"lint": "eslint .",
2626
"type-check": "tsc index.d.ts",
2727
"prepare": "husky install",
28+
"prepublishOnly": "node scripts/prepublish",
2829
"bundle-size": "node scripts/bundle-size"
2930
},
3031
"author": "Nicolas Charpentier <[email protected]>",

scripts/prepublish.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/node
2+
const fs = require('node:fs');
3+
4+
const packageJson = require('../package.json');
5+
const path = require.resolve('../index.js');
6+
7+
fs.writeFileSync(
8+
path,
9+
fs
10+
.readFileSync(path, 'utf8')
11+
.replace('<INJECT_VERSION>', `${packageJson.name}@${packageJson.version}`),
12+
);

0 commit comments

Comments
 (0)