New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@nevware21/grunt-ts-plugin

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nevware21/grunt-ts-plugin - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

CHANGELOG.md

12

package.json
{
"name": "@nevware21/grunt-ts-plugin",
"description": "TypeScript Compilation Plugin for GruntJS",
"version": "0.1.0",
"version": "0.2.0",
"homepage": "https://github.com/nevware21/grunt-plugins",

@@ -14,7 +14,9 @@ "author": {

"typescript",
"task"
"task",
"compiler",
"build"
],
"scripts": {
"clean": "grunt clean",
"build": "grunt ts_plugin && npm run package",
"build": "grunt ts_plugin --verbose && npm run package",
"rebuild": "npm run build",

@@ -35,3 +37,3 @@ "package": "rollup -c rollup.config.js",

"type": "MIT",
"url": "https://github.com/nevware21/grunt-plugins/blob/master/LICENSE-MIT"
"url": "https://github.com/nevware21/grunt-plugins/blob/master/LICENSE"
}

@@ -46,3 +48,3 @@ ],

"@types/grunt": "0.4.25",
"@nevware21/grunt-plugins-shared-utils": "0.0.1",
"@nevware21/grunt-plugins-shared-utils": "0.2.0",
"grunt": "^1.4.0",

@@ -49,0 +51,0 @@ "grunt-cli": "^1.4.3",

@@ -205,3 +205,3 @@ 'use strict';

