Skip to content

Commit

Permalink
Merge 6202f4b into f6ee82e
Browse files Browse the repository at this point in the history
  • Loading branch information
pomek committed Feb 24, 2023
2 parents f6ee82e + 6202f4b commit 7be9247
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -727,10 +727,17 @@ module.exports = async function releaseSubRepositories( options ) {
// For this reason we have to temporarily replace the extension in the `main` field while the package is being published to npm.
// This change is then reverted.
const hasTypeScriptEntryPoint = packageJson.main && packageJson.main.endsWith( '.ts' );
const hasTypesProperty = !!packageJson.types;

if ( hasTypeScriptEntryPoint ) {
tools.updateJSONFile( packageJsonPath, jsonFile => {
jsonFile.main = jsonFile.main.replace( '.ts', '.js' );
const { main } = jsonFile;

jsonFile.main = main.replace( /\.ts$/, '.js' );

if ( !hasTypesProperty ) {
jsonFile.types = main.replace( /\.ts$/, '.d.ts' );
}

return jsonFile;
} );
Expand All @@ -756,7 +763,11 @@ module.exports = async function releaseSubRepositories( options ) {
// again to the `index.ts` file.
if ( hasTypeScriptEntryPoint ) {
tools.updateJSONFile( packageJsonPath, jsonFile => {
jsonFile.main = jsonFile.main.replace( '.js', '.ts' );
jsonFile.main = jsonFile.main.replace( /\.js$/, '.ts' );

if ( !hasTypesProperty ) {
delete jsonFile.types;
}

return jsonFile;
} );
Expand Down

0 comments on commit 7be9247

Please sign in to comment.