index.ts — tailwindcss Source File
Architecture documentation for index.ts, a typescript file in the tailwindcss codebase. 3 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR db071d11_4cec_4513_1261_677ffd86ce6e["index.ts"] 92f2d961_72a4_d195_92d7_2e66972f8894["node"] db071d11_4cec_4513_1261_677ffd86ce6e --> 92f2d961_72a4_d195_92d7_2e66972f8894 2a7660a5_3e09_bd74_37f0_e4e54bc64ce5["node:path"] db071d11_4cec_4513_1261_677ffd86ce6e --> 2a7660a5_3e09_bd74_37f0_e4e54bc64ce5 ba54c7c3_7b1e_9984_bfef_a693a3df2d84["postcss"] db071d11_4cec_4513_1261_677ffd86ce6e --> ba54c7c3_7b1e_9984_bfef_a693a3df2d84 4d87ade3_79e3_f749_8b40_7a0e8f43b9dc["index.ts"] 4d87ade3_79e3_f749_8b40_7a0e8f43b9dc --> db071d11_4cec_4513_1261_677ffd86ce6e style db071d11_4cec_4513_1261_677ffd86ce6e fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import { normalizePath } from '@tailwindcss/node'
import path from 'node:path'
import type { AtRule, Plugin } from 'postcss'
const SINGLE_QUOTE = "'"
const DOUBLE_QUOTE = '"'
export default function fixRelativePathsPlugin(): Plugin {
// Retain a list of touched at-rules to avoid infinite loops
let touched: WeakSet<AtRule> = new WeakSet()
function fixRelativePath(atRule: AtRule) {
let rootPath = atRule.root().source?.input.file
if (!rootPath) {
return
}
let inputFilePath = atRule.source?.input.file
if (!inputFilePath) {
return
}
if (touched.has(atRule)) {
return
}
let value = atRule.params[0]
let quote =
value[0] === DOUBLE_QUOTE && value[value.length - 1] === DOUBLE_QUOTE
? DOUBLE_QUOTE
: value[0] === SINGLE_QUOTE && value[value.length - 1] === SINGLE_QUOTE
? SINGLE_QUOTE
: null
if (!quote) {
return
}
let glob = atRule.params.slice(1, -1)
// Handle eventual negative rules. We only support one level of negation.
let negativePrefix = ''
if (glob.startsWith('!')) {
glob = glob.slice(1)
negativePrefix = '!'
}
// We only want to rewrite relative paths.
if (!glob.startsWith('./') && !glob.startsWith('../')) {
return
}
let absoluteGlob = path.posix.join(normalizePath(path.dirname(inputFilePath)), glob)
let absoluteRootPosixPath = path.posix.dirname(normalizePath(rootPath))
let relative = path.posix.relative(absoluteRootPosixPath, absoluteGlob)
// If the path points to a file in the same directory, `path.relative` will
// remove the leading `./` and we need to add it back in order to still
// consider the path relative
if (!relative.startsWith('.')) {
relative = './' + relative
}
atRule.params = quote + negativePrefix + relative + quote
touched.add(atRule)
}
return {
postcssPlugin: 'tailwindcss-postcss-fix-relative-paths',
Once(root) {
root.walkAtRules(/source|plugin|config/, fixRelativePath)
},
}
}
Domain
Subdomains
Functions
Dependencies
- node
- node:path
- postcss
Imported By
Source
Frequently Asked Questions
What does index.ts do?
index.ts is a source file in the tailwindcss codebase, written in typescript. It belongs to the BuildIntegrations domain, PostCSSPlugin subdomain.
What functions are defined in index.ts?
index.ts defines 1 function(s): fixRelativePathsPlugin.
What does index.ts depend on?
index.ts imports 3 module(s): node, node:path, postcss.
What files import index.ts?
index.ts is imported by 1 file(s): index.ts.
Where is index.ts in the architecture?
index.ts is located at packages/@tailwindcss-postcss/src/postcss-fix-relative-paths/index.ts (domain: BuildIntegrations, subdomain: PostCSSPlugin, directory: packages/@tailwindcss-postcss/src/postcss-fix-relative-paths).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free