@fluentic/style 0.1.0-beta.16 → 0.1.0-beta.18
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 +18 -0
- package/compiler/compiler/cache_identity.ts +115 -0
- package/compiler/compiler/compiler.ts +28 -1
- package/compiler/compiler/persistent_cache.ts +310 -0
- package/compiler/compiler/types.ts +12 -0
- package/compiler/extract/collector.ts +2 -2
- package/compiler/transform/evaluator/lazy_bindings.ts +63 -0
- package/compiler/transform/evaluator/metadata_cache.ts +124 -0
- package/compiler/transform/evaluator/tracer.ts +101 -86
- package/compiler/transform/extract/plugin.ts +21 -11
- package/compiler/transform/extract/utils/state.ts +3 -2
- package/compiler/utils/check_diagnostics.ts +18 -0
- package/compiler/utils/file_resolver.ts +24 -0
- package/dist/combine-BpOQWCtM.js.map +1 -1
- package/dist/compiler/index.mjs +1 -1
- package/dist/{compiler-AOb_VaKQ.mjs → compiler-Dpd41bCS.mjs} +646 -69
- package/dist/compiler-Dpd41bCS.mjs.map +1 -0
- package/dist/entry/rsc-dev.js.map +1 -1
- package/dist/{loader-fAuIjIik.mjs → loader-CR_NH6ub.mjs} +3 -3
- package/dist/{loader-fAuIjIik.mjs.map → loader-CR_NH6ub.mjs.map} +1 -1
- package/dist/{misc-CyZgGtc9.mjs → misc-D5AjOWP-.mjs} +31 -5
- package/dist/misc-D5AjOWP-.mjs.map +1 -0
- package/dist/plugin/farm/index.mjs +4 -4
- package/dist/plugin/farm/index.mjs.map +1 -1
- package/dist/plugin/nextjs/index.mjs +6 -6
- 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 +23 -20
- package/dist/plugin/vite/index.mjs.map +1 -1
- package/dist/plugin/webpack/index.mjs +2 -2
- package/dist/plugin/webpack/loader.mjs +2 -2
- package/dist/{registry-BMijh1CM.mjs → registry-CdSHrX-o.mjs} +2 -2
- package/dist/{registry-BMijh1CM.mjs.map → registry-CdSHrX-o.mjs.map} +1 -1
- package/dist/{shared-DY0kuBcN.cjs → shared-CcB1KDFI.cjs} +666 -76
- package/dist/shared-CcB1KDFI.cjs.map +1 -0
- package/dist/{shared-BfASWZo1.mjs → shared-CobOEWzt.mjs} +5 -5
- package/dist/shared-CobOEWzt.mjs.map +1 -0
- package/dist/{sidecar-cCzTDkzg.mjs → sidecar-CHDVQqN_.mjs} +3 -3
- package/dist/{sidecar-cCzTDkzg.mjs.map → sidecar-CHDVQqN_.mjs.map} +1 -1
- package/dist/style-CRs-vfY1.js.map +1 -1
- package/dist/types/compiler/compiler/cache_identity.d.ts +4 -0
- package/dist/types/compiler/compiler/compiler.d.ts +12 -0
- package/dist/types/compiler/compiler/persistent_cache.d.ts +14 -0
- package/dist/types/compiler/compiler/types.d.ts +11 -0
- package/dist/types/compiler/extract/collector.d.ts +1 -1
- package/dist/types/compiler/transform/evaluator/lazy_bindings.d.ts +22 -0
- package/dist/types/compiler/transform/evaluator/metadata_cache.d.ts +13 -0
- package/dist/types/compiler/transform/evaluator/tracer.d.ts +7 -0
- package/dist/types/compiler/transform/extract/utils/state.d.ts +3 -2
- package/dist/types/compiler/utils/check_diagnostics.d.ts +7 -0
- package/dist/types/compiler/utils/file_resolver.d.ts +4 -0
- package/dist/types/plugin/bundler/vite/state.d.ts +24 -0
- package/dist/types/plugin/utils/compiler.d.ts +12 -1
- package/dist/types/plugin/utils/filter.d.ts +11 -0
- package/dist/types/style/tokens.d.ts +1 -1
- package/dist/{utils-BO6Ix8t5.mjs → utils-CICsXGqS.mjs} +5 -5
- package/dist/utils-CICsXGqS.mjs.map +1 -0
- package/dist/{utils-EG9gh2g3.mjs → utils-XfsnoteV.mjs} +3 -3
- package/dist/{utils-EG9gh2g3.mjs.map → utils-XfsnoteV.mjs.map} +1 -1
- package/dist/{webpack-WXAJ3IYn.mjs → webpack-BAflvDbq.mjs} +7 -7
- package/dist/webpack-BAflvDbq.mjs.map +1 -0
- package/package.json +1 -1
- package/plugin/bundler/farm/plugin.ts +1 -1
- package/plugin/bundler/parcel/shared.ts +1 -1
- package/plugin/bundler/vite/plugin.ts +20 -17
- package/plugin/bundler/vite/state.ts +5 -6
- package/plugin/bundler/webpack/plugin.ts +2 -2
- package/plugin/nextjs/plugin.ts +2 -2
- package/plugin/nextjs/utils.ts +1 -1
- package/plugin/utils/compiler.ts +1 -2
- package/plugin/utils/filter.ts +65 -1
- package/style/tokens.ts +2 -1
- package/dist/compiler-AOb_VaKQ.mjs.map +0 -1
- package/dist/misc-CyZgGtc9.mjs.map +0 -1
- package/dist/shared-BfASWZo1.mjs.map +0 -1
- package/dist/shared-DY0kuBcN.cjs.map +0 -1
- package/dist/utils-BO6Ix8t5.mjs.map +0 -1
- package/dist/webpack-WXAJ3IYn.mjs.map +0 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CompilerInternal } from "../../compiler/index.js";
|
|
2
|
+
import { BabelCore } from "../utils/babel.js";
|
|
3
|
+
import type { BabelTypes } from "../utils/babel.js";
|
|
4
|
+
/** Immutable syntax only. Every consumer gets fresh nodes before annotations/evaluation. */
|
|
5
|
+
export declare function createTraceMetadataCache(internal: CompilerInternal): {
|
|
6
|
+
parse: (babel: typeof BabelCore, filePath: string, content: string) => BabelTypes.File | null;
|
|
7
|
+
getStats: () => {
|
|
8
|
+
parses: number;
|
|
9
|
+
memoryHits: number;
|
|
10
|
+
diskHits: number;
|
|
11
|
+
writes: number;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
@@ -5,4 +5,11 @@ export type Tracer = ReturnType<typeof createTracer>;
|
|
|
5
5
|
export declare function createTracer(internal: CompilerInternal): {
|
|
6
6
|
resolveImport: (babel: typeof BabelCore, source: string, fromFile: string) => EvalModuleBindings | null;
|
|
7
7
|
traceModule: (babel: typeof BabelCore, source: string, fromFile: string) => EvalModuleBindings | null;
|
|
8
|
+
getMetadataCacheStats: () => {
|
|
9
|
+
parses: number;
|
|
10
|
+
memoryHits: number;
|
|
11
|
+
diskHits: number;
|
|
12
|
+
writes: number;
|
|
13
|
+
};
|
|
14
|
+
beginCompilation(): void;
|
|
8
15
|
};
|
|
@@ -4,7 +4,8 @@ import type { CompilerOptions } from "../../../compiler/types.js";
|
|
|
4
4
|
import type { CompilerCssCollector } from "../../../extract/index.js";
|
|
5
5
|
import type { ImportSourceMatcher } from "../../../utils/import_source.js";
|
|
6
6
|
import type { EvalScope } from "../../evaluator/evaluator.js";
|
|
7
|
-
import type {
|
|
7
|
+
import type { LazyBindings } from "../../evaluator/lazy_bindings.js";
|
|
8
|
+
import type { ImportMap, ResolveImportFn } from "../../evaluator/types.js";
|
|
8
9
|
import type { BabelTypes } from "../../utils/babel.js";
|
|
9
10
|
export type HoistedDeclaration = {
|
|
10
11
|
declaration: BabelTypes.Statement;
|
|
@@ -19,7 +20,7 @@ export type ExtractPluginState = {
|
|
|
19
20
|
styleNames: Set<string>;
|
|
20
21
|
sheetNames: Set<string>;
|
|
21
22
|
styleMetas: Map<string, StyleFnMeta>;
|
|
22
|
-
bindings:
|
|
23
|
+
bindings: LazyBindings;
|
|
23
24
|
bindingNodes: Map<string, BabelTypes.Node>;
|
|
24
25
|
imports: ImportMap;
|
|
25
26
|
needsExtractImport: boolean;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type CheckDiagnostic = {
|
|
2
|
+
level: 'warn' | 'error';
|
|
3
|
+
message: string;
|
|
4
|
+
};
|
|
5
|
+
/** Extraction is synchronous; restore the previous observer for nested compilations. */
|
|
6
|
+
export declare function observeCheckDiagnostics<T>(onDiagnostic: (diagnostic: CheckDiagnostic) => void, run: () => T): T;
|
|
7
|
+
export declare function recordCheckDiagnostic(diagnostic: CheckDiagnostic): void;
|
|
@@ -8,5 +8,9 @@ export type ResolvedFile = {
|
|
|
8
8
|
mtimeMs: number;
|
|
9
9
|
};
|
|
10
10
|
export type ResolveFileFn = (info: ResolveFileInfo) => ResolvedFile | null;
|
|
11
|
+
declare let resolutionObserver: ((source: string, fromFile: string, result: ResolvedFile | null) => void) | null;
|
|
12
|
+
/** Synchronous extraction only; restore the previous observer even when extraction throws. */
|
|
13
|
+
export declare function observeFileResolutions<T>(observer: NonNullable<typeof resolutionObserver>, run: () => T): T;
|
|
11
14
|
export declare function clearResolverCache(): void;
|
|
12
15
|
export declare function resolveFile(source: string, fromFile: string): ResolvedFile | null;
|
|
16
|
+
export {};
|
|
@@ -12,6 +12,18 @@ export declare function createVitePluginState(options: PluginOptions): {
|
|
|
12
12
|
compileExtract: (args: import("../../../compiler/index.js").TransformExtractArgs) => import("../../../compiler/index.js").TransformExtractResult | null;
|
|
13
13
|
getExtractedCss: () => string;
|
|
14
14
|
invalidateFile: (_info: import("../../../compiler/index.js").CompilerInvalidateFileInfo) => void;
|
|
15
|
+
getPersistentCacheStats: () => {
|
|
16
|
+
hits: number;
|
|
17
|
+
misses: number;
|
|
18
|
+
bypasses: number;
|
|
19
|
+
writes: number;
|
|
20
|
+
};
|
|
21
|
+
getTraceMetadataCacheStats: () => {
|
|
22
|
+
parses: number;
|
|
23
|
+
memoryHits: number;
|
|
24
|
+
diskHits: number;
|
|
25
|
+
writes: number;
|
|
26
|
+
};
|
|
15
27
|
};
|
|
16
28
|
filter: import("../../utils/index.js").TransformFilter;
|
|
17
29
|
transform: (code: string, id: string, sourcemap?: import("../../utils/index.js").BundlerSourceMap | null) => {
|
|
@@ -44,6 +56,18 @@ export declare function createVitePluginState(options: PluginOptions): {
|
|
|
44
56
|
compileExtract: (args: import("../../../compiler/index.js").TransformExtractArgs) => import("../../../compiler/index.js").TransformExtractResult | null;
|
|
45
57
|
getExtractedCss: () => string;
|
|
46
58
|
invalidateFile: (_info: import("../../../compiler/index.js").CompilerInvalidateFileInfo) => void;
|
|
59
|
+
getPersistentCacheStats: () => {
|
|
60
|
+
hits: number;
|
|
61
|
+
misses: number;
|
|
62
|
+
bypasses: number;
|
|
63
|
+
writes: number;
|
|
64
|
+
};
|
|
65
|
+
getTraceMetadataCacheStats: () => {
|
|
66
|
+
parses: number;
|
|
67
|
+
memoryHits: number;
|
|
68
|
+
diskHits: number;
|
|
69
|
+
writes: number;
|
|
70
|
+
};
|
|
47
71
|
};
|
|
48
72
|
filter: import("../../utils/index.js").TransformFilter;
|
|
49
73
|
transform: (code: string, id: string, sourcemap?: import("../../utils/index.js").BundlerSourceMap | null) => {
|
|
@@ -6,7 +6,6 @@ export type PluginCssOptions = CompilerCssOptions;
|
|
|
6
6
|
export { CssPropPresets } from "../../compiler/index.js";
|
|
7
7
|
export type { CompilerCssPropOptions } from "../../compiler/index.js";
|
|
8
8
|
export type PluginOptions = CompilerOptions & TransformFilterOptions & {
|
|
9
|
-
cacheDir?: string;
|
|
10
9
|
cssOutput?: PluginCssOutputOptions;
|
|
11
10
|
};
|
|
12
11
|
export type PluginCompiler = ReturnType<typeof createPluginCompiler>;
|
|
@@ -29,6 +28,18 @@ export declare function createPluginCompiler(args: PluginCompilerArgs): {
|
|
|
29
28
|
compileExtract: (args: import("../../compiler/index.js").TransformExtractArgs) => import("../../compiler/index.js").TransformExtractResult | null;
|
|
30
29
|
getExtractedCss: () => string;
|
|
31
30
|
invalidateFile: (_info: import("../../compiler/index.js").CompilerInvalidateFileInfo) => void;
|
|
31
|
+
getPersistentCacheStats: () => {
|
|
32
|
+
hits: number;
|
|
33
|
+
misses: number;
|
|
34
|
+
bypasses: number;
|
|
35
|
+
writes: number;
|
|
36
|
+
};
|
|
37
|
+
getTraceMetadataCacheStats: () => {
|
|
38
|
+
parses: number;
|
|
39
|
+
memoryHits: number;
|
|
40
|
+
diskHits: number;
|
|
41
|
+
writes: number;
|
|
42
|
+
};
|
|
32
43
|
};
|
|
33
44
|
filter: import("./filter.js").TransformFilter;
|
|
34
45
|
transform: (code: string, id: string, sourcemap?: BundlerSourceMap | null) => {
|
|
@@ -5,6 +5,10 @@ export type FilterPattern = string | RegExp | Array<string | RegExp>;
|
|
|
5
5
|
export type TransformFilterOptions = {
|
|
6
6
|
include?: FilterPattern;
|
|
7
7
|
exclude?: FilterPattern;
|
|
8
|
+
/** Exact npm package names whose script files override file include/exclude rules. */
|
|
9
|
+
includePackages?: string | string[];
|
|
10
|
+
/** Exact npm package names excluded before all other filter rules. */
|
|
11
|
+
excludePackages?: string | string[];
|
|
8
12
|
};
|
|
9
13
|
export type TransformFilter = {
|
|
10
14
|
(id: string): boolean;
|
|
@@ -12,3 +16,10 @@ export type TransformFilter = {
|
|
|
12
16
|
};
|
|
13
17
|
export declare function normalizeModuleId(id: string): string;
|
|
14
18
|
export declare function createTransformFilter(options?: TransformFilterOptions): TransformFilter;
|
|
19
|
+
/** A conservative native prefilter; the shared JS filter remains authoritative. */
|
|
20
|
+
export declare function createTransformHookFilter(options?: TransformFilterOptions): {
|
|
21
|
+
id: {
|
|
22
|
+
include: RegExp | undefined;
|
|
23
|
+
exclude: RegExp[];
|
|
24
|
+
};
|
|
25
|
+
};
|
|
@@ -4,7 +4,7 @@ export type TokenTuple<T extends readonly ValueBase[]> = {
|
|
|
4
4
|
[P in T[number]]: StyleToken<InferValue<P>>;
|
|
5
5
|
};
|
|
6
6
|
export type TokenRecord<T extends object> = {
|
|
7
|
-
[P in keyof T]: T[P] extends readonly unknown[] ? StyleToken<T[P]> : T[P] extends object ? TokenRecord<T[P]> : T[P] extends ValueBase ? StyleToken<InferValue<T[P]>> : StyleToken<T[P]>;
|
|
7
|
+
[P in keyof T]: T[P] extends StyleToken<infer V> ? StyleToken<V> : T[P] extends readonly unknown[] ? StyleToken<T[P]> : T[P] extends object ? TokenRecord<T[P]> : T[P] extends ValueBase ? StyleToken<InferValue<T[P]>> : StyleToken<T[P]>;
|
|
8
8
|
};
|
|
9
9
|
export declare function createTokens<const T extends readonly ValueBase[]>(values: T): TokenTuple<T>;
|
|
10
10
|
export declare function createTokens<T extends object>(values: T): TokenRecord<T>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { c as getStyleFnMeta, s as normalizePath } from "./compiler-
|
|
2
|
-
import { f as resolvePluginSourcemapOptions, h as getPluginBuildDevConfig, m as getPluginBuildConfig } from "./misc-
|
|
3
|
-
import { n as STYLE_IMPORTS, t as createWebpackRegistry } from "./registry-
|
|
1
|
+
import { c as getStyleFnMeta, s as normalizePath } from "./compiler-Dpd41bCS.mjs";
|
|
2
|
+
import { f as resolvePluginSourcemapOptions, h as getPluginBuildDevConfig, m as getPluginBuildConfig } from "./misc-D5AjOWP-.mjs";
|
|
3
|
+
import { n as STYLE_IMPORTS, t as createWebpackRegistry } from "./registry-CdSHrX-o.mjs";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import { createHash } from "node:crypto";
|
|
6
6
|
import fs from "node:fs";
|
|
@@ -26,7 +26,7 @@ function getTransformLoaderPath() {
|
|
|
26
26
|
return createRequire(import.meta.url).resolve(LOADER_IMPORT_PATH);
|
|
27
27
|
}
|
|
28
28
|
function getNextCacheDir(rootDir, cacheDir) {
|
|
29
|
-
return cacheDir
|
|
29
|
+
return cacheDir === void 0 ? path.join(rootDir, ".next/cache/fluentic-style") : path.resolve(rootDir, cacheDir);
|
|
30
30
|
}
|
|
31
31
|
function getNextPrecollectCacheSubdir(dev) {
|
|
32
32
|
return dev ? PRECOLLECT_CACHE_DIRS.dev : PRECOLLECT_CACHE_DIRS.prod;
|
|
@@ -179,4 +179,4 @@ function replaceCssMarkerAsset(args) {
|
|
|
179
179
|
//#endregion
|
|
180
180
|
export { DEV_CSS_ROUTE as _, createNextBuildDevConfig as a, getNextCacheDir as c, isAppLayoutFile as d, nextRegistry as f, CSS_ENTRY_IMPORT_PATH as g, resolveNextCompilerOptions as h, createNextBuildConfig as i, getNextPrecollectCacheSubdir as l, replaceCssMarkerAsset as m, addAliases as n, createNextConfigHash as o, removeUndefinedValues as p, addWebpackPlugin as r, createSerializableImportSources as s, NEXT_COMPILER_IDS as t, getTransformLoaderPath as u, LOADER_IMPORT_PATH as v };
|
|
181
181
|
|
|
182
|
-
//# sourceMappingURL=utils-
|
|
182
|
+
//# sourceMappingURL=utils-CICsXGqS.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils-CICsXGqS.mjs","names":[],"sources":["../plugin/nextjs/constants.ts","../plugin/nextjs/utils.ts"],"sourcesContent":["import { STYLE_IMPORTS } from '../utils/imports';\n\nexport const DEV_CSS_ROUTE = '/__fluentic/dev.css';\n\nexport const LOADER_IMPORT_PATH = STYLE_IMPORTS.Plugin + '/nextjs/loader';\n\nexport const CSS_ENTRY_IMPORT_PATH = STYLE_IMPORTS.Plugin + '/nextjs/bundle.css';\n","import { createHash } from 'node:crypto';\nimport fs from 'node:fs';\nimport { createRequire } from 'node:module';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport type { Compilation, Compiler, WebpackPluginInstance } from 'webpack';\nimport type { Compiler as PluginCompiler } from '../../compiler';\nimport type { ImportSource } from '../../compiler/utils/import_source';\nimport { normalizePath } from '../../compiler/utils/path';\nimport type { BuildConfig, BuildDevConfig } from '../../config/build';\nimport { getStyleFnMeta } from '../../style/style';\nimport { createWebpackRegistry } from '../bundler/webpack/shared/registry';\nimport type { FileCssCache } from '../utils/cache';\nimport type { PluginOptions as BasePluginOptions } from '../utils/compiler';\nimport type { TransformFilter } from '../utils/filter';\nimport { getPluginBuildConfig, getPluginBuildDevConfig } from '../utils/runtimeEntry';\nimport type { SourcemapSidecar } from '../utils/sidecar';\nimport { resolvePluginSourcemapOptions } from '../utils/sourcemap';\nimport { LOADER_IMPORT_PATH } from './constants';\nimport type { PluginOptions, WebpackConfiguration } from './types';\n\nexport const nextRegistry = createWebpackRegistry('nextjs.registry');\n\nexport const PRECOLLECT_CACHE_DIRS = {\n dev: 'nextjs/precollect/dev',\n prod: 'nextjs/precollect/prod',\n};\n\nexport const NEXT_COMPILER_IDS = {\n turbopack: 'nextjs:turbopack',\n webpackServer: 'nextjs:webpack-server',\n webpackClient: 'nextjs:webpack-client',\n};\n\nexport type { PluginCompiler };\n\nexport type NextLoaderState = {\n compiler: PluginCompiler;\n filter: TransformFilter;\n dev: boolean;\n isServer: boolean;\n configHash: string;\n devCssHref: string | null;\n cssEntryImportPath: string;\n cssCache: Pick<FileCssCache, 'setFileCss'> | null;\n};\n\nexport type NextWebpackEntryValue = string | string[] | {\n import?: string | string[];\n [key: string]: unknown;\n};\n\nexport function getTransformLoaderPath() {\n return createRequire(import.meta.url).resolve(LOADER_IMPORT_PATH);\n}\n\nexport function getNextCacheDir(rootDir: string, cacheDir?: string) {\n return cacheDir === undefined ? path.join(rootDir, '.next/cache/fluentic-style') : path.resolve(rootDir, cacheDir);\n}\n\nexport function getNextPrecollectCacheSubdir(dev: boolean) {\n return dev ? PRECOLLECT_CACHE_DIRS.dev : PRECOLLECT_CACHE_DIRS.prod;\n}\n\nexport function createNextBuildConfig(options: PluginOptions): BuildConfig {\n return getPluginBuildConfig(options);\n}\n\nexport function createNextBuildDevConfig(options: PluginOptions): BuildDevConfig | null {\n return getPluginBuildDevConfig(options);\n}\n\nexport function createNextConfigHash(\n buildConfig: BuildConfig,\n dev: boolean,\n importSources?: readonly ImportSource[] | null,\n) {\n const values = [\n createPackageCacheIdentity(),\n dev ? 'dev' : 'prod',\n buildConfig.hoist ? 'hoist' : 'no-hoist',\n JSON.stringify(createSerializableImportSources(importSources)),\n ];\n\n return createHash('sha256').update(values.join('\\0')).digest('hex');\n}\n\nfunction createPackageCacheIdentity() {\n const require = createRequire(import.meta.url);\n let entryPath = '';\n\n try {\n entryPath = require.resolve('@fluentic/style/plugin/nextjs');\n } catch {\n entryPath = fileURLToPath(import.meta.url);\n }\n\n const packageInfo = findPackageInfo(entryPath);\n const parts = [\n packageInfo.version,\n normalizePath(packageInfo.packageRoot),\n normalizePath(entryPath),\n getStatIdentity(packageInfo.packageJsonPath),\n getStatIdentity(entryPath),\n ];\n\n return parts.join('\\0');\n}\n\nfunction findPackageInfo(entryPath: string) {\n let current = path.dirname(entryPath);\n\n while (true) {\n const packageJsonPath = path.join(current, 'package.json');\n\n try {\n const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')) as {\n name?: string;\n version?: string;\n };\n\n if (pkg.name === '@fluentic/style') {\n return {\n packageRoot: current,\n packageJsonPath,\n version: pkg.version ?? '',\n };\n }\n } catch {\n // Keep walking toward the filesystem root.\n }\n\n const parent = path.dirname(current);\n if (parent === current) break;\n current = parent;\n }\n\n return {\n packageRoot: path.dirname(entryPath),\n packageJsonPath: '',\n version: '',\n };\n}\n\nfunction getStatIdentity(filePath: string) {\n if (!filePath) return '';\n\n try {\n const stat = fs.statSync(filePath);\n return `${stat.size}:${stat.mtimeMs}`;\n } catch {\n return '';\n }\n}\n\nexport function createSerializableImportSources(\n importSources: readonly ImportSource[] | null | undefined,\n): ImportSource[] | undefined {\n if (!importSources?.length) return undefined;\n\n const result: ImportSource[] = [];\n\n for (const entry of importSources) {\n if (entry.check) continue;\n\n const source = serializeImportSourcePattern(entry.source);\n const name = entry.name;\n const meta = entry.meta ?? (entry.styleFn ? getStyleFnMeta(entry.styleFn) : null);\n\n if (!meta) continue;\n if (entry.source !== undefined && source === undefined) continue;\n\n result.push(removeUndefinedValues({\n source,\n name,\n meta,\n }));\n }\n\n return result.length ? result : undefined;\n}\n\nfunction serializeImportSourcePattern(\n source: ImportSource['source'],\n): string | string[] | undefined {\n if (source === undefined) return undefined;\n\n if (Array.isArray(source)) {\n const result: string[] = [];\n\n for (const item of source) {\n if (typeof item !== 'string') return undefined;\n result.push(item);\n }\n\n return result;\n }\n\n return typeof source === 'string' ? source : undefined;\n}\n\nexport function resolveNextCompilerOptions(\n options: PluginOptions,\n sidecar: SourcemapSidecar | null,\n buildConfig: BuildConfig,\n buildDevConfig: BuildDevConfig | null,\n dev: boolean,\n): BasePluginOptions {\n const resolved = resolvePluginSourcemapOptions({\n ...options,\n devSourcemap: dev ? 'sidecarServer' : 'sourceUrl',\n }, sidecar);\n\n return {\n ...resolved,\n css: {\n ...resolved.css,\n ...buildConfig.css,\n },\n dev: {\n ...resolved.dev,\n ...buildDevConfig,\n },\n };\n}\n\nexport function removeUndefinedValues<T>(value: T): T {\n if (Array.isArray(value)) {\n return value.map((item) => removeUndefinedValues(item)) as T;\n }\n\n if (!value || typeof value !== 'object') {\n return value;\n }\n\n const result: Record<string, unknown> = {};\n\n for (const [key, item] of Object.entries(value)) {\n if (item !== undefined) {\n result[key] = removeUndefinedValues(item);\n }\n }\n\n return result as T;\n}\n\nexport function prependClientEntry(entry: unknown, moduleId: string) {\n if (typeof entry === 'function') {\n return async () => prependClientEntry(await entry(), moduleId);\n }\n\n if (!entry || typeof entry !== 'object') return entry;\n\n const result: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(entry)) {\n result[key] = prependEntryValue(value as NextWebpackEntryValue, moduleId);\n }\n\n return result;\n}\n\nexport function prependEntryValue(entry: NextWebpackEntryValue, moduleId: string): NextWebpackEntryValue {\n if (typeof entry === 'string') {\n return entry === moduleId ? entry : [moduleId, entry];\n }\n\n if (Array.isArray(entry)) {\n return entry.includes(moduleId) ? entry : [moduleId, ...entry];\n }\n\n const imports = entry.import;\n if (!imports) return { ...entry, import: moduleId };\n\n return {\n ...entry,\n import: Array.isArray(imports)\n ? imports.includes(moduleId) ? imports : [moduleId, ...imports]\n : imports === moduleId\n ? imports\n : [moduleId, imports],\n };\n}\n\nexport function isAppLayoutFile(filePath: string) {\n return /\\/app\\/(?:[^/]+\\/)*layout\\.[cm]?[jt]sx?$/.test(normalizePath(filePath));\n}\n\nexport function hasCssMarker(source: string, marker: string) {\n return source.includes(marker);\n}\n\nexport function replaceCssMarker(source: string, marker: string, css: string) {\n return source.split(marker).join(css);\n}\n\nexport function addAliases(config: WebpackConfiguration, aliases: Record<string, string>) {\n if (!config.resolve) config.resolve = {};\n if (!config.resolve.alias) config.resolve.alias = {};\n Object.assign(config.resolve.alias, aliases);\n}\n\nexport function addWebpackPlugin(config: WebpackConfiguration, plugin: WebpackPluginInstance) {\n if (!config.plugins) config.plugins = [];\n config.plugins.push(plugin);\n}\n\nexport function replaceCssMarkerAsset(args: {\n compiler: Compiler;\n compilation: Compilation;\n css: string;\n marker: string;\n}) {\n for (const asset of args.compilation.getAssets()) {\n if (!asset.name.endsWith('.css')) continue;\n\n const source = asset.source.source().toString();\n if (!hasCssMarker(source, args.marker)) continue;\n\n args.compilation.updateAsset(\n asset.name,\n new args.compiler.webpack.sources.RawSource(\n replaceCssMarker(source, args.marker, args.css),\n ),\n );\n\n return true;\n }\n\n return false;\n}\n"],"mappings":";;;;;;;;;AAEA,MAAa,gBAAgB;AAE7B,MAAa,qBAAqB,cAAc,SAAS;AAEzD,MAAa,wBAAwB,cAAc,SAAS;;;ACe5D,MAAa,eAAe,sBAAsB,iBAAiB;AAEnE,MAAa,wBAAwB;CACnC,KAAK;CACL,MAAM;AACR;AAEA,MAAa,oBAAoB;CAC/B,WAAW;CACX,eAAe;CACf,eAAe;AACjB;AAoBA,SAAgB,yBAAyB;CACvC,OAAO,cAAc,OAAO,KAAK,GAAG,EAAE,QAAQ,kBAAkB;AAClE;AAEA,SAAgB,gBAAgB,SAAiB,UAAmB;CAClE,OAAO,aAAa,KAAA,IAAY,KAAK,KAAK,SAAS,4BAA4B,IAAI,KAAK,QAAQ,SAAS,QAAQ;AACnH;AAEA,SAAgB,6BAA6B,KAAc;CACzD,OAAO,MAAM,sBAAsB,MAAM,sBAAsB;AACjE;AAEA,SAAgB,sBAAsB,SAAqC;CACzE,OAAO,qBAAqB,OAA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{ n as STYLE_IMPORTS, t as createWebpackRegistry } from "./registry-
|
|
1
|
+
import { s as normalizePath } from "./compiler-Dpd41bCS.mjs";
|
|
2
|
+
import { n as STYLE_IMPORTS, t as createWebpackRegistry } from "./registry-CdSHrX-o.mjs";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
//#region plugin/bundler/webpack/utils.ts
|
|
@@ -46,4 +46,4 @@ function prependEntryImport(entryImport, runtimeFilePath) {
|
|
|
46
46
|
//#endregion
|
|
47
47
|
export { prependWebpackRuntimeEntry as a, hasWebpackCssMarker as i, getStylePackageDistPath as n, replaceWebpackCssMarker as o, getTransformLoaderPath as r, webpackRegistry as s, createWebpackRuntimeModuleSource as t };
|
|
48
48
|
|
|
49
|
-
//# sourceMappingURL=utils-
|
|
49
|
+
//# sourceMappingURL=utils-XfsnoteV.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils-
|
|
1
|
+
{"version":3,"file":"utils-XfsnoteV.mjs","names":[],"sources":["../plugin/bundler/webpack/utils.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport path from 'node:path';\nimport type { EntryNormalized } from 'webpack';\nimport { normalizePath } from '../../../compiler/utils/path';\nimport { SIDECAR_URL_GLOBAL_SYMBOL } from '../../../config/utils';\nimport type { PluginCompiler } from '../../utils';\nimport { STYLE_IMPORTS } from '../../utils/imports';\nimport { createWebpackRegistry } from './shared/registry';\n\ntype WebpackStaticEntry = Exclude<EntryNormalized, () => Promise<unknown>>;\ntype WebpackEntryDescription = WebpackStaticEntry[string];\n\nexport type WebpackLoaderState = {\n transform: PluginCompiler['transform'];\n};\n\nexport const webpackRegistry = createWebpackRegistry('webpack.registry');\n\nexport function getTransformLoaderPath() {\n return createRequire(import.meta.url).resolve(STYLE_IMPORTS.Plugin + '/webpack/loader');\n}\n\nexport function getStylePackageDistPath() {\n return path.resolve(path.dirname(getTransformLoaderPath()), '../..');\n}\n\nexport function createWebpackRuntimeModuleSource(\n extract: boolean,\n cssFilePath: string | null,\n options: {\n runtimeImportPath?: string | null;\n sidecarUrl?: string | null;\n } = {},\n) {\n return [\n extract && cssFilePath && `import ${JSON.stringify(normalizePath(cssFilePath))};`,\n options.sidecarUrl && options.runtimeImportPath && `import ${JSON.stringify(options.runtimeImportPath)};`,\n options.sidecarUrl &&\n `globalThis[Symbol.for(${JSON.stringify(SIDECAR_URL_GLOBAL_SYMBOL)})] = ${JSON.stringify(options.sidecarUrl)};`,\n '',\n ].filter(Boolean).join('\\n');\n}\n\nexport function replaceWebpackCssMarker(\n source: string,\n marker: string,\n css: string,\n) {\n return source.replace(marker, css);\n}\n\nexport function hasWebpackCssMarker(source: string, marker: string) {\n return source.includes(marker);\n}\n\nexport function prependWebpackRuntimeEntry(\n entry: EntryNormalized,\n runtimeFilePath: string,\n): EntryNormalized {\n if (typeof entry === 'function') {\n return async () => prependWebpackRuntimeStaticEntry(await entry(), runtimeFilePath);\n }\n\n return prependWebpackRuntimeStaticEntry(entry, runtimeFilePath);\n}\n\nfunction prependWebpackRuntimeStaticEntry(\n entry: WebpackStaticEntry,\n runtimeFilePath: string,\n): WebpackStaticEntry {\n const result: WebpackStaticEntry = {};\n\n for (const [key, value] of Object.entries(entry)) {\n result[key] = prependWebpackRuntimeEntryDescription(value, runtimeFilePath);\n }\n\n return result;\n}\n\nfunction prependWebpackRuntimeEntryDescription(\n entry: WebpackEntryDescription,\n runtimeFilePath: string,\n): WebpackEntryDescription {\n if (!entry.import) return entry;\n\n return {\n ...entry,\n import: prependEntryImport(entry.import, runtimeFilePath),\n };\n}\n\nfunction prependEntryImport(entryImport: string[], runtimeFilePath: string) {\n return entryImport.includes(runtimeFilePath)\n ? entryImport\n : [runtimeFilePath, ...entryImport];\n}\n"],"mappings":";;;;;AAgBA,MAAa,kBAAkB,sBAAsB,kBAAkB;AAEvE,SAAgB,yBAAyB;CACvC,OAAO,cAAc,OAAO,KAAK,GAAG,EAAE,QAAQ,cAAc,S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"./compiler-
|
|
2
|
-
import { C as createCompilerId, D as DEFAULT_TRANSFORM_EXCLUDE, E as invalidateFiles,
|
|
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-Dpd41bCS.mjs";
|
|
2
|
+
import { C as createCompilerId, D as DEFAULT_TRANSFORM_EXCLUDE, E as invalidateFiles, I as PLUGIN_NAME, N as BUNDLE_CSS_FILE, O as DEFAULT_TRANSFORM_INCLUDE, P as EXTRACTED_CSS_MARKER, R as writePluginCacheFile, T as getPluginCacheDir, _ as getStyleRuntimeMode, b as transformCssOutput, d as resolvePluginSourcemapFilePath, g as getStyleEntryDefines, h as getPluginBuildDevConfig, m as getPluginBuildConfig, t as formatError, u as resolveDevSourcemapMode, w as createPluginCompiler } from "./misc-D5AjOWP-.mjs";
|
|
3
|
+
import { t as getSourcemapSidecar } from "./sidecar-CHDVQqN_.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-XfsnoteV.mjs";
|
|
5
5
|
//#region plugin/bundler/webpack/plugin.ts
|
|
6
6
|
const WEBPACK_RUNTIME_FILE = "webpack-runtime.js";
|
|
7
7
|
function plugin(options = {}) {
|
|
@@ -16,7 +16,7 @@ var WebpackPlugin = class {
|
|
|
16
16
|
const extract = !dev;
|
|
17
17
|
const buildConfig = getPluginBuildConfig(this.options);
|
|
18
18
|
const buildDevConfig = getPluginBuildDevConfig(this.options);
|
|
19
|
-
const cacheDir = getPluginCacheDir(compiler.context, this.options.
|
|
19
|
+
const cacheDir = getPluginCacheDir(compiler.context, this.options.cache?.location);
|
|
20
20
|
const devSourcemap = resolveDevSourcemapMode(this.options.devSourcemap, dev);
|
|
21
21
|
const sourcemapSidecar = devSourcemap === "sidecarServer" ? getSourcemapSidecar({
|
|
22
22
|
projectDir: compiler.context,
|
|
@@ -94,7 +94,7 @@ function addTransformLoader(compiler, options, compilerId) {
|
|
|
94
94
|
}],
|
|
95
95
|
enforce: "pre",
|
|
96
96
|
test: DEFAULT_TRANSFORM_INCLUDE,
|
|
97
|
-
exclude: options.include ? void 0 : [DEFAULT_TRANSFORM_EXCLUDE, getStylePackageDistPath()]
|
|
97
|
+
exclude: options.include || options.includePackages?.length ? void 0 : [DEFAULT_TRANSFORM_EXCLUDE, getStylePackageDistPath()]
|
|
98
98
|
};
|
|
99
99
|
compiler.options.module.rules.unshift(rule);
|
|
100
100
|
}
|
|
@@ -104,4 +104,4 @@ function isRspackCompiler(compiler) {
|
|
|
104
104
|
//#endregion
|
|
105
105
|
export { plugin as t };
|
|
106
106
|
|
|
107
|
-
//# sourceMappingURL=webpack-
|
|
107
|
+
//# sourceMappingURL=webpack-BAflvDbq.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webpack-BAflvDbq.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.cache?.location);\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 || options.includePackages?.length ? 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,O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AY,CACxE,2BACA,wBAAwB,CAC1B;CACF;CAEA,SAAS,QAAQ,OAAO,MAAM,QAAQ,IAAI;AAC5C;AAEA,SAAS,iBAAiB,UAAoB;CAK5C,OAAO,OAJS,SAAS,QAIH,kBAAkB;AAC1C"}
|
package/package.json
CHANGED
|
@@ -66,7 +66,7 @@ export function plugin(options: FarmPluginOptions = {}) {
|
|
|
66
66
|
const buildDevConfig = getPluginBuildDevConfig(options);
|
|
67
67
|
const runtimeMode = getStyleRuntimeMode(dev);
|
|
68
68
|
const projectDir = process.cwd();
|
|
69
|
-
const cacheDir = getPluginCacheDir(projectDir, options.
|
|
69
|
+
const cacheDir = getPluginCacheDir(projectDir, options.cache?.location);
|
|
70
70
|
|
|
71
71
|
let state: PluginCompiler | null = null;
|
|
72
72
|
let sourcemapSidecar: SourcemapSidecar | null = null;
|
|
@@ -54,7 +54,7 @@ export { Optimizer, Resolver, Runtime, Transformer };
|
|
|
54
54
|
export function getParcelState(options: ParcelPluginOptions, pluginOptions: PluginOptions = {}) {
|
|
55
55
|
const projectDir = options.projectRoot ?? process.cwd();
|
|
56
56
|
const dev = options.mode !== 'production';
|
|
57
|
-
const cacheDir = getPluginCacheDir(projectDir, pluginOptions.
|
|
57
|
+
const cacheDir = getPluginCacheDir(projectDir, pluginOptions.cache?.location);
|
|
58
58
|
const key = JSON.stringify({ projectDir, dev, cacheDir });
|
|
59
59
|
|
|
60
60
|
if (state && stateKey === key) return state;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Plugin } from 'vite';
|
|
2
2
|
import { invalidateFiles, PLUGIN_NAME, type PluginOptions, transformCssOutput } from '../../utils';
|
|
3
3
|
import { hasCssMarker, replaceCssMarker } from '../../utils/cssMarker';
|
|
4
|
+
import { createTransformHookFilter } from '../../utils/filter';
|
|
4
5
|
import { formatError } from '../../utils/misc';
|
|
5
6
|
import { getVirtualModuleId, RESOLVED_RUNTIME_MODULE_ID } from '../../utils/virtual';
|
|
6
7
|
import { createVitePluginState } from './state';
|
|
@@ -60,24 +61,26 @@ export function plugin(options: PluginOptions = {}): Plugin {
|
|
|
60
61
|
},
|
|
61
62
|
},
|
|
62
63
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
64
|
+
transform: {
|
|
65
|
+
filter: createTransformHookFilter(options),
|
|
66
|
+
async handler(code, id) {
|
|
67
|
+
const current = state.getState();
|
|
68
|
+
if (!current.filter(id)) return null;
|
|
69
|
+
if (current.dev) await state.ensureSidecarStarted();
|
|
70
|
+
|
|
71
|
+
let result: ReturnType<typeof current.transform>;
|
|
72
|
+
try {
|
|
73
|
+
result = current.transform(code, id);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
this.error(toCleanViteError(error, id));
|
|
76
|
+
}
|
|
77
|
+
if (!result) return null;
|
|
76
78
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
return {
|
|
80
|
+
code: result.code,
|
|
81
|
+
map: result.map ? JSON.parse(result.map) : null,
|
|
82
|
+
};
|
|
83
|
+
},
|
|
81
84
|
},
|
|
82
85
|
|
|
83
86
|
async generateBundle(_, bundle) {
|
|
@@ -89,7 +89,7 @@ export function createVitePluginState(options: PluginOptions) {
|
|
|
89
89
|
if (state) return state;
|
|
90
90
|
|
|
91
91
|
const dev = config.command === 'serve';
|
|
92
|
-
const cacheDir = getPluginCacheDir(config.root, options.
|
|
92
|
+
const cacheDir = getPluginCacheDir(config.root, options.cache?.location);
|
|
93
93
|
const devSourcemap = resolveDevSourcemapMode(options.devSourcemap, dev);
|
|
94
94
|
|
|
95
95
|
ensureSidecar(dev, config.root);
|
|
@@ -101,10 +101,9 @@ export function createVitePluginState(options: PluginOptions) {
|
|
|
101
101
|
options: {
|
|
102
102
|
...options,
|
|
103
103
|
devSourcemap,
|
|
104
|
-
getSourcemapFilePath:
|
|
105
|
-
options.getSourcemapFilePath,
|
|
106
|
-
|
|
107
|
-
),
|
|
104
|
+
getSourcemapFilePath: dev
|
|
105
|
+
? resolvePluginSourcemapFilePath(options.getSourcemapFilePath, sidecar)
|
|
106
|
+
: options.getSourcemapFilePath,
|
|
108
107
|
},
|
|
109
108
|
runtimeMode: getStyleRuntimeMode(dev),
|
|
110
109
|
});
|
|
@@ -141,7 +140,7 @@ function createViteSidecar(args: {
|
|
|
141
140
|
}) {
|
|
142
141
|
return getSourcemapSidecar({
|
|
143
142
|
projectDir: args.root,
|
|
144
|
-
cacheDir: getPluginCacheDir(args.root, args.options.
|
|
143
|
+
cacheDir: getPluginCacheDir(args.root, args.options.cache?.location),
|
|
145
144
|
});
|
|
146
145
|
}
|
|
147
146
|
|
|
@@ -59,7 +59,7 @@ class WebpackPlugin implements WebpackPluginInstance {
|
|
|
59
59
|
|
|
60
60
|
const buildConfig = getPluginBuildConfig(this.options);
|
|
61
61
|
const buildDevConfig = getPluginBuildDevConfig(this.options);
|
|
62
|
-
const cacheDir = getPluginCacheDir(compiler.context, this.options.
|
|
62
|
+
const cacheDir = getPluginCacheDir(compiler.context, this.options.cache?.location);
|
|
63
63
|
const devSourcemap = resolveDevSourcemapMode(this.options.devSourcemap, dev);
|
|
64
64
|
|
|
65
65
|
const sourcemapSidecar = devSourcemap === 'sidecarServer'
|
|
@@ -223,7 +223,7 @@ function addTransformLoader(
|
|
|
223
223
|
use: [loader],
|
|
224
224
|
enforce: 'pre',
|
|
225
225
|
test: DEFAULT_TRANSFORM_INCLUDE,
|
|
226
|
-
exclude: options.include ? undefined : [
|
|
226
|
+
exclude: options.include || options.includePackages?.length ? undefined : [
|
|
227
227
|
DEFAULT_TRANSFORM_EXCLUDE,
|
|
228
228
|
getStylePackageDistPath(),
|
|
229
229
|
],
|
package/plugin/nextjs/plugin.ts
CHANGED
|
@@ -94,7 +94,7 @@ function createNextConfig(
|
|
|
94
94
|
dev: boolean,
|
|
95
95
|
): MaybePromise<NextConfig> {
|
|
96
96
|
const rootDir = process.cwd();
|
|
97
|
-
const cacheDir = getNextCacheDir(rootDir, options.
|
|
97
|
+
const cacheDir = getNextCacheDir(rootDir, options.cache?.location);
|
|
98
98
|
|
|
99
99
|
const cssCache = createFileCssCache({
|
|
100
100
|
cacheDir,
|
|
@@ -531,7 +531,7 @@ function addTransformLoader(
|
|
|
531
531
|
}],
|
|
532
532
|
enforce: 'pre',
|
|
533
533
|
test: DEFAULT_TRANSFORM_INCLUDE,
|
|
534
|
-
exclude: options.include ? undefined : [
|
|
534
|
+
exclude: options.include || options.includePackages?.length ? undefined : [
|
|
535
535
|
DEFAULT_TRANSFORM_EXCLUDE,
|
|
536
536
|
/\.next/,
|
|
537
537
|
/\.git/,
|
package/plugin/nextjs/utils.ts
CHANGED
|
@@ -55,7 +55,7 @@ export function getTransformLoaderPath() {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
export function getNextCacheDir(rootDir: string, cacheDir?: string) {
|
|
58
|
-
return cacheDir
|
|
58
|
+
return cacheDir === undefined ? path.join(rootDir, '.next/cache/fluentic-style') : path.resolve(rootDir, cacheDir);
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
export function getNextPrecollectCacheSubdir(dev: boolean) {
|
package/plugin/utils/compiler.ts
CHANGED
|
@@ -11,7 +11,6 @@ export { CssPropPresets } from '../../compiler';
|
|
|
11
11
|
export type { CompilerCssPropOptions } from '../../compiler';
|
|
12
12
|
|
|
13
13
|
export type PluginOptions = CompilerOptions & TransformFilterOptions & {
|
|
14
|
-
cacheDir?: string;
|
|
15
14
|
cssOutput?: PluginCssOutputOptions;
|
|
16
15
|
};
|
|
17
16
|
|
|
@@ -32,7 +31,7 @@ export function createCompilerId(name?: string) {
|
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
export function getPluginCacheDir(projectDir: string, cacheDir?: string) {
|
|
35
|
-
return cacheDir
|
|
34
|
+
return cacheDir === undefined ? path.join(projectDir, PLUGIN_CACHE_DIR) : path.resolve(projectDir, cacheDir);
|
|
36
35
|
}
|
|
37
36
|
|
|
38
37
|
export function createPluginCompiler(args: PluginCompilerArgs) {
|
package/plugin/utils/filter.ts
CHANGED
|
@@ -12,6 +12,10 @@ export type FilterPattern = string | RegExp | Array<string | RegExp>;
|
|
|
12
12
|
export type TransformFilterOptions = {
|
|
13
13
|
include?: FilterPattern;
|
|
14
14
|
exclude?: FilterPattern;
|
|
15
|
+
/** Exact npm package names whose script files override file include/exclude rules. */
|
|
16
|
+
includePackages?: string | string[];
|
|
17
|
+
/** Exact npm package names excluded before all other filter rules. */
|
|
18
|
+
excludePackages?: string | string[];
|
|
15
19
|
};
|
|
16
20
|
|
|
17
21
|
export type TransformFilter = {
|
|
@@ -25,6 +29,8 @@ export function normalizeModuleId(id: string) {
|
|
|
25
29
|
|
|
26
30
|
export function createTransformFilter(options: TransformFilterOptions = {}): TransformFilter {
|
|
27
31
|
const includes = normalizeMatchers(options.include);
|
|
32
|
+
const includePackages = createPackagePattern(options.includePackages);
|
|
33
|
+
const excludePackages = createPackagePattern(options.excludePackages);
|
|
28
34
|
|
|
29
35
|
const excludes = normalizeMatchers(
|
|
30
36
|
options.exclude ?? (options.include ? undefined : DEFAULT_TRANSFORM_EXCLUDE),
|
|
@@ -38,7 +44,12 @@ export function createTransformFilter(options: TransformFilterOptions = {}): Tra
|
|
|
38
44
|
|
|
39
45
|
if (cached !== undefined) return cached;
|
|
40
46
|
|
|
41
|
-
const
|
|
47
|
+
const packagePath = normalizePath(filePath);
|
|
48
|
+
const result = excludePackages?.test(packagePath)
|
|
49
|
+
? false
|
|
50
|
+
: includePackages?.test(packagePath)
|
|
51
|
+
? DEFAULT_TRANSFORM_INCLUDE.test(filePath)
|
|
52
|
+
: shouldTransform(filePath, includes, excludes);
|
|
42
53
|
|
|
43
54
|
cache.set(filePath, result);
|
|
44
55
|
|
|
@@ -96,3 +107,56 @@ function shouldTransform(
|
|
|
96
107
|
|
|
97
108
|
return false;
|
|
98
109
|
}
|
|
110
|
+
|
|
111
|
+
/** A conservative native prefilter; the shared JS filter remains authoritative. */
|
|
112
|
+
export function createTransformHookFilter(options: TransformFilterOptions = {}) {
|
|
113
|
+
const includePackages = createPackagePattern(options.includePackages);
|
|
114
|
+
const excludePackages = createPackagePattern(options.excludePackages);
|
|
115
|
+
const exclude: RegExp[] = [];
|
|
116
|
+
if (excludePackages) exclude.push(excludePackages);
|
|
117
|
+
|
|
118
|
+
if (!options.include && options.exclude === undefined) {
|
|
119
|
+
// Package inclusions override the default node_modules exclusion.
|
|
120
|
+
exclude.push(
|
|
121
|
+
new RegExp(
|
|
122
|
+
`^${includePackages ? `(?!${includePackages.source})` : ''}[^?#]*node_modules`,
|
|
123
|
+
),
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return {
|
|
128
|
+
id: {
|
|
129
|
+
// Custom globs/regexes run against normalized IDs in the shared filter.
|
|
130
|
+
// Keeping the native check broad avoids changing their matching semantics.
|
|
131
|
+
include: options.include ? undefined : /^[^?#]*\.[cm]?[jt]sx?(?:[?#][\s\S]*)?$/,
|
|
132
|
+
exclude,
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function createPackagePattern(packages?: string | string[]): RegExp | undefined {
|
|
138
|
+
const names = typeof packages === 'string' ? [packages] : packages ?? [];
|
|
139
|
+
if (!names.length) return undefined;
|
|
140
|
+
|
|
141
|
+
for (const name of names) {
|
|
142
|
+
if (!/^(?:@[a-zA-Z0-9_][a-zA-Z0-9._-]*\/)?[a-zA-Z0-9_][a-zA-Z0-9._-]*$/.test(name)) {
|
|
143
|
+
throw new Error(
|
|
144
|
+
`[fluentic-style] Invalid package name in includePackages/excludePackages: ${JSON.stringify(name)}`,
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const separator = '[/\\\\]';
|
|
150
|
+
const alternatives = names.map((name) => name.split('/').map(escapeRegExp).join(separator)).join('|');
|
|
151
|
+
// Match the innermost node_modules owner, including pnpm's nested layout.
|
|
152
|
+
// A package's nested dependencies must not inherit its include/exclude rule.
|
|
153
|
+
return new RegExp(
|
|
154
|
+
`^(?:[^?#]*${separator})?node_modules${separator}(?:${alternatives})` +
|
|
155
|
+
`(?![^?#]*${separator}node_modules${separator})` +
|
|
156
|
+
`(?:${separator}[^?#]*)?(?:[?#][\\s\\S]*)?$`,
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function escapeRegExp(value: string) {
|
|
161
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
162
|
+
}
|
package/style/tokens.ts
CHANGED
|
@@ -8,7 +8,8 @@ export type TokenTuple<T extends readonly ValueBase[]> = {
|
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
export type TokenRecord<T extends object> = {
|
|
11
|
-
[P in keyof T]: T[P] extends
|
|
11
|
+
[P in keyof T]: T[P] extends StyleToken<infer V> ? StyleToken<V>
|
|
12
|
+
: T[P] extends readonly unknown[] ? StyleToken<T[P]>
|
|
12
13
|
: T[P] extends object ? TokenRecord<T[P]>
|
|
13
14
|
: T[P] extends ValueBase ? StyleToken<InferValue<T[P]>>
|
|
14
15
|
: StyleToken<T[P]>;
|