Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

sonda

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sonda - npm Package Compare versions

Comparing version
0.7.0
to
0.7.1
+31
bin/sonda-angular.js
#!/usr/bin/env node
import { parseArgs } from 'util';
import Sonda from 'sonda/angular';
const { values } = parseArgs( {
options: {
config: { type: 'string' },
projects: { type: 'string', multiple: true },
format: { type: 'string' },
filename: { type: 'string' },
'no-open': { type: 'boolean' },
detailed: { type: 'boolean' },
sources: { type: 'boolean' },
gzip: { type: 'boolean' },
brotli: { type: 'boolean' }
},
// Skip `node sonda-angular`
args: process.argv.slice( 2 ),
// Fail when unknown argument is used
strict: true
} );
if ( values[ 'no-open' ] ) {
values.open = false;
delete values[ 'no-open' ];
}
Sonda( values );
"use strict";
const require_src = require('../src.cjs');
const require_esbuild = require('../esbuild.cjs');
const path = require_src.__toESM(require("path"));
const fs = require_src.__toESM(require("fs"));
//#region src/entrypoints/angular.ts
function SondaAngular(options = {}) {
const cwd = process.cwd();
const { config = "angular.json", projects = [],...opts } = options;
opts.format ??= "html";
opts.filename ??= `sonda-report-[project].${opts.format}`;
if (!opts.filename.includes("[project]")) throw new Error("SondaAngular: The \"filename\" option must include the \"[project]\" token.");
const angularConfig = loadJson(config);
const projectsToGenerate = projects.length ? projects : Object.keys(angularConfig.projects);
for (const project of projectsToGenerate) {
const { outputPath } = angularConfig.projects[project].architect.build.options;
const paths = typeof outputPath === "object" ? outputPath : { base: outputPath };
paths.base = (0, path.resolve)(cwd, paths.base);
paths.browser = (0, path.resolve)(paths.base, paths.browser || "browser");
paths.server = (0, path.resolve)(paths.base, paths.server || "server");
const metafile = updateMetafile(loadJson((0, path.resolve)(paths.base, "stats.json")), paths);
const sondaOptions = Object.assign({}, opts);
sondaOptions.filename = sondaOptions.filename.replace("[project]", project);
require_esbuild.processEsbuildMetaFile(metafile, sondaOptions);
}
}
function loadJson(path$1) {
return JSON.parse((0, fs.readFileSync)((0, path.resolve)(process.cwd(), path$1), "utf8"));
}
/**
* Output paths in metafile only include file name, without the relative path from the current
* working directory. For example, in the metafile the output path is "main-xxx.js", but in the
* file system it's "dist/project/browser/en/main-xxx.js". This function updates the output paths
* to include the relative path from the current working directory.
*/
function updateMetafile(metafile, paths) {
const cwd = process.cwd();
const outputs = Object.assign({}, metafile.outputs);
metafile.outputs = {};
for (const path$1 of (0, fs.readdirSync)(paths.base, {
encoding: "utf8",
recursive: true
})) {
const absolutePath = (0, path.resolve)(paths.base, path$1);
const filename = (0, path.basename)(absolutePath);
const originalOutput = outputs[filename];
if (originalOutput) metafile.outputs[(0, path.relative)(cwd, absolutePath)] = originalOutput;
}
return metafile;
}
//#endregion
module.exports = SondaAngular;
//# sourceMappingURL=angular.cjs.map
{"version":3,"file":"angular.cjs","names":["options: Partial<AngularUserOptions>","paths: Paths","path: string","path","metafile: Metafile"],"sources":["../../src/entrypoints/angular.ts"],"sourcesContent":["import { readFileSync, readdirSync } from 'fs';\nimport { basename, relative, resolve } from 'path';\nimport type { UserOptions } from '../types';\nimport type { Metafile } from 'esbuild';\nimport { processEsbuildMetaFile } from './esbuild';\n\ninterface AngularUserOptions extends UserOptions {\n config: string;\n projects: string[];\n}\n\ninterface Paths {\n base: string;\n browser: string;\n server: string;\n}\n\nexport default function SondaAngular( options: Partial<AngularUserOptions> = {} ): void {\n const cwd = process.cwd();\n const {\n config = 'angular.json',\n projects = [],\n ...opts\n } = options;\n\n opts.format ??= 'html';\n opts.filename ??= `sonda-report-[project].${ opts.format }`;\n\n // Angular workspaces can have multiple projects, so we need to generate a report for each\n if ( !opts.filename.includes( '[project]' ) ) {\n throw new Error( 'SondaAngular: The \"filename\" option must include the \"[project]\" token.' );\n }\n\n const angularConfig = loadJson( config );\n const projectsToGenerate = projects.length ? projects : Object.keys( angularConfig.projects );\n\n for ( const project of projectsToGenerate ) {\n const { outputPath } = angularConfig.projects[ project ].architect.build.options;\n const paths: Paths = typeof outputPath === 'object'\n ? outputPath\n : { base: outputPath };\n\n paths.base = resolve( cwd, paths.base );\n paths.browser = resolve( paths.base, paths.browser || 'browser' );\n paths.server = resolve( paths.base, paths.server || 'server' );\n\n const metafile = updateMetafile(\n loadJson<Metafile>( resolve( paths.base, 'stats.json' ) ),\n paths\n );\n\n // Because this configuration is shared between multiple projects, we need to clone it\n const sondaOptions = Object.assign( {}, opts );\n\n // Replace the \"[project]\" token with the current project name\n sondaOptions.filename = sondaOptions.filename!.replace( '[project]', project );\n\n processEsbuildMetaFile( metafile, sondaOptions );\n }\n}\n\nfunction loadJson<T extends any = any>( path: string ): T {\n return JSON.parse(\n readFileSync( resolve( process.cwd(), path ), 'utf8' )\n );\n}\n\n/**\n * Output paths in metafile only include file name, without the relative path from the current\n * working directory. For example, in the metafile the output path is \"main-xxx.js\", but in the\n * file system it's \"dist/project/browser/en/main-xxx.js\". This function updates the output paths\n * to include the relative path from the current working directory.\n */\nfunction updateMetafile(\n metafile: Metafile,\n paths: Paths\n): Metafile {\n const cwd = process.cwd();\n\n // Clone the original outputs object\n const outputs = Object.assign( {}, metafile.outputs );\n\n // Reset the outputs\n metafile.outputs = {};\n\n for ( const path of readdirSync( paths.base, { encoding: 'utf8', recursive: true } ) ) {\n const absolutePath = resolve( paths.base, path );\n const filename = basename( absolutePath );\n const originalOutput = outputs[ filename ];\n\n // If the output file name exists in the original outputs, add the updated relative path\n if ( originalOutput ) {\n metafile.outputs[ relative( cwd, absolutePath ) ] = originalOutput;\n }\n }\n\n return metafile;\n}\n"],"mappings":";;;;;;;AAiBe,SAAS,aAAcA,UAAuC,CAAE,GAAS;CACtF,MAAM,MAAM,QAAQ,KAAK;CACzB,MAAM,EACJ,SAAS,gBACT,WAAW,CAAE,EACb,GAAG,MACJ,GAAG;AAEJ,MAAK,WAAW;AAChB,MAAK,cAAc,yBAA0B,KAAK,OAAQ;AAG1D,MAAM,KAAK,SAAS,SAAU,YAAa,CACzC,OAAM,IAAI,MAAO;CAGnB,MAAM,gBAAgB,SAAU,OAAQ;CACxC,MAAM,qBAAqB,SAAS,SAAS,WAAW,OAAO,KAAM,cAAc,SAAU;AAE7F,MAAM,MAAM,WAAW,oBAAqB;EAC1C,MAAM,EAAE,YAAY,GAAG,cAAc,SAAU,SAAU,UAAU,MAAM;EACzE,MAAMC,eAAsB,eAAe,WACvC,aACA,EAAE,MAAM,WAAY;AAExB,QAAM,OAAO,kBAAS,KAAK,MAAM,KAAM;AACvC,QAAM,UAAU,kBAAS,MAAM,MAAM,MAAM,WAAW,UAAW;AACjE,QAAM,SAAS,kBAAS,MAAM,MAAM,MAAM,UAAU,SAAU;EAE9D,MAAM,WAAW,eACf,SAAoB,kBAAS,MAAM,MAAM,aAAc,CAAE,EACzD,MACD;EAGD,MAAM,eAAe,OAAO,OAAQ,CAAE,GAAE,KAAM;AAG9C,eAAa,WAAW,aAAa,SAAU,QAAS,aAAa,QAAS;AAE9E,yCAAwB,UAAU,aAAc;CACjD;AACF;AAED,SAAS,SAA+BC,QAAkB;AACxD,QAAO,KAAK,MACV,qBAAc,kBAAS,QAAQ,KAAK,EAAEC,OAAM,EAAE,OAAQ,CACvD;AACF;;;;;;;AAQD,SAAS,eACPC,UACAH,OACU;CACV,MAAM,MAAM,QAAQ,KAAK;CAGzB,MAAM,UAAU,OAAO,OAAQ,CAAE,GAAE,SAAS,QAAS;AAGrD,UAAS,UAAU,CAAE;AAErB,MAAM,MAAME,UAAQ,oBAAa,MAAM,MAAM;EAAE,UAAU;EAAQ,WAAW;CAAM,EAAE,EAAG;EACrF,MAAM,eAAe,kBAAS,MAAM,MAAMA,OAAM;EAChD,MAAM,WAAW,mBAAU,aAAc;EACzC,MAAM,iBAAiB,QAAS;AAGhC,MAAK,eACH,UAAS,QAAS,mBAAU,KAAK,aAAc,IAAK;CAEvD;AAED,QAAO;AACR"}
import type { UserOptions } from '../types';
interface AngularUserOptions extends UserOptions {
config: string;
projects: string[];
}
export default function SondaAngular(options?: Partial<AngularUserOptions>): void;
export {};
import "../src.mjs";
import { processEsbuildMetaFile } from "../esbuild.mjs";
import { basename, relative, resolve } from "path";
import { readFileSync, readdirSync } from "fs";
//#region src/entrypoints/angular.ts
function SondaAngular(options = {}) {
const cwd = process.cwd();
const { config = "angular.json", projects = [],...opts } = options;
opts.format ??= "html";
opts.filename ??= `sonda-report-[project].${opts.format}`;
if (!opts.filename.includes("[project]")) throw new Error("SondaAngular: The \"filename\" option must include the \"[project]\" token.");
const angularConfig = loadJson(config);
const projectsToGenerate = projects.length ? projects : Object.keys(angularConfig.projects);
for (const project of projectsToGenerate) {
const { outputPath } = angularConfig.projects[project].architect.build.options;
const paths = typeof outputPath === "object" ? outputPath : { base: outputPath };
paths.base = resolve(cwd, paths.base);
paths.browser = resolve(paths.base, paths.browser || "browser");
paths.server = resolve(paths.base, paths.server || "server");
const metafile = updateMetafile(loadJson(resolve(paths.base, "stats.json")), paths);
const sondaOptions = Object.assign({}, opts);
sondaOptions.filename = sondaOptions.filename.replace("[project]", project);
processEsbuildMetaFile(metafile, sondaOptions);
}
}
function loadJson(path) {
return JSON.parse(readFileSync(resolve(process.cwd(), path), "utf8"));
}
/**
* Output paths in metafile only include file name, without the relative path from the current
* working directory. For example, in the metafile the output path is "main-xxx.js", but in the
* file system it's "dist/project/browser/en/main-xxx.js". This function updates the output paths
* to include the relative path from the current working directory.
*/
function updateMetafile(metafile, paths) {
const cwd = process.cwd();
const outputs = Object.assign({}, metafile.outputs);
metafile.outputs = {};
for (const path of readdirSync(paths.base, {
encoding: "utf8",
recursive: true
})) {
const absolutePath = resolve(paths.base, path);
const filename = basename(absolutePath);
const originalOutput = outputs[filename];
if (originalOutput) metafile.outputs[relative(cwd, absolutePath)] = originalOutput;
}
return metafile;
}
//#endregion
export { SondaAngular as default };
//# sourceMappingURL=angular.mjs.map
{"version":3,"file":"angular.mjs","names":["options: Partial<AngularUserOptions>","paths: Paths","path: string","metafile: Metafile"],"sources":["../../src/entrypoints/angular.ts"],"sourcesContent":["import { readFileSync, readdirSync } from 'fs';\nimport { basename, relative, resolve } from 'path';\nimport type { UserOptions } from '../types';\nimport type { Metafile } from 'esbuild';\nimport { processEsbuildMetaFile } from './esbuild';\n\ninterface AngularUserOptions extends UserOptions {\n config: string;\n projects: string[];\n}\n\ninterface Paths {\n base: string;\n browser: string;\n server: string;\n}\n\nexport default function SondaAngular( options: Partial<AngularUserOptions> = {} ): void {\n const cwd = process.cwd();\n const {\n config = 'angular.json',\n projects = [],\n ...opts\n } = options;\n\n opts.format ??= 'html';\n opts.filename ??= `sonda-report-[project].${ opts.format }`;\n\n // Angular workspaces can have multiple projects, so we need to generate a report for each\n if ( !opts.filename.includes( '[project]' ) ) {\n throw new Error( 'SondaAngular: The \"filename\" option must include the \"[project]\" token.' );\n }\n\n const angularConfig = loadJson( config );\n const projectsToGenerate = projects.length ? projects : Object.keys( angularConfig.projects );\n\n for ( const project of projectsToGenerate ) {\n const { outputPath } = angularConfig.projects[ project ].architect.build.options;\n const paths: Paths = typeof outputPath === 'object'\n ? outputPath\n : { base: outputPath };\n\n paths.base = resolve( cwd, paths.base );\n paths.browser = resolve( paths.base, paths.browser || 'browser' );\n paths.server = resolve( paths.base, paths.server || 'server' );\n\n const metafile = updateMetafile(\n loadJson<Metafile>( resolve( paths.base, 'stats.json' ) ),\n paths\n );\n\n // Because this configuration is shared between multiple projects, we need to clone it\n const sondaOptions = Object.assign( {}, opts );\n\n // Replace the \"[project]\" token with the current project name\n sondaOptions.filename = sondaOptions.filename!.replace( '[project]', project );\n\n processEsbuildMetaFile( metafile, sondaOptions );\n }\n}\n\nfunction loadJson<T extends any = any>( path: string ): T {\n return JSON.parse(\n readFileSync( resolve( process.cwd(), path ), 'utf8' )\n );\n}\n\n/**\n * Output paths in metafile only include file name, without the relative path from the current\n * working directory. For example, in the metafile the output path is \"main-xxx.js\", but in the\n * file system it's \"dist/project/browser/en/main-xxx.js\". This function updates the output paths\n * to include the relative path from the current working directory.\n */\nfunction updateMetafile(\n metafile: Metafile,\n paths: Paths\n): Metafile {\n const cwd = process.cwd();\n\n // Clone the original outputs object\n const outputs = Object.assign( {}, metafile.outputs );\n\n // Reset the outputs\n metafile.outputs = {};\n\n for ( const path of readdirSync( paths.base, { encoding: 'utf8', recursive: true } ) ) {\n const absolutePath = resolve( paths.base, path );\n const filename = basename( absolutePath );\n const originalOutput = outputs[ filename ];\n\n // If the output file name exists in the original outputs, add the updated relative path\n if ( originalOutput ) {\n metafile.outputs[ relative( cwd, absolutePath ) ] = originalOutput;\n }\n }\n\n return metafile;\n}\n"],"mappings":";;;;;;AAiBe,SAAS,aAAcA,UAAuC,CAAE,GAAS;CACtF,MAAM,MAAM,QAAQ,KAAK;CACzB,MAAM,EACJ,SAAS,gBACT,WAAW,CAAE,EACb,GAAG,MACJ,GAAG;AAEJ,MAAK,WAAW;AAChB,MAAK,cAAc,yBAA0B,KAAK,OAAQ;AAG1D,MAAM,KAAK,SAAS,SAAU,YAAa,CACzC,OAAM,IAAI,MAAO;CAGnB,MAAM,gBAAgB,SAAU,OAAQ;CACxC,MAAM,qBAAqB,SAAS,SAAS,WAAW,OAAO,KAAM,cAAc,SAAU;AAE7F,MAAM,MAAM,WAAW,oBAAqB;EAC1C,MAAM,EAAE,YAAY,GAAG,cAAc,SAAU,SAAU,UAAU,MAAM;EACzE,MAAMC,eAAsB,eAAe,WACvC,aACA,EAAE,MAAM,WAAY;AAExB,QAAM,OAAO,QAAS,KAAK,MAAM,KAAM;AACvC,QAAM,UAAU,QAAS,MAAM,MAAM,MAAM,WAAW,UAAW;AACjE,QAAM,SAAS,QAAS,MAAM,MAAM,MAAM,UAAU,SAAU;EAE9D,MAAM,WAAW,eACf,SAAoB,QAAS,MAAM,MAAM,aAAc,CAAE,EACzD,MACD;EAGD,MAAM,eAAe,OAAO,OAAQ,CAAE,GAAE,KAAM;AAG9C,eAAa,WAAW,aAAa,SAAU,QAAS,aAAa,QAAS;AAE9E,yBAAwB,UAAU,aAAc;CACjD;AACF;AAED,SAAS,SAA+BC,MAAkB;AACxD,QAAO,KAAK,MACV,aAAc,QAAS,QAAQ,KAAK,EAAE,KAAM,EAAE,OAAQ,CACvD;AACF;;;;;;;AAQD,SAAS,eACPC,UACAF,OACU;CACV,MAAM,MAAM,QAAQ,KAAK;CAGzB,MAAM,UAAU,OAAO,OAAQ,CAAE,GAAE,SAAS,QAAS;AAGrD,UAAS,UAAU,CAAE;AAErB,MAAM,MAAM,QAAQ,YAAa,MAAM,MAAM;EAAE,UAAU;EAAQ,WAAW;CAAM,EAAE,EAAG;EACrF,MAAM,eAAe,QAAS,MAAM,MAAM,KAAM;EAChD,MAAM,WAAW,SAAU,aAAc;EACzC,MAAM,iBAAiB,QAAS;AAGhC,MAAK,eACH,UAAS,QAAS,SAAU,KAAK,aAAc,IAAK;CAEvD;AAED,QAAO;AACR"}
"use strict";
const require_src = require('./src.cjs');
const path = require_src.__toESM(require("path"));
//#region src/entrypoints/esbuild.ts
function SondaEsbuildPlugin(options = {}) {
return {
name: "sonda",
setup(build) {
if (options.enabled === false) return;
build.initialOptions.metafile = true;
options.detailed = false;
build.onEnd((result) => processEsbuildMetaFile(result.metafile, options));
}
};
}
function processEsbuildMetaFile(metafile, options) {
const cwd = process.cwd();
const inputs = Object.entries(metafile.inputs).reduce((acc, [path$1, data]) => {
acc[path$1] = {
bytes: data.bytes,
format: data.format ?? "unknown",
imports: data.imports.map((data$1) => data$1.path),
belongsTo: null
};
/**
* Because esbuild already reads the existing source maps, there may be
* cases where some report "outputs" include "inputs" that don't exist
* in the main "inputs" object. To avoid this, we parse each esbuild
* input and add its sources to the "inputs" object.
*/
require_src.addSourcesToInputs((0, path.resolve)(cwd, path$1), acc);
return acc;
}, {});
require_src.generateReportFromAssets(Object.keys(metafile.outputs).map((path$1) => (0, path.resolve)(cwd, path$1)), inputs, options);
}
//#endregion
Object.defineProperty(exports, 'SondaEsbuildPlugin', {
enumerable: true,
get: function () {
return SondaEsbuildPlugin;
}
});
Object.defineProperty(exports, 'processEsbuildMetaFile', {
enumerable: true,
get: function () {
return processEsbuildMetaFile;
}
});
//# sourceMappingURL=esbuild.cjs.map
{"version":3,"file":"esbuild.cjs","names":["options: Partial<UserOptions>","metafile: Metafile","path","data"],"sources":["../src/entrypoints/esbuild.ts"],"sourcesContent":["import { resolve } from 'path';\nimport { generateReportFromAssets, addSourcesToInputs } from '../index.js';\nimport type { Metafile, Plugin } from 'esbuild';\nimport type { JsonReport, UserOptions } from '../types.js';\n\nexport default function SondaEsbuildPlugin( options: Partial<UserOptions> = {} ): Plugin {\n\treturn {\n\t\tname: 'sonda',\n\t\tsetup( build ) {\n\t\t\tif ( options.enabled === false ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tbuild.initialOptions.metafile = true;\n\n\t\t\t// Esbuild already reads the existing source maps, so there's no need to do it again\n\t\t\toptions.detailed = false;\n\n\t\t\tbuild.onEnd( result => processEsbuildMetaFile( result.metafile!, options ) );\n\t\t}\n\t};\n}\n\nexport function processEsbuildMetaFile( metafile: Metafile, options: Partial<UserOptions> ): void {\n\tconst cwd = process.cwd();\n\tconst inputs = Object\n\t\t.entries( metafile.inputs )\n\t\t.reduce( ( acc, [ path, data ] ) => {\n\t\t\tacc[ path ] = {\n\t\t\t\tbytes: data.bytes,\n\t\t\t\tformat: data.format ?? 'unknown',\n\t\t\t\timports: data.imports.map( data => data.path ),\n\t\t\t\tbelongsTo: null,\n\t\t\t};\n\n\t\t\t/**\n\t\t\t * Because esbuild already reads the existing source maps, there may be\n\t\t\t * cases where some report \"outputs\" include \"inputs\" that don't exist\n\t\t\t * in the main \"inputs\" object. To avoid this, we parse each esbuild\n\t\t\t * input and add its sources to the \"inputs\" object.\n\t\t\t */\n\t\t\taddSourcesToInputs(\n\t\t\t\tresolve( cwd, path ),\n\t\t\t\tacc\n\t\t\t);\n\n\t\t\treturn acc;\n\t\t}, {} as JsonReport[ 'inputs' ] );\n\n\tgenerateReportFromAssets(\n\t\tObject.keys( metafile!.outputs ).map( path => resolve( cwd, path ) ),\n\t\tinputs,\n\t\toptions\n\t);\n}\n"],"mappings":";;;;;AAKe,SAAS,mBAAoBA,UAAgC,CAAE,GAAW;AACxF,QAAO;EACN,MAAM;EACN,MAAO,OAAQ;AACd,OAAK,QAAQ,YAAY,MACxB;AAGD,SAAM,eAAe,WAAW;AAGhC,WAAQ,WAAW;AAEnB,SAAM,MAAO,YAAU,uBAAwB,OAAO,UAAW,QAAS,CAAE;EAC5E;CACD;AACD;AAEM,SAAS,uBAAwBC,UAAoBD,SAAsC;CACjG,MAAM,MAAM,QAAQ,KAAK;CACzB,MAAM,SAAS,OACb,QAAS,SAAS,OAAQ,CAC1B,OAAQ,CAAE,KAAK,CAAEE,QAAM,KAAM,KAAM;AACnC,MAAKA,UAAS;GACb,OAAO,KAAK;GACZ,QAAQ,KAAK,UAAU;GACvB,SAAS,KAAK,QAAQ,IAAK,YAAQC,OAAK,KAAM;GAC9C,WAAW;EACX;;;;;;;AAQD,iCACC,kBAAS,KAAKD,OAAM,EACpB,IACA;AAED,SAAO;CACP,GAAE,CAAE,EAA4B;AAElC,sCACC,OAAO,KAAM,SAAU,QAAS,CAAC,IAAK,YAAQ,kBAAS,KAAKA,OAAM,CAAE,EACpE,QACA,QACA;AACD"}
import { addSourcesToInputs, generateReportFromAssets } from "./src.mjs";
import { resolve } from "path";
//#region src/entrypoints/esbuild.ts
function SondaEsbuildPlugin(options = {}) {
return {
name: "sonda",
setup(build) {
if (options.enabled === false) return;
build.initialOptions.metafile = true;
options.detailed = false;
build.onEnd((result) => processEsbuildMetaFile(result.metafile, options));
}
};
}
function processEsbuildMetaFile(metafile, options) {
const cwd = process.cwd();
const inputs = Object.entries(metafile.inputs).reduce((acc, [path, data]) => {
acc[path] = {
bytes: data.bytes,
format: data.format ?? "unknown",
imports: data.imports.map((data$1) => data$1.path),
belongsTo: null
};
/**
* Because esbuild already reads the existing source maps, there may be
* cases where some report "outputs" include "inputs" that don't exist
* in the main "inputs" object. To avoid this, we parse each esbuild
* input and add its sources to the "inputs" object.
*/
addSourcesToInputs(resolve(cwd, path), acc);
return acc;
}, {});
generateReportFromAssets(Object.keys(metafile.outputs).map((path) => resolve(cwd, path)), inputs, options);
}
//#endregion
export { SondaEsbuildPlugin, processEsbuildMetaFile };
//# sourceMappingURL=esbuild.mjs.map
{"version":3,"file":"esbuild.mjs","names":["options: Partial<UserOptions>","metafile: Metafile","data"],"sources":["../src/entrypoints/esbuild.ts"],"sourcesContent":["import { resolve } from 'path';\nimport { generateReportFromAssets, addSourcesToInputs } from '../index.js';\nimport type { Metafile, Plugin } from 'esbuild';\nimport type { JsonReport, UserOptions } from '../types.js';\n\nexport default function SondaEsbuildPlugin( options: Partial<UserOptions> = {} ): Plugin {\n\treturn {\n\t\tname: 'sonda',\n\t\tsetup( build ) {\n\t\t\tif ( options.enabled === false ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tbuild.initialOptions.metafile = true;\n\n\t\t\t// Esbuild already reads the existing source maps, so there's no need to do it again\n\t\t\toptions.detailed = false;\n\n\t\t\tbuild.onEnd( result => processEsbuildMetaFile( result.metafile!, options ) );\n\t\t}\n\t};\n}\n\nexport function processEsbuildMetaFile( metafile: Metafile, options: Partial<UserOptions> ): void {\n\tconst cwd = process.cwd();\n\tconst inputs = Object\n\t\t.entries( metafile.inputs )\n\t\t.reduce( ( acc, [ path, data ] ) => {\n\t\t\tacc[ path ] = {\n\t\t\t\tbytes: data.bytes,\n\t\t\t\tformat: data.format ?? 'unknown',\n\t\t\t\timports: data.imports.map( data => data.path ),\n\t\t\t\tbelongsTo: null,\n\t\t\t};\n\n\t\t\t/**\n\t\t\t * Because esbuild already reads the existing source maps, there may be\n\t\t\t * cases where some report \"outputs\" include \"inputs\" that don't exist\n\t\t\t * in the main \"inputs\" object. To avoid this, we parse each esbuild\n\t\t\t * input and add its sources to the \"inputs\" object.\n\t\t\t */\n\t\t\taddSourcesToInputs(\n\t\t\t\tresolve( cwd, path ),\n\t\t\t\tacc\n\t\t\t);\n\n\t\t\treturn acc;\n\t\t}, {} as JsonReport[ 'inputs' ] );\n\n\tgenerateReportFromAssets(\n\t\tObject.keys( metafile!.outputs ).map( path => resolve( cwd, path ) ),\n\t\tinputs,\n\t\toptions\n\t);\n}\n"],"mappings":";;;;AAKe,SAAS,mBAAoBA,UAAgC,CAAE,GAAW;AACxF,QAAO;EACN,MAAM;EACN,MAAO,OAAQ;AACd,OAAK,QAAQ,YAAY,MACxB;AAGD,SAAM,eAAe,WAAW;AAGhC,WAAQ,WAAW;AAEnB,SAAM,MAAO,YAAU,uBAAwB,OAAO,UAAW,QAAS,CAAE;EAC5E;CACD;AACD;AAEM,SAAS,uBAAwBC,UAAoBD,SAAsC;CACjG,MAAM,MAAM,QAAQ,KAAK;CACzB,MAAM,SAAS,OACb,QAAS,SAAS,OAAQ,CAC1B,OAAQ,CAAE,KAAK,CAAE,MAAM,KAAM,KAAM;AACnC,MAAK,QAAS;GACb,OAAO,KAAK;GACZ,QAAQ,KAAK,UAAU;GACvB,SAAS,KAAK,QAAQ,IAAK,YAAQE,OAAK,KAAM;GAC9C,WAAW;EACX;;;;;;;AAQD,qBACC,QAAS,KAAK,KAAM,EACpB,IACA;AAED,SAAO;CACP,GAAE,CAAE,EAA4B;AAElC,0BACC,OAAO,KAAM,SAAU,QAAS,CAAC,IAAK,UAAQ,QAAS,KAAK,KAAM,CAAE,EACpE,QACA,QACA;AACD"}
+10
-4
# Changelog
## 0.7.1
### Patch Changes
- e05d444: Add Angular CLI integration
## 0.7.0

