next-yak 8.0.1 → 8.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../loaders/webpack-loader.ts","../../loaders/lib/debugLogger.ts","../../loaders/lib/extractCss.ts","../../loaders/lib/resolveCrossFileSelectors.ts","../../cross-file-resolver/parseModule.ts","../../cross-file-resolver/Errors.ts","../../cross-file-resolver/resolveCrossFileConstant.ts"],"sourcesContent":["import type { LoaderContext } from \"webpack\";\nimport type { YakConfigOptions } from \"../withYak/index.js\";\nimport { createDebugLogger } from \"./lib/debugLogger.js\";\nimport { extractCss } from \"./lib/extractCss.js\";\nimport { resolveCrossFileConstant } from \"./lib/resolveCrossFileSelectors.js\";\n\n/**\n * Transform typescript to css\n *\n * This loader takes the cached result from the yak tsloader\n * and extracts the css from the generated comments\n */\nexport default async function cssExtractLoader(\n this: LoaderContext<YakConfigOptions>,\n // Instead of the source code, we receive the extracted css\n // from the yak-swc transformation\n _code: string,\n sourceMap: string | undefined,\n): Promise<string | void> {\n const callback = this.async();\n // Load the module from the original typescript request (without !=! and the query)\n return this.loadModule(this.resourcePath, (err, source) => {\n if (err) {\n return callback(err);\n }\n if (!source) {\n return callback(\n new Error(`Source code for ${this.resourcePath} is empty`),\n );\n }\n const { experiments } = this.getOptions();\n const debugLog = createDebugLogger(this, experiments?.debug);\n\n debugLog(\"ts\", source);\n const css = extractCss(source, experiments?.transpilationMode);\n debugLog(\"css\", css);\n\n return resolveCrossFileConstant(this, this.context, css).then((result) => {\n debugLog(\"css-resolved\", css);\n return callback(null, result, sourceMap);\n }, callback);\n });\n}\n","import { relative } from \"path\";\nimport type { LoaderContext } from \"webpack\";\nimport type { YakConfigOptions } from \"../../withYak/index.js\";\n\n/**\n * Creates a debug logger function that conditionally logs messages\n * based on debug options and file paths.\n */\nexport function createDebugLogger(\n loaderContext: LoaderContext<unknown>,\n debugOptions: Required<YakConfigOptions>[\"experiments\"][\"debug\"],\n) {\n if (!debugOptions) {\n return () => {};\n }\n const currentPath = loaderContext._compiler\n ? relative(loaderContext._compiler.context, loaderContext.resourcePath)\n : loaderContext.resourcePath;\n return (\n messageType: \"ts\" | \"css\" | \"css-resolved\",\n message: string | Buffer<ArrayBufferLike> | undefined,\n ) => {\n // the path contains already the extension for the ts{x} file\n const pathWithExtension =\n messageType !== \"ts\" ? currentPath + `.${messageType}` : currentPath;\n if (\n debugOptions === true ||\n new RegExp(debugOptions).test(pathWithExtension)\n ) {\n console.log(\"🐮 Yak\", pathWithExtension, \"\\n\\n\", message);\n }\n };\n}\n","import { YakConfigOptions } from \"../../withYak/index.js\";\n\n/**\n * Extracts CSS content from code that contains YAK-generated CSS comments.\n * Parses the input code and returns the extracted CSS, optionally adding\n * a cssmodules directive based on the transpilation mode.\n */\nexport function extractCss(\n code: string | Buffer<ArrayBufferLike>,\n transpilationMode: NonNullable<\n YakConfigOptions[\"experiments\"]\n >[\"transpilationMode\"],\n): string {\n let codeString: string;\n\n if (typeof code === \"string\") {\n codeString = code;\n } else if (code instanceof Buffer) {\n codeString = code.toString(\"utf-8\");\n } else if (code instanceof ArrayBuffer) {\n codeString = new TextDecoder(\"utf-8\").decode(code);\n } else {\n throw new Error(\n \"Invalid input type: code must be string, Buffer, or ArrayBuffer\",\n );\n }\n\n const codeParts = codeString.split(\"/*YAK Extracted CSS:\\n\");\n let result = \"\";\n for (let i = 1; i < codeParts.length; i++) {\n const codeUntilEnd = codeParts[i].split(\"*/\")[0];\n result += codeUntilEnd;\n }\n if (result && transpilationMode !== \"Css\") {\n result = \"/* cssmodules-pure-no-check */\\n\" + result;\n }\n\n return result;\n}\n","import { parse } from \"@babel/parser\";\nimport traverse from \"@babel/traverse\";\nimport type { Compilation, LoaderContext } from \"webpack\";\nimport {\n ModuleExport,\n ModuleExports,\n ParseContext,\n ParsedModule,\n parseModule,\n} from \"../../cross-file-resolver/parseModule.js\";\nimport {\n ResolveContext,\n resolveCrossFileConstant as genericResolveCrossFileConstant,\n} from \"../../cross-file-resolver/resolveCrossFileConstant.js\";\nimport { YakConfigOptions } from \"../../withYak/index.js\";\n\nconst compilationCache = new WeakMap<\n Compilation,\n {\n parsedFiles: Map<string, ParsedModule>;\n }\n>();\n\nexport async function resolveCrossFileConstant(\n loader: LoaderContext<{}>,\n pathContext: string,\n css: string,\n): Promise<string> {\n const { resolved } = await genericResolveCrossFileConstant(\n getResolveContext(loader),\n loader.resourcePath,\n css,\n );\n return resolved;\n}\n\nfunction getCompilationCache(loader: LoaderContext<YakConfigOptions>) {\n const compilation = loader._compilation;\n if (!compilation) {\n throw new Error(\"Webpack compilation object not available\");\n }\n let cache = compilationCache.get(compilation);\n if (!cache) {\n cache = {\n parsedFiles: new Map(),\n };\n compilationCache.set(compilation, cache);\n }\n return cache;\n}\n\nfunction getParseContext(\n loader: LoaderContext<YakConfigOptions>,\n): ParseContext {\n return {\n cache: { parse: getCompilationCache(loader).parsedFiles },\n async extractExports(modulePath) {\n const sourceContents = new Promise<string>((resolve, reject) =>\n loader.fs.readFile(modulePath, \"utf-8\", (err, result) => {\n if (err) return reject(err);\n resolve(result || \"\");\n }),\n );\n return parseExports(await sourceContents);\n },\n async getTransformed(modulePath) {\n const transformedSource = new Promise<string>((resolve, reject) => {\n loader.loadModule(modulePath, (err, source) => {\n if (err) return reject(err);\n let sourceString: string;\n if (typeof source === \"string\") {\n sourceString = source;\n } else if (source instanceof Buffer) {\n sourceString = source.toString(\"utf-8\");\n } else if (source instanceof ArrayBuffer) {\n sourceString = new TextDecoder(\"utf-8\").decode(source);\n } else {\n throw new Error(\n \"Invalid input type: code must be string, Buffer, or ArrayBuffer\",\n );\n }\n resolve(sourceString || \"\");\n });\n });\n return { code: await transformedSource };\n },\n async evaluateYakModule(modulePath) {\n return loader.importModule(modulePath);\n },\n transpilationMode: loader.getOptions().experiments?.transpilationMode,\n };\n}\n\nfunction getResolveContext(\n loader: LoaderContext<YakConfigOptions>,\n): ResolveContext {\n const parseContext = getParseContext(loader);\n return {\n parse: (modulePath) => parseModule(parseContext, modulePath),\n resolve: async (specifier, importer) => {\n return resolveModule(loader, specifier, dirname(importer));\n },\n };\n}\n\n/**\n * Resolves a module by wrapping loader.resolve in a promise\n */\nexport async function resolveModule(\n loader: LoaderContext<{}>,\n moduleSpecifier: string,\n context: string,\n): Promise<string> {\n return new Promise<string>((resolve, reject) => {\n loader.resolve(context, moduleSpecifier, (err, result) => {\n if (err) return reject(err);\n if (!result)\n return reject(new Error(`Could not resolve ${moduleSpecifier}`));\n resolve(result);\n });\n });\n}\n\nexport async function parseExports(\n sourceContents: string,\n): Promise<ModuleExports> {\n const moduleExports: ModuleExports = {\n importYak: true,\n named: {},\n all: [],\n };\n\n // Track variable declarations for lookup\n const variableDeclarations: Record<string, babel.types.Expression> = {};\n\n // Track default export identifier if present\n let defaultIdentifier: string | null = null;\n\n try {\n const ast = parse(sourceContents, {\n sourceType: \"module\",\n plugins: [\"jsx\", \"typescript\"] as const,\n });\n\n traverse.default(ast, {\n // Track all variable declarations in the file\n VariableDeclarator({ node }) {\n if (node.id.type === \"Identifier\" && node.init) {\n variableDeclarations[node.id.name] = node.init;\n }\n },\n\n ExportNamedDeclaration({ node }) {\n if (node.source) {\n node.specifiers.forEach((specifier) => {\n if (\n specifier.type === \"ExportSpecifier\" &&\n specifier.exported.type === \"Identifier\" &&\n specifier.local.type === \"Identifier\"\n ) {\n moduleExports.named[specifier.exported.name] = {\n type: \"re-export\",\n from: node.source!.value,\n name: specifier.local.name,\n };\n }\n });\n } else if (node.declaration?.type === \"VariableDeclaration\") {\n node.declaration.declarations.forEach((declaration) => {\n if (declaration.id.type === \"Identifier\" && declaration.init) {\n const parsed = parseExportValueExpression(declaration.init);\n if (parsed) {\n moduleExports.named[declaration.id.name] = parsed;\n }\n }\n });\n }\n },\n ExportDeclaration({ node }) {\n if (\"specifiers\" in node && node.source) {\n const { specifiers, source } = node;\n specifiers.forEach((specifier) => {\n // export * as color from \"./colors\";\n if (\n specifier.type === \"ExportNamespaceSpecifier\" &&\n specifier.exported.type === \"Identifier\"\n ) {\n moduleExports.named[specifier.exported.name] = {\n type: \"namespace-re-export\",\n from: source.value,\n };\n }\n });\n }\n },\n ExportDefaultDeclaration({ node }) {\n if (node.declaration.type === \"Identifier\") {\n // e.g. export default variableName;\n // Save the identifier name to look up later\n defaultIdentifier = node.declaration.name;\n } else if (\n node.declaration.type === \"FunctionDeclaration\" ||\n node.declaration.type === \"ClassDeclaration\"\n ) {\n // e.g. export default function() {...} or export default class {...}\n moduleExports.named[\"default\"] = {\n type: \"unsupported\",\n hint: node.declaration.type,\n };\n } else {\n // e.g. export default { ... } or export default \"value\"\n moduleExports.named[\"default\"] = parseExportValueExpression(\n node.declaration as babel.types.Expression,\n );\n }\n },\n ExportAllDeclaration({ node }) {\n moduleExports.all.push(node.source.value);\n },\n });\n // If we found a default export that's an identifier, look up its value\n if (defaultIdentifier && variableDeclarations[defaultIdentifier]) {\n moduleExports.named[\"default\"] = parseExportValueExpression(\n variableDeclarations[defaultIdentifier],\n );\n }\n\n return moduleExports;\n } catch (error) {\n throw new Error(`Error parsing exports: ${(error as Error).message}`);\n }\n}\n\n/**\n * Unpacks a TSAsExpression to its expression value\n */\nfunction unpackTSAsExpression(\n node: babel.types.TSAsExpression | babel.types.Expression,\n): babel.types.Expression {\n if (node.type === \"TSAsExpression\") {\n return unpackTSAsExpression(node.expression);\n }\n return node;\n}\n\nfunction parseExportValueExpression(\n node: babel.types.Expression,\n): ModuleExport {\n // ignores `as` casts so it doesn't interfere with the ast node type detection\n const expression = unpackTSAsExpression(node);\n if (\n expression.type === \"CallExpression\" ||\n expression.type === \"TaggedTemplateExpression\"\n ) {\n return { type: \"tag-template\" };\n } else if (\n expression.type === \"StringLiteral\" ||\n expression.type === \"NumericLiteral\"\n ) {\n return { type: \"constant\", value: expression.value };\n } else if (\n expression.type === \"UnaryExpression\" &&\n expression.operator === \"-\" &&\n expression.argument.type === \"NumericLiteral\"\n ) {\n return { type: \"constant\", value: -expression.argument.value };\n } else if (\n expression.type === \"TemplateLiteral\" &&\n expression.quasis.length === 1\n ) {\n return { type: \"constant\", value: expression.quasis[0].value.raw };\n } else if (expression.type === \"ObjectExpression\") {\n return { type: \"record\", value: parseObjectExpression(expression) };\n }\n return { type: \"unsupported\", hint: expression.type };\n}\n\nfunction parseObjectExpression(\n node: babel.types.ObjectExpression,\n): Record<string, ModuleExport> {\n let result: Record<string, ModuleExport> = {};\n for (const property of node.properties) {\n if (\n property.type === \"ObjectProperty\" &&\n property.key.type === \"Identifier\"\n ) {\n const key = property.key.name;\n const parsed = parseExportValueExpression(\n property.value as babel.types.Expression,\n );\n if (parsed) {\n result[key] = parsed;\n }\n }\n }\n return result;\n}\n\nconst DIRNAME_POSIX_REGEX =\n /^((?:\\.(?![^\\/]))|(?:(?:\\/?|)(?:[\\s\\S]*?)))(?:\\/+?|)(?:(?:\\.{1,2}|[^\\/]+?|)(?:\\.[^.\\/]*|))(?:[\\/]*)$/;\nconst DIRNAME_WIN32_REGEX =\n /^((?:\\.(?![^\\\\]))|(?:(?:\\\\?|)(?:[\\s\\S]*?)))(?:\\\\+?|)(?:(?:\\.{1,2}|[^\\\\]+?|)(?:\\.[^.\\\\]*|))(?:[\\\\]*)$/;\n\n/**\n * Polyfill for `node:path` method dirname.\n * Keeps yak independent from node api (therefore executable in browser)\n */\nfunction dirname(path: string) {\n let dirname = DIRNAME_POSIX_REGEX.exec(path)?.[1];\n\n if (!dirname) {\n dirname = DIRNAME_WIN32_REGEX.exec(path)?.[1];\n }\n\n if (!dirname) {\n throw new Error(`Can't extract dirname from ${path}`);\n }\n\n return dirname;\n}\n","import { type Cache } from \"./types.js\";\n\nexport async function parseModule(\n context: ParseContext,\n modulePath: string,\n): Promise<ParsedModule> {\n try {\n const isYak =\n modulePath.endsWith(\".yak.ts\") ||\n modulePath.endsWith(\".yak.tsx\") ||\n modulePath.endsWith(\".yak.js\") ||\n modulePath.endsWith(\".yak.jsx\");\n\n // handle yak file by evaluating and mapping exported value to the\n // `ModuleExport` format. This operation is not cached to always get a fresh\n // value from those modules\n if (isYak && context.evaluateYakModule) {\n const yakModule = await context.evaluateYakModule(modulePath);\n const yakExports = objectToModuleExport(yakModule);\n\n return {\n type: \"yak\",\n exports: { importYak: false, named: yakExports, all: [] },\n path: modulePath,\n };\n }\n\n if (context.cache?.parse === undefined) {\n return uncachedParseModule(context, modulePath);\n }\n\n const cached = context.cache.parse.get(modulePath);\n if (cached === undefined) {\n // We cache the parsed file to avoid re-parsing it.\n // It's ok, that initial parallel requests to the same file will parse it multiple times.\n // This avoid deadlocks do to the fact that we load multiple modules in the chain for cross file references.\n const parsedModule = await uncachedParseModule(context, modulePath);\n\n context.cache.parse.set(modulePath, parsedModule);\n if (context.cache.parse.addDependency) {\n context.cache.parse.addDependency(modulePath, modulePath);\n }\n return parsedModule;\n }\n\n return cached;\n } catch (error) {\n throw new Error(\n `Error parsing file ${modulePath}: ${(error as Error).message}`,\n );\n }\n}\n\nexport async function uncachedParseModule(\n context: ParseContext,\n modulePath: string,\n): Promise<ParsedModule> {\n const exports = await context.extractExports(modulePath);\n\n // early exit if no yak import was found\n if (!exports.importYak) {\n return {\n type: \"regular\",\n path: modulePath,\n exports,\n };\n }\n\n const transformed = await context.getTransformed(modulePath);\n const mixins = parseMixins(transformed.code);\n const styledComponents = parseStyledComponents(\n transformed.code,\n context.transpilationMode,\n );\n\n return {\n type: \"regular\",\n path: modulePath,\n js: transformed,\n exports,\n styledComponents,\n mixins,\n };\n}\n\nfunction parseMixins(sourceContents: string): Record<string, Mixin> {\n // Mixins are always in the following format:\n // /*YAK EXPORTED MIXIN:fancy:aspectRatio:16:9\n // css\n // */\n const mixinParts = sourceContents.split(\"/*YAK EXPORTED MIXIN:\");\n let mixins: Record<\n string,\n { type: \"mixin\"; value: string; nameParts: string[] }\n > = {};\n\n for (let i = 1; i < mixinParts.length; i++) {\n const [comment] = mixinParts[i].split(\"*/\", 1);\n const position = comment.indexOf(\"\\n\");\n const name = comment.slice(0, position);\n const value = comment.slice(position + 1);\n mixins[name] = {\n type: \"mixin\",\n value,\n nameParts: name.split(\":\").map((part) => decodeURIComponent(part)),\n };\n }\n return mixins;\n}\n\nfunction parseStyledComponents(\n sourceContents: string,\n transpilationMode?: \"Css\" | \"CssModule\",\n): Record<string, StyledComponent> {\n // cross-file Styled Components are always in the following format:\n // /*YAK EXPORTED STYLED:ComponentName:ClassName*/\n const styledParts = sourceContents.split(\"/*YAK EXPORTED STYLED:\");\n let styledComponents: Record<string, StyledComponent> = {};\n\n for (let i = 1; i < styledParts.length; i++) {\n const [comment] = styledParts[i].split(\"*/\", 1);\n const [componentName, className] = comment.split(\":\");\n styledComponents[componentName] = {\n type: \"styled-component\",\n nameParts: componentName.split(\".\"),\n value:\n transpilationMode === \"Css\"\n ? `.${className}`\n : `:global(.${className})`,\n };\n }\n\n return styledComponents;\n}\n\nfunction objectToModuleExport(object: object) {\n return Object.fromEntries(\n Object.entries(object).map(([key, value]): [string, ModuleExport] => {\n if (typeof value === \"string\" || typeof value === \"number\") {\n return [key, { type: \"constant\" as const, value }];\n } else if (value && (typeof value === \"object\" || Array.isArray(value))) {\n return [\n key,\n { type: \"record\" as const, value: objectToModuleExport(value) },\n ];\n } else {\n return [key, { type: \"unsupported\" as const, hint: String(value) }];\n }\n }),\n );\n}\n\nexport type ParseContext = {\n cache?: { parse?: Cache<ParsedModule> };\n transpilationMode?: \"Css\" | \"CssModule\";\n evaluateYakModule?: (\n modulePath: string,\n ) => Promise<Record<string, unknown>> | Record<string, unknown>;\n extractExports: (\n modulePath: string,\n ) => Promise<ModuleExports> | ModuleExports;\n getTransformed: (\n modulePath: string,\n ) => Promise<{ code: string; map?: string }> | { code: string; map?: string };\n};\n\nexport type ModuleExports = {\n importYak: boolean;\n named: Record<string, ModuleExport>;\n all: string[];\n};\n\nexport type ConstantExport = { type: \"constant\"; value: string | number };\nexport type RecordExport = {\n type: \"record\";\n value: Record<string, ModuleExport>;\n};\nexport type UnsupportedExport = { type: \"unsupported\"; hint?: string };\nexport type ReExport = { type: \"re-export\"; name: string; from: string };\nexport type NamespaceReExport = { type: \"namespace-re-export\"; from: string };\nexport type TagTemplateExport = { type: \"tag-template\" };\n\nexport type ModuleExport =\n | ConstantExport\n | TagTemplateExport\n | RecordExport\n | UnsupportedExport\n | ReExport\n | NamespaceReExport;\n\nexport type ParsedModule = {\n path: string;\n exports: ModuleExports;\n} & (\n | {\n type: \"regular\";\n js?: { code: string; map?: string };\n styledComponents?: Record<string, StyledComponent>;\n mixins?: Record<string, Mixin>;\n }\n | {\n type: \"yak\";\n }\n);\n\nexport type StyledComponent = {\n type: \"styled-component\";\n value: string;\n nameParts: string[];\n};\n\nexport type Mixin = { type: \"mixin\"; value: string; nameParts: string[] };\n","export class CauseError extends Error {\n circular?: boolean;\n constructor(message: string, options?: { cause?: unknown }) {\n super(\n `${message}${options?.cause ? `\\n Caused by: ${typeof options.cause === \"object\" && options.cause !== null && \"message\" in options.cause ? options.cause.message : String(options.cause)}` : \"\"}`,\n );\n\n if (options?.cause instanceof CauseError && options.cause.circular) {\n this.circular = true;\n }\n }\n}\n\nexport class ResolveError extends CauseError {}\n\nexport class CircularDependencyError extends CauseError {\n constructor(message: string, options?: { cause?: unknown }) {\n super(message, options);\n this.circular = true;\n }\n}\n","import type {\n ConstantExport,\n ModuleExport,\n ParsedModule,\n RecordExport,\n} from \"./parseModule.js\";\nimport { Cache } from \"./types.js\";\nimport { CauseError, CircularDependencyError, ResolveError } from \"./Errors.js\";\n\nconst yakCssImportRegex =\n // Make mixin and selector non optional once we dropped support for the babel plugin\n /--yak-css-import\\:\\s*url\\(\"([^\"]+)\",?(|mixin|selector)\\)(;?)/g;\n\n/**\n * Resolves cross-file selectors in css files\n *\n * e.g.:\n * theme.ts:\n * ```ts\n * export const colors = {\n * primary: \"#ff0000\",\n * secondary: \"#00ff00\",\n * };\n * ```\n *\n * styles.ts:\n * ```ts\n * import { colors } from \"./theme\";\n * export const button = css`\n * background-color: ${colors.primary};\n * `;\n */\nexport async function resolveCrossFileConstant(\n context: ResolveContext,\n filePath: string,\n css: string,\n): Promise<{ resolved: string; dependencies: string[] }> {\n const resolveCrossFileConstant = context.cache?.resolveCrossFileConstant;\n if (resolveCrossFileConstant === undefined) {\n return uncachedResolveCrossFileConstant(context, filePath, css);\n }\n\n const cacheKey = await sha1(filePath + \":\" + css);\n\n const cached = resolveCrossFileConstant.get(cacheKey);\n\n if (cached === undefined) {\n const resolvedCrossFilConstantPromise = uncachedResolveCrossFileConstant(\n context,\n filePath,\n css,\n );\n resolveCrossFileConstant.set(cacheKey, resolvedCrossFilConstantPromise);\n\n if (resolveCrossFileConstant.addDependency) {\n resolveCrossFileConstant.addDependency(cacheKey, filePath);\n resolvedCrossFilConstantPromise.then((value) => {\n for (const dep of value.dependencies) {\n resolveCrossFileConstant!.addDependency!(cacheKey, dep);\n }\n });\n }\n\n return resolvedCrossFilConstantPromise;\n }\n\n return cached;\n}\n\nexport async function uncachedResolveCrossFileConstant(\n context: ResolveContext,\n filePath: string,\n css: string,\n): Promise<{ resolved: string; dependencies: string[] }> {\n const yakImports = await parseYakCssImport(context, filePath, css);\n\n if (yakImports.length === 0) {\n return { resolved: css, dependencies: [] };\n }\n\n try {\n const dependencies = new Set<string>();\n\n const resolvedValues = await Promise.all(\n yakImports.map(async ({ moduleSpecifier, specifier }) => {\n const { resolved: resolvedModule } = await resolveModule(\n context,\n moduleSpecifier,\n );\n\n const resolvedValue = await resolveModuleSpecifierRecursively(\n context,\n resolvedModule,\n specifier,\n );\n\n for (const dependency of resolvedValue.from) {\n dependencies.add(dependency);\n }\n\n return resolvedValue;\n }),\n );\n\n // Replace the imports with the resolved values\n let result = css;\n for (let i = yakImports.length - 1; i >= 0; i--) {\n const { position, size, importKind, specifier, semicolon } =\n yakImports[i];\n const resolved = resolvedValues[i];\n\n let replacement: string;\n\n if (resolved.type === \"unresolved-tag\") {\n // tag that could not be resolved to styled-components or mixins are\n // interpolated to produce valid CSS with minimal impact (since we don't\n // know what the value should actually be). For mixins (CSS rules) we\n // interpolate an empty string, and for selectors we interpolate\n // \"undefined\" (a selector that would match nothing)\n replacement = importKind === \"mixin\" ? \"\" : \"undefined\";\n } else {\n if (importKind === \"selector\") {\n if (\n resolved.type !== \"styled-component\" &&\n resolved.type !== \"constant\"\n ) {\n throw new Error(\n `Found \"${\n resolved.type\n }\" but expected a selector - did you forget a semicolon after \"${specifier.join(\n \".\",\n )}\"?`,\n );\n }\n }\n\n replacement =\n resolved.type === \"styled-component\"\n ? resolved.value\n : resolved.value +\n // resolved.value can be of two different types:\n // - mixin:\n // ${mixinName};\n // - constant:\n // color: ${value};\n // For mixins the semicolon is already included in the value\n // but for constants it has to be added manually\n ([\"}\", \";\"].includes(String(resolved.value).trimEnd().slice(-1))\n ? \"\"\n : semicolon);\n }\n\n result =\n result.slice(0, position) +\n String(replacement) +\n result.slice(position + size);\n }\n\n return { resolved: result, dependencies: Array.from(dependencies) };\n } catch (error) {\n throw new CauseError(\n `Error while resolving cross-file selectors in file \"${filePath}\"`,\n { cause: error },\n );\n }\n}\n\n/**\n * Search for --yak-css-import: url(\"path/to/module\") in the css\n */\nasync function parseYakCssImport(\n context: ResolveContext,\n filePath: string,\n css: string,\n): Promise<YakCssImport[]> {\n const yakImports: YakCssImport[] = [];\n\n for (const match of css.matchAll(yakCssImportRegex)) {\n const [fullMatch, encodedArguments, importKind, semicolon] = match;\n const [moduleSpecifier, ...specifier] = encodedArguments\n .split(\":\")\n .map((entry) => decodeURIComponent(entry));\n\n yakImports.push({\n encodedArguments,\n moduleSpecifier: await context.resolve(moduleSpecifier, filePath),\n specifier,\n importKind: importKind as YakImportKind,\n semicolon,\n position: match.index,\n size: fullMatch.length,\n });\n }\n\n return yakImports;\n}\n\nasync function resolveModule(context: ResolveContext, filePath: string) {\n if (context.cache?.resolve === undefined) {\n return uncachedResolveModule(context, filePath);\n }\n\n const cached = context.cache.resolve.get(filePath);\n if (cached === undefined) {\n const resolvedPromise = uncachedResolveModule(context, filePath);\n context.cache.resolve.set(filePath, resolvedPromise);\n\n if (context.cache.resolve.addDependency) {\n context.cache.resolve.addDependency(filePath, filePath);\n resolvedPromise.then((value) => {\n for (const dep of value.dependencies) {\n context.cache!.resolve!.addDependency!(filePath, dep);\n }\n });\n }\n\n return resolvedPromise;\n }\n\n return cached;\n}\n\nasync function uncachedResolveModule(\n context: ResolveContext,\n filePath: string,\n): Promise<{ resolved: ResolvedModule; dependencies: string[] }> {\n const parsedModule = await context.parse(filePath);\n\n const exports = parsedModule.exports as ResolvedExports;\n\n if (parsedModule.type !== \"regular\") {\n return {\n resolved: {\n path: parsedModule.path,\n exports,\n },\n dependencies: [],\n };\n }\n\n const dependencies = new Set<string>();\n\n // Reconcile styled-component \"name\" structure with export structure\n if (parsedModule.styledComponents) {\n Object.values(parsedModule.styledComponents).map((styledComponent) => {\n if (styledComponent.nameParts.length === 1) {\n exports.named[styledComponent.nameParts[0]] = {\n type: \"styled-component\",\n className: styledComponent.value,\n };\n } else {\n let exportEntry = exports.named[styledComponent.nameParts[0]];\n\n if (!exportEntry) {\n exportEntry = { type: \"record\", value: {} };\n exports.named[styledComponent.nameParts[0]] = exportEntry;\n } else if (exportEntry.type !== \"record\") {\n throw new CauseError(`Error parsing file \"${parsedModule.path}\"`, {\n cause: `\"${styledComponent.nameParts[0]}\" is not a record`,\n });\n }\n\n let current = exportEntry.value;\n for (let i = 1; i < styledComponent.nameParts.length - 1; i++) {\n let next = current[styledComponent.nameParts[i]];\n if (!next) {\n next = { type: \"record\", value: {} };\n current[styledComponent.nameParts[i]] = next;\n } else if (next.type !== \"record\") {\n throw new CauseError(`Error parsing file \"${parsedModule.path}\"`, {\n cause: `\"${styledComponent.nameParts.slice(0, i + 1).join(\".\")}\" is not a record`,\n });\n }\n current = next.value;\n }\n current[\n styledComponent.nameParts[styledComponent.nameParts.length - 1]\n ] = {\n type: \"styled-component\",\n className: styledComponent.value,\n };\n }\n });\n }\n\n // Recursively resolve cross-file constants in mixins\n // e.g. cross file mixins inside a cross file mixin\n // or a cross file selector inside a cross file mixin\n if (parsedModule.mixins) {\n await Promise.all(\n Object.values(parsedModule.mixins).map(async (mixin) => {\n const { resolved, dependencies: deps } = await resolveCrossFileConstant(\n context,\n parsedModule.path,\n mixin.value,\n );\n\n for (const dep of deps) {\n dependencies.add(dep);\n }\n\n if (mixin.nameParts.length === 1) {\n exports.named[mixin.nameParts[0]] = {\n type: \"mixin\",\n value: resolved,\n };\n } else {\n let exportEntry = exports.named[mixin.nameParts[0]];\n\n if (!exportEntry) {\n exportEntry = { type: \"record\", value: {} };\n exports.named[mixin.nameParts[0]] = exportEntry;\n } else if (exportEntry.type !== \"record\") {\n throw new CauseError(`Error parsing file \"${parsedModule.path}\"`, {\n cause: `\"${mixin.nameParts[0]}\" is not a record`,\n });\n }\n\n let current = exportEntry.value;\n for (let i = 1; i < mixin.nameParts.length - 1; i++) {\n let next = current[mixin.nameParts[i]];\n if (!next) {\n next = { type: \"record\", value: {} };\n current[mixin.nameParts[i]] = next;\n } else if (next.type !== \"record\") {\n throw new CauseError(\n `Error parsing file \"${parsedModule.path}\"`,\n {\n cause: `\"${mixin.nameParts.slice(0, i + 1).join(\".\")}\" is not a record`,\n },\n );\n }\n current = next.value;\n }\n current[mixin.nameParts[mixin.nameParts.length - 1]] = {\n type: \"mixin\",\n value: resolved,\n };\n }\n }),\n );\n }\n return {\n resolved: {\n path: parsedModule.path,\n exports,\n },\n dependencies: Array.from(dependencies),\n };\n}\n\nasync function resolveModuleSpecifierRecursively(\n context: ResolveContext,\n resolvedModule: ResolvedModule,\n specifiers: string[],\n seen = new Set<string>(),\n): Promise<ResolvedCssImport> {\n const exportName = specifiers[0];\n const exportValue = resolvedModule.exports.named[exportName];\n if (exportValue !== undefined) {\n if (seen.has(resolvedModule.path + \":\" + exportName)) {\n throw new CircularDependencyError(\n `Unable to resolve \"${specifiers.join(\".\")}\" in module \"${\n resolvedModule.path\n }\"`,\n { cause: \"Circular dependency detected\" },\n );\n }\n\n seen.add(resolvedModule.path + \":\" + exportName);\n return resolveModuleExport(\n context,\n resolvedModule.path,\n exportValue,\n specifiers,\n seen,\n );\n }\n\n let i = 1;\n for (const from of resolvedModule.exports.all) {\n if (context.exportAllLimit && i++ > context.exportAllLimit) {\n throw new ResolveError(\n `Unable to resolve \"${specifiers.join(\".\")}\" in module \"${\n resolvedModule.path\n }\"`,\n {\n cause: `More than ${context.exportAllLimit} star exports are not supported for performance reasons`,\n },\n );\n }\n\n try {\n const resolved = await resolveModuleExport(\n context,\n resolvedModule.path,\n {\n type: \"re-export\",\n from,\n name: exportName,\n },\n specifiers,\n seen,\n );\n\n if (seen.has(resolvedModule.path + \":*\")) {\n throw new CircularDependencyError(\n `Unable to resolve \"${specifiers.join(\".\")}\" in module \"${\n resolvedModule.path\n }\"`,\n { cause: \"Circular dependency detected\" },\n );\n }\n\n seen.add(resolvedModule.path + \":*\");\n\n return resolved;\n } catch (error) {\n // ignore resolve error, it means the specifier was not found in the\n // current module, we just have to continue the loop.\n if (!(error instanceof ResolveError)) {\n throw error;\n }\n // if the cause of the error is a circular dependency down the road do not\n // ignore the error\n if (error.circular) {\n throw error;\n }\n }\n }\n\n throw new ResolveError(`Unable to resolve \"${specifiers.join(\".\")}\"`, {\n cause: `no matching export found in module \"${resolvedModule.path}\"`,\n });\n}\n\nasync function resolveModuleExport(\n context: ResolveContext,\n filePath: string,\n moduleExport: ResolvedExport,\n specifiers: string[],\n seen: Set<string>,\n): Promise<ResolvedCssImport> {\n try {\n switch (moduleExport.type) {\n case \"re-export\": {\n const { resolved: reExportedModule } = await resolveModule(\n context,\n await context.resolve(moduleExport.from, filePath),\n );\n const resolved = await resolveModuleSpecifierRecursively(\n context,\n reExportedModule,\n [moduleExport.name, ...specifiers.slice(1)],\n seen,\n );\n if (resolved) {\n resolved.from.push(filePath);\n }\n return resolved;\n }\n case \"namespace-re-export\": {\n const { resolved: reExportedModule } = await resolveModule(\n context,\n await context.resolve(moduleExport.from, filePath),\n );\n const resolved = await resolveModuleSpecifierRecursively(\n context,\n reExportedModule,\n specifiers.slice(1),\n seen,\n );\n if (resolved) {\n resolved.from.push(filePath);\n }\n return resolved;\n }\n case \"styled-component\": {\n return {\n type: \"styled-component\",\n from: [filePath],\n source: filePath,\n name: specifiers[specifiers.length - 1],\n value: moduleExport.className,\n };\n }\n // usually at this point `tag-template` exports where already resolved to\n // styled-components if a matching styled-component comment was generated\n // by yak-swc. So resolving a value to a `tag-template` at this stage\n // would mean that the user tried to use the result of a call to a\n // different tag-template than yak's styled in a template. This is usually\n // invalid.\n //\n // But there is an issue with Nextjs. Next build in two passes, once for\n // the server bundle, once for the client bundle. During the server-side\n // build, each module with the `\"use client\"` directive is transformed to\n // throw errors if the exported symbol are used. This transformation\n // removes the comments generated by `yak-swc`, so instead of the expected\n // `styled-component`, calls to `styled` resolve to a `tag-template`\n // (because no classname was found in the now absent comments).\n //\n // To summarize, if a \"use client\" bundle exports a styled component that\n // is used in a \"standard\" module, the resolve logic would throw with\n // \"unknown type tag-template\".\n //\n // To avoid this error, the resolve logic must handle those `tag-template`\n // with a special type `unresolved-tag`. Those will be interpolated to\n // valid CSS with minimal effect (to avoid CSS syntax error in the case of\n // Nextjs server build)\n case \"tag-template\": {\n return {\n type: \"unresolved-tag\",\n from: [filePath],\n source: filePath,\n name: specifiers[specifiers.length - 1],\n };\n }\n case \"constant\": {\n return {\n type: \"constant\",\n from: [filePath],\n source: filePath,\n value: moduleExport.value,\n };\n }\n case \"record\": {\n const resolvedInRecord = resolveSpecifierInRecord(\n moduleExport,\n specifiers[0],\n specifiers.slice(1),\n );\n return resolveModuleExport(\n context,\n filePath,\n resolvedInRecord,\n specifiers,\n seen,\n );\n }\n case \"mixin\": {\n return {\n type: \"mixin\",\n from: [filePath],\n source: filePath,\n value: moduleExport.value,\n };\n }\n }\n } catch (error) {\n throw new ResolveError(\n `Unable to resolve \"${specifiers.join(\".\")}\" in module \"${filePath}\"`,\n { cause: error },\n );\n }\n\n throw new ResolveError(\n `Unable to resolve \"${specifiers.join(\".\")}\" in module \"${filePath}\"`,\n { cause: `unknown type \"${moduleExport.type}\"` },\n );\n}\n\nfunction resolveSpecifierInRecord(\n record: ExtendedRecordExport,\n name: string,\n specifiers: string[],\n): ConstantExport | ResolvedStyledComponent | ResolvedMixin {\n if (specifiers.length === 0) {\n throw new ResolveError(\"did not expect an object\");\n }\n let depth = 0;\n let current: ResolvedExport = record;\n while (current && current.type === \"record\" && depth < specifiers.length) {\n current = current.value[specifiers[depth]];\n depth += 1;\n }\n\n if (current === undefined || depth !== specifiers.length) {\n throw new ResolveError(\n `Unable to resolve \"${specifiers.join(\".\")}\" in object/array \"${name}\"`,\n { cause: \"path not found\" },\n );\n }\n\n if (\n current.type === \"constant\" ||\n current.type === \"styled-component\" ||\n current.type === \"mixin\"\n ) {\n return current;\n }\n\n // mixins in .yak files are wrapped inside an object with a __yak key\n if (\n current.type === \"record\" &&\n \"__yak\" in current.value &&\n current.value.__yak.type === \"constant\"\n ) {\n return { type: \"mixin\", value: String(current.value.__yak.value) };\n }\n\n throw new ResolveError(\n `Unable to resolve \"${specifiers.join(\".\")}\" in object/array \"${name}\"`,\n { cause: \"only string and numbers are supported\" },\n );\n}\n\n/**\n * hex SHA-1 hash of a message using webcrypto\n * Keeps yak independent from node api (therefore executable in browser)\n */\nasync function sha1(message: string) {\n const resultBuffer = await globalThis.crypto.subtle.digest(\n \"SHA-1\",\n new TextEncoder().encode(message),\n );\n return Array.from(new Uint8Array(resultBuffer), (byte) =>\n byte.toString(16).padStart(2, \"0\"),\n ).join(\"\");\n}\n\ntype ResolvedCssImport =\n | {\n type: \"styled-component\";\n source: string;\n from: string[];\n name: string;\n value: string;\n }\n | {\n type: \"unresolved-tag\";\n source: string;\n from: string[];\n name: string;\n }\n | { type: \"mixin\"; source: string; from: string[]; value: string | number }\n | {\n type: \"constant\";\n source: string;\n from: string[];\n value: string | number;\n };\n\nexport type ResolveContext = {\n parse: (modulePath: string) => Promise<ParsedModule> | ParsedModule;\n cache?: {\n resolve?: Cache<\n Promise<{ resolved: ResolvedModule; dependencies: string[] }>\n >;\n resolveCrossFileConstant?: Cache<\n Promise<{ resolved: string; dependencies: string[] }>\n >;\n };\n exportAllLimit?: number;\n resolve: (specifier: string, importer: string) => Promise<string> | string;\n};\n\ntype YakImportKind = \"mixin\" | \"selector\";\n\ntype YakCssImport = {\n encodedArguments: string;\n moduleSpecifier: string;\n specifier: string[];\n importKind: YakImportKind;\n semicolon: string;\n position: number;\n size: number;\n};\n\nexport type ExtendedRecordExport = {\n type: \"record\";\n value: Record<string, ResolvedExport>;\n};\n\nexport type ResolvedMixin = { type: \"mixin\"; value: string };\nexport type ResolvedStyledComponent = {\n type: \"styled-component\";\n className: string;\n};\n\nexport type ResolvedExport =\n | Exclude<ModuleExport, RecordExport>\n | ExtendedRecordExport\n | ResolvedStyledComponent\n | ResolvedMixin;\n\nexport type ResolvedExports = {\n named: Record<string, ResolvedExport>;\n all: string[];\n};\n\nexport type ResolvedModule = {\n path: string;\n exports: ResolvedExports;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAAyB;AAQlB,SAAS,kBACd,eACA,cACA;AACA,MAAI,CAAC,cAAc;AACjB,WAAO,MAAM;AAAA,IAAC;AAAA,EAChB;AACA,QAAM,cAAc,cAAc,gBAC9B,sBAAS,cAAc,UAAU,SAAS,cAAc,YAAY,IACpE,cAAc;AAClB,SAAO,CACL,aACA,YACG;AAEH,UAAM,oBACJ,gBAAgB,OAAO,cAAc,IAAI,WAAW,KAAK;AAC3D,QACE,iBAAiB,QACjB,IAAI,OAAO,YAAY,EAAE,KAAK,iBAAiB,GAC/C;AACA,cAAQ,IAAI,iBAAU,mBAAmB,QAAQ,OAAO;AAAA,IAC1D;AAAA,EACF;AACF;;;ACzBO,SAAS,WACd,MACA,mBAGQ;AACR,MAAI;AAEJ,MAAI,OAAO,SAAS,UA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M,WAAW,QAAQ,aAAa,iBAAiB;AAC7D,aAAS,OAAO,GAAG;AAEnB,WAAOC,0BAAyB,MAAM,KAAK,SAAS,GAAG,EAAE,KAAK,CAAC,WAAW;AACxE,eAAS,gBAAgB,GAAG;AAC5B,aAAO,SAAS,MAAM,QAAQ,SAAS;AAAA,IACzC,GAAG,QAAQ;AAAA,EACb,CAAC;AACH;","names":["exports","resolveCrossFileConstant","exports","resolveCrossFileConstant","resolveModule","traverse","dirname","resolveCrossFileConstant"]}
@@ -98,7 +98,7 @@ function addYakWebpack(nextConfig, yakOptions, yakPluginOptions) {
98
98
  }
