Skip to content

packageJsonWatch, testing package.json and impliedNodeFormat use in transformer #48958

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

Closed

Conversation

craigphicks
Copy link

@craigphicks craigphicks commented May 4, 2022

With regards to "Handle package.json watch in tsc, tsc --build and tsserver" #48889

@sheetalkamat
@weswigham
@andrewbranch

(C.f. the now closed question #48794 where @andrewbranch and @weswigham explained how to use SourceFile.impliedNodeFormat.)

I saw this pull and assumed the content is necessary to get correct values for SourceFile.impliedNodeFormat.
Therefore on the packageJsonWatch branch I created a test to check the value of impliedNodeFormat from inside a transformer when

  • tsconfig:compilerOptions:moduleResolution is set to "Node12", and
  • package.json exists and type is "commonjs"

From the transformer, the value of impliedNodeFormat is correctly ModuleKind.CommonJS

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label May 4, 2022
@typescript-bot
Copy link
Collaborator

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

Changes to be committed:
	modified:   src/testRunner/unittests/tsbuildWatch/publicApiImpliedNodeFormat.ts
	new file:   tests/baselines/reference/tsbuildWatch/publicApi/with-custom-transformers,-test-that-impliedNodeFormat-is-set.js

* tests the impliedNodeFormat is correctly set for custom transformer,  in a simple case with compilerOptions:nodeResolution set to Node12
 Changes to be committed:
	modified:   src/testRunner/unittests/tsbuildWatch/publicApiImpliedNodeFormat.ts
	modified:   tests/baselines/reference/tsbuildWatch/publicApi/with-custom-transformers,-test-that-impliedNodeFormat-is-set.js

* add test to change package.json type from coomonjs tp module => impliedNodeFormat correctly changes
* add test to change package.json data only => project rebuild (not really desired, but it doesn't affect correctness)
 Changes to be committed:
	modified:   src/testRunner/unittests/tsbuildWatch/publicApiImpliedNodeFormat.ts
	modified:   tests/baselines/reference/tsbuildWatch/publicApi/with-custom-transformers,-test-that-impliedNodeFormat-is-set.js

* adding tests for other combinations of module and moduleResolution

| module  | moduleResolution |  uses package.json:type |
|--       |--                |--                       |
| unset   | "node12"             |  true           |
| "node12" | unset             |  true           |
| "node12" | "node"             |  false           |
Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

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

I don't understand the purpose of this PR. @sheetalkamat or @andrewbranch ?

builder.build();
runWatchBaseline({
scenario: "publicApi",
subScenario: "with custom transformers, test that impliedNodeFormat is set",
Copy link
Member

Choose a reason for hiding this comment

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

I don't know how good filesystems are at handling , -- I feel like the escaping code in runWatchBaseline should remove it.

Copy link
Author

Choose a reason for hiding this comment

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

Yes it comes out ugly with-custom-transformers,-test-that-impliedNodeFormat-is-set. I'll normalize it.,

Copy link
Author

@craigphicks craigphicks May 13, 2022

Choose a reason for hiding this comment

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

Changed to

subScenario: "with custom transformers impliedNodeFormat",

in now uploaded code.

});
}
// function printModuleResolutionCache(buildr: SolutionBuilder<EmitAndSemanticDiagnosticsBuilderProgram>){
// const x = { moduleResolutionCache: buildr.getModuleResolutionCache() };
Copy link
Member

Choose a reason for hiding this comment

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

what is this test testing? I expected to see getModuleResolutionCache somewhere, but it's commented out here

Copy link
Author

Choose a reason for hiding this comment

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

This test is writing and changing package.json "type" fields (values "commonjs" or "module"), and checking that the change detected is propagated up to the SourceFile["impliedNodeFormat"] field - in the context of a SolutionBuilder watch build.

The getModuleResolutionCache is apparently not used at all (and will not be used). I didn't know that, and put it there as part of a question I asked @sheetalkamat. I will remove it.

Copy link
Author

Choose a reason for hiding this comment

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

The commented out code referring to getModuleResolutionCache is removed in the now uploaded code.

 Changes to be committed:
	modified:   src/compiler/tsbuildPublic.ts

The public accessor for getModuleResolutionCache is removed

	modified:   src/testRunner/unittests/tsbuildWatch/publicApiImpliedNodeFormat.ts

Baseline description simplified, resulting in more legible naming of the baseline

	renamed:    tests/baselines/reference/tsbuildWatch/publicApi/with-custom-transformers,-test-that-impliedNodeFormat-is-set.js -> tests/baselines/reference/tsbuildWatch/publicApi/with-custom-transformers-impliedNodeFormat.js
@sandersn
Copy link
Member

sandersn commented Apr 1, 2025

Unfortunately, we haven't had time to review this PR and there's no issue showing an intent to add it to Typescript. I think it makes most sense to close this PR and re-open it if something changes.

@sandersn sandersn closed this Apr 1, 2025
@github-project-automation github-project-automation bot moved this from Waiting on reviewers to Done in PR Backlog Apr 1, 2025
@sandersn sandersn removed this from PR Backlog Apr 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants