Socket
Socket
Sign inDemoInstall

ts-loader

Package Overview
Dependencies
Maintainers
3
Versions
165
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-loader - npm Package Compare versions

Comparing version 8.1.0 to 9.0.0

5

.eslintrc.js
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
extends: ['plugin:node/recommended', 'plugin:prettier/recommended'],
extends: ['plugin:node/recommended'/*, 'plugin:prettier/recommended'*/],
parserOptions: {

@@ -23,4 +23,3 @@ ecmaVersion: 2018,

'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin
'prettier/@typescript-eslint', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
'plugin:prettier/recommended', // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
'prettier', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
],

@@ -27,0 +26,0 @@ rules: {

# Changelog
## v9.0.0
Breaking changes:
- minimum webpack version: 5
- minimum node version: 12
Changes:
* [webpack 5 migration](https://github.com/TypeStrong/ts-loader/pull/1251) - thanks @johnnyreilly, @jonwallsten, @sokra, @appzuka, @alexander-akait
## v8.1.0

@@ -4,0 +13,0 @@ * [feat: remove top-level typescript import statements](https://github.com/TypeStrong/ts-loader/pull/1259) - thanks @ulivz

2

dist/after-compile.d.ts

@@ -9,3 +9,3 @@ import * as webpack from 'webpack';

*/
export declare function makeAfterCompile(instance: TSInstance, configFilePath: string | undefined): (compilation: webpack.compilation.Compilation, callback: () => void) => void;
export declare function makeAfterCompile(instance: TSInstance, configFilePath: string | undefined): (compilation: webpack.Compilation, callback: () => void) => void;
//# sourceMappingURL=after-compile.d.ts.map

@@ -5,2 +5,3 @@ "use strict";

const path = require("path");
const webpack = require("webpack");
const constants = require("./constants");

@@ -68,3 +69,3 @@ const instances_1 = require("./instances");

compilation.modules.forEach(module => {
if (module.resource) {
if (module instanceof webpack.NormalModule && module.resource) {
const modulePath = filePathKeyMapper(module.resource);

@@ -223,7 +224,8 @@ const existingModules = modules.get(modulePath);

function outputFileToAsset(outputFile, compilation) {
const assetPath = path.relative(compilation.compiler.outputPath, outputFile.name);
compilation.assets[assetPath] = {
source: () => outputFile.text,
size: () => outputFile.text.length,
};
const assetPath = path
.relative(compilation.compiler.outputPath, outputFile.name)
// According to @alexander-akait (and @sokra) we should always '/' https://github.com/TypeStrong/ts-loader/pull/1251#issuecomment-799606985
.replace(/\\/g, '/');
// As suggested by @JonWallsten here: https://github.com/TypeStrong/ts-loader/pull/1251#issuecomment-800032753
compilation.emitAsset(assetPath, new webpack.sources.RawSource(outputFile.text));
}

@@ -269,22 +271,13 @@ function outputFilesToAsset(outputFiles, compilation, skipOutputFile) {

function removeCompilationTSLoaderErrors(compilation, loaderOptions) {
compilation.errors = compilation.errors.filter(error => error.loaderSource !== utils_1.tsLoaderSource(loaderOptions));
compilation.errors = compilation.errors.filter(error => error.details !== utils_1.tsLoaderSource(loaderOptions));
}
function removeModuleTSLoaderError(module, loaderOptions) {
/**
* Since webpack 5, the `errors` property is deprecated,
* so we can check if some methods for reporting errors exist.
*/
if (!!module.addError) {
const warnings = module.getWarnings();
const errors = module.getErrors();
module.clearWarningsAndErrors();
Array.from(warnings || []).forEach(warning => module.addWarning(warning));
Array.from(errors || [])
.filter((error) => error.loaderSource !== utils_1.tsLoaderSource(loaderOptions))
.forEach(error => module.addError(error));
}
else {
module.errors = module.errors.filter(error => error.loaderSource !== utils_1.tsLoaderSource(loaderOptions));
}
const warnings = module.getWarnings();
const errors = module.getErrors();
module.clearWarningsAndErrors();
Array.from(warnings || []).forEach(warning => module.addWarning(warning));
Array.from(errors || [])
.filter((error) => error.loaderSource !== utils_1.tsLoaderSource(loaderOptions))
.forEach(error => module.addError(error));
}
//# sourceMappingURL=after-compile.js.map
import { Chalk } from 'chalk';
import type * as typescript from 'typescript';
import * as webpack from 'webpack';
import { LoaderOptions, WebpackError } from './interfaces';
import { LoaderOptions, WebpackLoaderContext } from './interfaces';
import * as logger from './logger';

@@ -10,6 +10,6 @@ interface ConfigFile {

}
export declare function getConfigFile(compiler: typeof typescript, colors: Chalk, loader: webpack.loader.LoaderContext, loaderOptions: LoaderOptions, compilerCompatible: boolean, log: logger.Logger, compilerDetailsLogMessage: string): {
export declare function getConfigFile(compiler: typeof typescript, colors: Chalk, loader: WebpackLoaderContext, loaderOptions: LoaderOptions, compilerCompatible: boolean, log: logger.Logger, compilerDetailsLogMessage: string): {
configFilePath: string | undefined;
configFile: ConfigFile;
configFileError: WebpackError | undefined;
configFileError: webpack.WebpackError | undefined;
};

@@ -16,0 +16,0 @@ export declare function getConfigParseResult(compiler: typeof typescript, configFile: ConfigFile, basePath: string, configFilePath: string | undefined, loaderOptions: LoaderOptions): typescript.ParsedCommandLine;

@@ -84,3 +84,6 @@ "use strict";

function getConfigParseResult(compiler, configFile, basePath, configFilePath, loaderOptions) {
const configParseResult = compiler.parseJsonConfigFileContent(configFile.config, Object.assign(Object.assign({}, compiler.sys), { useCaseSensitiveFileNames: utils_1.useCaseSensitiveFileNames(compiler, loaderOptions) }), basePath, getCompilerOptionsToExtend(compiler, loaderOptions, basePath, configFilePath || 'tsconfig.json'));
const configParseResult = compiler.parseJsonConfigFileContent(configFile.config, {
...compiler.sys,
useCaseSensitiveFileNames: utils_1.useCaseSensitiveFileNames(compiler, loaderOptions),
}, basePath, getCompilerOptionsToExtend(compiler, loaderOptions, basePath, configFilePath || 'tsconfig.json'));
if (!loaderOptions.projectReferences) {

@@ -98,5 +101,8 @@ configParseResult.projectReferences = undefined;

function getParsedCommandLine(compiler, loaderOptions, configFilePath) {
const result = compiler.getParsedCommandLineOfConfigFile(configFilePath, getCompilerOptionsToExtend(compiler, loaderOptions, path.dirname(configFilePath), configFilePath), Object.assign(Object.assign({}, compiler.sys), { useCaseSensitiveFileNames: utils_1.useCaseSensitiveFileNames(compiler, loaderOptions),
const result = compiler.getParsedCommandLineOfConfigFile(configFilePath, getCompilerOptionsToExtend(compiler, loaderOptions, path.dirname(configFilePath), configFilePath), {
...compiler.sys,
useCaseSensitiveFileNames: utils_1.useCaseSensitiveFileNames(compiler, loaderOptions),
// eslint-disable-next-line @typescript-eslint/no-empty-function
onUnRecoverableConfigFileDiagnostic: () => { } }), extendedConfigCache);
onUnRecoverableConfigFileDiagnostic: () => { },
}, extendedConfigCache);
if (result) {

@@ -103,0 +109,0 @@ result.options = compilerSetup_1.getCompilerOptions(result, compiler);

@@ -1,7 +0,6 @@

import * as webpack from 'webpack';
import { LoaderOptions } from './interfaces';
import { LoaderOptions, WebpackLoaderContext } from './interfaces';
/**
* The entry point for ts-loader
*/
declare function loader(this: webpack.loader.LoaderContext, contents: string): void;
declare function loader(this: WebpackLoaderContext, contents: string): void;
export = loader;

@@ -8,0 +7,0 @@ /**

@@ -391,3 +391,3 @@ "use strict";

const { outputText, sourceMapText, diagnostics, } = instance.compiler.transpileModule(contents, {
compilerOptions: Object.assign(Object.assign({}, instance.compilerOptions), { rootDir: undefined }),
compilerOptions: { ...instance.compilerOptions, rootDir: undefined },
transformers: instance.transformers,

@@ -402,12 +402,3 @@ reportDiagnostics: true,

const errors = utils_1.formatErrors(diagnostics, instance.loaderOptions, instance.colors, instance.compiler, { module }, loaderContext.context);
/**
* Since webpack 5, the `errors` property is deprecated,
* so we can check if some methods for reporting errors exist.
*/
if (module.addError) {
errors.forEach(error => module.addError(error));
}
else {
module.errors.push(...errors);
}
errors.forEach(error => module.addError(error));
}

@@ -414,0 +405,0 @@ return { outputText, sourceMapText };

import type * as typescript from 'typescript';
import * as webpack from 'webpack';
import { LoaderOptions, TSInstance, WebpackError } from './interfaces';
import { LoaderOptions, TSInstance, WebpackLoaderContext } from './interfaces';
/**

@@ -11,9 +11,9 @@ * The loader is executed once for each file seen by webpack. However, we need to keep

*/
export declare function getTypeScriptInstance(loaderOptions: LoaderOptions, loader: webpack.loader.LoaderContext): {
export declare function getTypeScriptInstance(loaderOptions: LoaderOptions, loader: WebpackLoaderContext): {
instance?: TSInstance;
error?: WebpackError;
error?: webpack.WebpackError;
};
export declare function initializeInstance(loader: webpack.loader.LoaderContext, instance: TSInstance): void;
export declare function reportTranspileErrors(instance: TSInstance, loader: webpack.loader.LoaderContext): void;
export declare function buildSolutionReferences(instance: TSInstance, loader: webpack.loader.LoaderContext): void;
export declare function initializeInstance(loader: WebpackLoaderContext, instance: TSInstance): void;
export declare function reportTranspileErrors(instance: TSInstance, loader: WebpackLoaderContext): void;
export declare function buildSolutionReferences(instance: TSInstance, loader: WebpackLoaderContext): void;
export declare function forEachResolvedProjectReference<T>(resolvedProjectReferences: readonly (typescript.ResolvedProjectReference | undefined)[] | undefined, cb: (resolvedProjectReference: typescript.ResolvedProjectReference) => T | undefined): T | undefined;

@@ -20,0 +20,0 @@ export declare function getOutputFileNames(instance: TSInstance, configFile: typescript.ParsedCommandLine, inputFileName: string): string[];

@@ -7,3 +7,2 @@ "use strict";

const path = require("path");
const webpack = require("webpack");
const after_compile_1 = require("./after-compile");

@@ -40,3 +39,3 @@ const compilerSetup_1 = require("./compilerSetup");

return {
error: utils_1.makeError(loaderOptions, colors.red(compiler.errorMessage), undefined),
error: utils_1.makeError(loaderOptions, colors.red(compiler.errorMessage), ''),
};

@@ -99,14 +98,5 @@ }

const errors = utils_1.formatErrors(configParseResult.errors, loaderOptions, colors, compiler, { file: configFilePath }, loader.context);
/**
* Since webpack 5, the `errors` property is deprecated,
* so we can check if some methods for reporting errors exist.
*/
if (module.addError) {
errors.forEach(error => module.addError(error));
}
else {
module.errors.push(...errors);
}
errors.forEach(error => module.addError(error));
return {
error: utils_1.makeError(loaderOptions, colors.red('error while parsing tsconfig.json'), configFilePath),
error: utils_1.makeError(loaderOptions, colors.red('error while parsing tsconfig.json'), configFilePath || ''),
};

@@ -205,31 +195,21 @@ }

}
// Adding assets in afterCompile is deprecated in webpack 5 so we
// need different behavior for webpack4 and 5
const addAssetHooks = !!webpack.version.match(/^4.*/)
? (loader, instance) => {
// add makeAfterCompile with addAssets = true to emit assets and report errors
loader._compiler.hooks.afterCompile.tapAsync('ts-loader', after_compile_1.makeAfterCompile(instance, instance.configFilePath));
}
: (loader, instance) => {
// We must be running under webpack 5+
// makeAfterCompile is a closure. It returns a function which closes over the variable checkAllFilesForErrors
// We need to get the function once and then reuse it, otherwise it will be recreated each time
// and all files will always be checked.
const cachedMakeAfterCompile = after_compile_1.makeAfterCompile(instance, instance.configFilePath);
// compilation is actually of type webpack.compilation.Compilation, but afterProcessAssets
// only exists in webpack5 and at the time of writing ts-loader is built using webpack4
const makeAssetsCallback = (compilation) => {
compilation.hooks.afterProcessAssets.tap('ts-loader', () => cachedMakeAfterCompile(compilation, () => {
return null;
}));
};
// We need to add the hook above for each run.
// For the first run, we just need to add the hook to loader._compilation
makeAssetsCallback(loader._compilation);
// For future calls in watch mode we need to watch for a new compilation and add the hook
loader._compiler.hooks.compilation.tap('ts-loader', makeAssetsCallback);
// It may be better to add assets at the processAssets stage (https://webpack.js.org/api/compilation-hooks/#processassets)
// This requires Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL, which does not exist in webpack4
// Consider changing this when ts-loader is built using webpack5
function addAssetHooks(loader, instance) {
// makeAfterCompile is a closure. It returns a function which closes over the variable checkAllFilesForErrors
// We need to get the function once and then reuse it, otherwise it will be recreated each time
// and all files will always be checked.
const cachedMakeAfterCompile = after_compile_1.makeAfterCompile(instance, instance.configFilePath);
const makeAssetsCallback = (compilation) => {
compilation.hooks.afterProcessAssets.tap('ts-loader', () => cachedMakeAfterCompile(compilation, () => {
return null;
}));
};
// We need to add the hook above for each run.
// For the first run, we just need to add the hook to loader._compilation
makeAssetsCallback(loader._compilation);
// For future calls in watch mode we need to watch for a new compilation and add the hook
loader._compiler.hooks.compilation.tap('ts-loader', makeAssetsCallback);
// It may be better to add assets at the processAssets stage (https://webpack.js.org/api/compilation-hooks/#processassets)
// This requires Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL, which does not exist in webpack4
// Consider changing this when ts-loader is built using webpack5
}
function initializeInstance(loader, instance) {

@@ -321,12 +301,3 @@ if (!instance.initialSetupPending) {

const errors = utils_1.formatErrors(diagnostics, instance.loaderOptions, instance.colors, instance.compiler, { file: instance.configFilePath || 'tsconfig.json' }, loader.context);
/**
* Since webpack 5, the `errors` property is deprecated,
* so we can check if some methods for reporting errors exist.
*/
if (module.addError) {
[...solutionErrors, ...errors].forEach(error => module.addError(error));
}
else {
module.errors.push(...solutionErrors, ...errors);
}
[...solutionErrors, ...errors].forEach(error => module.addError(error));
}

@@ -333,0 +304,0 @@ }

@@ -0,4 +1,7 @@

/// <reference types="node" />
import type * as typescript from 'typescript';
import { Chalk } from 'chalk';
import * as logger from './logger';
import type * as webpack from 'webpack';
import type * as enhancedResolve from 'enhanced-resolve';
export interface ErrorInfo {

@@ -19,33 +22,2 @@ code: number;

};
export declare type WebpackSourcePosition = {
/** 1-based */
line: number;
/** 0-based */
column?: number;
};
export interface WebpackError {
module?: any;
file?: string;
message: string;
loc?: {
start: WebpackSourcePosition;
end?: WebpackSourcePosition;
};
location?: FileLocation;
loaderSource: string;
}
export interface WebpackModule {
resource: string;
errors: WebpackError[];
addWarning(warning: Error): void;
addError(error: WebpackError | Error): void;
getWarnings(): Iterable<Error> | undefined;
getErrors(): Iterable<WebpackError | Error> | undefined;
clearWarningsAndErrors(): void;
buildMeta: {
tsLoaderFileVersion: number;
tsLoaderDefinitionFileVersions: string[];
};
}
export declare type ResolveSync = (context: string | undefined, path: string, moduleName: string) => string;
export interface HostMayBeCacheable {

@@ -237,2 +209,155 @@ clearCache?(): void;

export declare type Severity = 'error' | 'warning';
export declare type WebpackLoaderCallback = (err: Error | undefined | null, content?: string | Buffer, sourceMap?: string | any) => void;
/** based on https://github.com/webpack/webpack/pull/13164#issuecomment-821357676 */
export interface WebpackLoaderContext {
version: number;
/**
* Hacky access to the Compilation object of webpack.
*/
_compilation: webpack.Compilation;
/**
* Hacky access to the Compiler object of webpack.
*/
_compiler: webpack.Compiler;
/**
* Hacky access to the Module object being loaded.
*/
_module: webpack.NormalModule;
addBuildDependency(dep: string): void;
/**
* Add a directory as dependency of the loader result.
* https://github.com/webpack/loader-runner/blob/6221befd031563e130f59d171e732950ee4402c6/lib/LoaderRunner.js#L305
*/
addContextDependency(context: string): void;
/**
* Adds a file as dependency of the loader result in order to make them watchable.
* For example, html-loader uses this technique as it finds src and src-set attributes.
* Then, it sets the url's for those attributes as dependencies of the html file that is parsed.
* https://github.com/webpack/loader-runner/blob/6221befd031563e130f59d171e732950ee4402c6/lib/LoaderRunner.js#L302
*/
addDependency(file: string): void;
/** https://github.com/webpack/loader-runner/blob/6221befd031563e130f59d171e732950ee4402c6/lib/LoaderRunner.js#L308 */
addMissingDependency(context: string): void;
/**
* Make this loader async.
* https://github.com/webpack/loader-runner/blob/6221befd031563e130f59d171e732950ee4402c6/lib/LoaderRunner.js#L108
*/
async(): WebpackLoaderCallback | undefined;
/**
* Make this loader result cacheable. By default it's not cacheable.
* A cacheable loader must have a deterministic result, when inputs and dependencies haven't changed.
* This means the loader shouldn't have other dependencies than specified with this.addDependency.
* Most loaders are deterministic and cacheable.
* https://github.com/webpack/loader-runner/blob/6221befd031563e130f59d171e732950ee4402c6/lib/LoaderRunner.js#L297
*/
cacheable(flag?: boolean): void;
/** https://github.com/webpack/loader-runner/blob/6221befd031563e130f59d171e732950ee4402c6/lib/LoaderRunner.js#L116 */
callback(): void;
/**
* Remove all dependencies of the loader result. Even initial dependencies and these of other loaders. Consider using pitch.
* https://github.com/webpack/loader-runner/blob/6221befd031563e130f59d171e732950ee4402c6/lib/LoaderRunner.js#L320
*/
clearDependencies(): void;
/**
* The directory of the module. Can be used as context for resolving other stuff.
* eg '/workspaces/ts-loader/examples/vanilla/src'
* https://github.com/webpack/loader-runner/blob/6221befd031563e130f59d171e732950ee4402c6/lib/LoaderRunner.js#L289
*/
context: string;
/** https://github.com/webpack/loader-runner/blob/6221befd031563e130f59d171e732950ee4402c6/lib/LoaderRunner.js#L358 */
readonly currentRequest: string;
/** https://github.com/webpack/loader-runner/blob/6221befd031563e130f59d171e732950ee4402c6/lib/LoaderRunner.js#L381 */
readonly data: any;
/**
* alias of addDependency
* Adds a file as dependency of the loader result in order to make them watchable.
* For example, html-loader uses this technique as it finds src and src-set attributes.
* Then, it sets the url's for those attributes as dependencies of the html file that is parsed.
* https://github.com/webpack/loader-runner/blob/6221befd031563e130f59d171e732950ee4402c6/lib/LoaderRunner.js#L302
*/
dependency(file: string): void;
/**
* https://github.com/webpack/webpack/blob/49890b77aae455b3204c17fdbed78eeb47bc1d98/lib/NormalModule.js#L520
*/
emitError(error: Error | string): void;
/** https://github.com/webpack/webpack/blob/49890b77aae455b3204c17fdbed78eeb47bc1d98/lib/NormalModule.js#L562 */
emitFile(name: string, content: string, sourceMap: string, assetInfo: webpack.AssetInfo): void;
/**
* https://github.com/webpack/webpack/blob/49890b77aae455b3204c17fdbed78eeb47bc1d98/lib/NormalModule.js#L510
*/
emitWarning(warning: Error | string): void;
/** https://github.com/webpack/webpack/blob/49890b77aae455b3204c17fdbed78eeb47bc1d98/lib/NormalModule.js#L590 */
fs: enhancedResolve.CachedInputFileSystem;
/** https://github.com/webpack/loader-runner/blob/6221befd031563e130f59d171e732950ee4402c6/lib/LoaderRunner.js#L314 */
getContextDependencies(): string[];
/** https://github.com/webpack/loader-runner/blob/6221befd031563e130f59d171e732950ee4402c6/lib/LoaderRunner.js#L311 */
getDependencies(): string[];
/** https://github.com/webpack/webpack/blob/49890b77aae455b3204c17fdbed78eeb47bc1d98/lib/NormalModule.js#L530 */
getLogger(name: string): webpack.Compilation['logger'];
/** https://github.com/webpack/loader-runner/blob/6221befd031563e130f59d171e732950ee4402c6/lib/LoaderRunner.js#L317 */
getMissingDependencies(): string[];
/** https://github.com/webpack/webpack/blob/49890b77aae455b3204c17fdbed78eeb47bc1d98/lib/NormalModule.js#L472 */
getOptions(schema: any): any;
/** https://github.com/webpack/webpack/blob/49890b77aae455b3204c17fdbed78eeb47bc1d98/lib/NormalModule.js#L541 */
getResolve(options: webpack.Configuration): any;
/**
* The index in the loaders array of the current loader.
* In the example: in loader1: 0, in loader2: 1
* https://github.com/webpack/loader-runner/blob/6221befd031563e130f59d171e732950ee4402c6/lib/LoaderRunner.js#L290
*/
loaderIndex: number;
/**
* Resolves the given request to a module, applies all configured loaders and calls
* back with the generated source, the sourceMap and the module instance (usually an
* instance of NormalModule). Use this function if you need to know the source code
* of another module to generate the result.
*/
loadModule(request: string, callback: (err: Error | null, source: string, sourceMap: any, module: webpack.Module) => void): void;
/** https://github.com/webpack/webpack/blob/49890b77aae455b3204c17fdbed78eeb47bc1d98/lib/NormalModule.js#L586 */
mode: 'development' | 'production' | 'none';
/** https://github.com/webpack/loader-runner/blob/6221befd031563e130f59d171e732950ee4402c6/lib/LoaderRunner.js#L366 */
readonly previousRequest: any;
/** https://github.com/webpack/loader-runner/blob/6221befd031563e130f59d171e732950ee4402c6/lib/LoaderRunner.js#L374 */
readonly query: any;
/** https://github.com/webpack/loader-runner/blob/6221befd031563e130f59d171e732950ee4402c6/lib/LoaderRunner.js#L348 */
readonly remainingRequest: any;
/** https://github.com/webpack/loader-runner/blob/6221befd031563e130f59d171e732950ee4402c6/lib/LoaderRunner.js#L340 */
readonly request: any;
/** https://github.com/webpack/webpack/blob/49890b77aae455b3204c17fdbed78eeb47bc1d98/lib/NormalModule.js#L538 */
resolve(context: string, request: any, callback: any): any;
/**
* Starting with webpack 4, the formerly `this.options.context` is provided as `this.rootContext`.
* https://github.com/webpack/webpack/blob/49890b77aae455b3204c17fdbed78eeb47bc1d98/lib/NormalModule.js#L583
*/
rootContext: string;
/**
* An array of all the loaders. It is writeable in the pitch phase.
* loaders = [{request: string, path: string, query: string, module: function}]
*
* In the example:
* [
* { request: "/abc/loader1.js?xyz",
* path: "/abc/loader1.js",
* query: "?xyz",
* module: [Function]
* },
* { request: "/abc/node_modules/loader2/index.js",
* path: "/abc/node_modules/loader2/index.js",
* query: "",
* module: [Function]
* }
* ]
*
* https://github.com/webpack/loader-runner/blob/6221befd031563e130f59d171e732950ee4402c6/lib/LoaderRunner.js#L291
* https://github.com/webpack/loader-runner/blob/6221befd031563e130f59d171e732950ee4402c6/lib/LoaderRunner.js#L46
*/
loaders: {
request: string;
}[];
/**
* The resource file.
* In the example: "/abc/resource.js"
*/
resourcePath: string;
}
//# sourceMappingURL=interfaces.d.ts.map

@@ -1,4 +0,4 @@

import * as webpack from 'webpack';
import { ResolveSync } from './interfaces';
export declare function makeResolver(options: webpack.Configuration): ResolveSync;
import type * as webpack from 'webpack';
export declare function makeResolver(options: webpack.WebpackOptionsNormalized): ResolveSync;
export declare type ResolveSync = (context: string | undefined, path: string, moduleName: string) => string | false;
//# sourceMappingURL=resolver.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeResolver = void 0;
// eslint-disable-next-line @typescript-eslint/no-var-requires
const node = require('enhanced-resolve/lib/node');
const enhanced_resolve_1 = require("enhanced-resolve");
function makeResolver(options) {
return node.create.sync(options.resolve);
return enhanced_resolve_1.create.sync(options.resolve);
}
exports.makeResolver = makeResolver;
//# sourceMappingURL=resolver.js.map
import type * as typescript from 'typescript';
import * as webpack from 'webpack';
import { FilePathKey, ServiceHostWhichMayBeCacheable, SolutionBuilderWithWatchHost, TSInstance, WatchHost, WebpackError } from './interfaces';
import { FilePathKey, ServiceHostWhichMayBeCacheable, SolutionBuilderWithWatchHost, TSInstance, WatchHost, WebpackLoaderContext } from './interfaces';
/**
* Create the TypeScript language service
*/
export declare function makeServicesHost(scriptRegex: RegExp, loader: webpack.loader.LoaderContext, instance: TSInstance, projectReferences?: ReadonlyArray<typescript.ProjectReference>): ServiceHostWhichMayBeCacheable;
export declare function makeServicesHost(scriptRegex: RegExp, loader: WebpackLoaderContext, instance: TSInstance, projectReferences?: ReadonlyArray<typescript.ProjectReference>): ServiceHostWhichMayBeCacheable;
export declare function updateFileWithText(instance: TSInstance, key: FilePathKey, filePath: string, text: (nFilePath: string) => string): void;

@@ -12,8 +12,8 @@ /**

*/
export declare function makeWatchHost(scriptRegex: RegExp, loader: webpack.loader.LoaderContext, instance: TSInstance, projectReferences?: ReadonlyArray<typescript.ProjectReference>): WatchHost;
export declare function makeWatchHost(scriptRegex: RegExp, loader: WebpackLoaderContext, instance: TSInstance, projectReferences?: ReadonlyArray<typescript.ProjectReference>): WatchHost;
/**
* Create the TypeScript Watch host
*/
export declare function makeSolutionBuilderHost(scriptRegex: RegExp, loader: webpack.loader.LoaderContext, instance: TSInstance): SolutionBuilderWithWatchHost;
export declare function getSolutionErrors(instance: TSInstance, context: string): WebpackError[];
export declare function makeSolutionBuilderHost(scriptRegex: RegExp, loader: WebpackLoaderContext, instance: TSInstance): SolutionBuilderWithWatchHost;
export declare function getSolutionErrors(instance: TSInstance, context: string): webpack.WebpackError[];
//# sourceMappingURL=servicesHost.d.ts.map

@@ -62,5 +62,9 @@ "use strict";

utils_1.fsReadFile(filePathToCheck) !== undefined, instance.loaderOptions.experimentalFileCaching);
const servicesHost = Object.assign(Object.assign({ getProjectVersion: () => `${instance.version}`, getProjectReferences: () => projectReferences, getScriptFileNames: () => [...files.values()]
const servicesHost = {
getProjectVersion: () => `${instance.version}`,
getProjectReferences: () => projectReferences,
getScriptFileNames: () => [...files.values()]
.map(({ fileName }) => fileName)
.filter(filePath => filePath.match(scriptRegex)), getScriptVersion: (fileName) => {
.filter(filePath => filePath.match(scriptRegex)),
getScriptVersion: (fileName) => {
var _a;

@@ -80,3 +84,4 @@ fileName = path.normalize(fileName);

: '';
}, getScriptSnapshot: (fileName) => {
},
getScriptSnapshot: (fileName) => {
// This is called any time TypeScript needs a file's text

@@ -105,6 +110,11 @@ // We either load from memory or from disk

return compiler.ScriptSnapshot.fromString(file.text);
} }, moduleResolutionHost), { getCompilationSettings: () => compilerOptions, log: moduleResolutionHost.trace,
},
...moduleResolutionHost,
getCompilationSettings: () => compilerOptions,
log: moduleResolutionHost.trace,
// used for (/// <reference types="...">) see https://github.com/Realytics/fork-ts-checker-webpack-plugin/pull/250#issuecomment-485061329
resolveTypeReferenceDirectives,
resolveModuleNames, getCustomTransformers: () => instance.transformers });
resolveModuleNames,
getCustomTransformers: () => instance.transformers,
};
return servicesHost;

@@ -238,3 +248,8 @@ }

/*enabledCaching*/ false);
const watchHost = Object.assign(Object.assign({ rootFiles: getRootFileNames(), options: compilerOptions }, moduleResolutionHost), { readFile: readFileWithCachingText, watchFile: (fileName, callback, pollingInterval, options) => {
const watchHost = {
rootFiles: getRootFileNames(),
options: compilerOptions,
...moduleResolutionHost,
readFile: readFileWithCachingText,
watchFile: (fileName, callback, pollingInterval, options) => {
var _a;

@@ -248,7 +263,9 @@ const outputFileKey = (_a = instance.solutionBuilderHost) === null || _a === void 0 ? void 0 : _a.getOutputFileKeyFromReferencedProject(fileName);

return watchFile(outputFileName, (_fileName, eventKind) => callback(fileName, eventKind), pollingInterval, options);
}, watchDirectory,
},
watchDirectory,
// used for (/// <reference types="...">) see https://github.com/Realytics/fork-ts-checker-webpack-plugin/pull/250#issuecomment-485061329
resolveTypeReferenceDirectives,
resolveModuleNames,
invokeFileWatcher, updateRootFileNames: () => {
invokeFileWatcher,
updateRootFileNames: () => {
instance.changedFilesList = false;

@@ -258,5 +275,8 @@ if (instance.watchOfFilesAndCompilerOptions !== undefined) {

}
}, createProgram: projectReferences === undefined
},
createProgram: projectReferences === undefined
? compiler.createEmitAndSemanticDiagnosticsBuilderProgram
: createBuilderProgramWithReferences, outputFiles: new Map() });
: createBuilderProgramWithReferences,
outputFiles: new Map(),
};
return watchHost;

@@ -361,5 +381,9 @@ function getRootFileNames() {

const sysHost = compiler.createSolutionBuilderWithWatchHost(compiler.sys, compiler.createEmitAndSemanticDiagnosticsBuilderProgram, reportDiagnostic, reportSolutionBuilderStatus, reportWatchStatus);
const solutionBuilderHost = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, sysHost), moduleResolutionHost), { resolveModuleNames,
const solutionBuilderHost = {
...sysHost,
...moduleResolutionHost,
resolveModuleNames,
resolveTypeReferenceDirectives,
diagnostics }), createWatchFactory(filePathKeyMapper, compiler)), {
diagnostics,
...createWatchFactory(filePathKeyMapper, compiler),
// Overrides

@@ -397,3 +421,4 @@ writeFile: (name, text, writeByteOrderMark) => {

}
}, createDirectory: sysHost.createDirectory &&
},
createDirectory: sysHost.createDirectory &&
(directory => {

@@ -403,12 +428,17 @@ var _a;

(_a = moduleResolutionHost.directoryExistsCache) === null || _a === void 0 ? void 0 : _a.delete(directory);
}), afterProgramEmitAndDiagnostics: transpileOnly ? undefined : storeDtsFiles, setTimeout: (callback, _time, ...args) => {
}),
afterProgramEmitAndDiagnostics: transpileOnly ? undefined : storeDtsFiles,
setTimeout: (callback, _time, ...args) => {
timeoutId = [callback, args];
return timeoutId;
}, clearTimeout: _timeoutId => {
},
clearTimeout: _timeoutId => {
timeoutId = undefined;
}, getParsedCommandLine: file => {
},
getParsedCommandLine: file => {
const config = config_1.getParsedCommandLine(compiler, instance.loaderOptions, file);
configFileInfo.set(filePathKeyMapper(file), { config });
return config;
}, writtenFiles,
},
writtenFiles,
configFileInfo,

@@ -420,10 +450,13 @@ outputAffectingInstanceVersion,

getOutputFileAndKeyFromReferencedProject,
getOutputFileTextAndKeyFromReferencedProject, getInputFileNameFromOutput: fileName => {
getOutputFileTextAndKeyFromReferencedProject,
getInputFileNameFromOutput: fileName => {
const result = getInputFileNameFromOutput(fileName);
return typeof result === 'string' ? result : undefined;
}, getOutputFilesFromReferencedProjectInput,
},
getOutputFilesFromReferencedProjectInput,
buildReferences,
ensureAllReferenceTimestamps,
clearCache,
close });
close,
};
return solutionBuilderHost;

@@ -646,5 +679,7 @@ function close() {

const originalFileName = resolveSync(undefined, path.normalize(path.dirname(containingFile)), moduleName);
const resolvedFileName = appendTsTsxSuffixesIfRequired(originalFileName);
if (resolvedFileName.match(scriptRegex) !== null) {
resolutionResult = { resolvedFileName, originalFileName };
if (originalFileName) {
const resolvedFileName = appendTsTsxSuffixesIfRequired(originalFileName);
if (resolvedFileName.match(scriptRegex) !== null) {
resolutionResult = { resolvedFileName, originalFileName };
}
}

@@ -651,0 +686,0 @@ }

@@ -0,4 +1,6 @@

/// <reference types="node" />
import { Chalk } from 'chalk';
import * as webpack from 'webpack';
import type * as typescript from 'typescript';
import { FileLocation, FilePathKey, LoaderOptions, ResolvedModule, ReverseDependencyGraph, TSInstance, WebpackError, WebpackModule } from './interfaces';
import { FileLocation, FilePathKey, LoaderOptions, ResolvedModule, ReverseDependencyGraph, TSInstance } from './interfaces';
/**

@@ -10,6 +12,6 @@ * Take TypeScript errors, parse them and format to webpack errors

file?: string;
module?: WebpackModule;
}, context: string): WebpackError[];
export declare function fsReadFile(fileName: string, encoding?: string | undefined): string | undefined;
export declare function makeError(loaderOptions: LoaderOptions, message: string, file: string | undefined, location?: FileLocation, endLocation?: FileLocation): WebpackError;
module?: webpack.Module;
}, context: string): webpack.WebpackError[];
export declare function fsReadFile(fileName: string, encoding?: BufferEncoding | undefined): string | undefined;
export declare function makeError(loaderOptions: LoaderOptions, message: string, file: string, location?: FileLocation, endLocation?: FileLocation): webpack.WebpackError;
export declare function tsLoaderSource(loaderOptions: LoaderOptions): string;

@@ -16,0 +18,0 @@ export declare function appendSuffixIfMatch(patterns: (RegExp | string)[], filePath: string, suffix: string): string;

@@ -7,2 +7,3 @@ "use strict";

const path = require("path");
const webpack = require("webpack");
const constants = require("./constants");

@@ -93,11 +94,19 @@ const instances_1 = require("./instances");

function makeError(loaderOptions, message, file, location, endLocation) {
return {
message,
file,
loc: location === undefined
? undefined
: makeWebpackLocation(location, endLocation),
location,
loaderSource: tsLoaderSource(loaderOptions),
};
const error = new webpack.WebpackError(message);
error.file = file;
error.loc =
location === undefined
? { name: file }
: makeWebpackLocation(location, endLocation);
error.details = tsLoaderSource(loaderOptions);
return error;
// return {
// message,
// file,
// loc:
// location === undefined
// ? { name: file }
// : makeWebpackLocation(location, endLocation),
// details: tsLoaderSource(loaderOptions),
// };
}

@@ -104,0 +113,0 @@ exports.makeError = makeError;

import * as webpack from 'webpack';
import { TSInstance } from './interfaces';
import { TSInstance, WebpackLoaderContext } from './interfaces';
/**
* Make function which will manually update changed files
*/
export declare function makeWatchRun(instance: TSInstance, loader: webpack.loader.LoaderContext): (compiler: webpack.Compiler, callback: (err?: Error | undefined) => void) => void;
export declare function makeWatchRun(instance: TSInstance, loader: WebpackLoaderContext): (compiler: webpack.Compiler, callback: (err?: Error | undefined) => void) => void;
//# sourceMappingURL=watch-run.d.ts.map

@@ -29,6 +29,8 @@ "use strict";

const lastTime = lastTimes.get(key) || startTime;
if (date <= lastTime) {
if (!date ||
date === 'ignore' ||
(date.timestamp || date.safeTime) <= lastTime) {
continue;
}
lastTimes.set(key, date);
lastTimes.set(key, date.timestamp || date.safeTime);
promises.push(updateFile(instance, key, filePath, loader, loaderIndex));

@@ -35,0 +37,0 @@ }

{
"name": "ts-loader",
"version": "8.1.0",
"version": "9.0.0",
"description": "TypeScript loader for webpack",

@@ -9,3 +9,3 @@ "main": "index.js",

"build": "tsc --version && tsc --project \"./src\"",
"lint": "eslint -c .eslintrc.js --ext .ts ./src",
"lint": "tsc --project \"./src\" --noEmit && eslint -c .eslintrc.js --ext .ts ./src",
"comparison-tests": "git clean -xfd test/comparison-tests && npm link ./test/comparison-tests/testLib && node test/comparison-tests/run-tests.js",

@@ -45,3 +45,3 @@ "comparison-tests-generate": "git clean -xfd test/comparison-tests && node test/comparison-tests/stub-new-version.js",

"engines": {
"node": ">=10.0.0"
"node": ">=12.0.0"
},

@@ -60,3 +60,3 @@ "author": "John Reilly <johnny_reilly@hotmail.com> (https://blog.johnnyreilly.com)",

"chalk": "^4.1.0",
"enhanced-resolve": "^4.0.0",
"enhanced-resolve": "^5.0.0",
"loader-utils": "^2.0.0",

@@ -67,6 +67,5 @@ "micromatch": "^4.0.0",

"devDependencies": {
"@types/micromatch": "^3.1.0",
"@types/micromatch": "^4.0.0",
"@types/node": "*",
"@types/semver": "^7.3.4",
"@types/webpack": "^4.4.30",
"@typescript-eslint/eslint-plugin": "^4.0.0",

@@ -83,16 +82,15 @@ "@typescript-eslint/parser": "^4.0.0",

"eslint": "^7.1.0",
"eslint-config-prettier": "^6.11.0",
"eslint-config-prettier": "^8.0.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.1.3",
"fs-extra": "^7.0.0",
"fs-extra": "^9.0.0",
"glob": "^7.1.1",
"html-webpack-plugin": "^3.2.0",
"husky": "^2.0.0",
"jasmine-core": "^3.0.0",
"karma": "^4.0.0",
"karma-chrome-launcher": "^2.2.0",
"karma-jasmine": "^2.0.0",
"karma": "^6.0.0",
"karma-chrome-launcher": "^3.1.0",
"karma-jasmine": "^4.0.0",
"karma-mocha-reporter": "^2.0.0",
"karma-sourcemap-loader": "^0.3.6",
"karma-webpack": "^4.0.0-rc.5",
"karma-sourcemap-loader": "^0.3.8",
"karma-webpack": "^5.0.0",
"lint-staged": "^8.0.0",

@@ -105,4 +103,4 @@ "markdown-toc": "^1.2.0",

"typescript": "^4.0.0",
"webpack": "^4.5.0",
"webpack-cli": "^3.1.1"
"webpack": "^5.20.0",
"webpack-cli": "^4.5.0"
},

@@ -109,0 +107,0 @@ "peerDependencies": {

# TypeScript loader for webpack
[![npm version](https://img.shields.io/npm/v/ts-loader.svg)](https://www.npmjs.com/package/ts-loader)
![GitHub build)](https://github.com/TypeStrong/ts-loader/workflows/Continuous%20Integration%20(build%20and%20test)/badge.svg)
[![build and test](https://github.com/TypeStrong/ts-loader/actions/workflows/push.yml/badge.svg)](https://github.com/TypeStrong/ts-loader/actions/workflows/push.yml)
[![Downloads](http://img.shields.io/npm/dm/ts-loader.svg)](https://npmjs.org/package/ts-loader)

@@ -130,21 +130,11 @@ [![node version](https://img.shields.io/node/v/ts-loader.svg)](https://www.npmjs.com/package/ts-loader)

`ts-loader` works very well in combination with [babel](https://babeljs.io/) and [babel-loader](https://github.com/babel/babel-loader). There is an [example](https://github.com/Microsoft/TypeScriptSamples/tree/master/react-flux-babel-karma) of this in the official [TypeScript Samples](https://github.com/Microsoft/TypeScriptSamples). Alternatively take a look at our own [example](examples/react-babel-karma-gulp).
`ts-loader` works very well in combination with [babel](https://babeljs.io/) and [babel-loader](https://github.com/babel/babel-loader). There is an [example](https://github.com/Microsoft/TypeScriptSamples/tree/master/react-flux-babel-karma) of this in the official [TypeScript Samples](https://github.com/Microsoft/TypeScriptSamples).
### Parallelising Builds
It's possible to parallelise your builds. Historically this was useful from a performance perspective with webpack 2 / 3. [With webpack 4+ there appears to be significantly less benefit and perhaps even cost.](https://blog.johnnyreilly.com/2018/12/you-might-not-need-thread-loader.html)
But if that's what you want to do, there's two ways to achieve this: [happypack](https://github.com/amireh/happypack) and [thread-loader](https://github.com/webpack-contrib/thread-loader). Both should be used in combination with [fork-ts-checker-webpack-plugin](https://github.com/Realytics/fork-ts-checker-webpack-plugin) for typechecking.)
To read more, look at [this post](https://medium.com/webpack/typescript-webpack-super-pursuit-mode-83cc568dea79) by [@johnny_reilly](https://twitter.com/johnny_reilly) on the webpack publication channel.
If you'd like find out further ways to improve your build using the watch API then take a look at [this post](https://medium.com/@kenneth_chau/speeding-up-webpack-typescript-incremental-builds-by-7x-3912ba4c1d15) by [@kenneth_chau](https://twitter.com/kenneth_chau).
### Compatibility
* TypeScript: 3.6.3+
* webpack: 4.x+ (please use `ts-loader` 3.x if you need webpack 2 or 3 support)
* node: 6.11.5 minimum (aligned with webpack 4)
* webpack: 5.x+ (please use `ts-loader` 8.x if you need webpack 4 support)
* node: 12.x+
A full test suite runs each night (and on each pull request). It runs both on [Linux](https://travis-ci.org/TypeStrong/ts-loader) and [Windows](https://ci.appveyor.com/project/JohnReilly/ts-loader), testing `ts-loader` against major releases of TypeScript. The test suite also runs against TypeScript@next (because we want to use it as much as you do).
A full test suite runs each night (and on each pull request). It runs both on Linux and Windows, testing `ts-loader` against major releases of TypeScript. The test suite also runs against TypeScript@next (because we want to use it as much as you do).

@@ -742,4 +732,4 @@ If you become aware of issues not caught by the test suite then please let us know. Better yet, write a test and submit it in a PR!

plugins: [
new webpack.WatchIgnorePlugin(
paths:{[
new webpack.WatchIgnorePlugin({
paths:[
/\.js$/,

@@ -746,0 +736,0 @@ /\.d\.ts$/

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc