Code Monkey home page Code Monkey logo

import-cost's Introduction

Import Cost Build Status Stand With Ukraine

This extension will display inline in the editor the size of the imported package. The extension utilizes webpack in order to detect the imported size.

Example Image

This project includes implementation of:

Enjoy!

Third-Party Editor Plugin Links

Why & How

We detail the why and how in this blog post: https://citw.dev/posts/import-cost

Developer guidelines

In this project we use npm workspaces for managing the multiple packages.

Getting started

In order to start working all you need to do is:

$ git clone [email protected]:wix/import-cost.git
$ npm install
$ code packages/import-cost
$ code packages/vscode-import-cost

Once VSCode workspaces are open:

  • Hit F5 to run tests in import-cost
  • Hit F5 to run the vscode-import-cost extension in debug mode

Applying changes

Thanks to npm workspaces, we have a symbolic link in the vscode-import-cost node modules folder to the local import-cost, which makes applying changes very easy. You can verify that link exists by running the following command:

$ ls -la packages/vscode-import-cost/node_modules | grep import-cost
lrwxr-xr-x    1 shahar  staff    17 Aug  6 09:38 import-cost -> ../../import-cost

If anything goes wrong and link does not exist, just run the following commands at the root of this project and npm will sort it out:

$ git clean -xdf
$ npm install

After you make any changes to the import-cost node module, don't forget to trigger transpilation in order to see those changes when running the vscode-import-cost extension:

$ npm test

Publishing changes

When you are ready to publish a new version of the extension, you first need to publish a new version of import-cost (unless nothing changed there). This is done by first commiting all your changes, then simply run the following commands:

$ cd packages/import-cost
$ npm version patch | minor | major
$ git commit -a -m "releasing version X.X.X"
$ git push
$ npm publish

Then go ahead and release the extension with almost same steps (except for last one):

$ cd packages/vscode-import-cost
$ npm version patch | minor | major
$ git commit -a -m "releasing version X.X.X"
$ git push
$ vsce publish

Don't forget to update README.md with details of what is new in the released version...

import-cost's People

Contributors

alexkrolick avatar denysdovhan avatar dependabot[bot] avatar giladartzi avatar hiramhuang avatar ipatalas avatar jakehedman avatar jamiebuilds avatar leeor avatar ranyitz avatar shahata avatar sthuck avatar tbremer avatar tomashubelbauer avatar yairhaimo avatar yardnsm avatar yazshel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

import-cost's Issues

Brotli Sizes

You have Gzip'd size; add Brotli to increase awareness that it's out in modern browsers, compresses better than gzip, and should be used more often.

doesn't properly calculate de-structuring

take lodash for instance:

screen shot 2017-08-10 at 9 12 27 am

70.4K just pulled in raw.

Now if I attempt the de-structuring syntax I should see the combined size of the de-structured methods. As you can see, it actually reports slightly larger.

screen shot 2017-08-10 at 9 13 05 am

Breaking them apart individually works fine.

screen shot 2017-08-10 at 9 11 49 am

The calculation shown for a de-structured lib should maybe just show the combined size of the individual pieces used? I think that would be safe since the best case for using that syntax is to cherry-pick what's included in the build during a tree-shaking process.

Setting to exclude files or directories

When I open a webpack config file (such a build/webpack.base.conf.js from a VueJS template), the plugin generates a high CPU load but I don't care about the results because these files won't present in my app bundle.

Is it possible to add a setting to exclude some files or directories based on regex?

Stuck at 'Calculating...'

After installing the plugin, I opened a .js file with a single import. I see Calculating... appear but it never actually resolves to anything. I realize this isn't much information to go on so let me know how I can help to further investigate.

image

Cannot find Module when calculating cost of material-ui package

Any ideas on why this is happening?

[Extension Host] debugger inspector at %cmodule.js:472
    throw err;
    ^

Error: Cannot find module 'f:\Programing\react-components\node_modules\material-ui\FlatButt%con\package.json'
    at Function.Module._resolveFilename (module.js:470:15)
    at Function.Module._load (module.js:418:25)
    at Module.require (module.js:498:17)
    at require (internal/%cmodule.js:20:19)
    at calcSize (C:\Users\Work\.vscode\extensions\wix.vscode-import-cost-2.6.0\node%c_modules\import-cost\dist\src\webpack.js:34:21)
    at handle (C:\Users\Work\.vscode\extensions\wix.vscode-import-cost-2.6.0\node_modules\worker-farm\lib\child\index.js:44:8)
    at process.<anonymous> (C:\Users\Work\.vscode\extensions\wix.vscode-import-cost-2.6.0\node_modules\worker-farm\lib\child\index.js:51:3)
    at emitTwo (events.js:106:13)
    at process.emit (events.js:194:7)
    at process.nextTick (%cinternal/child_process.js:766:12)
