@yak/react 0.0.0-stage → 10.0.0-rc.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/LICENSE +21 -0
- package/README.md +102 -2
- package/dist/context/baseContext.cjs +9 -0
- package/dist/context/baseContext.cjs.map +1 -0
- package/dist/context/baseContext.d.cts +6 -0
- package/dist/context/baseContext.d.ts +6 -0
- package/dist/context/baseContext.js +8 -0
- package/dist/context/baseContext.js.map +1 -0
- package/dist/context/index.cjs +45 -0
- package/dist/context/index.cjs.map +1 -0
- package/dist/context/index.d.cts +21 -0
- package/dist/context/index.d.ts +21 -0
- package/dist/context/index.js +15 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/index.server.cjs +47 -0
- package/dist/context/index.server.cjs.map +1 -0
- package/dist/context/index.server.d.cts +10 -0
- package/dist/context/index.server.d.ts +10 -0
- package/dist/context/index.server.js +17 -0
- package/dist/context/index.server.js.map +1 -0
- package/dist/cross-file-resolver/index.d.ts +199 -0
- package/dist/cross-file-resolver/index.js +535 -0
- package/dist/cross-file-resolver/index.js.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +320 -0
- package/dist/index.d.ts +320 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/internal.cjs +544 -0
- package/dist/internal.cjs.map +1 -0
- package/dist/internal.d.cts +452 -0
- package/dist/internal.d.ts +452 -0
- package/dist/internal.js +363 -0
- package/dist/internal.js.map +1 -0
- package/dist/isolated-source-eval/index.d.ts +30 -0
- package/dist/isolated-source-eval/index.js +317 -0
- package/dist/isolated-source-eval/index.js.map +1 -0
- package/dist/isolated-source-eval/worker.js +59 -0
- package/dist/isolated-source-eval/worker.js.map +1 -0
- package/dist/jsx-dev-runtime.cjs +2 -0
- package/dist/jsx-dev-runtime.cjs.map +1 -0
- package/dist/jsx-dev-runtime.d.cts +7 -0
- package/dist/jsx-dev-runtime.d.ts +7 -0
- package/dist/jsx-dev-runtime.js +2 -0
- package/dist/jsx-dev-runtime.js.map +1 -0
- package/dist/jsx-runtime.cjs +2 -0
- package/dist/jsx-runtime.cjs.map +1 -0
- package/dist/jsx-runtime.d.cts +38 -0
- package/dist/jsx-runtime.d.ts +38 -0
- package/dist/jsx-runtime.js +2 -0
- package/dist/jsx-runtime.js.map +1 -0
- package/dist/loaders/turbo-loader.cjs +803 -0
- package/dist/loaders/turbo-loader.cjs.map +1 -0
- package/dist/loaders/turbo-loader.d.cts +15 -0
- package/dist/loaders/vite-plugin.d.ts +111 -0
- package/dist/loaders/vite-plugin.js +878 -0
- package/dist/loaders/vite-plugin.js.map +1 -0
- package/dist/loaders/webpack-loader.cjs +697 -0
- package/dist/loaders/webpack-loader.cjs.map +1 -0
- package/dist/loaders/webpack-loader.d.cts +12 -0
- package/dist/rsbuild/index.d.ts +29 -0
- package/dist/rsbuild/index.js +52 -0
- package/dist/rsbuild/index.js.map +1 -0
- package/dist/static/chunk-DK3Fl9T5.js +1 -0
- package/dist/static/index.cjs +2 -0
- package/dist/static/index.cjs.map +1 -0
- package/dist/static/index.d.cts +28 -0
- package/dist/static/index.d.ts +28 -0
- package/dist/static/index.js +2 -0
- package/dist/static/index.js.map +1 -0
- package/dist/withYak/index.cjs +208 -0
- package/dist/withYak/index.cjs.map +1 -0
- package/dist/withYak/index.d.cts +121 -0
- package/dist/withYak/index.d.ts +121 -0
- package/dist/withYak/index.js +177 -0
- package/dist/withYak/index.js.map +1 -0
- package/loaders/lib/resolveCrossFileSelectors.ts +162 -0
- package/loaders/turbo-evaluator.ts +134 -0
- package/loaders/turbo-loader.ts +180 -0
- package/loaders/vite-plugin.ts +28 -0
- package/loaders/webpack-loader.ts +44 -0
- package/package.json +214 -3
- package/rsbuild/index.ts +92 -0
- package/runtime/__tests__/atoms.test.tsx +48 -0
- package/runtime/__tests__/attrs.test.tsx +490 -0
- package/runtime/__tests__/cssLiteral.test.tsx +503 -0
- package/runtime/__tests__/cssProp.test.tsx +392 -0
- package/runtime/__tests__/cssPropTest.tsx +227 -0
- package/runtime/__tests__/foldedJsxParity.test.tsx +117 -0
- package/runtime/__tests__/styled.test.tsx +653 -0
- package/runtime/__tests__/tsconfig.json +18 -0
- package/runtime/__tests__/typeTest.tsx +374 -0
- package/runtime/atoms.tsx +36 -0
- package/runtime/context/README.md +84 -0
- package/runtime/context/baseContext.tsx +5 -0
- package/runtime/context/index.server.tsx +22 -0
- package/runtime/context/index.tsx +36 -0
- package/runtime/cssLiteral.tsx +214 -0
- package/runtime/globalStyle.tsx +54 -0
- package/runtime/index.ts +37 -0
- package/runtime/internal.ts +42 -0
- package/runtime/internals/mergeClassNames.ts +23 -0
- package/runtime/internals/mergeCssProp.ts +69 -0
- package/runtime/internals/propMarkers.ts +20 -0
- package/runtime/internals/unitPostFix.ts +34 -0
- package/runtime/jsx-dev-runtime.ts +6 -0
- package/runtime/jsx-runtime.ts +48 -0
- package/runtime/keyframes.tsx +30 -0
- package/runtime/mocks/cssLiteral.ts +74 -0
- package/runtime/mocks/globalStyle.ts +14 -0
- package/runtime/mocks/keyframes.ts +29 -0
- package/runtime/mocks/styled.ts +8 -0
- package/runtime/publicStyledApi.ts +159 -0
- package/runtime/styled.tsx +372 -0
- package/runtime/styledDom.tsx +139 -0
- package/withYak/allow-global-css.ts +94 -0
- package/withYak/index.ts +282 -0
|
@@ -0,0 +1,697 @@
|
|
|
1
|
+
let path = require("path");
|
|
2
|
+
let _babel_parser = require("@babel/parser");
|
|
3
|
+
|
|
4
|
+
//#region ../yak-internals/loaders/lib/debugLogger.ts
|
|
5
|
+
function createDebugLogger(debugOptions, rootPath) {
|
|
6
|
+
if (!debugOptions) return () => {};
|
|
7
|
+
throwOnDeprecatedDebugOptions(debugOptions);
|
|
8
|
+
const pattern = debugOptions === true ? void 0 : debugOptions.pattern;
|
|
9
|
+
const typesArray = debugOptions === true ? void 0 : debugOptions.types;
|
|
10
|
+
let compiledPattern = null;
|
|
11
|
+
if (pattern) try {
|
|
12
|
+
compiledPattern = new RegExp(pattern);
|
|
13
|
+
} catch (error) {
|
|
14
|
+
throw new Error(`Invalid debug pattern: "${pattern}" is not a valid regular expression. ${error instanceof Error ? error.message : ""}`);
|
|
15
|
+
}
|
|
16
|
+
const types = typesArray ? new Set(typesArray) : null;
|
|
17
|
+
return (messageType, message, filePath) => {
|
|
18
|
+
if (types && !types.has(messageType)) return;
|
|
19
|
+
const relativePath = (0, path.relative)(rootPath, filePath);
|
|
20
|
+
if (!compiledPattern || compiledPattern.test(relativePath)) console.log("🐮 Yak", `[${messageType}]`, relativePath, "\n\n", message);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function throwOnDeprecatedDebugOptions(debugOptions) {
|
|
24
|
+
if (typeof debugOptions === "string") {
|
|
25
|
+
const suggestion = suggestTypesForExtensionPattern(debugOptions) ?? `debug: { pattern: "${debugOptions}" }`;
|
|
26
|
+
throw new Error(`The debug option no longer accepts a string. Please update your config:\n Before: debug: "${debugOptions}"\n After: ${suggestion}`);
|
|
27
|
+
}
|
|
28
|
+
if (typeof debugOptions === "object" && "filter" in debugOptions) throw new Error("The debug option no longer accepts { filter, type }. Please update your config:\n Before: debug: { filter: ..., type: \"...\" }\n After: debug: { pattern: \"...\", types: [\"ts\", \"css\", \"css-resolved\"] }");
|
|
29
|
+
if (typeof debugOptions === "object" && debugOptions.pattern) {
|
|
30
|
+
const suggestion = suggestTypesForExtensionPattern(debugOptions.pattern);
|
|
31
|
+
if (suggestion) throw new Error(`The debug pattern "${debugOptions.pattern}" looks like it's filtering by output type using the old file extension convention.\nThe pattern now only matches file paths. Use the "types" option to filter by output type:\n Before: debug: { pattern: "${debugOptions.pattern}" }\n After: ${suggestion}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function suggestTypesForExtensionPattern(pattern) {
|
|
35
|
+
const extensionMatch = pattern.match(/\.\(?(?:css-resolved|css)\)?\$?$/);
|
|
36
|
+
if (!extensionMatch) return null;
|
|
37
|
+
const type = extensionMatch[0].includes("css-resolved") ? "css-resolved" : "css";
|
|
38
|
+
const remaining = pattern.slice(0, extensionMatch.index);
|
|
39
|
+
return remaining ? `debug: { pattern: "${remaining}", types: ["${type}"] }` : `debug: { types: ["${type}"] }`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region ../yak-internals/loaders/lib/extractCss.ts
|
|
44
|
+
function extractCss(code, transpilationMode) {
|
|
45
|
+
let codeString;
|
|
46
|
+
if (typeof code === "string") codeString = code;
|
|
47
|
+
else if (code instanceof Buffer) codeString = code.toString("utf-8");
|
|
48
|
+
else if (code instanceof ArrayBuffer) codeString = new TextDecoder("utf-8").decode(code);
|
|
49
|
+
else throw new Error("Invalid input type: code must be string, Buffer, or ArrayBuffer");
|
|
50
|
+
const codeParts = codeString.split("/*YAK Extracted CSS:\n");
|
|
51
|
+
let result = "";
|
|
52
|
+
for (let i = 1; i < codeParts.length; i++) {
|
|
53
|
+
const codeUntilEnd = codeParts[i].split("*/")[0];
|
|
54
|
+
result += codeUntilEnd;
|
|
55
|
+
}
|
|
56
|
+
if (result && transpilationMode !== "Css") result = "/* cssmodules-pure-no-check */\n" + result;
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region ../yak-internals/cross-file-resolver/parseModule.ts
|
|
62
|
+
async function parseModule(context, modulePath) {
|
|
63
|
+
try {
|
|
64
|
+
if ((modulePath.endsWith(".yak.ts") || modulePath.endsWith(".yak.tsx") || modulePath.endsWith(".yak.js") || modulePath.endsWith(".yak.jsx")) && context.evaluateYakModule) return {
|
|
65
|
+
type: "yak",
|
|
66
|
+
exports: {
|
|
67
|
+
importYak: false,
|
|
68
|
+
named: objectToModuleExport(await context.evaluateYakModule(modulePath)),
|
|
69
|
+
all: []
|
|
70
|
+
},
|
|
71
|
+
path: modulePath
|
|
72
|
+
};
|
|
73
|
+
if (context.cache?.parse === void 0) return await uncachedParseModule(context, modulePath);
|
|
74
|
+
const cached = context.cache.parse.get(modulePath);
|
|
75
|
+
if (cached === void 0) {
|
|
76
|
+
const parsedModule = await uncachedParseModule(context, modulePath);
|
|
77
|
+
context.cache.parse.set(modulePath, parsedModule);
|
|
78
|
+
if (context.cache.parse.addDependency) context.cache.parse.addDependency(modulePath, modulePath);
|
|
79
|
+
return parsedModule;
|
|
80
|
+
}
|
|
81
|
+
return cached;
|
|
82
|
+
} catch (error) {
|
|
83
|
+
const causeMessage = error instanceof Error ? error.message : String(error);
|
|
84
|
+
throw new Error(`Error parsing file "${modulePath}"\n Caused by: ${causeMessage}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async function uncachedParseModule(context, modulePath) {
|
|
88
|
+
const exports = await context.extractExports(modulePath);
|
|
89
|
+
if (!exports.importYak) return {
|
|
90
|
+
type: "regular",
|
|
91
|
+
path: modulePath,
|
|
92
|
+
exports
|
|
93
|
+
};
|
|
94
|
+
const transformed = await context.getTransformed(modulePath);
|
|
95
|
+
const mixins = parseMixins(transformed.code);
|
|
96
|
+
return {
|
|
97
|
+
type: "regular",
|
|
98
|
+
path: modulePath,
|
|
99
|
+
js: transformed,
|
|
100
|
+
exports,
|
|
101
|
+
styledComponents: parseStyledComponents(transformed.code, context.transpilationMode),
|
|
102
|
+
mixins
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function parseMixins(sourceContents) {
|
|
106
|
+
const mixinParts = sourceContents.split("/*YAK EXPORTED MIXIN:");
|
|
107
|
+
let mixins = {};
|
|
108
|
+
for (let i = 1; i < mixinParts.length; i++) {
|
|
109
|
+
const [comment] = mixinParts[i].split("*/", 1);
|
|
110
|
+
const position = comment.indexOf("\n");
|
|
111
|
+
const name = comment.slice(0, position);
|
|
112
|
+
mixins[name] = {
|
|
113
|
+
type: "mixin",
|
|
114
|
+
value: comment.slice(position + 1),
|
|
115
|
+
nameParts: name.split(":").map((part) => decodeURIComponent(part))
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
return mixins;
|
|
119
|
+
}
|
|
120
|
+
function parseStyledComponents(sourceContents, transpilationMode) {
|
|
121
|
+
const styledParts = sourceContents.split("/*YAK EXPORTED STYLED:");
|
|
122
|
+
let styledComponents = {};
|
|
123
|
+
for (let i = 1; i < styledParts.length; i++) {
|
|
124
|
+
const [comment] = styledParts[i].split("*/", 1);
|
|
125
|
+
const [componentName, className] = comment.split(":");
|
|
126
|
+
styledComponents[componentName] = {
|
|
127
|
+
type: "styled-component",
|
|
128
|
+
nameParts: componentName.split("."),
|
|
129
|
+
value: transpilationMode === "Css" ? `.${className}` : `:global(.${className})`
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
return styledComponents;
|
|
133
|
+
}
|
|
134
|
+
function objectToModuleExport(object) {
|
|
135
|
+
return Object.fromEntries(Object.entries(object).map(([key, value]) => {
|
|
136
|
+
if (typeof value === "string" || typeof value === "number") return [key, {
|
|
137
|
+
type: "constant",
|
|
138
|
+
value
|
|
139
|
+
}];
|
|
140
|
+
else if (value && (typeof value === "object" || Array.isArray(value))) return [key, {
|
|
141
|
+
type: "record",
|
|
142
|
+
value: objectToModuleExport(value)
|
|
143
|
+
}];
|
|
144
|
+
else return [key, {
|
|
145
|
+
type: "unsupported",
|
|
146
|
+
hint: String(value)
|
|
147
|
+
}];
|
|
148
|
+
}));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
//#endregion
|
|
152
|
+
//#region ../yak-internals/cross-file-resolver/Errors.ts
|
|
153
|
+
var CauseError = class CauseError extends Error {
|
|
154
|
+
constructor(message, options) {
|
|
155
|
+
super(`${message}${options?.cause ? `\n Caused by: ${typeof options.cause === "object" && options.cause !== null && "message" in options.cause ? options.cause.message : String(options.cause)}` : ""}`);
|
|
156
|
+
if (options?.cause instanceof CauseError && options.cause.circular) this.circular = true;
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
var ResolveError = class extends CauseError {};
|
|
160
|
+
var UnsupportedExportError = class extends ResolveError {};
|
|
161
|
+
var CircularDependencyError = class extends CauseError {
|
|
162
|
+
constructor(message, options) {
|
|
163
|
+
super(message, options);
|
|
164
|
+
this.circular = true;
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
//#endregion
|
|
169
|
+
//#region ../yak-internals/cross-file-resolver/resolveCrossFileConstant.ts
|
|
170
|
+
const yakCssImportRegex = /--yak-css-import:\s*url\("([^"]+)",?(|mixin|selector)\)(;?)/g;
|
|
171
|
+
async function resolveCrossFileConstant$1(context, filePath, css) {
|
|
172
|
+
const resolveCrossFileConstant = context.cache?.resolveCrossFileConstant;
|
|
173
|
+
if (resolveCrossFileConstant === void 0) return uncachedResolveCrossFileConstant(context, filePath, css);
|
|
174
|
+
const cacheKey = await sha1(filePath + ":" + css);
|
|
175
|
+
const cached = resolveCrossFileConstant.get(cacheKey);
|
|
176
|
+
if (cached === void 0) {
|
|
177
|
+
const resolvedCrossFilConstantPromise = uncachedResolveCrossFileConstant(context, filePath, css);
|
|
178
|
+
resolveCrossFileConstant.set(cacheKey, resolvedCrossFilConstantPromise);
|
|
179
|
+
if (resolveCrossFileConstant.addDependency) {
|
|
180
|
+
resolveCrossFileConstant.addDependency(cacheKey, filePath);
|
|
181
|
+
resolvedCrossFilConstantPromise.then((value) => {
|
|
182
|
+
for (const dep of value.dependencies) resolveCrossFileConstant.addDependency(cacheKey, dep);
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
return resolvedCrossFilConstantPromise;
|
|
186
|
+
}
|
|
187
|
+
return cached;
|
|
188
|
+
}
|
|
189
|
+
async function uncachedResolveCrossFileConstant(context, filePath, css) {
|
|
190
|
+
const yakImports = await parseYakCssImport(context, filePath, css);
|
|
191
|
+
if (yakImports.length === 0) return {
|
|
192
|
+
resolved: css,
|
|
193
|
+
dependencies: []
|
|
194
|
+
};
|
|
195
|
+
try {
|
|
196
|
+
const dependencies = /* @__PURE__ */ new Set();
|
|
197
|
+
const resolvedValues = await Promise.all(yakImports.map(async ({ moduleSpecifier, specifier }) => {
|
|
198
|
+
const { resolved: resolvedModule } = await resolveModule$1(context, moduleSpecifier);
|
|
199
|
+
const resolvedValue = await resolveModuleSpecifierRecursively(context, resolvedModule, specifier);
|
|
200
|
+
for (const dependency of resolvedValue.from) dependencies.add(dependency);
|
|
201
|
+
return resolvedValue;
|
|
202
|
+
}));
|
|
203
|
+
let result = css;
|
|
204
|
+
for (let i = yakImports.length - 1; i >= 0; i--) {
|
|
205
|
+
const { position, size, importKind, specifier, semicolon } = yakImports[i];
|
|
206
|
+
const resolved = resolvedValues[i];
|
|
207
|
+
let replacement;
|
|
208
|
+
if (resolved.type === "unresolved-tag") replacement = importKind === "mixin" ? "" : "undefined";
|
|
209
|
+
else {
|
|
210
|
+
if (importKind === "selector") {
|
|
211
|
+
if (resolved.type !== "styled-component" && resolved.type !== "constant") throw new Error(`Found "${resolved.type}" but expected a selector - did you forget a semicolon after "${specifier.join(".")}"?`);
|
|
212
|
+
}
|
|
213
|
+
replacement = resolved.type === "styled-component" ? resolved.value : resolved.value + (["}", ";"].includes(String(resolved.value).trimEnd().slice(-1)) ? "" : semicolon);
|
|
214
|
+
}
|
|
215
|
+
result = result.slice(0, position) + String(replacement) + result.slice(position + size);
|
|
216
|
+
}
|
|
217
|
+
return {
|
|
218
|
+
resolved: result,
|
|
219
|
+
dependencies: Array.from(dependencies)
|
|
220
|
+
};
|
|
221
|
+
} catch (error) {
|
|
222
|
+
throw new CauseError(`Error while resolving cross-file selectors in file "${filePath}"`, { cause: error });
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
async function parseYakCssImport(context, filePath, css) {
|
|
226
|
+
const yakImports = [];
|
|
227
|
+
for (const match of css.matchAll(yakCssImportRegex)) {
|
|
228
|
+
const [fullMatch, encodedArguments, importKind, semicolon] = match;
|
|
229
|
+
const [moduleSpecifier, ...specifier] = encodedArguments.split(":").map((entry) => decodeURIComponent(entry));
|
|
230
|
+
yakImports.push({
|
|
231
|
+
encodedArguments,
|
|
232
|
+
moduleSpecifier: await context.resolve(moduleSpecifier, filePath),
|
|
233
|
+
specifier,
|
|
234
|
+
importKind,
|
|
235
|
+
semicolon,
|
|
236
|
+
position: match.index,
|
|
237
|
+
size: fullMatch.length
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
return yakImports;
|
|
241
|
+
}
|
|
242
|
+
async function resolveModule$1(context, filePath) {
|
|
243
|
+
if (context.cache?.resolve === void 0) return uncachedResolveModule(context, filePath);
|
|
244
|
+
const cached = context.cache.resolve.get(filePath);
|
|
245
|
+
if (cached === void 0) {
|
|
246
|
+
const resolvedPromise = uncachedResolveModule(context, filePath);
|
|
247
|
+
context.cache.resolve.set(filePath, resolvedPromise);
|
|
248
|
+
if (context.cache.resolve.addDependency) {
|
|
249
|
+
context.cache.resolve.addDependency(filePath, filePath);
|
|
250
|
+
resolvedPromise.then((value) => {
|
|
251
|
+
for (const dep of value.dependencies) context.cache.resolve.addDependency(filePath, dep);
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
return resolvedPromise;
|
|
255
|
+
}
|
|
256
|
+
return cached;
|
|
257
|
+
}
|
|
258
|
+
async function uncachedResolveModule(context, filePath) {
|
|
259
|
+
const parsedModule = await context.parse(filePath);
|
|
260
|
+
const exports = parsedModule.exports;
|
|
261
|
+
if (parsedModule.type !== "regular") return {
|
|
262
|
+
resolved: {
|
|
263
|
+
path: parsedModule.path,
|
|
264
|
+
exports
|
|
265
|
+
},
|
|
266
|
+
dependencies: []
|
|
267
|
+
};
|
|
268
|
+
const dependencies = /* @__PURE__ */ new Set();
|
|
269
|
+
if (parsedModule.styledComponents) Object.values(parsedModule.styledComponents).map((styledComponent) => {
|
|
270
|
+
if (styledComponent.nameParts.length === 1) exports.named[styledComponent.nameParts[0]] = {
|
|
271
|
+
type: "styled-component",
|
|
272
|
+
className: styledComponent.value
|
|
273
|
+
};
|
|
274
|
+
else {
|
|
275
|
+
let exportEntry = exports.named[styledComponent.nameParts[0]];
|
|
276
|
+
if (!exportEntry) {
|
|
277
|
+
exportEntry = {
|
|
278
|
+
type: "record",
|
|
279
|
+
value: {}
|
|
280
|
+
};
|
|
281
|
+
exports.named[styledComponent.nameParts[0]] = exportEntry;
|
|
282
|
+
} else if (exportEntry.type !== "record") throw new CauseError(`Error parsing file "${parsedModule.path}"`, { cause: `"${styledComponent.nameParts[0]}" is not a record` });
|
|
283
|
+
let current = exportEntry.value;
|
|
284
|
+
for (let i = 1; i < styledComponent.nameParts.length - 1; i++) {
|
|
285
|
+
let next = current[styledComponent.nameParts[i]];
|
|
286
|
+
if (!next) {
|
|
287
|
+
next = {
|
|
288
|
+
type: "record",
|
|
289
|
+
value: {}
|
|
290
|
+
};
|
|
291
|
+
current[styledComponent.nameParts[i]] = next;
|
|
292
|
+
} else if (next.type !== "record") throw new CauseError(`Error parsing file "${parsedModule.path}"`, { cause: `"${styledComponent.nameParts.slice(0, i + 1).join(".")}" is not a record` });
|
|
293
|
+
current = next.value;
|
|
294
|
+
}
|
|
295
|
+
current[styledComponent.nameParts[styledComponent.nameParts.length - 1]] = {
|
|
296
|
+
type: "styled-component",
|
|
297
|
+
className: styledComponent.value
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
if (parsedModule.mixins) await Promise.all(Object.values(parsedModule.mixins).map(async (mixin) => {
|
|
302
|
+
const { resolved, dependencies: deps } = await resolveCrossFileConstant$1(context, parsedModule.path, mixin.value);
|
|
303
|
+
for (const dep of deps) dependencies.add(dep);
|
|
304
|
+
if (mixin.nameParts.length === 1) exports.named[mixin.nameParts[0]] = {
|
|
305
|
+
type: "mixin",
|
|
306
|
+
value: resolved
|
|
307
|
+
};
|
|
308
|
+
else {
|
|
309
|
+
let exportEntry = exports.named[mixin.nameParts[0]];
|
|
310
|
+
if (!exportEntry) {
|
|
311
|
+
exportEntry = {
|
|
312
|
+
type: "record",
|
|
313
|
+
value: {}
|
|
314
|
+
};
|
|
315
|
+
exports.named[mixin.nameParts[0]] = exportEntry;
|
|
316
|
+
} else if (exportEntry.type !== "record") throw new CauseError(`Error parsing file "${parsedModule.path}"`, { cause: `"${mixin.nameParts[0]}" is not a record` });
|
|
317
|
+
let current = exportEntry.value;
|
|
318
|
+
for (let i = 1; i < mixin.nameParts.length - 1; i++) {
|
|
319
|
+
let next = current[mixin.nameParts[i]];
|
|
320
|
+
if (!next) {
|
|
321
|
+
next = {
|
|
322
|
+
type: "record",
|
|
323
|
+
value: {}
|
|
324
|
+
};
|
|
325
|
+
current[mixin.nameParts[i]] = next;
|
|
326
|
+
} else if (next.type !== "record") throw new CauseError(`Error parsing file "${parsedModule.path}"`, { cause: `"${mixin.nameParts.slice(0, i + 1).join(".")}" is not a record` });
|
|
327
|
+
current = next.value;
|
|
328
|
+
}
|
|
329
|
+
current[mixin.nameParts[mixin.nameParts.length - 1]] = {
|
|
330
|
+
type: "mixin",
|
|
331
|
+
value: resolved
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
}));
|
|
335
|
+
return {
|
|
336
|
+
resolved: {
|
|
337
|
+
path: parsedModule.path,
|
|
338
|
+
exports
|
|
339
|
+
},
|
|
340
|
+
dependencies: Array.from(dependencies)
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
async function resolveModuleSpecifierRecursively(context, resolvedModule, specifiers, seen = /* @__PURE__ */ new Set()) {
|
|
344
|
+
const exportName = specifiers[0];
|
|
345
|
+
const exportValue = resolvedModule.exports.named[exportName];
|
|
346
|
+
if (exportValue !== void 0) {
|
|
347
|
+
if (seen.has(resolvedModule.path + ":" + exportName)) throw new CircularDependencyError(`Unable to resolve "${specifiers.join(".")}" in module "${resolvedModule.path}"`, { cause: "Circular dependency detected" });
|
|
348
|
+
seen.add(resolvedModule.path + ":" + exportName);
|
|
349
|
+
return resolveModuleExport(context, resolvedModule.path, exportValue, specifiers, seen);
|
|
350
|
+
}
|
|
351
|
+
let i = 1;
|
|
352
|
+
for (const from of resolvedModule.exports.all) {
|
|
353
|
+
if (context.exportAllLimit && i++ > context.exportAllLimit) throw new ResolveError(`Unable to resolve "${specifiers.join(".")}" in module "${resolvedModule.path}"`, { cause: `More than ${context.exportAllLimit} star exports are not supported for performance reasons` });
|
|
354
|
+
try {
|
|
355
|
+
const resolved = await resolveModuleExport(context, resolvedModule.path, {
|
|
356
|
+
type: "re-export",
|
|
357
|
+
from,
|
|
358
|
+
name: exportName
|
|
359
|
+
}, specifiers, seen);
|
|
360
|
+
if (seen.has(resolvedModule.path + ":*")) throw new CircularDependencyError(`Unable to resolve "${specifiers.join(".")}" in module "${resolvedModule.path}"`, { cause: "Circular dependency detected" });
|
|
361
|
+
seen.add(resolvedModule.path + ":*");
|
|
362
|
+
return resolved;
|
|
363
|
+
} catch (error) {
|
|
364
|
+
if (!(error instanceof ResolveError)) throw error;
|
|
365
|
+
if (error.circular) throw error;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
throw new ResolveError(`Unable to resolve "${specifiers.join(".")}"`, { cause: `no matching export found in module "${resolvedModule.path}"` });
|
|
369
|
+
}
|
|
370
|
+
async function resolveModuleExport(context, filePath, moduleExport, specifiers, seen) {
|
|
371
|
+
const failureMessage = `Unable to resolve "${specifiers.join(".")}" in module "${filePath}"`;
|
|
372
|
+
try {
|
|
373
|
+
switch (moduleExport.type) {
|
|
374
|
+
case "re-export": {
|
|
375
|
+
const { resolved: reExportedModule } = await resolveModule$1(context, await context.resolve(moduleExport.from, filePath));
|
|
376
|
+
const resolved = await resolveModuleSpecifierRecursively(context, reExportedModule, [moduleExport.name, ...specifiers.slice(1)], seen);
|
|
377
|
+
if (resolved) resolved.from.push(filePath);
|
|
378
|
+
return resolved;
|
|
379
|
+
}
|
|
380
|
+
case "namespace-re-export": {
|
|
381
|
+
const { resolved: reExportedModule } = await resolveModule$1(context, await context.resolve(moduleExport.from, filePath));
|
|
382
|
+
const resolved = await resolveModuleSpecifierRecursively(context, reExportedModule, specifiers.slice(1), seen);
|
|
383
|
+
if (resolved) resolved.from.push(filePath);
|
|
384
|
+
return resolved;
|
|
385
|
+
}
|
|
386
|
+
case "styled-component": return {
|
|
387
|
+
type: "styled-component",
|
|
388
|
+
from: [filePath],
|
|
389
|
+
source: filePath,
|
|
390
|
+
name: specifiers[specifiers.length - 1],
|
|
391
|
+
value: moduleExport.className
|
|
392
|
+
};
|
|
393
|
+
case "tag-template": return {
|
|
394
|
+
type: "unresolved-tag",
|
|
395
|
+
from: [filePath],
|
|
396
|
+
source: filePath,
|
|
397
|
+
name: specifiers[specifiers.length - 1]
|
|
398
|
+
};
|
|
399
|
+
case "constant": return {
|
|
400
|
+
type: "constant",
|
|
401
|
+
from: [filePath],
|
|
402
|
+
source: filePath,
|
|
403
|
+
value: moduleExport.value
|
|
404
|
+
};
|
|
405
|
+
case "record": return resolveModuleExport(context, filePath, resolveSpecifierInRecord(moduleExport, specifiers[0], specifiers.slice(1)), specifiers, seen);
|
|
406
|
+
case "mixin": return {
|
|
407
|
+
type: "mixin",
|
|
408
|
+
from: [filePath],
|
|
409
|
+
source: filePath,
|
|
410
|
+
value: moduleExport.value
|
|
411
|
+
};
|
|
412
|
+
case "unsupported": throw new UnsupportedExportError(failureMessage, { cause: explainUnsupported(filePath, specifiers.join("."), moduleExport.hint, moduleExport.source) });
|
|
413
|
+
}
|
|
414
|
+
} catch (error) {
|
|
415
|
+
if (error instanceof UnsupportedExportError) throw error;
|
|
416
|
+
throw new ResolveError(failureMessage, { cause: error });
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
function explainUnsupported(filePath, specifier, hint, source) {
|
|
420
|
+
const isYakFile = /\.yak\.(?:ts|tsx|js|jsx)$/.test(filePath);
|
|
421
|
+
const docs = "https://yak.js.org/docs/migration-from-styled-components#move-some-code-to-yak-files";
|
|
422
|
+
const snippet = source ? renderSourceSnippet(filePath, source, hint ?? "") : void 0;
|
|
423
|
+
const lines = [];
|
|
424
|
+
if (isYakFile) {
|
|
425
|
+
const got = hint ? ` (got \`${hint}\`)` : "";
|
|
426
|
+
lines.push(`\`${specifier}\` evaluated to a value that cannot be inlined into CSS${got}.`);
|
|
427
|
+
if (snippet) lines.push(snippet);
|
|
428
|
+
lines.push(` help: replace it with a string, number, or plain object/array of those`, ` see: ${docs}`);
|
|
429
|
+
return lines.join("\n");
|
|
430
|
+
}
|
|
431
|
+
const got = hint ? ` (got a ${hint})` : "";
|
|
432
|
+
lines.push(`\`${specifier}\` is not a string or number literal${got}.`);
|
|
433
|
+
if (snippet) lines.push(snippet);
|
|
434
|
+
lines.push(` help: rename "${filePath}" to "${suggestYakFileName(filePath)}" so its exports run at build time`, ` (or replace \`${specifier}\` with a literal value)`, ` see: ${docs}`);
|
|
435
|
+
return lines.join("\n");
|
|
436
|
+
}
|
|
437
|
+
function suggestYakFileName(filePath) {
|
|
438
|
+
const match = filePath.match(/^(.*)\.(ts|tsx|js|jsx)$/);
|
|
439
|
+
if (!match) return filePath;
|
|
440
|
+
return `${match[1]}.yak.${match[2]}`;
|
|
441
|
+
}
|
|
442
|
+
function renderSourceSnippet(filePath, source, label) {
|
|
443
|
+
const startLine = source.start.line;
|
|
444
|
+
const startCol = source.start.column;
|
|
445
|
+
const caretLen = source.end.line === startLine ? Math.max(1, source.end.column - startCol) : Math.max(1, source.lineText.length - startCol);
|
|
446
|
+
const lineNumStr = String(startLine);
|
|
447
|
+
const gutterPad = " ".repeat(lineNumStr.length);
|
|
448
|
+
return [
|
|
449
|
+
` --> ${filePath}:${startLine}:${startCol + 1}`,
|
|
450
|
+
` ${gutterPad} |`,
|
|
451
|
+
` ${lineNumStr} | ${source.lineText}`,
|
|
452
|
+
` ${gutterPad} | ${" ".repeat(startCol)}${"^".repeat(caretLen)} ${label}`
|
|
453
|
+
].join("\n");
|
|
454
|
+
}
|
|
455
|
+
function resolveSpecifierInRecord(record, name, specifiers) {
|
|
456
|
+
if (specifiers.length === 0) throw new ResolveError("did not expect an object");
|
|
457
|
+
let depth = 0;
|
|
458
|
+
let current = record;
|
|
459
|
+
while (current && current.type === "record" && depth < specifiers.length) {
|
|
460
|
+
current = current.value[specifiers[depth]];
|
|
461
|
+
depth += 1;
|
|
462
|
+
}
|
|
463
|
+
if (current === void 0 || depth !== specifiers.length) throw new ResolveError(`Unable to resolve "${specifiers.join(".")}" in object/array "${name}"`, { cause: "path not found" });
|
|
464
|
+
if (current.type === "constant" || current.type === "styled-component" || current.type === "mixin") return current;
|
|
465
|
+
if (current.type === "record" && "__yak" in current.value && current.value.__yak.type === "constant") return {
|
|
466
|
+
type: "mixin",
|
|
467
|
+
value: String(current.value.__yak.value)
|
|
468
|
+
};
|
|
469
|
+
throw new ResolveError(`Unable to resolve "${specifiers.join(".")}" in object/array "${name}"`, { cause: "only string and numbers are supported" });
|
|
470
|
+
}
|
|
471
|
+
async function sha1(message) {
|
|
472
|
+
const resultBuffer = await globalThis.crypto.subtle.digest("SHA-1", new TextEncoder().encode(message));
|
|
473
|
+
return Array.from(new Uint8Array(resultBuffer), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
//#endregion
|
|
477
|
+
//#region ../yak-internals/packageNames.ts
|
|
478
|
+
const yakPackageNames = ["@yak/react", "@yak/solid"];
|
|
479
|
+
|
|
480
|
+
//#endregion
|
|
481
|
+
//#region ../yak-internals/loaders/lib/parseExports.ts
|
|
482
|
+
async function parseExports(sourceContents) {
|
|
483
|
+
try {
|
|
484
|
+
const ast = (0, _babel_parser.parse)(sourceContents, {
|
|
485
|
+
sourceType: "module",
|
|
486
|
+
plugins: ["jsx", "typescript"]
|
|
487
|
+
});
|
|
488
|
+
const moduleExports = {
|
|
489
|
+
importYak: ast.program.body.some((node) => node.type === "ImportDeclaration" && yakPackageNames.includes(node.source.value)),
|
|
490
|
+
named: {},
|
|
491
|
+
all: []
|
|
492
|
+
};
|
|
493
|
+
const variableDeclarations = {};
|
|
494
|
+
let defaultIdentifier = null;
|
|
495
|
+
for (const node of ast.program.body) {
|
|
496
|
+
if (node.type === "VariableDeclaration") {
|
|
497
|
+
for (const decl of node.declarations) if (decl.id.type === "Identifier" && decl.init) variableDeclarations[decl.id.name] = decl.init;
|
|
498
|
+
}
|
|
499
|
+
if (node.type === "ExportNamedDeclaration") {
|
|
500
|
+
if (node.source) for (const specifier of node.specifiers) {
|
|
501
|
+
if (specifier.type === "ExportSpecifier" && specifier.exported.type === "Identifier" && specifier.local.type === "Identifier") moduleExports.named[specifier.exported.name] = {
|
|
502
|
+
type: "re-export",
|
|
503
|
+
from: node.source.value,
|
|
504
|
+
name: specifier.local.name
|
|
505
|
+
};
|
|
506
|
+
if (specifier.type === "ExportNamespaceSpecifier" && specifier.exported.type === "Identifier") moduleExports.named[specifier.exported.name] = {
|
|
507
|
+
type: "namespace-re-export",
|
|
508
|
+
from: node.source.value
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
else if (node.declaration?.type === "VariableDeclaration") {
|
|
512
|
+
for (const declaration of node.declaration.declarations) if (declaration.id.type === "Identifier" && declaration.init) {
|
|
513
|
+
variableDeclarations[declaration.id.name] = declaration.init;
|
|
514
|
+
const parsed = parseExportValueExpression(declaration.init, sourceContents);
|
|
515
|
+
if (parsed) moduleExports.named[declaration.id.name] = parsed;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
if (node.type === "ExportDefaultDeclaration") {
|
|
520
|
+
if (node.declaration.type === "Identifier") defaultIdentifier = node.declaration.name;
|
|
521
|
+
else if (node.declaration.type === "FunctionDeclaration" || node.declaration.type === "ClassDeclaration") moduleExports.named["default"] = {
|
|
522
|
+
type: "unsupported",
|
|
523
|
+
hint: node.declaration.type,
|
|
524
|
+
source: extractUnsupportedSource(node.declaration.loc, sourceContents)
|
|
525
|
+
};
|
|
526
|
+
else moduleExports.named["default"] = parseExportValueExpression(node.declaration, sourceContents);
|
|
527
|
+
}
|
|
528
|
+
if (node.type === "ExportAllDeclaration") moduleExports.all.push(node.source.value);
|
|
529
|
+
}
|
|
530
|
+
if (defaultIdentifier && variableDeclarations[defaultIdentifier]) moduleExports.named["default"] = parseExportValueExpression(variableDeclarations[defaultIdentifier], sourceContents);
|
|
531
|
+
return moduleExports;
|
|
532
|
+
} catch (error) {
|
|
533
|
+
throw new Error(`Error parsing exports: ${error.message}`);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
function unpackTSAsExpression(node) {
|
|
537
|
+
if (node.type === "TSAsExpression" || node.type === "TSSatisfiesExpression") return unpackTSAsExpression(node.expression);
|
|
538
|
+
return node;
|
|
539
|
+
}
|
|
540
|
+
function parseExportValueExpression(node, code) {
|
|
541
|
+
const expression = unpackTSAsExpression(node);
|
|
542
|
+
if (expression.type === "CallExpression" || expression.type === "TaggedTemplateExpression") return { type: "tag-template" };
|
|
543
|
+
else if (expression.type === "StringLiteral" || expression.type === "NumericLiteral") return {
|
|
544
|
+
type: "constant",
|
|
545
|
+
value: expression.value
|
|
546
|
+
};
|
|
547
|
+
else if (expression.type === "UnaryExpression" && expression.operator === "-" && expression.argument.type === "NumericLiteral") return {
|
|
548
|
+
type: "constant",
|
|
549
|
+
value: -expression.argument.value
|
|
550
|
+
};
|
|
551
|
+
else if (expression.type === "TemplateLiteral" && expression.quasis.length === 1) return {
|
|
552
|
+
type: "constant",
|
|
553
|
+
value: expression.quasis[0].value.raw
|
|
554
|
+
};
|
|
555
|
+
else if (expression.type === "ObjectExpression") return {
|
|
556
|
+
type: "record",
|
|
557
|
+
value: parseObjectExpression(expression, code)
|
|
558
|
+
};
|
|
559
|
+
return {
|
|
560
|
+
type: "unsupported",
|
|
561
|
+
hint: expression.type,
|
|
562
|
+
source: extractUnsupportedSource(expression.loc, code)
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
function parseObjectExpression(node, code) {
|
|
566
|
+
let result = {};
|
|
567
|
+
for (const property of node.properties) if (property.type === "ObjectProperty" && property.key.type === "Identifier") {
|
|
568
|
+
const key = property.key.name;
|
|
569
|
+
const parsed = parseExportValueExpression(property.value, code);
|
|
570
|
+
if (parsed) result[key] = parsed;
|
|
571
|
+
}
|
|
572
|
+
return result;
|
|
573
|
+
}
|
|
574
|
+
function extractUnsupportedSource(loc, code) {
|
|
575
|
+
if (!loc || !code) return void 0;
|
|
576
|
+
const lineText = code.split(/\r?\n/)[loc.start.line - 1];
|
|
577
|
+
if (lineText === void 0) return void 0;
|
|
578
|
+
return {
|
|
579
|
+
start: {
|
|
580
|
+
line: loc.start.line,
|
|
581
|
+
column: loc.start.column
|
|
582
|
+
},
|
|
583
|
+
end: {
|
|
584
|
+
line: loc.end.line,
|
|
585
|
+
column: loc.end.column
|
|
586
|
+
},
|
|
587
|
+
lineText
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
//#endregion
|
|
592
|
+
//#region loaders/lib/resolveCrossFileSelectors.ts
|
|
593
|
+
const compilationCache = /* @__PURE__ */ new WeakMap();
|
|
594
|
+
async function resolveCrossFileConstant(loader, pathContext, css) {
|
|
595
|
+
const { resolved } = await resolveCrossFileConstant$1(getResolveContext(loader), loader.resourcePath, css);
|
|
596
|
+
return resolved;
|
|
597
|
+
}
|
|
598
|
+
function getCompilationCache(loader) {
|
|
599
|
+
const compilation = loader._compilation;
|
|
600
|
+
if (!compilation) throw new Error("Webpack compilation object not available");
|
|
601
|
+
let cache = compilationCache.get(compilation);
|
|
602
|
+
if (!cache) {
|
|
603
|
+
cache = { parsedFiles: /* @__PURE__ */ new Map() };
|
|
604
|
+
compilationCache.set(compilation, cache);
|
|
605
|
+
}
|
|
606
|
+
return cache;
|
|
607
|
+
}
|
|
608
|
+
function getParseContext(loader) {
|
|
609
|
+
return {
|
|
610
|
+
cache: { parse: getCompilationCache(loader).parsedFiles },
|
|
611
|
+
async extractExports(modulePath) {
|
|
612
|
+
const sourceContents = new Promise((resolve, reject) => loader.fs.readFile(modulePath, "utf-8", (err, result) => {
|
|
613
|
+
if (err) return reject(err);
|
|
614
|
+
resolve(result || "");
|
|
615
|
+
}));
|
|
616
|
+
return parseExports(await sourceContents);
|
|
617
|
+
},
|
|
618
|
+
async getTransformed(modulePath) {
|
|
619
|
+
return { code: await new Promise((resolve, reject) => {
|
|
620
|
+
loader.loadModule(modulePath, (err, source) => {
|
|
621
|
+
if (err) {
|
|
622
|
+
const compilation = loader._compilation;
|
|
623
|
+
if (compilation) try {
|
|
624
|
+
for (const mod of compilation.modules) if ("resource" in mod && mod.resource === modulePath) {
|
|
625
|
+
const errors = mod.getErrors();
|
|
626
|
+
if (errors) {
|
|
627
|
+
const messages = Array.from(errors).map((e) => e.message).filter(Boolean);
|
|
628
|
+
if (messages.length > 0) return reject(new Error(messages.join("\n")));
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
} catch {}
|
|
632
|
+
return reject(err);
|
|
633
|
+
}
|
|
634
|
+
let sourceString;
|
|
635
|
+
if (typeof source === "string") sourceString = source;
|
|
636
|
+
else if (source instanceof Buffer) sourceString = source.toString("utf-8");
|
|
637
|
+
else if (source instanceof ArrayBuffer) sourceString = new TextDecoder("utf-8").decode(source);
|
|
638
|
+
else throw new Error("Invalid input type: code must be string, Buffer, or ArrayBuffer");
|
|
639
|
+
resolve(sourceString || "");
|
|
640
|
+
});
|
|
641
|
+
}) };
|
|
642
|
+
},
|
|
643
|
+
async evaluateYakModule(modulePath) {
|
|
644
|
+
return loader.importModule(modulePath);
|
|
645
|
+
},
|
|
646
|
+
transpilationMode: loader.getOptions().experiments?.transpilationMode
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
function getResolveContext(loader) {
|
|
650
|
+
const parseContext = getParseContext(loader);
|
|
651
|
+
return {
|
|
652
|
+
parse: (modulePath) => parseModule(parseContext, modulePath),
|
|
653
|
+
resolve: async (specifier, importer) => {
|
|
654
|
+
return resolveModule(loader, specifier, dirname(importer));
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
async function resolveModule(loader, moduleSpecifier, context) {
|
|
659
|
+
return new Promise((resolve, reject) => {
|
|
660
|
+
loader.resolve(context, moduleSpecifier, (err, result) => {
|
|
661
|
+
if (err) return reject(err);
|
|
662
|
+
if (!result) return reject(/* @__PURE__ */ new Error(`Could not resolve ${moduleSpecifier}`));
|
|
663
|
+
resolve(result);
|
|
664
|
+
});
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
const DIRNAME_POSIX_REGEX = /^((?:\.(?![^/]))|(?:(?:\/?|)(?:[\s\S]*?)))(?:\/+?|)(?:(?:\.{1,2}|[^/]+?|)(?:\.[^./]*|))(?:[/]*)$/;
|
|
668
|
+
const DIRNAME_WIN32_REGEX = /^((?:\.(?![^\\]))|(?:(?:\\?|)(?:[\s\S]*?)))(?:\\+?|)(?:(?:\.{1,2}|[^\\]+?|)(?:\.[^.\\]*|))(?:[\\]*)$/;
|
|
669
|
+
function dirname(path) {
|
|
670
|
+
let dirname = DIRNAME_POSIX_REGEX.exec(path)?.[1];
|
|
671
|
+
if (!dirname) dirname = DIRNAME_WIN32_REGEX.exec(path)?.[1];
|
|
672
|
+
if (!dirname) throw new Error(`Can't extract dirname from ${path}`);
|
|
673
|
+
return dirname;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
//#endregion
|
|
677
|
+
//#region loaders/webpack-loader.ts
|
|
678
|
+
async function cssExtractLoader(_code, sourceMap) {
|
|
679
|
+
const callback = this.async();
|
|
680
|
+
return this.loadModule(this.resourcePath, (err, source) => {
|
|
681
|
+
if (err) return callback(err);
|
|
682
|
+
if (!source) return callback(/* @__PURE__ */ new Error(`Source code for ${this.resourcePath} is empty`));
|
|
683
|
+
const { experiments } = this.getOptions();
|
|
684
|
+
const debugLog = createDebugLogger(experiments?.debug, this._compiler?.context ?? process.cwd());
|
|
685
|
+
debugLog("ts", source, this.resourcePath);
|
|
686
|
+
const css = extractCss(source, experiments?.transpilationMode);
|
|
687
|
+
debugLog("css", css, this.resourcePath);
|
|
688
|
+
return resolveCrossFileConstant(this, this.context, css).then((result) => {
|
|
689
|
+
debugLog("css-resolved", result, this.resourcePath);
|
|
690
|
+
return callback(null, result, sourceMap);
|
|
691
|
+
}, callback);
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
//#endregion
|
|
696
|
+
module.exports = cssExtractLoader;
|
|
697
|
+
//# sourceMappingURL=webpack-loader.cjs.map
|