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

Convert @fluid-example/table-document tests to use esnext modules #15939

Merged
merged 1 commit into from
Jun 12, 2023

Conversation

Abe27342
Copy link
Contributor

@Abe27342 Abe27342 commented Jun 9, 2023

Description

This makes progress toward #15917 by converting @fluid-example/table-document's tests to run esnext modules only.

It's not yet feasible to convert the whole package to esnext, as despite being an example package it's currently used by some internal partners. I've therefore just converted the test config to use esnext.

@Abe27342 Abe27342 requested a review from a team as a code owner June 9, 2023 21:12
@github-actions github-actions bot added area: examples Changes that focus on our examples base: main PRs targeted against main branch labels Jun 9, 2023
@msfluid-bot
Copy link
Collaborator

@fluid-example/bundle-size-tests: +30 Bytes
Metric NameBaseline SizeCompare SizeSize Diff
aqueduct.js 448.83 KB 448.84 KB +6 Bytes
connectionState.js 680 Bytes 680 Bytes No change
containerRuntime.js 239.47 KB 239.47 KB +2 Bytes
loader.js 154.4 KB 154.4 KB +4 Bytes
map.js 46.66 KB 46.66 KB +2 Bytes
matrix.js 146.59 KB 146.59 KB +2 Bytes
odspDriver.js 92.31 KB 92.32 KB +6 Bytes
odspPrefetchSnapshot.js 43.64 KB 43.64 KB +4 Bytes
sharedString.js 163.26 KB 163.27 KB +2 Bytes
sharedTree2.js 279.92 KB 279.92 KB No change
Total Size 1.73 MB 1.73 MB +30 Bytes

Baseline commit: 1f97dff

Generated by 🚫 dangerJS against 33e918c

// ESLint's resolver doesn't resolve relative imports of ESNext modules correctly, since
// it resolves the path relative to the .ts file (and assumes a file with a .js extension
// should exist there)
"import/no-unresolved": ["error", { ignore: ["^\\.(.*)\\.js$"] }],
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'd love to make eslint's module resolver understand these imports, but I'm not sure it's possible out of the box (we'd have to maintain our own resolver, and I'm not sure if it would be a trivial wrapper over the base node resolver or not). I don't think this rule provides particularly high value for relative imports though, so IMO it's not the worst.

Copy link
Contributor

Choose a reason for hiding this comment

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

Someone must have written a solution for this already, right? Typescript transpiled to a different folder + ESM should be a common scenario by now...? Can be addressed separately.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for prodding me to look into this again. I think we can actually make this work nicely by removing eslint-plugin-unused-imports, transitioning to eslint-plugin-import, and updating our import resolve to be eslint-import-resolver-typescript (where the default extensionAlias should work perfectly). that'll require a release of the common lint config, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

overrides: [
{
// Rules only for test files
files: ["*.spec.ts", "src/test/**"],
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit. There should be no *.spec.ts files outside src/test/ anyway, right? Not 100% sure about the glob syntax, if it's incorrect then just keep src/test/**?

Suggested change
files: ["*.spec.ts", "src/test/**"],
files: ["src/test/**/*.spec.ts"],

Copy link
Contributor Author

Choose a reason for hiding this comment

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

seems like we use this glob in basically all our other packages with "test-only overrides". i'd prefer to keep that consistent over some simplification. We do want non-.spec files inside the test-folder to be exempted as well though, so if we were to change it, it should be src/test/**

// ESLint's resolver doesn't resolve relative imports of ESNext modules correctly, since
// it resolves the path relative to the .ts file (and assumes a file with a .js extension
// should exist there)
"import/no-unresolved": ["error", { ignore: ["^\\.(.*)\\.js$"] }],
Copy link
Contributor

Choose a reason for hiding this comment

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

Someone must have written a solution for this already, right? Typescript transpiled to a different folder + ESM should be a common scenario by now...? Can be addressed separately.

@Abe27342 Abe27342 merged commit 10b0742 into microsoft:main Jun 12, 2023
@Abe27342 Abe27342 deleted the table-document-esm branch June 15, 2023 23:16
connorskees pushed a commit to connorskees/FluidFramework that referenced this pull request Jul 19, 2023
…crosoft#15939)

## Description

This makes progress toward microsoft#15917 by converting
`@fluid-example/table-document`'s tests to run esnext modules only.

It's not yet feasible to convert the whole package to esnext, as despite
being an example package it's currently used by some internal partners.
I've therefore just converted the test config to use esnext.
Abe27342 added a commit that referenced this pull request Aug 1, 2023
## Description

#15939 and related PRs disabled this linter rule for imports to `.js`
files, since the base eslint module resolver doesn't understand that
relative imports to .js should sometimes conceptually refer to .ts files
instead. This re-enables linting for that rule in affected packages by
using
[eslint-import-resolver-typescript](https://www.npmjs.com/package/eslint-import-resolver-typescript).
pradeepvairamani pushed a commit that referenced this pull request Aug 9, 2023
## Description

#15939 and related PRs disabled this linter rule for imports to `.js`
files, since the base eslint module resolver doesn't understand that
relative imports to .js should sometimes conceptually refer to .ts files
instead. This re-enables linting for that rule in affected packages by
using
[eslint-import-resolver-typescript](https://www.npmjs.com/package/eslint-import-resolver-typescript).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: examples Changes that focus on our examples base: main PRs targeted against main branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants