@parcel/transformer-postcss 2.0.0-nightly.150 → 2.0.0-nightly.1501

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