@parcel/transformer-postcss 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/PostCSSTransformer.js +13 -81
- package/lib/loadConfig.js +5 -56
- package/lib/loadPlugins.js +0 -5
- package/package.json +7 -7
- package/src/loadConfig.js +2 -12
|
@@ -4,98 +4,69 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
function _hash() {
|
|
9
8
|
const data = require("@parcel/hash");
|
|
10
|
-
|
|
11
9
|
_hash = function () {
|
|
12
10
|
return data;
|
|
13
11
|
};
|
|
14
|
-
|
|
15
12
|
return data;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
function _utils() {
|
|
19
15
|
const data = require("@parcel/utils");
|
|
20
|
-
|
|
21
16
|
_utils = function () {
|
|
22
17
|
return data;
|
|
23
18
|
};
|
|
24
|
-
|
|
25
19
|
return data;
|
|
26
20
|
}
|
|
27
|
-
|
|
28
21
|
function _plugin() {
|
|
29
22
|
const data = require("@parcel/plugin");
|
|
30
|
-
|
|
31
23
|
_plugin = function () {
|
|
32
24
|
return data;
|
|
33
25
|
};
|
|
34
|
-
|
|
35
26
|
return data;
|
|
36
27
|
}
|
|
37
|
-
|
|
38
28
|
function _nullthrows() {
|
|
39
29
|
const data = _interopRequireDefault(require("nullthrows"));
|
|
40
|
-
|
|
41
30
|
_nullthrows = function () {
|
|
42
31
|
return data;
|
|
43
32
|
};
|
|
44
|
-
|
|
45
33
|
return data;
|
|
46
34
|
}
|
|
47
|
-
|
|
48
35
|
function _path() {
|
|
49
36
|
const data = _interopRequireDefault(require("path"));
|
|
50
|
-
|
|
51
37
|
_path = function () {
|
|
52
38
|
return data;
|
|
53
39
|
};
|
|
54
|
-
|
|
55
40
|
return data;
|
|
56
41
|
}
|
|
57
|
-
|
|
58
42
|
function _semver() {
|
|
59
43
|
const data = _interopRequireDefault(require("semver"));
|
|
60
|
-
|
|
61
44
|
_semver = function () {
|
|
62
45
|
return data;
|
|
63
46
|
};
|
|
64
|
-
|
|
65
47
|
return data;
|
|
66
48
|
}
|
|
67
|
-
|
|
68
49
|
function _postcssValueParser() {
|
|
69
50
|
const data = _interopRequireDefault(require("postcss-value-parser"));
|
|
70
|
-
|
|
71
51
|
_postcssValueParser = function () {
|
|
72
52
|
return data;
|
|
73
53
|
};
|
|
74
|
-
|
|
75
54
|
return data;
|
|
76
55
|
}
|
|
77
|
-
|
|
78
56
|
var _loadConfig = require("./loadConfig");
|
|
79
|
-
|
|
80
57
|
var _constants = require("./constants");
|
|
81
|
-
|
|
82
58
|
function _diagnostic() {
|
|
83
59
|
const data = require("@parcel/diagnostic");
|
|
84
|
-
|
|
85
60
|
_diagnostic = function () {
|
|
86
61
|
return data;
|
|
87
62
|
};
|
|
88
|
-
|
|
89
63
|
return data;
|
|
90
64
|
}
|
|
91
|
-
|
|
92
65
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
93
|
-
|
|
94
66
|
const COMPOSES_RE = /composes:.+from\s*("|').*("|')\s*;?/;
|
|
95
67
|
const FROM_IMPORT_RE = /.+from\s*(?:"|')(.*)(?:"|')\s*;?/;
|
|
96
68
|
const LEGACY_MODULE_RE = /@value|:export|(:global|:local|:import)(?!\s*\()/i;
|
|
97
69
|
const MODULE_BY_NAME_RE = /\.module\./;
|
|
98
|
-
|
|
99
70
|
var _default = new (_plugin().Transformer)({
|
|
100
71
|
loadConfig({
|
|
101
72
|
config,
|
|
@@ -108,24 +79,20 @@ var _default = new (_plugin().Transformer)({
|
|
|
108
79
|
logger
|
|
109
80
|
});
|
|
110
81
|
},
|
|
111
|
-
|
|
112
82
|
canReuseAST({
|
|
113
83
|
ast
|
|
114
84
|
}) {
|
|
115
85
|
return ast.type === 'postcss' && _semver().default.satisfies(ast.version, _constants.POSTCSS_RANGE);
|
|
116
86
|
},
|
|
117
|
-
|
|
118
87
|
async parse({
|
|
119
88
|
asset,
|
|
120
89
|
config,
|
|
121
90
|
options
|
|
122
91
|
}) {
|
|
123
92
|
let isLegacy = await isLegacyCssModule(asset);
|
|
124
|
-
|
|
125
93
|
if (!config && !isLegacy) {
|
|
126
94
|
return;
|
|
127
95
|
}
|
|
128
|
-
|
|
129
96
|
const postcss = await loadPostcss(options, asset.filePath);
|
|
130
97
|
return {
|
|
131
98
|
type: 'postcss',
|
|
@@ -135,7 +102,6 @@ var _default = new (_plugin().Transformer)({
|
|
|
135
102
|
}).toJSON()
|
|
136
103
|
};
|
|
137
104
|
},
|
|
138
|
-
|
|
139
105
|
async transform({
|
|
140
106
|
asset,
|
|
141
107
|
config,
|
|
@@ -145,7 +111,6 @@ var _default = new (_plugin().Transformer)({
|
|
|
145
111
|
}) {
|
|
146
112
|
asset.type = 'css';
|
|
147
113
|
let isLegacy = await isLegacyCssModule(asset);
|
|
148
|
-
|
|
149
114
|
if (isLegacy && !config) {
|
|
150
115
|
config = {
|
|
151
116
|
raw: {},
|
|
@@ -156,30 +121,27 @@ var _default = new (_plugin().Transformer)({
|
|
|
156
121
|
to: asset.filePath,
|
|
157
122
|
modules: {}
|
|
158
123
|
}
|
|
159
|
-
};
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
// TODO: warning?
|
|
160
127
|
}
|
|
161
128
|
|
|
162
129
|
if (!config) {
|
|
163
130
|
return [asset];
|
|
164
131
|
}
|
|
165
|
-
|
|
166
132
|
const postcss = await loadPostcss(options, asset.filePath);
|
|
167
133
|
let ast = (0, _nullthrows().default)(await asset.getAST());
|
|
168
134
|
let program = postcss.fromJSON(ast.program);
|
|
169
135
|
let plugins = [...config.hydrated.plugins];
|
|
170
136
|
let cssModules = null;
|
|
171
|
-
|
|
172
137
|
if (config.hydrated.modules) {
|
|
173
138
|
asset.meta.cssModulesCompiled = 'postcss';
|
|
174
139
|
let code = asset.isASTDirty() ? null : await asset.getCode();
|
|
175
|
-
|
|
176
140
|
if (Object.keys(config.hydrated.modules).length === 0 && code && !isLegacy && !LEGACY_MODULE_RE.test(code)) {
|
|
177
141
|
let filename = _path().default.basename(config.filePath);
|
|
178
|
-
|
|
179
142
|
let message;
|
|
180
143
|
let configKey;
|
|
181
144
|
let hint;
|
|
182
|
-
|
|
183
145
|
if (config.raw.modules) {
|
|
184
146
|
message = (0, _diagnostic().md)`The "modules" option in __${filename}__ can be replaced with configuration for @parcel/transformer-css to improve build performance.`;
|
|
185
147
|
configKey = '/modules';
|
|
@@ -189,22 +151,17 @@ var _default = new (_plugin().Transformer)({
|
|
|
189
151
|
configKey = '/plugins/postcss-modules';
|
|
190
152
|
hint = (0, _diagnostic().md)`Remove the "postcss-modules" plugin from __${filename}__`;
|
|
191
153
|
}
|
|
192
|
-
|
|
193
154
|
if (filename === 'package.json') {
|
|
194
155
|
configKey = `/postcss${configKey}`;
|
|
195
156
|
}
|
|
196
|
-
|
|
197
157
|
let hints = ['Enable the "cssModules" option for "@parcel/transformer-css" in your package.json'];
|
|
198
|
-
|
|
199
158
|
if (plugins.length === 0) {
|
|
200
159
|
message += (0, _diagnostic().md)` Since there are no other plugins, __${filename}__ can be deleted safely.`;
|
|
201
160
|
hints.push((0, _diagnostic().md)`Delete __${filename}__`);
|
|
202
161
|
} else {
|
|
203
162
|
hints.push(hint);
|
|
204
163
|
}
|
|
205
|
-
|
|
206
164
|
let codeFrames;
|
|
207
|
-
|
|
208
165
|
if (_path().default.extname(filename) !== '.js') {
|
|
209
166
|
let contents = await asset.fs.readFile(config.filePath, 'utf8');
|
|
210
167
|
codeFrames = [{
|
|
@@ -231,16 +188,15 @@ var _default = new (_plugin().Transformer)({
|
|
|
231
188
|
}]
|
|
232
189
|
}];
|
|
233
190
|
}
|
|
234
|
-
|
|
235
191
|
logger.warn({
|
|
236
192
|
message,
|
|
237
193
|
hints,
|
|
238
194
|
documentationURL: 'https://parceljs.org/languages/css/#enabling-css-modules-globally',
|
|
239
195
|
codeFrames
|
|
240
196
|
});
|
|
241
|
-
}
|
|
242
|
-
|
|
197
|
+
}
|
|
243
198
|
|
|
199
|
+
// TODO: should this be resolved from the project root?
|
|
244
200
|
let postcssModules = await options.packageManager.require('postcss-modules', asset.filePath, {
|
|
245
201
|
range: '^4.3.0',
|
|
246
202
|
saveDev: true,
|
|
@@ -252,11 +208,9 @@ var _default = new (_plugin().Transformer)({
|
|
|
252
208
|
generateScopedName: (name, filename) => `${name}_${(0, _hash().hashString)(_path().default.relative(options.projectRoot, filename)).substr(0, 6)}`,
|
|
253
209
|
...config.hydrated.modules
|
|
254
210
|
}));
|
|
255
|
-
|
|
256
211
|
if (code == null || COMPOSES_RE.test(code)) {
|
|
257
212
|
program.walkDecls(decl => {
|
|
258
213
|
let [, importPath] = FROM_IMPORT_RE.exec(decl.value) || [];
|
|
259
|
-
|
|
260
214
|
if (decl.prop === 'composes' && importPath != null) {
|
|
261
215
|
let parsed = (0, _postcssValueParser().default)(decl.value);
|
|
262
216
|
parsed.walk(node => {
|
|
@@ -278,9 +232,9 @@ var _default = new (_plugin().Transformer)({
|
|
|
278
232
|
}
|
|
279
233
|
});
|
|
280
234
|
}
|
|
281
|
-
}
|
|
282
|
-
|
|
235
|
+
}
|
|
283
236
|
|
|
237
|
+
// $FlowFixMe Added in Flow 0.121.0 upgrade in #4381
|
|
284
238
|
let {
|
|
285
239
|
messages,
|
|
286
240
|
root
|
|
@@ -290,61 +244,50 @@ var _default = new (_plugin().Transformer)({
|
|
|
290
244
|
version: '8.2.1',
|
|
291
245
|
program: root.toJSON()
|
|
292
246
|
});
|
|
293
|
-
|
|
294
247
|
for (let msg of messages) {
|
|
295
248
|
if (msg.type === 'dependency') {
|
|
296
249
|
asset.invalidateOnFileChange(msg.file);
|
|
297
250
|
} else if (msg.type === 'dir-dependency') {
|
|
298
251
|
var _msg$glob;
|
|
299
|
-
|
|
300
252
|
let pattern = `${msg.dir}/${(_msg$glob = msg.glob) !== null && _msg$glob !== void 0 ? _msg$glob : '**/*'}`;
|
|
301
253
|
let files = await (0, _utils().glob)(pattern, asset.fs, {
|
|
302
254
|
onlyFiles: true
|
|
303
255
|
});
|
|
304
|
-
|
|
305
256
|
for (let file of files) {
|
|
306
257
|
asset.invalidateOnFileChange(_path().default.normalize(file));
|
|
307
258
|
}
|
|
308
|
-
|
|
309
259
|
asset.invalidateOnFileCreate({
|
|
310
260
|
glob: pattern
|
|
311
261
|
});
|
|
312
262
|
}
|
|
313
263
|
}
|
|
314
|
-
|
|
315
264
|
let assets = [asset];
|
|
316
|
-
|
|
317
265
|
if (cssModules) {
|
|
318
266
|
// $FlowFixMe
|
|
319
267
|
let cssModulesList = Object.entries(cssModules);
|
|
320
268
|
let deps = asset.getDependencies().filter(dep => dep.priority === 'sync');
|
|
321
269
|
let code;
|
|
322
|
-
|
|
323
270
|
if (deps.length > 0) {
|
|
324
271
|
code = `
|
|
325
272
|
module.exports = Object.assign({}, ${deps.map(dep => `require(${JSON.stringify(dep.specifier)})`).join(', ')}, ${JSON.stringify(cssModules, null, 2)});
|
|
326
273
|
`;
|
|
327
274
|
} else {
|
|
328
|
-
code = cssModulesList.map(
|
|
275
|
+
code = cssModulesList.map(
|
|
276
|
+
// This syntax enables shaking the invidual statements, so that unused classes don't even exist in JS.
|
|
329
277
|
([className, classNameHashed]) => `module.exports[${JSON.stringify(className)}] = ${JSON.stringify(classNameHashed)};`).join('\n');
|
|
330
278
|
}
|
|
331
|
-
|
|
332
279
|
asset.symbols.ensure();
|
|
333
|
-
|
|
334
280
|
for (let [k, v] of cssModulesList) {
|
|
335
281
|
asset.symbols.set(k, v);
|
|
336
282
|
}
|
|
337
|
-
|
|
338
283
|
asset.symbols.set('default', 'default');
|
|
339
284
|
assets.push({
|
|
340
285
|
type: 'js',
|
|
341
286
|
content: code
|
|
342
287
|
});
|
|
343
288
|
}
|
|
344
|
-
|
|
345
289
|
return assets;
|
|
346
290
|
},
|
|
347
|
-
|
|
348
291
|
async generate({
|
|
349
292
|
asset,
|
|
350
293
|
ast,
|
|
@@ -359,11 +302,8 @@ var _default = new (_plugin().Transformer)({
|
|
|
359
302
|
content: code
|
|
360
303
|
};
|
|
361
304
|
}
|
|
362
|
-
|
|
363
305
|
});
|
|
364
|
-
|
|
365
306
|
exports.default = _default;
|
|
366
|
-
|
|
367
307
|
async function createLoader(asset, resolve, options) {
|
|
368
308
|
let {
|
|
369
309
|
default: FileSystemLoader
|
|
@@ -372,32 +312,26 @@ async function createLoader(asset, resolve, options) {
|
|
|
372
312
|
async fetch(composesPath, relativeTo) {
|
|
373
313
|
let importPath = composesPath.replace(/^["']|["']$/g, '');
|
|
374
314
|
let resolved = await resolve(relativeTo, importPath);
|
|
375
|
-
|
|
376
315
|
let rootRelativePath = _path().default.resolve(_path().default.dirname(relativeTo), resolved);
|
|
377
|
-
|
|
378
|
-
|
|
316
|
+
let root = _path().default.resolve('/');
|
|
317
|
+
// fixes an issue on windows which is part of the css-modules-loader-core
|
|
379
318
|
// see https://github.com/css-modules/css-modules-loader-core/issues/230
|
|
380
|
-
|
|
381
|
-
|
|
382
319
|
if (rootRelativePath.startsWith(root)) {
|
|
383
320
|
rootRelativePath = rootRelativePath.substr(root.length);
|
|
384
321
|
}
|
|
385
|
-
|
|
386
322
|
let source = await asset.fs.readFile(resolved, 'utf-8');
|
|
387
323
|
let {
|
|
388
324
|
exportTokens
|
|
389
|
-
} = await this.core.load(source, rootRelativePath, undefined,
|
|
325
|
+
} = await this.core.load(source, rootRelativePath, undefined,
|
|
326
|
+
// $FlowFixMe[method-unbinding]
|
|
390
327
|
this.fetch.bind(this));
|
|
391
328
|
return exportTokens;
|
|
392
329
|
}
|
|
393
|
-
|
|
394
330
|
get finalSource() {
|
|
395
331
|
return '';
|
|
396
332
|
}
|
|
397
|
-
|
|
398
333
|
};
|
|
399
334
|
}
|
|
400
|
-
|
|
401
335
|
function loadPostcss(options, from) {
|
|
402
336
|
return options.packageManager.require('postcss', from, {
|
|
403
337
|
range: _constants.POSTCSS_RANGE,
|
|
@@ -405,12 +339,10 @@ function loadPostcss(options, from) {
|
|
|
405
339
|
shouldAutoInstall: options.shouldAutoInstall
|
|
406
340
|
});
|
|
407
341
|
}
|
|
408
|
-
|
|
409
342
|
async function isLegacyCssModule(asset) {
|
|
410
343
|
if (!MODULE_BY_NAME_RE.test(asset.filePath)) {
|
|
411
344
|
return false;
|
|
412
345
|
}
|
|
413
|
-
|
|
414
346
|
let code = await asset.getCode();
|
|
415
347
|
return LEGACY_MODULE_RE.test(code);
|
|
416
348
|
}
|
package/lib/loadConfig.js
CHANGED
|
@@ -4,88 +4,59 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.load = load;
|
|
7
|
-
|
|
8
7
|
function _path() {
|
|
9
8
|
const data = _interopRequireDefault(require("path"));
|
|
10
|
-
|
|
11
9
|
_path = function () {
|
|
12
10
|
return data;
|
|
13
11
|
};
|
|
14
|
-
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function _utils() {
|
|
19
|
-
const data = require("@parcel/utils");
|
|
20
|
-
|
|
21
|
-
_utils = function () {
|
|
22
|
-
return data;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
12
|
return data;
|
|
26
13
|
}
|
|
27
|
-
|
|
28
14
|
function _diagnostic() {
|
|
29
15
|
const data = require("@parcel/diagnostic");
|
|
30
|
-
|
|
31
16
|
_diagnostic = function () {
|
|
32
17
|
return data;
|
|
33
18
|
};
|
|
34
|
-
|
|
35
19
|
return data;
|
|
36
20
|
}
|
|
37
|
-
|
|
38
21
|
function _nullthrows() {
|
|
39
22
|
const data = _interopRequireDefault(require("nullthrows"));
|
|
40
|
-
|
|
41
23
|
_nullthrows = function () {
|
|
42
24
|
return data;
|
|
43
25
|
};
|
|
44
|
-
|
|
45
26
|
return data;
|
|
46
27
|
}
|
|
47
|
-
|
|
48
28
|
function _clone() {
|
|
49
29
|
const data = _interopRequireDefault(require("clone"));
|
|
50
|
-
|
|
51
30
|
_clone = function () {
|
|
52
31
|
return data;
|
|
53
32
|
};
|
|
54
|
-
|
|
55
33
|
return data;
|
|
56
34
|
}
|
|
57
|
-
|
|
58
35
|
var _constants = require("./constants");
|
|
59
|
-
|
|
60
36
|
var _loadPlugins = _interopRequireDefault(require("./loadPlugins"));
|
|
61
|
-
|
|
62
37
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
63
|
-
|
|
64
38
|
async function configHydrator(configFile, config, resolveFrom, options, logger) {
|
|
65
39
|
if (configFile == null) {
|
|
66
40
|
return;
|
|
67
|
-
}
|
|
68
|
-
|
|
41
|
+
}
|
|
69
42
|
|
|
43
|
+
// Load the custom config...
|
|
70
44
|
let modulesConfig;
|
|
71
45
|
let configFilePlugins = (0, _clone().default)(configFile.plugins);
|
|
72
|
-
|
|
73
46
|
if (configFilePlugins != null && typeof configFilePlugins === 'object' && configFilePlugins['postcss-modules'] != null) {
|
|
74
47
|
modulesConfig = configFilePlugins['postcss-modules'];
|
|
75
48
|
delete configFilePlugins['postcss-modules'];
|
|
76
49
|
}
|
|
77
|
-
|
|
78
50
|
if (!modulesConfig && configFile.modules) {
|
|
79
51
|
modulesConfig = {};
|
|
80
52
|
}
|
|
53
|
+
let plugins = await (0, _loadPlugins.default)(configFilePlugins, (0, _nullthrows().default)(resolveFrom), options);
|
|
81
54
|
|
|
82
|
-
|
|
55
|
+
// contents is either:
|
|
83
56
|
// from JSON: { plugins: { 'postcss-foo': { ...opts } } }
|
|
84
57
|
// from JS (v8): { plugins: [ { postcssPlugin: 'postcss-foo', ...visitor callback functions } ]
|
|
85
58
|
// from JS (v7): { plugins: [ [Function: ...] ]
|
|
86
|
-
|
|
87
59
|
let pluginArray = Array.isArray(configFilePlugins) ? configFilePlugins : Object.keys(configFilePlugins);
|
|
88
|
-
|
|
89
60
|
for (let p of pluginArray) {
|
|
90
61
|
if (typeof p === 'string') {
|
|
91
62
|
config.addDevDependency({
|
|
@@ -94,16 +65,12 @@ async function configHydrator(configFile, config, resolveFrom, options, logger)
|
|
|
94
65
|
});
|
|
95
66
|
}
|
|
96
67
|
}
|
|
97
|
-
|
|
98
68
|
let redundantPlugins = pluginArray.filter(p => p === 'autoprefixer' || p === 'postcss-preset-env');
|
|
99
|
-
|
|
100
69
|
if (redundantPlugins.length > 0) {
|
|
101
70
|
let filename = _path().default.basename(resolveFrom);
|
|
102
|
-
|
|
103
71
|
let isPackageJson = filename === 'package.json';
|
|
104
72
|
let message;
|
|
105
73
|
let hints = [];
|
|
106
|
-
|
|
107
74
|
if (!isPackageJson && redundantPlugins.length === pluginArray.length) {
|
|
108
75
|
message = (0, _diagnostic().md)`Parcel includes CSS transpilation and vendor prefixing by default. PostCSS config __${filename}__ contains only redundant plugins. Deleting it may significantly improve build performance.`;
|
|
109
76
|
hints.push((0, _diagnostic().md)`Delete __${filename}__`);
|
|
@@ -111,9 +78,7 @@ async function configHydrator(configFile, config, resolveFrom, options, logger)
|
|
|
111
78
|
message = (0, _diagnostic().md)`Parcel includes CSS transpilation and vendor prefixing by default. PostCSS config __${filename}__ contains the following redundant plugins: ${[...redundantPlugins].map(p => _diagnostic().md.underline(p))}. Removing these may improve build performance.`;
|
|
112
79
|
hints.push((0, _diagnostic().md)`Remove the above plugins from __${filename}__`);
|
|
113
80
|
}
|
|
114
|
-
|
|
115
81
|
let codeFrames;
|
|
116
|
-
|
|
117
82
|
if (_path().default.extname(filename) !== '.js') {
|
|
118
83
|
let contents = await options.inputFS.readFile(resolveFrom, 'utf8');
|
|
119
84
|
let prefix = isPackageJson ? '/postcss' : '';
|
|
@@ -141,7 +106,6 @@ async function configHydrator(configFile, config, resolveFrom, options, logger)
|
|
|
141
106
|
}]
|
|
142
107
|
}];
|
|
143
108
|
}
|
|
144
|
-
|
|
145
109
|
logger.warn({
|
|
146
110
|
message,
|
|
147
111
|
hints,
|
|
@@ -149,7 +113,6 @@ async function configHydrator(configFile, config, resolveFrom, options, logger)
|
|
|
149
113
|
codeFrames
|
|
150
114
|
});
|
|
151
115
|
}
|
|
152
|
-
|
|
153
116
|
return {
|
|
154
117
|
raw: configFile,
|
|
155
118
|
filePath: resolveFrom,
|
|
@@ -161,7 +124,6 @@ async function configHydrator(configFile, config, resolveFrom, options, logger)
|
|
|
161
124
|
}
|
|
162
125
|
};
|
|
163
126
|
}
|
|
164
|
-
|
|
165
127
|
async function load({
|
|
166
128
|
config,
|
|
167
129
|
options,
|
|
@@ -170,12 +132,10 @@ async function load({
|
|
|
170
132
|
if (!config.isSource) {
|
|
171
133
|
return;
|
|
172
134
|
}
|
|
173
|
-
|
|
174
|
-
let configFile = await config.getConfig(['.postcssrc', '.postcssrc.json', '.postcssrc.js', '.postcssrc.cjs', 'postcss.config.js', 'postcss.config.cjs'], {
|
|
135
|
+
let configFile = await config.getConfig(['.postcssrc', '.postcssrc.json', '.postcssrc.js', '.postcssrc.cjs', '.postcssrc.mjs', 'postcss.config.js', 'postcss.config.cjs', 'postcss.config.mjs'], {
|
|
175
136
|
packageKey: 'postcss'
|
|
176
137
|
});
|
|
177
138
|
let contents = null;
|
|
178
|
-
|
|
179
139
|
if (configFile) {
|
|
180
140
|
config.addDevDependency({
|
|
181
141
|
specifier: 'postcss',
|
|
@@ -183,31 +143,20 @@ async function load({
|
|
|
183
143
|
range: _constants.POSTCSS_RANGE
|
|
184
144
|
});
|
|
185
145
|
contents = configFile.contents;
|
|
186
|
-
|
|
187
146
|
let isDynamic = configFile && _path().default.extname(configFile.filePath).endsWith('js');
|
|
188
|
-
|
|
189
147
|
if (isDynamic) {
|
|
190
148
|
// We have to invalidate on startup in case the config is non-deterministic,
|
|
191
149
|
// e.g. using unknown environment variables, reading from the filesystem, etc.
|
|
192
150
|
logger.warn({
|
|
193
151
|
message: 'WARNING: Using a JavaScript PostCSS config file means losing out on caching features of Parcel. Use a .postcssrc(.json) file whenever possible.'
|
|
194
152
|
});
|
|
195
|
-
config.invalidateOnStartup(); // Also add the config as a dev dependency so we attempt to reload in watch mode.
|
|
196
|
-
|
|
197
|
-
config.addDevDependency({
|
|
198
|
-
specifier: (0, _utils().relativePath)(_path().default.dirname(config.searchPath), configFile.filePath),
|
|
199
|
-
resolveFrom: config.searchPath
|
|
200
|
-
});
|
|
201
153
|
}
|
|
202
|
-
|
|
203
154
|
if (typeof contents !== 'object') {
|
|
204
155
|
throw new Error('PostCSS config should be an object.');
|
|
205
156
|
}
|
|
206
|
-
|
|
207
157
|
if (contents.plugins == null || typeof contents.plugins !== 'object' || Object.keys(contents.plugins).length === 0) {
|
|
208
158
|
throw new Error('PostCSS config must have plugins');
|
|
209
159
|
}
|
|
210
160
|
}
|
|
211
|
-
|
|
212
161
|
return configHydrator(contents, config, configFile === null || configFile === void 0 ? void 0 : configFile.filePath, options, logger);
|
|
213
162
|
}
|
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,20 +14,16 @@ 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
|
});
|
|
27
24
|
plugin = plugin.default || plugin;
|
|
28
|
-
|
|
29
25
|
if (options != null && typeof options === 'object' && Object.keys(options).length > 0) {
|
|
30
26
|
plugin = plugin(options);
|
|
31
27
|
}
|
|
32
|
-
|
|
33
28
|
return plugin.default || plugin;
|
|
34
29
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcel/transformer-postcss",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -17,13 +17,13 @@
|
|
|
17
17
|
"source": "src/PostCSSTransformer.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/diagnostic": "2.
|
|
24
|
-
"@parcel/hash": "2.
|
|
25
|
-
"@parcel/plugin": "2.
|
|
26
|
-
"@parcel/utils": "2.
|
|
23
|
+
"@parcel/diagnostic": "2.9.0",
|
|
24
|
+
"@parcel/hash": "2.9.0",
|
|
25
|
+
"@parcel/plugin": "2.9.0",
|
|
26
|
+
"@parcel/utils": "2.9.0",
|
|
27
27
|
"clone": "^2.1.1",
|
|
28
28
|
"nullthrows": "^1.1.1",
|
|
29
29
|
"postcss-value-parser": "^4.2.0",
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"postcss": "^8.4.5",
|
|
34
34
|
"postcss-modules": "^4.3.1"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "dd9435be8afed35c5ffc161cf4b586fd6c78fc1f"
|
|
37
37
|
}
|
package/src/loadConfig.js
CHANGED
|
@@ -6,7 +6,6 @@ import type {
|
|
|
6
6
|
PluginLogger,
|
|
7
7
|
} from '@parcel/types';
|
|
8
8
|
import path from 'path';
|
|
9
|
-
import {relativePath} from '@parcel/utils';
|
|
10
9
|
import {md, generateJSONCodeHighlights} from '@parcel/diagnostic';
|
|
11
10
|
import nullthrows from 'nullthrows';
|
|
12
11
|
import clone from 'clone';
|
|
@@ -165,8 +164,10 @@ export async function load({
|
|
|
165
164
|
'.postcssrc.json',
|
|
166
165
|
'.postcssrc.js',
|
|
167
166
|
'.postcssrc.cjs',
|
|
167
|
+
'.postcssrc.mjs',
|
|
168
168
|
'postcss.config.js',
|
|
169
169
|
'postcss.config.cjs',
|
|
170
|
+
'postcss.config.mjs',
|
|
170
171
|
],
|
|
171
172
|
{packageKey: 'postcss'},
|
|
172
173
|
);
|
|
@@ -189,17 +190,6 @@ export async function load({
|
|
|
189
190
|
message:
|
|
190
191
|
'WARNING: Using a JavaScript PostCSS config file means losing out on caching features of Parcel. Use a .postcssrc(.json) file whenever possible.',
|
|
191
192
|
});
|
|
192
|
-
|
|
193
|
-
config.invalidateOnStartup();
|
|
194
|
-
|
|
195
|
-
// Also add the config as a dev dependency so we attempt to reload in watch mode.
|
|
196
|
-
config.addDevDependency({
|
|
197
|
-
specifier: relativePath(
|
|
198
|
-
path.dirname(config.searchPath),
|
|
199
|
-
configFile.filePath,
|
|
200
|
-
),
|
|
201
|
-
resolveFrom: config.searchPath,
|
|
202
|
-
});
|
|
203
193
|
}
|
|
204
194
|
|
|
205
195
|
if (typeof contents !== 'object') {
|