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

@bundle-stats/plugin-webpack-filter

Package Overview
Dependencies
Maintainers
2
Versions
322
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bundle-stats/plugin-webpack-filter - npm Package Compare versions

Comparing version 4.0.0-alpha.15 to 4.0.0-rc.1

85

lib-esm/index.js

@@ -1,39 +0,53 @@

import flow from 'lodash/fp/flow';
import fromPairs from 'lodash/fp/fromPairs';
import get from 'lodash/fp/get';
import map from 'lodash/fp/map';
import _filter from 'lodash/fp/filter';
import pick from 'lodash/fp/pick';
import toPairs from 'lodash/fp/toPairs';
const PATH_IGNORE_PATTERN = '.map$';
export default (source, options = {}) => {
var _a;
var _a, _b, _c;
const pathIgnorePattern = new RegExp(options.pathIgnorePattern || PATH_IGNORE_PATTERN);
const builtAt = get('builtAt')(source);
const hash = get('hash')(source);
const assets = flow([
get('assets'),
map(pick(['name', 'size'])),
_filter(({ name }) => name && !pathIgnorePattern.test(name)),
])(source);
const entrypoints = flow([
get('entrypoints'),
toPairs,
map(([key, value]) => [key, pick('assets')(value)]),
fromPairs,
])(source);
const chunks = flow([
get('chunks'),
map(pick(['id', 'entry', 'initial', 'files', 'names'])),
_filter(({ id }) => id !== null && typeof id !== 'undefined'),
])(source);
const modules = (_a = source === null || source === void 0 ? void 0 : source.modules) === null || _a === void 0 ? void 0 : _a.map(({ name, size, chunks: moduleChunks, modules: concatenatedModules }) => ({
name,
size,
chunks: moduleChunks === null || moduleChunks === void 0 ? void 0 : moduleChunks.filter((chunkId) => chunkId !== null && typeof chunkId !== 'undefined'),
modules: concatenatedModules === null || concatenatedModules === void 0 ? void 0 : concatenatedModules.map((concatenatedModule) => ({
name: concatenatedModule.name,
size: concatenatedModule.size,
})),
}));
const { builtAt, hash } = source;
const assets = ((_a = source.assets) === null || _a === void 0 ? void 0 : _a.reduce((agg, asset) => {
if (!asset.name || pathIgnorePattern.test(asset.name)) {
return agg;
}
agg.push({
name: asset.name,
size: asset.size,
});
return agg;
}, [])) || [];
const chunks = ((_b = source.chunks) === null || _b === void 0 ? void 0 : _b.reduce((agg, chunk) => {
if (typeof chunk.id === 'undefined' || chunk.id === null) {
return agg;
}
agg.push({
id: chunk.id,
entry: chunk.entry,
initial: chunk.initial,
files: chunk.files,
names: chunk.names,
});
return agg;
}, [])) || [];
const modules = ((_c = source.modules) === null || _c === void 0 ? void 0 : _c.reduce((agg, moduleStats) => {
var _a, _b;
if (!moduleStats.name) {
return agg;
}
const moduleChunks = ((_a = moduleStats.chunks) === null || _a === void 0 ? void 0 : _a.filter((chunkId) => chunkId !== null && typeof chunkId !== 'undefined')) || [];
const concatenatedModules = (_b = moduleStats.modules) === null || _b === void 0 ? void 0 : _b.reduce((aggConcatenatedModules, concatenatedModule) => {
if (!concatenatedModule.name) {
return aggConcatenatedModules;
}
aggConcatenatedModules.push({
name: concatenatedModule.name,
size: concatenatedModule.size,
});
return aggConcatenatedModules;
}, []);
agg.push({
name: moduleStats.name,
size: moduleStats.size,
chunks: moduleChunks,
...(concatenatedModules && { modules: concatenatedModules }),
});
return agg;
}, [])) || [];
return {

@@ -43,3 +57,2 @@ builtAt,

assets,
entrypoints,
chunks,

@@ -46,0 +59,0 @@ modules,

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const flow_1 = __importDefault(require("lodash/fp/flow"));
const fromPairs_1 = __importDefault(require("lodash/fp/fromPairs"));
const get_1 = __importDefault(require("lodash/fp/get"));
const map_1 = __importDefault(require("lodash/fp/map"));
const filter_1 = __importDefault(require("lodash/fp/filter"));
const pick_1 = __importDefault(require("lodash/fp/pick"));
const toPairs_1 = __importDefault(require("lodash/fp/toPairs"));
const PATH_IGNORE_PATTERN = '.map$';
exports.default = (source, options = {}) => {
const pathIgnorePattern = new RegExp(options.pathIgnorePattern || PATH_IGNORE_PATTERN);
const builtAt = (0, get_1.default)('builtAt')(source);
const hash = (0, get_1.default)('hash')(source);
const assets = (0, flow_1.default)([
(0, get_1.default)('assets'),
(0, map_1.default)((0, pick_1.default)(['name', 'size'])),
(0, filter_1.default)(({ name }) => name && !pathIgnorePattern.test(name)),
])(source);
const entrypoints = (0, flow_1.default)([
(0, get_1.default)('entrypoints'),
toPairs_1.default,
(0, map_1.default)(([key, value]) => [key, (0, pick_1.default)('assets')(value)]),
fromPairs_1.default,
])(source);
const chunks = (0, flow_1.default)([
(0, get_1.default)('chunks'),
(0, map_1.default)((0, pick_1.default)(['id', 'entry', 'initial', 'files', 'names'])),
(0, filter_1.default)(({ id }) => id !== null && typeof id !== 'undefined'),
])(source);
const modules = source?.modules?.map(({ name, size, chunks: moduleChunks, modules: concatenatedModules }) => ({
name,
size,
chunks: moduleChunks?.filter((chunkId) => chunkId !== null && typeof chunkId !== 'undefined'),
modules: concatenatedModules?.map((concatenatedModule) => ({
name: concatenatedModule.name,
size: concatenatedModule.size,
})),
}));
const { builtAt, hash } = source;
const assets = source.assets?.reduce((agg, asset) => {
if (!asset.name || pathIgnorePattern.test(asset.name)) {
return agg;
}
agg.push({
name: asset.name,
size: asset.size,
});
return agg;
}, []) || [];
const chunks = source.chunks?.reduce((agg, chunk) => {
if (typeof chunk.id === 'undefined' || chunk.id === null) {
return agg;
}
agg.push({
id: chunk.id,
entry: chunk.entry,
initial: chunk.initial,
files: chunk.files,
names: chunk.names,
});
return agg;
}, []) || [];
const modules = source.modules?.reduce((agg, moduleStats) => {
if (!moduleStats.name) {
return agg;
}
const moduleChunks = moduleStats.chunks?.filter((chunkId) => chunkId !== null && typeof chunkId !== 'undefined') || [];
const concatenatedModules = moduleStats.modules?.reduce((aggConcatenatedModules, concatenatedModule) => {
if (!concatenatedModule.name) {
return aggConcatenatedModules;
}
aggConcatenatedModules.push({
name: concatenatedModule.name,
size: concatenatedModule.size,
});
return aggConcatenatedModules;
}, []);
agg.push({
name: moduleStats.name,
size: moduleStats.size,
chunks: moduleChunks,
...(concatenatedModules && { modules: concatenatedModules }),
});
return agg;
}, []) || [];
return {

@@ -47,3 +57,2 @@ builtAt,

assets,
entrypoints,
chunks,

@@ -50,0 +59,0 @@ modules,

{
"name": "@bundle-stats/plugin-webpack-filter",
"version": "4.0.0-alpha.15",
"version": "4.0.0-rc.1",
"description": "BundleStats webpack filter plugin",

@@ -39,3 +39,2 @@ "main": "lib/index.js",

"@types/jest": "28.1.4",
"@types/lodash": "4.14.182",
"@types/webpack": "5.28.0",

@@ -46,3 +45,2 @@ "core-js": "3.23.3",

"jest-date-mock": "1.0.8",
"lodash": "4.17.21",
"regenerator-runtime": "0.13.9",

@@ -53,6 +51,5 @@ "ts-jest": "28.0.5",

"peerDependencies": {
"core-js": "^3.0.0",
"lodash": "^4.0.0"
"core-js": "^3.0.0"
},
"gitHead": "d076065ddbf0eb25cf871b527c141b867de10272"
"gitHead": "8f28ce5d4c570ac11670f5f0f34a3c9c3ea6a162"
}
// eslint-disable-next-line import/no-extraneous-dependencies
import { StatsAsset, StatsCompilation, StatsModule } from 'webpack';
import flow from 'lodash/fp/flow';
import fromPairs from 'lodash/fp/fromPairs';
import get from 'lodash/fp/get';
import map from 'lodash/fp/map';
import _filter from 'lodash/fp/filter';
import pick from 'lodash/fp/pick';
import toPairs from 'lodash/fp/toPairs';
import { StatsCompilation } from 'webpack';

@@ -17,27 +10,36 @@ const PATH_IGNORE_PATTERN = '.map$';

type WebpackStatsFilteredAsset = Pick<StatsAsset, 'name' | 'size'>;
interface WebpackStatsFileteredEntrypoint {
assets: Array<string>;
export interface WebpackStatsFilteredAsset {
name: string;
size?: number;
}
interface WebpackStatsFilteredChunk {
export interface WebpackStatsFilteredChunk {
entry: boolean;
id: number | string;
initial: boolean;
files: Array<string>;
names: Array<string>;
files?: Array<string>;
names?: Array<string>;
}
interface WebpackStatsFileteredModule extends Pick<StatsModule, 'name' | 'size' | 'chunks'> {
modules?: Array<Pick<StatsModule, 'name' | 'size'>>;
export interface WebpackStatsFilteredModule {
name: string;
size?: number;
chunks: Array<string | number>;
}
interface WebpackStatsFiltered {
builtAt?: string;
export interface WebpackStatsFilteredConcatenatedModule {
name: string;
size?: number;
}
export interface WebpackStatsFilteredRootModule extends WebpackStatsFilteredModule {
modules?: Array<WebpackStatsFilteredConcatenatedModule>;
}
export interface WebpackStatsFiltered {
builtAt?: number;
hash?: string;
assets?: Array<WebpackStatsFilteredAsset>;
entrypoints?: Record<string, WebpackStatsFileteredEntrypoint>;
chunks?: Array<WebpackStatsFilteredChunk>;
modules?: Array<WebpackStatsFileteredModule>;
modules?: Array<WebpackStatsFilteredRootModule>;
}

@@ -49,3 +51,4 @@

export default (
source: StatsCompilation, options: BundleStatsOptions = {},
source: StatsCompilation,
options: BundleStatsOptions = {},
): WebpackStatsFiltered => {

@@ -55,39 +58,75 @@ const pathIgnorePattern = new RegExp(options.pathIgnorePattern || PATH_IGNORE_PATTERN);

// meta
const builtAt = get('builtAt')(source);
const hash = get('hash')(source);
const { builtAt, hash } = source;
// rawData
const assets = flow([
get('assets'),
map(pick(['name', 'size'])),
// Skip assets with empty name or ignore pattern
_filter(({ name }) => name && !pathIgnorePattern.test(name)),
])(source);
const assets =
source.assets?.reduce((agg, asset) => {
// Skip assets with empty name or ignore pattern
if (!asset.name || pathIgnorePattern.test(asset.name)) {
return agg;
}
const entrypoints = flow([
get('entrypoints'),
toPairs,
map(([key, value]) => [key, pick('assets')(value)]),
fromPairs,
])(source);
agg.push({
name: asset.name,
size: asset.size,
});
const chunks = flow([
get('chunks'),
map(pick(['id', 'entry', 'initial', 'files', 'names'])),
// Skip chunks with empty id
_filter(({ id }) => id !== null && typeof id !== 'undefined'),
])(source);
return agg;
}, [] as Array<WebpackStatsFilteredAsset>) || [];
const modules = source?.modules?.map(
({ name, size, chunks: moduleChunks, modules: concatenatedModules }) => ({
name,
size,
chunks: moduleChunks?.filter((chunkId) => chunkId !== null && typeof chunkId !== 'undefined'),
modules: concatenatedModules?.map((concatenatedModule) => ({
name: concatenatedModule.name,
size: concatenatedModule.size,
})),
}),
);
const chunks =
source.chunks?.reduce((agg, chunk) => {
// Skip chunks with empty ids
if (typeof chunk.id === 'undefined' || chunk.id === null) {
return agg;
}
agg.push({
id: chunk.id,
entry: chunk.entry,
initial: chunk.initial,
files: chunk.files,
names: chunk.names,
});
return agg;
}, [] as Array<WebpackStatsFilteredChunk>) || [];
const modules =
source.modules?.reduce((agg, moduleStats) => {
if (!moduleStats.name) {
return agg;
}
const moduleChunks =
moduleStats.chunks?.filter(
(chunkId) => chunkId !== null && typeof chunkId !== 'undefined',
) || [];
const concatenatedModules = moduleStats.modules?.reduce(
(aggConcatenatedModules, concatenatedModule) => {
if (!concatenatedModule.name) {
return aggConcatenatedModules;
}
aggConcatenatedModules.push({
name: concatenatedModule.name,
size: concatenatedModule.size,
});
return aggConcatenatedModules;
},
[] as Array<WebpackStatsFilteredConcatenatedModule>,
);
agg.push({
name: moduleStats.name,
size: moduleStats.size,
chunks: moduleChunks,
...(concatenatedModules && { modules: concatenatedModules }),
});
return agg;
}, [] as Array<WebpackStatsFilteredRootModule>) || [];
return {

@@ -97,3 +136,2 @@ builtAt,

assets,
entrypoints,
chunks,

@@ -100,0 +138,0 @@ modules,

@@ -1,28 +0,36 @@

import { StatsAsset, StatsCompilation, StatsModule } from 'webpack';
import { StatsCompilation } from 'webpack';
interface BundleStatsOptions {
pathIgnorePattern?: string;
}
declare type WebpackStatsFilteredAsset = Pick<StatsAsset, 'name' | 'size'>;
interface WebpackStatsFileteredEntrypoint {
assets: Array<string>;
export interface WebpackStatsFilteredAsset {
name: string;
size?: number;
}
interface WebpackStatsFilteredChunk {
export interface WebpackStatsFilteredChunk {
entry: boolean;
id: number | string;
initial: boolean;
files: Array<string>;
names: Array<string>;
files?: Array<string>;
names?: Array<string>;
}
interface WebpackStatsFileteredModule extends Pick<StatsModule, 'name' | 'size' | 'chunks'> {
modules?: Array<Pick<StatsModule, 'name' | 'size'>>;
export interface WebpackStatsFilteredModule {
name: string;
size?: number;
chunks: Array<string | number>;
}
interface WebpackStatsFiltered {
builtAt?: string;
export interface WebpackStatsFilteredConcatenatedModule {
name: string;
size?: number;
}
export interface WebpackStatsFilteredRootModule extends WebpackStatsFilteredModule {
modules?: Array<WebpackStatsFilteredConcatenatedModule>;
}
export interface WebpackStatsFiltered {
builtAt?: number;
hash?: string;
assets?: Array<WebpackStatsFilteredAsset>;
entrypoints?: Record<string, WebpackStatsFileteredEntrypoint>;
chunks?: Array<WebpackStatsFilteredChunk>;
modules?: Array<WebpackStatsFileteredModule>;
modules?: Array<WebpackStatsFilteredRootModule>;
}
declare const _default: (source: StatsCompilation, options?: BundleStatsOptions) => WebpackStatsFiltered;
export default _default;

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