From 6202f4bb4533676a5f1540f74ca9a019e8d1912a Mon Sep 17 00:00:00 2001 From: Kamil Piechaczek Date: Fri, 24 Feb 2023 13:03:54 +0100 Subject: [PATCH] When publishing packages, adds the types field to pkg.json. --- .../lib/tasks/releasesubrepositories.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/ckeditor5-dev-release-tools/lib/tasks/releasesubrepositories.js b/packages/ckeditor5-dev-release-tools/lib/tasks/releasesubrepositories.js index 67059ef4a..a5b62f9a2 100644 --- a/packages/ckeditor5-dev-release-tools/lib/tasks/releasesubrepositories.js +++ b/packages/ckeditor5-dev-release-tools/lib/tasks/releasesubrepositories.js @@ -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; } ); @@ -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; } );