99
99
  webpackConfig.module.rules.push({
100
100
  test: yakOptions.experiments?.transpilationMode === "Css" ? /\.yak\.css$/ : /\.yak\.module\.css$/,
101
- loader: import_node_path.default.join(currentDir, "../loaders/webpack-loader.js"),
101
+ loader: import_node_path.default.join(currentDir, "../loaders/webpack-loader.cjs"),
102
102
  options: yakOptions
103
103
  });
104
104
  const yakContext = resolveYakContext(
@@ -1 +1 @@
1
- {"version":3,"sources":["../../withYak/index.ts"],"sourcesContent":["/// <reference types=\"node\" />\nimport { existsSync } from \"node:fs\";\nimport path, { dirname } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { NextConfig } from \"../../example/node_modules/next/dist/server/config.js\";\n\nconst currentDir =\n typeof __dirname !== \"undefined\"\n ? __dirname\n : dirname(fileURLToPath(import.meta.url));\n\nexport type YakConfigOptions = {\n /**\n * Generate compact CSS class and variable names.\n * @defaultValue\n * enabled if NODE_ENV is set to `production`, otherwise disabled\n */\n minify?: boolean;\n contextPath?: string;\n /**\n * Optional prefix for generated CSS identifiers.\n * This can be used to ensure unique class names across different applications\n * or to add organization-specific prefixes.\n */\n prefix?: string;\n /**\n * Adds `displayName` to each component for better React DevTools debugging\n * - Enabled by default in development mode\n * - Disabled by default in production\n * - Increases bundle size slightly when enabled\n */\n displayNames?: boolean;\n experiments?: {\n /**\n * A regex pattern to filter files based on their path.\n * Use \".css$\" to filter the raw CSS transpilation and \".css-resolved$\" for resolved CSS\n * Use true to enable debug mode for all files\n */\n debug?: boolean | string;\n transpilationMode?: \"CssModule\" | \"Css\";\n };\n};\n\nconst addYak = (yakOptions: YakConfigOptions, nextConfig: NextConfig) => {\n const minify = yakOptions.minify ?? process.env.NODE_ENV === \"production\";\n const yakPluginOptions = {\n minify,\n basePath: currentDir,\n prefix: yakOptions.prefix,\n displayNames: yakOptions.displayNames ?? !minify,\n };\n\n if (process.env.TURBOPACK === \"1\" || process.env.TURBOPACK === \"auto\") {\n addYakTurbopack(nextConfig, yakOptions, {\n ...yakPluginOptions,\n importMode: { type: \"DataUrl\" },\n });\n } else {\n addYakWebpack(nextConfig, yakOptions, {\n ...yakPluginOptions,\n importMode: {\n type: \"InlineMatchResource\",\n transpilation: yakOptions.experiments?.transpilationMode ?? \"CssModule\",\n },\n });\n }\n return nextConfig;\n};\n\n/**\n * Configure Turbopack with yak loader for CSS-in-JS transformation\n * @param nextConfig - Next.js configuration object\n * @param yakOptions - Yak configuration options\n * @param yakPluginOptions - Processed plugin options for yak-swc\n */\nfunction addYakTurbopack(\n nextConfig: NextConfig,\n yakOptions: YakConfigOptions,\n yakPluginOptions: {\n minify: boolean;\n basePath: string;\n prefix?: string;\n displayNames: boolean;\n importMode: { type: string };\n },\n) {\n // turbopack can't handle options with undefined values, so we remove them\n const yakLoader = removeUndefinedRecursive({\n loader: path.join(currentDir, \"../loaders/turbo-loader.js\"),\n options: {\n yakOptions: yakOptions,\n yakPluginOptions: yakPluginOptions,\n },\n }) as { loader: string; options: {} };\n\n nextConfig.turbopack ||= {};\n nextConfig.turbopack.rules ||= {};\n\n const ruleKey = \"*.{js,jsx,cjs,mjs,ts,tsx,cts,mts}\";\n nextConfig.turbopack.rules[ruleKey] = {\n loaders: [],\n ...nextConfig.turbopack.rules[ruleKey],\n };\n nextConfig.turbopack.rules[ruleKey].loaders.push(yakLoader);\n\n // Configure resolveAlias for custom yak context (similar to webpack)\n // This allows users to provide a custom context file that will be used\n // instead of the default baseContext\n const yakContext = resolveYakContext(yakOptions.contextPath, process.cwd());\n if (yakContext) {\n nextConfig.turbopack.resolveAlias ||= {};\n nextConfig.turbopack.resolveAlias[\"next-yak/context/baseContext\"] =\n // This is a hack around the fact that turbopack currently only supports relative paths\n // turbopack: \"server relative imports are not implemented yet\"\n // Relative is quite dangerous here as it relies on the cwd being the starting point\n `./${path.relative(process.cwd(), yakContext)}`;\n }\n}\n\n/**\n * Configure Webpack with yak SWC plugin and webpack loader for CSS-in-JS transformation\n * @param nextConfig - Next.js configuration object\n * @param yakOptions - Yak configuration options\n * @param yakPluginOptions - Processed plugin options for yak-swc\n */\nfunction addYakWebpack(\n nextConfig: NextConfig,\n yakOptions: YakConfigOptions,\n yakPluginOptions: {\n minify: boolean;\n basePath: string;\n prefix?: string;\n displayNames: boolean;\n importMode: { type: string; transpilation?: string };\n },\n) {\n // Add SWC plugin for Webpack\n nextConfig.experimental ||= {};\n nextConfig.experimental.swcPlugins ||= [];\n nextConfig.experimental.swcPlugins.push([\"yak-swc\", yakPluginOptions]);\n\n // Configure webpack loader\n const previousConfig = nextConfig.webpack;\n nextConfig.webpack = (webpackConfig, options) => {\n if (previousConfig) {\n webpackConfig = previousConfig(webpackConfig, options);\n }\n\n webpackConfig.module.rules.push({\n test:\n yakOptions.experiments?.transpilationMode === \"Css\"\n ? /\\.yak\\.css$/\n : /\\.yak\\.module\\.css$/,\n loader: path.join(currentDir, \"../loaders/webpack-loader.js\"),\n options: yakOptions,\n });\n\n // With the following alias the internal next-yak code\n // is able to import a context which works for server components\n const yakContext = resolveYakContext(\n yakOptions.contextPath,\n webpackConfig.context || process.cwd(),\n );\n if (yakContext) {\n webpackConfig.resolve.alias[\"next-yak/context/baseContext\"] = yakContext;\n }\n\n return webpackConfig;\n };\n}\n\n/**\n * Recursively removes undefined values from an object or array.\n *\n * This function deeply traverses the input object/array and creates a new structure\n * with all undefined values filtered out. For objects, properties with undefined values\n * are omitted. For arrays, undefined elements are removed from the result.\n *\n * @param obj - The object or array to process\n * @returns A new object/array with undefined values removed, or the original value if no changes were needed\n */\nfunction removeUndefinedRecursive<T>(obj: T): {} {\n if (typeof obj !== \"object\" || obj === null) {\n return obj as {};\n }\n\n if (Array.isArray(obj)) {\n const filtered: unknown[] = [];\n for (let i = 0; i < obj.length; i++) {\n const processed = removeUndefinedRecursive(obj[i]);\n if (processed !== undefined) {\n filtered.push(processed);\n }\n }\n return filtered as {};\n }\n\n const newObj: Record<string, unknown> = {};\n let hasChanges = false;\n\n for (const key in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n const value = removeUndefinedRecursive((obj as any)[key]);\n if (value !== undefined) {\n newObj[key] = value;\n hasChanges = true;\n }\n }\n }\n\n return hasChanges ? (newObj as {}) : obj;\n}\n\n/**\n * Try to resolve yak\n */\nfunction resolveYakContext(contextPath: string | undefined, cwd: string) {\n const yakContext = contextPath\n ? path.resolve(cwd, contextPath)\n : path.resolve(cwd, \"yak.context\");\n const extensions = [\"\", \".ts\", \".tsx\", \".js\", \".jsx\"];\n for (const extension in extensions) {\n const fileName = yakContext + extensions[extension];\n if (existsSync(fileName)) {\n return fileName;\n }\n }\n if (contextPath) {\n throw new Error(`Could not find yak context file at ${yakContext}`);\n }\n}\n\n// Wrapper to allow sync, async, and function configuration of Next.js\n/**\n * Add Yak to your Next.js app\n *\n * @usage\n *\n * ```ts\n * // next.config.js\n * const { withYak } = require(\"next-yak/withYak\");\n * const nextConfig = {\n * // your next config here\n * };\n * module.exports = withYak(nextConfig);\n * ```\n *\n * With a custom yakConfig\n *\n * ```ts\n * // next.config.js\n * const { withYak } = require(\"next-yak/withYak\");\n * const nextConfig = {\n * // your next config here\n * };\n * const yakConfig = {\n * // Optional prefix for generated CSS identifiers\n * prefix: \"my-app\",\n * // Other yak config options...\n * };\n * module.exports = withYak(yakConfig, nextConfig);\n * ```\n */\nexport const withYak: {\n <\n T extends\n | Record<string, any>\n | ((...args: any[]) => Record<string, any>)\n | ((...args: any[]) => Promise<Record<string, any>>),\n >(\n yakOptions: YakConfigOptions,\n nextConfig: T,\n ): T;\n // no yakConfig\n <\n T extends\n | Record<string, any>\n | ((...args: any[]) => Record<string, any>)\n | ((...args: any[]) => Promise<Record<string, any>>),\n >(\n nextConfig: T,\n _?: undefined,\n ): T;\n} = (maybeYakOptions, nextConfig) => {\n if (nextConfig === undefined) {\n return withYak({}, maybeYakOptions);\n }\n // If the second parameter is present the first parameter must be a YakConfigOptions\n const yakOptions = maybeYakOptions as YakConfigOptions;\n if (typeof nextConfig === \"function\") {\n /**\n * A NextConfig can be a sync or async function\n * https://nextjs.org/docs/pages/api-reference/next-config-js\n * @param {any[]} args\n */\n return (...args) => {\n /** Dynamic Next Configs can be async or sync */\n const config = nextConfig(...args) as NextConfig | Promise<NextConfig>;\n return config instanceof Promise\n ? config.then((config) => addYak(yakOptions, config))\n : addYak(yakOptions, config);\n };\n }\n return addYak(yakOptions, nextConfig);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAA2B;AAC3B,uBAA8B;AAC9B,sBAA8B;AAH9B;AAMA,IAAM,aACJ,OAAO,cAAc,cACjB,gBACA,8BAAQ,+BAAc,YAAY,GAAG,CAAC;AAkC5C,IAAM,SAAS,CAAC,YAA8B,eAA2B;AACvE,QAAM,SAAS,WAAW,UAAU,QAAQ,IAAI,aAAa;AAC7D,QAAM,mBAAmB;AAAA,IACvB;AAAA,IACA,UAAU;AAAA,IACV,QAAQ,WAAW;AAAA,IACnB,cAAc,WAAW,gBAAgB,CAAC;AAAA,EAC5C;AAEA,MAAI,QAAQ,IAAI,cAAc,OAAO,QAAQ,IAAI,cAAc,QAAQ;AACrE,oBAAgB,YAAY,YAAY;AAAA,MACtC,GAAG;AAAA,MACH,YAAY,EAAE,MAAM,UAAU;AAAA,IAChC,CAAC;AAAA,EACH,OAAO;AACL,kBAAc,YAAY,YAAY;AAAA,MACpC,GA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,IAAM,UAoBT,CAAC,iBAAiB,eAAe;AACnC,MAAI,eAAe,QAAW;AAC5B,WAAO,QAAQ,CAAC,GAAG,eAAe;AAAA,EACpC;AAEA,QAAM,aAAa;AACnB,MAAI,OAAO,eAAe,YAAY;AAMpC,WAAO,IAAI,SAAS;AAElB,YAAM,SAAS,WAAW,GAAG,IAAI;AACjC,aAAO,kBAAkB,UACrB,OAAO,KAAK,CAACC,YAAW,OAAO,YAAYA,OAAM,CAAC,IAClD,OAAO,YAAY,MAAM;AAAA,IAC/B;AAAA,EACF;AACA,SAAO,OAAO,YAAY,UAAU;AACtC;","names":["path","config"]}
1
+ {"version":3,"sources":["../../withYak/index.ts"],"sourcesContent":["/// <reference types=\"node\" />\nimport type { NextConfig } from \"next\";\nimport { existsSync } from \"node:fs\";\nimport path, { dirname } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nconst currentDir =\n typeof __dirname !== \"undefined\"\n ? __dirname\n : dirname(fileURLToPath(import.meta.url));\n\nexport type YakConfigOptions = {\n /**\n * Generate compact CSS class and variable names.\n * @defaultValue\n * enabled if NODE_ENV is set to `production`, otherwise disabled\n */\n minify?: boolean;\n contextPath?: string;\n /**\n * Optional prefix for generated CSS identifiers.\n * This can be used to ensure unique class names across different applications\n * or to add organization-specific prefixes.\n */\n prefix?: string;\n /**\n * Adds `displayName` to each component for better React DevTools debugging\n * - Enabled by default in development mode\n * - Disabled by default in production\n * - Increases bundle size slightly when enabled\n */\n displayNames?: boolean;\n experiments?: {\n /**\n * A regex pattern to filter files based on their path.\n * Use \".css$\" to filter the raw CSS transpilation and \".css-resolved$\" for resolved CSS\n * Use true to enable debug mode for all files\n */\n debug?: boolean | string;\n transpilationMode?: \"CssModule\" | \"Css\";\n };\n};\n\nconst addYak = (yakOptions: YakConfigOptions, nextConfig: NextConfig) => {\n const minify = yakOptions.minify ?? process.env.NODE_ENV === \"production\";\n const yakPluginOptions = {\n minify,\n basePath: currentDir,\n prefix: yakOptions.prefix,\n displayNames: yakOptions.displayNames ?? !minify,\n };\n\n if (process.env.TURBOPACK === \"1\" || process.env.TURBOPACK === \"auto\") {\n addYakTurbopack(nextConfig, yakOptions, {\n ...yakPluginOptions,\n importMode: { type: \"DataUrl\" },\n });\n } else {\n addYakWebpack(nextConfig, yakOptions, {\n ...yakPluginOptions,\n importMode: {\n type: \"InlineMatchResource\",\n transpilation: yakOptions.experiments?.transpilationMode ?? \"CssModule\",\n },\n });\n }\n return nextConfig;\n};\n\n/**\n * Configure Turbopack with yak loader for CSS-in-JS transformation\n * @param nextConfig - Next.js configuration object\n * @param yakOptions - Yak configuration options\n * @param yakPluginOptions - Processed plugin options for yak-swc\n */\nfunction addYakTurbopack(\n nextConfig: NextConfig,\n yakOptions: YakConfigOptions,\n yakPluginOptions: {\n minify: boolean;\n basePath: string;\n prefix?: string;\n displayNames: boolean;\n importMode: { type: string };\n },\n) {\n // turbopack can't handle options with undefined values, so we remove them\n const yakLoader = removeUndefinedRecursive({\n loader: path.join(currentDir, \"../loaders/turbo-loader.js\"),\n options: {\n yakOptions: yakOptions,\n yakPluginOptions: yakPluginOptions,\n },\n }) as { loader: string; options: {} };\n\n nextConfig.turbopack ||= {};\n nextConfig.turbopack.rules ||= {};\n\n const ruleKey = \"*.{js,jsx,cjs,mjs,ts,tsx,cts,mts}\";\n nextConfig.turbopack.rules[ruleKey] = {\n loaders: [],\n ...nextConfig.turbopack.rules[ruleKey],\n };\n nextConfig.turbopack.rules[ruleKey].loaders.push(yakLoader);\n\n // Configure resolveAlias for custom yak context (similar to webpack)\n // This allows users to provide a custom context file that will be used\n // instead of the default baseContext\n const yakContext = resolveYakContext(yakOptions.contextPath, process.cwd());\n if (yakContext) {\n nextConfig.turbopack.resolveAlias ||= {};\n nextConfig.turbopack.resolveAlias[\"next-yak/context/baseContext\"] =\n // This is a hack around the fact that turbopack currently only supports relative paths\n // turbopack: \"server relative imports are not implemented yet\"\n // Relative is quite dangerous here as it relies on the cwd being the starting point\n `./${path.relative(process.cwd(), yakContext)}`;\n }\n}\n\n/**\n * Configure Webpack with yak SWC plugin and webpack loader for CSS-in-JS transformation\n * @param nextConfig - Next.js configuration object\n * @param yakOptions - Yak configuration options\n * @param yakPluginOptions - Processed plugin options for yak-swc\n */\nfunction addYakWebpack(\n nextConfig: NextConfig,\n yakOptions: YakConfigOptions,\n yakPluginOptions: {\n minify: boolean;\n basePath: string;\n prefix?: string;\n displayNames: boolean;\n importMode: { type: string; transpilation?: string };\n },\n) {\n // Add SWC plugin for Webpack\n nextConfig.experimental ||= {};\n nextConfig.experimental.swcPlugins ||= [];\n nextConfig.experimental.swcPlugins.push([\"yak-swc\", yakPluginOptions]);\n\n // Configure webpack loader\n const previousConfig = nextConfig.webpack;\n nextConfig.webpack = (webpackConfig, options) => {\n if (previousConfig) {\n webpackConfig = previousConfig(webpackConfig, options);\n }\n\n webpackConfig.module.rules.push({\n test:\n yakOptions.experiments?.transpilationMode === \"Css\"\n ? /\\.yak\\.css$/\n : /\\.yak\\.module\\.css$/,\n loader: path.join(currentDir, \"../loaders/webpack-loader.cjs\"),\n options: yakOptions,\n });\n\n // With the following alias the internal next-yak code\n // is able to import a context which works for server components\n const yakContext = resolveYakContext(\n yakOptions.contextPath,\n webpackConfig.context || process.cwd(),\n );\n if (yakContext) {\n webpackConfig.resolve.alias[\"next-yak/context/baseContext\"] = yakContext;\n }\n\n return webpackConfig;\n };\n}\n\n/**\n * Recursively removes undefined values from an object or array.\n *\n * This function deeply traverses the input object/array and creates a new structure\n * with all undefined values filtered out. For objects, properties with undefined values\n * are omitted. For arrays, undefined elements are removed from the result.\n *\n * @param obj - The object or array to process\n * @returns A new object/array with undefined values removed, or the original value if no changes were needed\n */\nfunction removeUndefinedRecursive<T>(obj: T): {} {\n if (typeof obj !== \"object\" || obj === null) {\n return obj as {};\n }\n\n if (Array.isArray(obj)) {\n const filtered: unknown[] = [];\n for (let i = 0; i < obj.length; i++) {\n const processed = removeUndefinedRecursive(obj[i]);\n if (processed !== undefined) {\n filtered.push(processed);\n }\n }\n return filtered as {};\n }\n\n const newObj: Record<string, unknown> = {};\n let hasChanges = false;\n\n for (const key in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n const value = removeUndefinedRecursive((obj as any)[key]);\n if (value !== undefined) {\n newObj[key] = value;\n hasChanges = true;\n }\n }\n }\n\n return hasChanges ? (newObj as {}) : obj;\n}\n\n/**\n * Try to resolve yak\n */\nfunction resolveYakContext(contextPath: string | undefined, cwd: string) {\n const yakContext = contextPath\n ? path.resolve(cwd, contextPath)\n : path.resolve(cwd, \"yak.context\");\n const extensions = [\"\", \".ts\", \".tsx\", \".js\", \".jsx\"];\n for (const extension in extensions) {\n const fileName = yakContext + extensions[extension];\n if (existsSync(fileName)) {\n return fileName;\n }\n }\n if (contextPath) {\n throw new Error(`Could not find yak context file at ${yakContext}`);\n }\n}\n\n// Wrapper to allow sync, async, and function configuration of Next.js\n/**\n * Add Yak to your Next.js app\n *\n * @usage\n *\n * ```ts\n * // next.config.js\n * const { withYak } = require(\"next-yak/withYak\");\n * const nextConfig = {\n * // your next config here\n * };\n * module.exports = withYak(nextConfig);\n * ```\n *\n * With a custom yakConfig\n *\n * ```ts\n * // next.config.js\n * const { withYak } = require(\"next-yak/withYak\");\n * const nextConfig = {\n * // your next config here\n * };\n * const yakConfig = {\n * // Optional prefix for generated CSS identifiers\n * prefix: \"my-app\",\n * // Other yak config options...\n * };\n * module.exports = withYak(yakConfig, nextConfig);\n * ```\n */\nexport const withYak: {\n <\n T extends\n | Record<string, any>\n | ((...args: any[]) => Record<string, any>)\n | ((...args: any[]) => Promise<Record<string, any>>),\n >(\n yakOptions: YakConfigOptions,\n nextConfig: T,\n ): T;\n // no yakConfig\n <\n T extends\n | Record<string, any>\n | ((...args: any[]) => Record<string, any>)\n | ((...args: any[]) => Promise<Record<string, any>>),\n >(\n nextConfig: T,\n _?: undefined,\n ): T;\n} = (maybeYakOptions, nextConfig) => {\n if (nextConfig === undefined) {\n return withYak({}, maybeYakOptions);\n }\n // If the second parameter is present the first parameter must be a YakConfigOptions\n const yakOptions = maybeYakOptions as YakConfigOptions;\n if (typeof nextConfig === \"function\") {\n /**\n * A NextConfig can be a sync or async function\n * https://nextjs.org/docs/pages/api-reference/next-config-js\n * @param {any[]} args\n */\n return (...args) => {\n /** Dynamic Next Configs can be async or sync */\n const config = nextConfig(...args) as NextConfig | Promise<NextConfig>;\n return config instanceof Promise\n ? config.then((config) => addYak(yakOptions, config))\n : addYak(yakOptions, config);\n };\n }\n return addYak(yakOptions, nextConfig);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,qBAA2B;AAC3B,uBAA8B;AAC9B,sBAA8B;AAJ9B;AAMA,IAAM,aACJ,OAAO,cAAc,cACjB,gBACA,8BAAQ,+BAAc,YAAY,GAAG,CAAC;AAkC5C,IAAM,SAAS,CAAC,YAA8B,eAA2B;AACvE,QAAM,SAAS,WAAW,UAAU,QAAQ,IAAI,aAAa;AAC7D,QAAM,mBAAmB;AAAA,IACvB;AAAA,IACA,UAAU;AAAA,IACV,QAAQ,WAAW;AAAA,IACnB,cAAc,WAAW,gBAAgB,CAAC;AAAA,EAC5C;AAEA,MAAI,QAAQ,IAAI,cAAc,OAAO,QAAQ,IAAI,cAAc,QAAQ;AACrE,oBAAgB,YAAY,YAAY;AAAA,MACtC,GAAG;AAAA,MACH,YAAY,EAAE,MAAM,UAAU;AAAA,IAChC,CAAC;AAAA,EACH,OAAO;AACL,kBAAc,YAAY,YAAY;AAAA,MACpC,GAAG;AAAA,MACH,YAAY;AAAA,QACV,MAAM;AAAA,QACN,eAAe,WAAW,aAAa,qBAAqB;AAAA,MAC9D;AAAA,IACF,CAAC;AAAA,EACH;AACA,SAAO;AACT;AAQA,SAAS,gBACP,YACA,YACA,kBAOA;AAEA,QAAM,YAAY,yBAAyB;AAAA,IACzC,QAAQ,iBAAAA,QAAK,KAAK,YAAY,4BAA4B;AAAA,IA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K,CAACC,YAAW,OAAO,YAAYA,OAAM,CAAC,IAClD,OAAO,YAAY,MAAM;AAAA,IAC/B;AAAA,EACF;AACA,SAAO,OAAO,YAAY,UAAU;AACtC;","names":["path","config"]}
@@ -63,7 +63,7 @@ function addYakWebpack(nextConfig, yakOptions, yakPluginOptions) {
63
63
  }
64
64
  webpackConfig.module.rules.push({
65
65
  test: yakOptions.experiments?.transpilationMode === "Css" ? /\.yak\.css$/ : /\.yak\.module\.css$/,
66
- loader: path.join(currentDir, "../loaders/webpack-loader.js"),
66
+ loader: path.join(currentDir, "../loaders/webpack-loader.cjs"),
67
67
  options: yakOptions
68
68
  });
69
69
  const yakContext = resolveYakContext(
@@ -1 +1 @@
1
- {"version":3,"sources":["../../withYak/index.ts"],"sourcesContent":["/// <reference types=\"node\" />\nimport { existsSync } from \"node:fs\";\nimport path, { dirname } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { NextConfig } from \"../../example/node_modules/next/dist/server/config.js\";\n\nconst currentDir =\n typeof __dirname !== \"undefined\"\n ? __dirname\n : dirname(fileURLToPath(import.meta.url));\n\nexport type YakConfigOptions = {\n /**\n * Generate compact CSS class and variable names.\n * @defaultValue\n * enabled if NODE_ENV is set to `production`, otherwise disabled\n */\n minify?: boolean;\n contextPath?: string;\n /**\n * Optional prefix for generated CSS identifiers.\n * This can be used to ensure unique class names across different applications\n * or to add organization-specific prefixes.\n */\n prefix?: string;\n /**\n * Adds `displayName` to each component for better React DevTools debugging\n * - Enabled by default in development mode\n * - Disabled by default in production\n * - Increases bundle size slightly when enabled\n */\n displayNames?: boolean;\n experiments?: {\n /**\n * A regex pattern to filter files based on their path.\n * Use \".css$\" to filter the raw CSS transpilation and \".css-resolved$\" for resolved CSS\n * Use true to enable debug mode for all files\n */\n debug?: boolean | string;\n transpilationMode?: \"CssModule\" | \"Css\";\n };\n};\n\nconst addYak = (yakOptions: YakConfigOptions, nextConfig: NextConfig) => {\n const minify = yakOptions.minify ?? process.env.NODE_ENV === \"production\";\n const yakPluginOptions = {\n minify,\n basePath: currentDir,\n prefix: yakOptions.prefix,\n displayNames: yakOptions.displayNames ?? !minify,\n };\n\n if (process.env.TURBOPACK === \"1\" || process.env.TURBOPACK === \"auto\") {\n addYakTurbopack(nextConfig, yakOptions, {\n ...yakPluginOptions,\n importMode: { type: \"DataUrl\" },\n });\n } else {\n addYakWebpack(nextConfig, yakOptions, {\n ...yakPluginOptions,\n importMode: {\n type: \"InlineMatchResource\",\n transpilation: yakOptions.experiments?.transpilationMode ?? \"CssModule\",\n },\n });\n }\n return nextConfig;\n};\n\n/**\n * Configure Turbopack with yak loader for CSS-in-JS transformation\n * @param nextConfig - Next.js configuration object\n * @param yakOptions - Yak configuration options\n * @param yakPluginOptions - Processed plugin options for yak-swc\n */\nfunction addYakTurbopack(\n nextConfig: NextConfig,\n yakOptions: YakConfigOptions,\n yakPluginOptions: {\n minify: boolean;\n basePath: string;\n prefix?: string;\n displayNames: boolean;\n importMode: { type: string };\n },\n) {\n // turbopack can't handle options with undefined values, so we remove them\n const yakLoader = removeUndefinedRecursive({\n loader: path.join(currentDir, \"../loaders/turbo-loader.js\"),\n options: {\n yakOptions: yakOptions,\n yakPluginOptions: yakPluginOptions,\n },\n }) as { loader: string; options: {} };\n\n nextConfig.turbopack ||= {};\n nextConfig.turbopack.rules ||= {};\n\n const ruleKey = \"*.{js,jsx,cjs,mjs,ts,tsx,cts,mts}\";\n nextConfig.turbopack.rules[ruleKey] = {\n loaders: [],\n ...nextConfig.turbopack.rules[ruleKey],\n };\n nextConfig.turbopack.rules[ruleKey].loaders.push(yakLoader);\n\n // Configure resolveAlias for custom yak context (similar to webpack)\n // This allows users to provide a custom context file that will be used\n // instead of the default baseContext\n const yakContext = resolveYakContext(yakOptions.contextPath, process.cwd());\n if (yakContext) {\n nextConfig.turbopack.resolveAlias ||= {};\n nextConfig.turbopack.resolveAlias[\"next-yak/context/baseContext\"] =\n // This is a hack around the fact that turbopack currently only supports relative paths\n // turbopack: \"server relative imports are not implemented yet\"\n // Relative is quite dangerous here as it relies on the cwd being the starting point\n `./${path.relative(process.cwd(), yakContext)}`;\n }\n}\n\n/**\n * Configure Webpack with yak SWC plugin and webpack loader for CSS-in-JS transformation\n * @param nextConfig - Next.js configuration object\n * @param yakOptions - Yak configuration options\n * @param yakPluginOptions - Processed plugin options for yak-swc\n */\nfunction addYakWebpack(\n nextConfig: NextConfig,\n yakOptions: YakConfigOptions,\n yakPluginOptions: {\n minify: boolean;\n basePath: string;\n prefix?: string;\n displayNames: boolean;\n importMode: { type: string; transpilation?: string };\n },\n) {\n // Add SWC plugin for Webpack\n nextConfig.experimental ||= {};\n nextConfig.experimental.swcPlugins ||= [];\n nextConfig.experimental.swcPlugins.push([\"yak-swc\", yakPluginOptions]);\n\n // Configure webpack loader\n const previousConfig = nextConfig.webpack;\n nextConfig.webpack = (webpackConfig, options) => {\n if (previousConfig) {\n webpackConfig = previousConfig(webpackConfig, options);\n }\n\n webpackConfig.module.rules.push({\n test:\n yakOptions.experiments?.transpilationMode === \"Css\"\n ? /\\.yak\\.css$/\n : /\\.yak\\.module\\.css$/,\n loader: path.join(currentDir, \"../loaders/webpack-loader.js\"),\n options: yakOptions,\n });\n\n // With the following alias the internal next-yak code\n // is able to import a context which works for server components\n const yakContext = resolveYakContext(\n yakOptions.contextPath,\n webpackConfig.context || process.cwd(),\n );\n if (yakContext) {\n webpackConfig.resolve.alias[\"next-yak/context/baseContext\"] = yakContext;\n }\n\n return webpackConfig;\n };\n}\n\n/**\n * Recursively removes undefined values from an object or array.\n *\n * This function deeply traverses the input object/array and creates a new structure\n * with all undefined values filtered out. For objects, properties with undefined values\n * are omitted. For arrays, undefined elements are removed from the result.\n *\n * @param obj - The object or array to process\n * @returns A new object/array with undefined values removed, or the original value if no changes were needed\n */\nfunction removeUndefinedRecursive<T>(obj: T): {} {\n if (typeof obj !== \"object\" || obj === null) {\n return obj as {};\n }\n\n if (Array.isArray(obj)) {\n const filtered: unknown[] = [];\n for (let i = 0; i < obj.length; i++) {\n const processed = removeUndefinedRecursive(obj[i]);\n if (processed !== undefined) {\n filtered.push(processed);\n }\n }\n return filtered as {};\n }\n\n const newObj: Record<string, unknown> = {};\n let hasChanges = false;\n\n for (const key in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n const value = removeUndefinedRecursive((obj as any)[key]);\n if (value !== undefined) {\n newObj[key] = value;\n hasChanges = true;\n }\n }\n }\n\n return hasChanges ? (newObj as {}) : obj;\n}\n\n/**\n * Try to resolve yak\n */\nfunction resolveYakContext(contextPath: string | undefined, cwd: string) {\n const yakContext = contextPath\n ? path.resolve(cwd, contextPath)\n : path.resolve(cwd, \"yak.context\");\n const extensions = [\"\", \".ts\", \".tsx\", \".js\", \".jsx\"];\n for (const extension in extensions) {\n const fileName = yakContext + extensions[extension];\n if (existsSync(fileName)) {\n return fileName;\n }\n }\n if (contextPath) {\n throw new Error(`Could not find yak context file at ${yakContext}`);\n }\n}\n\n// Wrapper to allow sync, async, and function configuration of Next.js\n/**\n * Add Yak to your Next.js app\n *\n * @usage\n *\n * ```ts\n * // next.config.js\n * const { withYak } = require(\"next-yak/withYak\");\n * const nextConfig = {\n * // your next config here\n * };\n * module.exports = withYak(nextConfig);\n * ```\n *\n * With a custom yakConfig\n *\n * ```ts\n * // next.config.js\n * const { withYak } = require(\"next-yak/withYak\");\n * const nextConfig = {\n * // your next config here\n * };\n * const yakConfig = {\n * // Optional prefix for generated CSS identifiers\n * prefix: \"my-app\",\n * // Other yak config options...\n * };\n * module.exports = withYak(yakConfig, nextConfig);\n * ```\n */\nexport const withYak: {\n <\n T extends\n | Record<string, any>\n | ((...args: any[]) => Record<string, any>)\n | ((...args: any[]) => Promise<Record<string, any>>),\n >(\n yakOptions: YakConfigOptions,\n nextConfig: T,\n ): T;\n // no yakConfig\n <\n T extends\n | Record<string, any>\n | ((...args: any[]) => Record<string, any>)\n | ((...args: any[]) => Promise<Record<string, any>>),\n >(\n nextConfig: T,\n _?: undefined,\n ): T;\n} = (maybeYakOptions, nextConfig) => {\n if (nextConfig === undefined) {\n return withYak({}, maybeYakOptions);\n }\n // If the second parameter is present the first parameter must be a YakConfigOptions\n const yakOptions = maybeYakOptions as YakConfigOptions;\n if (typeof nextConfig === \"function\") {\n /**\n * A NextConfig can be a sync or async function\n * https://nextjs.org/docs/pages/api-reference/next-config-js\n * @param {any[]} args\n */\n return (...args) => {\n /** Dynamic Next Configs can be async or sync */\n const config = nextConfig(...args) as NextConfig | Promise<NextConfig>;\n return config instanceof Promise\n ? config.then((config) => addYak(yakOptions, config))\n : addYak(yakOptions, config);\n };\n }\n return addYak(yakOptions, nextConfig);\n};\n"],"mappings":";AACA,SAAS,kBAAkB;AAC3B,OAAO,QAAQ,eAAe;AAC9B,SAAS,qBAAqB;AAG9B,IAAM,aACJ,OAAO,cAAc,cACjB,YACA,QAAQ,cAAc,YAAY,GAAG,CAAC;AAkC5C,IAAM,SAAS,CAAC,YAA8B,eAA2B;AACvE,QAAM,SAAS,WAAW,UAAU,QAAQ,IAAI,aAAa;AAC7D,QAAM,mBAAmB;AAAA,IACvB;AAAA,IACA,UAAU;AAAA,IACV,QAAQ,WAAW;AAAA,IACnB,cAAc,WAAW,gBAAgB,CAAC;AAAA,EAC5C;AAEA,MAAI,QAAQ,IAAI,cAAc,OAAO,QAAQ,IAAI,cAAc,QAAQ;AACrE,oBAAgB,YAAY,YAAY;AAAA,MACtC,GAAG;AAAA,MACH,YAAY,EAAE,MAAM,UAAU;AAAA,IAChC,CAAC;AAAA,EACH,OAAO;AACL,kBAAc,YAAY,YAAY;AAAA,MACpC,GAAG;AAAA,MACH,YAAY;AAAA,QACV,MAAM;AAAA,QACN,eAAe,WAAW,aAAa,qBAAqB;AAAA,MAC9D;AAAA,IACF,CAAC;AAAA,EACH;AACA,SAAO;AACT;AAQA,SAAS,gBACP,YACA,YACA,kBAOA;AAEA,QAAM,YAAY,yBAAyB;AAAA,IACzC,QAAQ,KAAK,KAAK,YAAY,4BAA4B;AAAA,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,CAAC,IAClD,OAAO,YAAY,MAAM;AAAA,IAC/B;AAAA,EACF;AACA,SAAO,OAAO,YAAY,UAAU;AACtC;","names":["config"]}
1
+ {"version":3,"sources":["../../withYak/index.ts"],"sourcesContent":["/// <reference types=\"node\" />\nimport type { NextConfig } from \"next\";\nimport { existsSync } from \"node:fs\";\nimport path, { dirname } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nconst currentDir =\n typeof __dirname !== \"undefined\"\n ? __dirname\n : dirname(fileURLToPath(import.meta.url));\n\nexport type YakConfigOptions = {\n /**\n * Generate compact CSS class and variable names.\n * @defaultValue\n * enabled if NODE_ENV is set to `production`, otherwise disabled\n */\n minify?: boolean;\n contextPath?: string;\n /**\n * Optional prefix for generated CSS identifiers.\n * This can be used to ensure unique class names across different applications\n * or to add organization-specific prefixes.\n */\n prefix?: string;\n /**\n * Adds `displayName` to each component for better React DevTools debugging\n * - Enabled by default in development mode\n * - Disabled by default in production\n * - Increases bundle size slightly when enabled\n */\n displayNames?: boolean;\n experiments?: {\n /**\n * A regex pattern to filter files based on their path.\n * Use \".css$\" to filter the raw CSS transpilation and \".css-resolved$\" for resolved CSS\n * Use true to enable debug mode for all files\n */\n debug?: boolean | string;\n transpilationMode?: \"CssModule\" | \"Css\";\n };\n};\n\nconst addYak = (yakOptions: YakConfigOptions, nextConfig: NextConfig) => {\n const minify = yakOptions.minify ?? process.env.NODE_ENV === \"production\";\n const yakPluginOptions = {\n minify,\n basePath: currentDir,\n prefix: yakOptions.prefix,\n displayNames: yakOptions.displayNames ?? !minify,\n };\n\n if (process.env.TURBOPACK === \"1\" || process.env.TURBOPACK === \"auto\") {\n addYakTurbopack(nextConfig, yakOptions, {\n ...yakPluginOptions,\n importMode: { type: \"DataUrl\" },\n });\n } else {\n addYakWebpack(nextConfig, yakOptions, {\n ...yakPluginOptions,\n importMode: {\n type: \"InlineMatchResource\",\n transpilation: yakOptions.experiments?.transpilationMode ?? \"CssModule\",\n },\n });\n }\n return nextConfig;\n};\n\n/**\n * Configure Turbopack with yak loader for CSS-in-JS transformation\n * @param nextConfig - Next.js configuration object\n * @param yakOptions - Yak configuration options\n * @param yakPluginOptions - Processed plugin options for yak-swc\n */\nfunction addYakTurbopack(\n nextConfig: NextConfig,\n yakOptions: YakConfigOptions,\n yakPluginOptions: {\n minify: boolean;\n basePath: string;\n prefix?: string;\n displayNames: boolean;\n importMode: { type: string };\n },\n) {\n // turbopack can't handle options with undefined values, so we remove them\n const yakLoader = removeUndefinedRecursive({\n loader: path.join(currentDir, \"../loaders/turbo-loader.js\"),\n options: {\n yakOptions: yakOptions,\n yakPluginOptions: yakPluginOptions,\n },\n }) as { loader: string; options: {} };\n\n nextConfig.turbopack ||= {};\n nextConfig.turbopack.rules ||= {};\n\n const ruleKey = \"*.{js,jsx,cjs,mjs,ts,tsx,cts,mts}\";\n nextConfig.turbopack.rules[ruleKey] = {\n loaders: [],\n ...nextConfig.turbopack.rules[ruleKey],\n };\n nextConfig.turbopack.rules[ruleKey].loaders.push(yakLoader);\n\n // Configure resolveAlias for custom yak context (similar to webpack)\n // This allows users to provide a custom context file that will be used\n // instead of the default baseContext\n const yakContext = resolveYakContext(yakOptions.contextPath, process.cwd());\n if (yakContext) {\n nextConfig.turbopack.resolveAlias ||= {};\n nextConfig.turbopack.resolveAlias[\"next-yak/context/baseContext\"] =\n // This is a hack around the fact that turbopack currently only supports relative paths\n // turbopack: \"server relative imports are not implemented yet\"\n // Relative is quite dangerous here as it relies on the cwd being the starting point\n `./${path.relative(process.cwd(), yakContext)}`;\n }\n}\n\n/**\n * Configure Webpack with yak SWC plugin and webpack loader for CSS-in-JS transformation\n * @param nextConfig - Next.js configuration object\n * @param yakOptions - Yak configuration options\n * @param yakPluginOptions - Processed plugin options for yak-swc\n */\nfunction addYakWebpack(\n nextConfig: NextConfig,\n yakOptions: YakConfigOptions,\n yakPluginOptions: {\n minify: boolean;\n basePath: string;\n prefix?: string;\n displayNames: boolean;\n importMode: { type: string; transpilation?: string };\n },\n) {\n // Add SWC plugin for Webpack\n nextConfig.experimental ||= {};\n nextConfig.experimental.swcPlugins ||= [];\n nextConfig.experimental.swcPlugins.push([\"yak-swc\", yakPluginOptions]);\n\n // Configure webpack loader\n const previousConfig = nextConfig.webpack;\n nextConfig.webpack = (webpackConfig, options) => {\n if (previousConfig) {\n webpackConfig = previousConfig(webpackConfig, options);\n }\n\n webpackConfig.module.rules.push({\n test:\n yakOptions.experiments?.transpilationMode === \"Css\"\n ? /\\.yak\\.css$/\n : /\\.yak\\.module\\.css$/,\n loader: path.join(currentDir, \"../loaders/webpack-loader.cjs\"),\n options: yakOptions,\n });\n\n // With the following alias the internal next-yak code\n // is able to import a context which works for server components\n const yakContext = resolveYakContext(\n yakOptions.contextPath,\n webpackConfig.context || process.cwd(),\n );\n if (yakContext) {\n webpackConfig.resolve.alias[\"next-yak/context/baseContext\"] = yakContext;\n }\n\n return webpackConfig;\n };\n}\n\n/**\n * Recursively removes undefined values from an object or array.\n *\n * This function deeply traverses the input object/array and creates a new structure\n * with all undefined values filtered out. For objects, properties with undefined values\n * are omitted. For arrays, undefined elements are removed from the result.\n *\n * @param obj - The object or array to process\n * @returns A new object/array with undefined values removed, or the original value if no changes were needed\n */\nfunction removeUndefinedRecursive<T>(obj: T): {} {\n if (typeof obj !== \"object\" || obj === null) {\n return obj as {};\n }\n\n if (Array.isArray(obj)) {\n const filtered: unknown[] = [];\n for (let i = 0; i < obj.length; i++) {\n const processed = removeUndefinedRecursive(obj[i]);\n if (processed !== undefined) {\n filtered.push(processed);\n }\n }\n return filtered as {};\n }\n\n const newObj: Record<string, unknown> = {};\n let hasChanges = false;\n\n for (const key in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n const value = removeUndefinedRecursive((obj as any)[key]);\n if (value !== undefined) {\n newObj[key] = value;\n hasChanges = true;\n }\n }\n }\n\n return hasChanges ? (newObj as {}) : obj;\n}\n\n/**\n * Try to resolve yak\n */\nfunction resolveYakContext(contextPath: string | undefined, cwd: string) {\n const yakContext = contextPath\n ? path.resolve(cwd, contextPath)\n : path.resolve(cwd, \"yak.context\");\n const extensions = [\"\", \".ts\", \".tsx\", \".js\", \".jsx\"];\n for (const extension in extensions) {\n const fileName = yakContext + extensions[extension];\n if (existsSync(fileName)) {\n return fileName;\n }\n }\n if (contextPath) {\n throw new Error(`Could not find yak context file at ${yakContext}`);\n }\n}\n\n// Wrapper to allow sync, async, and function configuration of Next.js\n/**\n * Add Yak to your Next.js app\n *\n * @usage\n *\n * ```ts\n * // next.config.js\n * const { withYak } = require(\"next-yak/withYak\");\n * const nextConfig = {\n * // your next config here\n * };\n * module.exports = withYak(nextConfig);\n * ```\n *\n * With a custom yakConfig\n *\n * ```ts\n * // next.config.js\n * const { withYak } = require(\"next-yak/withYak\");\n * const nextConfig = {\n * // your next config here\n * };\n * const yakConfig = {\n * // Optional prefix for generated CSS identifiers\n * prefix: \"my-app\",\n * // Other yak config options...\n * };\n * module.exports = withYak(yakConfig, nextConfig);\n * ```\n */\nexport const withYak: {\n <\n T extends\n | Record<string, any>\n | ((...args: any[]) => Record<string, any>)\n | ((...args: any[]) => Promise<Record<string, any>>),\n >(\n yakOptions: YakConfigOptions,\n nextConfig: T,\n ): T;\n // no yakConfig\n <\n T extends\n | Record<string, any>\n | ((...args: any[]) => Record<string, any>)\n | ((...args: any[]) => Promise<Record<string, any>>),\n >(\n nextConfig: T,\n _?: undefined,\n ): T;\n} = (maybeYakOptions, nextConfig) => {\n if (nextConfig === undefined) {\n return withYak({}, maybeYakOptions);\n }\n // If the second parameter is present the first parameter must be a YakConfigOptions\n const yakOptions = maybeYakOptions as YakConfigOptions;\n if (typeof nextConfig === \"function\") {\n /**\n * A NextConfig can be a sync or async function\n * https://nextjs.org/docs/pages/api-reference/next-config-js\n * @param {any[]} args\n */\n return (...args) => {\n /** Dynamic Next Configs can be async or sync */\n const config = nextConfig(...args) as NextConfig | Promise<NextConfig>;\n return config instanceof Promise\n ? config.then((config) => addYak(yakOptions, config))\n : add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,OAAO,UAAU,eAAe,KAAK,KAAK,GAAG,GAAG;AAClD,YAAM,QAAQ,yBAA0B,IAAY,GAAG,CAAC;AACxD,UAAI,UAAU,QAAW;AACvB,eAAO,GAAG,IAAI;AACd,qBAAa;AAAA,MACf;AAAA,IACF;AAAA,EACF;AAEA,SAAO,aAAc,SAAgB;AACvC;AAKA,SAAS,kBAAkB,aAAiC,KAAa;AACvE,QAAM,aAAa,cACf,KAAK,QAAQ,KAAK,WAAW,IAC7B,KAAK,QAAQ,KAAK,aAAa;AACnC,QAAM,aAAa,CAAC,IAAI,OAAO,QAAQ,OAAO,MAAM;AACpD,aAAW,aAAa,YAAY;AAClC,UAAM,WAAW,aAAa,WAAW,SAAS;AAClD,QAAI,WAAW,QAAQ,GAAG;AACxB,aAAO;AAAA,IACT;AAAA,EACF;AACA,MAAI,aAAa;AACf,UAAM,IAAI,MAAM,sCAAsC,UAAU,EAAE;AAAA,EACpE;AACF;AAiCO,IAAM,UAoBT,CAAC,iBAAiB,eAAe;AACnC,MAAI,eAAe,QAAW;AAC5B,WAAO,QAAQ,CAAC,GAAG,eAAe;AAAA,EACpC;AAEA,QAAM,aAAa;AACnB,MAAI,OAAO,eAAe,YAAY;AAMpC,WAAO,IAAI,SAAS;AAElB,YAAM,SAAS,WAAW,GAAG,IAAI;AACjC,aAAO,kBAAkB,UACrB,OAAO,KAAK,CAACA,YAAW,OAAO,YAAYA,OAAM,CAAC,IAClD,OAAO,YAAY,MAAM;AAAA,IAC/B;AAAA,EACF;AACA,SAAO,OAAO,YAAY,UAAU;AACtC;","names":["config"]}
@@ -10,8 +10,9 @@ import { createDebugLogger } from "./lib/debugLogger.js";
10
10
  import { extractCss } from "./lib/extractCss.js";
11
11
  import { parseExports } from "./lib/resolveCrossFileSelectors.js";
12
12
 
13
- const require = createRequire(import.meta.url);
14
- const yakSwcPluginPath = require.resolve("yak-swc");
13
+ const universalRequire =
14
+ typeof require === "undefined" ? createRequire(import.meta.url) : require;
15
+ const yakSwcPluginPath = universalRequire.resolve("yak-swc");
15
16
 
16
17
  /**
17
18
  * This loader transforms styled-components styles to a static data-url import
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-yak",
3
- "version": "8.0.1",
3
+ "version": "8.0.2",
4
4
  "type": "module",
5
5
  "types": "./dist/",
6
6
  "sideEffects": false,
@@ -60,14 +60,14 @@
60
60
  "require": "./dist/jsx-dev-runtime.cjs",
61
61
  "import": "./dist/jsx-dev-runtime.js"
62
62
  },
63
- "./loaders/webpack-loader": "./dist/loaders/webpack-loader.js",
64
- "./loaders/turbopack-loader": "./dist/loaders/turbopack-loader.js"
63
+ "./loaders/webpack-loader": "./dist/loaders/webpack-loader.cjs",
64
+ "./loaders/turbopack-loader": "./dist/loaders/turbopack-loader.cjs"
65
65
  },
66
66
  "dependencies": {
67
67
  "@babel/parser": "^7.28.5",
68
68
  "@babel/traverse": "^7.28.5",
69
69
  "@swc/core": "1.13.20",
70
- "yak-swc": "8.0.1"
70
+ "yak-swc": "8.0.2"
71
71
  },
72
72
  "devDependencies": {
73
73
  "@testing-library/jest-dom": "6.9.1",
@@ -81,7 +81,7 @@
81
81
  "@types/webpack": "5.28.5",
82
82
  "fast-glob": "3.3.3",
83
83
  "jsdom": "27.0.1",
84
- "next": "16.0.1",
84
+ "next": "16.0.4",
85
85
  "react": "19.2.0",
86
86
  "tsup": "8.5.0",
87
87
  "typescript": "5.9.3",
package/withYak/index.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  /// <reference types="node" />
2
+ import type { NextConfig } from "next";
2
3
  import { existsSync } from "node:fs";
3
4
  import path, { dirname } from "node:path";
4
5
  import { fileURLToPath } from "node:url";
5
- import { NextConfig } from "../../example/node_modules/next/dist/server/config.js";
6
6
 
7
7
  const currentDir =
8
8
  typeof __dirname !== "undefined"
@@ -151,7 +151,7 @@ function addYakWebpack(
151
151
  yakOptions.experiments?.transpilationMode === "Css"
152
152
  ? /\.yak\.css$/
153
153
  : /\.yak\.module\.css$/,
154
- loader: path.join(currentDir, "../loaders/webpack-loader.js"),
154
+ loader: path.join(currentDir, "../loaders/webpack-loader.cjs"),
155
155
  options: yakOptions,
156
156
  });
157
157
 
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../loaders/turbo-loader.ts","../../cross-file-resolver/parseModule.ts","../../cross-file-resolver/Errors.ts","../../cross-file-resolver/resolveCrossFileConstant.ts","../../loaders/lib/debugLogger.ts","../../loaders/lib/extractCss.ts","../../loaders/lib/resolveCrossFileSelectors.ts"],"sourcesContent":["import { transform as swcTransform } from \"@swc/core\";\nimport { createRequire } from \"node:module\";\nimport { dirname } from \"node:path\";\nimport { createContext, runInContext } from \"node:vm\";\nimport type { LoaderContext } from \"webpack\";\nimport { parseModule } from \"../cross-file-resolver/parseModule.js\";\nimport { resolveCrossFileConstant } from \"../cross-file-resolver/resolveCrossFileConstant.js\";\nimport type { YakConfigOptions } from \"../withYak/index.js\";\nimport { createDebugLogger } from \"./lib/debugLogger.js\";\nimport { extractCss } from \"./lib/extractCss.js\";\nimport { parseExports } from \"./lib/resolveCrossFileSelectors.js\";\n\nconst require = createRequire(import.meta.url);\nconst yakSwcPluginPath = require.resolve(\"yak-swc\");\n\n/**\n * This loader transforms styled-components styles to a static data-url import\n * The compile-time nexy-yak transformation takes javascript/typescript as input,\n * strips all inline css code and adds the css as static css urls\n * e.g.: `import \"data:text/css;base64,\"`\n */\nexport default async function cssExtractLoader(\n this: LoaderContext<{ yakOptions: YakConfigOptions; yakPluginOptions: any }>,\n code: string,\n sourceMap: string | undefined,\n): Promise<string | void> {\n const callback = this.async();\n\n // process only files which include next-yak for maximal compile performance\n if (!code.includes(\"next-yak\")) {\n return callback(null, code, sourceMap);\n }\n\n const {\n yakPluginOptions,\n yakOptions: { experiments },\n } = this.getOptions();\n const debugLog = createDebugLogger(this, experiments?.debug);\n const resolveTurbopack = this.getResolve({});\n const transform = createTransform(yakPluginOptions, yakSwcPluginPath);\n\n const resolveFn = (specifier: string, importer: string) => {\n return new Promise<string>((resolve, reject) => {\n resolveTurbopack(dirname(importer), specifier, (err, result) => {\n if (err) return reject(err);\n if (!result) return reject(new Error(`Could not resolve ${specifier}`));\n resolve(result);\n });\n });\n };\n\n const fsReadFile = (filePath: string) =>\n new Promise<string>((resolve, reject) =>\n this.fs.readFile(filePath, \"utf-8\", (err, result) => {\n if (err) return reject(err);\n if (!result) return reject(new Error(`File not found: ${filePath}`));\n resolve(result);\n }),\n );\n\n const result = await transform(\n code,\n this.resourcePath,\n this.rootContext,\n sourceMap,\n );\n debugLog(\"ts\", result.code);\n\n let css = extractCss(result.code, \"Css\");\n debugLog(\"css\", css);\n\n const { resolved } = await resolveCrossFileConstant(\n {\n parse: (modulePath) => {\n return parseModule(\n {\n transpilationMode: \"Css\",\n extractExports: async (modulePath) => {\n const sourceContents = await fsReadFile(modulePath);\n return parseExports(sourceContents);\n },\n getTransformed: async (modulePath) => {\n const sourceContent = await fsReadFile(modulePath);\n return transform(sourceContent, modulePath, this.rootContext);\n },\n evaluateYakModule: async (modulePath: string) => {\n const code = await fsReadFile(modulePath);\n\n const transformed = await swcTransform(code, {\n filename: modulePath,\n sourceFileName: modulePath,\n jsc: {\n transform: {\n react: { runtime: \"automatic\" },\n },\n experimental: {\n plugins: [[yakSwcPluginPath, yakPluginOptions]],\n },\n },\n module: {\n type: \"commonjs\",\n },\n });\n\n const moduleObject = { exports: {} };\n const context = createContext({\n require: (path: string) => {\n throw new Error(\n `Yak files cannot have imports in turbopack.\\n` +\n `Found require/import usage in: ${modulePath} to import: ${path}.\\n` +\n `Yak files should be self-contained and only export constants or styled components.\\n` +\n `This will be resolved once Vercel adds \"this.importModule\" support for turbopack.`,\n );\n },\n __filename: modulePath,\n __dirname: dirname(modulePath),\n global: {},\n console,\n Buffer,\n process,\n setTimeout,\n clearTimeout,\n setInterval,\n clearInterval,\n setImmediate,\n clearImmediate,\n exports: moduleObject.exports,\n module: moduleObject,\n });\n runInContext(transformed.code, context);\n\n return moduleObject.exports;\n },\n },\n modulePath,\n );\n },\n resolve: resolveFn,\n },\n this.resourcePath,\n css,\n );\n\n const dataUrl = result.code\n .split(\"\\n\")\n .find((line) => line.includes(\"data:text/css;base64\"))!;\n\n const codeWithCrossFileResolved = result.code.replace(\n dataUrl,\n `import \"data:text/css;base64,${Buffer.from(resolved).toString(\"base64\")}\"`,\n );\n\n debugLog(\"css-resolved\", resolved);\n return callback(null, codeWithCrossFileResolved, result.map);\n}\n\nfunction createTransform(yakPluginOptions: any, yakSwcPluginPath: string) {\n return (\n data: string,\n modulePath: string,\n rootPath: string,\n sourceMap?: any,\n ) =>\n // https://github.com/vercel/next.js/blob/canary/packages/next/src/build/webpack/loaders/next-swc-loader.ts#L143\n swcTransform(data, {\n filename: modulePath,\n inputSourceMap: sourceMap,\n sourceMaps: true,\n sourceFileName: modulePath,\n sourceRoot: rootPath,\n jsc: {\n experimental: {\n plugins: [[yakSwcPluginPath, yakPluginOptions]],\n },\n transform: {\n react: {\n runtime: \"preserve\",\n },\n },\n target: \"es2022\",\n loose: false,\n minify: {\n compress: false,\n mangle: false,\n },\n preserveAllComments: true,\n },\n minify: false,\n isModule: true,\n });\n}\n","import { type Cache } from \"./types.js\";\n\nexport async function parseModule(\n context: ParseContext,\n modulePath: string,\n): Promise<ParsedModule> {\n try {\n const isYak =\n modulePath.endsWith(\".yak.ts\") ||\n modulePath.endsWith(\".yak.tsx\") ||\n modulePath.endsWith(\".yak.js\") ||\n modulePath.endsWith(\".yak.jsx\");\n\n // handle yak file by evaluating and mapping exported value to the\n // `ModuleExport` format. This operation is not cached to always get a fresh\n // value from those modules\n if (isYak && context.evaluateYakModule) {\n const yakModule = await context.evaluateYakModule(modulePath);\n const yakExports = objectToModuleExport(yakModule);\n\n return {\n type: \"yak\",\n exports: { importYak: false, named: yakExports, all: [] },\n path: modulePath,\n };\n }\n\n if (context.cache?.parse === undefined) {\n return uncachedParseModule(context, modulePath);\n }\n\n const cached = context.cache.parse.get(modulePath);\n if (cached === undefined) {\n // We cache the parsed file to avoid re-parsing it.\n // It's ok, that initial parallel requests to the same file will parse it multiple times.\n // This avoid deadlocks do to the fact that we load multiple modules in the chain for cross file references.\n const parsedModule = await uncachedParseModule(context, modulePath);\n\n context.cache.parse.set(modulePath, parsedModule);\n if (context.cache.parse.addDependency) {\n context.cache.parse.addDependency(modulePath, modulePath);\n }\n return parsedModule;\n }\n\n return cached;\n } catch (error) {\n throw new Error(\n `Error parsing file ${modulePath}: ${(error as Error).message}`,\n );\n }\n}\n\nexport async function uncachedParseModule(\n context: ParseContext,\n modulePath: string,\n): Promise<ParsedModule> {\n const exports = await context.extractExports(modulePath);\n\n // early exit if no yak import was found\n if (!exports.importYak) {\n return {\n type: \"regular\",\n path: modulePath,\n exports,\n };\n }\n\n const transformed = await context.getTransformed(modulePath);\n const mixins = parseMixins(transformed.code);\n const styledComponents = parseStyledComponents(\n transformed.code,\n context.transpilationMode,\n );\n\n return {\n type: \"regular\",\n path: modulePath,\n js: transformed,\n exports,\n styledComponents,\n mixins,\n };\n}\n\nfunction parseMixins(sourceContents: string): Record<string, Mixin> {\n // Mixins are always in the following format:\n // /*YAK EXPORTED MIXIN:fancy:aspectRatio:16:9\n // css\n // */\n const mixinParts = sourceContents.split(\"/*YAK EXPORTED MIXIN:\");\n let mixins: Record<\n string,\n { type: \"mixin\"; value: string; nameParts: string[] }\n > = {};\n\n for (let i = 1; i < mixinParts.length; i++) {\n const [comment] = mixinParts[i].split(\"*/\", 1);\n const position = comment.indexOf(\"\\n\");\n const name = comment.slice(0, position);\n const value = comment.slice(position + 1);\n mixins[name] = {\n type: \"mixin\",\n value,\n nameParts: name.split(\":\").map((part) => decodeURIComponent(part)),\n };\n }\n return mixins;\n}\n\nfunction parseStyledComponents(\n sourceContents: string,\n transpilationMode?: \"Css\" | \"CssModule\",\n): Record<string, StyledComponent> {\n // cross-file Styled Components are always in the following format:\n // /*YAK EXPORTED STYLED:ComponentName:ClassName*/\n const styledParts = sourceContents.split(\"/*YAK EXPORTED STYLED:\");\n let styledComponents: Record<string, StyledComponent> = {};\n\n for (let i = 1; i < styledParts.length; i++) {\n const [comment] = styledParts[i].split(\"*/\", 1);\n const [componentName, className] = comment.split(\":\");\n styledComponents[componentName] = {\n type: \"styled-component\",\n nameParts: componentName.split(\".\"),\n value:\n transpilationMode === \"Css\"\n ? `.${className}`\n : `:global(.${className})`,\n };\n }\n\n return styledComponents;\n}\n\nfunction objectToModuleExport(object: object) {\n return Object.fromEntries(\n Object.entries(object).map(([key, value]): [string, ModuleExport] => {\n if (typeof value === \"string\" || typeof value === \"number\") {\n return [key, { type: \"constant\" as const, value }];\n } else if (value && (typeof value === \"object\" || Array.isArray(value))) {\n return [\n key,\n { type: \"record\" as const, value: objectToModuleExport(value) },\n ];\n } else {\n return [key, { type: \"unsupported\" as const, hint: String(value) }];\n }\n }),\n );\n}\n\nexport type ParseContext = {\n cache?: { parse?: Cache<ParsedModule> };\n transpilationMode?: \"Css\" | \"CssModule\";\n evaluateYakModule?: (\n modulePath: string,\n ) => Promise<Record<string, unknown>> | Record<string, unknown>;\n extractExports: (\n modulePath: string,\n ) => Promise<ModuleExports> | ModuleExports;\n getTransformed: (\n modulePath: string,\n ) => Promise<{ code: string; map?: string }> | { code: string; map?: string };\n};\n\nexport type ModuleExports = {\n importYak: boolean;\n named: Record<string, ModuleExport>;\n all: string[];\n};\n\nexport type ConstantExport = { type: \"constant\"; value: string | number };\nexport type RecordExport = {\n type: \"record\";\n value: Record<string, ModuleExport>;\n};\nexport type UnsupportedExport = { type: \"unsupported\"; hint?: string };\nexport type ReExport = { type: \"re-export\"; name: string; from: string };\nexport type NamespaceReExport = { type: \"namespace-re-export\"; from: string };\nexport type TagTemplateExport = { type: \"tag-template\" };\n\nexport type ModuleExport =\n | ConstantExport\n | TagTemplateExport\n | RecordExport\n | UnsupportedExport\n | ReExport\n | NamespaceReExport;\n\nexport type ParsedModule = {\n path: string;\n exports: ModuleExports;\n} & (\n | {\n type: \"regular\";\n js?: { code: string; map?: string };\n styledComponents?: Record<string, StyledComponent>;\n mixins?: Record<string, Mixin>;\n }\n | {\n type: \"yak\";\n }\n);\n\nexport type StyledComponent = {\n type: \"styled-component\";\n value: string;\n nameParts: string[];\n};\n\nexport type Mixin = { type: \"mixin\"; value: string; nameParts: string[] };\n","export class CauseError extends Error {\n circular?: boolean;\n constructor(message: string, options?: { cause?: unknown }) {\n super(\n `${message}${options?.cause ? `\\n Caused by: ${typeof options.cause === \"object\" && options.cause !== null && \"message\" in options.cause ? options.cause.message : String(options.cause)}` : \"\"}`,\n );\n\n if (options?.cause instanceof CauseError && options.cause.circular) {\n this.circular = true;\n }\n }\n}\n\nexport class ResolveError extends CauseError {}\n\nexport class CircularDependencyError extends CauseError {\n constructor(message: string, options?: { cause?: unknown }) {\n super(message, options);\n this.circular = true;\n }\n}\n","import type {\n ConstantExport,\n ModuleExport,\n ParsedModule,\n RecordExport,\n} from \"./parseModule.js\";\nimport { Cache } from \"./types.js\";\nimport { CauseError, CircularDependencyError, ResolveError } from \"./Errors.js\";\n\nconst yakCssImportRegex =\n // Make mixin and selector non optional once we dropped support for the babel plugin\n /--yak-css-import\\:\\s*url\\(\"([^\"]+)\",?(|mixin|selector)\\)(;?)/g;\n\n/**\n * Resolves cross-file selectors in css files\n *\n * e.g.:\n * theme.ts:\n * ```ts\n * export const colors = {\n * primary: \"#ff0000\",\n * secondary: \"#00ff00\",\n * };\n * ```\n *\n * styles.ts:\n * ```ts\n * import { colors } from \"./theme\";\n * export const button = css`\n * background-color: ${colors.primary};\n * `;\n */\nexport async function resolveCrossFileConstant(\n context: ResolveContext,\n filePath: string,\n css: string,\n): Promise<{ resolved: string; dependencies: string[] }> {\n const resolveCrossFileConstant = context.cache?.resolveCrossFileConstant;\n if (resolveCrossFileConstant === undefined) {\n return uncachedResolveCrossFileConstant(context, filePath, css);\n }\n\n const cacheKey = await sha1(filePath + \":\" + css);\n\n const cached = resolveCrossFileConstant.get(cacheKey);\n\n if (cached === undefined) {\n const resolvedCrossFilConstantPromise = uncachedResolveCrossFileConstant(\n context,\n filePath,\n css,\n );\n resolveCrossFileConstant.set(cacheKey, resolvedCrossFilConstantPromise);\n\n if (resolveCrossFileConstant.addDependency) {\n resolveCrossFileConstant.addDependency(cacheKey, filePath);\n resolvedCrossFilConstantPromise.then((value) => {\n for (const dep of value.dependencies) {\n resolveCrossFileConstant!.addDependency!(cacheKey, dep);\n }\n });\n }\n\n return resolvedCrossFilConstantPromise;\n }\n\n return cached;\n}\n\nexport async function uncachedResolveCrossFileConstant(\n context: ResolveContext,\n filePath: string,\n css: string,\n): Promise<{ resolved: string; dependencies: string[] }> {\n const yakImports = await parseYakCssImport(context, filePath, css);\n\n if (yakImports.length === 0) {\n return { resolved: css, dependencies: [] };\n }\n\n try {\n const dependencies = new Set<string>();\n\n const resolvedValues = await Promise.all(\n yakImports.map(async ({ moduleSpecifier, specifier }) => {\n const { resolved: resolvedModule } = await resolveModule(\n context,\n moduleSpecifier,\n );\n\n const resolvedValue = await resolveModuleSpecifierRecursively(\n context,\n resolvedModule,\n specifier,\n );\n\n for (const dependency of resolvedValue.from) {\n dependencies.add(dependency);\n }\n\n return resolvedValue;\n }),\n );\n\n // Replace the imports with the resolved values\n let result = css;\n for (let i = yakImports.length - 1; i >= 0; i--) {\n const { position, size, importKind, specifier, semicolon } =\n yakImports[i];\n const resolved = resolvedValues[i];\n\n let replacement: string;\n\n if (resolved.type === \"unresolved-tag\") {\n // tag that could not be resolved to styled-components or mixins are\n // interpolated to produce valid CSS with minimal impact (since we don't\n // know what the value should actually be). For mixins (CSS rules) we\n // interpolate an empty string, and for selectors we interpolate\n // \"undefined\" (a selector that would match nothing)\n replacement = importKind === \"mixin\" ? \"\" : \"undefined\";\n } else {\n if (importKind === \"selector\") {\n if (\n resolved.type !== \"styled-component\" &&\n resolved.type !== \"constant\"\n ) {\n throw new Error(\n `Found \"${\n resolved.type\n }\" but expected a selector - did you forget a semicolon after \"${specifier.join(\n \".\",\n )}\"?`,\n );\n }\n }\n\n replacement =\n resolved.type === \"styled-component\"\n ? resolved.value\n : resolved.value +\n // resolved.value can be of two different types:\n // - mixin:\n // ${mixinName};\n // - constant:\n // color: ${value};\n // For mixins the semicolon is already included in the value\n // but for constants it has to be added manually\n ([\"}\", \";\"].includes(String(resolved.value).trimEnd().slice(-1))\n ? \"\"\n : semicolon);\n }\n\n result =\n result.slice(0, position) +\n String(replacement) +\n result.slice(position + size);\n }\n\n return { resolved: result, dependencies: Array.from(dependencies) };\n } catch (error) {\n throw new CauseError(\n `Error while resolving cross-file selectors in file \"${filePath}\"`,\n { cause: error },\n );\n }\n}\n\n/**\n * Search for --yak-css-import: url(\"path/to/module\") in the css\n */\nasync function parseYakCssImport(\n context: ResolveContext,\n filePath: string,\n css: string,\n): Promise<YakCssImport[]> {\n const yakImports: YakCssImport[] = [];\n\n for (const match of css.matchAll(yakCssImportRegex)) {\n const [fullMatch, encodedArguments, importKind, semicolon] = match;\n const [moduleSpecifier, ...specifier] = encodedArguments\n .split(\":\")\n .map((entry) => decodeURIComponent(entry));\n\n yakImports.push({\n encodedArguments,\n moduleSpecifier: await context.resolve(moduleSpecifier, filePath),\n specifier,\n importKind: importKind as YakImportKind,\n semicolon,\n position: match.index,\n size: fullMatch.length,\n });\n }\n\n return yakImports;\n}\n\nasync function resolveModule(context: ResolveContext, filePath: string) {\n if (context.cache?.resolve === undefined) {\n return uncachedResolveModule(context, filePath);\n }\n\n const cached = context.cache.resolve.get(filePath);\n if (cached === undefined) {\n const resolvedPromise = uncachedResolveModule(context, filePath);\n context.cache.resolve.set(filePath, resolvedPromise);\n\n if (context.cache.resolve.addDependency) {\n context.cache.resolve.addDependency(filePath, filePath);\n resolvedPromise.then((value) => {\n for (const dep of value.dependencies) {\n context.cache!.resolve!.addDependency!(filePath, dep);\n }\n });\n }\n\n return resolvedPromise;\n }\n\n return cached;\n}\n\nasync function uncachedResolveModule(\n context: ResolveContext,\n filePath: string,\n): Promise<{ resolved: ResolvedModule; dependencies: string[] }> {\n const parsedModule = await context.parse(filePath);\n\n const exports = parsedModule.exports as ResolvedExports;\n\n if (parsedModule.type !== \"regular\") {\n return {\n resolved: {\n path: parsedModule.path,\n exports,\n },\n dependencies: [],\n };\n }\n\n const dependencies = new Set<string>();\n\n // Reconcile styled-component \"name\" structure with export structure\n if (parsedModule.styledComponents) {\n Object.values(parsedModule.styledComponents).map((styledComponent) => {\n if (styledComponent.nameParts.length === 1) {\n exports.named[styledComponent.nameParts[0]] = {\n type: \"styled-component\",\n className: styledComponent.value,\n };\n } else {\n let exportEntry = exports.named[styledComponent.nameParts[0]];\n\n if (!exportEntry) {\n exportEntry = { type: \"record\", value: {} };\n exports.named[styledComponent.nameParts[0]] = exportEntry;\n } else if (exportEntry.type !== \"record\") {\n throw new CauseError(`Error parsing file \"${parsedModule.path}\"`, {\n cause: `\"${styledComponent.nameParts[0]}\" is not a record`,\n });\n }\n\n let current = exportEntry.value;\n for (let i = 1; i < styledComponent.nameParts.length - 1; i++) {\n let next = current[styledComponent.nameParts[i]];\n if (!next) {\n next = { type: \"record\", value: {} };\n current[styledComponent.nameParts[i]] = next;\n } else if (next.type !== \"record\") {\n throw new CauseError(`Error parsing file \"${parsedModule.path}\"`, {\n cause: `\"${styledComponent.nameParts.slice(0, i + 1).join(\".\")}\" is not a record`,\n });\n }\n current = next.value;\n }\n current[\n styledComponent.nameParts[styledComponent.nameParts.length - 1]\n ] = {\n type: \"styled-component\",\n className: styledComponent.value,\n };\n }\n });\n }\n\n // Recursively resolve cross-file constants in mixins\n // e.g. cross file mixins inside a cross file mixin\n // or a cross file selector inside a cross file mixin\n if (parsedModule.mixins) {\n await Promise.all(\n Object.values(parsedModule.mixins).map(async (mixin) => {\n const { resolved, dependencies: deps } = await resolveCrossFileConstant(\n context,\n parsedModule.path,\n mixin.value,\n );\n\n for (const dep of deps) {\n dependencies.add(dep);\n }\n\n if (mixin.nameParts.length === 1) {\n exports.named[mixin.nameParts[0]] = {\n type: \"mixin\",\n value: resolved,\n };\n } else {\n let exportEntry = exports.named[mixin.nameParts[0]];\n\n if (!exportEntry) {\n exportEntry = { type: \"record\", value: {} };\n exports.named[mixin.nameParts[0]] = exportEntry;\n } else if (exportEntry.type !== \"record\") {\n throw new CauseError(`Error parsing file \"${parsedModule.path}\"`, {\n cause: `\"${mixin.nameParts[0]}\" is not a record`,\n });\n }\n\n let current = exportEntry.value;\n for (let i = 1; i < mixin.nameParts.length - 1; i++) {\n let next = current[mixin.nameParts[i]];\n if (!next) {\n next = { type: \"record\", value: {} };\n current[mixin.nameParts[i]] = next;\n } else if (next.type !== \"record\") {\n throw new CauseError(\n `Error parsing file \"${parsedModule.path}\"`,\n {\n cause: `\"${mixin.nameParts.slice(0, i + 1).join(\".\")}\" is not a record`,\n },\n );\n }\n current = next.value;\n }\n current[mixin.nameParts[mixin.nameParts.length - 1]] = {\n type: \"mixin\",\n value: resolved,\n };\n }\n }),\n );\n }\n return {\n resolved: {\n path: parsedModule.path,\n exports,\n },\n dependencies: Array.from(dependencies),\n };\n}\n\nasync function resolveModuleSpecifierRecursively(\n context: ResolveContext,\n resolvedModule: ResolvedModule,\n specifiers: string[],\n seen = new Set<string>(),\n): Promise<ResolvedCssImport> {\n const exportName = specifiers[0];\n const exportValue = resolvedModule.exports.named[exportName];\n if (exportValue !== undefined) {\n if (seen.has(resolvedModule.path + \":\" + exportName)) {\n throw new CircularDependencyError(\n `Unable to resolve \"${specifiers.join(\".\")}\" in module \"${\n resolvedModule.path\n }\"`,\n { cause: \"Circular dependency detected\" },\n );\n }\n\n seen.add(resolvedModule.path + \":\" + exportName);\n return resolveModuleExport(\n context,\n resolvedModule.path,\n exportValue,\n specifiers,\n seen,\n );\n }\n\n let i = 1;\n for (const from of resolvedModule.exports.all) {\n if (context.exportAllLimit && i++ > context.exportAllLimit) {\n throw new ResolveError(\n `Unable to resolve \"${specifiers.join(\".\")}\" in module \"${\n resolvedModule.path\n }\"`,\n {\n cause: `More than ${context.exportAllLimit} star exports are not supported for performance reasons`,\n },\n );\n }\n\n try {\n const resolved = await resolveModuleExport(\n context,\n resolvedModule.path,\n {\n type: \"re-export\",\n from,\n name: exportName,\n },\n specifiers,\n seen,\n );\n\n if (seen.has(resolvedModule.path + \":*\")) {\n throw new CircularDependencyError(\n `Unable to resolve \"${specifiers.join(\".\")}\" in module \"${\n resolvedModule.path\n }\"`,\n { cause: \"Circular dependency detected\" },\n );\n }\n\n seen.add(resolvedModule.path + \":*\");\n\n return resolved;\n } catch (error) {\n // ignore resolve error, it means the specifier was not found in the\n // current module, we just have to continue the loop.\n if (!(error instanceof ResolveError)) {\n throw error;\n }\n // if the cause of the error is a circular dependency down the road do not\n // ignore the error\n if (error.circular) {\n throw error;\n }\n }\n }\n\n throw new ResolveError(`Unable to resolve \"${specifiers.join(\".\")}\"`, {\n cause: `no matching export found in module \"${resolvedModule.path}\"`,\n });\n}\n\nasync function resolveModuleExport(\n context: ResolveContext,\n filePath: string,\n moduleExport: ResolvedExport,\n specifiers: string[],\n seen: Set<string>,\n): Promise<ResolvedCssImport> {\n try {\n switch (moduleExport.type) {\n case \"re-export\": {\n const { resolved: reExportedModule } = await resolveModule(\n context,\n await context.resolve(moduleExport.from, filePath),\n );\n const resolved = await resolveModuleSpecifierRecursively(\n context,\n reExportedModule,\n [moduleExport.name, ...specifiers.slice(1)],\n seen,\n );\n if (resolved) {\n resolved.from.push(filePath);\n }\n return resolved;\n }\n case \"namespace-re-export\": {\n const { resolved: reExportedModule } = await resolveModule(\n context,\n await context.resolve(moduleExport.from, filePath),\n );\n const resolved = await resolveModuleSpecifierRecursively(\n context,\n reExportedModule,\n specifiers.slice(1),\n seen,\n );\n if (resolved) {\n resolved.from.push(filePath);\n }\n return resolved;\n }\n case \"styled-component\": {\n return {\n type: \"styled-component\",\n from: [filePath],\n source: filePath,\n name: specifiers[specifiers.length - 1],\n value: moduleExport.className,\n };\n }\n // usually at this point `tag-template` exports where already resolved to\n // styled-components if a matching styled-component comment was generated\n // by yak-swc. So resolving a value to a `tag-template` at this stage\n // would mean that the user tried to use the result of a call to a\n // different tag-template than yak's styled in a template. This is usually\n // invalid.\n //\n // But there is an issue with Nextjs. Next build in two passes, once for\n // the server bundle, once for the client bundle. During the server-side\n // build, each module with the `\"use client\"` directive is transformed to\n // throw errors if the exported symbol are used. This transformation\n // removes the comments generated by `yak-swc`, so instead of the expected\n // `styled-component`, calls to `styled` resolve to a `tag-template`\n // (because no classname was found in the now absent comments).\n //\n // To summarize, if a \"use client\" bundle exports a styled component that\n // is used in a \"standard\" module, the resolve logic would throw with\n // \"unknown type tag-template\".\n //\n // To avoid this error, the resolve logic must handle those `tag-template`\n // with a special type `unresolved-tag`. Those will be interpolated to\n // valid CSS with minimal effect (to avoid CSS syntax error in the case of\n // Nextjs server build)\n case \"tag-template\": {\n return {\n type: \"unresolved-tag\",\n from: [filePath],\n source: filePath,\n name: specifiers[specifiers.length - 1],\n };\n }\n case \"constant\": {\n return {\n type: \"constant\",\n from: [filePath],\n source: filePath,\n value: moduleExport.value,\n };\n }\n case \"record\": {\n const resolvedInRecord = resolveSpecifierInRecord(\n moduleExport,\n specifiers[0],\n specifiers.slice(1),\n );\n return resolveModuleExport(\n context,\n filePath,\n resolvedInRecord,\n specifiers,\n seen,\n );\n }\n case \"mixin\": {\n return {\n type: \"mixin\",\n from: [filePath],\n source: filePath,\n value: moduleExport.value,\n };\n }\n }\n } catch (error) {\n throw new ResolveError(\n `Unable to resolve \"${specifiers.join(\".\")}\" in module \"${filePath}\"`,\n { cause: error },\n );\n }\n\n throw new ResolveError(\n `Unable to resolve \"${specifiers.join(\".\")}\" in module \"${filePath}\"`,\n { cause: `unknown type \"${moduleExport.type}\"` },\n );\n}\n\nfunction resolveSpecifierInRecord(\n record: ExtendedRecordExport,\n name: string,\n specifiers: string[],\n): ConstantExport | ResolvedStyledComponent | ResolvedMixin {\n if (specifiers.length === 0) {\n throw new ResolveError(\"did not expect an object\");\n }\n let depth = 0;\n let current: ResolvedExport = record;\n while (current && current.type === \"record\" && depth < specifiers.length) {\n current = current.value[specifiers[depth]];\n depth += 1;\n }\n\n if (current === undefined || depth !== specifiers.length) {\n throw new ResolveError(\n `Unable to resolve \"${specifiers.join(\".\")}\" in object/array \"${name}\"`,\n { cause: \"path not found\" },\n );\n }\n\n if (\n current.type === \"constant\" ||\n current.type === \"styled-component\" ||\n current.type === \"mixin\"\n ) {\n return current;\n }\n\n // mixins in .yak files are wrapped inside an object with a __yak key\n if (\n current.type === \"record\" &&\n \"__yak\" in current.value &&\n current.value.__yak.type === \"constant\"\n ) {\n return { type: \"mixin\", value: String(current.value.__yak.value) };\n }\n\n throw new ResolveError(\n `Unable to resolve \"${specifiers.join(\".\")}\" in object/array \"${name}\"`,\n { cause: \"only string and numbers are supported\" },\n );\n}\n\n/**\n * hex SHA-1 hash of a message using webcrypto\n * Keeps yak independent from node api (therefore executable in browser)\n */\nasync function sha1(message: string) {\n const resultBuffer = await globalThis.crypto.subtle.digest(\n \"SHA-1\",\n new TextEncoder().encode(message),\n );\n return Array.from(new Uint8Array(resultBuffer), (byte) =>\n byte.toString(16).padStart(2, \"0\"),\n ).join(\"\");\n}\n\ntype ResolvedCssImport =\n | {\n type: \"styled-component\";\n source: string;\n from: string[];\n name: string;\n value: string;\n }\n | {\n type: \"unresolved-tag\";\n source: string;\n from: string[];\n name: string;\n }\n | { type: \"mixin\"; source: string; from: string[]; value: string | number }\n | {\n type: \"constant\";\n source: string;\n from: string[];\n value: string | number;\n };\n\nexport type ResolveContext = {\n parse: (modulePath: string) => Promise<ParsedModule> | ParsedModule;\n cache?: {\n resolve?: Cache<\n Promise<{ resolved: ResolvedModule; dependencies: string[] }>\n >;\n resolveCrossFileConstant?: Cache<\n Promise<{ resolved: string; dependencies: string[] }>\n >;\n };\n exportAllLimit?: number;\n resolve: (specifier: string, importer: string) => Promise<string> | string;\n};\n\ntype YakImportKind = \"mixin\" | \"selector\";\n\ntype YakCssImport = {\n encodedArguments: string;\n moduleSpecifier: string;\n specifier: string[];\n importKind: YakImportKind;\n semicolon: string;\n position: number;\n size: number;\n};\n\nexport type ExtendedRecordExport = {\n type: \"record\";\n value: Record<string, ResolvedExport>;\n};\n\nexport type ResolvedMixin = { type: \"mixin\"; value: string };\nexport type ResolvedStyledComponent = {\n type: \"styled-component\";\n className: string;\n};\n\nexport type ResolvedExport =\n | Exclude<ModuleExport, RecordExport>\n | ExtendedRecordExport\n | ResolvedStyledComponent\n | ResolvedMixin;\n\nexport type ResolvedExports = {\n named: Record<string, ResolvedExport>;\n all: string[];\n};\n\nexport type ResolvedModule = {\n path: string;\n exports: ResolvedExports;\n};\n","import { relative } from \"path\";\nimport type { LoaderContext } from \"webpack\";\nimport type { YakConfigOptions } from \"../../withYak/index.js\";\n\n/**\n * Creates a debug logger function that conditionally logs messages\n * based on debug options and file paths.\n */\nexport function createDebugLogger(\n loaderContext: LoaderContext<unknown>,\n debugOptions: Required<YakConfigOptions>[\"experiments\"][\"debug\"],\n) {\n if (!debugOptions) {\n return () => {};\n }\n const currentPath = loaderContext._compiler\n ? relative(loaderContext._compiler.context, loaderContext.resourcePath)\n : loaderContext.resourcePath;\n return (\n messageType: \"ts\" | \"css\" | \"css-resolved\",\n message: string | Buffer<ArrayBufferLike> | undefined,\n ) => {\n // the path contains already the extension for the ts{x} file\n const pathWithExtension =\n messageType !== \"ts\" ? currentPath + `.${messageType}` : currentPath;\n if (\n debugOptions === true ||\n new RegExp(debugOptions).test(pathWithExtension)\n ) {\n console.log(\"🐮 Yak\", pathWithExtension, \"\\n\\n\", message);\n }\n };\n}\n","import { YakConfigOptions } from \"../../withYak/index.js\";\n\n/**\n * Extracts CSS content from code that contains YAK-generated CSS comments.\n * Parses the input code and returns the extracted CSS, optionally adding\n * a cssmodules directive based on the transpilation mode.\n */\nexport function extractCss(\n code: string | Buffer<ArrayBufferLike>,\n transpilationMode: NonNullable<\n YakConfigOptions[\"experiments\"]\n >[\"transpilationMode\"],\n): string {\n let codeString: string;\n\n if (typeof code === \"string\") {\n codeString = code;\n } else if (code instanceof Buffer) {\n codeString = code.toString(\"utf-8\");\n } else if (code instanceof ArrayBuffer) {\n codeString = new TextDecoder(\"utf-8\").decode(code);\n } else {\n throw new Error(\n \"Invalid input type: code must be string, Buffer, or ArrayBuffer\",\n );\n }\n\n const codeParts = codeString.split(\"/*YAK Extracted CSS:\\n\");\n let result = \"\";\n for (let i = 1; i < codeParts.length; i++) {\n const codeUntilEnd = codeParts[i].split(\"*/\")[0];\n result += codeUntilEnd;\n }\n if (result && transpilationMode !== \"Css\") {\n result = \"/* cssmodules-pure-no-check */\\n\" + result;\n }\n\n return result;\n}\n","import { parse } from \"@babel/parser\";\nimport traverse from \"@babel/traverse\";\nimport type { Compilation, LoaderContext } from \"webpack\";\nimport {\n ModuleExport,\n ModuleExports,\n ParseContext,\n ParsedModule,\n parseModule,\n} from \"../../cross-file-resolver/parseModule.js\";\nimport {\n ResolveContext,\n resolveCrossFileConstant as genericResolveCrossFileConstant,\n} from \"../../cross-file-resolver/resolveCrossFileConstant.js\";\nimport { YakConfigOptions } from \"../../withYak/index.js\";\n\nconst compilationCache = new WeakMap<\n Compilation,\n {\n parsedFiles: Map<string, ParsedModule>;\n }\n>();\n\nexport async function resolveCrossFileConstant(\n loader: LoaderContext<{}>,\n pathContext: string,\n css: string,\n): Promise<string> {\n const { resolved } = await genericResolveCrossFileConstant(\n getResolveContext(loader),\n loader.resourcePath,\n css,\n );\n return resolved;\n}\n\nfunction getCompilationCache(loader: LoaderContext<YakConfigOptions>) {\n const compilation = loader._compilation;\n if (!compilation) {\n throw new Error(\"Webpack compilation object not available\");\n }\n let cache = compilationCache.get(compilation);\n if (!cache) {\n cache = {\n parsedFiles: new Map(),\n };\n compilationCache.set(compilation, cache);\n }\n return cache;\n}\n\nfunction getParseContext(\n loader: LoaderContext<YakConfigOptions>,\n): ParseContext {\n return {\n cache: { parse: getCompilationCache(loader).parsedFiles },\n async extractExports(modulePath) {\n const sourceContents = new Promise<string>((resolve, reject) =>\n loader.fs.readFile(modulePath, \"utf-8\", (err, result) => {\n if (err) return reject(err);\n resolve(result || \"\");\n }),\n );\n return parseExports(await sourceContents);\n },\n async getTransformed(modulePath) {\n const transformedSource = new Promise<string>((resolve, reject) => {\n loader.loadModule(modulePath, (err, source) => {\n if (err) return reject(err);\n let sourceString: string;\n if (typeof source === \"string\") {\n sourceString = source;\n } else if (source instanceof Buffer) {\n sourceString = source.toString(\"utf-8\");\n } else if (source instanceof ArrayBuffer) {\n sourceString = new TextDecoder(\"utf-8\").decode(source);\n } else {\n throw new Error(\n \"Invalid input type: code must be string, Buffer, or ArrayBuffer\",\n );\n }\n resolve(sourceString || \"\");\n });\n });\n return { code: await transformedSource };\n },\n async evaluateYakModule(modulePath) {\n return loader.importModule(modulePath);\n },\n transpilationMode: loader.getOptions().experiments?.transpilationMode,\n };\n}\n\nfunction getResolveContext(\n loader: LoaderContext<YakConfigOptions>,\n): ResolveContext {\n const parseContext = getParseContext(loader);\n return {\n parse: (modulePath) => parseModule(parseContext, modulePath),\n resolve: async (specifier, importer) => {\n return resolveModule(loader, specifier, dirname(importer));\n },\n };\n}\n\n/**\n * Resolves a module by wrapping loader.resolve in a promise\n */\nexport async function resolveModule(\n loader: LoaderContext<{}>,\n moduleSpecifier: string,\n context: string,\n): Promise<string> {\n return new Promise<string>((resolve, reject) => {\n loader.resolve(context, moduleSpecifier, (err, result) => {\n if (err) return reject(err);\n if (!result)\n return reject(new Error(`Could not resolve ${moduleSpecifier}`));\n resolve(result);\n });\n });\n}\n\nexport async function parseExports(\n sourceContents: string,\n): Promise<ModuleExports> {\n const moduleExports: ModuleExports = {\n importYak: true,\n named: {},\n all: [],\n };\n\n // Track variable declarations for lookup\n const variableDeclarations: Record<string, babel.types.Expression> = {};\n\n // Track default export identifier if present\n let defaultIdentifier: string | null = null;\n\n try {\n const ast = parse(sourceContents, {\n sourceType: \"module\",\n plugins: [\"jsx\", \"typescript\"] as const,\n });\n\n traverse.default(ast, {\n // Track all variable declarations in the file\n VariableDeclarator({ node }) {\n if (node.id.type === \"Identifier\" && node.init) {\n variableDeclarations[node.id.name] = node.init;\n }\n },\n\n ExportNamedDeclaration({ node }) {\n if (node.source) {\n node.specifiers.forEach((specifier) => {\n if (\n specifier.type === \"ExportSpecifier\" &&\n specifier.exported.type === \"Identifier\" &&\n specifier.local.type === \"Identifier\"\n ) {\n moduleExports.named[specifier.exported.name] = {\n type: \"re-export\",\n from: node.source!.value,\n name: specifier.local.name,\n };\n }\n });\n } else if (node.declaration?.type === \"VariableDeclaration\") {\n node.declaration.declarations.forEach((declaration) => {\n if (declaration.id.type === \"Identifier\" && declaration.init) {\n const parsed = parseExportValueExpression(declaration.init);\n if (parsed) {\n moduleExports.named[declaration.id.name] = parsed;\n }\n }\n });\n }\n },\n ExportDeclaration({ node }) {\n if (\"specifiers\" in node && node.source) {\n const { specifiers, source } = node;\n specifiers.forEach((specifier) => {\n // export * as color from \"./colors\";\n if (\n specifier.type === \"ExportNamespaceSpecifier\" &&\n specifier.exported.type === \"Identifier\"\n ) {\n moduleExports.named[specifier.exported.name] = {\n type: \"namespace-re-export\",\n from: source.value,\n };\n }\n });\n }\n },\n ExportDefaultDeclaration({ node }) {\n if (node.declaration.type === \"Identifier\") {\n // e.g. export default variableName;\n // Save the identifier name to look up later\n defaultIdentifier = node.declaration.name;\n } else if (\n node.declaration.type === \"FunctionDeclaration\" ||\n node.declaration.type === \"ClassDeclaration\"\n ) {\n // e.g. export default function() {...} or export default class {...}\n moduleExports.named[\"default\"] = {\n type: \"unsupported\",\n hint: node.declaration.type,\n };\n } else {\n // e.g. export default { ... } or export default \"value\"\n moduleExports.named[\"default\"] = parseExportValueExpression(\n node.declaration as babel.types.Expression,\n );\n }\n },\n ExportAllDeclaration({ node }) {\n moduleExports.all.push(node.source.value);\n },\n });\n // If we found a default export that's an identifier, look up its value\n if (defaultIdentifier && variableDeclarations[defaultIdentifier]) {\n moduleExports.named[\"default\"] = parseExportValueExpression(\n variableDeclarations[defaultIdentifier],\n );\n }\n\n return moduleExports;\n } catch (error) {\n throw new Error(`Error parsing exports: ${(error as Error).message}`);\n }\n}\n\n/**\n * Unpacks a TSAsExpression to its expression value\n */\nfunction unpackTSAsExpression(\n node: babel.types.TSAsExpression | babel.types.Expression,\n): babel.types.Expression {\n if (node.type === \"TSAsExpression\") {\n return unpackTSAsExpression(node.expression);\n }\n return node;\n}\n\nfunction parseExportValueExpression(\n node: babel.types.Expression,\n): ModuleExport {\n // ignores `as` casts so it doesn't interfere with the ast node type detection\n const expression = unpackTSAsExpression(node);\n if (\n expression.type === \"CallExpression\" ||\n expression.type === \"TaggedTemplateExpression\"\n ) {\n return { type: \"tag-template\" };\n } else if (\n expression.type === \"StringLiteral\" ||\n expression.type === \"NumericLiteral\"\n ) {\n return { type: \"constant\", value: expression.value };\n } else if (\n expression.type === \"UnaryExpression\" &&\n expression.operator === \"-\" &&\n expression.argument.type === \"NumericLiteral\"\n ) {\n return { type: \"constant\", value: -expression.argument.value };\n } else if (\n expression.type === \"TemplateLiteral\" &&\n expression.quasis.length === 1\n ) {\n return { type: \"constant\", value: expression.quasis[0].value.raw };\n } else if (expression.type === \"ObjectExpression\") {\n return { type: \"record\", value: parseObjectExpression(expression) };\n }\n return { type: \"unsupported\", hint: expression.type };\n}\n\nfunction parseObjectExpression(\n node: babel.types.ObjectExpression,\n): Record<string, ModuleExport> {\n let result: Record<string, ModuleExport> = {};\n for (const property of node.properties) {\n if (\n property.type === \"ObjectProperty\" &&\n property.key.type === \"Identifier\"\n ) {\n const key = property.key.name;\n const parsed = parseExportValueExpression(\n property.value as babel.types.Expression,\n );\n if (parsed) {\n result[key] = parsed;\n }\n }\n }\n return result;\n}\n\nconst DIRNAME_POSIX_REGEX =\n /^((?:\\.(?![^\\/]))|(?:(?:\\/?|)(?:[\\s\\S]*?)))(?:\\/+?|)(?:(?:\\.{1,2}|[^\\/]+?|)(?:\\.[^.\\/]*|))(?:[\\/]*)$/;\nconst DIRNAME_WIN32_REGEX =\n /^((?:\\.(?![^\\\\]))|(?:(?:\\\\?|)(?:[\\s\\S]*?)))(?:\\\\+?|)(?:(?:\\.{1,2}|[^\\\\]+?|)(?:\\.[^.\\\\]*|))(?:[\\\\]*)$/;\n\n/**\n * Polyfill for `node:path` method dirname.\n * Keeps yak independent from node api (therefore executable in browser)\n */\nfunction dirname(path: string) {\n let dirname = DIRNAME_POSIX_REGEX.exec(path)?.[1];\n\n if (!dirname) {\n dirname = DIRNAME_WIN32_REGEX.exec(path)?.[1];\n }\n\n if (!dirname) {\n throw new Error(`Can't extract dirname from ${path}`);\n }\n\n return dirname;\n}\n"],"mappings":";AAAA,SAAS,aAAa,oBAAoB;AAC1C,SAAS,qBAAqB;AAC9B,SAAS,eAAe;AACxB,SAAS,eAAe,oBAAoB;;;ACD5C,eAAsB,YACpB,SACA,YACuB;AACvB,MAAI;AACF,UAAM,QACJ,WAAW,SAAS,SAAS,KAC7B,WAAW,SAAS,UAAU,KAC9B,WAAW,SAAS,SAAS,KAC7B,WAAW,SAAS,UAAU;AAKhC,QAAI,SAAS,QAAQ,mBAAmB;AACtC,YAAM,YAAY,MAAM,QAAQ,kBAAkB,UAAU;AAC5D,YAAM,aAAa,qBAAqB,SAAS;AAEjD,aAAO;AAAA,QACL,MAAM;AAAA,QACN,SAAS,EAAE,WAAW,OAAO,OAAO,YAAY,KAAK,CAAC,EAAE;AAAA,QACxD,MAAM;AAAA,MACR;AAAA,IACF;AAEA,QAAI,QAAQ,OAAO,UAAU,QAAW;AACtC,aAAO,oBAAoB,SAAS,UAAU;AAAA,IAChD;AAEA,UAAM,SAAS,QAAQ,MAAM,MAAM,IAAI,UAAU;AACjD,QAAI,WAAW,QAAW;AAIxB,YAAM,eAAe,MAAM,oBAAoB,SAAS,UAAU;AAElE,cAAQ,MAAM,MAAM,IAAI,YAAY,YAAY;AAChD,UAAI,QAAQ,MAAM,MAAM,eAAe;AACrC,gBAAQ,MAAM,MAAM,cAAc,YAAY,UAAU;AAAA,MAC1D;AACA,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT,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AAY;AAAA,MACZ,KAAK;AAAA,QACH,cAAc;AAAA,UACZ,SAAS,CAAC,CAACA,mBAAkB,gBAAgB,CAAC;AAAA,QAChD;AAAA,QACA,WAAW;AAAA,UACT,OAAO;AAAA,YACL,SAAS;AAAA,UACX;AAAA,QACF;AAAA,QACA,QAAQ;AAAA,QACR,OAAO;AAAA,QACP,QAAQ;AAAA,UACN,UAAU;AAAA,UACV,QAAQ;AAAA,QACV;AAAA,QACA,qBAAqB;AAAA,MACvB;AAAA,MACA,QAAQ;AAAA,MACR,UAAU;AAAA,IACZ,CAAC;AAAA;AACL;","names":["resolveCrossFileConstant","require","result","modulePath","code","yakSwcPluginPath"]}