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 9.3.1 to 9.5.1

renovate.json

1

.eslintrc.js

@@ -33,2 +33,3 @@ module.exports = {

// '@typescript-eslint/no-namespace': 'off' // maybe we should consider enabling it in the future
'@typescript-eslint/consistent-type-imports': 'error', // the replacement of "importsNotUsedAsValues": "error"
},

@@ -35,0 +36,0 @@ },

# Changelog
## 9.5.1
* [fix: inputSourceMap can be null](https://github.com/TypeStrong/ts-loader/pull/1639) [#1638] - thanks @johnnyreilly and @michaeltford
## 9.5.0
* [Feature: map the input source map in case ts-loader is used in a loader pipeline](https://github.com/TypeStrong/ts-loader/pull/1626) - thanks @Ka0o0 and @bojanv55
## 9.4.4
* [Bug fix: let users override skipLibCheck](https://github.com/TypeStrong/ts-loader/pull/1617) - thanks @haakonflatval-cognite
## 9.4.3
* [Bug fix: add config file as build dependency](https://github.com/TypeStrong/ts-loader/pull/1611) - thanks @alexander-akait
## 9.4.2
* [Bug fix: Use custom transformer when building solution references](https://github.com/TypeStrong/ts-loader/pull/1550) [#1025] - thanks @feosuna1
## 9.4.1
* [Hotfix: Disable `enhanced-resolve`](https://github.com/TypeStrong/ts-loader/pull/1505) - thanks @manuth
## v9.4.0
* [Add Support for Resolving `.cjs`, `.mjs`, `.cts` and `.mts` Files](https://github.com/TypeStrong/ts-loader/pull/1503) [#1503] - thanks @manuth
## v9.3.1

@@ -4,0 +26,0 @@

2

dist/after-compile.d.ts
import * as webpack from 'webpack';
import { TSInstance } from './interfaces';
import type { TSInstance } from './interfaces';
/**

@@ -4,0 +4,0 @@ * This returns a function that has options to add assets and also to provide errors to webpack

import type * as typescript from 'typescript';
import { LoaderOptions } from './interfaces';
import * as logger from './logger';
import type { LoaderOptions } from './interfaces';
import type * as logger from './logger';
export declare function getCompiler(loaderOptions: LoaderOptions, log: logger.Logger): {

@@ -10,3 +10,5 @@ compiler: typeof typescript | undefined;

};
export declare function getCompilerOptions(configParseResult: typescript.ParsedCommandLine, compiler: typeof typescript): typescript.CompilerOptions;
export declare function getCompilerOptions(configParseResult: typescript.ParsedCommandLine, compiler: typeof typescript): {
skipLibCheck: boolean;
} & typescript.CompilerOptions;
//# sourceMappingURL=compilerSetup.d.ts.map

@@ -45,4 +45,4 @@ "use strict";

function getCompilerOptions(configParseResult, compiler) {
const compilerOptions = Object.assign({}, configParseResult.options, {
skipLibCheck: true,
const defaultOptions = { skipLibCheck: true };
const compilerOptions = Object.assign(defaultOptions, configParseResult.options, {
suppressOutputPathCheck: true, // This is why: https://github.com/Microsoft/TypeScript/issues/7363

@@ -49,0 +49,0 @@ });

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

import { Chalk } from 'chalk';
import type { Chalk } from 'chalk';
import type * as typescript from 'typescript';
import * as webpack from 'webpack';
import { LoaderOptions } from './interfaces';
import * as logger from './logger';
import type * as webpack from 'webpack';
import type { LoaderOptions } from './interfaces';
import type * as logger from './logger';
interface ConfigFile {

@@ -7,0 +7,0 @@ config?: any;

@@ -9,2 +9,3 @@ export declare const EOL: string;

export declare const tsTsxRegex: RegExp;
export declare const declarationRegex: RegExp;
export declare const dtsDtsxOrDtsDtsxMapRegex: RegExp;

@@ -11,0 +12,0 @@ export declare const dtsTsTsxRegex: RegExp;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.nodeModules = exports.jsonRegex = exports.jsJsxMap = exports.jsJsx = exports.tsTsxJsJsxRegex = exports.dtsTsTsxJsJsxRegex = exports.dtsTsTsxRegex = exports.dtsDtsxOrDtsDtsxMapRegex = exports.tsTsxRegex = exports.tsxRegex = exports.extensionRegex = exports.LineFeedCode = exports.CarriageReturnLineFeedCode = exports.LineFeed = exports.CarriageReturnLineFeed = exports.EOL = void 0;
exports.nodeModules = exports.jsonRegex = exports.jsJsxMap = exports.jsJsx = exports.tsTsxJsJsxRegex = exports.dtsTsTsxJsJsxRegex = exports.dtsTsTsxRegex = exports.dtsDtsxOrDtsDtsxMapRegex = exports.declarationRegex = exports.tsTsxRegex = exports.tsxRegex = exports.extensionRegex = exports.LineFeedCode = exports.CarriageReturnLineFeedCode = exports.LineFeed = exports.CarriageReturnLineFeed = exports.EOL = void 0;
const os = require("os");

@@ -12,11 +12,12 @@ exports.EOL = os.EOL;

exports.tsxRegex = /\.tsx$/i;
exports.tsTsxRegex = /\.ts(x?)$/i;
exports.dtsDtsxOrDtsDtsxMapRegex = /\.d\.ts(x?)(\.map)?$/i;
exports.dtsTsTsxRegex = /(\.d)?\.ts(x?)$/i;
exports.dtsTsTsxJsJsxRegex = /((\.d)?\.ts(x?)|js(x?))$/i;
exports.tsTsxJsJsxRegex = /\.tsx?$|\.jsx?$/i;
exports.jsJsx = /\.js(x?)$/i;
exports.jsJsxMap = /\.js(x?)\.map$/i;
exports.tsTsxRegex = /\.([cm]?ts|tsx)$/i;
exports.declarationRegex = /\.d\.([cm]?ts|tsx)$/i;
exports.dtsDtsxOrDtsDtsxMapRegex = /\.d\.([cm]?ts|tsx)(\.map)?$/i;
exports.dtsTsTsxRegex = /(\.d)?\.([cm]?ts|tsx)$/i;
exports.dtsTsTsxJsJsxRegex = /((\.d)?\.([cm]?[tj]s|[tj]sx))$/i;
exports.tsTsxJsJsxRegex = /\.([cm]?[tj]s|[tj]sx)$/i;
exports.jsJsx = /\.([cm]?js|jsx)$/i;
exports.jsJsxMap = /\.([cm]?js|jsx)\.map$/i;
exports.jsonRegex = /\.json$/i;
exports.nodeModules = /node_modules/i;
//# sourceMappingURL=constants.js.map
import type * as webpack from 'webpack';
import { LoaderOptions } from './interfaces';
import type { LoaderOptions } from './interfaces';
/**
* The entry point for ts-loader
*/
declare function loader(this: webpack.LoaderContext<LoaderOptions>, contents: string): void;
declare function loader(this: webpack.LoaderContext<LoaderOptions>, contents: string, inputSourceMap?: Record<string, any>): void;
export = loader;

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

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

const utils_1 = require("./utils");
const source_map_1 = require("source-map");
const loaderOptionsCache = {};

@@ -12,3 +13,3 @@ /**

*/
function loader(contents) {
function loader(contents, inputSourceMap) {
this.cacheable && this.cacheable();

@@ -24,5 +25,5 @@ const callback = this.async();

(0, instances_1.buildSolutionReferences)(instance, this);
successLoader(this, contents, callback, instance);
successLoader(this, contents, callback, instance, inputSourceMap);
}
function successLoader(loaderContext, contents, callback, instance) {
function successLoader(loaderContext, contents, callback, instance, inputSourceMap) {
(0, instances_1.initializeInstance)(loaderContext, instance);

@@ -42,5 +43,7 @@ (0, instances_1.reportTranspileErrors)(instance, loaderContext);

: getEmit(rawFilePath, filePath, instance, loaderContext);
makeSourceMapAndFinish(sourceMapText, outputText, filePath, contents, loaderContext, fileVersion, callback, instance);
// the following function is async, which means it will immediately return and run in the "background"
// Webpack will be notified when it's finished when the function calls the `callback` method
makeSourceMapAndFinish(sourceMapText, outputText, filePath, contents, loaderContext, fileVersion, callback, instance, inputSourceMap);
}
function makeSourceMapAndFinish(sourceMapText, outputText, filePath, contents, loaderContext, fileVersion, callback, instance) {
function makeSourceMapAndFinish(sourceMapText, outputText, filePath, contents, loaderContext, fileVersion, callback, instance, inputSourceMap) {
if (outputText === null || outputText === undefined) {

@@ -61,3 +64,21 @@ setModuleMeta(loaderContext, instance, fileVersion);

setModuleMeta(loaderContext, instance, fileVersion);
callback(null, output, sourceMap);
// there are two cases where we don't need to perform input source map mapping:
// - either the ts-compiler did not generate a source map (tsconfig had `sourceMap` set to false)
// - or we did not get an input source map
//
// in the first case, we simply return undefined.
// in the second case we only need to return the newly generated source map
// this avoids that we have to make a possibly expensive call to the source-map lib
if (sourceMap === undefined || !inputSourceMap) {
callback(null, output, sourceMap);
return;
}
// otherwise we have to make a mapping to the input source map which is asynchronous
mapToInputSourceMap(sourceMap, loaderContext, inputSourceMap)
.then(mappedSourceMap => {
callback(null, output, mappedSourceMap);
})
.catch((e) => {
callback(e);
});
}

@@ -430,3 +451,40 @@ function setModuleMeta(loaderContext, instance, fileVersion) {

}
/**
* This method maps the newly generated @param{sourceMap} to the input source map.
* This is required when ts-loader is not the first loader in the Webpack loader chain.
*/
function mapToInputSourceMap(sourceMap, loaderContext, inputSourceMap) {
return new Promise((resolve, reject) => {
const inMap = {
file: loaderContext.remainingRequest,
mappings: inputSourceMap.mappings,
names: inputSourceMap.names,
sources: inputSourceMap.sources,
sourceRoot: inputSourceMap.sourceRoot,
sourcesContent: inputSourceMap.sourcesContent,
version: inputSourceMap.version,
};
Promise.all([
new source_map_1.SourceMapConsumer(inMap),
new source_map_1.SourceMapConsumer(sourceMap),
])
.then(sourceMapConsumers => {
try {
const generator = source_map_1.SourceMapGenerator.fromSourceMap(sourceMapConsumers[1]);
generator.applySourceMap(sourceMapConsumers[0]);
const mappedSourceMap = generator.toJSON();
// before resolving, we free memory by calling destroy on the source map consumers
sourceMapConsumers.forEach(sourceMapConsumer => sourceMapConsumer.destroy());
resolve(mappedSourceMap);
}
catch (e) {
//before rejecting, we free memory by calling destroy on the source map consumers
sourceMapConsumers.forEach(sourceMapConsumer => sourceMapConsumer.destroy());
reject(e);
}
})
.catch(reject);
});
}
module.exports = loader;
//# sourceMappingURL=index.js.map

@@ -1,5 +0,5 @@

import * as webpack from 'webpack';
import { TSInstance } from './interfaces';
import type * as webpack from 'webpack';
import type { TSInstance } from './interfaces';
export declare function getTSInstanceFromCache(key: webpack.Compiler, name: string): TSInstance | undefined;
export declare function setTSInstanceInCache(key: webpack.Compiler | undefined, name: string, instance: TSInstance): void;
//# sourceMappingURL=instance-cache.d.ts.map
import type * as typescript from 'typescript';
import * as webpack from 'webpack';
import { LoaderOptions, TSInstance } from './interfaces';
import type { LoaderOptions, TSInstance } from './interfaces';
/**

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

export declare function initializeInstance(loader: webpack.LoaderContext<LoaderOptions>, instance: TSInstance): void;
export declare function getCustomTransformers(loaderOptions: LoaderOptions, program: typescript.Program | undefined, getProgram: (() => typescript.Program | undefined) | undefined): any;
export declare function reportTranspileErrors(instance: TSInstance, loader: webpack.LoaderContext<LoaderOptions>): void;

@@ -18,0 +19,0 @@ export declare function buildSolutionReferences(instance: TSInstance, loader: webpack.LoaderContext<LoaderOptions>): void;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getEmitOutput = exports.getEmitFromWatchHost = exports.getInputFileNameFromOutput = exports.getOutputFileNames = exports.forEachResolvedProjectReference = exports.buildSolutionReferences = exports.reportTranspileErrors = exports.initializeInstance = exports.getTypeScriptInstance = void 0;
exports.getEmitOutput = exports.getEmitFromWatchHost = exports.getInputFileNameFromOutput = exports.getOutputFileNames = exports.forEachResolvedProjectReference = exports.buildSolutionReferences = exports.reportTranspileErrors = exports.getCustomTransformers = exports.initializeInstance = exports.getTypeScriptInstance = void 0;
const chalk = require("chalk");

@@ -82,2 +82,5 @@ const fs = require("fs");

const { configFilePath, configFile } = configFileAndPath;
if (configFilePath) {
loader.addBuildDependency(configFilePath);
}
const filePathKeyMapper = createFilePathKeyMapper(compiler, loaderOptions);

@@ -220,20 +223,2 @@ if (configFilePath && loaderOptions.projectReferences) {

instance.initialSetupPending = false;
// same strategy as https://github.com/s-panferov/awesome-typescript-loader/pull/531/files
let { getCustomTransformers: customerTransformers } = instance.loaderOptions;
let getCustomTransformers = Function.prototype;
if (typeof customerTransformers === 'function') {
getCustomTransformers = customerTransformers;
}
else if (typeof customerTransformers === 'string') {
try {
customerTransformers = require(customerTransformers);
}
catch (err) {
throw new Error(`Failed to load customTransformers from "${instance.loaderOptions.getCustomTransformers}": ${err instanceof Error ? err.message : 'unknown error'}`);
}
if (typeof customerTransformers !== 'function') {
throw new Error(`Custom transformers in "${instance.loaderOptions.getCustomTransformers}" should export a function, got ${typeof customerTransformers}`);
}
getCustomTransformers = customerTransformers;
}
if (instance.loaderOptions.transpileOnly) {

@@ -249,3 +234,3 @@ const program = (instance.program =

const getProgram = () => program;
instance.transformers = getCustomTransformers(program, getProgram);
instance.transformers = getCustomTransformers(instance.loaderOptions, program, getProgram);
// Setup watch run for solution building

@@ -271,3 +256,3 @@ if (instance.solutionBuilderHost) {

instance.program = getProgram();
instance.transformers = getCustomTransformers(instance.program, getProgram);
instance.transformers = getCustomTransformers(instance.loaderOptions, instance.program, getProgram);
}

@@ -278,3 +263,3 @@ else {

const getProgram = () => instance.languageService.getProgram();
instance.transformers = getCustomTransformers(getProgram(), getProgram);
instance.transformers = getCustomTransformers(instance.loaderOptions, getProgram(), getProgram);
}

@@ -286,2 +271,24 @@ addAssetHooks(loader, instance);

exports.initializeInstance = initializeInstance;
function getCustomTransformers(loaderOptions, program, getProgram) {
// same strategy as https://github.com/s-panferov/awesome-typescript-loader/pull/531/files
let { getCustomTransformers: customerTransformers } = loaderOptions;
let getCustomTransformers = Function.prototype;
if (typeof customerTransformers === 'function') {
getCustomTransformers = customerTransformers;
}
else if (typeof customerTransformers === 'string') {
try {
customerTransformers = require(customerTransformers);
}
catch (err) {
throw new Error(`Failed to load customTransformers from "${loaderOptions.getCustomTransformers}": ${err instanceof Error ? err.message : 'unknown error'}`);
}
if (typeof customerTransformers !== 'function') {
throw new Error(`Custom transformers in "${loaderOptions.getCustomTransformers}" should export a function, got ${typeof customerTransformers}`);
}
getCustomTransformers = customerTransformers;
}
return getCustomTransformers(program, getProgram);
}
exports.getCustomTransformers = getCustomTransformers;
function getScriptRegexp(instance) {

@@ -292,9 +299,9 @@ // If resolveJsonModules is set, we should accept json files

return instance.configParseResult.options.allowJs === true
? /\.tsx?$|\.json$|\.jsx?$/i
: /\.tsx?$|\.json$/i;
? /\.([cm]?[tj]s|[tj]sx|json)$/i
: /\.([cm]?ts|tsx|json)$/i;
}
// if allowJs is set then we should accept js(x) files
return instance.configParseResult.options.allowJs === true
? /\.tsx?$|\.jsx?$/i
: /\.tsx?$/i;
? /\.([cm]?[tj]s|[tj]sx)$/i
: /\.([cm]?ts|tsx)$/i;
}

@@ -415,3 +422,3 @@ function reportTranspileErrors(instance, loader) {

function getInputFileNameFromOutput(instance, filePath) {
if (filePath.match(constants_1.tsTsxRegex) && !fileExtensionIs(filePath, '.d.ts')) {
if (filePath.match(constants_1.tsTsxRegex) && !constants_1.declarationRegex.test(filePath)) {
return undefined;

@@ -418,0 +425,0 @@ }

import type * as typescript from 'typescript';
import { Chalk } from 'chalk';
import * as logger from './logger';
import type { Chalk } from 'chalk';
import type * as logger from './logger';
export interface ErrorInfo {

@@ -13,3 +13,3 @@ code: number;

}
export declare type FileLocation = {
export type FileLocation = {
/** 1-based */

@@ -50,3 +50,3 @@ line: number;

}
export declare type WatchCallbacks<T> = Map<FilePathKey, {
export type WatchCallbacks<T> = Map<FilePathKey, {
fileName: string;

@@ -70,3 +70,3 @@ callbacks: T[];

}
export declare type FilePathKey = string & {
export type FilePathKey = string & {
__filePathKeyBrand: any;

@@ -172,8 +172,8 @@ };

}
export declare type DependencyGraph = Map<FilePathKey, ResolvedModule[]>;
export declare type ReverseDependencyGraph = Map<FilePathKey, Map<FilePathKey, true>>;
export declare type LogLevel = 'INFO' | 'WARN' | 'ERROR';
export declare type ResolveModuleName = (moduleName: string, containingFile: string, compilerOptions: typescript.CompilerOptions, moduleResolutionHost: typescript.ModuleResolutionHost) => typescript.ResolvedModuleWithFailedLookupLocations;
export declare type CustomResolveModuleName = (moduleName: string, containingFile: string, compilerOptions: typescript.CompilerOptions, moduleResolutionHost: typescript.ModuleResolutionHost, parentResolver: ResolveModuleName) => typescript.ResolvedModuleWithFailedLookupLocations;
export declare type CustomResolveTypeReferenceDirective = (typeDirectiveName: string, containingFile: string, compilerOptions: typescript.CompilerOptions, moduleResolutionHost: typescript.ModuleResolutionHost, parentResolver: typeof typescript.resolveTypeReferenceDirective) => typescript.ResolvedTypeReferenceDirectiveWithFailedLookupLocations;
export type DependencyGraph = Map<FilePathKey, ResolvedModule[]>;
export type ReverseDependencyGraph = Map<FilePathKey, Map<FilePathKey, true>>;
export type LogLevel = 'INFO' | 'WARN' | 'ERROR';
export type ResolveModuleName = (moduleName: string, containingFile: string, compilerOptions: typescript.CompilerOptions, moduleResolutionHost: typescript.ModuleResolutionHost) => typescript.ResolvedModuleWithFailedLookupLocations;
export type CustomResolveModuleName = (moduleName: string, containingFile: string, compilerOptions: typescript.CompilerOptions, moduleResolutionHost: typescript.ModuleResolutionHost, parentResolver: ResolveModuleName) => typescript.ResolvedModuleWithFailedLookupLocations;
export type CustomResolveTypeReferenceDirective = (typeDirectiveName: string, containingFile: string, compilerOptions: typescript.CompilerOptions, moduleResolutionHost: typescript.ModuleResolutionHost, parentResolver: typeof typescript.resolveTypeReferenceDirective) => typescript.ResolvedTypeReferenceDirectiveWithFailedLookupLocations;
export interface LoaderOptions {

@@ -221,3 +221,3 @@ silent: boolean;

/** where key is filepath */
export declare type TSFiles = Map<FilePathKey, TSFile>;
export type TSFiles = Map<FilePathKey, TSFile>;
export interface ResolvedModule {

@@ -239,4 +239,4 @@ originalFileName: string;

}
export declare type Severity = 'error' | 'warning';
export type Severity = 'error' | 'warning';
export {};
//# sourceMappingURL=interfaces.d.ts.map

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

import { Chalk } from 'chalk';
import { LoaderOptions } from './interfaces';
declare type LoggerFunc = (message: string) => void;
import type { Chalk } from 'chalk';
import type { LoaderOptions } from './interfaces';
type LoggerFunc = (message: string) => void;
export interface Logger {

@@ -5,0 +5,0 @@ log: LoggerFunc;

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

LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
})(LogLevel = exports.LogLevel || (exports.LogLevel = {}));
})(LogLevel || (exports.LogLevel = LogLevel = {}));
const stderrConsole = new console_1.Console(process.stderr);

@@ -13,0 +13,0 @@ const stdoutConsole = new console_1.Console(process.stdout);

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;
export declare function makeResolver(_options: webpack.WebpackOptionsNormalized): ResolveSync;
export type ResolveSync = {
(context: any, path: string, moduleName: string): string | false;
(path: string, moduleName: string): string | false;
};
//# sourceMappingURL=resolver.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeResolver = void 0;
const enhanced_resolve_1 = require("enhanced-resolve");
function makeResolver(options) {
return enhanced_resolve_1.create.sync(options.resolve);
function makeResolver(_options) {
/* Currently, `enhanced-resolve` does not work properly alongside `ts-loader`.
* This feature is disabled until a proper worflow has been worked out. */
return (_context, _path, _moduleName) => {
throw new Error();
};
}
exports.makeResolver = makeResolver;
//# sourceMappingURL=resolver.js.map
import type * as typescript from 'typescript';
import * as webpack from 'webpack';
import { FilePathKey, LoaderOptions, ServiceHostWhichMayBeCacheable, SolutionBuilderWithWatchHost, TSInstance, WatchHost } from './interfaces';
import type * as webpack from 'webpack';
import type { FilePathKey, LoaderOptions, ServiceHostWhichMayBeCacheable, SolutionBuilderWithWatchHost, TSInstance, WatchHost } from './interfaces';
/**

@@ -5,0 +5,0 @@ * Create the TypeScript language service

@@ -122,4 +122,4 @@ "use strict";

const resolveModuleName = makeResolveModuleName(compiler, compilerOptions, moduleResolutionHost, customResolveModuleName, instance);
const resolveModuleNames = (moduleNames, containingFile, _reusedNames, redirectedReference) => {
const resolvedModules = moduleNames.map(moduleName => resolveModule(resolveSync, resolveModuleName, appendTsTsxSuffixesIfRequired, scriptRegex, moduleName, containingFile, redirectedReference));
const resolveModuleNames = (moduleNames, containingFile, _reusedNames, redirectedReference, _, containingSourceFile) => {
const resolvedModules = moduleNames.map(moduleName => resolveModule(resolveSync, resolveModuleName, appendTsTsxSuffixesIfRequired, scriptRegex, moduleName, containingFile, redirectedReference, containingSourceFile));
(0, utils_1.populateDependencyGraph)(resolvedModules, instance, containingFile);

@@ -416,2 +416,5 @@ return resolvedModules;

const sysHost = compiler.createSolutionBuilderWithWatchHost(compiler.sys, compiler.createEmitAndSemanticDiagnosticsBuilderProgram, reportDiagnostic, reportSolutionBuilderStatus, reportWatchStatus);
// Keeps track of the various `typescript.CustomTransformers` for each program that is created.
const customTransformers = new Map();
// let lastBuilderProgram: typescript.CreateProgram | undefined = undefined;
const solutionBuilderHost = {

@@ -427,2 +430,13 @@ ...sysHost,

(_d = instance.moduleResolutionCache) === null || _d === void 0 ? void 0 : _d.update(instance.compilerOptions);
if (options) {
// The `configFilePath` is the same value that is used as the `project` parameter of
// `getCustomtransformers` below.
const project = options.configFilePath;
if (typeof project === "string") {
// Custom transformers need a reference to the `typescript.Program`, that reference is
// unavailable during the the `getCustomTransformers` callback below.
const transformers = (0, instances_1.getCustomTransformers)(instance.loaderOptions, result.getProgram(), result.getProgram);
customTransformers.set(project, transformers);
}
}
return result;

@@ -434,2 +448,5 @@ },

...createWatchFactory(filePathKeyMapper, compiler),
getCustomTransformers: function (project) {
return customTransformers.get(project);
},
// Overrides

@@ -736,6 +753,6 @@ writeFile: (name, text, writeByteOrderMark) => {

}
function resolveModule(resolveSync, resolveModuleName, appendTsTsxSuffixesIfRequired, scriptRegex, moduleName, containingFile, redirectedReference) {
function resolveModule(resolveSync, resolveModuleName, appendTsTsxSuffixesIfRequired, scriptRegex, moduleName, containingFile, redirectedReference, containingSourceFile) {
let resolutionResult;
try {
const originalFileName = resolveSync(undefined, path.normalize(path.dirname(containingFile)), moduleName);
const originalFileName = resolveSync(path.normalize(path.dirname(containingFile)), moduleName);
if (originalFileName) {

@@ -749,3 +766,3 @@ const resolvedFileName = appendTsTsxSuffixesIfRequired(originalFileName);

catch (e) { }
const tsResolution = resolveModuleName(moduleName, containingFile, redirectedReference);
const tsResolution = resolveModuleName(moduleName, containingFile, redirectedReference, containingSourceFile);
if (tsResolution.resolvedModule !== undefined) {

@@ -772,3 +789,3 @@ const resolvedFileName = path.normalize(tsResolution.resolvedModule.resolvedFileName);

}
return (moduleName, containingFile, redirectedReference) => compiler.resolveModuleName(moduleName, containingFile, compilerOptions, moduleResolutionHost, instance.moduleResolutionCache, redirectedReference);
return (moduleName, containingFileName, redirectedReference, containingFile) => compiler.resolveModuleName(moduleName, containingFileName, compilerOptions, moduleResolutionHost, instance.moduleResolutionCache, redirectedReference, containingFile === null || containingFile === void 0 ? void 0 : containingFile.impliedNodeFormat);
}

@@ -775,0 +792,0 @@ return (moduleName, containingFile) => customResolveModuleName(moduleName, containingFile, compilerOptions, moduleResolutionHost, compiler.resolveModuleName);

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

@@ -7,0 +7,0 @@ * Take TypeScript errors, parse them and format to webpack errors

@@ -1,3 +0,3 @@

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

@@ -4,0 +4,0 @@ * Make function which will manually update changed files

{
"name": "ts-loader",
"version": "9.3.1",
"version": "9.5.1",
"description": "TypeScript loader for webpack",

@@ -46,5 +46,5 @@ "main": "index.js",

},
"author": "John Reilly <johnny_reilly@hotmail.com> (https://blog.johnnyreilly.com)",
"author": "John Reilly <johnny_reilly@hotmail.com> (https://johnnyreilly.com)",
"contributors": [
"John Reilly <johnny_reilly@hotmail.com> (https://blog.johnnyreilly.com)",
"John Reilly <johnny_reilly@hotmail.com> (https://johnnyreilly.com)",
"James Brantly <james@jbrantly.com> (http://www.jbrantly.com/)"

@@ -61,3 +61,4 @@ ],

"micromatch": "^4.0.0",
"semver": "^7.3.4"
"semver": "^7.3.4",
"source-map": "^0.7.4"
},

@@ -68,4 +69,4 @@ "devDependencies": {

"@types/semver": "^7.3.4",
"@typescript-eslint/eslint-plugin": "^4.0.0",
"@typescript-eslint/parser": "^4.0.0",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"babel": "^6.0.0",

@@ -79,10 +80,10 @@ "babel-core": "^6.0.0",

"escape-string-regexp": "^2.0.0",
"eslint": "^7.1.0",
"eslint": "^8.0.0",
"eslint-config-prettier": "^8.0.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.1.3",
"fs-extra": "^9.0.0",
"eslint-plugin-prettier": "^4.0.0",
"fs-extra": "^11.0.0",
"glob": "^7.1.1",
"husky": "^2.0.0",
"jasmine-core": "^3.0.0",
"husky": "^8.0.0",
"jasmine-core": "^4.0.0",
"karma": "^6.0.0",

@@ -92,3 +93,3 @@ "karma-chrome-launcher": "^3.1.0",

"karma-mocha-reporter": "^2.0.0",
"karma-sourcemap-loader": "^0.3.8",
"karma-sourcemap-loader": "^0.4.0",
"karma-webpack": "^5.0.0",

@@ -101,5 +102,5 @@ "lint-staged": "^8.0.0",

"rimraf": "^2.6.2",
"typescript": "^4.7.3",
"webpack": "^5.20.0",
"webpack-cli": "^4.5.0"
"typescript": "^5.2.2",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0"
},

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

@@ -5,3 +5,3 @@ # TypeScript loader for webpack

[![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)
[![Downloads](https://img.shields.io/npm/dm/ts-loader.svg)](https://npmjs.org/package/ts-loader)
[![node version](https://img.shields.io/node/v/ts-loader.svg)](https://www.npmjs.com/package/ts-loader)

@@ -37,3 +37,2 @@ [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)

* [Babel](#babel)
* [Parallelising Builds](#parallelising-builds)
* [Compatibility](#compatibility)

@@ -43,3 +42,3 @@ * [Configuration](#configuration)

* [Code Splitting and Loading Other Resources](#code-splitting-and-loading-other-resources)
* [Declarations (.d.ts)](#declarations-dts)
* [Declarations (.d.ts)](#declaration-files-dts)
* [Failing the build on TypeScript compilation error](#failing-the-build-on-typescript-compilation-error)

@@ -161,8 +160,14 @@ * [`baseUrl` / `paths` module resolution](#baseurl--paths-module-resolution)

// Add `.ts` and `.tsx` as a resolvable extension.
extensions: [".ts", ".tsx", ".js"]
extensions: [".ts", ".tsx", ".js"],
// Add support for TypeScripts fully qualified ESM imports.
extensionAlias: {
".js": [".js", ".ts"],
".cjs": [".cjs", ".cts"],
".mjs": [".mjs", ".mts"]
}
},
module: {
rules: [
// all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
{ test: /\.tsx?$/, loader: "ts-loader" }
// all files with a `.ts`, `.cts`, `.mts` or `.tsx` extension will be handled by `ts-loader`
{ test: /\.([cm]?ts|tsx)$/, loader: "ts-loader" }
]

@@ -226,6 +231,10 @@ }

### Declarations (.d.ts)
### Declaration Files (.d.ts)
To output a built .d.ts file, you can set `"declaration": true` in your tsconfig, and use the [DeclarationBundlerPlugin](https://www.npmjs.com/package/declaration-bundler-webpack-plugin) in your webpack config.
To output declaration files (.d.ts), you can set "declaration": true in your tsconfig and set "transpileOnly" to false.
If you use ts-loader with "transpileOnly": true along with [fork-ts-checker-webpack-plugin](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin), you will need to configure fork-ts-checker-webpack-plugin to output definition files, you can learn more on the plugin's documentation page: https://github.com/TypeStrong/fork-ts-checker-webpack-plugin#typescript-options
To output a built .d.ts file, you can use the [DeclarationBundlerPlugin](https://www.npmjs.com/package/types-webpack-bundler) in your webpack config.
### Failing the build on TypeScript compilation error

@@ -734,3 +743,3 @@

/\.js$/,
/\.d\.ts$/
/\.d\.[cm]?ts$/
])

@@ -744,3 +753,3 @@ ],

/\.js$/,
/\.d\.ts$/
/\.d\.[cm]ts$/
]})

@@ -767,3 +776,3 @@ ],

`ts-loader` was started by [James Brantly](https://github.com/jbrantly), since 2016 [John Reilly](https://github.com/johnnyreilly) has been taking good care of it. If you're interested, you can [read more about how that came to pass](https://blog.johnnyreilly.com/2016/11/01/but-you-cant-die-i-love-you-ts-loader).
`ts-loader` was started by [James Brantly](https://github.com/jbrantly), since 2016 [John Reilly](https://github.com/johnnyreilly) has been taking good care of it. If you're interested, you can [read more about how that came to pass](https://johnnyreilly.com/but-you-cant-die-i-love-you-ts-loader).

@@ -770,0 +779,0 @@ ## License

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

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