@parcel/transformer-postcss 2.8.4-nightly.0 → 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.
@@ -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
- }; // TODO: warning?
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
- } // TODO: should this be resolved from the project root?
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
- } // $FlowFixMe Added in Flow 0.121.0 upgrade in #4381
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( // This syntax enables shaking the invidual statements, so that unused classes don't even exist in JS.
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
- let root = _path().default.resolve('/'); // fixes an issue on windows which is part of the css-modules-loader-core
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, // $FlowFixMe[method-unbinding]
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,78 +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
12
  return data;
16
13
  }
17
-
18
14
  function _diagnostic() {
19
15
  const data = require("@parcel/diagnostic");
20
-
21
16
  _diagnostic = function () {
22
17
  return data;
23
18
  };
24
-
25
19
  return data;
26
20
  }
27
-
28
21
  function _nullthrows() {
29
22
  const data = _interopRequireDefault(require("nullthrows"));
30
-
31
23
  _nullthrows = function () {
32
24
  return data;
33
25
  };
34
-
35
26
  return data;
36
27
  }
37
-
38
28
  function _clone() {
39
29
  const data = _interopRequireDefault(require("clone"));
40
-
41
30
  _clone = function () {
42
31
  return data;
43
32
  };
44
-
45
33
  return data;
46
34
  }
47
-
48
35
  var _constants = require("./constants");
49
-
50
36
  var _loadPlugins = _interopRequireDefault(require("./loadPlugins"));
51
-
52
37
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
53
-
54
38
  async function configHydrator(configFile, config, resolveFrom, options, logger) {
55
39
  if (configFile == null) {
56
40
  return;
57
- } // Load the custom config...
58
-
41
+ }
59
42
 
43
+ // Load the custom config...
60
44
  let modulesConfig;
61
45
  let configFilePlugins = (0, _clone().default)(configFile.plugins);
62
-
63
46
  if (configFilePlugins != null && typeof configFilePlugins === 'object' && configFilePlugins['postcss-modules'] != null) {
64
47
  modulesConfig = configFilePlugins['postcss-modules'];
65
48
  delete configFilePlugins['postcss-modules'];
66
49
  }
67
-
68
50
  if (!modulesConfig && configFile.modules) {
69
51
  modulesConfig = {};
70
52
  }
53
+ let plugins = await (0, _loadPlugins.default)(configFilePlugins, (0, _nullthrows().default)(resolveFrom), options);
71
54
 
72
- let plugins = await (0, _loadPlugins.default)(configFilePlugins, (0, _nullthrows().default)(resolveFrom), options); // contents is either:
55
+ // contents is either:
73
56
  // from JSON: { plugins: { 'postcss-foo': { ...opts } } }
74
57
  // from JS (v8): { plugins: [ { postcssPlugin: 'postcss-foo', ...visitor callback functions } ]
75
58
  // from JS (v7): { plugins: [ [Function: ...] ]
76
-
77
59
  let pluginArray = Array.isArray(configFilePlugins) ? configFilePlugins : Object.keys(configFilePlugins);
78
-
79
60
  for (let p of pluginArray) {
80
61
  if (typeof p === 'string') {
81
62
  config.addDevDependency({
@@ -84,16 +65,12 @@ async function configHydrator(configFile, config, resolveFrom, options, logger)
84
65
  });
85
66
  }
86
67
  }
87
-
88
68
  let redundantPlugins = pluginArray.filter(p => p === 'autoprefixer' || p === 'postcss-preset-env');
