diff --git a/README.md b/README.md index b9caded..290eefc 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Usage ## install ``` -npm install --save-dev lasso-unpack +npm install -g lasso-unpack lasso-unpack ```` @@ -23,7 +23,7 @@ parseBundle('lib/build.js'); ## Output -Output a `lasso-stats.json` file to the parent directory. +Output a `lasso-stats.json` file to the parent directory, you can check all the files and their sizes bundled by Lasso. The lasso-stats.json will look like this : @@ -43,9 +43,13 @@ The lasso-stats.json will look like this : input and output example files provided here https://github.com/ajay2507/lasso-unpack/tree/master/examples +## Issues +If you are facing any issues or have any improvements, you can create issue here +https://github.com/ajay2507/lasso-unpack/issues + ## Problem -Developer should know what presents inside bundle created by Lasso. It should not be a black box. lasso-unpack solves this problem, it unpacks the bundle and shows all the files present in the bundle. It includes content and size of js file. +Developer should know what presents inside bundle created by Lasso. It should not be a black box. lasso-unpack solves this problem, it unpacks the bundle and shows all the files present in the bundle. It includes content and size of js. file. License ======== diff --git a/lib/lasso-unpack.js b/lib/lasso-unpack.js index ef7c4f1..6316752 100644 --- a/lib/lasso-unpack.js +++ b/lib/lasso-unpack.js @@ -13,14 +13,16 @@ const isValidFunctionExpression = require('./utils').isValidFunctionExpression; const isFunctionExpression = require('./utils').isFunctionExpression; function parseLassoBundle(fileName) { - console.log("Input path provided => " + path.resolve(fileName)); const fileContent = fs.readFileSync(path.resolve(fileName), 'utf8'); const ast = acorn.parse(fileContent, { sourceType: 'script' }); - + let initial = new Stats(); const walkState = []; - if (ast.body.length === 0) return "Empty File" + if (ast.body.length === 0) return "Empty File"; + // get total bundle size. + isProgram(ast, walkState, initial); + // iterate the AST tree. walk.recursive( ast, walkState, @@ -76,6 +78,15 @@ function extractLiterals(stats, args) { } } +function isProgram(ast, walkState, initial) { + if (ast.type === "Program") { + initial.setPackageName('BundleSize'); + initial.setFileName('program'); + initial.setSize(ast.end - ast.start); + walkState.push(initial); + } +} + function extractContent(fileContent, stats, node) { if (isValidFunctionExpression(node)) { let body = node.body; diff --git a/package.json b/package.json index 9390f5d..a99955d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lasso-unpack", - "version": "1.0.0", + "version": "1.0.1", "description": "unpack bundle - Generate stats json from lasso bundle", "main": "lib/lasso-unpack.js", "bin": {