From 06823fbf1c2e763a5bf76c3990ca98fbbcd98691 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Tue, 14 May 2024 14:05:49 +0800 Subject: updated node_modules --- node_modules/stylehacks/src/index.js | 63 +++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 26 deletions(-) (limited to 'node_modules/stylehacks/src') 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} BrowserslistOptions + * @typedef {{lint?: boolean} & AutoprefixerOptions & BrowserslistOptions} Options + */ /** * @type {import('postcss').PluginCreator} @@ -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); + }); + }); + }, + }; }, }; } -- cgit v1.2.3