Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update tooling (rollup, etc) (ignore red x, it is coveralls) #1931

Merged
merged 7 commits into from
Jun 4, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 11 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ module.exports = {
"getter-return": "off",
"no-console": "off",
"no-var": "error",
// Things that don't play nicely with TS:
"no-unused-vars": "off",
"no-extra-semi": "off"
"no-undef": "off",
"no-extra-semi": "off" // doesn't get along well with prettier
},
globals: {
process: "readable",
Expand All @@ -26,5 +25,14 @@ module.exports = {
setTimeout: "readable",
clearTimeout: "readable",
module: "writable"
},
overrides: {
files: ["**/*.ts"],
rules: {
// Things that don't play nicely with TS:
"require-yield": "off",
"no-unused-vars": "off",
"no-extra-semi": "off"
}
}
}
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
language: node_js
install:
- yarn install --frozen-lockfile
script: CI=true yarn test:travis
after_success:
- cat ./coverage/lcov.info|./node_modules/coveralls/bin/coveralls.js
script:
- CI=true yarn test:travis
- cat ./coverage/lcov.info|./node_modules/coveralls/bin/coveralls.js
node_js:
- 10
- 10
addons:
apt:
packages:
Expand Down
33 changes: 11 additions & 22 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
{
"[typescript]": {
"editor.formatOnSave": true,
"editor.formatOnPaste": false
},
"[javascript]": {
"editor.formatOnSave": true,
"editor.formatOnPaste": false
},
// Note, these settings should match lint-staged settings!
"prettier.semi": false,
"prettier.tabWidth": 4,
"prettier.useTabs": false,
"prettier.printWidth": 100,
"prettier.singleQuote": false,
"[typescript]": {
"editor.formatOnSave": true,
"editor.formatOnPaste": false
},
"[javascript]": {
"editor.formatOnSave": true,
"editor.formatOnPaste": false
},
"typescript.tsdk": "node_modules/typescript/lib",
// "javascript.validate.enable": false // enable for flow
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact"
]
}
// "javascript.validate.enable": false // enable for flow
"eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact"]
}
80 changes: 43 additions & 37 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@
"test:flow": "node_modules/.bin/flow check",
"test:performance": "npm run small-build && PERSIST=true time node --expose-gc test/perf/index.js",
"test:travis": "yarn test:all && yarn test:performance && yarn test -i --coverage && yarn test:webpack && yarn size",
"prettier": "prettier --write --print-width 100 --tab-width 4 --no-semi \"**/*.js\" \"**/*.jsx\" \"**/*.tsx\" \"**/*.ts\"",
"prettier": "prettier \"**/*.js\" \"**/*.jsx\" \"**/*.tsx\" \"**/*.ts\"",
"_prepublish": "npm run small-build",
"quick-build": "tsc --pretty",
"small-build": "node scripts/build.js",
"lint": "eslint src/*.ts src/types/*.ts src/api/*.ts src/core/*.ts src/utils/*.ts",
"lint": "eslint src/**/*.ts",
"size": "size-limit --babili 20KB lib/mobx.js",
"precommit": "lint-staged",
"publish-script": "node scripts/publish.js"
},
"repository": {
Expand All @@ -46,41 +45,38 @@
],
"homepage": "https://mobx.js.org/",
"devDependencies": {
"@babel/core": "^7.1.0",
"@babel/plugin-proposal-class-properties": "^7.1.0",
"@babel/plugin-proposal-decorators": "^7.1.0",
"@babel/preset-env": "^7.1.0",
"@types/jest": "^21.1.9",
"@types/node": "^7.0.22",
"@typescript-eslint/eslint-plugin": "^1.3.0",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^23.6.0",
"browserify": "^12.0.1",
"@babel/core": "^7.3.4",
"@babel/plugin-proposal-class-properties": "^7.3.4",
"@babel/plugin-proposal-decorators": "^7.3.0",
"@babel/plugin-transform-runtime": "^7.3.4",
"@babel/preset-env": "^7.3.4",
"@babel/runtime": "^7.3.4",
"@types/jest": "^24.0.11",
"@types/node": "^11.11.3",
"@typescript-eslint/eslint-plugin": "^1.4.2",
"babel-jest": "^24.5.0",
"chalk": "^1.1.3",
"coveralls": "^2.11.4",
"envify": "^4.1.0",
"eslint": "^5.13.0",
"coveralls": "^3.0.3",
"eslint": "^5.15.2",
"flow-bin": "^0.59.0",
"fs-extra": "^3.0.1",
"husky": "^0.14.3",
"iterall": "^1.0.2",
"jest": "^23.6.0",
"lint-staged": "^3.6.1",
"lodash.intersection": "^3.2.0",
"ncp": "^2.0.0",
"prettier": "^1.4.4",
"regenerator-runtime": "^0.11.1",
"rollup": "^0.41.6",
"rollup-plugin-filesize": "^1.3.2",
"rollup-plugin-node-resolve": "^3.0.0",
"serializr": "^1.3.0",
"shelljs": "^0.8.2",
"size-limit": "^0.2.0",
"tape": "^4.2.2",
"ts-jest": "^22.0.0",
"tslib": "^1.7.1",
"typescript": "^3.2.1",
"uglify-es": "^3.3.9"
"fs-extra": "^7.0.1",
"husky": "^1.3.1",
"iterall": "^1.2.2",
"jest": "^24.5.0",
"lint-staged": "^8.1.5",
"prettier": "^1.16.4",
"rollup": "^1.6.0",
"rollup-plugin-filesize": "^6.0.1",
"rollup-plugin-node-resolve": "^4.0.1",
"rollup-plugin-replace": "^2.1.0",
"rollup-plugin-terser": "^4.0.4",
"serializr": "^1.5.1",
"shelljs": "^0.8.3",
"size-limit": "^1.0.0",
"tape": "^4.10.1",
"ts-jest": "^24.0.0",
"tslib": "^1.9.3",
"typescript": "^3.3.3333"
},
"dependencies": {},
"keywords": [
Expand All @@ -99,11 +95,16 @@
],
"lint-staged": {
"*.{ts,tsx,js,jsx}": [
"prettier --write --print-width 100 --tab-width 4 --no-semi",
"prettier --write",
"git add"
]
},
"jest": {
"globals": {
"ts-jest": {
"tsConfig": "tsconfig.test.json"
}
},
"transform": {
"^.+\\.tsx?$": "ts-jest",
"^.+\\.jsx?$": "babel-jest"
Expand All @@ -123,5 +124,10 @@
"watchPathIgnorePatterns": [
"<rootDir>/node_modules/"
]
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
}
}
137 changes: 51 additions & 86 deletions scripts/build.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
const rollup = require("rollup")
const { rollup } = require("rollup")
const resolvePlugin = require("rollup-plugin-node-resolve")
const filesizePlugin = require("rollup-plugin-filesize")
const replacePlugin = require("rollup-plugin-replace")
const terserPlugin = require("rollup-plugin-terser").terser

