@fluentic/style 0.1.0-beta.5 → 0.1.0-beta.6
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/CHANGELOG.md +14 -0
- package/README.md +105 -31
- package/atomic/className.ts +19 -2
- package/atomic/utils/hash.ts +1 -65
- package/compiler/compiler/compiler.ts +85 -8
- package/compiler/cssProp.ts +0 -14
- package/compiler/transform/cssProp/plugin.ts +33 -1
- package/compiler/transform/evaluator/evaluator.ts +1 -0
- package/compiler/transform/extract/chain/chain.ts +120 -11
- package/compiler/utils/import_source.ts +17 -7
- package/dist/{combine-Ca6LfFxv.js → combine-D0AXSTn-.js} +2 -2
- package/dist/{combine-Ca6LfFxv.js.map → combine-D0AXSTn-.js.map} +1 -1
- package/dist/compiler/index.mjs +1 -1
- package/dist/{compiler-OgDBuqfs.mjs → compiler-CCvRlaq0.mjs} +141 -89
- package/dist/compiler-CCvRlaq0.mjs.map +1 -0
- package/dist/{config-Barf8f4B.js → config-B-w6rOe0.js} +2 -2
- package/dist/{config-Barf8f4B.js.map → config-B-w6rOe0.js.map} +1 -1
- package/dist/{config-CsB4MuFI.js → config-B1WtpYar.js} +2 -2
- package/dist/{config-CsB4MuFI.js.map → config-B1WtpYar.js.map} +1 -1
- package/dist/{config-t76UljYv.js → config-CCMwA9Gm.js} +2 -2
- package/dist/{config-t76UljYv.js.map → config-CCMwA9Gm.js.map} +1 -1
- package/dist/{createTransformElement-DDqld3RF.js → createTransformElement-PCilcudP.js} +2 -2
- package/dist/{createTransformElement-DDqld3RF.js.map → createTransformElement-PCilcudP.js.map} +1 -1
- package/dist/{css-a9O5so0b.js → css-DirG7Jwu.js} +41 -7
- package/dist/css-DirG7Jwu.js.map +1 -0
- package/dist/{css-YfHN_8Nk.js → css-nmclCl2P.js} +8 -8
- package/dist/{css-YfHN_8Nk.js.map → css-nmclCl2P.js.map} +1 -1
- package/dist/{css-CZwrac6F.js → css-shX7_73D.js} +12 -41
- package/dist/css-shX7_73D.js.map +1 -0
- package/dist/css.js +1 -1
- package/dist/{data-CzHJg147.js → data-DUvixly5.js} +14 -6
- package/dist/data-DUvixly5.js.map +1 -0
- package/dist/{debug-DkrxyknP.js → debug-DJRCBKhM.js} +2 -2
- package/dist/{debug-DkrxyknP.js.map → debug-DJRCBKhM.js.map} +1 -1
- package/dist/dev/rsc.js +5 -5
- package/dist/{dev-z4laBwlS.js → dev-Cwha8aAp.js} +4 -4
- package/dist/{dev-z4laBwlS.js.map → dev-Cwha8aAp.js.map} +1 -1
- package/dist/dev.js +1 -1
- package/dist/dialect/extracted/index.js +1 -1
- package/dist/dialect/index.js +1 -1
- package/dist/{elementMarker-CqhU_l_m.js → elementMarker-Cb46vtLU.js} +3 -3
- package/dist/{elementMarker-CqhU_l_m.js.map → elementMarker-Cb46vtLU.js.map} +1 -1
- package/dist/entry/dev/adapter/preact.js +2 -2
- package/dist/entry/dev/adapter/react.js +2 -2
- package/dist/entry/dev/adapter/solid.js +2 -2
- package/dist/entry/dev/css.js +2 -2
- package/dist/entry/dev/jsx-dev-runtime.js +2 -2
- package/dist/entry/dev/jsx-runtime.js +2 -2
- package/dist/entry/dev.js +8 -8
- package/dist/entry/prod/adapter/preact.js +1 -1
- package/dist/entry/prod/adapter/react.js +1 -1
- package/dist/entry/prod/adapter/solid.js +1 -1
- package/dist/entry/prod/css.js +2 -2
- package/dist/entry/prod.js +2 -2
- package/dist/entry/rsc-dev/adapter/preact.js +5 -4
- package/dist/entry/rsc-dev/adapter/preact.js.map +1 -1
- package/dist/entry/rsc-dev/adapter/react.js +5 -4
- package/dist/entry/rsc-dev/adapter/react.js.map +1 -1
- package/dist/entry/rsc-dev/adapter/solid.js +5 -4
- package/dist/entry/rsc-dev/adapter/solid.js.map +1 -1
- package/dist/entry/rsc-dev/css.js +2 -2
- package/dist/entry/rsc-dev/dev.js +5 -6
- package/dist/entry/rsc-dev/dev.js.map +1 -1
- package/dist/entry/rsc-dev/jsx-dev-runtime.js +2 -2
- package/dist/entry/rsc-dev/jsx-runtime.js +2 -2
- package/dist/entry/rsc-dev.js +5 -5
- package/dist/entry/rsc-prod/css.js +2 -2
- package/dist/entry/rsc-prod.js +2 -2
- package/dist/{env-Db2cRt-h.js → env-0Gu2Jh47.js} +2 -39
- package/dist/env-0Gu2Jh47.js.map +1 -0
- package/dist/{utils-CLnpwhJd.js → getClassName-CHZKhmde.js} +5 -43
- package/dist/getClassName-CHZKhmde.js.map +1 -0
- package/dist/{getClassName-DaZF5nfJ.js → getClassName-CHd0iCXp.js} +3 -3
- package/dist/{getClassName-DaZF5nfJ.js.map → getClassName-CHd0iCXp.js.map} +1 -1
- package/dist/global-Dg37z0lV.js +14 -0
- package/dist/global-Dg37z0lV.js.map +1 -0
- package/dist/{hash-BOlQThNz.js → hash-Cr-LCWDt.js} +2 -40
- package/dist/hash-Cr-LCWDt.js.map +1 -0
- package/dist/index.js +6 -6
- package/dist/jsx/jsx-dev-runtime.js +1 -1
- package/dist/jsx/jsx-dev-runtime.server.js +1 -1
- package/dist/jsx/jsx-runtime.js +1 -1
- package/dist/jsx/jsx-runtime.server.js +1 -1
- package/dist/{jsx-C2pnWLcb.js → jsx-BMFC8_tA.js} +4 -4
- package/dist/{jsx-C2pnWLcb.js.map → jsx-BMFC8_tA.js.map} +1 -1
- package/dist/{jsx_runtime-XJSHujgI.js → jsx_runtime-Ch1pZ6-n.js} +2 -2
- package/dist/{jsx_runtime-XJSHujgI.js.map → jsx_runtime-Ch1pZ6-n.js.map} +1 -1
- package/dist/{loader-DHvgp0fK.mjs → loader-hNaefW-U.mjs} +13 -14
- package/dist/loader-hNaefW-U.mjs.map +1 -0
- package/dist/{misc-BuSLnvx0.mjs → misc-1OS0aeY1.mjs} +2 -2
- package/dist/{misc-BuSLnvx0.mjs.map → misc-1OS0aeY1.mjs.map} +1 -1
- package/dist/{namedTokens-D3tt-joz.js → namedTokens-mgRfd9hs.js} +3 -3
- package/dist/{namedTokens-D3tt-joz.js.map → namedTokens-mgRfd9hs.js.map} +1 -1
- package/dist/plugin/farm/index.mjs +3 -3
- package/dist/plugin/nextjs/index.mjs +120 -16
- package/dist/plugin/nextjs/index.mjs.map +1 -1
- package/dist/plugin/nextjs/loader.mjs +4 -4
- package/dist/plugin/parcel/index.cjs +1 -1
- package/dist/plugin/parcel/index.mjs +2 -2
- package/dist/plugin/parcel/optimizer.cjs +1 -1
- package/dist/plugin/parcel/optimizer.mjs +2 -2
- package/dist/plugin/parcel/resolver.cjs +1 -1
- package/dist/plugin/parcel/resolver.mjs +2 -2
- package/dist/plugin/parcel/runtime.cjs +1 -1
- package/dist/plugin/parcel/runtime.mjs +1 -1
- package/dist/plugin/parcel/transformer.cjs +1 -1
- package/dist/plugin/parcel/transformer.mjs +2 -2
- package/dist/plugin/rspack/index.mjs +2 -2
- package/dist/plugin/vite/index.mjs +3 -3
- package/dist/plugin/webpack/index.mjs +2 -2
- package/dist/plugin/webpack/loader.mjs +2 -2
- package/dist/presets/tailwind/index.js +25 -3
- package/dist/presets/tailwind/index.js.map +1 -1
- package/dist/{registry-r3BKWqpI.mjs → registry-OA0niXJL.mjs} +2 -2
- package/dist/{registry-r3BKWqpI.mjs.map → registry-OA0niXJL.mjs.map} +1 -1
- package/dist/{resolveClassNameRuntime-D5a37GNr.js → resolveClassNameRuntime-BKXT1bmR.js} +2 -2
- package/dist/{resolveClassNameRuntime-D5a37GNr.js.map → resolveClassNameRuntime-BKXT1bmR.js.map} +1 -1
- package/dist/{rules-B0_rKPfB.js → rules-DgcCENkw.js} +5 -5
- package/dist/{rules-B0_rKPfB.js.map → rules-DgcCENkw.js.map} +1 -1
- package/dist/server.js +10 -10
- package/dist/{shared-8_Msr7Q5.cjs → shared-Bc9RwNNj.cjs} +140 -88
- package/dist/shared-Bc9RwNNj.cjs.map +1 -0
- package/dist/{shared-BGO_05rW.mjs → shared-COiLPdZ1.mjs} +4 -4
- package/dist/{shared-BGO_05rW.mjs.map → shared-COiLPdZ1.mjs.map} +1 -1
- package/dist/sheet-B87QCFWF.js +7 -0
- package/dist/{sheet-BpLZIIuO.js.map → sheet-B87QCFWF.js.map} +1 -1
- package/dist/{sidecar-Bu2x35JE.mjs → sidecar-ViZUL9B8.mjs} +3 -3
- package/dist/{sidecar-Bu2x35JE.mjs.map → sidecar-ViZUL9B8.mjs.map} +1 -1
- package/dist/{styleStore-BDy5TH6N.js → styleStore-BlC8Ax9f.js} +3 -3
- package/dist/{styleStore-BDy5TH6N.js.map → styleStore-BlC8Ax9f.js.map} +1 -1
- package/dist/{styleStore-DX3z_UVK.js → styleStore-DHzH25A7.js} +2 -2
- package/dist/{styleStore-DX3z_UVK.js.map → styleStore-DHzH25A7.js.map} +1 -1
- package/dist/{token-BsW_S8fN.js → token-CAQWMtan.js} +2 -2
- package/dist/{token-BsW_S8fN.js.map → token-CAQWMtan.js.map} +1 -1
- package/dist/{trace-BdKEpgME.js → trace-D3yBmJad.js} +2 -2
- package/dist/{trace-BdKEpgME.js.map → trace-D3yBmJad.js.map} +1 -1
- package/dist/{trace-DcuMxR45.js → trace-DdXWjgAD.js} +3 -3
- package/dist/{trace-DcuMxR45.js.map → trace-DdXWjgAD.js.map} +1 -1
- package/dist/{types-BEUgXuu2.js → types-BhdAXX7z.js} +7 -7
- package/dist/{types-BEUgXuu2.js.map → types-BhdAXX7z.js.map} +1 -1
- package/dist/utils-B6HVRX10.js +42 -0
- package/dist/utils-B6HVRX10.js.map +1 -0
- package/dist/{utils-BPDxr-oc.mjs → utils-C7UalRKf.mjs} +41 -7
- package/dist/utils-C7UalRKf.mjs.map +1 -0
- package/dist/{utils-sBVZEq4u.js → utils-Cd4wqN56.js} +2 -39
- package/dist/utils-Cd4wqN56.js.map +1 -0
- package/dist/{utils-DZjLTV4D.mjs → utils-DjxH0zc7.mjs} +3 -3
- package/dist/{utils-DZjLTV4D.mjs.map → utils-DjxH0zc7.mjs.map} +1 -1
- package/dist/utils-DxCpyV2E.js +62 -0
- package/dist/utils-DxCpyV2E.js.map +1 -0
- package/dist/utils.js +2 -2
- package/dist/{webpack-DTKgR-HY.mjs → webpack-6et2ZVI6.mjs} +5 -5
- package/dist/{webpack-DTKgR-HY.mjs.map → webpack-6et2ZVI6.mjs.map} +1 -1
- package/entry/rsc_dev/adapter/preact.ts +9 -1
- package/entry/rsc_dev/adapter/react.ts +9 -1
- package/entry/rsc_dev/adapter/solid.ts +9 -1
- package/package.json +21 -11
- package/plugin/bundler/webpack/shared/loader.ts +9 -7
- package/plugin/nextjs/plugin.ts +205 -15
- package/plugin/nextjs/types.ts +1 -2
- package/plugin/nextjs/utils.ts +50 -0
- package/presets/tailwind/classname/transform.ts +32 -1
- package/runtime/adapter/utils.ts +40 -14
- package/dist/compiler-OgDBuqfs.mjs.map +0 -1
- package/dist/css-CZwrac6F.js.map +0 -1
- package/dist/css-a9O5so0b.js.map +0 -1
- package/dist/css_extra-CXXZAylc.js +0 -8
- package/dist/css_extra-CXXZAylc.js.map +0 -1
- package/dist/data-CzHJg147.js.map +0 -1
- package/dist/env-Db2cRt-h.js.map +0 -1
- package/dist/getClassName-DKtQl5ZX.js +0 -32
- package/dist/getClassName-DKtQl5ZX.js.map +0 -1
- package/dist/global-zYTvWskP.js +0 -10
- package/dist/global-zYTvWskP.js.map +0 -1
- package/dist/hash-BOlQThNz.js.map +0 -1
- package/dist/loader-DHvgp0fK.mjs.map +0 -1
- package/dist/shared-8_Msr7Q5.cjs.map +0 -1
- package/dist/sheet-BpLZIIuO.js +0 -7
- package/dist/utils-BPDxr-oc.mjs.map +0 -1
- package/dist/utils-CLnpwhJd.js.map +0 -1
- package/dist/utils-okFWrQsg.js +0 -41
- package/dist/utils-okFWrQsg.js.map +0 -1
- package/dist/utils-sBVZEq4u.js.map +0 -1
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
//#region runtime/adapter/utils.ts
|
|
2
|
+
function createMergeJsxProps(getClassName, options) {
|
|
3
|
+
return function mergeJsxProps(parts) {
|
|
4
|
+
let props = null;
|
|
5
|
+
let cssProps = null;
|
|
6
|
+
for (let index = 0; index < parts.length; index++) {
|
|
7
|
+
const result = mergePart(props, parts[index]);
|
|
8
|
+
props = result.props;
|
|
9
|
+
if (result.css) {
|
|
10
|
+
if (!cssProps) cssProps = [];
|
|
11
|
+
cssProps.push(result.css);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return mergeCssProps(props ?? {}, cssProps, getClassName, options);
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function mergePart(props, part) {
|
|
18
|
+
if (!part) return {
|
|
19
|
+
css: null,
|
|
20
|
+
props
|
|
21
|
+
};
|
|
22
|
+
const next = props ? { ...props } : {};
|
|
23
|
+
const attrs = part;
|
|
24
|
+
const css = attrs.css;
|
|
25
|
+
for (const key in attrs) if (key !== "css") next[key] = attrs[key];
|
|
26
|
+
return {
|
|
27
|
+
css: css ? css : null,
|
|
28
|
+
props: next
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function mergeCssProps(props, cssProps, getClassName, options) {
|
|
32
|
+
if (!cssProps?.length) return props;
|
|
33
|
+
const className = getClassName(cssProps.length === 1 ? cssProps[0] : cssProps, {
|
|
34
|
+
className: getClassValue(props, options.classProp),
|
|
35
|
+
style: props[options.styleProp]
|
|
36
|
+
});
|
|
37
|
+
delete props.class;
|
|
38
|
+
delete props.className;
|
|
39
|
+
if (className.className !== void 0) props[options.classProp] = className.className;
|
|
40
|
+
if (className.style !== void 0) props[options.styleProp] = options.styleMode === "solid" ? toSolidStyle(className.style) : className.style;
|
|
41
|
+
if (options.preserveResultProps) for (const key in className) {
|
|
42
|
+
if (key === "className" || key === "style") continue;
|
|
43
|
+
props[key] = className[key];
|
|
44
|
+
}
|
|
45
|
+
return props;
|
|
46
|
+
}
|
|
47
|
+
function getClassValue(props, classProp) {
|
|
48
|
+
return props[classProp] ?? props[classProp === "class" ? "className" : "class"];
|
|
49
|
+
}
|
|
50
|
+
function toSolidStyle(style) {
|
|
51
|
+
const next = {};
|
|
52
|
+
for (const key in style) next[toCssPropertyName(key)] = style[key];
|
|
53
|
+
return next;
|
|
54
|
+
}
|
|
55
|
+
function toCssPropertyName(key) {
|
|
56
|
+
if (key.startsWith("--") || key.includes("-")) return key;
|
|
57
|
+
return key.replace(/[A-Z]/g, (char) => `-${char.toLowerCase()}`);
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
export { createMergeJsxProps as t };
|
|
61
|
+
|
|
62
|
+
//# sourceMappingURL=utils-DxCpyV2E.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils-DxCpyV2E.js","names":[],"sources":["../runtime/adapter/utils.ts"],"sourcesContent":["import type { ClassNameProps, ClassNameResult } from '../core/className';\nimport type { StyleProp } from '../types';\n\nexport type JsxCssPropStyleMode = 'react' | 'solid';\n\nexport type JsxCssPropMergeOptions = {\n classProp: 'class' | 'className';\n styleProp: 'style';\n styleMode: JsxCssPropStyleMode;\n preserveResultProps?: boolean;\n};\n\nexport type JsxCssPropInput = Record<PropertyKey, unknown>;\n\nexport type GetClassNameFn = (\n styleProp: StyleProp,\n props?: ClassNameProps,\n) => ClassNameResult;\n\nexport function createMergeJsxProps(\n getClassName: GetClassNameFn,\n options: JsxCssPropMergeOptions,\n) {\n return function mergeJsxProps(parts: readonly unknown[]) {\n let props: JsxCssPropInput | null = null;\n let cssProps: StyleProp[] | null = null;\n\n for (let index = 0; index < parts.length; index++) {\n const result = mergePart(props, parts[index]);\n props = result.props;\n\n if (result.css) {\n if (!cssProps) cssProps = [];\n cssProps.push(result.css);\n }\n }\n\n return mergeCssProps(props ?? {}, cssProps, getClassName, options);\n };\n}\n\nfunction mergePart(\n props: JsxCssPropInput | null,\n part: unknown,\n) {\n if (!part) return { css: null, props };\n\n const next = props ? { ...props } : {};\n const attrs = part as JsxCssPropInput;\n const css = attrs.css;\n\n for (const key in attrs) {\n if (key !== 'css') next[key] = attrs[key];\n }\n\n return {\n css: css ? css as StyleProp : null,\n props: next,\n };\n}\n\nfunction mergeCssProps(\n props: JsxCssPropInput,\n cssProps: StyleProp[] | null,\n getClassName: GetClassNameFn,\n options: JsxCssPropMergeOptions,\n) {\n if (!cssProps?.length) return props;\n\n const className = getClassName(cssProps.length === 1 ? cssProps[0] : cssProps, {\n className: getClassValue(props, options.classProp),\n style: props[options.styleProp] as ClassNameProps['style'],\n });\n\n delete props.class;\n delete props.className;\n\n if (className.className !== undefined) {\n props[options.classProp] = className.className;\n }\n\n if (className.style !== undefined) {\n props[options.styleProp] = options.styleMode === 'solid'\n ? toSolidStyle(className.style as Record<string, unknown>)\n : className.style;\n }\n\n if (options.preserveResultProps) {\n for (const key in className) {\n if (key === 'className' || key === 'style') continue;\n\n props[key] = className[key as keyof ClassNameResult];\n }\n }\n\n return props;\n}\n\nfunction getClassValue(\n props: JsxCssPropInput,\n classProp: 'class' | 'className',\n) {\n return (props[classProp] ?? props[classProp === 'class' ? 'className' : 'class']) as ClassNameProps['className'];\n}\n\nfunction toSolidStyle(style: Record<string, unknown>) {\n const next: Record<string, unknown> = {};\n\n for (const key in style) {\n next[toCssPropertyName(key)] = style[key];\n }\n\n return next;\n}\n\nfunction toCssPropertyName(key: string) {\n if (key.startsWith('--') || key.includes('-')) return key;\n\n return key.replace(/[A-Z]/g, (char) => `-${char.toLowerCase()}`);\n}\n"],"mappings":";AAmBA,SAAgB,oBACd,cACA,SACA;CACA,OAAO,SAAS,cAAc,OAA2B;EACvD,IAAI,QAAgC;EACpC,IAAI,WAA+B;EAEnC,KAAK,IAAI,QAAQ,GAAG,QAAQ,MAAM,QAAQ,SAAS;GACjD,MAAM,SAAS,UAAU,OAAO,MAAM,MAAM;GAC5C,QAAQ,OAAO;GAEf,IAAI,OAAO,KAAK;IACd,IAAI,CAAC,UAAU,WAAW,CAAC;IAC3B,SAAS,KAAK,OAAO,GAAG;GAC1B;EACF;EAEA,OAAO,cAAc,SAAS,CAAC,GAAG,UAAU,cAAc,OAAO;CACnE;AACF;AAEA,SAAS,UACP,OACA,MACA;CACA,IAA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 +1,6 @@
|
|
|
1
|
-
import "./data-
|
|
1
|
+
import "./data-DUvixly5.js";
|
|
2
2
|
import { _ as isSlotData, m as isSelectorData } from "./value-CpJpQ00y.js";
|
|
3
|
-
import { h as isStyleTokenData } from "./token-
|
|
3
|
+
import { h as isStyleTokenData } from "./token-CAQWMtan.js";
|
|
4
4
|
//#region style/utils/expose.ts
|
|
5
5
|
function exposeStyle(styles) {
|
|
6
6
|
return exposeStyleObject(styles);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { r as getStyleRuntimeImportPath } from "./compiler-
|
|
2
|
-
import { C as createPluginCompiler, D as DEFAULT_TRANSFORM_INCLUDE, E as DEFAULT_TRANSFORM_EXCLUDE, I as writePluginCacheFile, M as EXTRACTED_CSS_MARKER, P as PLUGIN_NAME, S as createCompilerId, T as invalidateFiles, _ as getStyleRuntimeMode, d as resolvePluginSourcemapFilePath, g as getStyleEntryDefines, h as getPluginBuildDevConfig, j as BUNDLE_CSS_FILE, m as getPluginBuildConfig, t as formatError, u as resolveDevSourcemapMode, w as getPluginCacheDir, y as transformCssOutput } from "./misc-
|
|
3
|
-
import { t as getSourcemapSidecar } from "./sidecar-
|
|
4
|
-
import { a as prependWebpackRuntimeEntry, i as hasWebpackCssMarker, n as getStylePackageDistPath, o as replaceWebpackCssMarker, r as getTransformLoaderPath, s as webpackRegistry, t as createWebpackRuntimeModuleSource } from "./utils-
|
|
1
|
+
import { r as getStyleRuntimeImportPath } from "./compiler-CCvRlaq0.mjs";
|
|
2
|
+
import { C as createPluginCompiler, D as DEFAULT_TRANSFORM_INCLUDE, E as DEFAULT_TRANSFORM_EXCLUDE, I as writePluginCacheFile, M as EXTRACTED_CSS_MARKER, P as PLUGIN_NAME, S as createCompilerId, T as invalidateFiles, _ as getStyleRuntimeMode, d as resolvePluginSourcemapFilePath, g as getStyleEntryDefines, h as getPluginBuildDevConfig, j as BUNDLE_CSS_FILE, m as getPluginBuildConfig, t as formatError, u as resolveDevSourcemapMode, w as getPluginCacheDir, y as transformCssOutput } from "./misc-1OS0aeY1.mjs";
|
|
3
|
+
import { t as getSourcemapSidecar } from "./sidecar-ViZUL9B8.mjs";
|
|
4
|
+
import { a as prependWebpackRuntimeEntry, i as hasWebpackCssMarker, n as getStylePackageDistPath, o as replaceWebpackCssMarker, r as getTransformLoaderPath, s as webpackRegistry, t as createWebpackRuntimeModuleSource } from "./utils-DjxH0zc7.mjs";
|
|
5
5
|
//#region plugin/bundler/webpack/plugin.ts
|
|
6
6
|
const WEBPACK_RUNTIME_FILE = "webpack-runtime.js";
|
|
7
7
|
function plugin(options = {}) {
|
|
@@ -104,4 +104,4 @@ function isRspackCompiler(compiler) {
|
|
|
104
104
|
//#endregion
|
|
105
105
|
export { plugin as t };
|
|
106
106
|
|
|
107
|
-
//# sourceMappingURL=webpack-
|
|
107
|
+
//# sourceMappingURL=webpack-6et2ZVI6.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webpack-
|
|
1
|
+
{"version":3,"file":"webpack-6et2ZVI6.mjs","names":[],"sources":["../plugin/bundler/webpack/plugin.ts"],"sourcesContent":["import type { Compiler, RuleSetRule, WebpackPluginInstance } from 'webpack';\nimport { getStyleRuntimeImportPath } from '../../../compiler/utils/imports';\nimport {\n BUNDLE_CSS_FILE,\n createCompilerId,\n createPluginCompiler,\n DEFAULT_TRANSFORM_EXCLUDE,\n DEFAULT_TRANSFORM_INCLUDE,\n EXTRACTED_CSS_MARKER,\n getPluginCacheDir,\n invalidateFiles,\n PLUGIN_NAME,\n type PluginOptions,\n resolvePluginSourcemapFilePath,\n transformCssOutput,\n writePluginCacheFile,\n} from '../../utils';\nimport { formatError } from '../../utils/misc';\nimport {\n getPluginBuildConfig,\n getPluginBuildDevConfig,\n getStyleEntryDefines,\n getStyleRuntimeMode,\n} from '../../utils/runtimeEntry';\nimport { getSourcemapSidecar } from '../../utils/sidecar';\nimport { resolveDevSourcemapMode } from '../../utils/sourcemap';\nimport {\n createWebpackRuntimeModuleSource,\n getStylePackageDistPath,\n getTransformLoaderPath,\n hasWebpackCssMarker,\n prependWebpackRuntimeEntry,\n replaceWebpackCssMarker,\n type WebpackLoaderState,\n webpackRegistry,\n} from './utils';\n\nexport { CssPropPresets } from '../../utils';\nexport type { CompilerCssPropOptions, PluginOptions } from '../../utils';\n\nconst WEBPACK_RUNTIME_FILE = 'webpack-runtime.js';\n\nexport default plugin;\n\nexport function plugin(options: PluginOptions = {}) {\n return new WebpackPlugin(options);\n}\n\nclass WebpackPlugin implements WebpackPluginInstance {\n private readonly options: PluginOptions;\n\n constructor(options: PluginOptions = {}) {\n this.options = options;\n }\n\n apply(compiler: Compiler) {\n const dev = compiler.options.mode === 'development';\n const extract = !dev;\n\n const buildConfig = getPluginBuildConfig(this.options);\n const buildDevConfig = getPluginBuildDevConfig(this.options);\n const cacheDir = getPluginCacheDir(compiler.context, this.options.cacheDir);\n const devSourcemap = resolveDevSourcemapMode(this.options.devSourcemap, dev);\n\n const sourcemapSidecar = devSourcemap === 'sidecarServer'\n ? getSourcemapSidecar({ projectDir: compiler.context, cacheDir })\n : null;\n\n const getSourcemapFilePath = resolvePluginSourcemapFilePath(\n this.options.getSourcemapFilePath,\n sourcemapSidecar,\n );\n\n const runtimeMode = getStyleRuntimeMode(dev);\n const useRuntimeSidecarUrl = isRspackCompiler(compiler) && devSourcemap === 'sidecarServer';\n\n const createRuntimeSource = (sidecarUrl: string | null = null) =>\n createWebpackRuntimeModuleSource(\n extract,\n cssFilePath,\n useRuntimeSidecarUrl\n ? {\n runtimeImportPath: getStyleRuntimeImportPath(runtimeMode),\n sidecarUrl,\n }\n : undefined,\n );\n\n const state = createPluginCompiler({\n projectDir: compiler.context,\n cacheDir,\n dev,\n options: { ...this.options, devSourcemap, getSourcemapFilePath },\n runtimeMode,\n });\n\n const cssFilePath = extract\n ? writePluginCacheFile(state, BUNDLE_CSS_FILE, EXTRACTED_CSS_MARKER)\n : null;\n\n const runtimeFilePath = writePluginCacheFile(\n state,\n WEBPACK_RUNTIME_FILE,\n createRuntimeSource(),\n );\n\n const compilerId = createCompilerId('webpack');\n\n webpackRegistry.setEntry<WebpackLoaderState>(compilerId, {\n transform: state.transform,\n });\n\n compiler.options.entry = prependWebpackRuntimeEntry(\n compiler.options.entry,\n runtimeFilePath,\n );\n\n addTransformLoader(compiler, this.options, compilerId);\n\n const entryDefines = getStyleEntryDefines(buildConfig, buildDevConfig, null);\n\n compiler.options.plugins ??= [];\n compiler.options.plugins.push(\n new compiler.webpack.DefinePlugin(entryDefines),\n );\n\n compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, async () => {\n await sourcemapSidecar?.ensureStarted();\n\n Object.assign(\n entryDefines,\n getStyleEntryDefines(\n buildConfig,\n buildDevConfig,\n sourcemapSidecar?.getBaseUrl() || null,\n ),\n );\n writePluginCacheFile(\n state,\n WEBPACK_RUNTIME_FILE,\n createRuntimeSource(sourcemapSidecar?.getBaseUrl() || null),\n );\n });\n\n compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async (watchCompiler) => {\n await sourcemapSidecar?.ensureStarted();\n Object.assign(\n entryDefines,\n getStyleEntryDefines(\n buildConfig,\n buildDevConfig,\n sourcemapSidecar?.getBaseUrl() || null,\n ),\n );\n writePluginCacheFile(\n state,\n WEBPACK_RUNTIME_FILE,\n createRuntimeSource(sourcemapSidecar?.getBaseUrl() || null),\n );\n\n const files = watchCompiler.modifiedFiles;\n if (!files || !files.size) return;\n\n invalidateFiles(state.compiler, files);\n state.filter.clear();\n });\n\n compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {\n if (dev) return;\n\n compilation.hooks.processAssets.tapPromise(\n {\n name: PLUGIN_NAME,\n stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,\n },\n async () => {\n const css = await transformCssOutput(\n state.compiler.getExtractedCss(),\n this.options.cssOutput,\n BUNDLE_CSS_FILE,\n );\n if (!css) return;\n\n for (const asset of compilation.getAssets()) {\n if (!asset.name.endsWith('.css')) continue;\n\n const source = asset.source.source().toString();\n if (!hasWebpackCssMarker(source, EXTRACTED_CSS_MARKER)) continue;\n\n compilation.updateAsset(\n asset.name,\n new compiler.webpack.sources.RawSource(\n replaceWebpackCssMarker(source, EXTRACTED_CSS_MARKER, css),\n ),\n );\n\n return;\n }\n\n compilation.warnings.push(\n new Error(formatError(\n 'No CSS asset containing the Fluentic marker was emitted by Webpack, so extracted CSS could not be attached. ' +\n 'Make sure your Webpack config handles CSS imports so Webpack owns the output filename, hashing, and runtime loading.',\n )),\n );\n },\n );\n });\n }\n}\n\nfunction addTransformLoader(\n compiler: Compiler,\n options: PluginOptions,\n compilerId: string,\n) {\n const loader = {\n loader: getTransformLoaderPath(),\n options: { ...options, compilerId },\n };\n\n const rule: RuleSetRule = {\n use: [loader],\n enforce: 'pre',\n test: DEFAULT_TRANSFORM_INCLUDE,\n exclude: options.include ? undefined : [\n DEFAULT_TRANSFORM_EXCLUDE,\n getStylePackageDistPath(),\n ],\n };\n\n compiler.options.module.rules.unshift(rule);\n}\n\nfunction isRspackCompiler(compiler: Compiler) {\n const webpack = compiler.webpack as typeof compiler.webpack & {\n rspackVersion?: unknown;\n };\n\n return typeof webpack.rspackVersion === 'string';\n}\n"],"mappings":";;;;;AAwCA,MAAM,uBAAuB;AAI7B,SAAgB,OAAO,UAAyB,CAAC,GAAG;CAClD,OAAO,IAAI,cAAc,OAAO;AAClC;AAEA,IAAM,gBAAN,MAAqD;CAGnD,YAAY,UAAyB,CAAC,GAAG;EACvC,KAAK,UAAU;CACjB;CAEA,MAAM,UAAoB;EACxB,MAAM,MAAM,SAAS,QAAQ,SAAS;EACtC,MAAM,UAAU,CAAC;EAEjB,MAAM,cAAc,qBAAqB,KAAK,OAAO;EACrD,MAAM,iBAAiB,wBAAwB,KAAK,OAAO;EAC3D,MAAM,WAAW,kBAAkB,SAAS,SAAS,KAAK,QAAQ,QAAQ;EAC1E,MAAM,eAAe,wBAAwB,KAAK,QAAQ,cAAc,GAA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AIH,kBAAkB;AAC1C"}
|
|
@@ -1 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { createMergeJsxProps } from '../../../runtime/adapter/utils';
|
|
2
|
+
import { getClassName } from '../../../runtime/rsc/getClassName';
|
|
3
|
+
|
|
4
|
+
export const mergeJsxProps = createMergeJsxProps(getClassName, {
|
|
5
|
+
classProp: 'class',
|
|
6
|
+
styleProp: 'style',
|
|
7
|
+
styleMode: 'react',
|
|
8
|
+
preserveResultProps: true,
|
|
9
|
+
});
|
|
@@ -1 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { createMergeJsxProps } from '../../../runtime/adapter/utils';
|
|
2
|
+
import { getClassName } from '../../../runtime/rsc/getClassName';
|
|
3
|
+
|
|
4
|
+
export const mergeJsxProps = createMergeJsxProps(getClassName, {
|
|
5
|
+
classProp: 'className',
|
|
6
|
+
styleProp: 'style',
|
|
7
|
+
styleMode: 'react',
|
|
8
|
+
preserveResultProps: true,
|
|
9
|
+
});
|
|
@@ -1 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { createMergeJsxProps } from '../../../runtime/adapter/utils';
|
|
2
|
+
import { getClassName } from '../../../runtime/rsc/getClassName';
|
|
3
|
+
|
|
4
|
+
export const mergeJsxProps = createMergeJsxProps(getClassName, {
|
|
5
|
+
classProp: 'class',
|
|
6
|
+
styleProp: 'style',
|
|
7
|
+
styleMode: 'solid',
|
|
8
|
+
preserveResultProps: true,
|
|
9
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluentic/style",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.6",
|
|
4
4
|
"description": "Type-safe styles that scale with your components.",
|
|
5
5
|
"homepage": "https://fluenticstack.com/style",
|
|
6
6
|
"repository": {
|
|
@@ -39,7 +39,8 @@
|
|
|
39
39
|
".": {
|
|
40
40
|
"types": "./index.ts",
|
|
41
41
|
"react-server": "./dist/server.js",
|
|
42
|
-
"import": "./dist/index.js"
|
|
42
|
+
"import": "./dist/index.js",
|
|
43
|
+
"default": "./dist/index.js"
|
|
43
44
|
},
|
|
44
45
|
"./plugin/vite": {
|
|
45
46
|
"types": "./plugin/bundler/vite/index.ts",
|
|
@@ -130,7 +131,8 @@
|
|
|
130
131
|
},
|
|
131
132
|
"./config": {
|
|
132
133
|
"types": "./config/index.ts",
|
|
133
|
-
"import": "./dist/config/index.js"
|
|
134
|
+
"import": "./dist/config/index.js",
|
|
135
|
+
"default": "./dist/config/index.js"
|
|
134
136
|
},
|
|
135
137
|
"./compiler": {
|
|
136
138
|
"types": "./compiler/index.ts",
|
|
@@ -138,35 +140,43 @@
|
|
|
138
140
|
},
|
|
139
141
|
"./selector": {
|
|
140
142
|
"types": "./selector/index.ts",
|
|
141
|
-
"import": "./dist/selector/index.js"
|
|
143
|
+
"import": "./dist/selector/index.js",
|
|
144
|
+
"default": "./dist/selector/index.js"
|
|
142
145
|
},
|
|
143
146
|
"./dialect": {
|
|
144
147
|
"types": "./dialect/index.ts",
|
|
145
|
-
"import": "./dist/dialect/index.js"
|
|
148
|
+
"import": "./dist/dialect/index.js",
|
|
149
|
+
"default": "./dist/dialect/index.js"
|
|
146
150
|
},
|
|
147
151
|
"./dialect/extracted": {
|
|
148
152
|
"types": "./dialect/extracted/index.ts",
|
|
149
|
-
"import": "./dist/dialect/extracted/index.js"
|
|
153
|
+
"import": "./dist/dialect/extracted/index.js",
|
|
154
|
+
"default": "./dist/dialect/extracted/index.js"
|
|
150
155
|
},
|
|
151
156
|
"./presets/tailwind": {
|
|
152
157
|
"types": "./presets/tailwind/index.ts",
|
|
153
|
-
"import": "./dist/presets/tailwind/index.js"
|
|
158
|
+
"import": "./dist/presets/tailwind/index.js",
|
|
159
|
+
"default": "./dist/presets/tailwind/index.js"
|
|
154
160
|
},
|
|
155
161
|
"./dev": {
|
|
156
162
|
"types": "./dev/index.ts",
|
|
157
|
-
"import": "./dist/dev.js"
|
|
163
|
+
"import": "./dist/dev.js",
|
|
164
|
+
"default": "./dist/dev.js"
|
|
158
165
|
},
|
|
159
166
|
"./dev/rsc": {
|
|
160
167
|
"types": "./runtime/rsc/index.ts",
|
|
161
|
-
"import": "./dist/dev/rsc.js"
|
|
168
|
+
"import": "./dist/dev/rsc.js",
|
|
169
|
+
"default": "./dist/dev/rsc.js"
|
|
162
170
|
},
|
|
163
171
|
"./css": {
|
|
164
172
|
"types": "./css/index.ts",
|
|
165
|
-
"import": "./dist/css.js"
|
|
173
|
+
"import": "./dist/css.js",
|
|
174
|
+
"default": "./dist/css.js"
|
|
166
175
|
},
|
|
167
176
|
"./utils": {
|
|
168
177
|
"types": "./style/utils/index.ts",
|
|
169
|
-
"import": "./dist/utils.js"
|
|
178
|
+
"import": "./dist/utils.js",
|
|
179
|
+
"default": "./dist/utils.js"
|
|
170
180
|
},
|
|
171
181
|
"./builder/extract": {
|
|
172
182
|
"types": "./builder/extract/index.ts",
|
|
@@ -31,11 +31,13 @@ export type WebpackLoaderFilterArgs<State> = {
|
|
|
31
31
|
options: WebpackLoaderOptions;
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
+
export type MaybePromise<T> = Promise<T> | T;
|
|
35
|
+
|
|
34
36
|
export function createWebpackLoader<State>(args: {
|
|
35
37
|
getEntry: (compilerId: string, options: WebpackLoaderOptions) => State | null | undefined;
|
|
36
38
|
missingCompilerMessage: string;
|
|
37
39
|
shouldTransform?: (args: WebpackLoaderFilterArgs<State>) => boolean;
|
|
38
|
-
transform: (args: WebpackLoaderTransformArgs<State>) => WebpackLoaderResult | null
|
|
40
|
+
transform: (args: WebpackLoaderTransformArgs<State>) => MaybePromise<WebpackLoaderResult | null>;
|
|
39
41
|
}): LoaderDefinitionFunction<WebpackLoaderOptions> {
|
|
40
42
|
return function(source, inputMap) {
|
|
41
43
|
const callback = this.async();
|
|
@@ -58,16 +60,16 @@ export function createWebpackLoader<State>(args: {
|
|
|
58
60
|
return;
|
|
59
61
|
}
|
|
60
62
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
+
Promise.resolve().then(() =>
|
|
64
|
+
args.transform({
|
|
63
65
|
code: source.toString(),
|
|
64
66
|
entry,
|
|
65
67
|
filePath,
|
|
66
68
|
inputMap: inputMap as BabelTransformSourceMap,
|
|
67
69
|
loaderContext: this,
|
|
68
70
|
options,
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
+
})
|
|
72
|
+
).then((result) => {
|
|
71
73
|
if (!result) {
|
|
72
74
|
callback(null, source, inputMap);
|
|
73
75
|
return;
|
|
@@ -81,9 +83,9 @@ export function createWebpackLoader<State>(args: {
|
|
|
81
83
|
this.rootContext,
|
|
82
84
|
),
|
|
83
85
|
);
|
|
84
|
-
}
|
|
86
|
+
}).catch((err) => {
|
|
85
87
|
callback(err as Error);
|
|
86
|
-
}
|
|
88
|
+
});
|
|
87
89
|
};
|
|
88
90
|
}
|
|
89
91
|
|
package/plugin/nextjs/plugin.ts
CHANGED
|
@@ -2,13 +2,14 @@ import type { NextConfig } from 'next';
|
|
|
2
2
|
import { PHASE_DEVELOPMENT_SERVER } from 'next/constants';
|
|
3
3
|
import fs from 'node:fs';
|
|
4
4
|
import path from 'node:path';
|
|
5
|
-
import type { Compiler, RuleSetRule } from 'webpack';
|
|
5
|
+
import type { Compilation, Compiler, RuleSetRule } from 'webpack';
|
|
6
6
|
import type { BuildConfig, BuildDevConfig } from '../../config/build';
|
|
7
7
|
import { isPromiseLike } from '../../utils/object';
|
|
8
8
|
import {
|
|
9
9
|
BUNDLE_CSS_FILE,
|
|
10
10
|
createCompilerId,
|
|
11
11
|
createFileCssCache,
|
|
12
|
+
createFileCssContentHash,
|
|
12
13
|
createPluginCompiler,
|
|
13
14
|
DEFAULT_TRANSFORM_EXCLUDE,
|
|
14
15
|
DEFAULT_TRANSFORM_INCLUDE,
|
|
@@ -42,6 +43,7 @@ import {
|
|
|
42
43
|
createNextBuildConfig,
|
|
43
44
|
createNextBuildDevConfig,
|
|
44
45
|
createNextConfigHash,
|
|
46
|
+
createSerializableImportSources,
|
|
45
47
|
getNextCacheDir,
|
|
46
48
|
getNextPrecollectCacheSubdir,
|
|
47
49
|
getTransformLoaderPath,
|
|
@@ -49,8 +51,8 @@ import {
|
|
|
49
51
|
type NextLoaderState,
|
|
50
52
|
nextRegistry,
|
|
51
53
|
removeUndefinedValues,
|
|
52
|
-
replaceCssMarkerAsset,
|
|
53
54
|
resolveNextCompilerOptions,
|
|
55
|
+
replaceCssMarkerAsset,
|
|
54
56
|
} from './utils';
|
|
55
57
|
|
|
56
58
|
export { CssPropPresets } from '../utils';
|
|
@@ -59,8 +61,6 @@ export type { CompilerCssPropOptions } from '../utils';
|
|
|
59
61
|
export default plugin;
|
|
60
62
|
|
|
61
63
|
const TURBOPACK_TRANSFORM_EXTENSIONS: readonly string[] = ['*.ts', '*.tsx', '*.js', '*.jsx'];
|
|
62
|
-
const clearedPrecollectCacheRoots = new Set<string>();
|
|
63
|
-
|
|
64
64
|
type NextPhaseState = {
|
|
65
65
|
buildConfig: BuildConfig;
|
|
66
66
|
buildDevConfig: BuildDevConfig | null;
|
|
@@ -110,17 +110,20 @@ function createNextConfig(
|
|
|
110
110
|
phaseState.configHash = createNextConfigHash(
|
|
111
111
|
phaseState.buildConfig,
|
|
112
112
|
phaseState.dev,
|
|
113
|
+
options.importSources,
|
|
113
114
|
);
|
|
114
115
|
|
|
115
116
|
let sidecar: SourcemapSidecar | null = null;
|
|
116
117
|
|
|
117
118
|
if (dev) {
|
|
118
|
-
const
|
|
119
|
+
const getDevCss = () => cssCache.getCss({
|
|
120
|
+
...phaseState.buildConfig.css,
|
|
121
|
+
configHash: phaseState.configHash,
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const route: SidecarRouteHandler = async () => ({
|
|
119
125
|
contentType: 'text/css; charset=utf-8',
|
|
120
|
-
body:
|
|
121
|
-
...phaseState.buildConfig.css,
|
|
122
|
-
configHash: phaseState.configHash,
|
|
123
|
-
}),
|
|
126
|
+
body: await waitForDevCss(getDevCss),
|
|
124
127
|
});
|
|
125
128
|
|
|
126
129
|
sidecar = getSourcemapSidecar({
|
|
@@ -146,6 +149,22 @@ function createNextConfig(
|
|
|
146
149
|
: finish();
|
|
147
150
|
}
|
|
148
151
|
|
|
152
|
+
async function waitForDevCss(getCss: () => string) {
|
|
153
|
+
let css = getCss();
|
|
154
|
+
if (css) return css;
|
|
155
|
+
|
|
156
|
+
const deadline = Date.now() + 5000;
|
|
157
|
+
|
|
158
|
+
while (Date.now() < deadline) {
|
|
159
|
+
await new Promise((resolve) => setTimeout(resolve, 25));
|
|
160
|
+
|
|
161
|
+
css = getCss();
|
|
162
|
+
if (css) return css;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return css;
|
|
166
|
+
}
|
|
167
|
+
|
|
149
168
|
function createFluenticNextConfigResolved(
|
|
150
169
|
nextConfig: NextConfig,
|
|
151
170
|
options: PluginOptions,
|
|
@@ -162,7 +181,7 @@ function createFluenticNextConfigResolved(
|
|
|
162
181
|
const projectDir = process.cwd();
|
|
163
182
|
|
|
164
183
|
const devCssHref = dev && sidecar
|
|
165
|
-
?
|
|
184
|
+
? DEV_CSS_ROUTE
|
|
166
185
|
: null;
|
|
167
186
|
|
|
168
187
|
const turbopackCompilerId = createCompilerId(NEXT_COMPILER_IDS.turbopack);
|
|
@@ -204,6 +223,7 @@ function createFluenticNextConfigResolved(
|
|
|
204
223
|
return {
|
|
205
224
|
...nextConfig,
|
|
206
225
|
env: nextConfig.env,
|
|
226
|
+
rewrites: createNextRewrites(nextConfig.rewrites, dev && sidecar ? sidecar : null),
|
|
207
227
|
compiler: {
|
|
208
228
|
...originalCompiler,
|
|
209
229
|
define: {
|
|
@@ -246,6 +266,7 @@ function createFluenticNextConfigResolved(
|
|
|
246
266
|
cssAliases: turbopackCssAliases,
|
|
247
267
|
dev,
|
|
248
268
|
devCssHref,
|
|
269
|
+
options,
|
|
249
270
|
projectDir,
|
|
250
271
|
}),
|
|
251
272
|
webpack(config: WebpackConfiguration, context: WebpackConfigContext) {
|
|
@@ -302,6 +323,7 @@ function createFluenticNextConfigResolved(
|
|
|
302
323
|
cssOutput: options.cssOutput,
|
|
303
324
|
cssCache,
|
|
304
325
|
dev: context.dev,
|
|
326
|
+
filter: state.filter,
|
|
305
327
|
sidecar,
|
|
306
328
|
});
|
|
307
329
|
|
|
@@ -310,6 +332,45 @@ function createFluenticNextConfigResolved(
|
|
|
310
332
|
};
|
|
311
333
|
}
|
|
312
334
|
|
|
335
|
+
function createNextRewrites(
|
|
336
|
+
originalRewrites: NextConfig['rewrites'],
|
|
337
|
+
sidecar: SourcemapSidecar | null,
|
|
338
|
+
): NextConfig['rewrites'] {
|
|
339
|
+
if (!sidecar) return originalRewrites;
|
|
340
|
+
|
|
341
|
+
return async () => {
|
|
342
|
+
await sidecar.ensureStarted();
|
|
343
|
+
|
|
344
|
+
const devCssRewrite = {
|
|
345
|
+
source: DEV_CSS_ROUTE,
|
|
346
|
+
destination: sidecar.getRouteUrl(DEV_CSS_ROUTE),
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
const original = await originalRewrites?.();
|
|
350
|
+
|
|
351
|
+
if (!original) {
|
|
352
|
+
return {
|
|
353
|
+
beforeFiles: [devCssRewrite],
|
|
354
|
+
afterFiles: [],
|
|
355
|
+
fallback: [],
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
if (Array.isArray(original)) {
|
|
360
|
+
return {
|
|
361
|
+
beforeFiles: [devCssRewrite],
|
|
362
|
+
afterFiles: original,
|
|
363
|
+
fallback: [],
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
return {
|
|
368
|
+
...original,
|
|
369
|
+
beforeFiles: [devCssRewrite, ...(original.beforeFiles ?? [])],
|
|
370
|
+
};
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
|
|
313
374
|
function getImportableCssCacheDir(projectDir: string) {
|
|
314
375
|
return path.join(projectDir, PLUGIN_CACHE_DIR);
|
|
315
376
|
}
|
|
@@ -325,6 +386,7 @@ function createTurbopackConfig(
|
|
|
325
386
|
cssAliases: Record<string, string>;
|
|
326
387
|
dev: boolean;
|
|
327
388
|
devCssHref: string | null;
|
|
389
|
+
options: PluginOptions;
|
|
328
390
|
projectDir: string;
|
|
329
391
|
},
|
|
330
392
|
): TurbopackConfig {
|
|
@@ -354,12 +416,16 @@ function mergeTurbopackRules(
|
|
|
354
416
|
cssAliases: Record<string, string>;
|
|
355
417
|
dev: boolean;
|
|
356
418
|
devCssHref: string | null;
|
|
419
|
+
options: PluginOptions;
|
|
357
420
|
projectDir: string;
|
|
358
421
|
},
|
|
359
422
|
): TurbopackRules {
|
|
423
|
+
const compilerOptions = createSerializableTurbopackCompilerOptions(args.options);
|
|
424
|
+
|
|
360
425
|
const loaderItem: TurbopackLoaderItem = {
|
|
361
426
|
loader: LOADER_IMPORT_PATH,
|
|
362
427
|
options: removeUndefinedValues({
|
|
428
|
+
...compilerOptions,
|
|
363
429
|
buildConfig: args.buildConfig,
|
|
364
430
|
buildDevConfig: args.buildDevConfig,
|
|
365
431
|
cacheDir: args.cacheDir,
|
|
@@ -382,6 +448,55 @@ function mergeTurbopackRules(
|
|
|
382
448
|
return nextRules as TurbopackRules;
|
|
383
449
|
}
|
|
384
450
|
|
|
451
|
+
function createSerializableTurbopackCompilerOptions(
|
|
452
|
+
options: PluginOptions,
|
|
453
|
+
): Partial<PluginOptions> {
|
|
454
|
+
return removeUndefinedValues({
|
|
455
|
+
css: options.css,
|
|
456
|
+
cssProp: options.cssProp,
|
|
457
|
+
dev: options.dev,
|
|
458
|
+
hoist: options.hoist,
|
|
459
|
+
importSources: createSerializableTurbopackImportSources(options.importSources),
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
function createSerializableTurbopackImportSources(
|
|
464
|
+
importSources: PluginOptions['importSources'],
|
|
465
|
+
): PluginOptions['importSources'] | undefined {
|
|
466
|
+
const serialized = createSerializableImportSources(importSources);
|
|
467
|
+
if (!serialized) return undefined;
|
|
468
|
+
|
|
469
|
+
const result = serialized.filter((entry) => isSerializableLoaderValue(entry));
|
|
470
|
+
return result.length ? result : undefined;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
function isSerializableLoaderValue(value: unknown): boolean {
|
|
474
|
+
if (value === null) return true;
|
|
475
|
+
|
|
476
|
+
const valueType = typeof value;
|
|
477
|
+
|
|
478
|
+
if (
|
|
479
|
+
valueType === 'string' ||
|
|
480
|
+
valueType === 'number' ||
|
|
481
|
+
valueType === 'boolean'
|
|
482
|
+
) {
|
|
483
|
+
return true;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
if (valueType !== 'object') return false;
|
|
487
|
+
|
|
488
|
+
if (Array.isArray(value)) {
|
|
489
|
+
return value.every((item) => isSerializableLoaderValue(item));
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
const prototype = Object.getPrototypeOf(value);
|
|
493
|
+
if (prototype !== Object.prototype && prototype !== null) return false;
|
|
494
|
+
|
|
495
|
+
return Object.values(value as Record<string, unknown>).every((item) =>
|
|
496
|
+
isSerializableLoaderValue(item),
|
|
497
|
+
);
|
|
498
|
+
}
|
|
499
|
+
|
|
385
500
|
function prependTurbopackLoader(rule: unknown, loader: TurbopackLoaderItem) {
|
|
386
501
|
if (!rule || typeof rule !== 'object' || Array.isArray(rule)) {
|
|
387
502
|
return { loaders: [loader] };
|
|
@@ -478,6 +593,7 @@ function addLifecyclePlugin(
|
|
|
478
593
|
cssOutput: PluginCssOutputOptions | undefined;
|
|
479
594
|
cssCache: ReturnType<typeof createFileCssCache>;
|
|
480
595
|
dev: boolean;
|
|
596
|
+
filter: NextLoaderState['filter'];
|
|
481
597
|
sidecar: SourcemapSidecar | null;
|
|
482
598
|
},
|
|
483
599
|
) {
|
|
@@ -485,11 +601,6 @@ function addLifecyclePlugin(
|
|
|
485
601
|
apply(webpackCompiler: Compiler) {
|
|
486
602
|
webpackCompiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, async () => {
|
|
487
603
|
await args.sidecar?.ensureStarted();
|
|
488
|
-
|
|
489
|
-
if (!args.dev && !clearedPrecollectCacheRoots.has(args.cssCache.rootDir)) {
|
|
490
|
-
clearedPrecollectCacheRoots.add(args.cssCache.rootDir);
|
|
491
|
-
args.cssCache.clear();
|
|
492
|
-
}
|
|
493
604
|
});
|
|
494
605
|
|
|
495
606
|
webpackCompiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async (watchCompiler) => {
|
|
@@ -510,6 +621,8 @@ function addLifecyclePlugin(
|
|
|
510
621
|
stage: webpackCompiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
|
|
511
622
|
},
|
|
512
623
|
async () => {
|
|
624
|
+
precollectProductionCssFromCompilation(args, compilation, webpackCompiler);
|
|
625
|
+
|
|
513
626
|
const css = await transformCssOutput(
|
|
514
627
|
args.cssCache.getCss({
|
|
515
628
|
...args.buildConfig.css,
|
|
@@ -533,3 +646,80 @@ function addLifecyclePlugin(
|
|
|
533
646
|
},
|
|
534
647
|
});
|
|
535
648
|
}
|
|
649
|
+
|
|
650
|
+
function precollectProductionCssFromCompilation(
|
|
651
|
+
args: {
|
|
652
|
+
configHash: string;
|
|
653
|
+
compiler: NextLoaderState['compiler'];
|
|
654
|
+
cssCache: ReturnType<typeof createFileCssCache>;
|
|
655
|
+
dev: boolean;
|
|
656
|
+
filter: NextLoaderState['filter'];
|
|
657
|
+
},
|
|
658
|
+
compilation: Compilation,
|
|
659
|
+
webpackCompiler: Compiler,
|
|
660
|
+
) {
|
|
661
|
+
if (args.dev) return;
|
|
662
|
+
|
|
663
|
+
const existingCss = args.cssCache.getCss({
|
|
664
|
+
configHash: args.configHash,
|
|
665
|
+
});
|
|
666
|
+
|
|
667
|
+
if (existingCss) return;
|
|
668
|
+
|
|
669
|
+
const files = getCompilationSourceFiles(compilation, webpackCompiler.context, args.filter);
|
|
670
|
+
|
|
671
|
+
for (const filePath of files) {
|
|
672
|
+
let code: string;
|
|
673
|
+
|
|
674
|
+
try {
|
|
675
|
+
code = fs.readFileSync(filePath, 'utf8');
|
|
676
|
+
} catch {
|
|
677
|
+
continue;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
const result = args.compiler.compileExtract({
|
|
681
|
+
code,
|
|
682
|
+
filePath,
|
|
683
|
+
sourcemap: null,
|
|
684
|
+
});
|
|
685
|
+
|
|
686
|
+
if (!result) continue;
|
|
687
|
+
|
|
688
|
+
args.cssCache.setFileCss({
|
|
689
|
+
filePath,
|
|
690
|
+
contentHash: createFileCssContentHash(code),
|
|
691
|
+
configHash: args.configHash,
|
|
692
|
+
rules: result.rules,
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
function getCompilationSourceFiles(
|
|
698
|
+
compilation: Compilation,
|
|
699
|
+
projectDir: string,
|
|
700
|
+
filter: NextLoaderState['filter'],
|
|
701
|
+
) {
|
|
702
|
+
const files = new Set<string>();
|
|
703
|
+
const dependencies = compilation.fileDependencies ?? new Set<string>();
|
|
704
|
+
|
|
705
|
+
for (const filePath of dependencies) {
|
|
706
|
+
if (!isProjectSourceFile(filePath, projectDir, filter)) continue;
|
|
707
|
+
files.add(path.normalize(filePath));
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
return [...files].sort();
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
function isProjectSourceFile(
|
|
714
|
+
filePath: string,
|
|
715
|
+
projectDir: string,
|
|
716
|
+
filter: NextLoaderState['filter'],
|
|
717
|
+
) {
|
|
718
|
+
if (!path.isAbsolute(filePath)) return false;
|
|
719
|
+
if (!filePath.startsWith(projectDir + path.sep)) return false;
|
|
720
|
+
if (filePath.includes(`${path.sep}.next${path.sep}`)) return false;
|
|
721
|
+
if (filePath.includes(`${path.sep}.git${path.sep}`)) return false;
|
|
722
|
+
if (!filter(filePath)) return false;
|
|
723
|
+
|
|
724
|
+
return true;
|
|
725
|
+
}
|