Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

closure-calculate-chunks

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

closure-calculate-chunks - npm Package Compare versions

Comparing version 3.0.1 to 3.0.2

14

cli.js

@@ -65,2 +65,7 @@ #!/usr/bin/env node

})
.option('name-prefix', {
describe: 'Prefix string prepended to each chunk name',
default: '',
type: 'string'
})
.strict()

@@ -164,3 +169,3 @@ .help()

if (flags.visualize) {
generateHtml(chunkGraph, namingStyle)
generateHtml(chunkGraph, flags.namePrefix, namingStyle)
.then((html) => new Promise((resolve, reject) => {

@@ -188,3 +193,8 @@ const tempFile = temp.path({ prefix: 'closure-calculate-chunks-', suffix: '.html' });

try {
process.stdout.write(JSON.stringify(chunkGraph.getClosureCompilerFlags(namingStyle), null, 2) + '\n');
process.stdout.write(
JSON.stringify(
chunkGraph.getClosureCompilerFlags(flags.namePrefix, namingStyle),
null,
2) +
'\n');
} catch (e) {

@@ -191,0 +201,0 @@ process.stderr.write(`Error: ${e.message}\n`);

14

lib/chunk-graph.js

@@ -106,6 +106,7 @@ import graphlib from 'graphlib';

*
* @param {string=} namePrefix
* @param {!NAMING_STYLE=} namingStyle
* @return {{sources: !Array<string>, chunk: !Array<string>}}
*/
getClosureCompilerFlags(namingStyle = NAMING_STYLE.ENTRYPOINT) {
getClosureCompilerFlags(namePrefix = '', namingStyle = NAMING_STYLE.ENTRYPOINT) {
const closureGraph = this.toDependencyGraph();

@@ -131,3 +132,3 @@ const cycles = graphlib.alg.findCycles(closureGraph);

let sourceCount = 0;
const getOutputChunkName = outputChunkNaming(this.entrypoint, namingStyle);
const getOutputChunkName = outputChunkNaming(this.entrypoint, namePrefix, namingStyle);
while(sortedChunks.length > 0) {

@@ -155,4 +156,7 @@ let {length} = sortedChunks;

visitedChunks.add(chunkName);
const chunkParents = parents.length === 0 ? '' : `:${parents.map(getOutputChunkName).join(',')}`;
chunks.push(`${getOutputChunkName(chunkName)}:${chunk.sources.size}${chunkParents}`);
const chunkDefParts = [getOutputChunkName(chunkName), chunk.sources.size];
if (parents.length > 0) {
chunkDefParts.push(parents.map(getOutputChunkName).join(','));
}
chunks.push(chunkDefParts.join(':'));
sources.push(...chunk.sources);

@@ -182,3 +186,3 @@ sortedChunks.splice(i, 1);

* The first entry is the primary entrypoint.
* @param {!Array<{parent: string, child: {name: string, files: !Array<string>}}>} manualEntrypoints additional files to be manually added.
* @param {!Array<{parent: string, child: {name: string, files: !Array<string>}}>=} manualEntrypoints additional files to be manually added.
* @param {!Array<string>=} packageJsonEntryNames prefence order of fields to look for in package.json files for the main file

@@ -185,0 +189,0 @@ * @param {string=} baseDirectory root directory of application

@@ -11,8 +11,10 @@ import path from 'path';

* @param {string} entrypoint
* @param {string=} namePrefix
* @param {!NAMING_STYLE=} namingStyle
* @return {function(string): string}
*/
export const outputChunkNaming = (entrypoint, namingStyle = NAMING_STYLE.ENTRYPOINT) => {
export const outputChunkNaming = (entrypoint, namePrefix = '', namingStyle = NAMING_STYLE.ENTRYPOINT) => {
let chunkNameIndex = 0;
let outputChunkNames = new Map();
const outputChunkNames = new Map();
const usedNames = new Set();
return (chunkName) => {

@@ -22,8 +24,15 @@ if (!outputChunkNames.has(chunkName)) {

if (chunkName === entrypoint) {
outputChunkNames.set(chunkName, 'main.js');
outputChunkNames.set(chunkName, `${namePrefix}main`);
} else {
outputChunkNames.set(chunkName, `${chunkNameIndex++}.js`);
outputChunkNames.set(chunkName, `${namePrefix}${chunkNameIndex++}`);
}
} else {
outputChunkNames.set(chunkName, path.relative(process.cwd(), chunkName));
let outputChunkName = namePrefix + path.basename(chunkName, path.extname(chunkName));
let proposedName = outputChunkName;
for (let suffix = 1; usedNames.has(proposedName); suffix++) {
proposedName = outputChunkName + suffix;
}
outputChunkName = proposedName;
usedNames.add(outputChunkName);
outputChunkNames.set(chunkName, outputChunkName);
}

@@ -30,0 +39,0 @@ }

@@ -98,7 +98,8 @@ import fs from 'fs';

* @param {!ChunkGraph} chunkGraph
* @param {string=} namePrefix
* @param {!NAMING_STYLE=} namingStyle
* @return {!Promise<string>}
*/
export default async function generateHtml(chunkGraph, namingStyle = NAMING_STYLE.ENTRYPOINT) {
const getOutputChunkName = outputChunkNaming(chunkGraph.entrypoint, namingStyle);
export default async function generateHtml(chunkGraph, namePrefix, namingStyle = NAMING_STYLE.ENTRYPOINT) {
const getOutputChunkName = outputChunkNaming(chunkGraph.entrypoint, namePrefix, namingStyle);
const replacements = {

@@ -105,0 +106,0 @@ 'entrypoint': getOutputChunkName(chunkGraph.entrypoint),

{
"name": "closure-calculate-chunks",
"version": "3.0.1",
"version": "3.0.2",
"description": "Analyze dependencies from entry points and split code for closure-compiler",

@@ -5,0 +5,0 @@ "bin": {

@@ -47,2 +47,5 @@ # closure-calculate-chunks

**--name-prefix prefix**
Prefix string prepended to each chunk name.
## Output

@@ -49,0 +52,0 @@ Outputs a JSON object with closure-compiler chunk definitions and source files in dependency order.

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