[Extension Host] debugger inspector at %cmodule.js:472
    throw err;
    ^

Error: Cannot find module 'f:\Programing\react-components\node_modules\material-ui\TextField\package.json'
    at Function.Module._resolveFilename (modul%ce.js:470:15)
    at Function.Module._load (module.js:418:25)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at calcSize (C:\Users\Work\.vscode\extensions\wix.vscode-import-cost-2.6.0\node_modules\i%cmport-cost\dist\src\webpack.js:34:21)
    at handle (C:\Users\Work\.vscode\extensions\wix.vscode-import-cost-2.6.0\node_mo%cdules\worker-farm\lib\child\index.js:44:8)
    at process.<anonymous> (C:\Users\Work\.vscode\extensions\wix.vscode-%cimport-cost-2.6.0\node_modules\worker-farm\lib\child\index.js:51:3)
    at emitTwo (events.js:106:13)
    at%c process.emit (events.js:194:7)
    at process.nextTick (internal/child_process.js:766:12)

Plugin is not doing/showing anything

I'm not sure if we are supposed to have specific dependencies installed or if I am doing something wrong, but I am not seeing anything happen when importing modules.

Example:

screen shot 2017-08-03 at 8 37 14 am

Exclude peerDependencies

Hi there - I noticed the import cost reported for preact-router is 5.1kb, which means it must be including the weight of preact itself in calculations (since preact-router is 2.0kb, preact is 3.3kb). Any thoughts around omitting imports of dependencies only specified as peerDependencies when performing a calculation? Seems like it could be accomplished by using peerDependencies to populate Webpack's externals config option.

Make annotations togglable

Hello,

I really like this package, only thing that is missing for me is the functionality that would allow me to quickly toggle the annotations on/off with a keybind. Is there any way this can be done already through vscode?

Startup Activation Too Long

  • Extension Name: vscode-import-cost
  • Extension Version: 2.5.1
  • OS Version: Darwin x64 17.2.0
  • VSCode version: 1.20.0-insider
{
	"activationTimes": {
		"startup": true,
		"codeLoadingTime": 4998,
		"activateCallTime": 1,
		"activateResolvedTime": 0,
		"activationEvent": "*"
	}
}

Memory leak

From @maxibanki on October 31, 2017 0:13

  • VSCode Version: Code - Insiders 1.18.0-insider (8deed535e26bc8ceebf83a9aa631580ebd610918, 2017-10-30T05:21:47.015Z)
  • OS Version: Windows_NT x64 6.1.7601
  • Extensions:
Extension Author (truncated) Version
markdown-checkbox bie 0.0.3
jshint dba 0.10.15
vscode-eslint dba 1.4.0
githistory don 0.2.3
xml Dot 1.9.2
gitlens eam 5.7.1
tslint eg2 1.0.14
vscode-abap lar 0.1.0
Go luk 0.6.66
postscript max 1.0.0
code-beautifier mic 1.7.2
debugger-for-chrome msj 3.4.0
vetur oct 0.10.1
vscode-docker Pet 0.0.20
vscode-icons rob 7.17.0
vscode-table-formatter shu 1.2.1
vscode-hexdump sle 1.6.0
addDocComments ste 0.0.8
html-preview-vscode tht 0.1.1
vscode-import-cost wix 2.5.1

(1 theme extensions excluded)


Steps to Reproduce: (not reproduceable)

  1. Open Vetur settings
  2. Click on contributions

Reproduces without extensions: Yes/No

Processes:
procexp64_2017-10-31_00-36-29
Command line:
"C:\Programme\VSCodeInsider\Code - Insiders.exe" C:\Users\mxs\.vscode-insiders\extensions\wix.vscode-import-cost-2.5.1\node_modules\worker-farm\lib\child\index.js "C:\Programme\VSCodeInsider\Code - Insiders.exe" c:\Programme\VSCodeInsider\resources\app\out\bootstrap --type=extensionHost
Process Explorer Performance Tab:
procexp64_2017-10-31_00-42-11

Hi,

I'm not so familiar with the process structure of VS Code, but in the command line arguments of the process which used so much RAM, there is the extension wix.vscode-import-cost-2.5.1 loading. Could this process used only for this extension, so that this is the cause of the high memory usage?

I tried to run the Dev Tools Performance Profiler, but it never finished, because of the always 100% usage of my memory in my notebook I think.

Best regards

Copied from original issue: microsoft/vscode#37192

The plugin starts creating temporary files in %temp% folder as soon as we enable it (creates average one file every second)

