Repository navigation
Proposal to support passing resolved compiler into webpack options #1725
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
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,13 @@ | ||
| import type { Colors } from './colors'; | ||
| import type { | ||
| API, | ||
| APIOptions, | ||
| Diagnostic, | ||
| ParsedCommandLine, | ||
| Snapshot, | ||
| SyntheticProjectId, | ||
| } from 'typescript/sync'; | ||
| import type { createFileSystemLayer } from 'typescript/fs'; | ||
| import type * as webpack from 'webpack'; | ||
|
|
||
| export interface ErrorInfo { | ||
|
|
@@ -38,12 +40,22 @@ export const LogLevel = { | |
| ERROR: 3, | ||
| } as const; | ||
|
|
||
| /** `API` from `typescript/sync` and `createFileSystemLayer` from `typescript/fs`. */ | ||
| export interface TypeScriptCompilerModules { | ||
| API: new (options?: APIOptions) => API; | ||
| createFileSystemLayer: typeof createFileSystemLayer; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would this approach work if we didn't pass |
||
| } | ||
|
|
||
| export interface LoaderOptions { | ||
| silent: boolean; | ||
| logLevel: keyof typeof LogLevel; | ||
| logInfoToStdOut: boolean; | ||
| instance: string; | ||
| compiler: string; | ||
| /** | ||
| * A package name (loaded with `require()`, needs Node 20.19+ / 22.12+), or | ||
| * the already-imported modules. Defaults to `'typescript'`. | ||
| */ | ||
| compiler?: string | TypeScriptCompilerModules; | ||
| configFile: string; | ||
| transpileOnly: boolean; | ||
| ignoreDiagnostics: number[]; | ||
|
|
@@ -82,6 +94,7 @@ export interface SyntheticProgram { | |
|
|
||
| export interface TypeScriptInstance { | ||
| api: API; | ||
| compiler: TypeScriptCompilerModules; | ||
| /** Real-cased, as given to the API - not a canonical key (see FilePath). */ | ||
| configFilePath: string; | ||
| transpileConfig?: ParsedCommandLine; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const compiledWithSuppliedCompiler = true; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import { fileURLToPath } from "node:url"; | ||
| import { API } from "typescript/sync"; | ||
| import { createFileSystemLayer } from "typescript/fs"; | ||
|
|
||
| export default { | ||
| mode: "development", | ||
| entry: "./app.ts", | ||
| output: { | ||
| filename: "bundle.js", | ||
| }, | ||
| resolve: { | ||
| extensions: [".ts", ".js"], | ||
| }, | ||
| module: { | ||
| rules: [ | ||
| { | ||
| test: /\.ts$/, | ||
| loader: "ts-loader", | ||
| options: { | ||
| compiler: { API, createFileSystemLayer }, | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| resolveLoader: { | ||
| alias: { | ||
| "ts-loader": fileURLToPath(new URL("../../../index.js", import.meta.url)), | ||
| }, | ||
| }, | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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.
I don't think the documentation is correct - here; it's an object that's passed and default value is not
'typescript'?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.
default is
typescriptused here https://github.com/TypeStrong/ts-loader/pull/1725/changes/BASE..f110b488792612b481dea18cdd36fb998b123170#diff-1bded13bfea4654df3b721738a266a835230e5539fe6fd27bc822e42a01ecd6fR44Uh oh!
There was an error while loading. Please reload this page.
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.
That's true - but it's quite peculiar!
Effectively the type is (I think):
I think it would be better if the default was
undefinedand that'typescript' |was removed from the union. Do you see what I mean?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.
but we can pass string like
'typescript-beta'or some other string that will be resolved inrequireCompilermaybe I am missing something
I tried to keep changes minimal, so that old configs would keep on working and only node 16 users would need to change webpack configs (pass object with API and createFileSystemLayer)
so if compiler option is missing default 'typescript' is used and required in
requireCompiler