From 718563dc9329b0afac535b9f4506bda7800a49e4 Mon Sep 17 00:00:00 2001 From: Haroen Viaene Date: Wed, 21 Sep 2022 16:07:24 +0200 Subject: [PATCH] fix(build): remove jsx pragma comments from build output fixes https://github.com/algolia/react-instantsearch/issues/3632 These comments aren't needed, as the jsx is already transpiled, and it can cause issues when someone uses the automatic runtime option, which doesn't allow jsx pragmas fixed in two places - umd / cjs / esm --> babel config - .d.ts --> postprocessing script of the tsc --- babel.config.js | 2 ++ package.json | 2 +- scripts/rollup/{config.js => rollup.config.js} | 0 scripts/typescript/extract.js | 8 ++++++++ 4 files changed, 11 insertions(+), 1 deletion(-) rename scripts/rollup/{config.js => rollup.config.js} (100%) diff --git a/babel.config.js b/babel.config.js index 611faf2bf9..b8b12d01f5 100644 --- a/babel.config.js +++ b/babel.config.js @@ -91,5 +91,7 @@ module.exports = (api) => { ], ], plugins: isTest ? testPlugins : buildPlugins, + // jsx is transpiled, so the comment should no longer be present in the final files + shouldPrintComment: (value) => value !== '* @jsx h ', }; }; diff --git a/package.json b/package.json index 98c63078ee..8f83fb7e56 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "start": "yarn run dev", "dev": "yarn run storybook", "build": "yarn run build:cjs && yarn run build:es && yarn run build:umd && yarn run build:types", - "build:umd": "rm -rf dist && BABEL_ENV=umd rollup --config scripts/rollup/config.js", + "build:umd": "rm -rf dist && BABEL_ENV=umd rollup --config scripts/rollup/rollup.config.js", "build:cjs": "rm -rf cjs && BABEL_ENV=cjs babel src --extensions '.js,.ts,.tsx' --out-dir cjs/ --ignore 'src/index.es.ts','**/__tests__','**/__mocks__' --quiet", "build:es": "rm -rf es && BABEL_ENV=es babel src --extensions '.js,.ts,.tsx' --out-dir es/ --ignore 'src/index.es.ts','**/__tests__','**/__mocks__' --quiet && BABEL_ENV=es babel src/index.es.ts --out-file es/index.js --quiet && echo '{\"type\":\"module\",\"sideEffects\":false}' > es/package.json", "build:types": "./scripts/typescript/extract.js", diff --git a/scripts/rollup/config.js b/scripts/rollup/rollup.config.js similarity index 100% rename from scripts/rollup/config.js rename to scripts/rollup/rollup.config.js diff --git a/scripts/typescript/extract.js b/scripts/typescript/extract.js index 3dcf12e795..4ad5cb9398 100755 --- a/scripts/typescript/extract.js +++ b/scripts/typescript/extract.js @@ -19,6 +19,14 @@ shell.sed( path.join(__dirname, '../../es/**/*.d.ts') ); +// remove @jsx pragma comments (as jsx is transpiled away) +shell.sed( + '-i', + /\/\*\* @jsx h \*\//, + '', + path.join(__dirname, '../../es/**/*.d.ts') +); + console.log(); console.log(`Validating definitions...`);