MCPcopy
hub / github.com/tailwindlabs/tailwindcss / Once

Function Once

packages/@tailwindcss-postcss/src/index.ts:86–359  ·  view source on GitHub ↗
(root, { result, postcss })

Source from the content-addressed store, hash-verified

84 {
85 postcssPlugin: 'tailwindcss',
86 async Once(root, { result, postcss }) {
87 using I = new Instrumentation()
88
89 let inputFile = result.opts.from ?? ''
90 let isCSSModuleFile = inputFile.endsWith('.module.css')
91
92 DEBUG && I.start(`[@tailwindcss/postcss] ${relative(base, inputFile)}`)
93
94 // Bail out early if this is guaranteed to be a non-Tailwind CSS file.
95 {
96 DEBUG && I.start('Quick bail check')
97 let canBail = true
98 root.walkAtRules((node) => {
99 if (
100 node.name === 'import' ||
101 node.name === 'reference' ||
102 node.name === 'theme' ||
103 node.name === 'variant' ||
104 node.name === 'config' ||
105 node.name === 'plugin' ||
106 node.name === 'apply' ||
107 node.name === 'tailwind'
108 ) {
109 canBail = false
110 return false
111 }
112 })
113 if (canBail) return
114 DEBUG && I.end('Quick bail check')
115 }
116
117 let context = getContextFromCache(postcss, inputFile, opts)
118 let inputBasePath = inputFile ? path.dirname(path.resolve(inputFile)) : base
119
120 // Whether this is the first build or not, if it is, then we can
121 // optimize the build by not creating the compiler until we need it.
122 let isInitialBuild = context.compiler === null
123
124 async function createCompiler() {
125 DEBUG && I.start('Setup compiler')
126 if (context.fullRebuildPaths.length > 0 && !isInitialBuild) {
127 clearRequireCache(context.fullRebuildPaths)
128 }
129
130 context.fullRebuildPaths = []
131
132 DEBUG && I.start('PostCSS AST -> Tailwind CSS AST')
133 let ast = postCssAstToCssAst(root)
134 DEBUG && I.end('PostCSS AST -> Tailwind CSS AST')
135
136 DEBUG && I.start('Create compiler')
137 let compiler = await compileAst(ast, {
138 from: result.opts.from,
139 base: inputBasePath,
140 shouldRewriteUrls,
141 onDependency: (path) => context.fullRebuildPaths.push(path),
142 // In CSS Module files, we have to disable the `@property` polyfill since these will
143 // emit global `*` rules which are considered to be non-pure and will cause builds

Callers

nothing calls this directly

Calls 11

toCssFunction · 0.90
cssAstToPostCssAstFunction · 0.90
resolveMethod · 0.80
setMethod · 0.80
errorMethod · 0.80
getContextFromCacheFunction · 0.70
createCompilerFunction · 0.70
relativeFunction · 0.50
startMethod · 0.45
endMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected