Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ts-loader

Package Overview
Dependencies
Maintainers
1
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 0.3.2 to 0.3.3

6

CHANGELOG.md
# Changelog
## v0.3.3
- Add support for reporting errors in declaration files (#10)
- Add support for watch mode for declaration files (#11)
- Fix issue with extra `sourceMappingURL` in output files (#12)
## v0.3.2

@@ -4,0 +10,0 @@

56

index.js

@@ -16,3 +16,17 @@ ///<reference path="node_modules/typescript/bin/typescript.d.ts" />

var instances = {};
function ensureTypeScriptInstance(options) {
function consoleError(msg) {
setTimeout(function () { return console.log('ERROR' + os.EOL + msg); }, 0);
}
function handleErrors(diagnostics, outputFn) {
diagnostics.forEach(function (diagnostic) {
if (diagnostic.file) {
var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start);
outputFn(" " + diagnostic.file.filename.blue + " (" + lineChar.line.toString().cyan + "," + lineChar.character.toString().cyan + "): " + diagnostic.messageText.red);
}
else {
outputFn(" " + "unknown file".blue + ": " + diagnostic.messageText.red);
}
});
}
function ensureTypeScriptInstance(options, loader) {
var compiler = require(options.compiler);

@@ -78,3 +92,3 @@ var files = {};

var languageService = compiler.createLanguageService(servicesHost, compiler.createDocumentRegistry());
return instances[options.instance] = {
var instance = instances[options.instance] = {
compiler: compiler,

@@ -85,2 +99,23 @@ compilerOptions: compilerOptions,

};
handleErrors(languageService.getCompilerOptionsDiagnostics(), consoleError);
// handle errors for all declaration files at the end of each compilation
loader._compiler.plugin("done", function (stats) {
Object.keys(instance.files).filter(function (filePath) { return !!filePath.match(/\.d\.ts$/); }).forEach(function (filePath) {
handleErrors(languageService.getSyntacticDiagnostics(filePath).concat(languageService.getSemanticDiagnostics(filePath)), consoleError);
});
});
// manually update changed declaration files
loader._compiler.plugin("watch-run", function (watching, cb) {
var mtimes = watching.compiler.watchFileSystem.watcher.mtimes;
Object.keys(mtimes).filter(function (filePath) { return !!filePath.match(/\.d\.ts$/); }).forEach(function (filePath) {
filePath = path.normalize(filePath);
var file = instance.files[filePath];
if (file) {
file.text = fs.readFileSync(filePath, { encoding: 'utf8' });
file.version++;
}
});
cb();
});
return instance;
}

@@ -100,3 +135,3 @@ function loader(contents) {

options.additionalFiles = options.additionalFiles.map(function (filePath) { return path.resolve(_this.context, filePath); });
var instance = ensureTypeScriptInstance(options);
var instance = ensureTypeScriptInstance(options, this);
if (!Object.prototype.hasOwnProperty.call(instance.files, filePath)) {

@@ -116,12 +151,7 @@ var filePaths = Object.keys(instance.files);

file.version++;
this.clearDependencies();
this.addDependency(filePath);
Object.keys(instance.files).filter(function (filePath) { return !!filePath.match(/\.d\.ts$/); }).forEach(this.addDependency.bind(this));
var output = langService.getEmitOutput(filePath);
var diagnostics = langService.getCompilerOptionsDiagnostics().concat(langService.getSyntacticDiagnostics(filePath)).concat(langService.getSemanticDiagnostics(filePath)).forEach(function (diagnostic) {
if (diagnostic.file) {
var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start);
_this.emitError(" " + diagnostic.file.filename.blue + " (" + lineChar.line.toString().cyan + "," + lineChar.character.toString().cyan + "): " + diagnostic.messageText.red);
}
else {
_this.emitError(" " + "unknown file".blue + ": " + diagnostic.messageText.red);
}
});
handleErrors(langService.getSyntacticDiagnostics(filePath).concat(langService.getSemanticDiagnostics(filePath)), this.emitError.bind(this));
if (output.outputFiles.length == 0)

@@ -135,3 +165,3 @@ throw new Error("Typescript emitted no output for " + filePath);

sourceMap.sourcesContent = [contents];
contents = output.outputFiles[1].text;
contents = output.outputFiles[1].text.replace(/^\/\/# sourceMappingURL=[^\r\n]*/gm, '');
}

@@ -138,0 +168,0 @@ else {

{
"name": "ts-loader",
"version": "0.3.2",
"version": "0.3.3",
"description": "TypeScript loader for webpack",

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

@@ -11,2 +11,7 @@ # TypeScript loader for webpack

### Running
Use webpack like normal, including `webpack --watch` and `webpack-dev-server`, or through another
build system using the [Node.js API](http://webpack.github.io/docs/node.js-api.html).
### Configuration

@@ -30,2 +35,3 @@

```
#### Options

@@ -32,0 +38,0 @@

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