@parcel/transformer-posthtml 2.14.4 → 2.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,41 +18,6 @@ function _path() {
18
18
  };
19
19
  return data;
20
20
  }
21
- function _posthtml() {
22
- const data = _interopRequireDefault(require("posthtml"));
23
- _posthtml = function () {
24
- return data;
25
- };
26
- return data;
27
- }
28
- function _posthtmlParser() {
29
- const data = require("posthtml-parser");
30
- _posthtmlParser = function () {
31
- return data;
32
- };
33
- return data;
34
- }
35
- function _posthtmlRender() {
36
- const data = require("posthtml-render");
37
- _posthtmlRender = function () {
38
- return data;
39
- };
40
- return data;
41
- }
42
- function _nullthrows() {
43
- const data = _interopRequireDefault(require("nullthrows"));
44
- _nullthrows = function () {
45
- return data;
46
- };
47
- return data;
48
- }
49
- function _semver() {
50
- const data = _interopRequireDefault(require("semver"));
51
- _semver = function () {
52
- return data;
53
- };
54
- return data;
55
- }
56
21
  var _loadPlugins = _interopRequireDefault(require("./loadPlugins"));
57
22
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
58
23
  var _default = exports.default = new (_plugin().Transformer)({
@@ -91,47 +56,27 @@ var _default = exports.default = new (_plugin().Transformer)({
91
56
  }
92
57
  }
93
58
  configFile.contents.plugins = plugins;
94
-
95
- // tells posthtml that we have already called parse
96
- configFile.contents.skipParse = true;
97
59
  delete configFile.contents.render;
98
60
  return configFile.contents;
99
61
  }
100
62
  },
