New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@wordpress/dependency-extraction-webpack-plugin

Package Overview
Dependencies
Maintainers
16
Versions
141
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wordpress/dependency-extraction-webpack-plugin - npm Package Compare versions

Comparing version 2.8.0 to 2.9.0

lib/types.d.ts

10

build-types/index.d.ts

@@ -62,3 +62,3 @@ export = DependencyExtractionWebpackPlugin;

*/
externalizeWpDeps(_context: any, request: any, callback: import("webpack").ExternalsFunctionCallback): void;
externalizeWpDeps(_context: [context: any, request: any, callback: import("webpack").ExternalsFunctionCallback][0], request: [context: any, request: any, callback: import("webpack").ExternalsFunctionCallback][1], callback: [context: any, request: any, callback: import("webpack").ExternalsFunctionCallback][2]): void;
/**

@@ -78,3 +78,3 @@ * @param {string} request

*/
apply(compiler: import("webpack").Compiler): void;
apply(compiler: WebpackCompiler): void;
}

@@ -96,3 +96,3 @@ declare namespace DependencyExtractionWebpackPlugin {

*/
outputFormat: "json" | "php";
outputFormat: 'php' | 'json';
/**

@@ -115,6 +115,7 @@ * Map module requests to an external.

};
type WebpackCompiler = import("webpack").Compiler;
/**
* Map module request to an external.
*/
type RequestToExternal = (request: string) => string | void | string[];
type RequestToExternal = (request: string) => string | string[] | void;
/**

@@ -134,4 +135,3 @@ * Map module request to a script handle.

};
type WebpackCompiler = import("webpack").Compiler;
type WebpackExternalsFunction = (context: any, request: any, callback: import("webpack").ExternalsFunctionCallback) => any;
//# sourceMappingURL=index.d.ts.map

@@ -5,2 +5,8 @@ <!-- Learn how to maintain this file at https://github.com/WordPress/gutenberg/tree/master/packages#maintaining-changelogs. -->

## 2.9.0 (2020-12-17)
### New feature
- Make the plugin compatible with webpack 5.
## 2.7.0 (2020-06-15)

@@ -7,0 +13,0 @@

@@ -6,6 +6,5 @@ /**

const path = require( 'path' );
const { ExternalsPlugin } = require( 'webpack' );
const { RawSource } = require( 'webpack-sources' );
// Ignore reason: json2php is untyped
// @ts-ignore
const webpack = require( 'webpack' );
// In webpack 5 there is a `webpack.sources` field but for webpack 4 we have to fallback to the `webpack-sources` package.
const { RawSource } = webpack.sources || require( 'webpack-sources' );
const json2php = require( 'json2php' );

@@ -21,49 +20,4 @@

/**
* Map module request to an external.
*
* @callback RequestToExternal
*
* @param {string} request Module request.
*
* @return {string|string[]|void} Return `undefined` to ignore the request.
* Return `string|string[]` to map the request to an external.
*/
/**
* Map module request to a script handle.
*
* @callback RequestToHandle
*
* @param {string} request Module request.
*
* @return {string|void} Return `undefined` to use the same name as the module.
* Return `string` to map the request to a specific script handle.
*/
/**
* @typedef AssetData
*
* @property {string} version String representing a particular build
* @property {string[]} dependencies The script dependencies
*/
/**
* @typedef Options
*
* @property {boolean} injectPolyfill Force wp-polyfill to be included in each entry point's dependency list. This is like importing `@wordpress/polyfill` for each entry point.
* @property {boolean} useDefaults Set to `false` to disable the default WordPress script request handling.
* @property {'php'|'json'} outputFormat The output format for the generated asset file.
* @property {RequestToExternal|undefined} [requestToExternal] Map module requests to an external.
* @property {RequestToHandle|undefined} [requestToHandle] Map module requests to a script handle.
* @property {string|null} combinedOutputFile This option is useful only when the combineAssets option is enabled. It allows providing a custom output file for the generated single assets file. It's possible to provide a path that is relative to the output directory.
* @property {boolean|undefined} combineAssets By default, one asset file is created for each entry point. When this flag is set to true, all information about assets is combined into a single assets.(json|php) file generated in the output directory.
*/
class DependencyExtractionWebpackPlugin {
/**
* @param {Partial<Options>} options
*/
constructor( options ) {
/** @type {Options} */
this.options = Object.assign(

@@ -80,3 +34,3 @@ {

/**
/*
* Track requests that are externalized.

@@ -87,4 +41,2 @@ *

* lists are generated.
*
* @type {Set<string>}
*/

@@ -94,4 +46,4 @@ this.externalizedDeps = new Set();

// Offload externalization work to the ExternalsPlugin.
this.externalsPlugin = new ExternalsPlugin(
'this',
this.externalsPlugin = new webpack.ExternalsPlugin(
'window',
this.externalizeWpDeps.bind( this )

@@ -101,10 +53,3 @@ );

/* eslint-disable jsdoc/valid-types */
/**
* @param {Parameters<WebpackExternalsFunction>[0]} _context
* @param {Parameters<WebpackExternalsFunction>[1]} request
* @param {Parameters<WebpackExternalsFunction>[2]} callback
*/
externalizeWpDeps( _context, request, callback ) {
/* eslint-enable jsdoc/valid-types */
let externalRequest;

@@ -128,3 +73,3 @@

return callback( null, { this: externalRequest } );
return callback( null, externalRequest );
}

@@ -135,6 +80,2 @@

/**
* @param {string} request
* @return {string} Transformed request
*/
mapRequestToDependency( request ) {

@@ -161,6 +102,2 @@ // Handle via options.requestToHandle first

/**
* @param {Object} asset
* @return {string} Stringified asset
*/
stringify( asset ) {

@@ -176,16 +113,5 @@ if ( this.options.outputFormat === 'php' ) {

/**
* @param {WebpackCompiler} compiler
* @return {void}
*/
apply( compiler ) {
this.externalsPlugin.apply( compiler );
// Assert the `string` type for output filename.
// The type indicates the option may be `undefined`.
// However, at this point in compilation, webpack has filled the options in if
// they were not provided.
const outputFilename = /** @type {{filename:string}} */ ( compiler
.options.output ).filename;
compiler.hooks.emit.tap( this.constructor.name, ( compilation ) => {

@@ -199,3 +125,2 @@ const {

/** @type {Record<string, AssetData>} */
const combinedAssetsData = {};

@@ -208,3 +133,2 @@

] of compilation.entrypoints.entries() ) {
/** @type {Set<string>} */
const entrypointExternalizedWpDeps = new Set();

@@ -215,12 +139,20 @@ if ( injectPolyfill ) {

const processModule = ( { userRequest } ) => {
if ( this.externalizedDeps.has( userRequest ) ) {
const scriptDependency = this.mapRequestToDependency(
userRequest
);
entrypointExternalizedWpDeps.add( scriptDependency );
}
};
// Search for externalized modules in all chunks.
for ( const chunk of entrypoint.chunks ) {
for ( const { userRequest } of chunk.modulesIterable ) {
if ( this.externalizedDeps.has( userRequest ) ) {
const scriptDependency = this.mapRequestToDependency(
userRequest
);
entrypointExternalizedWpDeps.add(
scriptDependency
);
for ( const chunkModule of chunk.modulesIterable ) {
processModule( chunkModule );
// loop through submodules of ConcatenatedModule
if ( chunkModule.modules ) {
for ( const concatModule of chunkModule.modules ) {
processModule( concatModule );
}
}

@@ -232,3 +164,2 @@ }

/** @type {AssetData} */
const assetData = {

@@ -246,11 +177,14 @@ // Get a sorted array so we can produce a stable, stringified representation.

const [ filename, query ] = entrypointName.split( '?', 2 );
const buildFilename = compilation.getPath( outputFilename, {
chunk: runtimeChunk,
filename,
query,
basename: basename( filename ),
contentHash: createHash( 'md4' )
.update( assetString )
.digest( 'hex' ),
} );
const buildFilename = compilation.getPath(
compiler.options.output.filename,
{
chunk: runtimeChunk,
filename,
query,
basename: basename( filename ),
contentHash: createHash( 'md4' )
.update( assetString )
.digest( 'hex' ),
}
);

@@ -301,6 +235,2 @@ if ( combineAssets ) {

/**
* @param {string} name
* @return {string} Basename
*/
function basename( name ) {

@@ -314,6 +244,1 @@ if ( ! name.includes( '/' ) ) {

module.exports = DependencyExtractionWebpackPlugin;
/**
* @typedef {import('webpack').Compiler} WebpackCompiler
* @typedef {import('webpack').ExternalsFunctionElement} WebpackExternalsFunction
*/

@@ -8,7 +8,8 @@ const WORDPRESS_NAMESPACE = '@wordpress/';

* Transform @wordpress dependencies:
* - request `@wordpress/api-fetch` becomes `[ 'wp', 'apiFetch' ]`
* - request `@wordpress/i18n` becomes `[ 'wp', 'i18n' ]`
*
* request `@wordpress/api-fetch` becomes `wp.apiFetch`
* request `@wordpress/i18n` becomes `wp.i18n`
*
* @type {import('.').RequestToExternal}
* @param {string} request Module request (the module name in `import from`) to be transformed
* @return {string|string[]|undefined} The resulting external definition. Return `undefined`
* to ignore the request. Return `string|string[]` to map the request to an external.
*/

@@ -53,7 +54,8 @@ function defaultRequestToExternal( request ) {

* Transform @wordpress dependencies:
* - request `@wordpress/i18n` becomes `wp-i18n`
* - request `@wordpress/escape-html` becomes `wp-escape-html`
*
* request `@wordpress/i18n` becomes `wp-i18n`
* request `@wordpress/escape-html` becomes `wp-escape-html`
*
* @type {import('.').RequestToHandle}
* @param {string} request Module request (the module name in `import from`) to be transformed
* @return {string|undefined} WordPress script handle to map the request to. Return `undefined`
* to use the same name as the module.
*/

@@ -81,3 +83,2 @@ function defaultRequestToHandle( request ) {

* @param {string} string Input dash-delimited string.
*
* @return {string} Camel-cased string.

@@ -84,0 +85,0 @@ */

{
"name": "@wordpress/dependency-extraction-webpack-plugin",
"version": "2.8.0",
"version": "2.9.0",
"description": "Extract WordPress script dependencies from webpack bundles.",

@@ -27,12 +27,14 @@ "author": "The WordPress Contributors",

"main": "lib/index.js",
"types": "build-types",
"types": "lib/types.d.ts",
"dependencies": {
"json2php": "^0.0.4",
"webpack": "^4.8.3",
"webpack-sources": "^1.3.0"
},
"peerDependencies": {
"webpack": "^4.8.3 || ^5.0.0"
},
"publishConfig": {
"access": "public"
},
"gitHead": "8e06f0d212f89adba9099106497117819adefc5a"
"gitHead": "0f57de12b3c47128b216629b08e5c1657e1ee329"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc