Skip to content

Commit

Permalink
fix(build): remove jsx pragma comments from build output
Browse files Browse the repository at this point in the history
fixes algolia/react-instantsearch#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
  • Loading branch information
Haroenv committed Sep 21, 2022
1 parent 50b4999 commit 718563d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ',
};
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
File renamed without changes.
8 changes: 8 additions & 0 deletions scripts/typescript/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -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...`);

Expand Down

0 comments on commit 718563d

Please sign in to comment.