Skip to content

Commit

Permalink
Merge pull request #954 from ckeditor/prevent-errors-when-ckeditor5-p…
Browse files Browse the repository at this point in the history
…remium-features-is-not-installed

Fix (build-tools): Don't fail when `ckeditor5-premium-features` is in `external`, but not installed.
  • Loading branch information
filipsobol committed May 16, 2024
2 parents 06b8f49 + be23a5c commit f078955
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
17 changes: 8 additions & 9 deletions packages/ckeditor5-dev-build-tools/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,8 @@ export async function getRollupConfig( options: BuildOptions ) {
*
* This mapping can be removed when old installation methods are deprecated.
*/
const coreRewrites = external.includes( 'ckeditor5' ) ?
getPackageDependencies( 'ckeditor5' ) :
[];

const commercialRewrites = external.includes( 'ckeditor5-premium-features' ) ?
getPackageDependencies( 'ckeditor5-premium-features' ) :
[];
const coreRewrites = getPackageDependencies( 'ckeditor5' );
const commercialRewrites = getPackageDependencies( 'ckeditor5-premium-features' );

external.push( ...coreRewrites, ...commercialRewrites );

Expand Down Expand Up @@ -283,9 +278,13 @@ function getOptionalPlugin<T extends InputPluginOption>( condition: unknown, plu
* Returns a list of keys in `package.json` file of a given dependency.
*/
function getPackageDependencies( packageName: string ): Array<string> {
const pkg: PackageJson = getUserDependency( `${ packageName }/package.json` );
try {
const pkg: PackageJson = getUserDependency( `${ packageName }/package.json` );

return Object.keys( pkg.dependencies! );
return Object.keys( pkg.dependencies! );
} catch {
return [];
}
}

/**
Expand Down
15 changes: 15 additions & 0 deletions packages/ckeditor5-dev-build-tools/tests/config/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,21 @@ test( '--external automatically adds packages that make up the "ckeditor5-premiu
expect( config.external( '@ckeditor/ckeditor5-real-time-collaboration/theme/usermarkers.css' ) ).toBe( false );
} );

test( '--external doesn\'t fail when "ckeditor5-premium-features" is not installed', async () => {
await mockGetUserDependency(
'ckeditor5-premium-features/package.json',
() => {
throw new Error( 'Cannot find module' );
}
);

const config = await getConfig( {
external: [ 'ckeditor5-premium-features' ]
} );

expect( config.external( 'ckeditor5-premium-features' ) ).toBe( true );
} );

test( '--translations', async () => {
const withoutTranslations = await getConfig();
const withTranslations = await getConfig( {
Expand Down

0 comments on commit f078955

Please sign in to comment.