@parcel/transformer-posthtml 2.8.3 → 2.9.0
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.
- package/lib/PostHTMLTransformer.js +10 -63
- package/lib/loadPlugins.js +0 -3
- package/package.json +5 -5
- package/src/PostHTMLTransformer.js +2 -12
|
@@ -4,91 +4,57 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
function _plugin() {
|
|
9
8
|
const data = require("@parcel/plugin");
|
|
10
|
-
|
|
11
9
|
_plugin = function () {
|
|
12
10
|
return data;
|
|
13
11
|
};
|
|
14
|
-
|
|
15
12
|
return data;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
function _path() {
|
|
19
15
|
const data = _interopRequireDefault(require("path"));
|
|
20
|
-
|
|
21
16
|
_path = function () {
|
|
22
17
|
return data;
|
|
23
18
|
};
|
|
24
|
-
|
|
25
19
|
return data;
|
|
26
20
|
}
|
|
27
|
-
|
|
28
21
|
function _posthtml() {
|
|
29
22
|
const data = _interopRequireDefault(require("posthtml"));
|
|
30
|
-
|
|
31
23
|
_posthtml = function () {
|
|
32
24
|
return data;
|
|
33
25
|
};
|
|
34
|
-
|
|
35
26
|
return data;
|
|
36
27
|
}
|
|
37
|
-
|
|
38
28
|
function _posthtmlParser() {
|
|
39
29
|
const data = require("posthtml-parser");
|
|
40
|
-
|
|
41
30
|
_posthtmlParser = function () {
|
|
42
31
|
return data;
|
|
43
32
|
};
|
|
44
|
-
|
|
45
33
|
return data;
|
|
46
34
|
}
|
|
47
|
-
|
|
48
35
|
function _posthtmlRender() {
|
|
49
36
|
const data = require("posthtml-render");
|
|
50
|
-
|
|
51
37
|
_posthtmlRender = function () {
|
|
52
38
|
return data;
|
|
53
39
|
};
|
|
54
|
-
|
|
55
40
|
return data;
|
|
56
41
|
}
|
|
57
|
-
|
|
58
42
|
function _nullthrows() {
|
|
59
43
|
const data = _interopRequireDefault(require("nullthrows"));
|
|
60
|
-
|
|
61
44
|
_nullthrows = function () {
|
|
62
45
|
return data;
|
|
63
46
|
};
|
|
64
|
-
|
|
65
47
|
return data;
|
|
66
48
|
}
|
|
67
|
-
|
|
68
49
|
function _semver() {
|
|
69
50
|
const data = _interopRequireDefault(require("semver"));
|
|
70
|
-
|
|
71
51
|
_semver = function () {
|
|
72
52
|
return data;
|
|
73
53
|
};
|
|
74
|
-
|
|
75
54
|
return data;
|
|
76
55
|
}
|
|
77
|
-
|
|
78
|
-
function _utils() {
|
|
79
|
-
const data = require("@parcel/utils");
|
|
80
|
-
|
|
81
|
-
_utils = function () {
|
|
82
|
-
return data;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
return data;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
56
|
var _loadPlugins = _interopRequireDefault(require("./loadPlugins"));
|
|
89
|
-
|
|
90
57
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
91
|
-
|
|
92
58
|
var _default = new (_plugin().Transformer)({
|
|
93
59
|
async loadConfig({
|
|
94
60
|
config,
|
|
@@ -98,33 +64,24 @@ var _default = new (_plugin().Transformer)({
|
|
|
98
64
|
if (!config.isSource) {
|
|
99
65
|
return;
|
|
100
66
|
}
|
|
101
|
-
|
|
102
|
-
let configFile = await config.getConfig(['.posthtmlrc', '.posthtmlrc.js', '.posthtmlrc.cjs', 'posthtml.config.js', 'posthtml.config.cjs'], {
|
|
67
|
+
let configFile = await config.getConfig(['.posthtmlrc', '.posthtmlrc.js', '.posthtmlrc.cjs', '.posthtmlrc.mjs', 'posthtml.config.js', 'posthtml.config.cjs', 'posthtml.config.mjs'], {
|
|
103
68
|
packageKey: 'posthtml'
|
|
104
69
|
});
|
|
105
|
-
|
|
106
70
|
if (configFile) {
|
|
107
71
|
let isJavascript = _path().default.extname(configFile.filePath).endsWith('js');
|
|
108
|
-
|
|
109
72
|
if (isJavascript) {
|
|
110
73
|
// We have to invalidate on startup in case the config is non-deterministic,
|
|
111
74
|
// e.g. using unknown environment variables, reading from the filesystem, etc.
|
|
112
75
|
logger.warn({
|
|
113
76
|
message: 'WARNING: Using a JavaScript PostHTML config file means losing out on caching features of Parcel. Use a .posthtmlrc (JSON) file whenever possible.'
|
|
114
77
|
});
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
config.addDevDependency({
|
|
118
|
-
specifier: (0, _utils().relativePath)(_path().default.dirname(config.searchPath), configFile.filePath),
|
|
119
|
-
resolveFrom: config.searchPath
|
|
120
|
-
});
|
|
121
|
-
} // Load plugins. This must be done before adding dev dependencies so we auto install.
|
|
122
|
-
|
|
78
|
+
}
|
|
123
79
|
|
|
124
|
-
|
|
80
|
+
// Load plugins. This must be done before adding dev dependencies so we auto install.
|
|
81
|
+
let plugins = await (0, _loadPlugins.default)(configFile.contents.plugins, config.searchPath, options);
|
|
125
82
|
|
|
83
|
+
// Now add dev dependencies so we invalidate when they change.
|
|
126
84
|
let pluginArray = Array.isArray(configFile.contents.plugins) ? configFile.contents.plugins : Object.keys(configFile.contents.plugins);
|
|
127
|
-
|
|
128
85
|
for (let p of pluginArray) {
|
|
129
86
|
if (typeof p === 'string') {
|
|
130
87
|
config.addDevDependency({
|
|
@@ -133,21 +90,19 @@ var _default = new (_plugin().Transformer)({
|
|
|
133
90
|
});
|
|
134
91
|
}
|
|
135
92
|
}
|
|
93
|
+
configFile.contents.plugins = plugins;
|
|
136
94
|
|
|
137
|
-
|
|
138
|
-
|
|
95
|
+
// tells posthtml that we have already called parse
|
|
139
96
|
configFile.contents.skipParse = true;
|
|
140
97
|
delete configFile.contents.render;
|
|
141
98
|
return configFile.contents;
|
|
142
99
|
}
|
|
143
100
|
},
|
|
144
|
-
|
|
145
101
|
canReuseAST({
|
|
146
102
|
ast
|
|
147
103
|
}) {
|
|
148
104
|
return ast.type === 'posthtml' && _semver().default.satisfies(ast.version, '^0.4.0');
|
|
149
105
|
},
|
|
150
|
-
|
|
151
106
|
async parse({
|
|
152
107
|
asset,
|
|
153
108
|
config
|
|
@@ -156,7 +111,6 @@ var _default = new (_plugin().Transformer)({
|
|
|
156
111
|
if (!config) {
|
|
157
112
|
return;
|
|
158
113
|
}
|
|
159
|
-
|
|
160
114
|
return {
|
|
161
115
|
type: 'posthtml',
|
|
162
116
|
version: '0.4.1',
|
|
@@ -167,7 +121,6 @@ var _default = new (_plugin().Transformer)({
|
|
|
167
121
|
})
|
|
168
122
|
};
|
|
169
123
|
},
|
|
170
|
-
|
|
171
124
|
async transform({
|
|
172
125
|
asset,
|
|
173
126
|
config
|
|
@@ -175,12 +128,11 @@ var _default = new (_plugin().Transformer)({
|
|
|
175
128
|
if (!config) {
|
|
176
129
|
return [asset];
|
|
177
130
|
}
|
|
178
|
-
|
|
179
131
|
let ast = (0, _nullthrows().default)(await asset.getAST());
|
|
180
|
-
let res = await (0, _posthtml().default)(config.plugins).process(ast.program, {
|
|
132
|
+
let res = await (0, _posthtml().default)(config.plugins).process(ast.program, {
|
|
133
|
+
...config,
|
|
181
134
|
plugins: config.plugins
|
|
182
135
|
});
|
|
183
|
-
|
|
184
136
|
if (res.messages) {
|
|
185
137
|
await Promise.all(res.messages.map(({
|
|
186
138
|
type,
|
|
@@ -189,20 +141,17 @@ var _default = new (_plugin().Transformer)({
|
|
|
189
141
|
if (type === 'dependency') {
|
|
190
142
|
return asset.invalidateOnFileChange(filePath);
|
|
191
143
|
}
|
|
192
|
-
|
|
193
144
|
return Promise.resolve();
|
|
194
145
|
}));
|
|
195
146
|
}
|
|
196
|
-
|
|
197
147
|
asset.setAST({
|
|
198
148
|
type: 'posthtml',
|
|
199
149
|
version: '0.4.1',
|
|
200
150
|
program: JSON.parse(JSON.stringify(res.tree)) // posthtml adds functions to the AST that are not serializable
|
|
201
|
-
|
|
202
151
|
});
|
|
152
|
+
|
|
203
153
|
return [asset];
|
|
204
154
|
},
|
|
205
|
-
|
|
206
155
|
generate({
|
|
207
156
|
ast,
|
|
208
157
|
asset
|
|
@@ -213,7 +162,5 @@ var _default = new (_plugin().Transformer)({
|
|
|
213
162
|
})
|
|
214
163
|
};
|
|
215
164
|
}
|
|
216
|
-
|
|
217
165
|
});
|
|
218
|
-
|
|
219
166
|
exports.default = _default;
|
package/lib/loadPlugins.js
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = loadExternalPlugins;
|
|
7
|
-
|
|
8
7
|
async function loadExternalPlugins(plugins, relative, options) {
|
|
9
8
|
if (Array.isArray(plugins)) {
|
|
10
9
|
return Promise.all(plugins.map(p => loadPlugin(p, relative, null, options.packageManager, options.shouldAutoInstall)).filter(Boolean));
|
|
@@ -15,12 +14,10 @@ async function loadExternalPlugins(plugins, relative, options) {
|
|
|
15
14
|
return [];
|
|
16
15
|
}
|
|
17
16
|
}
|
|
18
|
-
|
|
19
17
|
async function loadPlugin(pluginArg, relative, options = {}, packageManager, shouldAutoInstall) {
|
|
20
18
|
if (typeof pluginArg !== 'string') {
|
|
21
19
|
return pluginArg;
|
|
22
20
|
}
|
|
23
|
-
|
|
24
21
|
let plugin = await packageManager.require(pluginArg, relative, {
|
|
25
22
|
shouldAutoInstall
|
|
26
23
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcel/transformer-posthtml",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -17,16 +17,16 @@
|
|
|
17
17
|
"source": "src/PostHTMLTransformer.js",
|
|
18
18
|
"engines": {
|
|
19
19
|
"node": ">= 12.0.0",
|
|
20
|
-
"parcel": "^2.
|
|
20
|
+
"parcel": "^2.9.0"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@parcel/plugin": "2.
|
|
24
|
-
"@parcel/utils": "2.
|
|
23
|
+
"@parcel/plugin": "2.9.0",
|
|
24
|
+
"@parcel/utils": "2.9.0",
|
|
25
25
|
"nullthrows": "^1.1.1",
|
|
26
26
|
"posthtml": "^0.16.5",
|
|
27
27
|
"posthtml-parser": "^0.10.1",
|
|
28
28
|
"posthtml-render": "^3.0.0",
|
|
29
29
|
"semver": "^5.7.1"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "dd9435be8afed35c5ffc161cf4b586fd6c78fc1f"
|
|
32
32
|
}
|
|
@@ -8,7 +8,6 @@ import {parser as parse} from 'posthtml-parser';
|
|
|
8
8
|
import {render} from 'posthtml-render';
|
|
9
9
|
import nullthrows from 'nullthrows';
|
|
10
10
|
import semver from 'semver';
|
|
11
|
-
import {relativePath} from '@parcel/utils';
|
|
12
11
|
import loadPlugins from './loadPlugins';
|
|
13
12
|
|
|
14
13
|
export default (new Transformer({
|
|
@@ -22,8 +21,10 @@ export default (new Transformer({
|
|
|
22
21
|
'.posthtmlrc',
|
|
23
22
|
'.posthtmlrc.js',
|
|
24
23
|
'.posthtmlrc.cjs',
|
|
24
|
+
'.posthtmlrc.mjs',
|
|
25
25
|
'posthtml.config.js',
|
|
26
26
|
'posthtml.config.cjs',
|
|
27
|
+
'posthtml.config.mjs',
|
|
27
28
|
],
|
|
28
29
|
{
|
|
29
30
|
packageKey: 'posthtml',
|
|
@@ -39,17 +40,6 @@ export default (new Transformer({
|
|
|
39
40
|
message:
|
|
40
41
|
'WARNING: Using a JavaScript PostHTML config file means losing out on caching features of Parcel. Use a .posthtmlrc (JSON) file whenever possible.',
|
|
41
42
|
});
|
|
42
|
-
|
|
43
|
-
config.invalidateOnStartup();
|
|
44
|
-
|
|
45
|
-
// Also add the config as a dev dependency so we attempt to reload in watch mode.
|
|
46
|
-
config.addDevDependency({
|
|
47
|
-
specifier: relativePath(
|
|
48
|
-
path.dirname(config.searchPath),
|
|
49
|
-
configFile.filePath,
|
|
50
|
-
),
|
|
51
|
-
resolveFrom: config.searchPath,
|
|
52
|
-
});
|
|
53
43
|
}
|
|
54
44
|
|
|
55
45
|
// Load plugins. This must be done before adding dev dependencies so we auto install.
|