-
-
Notifications
You must be signed in to change notification settings - Fork 433
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
internal: remove usage of hand crafted webpack typings #927
Changes from 1 commit
db629db
2cbbdf3
ca07454
7a609f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -7,10 +7,6 @@ export const LineFeed = '\n'; | |||||
export const CarriageReturnLineFeedCode = 0; | ||||||
export const LineFeedCode = 1; | ||||||
|
||||||
export const ScriptTargetES2015 = 2; | ||||||
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. So interestingly the moving of using locally defined constants to directly depending on TypeScript would mark the first direct runtime (rather than compilation time) dependency on the I believe, back in the mists of time, this was an intentional choice by ts-loader's @jbrantly. I think the reasons were to do with ts-loader working with multiple versions of TypeScript - not bolted to a specific one that you build with. It may been related to the ability to supply your own version of TypeScript. Remember ntypescript? https://github.com/TypeStrong/ts-loader/blob/master/README.md#compiler-string-defaulttypescript See also: ts-loader/src/compilerSetup.ts Line 15 in 48626a9
I don't know if this matters anymore. The values of those enums are pretty much set in stone now. I'd appreciate any thoughts on this - it's probably fine. But I've a feeling that other views may be available too. Also @arcanis - would this create issues for yarn PnP support? 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.
Not if 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. Cool - it's already a Line 94 in 48626a9
|
||||||
|
||||||
export const ModuleKindCommonJs = 1; | ||||||
|
||||||
export const extensionRegex = /\.[^.]+$/; | ||||||
export const tsxRegex = /\.tsx$/i; | ||||||
export const tsTsxRegex = /\.ts(x?)$/i; | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import chalk, { Chalk } from 'chalk'; | |
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import * as typescript from 'typescript'; | ||
import * as webpack from 'webpack'; | ||
|
||
import { makeAfterCompile } from './after-compile'; | ||
import { getCompiler, getCompilerOptions } from './compilerSetup'; | ||
|
@@ -13,7 +14,6 @@ import { | |
TSFiles, | ||
TSInstance, | ||
TSInstances, | ||
Webpack, | ||
WebpackError | ||
} from './interfaces'; | ||
import * as logger from './logger'; | ||
|
@@ -29,6 +29,9 @@ import { makeWatchRun } from './watch-run'; | |
|
||
const instances = {} as TSInstances; | ||
|
||
// TODO: workaround for issues with webpack typings | ||
type PatchedHookCallback = any; | ||
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. |
||
|
||
/** | ||
* The loader is executed once for each file seen by webpack. However, we need to keep | ||
* a persistent instance of TypeScript that contains all of the files in the program | ||
|
@@ -38,7 +41,7 @@ const instances = {} as TSInstances; | |
*/ | ||
export function getTypeScriptInstance( | ||
loaderOptions: LoaderOptions, | ||
loader: Webpack | ||
loader: webpack.loader.LoaderContext | ||
): { instance?: TSInstance; error?: WebpackError } { | ||
if (instances.hasOwnProperty(loaderOptions.instance)) { | ||
const instance = instances[loaderOptions.instance]; | ||
|
@@ -67,7 +70,7 @@ export function getTypeScriptInstance( | |
|
||
function successfulTypeScriptInstance( | ||
loaderOptions: LoaderOptions, | ||
loader: Webpack, | ||
loader: webpack.loader.LoaderContext, | ||
log: logger.Logger, | ||
colors: Chalk, | ||
compiler: typeof typescript, | ||
|
@@ -307,10 +310,10 @@ function successfulTypeScriptInstance( | |
); | ||
} | ||
|
||
loader._compiler.hooks.afterCompile.tapAsync( | ||
'ts-loader', | ||
makeAfterCompile(instance, configFilePath) | ||
); | ||
loader._compiler.hooks.afterCompile.tapAsync('ts-loader', makeAfterCompile( | ||
instance, | ||
configFilePath | ||
) as PatchedHookCallback); | ||
loader._compiler.hooks.watchRun.tapAsync('ts-loader', makeWatchRun(instance)); | ||
|
||
return { instance }; | ||
|
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.
Bug #1 where the following properties are not available on a compiler instance.