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

build(tree): Make compatible with moduleResolution: node16 #18882

Closed
wants to merge 23 commits into from

Conversation

tylerbutler
Copy link
Member

@tylerbutler tylerbutler commented Dec 16, 2023

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.

@github-actions github-actions bot added area: dds Issues related to distributed data structures area: dds: tree area: dev experience Improving the experience of devs building on top of fluid area: examples Changes that focus on our examples area: runtime Runtime related issues area: tests Tests to add, test infrastructure improvements, etc dependencies Pull requests that update a dependency file base: main PRs targeted against main branch labels Dec 16, 2023
@github-actions github-actions bot added the public api change Changes to a public API label Dec 17, 2023
@github-actions github-actions bot added area: framework Framework is a tag for issues involving the developer framework. Eg Aqueduct and removed area: runtime Runtime related issues labels Dec 22, 2023
@@ -273,27 +273,27 @@ export class SchemaBuilder<
/**
* {@link leaf.number}
*/
public readonly number = leaf.number;
public readonly number: typeof leaf.number = leaf.number;
Copy link
Contributor

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.

Copy link
Contributor

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"> =
Copy link
Contributor

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(
Copy link
Contributor

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,
Copy link
Contributor

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> &
Copy link
Contributor

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.

@msfluid-bot
Copy link
Collaborator

msfluid-bot commented Dec 22, 2023

@fluid-example/bundle-size-tests: +209 Bytes
Metric NameBaseline SizeCompare SizeSize Diff
aqueduct.js 739.44 KB 739.48 KB +33 Bytes
connectionState.js 680 Bytes 680 Bytes No change
containerRuntime.js 538.32 KB 538.33 KB +11 Bytes
loader.js 166.08 KB 166.1 KB +22 Bytes
map.js 556.87 KB 556.89 KB +22 Bytes
matrix.js 655.14 KB 655.17 KB +22 Bytes
odspDriver.js 89.31 KB 89.35 KB +33 Bytes
odspPrefetchSnapshot.js 41.58 KB 41.61 KB +22 Bytes
sharedString.js 673.91 KB 673.93 KB +22 Bytes
sharedTree.js 787.83 KB 787.84 KB +11 Bytes
Total Size 4.27 MB 4.27 MB +209 Bytes

Baseline commit: 72b15bf

Generated by 🚫 dangerJS against 325bf6f

@github-actions github-actions bot removed the area: framework Framework is a tag for issues involving the developer framework. Eg Aqueduct label Dec 22, 2023
@tylerbutler tylerbutler marked this pull request as ready for review January 5, 2024 22:18
@tylerbutler tylerbutler requested review from msfluid-bot and a team as code owners January 5, 2024 22:18
@github-actions github-actions bot removed the area: dev experience Improving the experience of devs building on top of fluid label Jan 5, 2024
"main": "dist/index.js",
"module": "lib/index.js",
"module": "lib/index.mjs",
Copy link
Contributor

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",
Copy link
Contributor

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",
Copy link
Contributor

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",
Copy link
Contributor

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.

Copy link
Member Author

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';
Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

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.

Copy link
Contributor

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

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

@tylerbutler tylerbutler closed this Feb 7, 2024
@tylerbutler tylerbutler deleted the node16-tree branch March 19, 2024 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: dds: tree area: dds Issues related to distributed data structures area: examples Changes that focus on our examples area: tests Tests to add, test infrastructure improvements, etc base: main PRs targeted against main branch dependencies Pull requests that update a dependency file public api change Changes to a public API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants