Skip to content

Commit

Permalink
refactor: rewrites in TS; updates to TS setup
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamel committed Feb 24, 2019
1 parent 736d856 commit b1c26e6
Show file tree
Hide file tree
Showing 79 changed files with 3,894 additions and 2,350 deletions.
7 changes: 2 additions & 5 deletions .babelrc
Expand Up @@ -4,13 +4,10 @@
"@babel/typescript"
],
"plugins": [
[
"babel-plugin-module-resolver",
{ "root": ["./src/lib"], "alias": { "~": "./src" } }
],
["babel-plugin-module-resolver", { "alias": { "~": "./src" } }],
["@babel/plugin-proposal-decorators", { "decoratorsBeforeExport": false }],
"@babel/plugin-proposal-class-properties",
["@babel/plugin-proposal-object-rest-spread", { "useBuiltIns": true }]
],
"ignore": ["node_modules"]
"ignore": ["node_modules", "**/*.d.ts"]
}
75 changes: 60 additions & 15 deletions .eslintrc.js
@@ -1,40 +1,85 @@
const globals = require('eslint-restricted-globals');
const { EXT_JS, EXT_TS } = require('./project.config');
const { configs: ts } = require('@typescript-eslint/eslint-plugin');

module.exports = {
root: true,
parser: 'babel-eslint',
extends: ['standard', 'plugin:import/errors', 'prettier'],
env: {
node: true,
jest: true
},
parserOptions: {
impliedStrict: true
impliedStrict: true,
sourceType: 'module'
},
plugins: ['prettier', 'jest', 'import', 'babel'],
plugins: ['prettier', 'jest', 'import'],
globals: {},
rules: {
/* DISABLED */
'standard/no-callback-literal': 0,
/* WARNINGS */
'no-warning-comments': [
1,
{ terms: ['xxx', 'fixme', 'todo', 'refactor'], location: 'start' }
],
'no-unused-vars': 1,
'no-console': 1,
'jsx-a11y/no-autofocus': 0,
/* ERRORS */
// Add custom globals
'no-restricted-globals': [2, 'fetch'].concat(globals),
// eslint-plugin-babel
'babel/no-invalid-this': 1,
'babel/semi': 1,
// Prettier
'prettier/prettier': [2, require('./.prettierrc')]
},
settings: {
// babel-plugin-module-resolver
'import/resolver': {
'babel-module': {}
overrides: [
/* JAVASCRIPT */
{
files: [`*.{${EXT_JS}}`],
parser: 'babel-eslint',
plugins: ['babel'],
rules: {
'babel/no-invalid-this': 1,
'babel/semi': 1
},
settings: {
// babel-plugin-module-resolver
'import/resolver': {
'babel-module': {}
}
}
},
// eslint-import-resolver-typescript
'import/resolver': {
typescript: {}
/* TYPESCRIPT */
{
files: [`*.{${EXT_TS}}`],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
// Overrides don't allow for extends
rules: Object.assign(ts.recommended.rules, {
/* DISABLED */
'@typescript-eslint/indent': 0,
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/no-object-literal-type-assertion': 0,
'@typescript-eslint/explicit-function-return-type': 0,
/* WARNINGS */
'@typescript-eslint/no-unused-vars': [
1,
{
args: 'after-used',
argsIgnorePattern: '_.*',
ignoreRestSiblings: true
}
],
/* ERRORS */
'@typescript-eslint/interface-name-prefix': [2, 'always'],
'@typescript-eslint/no-use-before-define': [2, { functions: false }],
'@typescript-eslint/array-type': [2, 'array-simple']
}),
settings: {
// eslint-import-resolver-typescript
'import/resolver': {
typescript: {}
}
}
}
}
]
};
9 changes: 4 additions & 5 deletions .gitignore
@@ -1,13 +1,12 @@
# Project Specific #
####################
/docs
/lib
/bin
/dist
_test.*

# Node, Frameworks, Editors #
#############################
_test.js
_test.ts
build
dist
.cache
.env
.env.local
Expand Down
14 changes: 0 additions & 14 deletions .npmignore

This file was deleted.

29 changes: 29 additions & 0 deletions .spelling
@@ -0,0 +1,29 @@
# markdown-spellcheck spelling configuration file
# Format - lines beginning # are comments
# global dictionary is at the start, file overrides afterwards
# one word per line, to define a file override use ' - filename'
# where filename is relative to this configuration file
CLI
programatically
programatic
boolean
async
transpiling
ESLint
TSLint
TypeDoc
TravisCI
repo
config
npm
js
api
transpiled
typings
JSON
transpile
Promist
truthy
falsy
utils
thenable
19 changes: 18 additions & 1 deletion Jakefile.js
@@ -1 +1,18 @@
require('./setup/jake');
const fs = require('fs');
const path = require('path');
const { CONFIG_DIR } = require('./project.config');

const JAKE_DIR = path.join(CONFIG_DIR, 'scripts/tasks');

(function run(dir = JAKE_DIR) {
fs.readdirSync(dir).forEach((name) => {
const item = path.join(dir, name);

if (fs.statSync(item).isDirectory()) {
if (name === 'root') run(item);
else namespace(name, () => run(item));
} else if (/\.jake\.js$/.exec(item)) {
require(item);
}
});
})();
19 changes: 10 additions & 9 deletions README.md
@@ -1,12 +1,12 @@
# Promist

[![Version](https://img.shields.io/npm/v/promist.svg)](https://www.npmjs.com/package/promist)
[![Build Status](https://travis-ci.org/rafamel/promist.svg)](https://travis-ci.org/rafamel/promist)
[![Build Status](https://img.shields.io/travis/rafamel/promist.svg)](https://travis-ci.org/rafamel/promist)
[![Coverage](https://img.shields.io/coveralls/rafamel/promist.svg)](https://coveralls.io/github/rafamel/promist)
[![Dependencies](https://david-dm.org/rafamel/promist/status.svg)](https://david-dm.org/rafamel/promist)
[![Vulnerabilities](https://snyk.io/test/npm/promist/badge.svg)](https://snyk.io/test/npm/promist)
[![Issues](https://img.shields.io/github/issues/rafamel/promist.svg)](https://github.com/rafamel/promist/issues)
[![Dependencies](https://img.shields.io/david/rafamel/promist.svg)](https://david-dm.org/rafamel/promist)
[![Vulnerabilities](https://img.shields.io/snyk/vulnerabilities/npm/promist.svg)](https://snyk.io/test/npm/promist)
[![License](https://img.shields.io/github/license/rafamel/promist.svg)](https://github.com/rafamel/promist/blob/master/LICENSE)
[![Types](https://img.shields.io/npm/types/exits.svg)](https://www.npmjs.com/package/exits)

<!-- markdownlint-disable MD036 -->
**A dependable Promises and async utility belt.** Not a `Promise` implementation.
Expand Down Expand Up @@ -135,7 +135,7 @@ immediate().then(() => console.log('Next event loop')).

*Compose* functions mutate an input promise in order to provide some added functionality:

* They might not work adecuately if you're using non-standard methods for resolution other than `promise.then()`, `promise.catch()`, or `promise.finally()`.
* They might not work adequately if you're using non-standard methods for resolution other than `promise.then()`, `promise.catch()`, or `promise.finally()`.
* They can be chained via [`compose()`.](#composefns-function)

#### `deferrable(promise: Promise): Promise`
Expand All @@ -144,7 +144,7 @@ immediate().then(() => console.log('Next event loop')).
* `promise.resolve(value: any)`: Resolves the promise with the given `value`.
* `promise.reject(reason: any)`: Rejects the promise with the given `reason`.

If the input `promise` resolves or rejects before `promise.resolve()` or `promise.reject()` are called, they won't have any effect. If the opposite ocurrs, the resolution or rejection value of the input promise will be discarded.
If the input `promise` resolves or rejects before `promise.resolve()` or `promise.reject()` are called, they won't have any effect. If the opposite occurs, the resolution or rejection value of the input promise will be discarded.

```javascript
import { wait, deferrable } from 'promist';
Expand Down Expand Up @@ -263,11 +263,12 @@ Used to control async flow. It returns a promise returning function taking the s
import { control } from 'promist';

function* gen(n) {
// You can use yield as you'd use await; res = 20
// You can use yield as you'd use await
let res = yield Promise.resolve(n * 2);
// If tasks have been triggered by some event this won't execute
// test() will be called here,
// if it returns falsy or throws an error this next line won't execute
res = yield Promise.resolve(res * 5);
// res = 100

return res;
}

Expand Down
16 changes: 16 additions & 0 deletions jest.config.js
@@ -0,0 +1,16 @@
const { EXT_JS, EXT_TS } = require('./project.config');
const EXT = EXT_JS + ',' + EXT_TS;
const EXT_ARR = EXT.split(',').map((x) => x.trim());

module.exports = {
testEnvironment: 'node',
collectCoverage: true,
collectCoverageFrom: [`<rootDir>/src/**/*.{${EXT}}`],
modulePathIgnorePatterns: [
'<rootDir>/lib',
'<rootDir>/src/@types',
'<rootDir>/src/bin'
],
moduleFileExtensions: EXT_ARR.concat(['json']),
testPathIgnorePatterns: ['/node_modules/']
};
1 change: 0 additions & 1 deletion jsconfig.json
Expand Up @@ -3,7 +3,6 @@
"experimentalDecorators": true,
"baseUrl": ".",
"paths": {
"*": ["src/lib/*"],
"~/*": ["src/*"]
}
}
Expand Down

0 comments on commit b1c26e6

Please sign in to comment.