This repository was archived by the owner on Sep 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Update dependencies and linting + testing setup. #86
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
8ad580a
Linting and testing setup ported over from Aspa. WIP.
danieldunderfelt 9bd563a
Copy testing setup from the Aspa project.
danieldunderfelt 452fb6b
Update to Webpack 4, based on create-react-app PR #4077 https://githu…
danieldunderfelt 03b1d64
Make enhancements from various projects WIP.
danieldunderfelt ca7f290
Remove Webpack code splitting for now.
danieldunderfelt 68a3c15
Update dependencies.
danieldunderfelt 073d771
Add cache-loader and thread-loader to further speed up builds, fix pr…
danieldunderfelt b1035ce
Add comment about what the chunks plugin does.
danieldunderfelt 1161802
Change the CI run command in an attempt to appease Travis.
danieldunderfelt 5a1fd16
Upgrade packages.
danieldunderfelt 4b22fda
Bump node version.
danieldunderfelt 8dd1966
Try with a different test regex
danieldunderfelt 954d830
Fix Jest configuration so that tests will run in CI.
danieldunderfelt fc0186e
Build updates, parity with Aspa.
danieldunderfelt c210ea7
Add dotenv-expand dependency that is required for .env files to work.
danieldunderfelt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,4 @@ | |
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
.cache-loader |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"*.ts?(x)": [ | ||
"prettier-tslint fix \"src/**/*.ts?(x)\"", | ||
"yarn run codestyle", | ||
"git add" | ||
], | ||
"*.css": [ | ||
|
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 |
---|---|---|
@@ -1 +1 @@ | ||
8.9 | ||
10 |
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,8 @@ | ||
{ | ||
"printWidth": 85, | ||
"semi": false, | ||
"singleQuote": true, | ||
"bracketSpacing": true, | ||
"jsxBracketSameLine": true, | ||
"arrowParens": "always" | ||
} |
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 |
---|---|---|
@@ -1,16 +1,33 @@ | ||
{ | ||
"extends": "stylelint-config-standard", | ||
"rules": { | ||
"comment-empty-line-before": false, | ||
"comment-whitespace-inside": false, | ||
"no-descending-specificity": false, | ||
"declaration-colon-newline-after": false, | ||
"selector-pseudo-element-colon-notation": "single", | ||
"at-rule-no-vendor-prefix": true, | ||
"declaration-empty-line-before": null, | ||
"font-family-name-quotes": "always-where-recommended", | ||
"function-url-quotes": "never", | ||
"string-quotes": "single", | ||
"selector-pseudo-class-no-unknown": [true, { | ||
"ignorePseudoClasses": ["global", "root"] | ||
}], | ||
"property-no-unknown": [true, { | ||
"ignoreProperties": ["composes"] | ||
}] | ||
"number-leading-zero": "never", | ||
"selector-pseudo-class-no-unknown": [ | ||
true, | ||
{ | ||
"ignorePseudoClasses": [ | ||
"global", | ||
"root" | ||
] | ||
} | ||
], | ||
'property-no-unknown': [ | ||
true, | ||
{ | ||
ignoreProperties: [ | ||
'composes' | ||
] | ||
} | ||
] | ||
} | ||
} |
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,22 @@ | ||
let fs = require('fs'); | ||
module.exports = WatchTimestampsPlugin; | ||
|
||
function WatchTimestampsPlugin(patterns) { | ||
this.patterns = patterns; | ||
} | ||
|
||
WatchTimestampsPlugin.prototype.apply = function(compiler) { | ||
compiler.plugin('watch-run', (watch, callback) => { | ||
let patterns = this.patterns; | ||
let timestamps = watch.fileTimestamps || watch.compiler.fileTimestamps; | ||
|
||
Object.keys(timestamps).forEach(filepath => { | ||
if (patterns.some(pat => pat instanceof RegExp ? pat.test(filepath) : !~filepath.indexOf(pat))) { | ||
let time = fs.statSync(filepath).mtime; | ||
if (timestamps instanceof Map) timestamps.set(filepath, time); | ||
else timestamps[filepath] = time; | ||
} | ||
}); | ||
callback(); | ||
}); | ||
}; |
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 |
---|---|---|
@@ -1,7 +1,12 @@ | ||
// Copyright 2004-present Facebook. All Rights Reserved. | ||
const tsc = require('typescript'); | ||
const tsConfig = require('../../tsconfig.test.json'); | ||
|
||
'use strict'; | ||
|
||
const tsJestPreprocessor = require('ts-jest/preprocessor'); | ||
|
||
module.exports = tsJestPreprocessor; | ||
module.exports = { | ||
process(src, path) { | ||
if (path.endsWith('.ts') || path.endsWith('.tsx')) { | ||
return tsc.transpile(src, tsConfig.compilerOptions, path, []); | ||
} | ||
return src; | ||
}, | ||
}; |
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,149 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var fs = require('fs'); | ||
var path = require('path'); | ||
var chalk = require('chalk'); | ||
var filesize = require('filesize'); | ||
var recursive = require('recursive-readdir'); | ||
var stripAnsi = require('strip-ansi'); | ||
var gzipSize = require('gzip-size').sync; | ||
|
||
// Prints a detailed summary of build files. | ||
function printFileSizesAfterBuild( | ||
webpackStats, | ||
previousSizeMap, | ||
buildFolder, | ||
maxBundleGzipSize, | ||
maxChunkGzipSize | ||
) { | ||
var root = previousSizeMap.root; | ||
var sizes = previousSizeMap.sizes; | ||
var assets = (webpackStats.stats || [webpackStats]) | ||
.map(stats => | ||
stats | ||
.toJson() | ||
.assets.filter(asset => /\.(js|css)$/.test(asset.name)) | ||
.map(asset => { | ||
var fileContents = fs.readFileSync(path.join(root, asset.name)); | ||
var size = gzipSize(fileContents); | ||
var previousSize = sizes[removeFileNameHash(root, asset.name)]; | ||
var difference = getDifferenceLabel(size, previousSize); | ||
return { | ||
folder: path.join( | ||
path.basename(buildFolder), | ||
path.dirname(asset.name) | ||
), | ||
name: path.basename(asset.name), | ||
size: size, | ||
sizeLabel: | ||
filesize(size) + (difference ? ' (' + difference + ')' : '') | ||
}; | ||
}) | ||
) | ||
.reduce((single, all) => all.concat(single), []); | ||
assets.sort((a, b) => b.size - a.size); | ||
var longestSizeLabelLength = Math.max.apply( | ||
null, | ||
assets.map(a => stripAnsi(a.sizeLabel).length) | ||
); | ||
var suggestBundleSplitting = false; | ||
assets.forEach(asset => { | ||
var sizeLabel = asset.sizeLabel; | ||
var sizeLength = stripAnsi(sizeLabel).length; | ||
if (sizeLength < longestSizeLabelLength) { | ||
var rightPadding = ' '.repeat(longestSizeLabelLength - sizeLength); | ||
sizeLabel += rightPadding; | ||
} | ||
var isMainBundle = asset.name.indexOf('main.') === 0; | ||
var maxRecommendedSize = isMainBundle | ||
? maxBundleGzipSize | ||
: maxChunkGzipSize; | ||
var isLarge = maxRecommendedSize && asset.size > maxRecommendedSize; | ||
if (isLarge && path.extname(asset.name) === '.js') { | ||
suggestBundleSplitting = true; | ||
} | ||
console.log( | ||
' ' + | ||
(isLarge ? chalk.yellow(sizeLabel) : sizeLabel) + | ||
' ' + | ||
chalk.dim(asset.folder + path.sep) + | ||
chalk.cyan(asset.name) | ||
); | ||
}); | ||
if (suggestBundleSplitting) { | ||
console.log(); | ||
console.log( | ||
chalk.yellow('The bundle size is significantly larger than recommended.') | ||
); | ||
console.log( | ||
chalk.yellow( | ||
'Consider reducing it with code splitting: https://goo.gl/9VhYWB' | ||
) | ||
); | ||
console.log( | ||
chalk.yellow( | ||
'You can also analyze the project dependencies: https://goo.gl/LeUzfb' | ||
) | ||
); | ||
} | ||
} | ||
|
||
function removeFileNameHash(buildFolder, fileName) { | ||
return fileName | ||
.replace(buildFolder, '') | ||
.replace( | ||
/\/?(.*)(\.[0-9a-f]+)(\.chunk)?(\.js|\.css)/, | ||
(match, p1, p2, p3, p4) => p1 + p4 | ||
); | ||
} | ||
|
||
// Input: 1024, 2048 | ||
// Output: "(+1 KB)" | ||
function getDifferenceLabel(currentSize, previousSize) { | ||
var FIFTY_KILOBYTES = 1024 * 50; | ||
var difference = currentSize - previousSize; | ||
var fileSize = !Number.isNaN(difference) ? filesize(difference) : 0; | ||
if (difference >= FIFTY_KILOBYTES) { | ||
return chalk.red('+' + fileSize); | ||
} else if (difference < FIFTY_KILOBYTES && difference > 0) { | ||
return chalk.yellow('+' + fileSize); | ||
} else if (difference < 0) { | ||
return chalk.green(fileSize); | ||
} else { | ||
return ''; | ||
} | ||
} | ||
|
||
function measureFileSizesBeforeBuild(buildFolder) { | ||
return new Promise(resolve => { | ||
recursive(buildFolder, (err, fileNames) => { | ||
var sizes; | ||
if (!err && fileNames) { | ||
sizes = fileNames | ||
.filter(fileName => /\.(js|css)$/.test(fileName)) | ||
.reduce((memo, fileName) => { | ||
var contents = fs.readFileSync(fileName); | ||
var key = removeFileNameHash(buildFolder, fileName); | ||
memo[key] = gzipSize(contents); | ||
return memo; | ||
}, {}); | ||
} | ||
resolve({ | ||
root: buildFolder, | ||
sizes: sizes || {}, | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
module.exports = { | ||
measureFileSizesBeforeBuild: measureFileSizesBeforeBuild, | ||
printFileSizesAfterBuild: printFileSizesAfterBuild, | ||
}; |
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,43 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
// This Webpack plugin lets us interpolate custom variables into `index.html`. | ||
// Usage: `new InterpolateHtmlPlugin({ 'MY_VARIABLE': 42 })` | ||
// Then, you can use %MY_VARIABLE% in your `index.html`. | ||
|
||
// It works in tandem with HtmlWebpackPlugin. | ||
// Learn more about creating plugins like this: | ||
// https://github.com/ampedandwired/html-webpack-plugin#events | ||
|
||
'use strict'; | ||
const escapeStringRegexp = require('escape-string-regexp'); | ||
|
||
class InterpolateHtmlPlugin { | ||
constructor(replacements) { | ||
this.replacements = replacements; | ||
} | ||
|
||
apply(compiler) { | ||
compiler.hooks.compilation.tap('InterpolateHtmlPlugin', compilation => { | ||
compilation.hooks.htmlWebpackPluginBeforeHtmlProcessing.tap( | ||
'InterpolateHtmlPlugin', | ||
data => { | ||
// Run HTML through a series of user-specified string replacements. | ||
Object.keys(this.replacements).forEach(key => { | ||
const value = this.replacements[key]; | ||
data.html = data.html.replace( | ||
new RegExp('%' + escapeStringRegexp(key) + '%', 'g'), | ||
value | ||
); | ||
}); | ||
} | ||
); | ||
}); | ||
} | ||
} | ||
|
||
module.exports = InterpolateHtmlPlugin; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unified command to run tslint + Prettier and fix all codestyle issues.