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

fix(test runner): allow directory imports with path mapping #32491

Merged
merged 1 commit into from
Sep 9, 2024

Conversation

dgozman
Copy link
Contributor

@dgozman dgozman commented Sep 6, 2024

We now hopefully align with moduleResolution: bundler tsconfig option, allowing directory imports in every scenario, and allowing proper module imports when not going through the type mapping.

This regressed in #32078. Fixes #32480, fixes #31811.

tests/playwright-test/resolver.spec.ts Outdated Show resolved Hide resolved
tests/playwright-test/resolver.spec.ts Outdated Show resolved Hide resolved
tests/playwright-test/resolver.spec.ts Outdated Show resolved Hide resolved
tests/playwright-test/resolver.spec.ts Outdated Show resolved Hide resolved

This comment has been minimized.

@dgozman dgozman force-pushed the tr-fix-tsconfig-paths branch from f2b9a33 to f555d90 Compare September 6, 2024 19:46

This comment has been minimized.

@@ -367,8 +367,8 @@ export const test = base
const TSCONFIG = {
'compilerOptions': {
'target': 'ESNext',
'moduleResolution': 'node',
'module': 'commonjs',
'moduleResolution': 'bundler',
Copy link
Member

Choose a reason for hiding this comment

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

why did this change?

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 updates our default tsc config in tests to align with what we aim to support, particularly "bundler". Let me land it separately.

// - https://nodejs.org/dist/latest-v20.x/docs/api/modules.html#folders-as-modules

const mainField = getMainFieldFromPackageJson(packageJsonPath);
const mainFieldResolved = mainField ? resolveImportSpecifierExtension(path.resolve(resolved, mainField), isPathMapping) : undefined;
Copy link
Member

Choose a reason for hiding this comment

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

Why do we resolve package's main via path mapping? I don't think we should respect aliases in package.json, so should we just defer to Node from here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We do not apply path mappings here. resolveImportSpecifierExtension handles extension substitution, similarly to typescript.

Deferring to Node does not work, that's exactly the issue we are fixing. TypeScript allows ESM directory imports, while pure Node does not.

packages/playwright/src/util.ts Outdated Show resolved Hide resolved
@dgozman dgozman force-pushed the tr-fix-tsconfig-paths branch from f555d90 to 00b37ab Compare September 9, 2024 09:01

This comment has been minimized.

@dgozman dgozman force-pushed the tr-fix-tsconfig-paths branch from 00b37ab to 52589e8 Compare September 9, 2024 19:56
Copy link
Contributor

github-actions bot commented Sep 9, 2024

Test results for "tests 1"

1 failed
❌ [playwright-test] › babel.spec.ts:135:5 › should not transform external

2 flaky ⚠️ [playwright-test] › ui-mode-test-progress.spec.ts:165:5 › should update tracing network live
⚠️ [webkit-library] › library/download.spec.ts:698:3 › should convert navigation to a resource with unsupported mime type into download

29635 passed, 638 skipped
✔️✔️✔️

Merge workflow run.

@dgozman dgozman merged commit ae11867 into microsoft:main Sep 9, 2024
29 of 30 checks passed
dgozman added a commit to dgozman/playwright that referenced this pull request Sep 11, 2024
…ts with path mapping

We now hopefully align with `moduleResolution: bundler` tsconfig option,
allowing directory imports in every scenario, and allowing proper module
imports when not going through the type mapping.

This regressed in microsoft#32078. Fixes microsoft#32480, fixes microsoft#31811.
dgozman added a commit that referenced this pull request Sep 12, 2024
…ath mapping (#32571)

We now hopefully align with `moduleResolution: bundler` tsconfig option,
allowing directory imports in every scenario, and allowing proper module
imports when not going through the type mapping.

This regressed in #32078. Fixes #32480, fixes #31811.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants