Merge pull request #280 from substantial/replace-gulp
Replace Gulp and travisci
This commit is contained in:
commit
ad1a73326e
32
.circleci/config.yml
Normal file
32
.circleci/config.yml
Normal file
@ -0,0 +1,32 @@
|
||||
version: 2.1
|
||||
|
||||
orbs:
|
||||
node: circleci/node@1.1.6
|
||||
yarn: substantial/yarn@3.10.2
|
||||
node-build: substantial/node-build@2.3.0
|
||||
|
||||
jobs:
|
||||
build:
|
||||
executor:
|
||||
name: node/default
|
||||
tag: '12.14.1'
|
||||
steps:
|
||||
- checkout
|
||||
- yarn/install:
|
||||
cache-version: v2
|
||||
yarn-audit: false
|
||||
- node-build/eslint
|
||||
- run:
|
||||
name: Test
|
||||
command: |
|
||||
yarn test
|
||||
- run:
|
||||
name: dtslint
|
||||
command: |
|
||||
yarn dtslint
|
||||
- run:
|
||||
name: build
|
||||
command: |
|
||||
yarn build
|
||||
- node-build/store-results
|
||||
- node-build/release
|
31
.eslintrc
31
.eslintrc
@ -1,31 +0,0 @@
|
||||
{
|
||||
"extends": [
|
||||
"airbnb-base",
|
||||
"prettier"
|
||||
],
|
||||
"plugins": [
|
||||
"prettier"
|
||||
],
|
||||
"ecmaFeatures": {
|
||||
"experimentalObjectRestSpread": true
|
||||
},
|
||||
"rules": {
|
||||
"prettier/prettier": [
|
||||
"error",
|
||||
{
|
||||
"bracketSpacing": true,
|
||||
"semi": false,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "es5"
|
||||
}
|
||||
],
|
||||
"no-confusing-arrow": "off",
|
||||
"comma-dangle": ["error", {
|
||||
"arrays": "always-multiline",
|
||||
"objects": "always-multiline",
|
||||
"imports": "always-multiline",
|
||||
"exports": "always-multiline",
|
||||
"functions": "never"
|
||||
}]
|
||||
}
|
||||
}
|
81
.eslintrc.js
Normal file
81
.eslintrc.js
Normal file
@ -0,0 +1,81 @@
|
||||
const config = {
|
||||
parserOptions: {
|
||||
ecmaVersion: 2018,
|
||||
},
|
||||
env: {
|
||||
node: true,
|
||||
},
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"prettier"
|
||||
],
|
||||
"plugins": [
|
||||
"prettier"
|
||||
],
|
||||
"rules": {
|
||||
"no-confusing-arrow": "off",
|
||||
"comma-dangle": ["error", {
|
||||
"arrays": "always-multiline",
|
||||
"objects": "always-multiline",
|
||||
"imports": "always-multiline",
|
||||
"exports": "always-multiline",
|
||||
"functions": "never"
|
||||
}]
|
||||
},
|
||||
overrides: [
|
||||
{
|
||||
files: ['lib/**/*'],
|
||||
env: {
|
||||
es6: true,
|
||||
},
|
||||
parserOptions: {
|
||||
sourceType: 'module',
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ['test/**/*'] ,
|
||||
env: {
|
||||
mocha: true
|
||||
},
|
||||
parserOptions: {
|
||||
sourceType: 'module',
|
||||
},
|
||||
rules: {
|
||||
"no-unused-expressions": 'off'
|
||||
}
|
||||
},
|
||||
{
|
||||
files: ['**/*.@(ts|tsx)'],
|
||||
parser: '@typescript-eslint/parser',
|
||||
plugins: ['@typescript-eslint'],
|
||||
parserOptions: {
|
||||
sourceType: 'module',
|
||||
},
|
||||
rules: {
|
||||
'@typescript-eslint/class-name-casing': 'error',
|
||||
'@typescript-eslint/consistent-type-assertions': 'error',
|
||||
'@typescript-eslint/no-empty-interface': 'error',
|
||||
'@typescript-eslint/no-non-null-assertion': 'error',
|
||||
'@typescript-eslint/type-annotation-spacing': 'error',
|
||||
'@typescript-eslint/no-unused-vars': [
|
||||
'error',
|
||||
{
|
||||
argsIgnorePattern: '^_',
|
||||
ignoreRestSiblings: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ['**/*.d.ts'],
|
||||
rules: {
|
||||
'@typescript-eslint/no-useless-constructor': 'error',
|
||||
'no-var': 'off',
|
||||
'no-useless-constructor': 'off',
|
||||
strict: 'off',
|
||||
},
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
module.exports = config
|
4
.prettierignore
Normal file
4
.prettierignore
Normal file
@ -0,0 +1,4 @@
|
||||
package.json
|
||||
node_modules
|
||||
dist
|
||||
coverage
|
@ -1,9 +0,0 @@
|
||||
sudo: false
|
||||
language: node_js
|
||||
node_js:
|
||||
- '8'
|
||||
- '10'
|
||||
notifications:
|
||||
email:
|
||||
on_success: change
|
||||
on_failure: always
|
10
README.md
10
README.md
@ -7,7 +7,7 @@
|
||||
|
||||
[![Join the chat at https://gitter.im/substantial/updeep](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/substantial/updeep?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
[![NPM version][npm-image]][npm-url]
|
||||
[![Build Status][travis-image]][travis-url]
|
||||
[![Build Status][circleci-image]][circleci-url]
|
||||
[![Code Climate][codeclimate-image]][codeclimate-url]
|
||||
|
||||
[![Dependency Status][daviddm-image]][daviddm-url]
|
||||
@ -533,10 +533,10 @@ case.
|
||||
```bash
|
||||
$ npm login
|
||||
```
|
||||
1. Make sure the build passes (best to let it pass on travis, but you can run it locally):
|
||||
1. Make sure the build passes (best to let it pass on circleci, but you can run it locally):
|
||||
|
||||
```bash
|
||||
$ gulp
|
||||
$ npm build
|
||||
```
|
||||
1. Bump the version:
|
||||
|
||||
@ -572,8 +572,8 @@ MIT ©2015 [Substantial](http://substantial.com)
|
||||
[docset]: https://github.com/yanick/dash-docset-updeep
|
||||
[npm-image]: https://badge.fury.io/js/updeep.svg
|
||||
[npm-url]: https://npmjs.org/package/updeep
|
||||
[travis-image]: https://travis-ci.org/substantial/updeep.svg?branch=master
|
||||
[travis-url]: https://travis-ci.org/substantial/updeep
|
||||
[circleci-image]: https://circleci.com/gh/substantial/updeep.svg?style=shield
|
||||
[circleci-url]: https://circleci.com/gh/substantial/updeep
|
||||
[daviddm-image]: https://david-dm.org/substantial/updeep.svg?theme=shields.io
|
||||
[daviddm-url]: https://david-dm.org/substantial/updeep
|
||||
[daviddm-peer-image]: https://david-dm.org/substantial/updeep/peer-status.svg
|
||||
|
17
babel.config.js
Normal file
17
babel.config.js
Normal file
@ -0,0 +1,17 @@
|
||||
module.exports = (api) => {
|
||||
api.cache(true)
|
||||
return {
|
||||
presets: [
|
||||
[
|
||||
'@babel/preset-env',
|
||||
{
|
||||
loose: true,
|
||||
targets: {
|
||||
browsers: ['last 2 versions', 'IE >= 9'],
|
||||
},
|
||||
},
|
||||
],
|
||||
'@babel/preset-typescript',
|
||||
],
|
||||
}
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
"use strict"; // eslint-disable-line
|
||||
/* eslint no-var:0, func-names:0, import/no-extraneous-dependencies:0 */
|
||||
|
||||
var webpack = require('webpack')
|
||||
|
||||
module.exports = function createWebpackConfig(_options) {
|
||||
var config
|
||||
var options = _options || {}
|
||||
var env = options.env || 'development'
|
||||
|
||||
config = {
|
||||
context: options.context,
|
||||
entry: options.entry,
|
||||
|
||||
plugins: [
|
||||
new webpack.optimize.OccurrenceOrderPlugin(),
|
||||
new webpack.DefinePlugin({
|
||||
'process.env': {
|
||||
NODE_ENV: JSON.stringify(env),
|
||||
},
|
||||
}),
|
||||
],
|
||||
|
||||
node: {
|
||||
process: false,
|
||||
},
|
||||
|
||||
module: {
|
||||
loaders: [
|
||||
{ test: /\.js$/, loaders: ['babel-loader'], exclude: /node_modules/ },
|
||||
],
|
||||
},
|
||||
|
||||
output: {
|
||||
library: 'updeep',
|
||||
libraryTarget: 'umd',
|
||||
},
|
||||
|
||||
resolve: {
|
||||
extensions: ['', '.js'],
|
||||
},
|
||||
}
|
||||
|
||||
config.output.filename = options.filename
|
||||
|
||||
if (options.minify) {
|
||||
config.plugins.push(
|
||||
new webpack.optimize.UglifyJsPlugin({
|
||||
compressor: {
|
||||
pure_getters: true,
|
||||
unsafe: true,
|
||||
unsafe_comps: true,
|
||||
screw_ie8: true,
|
||||
warnings: false,
|
||||
},
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
return config
|
||||
}
|
95
gulpfile.js
95
gulpfile.js
@ -1,95 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
/* eslint strict:0, no-var:0, func-names:0 */
|
||||
var path = require('path')
|
||||
var gulp = require('gulp')
|
||||
|
||||
var babel = require('gulp-babel')
|
||||
var eslint = require('gulp-eslint')
|
||||
var mocha = require('gulp-mocha')
|
||||
var rimraf = require('rimraf')
|
||||
var webpack = require('webpack-stream')
|
||||
|
||||
var KarmaServer = require('karma').Server
|
||||
|
||||
var createWebpackConfig = require('./createWebpackConfig.js')
|
||||
|
||||
// Initialize the babel transpiler so ES2015 files gets compiled
|
||||
// when they're loaded
|
||||
require('babel-core/register')
|
||||
|
||||
gulp.task('clean', cb => {
|
||||
rimraf('./dist', cb)
|
||||
})
|
||||
|
||||
gulp.task('static', () =>
|
||||
gulp
|
||||
.src(['*.js', 'lib/**/*.js', 'test/**/*.js'])
|
||||
.pipe(eslint())
|
||||
.pipe(eslint.format())
|
||||
.pipe(eslint.failAfterError())
|
||||
)
|
||||
|
||||
gulp.task('test', ['test:karma', 'test:node'])
|
||||
|
||||
gulp.task('test:node', () =>
|
||||
gulp.src('test/**/*.js').pipe(mocha({ reporter: 'dot' }))
|
||||
)
|
||||
|
||||
gulp.task('test:karma', done => {
|
||||
new KarmaServer(
|
||||
{
|
||||
configFile: path.join(__dirname, 'karma.conf.js'),
|
||||
singleRun: true,
|
||||
},
|
||||
done
|
||||
).start()
|
||||
})
|
||||
|
||||
gulp.task('babel', () =>
|
||||
gulp
|
||||
.src('lib/**/*.js')
|
||||
.pipe(babel())
|
||||
.pipe(gulp.dest('dist'))
|
||||
)
|
||||
|
||||
gulp.task('watch', () => {
|
||||
gulp.start(['test:node'])
|
||||
gulp.watch(['lib/**/*.js', 'test/**/*.js'], ['test:node'])
|
||||
new KarmaServer({
|
||||
configFile: path.join(__dirname, 'karma.conf.js'),
|
||||
}).start()
|
||||
})
|
||||
|
||||
gulp.task('webpack', ['webpack:standalone', 'webpack:standalone:min'])
|
||||
|
||||
gulp.task('webpack:standalone', () => {
|
||||
var config = createWebpackConfig({ filename: 'updeep-standalone.js' })
|
||||
|
||||
return gulp
|
||||
.src('lib/index.js')
|
||||
.pipe(webpack(config))
|
||||
.pipe(gulp.dest('dist/umd/'))
|
||||
})
|
||||
|
||||
gulp.task('webpack:standalone:min', () => {
|
||||
var config = createWebpackConfig({
|
||||
filename: 'updeep-standalone.min.js',
|
||||
minify: true,
|
||||
env: 'production',
|
||||
})
|
||||
|
||||
return gulp
|
||||
.src('lib/index.js')
|
||||
.pipe(webpack(config))
|
||||
.pipe(gulp.dest('dist/umd/'))
|
||||
})
|
||||
|
||||
gulp.task('build', ['babel', 'webpack'])
|
||||
|
||||
gulp.task('build:clean', ['clean'], done => {
|
||||
gulp.start('build', done)
|
||||
})
|
||||
|
||||
gulp.task('prepublish', ['build:clean'])
|
||||
gulp.task('default', ['static', 'test'])
|
7
husky.config.js
Normal file
7
husky.config.js
Normal file
@ -0,0 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
hooks: {
|
||||
"pre-commit": "yarn run lint-staged",
|
||||
},
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
/* eslint strict:0, no-var:0, func-names:0 */
|
||||
|
||||
var createWebpackConfig = require('./createWebpackConfig')
|
||||
|
||||
module.exports = function(config) {
|
||||
config.set({
|
||||
// base path that will be used to resolve all patterns (eg. files, exclude)
|
||||
basePath: '',
|
||||
|
||||
// frameworks to use
|
||||
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
|
||||
frameworks: ['mocha'],
|
||||
|
||||
// list of files / patterns to load in the browser
|
||||
files: [
|
||||
{ pattern: 'test/**/*.js', watched: false, included: true, served: true },
|
||||
],
|
||||
|
||||
// list of files to exclude
|
||||
exclude: [],
|
||||
|
||||
// preprocess matching files before serving them to the browser
|
||||
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
|
||||
preprocessors: {
|
||||
'test/**/*.js': ['webpack'],
|
||||
},
|
||||
|
||||
webpack: createWebpackConfig(),
|
||||
|
||||
webpackMiddleware: {
|
||||
noInfo: true,
|
||||
watch: true,
|
||||
},
|
||||
|
||||
// test results reporter to use
|
||||
// possible values: 'dots', 'progress'
|
||||
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
|
||||
reporters: ['dots'],
|
||||
|
||||
// web server port
|
||||
port: 9876,
|
||||
|
||||
// enable / disable colors in the output (reporters and logs)
|
||||
colors: true,
|
||||
|
||||
// level of logging
|
||||
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN ||
|
||||
// config.LOG_INFO || config.LOG_DEBUG
|
||||
logLevel: config.LOG_INFO,
|
||||
|
||||
// start these browsers
|
||||
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
|
||||
browsers: ['PhantomJS'],
|
||||
|
||||
// Continuous Integration mode
|
||||
// if true, Karma captures browsers, runs the tests and exits
|
||||
singleRun: false,
|
||||
})
|
||||
}
|
@ -13,7 +13,7 @@ function needsFreezing(object) {
|
||||
function recur(object) {
|
||||
Object.freeze(object)
|
||||
|
||||
Object.keys(object).forEach(key => {
|
||||
Object.keys(object).forEach((key) => {
|
||||
const value = object[key]
|
||||
if (needsFreezing(value)) {
|
||||
recur(value)
|
||||
|
@ -2,5 +2,5 @@ import ifElse from './ifElse'
|
||||
import curry from './util/curry'
|
||||
|
||||
export default curry((predicate, trueUpdates, object) =>
|
||||
ifElse(predicate, trueUpdates, x => x, object)
|
||||
ifElse(predicate, trueUpdates, (x) => x, object)
|
||||
)
|
||||
|
@ -29,4 +29,4 @@ u.updateIn = updateIn
|
||||
u.omitted = omitted
|
||||
u.withDefault = withDefault
|
||||
|
||||
module.exports = u
|
||||
export default u
|
||||
|
@ -47,7 +47,7 @@ function resolveUpdates(updates, object) {
|
||||
function updateArray(updates, object) {
|
||||
const newArray = [...object]
|
||||
|
||||
Object.keys(updates).forEach(key => {
|
||||
Object.keys(updates).forEach((key) => {
|
||||
newArray[key] = updates[key]
|
||||
})
|
||||
|
||||
@ -91,13 +91,13 @@ function update(updates, object, ...args) {
|
||||
|
||||
if (Array.isArray(defaultedObject)) {
|
||||
return updateArray(resolvedUpdates, defaultedObject).filter(
|
||||
value => value !== innerOmitted
|
||||
(value) => value !== innerOmitted
|
||||
)
|
||||
}
|
||||
|
||||
return _omitBy(
|
||||
{ ...defaultedObject, ...resolvedUpdates },
|
||||
value => value === innerOmitted
|
||||
(value) => value === innerOmitted
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ const wildcard = '*'
|
||||
|
||||
function reducePath(acc, key) {
|
||||
if (key === wildcard) {
|
||||
return value =>
|
||||
return (value) =>
|
||||
Object.prototype.hasOwnProperty.call(value, wildcard)
|
||||
? // If we actually have wildcard as a property, update that
|
||||
update({ [wildcard]: acc }, value)
|
||||
|
@ -1,5 +1,5 @@
|
||||
import reject from 'lodash/reject'
|
||||
|
||||
export default function splitPath(path) {
|
||||
return Array.isArray(path) ? path : reject(`${path}`.split('.'), x => !x)
|
||||
return Array.isArray(path) ? path : reject(`${path}`.split('.'), (x) => !x)
|
||||
}
|
||||
|
6
lint-staged.config.js
Normal file
6
lint-staged.config.js
Normal file
@ -0,0 +1,6 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
'*.{js,ts}': ['eslint --fix'],
|
||||
'*.{md,json,html,yml}': ['prettier --write'],
|
||||
}
|
75
package.json
75
package.json
@ -12,64 +12,59 @@
|
||||
"dist",
|
||||
"types"
|
||||
],
|
||||
"main": "dist/index.js",
|
||||
"keywords": [
|
||||
"immutable",
|
||||
"frozen",
|
||||
"functional",
|
||||
"declarative"
|
||||
],
|
||||
"scripts": {
|
||||
"dtslint": "dtslint --localTs node_modules/typescript/lib types",
|
||||
"test": "gulp && yarn -s dtslint",
|
||||
"test:watch": "gulp watch",
|
||||
"prepublish": "gulp prepublish",
|
||||
"perf-server": "`npm bin`/webpack-dev-server --config perf/webpack.config.js --hot"
|
||||
},
|
||||
"source": "lib/index.js",
|
||||
"main": "dist/index.js",
|
||||
"module": "dist/index.module.js",
|
||||
"types": "types",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/substantial/updeep/issues"
|
||||
},
|
||||
"scripts": {
|
||||
"benchmark": "NODE_ENV=production node --require \"@babel/register\" perf",
|
||||
"build": "microbundle",
|
||||
"dev": "microbundle watch",
|
||||
"dtslint": "dtslint --localTs node_modules/typescript/lib types",
|
||||
"eslint": "eslint --ext .js,.jsx,.ts,.tsx",
|
||||
"lint": "yarn -s eslint . && yarn -s dtslint",
|
||||
"test": "mocha --recursive --require \"@babel/register\" test"
|
||||
},
|
||||
"dependencies": {
|
||||
"lodash": "^4.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.7.0",
|
||||
"@babel/plugin-proposal-object-rest-spread": "^7.6.2",
|
||||
"@babel/preset-env": "^7.7.1",
|
||||
"@babel/preset-typescript": "^7.9.0",
|
||||
"@babel/register": "^7.7.0",
|
||||
"@types/chai": "^4.1.7",
|
||||
"@types/lodash": "^4.14.119",
|
||||
"@types/mocha": "^7.0.1",
|
||||
"@types/node": "^13.1.0",
|
||||
"babel-core": "^6.4.0",
|
||||
"babel-loader": "^6.2.1",
|
||||
"babel-preset-es2015": "^6.3.13",
|
||||
"babel-preset-stage-2": "^6.3.13",
|
||||
"@types/node": "^13.9.8",
|
||||
"@typescript-eslint/eslint-plugin": "^2.26.0",
|
||||
"@typescript-eslint/parser": "^2.26.0",
|
||||
"benchmark": "^2.1.4",
|
||||
"chai": "^4.2.0",
|
||||
"dtslint": "^2.0.0",
|
||||
"eslint": "^4.19.1",
|
||||
"eslint-config-airbnb-base": "^11.1.3",
|
||||
"eslint-config-prettier": "^6.3.0",
|
||||
"eslint-plugin-import": "^2.2.0",
|
||||
"eslint-plugin-prettier": "^2.0.1",
|
||||
"exports-loader": "^0.7.0",
|
||||
"gulp": "^3.6.0",
|
||||
"gulp-babel": "^7.0.1",
|
||||
"gulp-eslint": "^3.0.1",
|
||||
"gulp-mocha": "^2.0.0",
|
||||
"karma": "^4.3.0",
|
||||
"karma-babel-preprocessor": "^7.0.0",
|
||||
"karma-chrome-launcher": "^3.1.0",
|
||||
"karma-mocha": "^1.3.0",
|
||||
"karma-mocha-reporter": "^2.2.5",
|
||||
"karma-phantomjs-launcher": "^1.0.4",
|
||||
"karma-webpack": "^2.0.13",
|
||||
"chalk": "^4.0.0",
|
||||
"dtslint": "^3.4.1",
|
||||
"eslint": "^6.8.0",
|
||||
"eslint-config-prettier": "^6.10.1",
|
||||
"eslint-plugin-expect-type": "^0.0.4",
|
||||
"eslint-plugin-import": "^2.20.2",
|
||||
"eslint-plugin-prettier": "^3.1.2",
|
||||
"husky": "^4.2.3",
|
||||
"lint-staged": "^10.1.1",
|
||||
"microbundle": "^0.11.0",
|
||||
"mocha": "^7.0.0",
|
||||
"phantomjs-prebuilt": "^2.1.14",
|
||||
"prettier": "^1.1.0",
|
||||
"rimraf": "^3.0.0",
|
||||
"typescript": "^3.6.3",
|
||||
"webpack": "^1.10.5",
|
||||
"webpack-dev-server": "^3.1.11",
|
||||
"webpack-stream": "^2.1.0"
|
||||
},
|
||||
"types": "types"
|
||||
"prettier": "^2.0.2",
|
||||
"table": "^5.4.6",
|
||||
"typescript": "^3.6.3"
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +0,0 @@
|
||||
{
|
||||
"extends": "../.eslintrc",
|
||||
"rules": {
|
||||
"new-cap": [2, {
|
||||
"capIsNewExceptions": [
|
||||
"Suite"
|
||||
]
|
||||
}],
|
||||
}
|
||||
}
|
14
perf/.eslintrc.js
Normal file
14
perf/.eslintrc.js
Normal file
@ -0,0 +1,14 @@
|
||||
module.exports = {
|
||||
extends: require.resolve("../.eslintrc.js"),
|
||||
env: {
|
||||
node: true,
|
||||
es6: true,
|
||||
},
|
||||
parserOptions: {
|
||||
sourceType: 'module',
|
||||
},
|
||||
rules: {
|
||||
'no-unused-vars': 'off',
|
||||
'@typescript-eslint/no-unused-vars': 'off'
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>updeep perf</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
</head>
|
||||
<body>
|
||||
<div>Running tests...</div>
|
||||
<div id='perf'></div>
|
||||
<script src='/assets/perf.js'></script>
|
||||
<p>Done!</p>
|
||||
</body>
|
||||
</html>
|
@ -1,14 +1,14 @@
|
||||
/* eslint no-console:0, no-unused-vars:0, import/no-extraneous-dependencies:0 */
|
||||
/* global document */
|
||||
const Benchmark = require('benchmark')
|
||||
import Benchmark from 'benchmark'
|
||||
import {table} from 'table'
|
||||
import chalk from 'chalk'
|
||||
|
||||
const u = require('../lib')
|
||||
const _ = require('lodash')
|
||||
const { curry2, curry4 } = require('../lib/util/curry')
|
||||
import _ from 'lodash'
|
||||
import u from '../dist/index.umd.js'
|
||||
import {curry2, curry4 } from '../lib/util/curry'
|
||||
|
||||
const add4 = (a, b, c, d) => a + b + c + d
|
||||
const add2 = (a, b) => a + b
|
||||
const fakeCurryAdd = x => y => x + y
|
||||
const fakeCurryAdd = (x) => (y) => x + y
|
||||
const lodashCurryAdd2 = _.curry(add2)
|
||||
const updeepCurryAdd2 = curry2(add2)
|
||||
const lodashCurryAdd4 = _.curry(add4)
|
||||
@ -18,33 +18,31 @@ const updeepCurryAdd4 = curry4(add4)
|
||||
const array = [0, 1, 2, 3, 4, 5]
|
||||
// const doUpdate = u(x => x + 1);
|
||||
|
||||
function log(str) {
|
||||
if (typeof document !== 'undefined') {
|
||||
console.log(str)
|
||||
const el = document.getElementById('perf')
|
||||
el.innerHTML += str
|
||||
}
|
||||
}
|
||||
|
||||
const log = console.log
|
||||
|
||||
function createSuite(suiteName, tests) {
|
||||
const suite = Benchmark.Suite() // eslint-disable
|
||||
const results = []
|
||||
|
||||
return () => {
|
||||
log(`<h2>${suiteName}</h2><ul>`)
|
||||
const suite = Benchmark.Suite({
|
||||
onCycle: (event) => {
|
||||
results.push(event.target)
|
||||
},
|
||||
onError: (event) => {
|
||||
console.error(event)
|
||||
},
|
||||
})
|
||||
|
||||
_.each(tests, (fn, testName) => {
|
||||
suite.add(testName, fn)
|
||||
})
|
||||
|
||||
suite
|
||||
.on('cycle', event => {
|
||||
log(`<li>${String(event.target)}</li>`)
|
||||
return () => new Promise((resolve, reject) => {
|
||||
suite.on('complete', () => resolve({
|
||||
suiteName,
|
||||
results,
|
||||
})).on('error', reject).run({ async: true})
|
||||
})
|
||||
.on('complete', () => {
|
||||
log('</ul>')
|
||||
})
|
||||
.run({ async: true })
|
||||
}
|
||||
}
|
||||
|
||||
const curryVsLodash = createSuite('Curry', {
|
||||
@ -82,6 +80,25 @@ const applyVsDestructure = createSuite('apply vs destructure', {
|
||||
destructure: () => fnDestructure(1, 2, 3, 4, 5),
|
||||
})
|
||||
|
||||
curryVsLodash()
|
||||
mapVsLodash()
|
||||
// applyVsDestructure();
|
||||
const printSuiteResults = (suiteResults) => {
|
||||
const HEADERS = ['Suite Name', 'Results (fastest first)'].map(s => chalk.bold(s))
|
||||
|
||||
const data = suiteResults.reduce((acc, {suiteName, results}) => {
|
||||
const row = [
|
||||
chalk.cyan(suiteName),
|
||||
results.sort((a, b) => -a.compare(b)).map(String).join('\n'),
|
||||
]
|
||||
|
||||
acc.push(row)
|
||||
return acc
|
||||
}, [HEADERS])
|
||||
|
||||
log(table(data))
|
||||
}
|
||||
|
||||
|
||||
Promise.all([
|
||||
curryVsLodash(),
|
||||
mapVsLodash(),
|
||||
// applyVsDestructure(),
|
||||
]).then(printSuiteResults)
|
||||
|
@ -1,29 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
/* eslint strict:0, no-var:0, func-names:0 */
|
||||
|
||||
var path = require('path')
|
||||
|
||||
var config = require('../createWebpackConfig')({
|
||||
context: __dirname,
|
||||
entry: ['webpack/hot/dev-server', './index.js'],
|
||||
minify: false,
|
||||
env: 'production',
|
||||
})
|
||||
|
||||
config.output = {
|
||||
path: path.join(__dirname, './build'),
|
||||
publicPath: '/assets/',
|
||||
filename: 'perf.js',
|
||||
}
|
||||
|
||||
config.devServer = {
|
||||
contentBase: __dirname,
|
||||
noInfo: true,
|
||||
hot: true,
|
||||
inline: true,
|
||||
}
|
||||
|
||||
config.module.noParse = [/benchmark\.js$/]
|
||||
|
||||
module.exports = config
|
12
prettier.config.js
Normal file
12
prettier.config.js
Normal file
@ -0,0 +1,12 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
endOfLine: 'lf',
|
||||
semi: false,
|
||||
singleQuote: true,
|
||||
tabWidth: 2,
|
||||
trailingComma: 'es5',
|
||||
bracketSpacing: false,
|
||||
|
||||
proseWrap: 'always',
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
{
|
||||
"env": {
|
||||
"mocha": true
|
||||
},
|
||||
"rules": {
|
||||
"no-unused-expressions": 0
|
||||
}
|
||||
}
|
@ -50,15 +50,14 @@ describe('u.freeze', () => {
|
||||
expect(Object.isFrozen(object.foo)).to.be.false
|
||||
})
|
||||
|
||||
if (typeof process !== 'undefined') {
|
||||
it('does not freeze in production', () => {
|
||||
process.env.NODE_ENV = 'production'
|
||||
|
||||
const object = {}
|
||||
u.freeze(object)
|
||||
|
||||
expect(Object.isFrozen(object)).to.be.false
|
||||
})
|
||||
}
|
||||
|
||||
it('handles null objects', () => {
|
||||
const object = { foo: null }
|
||||
|
@ -19,7 +19,7 @@ describe('u.if', () => {
|
||||
|
||||
it('will use the result of a function passed as a predicate', () => {
|
||||
const object = { a: 0 }
|
||||
const aIsThree = x => x.a === 3
|
||||
const aIsThree = (x) => x.a === 3
|
||||
const result = u.if(aIsThree, { b: 1 }, object)
|
||||
|
||||
expect(result).to.eql({ a: 0 })
|
||||
@ -27,8 +27,8 @@ describe('u.if', () => {
|
||||
|
||||
it('can be partially applied', () => {
|
||||
const object = { a: 2 }
|
||||
const isEven = x => x % 2 === 0
|
||||
const inc = x => x + 1
|
||||
const isEven = (x) => x % 2 === 0
|
||||
const inc = (x) => x + 1
|
||||
|
||||
const result = u(
|
||||
{
|
||||
|
@ -16,7 +16,7 @@ describe('u.ifElse', () => {
|
||||
|
||||
it('will use the result of a function passed as a predicate', () => {
|
||||
const object = { a: 0 }
|
||||
const aIsThree = x => x.a === 3
|
||||
const aIsThree = (x) => x.a === 3
|
||||
const result = u.ifElse(aIsThree, { b: 1 }, { b: 4 }, object)
|
||||
|
||||
expect(result).to.eql({ a: 0, b: 4 })
|
||||
@ -24,9 +24,9 @@ describe('u.ifElse', () => {
|
||||
|
||||
it('can be partially applied', () => {
|
||||
const object = { a: 2 }
|
||||
const isEven = x => x % 2 === 0
|
||||
const inc = x => x + 1
|
||||
const dec = x => x - 1
|
||||
const isEven = (x) => x % 2 === 0
|
||||
const inc = (x) => x + 1
|
||||
const dec = (x) => x - 1
|
||||
|
||||
const result = u(
|
||||
{
|
||||
|
@ -8,7 +8,7 @@ describe('u.is', () => {
|
||||
})
|
||||
|
||||
it('returns true if path matches a function predicate', () => {
|
||||
const isEven = x => x % 2 === 0
|
||||
const isEven = (x) => x % 2 === 0
|
||||
const result = u.is('a.b', isEven, { a: { b: 6 } })
|
||||
expect(result).to.be.true
|
||||
})
|
||||
@ -19,7 +19,7 @@ describe('u.is', () => {
|
||||
})
|
||||
|
||||
it('returns false if path matches a function predicate', () => {
|
||||
const isEven = x => x % 2 === 0
|
||||
const isEven = (x) => x % 2 === 0
|
||||
const result = u.is('a.b', isEven, { a: { b: 7 } })
|
||||
expect(result).to.be.false
|
||||
})
|
||||
|
@ -4,7 +4,7 @@ import u from '../lib'
|
||||
describe('u.map', () => {
|
||||
it('applies updates to each item in an array', () => {
|
||||
const object = [0, 1, 2]
|
||||
const inc = x => x + 1
|
||||
const inc = (x) => x + 1
|
||||
const result = u.map(inc, object)
|
||||
|
||||
expect(result).to.eql([1, 2, 3])
|
||||
@ -12,7 +12,7 @@ describe('u.map', () => {
|
||||
|
||||
it('applies updates to each value in an object', () => {
|
||||
const object = { a: 0, b: 1, c: 2 }
|
||||
const inc = x => x + 1
|
||||
const inc = (x) => x + 1
|
||||
const result = u.map(inc, object)
|
||||
|
||||
expect(result).to.eql({ a: 1, b: 2, c: 3 })
|
||||
@ -27,7 +27,7 @@ describe('u.map', () => {
|
||||
|
||||
it('returns the same object if no updates are made', () => {
|
||||
const array = [0, 1]
|
||||
const ident = x => x
|
||||
const ident = (x) => x
|
||||
let result = u.map(ident, array)
|
||||
|
||||
expect(result).to.equal(array)
|
||||
|
@ -18,7 +18,7 @@ describe('u.reject', () => {
|
||||
const object = { foo: [1, 2, 3] }
|
||||
const result = u(
|
||||
{
|
||||
foo: u.reject(x => x === 'Justin Bieber'),
|
||||
foo: u.reject((x) => x === 'Justin Bieber'),
|
||||
},
|
||||
object
|
||||
)
|
||||
@ -30,7 +30,7 @@ describe('u.reject', () => {
|
||||
const object = { foo: [1, 2, 3, 4] }
|
||||
const result = u(
|
||||
{
|
||||
foo: u.reject(x => x === 4),
|
||||
foo: u.reject((x) => x === 4),
|
||||
},
|
||||
object
|
||||
)
|
||||
|
@ -9,7 +9,7 @@ describe('u.updateIn', () => {
|
||||
})
|
||||
|
||||
it('can update a single path described with a string with a function', () => {
|
||||
const inc = x => x + 1
|
||||
const inc = (x) => x + 1
|
||||
const object = { a: { b: 0 } }
|
||||
const result = u.updateIn('a.b', inc, object)
|
||||
expect(result).to.eql({ a: { b: 1 } })
|
||||
@ -45,17 +45,17 @@ describe('u.updateIn', () => {
|
||||
|
||||
it('can multiple elements of an array with *', () => {
|
||||
let object = { a: [{ b: 0 }, { b: 1 }, { b: 2 }] }
|
||||
let result = u.updateIn('a.*.b', x => x + 1, object)
|
||||
let result = u.updateIn('a.*.b', (x) => x + 1, object)
|
||||
expect(result).to.eql({ a: [{ b: 1 }, { b: 2 }, { b: 3 }] })
|
||||
|
||||
object = { a: [0, 1, 2] }
|
||||
result = u.updateIn(['a', '*'], x => x + 1, object)
|
||||
result = u.updateIn(['a', '*'], (x) => x + 1, object)
|
||||
expect(result).to.eql({ a: [1, 2, 3] })
|
||||
})
|
||||
|
||||
it('can update properties named *', () => {
|
||||
const object = { '*': 1, x: 1 }
|
||||
const result = u.updateIn('*', x => x + 1, object)
|
||||
const result = u.updateIn('*', (x) => x + 1, object)
|
||||
expect(result).to.eql({ '*': 2, x: 1 })
|
||||
})
|
||||
})
|
||||
|
@ -57,7 +57,7 @@ describe('updeep', () => {
|
||||
})
|
||||
|
||||
it('can use functions to update values', () => {
|
||||
const inc = i => i + 1
|
||||
const inc = (i) => i + 1
|
||||
const object = { foo: 3, bar: 4, baz: 7 }
|
||||
const result = u({ foo: inc, bar: inc }, object)
|
||||
|
||||
@ -65,7 +65,7 @@ describe('updeep', () => {
|
||||
})
|
||||
|
||||
it('can be partially applied', () => {
|
||||
const inc = i => i + 1
|
||||
const inc = (i) => i + 1
|
||||
const object = { foo: 3 }
|
||||
const incFoo = u({ foo: inc })
|
||||
|
||||
@ -95,7 +95,7 @@ describe('updeep', () => {
|
||||
})
|
||||
|
||||
it('can take a function as the updater', () => {
|
||||
const result = u(i => i + 1, 7)
|
||||
const result = u((i) => i + 1, 7)
|
||||
|
||||
expect(result).to.eql(8)
|
||||
})
|
||||
@ -148,7 +148,7 @@ describe('updeep', () => {
|
||||
|
||||
describe('u.omitted', () => {
|
||||
it('omit properties via u.omitted', () => {
|
||||
expectU(u({ a: u.omitted, b: i => i + 1 }), { a: 1, b: 2 }, { b: 3 })
|
||||
expectU(u({ a: u.omitted, b: (i) => i + 1 }), { a: 1, b: 2 }, { b: 3 })
|
||||
})
|
||||
|
||||
it('omit array and object properties', () => {
|
||||
|
@ -3,7 +3,7 @@ import { curry1, curry2, curry3, curry4, _ } from '../../lib/util/curry'
|
||||
|
||||
describe('curry1', () => {
|
||||
it('can curry one arguments', () => {
|
||||
const addOne = curry1(x => x + 1)
|
||||
const addOne = curry1((x) => x + 1)
|
||||
expect(addOne(3)).to.equal(4)
|
||||
expect(addOne()(3)).to.equal(4)
|
||||
})
|
||||
|
@ -3,14 +3,14 @@ import u from '../lib'
|
||||
|
||||
describe('u.withDefault', () => {
|
||||
it('uses the default as the basis for the update if the object is undefined', () => {
|
||||
const inc = x => x + 1
|
||||
const inc = (x) => x + 1
|
||||
const result = u.withDefault({ a: 0 }, { a: inc }, undefined)
|
||||
|
||||
expect(result).to.eql({ a: 1 })
|
||||
})
|
||||
|
||||
it('uses ignores the default if the object is defined', () => {
|
||||
const inc = x => x + 1
|
||||
const inc = (x) => x + 1
|
||||
const result = u.withDefault({ a: 0 }, { a: inc }, { a: 3 })
|
||||
|
||||
expect(result).to.eql({ a: 4 })
|
||||
|
@ -1,5 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
/* eslint strict:0, no-var:0, func-names:0 */
|
||||
|
||||
module.exports = require('./createWebpackConfig')()
|
Loading…
Reference in New Issue
Block a user