Skip to content

Milestone 1.0.2 #122

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

Merged
merged 8 commits into from
Oct 24, 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ jest
coverage
jsdoc-api
node_modules
.nyc_output
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ language: node_js
node_js:
- stable
- lts/*
- 6
- 4
- 8

after_success:
- cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Change Log
# Changelog

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [1.0.2](https://github.com/posthtml/posthtml-loader/compare/v1.0.1...v1.0.2) (2019-10-24)

<a name="1.0.1"></a>
## [1.0.1](https://github.com/posthtml/posthtml-loader/compare/v1.0.0...v1.0.1) (2017-12-18)

Expand Down
12 changes: 6 additions & 6 deletions lib/Error.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
'use strict'

class LoaderError extends Error {
constructor(err) {
super(err);
constructor (err) {
super(err)

this.name = 'PostHTML Loader';
this.message = `\n\n${err.message}\n`;
this.name = 'PostHTML Loader'
this.message = `\n\n${err.message}\n`

// TODO(michael-ciniawsky)
// add 'SyntaxError', 'PluginError', 'PluginWarning'

Error.captureStackTrace(this, this.constructor);
Error.captureStackTrace(this, this.constructor)
}
}

module.exports = LoaderError;
module.exports = LoaderError
124 changes: 62 additions & 62 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = function loader (html, map, meta) {
// Loader Options
const options = loaderUtils.getOptions(this) || {}

validateOptions(schema, options, 'PostHTML Loader')
validateOptions(schema, options, { name: 'PostHTML Loader', baseDataPath: 'options' })

// Make the loader async
const cb = this.async()
Expand Down Expand Up @@ -84,80 +84,80 @@ module.exports = function loader (html, map, meta) {

return posthtmlrc(rc.ctx, rc.path, { argv: false })
})
.then((config) => {
if (!config) config = {}
.then((config) => {
if (!config) config = {}

if (config.file) this.addDependency(config.file)
if (config.file) this.addDependency(config.file)

if (config.options) {
if (config.options) {
// Disable overriding `options.to` (`posthtml.config.js`)
if (config.options.to) delete config.options.to
// Disable overriding `options.from` (`posthtml.config.js`)
if (config.options.from) delete config.options.from
}
if (config.options.to) delete config.options.to
// Disable overriding `options.from` (`posthtml.config.js`)
if (config.options.from) delete config.options.from
}

let plugins = config.plugins || []
let options = Object.assign(
{ from: file, to: file },
config.options
)
const plugins = config.plugins || []
const options = Object.assign(
{ from: file, to: file },
config.options
)

if (typeof options.parser === 'string') {
options.parser = require(options.parser)()
}
if (typeof options.parser === 'string') {
options.parser = require(options.parser)()
}

// TODO(michael-ciniawsky) enable if when custom renderer available
// if (typeof options.render === 'string') {
// options.render = require(options.render)()
// }

return posthtml(plugins)
.process(html, options)
.then((result) => {
if (result.messages) {
result.messages.forEach((msg) => {
switch (msg.type) {
case 'error':
this.emitError(msg.message)

break
case 'warning':
this.emitWarning(msg.message)

break
case 'dependency':
this.addDependency(msg.file)

break
default:
break
}
})
}
// TODO(michael-ciniawsky) enable if when custom renderer available
// if (typeof options.render === 'string') {
// options.render = require(options.render)()
// }

html = result.html
return posthtml(plugins)
.process(html, options)
.then((result) => {
if (result.messages) {
result.messages.forEach((msg) => {
switch (msg.type) {
case 'error':
this.emitError(msg.message)

if (this.loaderIndex === 0) {
html = `export default \`${html}\``
break
case 'warning':
this.emitWarning(msg.message)

cb(null, html)
break
case 'dependency':
this.addDependency(msg.file)

return null
}
break
default:
break
}
})
}

if (!meta) meta = {}
html = result.html

meta.ast = { type: 'posthtml', root: result.tree }
meta.messages = result.messages
if (this.loaderIndex === 0) {
html = `export default \`${html}\``

cb(null, html, map, meta)
cb(null, html)

return null
})
})
.catch((err) => {
cb(new LoaderError(err))
return null
}

return null
})
if (!meta) meta = {}

meta.ast = { type: 'posthtml', root: result.tree }
meta.messages = result.messages

cb(null, html, map, meta)

return null
})
})
.catch((err) => {
cb(new LoaderError(err))

return null
})
}
2 changes: 1 addition & 1 deletion lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = function parseOptions (params) {

if (typeof params.plugins === 'undefined') plugins = []
else if (Array.isArray(params.plugins)) plugins = params.plugins
else plugins = [ params.plugins ]
else plugins = [params.plugins]

const options = {}

Expand Down
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "posthtml-loader",
"description": "PostHTML for Webpack",
"version": "1.0.1",
"version": "1.0.2",
"main": "lib/index.js",
"engines": {
"node": ">= 4"
"node": ">= 8"
},
"files": [
"lib"
Expand All @@ -19,20 +19,20 @@
},
"dependencies": {
"loader-utils": "^1.1.0",
"posthtml": "^0.11.0",
"posthtml": "^0.12.0",
"posthtml-load-config": "^1.0.0",
"schema-utils": "^0.4.3"
"schema-utils": "^2.5.0"
},
"devDependencies": {
"coveralls": "^2.0.0",
"del": "^3.0.0",
"jest": "^21.0.0",
"jsdoc-to-markdown": "^3.0.0",
"memory-fs": "^0.4.0",
"coveralls": "^3.0.7",
"del": "^5.1.0",
"jest": "^24.9.0",
"jsdoc-to-markdown": "^5.0.2",
"memory-fs": "^0.5.0",
"posthtml-sugarml": "1.0.0-alpha3",
"standard": "^10.0.0",
"standard-version": "^4.0.0",
"webpack": "^3.0.0"
"standard": "^14.3.1",
"standard-version": "^7.0.0",
"webpack": "^4.41.2"
},
"keywords": [
"HTML",
Expand Down
16 changes: 9 additions & 7 deletions test/__snapshots__/Errors.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Errors Validation Error 1`] = `
"PostHTML Loader Invalid Options

options.plugins should be array
options.plugins should be object
options.plugins should pass \\"instanceof\\" keyword validation
options.plugins should match exactly one schema in oneOf
"
"Invalid options object. PostHTML Loader has been initialised using an options object that does not match the API schema.
- options.plugins should be one of these:
[any, ...] | object { … } | function
Details:
* options.plugins should be an array:
[any, ...]
* options.plugins should be an object:
object { … }
* options.plugins should be an instance of function."
`;
6 changes: 0 additions & 6 deletions test/__snapshots__/loader.test.js.snap

This file was deleted.

2 changes: 1 addition & 1 deletion test/fixtures/fixture.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import html from './fixture.html'
import html from './fixture.html' // eslint-disable-line
2 changes: 1 addition & 1 deletion test/fixtures/options/parser/fixture.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import html from './fixture.ssml'
import html from './fixture.ssml' // eslint-disable-line
16 changes: 10 additions & 6 deletions test/helpers/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ const del = require('del')
const webpack = require('webpack')
const MemoryFS = require('memory-fs')

const optimization = (config) => {
return {
splitChunks: {
minChunks: Infinity
}
}
}

const modules = (config) => {
return {
rules: config.rules
Expand All @@ -23,12 +31,7 @@ const modules = (config) => {
}
}

const plugins = config => ([
new webpack.optimize.CommonsChunkPlugin({
names: ['runtime'],
minChunks: Infinity
})
].concat(config.plugins || []))
const plugins = config => ([].concat(config.plugins || []))

const output = (config) => {
return {
Expand All @@ -47,6 +50,7 @@ module.exports = function (fixture, config, options) {
context: path.resolve(__dirname, '..', 'fixtures'),
entry: `./${fixture}`,
output: output(config),
optimization: optimization(config),
module: modules(config),
plugins: plugins(config)
}
Expand Down
11 changes: 0 additions & 11 deletions test/options/__snapshots__/config.test.js.snap

This file was deleted.

5 changes: 0 additions & 5 deletions test/options/__snapshots__/parser.test.js.snap

This file was deleted.

16 changes: 0 additions & 16 deletions test/options/__snapshots__/plugins.test.js.snap

This file was deleted.