@fluentic/style 0.1.0-beta.5 → 0.1.0-beta.7
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 +28 -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 -3
- package/dist/entry/prod.js.map +1 -1
- 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 -6
- package/dist/entry/rsc-dev.js.map +1 -1
- 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/{types-BEUgXuu2.js → style-DFsOmxLg.js} +7 -8
- package/dist/{types-BEUgXuu2.js.map → style-DFsOmxLg.js.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/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/jsx/types/index.ts +0 -2
- package/package.json +30 -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
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
|
+
}
|
package/plugin/nextjs/types.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { NextConfig } from 'next';
|
|
2
|
-
import type { PHASE_TYPE } from 'next/constants';
|
|
3
2
|
import type { OmitProps } from '../../utils/type';
|
|
4
3
|
import type { PluginOptions as BasePluginOptions } from '../utils';
|
|
5
4
|
|
|
@@ -12,7 +11,7 @@ export type NextConfigContext = {
|
|
|
12
11
|
};
|
|
13
12
|
|
|
14
13
|
export type NextConfigFunction = (
|
|
15
|
-
phase:
|
|
14
|
+
phase: string,
|
|
16
15
|
context: NextConfigContext,
|
|
17
16
|
) => MaybePromise<NextConfig>;
|
|
18
17
|
|
package/plugin/nextjs/utils.ts
CHANGED
|
@@ -3,8 +3,10 @@ import { createRequire } from 'node:module';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import type { Compilation, Compiler, WebpackPluginInstance } from 'webpack';
|
|
5
5
|
import type { Compiler as PluginCompiler } from '../../compiler';
|
|
6
|
+
import type { ImportSource } from '../../compiler/utils/import_source';
|
|
6
7
|
import { normalizePath } from '../../compiler/utils/path';
|
|
7
8
|
import type { BuildConfig, BuildDevConfig } from '../../config/build';
|
|
9
|
+
import { getStyleFnMeta } from '../../style/style';
|
|
8
10
|
import { createWebpackRegistry } from '../bundler/webpack/shared/registry';
|
|
9
11
|
import type { FileCssCache } from '../utils/cache';
|
|
10
12
|
import type { PluginOptions as BasePluginOptions } from '../utils/compiler';
|
|
@@ -69,15 +71,63 @@ export function createNextBuildDevConfig(options: PluginOptions): BuildDevConfig
|
|
|
69
71
|
export function createNextConfigHash(
|
|
70
72
|
buildConfig: BuildConfig,
|
|
71
73
|
dev: boolean,
|
|
74
|
+
importSources?: readonly ImportSource[] | null,
|
|
72
75
|
) {
|
|
73
76
|
const values = [
|
|
74
77
|
dev ? 'dev' : 'prod',
|
|
75
78
|
buildConfig.hoist ? 'hoist' : 'no-hoist',
|
|
79
|
+
JSON.stringify(createSerializableImportSources(importSources)),
|
|
76
80
|
];
|
|
77
81
|
|
|
78
82
|
return createHash('sha256').update(values.join('\0')).digest('hex');
|
|
79
83
|
}
|
|
80
84
|
|
|
85
|
+
export function createSerializableImportSources(
|
|
86
|
+
importSources: readonly ImportSource[] | null | undefined,
|
|
87
|
+
): ImportSource[] | undefined {
|
|
88
|
+
if (!importSources?.length) return undefined;
|
|
89
|
+
|
|
90
|
+
const result: ImportSource[] = [];
|
|
91
|
+
|
|
92
|
+
for (const entry of importSources) {
|
|
93
|
+
if (entry.check) continue;
|
|
94
|
+
|
|
95
|
+
const source = serializeImportSourcePattern(entry.source);
|
|
96
|
+
const name = entry.name;
|
|
97
|
+
const meta = entry.meta ?? (entry.styleFn ? getStyleFnMeta(entry.styleFn) : null);
|
|
98
|
+
|
|
99
|
+
if (!meta) continue;
|
|
100
|
+
if (entry.source !== undefined && source === undefined) continue;
|
|
101
|
+
|
|
102
|
+
result.push(removeUndefinedValues({
|
|
103
|
+
source,
|
|
104
|
+
name,
|
|
105
|
+
meta,
|
|
106
|
+
}));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return result.length ? result : undefined;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function serializeImportSourcePattern(
|
|
113
|
+
source: ImportSource['source'],
|
|
114
|
+
): string | string[] | undefined {
|
|
115
|
+
if (source === undefined) return undefined;
|
|
116
|
+
|
|
117
|
+
if (Array.isArray(source)) {
|
|
118
|
+
const result: string[] = [];
|
|
119
|
+
|
|
120
|
+
for (const item of source) {
|
|
121
|
+
if (typeof item !== 'string') return undefined;
|
|
122
|
+
result.push(item);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return result;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return typeof source === 'string' ? source : undefined;
|
|
129
|
+
}
|
|
130
|
+
|
|
81
131
|
export function resolveNextCompilerOptions(
|
|
82
132
|
options: PluginOptions,
|
|
83
133
|
sidecar: SourcemapSidecar | null,
|
|
@@ -127,7 +127,7 @@ function classNameToStyle(className: TailwindClassName, theme: TailwindTheme): R
|
|
|
127
127
|
if (className.startsWith('w-')) return { w: ref(className, 'w-', [theme.sizes, theme.spacing]) };
|
|
128
128
|
if (className.startsWith('h-')) return { h: ref(className, 'h-', [theme.sizes, theme.spacing]) };
|
|
129
129
|
if (className.startsWith('bg-')) return { bg: ref(className, 'bg-', theme.colors) };
|
|
130
|
-
if (className.startsWith('text-')) return
|
|
130
|
+
if (className.startsWith('text-')) return textStyle(className.slice('text-'.length), theme);
|
|
131
131
|
if (className.startsWith('font-')) return { font: ref(className, 'font-', theme.fontWeights) };
|
|
132
132
|
if (className.startsWith('leading-')) return { leading: ref(className, 'leading-', theme.lineHeights) };
|
|
133
133
|
if (className.startsWith('rounded-')) return { rounded: ref(className, 'rounded-', theme.radii) };
|
|
@@ -151,6 +151,37 @@ function borderStyle(value: string, theme: TailwindTheme): Record<string, unknow
|
|
|
151
151
|
return { borderColor: scaleRef(value, theme.colors) };
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
+
function textStyle(value: string, theme: TailwindTheme): Record<string, unknown> {
|
|
155
|
+
if (value.startsWith('[') && value.endsWith(']')) {
|
|
156
|
+
const arbitrary = value.slice(1, -1).replace(/_/g, ' ');
|
|
157
|
+
const hinted = parseArbitraryTextHint(arbitrary);
|
|
158
|
+
|
|
159
|
+
if (hinted) return hinted;
|
|
160
|
+
if (isLikelyFontSize(arbitrary)) return { textSize: arbitrary };
|
|
161
|
+
|
|
162
|
+
return { text: arbitrary };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return { text: scaleRef(value, [theme.fontSizes, theme.colors]) };
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function parseArbitraryTextHint(value: string): Record<string, unknown> | null {
|
|
169
|
+
const splitAt = value.indexOf(':');
|
|
170
|
+
if (splitAt < 1) return null;
|
|
171
|
+
|
|
172
|
+
const hint = value.slice(0, splitAt);
|
|
173
|
+
const textValue = value.slice(splitAt + 1);
|
|
174
|
+
|
|
175
|
+
if (hint === 'length' || hint === 'size') return { textSize: textValue };
|
|
176
|
+
if (hint === 'color') return { text: textValue };
|
|
177
|
+
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function isLikelyFontSize(value: string) {
|
|
182
|
+
return /^(?:-?\d*\.?\d+(?:px|r?em|lh|vh|vw|vmin|vmax|%|ch|ex|cap|ic)|(?:calc|clamp|min|max)\()/.test(value);
|
|
183
|
+
}
|
|
184
|
+
|
|
154
185
|
function scaleRef(value: string, scale?: TailwindScale | (TailwindScale | undefined)[]) {
|
|
155
186
|
const scales = Array.isArray(scale) ? scale : [scale];
|
|
156
187
|
const path = value.replace(/-/g, '.');
|
package/runtime/adapter/utils.ts
CHANGED
|
@@ -7,6 +7,7 @@ export type JsxCssPropMergeOptions = {
|
|
|
7
7
|
classProp: 'class' | 'className';
|
|
8
8
|
styleProp: 'style';
|
|
9
9
|
styleMode: JsxCssPropStyleMode;
|
|
10
|
+
preserveResultProps?: boolean;
|
|
10
11
|
};
|
|
11
12
|
|
|
12
13
|
export type JsxCssPropInput = Record<PropertyKey, unknown>;
|
|
@@ -22,22 +23,27 @@ export function createMergeJsxProps(
|
|
|
22
23
|
) {
|
|
23
24
|
return function mergeJsxProps(parts: readonly unknown[]) {
|
|
24
25
|
let props: JsxCssPropInput | null = null;
|
|
26
|
+
let cssProps: StyleProp[] | null = null;
|
|
25
27
|
|
|
26
28
|
for (let index = 0; index < parts.length; index++) {
|
|
27
|
-
|
|
29
|
+
const result = mergePart(props, parts[index]);
|
|
30
|
+
props = result.props;
|
|
31
|
+
|
|
32
|
+
if (result.css) {
|
|
33
|
+
if (!cssProps) cssProps = [];
|
|
34
|
+
cssProps.push(result.css);
|
|
35
|
+
}
|
|
28
36
|
}
|
|
29
37
|
|
|
30
|
-
return props ?? {};
|
|
38
|
+
return mergeCssProps(props ?? {}, cssProps, getClassName, options);
|
|
31
39
|
};
|
|
32
40
|
}
|
|
33
41
|
|
|
34
42
|
function mergePart(
|
|
35
43
|
props: JsxCssPropInput | null,
|
|
36
44
|
part: unknown,
|
|
37
|
-
getClassName: GetClassNameFn,
|
|
38
|
-
options: JsxCssPropMergeOptions,
|
|
39
45
|
) {
|
|
40
|
-
if (!part) return props;
|
|
46
|
+
if (!part) return { css: null, props };
|
|
41
47
|
|
|
42
48
|
const next = props ? { ...props } : {};
|
|
43
49
|
const attrs = part as JsxCssPropInput;
|
|
@@ -47,27 +53,47 @@ function mergePart(
|
|
|
47
53
|
if (key !== 'css') next[key] = attrs[key];
|
|
48
54
|
}
|
|
49
55
|
|
|
50
|
-
|
|
56
|
+
return {
|
|
57
|
+
css: css ? css as StyleProp : null,
|
|
58
|
+
props: next,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
51
61
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
62
|
+
function mergeCssProps(
|
|
63
|
+
props: JsxCssPropInput,
|
|
64
|
+
cssProps: StyleProp[] | null,
|
|
65
|
+
getClassName: GetClassNameFn,
|
|
66
|
+
options: JsxCssPropMergeOptions,
|
|
67
|
+
) {
|
|
68
|
+
if (!cssProps?.length) return props;
|
|
69
|
+
|
|
70
|
+
const className = getClassName(cssProps.length === 1 ? cssProps[0] : cssProps, {
|
|
71
|
+
className: getClassValue(props, options.classProp),
|
|
72
|
+
style: props[options.styleProp] as ClassNameProps['style'],
|
|
55
73
|
});
|
|
56
74
|
|
|
57
|
-
delete
|
|
58
|
-
delete
|
|
75
|
+
delete props.class;
|
|
76
|
+
delete props.className;
|
|
59
77
|
|
|
60
78
|
if (className.className !== undefined) {
|
|
61
|
-
|
|
79
|
+
props[options.classProp] = className.className;
|
|
62
80
|
}
|
|
63
81
|
|
|
64
82
|
if (className.style !== undefined) {
|
|
65
|
-
|
|
83
|
+
props[options.styleProp] = options.styleMode === 'solid'
|
|
66
84
|
? toSolidStyle(className.style as Record<string, unknown>)
|
|
67
85
|
: className.style;
|
|
68
86
|
}
|
|
69
87
|
|
|
70
|
-
|
|
88
|
+
if (options.preserveResultProps) {
|
|
89
|
+
for (const key in className) {
|
|
90
|
+
if (key === 'className' || key === 'style') continue;
|
|
91
|
+
|
|
92
|
+
props[key] = className[key as keyof ClassNameResult];
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return props;
|
|
71
97
|
}
|
|
72
98
|
|
|
73
99
|
function getClassValue(
|