Skip to content

Commit

Permalink
Merge pull request #902 from ckeditor/ck/13673-improve-esm-support
Browse files Browse the repository at this point in the history
Fix (tests): Fixed processing of the ESM packages when running automated and manual tests. See ckeditor/ckeditor5#13673.

MINOR BREAKING CHANGE (utils): Removed `getJavaScriptWithoutImportExtensions()` loader introduced in #885.
  • Loading branch information
pomek authored Dec 14, 2023
2 parents e85db64 + e3f4d59 commit 7a06ddb
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,26 @@ module.exports = function getWebpackConfigForAutomatedTests( options ) {
new webpack.DefinePlugin( definitions ),
new webpack.ProvidePlugin( {
Buffer: [ 'buffer', 'Buffer' ],
process: 'process/browser'
process: 'process/browser.js'
} )
],

resolve: {
fallback: {
'timers': false
},

extensions: options.resolveJsFirst ?
[ '.js', '.ts', '.json' ] :
[ '.ts', '.js', '.json' ]
[ '.ts', '.js', '.json' ],

extensionAlias: {
'.js': [ '.js', '.ts' ]
}
},

module: {
rules: [
loaders.getJavaScriptWithoutImportExtensions(),

options.coverage ? loaders.getCoverageLoader( { files: options.files } ) : null,

loaders.getIconsLoader(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,22 @@ module.exports = function getWebpackConfigForManualTests( options ) {
new webpack.DefinePlugin( definitions ),
new webpack.ProvidePlugin( {
Buffer: [ 'buffer', 'Buffer' ],
process: 'process/browser'
process: 'process/browser.js'
} )
],

resolve: {
fallback: {
'timers': false
},
extensions: [ '.ts', '.js', '.json' ]
extensions: [ '.ts', '.js', '.json' ],
extensionAlias: {
'.js': [ '.js', '.ts' ]
}
},

module: {
rules: [
loaders.getJavaScriptWithoutImportExtensions(),

loaders.getIconsLoader( { matchExtensionOnly: true } ),

loaders.getStylesLoader( {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ describe( 'getWebpackConfigForAutomatedTests()', () => {
stubs = {
getDefinitionsFromFile: sinon.stub().returns( {} ),
loaders: {
getJavaScriptWithoutImportExtensions: sinon.stub().returns( {} ),
getIconsLoader: sinon.stub().returns( {} ),
getStylesLoader: sinon.stub().returns( {} ),
getTypeScriptLoader: sinon.stub().returns( {} ),
Expand Down Expand Up @@ -59,8 +58,6 @@ describe( 'getWebpackConfigForAutomatedTests()', () => {
expect( webpackConfig.resolve.extensions ).to.deep.equal( [ '.ts', '.js', '.json' ] );
expect( webpackConfig.resolve.fallback.timers ).to.equal( false );

expect( stubs.loaders.getJavaScriptWithoutImportExtensions.calledOnce ).to.equal( true );

expect( stubs.loaders.getIconsLoader.calledOnce ).to.equal( true );

expect( stubs.loaders.getStylesLoader.calledOnce ).to.equal( true );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ describe( 'getWebpackConfigForManualTests()', () => {
stubs = {
getDefinitionsFromFile: sinon.stub().returns( {} ),
loaders: {
getJavaScriptWithoutImportExtensions: sinon.stub().returns( {} ),
getIconsLoader: sinon.stub().returns( {} ),
getStylesLoader: sinon.stub().returns( {} ),
getTypeScriptLoader: sinon.stub().returns( {} ),
Expand Down Expand Up @@ -80,8 +79,6 @@ describe( 'getWebpackConfigForManualTests()', () => {
tsconfig: '/tsconfig/path'
} );

expect( stubs.loaders.getJavaScriptWithoutImportExtensions.calledOnce ).to.equal( true );

expect( stubs.loaders.getIconsLoader.calledOnce ).to.equal( true );
expect( stubs.loaders.getIconsLoader.firstCall.args[ 0 ] ).to.have.property( 'matchExtensionOnly', true );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@ module.exports = function getDllPluginWebpackConfig( webpack, options ) {
],

resolve: {
extensions: [ '.ts', '.js', '.json' ]
extensions: [ '.ts', '.js', '.json' ],
extensionAlias: {
'.js': [ '.js', '.ts' ]
}
},

module: {
rules: [
loaders.getJavaScriptWithoutImportExtensions(),
loaders.getIconsLoader( { matchExtensionOnly: true } ),
loaders.getStylesLoader( {
themePath: options.themePath,
Expand Down
14 changes: 0 additions & 14 deletions packages/ckeditor5-dev-utils/lib/loaders/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,6 @@ const { getPostCssConfig } = require( '../styles' );
const escapedPathSep = path.sep == '/' ? '/' : '\\\\';

module.exports = {
/**
* This loader causes webpack to not require file
* extensions in imports when the `type:module`
* option is added to the `package.json`.
*/
getJavaScriptWithoutImportExtensions() {
return {
test: /\.m?js$/,
resolve: {
fullySpecified: false
}
};
},

/**
* @param {Object} [options]
* @param {String} [options.configFile]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ describe( 'builds/getDllPluginWebpackConfig()', () => {
DllReferencePlugin: sandbox.stub()
},
loaders: {
getJavaScriptWithoutImportExtensions: sinon.stub(),
getIconsLoader: sinon.stub(),
getStylesLoader: sinon.stub(),
getTypeScriptLoader: sinon.stub()
Expand Down Expand Up @@ -275,20 +274,6 @@ describe( 'builds/getDllPluginWebpackConfig()', () => {
} );
} );

describe( 'getJavaScriptWithoutImportExtensions()', () => {
it( 'it should get the loader', () => {
stubs.tools.readPackageName.returns( '@ckeditor/ckeditor5-html-embed' );

getDllPluginWebpackConfig( stubs.webpack, {
packagePath: '/package/path',
themePath: '/theme/path',
manifestPath: '/manifest/path'
} );

expect( stubs.loaders.getJavaScriptWithoutImportExtensions.calledOnce ).to.equal( true );
} );
} );

describe( 'getIconsLoader()', () => {
it( 'it should get the loader', () => {
stubs.tools.readPackageName.returns( '@ckeditor/ckeditor5-html-embed' );
Expand Down

0 comments on commit 7a06ddb

Please sign in to comment.