Skip to content

Commit

Permalink
Merge pull request #145 from ckeditor/i/139
Browse files Browse the repository at this point in the history
Fix (tools): Added support for a package name without an organization prefix. Preparing the DLL build will not throw an error for such a package. Closes #139.
  • Loading branch information
pomek committed Apr 13, 2023
2 parents 64bdb5e + d6700fd commit a820183
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = async options => {
}

const pkgJson = require( path.join( options.cwd, 'package.json' ) );
const packageName = pkgJson.name.split( '/' ).pop();
const packageName = pkgJson.name.includes( '/' ) ? pkgJson.name.split( '/' ).pop() : pkgJson.name;

return downloadTranslations( {
// Token used for authentication with the Transifex service.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = async options => {
}

const pkgJson = require( path.join( options.cwd, 'package.json' ) );
const packageName = pkgJson.name.split( '/' ).pop();
const packageName = pkgJson.name.includes( '/' ) ? pkgJson.name.split( '/' ).pop() : pkgJson.name;

return uploadPotFiles( {
// Token used for authentication with the Transifex service.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ const { CKEditorTranslationsPlugin } = require( '@ckeditor/ckeditor5-dev-transla
const { loaderDefinitions } = require( './webpack-utils' );

module.exports = options => {
const packageJson = require( path.join( options.cwd, 'package.json' ) );
const pkgJson = require( path.join( options.cwd, 'package.json' ) );

// `dllName` is a short package name without the scope and the `ckeditor5-` prefix.
// E.g. for the package called `@ckeditor/ckeditor5-example-package`, the short name is `example-package`.
const dllName = packageJson.name.split( '/' )[ 1 ].replace( /^ckeditor5-/, '' );
const packageName = pkgJson.name.includes( '/' ) ? pkgJson.name.split( '/' ).pop() : pkgJson.name;
const dllName = packageName.replace( /^ckeditor5-/, '' );

// `dllWindowKey` is a name of a key which will be used for exposing the DLL library under
// the `window.CKEditor5` global variable. E.g. for the package called `@ckeditor/ckeditor5-example-package`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,36 @@ describe( 'lib/tasks/translations-download', () => {
expect( translationsDownload ).to.be.a( 'function' );
} );

it( 'downloads translation files', async () => {
it( 'downloads translation files for package "ckeditor5-foo"', async () => {
mockery.registerMock( '/workspace/package.json', {
name: 'ckeditor5-foo'
} );

stubs.transifex.getToken.resolves( 'secretToken' );
stubs.transifex.downloadTranslations.resolves( 'OK' );

const results = await translationsDownload( {
cwd: '/workspace',
organization: 'foo',
project: 'bar'
} );

expect( results ).to.equal( 'OK' );

expect( stubs.transifex.downloadTranslations.calledOnce ).to.equal( true );
expect( stubs.transifex.downloadTranslations.firstCall.firstArg ).to.deep.equal( {
token: 'secretToken',
organizationName: 'foo',
projectName: 'bar',
cwd: '/workspace',
packages: new Map( [
[ 'ckeditor5-foo', '.' ]
] ),
simplifyLicenseHeader: true
} );
} );

it( 'downloads translation files for package "@ckeditor/ckeditor5-foo"', async () => {
stubs.transifex.getToken.resolves( 'secretToken' );
stubs.transifex.downloadTranslations.resolves( 'OK' );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,35 @@ describe( 'lib/tasks/translations-upload', () => {
expect( translationsUpload ).to.be.a( 'function' );
} );

it( 'uploads translation files', async () => {
it( 'uploads translation files for package "ckeditor5-foo"', async () => {
mockery.registerMock( '/workspace/package.json', {
name: 'ckeditor5-foo'
} );

stubs.transifex.getToken.resolves( 'secretToken' );
stubs.transifex.uploadPotFiles.resolves( 'OK' );

const results = await translationsUpload( {
cwd: '/workspace',
organization: 'foo',
project: 'bar'
} );

expect( results ).to.equal( 'OK' );

expect( stubs.transifex.uploadPotFiles.calledOnce ).to.equal( true );
expect( stubs.transifex.uploadPotFiles.firstCall.firstArg ).to.deep.equal( {
token: 'secretToken',
cwd: '/workspace',
organizationName: 'foo',
packages: new Map( [
[ 'ckeditor5-foo', 'tmp/.transifex/ckeditor5-foo' ]
] ),
projectName: 'bar'
} );
} );

it( 'uploads translation files for package "@ckeditor/ckeditor5-foo"', async () => {
stubs.transifex.getToken.resolves( 'secretToken' );
stubs.transifex.uploadPotFiles.resolves( 'OK' );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@ describe( 'lib/utils/get-webpack-config-dll', () => {
} );

describe( 'verifying exposed DLL names', () => {
it( 'returns "foo" for a window key and a file name for the "ckeditor5-foo" package', () => {
stubs.packageJson.name = 'ckeditor5-foo';

const webpackConfig = getWebpackConfigDll( { cwd } );

expect( webpackConfig.output.filename ).to.equal( 'foo.js' );
expect( webpackConfig.output.library ).to.deep.equal( [ 'CKEditor5', 'foo' ] );
} );

it( 'returns "foo" for a window key and a file name for the "@ckeditor/ckeditor5-foo" package', () => {
const webpackConfig = getWebpackConfigDll( { cwd } );

Expand Down

0 comments on commit a820183

Please sign in to comment.