Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Change getThemePath to support mono repos #175

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions packages/ckeditor5-package-tools/lib/utils/get-theme-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,14 @@

/* eslint-env node */

const path = require( 'path' );

/**
* Returns an absolute path to the main file of the `@ckeditor/ckeditor5-theme-lark` package.
*
* The function does the same as what does `require.resolve()`. However, there is no option for mocking it in tests,
* hence the value is obtained manually.
* Used to assist mocking require.resolve() in tests.
*
* @param {String} cwd
* @param {Function} resolver
* @return {String}
*/
module.exports = function getThemePath( cwd ) {
const packagePath = path.join( cwd, 'node_modules', '@ckeditor', 'ckeditor5-theme-lark' );
const packageJson = require( path.join( packagePath, 'package.json' ) );

return path.join( packagePath, packageJson.main );
module.exports = function getThemePath( resolver ) {
return resolver( '@ckeditor/ckeditor5-theme-lark' );
};
4 changes: 2 additions & 2 deletions packages/ckeditor5-package-tools/lib/utils/webpack-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports = {
};
},

styles: cwd => {
styles: () => {
return {
test: /\.css$/,
use: [
Expand All @@ -64,7 +64,7 @@ module.exports = {
options: {
postcssOptions: getPostCssConfig( {
themeImporter: {
themePath: getThemePath( cwd )
themePath: getThemePath( require.resolve )
},
minify: true
} )
Expand Down
22 changes: 4 additions & 18 deletions packages/ckeditor5-package-tools/tests/utils/get-theme-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ const sinon = require( 'sinon' );
const expect = require( 'chai' ).expect;

describe( 'lib/utils/get-theme-path', () => {
let getThemePath, stubs;

const cwd = '/process/cwd';
let getThemePath;

beforeEach( () => {
mockery.enable( {
Expand All @@ -21,19 +19,6 @@ describe( 'lib/utils/get-theme-path', () => {
warnOnUnregistered: false
} );

stubs = {
packageJson: {
name: '@ckeditor/ckeditor5-theme-lark',
main: './theme/theme.css'
},
path: {
join: sinon.stub().callsFake( ( ...chunks ) => chunks.join( '/' ).replace( '/./', '/' ) )
}
};

mockery.registerMock( 'path', stubs.path );
mockery.registerMock( '/process/cwd/node_modules/@ckeditor/ckeditor5-theme-lark/package.json', stubs.packageJson );

getThemePath = require( '../../lib/utils/get-theme-path' );
} );

Expand All @@ -46,7 +31,8 @@ describe( 'lib/utils/get-theme-path', () => {
expect( getThemePath ).to.be.a( 'function' );
} );

it( 'returns an absolute path to an entry file of the "@ckeditor/ckeditor5-theme-lark" package', () => {
expect( getThemePath( cwd ) ).to.equal( '/process/cwd/node_modules/@ckeditor/ckeditor5-theme-lark/theme/theme.css' );
it( 'resolves the "@ckeditor/ckeditor5-theme-lark" package', () => {
const resolver = packageName => packageName;
expect( getThemePath( resolver ) ).to.equal( '@ckeditor/ckeditor5-theme-lark' );
} );
} );
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ describe( 'lib/utils/webpack-utils', () => {
// Webpack processes loaders from the bottom, to the top. Hence, "postcss-loader" will be called as the first one.
it( 'uses "postcss-loader" for processing CKEditor 5 assets', () => {
expect( stubs.getThemePath.calledOnce ).to.equal( true );
expect( stubs.getThemePath.firstCall.args[ 0 ] ).to.equal( '/process/cwd' );
expect( typeof stubs.getThemePath.firstCall.args[ 0 ] == 'function' ).to.equal( true );
expect( stubs.getThemePath.firstCall.args[ 0 ].prototype.constructor.name ).to.equal( 'resolve' );

expect( stubs.devUtils.styles.getPostCssConfig.calledOnce ).to.equal( true );
expect( stubs.devUtils.styles.getPostCssConfig.firstCall.firstArg ).to.deep.equal( {
Expand Down