summaryrefslogtreecommitdiff
path: root/node_modules/tailwindcss/src/lib/findAtConfigPath.js
diff options
context:
space:
mode:
authorPhilipp Tanlak <philipp.tanlak@gmail.com>2025-11-24 20:54:57 +0100
committerPhilipp Tanlak <philipp.tanlak@gmail.com>2025-11-24 20:57:48 +0100
commitb1e2c8fd5cb5dfa46bc440a12eafaf56cd844b1c (patch)
tree49d360fd6cbc6a2754efe93524ac47ff0fbe0f7d /node_modules/tailwindcss/src/lib/findAtConfigPath.js
Docs
Diffstat (limited to 'node_modules/tailwindcss/src/lib/findAtConfigPath.js')
-rw-r--r--node_modules/tailwindcss/src/lib/findAtConfigPath.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/node_modules/tailwindcss/src/lib/findAtConfigPath.js b/node_modules/tailwindcss/src/lib/findAtConfigPath.js
new file mode 100644
index 0000000..ac0adab
--- /dev/null
+++ b/node_modules/tailwindcss/src/lib/findAtConfigPath.js
@@ -0,0 +1,48 @@
+import fs from 'fs'
+import path from 'path'
+
+/**
+ * Find the @config at-rule in the given CSS AST and return the relative path to the config file
+ *
+ * @param {import('postcss').Root} root
+ * @param {import('postcss').Result} result
+ */
+export function findAtConfigPath(root, result) {
+ let configPath = null
+ let relativeTo = null
+
+ root.walkAtRules('config', (rule) => {
+ relativeTo = rule.source?.input.file ?? result.opts.from ?? null
+
+ if (relativeTo === null) {
+ throw rule.error(
+ 'The `@config` directive cannot be used without setting `from` in your PostCSS config.'
+ )
+ }
+
+ if (configPath) {
+ throw rule.error('Only one `@config` directive is allowed per file.')
+ }
+
+ let matches = rule.params.match(/(['"])(.*?)\1/)
+ if (!matches) {
+ throw rule.error('A path is required when using the `@config` directive.')
+ }
+
+ let inputPath = matches[2]
+ if (path.isAbsolute(inputPath)) {
+ throw rule.error('The `@config` directive cannot be used with an absolute path.')
+ }
+
+ configPath = path.resolve(path.dirname(relativeTo), inputPath)
+ if (!fs.existsSync(configPath)) {
+ throw rule.error(
+ `The config file at "${inputPath}" does not exist. Make sure the path is correct and the file exists.`
+ )
+ }
+
+ rule.remove()
+ })
+
+ return configPath ? configPath : null
+}