101
- canReuseAST({
102
- ast
103
- }) {
104
- return ast.type === 'posthtml' && _semver().default.satisfies(ast.version, '^0.4.0');
105
- },
106
- async parse({
107
- asset,
108
- config
109
- }) {
110
- // if we don't have a config it is posthtml is not configure, don't parse
111
- if (!config) {
112
- return;
113
- }
114
- return {
115
- type: 'posthtml',
116
- version: '0.4.1',
117
- program: (0, _posthtmlParser().parser)(await asset.getCode(), {
118
- lowerCaseAttributeNames: true,
119
- sourceLocations: true,
120
- xmlMode: asset.type === 'xhtml'
121
- })
122
- };
123
- },
124
63
  async transform({
125
64
  asset,
126
- config
65
+ config,
66
+ options
127
67
  }) {
128
68
  if (!config) {
129
69
  return [asset];
130
70
  }
131
- let ast = (0, _nullthrows().default)(await asset.getAST());
132
- let res = await (0, _posthtml().default)(config.plugins).process(ast.program, {
71
+ let posthtml = await options.packageManager.require('posthtml', asset.filePath, {
72
+ range: '^0.16.5'
73
+ });
74
+ let code = await asset.getCode();
75
+ let res = await posthtml(config.plugins).process(code, {
133
76
  ...config,
134
- plugins: config.plugins
77
+ plugins: config.plugins,
78
+ xmlMode: asset.type === 'xhtml',
79
+ closingSingleTag: asset.type === 'xhtml' ? 'slash' : undefined
135
80
  });
136
81
  if (res.messages) {
137
82
  for (let {
@@ -143,21 +88,7 @@ var _default = exports.default = new (_plugin().Transformer)({
143
88
  }
144
89
  }
145
90
  }
146
- asset.setAST({
147
- type: 'posthtml',
148
- version: '0.4.1',
149
- program: JSON.parse(JSON.stringify(res.tree)) // posthtml adds functions to the AST that are not serializable
150
- });
91
+ asset.setCode(res.html);
151
92
  return [asset];
152
- },
153
- generate({
154
- ast,
155
- asset
156
- }) {
157
- return {
158
- content: (0, _posthtmlRender().render)(ast.program, {
159
- closingSingleTag: asset.type === 'xhtml' ? 'slash' : undefined
160
- })
161
- };
162
93
  }
163
94
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcel/transformer-posthtml",
3
- "version": "2.14.4",
3
+ "version": "2.15.1",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -17,16 +17,11 @@
17
17
  "source": "src/PostHTMLTransformer.js",
18
18
  "engines": {
19
19
  "node": ">= 16.0.0",
20
- "parcel": "^2.14.4"
20
+ "parcel": "^2.15.1"
21
21
  },
22
22
  "dependencies": {
23
- "@parcel/plugin": "2.14.4",
24
- "@parcel/utils": "2.14.4",
25
- "nullthrows": "^1.1.1",
26
- "posthtml": "^0.16.5",
27
- "posthtml-parser": "^0.12.1",
28
- "posthtml-render": "^3.0.0",
29
- "semver": "^7.5.2"
23
+ "@parcel/plugin": "2.15.1",
24
+ "@parcel/utils": "2.15.1"
30
25
  },
31
- "gitHead": "c09fee751b61e2f9d52164f88248b9c668614134"
26
+ "gitHead": "6a9fd4c67355d7b00eba32b73346f88ee766220b"
32
27
  }
@@ -3,11 +3,6 @@
3
3
  import {Transformer} from '@parcel/plugin';
4
4
 
5
5
  import path from 'path';
6
- import posthtml from 'posthtml';
7
- import {parser as parse} from 'posthtml-parser';
8
- import {render} from 'posthtml-render';
9
- import nullthrows from 'nullthrows';
10
- import semver from 'semver';
11
6
  import loadPlugins from './loadPlugins';
12
7
 
13
8
  export default (new Transformer({
@@ -64,44 +59,31 @@ export default (new Transformer({
64
59
 
65
60
  configFile.contents.plugins = plugins;
66
61
 
67
- // tells posthtml that we have already called parse
68
- configFile.contents.skipParse = true;
69
62
  delete configFile.contents.render;
70
63
 
71
64
  return configFile.contents;
72
65
  }
73
66
  },
74
67
 
75
- canReuseAST({ast}) {
76
- return ast.type === 'posthtml' && semver.satisfies(ast.version, '^0.4.0');
77
- },
78
-
79
- async parse({asset, config}) {
80
- // if we don't have a config it is posthtml is not configure, don't parse
81
- if (!config) {
82
- return;
83
- }
84
-
85
- return {
86
- type: 'posthtml',
87
- version: '0.4.1',
88
- program: parse(await asset.getCode(), {
89
- lowerCaseAttributeNames: true,
90
- sourceLocations: true,
91
- xmlMode: asset.type === 'xhtml',
92
- }),
93
- };
94
- },
95
-
96
- async transform({asset, config}) {
68
+ async transform({asset, config, options}) {
97
69
  if (!config) {
98
70
  return [asset];
99
71
  }
100
72
 
101
- let ast = nullthrows(await asset.getAST());
102
- let res = await posthtml(config.plugins).process(ast.program, {
73
+ let posthtml = await options.packageManager.require(
74
+ 'posthtml',
75
+ asset.filePath,
76
+ {
77
+ range: '^0.16.5',
78
+ },
79
+ );
80
+
81
+ let code = await asset.getCode();
82
+ let res = await posthtml(config.plugins).process(code, {
103
83
  ...config,
104
84
  plugins: config.plugins,
85
+ xmlMode: asset.type === 'xhtml',
86
+ closingSingleTag: asset.type === 'xhtml' ? 'slash' : undefined,
105
87
  });
106
88
 
107
89
  if (res.messages) {
@@ -112,20 +94,7 @@ export default (new Transformer({
112
94
  }
113
95
  }
114
96
 
115
- asset.setAST({
116
- type: 'posthtml',
117
- version: '0.4.1',
118
- program: JSON.parse(JSON.stringify(res.tree)), // posthtml adds functions to the AST that are not serializable
119
- });
120
-
97
+ asset.setCode(res.html);
121
98
  return [asset];
122
99
  },
123
-
124
- generate({ast, asset}) {
125
- return {
126
- content: render(ast.program, {
127
- closingSingleTag: asset.type === 'xhtml' ? 'slash' : undefined,
128
- }),
129
- };
130
- },
131
100
  }): Transformer);