summaryrefslogtreecommitdiff
path: root/node_modules/stylehacks/src
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2024-05-14 14:05:49 +0800
committerlittleblack111 <littleblack11111@gmail.com>2024-05-14 14:05:49 +0800
commit06823fbf1c2e763a5bf76c3990ca98fbbcd98691 (patch)
tree4280bece3888d12a022093bf1a9cd1b049393602 /node_modules/stylehacks/src
parent1368909b3cd552dbb0d12d5863c597f5be46177d (diff)
updated node_modules
Diffstat (limited to 'node_modules/stylehacks/src')
-rw-r--r--node_modules/stylehacks/src/index.js63
1 files changed, 37 insertions, 26 deletions
diff --git a/node_modules/stylehacks/src/index.js b/node_modules/stylehacks/src/index.js
index 6b8ce94c..378a61f6 100644
--- a/node_modules/stylehacks/src/index.js
+++ b/node_modules/stylehacks/src/index.js
@@ -1,8 +1,13 @@
'use strict';
+const { dirname } = require('path');
const browserslist = require('browserslist');
const plugins = require('./plugins');
-/** @typedef {{lint?: boolean}} Options */
+/**
+ * @typedef {{ overrideBrowserslist?: string | string[] }} AutoprefixerOptions
+ * @typedef {Pick<browserslist.Options, 'stats' | 'path' | 'env'>} BrowserslistOptions
+ * @typedef {{lint?: boolean} & AutoprefixerOptions & BrowserslistOptions} Options
+ */
/**
* @type {import('postcss').PluginCreator<Options>}
@@ -13,36 +18,42 @@ function pluginCreator(opts = {}) {
return {
postcssPlugin: 'stylehacks',
- OnceExit(css, { result }) {
- /** @type {typeof result.opts & browserslist.Options} */
- const resultOpts = result.opts || {};
- const browsers = browserslist(null, {
- stats: resultOpts.stats,
- path: __dirname,
- env: resultOpts.env,
+ /**
+ * @param {import('postcss').Result & {opts: BrowserslistOptions & {file?: string}}} result
+ */
+ prepare(result) {
+ const { stats, env, from, file } = result.opts || {};
+ const browsers = browserslist(opts.overrideBrowserslist, {
+ stats: opts.stats || stats,
+ path: opts.path || dirname(from || file || __filename),
+ env: opts.env || env,
});
- /** @type {import('./plugin').Plugin[]} */
- const processors = [];
- for (const Plugin of plugins) {
- const hack = new Plugin(result);
- if (!browsers.some((browser) => hack.targets.has(browser))) {
- processors.push(hack);
- }
- }
- css.walk((node) => {
- processors.forEach((proc) => {
- if (!proc.nodeTypes.has(node.type)) {
- return;
+ return {
+ OnceExit(css) {
+ /** @type {import('./plugin').Plugin[]} */
+ const processors = [];
+ for (const Plugin of plugins) {
+ const hack = new Plugin(result);
+ if (!browsers.some((browser) => hack.targets.has(browser))) {
+ processors.push(hack);
+ }
}
+ css.walk((node) => {
+ processors.forEach((proc) => {
+ if (!proc.nodeTypes.has(node.type)) {
+ return;
+ }
- if (opts.lint) {
- return proc.detectAndWarn(node);
- }
+ if (opts.lint) {
+ return proc.detectAndWarn(node);
+ }
- return proc.detectAndResolve(node);
- });
- });
+ return proc.detectAndResolve(node);
+ });
+ });
+ },
+ };
},
};
}