-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[FEATURE] Stable types for @ember/owner
#20288
Conversation
- Rename the existing `build` command to `build:js`, introduce a `build:types` command, and make a new top-level `build` command that dispatches both of the others with `npm-run-all`. - Update handling for type checking to include separate passes for the library TS code and *each* of the type test packages.
We might want *some* lints on these at some point, but for now this is the right tradeoff here.
- The modules needed to be "absolute" not "relative" for the filtering to work correctly. - That in turn meant we needed to *insert* a relative lookup. - But we also needed to make sure we treat top-level packages *as such* rather than linking to their `index`, else TS does not resolve them correctly with these side effect modules.
- Remove `@ember/-internals/owner` and `@ember/owner` from the list of excluded preview types in the types publishing script, so they now get emitted correctly into `types/stable`. - Remove `@ember/owner` from the preview types and put it in the stable types instead, so users don't get conflicting type dependencies. - Internally in `@ember/owner`, use absolute package paths, not relative. For referencing other (even internal) packages, it's important that we *not* use relative paths, so that (a) the published types work when wrapped in `declare module` statements but also (b) we have clearer boundaries for them, which will unlock further improvements to this infrastructure in the future.
These really belong in the `@ember/application` re-export, not in the tests for `@ember/owner` itself, which should have no knowledge of the existence of `@ember/application` (but vice versa is fine).
This guarantees that we will be testing exactly what our consumers use, with the only difference being the specific import paths used to expose the side effect modules. It also keeps the type tests from diverging between the two sets of types. Previously, following the DefinitelyTyped approach, all the preview type modules had their own `tsconfig.json`, but this actually made them fail to interoperate with stable types, and this approach *only* works if they work together. Removing those means they operate as a single coherent set of type definitions with the stable types, distinguished *only* by the way they are authored.
6f32b76
to
d580037
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
High level this all makes sense to me! Were all the types/preview/**/tsconfig.json
files unneeded to begin with or did moving the tests around somehow impact that?
I believe they were unneeded in the first place, they were just leftover cruft from the DefinitelyTyped migration: DefinitelyTyped does need them given how its structure works, but we don't because we are doing the |
This PR introduces the first stable types published from Ember's source code! 🎉 🚀
Here's how it works:
Using the infrastructure introduced in add type tests infrastructure for supported TS versions #20185 (with some bug fixes), we include references to the types from
@ember/owner
and its dependency@ember/-internals/owner
in thetypes/stable/index.d.ts
file we generate as part of the build (3ca9834).Accordingly, we now treat generating these types as part of the build operation:
yarn build
both runs a normal Ember build to generate the JS (build:js
) and runstypes/publish.mjs
to emit these type definitions.Since those types now exist, we also remove the corresponding types from
types/preview
, so that end users who are using our recommended imports——will not get type conflicts from our own types (also 3ca9834).
We collapse the two sets of type tests together (74c2895). This was just a miss before: I didn't realize that we were going to necessarily want to be testing them as a coherent whole, but of course, that's how our consumers will be experiencing them, so that's how we need to test them. The combination of (1) and (3) made this really obvious.
As part of this PR, I introduced an absolute nightmare/monstrosity in abusing regex find and replace for the
types/publish.mjs
script to get rid ofdeclare
usages in the emitted module (see 86f6e52). In a future PR—indeed, the next PR, before landing any more such changes—I will switch that over to usingrecast
to remove those in a more reasonable way, and then runningprettier
against the results so that the emitted type definition files look reasonable.