From b7bead5cfea7cb6de2eecb3a6303b17f53eac8d1 Mon Sep 17 00:00:00 2001 From: Filip Sobol Date: Mon, 3 Jul 2023 15:36:25 +0200 Subject: [PATCH 1/2] Improve ESM support --- .../lib/utils/automated-tests/getwebpackconfig.js | 9 ++++++--- .../lib/utils/manual-tests/getwebpackconfig.js | 7 ++++--- .../utils/automated-tests/getwebpackconfig.js | 3 --- .../tests/utils/manual-tests/getwebpackconfig.js | 3 --- .../lib/builds/getdllpluginwebpackconfig.js | 6 ++++-- packages/ckeditor5-dev-utils/lib/loaders/index.js | 14 -------------- .../tests/builds/getdllpluginwebpackconfig.js | 15 --------------- 7 files changed, 14 insertions(+), 43 deletions(-) diff --git a/packages/ckeditor5-dev-tests/lib/utils/automated-tests/getwebpackconfig.js b/packages/ckeditor5-dev-tests/lib/utils/automated-tests/getwebpackconfig.js index 734f895e9..407485f48 100644 --- a/packages/ckeditor5-dev-tests/lib/utils/automated-tests/getwebpackconfig.js +++ b/packages/ckeditor5-dev-tests/lib/utils/automated-tests/getwebpackconfig.js @@ -37,15 +37,18 @@ module.exports = function getWebpackConfigForAutomatedTests( options ) { 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(), diff --git a/packages/ckeditor5-dev-tests/lib/utils/manual-tests/getwebpackconfig.js b/packages/ckeditor5-dev-tests/lib/utils/manual-tests/getwebpackconfig.js index f15a8bcae..64936fe30 100644 --- a/packages/ckeditor5-dev-tests/lib/utils/manual-tests/getwebpackconfig.js +++ b/packages/ckeditor5-dev-tests/lib/utils/manual-tests/getwebpackconfig.js @@ -64,13 +64,14 @@ module.exports = function getWebpackConfigForManualTests( options ) { 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( { diff --git a/packages/ckeditor5-dev-tests/tests/utils/automated-tests/getwebpackconfig.js b/packages/ckeditor5-dev-tests/tests/utils/automated-tests/getwebpackconfig.js index 5679355ab..230720732 100644 --- a/packages/ckeditor5-dev-tests/tests/utils/automated-tests/getwebpackconfig.js +++ b/packages/ckeditor5-dev-tests/tests/utils/automated-tests/getwebpackconfig.js @@ -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( {} ), @@ -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 ); diff --git a/packages/ckeditor5-dev-tests/tests/utils/manual-tests/getwebpackconfig.js b/packages/ckeditor5-dev-tests/tests/utils/manual-tests/getwebpackconfig.js index 7dbcdebf1..422163c82 100644 --- a/packages/ckeditor5-dev-tests/tests/utils/manual-tests/getwebpackconfig.js +++ b/packages/ckeditor5-dev-tests/tests/utils/manual-tests/getwebpackconfig.js @@ -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( {} ), @@ -71,8 +70,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 ); diff --git a/packages/ckeditor5-dev-utils/lib/builds/getdllpluginwebpackconfig.js b/packages/ckeditor5-dev-utils/lib/builds/getdllpluginwebpackconfig.js index 41c9c5420..8f855d75b 100644 --- a/packages/ckeditor5-dev-utils/lib/builds/getdllpluginwebpackconfig.js +++ b/packages/ckeditor5-dev-utils/lib/builds/getdllpluginwebpackconfig.js @@ -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, diff --git a/packages/ckeditor5-dev-utils/lib/loaders/index.js b/packages/ckeditor5-dev-utils/lib/loaders/index.js index 3b5646107..a0b29fd26 100644 --- a/packages/ckeditor5-dev-utils/lib/loaders/index.js +++ b/packages/ckeditor5-dev-utils/lib/loaders/index.js @@ -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] diff --git a/packages/ckeditor5-dev-utils/tests/builds/getdllpluginwebpackconfig.js b/packages/ckeditor5-dev-utils/tests/builds/getdllpluginwebpackconfig.js index 7467f8666..55c8a8ff8 100644 --- a/packages/ckeditor5-dev-utils/tests/builds/getdllpluginwebpackconfig.js +++ b/packages/ckeditor5-dev-utils/tests/builds/getdllpluginwebpackconfig.js @@ -44,7 +44,6 @@ describe( 'builds/getDllPluginWebpackConfig()', () => { DllReferencePlugin: sandbox.stub() }, loaders: { - getJavaScriptWithoutImportExtensions: sinon.stub(), getIconsLoader: sinon.stub(), getStylesLoader: sinon.stub(), getTypeScriptLoader: sinon.stub() @@ -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' ); From 88515d16149a9718ea5e8b90f8be89456bc6109a Mon Sep 17 00:00:00 2001 From: Filip Sobol Date: Tue, 4 Jul 2023 12:18:21 +0200 Subject: [PATCH 2/2] Update paths to the 'process' dependency --- .../lib/utils/automated-tests/getwebpackconfig.js | 2 +- .../lib/utils/manual-tests/getwebpackconfig.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ckeditor5-dev-tests/lib/utils/automated-tests/getwebpackconfig.js b/packages/ckeditor5-dev-tests/lib/utils/automated-tests/getwebpackconfig.js index 407485f48..b5795116b 100644 --- a/packages/ckeditor5-dev-tests/lib/utils/automated-tests/getwebpackconfig.js +++ b/packages/ckeditor5-dev-tests/lib/utils/automated-tests/getwebpackconfig.js @@ -29,7 +29,7 @@ module.exports = function getWebpackConfigForAutomatedTests( options ) { new webpack.DefinePlugin( definitions ), new webpack.ProvidePlugin( { Buffer: [ 'buffer', 'Buffer' ], - process: 'process/browser' + process: 'process/browser.js' } ) ], diff --git a/packages/ckeditor5-dev-tests/lib/utils/manual-tests/getwebpackconfig.js b/packages/ckeditor5-dev-tests/lib/utils/manual-tests/getwebpackconfig.js index 64936fe30..bf1f67aa8 100644 --- a/packages/ckeditor5-dev-tests/lib/utils/manual-tests/getwebpackconfig.js +++ b/packages/ckeditor5-dev-tests/lib/utils/manual-tests/getwebpackconfig.js @@ -56,7 +56,7 @@ module.exports = function getWebpackConfigForManualTests( options ) { new webpack.DefinePlugin( definitions ), new webpack.ProvidePlugin( { Buffer: [ 'buffer', 'Buffer' ], - process: 'process/browser' + process: 'process/browser.js' } ) ],