From a2bc8b3bf6f31d8ed0a8c33e642f5f828dce978b Mon Sep 17 00:00:00 2001 From: Filip Sobol Date: Thu, 5 Dec 2024 12:45:53 +0100 Subject: [PATCH 1/4] Fix: Unify TypeScript declaration files --- scripts/nim/build-ckeditor5.mjs | 4 +- scripts/nim/build-package.mjs | 3 +- .../release/utils/getckeditor5packagejson.mjs | 4 +- .../release/utils/updatepackageentrypoint.mjs | 47 +++++++++++++++++-- 4 files changed, 49 insertions(+), 9 deletions(-) diff --git a/scripts/nim/build-ckeditor5.mjs b/scripts/nim/build-ckeditor5.mjs index e9f225394b4..10f1ac73956 100644 --- a/scripts/nim/build-ckeditor5.mjs +++ b/scripts/nim/build-ckeditor5.mjs @@ -42,7 +42,9 @@ function dist( path ) { * We don't want to repeat this in other steps. */ clean: true, - declarations: true, + + // Temporarily disabled to avoid problems caused by duplicate declarations. + // declarations: true, translations: 'packages/**/*.po' } ); diff --git a/scripts/nim/build-package.mjs b/scripts/nim/build-package.mjs index 40299871134..34e1524cc60 100644 --- a/scripts/nim/build-package.mjs +++ b/scripts/nim/build-package.mjs @@ -28,7 +28,8 @@ import { build } from '@ckeditor/ckeditor5-dev-build-tools'; ], clean: true, sourceMap: true, - declarations: true, + // Temporarily disabled to avoid problems caused by duplicate declarations. + // declarations: true, translations: '**/*.po' } ); } )(); diff --git a/scripts/release/utils/getckeditor5packagejson.mjs b/scripts/release/utils/getckeditor5packagejson.mjs index 753c847db9d..6a43f1b2e1b 100644 --- a/scripts/release/utils/getckeditor5packagejson.mjs +++ b/scripts/release/utils/getckeditor5packagejson.mjs @@ -27,10 +27,10 @@ export default function getCKEditor5PackageJson() { type: 'module', main: 'dist/ckeditor5.js', module: 'dist/ckeditor5.js', - types: 'dist/index.d.ts', + types: 'src/index.d.ts', exports: { '.': { - 'types': './dist/index.d.ts', + 'types': './src/index.d.ts', 'import': './dist/ckeditor5.js' }, './*': './dist/*', diff --git a/scripts/release/utils/updatepackageentrypoint.mjs b/scripts/release/utils/updatepackageentrypoint.mjs index 2df485c064a..373ff37c4e6 100644 --- a/scripts/release/utils/updatepackageentrypoint.mjs +++ b/scripts/release/utils/updatepackageentrypoint.mjs @@ -19,14 +19,51 @@ export default async function updatePackageEntryPoint( packagePath ) { const packageJsonPath = path.join( packagePath, 'package.json' ); const pkgJson = await fs.readJson( packageJsonPath ); - const { main } = pkgJson; + const main = pkgJson.main.replace( /\.ts$/, '.js' ); + const types = pkgJson.main.replace( /\.ts$/, '.d.ts' ); + const files = pkgJson.files || []; - if ( !main ) { - return; + pkgJson.main = main; + pkgJson.types = types; + + pkgJson.exports = { + '.': { + types: './' + types, + import: './' + main + }, + './dist/*': { + /** + * To avoid problems caused by having two different copies of the declaration + * files, the new installation methods will temporarily use those from the + * old installation methods. Once the old methods are removed, the declaration + * files will be moved to the `dist` directory. + */ + types: './' + types, + import: './dist/*' + }, + './src/*': { + types: './' + types, + import: './src/*' + } + }; + + if ( files.includes( 'build' ) ) { + pkgJson.exports[ './build/*' ] = './build/*'; + } + + if ( files.includes( 'lang' ) ) { + pkgJson.exports[ './lang/*' ] = './lang/*'; + } + + if ( files.includes( 'theme' ) ) { + pkgJson.exports[ './theme/*' ] = './theme/*'; + } + + if ( files.includes( 'ckeditor5-metadata.json' ) ) { + pkgJson.exports[ './ckeditor5-metadata.json' ] = './ckeditor5-metadata.json'; } - pkgJson.main = main.replace( /\.ts$/, '.js' ); - pkgJson.types = main.replace( /\.ts$/, '.d.ts' ); + pkgJson.exports[ './package.json' ] = './package.json'; return fs.writeJson( packageJsonPath, pkgJson ); From 775a742ab472b5b9e0998a3f4dcf59a2f14f354d Mon Sep 17 00:00:00 2001 From: Filip Sobol Date: Fri, 6 Dec 2024 09:34:25 +0100 Subject: [PATCH 2/4] Update based on feedback --- scripts/nim/build-ckeditor5.mjs | 3 --- scripts/nim/build-package.mjs | 2 -- scripts/release/utils/updatepackageentrypoint.mjs | 8 ++++---- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/scripts/nim/build-ckeditor5.mjs b/scripts/nim/build-ckeditor5.mjs index 10f1ac73956..c7ffc0202da 100644 --- a/scripts/nim/build-ckeditor5.mjs +++ b/scripts/nim/build-ckeditor5.mjs @@ -42,9 +42,6 @@ function dist( path ) { * We don't want to repeat this in other steps. */ clean: true, - - // Temporarily disabled to avoid problems caused by duplicate declarations. - // declarations: true, translations: 'packages/**/*.po' } ); diff --git a/scripts/nim/build-package.mjs b/scripts/nim/build-package.mjs index 34e1524cc60..b724cc22479 100644 --- a/scripts/nim/build-package.mjs +++ b/scripts/nim/build-package.mjs @@ -28,8 +28,6 @@ import { build } from '@ckeditor/ckeditor5-dev-build-tools'; ], clean: true, sourceMap: true, - // Temporarily disabled to avoid problems caused by duplicate declarations. - // declarations: true, translations: '**/*.po' } ); } )(); diff --git a/scripts/release/utils/updatepackageentrypoint.mjs b/scripts/release/utils/updatepackageentrypoint.mjs index 373ff37c4e6..93989b63a44 100644 --- a/scripts/release/utils/updatepackageentrypoint.mjs +++ b/scripts/release/utils/updatepackageentrypoint.mjs @@ -51,11 +51,11 @@ export default async function updatePackageEntryPoint( packagePath ) { pkgJson.exports[ './build/*' ] = './build/*'; } - if ( files.includes( 'lang' ) ) { + if ( checkPathExists( packagePath, 'lang' ) ) { pkgJson.exports[ './lang/*' ] = './lang/*'; } - if ( files.includes( 'theme' ) ) { + if ( checkPathExists( packagePath, 'theme' ) ) { pkgJson.exports[ './theme/*' ] = './theme/*'; } @@ -82,10 +82,10 @@ export default async function updatePackageEntryPoint( packagePath ) { } // Otherwise, let's check if the package contains a `tsconfig.json` file. - return checkFileExists( path.join( packagePath, 'tsconfig.json' ) ); + return checkPathExists( path.join( packagePath, 'tsconfig.json' ) ); } - function checkFileExists( file ) { + function checkPathExists( file ) { return fs.access( file, fs.constants.F_OK ) .then( () => true ) .catch( () => false ); From 385702bf6640dc48dc5e6ad9b14ae51d7c236674 Mon Sep 17 00:00:00 2001 From: Filip Sobol Date: Fri, 6 Dec 2024 10:17:10 +0100 Subject: [PATCH 3/4] Fix `updatePackageEntryPoint` --- scripts/release/utils/updatepackageentrypoint.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/release/utils/updatepackageentrypoint.mjs b/scripts/release/utils/updatepackageentrypoint.mjs index 242bca6cc94..57093041842 100644 --- a/scripts/release/utils/updatepackageentrypoint.mjs +++ b/scripts/release/utils/updatepackageentrypoint.mjs @@ -51,11 +51,11 @@ export default async function updatePackageEntryPoint( packagePath ) { pkgJson.exports[ './build/*' ] = './build/*'; } - if ( checkPathExists( packagePath, 'lang' ) ) { + if ( checkPathExists( path.join( packagePath, 'lang' ) ) ) { pkgJson.exports[ './lang/*' ] = './lang/*'; } - if ( checkPathExists( packagePath, 'theme' ) ) { + if ( checkPathExists( path.join( packagePath, 'theme' ) ) ) { pkgJson.exports[ './theme/*' ] = './theme/*'; } From 2d7c9522726bec7829e7cb882b13064604cd0785 Mon Sep 17 00:00:00 2001 From: Filip Sobol Date: Fri, 6 Dec 2024 10:48:30 +0100 Subject: [PATCH 4/4] Add missing `await` --- scripts/release/utils/updatepackageentrypoint.mjs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/release/utils/updatepackageentrypoint.mjs b/scripts/release/utils/updatepackageentrypoint.mjs index 57093041842..a8bb2837c43 100644 --- a/scripts/release/utils/updatepackageentrypoint.mjs +++ b/scripts/release/utils/updatepackageentrypoint.mjs @@ -51,11 +51,11 @@ export default async function updatePackageEntryPoint( packagePath ) { pkgJson.exports[ './build/*' ] = './build/*'; } - if ( checkPathExists( path.join( packagePath, 'lang' ) ) ) { + if ( await checkPathExists( path.join( packagePath, 'lang' ) ) ) { pkgJson.exports[ './lang/*' ] = './lang/*'; } - if ( checkPathExists( path.join( packagePath, 'theme' ) ) ) { + if ( await checkPathExists( path.join( packagePath, 'theme' ) ) ) { pkgJson.exports[ './theme/*' ] = './theme/*'; } @@ -85,6 +85,10 @@ export default async function updatePackageEntryPoint( packagePath ) { return checkPathExists( path.join( packagePath, 'tsconfig.json' ) ); } + /** + * @param {String} file + * @returns {Promise.} + */ function checkPathExists( file ) { return fs.access( file, fs.constants.F_OK ) .then( () => true )