ambar / vscode-bundle-size

Display the bundle size of npm packages: https://marketplace.visualstudio.com/items?itemName=ambar.bundle-size
35 stars 1 forks source link

FR: Support Bare Module Specifier Resolution #7

Closed elijaholmos closed 2 years ago

elijaholmos commented 2 years ago

many nodejs projects leverage Bare Module Specifier (https://github.com/jkrems/proposal-pkg-exports) to specify custom package imports/exports in the package.json. for example, see firebase-admin sdk or even a smaller package like set-interval-async.

the package.json for these modules will typically be structured like so:

"exports": {
    ".": {
      "types": "./dist/dynamic/set-interval-async.d.cts",
      "require": "./dist/dynamic/set-interval-async.cjs",
      "import": "./dist/dynamic/set-interval-async.mjs"
    },
    "./dynamic": {
      "types": "./dist/dynamic/set-interval-async.d.cts",
      "require": "./dist/dynamic/set-interval-async.cjs",
      "import": "./dist/dynamic/set-interval-async.mjs"
    },
    "./fixed": {
      "types": "./dist/fixed/set-interval-async.d.cts",
      "require": "./dist/fixed/set-interval-async.cjs",
      "import": "./dist/fixed/set-interval-async.mjs"
    }
  }

notice how ./package.json is not included.

currently, the extension errors when attempting to resolve the bundle size of these modules, with an error like so:

2022-10-20T00:57:51.490Z extension exception set-interval-async/fixed [Error: Package subpath './package.json' is not defined by "exports" in c:\<path>\node_modules\set-interval-async\package.json]

My feature request is to support the bare module specifier syntax as described above.

ambar commented 2 years ago

@elijaholmos Released in v1.5.0, should work now:

image
elijaholmos commented 2 years ago

thanks for the quick response, @ambar! the extension works much better: image

image

only problem I see now is in the above screenshot with firebase-admin/database. here's the extension output for my file: image

not sure if this is a problem with my machine, the firebase-admin package, or something else πŸ˜… I don't mind one package not working, though- everything else has worked greatly!

ambar commented 2 years ago

@elijaholmos Thanks for the feedback, I'll look at that question when I have time.

elijaholmos commented 2 years ago

@ambar No rush. enjoy the rest of your day

ambar commented 2 years ago

It seems firebase-admin is a package that only supports node, not browser (which is the default of the Bundle Size plugin), at least in current version of esbuild (maybe a compatibility issue of exports field).


# ok
echo "import { getDatabase } from 'firebase-admin/database'" | yarn esbuild --bundle --platform=node --minify > bundle.js

# fail
echo "import { getDatabase } from 'firebase-admin/database'" | yarn esbuild --bundle --platform=browser --minify > bundle.js

✘ [ERROR] Could not resolve "@firebase/database-compat/standalone"

    node_modules/firebase-admin/lib/database/index.js:20:29:
      20 β”‚ const standalone_1 = require("@firebase/database-compat/standalone");
         β•΅                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  The path "./standalone" is not currently exported by package "@firebase/database-compat":

    node_modules/@firebase/database-compat/package.json:16:13:
      16 β”‚   "exports": {
         β•΅              ^

  None of the conditions provided ("types", "node") match any of the currently active conditions
  ("browser", "default", "require"):

    node_modules/@firebase/database-compat/package.json:27:20:
      27 β”‚     "./standalone": {
elijaholmos commented 2 years ago

I see, so it looks like it's an issue on the package level. thank you for looking into it!