Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1693516 - Publish type declarations along with @mozilla/glean package #85

Merged
merged 9 commits into from
Feb 23, 2021

Conversation

brizental
Copy link
Contributor

@brizental brizental commented Feb 23, 2021

For reference, an npm publish dry run looks like:

npm notice 
npm notice 馃摝  @mozilla/glean@0.1.1
npm notice === Tarball Contents === 
npm notice 1.2kB README.md                                           
npm notice 968B  dist/webext/core/config.js                          
npm notice 665B  dist/webext/core/constants.js                       
npm notice 5.6kB dist/webext/core/dispatcher.js                      
npm notice 9.5kB dist/webext/core/glean.js                           
npm notice 4.9kB dist/webext/core/internal_metrics.js                
npm notice 577B  dist/webext/core/internal_pings.js                  
npm notice 4.9kB dist/webext/core/metrics/database.js                
npm notice 3.1kB dist/webext/core/metrics/events_database.js         
npm notice 1.6kB dist/webext/core/metrics/index.js                   
npm notice 438B  dist/webext/core/metrics/time_unit.js               
npm notice 1.3kB dist/webext/core/metrics/types/boolean.js           
npm notice 2.3kB dist/webext/core/metrics/types/counter.js           
npm notice 6.2kB dist/webext/core/metrics/types/datetime.js          
npm notice 2.1kB dist/webext/core/metrics/types/event.js             
npm notice 1.8kB dist/webext/core/metrics/types/string.js            
npm notice 2.0kB dist/webext/core/metrics/types/uuid.js              
npm notice 1.1kB dist/webext/core/metrics/utils.js                   
npm notice 2.3kB dist/webext/core/pings/database.js                  
npm notice 1.7kB dist/webext/core/pings/index.js                     
npm notice 6.1kB dist/webext/core/pings/maker.js                     
npm notice 814B  dist/webext/core/platform_info.js                   
npm notice 77B   dist/webext/core/storage/index.js                   
npm notice 2.3kB dist/webext/core/storage/utils.js                   
npm notice 5.1kB dist/webext/core/upload/index.js                    
npm notice 243B  dist/webext/core/upload/uploader.js                 
npm notice 2.2kB dist/webext/core/utils.js                           
npm notice 711B  dist/webext/index/webext.js                         
npm notice 77B   dist/webext/platform/index.js                       
npm notice 1.0kB dist/webext/platform/test/index.js                  
npm notice 1.0kB dist/webext/platform/test/storage.js                
npm notice 564B  dist/webext/platform/webext/index.js                
npm notice 990B  dist/webext/platform/webext/platform_info.js        
npm notice 2.8kB dist/webext/platform/webext/storage.js              
npm notice 1.5kB dist/webext/platform/webext/uploader.js             
npm notice 587B  dist/webext/types/core/config.d.ts                  
npm notice 458B  dist/webext/types/core/constants.d.ts               
npm notice 5.6kB dist/webext/types/core/dispatcher.d.ts              
npm notice 6.1kB dist/webext/types/core/glean.d.ts                   
npm notice 1.4kB dist/webext/types/core/internal_metrics.d.ts        
npm notice 308B  dist/webext/types/core/internal_pings.d.ts          
npm notice 5.0kB dist/webext/types/core/metrics/database.d.ts        
npm notice 3.2kB dist/webext/types/core/metrics/events_database.d.ts 
npm notice 3.0kB dist/webext/types/core/metrics/index.d.ts           
npm notice 331B  dist/webext/types/core/metrics/time_unit.d.ts       
npm notice 1.0kB dist/webext/types/core/metrics/types/boolean.d.ts   
npm notice 2.0kB dist/webext/types/core/metrics/types/counter.d.ts   
npm notice 4.1kB dist/webext/types/core/metrics/types/datetime.d.ts  
npm notice 1.5kB dist/webext/types/core/metrics/types/event.d.ts     
npm notice 1.9kB dist/webext/types/core/metrics/types/string.d.ts    
npm notice 1.9kB dist/webext/types/core/metrics/types/uuid.d.ts      
npm notice 881B  dist/webext/types/core/metrics/utils.d.ts           
npm notice 3.4kB dist/webext/types/core/pings/database.d.ts          
npm notice 1.2kB dist/webext/types/core/pings/index.d.ts             
npm notice 2.6kB dist/webext/types/core/pings/maker.d.ts             
npm notice 991B  dist/webext/types/core/platform_info.d.ts           
npm notice 2.4kB dist/webext/types/core/storage/index.d.ts           
npm notice 1.4kB dist/webext/types/core/storage/utils.d.ts           
npm notice 5.2kB dist/webext/types/core/upload/index.d.ts            
npm notice 659B  dist/webext/types/core/upload/uploader.d.ts         
npm notice 2.9kB dist/webext/types/core/utils.d.ts                   
npm notice 1.9kB dist/webext/types/index/webext.d.ts                 
npm notice 448B  dist/webext/types/platform/index.d.ts               
npm notice 100B  dist/webext/types/platform/test/index.d.ts          
npm notice 633B  dist/webext/types/platform/test/storage.d.ts        
npm notice 104B  dist/webext/types/platform/webext/index.d.ts        
npm notice 136B  dist/webext/types/platform/webext/platform_info.d.ts
npm notice 1.4kB dist/webext/types/platform/webext/storage.d.ts      
npm notice 312B  dist/webext/types/platform/webext/uploader.d.ts     
npm notice 2.7kB package.json                                        
npm notice === Tarball Details === 
npm notice name:          @mozilla/glean                          
npm notice version:       0.1.1                                   
npm notice filename:      @mozilla/glean-0.1.1.tgz                
npm notice package size:  33.3 kB                                 
npm notice unpacked size: 147.8 kB                                
npm notice shasum:        299d4a55e0ab9382cebbf150a8da8a29b1220b13
npm notice integrity:     sha512-ZOv4Kd3hYI6OC[...]H6Wk1HlnjM/8w==
npm notice total files:   70                                      
npm notice 

