Skip to content

Commit dd63c39

Browse files
authored
Merge pull request #122 from posthtml/milestone-1.0.2
Milestone 1.0.2
2 parents e97da5a + 6076164 commit dd63c39

15 files changed

Lines changed: 107 additions & 137 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ jest
1212
coverage
1313
jsdoc-api
1414
node_modules
15+
.nyc_output

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ language: node_js
33
node_js:
44
- stable
55
- lts/*
6-
- 6
7-
- 4
6+
- 8
87

98
after_success:
109
- cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
# Change Log
1+
# Changelog
22

33
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.
44

5+
### [1.0.2](https://github.com/posthtml/posthtml-loader/compare/v1.0.1...v1.0.2) (2019-10-24)
6+
57
<a name="1.0.1"></a>
68
## [1.0.1](https://github.com/posthtml/posthtml-loader/compare/v1.0.0...v1.0.1) (2017-12-18)
79

lib/Error.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
'use strict'
22

33
class LoaderError extends Error {
4-
constructor(err) {
5-
super(err);
4+
constructor (err) {
5+
super(err)
66

7-
this.name = 'PostHTML Loader';
8-
this.message = `\n\n${err.message}\n`;
7+
this.name = 'PostHTML Loader'
8+
this.message = `\n\n${err.message}\n`
99

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

13-
Error.captureStackTrace(this, this.constructor);
13+
Error.captureStackTrace(this, this.constructor)
1414
}
1515
}
1616

17-
module.exports = LoaderError;
17+
module.exports = LoaderError

lib/index.js

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module.exports = function loader (html, map, meta) {
3737
// Loader Options
3838
const options = loaderUtils.getOptions(this) || {}
3939

40-
validateOptions(schema, options, 'PostHTML Loader')
40+
validateOptions(schema, options, { name: 'PostHTML Loader', baseDataPath: 'options' })
4141

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

8585
return posthtmlrc(rc.ctx, rc.path, { argv: false })
8686
})
87-
.then((config) => {
88-
if (!config) config = {}
87+
.then((config) => {
88+
if (!config) config = {}
8989

90-
if (config.file) this.addDependency(config.file)
90+
if (config.file) this.addDependency(config.file)
9191

92-
if (config.options) {
92+
if (config.options) {
9393
// Disable overriding `options.to` (`posthtml.config.js`)
94-
if (config.options.to) delete config.options.to
95-
// Disable overriding `options.from` (`posthtml.config.js`)
96-
if (config.options.from) delete config.options.from
97-
}
94+
if (config.options.to) delete config.options.to
95+
// Disable overriding `options.from` (`posthtml.config.js`)
96+
if (config.options.from) delete config.options.from
97+
}
9898

99-
let plugins = config.plugins || []
100-
let options = Object.assign(
101-
{ from: file, to: file },
102-
config.options
103-
)
99+
const plugins = config.plugins || []
100+
const options = Object.assign(
101+
{ from: file, to: file },
102+
config.options
103+
)
104104

105-
if (typeof options.parser === 'string') {
106-
options.parser = require(options.parser)()
107-
}
105+
if (typeof options.parser === 'string') {
106+
options.parser = require(options.parser)()
107+
}
108108

109-
// TODO(michael-ciniawsky) enable if when custom renderer available
110-
// if (typeof options.render === 'string') {
111-
// options.render = require(options.render)()
112-
// }
113-
114-
return posthtml(plugins)
115-
.process(html, options)
116-
.then((result) => {
117-
if (result.messages) {
118-
result.messages.forEach((msg) => {
119-
switch (msg.type) {
120-
case 'error':
121-
this.emitError(msg.message)
122-
123-
break
124-
case 'warning':
125-
this.emitWarning(msg.message)
126-
127-
break
128-
case 'dependency':
129-
this.addDependency(msg.file)
130-
131-
break
132-
default:
133-
break
134-
}
135-
})
136-
}
109+
// TODO(michael-ciniawsky) enable if when custom renderer available
110+
// if (typeof options.render === 'string') {
111+
// options.render = require(options.render)()
112+
// }
137113

138-
html = result.html
114+
return posthtml(plugins)
115+
.process(html, options)
116+
.then((result) => {
117+
if (result.messages) {
118+
result.messages.forEach((msg) => {
119+
switch (msg.type) {
120+
case 'error':
121+
this.emitError(msg.message)
139122

140-
if (this.loaderIndex === 0) {
141-
html = `export default \`${html}\``
123+
break
124+
case 'warning':
125+
this.emitWarning(msg.message)
142126

143-
cb(null, html)
127+
break
128+
case 'dependency':
129+
this.addDependency(msg.file)
144130

145-
return null
146-
}
131+
break
132+
default:
133+
break
134+
}
135+
})
136+
}
147137

148-
if (!meta) meta = {}
138+
html = result.html
149139

150-
meta.ast = { type: 'posthtml', root: result.tree }
151-
meta.messages = result.messages
140+
if (this.loaderIndex === 0) {
141+
html = `export default \`${html}\``
152142

153-
cb(null, html, map, meta)
143+
cb(null, html)
154144

155-
return null
156-
})
157-
})
158-
.catch((err) => {
159-
cb(new LoaderError(err))
145+
return null
146+
}
160147

161-
return null
162-
})
148+
if (!meta) meta = {}
149+
150+
meta.ast = { type: 'posthtml', root: result.tree }
151+
meta.messages = result.messages
152+
153+
cb(null, html, map, meta)
154+
155+
return null
156+
})
157+
})
158+
.catch((err) => {
159+
cb(new LoaderError(err))
160+
161+
return null
162+
})
163163
}

lib/options.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = function parseOptions (params) {
99

1010
if (typeof params.plugins === 'undefined') plugins = []
1111
else if (Array.isArray(params.plugins)) plugins = params.plugins
12-
else plugins = [ params.plugins ]
12+
else plugins = [params.plugins]
1313

1414
const options = {}
1515

package.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "posthtml-loader",
33
"description": "PostHTML for Webpack",
4-
"version": "1.0.1",
4+
"version": "1.0.2",
55
"main": "lib/index.js",
66
"engines": {
7-
"node": ">= 4"
7+
"node": ">= 8"
88
},
99
"files": [
1010
"lib"
@@ -19,20 +19,20 @@
1919
},
2020
"dependencies": {
2121
"loader-utils": "^1.1.0",
22-
"posthtml": "^0.11.0",
22+
"posthtml": "^0.12.0",
2323
"posthtml-load-config": "^1.0.0",
24-
"schema-utils": "^0.4.3"
24+
"schema-utils": "^2.5.0"
2525
},
2626
"devDependencies": {
27-
"coveralls": "^2.0.0",
28-
"del": "^3.0.0",
29-
"jest": "^21.0.0",
30-
"jsdoc-to-markdown": "^3.0.0",
31-
"memory-fs": "^0.4.0",
27+
"coveralls": "^3.0.7",
28+
"del": "^5.1.0",
29+
"jest": "^24.9.0",
30+
"jsdoc-to-markdown": "^5.0.2",
31+
"memory-fs": "^0.5.0",
3232
"posthtml-sugarml": "1.0.0-alpha3",
33-
"standard": "^10.0.0",
34-
"standard-version": "^4.0.0",
35-
"webpack": "^3.0.0"
33+
"standard": "^14.3.1",
34+
"standard-version": "^7.0.0",
35+
"webpack": "^4.41.2"
3636
},
3737
"keywords": [
3838
"HTML",
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`Errors Validation Error 1`] = `
4-
"PostHTML Loader Invalid Options
5-
6-
options.plugins should be array
7-
options.plugins should be object
8-
options.plugins should pass \\"instanceof\\" keyword validation
9-
options.plugins should match exactly one schema in oneOf
10-
"
4+
"Invalid options object. PostHTML Loader has been initialised using an options object that does not match the API schema.
5+
- options.plugins should be one of these:
6+
[any, ...] | object {} | function
7+
Details:
8+
* options.plugins should be an array:
9+
[any, ...]
10+
* options.plugins should be an object:
11+
object {}
12+
* options.plugins should be an instance of function."
1113
`;

test/__snapshots__/loader.test.js.snap

Lines changed: 0 additions & 6 deletions
This file was deleted.

test/fixtures/fixture.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
import html from './fixture.html'
1+
import html from './fixture.html' // eslint-disable-line

0 commit comments

Comments
 (0)