This is critical as at the end of the day, %temp% folder is having millions of unnecessary files with this plugin. It creates average one file every second.

  • Extension Name: vscode-import-cost
  • Extension Version: 2.5.1
  • OS Version: Windows 7 Enterprise Service Pack 1
  • VS Code:
    • Version: 1.19.1
    • Commit: 0759f77bb8d86658bc935a10a64f6182c5a1eeba
    • Date 2017-12-19T09:46:23.884Z
    • Shell 1.7.9
    • Renderer 58.0.3029.110
    • Node 7.9.0
    • Architecture x64

Reproduces without extensions: No

Initially I though it's an issue of VSCode. As soon as I start VSCode with an angular project, it started creating temp files having name like tmp-1468JkmT3B90uBgn.tmp in %temp% folder averaging 1 file/second.
After an hour, my '%temp%' was having more than 3500-4000 such files.

However, as soon as I disabled the plugin and started VSCode, no more files were created.

The files were having the content as below in each file..

import { Http, Response, Headers, RequestOptions } from '@angular/http'; console.log({ Http, Response, Headers, RequestOptions });
import { Observable } from 'rxjs/Observable'; console.log({ Observable });
import { AsyncSubject } from 'rxjs/AsyncSubject'; console.log({ AsyncSubject });

tmp-148402MhkXH8vCGgS.tmp.txt
tmp-1468JkmT3B90uBgn.tmp.txt

Tree shaking not calculating correctly when selectively importing

I've been moving to a different date library for my app and noticed that the calculated values don't seem to be right:
screen shot 2017-08-24 at 1 27 21 pm

I would expect these calculations to be equal. Can someone explain if I'm doing something wrong or why they shouldn't be the same?

Thanks! ๐Ÿ˜„

Better compability with gitlens

Hi,

I use the gitlens from @eamodio together with import-cost. Thank you both for these great plugins.

It would be nice, if import-cost could be more compatible to gitlens. This could be done quite easily with an optional setting, I think: disable import-cost on currently selected line. Normally gitlens shows you the $ git blame information for the current line. But together with import-cost I can't see this information - and the information from import-cost just becomes gray.

image

I personally would be fine to see

  • import-cost information if the line is not selected
  • gitlens information if the line is selected

Maybe we can just add a "importCost.hideOnCurrentLine" setting which is false by default?

[Feature Request] DRY it up

I'd love to see these messages on the package.json level and not on on every .js file. Could that be a possible setting?

For people like us on React Native it's extra important to consider the costs of modules we include. I think the benefit is saving these import costs from ever happening by never bringing in the code at all for modules that can't pull their weight.

Rationally, it might be an easy feature to switch all that calculating to the source in package.json.

Mechanism for calculation

Hi, I tried to see how you calculate the size but it seems that you depend on some webpack functionality.

i'm a bit puzzeled, as it shows some HUGE size for packages that I developed. For React and others all seems ok, but my package show 958KB! The source files in my package have only 126KB unminified. Where is the huge size coming from? Does this also include dependencies?

[EDIT] Package has no dependencies

If you want to try, the package is "apollo-authentication-semantic-ui"

Vue.js Support

There seems to be an issue with vue files

If you need an application, you can use any of this samples from here:

If you just need a sample file which does not work, here is one:

<template>
  <section class='row'>
    <div>Bridge</div>
  </section>
</template>

<script>
  import socket from '~plugins/socket.io.js'

  export default {
    mounted(){
     this.test()
    },
    data() {
      return {
        serverUrl: '127.0.0.1'
      }
    },
    methods: {
      test() {
        const connection = {serverURL: this.serverUrl};
      }
    }
  }
</script>

Allow to specify opacity for colors

Hi! Thanks for this awesome extension.

I would have a small request concerning colors. For now I find them quite vivid and would like a more subtle version. I could do it manually but then those colors would be dependant on my editor background. And it's quite annoying to do.

Several solutions for this:

  1. Add importCost.opacity: Accepting a value from 0 to 1, it would fade all the defined colors.
  2. Allow importCost.*PackageColor to be specified as RGBA: #7cc36e0a.
  3. Add importCost.*PackageOpacity so we can defined a different opacity for each color.

I think solution 1. is the simpler and make sure we have some consistency between all colors. But some users might want to keep small and medium package subtle and shout large package. So it's your call :)

I can provide a PR if you agree and choose one of those proposals.

Thanks!

Release without changelog updates

Hey, I think this latest release and the previous one lacked changelog update (at least as of the time of release). That's a real shame, I love reading what I am updating for each time I update my extensions, so please consider adding that to some sort of a release checklist. Thank you!

Incorrect (3x larger) measurements for libraries with a DEV mode

Hi ๐Ÿ‘‹

It looks like the plugin doesn't envify the bundle before computing the size. As a result, it is impossible for a library to provide "development mode" and benefit from dead code elimination in production mode without making it seem artificially larger. Even worse, providing flat bundles which in practice results in better performance and minification actually penalizes the library further because now both development and production copies are counted.

