Socket
Book a DemoInstallSign in
Socket

@hyrious/import-cost

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hyrious/import-cost

Get package size of import statements, powered by esbuild

latest
Source
npmnpm
Version
0.1.6
Version published
Weekly downloads
2
100%
Maintainers
1
Weekly downloads
 
Created
Source

@hyrious/import-cost

Get imported code size of a package.

This package is heavily inspired by import-cost.

Usage

CLI

> npx @hyrious/import-cost file.ts

Package   Cost     Where
lodash    70 kiB   file.ts:2

API

importCost(path, code, options?)

import { importCost } from '@hyrious/import-cost'

const result = await importCost('file.ts', `
  import { uniqueId } from 'lodash'
`)
// => { errors: [], warnings: [], packages: [
//   { path: 'file.ts', name: 'lodash', line: 2, size: 70000, gzip: 70000 }
// ] }
  • path {String} The path to the file, this is used for looking up the node_modules folder.
  • code {String} The contents of the file.
  • options {Object}
    • lang {String} Override the language infered from file extension. Available values: js, ts, jsx, tsx, vue, svelte.
    • external {String[]} Override packages to be excluded from the bundle. By default, all peer dependencies scanned from the package.json indicated by path will be excluded.
  • Returns: {Promise⟨Object⟩}
    • errors, warnings {Object[]} Passed through from esbuild.
    • packages {Object[]}
      • path {String} The path to the file, same as the input argument.
      • name {String} The name of the analyzed package.
      • line {Number} The line number of the import statement.
      • size {Number} The size of the package in bytes.
      • gzip {Number} The size of the package in bytes after gzip.
      • fail {Boolean} true if failed to bundle the package with esbuild.

cache

import { cache } from '@hyrious/import-cost'

cache.clear()

License

MIT @ hyrious

Keywords

import

FAQs

Package last updated on 23 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts