Skip to content

Commit

Permalink
Merge pull request #17597 from ckeditor/unify-declaration-files
Browse files Browse the repository at this point in the history
Fix: Unify TypeScript declaration files. Fixes #17575 and #17533.
  • Loading branch information
filipsobol authored Dec 16, 2024
2 parents 1b350d4 + 2d7c952 commit 417c261
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 11 deletions.
1 change: 0 additions & 1 deletion scripts/nim/build-ckeditor5.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ function dist( path ) {
* We don't want to repeat this in other steps.
*/
clean: true,
declarations: true,
translations: 'packages/**/*.po'
} );

Expand Down
1 change: 0 additions & 1 deletion scripts/nim/build-package.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import { build } from '@ckeditor/ckeditor5-dev-build-tools';
],
clean: true,
sourceMap: true,
declarations: true,
translations: '**/*.po'
} );
} )();
4 changes: 2 additions & 2 deletions scripts/release/utils/getckeditor5packagejson.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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/*',
Expand Down
55 changes: 48 additions & 7 deletions scripts/release/utils/updatepackageentrypoint.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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/*';
}

pkgJson.main = main.replace( /\.ts$/, '.js' );
pkgJson.types = main.replace( /\.ts$/, '.d.ts' );
if ( await checkPathExists( path.join( packagePath, 'lang' ) ) ) {
pkgJson.exports[ './lang/*' ] = './lang/*';
}

if ( await checkPathExists( path.join( packagePath, 'theme' ) ) ) {
pkgJson.exports[ './theme/*' ] = './theme/*';
}

if ( files.includes( 'ckeditor5-metadata.json' ) ) {
pkgJson.exports[ './ckeditor5-metadata.json' ] = './ckeditor5-metadata.json';
}

pkgJson.exports[ './package.json' ] = './package.json';

return fs.writeJson( packageJsonPath, pkgJson );

Expand All @@ -45,10 +82,14 @@ 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 ) {
/**
* @param {String} file
* @returns {Promise.<Boolean>}
*/
function checkPathExists( file ) {
return fs.access( file, fs.constants.F_OK )
.then( () => true )
.catch( () => false );
Expand Down

0 comments on commit 417c261

Please sign in to comment.