-
Notifications
You must be signed in to change notification settings - Fork 59
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
WIP: Flow specific changes #213
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a03de01
feat: make Flow linting possible
vmx a9d8aa8
fix: proper stack traces from tests
vmx 65c74c3
fix: transpile webpack bundle with Babel
vmx b4af0e6
feat: Rename Browser build to dist
vmx 3920ace
feat: Add Babel transpile step
vmx 82a00b6
feat: add watcher to Babel transpiling
vmx d590f4f
feat: add Flow type checking
vmx 6710eb0
feat: add copying Flow files
vmx 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[ignore] | ||
.*/node_modules/documentation/* | ||
|
||
[libs] | ||
|
||
[include] | ||
|
||
[options] | ||
suppress_comment= \\(.\\|\n\\)*\\@FlowIgnore |
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
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,5 +1,32 @@ | ||
'use strict' | ||
|
||
const browserTasks = require('./browser') | ||
const Listr = require('listr') | ||
|
||
module.exports = browserTasks | ||
const clean = require('../clean') | ||
const dist = require('./dist') | ||
const lib = require('./lib') | ||
const utils = require('../utils') | ||
|
||
const TASKS = new Listr([{ | ||
title: 'Clean ./dist', | ||
task: () => clean('dist'), | ||
enabled: (ctx) => ctx.dist | ||
}, { | ||
title: 'Webpack Build', | ||
task: dist.webpackBuild, | ||
enabled: (ctx) => ctx.dist | ||
}, { | ||
title: 'Write stats to disk', | ||
task: dist.writeStats, | ||
enabled: (ctx) => ctx.dist && ctx.webpackResult != null && ctx.stats | ||
}, { | ||
title: 'Minify', | ||
task: dist.minify, | ||
enabled: (ctx) => ctx.dist | ||
}, { | ||
title: 'Transpile src to lib', | ||
task: lib, | ||
enabled: (ctx) => ctx.lib | ||
}], utils.getListrConfig()) | ||
|
||
module.exports = TASKS |
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,109 @@ | ||
// Babel transform all *.js files from `src` to `lib` | ||
'use strict' | ||
|
||
const path = require('path') | ||
|
||
const babelCore = require('babel-core') | ||
const chokidar = require('chokidar') | ||
const fs = require('fs-extra') | ||
|
||
const utils = require('../utils') | ||
|
||
const babelConfig = { | ||
env: { | ||
development: { | ||
sourceMaps: 'inline', | ||
comments: false, | ||
presets: [ | ||
[ | ||
'env', | ||
{ | ||
targets: { | ||
node: 'current' | ||
} | ||
} | ||
], | ||
'flow-node' | ||
] | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Babel transpiles a file from `src` to `lib` | ||
* | ||
* @param {string} filename The filename relative to the `src` directory | ||
* | ||
* @returns {Promise} | ||
*/ | ||
const babel = (filename) => { | ||
const src = path.join('src', filename) | ||
const dest = path.join('lib', filename) | ||
|
||
// To have the right filename in the source map | ||
babelConfig.sourceFileName = path.join('..', src) | ||
|
||
return new Promise((resolve, reject) => { | ||
babelCore.transformFile( | ||
src, babelConfig, (err, result) => { | ||
if (err) { | ||
return reject(err) | ||
} | ||
resolve(result.code) | ||
}) | ||
}).then((code) => { | ||
return fs.outputFile(dest, code) | ||
}) | ||
} | ||
|
||
/** | ||
* Copies a file from `src` to `lib` with flow extension | ||
* | ||
* @param {string} filename The filename relative to the `src` directory | ||
* | ||
* @returns {Promise} | ||
*/ | ||
const flowCopy = (filename) => { | ||
const src = path.join('src', filename) | ||
const dest = path.join('lib', filename + '.flow') | ||
|
||
return fs.copy(src, dest) | ||
} | ||
|
||
const transform = (ctx) => { | ||
const srcDir = path.join(utils.getBasePath(), 'src') | ||
|
||
return new Promise((resolve, reject) => { | ||
// The watcher code is based on the babel-cli code (MIT licensed): | ||
// https://github.com/babel/babel/blob/6597a472b30419493f123bff1e9194e4c09e488e/packages/babel-cli/src/babel/dir.js#L164-L188` | ||
const watcher = chokidar.watch(srcDir, { | ||
persistent: ctx.watch, | ||
ignoreInitial: false, | ||
awaitWriteFinish: { | ||
stabilityThreshold: 50, | ||
pollInterval: 10 | ||
} | ||
}) | ||
|
||
;['add', 'change'].forEach((type) => { | ||
watcher.on(type, (filename) => { | ||
const relative = path.relative(srcDir, filename) | ||
console.log('Transform file: ' + relative) | ||
babel(relative) | ||
flowCopy(relative) | ||
}) | ||
}) | ||
|
||
watcher | ||
.on('ready', () => { | ||
// Finish the task after the initial scan. If files are watched, the | ||
// task will keep running though. | ||
resolve() | ||
}) | ||
.on('error', (err) => { | ||
reject(err) | ||
}) | ||
}) | ||
} | ||
|
||
module.exports = transform |
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
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
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.
This needs to link to a released package instead of GitHub URL
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.
For technical or practical/policy reasons? I'd prefer not publishing temporary forks.
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.
For reproducibility and not breaking stuff in the future. If Github goes down (happens strangely often) or the branch changes, it'll break the assumption that if package.json hasn't changed, we should get the same (~) dependencies. This has bitten us in the past, when cleaning up old repositories but forgetting to update some reference and cases where we want to run tests on old commits.
You can use Prelease tags in npm to publish draft-versions of packages: https://docs.npmjs.com/misc/semver#prerelease-tags
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.
So I could do a
1.0.1-flow.1
release and it won't do any harm for anyone not specifying exactly this version?