Quite a few libraries in the React ecosystem rely on this, including React and Redux themselves. This contributes to a trend of penalizing libraries that provide a development mode, which creates incentives for library developers to not provide it, hurting the library usability across the board.

In case of React the difference between the real and the reported size is especially staggering:

screen shot 2017-12-23 at 21 42 25

So it looks like import-cost is reporting the size as 3x larger than it would be in practice. You can verify it with tools like jsize or http://bundlephobia.com that have a correct algorithm.

There are two things that could be done to fix the measurements:

  • Envifying process.env.NODE_ENV to "production" with DefinePlugin.
  • peerDependencies need to be excluded from library's own measurements (#29).

For the first part, this should be enough. For the second part, here is an example of how to calculate externals from peerDependencies.

Please let me know if you have any concerns or questions, and I'd be very happy to answer them! Thanks for consideration.

Feature: color-code small/medium/large imports?

Would be nice if import sizes were colour coded (maybe configurable?)

I'm not 100% sure what webpack uses nowadays for determining what large imports are, but I'm sure we can come up with some sane numbers?

Just a though, love the plugin!

Kitsu has no import size calculated

Package: kitsu
Version: 1.3.0
VSC: 1.14.2

ES6 and CommonJS imports result in no size being displayed after calculating

import Kitsu from 'kitsu'
const Kitsu = require('kitsu')

html script tags

could the plugin also measure/report the size of javascript beeing loaded when linked inside html via <script> tag?

Can't install

I'm getting the following when I try to install the extension:

image

Installing other extensions seems fine. I don't know where to find the folder in the message to check permissions either.

Any suggestions?

Importing function from lodash causes to hang and spin up fans

Extension Name: vscode-import-cost
Extension Version: 2.6.0
OS Version: macOS 10.13.2
VS Code:

  • Version: 1.19.2
  • Commit: 490ef761b76b3f3b3832eff7a588aac891e5fe80
  • Date 2018-01-10T15:44:43.400Z
  • Node 9.1.0

Reproduces without extensions: No

Importing from a lodash single function hangs the calculation and makes the fans spin up hugely on my rMBP. Quitting and restarting VSCode does not resolve it.

screenshot 2018-01-11 14 52 25

Ubunto CPU high use

When the extension is enabled, the CPU is running extremely high. (80% - 100%).

OS: Ubuntu 16.04

Visual design tweaks

I worked on a few design tweaks over the weekend. It would be great if you folks could share some feedback! Thanks!

Dark theme
Dark theme

Light theme
vscode-light

  • I've used this emoji for the icon: ๐Ÿ“ฆ
  • We could use it with the CSS content rule. E.g. content: "๐Ÿ“ฆ 44.5K (gzipped: 13.8K)";

does not account for elided typescript type imports

When you import a typescript type from a module, and nothing else from that module is used anywhere in an expression, typescript omits the module's code, and just imports the type, meaning the import cost of importing the type is not the cost of importing the entire module.

For example:

import { IComponentOptions } from 'angular'; // 168.3K

However, the import cost is really practically nothing.

This gave me a bit of a heart attack when I first installed the extension, until I figured this out. Any way to account for this?

Cannot calculate when "import patching" is used.

No result for this:

import { Http, RequestOptions, URLSearchParams } from "@angular/http";
import "rxjs/add/operator/map";
import "rxjs/add/operator/first";
import "rxjs/add/operator/toPromise";
import "rxjs/add/operator/mergeMap";
import * as moment from "moment";
import { Storage } from "@ionic/storage";
import { Firebase } from "@ionic-native/firebase";
import * as URI from "urijs";

if I delete these lines:

import "rxjs/add/operator/map";
import "rxjs/add/operator/first";
import "rxjs/add/operator/toPromise";
import "rxjs/add/operator/mergeMap";

Everything works again.

Add support for babel-plugin-lodash to map package names

Great idea and plugin!

We use https://github.com/lodash/babel-plugin-lodash to map local names to sub-paths. I figure it would make sense when this plugin is configurable to support the plugin. Right now a lot of libraries work in the same schema like recompose or even frameworks like react-toolbox.

See also our babel config:
https://github.com/sebastian-software/babel-preset-edge/blob/master/src/index.js#L73

Alternatively... probably it would be also a good idea to just use the project's babel configuration in your webpack run.

Doesn't resolve packages higher in a tree?

In our projects we have multiple package.json files and node_modules directories down the tree.

If I open a file that imports a package from a tree higher up, it won't resolve the package at all.

An example:

project
 |- node_modules/ (contains axios)
 |- package.json (contains axios)
 |- sub_dir/
   |- node_modules/ (does not contain axios)
   |- package.json (does not contain axios)
   |- API.js (imports axios)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.