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.4 to 9.5.0

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.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

@@ -4,0 +7,0 @@ * [Bug fix: let users override skipLibCheck](https://github.com/TypeStrong/ts-loader/pull/1617) - thanks @haakonflatval-cognite

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

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

@@ -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;

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 === undefined) {
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';
/**

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

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 {

@@ -5,0 +5,0 @@ code: number;

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

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

@@ -4,0 +4,0 @@ export interface Logger {

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

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

import { Chalk } from 'chalk';
/// <reference types="node" />
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';
/**

@@ -13,3 +14,3 @@ * Take TypeScript errors, parse them and format to webpack errors

}, context: string): webpack.WebpackError[];
export declare function fsReadFile(fileName: string, encoding?: typescript.BufferEncoding | undefined): string | undefined;
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;

@@ -16,0 +17,0 @@ export declare function tsLoaderSource(loaderOptions: LoaderOptions): string;

@@ -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.4.4",
"version": "9.5.0",
"description": "TypeScript loader for webpack",

@@ -60,3 +60,4 @@ "main": "index.js",

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

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

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

@@ -98,3 +99,3 @@ "babel-core": "^6.0.0",

"rimraf": "^2.6.2",
"typescript": "^5.1.3",
"typescript": "^5.2.2",
"webpack": "^5.74.0",

@@ -101,0 +102,0 @@ "webpack-cli": "^4.10.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

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