|
| 1 | +"use strict"; |
| 2 | +Object.defineProperty(exports, "__esModule", { |
| 3 | + value: true |
| 4 | +}); |
| 5 | +const _setupTrackingContext = /*#__PURE__*/ _interop_require_default(require("./lib/setupTrackingContext")); |
| 6 | +const _processTailwindFeatures = /*#__PURE__*/ _interop_require_default(require("./processTailwindFeatures")); |
| 7 | +const _sharedState = require("./lib/sharedState"); |
| 8 | +const _findAtConfigPath = require("./lib/findAtConfigPath"); |
| 9 | +function _interop_require_default(obj) { |
| 10 | + return obj && obj.__esModule ? obj : { |
| 11 | + default: obj |
| 12 | + }; |
| 13 | +} |
| 14 | +module.exports = function tailwindcss(configOrPath) { |
| 15 | + return { |
| 16 | + postcssPlugin: "tailwindcss", |
| 17 | + plugins: [ |
| 18 | + _sharedState.env.DEBUG && function(root) { |
| 19 | + console.log("\n"); |
| 20 | + console.time("JIT TOTAL"); |
| 21 | + return root; |
| 22 | + }, |
| 23 | + async function(root, result) { |
| 24 | + var _findAtConfigPath1; |
| 25 | + // Use the path for the `@config` directive if it exists, otherwise use the |
| 26 | + // path for the file being processed |
| 27 | + configOrPath = (_findAtConfigPath1 = (0, _findAtConfigPath.findAtConfigPath)(root, result)) !== null && _findAtConfigPath1 !== void 0 ? _findAtConfigPath1 : configOrPath; |
| 28 | + let context = (0, _setupTrackingContext.default)(configOrPath); |
| 29 | + if (root.type === "document") { |
| 30 | + let roots = root.nodes.filter((node)=>node.type === "root"); |
| 31 | + for (const root of roots){ |
| 32 | + if (root.type === "root") { |
| 33 | + await (0, _processTailwindFeatures.default)(context)(root, result); |
| 34 | + } |
| 35 | + } |
| 36 | + return; |
| 37 | + } |
| 38 | + await (0, _processTailwindFeatures.default)(context)(root, result); |
| 39 | + }, |
| 40 | + false && function lightningCssPlugin(_root, result) { |
| 41 | + let postcss = require("postcss"); |
| 42 | + let lightningcss = require("lightningcss"); |
| 43 | + let browserslist = require("browserslist"); |
| 44 | + try { |
| 45 | + let transformed = lightningcss.transform({ |
| 46 | + filename: result.opts.from, |
| 47 | + code: Buffer.from(result.root.toString()), |
| 48 | + minify: false, |
| 49 | + sourceMap: !!result.map, |
| 50 | + inputSourceMap: result.map ? result.map.toString() : undefined, |
| 51 | + targets: typeof process !== "undefined" && process.env.JEST_WORKER_ID ? { |
| 52 | + chrome: 106 << 16 |
| 53 | + } : lightningcss.browserslistToTargets(browserslist(require("../package.json").browserslist)), |
| 54 | + drafts: { |
| 55 | + nesting: true, |
| 56 | + customMedia: true |
| 57 | + } |
| 58 | + }); |
| 59 | + var _result_map; |
| 60 | + result.map = Object.assign((_result_map = result.map) !== null && _result_map !== void 0 ? _result_map : {}, { |
| 61 | + toJSON () { |
| 62 | + return transformed.map.toJSON(); |
| 63 | + }, |
| 64 | + toString () { |
| 65 | + return transformed.map.toString(); |
| 66 | + } |
| 67 | + }); |
| 68 | + result.root = postcss.parse(transformed.code.toString("utf8")); |
| 69 | + } catch (err) { |
| 70 | + if (typeof process !== "undefined" && process.env.JEST_WORKER_ID) { |
| 71 | + let lines = err.source.split("\n"); |
| 72 | + err = new Error([ |
| 73 | + "Error formatting using Lightning CSS:", |
| 74 | + "", |
| 75 | + ...[ |
| 76 | + "```css", |
| 77 | + ...lines.slice(Math.max(err.loc.line - 3, 0), err.loc.line), |
| 78 | + " ".repeat(err.loc.column - 1) + "^-- " + err.toString(), |
| 79 | + ...lines.slice(err.loc.line, err.loc.line + 2), |
| 80 | + "```" |
| 81 | + ] |
| 82 | + ].join("\n")); |
| 83 | + } |
| 84 | + if (Error.captureStackTrace) { |
| 85 | + Error.captureStackTrace(err, lightningCssPlugin); |
| 86 | + } |
| 87 | + throw err; |
| 88 | + } |
| 89 | + }, |
| 90 | + _sharedState.env.DEBUG && function(root) { |
| 91 | + console.timeEnd("JIT TOTAL"); |
| 92 | + console.log("\n"); |
| 93 | + return root; |
| 94 | + } |
| 95 | + ].filter(Boolean) |
| 96 | + }; |
| 97 | +}; |
| 98 | +module.exports.postcss = true; |
0 commit comments