Skip to content

Commit

Permalink
Merge ffe70a4 into 2b09e99
Browse files Browse the repository at this point in the history
  • Loading branch information
xaviergonz committed Apr 20, 2019
2 parents 2b09e99 + ffe70a4 commit 91ca3db
Show file tree
Hide file tree
Showing 42 changed files with 6,791 additions and 5,093 deletions.
19 changes: 12 additions & 7 deletions .eslintrc.js
Expand Up @@ -15,19 +15,24 @@ 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",
global: "readable",
console: "readable",
setTimeout: "readable",
clearTimeout: "readable",
module: "writable",
Promise: "readable",
Map: "readable",
Set: "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
@@ -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:
- 8
- 8
addons:
apt:
packages:
Expand Down
33 changes: 11 additions & 22 deletions .vscode/settings.json
@@ -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"]
}
82 changes: 44 additions & 38 deletions package.json
Expand Up @@ -23,13 +23,12 @@
"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:es5 && yarn test:webpack && yarn size",
"test:es5": "yarn small-build && es-check es5 lib/mobx.js",
"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 @@ -47,42 +46,39 @@
],
"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",
"coveralls": "^3.0.3",
"es-check": "^5.0.0",
"eslint": "^5.13.0",
"eslint": "^5.15.2",
"flow-bin": "^0.59.0",
"fs-extra": "^3.0.1",
"husky": "^0.14.3",
"iterall": "^1.0.2",
"jest": "^22.0.4",
"lint-staged": "^3.6.1",
"lodash.intersection": "^3.2.0",
"ncp": "^2.0.0",
"prettier": "^1.12.1",
"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-js": "^2.6.1"
"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.1",
"tape": "^4.10.1",
"ts-jest": "^24.0.0",
"tslib": "^1.9.3",
"typescript": "^3.3.3333"
},
"dependencies": {},
"keywords": [
Expand All @@ -101,11 +97,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 @@ -125,5 +126,10 @@
"watchPathIgnorePatterns": [
"<rootDir>/node_modules/"
]
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
}
}
}
135 changes: 56 additions & 79 deletions scripts/build.js
@@ -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 All @@ -49,86 +40,72 @@ function runTypeScriptBuild(outDir, target, declarations) {
const message = result.diagnostics
.map(
d =>
`${ts.DiagnosticCategory[
d.category
]} ${d.code} (${d.file}:${d.start}): ${d.messageText}`
`${ts.DiagnosticCategory[d.category]} ${d.code} (${d.file}:${d.start}): ${
d.messageText
}`
)
.join("\n")

throw new Error(`Failed to compile typescript:\n\n${message}`)
}
}

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

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: "/** MobX - (c) Michel Weststrate 2015, 2016 - MIT Licensed */",
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(
`${binFolder}/uglifyjs -m sort,toplevel -c warnings=false --screw-ie8 --preamble "/** MobX - (c) Michel Weststrate 2015, 2016 - MIT Licensed */" --source-map lib/mobx.min.js.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 - 2018 - MIT Licensed */",
exports: "named",
name: format === "umd" ? "mobx" : undefined
})
exec(
`${binFolder}/uglifyjs -m sort,toplevel -c warnings=false --screw-ie8 --preamble "/** MobX - (c) Michel Weststrate 2015, 2016 - MIT Licensed */" --source-map lib/mobx.umd.min.js.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() {
runTypeScriptBuild(".build.cjs", ts.ScriptTarget.ES5, true)
runTypeScriptBuild(".build.es", ts.ScriptTarget.ES5, false)
return Promise.all([
generateBundledModule(
path.resolve(".build.cjs", "mobx.js"),
path.resolve("lib", "mobx.js"),
"cjs"
),

generateBundledModule(
path.resolve(".build.es", "mobx.js"),
path.resolve("lib", "mobx.module.js"),
"es"
)
]).then(() => {
generateUmd()
generateMinified()
copyFlowDefinitions()
})
async function build() {
runTypeScriptBuild(".build.es5", ts.ScriptTarget.ES5, true)
runTypeScriptBuild(".build.es6", ts.ScriptTarget.ES2015, false)

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
4 changes: 3 additions & 1 deletion src/api/flow.ts
Expand Up @@ -34,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

0 comments on commit 91ca3db

Please sign in to comment.