From 36bad2ea4b2d7518e26daba69a71d7a916577762 Mon Sep 17 00:00:00 2001 From: ULIVZ <472590061@qq.com> Date: Tue, 2 Mar 2021 17:00:40 +0800 Subject: [PATCH 1/3] feat: remove top-level typescript import statements --- src/after-compile.ts | 2 +- src/compilerSetup.ts | 9 +++++---- src/config.ts | 4 ++-- src/index.ts | 2 +- src/instances.ts | 4 ++-- src/interfaces.ts | 2 +- src/servicesHost.ts | 2 +- src/utils.ts | 2 +- 8 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/after-compile.ts b/src/after-compile.ts index 03fa8543a..81c21d4aa 100644 --- a/src/after-compile.ts +++ b/src/after-compile.ts @@ -1,5 +1,5 @@ import * as path from 'path'; -import * as ts from 'typescript'; +import type * as ts from 'typescript'; import * as webpack from 'webpack'; import * as constants from './constants'; diff --git a/src/compilerSetup.ts b/src/compilerSetup.ts index 3b53cc11c..68bb3a970 100644 --- a/src/compilerSetup.ts +++ b/src/compilerSetup.ts @@ -1,5 +1,5 @@ import * as semver from 'semver'; -import * as typescript from 'typescript'; +import type * as typescript from 'typescript'; import { LoaderOptions } from './interfaces'; import * as logger from './logger'; @@ -52,7 +52,8 @@ export function getCompiler(loaderOptions: LoaderOptions, log: logger.Logger) { } export function getCompilerOptions( - configParseResult: typescript.ParsedCommandLine + configParseResult: typescript.ParsedCommandLine, + compiler: typeof typescript ) { const compilerOptions = Object.assign({}, configParseResult.options, { skipLibCheck: true, @@ -63,9 +64,9 @@ export function getCompilerOptions( if ( compilerOptions.module === undefined && compilerOptions.target !== undefined && - compilerOptions.target < typescript.ScriptTarget.ES2015 + compilerOptions.target < compiler.ScriptTarget.ES2015 ) { - compilerOptions.module = typescript.ModuleKind.CommonJS; + compilerOptions.module = compiler.ModuleKind.CommonJS; } if (configParseResult.options.configFile) { diff --git a/src/config.ts b/src/config.ts index caeb6bf0e..ff14055b5 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,6 +1,6 @@ import { Chalk } from 'chalk'; import * as path from 'path'; -import * as typescript from 'typescript'; +import type * as typescript from 'typescript'; import * as webpack from 'webpack'; import { getCompilerOptions } from './compilerSetup'; @@ -187,7 +187,7 @@ export function getParsedCommandLine( extendedConfigCache ); if (result) { - result.options = getCompilerOptions(result); + result.options = getCompilerOptions(result, compiler); } return result; } diff --git a/src/index.ts b/src/index.ts index 95e53e301..ac3502a2c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ import * as crypto from 'crypto'; import * as loaderUtils from 'loader-utils'; import * as path from 'path'; -import * as typescript from 'typescript'; +import type * as typescript from 'typescript'; import * as webpack from 'webpack'; import * as constants from './constants'; diff --git a/src/instances.ts b/src/instances.ts index 3d7c299c5..aaa36b792 100644 --- a/src/instances.ts +++ b/src/instances.ts @@ -1,7 +1,7 @@ import * as chalk from 'chalk'; import * as fs from 'fs'; import * as path from 'path'; -import * as typescript from 'typescript'; +import type * as typescript from 'typescript'; import * as webpack from 'webpack'; import { makeAfterCompile } from './after-compile'; @@ -202,7 +202,7 @@ function successfulTypeScriptInstance( }; } - const compilerOptions = getCompilerOptions(configParseResult); + const compilerOptions = getCompilerOptions(configParseResult, compiler); const rootFileNames = new Set(); const files: TSFiles = new Map(); const otherFiles: TSFiles = new Map(); diff --git a/src/interfaces.ts b/src/interfaces.ts index fb7643e44..f2bf5a4b5 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -1,4 +1,4 @@ -import * as typescript from 'typescript'; +import type * as typescript from 'typescript'; import { Chalk } from 'chalk'; import * as logger from './logger'; diff --git a/src/servicesHost.ts b/src/servicesHost.ts index 170d03918..7432ceabb 100644 --- a/src/servicesHost.ts +++ b/src/servicesHost.ts @@ -1,5 +1,5 @@ import * as path from 'path'; -import * as typescript from 'typescript'; +import type * as typescript from 'typescript'; import * as webpack from 'webpack'; import { getParsedCommandLine } from './config'; import * as constants from './constants'; diff --git a/src/utils.ts b/src/utils.ts index 4974619c0..1b9691e9f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -2,7 +2,7 @@ import { Chalk } from 'chalk'; import * as fs from 'fs'; import * as micromatch from 'micromatch'; import * as path from 'path'; -import * as typescript from 'typescript'; +import type * as typescript from 'typescript'; import constants = require('./constants'); import { From 17beb96801d3804a3931a11596e81caf5e0e9ad8 Mon Sep 17 00:00:00 2001 From: John Reilly Date: Sun, 28 Mar 2021 08:11:43 +0100 Subject: [PATCH 2/3] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b9760fb33..55ad0e6e8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ts-loader", - "version": "8.0.18", + "version": "8.1.0", "description": "TypeScript loader for webpack", "main": "index.js", "types": "dist", From 32a75627d721c959f599d5cffb2dc789b34342e4 Mon Sep 17 00:00:00 2001 From: John Reilly Date: Sun, 28 Mar 2021 08:13:57 +0100 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 96a3e42a4..122e0dc5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## v8.1.0 +* [feat: remove top-level typescript import statements](https://github.com/TypeStrong/ts-loader/pull/1259) - thanks @ulivz + ## v8.0.18 * [Perf: Optimize fileExists callback path](https://github.com/TypeStrong/ts-loader/issues/1266) - thanks @berickson1