Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions dev-packages/rollup-utils/npmHelpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
makeSetSDKSourcePlugin,
makeSucrasePlugin,
} from './plugins/index.mjs';
import { makePackageNodeEsm } from './plugins/make-esm-plugin.mjs';
import { makePackageNodeEsm, makeReactEsmJsxRuntimePlugin } from './plugins/make-esm-plugin.mjs';
import { mergePlugins } from './utils.mjs';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
Expand Down Expand Up @@ -140,7 +140,11 @@ export function makeNPMConfigVariants(baseConfig, options = {}) {

if (emitEsm) {
variantSpecificConfigs.push({
output: { format: 'esm', dir: path.join(baseConfig.output.dir, 'esm'), plugins: [makePackageNodeEsm()] },
output: {
format: 'esm',
dir: path.join(baseConfig.output.dir, 'esm'),
plugins: [makePackageNodeEsm(), makeReactEsmJsxRuntimePlugin()],
},
});
}

Expand Down
15 changes: 15 additions & 0 deletions dev-packages/rollup-utils/plugins/make-esm-plugin.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs from 'node:fs';
import replacePlugin from '@rollup/plugin-replace';

/**
* Outputs a package.json file with {type: module} in the root of the output directory so that Node
Expand Down Expand Up @@ -29,3 +30,17 @@ export function makePackageNodeEsm() {
},
};
}

/**
* Makes sure that whenever we add an `react/jsx-runtime` import, we add a `.js` to make the import esm compatible.
*/
export function makeReactEsmJsxRuntimePlugin() {
return replacePlugin({
preventAssignment: false,
sourceMap: true,
values: {
"'react/jsx-runtime'": "'react/jsx-runtime.js'",
'"react/jsx-runtime"': '"react/jsx-runtime.js"',
},
});
}