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 paths in webpack-plugin for Windows environment #299

Merged
merged 2 commits into from
Oct 18, 2017
Merged
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
11 changes: 6 additions & 5 deletions packages/ckeditor5-dev-webpack-plugin/lib/replacetcalls.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

const path = require( 'path' );
const { TranslationService } = require( '@ckeditor/ckeditor5-dev-utils' ).translations;
const utils = require( './utils' );

/**
* Replaces all function call parameters with translated strings for the t function.
Expand All @@ -26,9 +27,9 @@ module.exports = function replaceTCalls( compiler, language ) {
process.cwd(),
'@ckeditor/ckeditor5-core/src/editor/editor.js',
( err, result ) => {
const pathToCoreTranslationPackage = result.match( /.+\/ckeditor5-core/ )[ 0 ];
const pathToCoreTranslationPackage = result.match( utils.CKEditor5CoreRegExp )[ 0 ];

translationService.loadPackage( pathToCoreTranslationPackage.replace( '/', path.sep ) );
translationService.loadPackage( pathToCoreTranslationPackage );
}
);
} );
Expand All @@ -44,20 +45,20 @@ module.exports = function replaceTCalls( compiler, language ) {

// Adds package to the translations if the resource comes from ckeditor5-* package.
function maybeLoadPackage( resolveOptions ) {
const packageNameRegExp = /\/ckeditor5-[^/]+\//;
const packageNameRegExp = utils.CKEditor5PackageNameRegExp;
const match = resolveOptions.resource.match( packageNameRegExp );

if ( match ) {
const index = resolveOptions.resource.search( packageNameRegExp ) + match[ 0 ].length;
const pathToPackage = resolveOptions.resource.slice( 0, index );

translationService.loadPackage( pathToPackage.replace( '/', path.sep ) );
translationService.loadPackage( pathToPackage );
}
}

// Injects loader when the file comes from ckeditor5-* packages.
function maybeAddLoader( resolveOptions ) {
if ( resolveOptions.resource.match( /\/ckeditor5-[^/]+\/src\/.+\.js$/ ) ) {
if ( resolveOptions.resource.match( utils.CKEditor5PackageSrcFileRegExp ) ) {
resolveOptions.loaders.unshift( path.join( __dirname, 'translatesourceloader.js' ) );
}
}
Expand Down
12 changes: 12 additions & 0 deletions packages/ckeditor5-dev-webpack-plugin/lib/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

'use strict';

module.exports = {
CKEditor5CoreRegExp: /.+[/\\]ckeditor5-core/,
CKEditor5PackageNameRegExp: /[/\\]ckeditor5-[^/\\]+[/\\]/,
CKEditor5PackageSrcFileRegExp: /[/\\]ckeditor5-[^/\\]+[/\\]src[/\\].+\.js$/
};
78 changes: 78 additions & 0 deletions packages/ckeditor5-dev-webpack-plugin/tests/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

'use strict';

const { expect } = require( 'chai' );
const utils = require( '../lib/utils.js' );

describe( 'webpack-plugin/utils', () => {
describe( 'CKEditor5CoreRegExp', () => {
it( 'should match CKEditor5 core package on Unix systems', () => {
const path = 'path/to/the/ckeditor5-core/src/file.js';

const match = path.match( utils.CKEditor5CoreRegExp );

expect( match ).to.not.be.null;
expect( match.length ).to.equal( 1 );
expect( match[ 0 ] ).to.equal( 'path/to/the/ckeditor5-core' );
} );

it( 'should match CKEditor5 core package on Windows systems', () => {
const path = 'C:\\some path\\to\\the\\ckeditor5-core\\src\\file.js';

const match = path.match( utils.CKEditor5CoreRegExp );

expect( match ).to.not.be.null;
expect( match.length ).to.equal( 1 );
expect( match[ 0 ] ).to.equal( 'C:\\some path\\to\\the\\ckeditor5-core' );
} );
} );

describe( 'CKEditor5PackageNameRegExp', () => {
it( 'should match CKEditor5 package name on Unix systems', () => {
const path = 'path/to/the/ckeditor5-enter/src/file.js';

const match = path.match( utils.CKEditor5PackageNameRegExp );

expect( match ).to.not.be.null;
expect( match.length ).to.equal( 1 );
expect( match[ 0 ] ).to.equal( '/ckeditor5-enter/' );
} );

it( 'should match CKEditor5 package name on Windows systems', () => {
const path = 'C:\\some path\\to\\the\\ckeditor5-enter\\src\\file.js';

const match = path.match( utils.CKEditor5PackageNameRegExp );

expect( match ).to.not.be.null;
expect( match.length ).to.equal( 1 );
expect( match[ 0 ] ).to.equal( '\\ckeditor5-enter\\' );
} );
} );

describe( 'CKEditor5PackageSrcFileRegExp', () => {
it( 'should match CKEditor5 package src file on Unix systems', () => {
const path = 'path/to/the/ckeditor5-enter/src/file.js';

const match = path.match( utils.CKEditor5PackageSrcFileRegExp );

expect( match ).to.not.be.null;
expect( match.length ).to.equal( 1 );
expect( match[ 0 ] ).to.equal( '/ckeditor5-enter/src/file.js' );
} );

it( 'should match CKEditor5 package src file on Windows systems', () => {
const path = 'C:\\some path\\to\\the\\ckeditor5-enter\\src\\file.js';

const match = path.match( utils.CKEditor5PackageSrcFileRegExp );

expect( match ).to.not.be.null;
expect( match.length ).to.equal( 1 );
expect( match[ 0 ] ).to.equal( '\\ckeditor5-enter\\src\\file.js' );
} );
} );
} );