This repository has been archived by the owner on Dec 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed
skyux test/watch
performance (#202)
* Removed tslint-loader * Created custom sky-tslint loader
- Loading branch information
1 parent
978813f
commit 4272474
Showing
10 changed files
with
245 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/*jshint node: true*/ | ||
'use strict'; | ||
|
||
module.exports = function () { | ||
const apply = (compiler) => { | ||
compiler.plugin('done', () => { | ||
// Delete the existing TSLint program after each compilation so that it will get | ||
// recreated when files change. | ||
require('./program').clearProgram(); | ||
}); | ||
}; | ||
|
||
return { apply }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/*jshint node: true*/ | ||
'use strict'; | ||
|
||
const tslint = require('tslint'); | ||
const skyPagesConfigUtil = require('../../config/sky-pages/sky-pages.config'); | ||
const programUtil = require('./program'); | ||
const tslintConfigPath = skyPagesConfigUtil.spaPath('tslint.json'); | ||
const tsConfigPath = skyPagesConfigUtil.spaPath('tsconfig.json'); | ||
|
||
const lint = (instance, input) => { | ||
const linterOptions = { | ||
fix: false, | ||
typeCheck: true | ||
}; | ||
|
||
const program = programUtil.getProgram(tsConfigPath); | ||
const configuration = tslint.Configuration.findConfiguration(tslintConfigPath).results; | ||
const linter = new tslint.Linter(linterOptions, program); | ||
linter.lint(instance.resourcePath, input, configuration); | ||
const result = linter.getResult(); | ||
|
||
if (result.failures.length) { | ||
return new Error(`Compilation failed due to tslint errors. ${result.output}`); | ||
} | ||
}; | ||
|
||
module.exports = function (input, map) { | ||
const callback = this.async(); | ||
const error = lint(this, input); | ||
|
||
callback(error, input, map); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/*jshint node: true*/ | ||
'use strict'; | ||
|
||
const tslint = require('tslint'); | ||
const logger = require('winston'); | ||
let _program; | ||
|
||
const getProgram = (tsconfigPath) => { | ||
if (!_program) { | ||
logger.info('Creating new TSLint compiler...'); | ||
_program = tslint.Linter.createProgram(tsconfigPath); | ||
logger.info('Done.'); | ||
} | ||
|
||
return _program; | ||
}; | ||
|
||
const clearProgram = () => { | ||
_program = undefined; | ||
}; | ||
|
||
module.exports = { | ||
getProgram, | ||
clearProgram | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/*jshint jasmine: true, node: true */ | ||
'use strict'; | ||
|
||
const programUtil = require('../loader/sky-tslint/program'); | ||
|
||
describe('SKY UX tslint Webpack checker plugin', () => { | ||
const pluginPath = '../loader/sky-tslint/checker-plugin'; | ||
|
||
it('should delete the TSLint program on the "done" hook', () => { | ||
spyOn(programUtil, 'clearProgram').and.callFake(() => {}); | ||
const plugin = require(pluginPath); | ||
const mockCompiler = { | ||
plugin: (hook, callback) => callback() | ||
}; | ||
const instance = new plugin(); | ||
instance.apply(mockCompiler); | ||
expect(programUtil.clearProgram).toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/*jshint jasmine: true, node: true */ | ||
'use strict'; | ||
|
||
const mock = require('mock-require'); | ||
const tslint = require('tslint'); | ||
|
||
describe('SKY UX tslint program util', () => { | ||
const utilPath = '../loader/sky-tslint/program'; | ||
|
||
beforeEach(() => { | ||
spyOn(tslint.Linter, 'createProgram').and.returnValue({}); | ||
}); | ||
|
||
afterEach(() => { | ||
mock.stopAll(); | ||
}); | ||
|
||
it('should create and return a TSLint program based on tsconfig.json path', () => { | ||
const util = mock.reRequire(utilPath); | ||
const tsconfigPath = 'tsconfig.json'; | ||
const program = util.getProgram(tsconfigPath); | ||
expect(program).toBeDefined(); | ||
expect(tslint.Linter.createProgram).toHaveBeenCalledWith(tsconfigPath); | ||
}); | ||
|
||
it('should return an existing TSLint program on proceeding requests', () => { | ||
const util = mock.reRequire(utilPath); | ||
const tsconfigPath = 'tsconfig.json'; | ||
|
||
util.getProgram(tsconfigPath); | ||
expect(tslint.Linter.createProgram.calls.count()).toEqual(1); | ||
|
||
util.getProgram(tsconfigPath); | ||
expect(tslint.Linter.createProgram.calls.count()).toEqual(1); | ||
}); | ||
|
||
it('should delete a TSLint program', () => { | ||
const util = mock.reRequire(utilPath); | ||
const tsconfigPath = 'tsconfig.json'; | ||
|
||
util.getProgram(tsconfigPath); | ||
expect(tslint.Linter.createProgram.calls.count()).toEqual(1); | ||
|
||
util.clearProgram(); | ||
util.getProgram(tsconfigPath); | ||
expect(tslint.Linter.createProgram.calls.count()).toEqual(2); | ||
}); | ||
}); |
Oops, something went wrong.