Socket
Socket
Sign inDemoInstall

grunt-ts

Package Overview
Dependencies
Maintainers
5
Versions
149
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-ts - npm Package Compare versions

Comparing version 5.0.0-beta.6 to 5.0.0

23

CHANGELOG.md
# Releases
## Next
* out and outDir in VS projects will now work consistently between grunt-ts and Visual Studio; the paths will resolve to be relative to the gruntfile even if the VS project is not in the same folder.
## v5.0.0 (2015-10-07)
Version 5 of grunt-ts represents a major overhaul of the options resolution system. More than 100 new tests have been added, so this should be the highest quality version of grunt-ts yet. Also, many integration tests have been rewritten as "heavy unit tests" (meaning they call into grunt-ts from grunt, but don't actually call `tsc`, so they run in ~0.02 sec). This allows validation of grunt-ts warnings, and assertion of exact command line parameters. Even though testing quality has gone up *significantly*, the overall time to run `grunt release` on grunt-ts itself has dropped from 184 seconds to 112 seconds - a 64% improvement.
* FIX: amdloader will now work for [`.tsx` extension as well](https://github.com/TypeStrong/grunt-ts/pull/274)
* FEAT: Added support for `tsconfig.json` [#202](https://github.com/TypeStrong/grunt-ts/issues/202). Supports maintenance of `files` property and optional TypeStrong custom `filesGlob` extension.
* NOTE: Upgrade to TypeScript 1.6 was out of scope for version 5.0 - that will be part of version 5.1 which should be available soon.
* NOTE: Significant use of ES6 features throughout - let & const, ES6 imports, destructuring, etc.
* CHORE: Upgraded to tslint v2.4.0.
* CHORE: Upgraded to csproj2ts v0.0.4.
* NOTE: Added dependency on strip-bom npm package.
* CHORE: Updated several definition files including nodeunit, NodeJS, and es6-promises.
* CHORE: 'use strict' throughout.
* CHORE: Upgraded to csproj2ts v0.0.4.
* FIX: Will now provide warning if `sourcemap` is used; should be `sourceMap`. This issue will be auto-resolved.
* FIX: Templates in grunt targets should always be resolved consistently now [#273](https://github.com/TypeStrong/grunt-ts/issues/273). Thanks for the report, @bjorm.
* FIX: html2ts should now honor the `outdir` setting [#271](https://github.com/TypeStrong/grunt-ts/issues/271). Thanks for the report, @hoeni.
* FIX: Target options should always work properly in conjunction with the `vs` option [#264](https://github.com/TypeStrong/grunt-ts/issues/264). Thanks for the report, @vtkalek.
* FIX: Task and target-level options should always override consistently now [#248](https://github.com/TypeStrong/grunt-ts/issues/248).
* FIX: out and outDir in VS projects will now work consistently between grunt-ts and Visual Studio; the paths will resolve to be relative to the gruntfile even if the VS project is not in the same folder.
* If `vs` is used with `files`, there will still be a warning, but grunt-ts will now append the files from the Visual Studio project to the result of each files glob. Previously it would compile the Visual Studio project files only (once per files entry).
* Fixed several broken warnings such as using an array for `dest` with `files`.
## v4.2.0 (2015-07-21)

@@ -7,0 +28,0 @@ * FEAT: TypeScript 1.5.3 support (TypeScript 1.5 "RTM").

2

package.json

@@ -5,3 +5,3 @@ {

"description": "Compile and manage your TypeScript project",
"version": "5.0.0-beta.6",
"version": "5.0.0",
"homepage": "https://github.com/grunt-ts/grunt-ts",

@@ -8,0 +8,0 @@ "repository": {

@@ -7,7 +7,6 @@ # grunt-ts

Grunt-ts is an npm package that handles TypeScript compilation work in GruntJS build scripts. It provides a [Grunt-compatible wrapper](#support-for-tsc-switches) for the `tsc` command-line compiler, and provides some [additional functionality](#grunt-ts-gruntfilejs-options) that improves the TypeScript development workflow. Grunt-ts even supports compiling against a [Visual Studio project](#vs) directly. Grunt-ts is itself written in [TypeScript](./tasks/ts.ts).
Grunt-ts is an npm package that handles TypeScript compilation work in GruntJS build scripts. It provides a [Grunt-compatible wrapper](#support-for-tsc-switches) for the `tsc` command-line compiler, and provides some [additional functionality](#grunt-ts-gruntfilejs-options) that improves the TypeScript development workflow. Grunt-ts supports compiling against [tsconfig.json](#tsconfig) or even a [Visual Studio project](#vs) directly. Grunt-ts is itself written in [TypeScript](./tasks/ts.ts).
### Latest Changes
Latest test release is `5.0.0-beta.1` which includes tsconfig support.
Current major release is 4.2, which includes TypeScript 1.5.
Latest release is `5.0.0`, which includes `tsconfig.json` support and TypeScript 1.5, among many other improvements.

@@ -997,4 +996,22 @@ [Full changelog is here](CHANGELOG.md).

Grunt-ts supports using a tsconfig.json file. Here are some example Gruntfile initConfig sections:
Grunt-ts can integrate with a `tsconfig.json` file in three ways which offer different behavior:
* As a `boolean`: simplest way for default behavior.
* As a `string`: still uses defaults, but allows specifying a specific path to the `tsconfig.json` file or the containing folder.
* As an `object`: allows detailed control over how grunt-ts works with `tsconfig.json`
**When specifying tsconfig as a boolean**
In this scenario, grunt-ts will use all settings from the `tsconfig.json` file in the same folder as `Gruntfile.js`.
* If a `filesGlob` property is present in the `tsconfig.json` file:
* It will be evaluated, and any identified files will be added to the compilation context.
* If a `files` property is present, it will be modified with the result from evaluating the `filesGlob` that is present **inside** `tsconfig.json` (the `files` element will **not** be updated with the results from any glob inside `Gruntfile.js`).
* If `exclude` is present, it will be ignored.
* If a `filesGlob` property is NOT present, but `files` is present:
* Any files specified in `files` will be added to the compilation context.
* If `exclude` is present, it will be ignored.
* If neither `filesGlob` nor `files` is present:
* All \*.ts and \*.tsx files in all subfolders will be added to the compilation context, **excluding** any subfolders specified in the optional `exclude` property.
* If a glob is also specified in the `Gruntfile.js`, grunt-ts will NOT update the `filesGlob` in the `tsconfig.json` file with it nor will those files be added to the `tsconfig.json` `files` element.
* The `tsconfig` property should function correctly as either a task option or a target property.
* If the `tsconfig.json` file does not exist or there is a parse error, compilation will be aborted with an error.
```js

@@ -1004,3 +1021,4 @@ grunt.initConfig({

default: {
tsconfig: true // Value must be a string referencing a file path such as "./somefolder/tsconfig.json", OR `true` to use the 'tsconfig.json' in same folder as Gruntfile.js
// specifying tsconfig as a boolean will use the 'tsconfig.json' in same folder as Gruntfile.js
tsconfig: true
}

@@ -1011,3 +1029,4 @@ }

or
**When specifying tsconfig as a string**
This scenario follows the same behavior as specifying `tsconfig.json` as a boolean, except that it is possible to use an explicit file name. If a directory name is provided instead, grunt-ts will use `tsconfig.json` in that directory. The path to `tsconfig.json` (or the directory that contains it) is relative to `Gruntfile.js`.

@@ -1018,2 +1037,3 @@ ```js

default: {
// specifying tsconfig as a string will use the specified `tsconfig.json` file.
tsconfig: './some/path/to/tsconfig.json'

@@ -1025,4 +1045,12 @@ }

also:
**When specifying tsconfig as an object**
This provides the most control over how grunt-ts integrates with `tsconfig.json`. Supported properties are:
* `tsconfig`: `string` (optional) - if absent, will default to `tsconfig.json` in same folder as `Gruntfile.js`. If a folder is passed, will use `tsconfig.json` in that folder.
* `ignoreFiles`: `boolean` (optional) - default is `false`. If true, will not inlcude files in `files` array from `tsconfig.json` in the compilation context.
* `ignoreSettings`: `boolean` (optional) - default is `false`. If true, will ignore `compilerOptions` section in `tsconfig.json` (will only use settings from `Gruntfile.js` or grunt-ts defaults)
* `overwriteFilesGlob`: `boolean` (optional) - default is `false`. If true, will overwrite the contents of the `filesGlob` array with the contents of the `src` glob from grunt-ts.
* `updateFiles`: `boolean` (optional) - default is `true`. Will modify the `files` array in `tsconfig.json` to match the result of evaluating a `filesGlob` that is present **inside** `tsconfig.json` (the `files` element will **not** be updated with the results from any glob inside `Gruntfile.js` unless `overwriteFilesGlob` is also `true`).
* `passThrough`: `boolean` (optional) - default is `false`. If `passThrough` is `true`, grunt-ts will run TypeScript (`tsc`) with the specified tsconfig folder, passing the `--project` option only (and anything in `additionalFlags`). This provides support for custom compilers with custom implementations of `tsconfig.json` support. Note: Since this entirely depends on support from `tsc`, the `tsconfig` option must be a directory (not a file) as of TypeScript 1.6.
```js

@@ -1032,5 +1060,10 @@ grunt.initConfig({

default: {
// specifying tsconfig as an object allows detailed configuration overrides...
tsconfig: {
tsconfig: './SomeOtherFolder/tsconfig.json',
ignoreFiles: true
ignoreFiles: false,
ignoreSettings: false,
overwriteFilesGlob: false,
updateFiles: true,
passThrough: false
}

@@ -1040,6 +1073,10 @@ }

});
```
Documentation for how this feature will work when fully implemented is here: https://github.com/TypeStrong/grunt-ts/issues/202#issuecomment-125992243
```
### Important notes:
* Globs in `filesGlob` in `tsconfig.json` are relative to the `tsconfig.json`, **not** the `Gruntfile.js`.
* `tsconfig` has a restriction when used with `files` in the Grunt task configuration: `overwriteFilesGlob` is NOT supported if `files` has more than one element. This will abort compilation.
* If `files` is absent in `tsconfig.json`, but `filesGlob` is present, grunt-ts will create and update the `files` array in `tsconfig.json` as long as `updateFiles` is `true` (the default). Since `files` will be created in this scenario, any values in the `exclude` array will be ignored.
* This feature may be used along with the `vs` keyword. Any settings found in `tsconfig.json` will override any settings found in the Visual Studio project file. Any files referenced in the Visual Studio file that are not also referenced in tsconfig.json *will* be included in the compilation context after any files from `tsconfig.json` (any files from `src` but not in `vs` or `tsconfig` will be included after that). The order of the files in `tsconfig.json` will override the order of the files in the VS project file.

@@ -1046,0 +1083,0 @@ #### verbose

@@ -266,5 +266,7 @@ /// <reference path="../../defs/tsd.d.ts"/>

fs.writeFileSync(tempfilename, args.join(' '));
var command;
// Switch implementation if a test version of executeNode exists.
if ('testExecute' in options) {
if (_.isFunction(options.testExecute)) {
command = [tsc, args.join(' ')];
executeNode = options.testExecute;

@@ -280,6 +282,7 @@ }

// this is the normal path.
command = [tsc, '@' + tempfilename];
executeNode = executeNodeDefault;
}
// Execute command
return executeNode([tsc, '@' + tempfilename], options).then(function (result) {
return executeNode(command, options).then(function (result) {
if (options.fast !== 'never' && result.code === 0) {

@@ -286,0 +289,0 @@ resetChangedFiles(newFiles, options.targetName);

@@ -307,5 +307,8 @@ /// <reference path="../../defs/tsd.d.ts"/>

let command: string[];
// Switch implementation if a test version of executeNode exists.
if ('testExecute' in options) {
if (_.isFunction(options.testExecute)) {
command = [tsc, args.join(' ')];
executeNode = options.testExecute;

@@ -319,2 +322,3 @@ } else {

// this is the normal path.
command = [tsc, '@' + tempfilename];
executeNode = executeNodeDefault;

@@ -324,3 +328,3 @@ }

// Execute command
return executeNode([tsc, '@' + tempfilename], options).then((result: ICompileResult) => {
return executeNode(command, options).then((result: ICompileResult) => {

@@ -327,0 +331,0 @@ if (options.fast !== 'never' && result.code === 0) {

@@ -45,6 +45,8 @@ /// <reference path="../../defs/tsd.d.ts"/>

fixMissingOptions(rawTargetOptions);
var _a = resolveAndWarnOnConfigurationIssues(rawTaskOptions, rawTargetOptions, targetName), errors = _a.errors, warnings = _a.warnings;
var result = emptyOptionsResolveResult();
(_b = result.errors).push.apply(_b, errors);
(_c = result.warnings).push.apply(_c, warnings);
{
var _a = resolveAndWarnOnConfigurationIssues(rawTaskOptions, rawTargetOptions, targetName), errors = _a.errors, warnings = _a.warnings;
(_b = result.errors).push.apply(_b, errors);
(_c = result.warnings).push.apply(_c, warnings);
}
result = applyGruntOptions(result, rawTaskOptions);

@@ -56,2 +58,3 @@ result = applyGruntOptions(result, rawTargetOptions);

result = addressAssociatedOptionsAndResolveConflicts(result);
result = logAdditionalConfigurationWarnings(result);
result = applyGruntTSDefaults(result);

@@ -84,2 +87,5 @@ if (result.targetName === undefined ||

}
function logAdditionalConfigurationWarnings(options) {
return options;
}
function resolveAndWarnOnConfigurationIssues(task, target, targetName) {

@@ -93,3 +99,41 @@ var errors = [], warnings = [];

checkLocations(target, "target \"" + targetName + "\"");
fixFilesUsedWithFast(task, 'ts task');
fixFilesUsedWithFast(target, "target \"" + targetName + "\"");
warnings.push.apply(warnings, getAdditionalWarnings(task, target, targetName));
return { errors: errors, warnings: warnings };
function getAdditionalWarnings(task, target, targetName) {
var additionalWarnings = [];
if (((task && task.src) || (target && target.src)) &&
((task && task.files) || (target && target.files))) {
additionalWarnings.push("Warning: In task \"" + targetName + "\", either \"files\" or \"src\" should be used - not both.");
}
if (((task && task.vs) || (target && target.vs)) &&
((task && task.files) || (target && target.files))) {
additionalWarnings.push("Warning: In task \"" + targetName + "\", either \"files\" or \"vs\" should be used - not both.");
}
if (usingDestArray(task) || usingDestArray(target)) {
additionalWarnings.push(("Warning: target \"" + targetName + "\" has an array specified for the files.dest property.") +
" This is not supported. Taking first element and ignoring the rest.");
}
return additionalWarnings;
function usingDestArray(task) {
var result = false;
if (task && task.files && _.isArray(task.files)) {
task.files.forEach(function (item) {
if (_.isArray(item.dest)) {
result = true;
}
;
});
}
return result;
}
}
function fixFilesUsedWithFast(task, configName) {
if (task && task.files && task.options && task.options.fast) {
warnings.push(("Warning: " + configName + " is attempting to use fast compilation with \"files\". ") +
"This is not currently supported. Setting \"fast\" to \"never\".");
task.options.fast = 'never';
}
}
function checkLocations(task, configName) {

@@ -211,9 +255,17 @@ // todo: clean this up. The top and bottom sections are largely the same.

};
if ('dest' in files[i]) {
if (utils.isJavaScriptFile(files[i].dest)) {
compilationSet.out = files[i].dest;
if ('dest' in files[i] && files[i].dest) {
var dest = void 0;
if (_.isArray(files[i].dest)) {
// using an array for dest is not supported. Only take first element.
dest = files[i].dest[0];
}
else {
compilationSet.outDir = files[i].dest;
dest = files[i].dest;
}
if (utils.isJavaScriptFile(dest)) {
compilationSet.out = dest;
}
else {
compilationSet.outDir = dest;
}
}

@@ -240,2 +292,6 @@ options.CompilationTasks.push(compilationSet);

}
if ('comments' in options && 'removeComments' in options) {
options.warnings.push("WARNING: Option \"comments\" and \"removeComments\" should not be used together. " +
("The --removeComments value of " + !!options.removeComments + " supercedes the --comments value of " + !!options.comments));
}
if ('comments' in options && !('removeComments' in options)) {

@@ -249,2 +305,6 @@ options.comments = !!options.comments;

}
if ('html' in options && options.CompilationTasks.length === 0) {
options.errors.push("ERROR: option `html` provided without specifying corresponding TypeScript source files to " +
"compile. The transform will not occur unless grunt-ts also expects to compile these files.");
}
options.CompilationTasks.forEach(function (compileTask) {

@@ -251,0 +311,0 @@ if (compileTask.out && compileTask.outDir) {

@@ -60,7 +60,8 @@ /// <reference path="../../defs/tsd.d.ts"/>

let {errors, warnings} = resolveAndWarnOnConfigurationIssues(rawTaskOptions, rawTargetOptions, targetName);
let result = emptyOptionsResolveResult();
result.errors.push(...errors);
result.warnings.push(...warnings);
{
const {errors, warnings} = resolveAndWarnOnConfigurationIssues(rawTaskOptions, rawTargetOptions, targetName);
result.errors.push(...errors);
result.warnings.push(...warnings);
}
result = applyGruntOptions(result, rawTaskOptions);

@@ -74,2 +75,3 @@ result = applyGruntOptions(result, rawTargetOptions);

result = addressAssociatedOptionsAndResolveConflicts(result);
result = logAdditionalConfigurationWarnings(result);
result = applyGruntTSDefaults(result);

@@ -105,2 +107,7 @@

function logAdditionalConfigurationWarnings(options: IGruntTSOptions) {
return options;
}
function resolveAndWarnOnConfigurationIssues(task: ITargetOptions,

@@ -117,6 +124,54 @@ target: ITargetOptions, targetName: string) {

checkLocations(target, `target "${targetName}"`);
fixFilesUsedWithFast(task, 'ts task');
fixFilesUsedWithFast(target, `target "${targetName}"`);
warnings.push(...getAdditionalWarnings(task, target, targetName));
return {errors, warnings};
function getAdditionalWarnings(task: any, target: any, targetName: string) {
const additionalWarnings = [];
if (((task && task.src) || (target && target.src)) &&
((task && task.files) || (target && target.files))) {
additionalWarnings.push(`Warning: In task "${targetName}", either "files" or "src" should be used - not both.`);
}
if (((task && task.vs) || (target && target.vs)) &&
((task && task.files) || (target && target.files))) {
additionalWarnings.push(`Warning: In task "${targetName}", either "files" or "vs" should be used - not both.`);
}
if (usingDestArray(task) || usingDestArray(target)) {
additionalWarnings.push(`Warning: target "${targetName}" has an array specified for the files.dest property.` +
` This is not supported. Taking first element and ignoring the rest.`);
}
return additionalWarnings;
function usingDestArray(task) {
let result = false;
if (task && task.files && _.isArray(task.files)) {
task.files.forEach(item => {
if (_.isArray(item.dest)) {
result = true;
};
});
}
return result;
}
}
function fixFilesUsedWithFast(task: any, configName: string) {
if (task && task.files && task.options && task.options.fast) {
warnings.push(`Warning: ${configName} is attempting to use fast compilation with "files". ` +
`This is not currently supported. Setting "fast" to "never".`);
task.options.fast = 'never';
}
}
function checkLocations(task: ITargetOptions, configName: string) {
// todo: clean this up. The top and bottom sections are largely the same.

@@ -247,8 +302,15 @@ if (task) {

};
if ('dest' in files[i]) {
if (utils.isJavaScriptFile(files[i].dest)) {
compilationSet.out = files[i].dest;
if ('dest' in files[i] && files[i].dest) {
let dest: string;
if (_.isArray(files[i].dest)) {
// using an array for dest is not supported. Only take first element.
dest = files[i].dest[0];
} else {
compilationSet.outDir = files[i].dest;
dest = files[i].dest;
}
if (utils.isJavaScriptFile(dest)) {
compilationSet.out = dest;
} else {
compilationSet.outDir = dest;
}
}

@@ -281,2 +343,7 @@ options.CompilationTasks.push(compilationSet);

if ('comments' in options && 'removeComments' in options) {
options.warnings.push(`WARNING: Option "comments" and "removeComments" should not be used together. ` +
`The --removeComments value of ${!!options.removeComments} supercedes the --comments value of ${!!options.comments}`);
}
if ('comments' in options && !('removeComments' in options)) {

@@ -290,2 +357,7 @@ options.comments = !!options.comments;

if ('html' in options && options.CompilationTasks.length === 0) {
options.errors.push(`ERROR: option \`html\` provided without specifying corresponding TypeScript source files to ` +
`compile. The transform will not occur unless grunt-ts also expects to compile these files.`);
}
options.CompilationTasks.forEach(compileTask => {

@@ -292,0 +364,0 @@ if (compileTask.out && compileTask.outDir) {

@@ -43,2 +43,9 @@ /// <reference path="../defs/tsd.d.ts"/>

});
options.errors.forEach(function (error) {
grunt.log.writeln(error.red);
});
if (options.errors.length > 0) {
done(false);
return;
}
proceed();

@@ -45,0 +52,0 @@ }).catch(function (error) {

@@ -59,2 +59,11 @@ /// <reference path="../defs/tsd.d.ts"/>

options.errors.forEach((error) => {
grunt.log.writeln(error.red);
});
if (options.errors.length > 0) {
done(false);
return;
}
proceed();

@@ -61,0 +70,0 @@ }).catch((error) => {

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