-
Notifications
You must be signed in to change notification settings - Fork 536
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
build(tree): Make compatible with moduleResolution: node16 #18882
Conversation
@@ -273,27 +273,27 @@ export class SchemaBuilder< | |||
/** | |||
* {@link leaf.number} | |||
*/ | |||
public readonly number = leaf.number; | |||
public readonly number: typeof leaf.number = leaf.number; |
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.
Some explicit types added where they were simple, to reduce the number of dynamic imports in d.?ts
files.
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.
We shouldn't have to make any source changes to get rollups and generate API reports.
Alternate solution for tree #19141
allowsTreeSchemaIdentifierSuperset(types, other.types), | ||
new Set([]), | ||
); | ||
export const optional: FieldKindWithEditor<OptionalFieldEditor, Multiplicity.Optional, "Optional"> = |
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.
Some explicit types added where they were simple, to reduce the number of dynamic imports in d.?ts
files (same below in this file).
@@ -328,7 +328,10 @@ export class TreeFieldSchema< | |||
/** | |||
* Schema for a field which must always be empty. | |||
*/ | |||
public static readonly empty = TreeFieldSchema.create(FieldKinds.forbidden, []); | |||
public static readonly empty: TreeFieldSchema<Forbidden, readonly []> = TreeFieldSchema.create( |
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.
Some explicit types added where they were simple, to reduce the number of dynamic imports in d.?ts
files.
@@ -8,6 +8,7 @@ export { OptionalChangeset, RegisterId } from "./optionalFieldChangeTypes"; | |||
export { | |||
optionalChangeHandler, | |||
optionalFieldEditor, | |||
OptionalFieldEditor, |
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.
This was done so I could add explicit types to some things, following what sequence field already did in terms of exports.
@@ -54,13 +54,17 @@ export interface MutableTreeStoredSchema extends TreeStoredSchemaSubscription { | |||
apply(newSchema: TreeStoredSchema): void; | |||
} | |||
|
|||
type eventsEmitterType = ISubscribable<SchemaEvents> & |
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.
Some explicit types added where they were simple, to reduce the number of dynamic imports in d.?ts
files.
⯅ @fluid-example/bundle-size-tests: +209 Bytes
Baseline commit: 72b15bf |
6a16a5d
to
538353c
Compare
"main": "dist/index.js", | ||
"module": "lib/index.js", | ||
"module": "lib/index.mjs", |
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.
Should just be removed - module is not supported and never will be
@@ -12,17 +12,19 @@ | |||
"author": "Microsoft and contributors", | |||
"sideEffects": false, | |||
"main": "dist/index.js", | |||
"module": "lib/index.js", | |||
"module": "lib/index.mjs", |
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.
Should just be removed - module is not supported
"bench": "mocha --timeout 999999 --perfMode --parentProcess --fgrep @Benchmark --reporter @fluid-tools/benchmark/dist/MochaReporter.js", | ||
"bench:profile": "mocha --v8-prof --v8-logfile=profile.log --v8-no-logfile-per-isolate --timeout 999999 --perfMode --fgrep @Benchmark --reporter @fluid-tools/benchmark/dist/MochaReporter.js && node --prof-process profile.log > profile.txt && rimraf profile.log && echo See results in profile.txt", | ||
"build": "fluid-build . --task build", | ||
"build:commonjs": "fluid-build . --task commonjs", | ||
"build:compile": "fluid-build . --task compile", | ||
"build:docs": "api-extractor run --local", | ||
"build:esnext": "tsc --project ./tsconfig.esnext.json", | ||
"build:genver": "gen-version", | ||
"build:esnext": "tsc-multi --config ../../../common/build/build-common/tsc-multi.esm.json", |
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.
I think we should prefer ESM first general but at least for tree
. Make sure we see all of the issues with ESM without filtering.
@@ -12,17 +12,19 @@ | |||
"author": "Microsoft and contributors", | |||
"sideEffects": false, | |||
"main": "dist/index.js", |
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.
"type" should be set (prefer "module" with esm as first class.)
and "exports" should be added.
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.
Agree on removing the main/module field ultimately, but I'd like to do it separately, and ideally for all packages in the release group. Also, are you sure that removing these is not a breaking change? I thought at least webpack used the module field, but haven't yet confirmed whether removing it breaks our own examples. That's the other (minor) reason I want to do it all at once - so I can make only one "breaking change" note.
@@ -4,6 +4,8 @@ | |||
|
|||
```ts | |||
|
|||
import { FieldKind as FieldKind_2 } from './schemaTypes.js'; | |||
import { FieldSchema as FieldSchema_2 } from './schemaTypes.js'; | |||
import { FluidObject } from '@fluidframework/core-interfaces'; |
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.
These are not valid which means the API extractor generated .d.ts files are probably incorrect.
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.
Here is an example log when I had such gunk: https://dev.azure.com/fluidframework/public/_build/results?buildId=228628&view=logs&j=3dc8fd7e-4368-5a92-293e-d53cefc8c4b3&t=bfe27d5f-9219-57c0-0d67-1b2946a32921
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.
It's worrisome to me that in the example you linked, the tools involved were only tsc and api-extractor. Does that imply that api-extractor itself doesn't like the Tree types? Maybe we should try updating api-extractor? Looks like the recent minor release added support for TypeScript 5.3 - https://github.com/microsoft/rushstack/blob/main/apps/api-extractor/CHANGELOG.md#7390
@Josmithr FYI.
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.
I was guessing it isn't a Tree type thing but something with moduleResolution support.
I did a test with updated api-extractor for my branch and results were not great.
First I tried exactly as I had things and then with tree typescript set to 5.3.3 which the changelog said is supported:
@fluidframework/tree: error during command 'api-extractor run --local --config ./api-extractor-lint.json' (exit code 1)
@fluidframework/tree: api-extractor 7.39.1 - https://api-extractor.com/
@fluidframework/tree:
@fluidframework/tree:
@fluidframework/tree:
@fluidframework/tree: ERROR: Error parsing /home/jasonha/ff/FluidFramework/packages/dds/tree/api-extractor-lint.json:
@fluidframework/tree: The "bundledPackages" list contains an invalid package name: "@fluidframework/.*"
[ 8/12] x @fluidframework/tree: api-extractor run --local --config ./api-extractor-lint.json - 0.327s
@fluidframework/tree: error during command 'api-extractor run --config ./api-extractor-cjs.json' (exit code 1)
@fluidframework/tree: api-extractor 7.39.1 - https://api-extractor.com/
@fluidframework/tree:
@fluidframework/tree: Analysis will use the bundled TypeScript version 5.1.6
@fluidframework/tree: *** The target project appears to use TypeScript 5.3.3 which is newer than the bundled compiler engine; consider upgrading API Extractor.
@fluidframework/tree:
@fluidframework/tree:
@fluidframework/tree: ERROR: program.getResolvedModule is not a function
[ 9/12] x @fluidframework/tree: api-extractor run --config ./api-extractor-cjs.json - 2.742s
@fluidframework/tree: error during command 'api-extractor run --local --config ./api-extractor-esm.json' (exit code 1)
@fluidframework/tree: api-extractor 7.39.1 - https://api-extractor.com/
@fluidframework/tree:
@fluidframework/tree: Analysis will use the bundled TypeScript version 5.1.6
@fluidframework/tree: *** The target project appears to use TypeScript 5.3.3 which is newer than the bundled compiler engine; consider upgrading API Extractor.
@fluidframework/tree:
@fluidframework/tree:
@fluidframework/tree: ERROR: program.getResolvedModule is not a function
[10/12] x @fluidframework/tree: api-extractor run --local --config ./api-extractor-esm.json - 2.726s
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.
These errors might be related to the manual api-extractor patch that @Josmithr has been managing. Presumably that patch will need to be regenerated.
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.
Good call out. The patch is listed as for a specific version but might not be. I then also found that we were forcing 5.1.6 into api-extractor per pnpm override. When I removed those two things the main runs worked. The lint case still complains about malformed bundledPackages.
No change on the results for the different module resolutions and bad results.
I feel like I've seen such things in other packages, but maybe it was always when playing with module resolution. I think there was some checked in at some point and then something corrected it later.
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.
Ha, ha. The patch is specifically about making bundledPackages
support regex.
Updates the tree package to build ESM using tsc-multi, create valid ESM types, and adds an exports field and testing using arethetypeswrong.
This change also required more changes to tsc-multi to handle the types tree uses. Those changes are included here by updating the patch.