From 11e6ee7bbcf69faf30a9b089814586d021d126d0 Mon Sep 17 00:00:00 2001 From: Marcelo Serpa <81248+fullofcaffeine@users.noreply.github.com> Date: Fri, 21 May 2021 19:06:40 -0500 Subject: [PATCH] Package as internal monorepo npm, remove top-level PoC module --- add-readable-js-assets-webpack-plugin.js | 41 ------------------- package-lock.json | 4 ++ package.json | 1 + .../package.json | 2 +- webpack.config.js | 4 +- 5 files changed, 8 insertions(+), 44 deletions(-) delete mode 100644 add-readable-js-assets-webpack-plugin.js diff --git a/add-readable-js-assets-webpack-plugin.js b/add-readable-js-assets-webpack-plugin.js deleted file mode 100644 index 1ac0a5f6b18934..00000000000000 --- a/add-readable-js-assets-webpack-plugin.js +++ /dev/null @@ -1,41 +0,0 @@ -/** - * External dependencies - */ -const fs = require( 'fs' ); -const path = require( 'path' ); - -class AddReadableJsAssetsWebpackPlugin { - extractUnminifiedFiles( compilation ) { - const files = compilation.chunks.flatMap( ( chunk ) => chunk.files ); - compilation.unminifiedAssets = files.map( ( file ) => { - const asset = compilation.assets[ file ]; - const unminifiedFile = file.replace( /\.min\.js$/, '.js' ); - return [ unminifiedFile, asset.source() ]; - } ); - } - async writeUnminifiedFiles( compilation ) { - for ( const [ file, source ] of compilation.unminifiedAssets ) { - await fs.promises.writeFile( - path.join( compilation.options.output.path, file ), - source - ); - } - } - apply( compiler ) { - compiler.hooks.compilation.tap( - this.constructor.name, - ( compilation ) => { - compilation.hooks.additionalAssets.tap( - this.constructor.name, - () => this.extractUnminifiedFiles( compilation ) - ); - } - ); - compiler.hooks.afterEmit.tapPromise( - this.constructor.name, - ( compilation ) => this.writeUnminifiedFiles( compilation ) - ); - } -} - -module.exports = AddReadableJsAssetsWebpackPlugin; diff --git a/package-lock.json b/package-lock.json index 4d8dafe096d79b..b0bb0de718c97a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14271,6 +14271,10 @@ } } }, + "@wordpress/readable-js-assets-webpack-plugin": { + "version": "file:packages/readable-js-assets-webpack-plugin", + "dev": true + }, "@wordpress/redux-routine": { "version": "file:packages/redux-routine", "requires": { diff --git a/package.json b/package.json index 13a4ee1788069b..8e678fe76354da 100644 --- a/package.json +++ b/package.json @@ -142,6 +142,7 @@ "@wordpress/project-management-automation": "file:packages/project-management-automation", "@wordpress/scripts": "file:packages/scripts", "@wordpress/stylelint-config": "file:packages/stylelint-config", + "@wordpress/readable-js-assets-webpack-plugin": "file:packages/readable-js-assets-webpack-plugin", "appium": "1.20.2", "babel-jest": "26.6.3", "babel-loader": "8.2.2", diff --git a/packages/readable-js-assets-webpack-plugin/package.json b/packages/readable-js-assets-webpack-plugin/package.json index c7a63a9f4cc1ed..c629044f4b63c7 100644 --- a/packages/readable-js-assets-webpack-plugin/package.json +++ b/packages/readable-js-assets-webpack-plugin/package.json @@ -1,6 +1,6 @@ { "name": "@wordpress/readable-js-assets-webpack-plugin", - "version": "1.0", + "version": "1.0.0", "description": "Generate a readable JS file for each JS asset.", "author": "The WordPress Contributors", "license": "GPL-2.0-or-later", diff --git a/webpack.config.js b/webpack.config.js index 1e6718011d0090..082a926c41ca14 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -20,7 +20,7 @@ const DependencyExtractionWebpackPlugin = require( '@wordpress/dependency-extrac /** * Internal dependencies */ -const AddReadableJsAssetsWebpackPlugin = require( './add-readable-js-assets-webpack-plugin' ); +const ReadableJsAssetsWebpackPlugin = require( '@wordpress/readable-js-assets-webpack-plugin' ); const { camelCaseDash, } = require( '@wordpress/dependency-extraction-webpack-plugin/lib/util' ); @@ -305,7 +305,7 @@ module.exports = { ] ) ), new DependencyExtractionWebpackPlugin( { injectPolyfill: true } ), - new AddReadableJsAssetsWebpackPlugin(), + new ReadableJsAssetsWebpackPlugin(), ].filter( Boolean ), watchOptions: { ignored: [ '**/node_modules', '**/packages/*/src' ],