next-yak 9.3.0 → 9.4.0
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.
- package/dist/loaders/turbo-loader.cjs +149 -93
- package/dist/loaders/turbo-loader.cjs.map +1 -1
- package/loaders/turbo-evaluator.ts +141 -0
- package/loaders/turbo-loader.ts +79 -92
- package/package.json +2 -2
|
@@ -5,6 +5,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __esm = (fn, res) => function __init() {
|
|
9
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
|
+
};
|
|
8
11
|
var __export = (target, all) => {
|
|
9
12
|
for (var name in all)
|
|
10
13
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -27,6 +30,85 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
30
|
));
|
|
28
31
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
32
|
|
|
33
|
+
// loaders/turbo-evaluator.ts
|
|
34
|
+
var turbo_evaluator_exports = {};
|
|
35
|
+
__export(turbo_evaluator_exports, {
|
|
36
|
+
createCompilationEvaluator: () => createCompilationEvaluator,
|
|
37
|
+
getEvaluatorSingleton: () => getEvaluatorSingleton
|
|
38
|
+
});
|
|
39
|
+
function invalidateDependenciesWithDiskModifications(evaluator) {
|
|
40
|
+
const modificationTimes = getFileModificationTimes();
|
|
41
|
+
const modifiedDependencies = [];
|
|
42
|
+
for (const [dep, lastModificationTime] of modificationTimes) {
|
|
43
|
+
try {
|
|
44
|
+
const currentModificationTime = (0, import_node_fs.statSync)(dep).mtimeMs;
|
|
45
|
+
if (currentModificationTime !== lastModificationTime) {
|
|
46
|
+
modifiedDependencies.push(dep);
|
|
47
|
+
modificationTimes.set(dep, currentModificationTime);
|
|
48
|
+
}
|
|
49
|
+
} catch {
|
|
50
|
+
modifiedDependencies.push(dep);
|
|
51
|
+
modificationTimes.delete(dep);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (modifiedDependencies.length > 0) {
|
|
55
|
+
evaluator.invalidate(...modifiedDependencies);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function recordModificationTimes(deps) {
|
|
59
|
+
const modificationTimes = getFileModificationTimes();
|
|
60
|
+
for (const dep of deps) {
|
|
61
|
+
try {
|
|
62
|
+
modificationTimes.set(dep, (0, import_node_fs.statSync)(dep).mtimeMs);
|
|
63
|
+
} catch {
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
async function createCompilationEvaluator() {
|
|
68
|
+
const evaluator = await getEvaluatorSingleton();
|
|
69
|
+
invalidateDependenciesWithDiskModifications(evaluator);
|
|
70
|
+
return async (modulePath, onDependency) => {
|
|
71
|
+
const result = await evaluator.evaluate(modulePath);
|
|
72
|
+
if (!result.ok) {
|
|
73
|
+
const error = new Error(result.error.message);
|
|
74
|
+
if (result.error.stack) {
|
|
75
|
+
error.stack = result.error.stack;
|
|
76
|
+
}
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
recordModificationTimes(result.dependencies);
|
|
80
|
+
if (onDependency) {
|
|
81
|
+
for (const dep of result.dependencies) {
|
|
82
|
+
onDependency(dep);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return result.value;
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
var import_node_fs, EVALUATOR_KEY, MTIMES_KEY, getFileModificationTimes, getEvaluatorSingleton;
|
|
89
|
+
var init_turbo_evaluator = __esm({
|
|
90
|
+
"loaders/turbo-evaluator.ts"() {
|
|
91
|
+
"use strict";
|
|
92
|
+
import_node_fs = require("fs");
|
|
93
|
+
EVALUATOR_KEY = /* @__PURE__ */ Symbol.for("next-yak-evaluator");
|
|
94
|
+
MTIMES_KEY = /* @__PURE__ */ Symbol.for("next-yak-mtimes");
|
|
95
|
+
getFileModificationTimes = () => globalThis[MTIMES_KEY] ??= /* @__PURE__ */ new Map();
|
|
96
|
+
getEvaluatorSingleton = async () => {
|
|
97
|
+
const processGlobal = globalThis;
|
|
98
|
+
if (!processGlobal[EVALUATOR_KEY]) {
|
|
99
|
+
processGlobal[EVALUATOR_KEY] = import("../isolated-source-eval/index.js").then(
|
|
100
|
+
({ createEvaluator }) => createEvaluator()
|
|
101
|
+
);
|
|
102
|
+
process.on("beforeExit", async () => {
|
|
103
|
+
const evaluator = await processGlobal[EVALUATOR_KEY];
|
|
104
|
+
await evaluator.dispose();
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return processGlobal[EVALUATOR_KEY];
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
|
|
30
112
|
// loaders/turbo-loader.ts
|
|
31
113
|
var turbo_loader_exports = {};
|
|
32
114
|
__export(turbo_loader_exports, {
|
|
@@ -36,7 +118,6 @@ module.exports = __toCommonJS(turbo_loader_exports);
|
|
|
36
118
|
var import_core = require("@swc/core");
|
|
37
119
|
var import_node_module = require("module");
|
|
38
120
|
var import_node_path = require("path");
|
|
39
|
-
var import_node_vm = require("vm");
|
|
40
121
|
|
|
41
122
|
// cross-file-resolver/parseModule.ts
|
|
42
123
|
async function parseModule(context, modulePath) {
|
|
@@ -853,104 +934,79 @@ async function cssExtractLoader(code, sourceMap) {
|
|
|
853
934
|
const transform = createTransform(yakPluginOptions, yakSwcPluginPath);
|
|
854
935
|
const resolveFn = (specifier, importer) => {
|
|
855
936
|
return new Promise((resolve, reject) => {
|
|
856
|
-
resolveTurbopack((0, import_node_path.dirname)(importer), specifier, (err,
|
|
937
|
+
resolveTurbopack((0, import_node_path.dirname)(importer), specifier, (err, result) => {
|
|
857
938
|
if (err) return reject(err);
|
|
858
|
-
if (!
|
|
859
|
-
resolve(
|
|
939
|
+
if (!result) return reject(new Error(`Could not resolve ${specifier}`));
|
|
940
|
+
resolve(result);
|
|
860
941
|
});
|
|
861
942
|
});
|
|
862
943
|
};
|
|
863
|
-
const
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
944
|
+
const crossFileDeps = /* @__PURE__ */ new Set();
|
|
945
|
+
let evaluate;
|
|
946
|
+
const fsReadFile = (filePath) => {
|
|
947
|
+
crossFileDeps.add(filePath);
|
|
948
|
+
return new Promise(
|
|
949
|
+
(resolve, reject) => this.fs.readFile(filePath, "utf-8", (err, result) => {
|
|
950
|
+
if (err) return reject(err);
|
|
951
|
+
if (!result) return reject(new Error(`File not found: ${filePath}`));
|
|
952
|
+
resolve(result);
|
|
953
|
+
})
|
|
954
|
+
);
|
|
955
|
+
};
|
|
956
|
+
try {
|
|
957
|
+
const result = await transform(
|
|
958
|
+
code,
|
|
959
|
+
this.resourcePath,
|
|
960
|
+
this.rootContext,
|
|
961
|
+
sourceMap
|
|
962
|
+
);
|
|
963
|
+
debugLog("ts", result.code, this.resourcePath);
|
|
964
|
+
let css = extractCss(result.code, "Css");
|
|
965
|
+
debugLog("css", css, this.resourcePath);
|
|
966
|
+
const { resolved } = await resolveCrossFileConstant(
|
|
967
|
+
{
|
|
968
|
+
parse: (modulePath) => {
|
|
969
|
+
return parseModule(
|
|
970
|
+
{
|
|
971
|
+
transpilationMode: "Css",
|
|
972
|
+
extractExports: async (modulePath2) => {
|
|
973
|
+
const sourceContents = await fsReadFile(modulePath2);
|
|
974
|
+
return parseExports(sourceContents);
|
|
975
|
+
},
|
|
976
|
+
getTransformed: async (modulePath2) => {
|
|
977
|
+
const sourceContent = await fsReadFile(modulePath2);
|
|
978
|
+
return transform(sourceContent, modulePath2, this.rootContext);
|
|
979
|
+
},
|
|
980
|
+
evaluateYakModule: async (modulePath2) => {
|
|
981
|
+
crossFileDeps.add(modulePath2);
|
|
982
|
+
evaluate ??= await (await Promise.resolve().then(() => (init_turbo_evaluator(), turbo_evaluator_exports))).createCompilationEvaluator();
|
|
983
|
+
return evaluate(modulePath2, (dep) => crossFileDeps.add(dep));
|
|
984
|
+
}
|
|
892
985
|
},
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
sourceFileName: modulePath2,
|
|
898
|
-
jsc: {
|
|
899
|
-
transform: {
|
|
900
|
-
react: { runtime: "automatic" }
|
|
901
|
-
},
|
|
902
|
-
experimental: {
|
|
903
|
-
plugins: [[yakSwcPluginPath, yakPluginOptions]]
|
|
904
|
-
}
|
|
905
|
-
},
|
|
906
|
-
module: {
|
|
907
|
-
type: "commonjs"
|
|
908
|
-
}
|
|
909
|
-
});
|
|
910
|
-
const moduleObject = { exports: {} };
|
|
911
|
-
const context = (0, import_node_vm.createContext)({
|
|
912
|
-
require: (path) => {
|
|
913
|
-
throw new Error(
|
|
914
|
-
`Yak files cannot have imports in turbopack.
|
|
915
|
-
Found require/import usage in: ${modulePath2} to import: ${path}.
|
|
916
|
-
Yak files should be self-contained and only export constants or styled components.
|
|
917
|
-
This will be resolved once Vercel adds "this.importModule" support for turbopack.`
|
|
918
|
-
);
|
|
919
|
-
},
|
|
920
|
-
__filename: modulePath2,
|
|
921
|
-
__dirname: (0, import_node_path.dirname)(modulePath2),
|
|
922
|
-
global: {},
|
|
923
|
-
console,
|
|
924
|
-
Buffer,
|
|
925
|
-
process,
|
|
926
|
-
setTimeout,
|
|
927
|
-
clearTimeout,
|
|
928
|
-
setInterval,
|
|
929
|
-
clearInterval,
|
|
930
|
-
setImmediate,
|
|
931
|
-
clearImmediate,
|
|
932
|
-
exports: moduleObject.exports,
|
|
933
|
-
module: moduleObject
|
|
934
|
-
});
|
|
935
|
-
(0, import_node_vm.runInContext)(transformed.code, context);
|
|
936
|
-
return moduleObject.exports;
|
|
937
|
-
}
|
|
938
|
-
},
|
|
939
|
-
modulePath
|
|
940
|
-
);
|
|
986
|
+
modulePath
|
|
987
|
+
);
|
|
988
|
+
},
|
|
989
|
+
resolve: resolveFn
|
|
941
990
|
},
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
991
|
+
this.resourcePath,
|
|
992
|
+
css
|
|
993
|
+
);
|
|
994
|
+
for (const dep of crossFileDeps) {
|
|
995
|
+
this.addDependency(dep);
|
|
996
|
+
}
|
|
997
|
+
const dataUrl = result.code.split("\n").find((line) => line.includes("data:text/css;base64"));
|
|
998
|
+
const codeWithCrossFileResolved = result.code.replace(
|
|
999
|
+
dataUrl,
|
|
1000
|
+
`import "data:text/css;base64,${Buffer.from(resolved).toString("base64")}"`
|
|
1001
|
+
);
|
|
1002
|
+
debugLog("css-resolved", resolved, this.resourcePath);
|
|
1003
|
+
return callback(null, codeWithCrossFileResolved, result.map);
|
|
1004
|
+
} catch (error) {
|
|
1005
|
+
for (const dep of crossFileDeps) {
|
|
1006
|
+
this.addDependency(dep);
|
|
1007
|
+
}
|
|
1008
|
+
return callback(error instanceof Error ? error : new Error(String(error)));
|
|
1009
|
+
}
|
|
954
1010
|
}
|
|
955
1011
|
function createTransform(yakPluginOptions, yakSwcPluginPath2) {
|
|
956
1012
|
return (data, modulePath, rootPath, sourceMap) => (
|
|
@@ -1 +1 @@
|
|
|
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 universalRequire =\n typeof require === \"undefined\" ? createRequire(import.meta.url) : require;\nconst yakSwcPluginPath = universalRequire.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(experiments?.debug, this.rootContext);\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, this.resourcePath);\n\n let css = extractCss(result.code, \"Css\");\n debugLog(\"css\", css, this.resourcePath);\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, this.resourcePath);\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 await 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 const causeMessage = error instanceof Error ? error.message : String(error);\n throw new Error(\n `Error parsing file \"${modulePath}\"\\n Caused by: ${causeMessage}`,\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 { YakConfigOptions } from \"../../withYak/index.js\";\n\ntype DebugOptions = Required<YakConfigOptions>[\"experiments\"][\"debug\"];\ntype DebugType = NonNullable<\n Exclude<DebugOptions, true | undefined>\n>[\"types\"] extends Array<infer T> | undefined\n ? T\n : never;\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 debugOptions: DebugOptions | undefined,\n rootPath: string,\n) {\n if (!debugOptions) {\n return () => {};\n }\n\n throwOnDeprecatedDebugOptions(debugOptions);\n\n // Handle true (log all) vs object (with optional filtering)\n const pattern = debugOptions === true ? undefined : debugOptions.pattern;\n const typesArray = debugOptions === true ? undefined : debugOptions.types;\n\n // Validate and pre-compile regex pattern\n let compiledPattern: RegExp | null = null;\n if (pattern) {\n try {\n compiledPattern = new RegExp(pattern);\n } catch (error) {\n throw new Error(\n `Invalid debug pattern: \"${pattern}\" is not a valid regular expression. ${\n error instanceof Error ? error.message : \"\"\n }`,\n );\n }\n }\n\n const types = typesArray ? new Set(typesArray) : null;\n\n return (\n messageType: DebugType,\n message: string | Buffer<ArrayBufferLike> | undefined,\n filePath: string,\n ) => {\n // Filter by type if specified\n if (types && !types.has(messageType)) {\n return;\n }\n\n const relativePath = relative(rootPath, filePath);\n\n // Filter by pattern if specified, or log all if no pattern\n if (!compiledPattern || compiledPattern.test(relativePath)) {\n console.log(\"🐮 Yak\", `[${messageType}]`, relativePath, \"\\n\\n\", message);\n }\n };\n}\n\n/**\n * Detects deprecated debug option shapes and throws helpful migration errors.\n * TODO: Remove this function in the next major version.\n */\nfunction throwOnDeprecatedDebugOptions(debugOptions: DebugOptions): void {\n // Old API: debug: \"regex-string\"\n if (typeof debugOptions === \"string\") {\n const suggestion =\n suggestTypesForExtensionPattern(debugOptions) ??\n `debug: { pattern: \"${debugOptions}\" }`;\n throw new Error(\n `The debug option no longer accepts a string. Please update your config:\\n` +\n ` Before: debug: \"${debugOptions}\"\\n` +\n ` After: ${suggestion}`,\n );\n }\n\n // Old API: debug: { filter: Function, type: string }\n if (typeof debugOptions === \"object\" && \"filter\" in debugOptions) {\n throw new Error(\n `The debug option no longer accepts { filter, type }. Please update your config:\\n` +\n ` Before: debug: { filter: ..., type: \"...\" }\\n` +\n ` After: debug: { pattern: \"...\", types: [\"ts\", \"css\", \"css-resolved\"] }`,\n );\n }\n\n // Old convention: pattern used \".css$\" or \".css-resolved$\" as file extension\n // for type filtering — the pattern now only matches file paths\n if (typeof debugOptions === \"object\" && debugOptions.pattern) {\n const suggestion = suggestTypesForExtensionPattern(debugOptions.pattern);\n if (suggestion) {\n throw new Error(\n `The debug pattern \"${debugOptions.pattern}\" looks like it's filtering by output type using the old file extension convention.\\n` +\n `The pattern now only matches file paths. Use the \"types\" option to filter by output type:\\n` +\n ` Before: debug: { pattern: \"${debugOptions.pattern}\" }\\n` +\n ` After: ${suggestion}`,\n );\n }\n }\n}\n\n/**\n * Checks if a pattern string uses the old \".css$\" / \".css-resolved$\" file\n * extension convention for type filtering. Returns a suggested replacement\n * or null if the pattern doesn't match.\n */\nfunction suggestTypesForExtensionPattern(pattern: string): string | null {\n const extensionMatch = pattern.match(/\\.\\(?(?:css-resolved|css)\\)?\\$?$/);\n if (!extensionMatch) {\n return null;\n }\n const type = extensionMatch[0].includes(\"css-resolved\")\n ? \"css-resolved\"\n : \"css\";\n const remaining = pattern.slice(0, extensionMatch.index);\n return remaining\n ? `debug: { pattern: \"${remaining}\", types: [\"${type}\"] }`\n : `debug: { types: [\"${type}\"] }`;\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) {\n // When webpack reports \"The loaded module contains errors\",\n // the actual errors are stored on the module in the compilation.\n // Extract and report the real errors for better debugging.\n const compilation = loader._compilation;\n if (compilation) {\n try {\n for (const mod of compilation.modules) {\n if (\"resource\" in mod && mod.resource === modulePath) {\n const errors = mod.getErrors();\n if (errors) {\n const messages = Array.from(errors)\n .map((e) => e.message)\n .filter(Boolean);\n if (messages.length > 0) {\n return reject(new Error(messages.join(\"\\n\")));\n }\n }\n }\n }\n } catch {\n // Ignore errors while trying to extract module errors\n }\n }\n return reject(err);\n }\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;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA0C;AAC1C,yBAA8B;AAC9B,uBAAwB;AACxB,qBAA4C;;;ACD5C,eAAsB,YACpB,SACA,YACuB;AACvB,MAAI;AACF,UAAM,QACJ,WAAW,SAAS,SAAS,KAC7B,WAAW,SAAS,UAAU,KAC9B,WAAW,SA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rossFileConstant","exports","traverse","result","modulePath","code","swcTransform","yakSwcPluginPath"]}
|
|
1
|
+
{"version":3,"sources":["../../loaders/turbo-evaluator.ts","../../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":["/**\n * Turbopack evaluator adapter.\n *\n * Bridges the low-level `Evaluator` (worker-thread module evaluator) and\n * turbopack's loader lifecycle. A single `Evaluator` instance is kept as a\n * singleton on `globalThis` because turbopack may create multiple loader\n * instances that share the same process — `Symbol.for` keys guarantee all\n * instances converge on the same evaluator and modification time map.\n *\n * Invalidation uses synchronous modification time polling rather than `fs.watch` because\n * turbopack can re-run a loader before a filesystem watcher event fires,\n * which would cause the evaluator to return stale cached results.\n */\nimport { statSync } from \"node:fs\";\nimport type { Evaluator } from \"../isolated-source-eval/evaluator.js\";\n\nconst EVALUATOR_KEY = Symbol.for(\"next-yak-evaluator\");\nconst MTIMES_KEY = Symbol.for(\"next-yak-mtimes\");\n\n/**\n * A shared `Map` of file paths to their last known modification times, used to detect changes on disk\n *\n * e.g. bar.ts -> 1680000000000 (Sat Mar 28 2024 12:00:00 GMT+0000)\n *\n * fs.fileWatch is not used as it might be out of sync with turbopacks own file watching also turbopack\n * spawns a loader pool which could cause a lot of file watchers to be created which can cause performance issues and hitting OS limits\n */\nconst getFileModificationTimes = () =>\n ((globalThis as typeof globalThis & { [MTIMES_KEY]?: Map<string, number> })[\n MTIMES_KEY\n ] ??= new Map<string, number>());\n\n/**\n * Returns the shared evaluator, creating it on first call.\n *\n * Uses `Symbol.for` keys on `globalThis` so every turbopack loader instance\n * in the process converges on the same evaluator and modification time map. A\n * `beforeExit` handler terminates the worker threads when the process winds\n * down.\n */\nexport const getEvaluatorSingleton = async (): Promise<Evaluator> => {\n const processGlobal = globalThis as typeof globalThis & {\n [EVALUATOR_KEY]?: Promise<Evaluator>;\n };\n if (!processGlobal[EVALUATOR_KEY]) {\n processGlobal[EVALUATOR_KEY] =\n import(\"../isolated-source-eval/index.js\").then(({ createEvaluator }) =>\n createEvaluator(),\n );\n // Kill the worker threads when the process exits\n process.on(\"beforeExit\", async () => {\n const evaluator = await processGlobal[EVALUATOR_KEY]!;\n await evaluator.dispose();\n });\n }\n return processGlobal[EVALUATOR_KEY]!;\n};\n\n/**\n * Turbopack runs the loader for the same compilation file-by-file, but multiple files can share the\n * same dependency. This function detects which dependencies actually changed\n * on disk and invalidates them once — this prevents re-evaluating the same module multiple times in the same compilation\n */\nfunction invalidateDependenciesWithDiskModifications(\n evaluator: Evaluator,\n): void {\n const modificationTimes = getFileModificationTimes();\n const modifiedDependencies: string[] = [];\n for (const [dep, lastModificationTime] of modificationTimes) {\n try {\n const currentModificationTime = statSync(dep).mtimeMs;\n if (currentModificationTime !== lastModificationTime) {\n modifiedDependencies.push(dep);\n modificationTimes.set(dep, currentModificationTime);\n }\n } catch {\n modifiedDependencies.push(dep);\n modificationTimes.delete(dep);\n }\n }\n if (modifiedDependencies.length > 0) {\n evaluator.invalidate(...modifiedDependencies);\n }\n}\n\n/** Snapshots the current modification times of `deps` so the next evaluation can detect changes. */\nfunction recordModificationTimes(deps: string[]): void {\n const modificationTimes = getFileModificationTimes();\n for (const dep of deps) {\n try {\n modificationTimes.set(dep, statSync(dep).mtimeMs);\n } catch {\n /* file may not exist */\n }\n }\n}\n\n/**\n * Creates an evaluator function scoped to a single loader invocation.\n *\n * Before evaluation, checks whether any previously recorded dependency has\n * changed on disk and invalidates the evaluator cache if so. After a\n * successful evaluation, records fresh modification times and notifies the caller of\n * every transitive dependency via `onDependency`.\n *\n * @returns A function that evaluates a yak module and returns its exports.\n * The returned function accepts:\n * - `modulePath` — absolute path to the module to evaluate.\n * - `onDependency` — called once per transitive dependency so the loader\n * can register file watchers with turbopack.\n * @throws If the evaluated module throws at runtime — the original stack\n * trace from the worker thread is preserved.\n */\nexport async function createCompilationEvaluator(): Promise<\n (\n modulePath: string,\n onDependency?: (dep: string) => void,\n ) => Promise<Record<string, unknown>>\n> {\n const evaluator = await getEvaluatorSingleton();\n invalidateDependenciesWithDiskModifications(evaluator);\n\n return async (modulePath, onDependency?) => {\n const result = await evaluator.evaluate(modulePath);\n if (!result.ok) {\n const error = new Error(result.error.message);\n if (result.error.stack) {\n error.stack = result.error.stack;\n }\n throw error;\n }\n // Store times of newly discovered dependencies for next compilation\n recordModificationTimes(result.dependencies);\n if (onDependency) {\n for (const dep of result.dependencies) {\n onDependency(dep);\n }\n }\n return result.value;\n };\n}\n","import { transform as swcTransform } from \"@swc/core\";\nimport { createRequire } from \"node:module\";\nimport { dirname } from \"node:path\";\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 universalRequire =\n typeof require === \"undefined\" ? createRequire(import.meta.url) : require;\nconst yakSwcPluginPath = universalRequire.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(experiments?.debug, this.rootContext);\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 crossFileDeps = new Set<string>();\n let evaluate:\n | Awaited<\n ReturnType<\n typeof import(\"./turbo-evaluator.js\").createCompilationEvaluator\n >\n >\n | undefined;\n const fsReadFile = (filePath: string) => {\n crossFileDeps.add(filePath);\n return 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\n try {\n const result = await transform(\n code,\n this.resourcePath,\n this.rootContext,\n sourceMap,\n );\n debugLog(\"ts\", result.code, this.resourcePath);\n\n let css = extractCss(result.code, \"Css\");\n debugLog(\"css\", css, this.resourcePath);\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 crossFileDeps.add(modulePath);\n /*\n * Turbopack doesn't let us know when a compilation start so by using a singleton evaluator we\n * we can at least ensture that we scan for file modifications only once per loader call\n */\n evaluate ??= await (\n await import(\"./turbo-evaluator.js\")\n ).createCompilationEvaluator();\n return evaluate(modulePath, (dep) => crossFileDeps.add(dep));\n },\n },\n modulePath,\n );\n },\n resolve: resolveFn,\n },\n this.resourcePath,\n css,\n );\n\n // Register cross-file dependencies so turbopack re-runs this loader\n // when any dependency changes (analogous to webpack's this.addDependency)\n for (const dep of crossFileDeps) {\n this.addDependency(dep);\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, this.resourcePath);\n return callback(null, codeWithCrossFileResolved, result.map);\n } catch (error) {\n // Register cross-file dependencies even on error so turbopack re-runs\n // this loader when a broken dependency is fixed.\n for (const dep of crossFileDeps) {\n this.addDependency(dep);\n }\n return callback(error instanceof Error ? error : new Error(String(error)));\n }\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 await 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 const causeMessage = error instanceof Error ? error.message : String(error);\n throw new Error(\n `Error parsing file \"${modulePath}\"\\n Caused by: ${causeMessage}`,\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 { YakConfigOptions } from \"../../withYak/index.js\";\n\ntype DebugOptions = Required<YakConfigOptions>[\"experiments\"][\"debug\"];\ntype DebugType = NonNullable<\n Exclude<DebugOptions, true | undefined>\n>[\"types\"] extends Array<infer T> | undefined\n ? T\n : never;\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 debugOptions: DebugOptions | undefined,\n rootPath: string,\n) {\n if (!debugOptions) {\n return () => {};\n }\n\n throwOnDeprecatedDebugOptions(debugOptions);\n\n // Handle true (log all) vs object (with optional filtering)\n const pattern = debugOptions === true ? undefined : debugOptions.pattern;\n const typesArray = debugOptions === true ? undefined : debugOptions.types;\n\n // Validate and pre-compile regex pattern\n let compiledPattern: RegExp | null = null;\n if (pattern) {\n try {\n compiledPattern = new RegExp(pattern);\n } catch (error) {\n throw new Error(\n `Invalid debug pattern: \"${pattern}\" is not a valid regular expression. ${\n error instanceof Error ? error.message : \"\"\n }`,\n );\n }\n }\n\n const types = typesArray ? new Set(typesArray) : null;\n\n return (\n messageType: DebugType,\n message: string | Buffer<ArrayBufferLike> | undefined,\n filePath: string,\n ) => {\n // Filter by type if specified\n if (types && !types.has(messageType)) {\n return;\n }\n\n const relativePath = relative(rootPath, filePath);\n\n // Filter by pattern if specified, or log all if no pattern\n if (!compiledPattern || compiledPattern.test(relativePath)) {\n console.log(\"🐮 Yak\", `[${messageType}]`, relativePath, \"\\n\\n\", message);\n }\n };\n}\n\n/**\n * Detects deprecated debug option shapes and throws helpful migration errors.\n * TODO: Remove this function in the next major version.\n */\nfunction throwOnDeprecatedDebugOptions(debugOptions: DebugOptions): void {\n // Old API: debug: \"regex-string\"\n if (typeof debugOptions === \"string\") {\n const suggestion =\n suggestTypesForExtensionPattern(debugOptions) ??\n `debug: { pattern: \"${debugOptions}\" }`;\n throw new Error(\n `The debug option no longer accepts a string. Please update your config:\\n` +\n ` Before: debug: \"${debugOptions}\"\\n` +\n ` After: ${suggestion}`,\n );\n }\n\n // Old API: debug: { filter: Function, type: string }\n if (typeof debugOptions === \"object\" && \"filter\" in debugOptions) {\n throw new Error(\n `The debug option no longer accepts { filter, type }. Please update your config:\\n` +\n ` Before: debug: { filter: ..., type: \"...\" }\\n` +\n ` After: debug: { pattern: \"...\", types: [\"ts\", \"css\", \"css-resolved\"] }`,\n );\n }\n\n // Old convention: pattern used \".css$\" or \".css-resolved$\" as file extension\n // for type filtering — the pattern now only matches file paths\n if (typeof debugOptions === \"object\" && debugOptions.pattern) {\n const suggestion = suggestTypesForExtensionPattern(debugOptions.pattern);\n if (suggestion) {\n throw new Error(\n `The debug pattern \"${debugOptions.pattern}\" looks like it's filtering by output type using the old file extension convention.\\n` +\n `The pattern now only matches file paths. Use the \"types\" option to filter by output type:\\n` +\n ` Before: debug: { pattern: \"${debugOptions.pattern}\" }\\n` +\n ` After: ${suggestion}`,\n );\n }\n }\n}\n\n/**\n * Checks if a pattern string uses the old \".css$\" / \".css-resolved$\" file\n * extension convention for type filtering. Returns a suggested replacement\n * or null if the pattern doesn't match.\n */\nfunction suggestTypesForExtensionPattern(pattern: string): string | null {\n const extensionMatch = pattern.match(/\\.\\(?(?:css-resolved|css)\\)?\\$?$/);\n if (!extensionMatch) {\n return null;\n }\n const type = extensionMatch[0].includes(\"css-resolved\")\n ? \"css-resolved\"\n : \"css\";\n const remaining = pattern.slice(0, extensionMatch.index);\n return remaining\n ? `debug: { pattern: \"${remaining}\", types: [\"${type}\"] }`\n : `debug: { types: [\"${type}\"] }`;\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) {\n // When webpack reports \"The loaded module contains errors\",\n // the actual errors are stored on the module in the compilation.\n // Extract and report the real errors for better debugging.\n const compilation = loader._compilation;\n if (compilation) {\n try {\n for (const mod of compilation.modules) {\n if (\"resource\" in mod && mod.resource === modulePath) {\n const errors = mod.getErrors();\n if (errors) {\n const messages = Array.from(errors)\n .map((e) => e.message)\n .filter(Boolean);\n if (messages.length > 0) {\n return reject(new Error(messages.join(\"\\n\")));\n }\n }\n }\n }\n } catch {\n // Ignore errors while trying to extract module errors\n }\n }\n return reject(err);\n }\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;AAAA;A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D;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":["exports","resolveCrossFileConstant","exports","traverse","modulePath","yakSwcPluginPath","swcTransform"]}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turbopack evaluator adapter.
|
|
3
|
+
*
|
|
4
|
+
* Bridges the low-level `Evaluator` (worker-thread module evaluator) and
|
|
5
|
+
* turbopack's loader lifecycle. A single `Evaluator` instance is kept as a
|
|
6
|
+
* singleton on `globalThis` because turbopack may create multiple loader
|
|
7
|
+
* instances that share the same process — `Symbol.for` keys guarantee all
|
|
8
|
+
* instances converge on the same evaluator and modification time map.
|
|
9
|
+
*
|
|
10
|
+
* Invalidation uses synchronous modification time polling rather than `fs.watch` because
|
|
11
|
+
* turbopack can re-run a loader before a filesystem watcher event fires,
|
|
12
|
+
* which would cause the evaluator to return stale cached results.
|
|
13
|
+
*/
|
|
14
|
+
import { statSync } from "node:fs";
|
|
15
|
+
import type { Evaluator } from "../isolated-source-eval/evaluator.js";
|
|
16
|
+
|
|
17
|
+
const EVALUATOR_KEY = Symbol.for("next-yak-evaluator");
|
|
18
|
+
const MTIMES_KEY = Symbol.for("next-yak-mtimes");
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A shared `Map` of file paths to their last known modification times, used to detect changes on disk
|
|
22
|
+
*
|
|
23
|
+
* e.g. bar.ts -> 1680000000000 (Sat Mar 28 2024 12:00:00 GMT+0000)
|
|
24
|
+
*
|
|
25
|
+
* fs.fileWatch is not used as it might be out of sync with turbopacks own file watching also turbopack
|
|
26
|
+
* spawns a loader pool which could cause a lot of file watchers to be created which can cause performance issues and hitting OS limits
|
|
27
|
+
*/
|
|
28
|
+
const getFileModificationTimes = () =>
|
|
29
|
+
((globalThis as typeof globalThis & { [MTIMES_KEY]?: Map<string, number> })[
|
|
30
|
+
MTIMES_KEY
|
|
31
|
+
] ??= new Map<string, number>());
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Returns the shared evaluator, creating it on first call.
|
|
35
|
+
*
|
|
36
|
+
* Uses `Symbol.for` keys on `globalThis` so every turbopack loader instance
|
|
37
|
+
* in the process converges on the same evaluator and modification time map. A
|
|
38
|
+
* `beforeExit` handler terminates the worker threads when the process winds
|
|
39
|
+
* down.
|
|
40
|
+
*/
|
|
41
|
+
export const getEvaluatorSingleton = async (): Promise<Evaluator> => {
|
|
42
|
+
const processGlobal = globalThis as typeof globalThis & {
|
|
43
|
+
[EVALUATOR_KEY]?: Promise<Evaluator>;
|
|
44
|
+
};
|
|
45
|
+
if (!processGlobal[EVALUATOR_KEY]) {
|
|
46
|
+
processGlobal[EVALUATOR_KEY] =
|
|
47
|
+
import("../isolated-source-eval/index.js").then(({ createEvaluator }) =>
|
|
48
|
+
createEvaluator(),
|
|
49
|
+
);
|
|
50
|
+
// Kill the worker threads when the process exits
|
|
51
|
+
process.on("beforeExit", async () => {
|
|
52
|
+
const evaluator = await processGlobal[EVALUATOR_KEY]!;
|
|
53
|
+
await evaluator.dispose();
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return processGlobal[EVALUATOR_KEY]!;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Turbopack runs the loader for the same compilation file-by-file, but multiple files can share the
|
|
61
|
+
* same dependency. This function detects which dependencies actually changed
|
|
62
|
+
* on disk and invalidates them once — this prevents re-evaluating the same module multiple times in the same compilation
|
|
63
|
+
*/
|
|
64
|
+
function invalidateDependenciesWithDiskModifications(
|
|
65
|
+
evaluator: Evaluator,
|
|
66
|
+
): void {
|
|
67
|
+
const modificationTimes = getFileModificationTimes();
|
|
68
|
+
const modifiedDependencies: string[] = [];
|
|
69
|
+
for (const [dep, lastModificationTime] of modificationTimes) {
|
|
70
|
+
try {
|
|
71
|
+
const currentModificationTime = statSync(dep).mtimeMs;
|
|
72
|
+
if (currentModificationTime !== lastModificationTime) {
|
|
73
|
+
modifiedDependencies.push(dep);
|
|
74
|
+
modificationTimes.set(dep, currentModificationTime);
|
|
75
|
+
}
|
|
76
|
+
} catch {
|
|
77
|
+
modifiedDependencies.push(dep);
|
|
78
|
+
modificationTimes.delete(dep);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (modifiedDependencies.length > 0) {
|
|
82
|
+
evaluator.invalidate(...modifiedDependencies);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Snapshots the current modification times of `deps` so the next evaluation can detect changes. */
|
|
87
|
+
function recordModificationTimes(deps: string[]): void {
|
|
88
|
+
const modificationTimes = getFileModificationTimes();
|
|
89
|
+
for (const dep of deps) {
|
|
90
|
+
try {
|
|
91
|
+
modificationTimes.set(dep, statSync(dep).mtimeMs);
|
|
92
|
+
} catch {
|
|
93
|
+
/* file may not exist */
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Creates an evaluator function scoped to a single loader invocation.
|
|
100
|
+
*
|
|
101
|
+
* Before evaluation, checks whether any previously recorded dependency has
|
|
102
|
+
* changed on disk and invalidates the evaluator cache if so. After a
|
|
103
|
+
* successful evaluation, records fresh modification times and notifies the caller of
|
|
104
|
+
* every transitive dependency via `onDependency`.
|
|
105
|
+
*
|
|
106
|
+
* @returns A function that evaluates a yak module and returns its exports.
|
|
107
|
+
* The returned function accepts:
|
|
108
|
+
* - `modulePath` — absolute path to the module to evaluate.
|
|
109
|
+
* - `onDependency` — called once per transitive dependency so the loader
|
|
110
|
+
* can register file watchers with turbopack.
|
|
111
|
+
* @throws If the evaluated module throws at runtime — the original stack
|
|
112
|
+
* trace from the worker thread is preserved.
|
|
113
|
+
*/
|
|
114
|
+
export async function createCompilationEvaluator(): Promise<
|
|
115
|
+
(
|
|
116
|
+
modulePath: string,
|
|
117
|
+
onDependency?: (dep: string) => void,
|
|
118
|
+
) => Promise<Record<string, unknown>>
|
|
119
|
+
> {
|
|
120
|
+
const evaluator = await getEvaluatorSingleton();
|
|
121
|
+
invalidateDependenciesWithDiskModifications(evaluator);
|
|
122
|
+
|
|
123
|
+
return async (modulePath, onDependency?) => {
|
|
124
|
+
const result = await evaluator.evaluate(modulePath);
|
|
125
|
+
if (!result.ok) {
|
|
126
|
+
const error = new Error(result.error.message);
|
|
127
|
+
if (result.error.stack) {
|
|
128
|
+
error.stack = result.error.stack;
|
|
129
|
+
}
|
|
130
|
+
throw error;
|
|
131
|
+
}
|
|
132
|
+
// Store times of newly discovered dependencies for next compilation
|
|
133
|
+
recordModificationTimes(result.dependencies);
|
|
134
|
+
if (onDependency) {
|
|
135
|
+
for (const dep of result.dependencies) {
|
|
136
|
+
onDependency(dep);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return result.value;
|
|
140
|
+
};
|
|
141
|
+
}
|
package/loaders/turbo-loader.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { transform as swcTransform } from "@swc/core";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { dirname } from "node:path";
|
|
4
|
-
import { createContext, runInContext } from "node:vm";
|
|
5
4
|
import type { LoaderContext } from "webpack";
|
|
6
5
|
import { parseModule } from "../cross-file-resolver/parseModule.js";
|
|
7
6
|
import { resolveCrossFileConstant } from "../cross-file-resolver/resolveCrossFileConstant.js";
|
|
@@ -50,109 +49,97 @@ export default async function cssExtractLoader(
|
|
|
50
49
|
});
|
|
51
50
|
};
|
|
52
51
|
|
|
53
|
-
const
|
|
54
|
-
|
|
52
|
+
const crossFileDeps = new Set<string>();
|
|
53
|
+
let evaluate:
|
|
54
|
+
| Awaited<
|
|
55
|
+
ReturnType<
|
|
56
|
+
typeof import("./turbo-evaluator.js").createCompilationEvaluator
|
|
57
|
+
>
|
|
58
|
+
>
|
|
59
|
+
| undefined;
|
|
60
|
+
const fsReadFile = (filePath: string) => {
|
|
61
|
+
crossFileDeps.add(filePath);
|
|
62
|
+
return new Promise<string>((resolve, reject) =>
|
|
55
63
|
this.fs.readFile(filePath, "utf-8", (err, result) => {
|
|
56
64
|
if (err) return reject(err);
|
|
57
65
|
if (!result) return reject(new Error(`File not found: ${filePath}`));
|
|
58
66
|
resolve(result);
|
|
59
67
|
}),
|
|
60
68
|
);
|
|
69
|
+
};
|
|
61
70
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
{
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
module: {
|
|
102
|
-
type: "commonjs",
|
|
103
|
-
},
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
const moduleObject = { exports: {} };
|
|
107
|
-
const context = createContext({
|
|
108
|
-
require: (path: string) => {
|
|
109
|
-
throw new Error(
|
|
110
|
-
`Yak files cannot have imports in turbopack.\n` +
|
|
111
|
-
`Found require/import usage in: ${modulePath} to import: ${path}.\n` +
|
|
112
|
-
`Yak files should be self-contained and only export constants or styled components.\n` +
|
|
113
|
-
`This will be resolved once Vercel adds "this.importModule" support for turbopack.`,
|
|
114
|
-
);
|
|
115
|
-
},
|
|
116
|
-
__filename: modulePath,
|
|
117
|
-
__dirname: dirname(modulePath),
|
|
118
|
-
global: {},
|
|
119
|
-
console,
|
|
120
|
-
Buffer,
|
|
121
|
-
process,
|
|
122
|
-
setTimeout,
|
|
123
|
-
clearTimeout,
|
|
124
|
-
setInterval,
|
|
125
|
-
clearInterval,
|
|
126
|
-
setImmediate,
|
|
127
|
-
clearImmediate,
|
|
128
|
-
exports: moduleObject.exports,
|
|
129
|
-
module: moduleObject,
|
|
130
|
-
});
|
|
131
|
-
runInContext(transformed.code, context);
|
|
132
|
-
|
|
133
|
-
return moduleObject.exports;
|
|
71
|
+
try {
|
|
72
|
+
const result = await transform(
|
|
73
|
+
code,
|
|
74
|
+
this.resourcePath,
|
|
75
|
+
this.rootContext,
|
|
76
|
+
sourceMap,
|
|
77
|
+
);
|
|
78
|
+
debugLog("ts", result.code, this.resourcePath);
|
|
79
|
+
|
|
80
|
+
let css = extractCss(result.code, "Css");
|
|
81
|
+
debugLog("css", css, this.resourcePath);
|
|
82
|
+
|
|
83
|
+
const { resolved } = await resolveCrossFileConstant(
|
|
84
|
+
{
|
|
85
|
+
parse: (modulePath) => {
|
|
86
|
+
return parseModule(
|
|
87
|
+
{
|
|
88
|
+
transpilationMode: "Css",
|
|
89
|
+
extractExports: async (modulePath) => {
|
|
90
|
+
const sourceContents = await fsReadFile(modulePath);
|
|
91
|
+
return parseExports(sourceContents);
|
|
92
|
+
},
|
|
93
|
+
getTransformed: async (modulePath) => {
|
|
94
|
+
const sourceContent = await fsReadFile(modulePath);
|
|
95
|
+
return transform(sourceContent, modulePath, this.rootContext);
|
|
96
|
+
},
|
|
97
|
+
evaluateYakModule: async (modulePath: string) => {
|
|
98
|
+
crossFileDeps.add(modulePath);
|
|
99
|
+
/*
|
|
100
|
+
* Turbopack doesn't let us know when a compilation start so by using a singleton evaluator we
|
|
101
|
+
* we can at least ensture that we scan for file modifications only once per loader call
|
|
102
|
+
*/
|
|
103
|
+
evaluate ??= await (
|
|
104
|
+
await import("./turbo-evaluator.js")
|
|
105
|
+
).createCompilationEvaluator();
|
|
106
|
+
return evaluate(modulePath, (dep) => crossFileDeps.add(dep));
|
|
107
|
+
},
|
|
134
108
|
},
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
109
|
+
modulePath,
|
|
110
|
+
);
|
|
111
|
+
},
|
|
112
|
+
resolve: resolveFn,
|
|
138
113
|
},
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
css,
|
|
143
|
-
);
|
|
114
|
+
this.resourcePath,
|
|
115
|
+
css,
|
|
116
|
+
);
|
|
144
117
|
|
|
145
|
-
|
|
146
|
-
.
|
|
147
|
-
|
|
118
|
+
// Register cross-file dependencies so turbopack re-runs this loader
|
|
119
|
+
// when any dependency changes (analogous to webpack's this.addDependency)
|
|
120
|
+
for (const dep of crossFileDeps) {
|
|
121
|
+
this.addDependency(dep);
|
|
122
|
+
}
|
|
148
123
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
);
|
|
124
|
+
const dataUrl = result.code
|
|
125
|
+
.split("\n")
|
|
126
|
+
.find((line) => line.includes("data:text/css;base64"))!;
|
|
153
127
|
|
|
154
|
-
|
|
155
|
-
|
|
128
|
+
const codeWithCrossFileResolved = result.code.replace(
|
|
129
|
+
dataUrl,
|
|
130
|
+
`import "data:text/css;base64,${Buffer.from(resolved).toString("base64")}"`,
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
debugLog("css-resolved", resolved, this.resourcePath);
|
|
134
|
+
return callback(null, codeWithCrossFileResolved, result.map);
|
|
135
|
+
} catch (error) {
|
|
136
|
+
// Register cross-file dependencies even on error so turbopack re-runs
|
|
137
|
+
// this loader when a broken dependency is fixed.
|
|
138
|
+
for (const dep of crossFileDeps) {
|
|
139
|
+
this.addDependency(dep);
|
|
140
|
+
}
|
|
141
|
+
return callback(error instanceof Error ? error : new Error(String(error)));
|
|
142
|
+
}
|
|
156
143
|
}
|
|
157
144
|
|
|
158
145
|
function createTransform(yakPluginOptions: any, yakSwcPluginPath: string) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-yak",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "./dist/",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"@babel/parser": "^7.29.0",
|
|
73
73
|
"@babel/traverse": "^7.29.0",
|
|
74
74
|
"@swc/core": "1.15.11",
|
|
75
|
-
"yak-swc": "9.
|
|
75
|
+
"yak-swc": "9.4.0"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@testing-library/jest-dom": "6.9.1",
|