@@ -22,6 +28,6 @@

* [Next.js](https://sonda.dev/frameworks/nextjs.html)
* [Nuxt](https://sonda.dev/frameworks/nuxt.html)
* [Astro](https://sonda.dev/frameworks/astro.html)
* [SvelteKit](https://sonda.dev/frameworks/sveltekit.html)
- [Next.js](https://sonda.dev/frameworks/nextjs.html)
- [Nuxt](https://sonda.dev/frameworks/nuxt.html)
- [Astro](https://sonda.dev/frameworks/astro.html)
- [SvelteKit](https://sonda.dev/frameworks/sveltekit.html)

@@ -28,0 +34,0 @@ #### New `enabled` option

@@ -1,39 +0,11 @@

"use strict";
const require_src = require('../src.cjs');
const path = require_src.__toESM(require("path"));
Object.defineProperty(exports, '__esModule', { value: true });
require('../src.cjs');
const require_esbuild = require('../esbuild.cjs');
//#region src/entrypoints/esbuild.ts
function SondaEsbuildPlugin(options = {}) {
return {
name: "sonda",
setup(build) {
if (options.enabled === false) return;
build.initialOptions.metafile = true;
options.detailed = false;
build.onEnd((result) => {
const cwd = process.cwd();
const inputs = Object.entries(result.metafile.inputs).reduce((acc, [path$1, data]) => {
acc[path$1] = {
bytes: data.bytes,
format: data.format ?? "unknown",
imports: data.imports.map((data$1) => data$1.path),
belongsTo: null
};
/**
* Because esbuild already reads the existing source maps, there may be
* cases where some report "outputs" include "inputs" that don't exist
* in the main "inputs" object. To avoid this, we parse each esbuild
* input and add its sources to the "inputs" object.
*/
require_src.addSourcesToInputs((0, path.resolve)(cwd, path$1), acc);
return acc;
}, {});
return require_src.generateReportFromAssets(Object.keys(result.metafile.outputs).map((path$1) => (0, path.resolve)(cwd, path$1)), inputs, options);
});
}
};
}
//#endregion
module.exports = SondaEsbuildPlugin;
//# sourceMappingURL=esbuild.cjs.map
Object.defineProperty(exports, 'default', {
enumerable: true,
get: function () {
return require_esbuild.SondaEsbuildPlugin;
}
});
exports.processEsbuildMetaFile = require_esbuild.processEsbuildMetaFile

@@ -1,3 +0,4 @@

import type { Plugin } from 'esbuild';
import type { Metafile, Plugin } from 'esbuild';
import type { UserOptions } from '../types.js';
export default function SondaEsbuildPlugin(options?: Partial<UserOptions>): Plugin;
export declare function processEsbuildMetaFile(metafile: Metafile, options: Partial<UserOptions>): void;

@@ -1,38 +0,4 @@

import { addSourcesToInputs, generateReportFromAssets } from "../src.mjs";
import { resolve } from "path";
import "../src.mjs";
import { SondaEsbuildPlugin, processEsbuildMetaFile } from "../esbuild.mjs";
//#region src/entrypoints/esbuild.ts
function SondaEsbuildPlugin(options = {}) {
return {
name: "sonda",
setup(build) {
if (options.enabled === false) return;
build.initialOptions.metafile = true;
options.detailed = false;
build.onEnd((result) => {
const cwd = process.cwd();
const inputs = Object.entries(result.metafile.inputs).reduce((acc, [path, data]) => {
acc[path] = {
bytes: data.bytes,
format: data.format ?? "unknown",
imports: data.imports.map((data$1) => data$1.path),
belongsTo: null
};
/**
* Because esbuild already reads the existing source maps, there may be
* cases where some report "outputs" include "inputs" that don't exist
* in the main "inputs" object. To avoid this, we parse each esbuild
* input and add its sources to the "inputs" object.
*/
addSourcesToInputs(resolve(cwd, path), acc);
return acc;
}, {});
return generateReportFromAssets(Object.keys(result.metafile.outputs).map((path) => resolve(cwd, path)), inputs, options);
});
}
};
}
//#endregion
export { SondaEsbuildPlugin as default };
//# sourceMappingURL=esbuild.mjs.map
export { SondaEsbuildPlugin as default, processEsbuildMetaFile };
{
"name": "sonda",
"version": "0.7.0",
"description": "Universal visualizer and analyzer for JavaScript and CSS bundles. Works with Vite, Rollup, webpack, Rspack, and esbuild",
"version": "0.7.1",
"description": "Universal visualizer and analyzer for JavaScript and CSS bundles. Works with most popular bundlers and frameworks.",
"keywords": [
"bundle",
"visualizer",
"analyzer",
"visualizer",
"source-map",
"vite",

@@ -18,3 +17,7 @@ "rollup",

"nuxt",
"astro"
"withastro",
"sveltekit",
"angular",
"performance",
"devtools"
],

@@ -35,2 +38,7 @@ "license": "MIT",

},
"./angular": {
"types": "./dist/entrypoints/angular.d.ts",
"import": "./dist/entrypoints/angular.mjs",
"require": "./dist/entrypoints/angular.cjs"
},
"./astro": {

@@ -89,5 +97,9 @@ "types": "./dist/entrypoints/astro.d.ts",

"files": [
"bin",
"dist",
"CHANGELOG.md"
],
"bin": {
"sonda-angular": "./bin/sonda-angular.js"
},
"dependencies": {

@@ -94,0 +106,0 @@ "@ampproject/remapping": "^2.3.0",

@@ -19,2 +19,3 @@ # Sonda

* SvelteKit
* Angular CLI

@@ -21,0 +22,0 @@ ## Installation

{"version":3,"file":"esbuild.cjs","names":["options: Partial<UserOptions>","path","data"],"sources":["../../src/entrypoints/esbuild.ts"],"sourcesContent":["import { resolve } from 'path';\nimport { generateReportFromAssets, addSourcesToInputs } from '../index.js';\nimport type { Plugin } from 'esbuild';\nimport type { JsonReport, UserOptions } from '../types.js';\n\nexport default function SondaEsbuildPlugin( options: Partial<UserOptions> = {} ): Plugin {\n\treturn {\n\t\tname: 'sonda',\n\t\tsetup( build ) {\n\t\t\tif ( options.enabled === false ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tbuild.initialOptions.metafile = true;\n\n\t\t\t// Esbuild already reads the existing source maps, so there's no need to do it again\n\t\t\toptions.detailed = false;\n\n\t\t\tbuild.onEnd( result => {\n\t\t\t\tconst cwd = process.cwd();\n\t\t\t\tconst inputs = Object\n\t\t\t\t\t.entries( result.metafile!.inputs )\n\t\t\t\t\t.reduce( ( acc, [ path, data ] ) => {\n\t\t\t\t\t\tacc[ path ] = {\n\t\t\t\t\t\t\tbytes: data.bytes,\n\t\t\t\t\t\t\tformat: data.format ?? 'unknown',\n\t\t\t\t\t\t\timports: data.imports.map( data => data.path ),\n\t\t\t\t\t\t\tbelongsTo: null,\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * Because esbuild already reads the existing source maps, there may be\n\t\t\t\t\t\t * cases where some report \"outputs\" include \"inputs\" that don't exist\n\t\t\t\t\t\t * in the main \"inputs\" object. To avoid this, we parse each esbuild\n\t\t\t\t\t\t * input and add its sources to the \"inputs\" object.\n\t\t\t\t\t\t */\n\t\t\t\t\t\taddSourcesToInputs(\n\t\t\t\t\t\t\tresolve( cwd, path ),\n\t\t\t\t\t\t\tacc\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\treturn acc;\n\t\t\t\t\t}, {} as JsonReport[ 'inputs' ] );\n\n\t\t\t\treturn generateReportFromAssets(\n\t\t\t\t\tObject.keys( result.metafile!.outputs ).map( path => resolve( cwd, path ) ),\n\t\t\t\t\tinputs,\n\t\t\t\t\toptions\n\t\t\t\t);\n\t\t\t} );\n\t\t}\n\t};\n}\n"],"mappings":";;;;;AAKe,SAAS,mBAAoBA,UAAgC,CAAE,GAAW;AACxF,QAAO;EACN,MAAM;EACN,MAAO,OAAQ;AACd,OAAK,QAAQ,YAAY,MACxB;AAGD,SAAM,eAAe,WAAW;AAGhC,WAAQ,WAAW;AAEnB,SAAM,MAAO,YAAU;IACtB,MAAM,MAAM,QAAQ,KAAK;IACzB,MAAM,SAAS,OACb,QAAS,OAAO,SAAU,OAAQ,CAClC,OAAQ,CAAE,KAAK,CAAEC,QAAM,KAAM,KAAM;AACnC,SAAKA,UAAS;MACb,OAAO,KAAK;MACZ,QAAQ,KAAK,UAAU;MACvB,SAAS,KAAK,QAAQ,IAAK,YAAQC,OAAK,KAAM;MAC9C,WAAW;KACX;;;;;;;AAQD,oCACC,kBAAS,KAAKD,OAAM,EACpB,IACA;AAED,YAAO;IACP,GAAE,CAAE,EAA4B;AAElC,WAAO,qCACN,OAAO,KAAM,OAAO,SAAU,QAAS,CAAC,IAAK,YAAQ,kBAAS,KAAKA,OAAM,CAAE,EAC3E,QACA,QACA;GACD,EAAE;EACH;CACD;AACD"}
{"version":3,"file":"esbuild.mjs","names":["options: Partial<UserOptions>","data"],"sources":["../../src/entrypoints/esbuild.ts"],"sourcesContent":["import { resolve } from 'path';\nimport { generateReportFromAssets, addSourcesToInputs } from '../index.js';\nimport type { Plugin } from 'esbuild';\nimport type { JsonReport, UserOptions } from '../types.js';\n\nexport default function SondaEsbuildPlugin( options: Partial<UserOptions> = {} ): Plugin {\n\treturn {\n\t\tname: 'sonda',\n\t\tsetup( build ) {\n\t\t\tif ( options.enabled === false ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tbuild.initialOptions.metafile = true;\n\n\t\t\t// Esbuild already reads the existing source maps, so there's no need to do it again\n\t\t\toptions.detailed = false;\n\n\t\t\tbuild.onEnd( result => {\n\t\t\t\tconst cwd = process.cwd();\n\t\t\t\tconst inputs = Object\n\t\t\t\t\t.entries( result.metafile!.inputs )\n\t\t\t\t\t.reduce( ( acc, [ path, data ] ) => {\n\t\t\t\t\t\tacc[ path ] = {\n\t\t\t\t\t\t\tbytes: data.bytes,\n\t\t\t\t\t\t\tformat: data.format ?? 'unknown',\n\t\t\t\t\t\t\timports: data.imports.map( data => data.path ),\n\t\t\t\t\t\t\tbelongsTo: null,\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * Because esbuild already reads the existing source maps, there may be\n\t\t\t\t\t\t * cases where some report \"outputs\" include \"inputs\" that don't exist\n\t\t\t\t\t\t * in the main \"inputs\" object. To avoid this, we parse each esbuild\n\t\t\t\t\t\t * input and add its sources to the \"inputs\" object.\n\t\t\t\t\t\t */\n\t\t\t\t\t\taddSourcesToInputs(\n\t\t\t\t\t\t\tresolve( cwd, path ),\n\t\t\t\t\t\t\tacc\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\treturn acc;\n\t\t\t\t\t}, {} as JsonReport[ 'inputs' ] );\n\n\t\t\t\treturn generateReportFromAssets(\n\t\t\t\t\tObject.keys( result.metafile!.outputs ).map( path => resolve( cwd, path ) ),\n\t\t\t\t\tinputs,\n\t\t\t\t\toptions\n\t\t\t\t);\n\t\t\t} );\n\t\t}\n\t};\n}\n"],"mappings":";;;;AAKe,SAAS,mBAAoBA,UAAgC,CAAE,GAAW;AACxF,QAAO;EACN,MAAM;EACN,MAAO,OAAQ;AACd,OAAK,QAAQ,YAAY,MACxB;AAGD,SAAM,eAAe,WAAW;AAGhC,WAAQ,WAAW;AAEnB,SAAM,MAAO,YAAU;IACtB,MAAM,MAAM,QAAQ,KAAK;IACzB,MAAM,SAAS,OACb,QAAS,OAAO,SAAU,OAAQ,CAClC,OAAQ,CAAE,KAAK,CAAE,MAAM,KAAM,KAAM;AACnC,SAAK,QAAS;MACb,OAAO,KAAK;MACZ,QAAQ,KAAK,UAAU;MACvB,SAAS,KAAK,QAAQ,IAAK,YAAQC,OAAK,KAAM;MAC9C,WAAW;KACX;;;;;;;AAQD,wBACC,QAAS,KAAK,KAAM,EACpB,IACA;AAED,YAAO;IACP,GAAE,CAAE,EAA4B;AAElC,WAAO,yBACN,OAAO,KAAM,OAAO,SAAU,QAAS,CAAC,IAAK,UAAQ,QAAS,KAAK,KAAM,CAAE,EAC3E,QACA,QACA;GACD,EAAE;EACH;CACD;AACD"}