Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Fixed skyux test/watch performance #202

Merged
merged 16 commits into from
Jun 29, 2017
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion config/webpack/build.webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ function getWebpackConfig(skyPagesConfig) {
// Ignore the "Cannot find module" error that occurs when referencing
// an aliased file. Webpack will still throw an error when a module
// cannot be resolved via a file path or alias.
ignoreDiagnostics: [2307]
ignoreDiagnostics: [2307],
transpileOnly: true
}
},
{
Expand Down
15 changes: 5 additions & 10 deletions config/webpack/serve.webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin');
const skyPagesConfigUtil = require('../sky-pages/sky-pages.config');
const hostUtils = require('../../utils/host-utils');

const moduleLoader = skyPagesConfigUtil.outPath('loader', 'sky-pages-module');

/**
* Returns the querystring base for parameters allowed to be passed through.
* PLEASE NOTE: The method is nearly duplicated in `runtime/params.ts`.
Expand Down Expand Up @@ -120,11 +118,6 @@ function getWebpackConfig(argv, skyPagesConfig) {
watch: true,
module: {
rules: [
{
enforce: 'pre',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this rule because it is already listed in "common" config.

test: /sky-pages\.module\.ts$/,
loader: moduleLoader
},
{
test: /\.ts$/,
use: [
Expand All @@ -134,15 +127,17 @@ function getWebpackConfig(argv, skyPagesConfig) {
// Ignore the "Cannot find module" error that occurs when referencing
// an aliased file. Webpack will still throw an error when a module
// cannot be resolved via a file path or alias.
ignoreDiagnostics: [2307]
ignoreDiagnostics: [2307],
transpileOnly: true
}
},
{
loader: 'angular2-template-loader'
}
]
],
exclude: [/\.e2e\.ts$/]
}
],
]
},
devServer: {
compress: true,
Expand Down
80 changes: 33 additions & 47 deletions config/webpack/test.webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
/*jslint node: true */
'use strict';

function getWebpackConfig(skyPagesConfig, argv) {

function spaPath() {
return skyPagesConfigUtil.spaPath.apply(skyPagesConfigUtil, arguments);
}

function outPath() {
return skyPagesConfigUtil.outPath.apply(skyPagesConfigUtil, arguments);
}

const path = require('path');
const path = require('path');
const DefinePlugin = require('webpack/lib/DefinePlugin');
const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin');
const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin');
const ProcessExitCode = require('../../plugin/process-exit-code');
const SkyTsLintCheckerPlugin = require('../../loader/sky-tslint/checker-plugin');
const skyPagesConfigUtil = require('../sky-pages/sky-pages.config');
const aliasBuilder = require('./alias-builder');

function spaPath() {
return skyPagesConfigUtil.spaPath.apply(skyPagesConfigUtil, arguments);
}

const DefinePlugin = require('webpack/lib/DefinePlugin');
const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin');
const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin');
const ProcessExitCode = require('../../plugin/process-exit-code');
const skyPagesConfigUtil = require('../sky-pages/sky-pages.config');
const aliasBuilder = require('./alias-builder');
function outPath() {
return skyPagesConfigUtil.outPath.apply(skyPagesConfigUtil, arguments);
}

function getWebpackConfig(skyPagesConfig, argv) {
const runCoverage = (!argv || argv.coverage !== false);
skyPagesConfig.runtime.includeRouteModule = false;

const ENV = process.env.ENV = process.env.NODE_ENV = 'test';
const srcPath = path.resolve(process.cwd(), 'src', 'app');
const moduleLoader = outPath('loader', 'sky-pages-module');

const resolves = [
process.cwd(),
Expand Down Expand Up @@ -66,17 +64,7 @@ function getWebpackConfig(skyPagesConfig, argv) {
{
enforce: 'pre',
test: /sky-pages\.module\.ts$/,
loader: moduleLoader
},
{
enforce: 'pre',
test: /\.ts$/,
loader: 'tslint-loader',
exclude: excludes,
options: {
emitErrors: true,
failOnHint: true
}
loader: outPath('loader', 'sky-pages-module')
},
{
enforce: 'pre',
Expand All @@ -87,7 +75,13 @@ function getWebpackConfig(skyPagesConfig, argv) {
{
enforce: 'pre',
loader: outPath('loader', 'sky-processor', 'preload'),
exclude: /node_modules/
exclude: excludes
},
{
enforce: 'pre',
test: /\.ts$/,
loader: outPath('loader', 'sky-tslint'),
exclude: excludes
},
{
test: /\.ts$/,
Expand All @@ -98,7 +92,9 @@ function getWebpackConfig(skyPagesConfig, argv) {
// Ignore the "Cannot find module" error that occurs when referencing
// an aliased file. Webpack will still throw an error when a module
// cannot be resolved via a file path or alias.
ignoreDiagnostics: [2307]
ignoreDiagnostics: [2307],
// Linting is handled by the sky-tslint loader.
transpileOnly: true
}
},
{
Expand All @@ -108,19 +104,12 @@ function getWebpackConfig(skyPagesConfig, argv) {
exclude: [/\.e2e\.ts$/]
},
{
test: /\.css$/,
loader: 'raw-loader'
test: /\.s?css$/,
use: ['raw-loader', 'sass-loader']
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some cleanup to match what's in common config.

},
{
test: /\.html$/,
loader: 'raw-loader'
},
{
test: /\.scss$/,
use: [
'raw-loader',
'sass-loader'
]
}
]
},
Expand All @@ -130,13 +119,7 @@ function getWebpackConfig(skyPagesConfig, argv) {
debug: true,
options: {
context: __dirname,
skyPagesConfig: skyPagesConfig,
tslint: {
emitErrors: false,
failOnHint: false,
resourcePath: 'src',
typeCheck: true
}
skyPagesConfig: skyPagesConfig
}
}),

Expand All @@ -159,6 +142,9 @@ function getWebpackConfig(skyPagesConfig, argv) {
{}
),

// Handles watch-mode maintenance for TSLint.
new SkyTsLintCheckerPlugin(),

// Webpack 2 behavior does not correctly return non-zero exit code.
new ProcessExitCode()
]
Expand Down
32 changes: 32 additions & 0 deletions loader/sky-tslint/checker-plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*jshint node: true*/
'use strict';

function SkyTsLintCheckerPlugin() {
let isWatchMode = false;

const apply = (compiler) => {
compiler.plugin('run', function (params, callback) {
isWatchMode = false;
callback();
});

compiler.plugin('watch-run', function (params, callback) {
isWatchMode = true;
callback();
});

compiler.plugin('emit', function (compilation, callback) {
if (isWatchMode === true) {
require('./program').clearProgram();
}

callback();
});
};

return {
apply
};
}

module.exports = SkyTsLintCheckerPlugin;
34 changes: 34 additions & 0 deletions loader/sky-tslint/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const tslint = require('tslint');
const skyPagesConfigUtil = require('../../config/sky-pages/sky-pages.config');
const skyTsLintProgram = require('./program');

const lint = (instance, input) => {
const options = {
fix: false,
typeCheck: true
};

const program = skyTsLintProgram.getProgram();
const linter = new tslint.Linter(options, program);
const tslintConfig = skyPagesConfigUtil.spaPath('tslint.json');
const configuration = tslint.Configuration.findConfiguration(tslintConfig).results;

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}`);
}

return;
};

module.exports = function (input, map) {
const instance = this;
const callback = instance.async();

instance.cacheable && instance.cacheable();

let error = lint(instance, input);
callback(error, input, map);
};
25 changes: 25 additions & 0 deletions loader/sky-tslint/program.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*jshint node: true*/
'use strict';

const tslint = require('tslint');
const skyPagesConfigUtil = require('../../config/sky-pages/sky-pages.config');

const tsconfigPath = skyPagesConfigUtil.spaPath('tsconfig.json');
let _context = {};

const getProgram = () => {
if (!_context.tslintProgram) {
_context.tslintProgram = tslint.Linter.createProgram(tsconfigPath);
}

return _context.tslintProgram;
};

const clearProgram = () => {
delete _context.tslintProgram;
};

module.exports = {
getProgram,
clearProgram
};
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"homepage": "https://github.com/blackbaud/skyux-builder#readme",
"peerDependencies": {
"@blackbaud/skyux": "2.0.0-rc.1"
"@blackbaud/skyux": "2.0.0-rc.2"
},
"dependencies": {
"@angular/common": "4.1.3",
Expand Down Expand Up @@ -86,7 +86,6 @@
"ts-helpers": "1.1.2",
"ts-node": "3.0.4",
"tslint": "5.2.0",
"tslint-loader": "3.5.3",
"typescript": "2.3.2",
"webpack": "2.5.1",
"webpack-dev-server": "2.4.5",
Expand Down