Skip to content

Commit afa7f88

Browse files
authored
Merge pull request #339 from posthtml/milestone-0.10.0
Milestone 0.10.0
2 parents b722c15 + 7878ede commit afa7f88

File tree

9 files changed

+4174
-20220
lines changed

9 files changed

+4174
-20220
lines changed

changelog.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1+
## 0.10.0 (2021-06-11)
2+
3+
* feat: resolve local plugin, close #336, close #338 ([44d877b](https://github.com/posthtml/posthtml-cli/commit/44d877b)), closes [#336](https://github.com/posthtml/posthtml-cli/issues/336) [#338](https://github.com/posthtml/posthtml-cli/issues/338)
4+
* test: resolve local plugin, issue #336, #338 ([2a0cb7d](https://github.com/posthtml/posthtml-cli/commit/2a0cb7d)), closes [#336](https://github.com/posthtml/posthtml-cli/issues/336) [#338](https://github.com/posthtml/posthtml-cli/issues/338)
5+
* fix: fails without config, close #337 ([8307ed3](https://github.com/posthtml/posthtml-cli/commit/8307ed3)), closes [#337](https://github.com/posthtml/posthtml-cli/issues/337)
6+
* build: update dep dev ([36e5996](https://github.com/posthtml/posthtml-cli/commit/36e5996))
7+
8+
9+
110
## <small>0.9.2 (2021-05-07)</small>
211

12+
* 0.9.2 ([b722c15](https://github.com/posthtml/posthtml-cli/commit/b722c15))
313
* Fix homepage link in package.json ([a07a0ea](https://github.com/posthtml/posthtml-cli/commit/a07a0ea))
414

515

package-lock.json

Lines changed: 4073 additions & 20191 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "posthtml-cli",
3-
"version": "0.9.2",
3+
"version": "0.10.0",
44
"description": "CLI for posthtml",
55
"license": "MIT",
66
"repository": "posthtml/posthtml-cli",
@@ -35,47 +35,47 @@
3535
],
3636
"dependencies": {
3737
"cosmiconfig": "^7.0.0",
38-
"fast-glob": "^3.2.4",
38+
"fast-glob": "^3.2.5",
3939
"make-dir": "^3.0.0",
4040
"meow": "^7.1.1",
4141
"merge-options": "^3.0.4",
4242
"normalize-path": "^3.0.0",
43-
"posthtml": "^0.15.1",
43+
"posthtml": "^0.16.4",
4444
"to-camel-case": "^1.0.0",
45-
"update-notifier": "^5.0.0"
45+
"update-notifier": "^5.1.0"
4646
},
4747
"devDependencies": {
48-
"@babel/cli": "^7.12.8",
49-
"@babel/core": "^7.12.9",
50-
"@babel/node": "^7.10.5",
51-
"@babel/preset-env": "^7.12.7",
52-
"@babel/register": "^7.11.5",
53-
"@commitlint/cli": "^11.0.0",
54-
"@commitlint/config-angular": "^11.0.0",
55-
"acorn": "^8.0.4",
56-
"ava": "^3.13.0",
48+
"@babel/cli": "^7.14.5",
49+
"@babel/core": "^7.14.5",
50+
"@babel/node": "^7.14.5",
51+
"@babel/preset-env": "^7.14.5",
52+
"@babel/register": "^7.14.5",
53+
"@commitlint/cli": "^12.1.4",
54+
"@commitlint/config-angular": "^12.1.4",
55+
"acorn": "^8.3.0",
56+
"ava": "^3.15.0",
5757
"babel-eslint": "^10.0.3",
5858
"babel-preset-minify": "^0.5.1",
5959
"clinton": "^0.14.0",
6060
"conventional-changelog-cli": "^2.1.0",
6161
"coveralls": "^3.0.9",
62-
"cpy": "^8.1.1",
63-
"eslint": "^7.14.0",
64-
"eslint-config-xo": "^0.33.1",
65-
"eslint-config-xo-space": "^0.25.0",
66-
"eslint-plugin-ava": "^11.0.0",
62+
"cpy": "^8.1.2",
63+
"eslint": "^7.28.0",
64+
"eslint-config-xo": "^0.36.0",
65+
"eslint-config-xo-space": "^0.27.0",
66+
"eslint-plugin-ava": "^12.0.0",
6767
"eslint-plugin-babel": "^5.3.1",
68-
"eslint-plugin-html": "^6.1.0",
69-
"eslint-plugin-import": "^2.22.1",
70-
"eslint-plugin-markdown": "^1.0.1",
68+
"eslint-plugin-html": "^6.1.2",
69+
"eslint-plugin-import": "^2.23.4",
70+
"eslint-plugin-markdown": "^2.2.0",
7171
"eslint-plugin-node": "^11.0.0",
72-
"eslint-plugin-promise": "^4.1.1",
73-
"eslint-plugin-unicorn": "^23.0.0",
74-
"execa": "^4.0.3",
75-
"husky": "^4.3.0",
72+
"eslint-plugin-promise": "^5.1.0",
73+
"eslint-plugin-unicorn": "^33.0.1",
74+
"execa": "^5.1.1",
75+
"husky": "^6.0.0",
7676
"is-promise": "^4.0.0",
77-
"lint-staged": "^10.5.2",
78-
"merge": "^2.1.0",
77+
"lint-staged": "^11.0.0",
78+
"merge": "^2.1.1",
7979
"nyc": "^15.0.0",
8080
"posthtml-bem": "^0.2.2",
8181
"posthtml-css-modules": "^0.1.3",

src/cfg-resolve.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ export default ({input, flags = {}}) => {
5757
}
5858

5959
if (!config && !use) {
60-
({config} = explorer.search());
60+
const search = explorer.search();
61+
config = search?.config;
6162
}
6263

6364
if (config?.root) {

src/cli.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import updateNotifier from 'update-notifier';
99
import posthtml from 'posthtml';
1010
import outResolve from './out-resolve';
1111
import cfgResolve from './cfg-resolve';
12+
import pluginResolve from './plugin-resolve';
1213

1314
const package_ = require('../package.json');
1415
updateNotifier({pkg: package_}).notify();
@@ -93,7 +94,7 @@ const read = file => new Promise(resolve => {
9394
const interopRequire = object => object && object.__esModule ? object.default : object;
9495

9596
const getPlugins = config => Object.keys(config.plugins || {})
96-
.map(plugin => interopRequire(require(plugin))(config.plugins[plugin]));
97+
.map(plugin => interopRequire(require(pluginResolve(plugin, config.root)))(config.plugins[plugin]));
9798

9899
const config = cfgResolve(cli);
99100

src/plugin-resolve.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import path from 'path';
2+
3+
const pluginExist = (pluginPath) => {
4+
try {
5+
require(pluginPath);
6+
return true;
7+
} catch {}
8+
9+
return false;
10+
}
11+
12+
export default (pluginName, root = './') => {
13+
if (pluginExist(pluginName)) {
14+
return pluginName;
15+
}
16+
17+
const pluginResolvePath = path.resolve(path.join(root, pluginName));
18+
if (pluginExist(pluginResolvePath)) {
19+
return pluginResolvePath;
20+
}
21+
22+
return pluginName;
23+
}

test/plugins/custom-plugin.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = function (options) {
2+
return function (tree) {
3+
return tree;
4+
};
5+
}

test/test-cli.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,19 @@ test('Transform html from two file', async t => {
6565
t.is((await read('test/expected/output-indent.html')), (await read(`${folder}/input-indent.html`)));
6666
});
6767

68+
test('Dont not transform html with local plugin', async t => {
69+
const filename = tempfile('.html');
70+
await execa(cli, [
71+
'test/fixtures/input.html',
72+
'-o',
73+
filename,
74+
'-u',
75+
'test/plugins/custom-plugin.js',
76+
]);
77+
t.true(await pathExists(filename));
78+
t.is((await read('test/fixtures/input.html')), (await read(filename)));
79+
});
80+
6881
// test('Transform html with options replace', async t => {
6982
// t.plan(2);
7083
// const folder = await tempfile();

test/test-plugin-resolve.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import path from 'path';
2+
import test from 'ava';
3+
import pluginResolve from '../src/plugin-resolve';
4+
5+
test('should return function', t => {
6+
t.true(typeof pluginResolve === 'function');
7+
});
8+
9+
test('should return node_modules module path', t => {
10+
const pluginName = 'posthtml-custom-elements';
11+
const pluginPath = pluginResolve(pluginName);
12+
t.is(pluginPath, pluginName);
13+
});
14+
15+
test('should return custom module path', t => {
16+
const pluginName = 'test/plugins/custom-plugin.js';
17+
const pluginPath = pluginResolve(pluginName);
18+
t.is(pluginPath, path.resolve(path.join('./', pluginName)));
19+
});

0 commit comments

Comments
 (0)