From 263f7024afb6ff62d0b6c044d4c2e5803d11bb44 Mon Sep 17 00:00:00 2001 From: D N <4661784+retyui@users.noreply.github.com> Date: Sat, 12 Jul 2025 12:03:46 +0200 Subject: [PATCH] Inject pkg. ver. before publish to reduce a bundle size To test: 1. Run `npm publish --dry-run` 2. Check index.js --- .circleci/config.yml | 2 ++ index.js | 4 +--- package.json | 1 + scripts/prepublish.js | 12 ++++++++++++ 4 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 scripts/prepublish.js diff --git a/.circleci/config.yml b/.circleci/config.yml index 8fd92ac..392da60 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -109,6 +109,8 @@ commands: name: Yarn Install command: | yarn install --frozen-lockfile --no-progress --non-interactive --cache-folder ~/.cache/yarn + cd ~/react-native-url-polyfill && yarn prepublishOnly + install-detox: steps: - restore-cache-detox-env diff --git a/index.js b/index.js index 71611b2..6322dff 100644 --- a/index.js +++ b/index.js @@ -1,12 +1,10 @@ import './js/ios10Fix'; -import packageJson from './package.json'; - export * from './js/URL'; export * from './js/URLSearchParams'; export function setupURLPolyfill() { - globalThis.REACT_NATIVE_URL_POLYFILL = `${packageJson.name}@${packageJson.version}`; + globalThis.REACT_NATIVE_URL_POLYFILL = ''; globalThis.URL = require('./js/URL').URL; globalThis.URLSearchParams = require('./js/URLSearchParams').URLSearchParams; diff --git a/package.json b/package.json index 206937e..a9835a4 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "lint": "eslint .", "type-check": "tsc index.d.ts", "prepare": "husky install", + "prepublishOnly": "node scripts/prepublish", "bundle-size": "node scripts/bundle-size" }, "author": "Nicolas Charpentier ", diff --git a/scripts/prepublish.js b/scripts/prepublish.js new file mode 100644 index 0000000..1c57ef9 --- /dev/null +++ b/scripts/prepublish.js @@ -0,0 +1,12 @@ +#!/usr/bin/node +const fs = require('node:fs'); + +const packageJson = require('../package.json'); +const path = require.resolve('../index.js'); + +fs.writeFileSync( + path, + fs + .readFileSync(path, 'utf8') + .replace('', `${packageJson.name}@${packageJson.version}`), +);