Skip to content

Commit c6a7b4c

Browse files
refactor: pass isWebpack5 into instance creation flow
Agent-Logs-Url: https://github.com/TypeStrong/ts-loader/sessions/80f981d4-a9e6-4dce-8da0-93e82749d5f2 Co-authored-by: johnnyreilly <1010525+johnnyreilly@users.noreply.github.com>
1 parent 6d40c52 commit c6a7b4c

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function loader(
4343
const callback = this.async();
4444
const isWebpack5 = typeof this.getOptions === 'function';
4545
const options = getLoaderOptions(this, isWebpack5);
46-
const instanceOrError = getTypeScriptInstance(options, this);
46+
const instanceOrError = getTypeScriptInstance(options, this, isWebpack5);
4747

4848
if (instanceOrError.error !== undefined) {
4949
callback(new Error(instanceOrError.error.message));

src/instances.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import {
3434
import { makeWatchRun } from './watch-run';
3535

3636
const instancesBySolutionBuilderConfigs = new Map<FilePathKey, TSInstance>();
37-
const detectWebpack5 = !!(webpack as any).sources;
3837

3938
/**
4039
* The loader is executed once for each file seen by webpack. However, we need to keep
@@ -45,7 +44,8 @@ const detectWebpack5 = !!(webpack as any).sources;
4544
*/
4645
export function getTypeScriptInstance(
4746
loaderOptions: LoaderOptions,
48-
loader: webpack.LoaderContext<LoaderOptions>
47+
loader: webpack.LoaderContext<LoaderOptions>,
48+
isWebpack5: boolean
4949
): { instance?: TSInstance; error?: webpack.WebpackError } {
5050
const existing = getTSInstanceFromCache(
5151
loader._compiler!,
@@ -73,6 +73,7 @@ export function getTypeScriptInstance(
7373
return successfulTypeScriptInstance(
7474
loaderOptions,
7575
loader,
76+
isWebpack5,
7677
log,
7778
colors,
7879
compiler.compiler!,
@@ -120,6 +121,7 @@ function createFilePathKeyMapper(
120121
function successfulTypeScriptInstance(
121122
loaderOptions: LoaderOptions,
122123
loader: webpack.LoaderContext<LoaderOptions>,
124+
isWebpack5: boolean,
123125
log: logger.Logger,
124126
colors: chalk.Chalk,
125127
compiler: typeof typescript,
@@ -149,7 +151,7 @@ function successfulTypeScriptInstance(
149151

150152
const { configFilePath, configFile } = configFileAndPath;
151153

152-
if (configFilePath && detectWebpack5) {
154+
if (configFilePath && isWebpack5) {
153155
loader.addBuildDependency(configFilePath);
154156
}
155157

@@ -217,7 +219,7 @@ function successfulTypeScriptInstance(
217219
// quick return for transpiling
218220
// we do need to check for any issues with TS options though
219221
const transpileInstance: TSInstance = {
220-
isWebpack5: detectWebpack5,
222+
isWebpack5,
221223
compiler,
222224
compilerOptions,
223225
appendTsTsxSuffixesIfRequired,
@@ -276,7 +278,7 @@ function successfulTypeScriptInstance(
276278
}
277279

278280
const instance: TSInstance = {
279-
isWebpack5: detectWebpack5,
281+
isWebpack5,
280282
compiler,
281283
compilerOptions,
282284
appendTsTsxSuffixesIfRequired,

0 commit comments

Comments
 (0)