const fs = require("fs-extra")
const path = require("path")
const ts = require("typescript")
const shell = require("shelljs")
const exec = shell.exec

// exit upon first error
shell.set("-e")

const binFolder = path.resolve("node_modules/.bin/")

function getCmd(cmd) {
if (process.platform === "win32") {
return path.join(binFolder, cmd + ".cmd")
}
return cmd
}

// make sure we're in the right folder
process.chdir(path.resolve(__dirname, ".."))

fs.removeSync("lib")
fs.removeSync(".build.cjs")
fs.removeSync(".build.es")
fs.removeSync(".build.es5")
fs.removeSync(".build.es6")

function runTypeScriptBuild(outDir, target, declarations) {
console.log(`Running typescript build (target: ${ts.ScriptTarget[target]}) in ${outDir}/`)
Expand Down Expand Up @@ -59,88 +50,62 @@ function runTypeScriptBuild(outDir, target, declarations) {
}
}

const rollupPlugins = [require("rollup-plugin-node-resolve")(), require("rollup-plugin-filesize")()]

const licensePreamble = "/** MobX - (c) Michel Weststrate 2015 - 2019 - MIT Licensed */"

function generateBundledModule(inputFile, outputFile, format) {
async function generateBundledModule(inputFile, outputFile, format, production) {
console.log(`Generating ${outputFile} bundle.`)

return rollup
.rollup({
entry: inputFile,
plugins: rollupPlugins
})
.then(bundle =>
bundle.write({
dest: outputFile,
format,
banner: licensePreamble,
exports: "named"
})
)
}

function generateUmd() {
console.log("Generating mobx.umd.js")
exec("browserify -s mobx -e lib/mobx.js -o lib/mobx.umd.js")
}

function generateMinified() {
const prodEnv = {
...process.env,
NODE_ENV: "production"
let plugins
if (production) {
plugins = [
resolvePlugin(),
replacePlugin({ "process.env.NODE_ENV": JSON.stringify("production") }),
terserPlugin(),
filesizePlugin()
]
} else {
plugins = [resolvePlugin(), filesizePlugin()]
}

console.log("Generating mobx.min.js and mobx.umd.min.js")
exec(`${getCmd(`envify`)} lib/mobx.js > lib/mobx.prod.js`, { env: prodEnv })
exec(
`${getCmd(
"uglifyjs"
)} --toplevel -m -c warnings=false -b beautify=false,preamble='"${licensePreamble}"' --source-map -o lib/mobx.min.js lib/mobx.prod.js`
)
exec(`${getCmd(`envify`)} lib/mobx.umd.js > lib/mobx.prod.umd.js`, {
env: prodEnv
const bundle = await rollup({
input: inputFile,
plugins
})

await bundle.write({
file: outputFile,
format,
banner: "/** MobX - (c) Michel Weststrate 2015 - 2019 - MIT Licensed */",
exports: "named",
name: format === "umd" ? "mobx" : undefined
})
exec(
`${getCmd(
`uglifyjs`
)} --toplevel -m -c warnings=false -b beautify=false,preamble='"${licensePreamble}"' --source-map -o lib/mobx.umd.min.js lib/mobx.prod.umd.js`
)
shell.rm("lib/mobx.prod.js", "lib/mobx.prod.umd.js")

console.log(`Generation of ${outputFile} bundle finished.`)
}

function copyFlowDefinitions() {
console.log("Copying flowtype definitions")
exec(`${getCmd(`ncp`)} flow-typed/mobx.js lib/mobx.js.flow`)
fs.copyFileSync("flow-typed/mobx.js", "lib/mobx.js.flow")
console.log("Copying of flowtype definitions done")
}

function build() {
async function build() {
runTypeScriptBuild(".build.es5", ts.ScriptTarget.ES5, true)
runTypeScriptBuild(".build.es6", ts.ScriptTarget.ES2015, false)
return Promise.all([
generateBundledModule(
path.resolve(".build.es5", "mobx.js"),
path.resolve("lib", "mobx.js"),
"cjs"
),

generateBundledModule(
path.resolve(".build.es5", "mobx.js"),
path.resolve("lib", "mobx.module.js"),
"es"
),

generateBundledModule(
path.resolve(".build.es6", "mobx.js"),
path.resolve("lib", "mobx.es6.js"),
"es"
)
]).then(() => {
generateUmd()
generateMinified()
copyFlowDefinitions()
})

const es5Build = path.join(".build.es5", "mobx.js")
const es6Build = path.join(".build.es6", "mobx.js")

await Promise.all([
generateBundledModule(es5Build, path.join("lib", "mobx.js"), "cjs", false),
generateBundledModule(es5Build, path.join("lib", "mobx.min.js"), "cjs", true),

generateBundledModule(es5Build, path.join("lib", "mobx.module.js"), "es", false),

generateBundledModule(es6Build, path.join("lib", "mobx.es6.js"), "es", false),

generateBundledModule(es5Build, path.join("lib", "mobx.umd.js"), "umd", false),
generateBundledModule(es5Build, path.join("lib", "mobx.umd.min.js"), "umd", true)
])
copyFlowDefinitions()
}

build().catch(e => {
Expand Down
12 changes: 9 additions & 3 deletions src/api/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ export interface FlowReturn<T> {
// we skip promises that are the result of yielding promises (except if they use flowReturn)
export type FlowReturnType<R> = IfAllAreFlowYieldThenVoid<
R extends FlowReturn<infer FR>
? FR extends Promise<infer FRP> ? FRP : FR
: R extends Promise<any> ? FlowYield : R
? FR extends Promise<infer FRP>
? FRP
: FR
: R extends Promise<any>
? FlowYield
: R
>

// we extract yielded promises from the return type
Expand All @@ -30,7 +34,9 @@ export function flow<R, Args extends any[]>(
generator: (...args: Args) => IterableIterator<R>
): (...args: Args) => CancellablePromise<FlowReturnType<R>> {
if (arguments.length !== 1)
fail(process.env.NODE_ENV && `Flow expects one 1 argument and cannot be used as decorator`)
fail(
!!process.env.NODE_ENV && `Flow expects one 1 argument and cannot be used as decorator`
)
const name = generator.name || "<unnamed flow>"

// Implementation based on https://github.com/tj/co/blob/master/index.js
Expand Down
Loading