danvk / source-map-explorer

Analyze and debug space usage through source maps
Apache License 2.0
3.83k stars 101 forks source link

Glob not working when not matching _exactly_ two files (and error message is misleading) #79

Closed arve0 closed 5 years ago

arve0 commented 5 years ago

No response on comment yet, so opening an issue.

Has anything changed in 1.6.0? Cannot get globs to work:

C:\Temp\sme>npm i -g source-map-explorer
C:\Users\_\AppData\Roaming\npm\source-map-explorer -> C:\Users\_\AppDa
ta\Roaming\npm\node_modules\source-map-explorer\index.js
+ source-map-explorer@1.6.0
updated 1 package in 0.957s

C:\Temp\sme>source-map-explorer --version
1.6.0

C:\Temp\sme>source-map-explorer main.*
File not found! --  ENOENT: no such file or directory, open 'main.*'

C:\Temp\sme>dir main.*
 Volumet i stasjon C er OSDisk
 Volumserienummeret er F65B-C808

 Innhold i C:\Temp\sme

11.01.2019  08:36             2 146 main.js
               1 fil(er)            2 146 byte
               0 mappe(r)   9 305 964 544 byte ledig

C:\Temp\sme>
arve0 commented 5 years ago

I get same results in 1.4.0 and 1.5.0:

C:\Temp\sme>source-map-explorer --version
1.5.0

C:\Temp\sme>source-map-explorer main.*
File not found! --  ENOENT: no such file or directory, open 'main.*'

C:\Temp\sme>source-map-explorer --version
1.4.0

C:\Temp\sme>source-map-explorer main.*
File not found! --  ENOENT: no such file or directory, open 'main.*'

For reference, glob was originally verified in https://github.com/facebook/create-react-app/issues/2717

arve0 commented 5 years ago

After debugging, I see that glob is only working when it also matches .map file. For example:

Code: https://github.com/danvk/source-map-explorer/blob/master/index.js#L203

This is a bit unintuitive, as <script.map.js> is an optional parameter.

arve0 commented 5 years ago

Proposed fix:

A. If .map is not given, shim as args['<script.js>'] + ".map" and glob for each of them. B. Fail hard when it does not match exactly two files: https://github.com/danvk/source-map-explorer/blob/master/index.js#L200 C. Add trailing star to glob if it does only match one file. D. If it matches one file, see if match + ".map" exists.

Let me know what you prefer, and I'll send a PR.

Edit: Added option D.