function findCommonPath(paths, seperator) {
var commonPath = findCommonRoot(paths);
var commonPath = findCommonRoot(paths.map(function (value) { return normalizePath(value); }));
var endIdx = -1;

@@ -221,2 +221,8 @@ if (commonPath) {

}
function normalizePath(path) {
if (path) {
return path.replace(/\\/g, "/");
}
return path || "";
}

@@ -230,2 +236,32 @@ /*

*/
var ErrorHandlerResponse;
(function (ErrorHandlerResponse) {
/**
* The handler did not identify whether this should be treated as an error, warning or ignore.
* So follow normal built in handling.
* Null and undefined responses are treated the same as this value
*/
ErrorHandlerResponse[ErrorHandlerResponse["Undefined"] = 0] = "Undefined";
/**
* Ignore this error with no logging
*/
ErrorHandlerResponse[ErrorHandlerResponse["Ignore"] = 1] = "Ignore";
/**
* Include the error in the log, but don't treat as an error or warning
*/
ErrorHandlerResponse[ErrorHandlerResponse["Silent"] = 2] = "Silent";
/**
* Treat as an error and fail the build
*/
ErrorHandlerResponse[ErrorHandlerResponse["Error"] = 3] = "Error";
})(ErrorHandlerResponse || (ErrorHandlerResponse = {}));
/*
* @nevware21/grunt-ts-plugins
* https://github.com/nevware21/grunt-plugins
*
* Copyright (c) 2021 Nevware21
* Licensed under the MIT license.
*/
var TsErrorRegEx = /error TS(\d+):/;
var TypeScriptCompiler = /** @class */ (function () {

@@ -236,3 +272,3 @@ function TypeScriptCompiler(grunt, options) {

_self.compile = function (tsFiles) { return __awaiter(_this, void 0, void 0, function () {
var startTime, args, showOverrides, tsc, tsCommand, compilerOptions, tsConfigFile, tsConfig, tsConfigRoot, projectRootDir, rootDir, projectDeclarationDir, declarationDir, outFile, lp, theArgs, runCmd, execResponse, endTime, chkResponse, response, message;
var startTime, args, showOverrides, tsc, tscVersion, useTempTsConfig, tmpTsConfig, tsCommand, tsConfig, compilerOptions, tsConfigFile, tsConfigRoot, projectRootDir, rootDir, projectDeclarationDir, declarationDir, outParam, outFile, fullTsConfigPath_1, tsConfigContent, runCmd, execResponse, endTime, chkResponse, response, message;
return __generator(this, function (_a) {

@@ -248,4 +284,10 @@ switch (_a.label) {

tsc = _getTsc();
_getTscVersion();
tscVersion = _getTscVersion();
if (tscVersion) {
grunt.log.writeln("Using tsc version: " + tscVersion);
}
useTempTsConfig = false;
tmpTsConfig = null;
tsCommand = getTempFile("tscommand");
tsConfig = {};
if (!tsCommand) {

@@ -258,3 +300,2 @@ throw new Error("Unable to create a temporary file");

tsConfig = _readTsConfig(tsConfigFile);
args.push("--project " + tsConfigFile);
compilerOptions = tsConfig.compilerOptions || compilerOptions;

@@ -270,3 +311,2 @@ tsConfigRoot = path__namespace.resolve(findCommonPath([tsConfigFile]));

if (!fs__namespace.existsSync(path__namespace.resolve(projectRootDir))) {
showOverrides = true;
rootDir = path__namespace.resolve(compilerOptions.rootDir);

@@ -279,2 +319,3 @@ if (rootDir !== tsConfigRoot && fs__namespace.existsSync(rootDir)) {

grunt.log.warn(("The rootDir specified in your project file [" + tsConfigFile + "] is invalid.\n - [" + compilerOptions.rootDir + "] resolves to [" + projectRootDir + "]\n - Using tsconfig location: [" + tsConfigRoot + "]").yellow);
rootDir = tsConfigRoot;
args.push("--rootDir " + quoteIfRequired(tsConfigRoot));

@@ -300,33 +341,55 @@ //throw new Error("The rootDir specified in your project file [" + tsConfigFile + "] is invalid. [" + compilerOptions.rootDir + "] resolves to [" + projectRootDir + "]")

}
if (compilerOptions.out) {
outFile = path__namespace.resolve(compilerOptions.out);
args.push("--outfile " + quoteIfRequired(outFile));
outParam = options.out;
if (outParam && compilerOptions.outDir) {
grunt.log.warn(("The 'out' parameter is not compatible usage of 'outDir' within the TsConfig project file -- ignoring the out parameter").magenta);
outParam = undefined;
}
// if (compilerOptions.outDir) {
// if (!options.baseDir) {
// let files: string[] = [];
// // files.push(path.resolve("."));
// files.push(path.resolve(tsConfigFile));
// if (compilerOptions.rootDir) {
// files.push(path.resolve(compilerOptions.rootDir));
// }
// options.baseDir = findCommonPath(files)
// } else if (compilerOptions.rootDir) {
// args.push("--rootDir " + quoteIfRequired(options.baseDir));
// }
// }
outFile = resolveValue(outParam, compilerOptions.out, compilerOptions.outFile);
if (outFile) {
outFile = path__namespace.resolve(outFile);
args.push("--out " + quoteIfRequired(outFile));
}
if (tsFiles && tsFiles.length > 0) {
fullTsConfigPath_1 = path__namespace.resolve(tsConfigFile);
tsConfig.files = tsConfig.files || [];
tsConfig.include = tsConfig.include || [];
tsFiles.forEach(function (theFile) {
if (theFile.endsWith("**")) {
theFile = theFile + "/*";
}
var fullFilePath = normalizePath(path__namespace.resolve(theFile));
var commonPath = findCommonPath([fullTsConfigPath_1, fullFilePath]);
// put globs in the include and files directly unless there are excludes already defined
var destContainer = (!tsConfig.exclude && theFile.indexOf("*") === -1 ? tsConfig.files : tsConfig.include);
if (commonPath) {
destContainer.push("." + fullFilePath.substring(commonPath.length));
}
else {
destContainer.push(theFile);
}
});
if (tsConfig.files && tsConfig.files.length === 0) {
delete tsConfig.files;
}
if (tsConfig.include && tsConfig.include.length === 0) {
delete tsConfig.include;
}
useTempTsConfig = true;
}
if (useTempTsConfig) {
tmpTsConfig = getTempFile(tsConfigFile || "tsconfig");
if (!tmpTsConfig) {
throw new Error("Unable to create temporary tsconfig file");
}
tsConfigContent = JSON.stringify(tsConfig, null, 4);
if (options.debug) {
grunt.log.writeln("Temp TsConfig.json [" + tmpTsConfig + "]:\n" + tsConfigContent);
}
fs__namespace.writeFileSync(tmpTsConfig, tsConfigContent);
args.push("--project " + tmpTsConfig);
}
else {
args.push("--project " + tsConfigFile);
}
}
// let baseDirFile: string = '.baseDir.ts';
// let baseDirFilePath: string;
// if (compilerOptions.outDir && options.baseDir) {
// baseDirFilePath = path.join(options.baseDir, baseDirFile);
// if (!fs.existsSync(baseDirFilePath)) {
// grunt.file.write(baseDirFilePath, '// Ignore this file. See https://github.com/microsoft/TypeScript/issues/287');
// }
// tsFiles.push(baseDirFilePath);
// }
// Quote any source files if required
for (lp = 0; lp < tsFiles.length; lp++) {
tsFiles[lp] = quoteIfRequired(tsFiles[lp]);
}
_a.label = 1;

@@ -343,5 +406,5 @@ case 1:

}
theArgs = tsFiles.concat(args);
// Create the temporary commands
if (showOverrides || options.debug) {
grunt.log.writeln("Ts-Plugin Invoking: " + tsc + " @" + tsCommand + "\n Contents...\n " + theArgs.join("\n ") + "\n");
grunt.log.writeln("Ts-Plugin Invoking: " + tsc + " @" + tsCommand + "\n Contents...\n " + args.join("\n ") + "\n");
}

@@ -351,3 +414,3 @@ else {

}
fs__namespace.writeFileSync(tsCommand, theArgs.join(" "));
fs__namespace.writeFileSync(tsCommand, args.join(" "));
runCmd = options.execute || doExecute;

@@ -362,3 +425,4 @@ return [4 /*yield*/, runCmd(grunt, [tsc, "@" + tsCommand])];

time: (endTime - startTime) / 1000,
isSuccess: !chkResponse.isError || (chkResponse.isOnlyTypeErrors && !options.failOnTypeErrors)
isSuccess: !chkResponse.isError || (chkResponse.isOnlyTypeErrors && !options.failOnTypeErrors),
errors: chkResponse.messages
};

@@ -376,3 +440,4 @@ if (response.isSuccess) {

case 3:
fs__namespace.unlinkSync(tsCommand);
tmpTsConfig && fs__namespace.unlinkSync(tmpTsConfig);
tsCommand && fs__namespace.unlinkSync(tsCommand);
return [7 /*endfinally*/];

@@ -449,3 +514,4 @@ case 4: return [2 /*return*/];

var level5 = errors[1 /* Level5 */];
var nonEmit = errors[3 /* NonEmit */];
var handlerErrors = errors[3 /* HandlerError */];
var nonEmit = errors[4 /* NonEmit */];
// Log error summary

@@ -467,2 +533,6 @@ if (level1 + level5 + nonEmit > 0) {

}
if (handlerErrors > 0) {
grunt.log.write(handlerErrors.toString() + ' handler error' +
(handlerErrors === 1 ? '' : 's') + ' ');
}
if (nonEmit > 0) {

@@ -495,3 +565,3 @@ grunt.log.write(nonEmit.toString() + ' non-emit-preventing type warning' + (nonEmit === 1 ? '' : 's') + ' ');

_a[2 /* TS7017 */] = 0,
_a[3 /* NonEmit */] = 0,
_a[4 /* NonEmit */] = 0,
_a);

@@ -501,22 +571,53 @@ var output = response.stdout || response.stderr;

var hasPreventEmitErrors = false;
var theErrors = [];
lines.forEach(function (value) {
if (value.search(/error TS7017:/g) >= 0) {
errors[2 /* TS7017 */]++;
var errorMatch = value.match(TsErrorRegEx);
if (errorMatch && errorMatch.length > 1) {
// We have an error match
var errorNumber = errorMatch[1];
var processError = ErrorHandlerResponse.Undefined;
if (options.onError) {
processError = options.onError(errorNumber, value);
if (processError === ErrorHandlerResponse.Error) {
errors[3 /* HandlerError */]++;
hasPreventEmitErrors = true;
}
}
if (!processError) {
processError = ErrorHandlerResponse.Error;
// Do default Handling
if (errorNumber === "7017") {
errors[2 /* TS7017 */]++;
}
else if (errorNumber[0] === "1") {
errors[0 /* Level1 */]++;
hasPreventEmitErrors = true;
}
else if (errorNumber[0] === "5") {
errors[1 /* Level5 */]++;
hasPreventEmitErrors = true;
}
else {
errors[4 /* NonEmit */]++;
processError = ErrorHandlerResponse.Silent;
}
}
if (processError !== ErrorHandlerResponse.Ignore) {
theErrors.push(value);
}
}
if (value.search(/error TS1\d+:/g) >= 0) {
errors[0 /* Level1 */]++;
hasPreventEmitErrors = true;
});
if (options.logOutput) {
if (response.stdout) {
grunt.log.writeln("StdOut:\n" + response.stdout);
}
else if (value.search(/error TS5\d+:/) >= 0) {
errors[1 /* Level5 */]++;
hasPreventEmitErrors = true;
if (response.stderr) {
grunt.log.writeln("StdErr:\n" + response.stderr);
}
else if (value.search(/error TS\d+:/) >= 0) {
errors[3 /* NonEmit */]++;
}
});
}
return {
isError: isError,
isOnlyTypeErrors: !hasPreventEmitErrors,
errors: errors
errors: errors,
messages: theErrors
};

@@ -529,2 +630,10 @@ }

/// <reference types="grunt" />
var buildFailingErrors = [
"6050",
"6051",
"6053",
"6054",
"6059",
"6082"
];
function pluginFn(grunt) {

@@ -535,2 +644,3 @@ grunt.registerMultiTask("ts", "Compile TypeScript project", function () {

var taskOptions = getGruntMultiTaskOptions(grunt, this);
//let taskFiles = this.files || [];
if (options.debug) {

@@ -544,2 +654,17 @@ grunt.log.verbose.writeln((" Options: [" + JSON.stringify(options) + "]").cyan);

}
function handleDefaultTsErrors(number, line) {
var response = null;
if (taskOptions.onError) {
response = taskOptions.onError(number, line);
}
if (!response && options.onError) {
response = options.onError(number, line);
}
if (!response) {
if (buildFailingErrors.indexOf(number) !== -1) {
response = ErrorHandlerResponse.Error;
}
}
return response;
}
var tsOptions = {

@@ -549,7 +674,8 @@ tsconfig: taskOptions.tsconfig,

compiler: resolveValue(taskOptions.compiler, options.compiler, null),
baseDir: resolveValue(taskOptions.baseDir, options.baseDir, null),
additionalFlags: resolveValue(taskOptions.additionalFlags, taskOptions.additionalFlags, null),
debug: resolveValue(taskOptions.debug, options.debug, false),
logOutput: resolveValue(taskOptions.logOutput, options.logOutput, false),
failOnTypeErrors: resolveValue(taskOptions.failOnTypeErrors, taskOptions.failOnTypeErrors, false),
out: taskOptions.out
out: taskOptions.out,
onError: resolveValue(taskOptions.onError, options.onError, handleDefaultTsErrors)
};

@@ -560,3 +686,3 @@ //let tsConfig = require(options.tsconfig);

return __awaiter(this, void 0, void 0, function () {
var ts;
var ts, response;
return __generator(this, function (_a) {

@@ -568,4 +694,12 @@ switch (_a.label) {

case 1:
_a.sent();
done(true);
response = _a.sent();
if (!response.isSuccess && response.errors) {
response.errors.forEach(function (value) {
grunt.log.error(value);
});
}
if (options.debug) {
grunt.log.writeln("Response: " + JSON.stringify(response));
}
done(response.isSuccess ? true : false);
return [2 /*return*/];

@@ -576,4 +710,4 @@ }

})().catch(function (error) {
grunt.log.error(error);
done(false);
grunt.log.error(JSON.stringify(error));
done(error);
});

@@ -580,0 +714,0 @@ });

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