89
-
90
69
  if (redundantPlugins.length > 0) {
91
70
  let filename = _path().default.basename(resolveFrom);
92
-
93
71
  let isPackageJson = filename === 'package.json';
94
72
  let message;
95
73
  let hints = [];
96
-
97
74
  if (!isPackageJson && redundantPlugins.length === pluginArray.length) {
98
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.`;
99
76
  hints.push((0, _diagnostic().md)`Delete __${filename}__`);
@@ -101,9 +78,7 @@ async function configHydrator(configFile, config, resolveFrom, options, logger)
101
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.`;
102
79
  hints.push((0, _diagnostic().md)`Remove the above plugins from __${filename}__`);
103
80
  }
104
-
105
81
  let codeFrames;
106
-
107
82
  if (_path().default.extname(filename) !== '.js') {
108
83
  let contents = await options.inputFS.readFile(resolveFrom, 'utf8');
109
84
  let prefix = isPackageJson ? '/postcss' : '';
@@ -131,7 +106,6 @@ async function configHydrator(configFile, config, resolveFrom, options, logger)
131
106
  }]
132
107
  }];
133
108
  }
134
-
135
109
  logger.warn({
136
110
  message,
137
111
  hints,
@@ -139,7 +113,6 @@ async function configHydrator(configFile, config, resolveFrom, options, logger)
139
113
  codeFrames
140
114
  });
141
115
  }
142
-
143
116
  return {
144
117
  raw: configFile,
145
118
  filePath: resolveFrom,
@@ -151,7 +124,6 @@ async function configHydrator(configFile, config, resolveFrom, options, logger)
151
124
  }
152
125
  };
153
126
  }
154
-
155
127
  async function load({
156
128
  config,
157
129
  options,
@@ -160,12 +132,10 @@ async function load({
160
132
  if (!config.isSource) {
161
133
  return;
162
134
  }
163
-
164
135
  let configFile = await config.getConfig(['.postcssrc', '.postcssrc.json', '.postcssrc.js', '.postcssrc.cjs', '.postcssrc.mjs', 'postcss.config.js', 'postcss.config.cjs', 'postcss.config.mjs'], {
165
136
  packageKey: 'postcss'
166
137
  });
167
138
  let contents = null;
168
-
169
139
  if (configFile) {
170
140
  config.addDevDependency({
171
141
  specifier: 'postcss',
@@ -173,9 +143,7 @@ async function load({
173
143
  range: _constants.POSTCSS_RANGE
174
144
  });
175
145
  contents = configFile.contents;
176
-
177
146
  let isDynamic = configFile && _path().default.extname(configFile.filePath).endsWith('js');
178
-
179
147
  if (isDynamic) {
180
148
  // We have to invalidate on startup in case the config is non-deterministic,
181
149
  // e.g. using unknown environment variables, reading from the filesystem, etc.
@@ -183,15 +151,12 @@ async function load({
183
151
  message: 'WARNING: Using a JavaScript PostCSS config file means losing out on caching features of Parcel. Use a .postcssrc(.json) file whenever possible.'
184
152
  });
185
153
  }
186
-
187
154
  if (typeof contents !== 'object') {
188
155
  throw new Error('PostCSS config should be an object.');
189
156
  }
190
-
191
157
  if (contents.plugins == null || typeof contents.plugins !== 'object' || Object.keys(contents.plugins).length === 0) {
192
158
  throw new Error('PostCSS config must have plugins');
193
159
  }
194
160
  }
195
-
196
161
  return configHydrator(contents, config, configFile === null || configFile === void 0 ? void 0 : configFile.filePath, options, logger);
197
162
  }
@@ -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.8.4-nightly.0+7b79c6d",
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.8.4-nightly.0+7b79c6d"
20
+ "parcel": "^2.9.0"
21
21
  },
22
22
  "dependencies": {
23
- "@parcel/diagnostic": "2.8.4-nightly.0+7b79c6d",
24
- "@parcel/hash": "2.8.4-nightly.0+7b79c6d",
25
- "@parcel/plugin": "2.8.4-nightly.0+7b79c6d",
26
- "@parcel/utils": "2.8.4-nightly.0+7b79c6d",
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": "7b79c6d69ffabef89810a8db61e9abdeb70d6990"
36
+ "gitHead": "dd9435be8afed35c5ffc161cf4b586fd6c78fc1f"
37
37
  }