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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API Extractor for @firestore/lite + exp #3657

Closed
wants to merge 13 commits into from

Conversation

schmidt-sebastian
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian commented Aug 18, 2020

This adds API Extractor to firestore lite. Fingers crossed that we can get the generated and the automated types to match (via follow-up cleanup).

@changeset-bot
Copy link

changeset-bot bot commented Aug 18, 2020

💥 No Changeset

Latest commit: 37c864b

Merging this PR will not cause any packages to be released. If these changes should not cause updates to packages in this repo, this is fine 🙂

If these changes should be published to npm, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@@ -1,5 +1,5 @@
{
"name": "@firebase/firestore/lite",
"name": "@firebase/firestore-lite",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API Extractor considers this name invalid - looks like one slash is the maximum.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Api-extractor doesn't support multiple entry points, so you need to trick it to think that lite is a package instead of a submodule.

(I have a PR to support multiple entry points, but only for documentation and api report)

Copy link
Contributor Author

@schmidt-sebastian schmidt-sebastian Aug 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name is invalid even outside of this PR. I get this error from IntelliJ when I turn on JSON schema validation:

String violates the pattern: '^(?:@[a-z0-9-*~][a-z0-9-*._~]*/)?[a-z0-9-~][a-z0-9-._~]*$' 
Inspection info: This inspection checks that JSON files conform to JSON Schemas assigned to them

The pattern seems to allow only one scoped package. Do we need to change it or should I spend some time trying to figure out how to work around this limitation without the name change?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name actually doesn't matter, so it can be whatever that's easier for you. We use/ to be consistent with how developer would use the submodules, so I prefer to stay this way. Does it give you any issue other than unpleasant validation error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the following error:

Error: Error parsing /Users/mrschmidt/GitHub/firebase/firebase-js-sdk/packages/firestore/lite/api-extractor.json:
The package name "@firebase/firestore/lite" contains an invalid character: "/"

The build stops after this message.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh right, api-extractor definitely doesn't like it. You can change it to - to work around it for now. I'm planning to release a forked version of api-extractor with support for multiple entry points. We will come back to this once that's done.

@schmidt-sebastian schmidt-sebastian changed the title Add Api Extractor for @firestore/lite Add API Extractor for @firestore/lite Aug 18, 2020
@@ -136,6 +135,7 @@
"ora": "4.0.5",
"prettier": "2.0.5",
"protractor": "5.4.2",
"rollup-plugin-copy": "3.3.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rollup-plugin-copy-asset doesn't allow me to move the proto files to dist/lite/src/proto

package.json Outdated
@@ -66,8 +66,7 @@
"@changesets/changelog-github": "0.2.6",
"@changesets/cli": "2.9.2",
"@microsoft/api-documenter": "7.8.21",
"@microsoft/api-extractor": "7.9.2",
"@types/mz": "2.7.1",
"@microsoft/api-extractor": "7.8.2-pr1796.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pulls in microsoft/rushstack#1029, which makes this diff about 500 lines smaller (see the revert 609b2b3)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eh, the commit shows 445 additions and 477 deletions, so the net gain seems to be 32 lines?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it 500 lines in terms of changed lines. I can go with the version that doesn't require the custom release if you prefer that (which might make sense especially since we seem to waiting on a lot of other PRs).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I created a new PR to merge just this: #3660

package.json Outdated
@@ -66,8 +66,7 @@
"@changesets/changelog-github": "0.2.6",
"@changesets/cli": "2.9.2",
"@microsoft/api-documenter": "7.8.21",
"@microsoft/api-extractor": "7.9.2",
"@types/mz": "2.7.1",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is in here twice.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Aug 18, 2020

Binary Size Report

Affected SDKs

  • @firebase/firestore-exp

    Type Base (3b26db4) Head (73b9fa9) Diff
    browser ? 189 kB ? (?)
    main ? 468 kB ? (?)
    module ? 189 kB ? (?)
    react-native ? 189 kB ? (?)
  • @firebase/firestore-lite

    Type Base (3b26db4) Head (73b9fa9) Diff
    browser ? 64.8 kB ? (?)
    main ? 141 kB ? (?)
    module ? 64.8 kB ? (?)
    react-native ? 64.9 kB ? (?)

Test Logs

Copy link
Member

@Feiyang1 Feiyang1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you planning to do the same for exp?

"extends": "../../../config/api-extractor.json",
"mainEntryPointFilePath": "../dist/lite/firestore/lite/index.d.ts",
"dtsRollup": {
"enabled": true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think you will ever need main and lite to share declarations? There is a risk where the same type from main and lite becomes incompatible if they use separate rollup d.ts files - see discussion here. It's probably not a problem for us, since we are already using separate d.ts files for lite and main, but it's good to keep that in mind.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to do that, neither now nor in the future. Most of our types are incompatible with one another (i.e. a DocumentReference that contains a a Lite Firestore is incompatible with a DocumentReference for the main Firestore).

package.json Outdated
@@ -66,8 +66,7 @@
"@changesets/changelog-github": "0.2.6",
"@changesets/cli": "2.9.2",
"@microsoft/api-documenter": "7.8.21",
"@microsoft/api-extractor": "7.9.2",
"@types/mz": "2.7.1",
"@microsoft/api-extractor": "7.8.2-pr1796.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eh, the commit shows 445 additions and 477 deletions, so the net gain seems to be 32 lines?

@@ -1,5 +1,5 @@
{
"name": "@firebase/firestore/lite",
"name": "@firebase/firestore-lite",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Api-extractor doesn't support multiple entry points, so you need to trick it to think that lite is a package instead of a submodule.

(I have a PR to support multiple entry points, but only for documentation and api report)

@@ -7,14 +7,15 @@
"description": "The Cloud Firestore component of the Firebase JS SDK.",
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
"scripts": {
"api-report:lite": "(cd lite; api-extractor run --local --verbose)",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once this PR is merged, we can generate api reports for multiple entry points together, so you won't generate report for lite and main separately.
It seems it might take a long time to merge though, so I might publish a forked version to npm which we will use. For now, this is okay.

dest: 'dist/lite/src'
},
{
// Copy into generated source files to support API Extractor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does API extractor need a different path?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The source tree that it uses are the .d.ts generated files in dist/lite/firestore/src, and by default the "proto" dir is missing. I assume that is because we provide d.ts files to begin with and so nothing gets generated.

FWIW, I changed this to only copy the d.ts file.

Copy link
Contributor Author

@schmidt-sebastian schmidt-sebastian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some follow up questions.

I planned to do this in a follow-up to for /exp. I realized that we are not actually blocked because of the behavior differences that I would like to clarify in the API documentation, since the APIs that have different behavior are already implemented twice (e.g. getDoc). I pushed the changes to this PR now since without them the build was broken.

package.json Outdated
@@ -66,8 +66,7 @@
"@changesets/changelog-github": "0.2.6",
"@changesets/cli": "2.9.2",
"@microsoft/api-documenter": "7.8.21",
"@microsoft/api-extractor": "7.9.2",
"@types/mz": "2.7.1",
"@microsoft/api-extractor": "7.8.2-pr1796.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it 500 lines in terms of changed lines. I can go with the version that doesn't require the custom release if you prefer that (which might make sense especially since we seem to waiting on a lot of other PRs).

"extends": "../../../config/api-extractor.json",
"mainEntryPointFilePath": "../dist/lite/firestore/lite/index.d.ts",
"dtsRollup": {
"enabled": true,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to do that, neither now nor in the future. Most of our types are incompatible with one another (i.e. a DocumentReference that contains a a Lite Firestore is incompatible with a DocumentReference for the main Firestore).

@@ -1,5 +1,5 @@
{
"name": "@firebase/firestore/lite",
"name": "@firebase/firestore-lite",
Copy link
Contributor Author

@schmidt-sebastian schmidt-sebastian Aug 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name is invalid even outside of this PR. I get this error from IntelliJ when I turn on JSON schema validation:

String violates the pattern: '^(?:@[a-z0-9-*~][a-z0-9-*._~]*/)?[a-z0-9-~][a-z0-9-._~]*$' 
Inspection info: This inspection checks that JSON files conform to JSON Schemas assigned to them

The pattern seems to allow only one scoped package. Do we need to change it or should I spend some time trying to figure out how to work around this limitation without the name change?

dest: 'dist/lite/src'
},
{
// Copy into generated source files to support API Extractor
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The source tree that it uses are the .d.ts generated files in dist/lite/firestore/src, and by default the "proto" dir is missing. I assume that is because we provide d.ts files to begin with and so nothing gets generated.

FWIW, I changed this to only copy the d.ts file.

@@ -365,31 +365,6 @@ export function snapshotEqual<T>(
right: DocumentSnapshot<T> | QuerySnapshot<T>
): boolean;

export type FirestoreErrorCode =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Lite SDK doesn't use FirestoreError.

@schmidt-sebastian schmidt-sebastian changed the title Add API Extractor for @firestore/lite Add API Extractor for @firestore/lite + exp Aug 19, 2020
@schmidt-sebastian
Copy link
Contributor Author

PR updated to undo the api-extractor upgrade.

@schmidt-sebastian
Copy link
Contributor Author

Abandoning.

@firebase firebase locked and limited conversation to collaborators Oct 17, 2020
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/litetypes branch November 9, 2020 22:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants