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.4.1 to 9.4.2

3

CHANGELOG.md
# Changelog
## 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

@@ -4,0 +7,0 @@ * [Hotfix: Disable `enhanced-resolve`](https://github.com/TypeStrong/ts-loader/pull/1505) - thanks @manuth

@@ -16,2 +16,3 @@ import type * as typescript from 'typescript';

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;

48

dist/instances.js
"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");

@@ -219,20 +219,2 @@ const fs = require("fs");

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) {

@@ -248,3 +230,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

@@ -270,3 +252,3 @@ if (instance.solutionBuilderHost) {

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

@@ -277,3 +259,3 @@ else {

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

@@ -285,2 +267,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) {

@@ -287,0 +291,0 @@ // If resolveJsonModules is set, we should accept json files

@@ -13,3 +13,3 @@ import type * as typescript from 'typescript';

}
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
import { Chalk } from 'chalk';
import { LoaderOptions } from './interfaces';
declare type LoggerFunc = (message: string) => void;
type LoggerFunc = (message: string) => void;
export interface Logger {

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

import type * as webpack from 'webpack';
export declare function makeResolver(_options: webpack.WebpackOptionsNormalized): ResolveSync;
export declare type ResolveSync = {
export type ResolveSync = {
(context: any, path: string, moduleName: string): string | false;

@@ -5,0 +5,0 @@ (path: string, moduleName: string): string | false;

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

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 = {

@@ -426,2 +429,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;

@@ -433,2 +447,5 @@ },

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

@@ -435,0 +452,0 @@ writeFile: (name, text, writeByteOrderMark) => {

{
"name": "ts-loader",
"version": "9.4.1",
"version": "9.4.2",
"description": "TypeScript loader for webpack",

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

"rimraf": "^2.6.2",
"typescript": "^4.8.2",
"webpack": "^5.20.0",
"webpack-cli": "^4.5.0"
"typescript": "^4.9.3",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0"
},

@@ -101,0 +101,0 @@ "peerDependencies": {

@@ -36,3 +36,2 @@ # TypeScript loader for webpack

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

@@ -42,3 +41,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)

@@ -160,8 +159,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" }
]

@@ -736,3 +741,3 @@ }

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

@@ -746,3 +751,3 @@ ],

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

@@ -749,0 +754,0 @@ ],

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