Also, glean_parser changes are underway. I have been working on those concurrently with this PR.

brizental added 8 commits February 23, 2021 13:23
It is important at least for now have these two samples.
In the future we should have integrations tests to verify that these are working.
This is in preparation for the next commit.

The issue is: Typescript will not resolve type aliases when compiling code
(see: microsoft/TypeScript#26722 (comment)).

Webpack will do that, but you'll that in the next commit
I move away from using webpack for compiling the library.

I personaly hate having the `../../../` everywhere
but unless we are willing to write our own tool
that resolves that on the compiled code, I don't see what else we could do.
- Why stop bundling?

It makes it easier to provide the type declarations.

- But, how?

If we bundle our code, we need to create type declarations on top of the bundled code,
but when the code is already bundled we lose all the file paths and type richness
(bundled code is Javascript after all), which means, in order to get a rich declaration file
we would need to write it ourselves.

That would be kinda stupid work, since we are using typescript and have all the types information.

- Ok well, create the declaration files based on the unbundled code

Yes sure, that is the obvious solution and is also what this commit prepares for.

Using declaration files from unbundled code on top of bundled code, does not work,
so we need to provide the code in an unbundled format in order for the declaration paths to be correct.

- Observations

The reflex to use webpack and bundle + minify our code, came from my web development days.

I looked at multiple libraries and it is common place to provide the library code unbundled.
Developers will consume that library and then bundle it themselves with their own build system.
When we decide to target static websites, we can provide a bundled version of our code using a CDN,
but that is IMO a bridge we can cross when we get there.

We already also have a bug (https://bugzilla.mozilla.org/show_bug.cgi?id=1693039) to provide
conditional exports for users coming from different environments, but since our first consumers
will be bergamot and rally and both are ok with ES6 modules, we are fine for now.
Sadly, Qt _needs_ the bundled code, so we provide a special build for
it.
It was necessary to move away from requiring the package json.

Because we were requiring it, it was showing up as one of the compiled
files and that confuses consumers that are importing the @mozilla/glean
package, because they will resolve the first found package.json.
This probably got lost on one of the previous commits.
@brizental brizental merged commit d1a1b34 into mozilla:main Feb 23, 2021
@brizental brizental deleted the 1693516-type-declarations branch February 23, 2021 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants