Gathering detailed insights and metrics for karma-typescript-preprocessor2
Gathering detailed insights and metrics for karma-typescript-preprocessor2
Gathering detailed insights and metrics for karma-typescript-preprocessor2
Gathering detailed insights and metrics for karma-typescript-preprocessor2
npm install karma-typescript-preprocessor2
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
8 Stars
33 Commits
5 Forks
2 Watching
1 Branches
4 Contributors
Updated on 27 Apr 2017
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-29%
22
Compared to previous day
Last week
-17.1%
131
Compared to previous week
Last month
-34.8%
764
Compared to previous month
Last year
-2.6%
11,182
Compared to previous year
2
7
Transpile files in memory using gulp-typescript. No temp files are generated.
This preprocessor uses gulp-typescript transpiler, a great plugin mainted by ivogabe and other 21 contributors. Among its best features we highlight:
First you need to include reference to this plugin in your package.json
, just write karma-typescript-preprocessor2 (note number 2 at the end):
1 { 2 "devDependencies": { 3 "karma": "^0.13.15", 4 "karma-typescript-preprocessor2": "1.2.1" 5 } 6 }
You can also install via cli:
$ npm install karma-typescript-preprocessor2 --save-dev
Here is a full featured example with all options that you can use to configure the preprocessor:
1// karma.conf.js 2module.exports = function(config) { 3 config.set({ 4 files: [ 5 '**/*.ts' // Preprocessor will convert Typescript to Javascript 6 ], 7 preprocessors: { 8 '**/*.ts': ['typescript', 'sourcemap'] // Use karma-sourcemap-loader 9 }, 10 typescriptPreprocessor: { 11 // options passed to typescript compiler 12 tsconfigPath: './tsconfig.json', // *obligatory 13 compilerOptions: { // *optional 14 removeComments: false 15 }, 16 // Options passed to gulp-sourcemaps to create sourcemaps 17 sourcemapOptions: {includeContent: true, sourceRoot: '/src'}, 18 // ignore all files that ends with .d.ts (this files will not be served) 19 ignorePath: function(path){ 20 return /\.d\.ts$/.test(path); 21 }, 22 // transforming the filenames 23 // you can pass more than one, they will be execute in order 24 transformPath: [function(path) { // *optional 25 return path.replace(/\.ts$/, '.js'); 26 }, function(path) { 27 return path.replace(/[\/\\]test[\/\\]/i, '/'); // remove directory test and change to / 28 }] 29 } 30 }); 31};
1//tsconfig.json 2{ 3 "compilerOptions": { 4 "noImplicitAny": false, 5 "module": "amd", 6 "noEmitOnError": false, 7 "removeComments": true, 8 "sourceMap": true, 9 "listFiles": true, 10 "experimentalDecorators": true, 11 "outDir": "wwwroot", 12 "target": "es5" 13 }, 14 "exclude": [ 15 "node_modules", 16 "wwwroot", 17 "artifacts" 18 ".git", 19 ".vs" 20 ] 21}
By design karma-typescript-preprocessor2
only allows primary configuration build by tsconfig.json
. Working this way, a lot of problems with typos and references are completely solved, as compiler will use same basedir
to resolve files, but you can always override (or include) new options by using compilerOptions
property.
As we use gulp-typescript to transpiler typescript code, we have the same unsuported properties as theirs, so:
singleRun: false
configuration instead.And obvious ones: help, version
Transpiling with gulp-typescript requires the use of gulp-sourcemaps to create sourcemaps.
Below there are list of plugin options
default value:
function(path){
return path.replace(/\.ts$/, '.js');//replace .ts to .js from virtual path
}
It is used to change virtual path of served files. Sometimes it should be necessary to change virtual directory of a served file to allow tests, example:
Let's suppose that you have the following folder hierarchy:
\basedir
\wwwroot
module
file1.js
file2.js
\src
module
file1.ts
file2.ts
\test
module
file1.spec.ts
file2.spec.ts
If file1.spec.ts
and file2.spec.ts
reference file1.ts
and file2.ts
, and you are using typescript module
option, you will need to remove virtual directory test
, so all modules referenced by *.specs.ts
will be solved successfully. To make it work, you just need to write something like:
// karma.conf.js
(...)
typescriptPreprocessor: {
// options passed to the typescript compiler
tsconfigPath: './tsconfig.json', //*obligatory
compilerOptions: {//*optional
removeComments: false
},
// transforming the filenames
// you can pass more than one, they will be execute in order
transformPath: [function(path) {//
return path.replace(/\.ts$/, '.js'); // first change .ts to js
}, function(path) {
return path.replace(/[\/\\]test[\/\\]/i, '/'); // remove directory test and change to /
}]
}
(...)
Here there is a simple example seed where you can see what is described here in action.
It could be used to ignore files that you don't want to serve. Keep in mind that ignorePath
runs before transformPath
default value:
function(path){
return /\.d\.ts$//.test(path);
}
Specify gulp-sourcemaps
write options. Inline sourcemaps are the easiest to configure for testing. For more info see gulp-sourcemaps write options.
You can provide or override any compiler options avaliable by gulp-typescript
, for more info you can access gulp-typescript project options.
karma-typescript-preprocessor2
is licensed under the MIT license.
Need help? Open an issue :)
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 2/26 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More