-
-
Notifications
You must be signed in to change notification settings - Fork 110
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] build: generate commonjs, es module, and umd versions of unified #76
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,5 @@ | |
.nyc_output/ | ||
coverage/ | ||
node_modules/ | ||
unified.js | ||
unified.min.js | ||
dist/ | ||
yarn.lock |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,10 @@ | ||
'use strict' | ||
|
||
var extend = require('extend') | ||
var bail = require('bail') | ||
var vfile = require('vfile') | ||
var trough = require('trough') | ||
var plain = require('is-plain-obj') | ||
|
||
// Expose a frozen processor. | ||
module.exports = unified().freeze() | ||
|
||
var slice = [].slice | ||
var own = {}.hasOwnProperty | ||
|
||
// Process pipeline. | ||
var pipeline = trough() | ||
.use(pipelineParse) | ||
.use(pipelineRun) | ||
.use(pipelineStringify) | ||
import extend from 'extend' | ||
import bail from 'bail' | ||
import vfile from 'vfile' | ||
import trough from 'trough' | ||
import plain from 'is-plain-obj' | ||
|
||
function pipelineParse(p, ctx) { | ||
ctx.tree = p.parse(ctx.file) | ||
|
@@ -131,6 +119,8 @@ function unified() { | |
// Data management. | ||
// Getter / setter for processor-specific informtion. | ||
function data(key, value) { | ||
var own = {}.hasOwnProperty | ||
|
||
if (typeof key === 'string') { | ||
// Set `key`. | ||
if (arguments.length === 2) { | ||
|
@@ -230,6 +220,7 @@ function unified() { | |
|
||
function addPlugin(plugin, value) { | ||
var entry = find(plugin) | ||
var slice = [].slice | ||
|
||
if (entry) { | ||
if (plain(entry[1]) && plain(value)) { | ||
|
@@ -361,6 +352,11 @@ function unified() { | |
|
||
function executor(resolve, reject) { | ||
var file = vfile(doc) | ||
// Process pipeline. | ||
var pipeline = trough() | ||
.use(pipelineParse) | ||
.use(pipelineRun) | ||
.use(pipelineStringify) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn’t this make every There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe, benchmarking would give better insights on the potential impact. |
||
|
||
pipeline.run(processor, {file: file}, done) | ||
|
||
|
@@ -461,3 +457,6 @@ function assertDone(name, asyncName, complete) { | |
) | ||
} | ||
} | ||
|
||
// Expose a frozen processor. | ||
export default unified().freeze() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was moved to the end due to bcoe/c8#66 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,11 +25,16 @@ | |
"Vse Mozhet Byt <[email protected]>", | ||
"Richard Littauer <[email protected]>" | ||
], | ||
"source": "index.js", | ||
"main": "dist/unified.js", | ||
"module": "dist/unified.mjs", | ||
"unpkg": "dist/unified.umd.js", | ||
"types": "types/index.d.ts", | ||
Comment on lines
+28
to
32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are the different build types recommended by microbundle The recommendations also line up pretty well with Babel's recommendations |
||
"sideEffects": false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this flag is specifically for bundlers, it signals that additional tree-shaking optimizations can be safely made. |
||
"files": [ | ||
"types/index.d.ts", | ||
"index.js", | ||
"lib" | ||
"dist" | ||
], | ||
"dependencies": { | ||
"bail": "^1.0.0", | ||
|
@@ -40,32 +45,23 @@ | |
}, | ||
"devDependencies": { | ||
"browserify": "^16.0.0", | ||
"c8": "^6.0.1", | ||
"dtslint": "^1.0.2", | ||
"nyc": "^14.0.0", | ||
"microbundle": "^0.11.0", | ||
"prettier": "^1.0.0", | ||
"remark-cli": "^7.0.0", | ||
"remark-preset-wooorm": "^6.0.0", | ||
"tape": "^4.0.0", | ||
"tinyify": "^2.5.1", | ||
"typescript": "^3.0.0", | ||
"xo": "^0.25.0" | ||
}, | ||
"scripts": { | ||
"format": "remark . -qfo && prettier --write \"**/{*.js,*.ts}\" && xo --fix", | ||
"build-bundle": "browserify index.js -s unified -o unified.js", | ||
"build-mangle": "browserify index.js -s unified -p tinyify -o unified.min.js", | ||
"build": "npm run build-bundle && npm run build-mangle", | ||
"format": "remark . -qfo && prettier --write \"index.js\" \"types/**\" && xo --fix", | ||
"build": "microbundle", | ||
"test-api": "node test", | ||
"test-coverage": "nyc --reporter lcov tape test", | ||
"test-coverage": "c8 --reporter=lcov --check-coverage --lines 100 --functions 100 --branches 100 tape test", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also migrate coverage to May open a separate PR just for this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. C8 seems to be pretty young, unstable (see There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (oh and see: #76 (comment)) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Young-ish, 1.0 was released in Oct 25, 2017, over two years ago.
🤷♂️ so do Nyc and Istanbul
It is a native feature of Chrome/Node and should more accurately reflect runtime coverage, than the build-instrumentation based approach of Instanbul (some work may still be needed), as well has having the performance boost from running directly in the platform. |
||
"test-types": "dtslint types", | ||
"test": "npm run format && npm run build && npm run test-coverage && npm run test-types" | ||
}, | ||
"nyc": { | ||
"check-coverage": true, | ||
"lines": 100, | ||
"functions": 100, | ||
"branches": 100 | ||
}, | ||
"prettier": { | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
|
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 some reason coverage doesn’t see this function as covered?
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 is likely also related to bcoe/c8#66