@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.
Files changed (89) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/compiler/compiler/cache_identity.ts +115 -0
  3. package/compiler/compiler/compiler.ts +28 -1
  4. package/compiler/compiler/persistent_cache.ts +310 -0
  5. package/compiler/compiler/types.ts +12 -0
  6. package/compiler/extract/collector.ts +2 -2
  7. package/compiler/transform/evaluator/lazy_bindings.ts +63 -0
  8. package/compiler/transform/evaluator/metadata_cache.ts +124 -0
  9. package/compiler/transform/evaluator/tracer.ts +101 -86
  10. package/compiler/transform/extract/plugin.ts +21 -11
  11. package/compiler/transform/extract/utils/state.ts +3 -2
  12. package/compiler/utils/check_diagnostics.ts +18 -0
  13. package/compiler/utils/file_resolver.ts +24 -0
  14. package/dist/combine-BpOQWCtM.js.map +1 -1
  15. package/dist/compiler/index.mjs +1 -1
  16. package/dist/{compiler-AOb_VaKQ.mjs → compiler-Dpd41bCS.mjs} +646 -69
  17. package/dist/compiler-Dpd41bCS.mjs.map +1 -0
  18. package/dist/entry/rsc-dev.js.map +1 -1
  19. package/dist/{loader-fAuIjIik.mjs → loader-CR_NH6ub.mjs} +3 -3
  20. package/dist/{loader-fAuIjIik.mjs.map → loader-CR_NH6ub.mjs.map} +1 -1
  21. package/dist/{misc-CyZgGtc9.mjs → misc-D5AjOWP-.mjs} +31 -5
  22. package/dist/misc-D5AjOWP-.mjs.map +1 -0
  23. package/dist/plugin/farm/index.mjs +4 -4
  24. package/dist/plugin/farm/index.mjs.map +1 -1
  25. package/dist/plugin/nextjs/index.mjs +6 -6
  26. package/dist/plugin/nextjs/index.mjs.map +1 -1
  27. package/dist/plugin/nextjs/loader.mjs +4 -4
  28. package/dist/plugin/parcel/index.cjs +1 -1
  29. package/dist/plugin/parcel/index.mjs +2 -2
  30. package/dist/plugin/parcel/optimizer.cjs +1 -1
  31. package/dist/plugin/parcel/optimizer.mjs +2 -2
  32. package/dist/plugin/parcel/resolver.cjs +1 -1
  33. package/dist/plugin/parcel/resolver.mjs +2 -2
  34. package/dist/plugin/parcel/runtime.cjs +1 -1
  35. package/dist/plugin/parcel/runtime.mjs +1 -1
  36. package/dist/plugin/parcel/transformer.cjs +1 -1
  37. package/dist/plugin/parcel/transformer.mjs +2 -2
  38. package/dist/plugin/rspack/index.mjs +2 -2
  39. package/dist/plugin/vite/index.mjs +23 -20
  40. package/dist/plugin/vite/index.mjs.map +1 -1
  41. package/dist/plugin/webpack/index.mjs +2 -2
  42. package/dist/plugin/webpack/loader.mjs +2 -2
  43. package/dist/{registry-BMijh1CM.mjs → registry-CdSHrX-o.mjs} +2 -2
  44. package/dist/{registry-BMijh1CM.mjs.map → registry-CdSHrX-o.mjs.map} +1 -1
  45. package/dist/{shared-DY0kuBcN.cjs → shared-CcB1KDFI.cjs} +666 -76
  46. package/dist/shared-CcB1KDFI.cjs.map +1 -0
  47. package/dist/{shared-BfASWZo1.mjs → shared-CobOEWzt.mjs} +5 -5
  48. package/dist/shared-CobOEWzt.mjs.map +1 -0
  49. package/dist/{sidecar-cCzTDkzg.mjs → sidecar-CHDVQqN_.mjs} +3 -3
  50. package/dist/{sidecar-cCzTDkzg.mjs.map → sidecar-CHDVQqN_.mjs.map} +1 -1
  51. package/dist/style-CRs-vfY1.js.map +1 -1
  52. package/dist/types/compiler/compiler/cache_identity.d.ts +4 -0
  53. package/dist/types/compiler/compiler/compiler.d.ts +12 -0
  54. package/dist/types/compiler/compiler/persistent_cache.d.ts +14 -0
  55. package/dist/types/compiler/compiler/types.d.ts +11 -0
  56. package/dist/types/compiler/extract/collector.d.ts +1 -1
  57. package/dist/types/compiler/transform/evaluator/lazy_bindings.d.ts +22 -0
  58. package/dist/types/compiler/transform/evaluator/metadata_cache.d.ts +13 -0
  59. package/dist/types/compiler/transform/evaluator/tracer.d.ts +7 -0
  60. package/dist/types/compiler/transform/extract/utils/state.d.ts +3 -2
  61. package/dist/types/compiler/utils/check_diagnostics.d.ts +7 -0
  62. package/dist/types/compiler/utils/file_resolver.d.ts +4 -0
  63. package/dist/types/plugin/bundler/vite/state.d.ts +24 -0
  64. package/dist/types/plugin/utils/compiler.d.ts +12 -1
  65. package/dist/types/plugin/utils/filter.d.ts +11 -0
  66. package/dist/types/style/tokens.d.ts +1 -1
  67. package/dist/{utils-BO6Ix8t5.mjs → utils-CICsXGqS.mjs} +5 -5
  68. package/dist/utils-CICsXGqS.mjs.map +1 -0
  69. package/dist/{utils-EG9gh2g3.mjs → utils-XfsnoteV.mjs} +3 -3
  70. package/dist/{utils-EG9gh2g3.mjs.map → utils-XfsnoteV.mjs.map} +1 -1
  71. package/dist/{webpack-WXAJ3IYn.mjs → webpack-BAflvDbq.mjs} +7 -7
  72. package/dist/webpack-BAflvDbq.mjs.map +1 -0
  73. package/package.json +1 -1
  74. package/plugin/bundler/farm/plugin.ts +1 -1
  75. package/plugin/bundler/parcel/shared.ts +1 -1
  76. package/plugin/bundler/vite/plugin.ts +20 -17
  77. package/plugin/bundler/vite/state.ts +5 -6
  78. package/plugin/bundler/webpack/plugin.ts +2 -2
  79. package/plugin/nextjs/plugin.ts +2 -2
  80. package/plugin/nextjs/utils.ts +1 -1
  81. package/plugin/utils/compiler.ts +1 -2
  82. package/plugin/utils/filter.ts +65 -1
  83. package/style/tokens.ts +2 -1
  84. package/dist/compiler-AOb_VaKQ.mjs.map +0 -1
  85. package/dist/misc-CyZgGtc9.mjs.map +0 -1
  86. package/dist/shared-BfASWZo1.mjs.map +0 -1
  87. package/dist/shared-DY0kuBcN.cjs.map +0 -1
  88. package/dist/utils-BO6Ix8t5.mjs.map +0 -1
  89. package/dist/webpack-WXAJ3IYn.mjs.map +0 -1
@@ -32,6 +32,10 @@ let picomatch = require("picomatch");
32
32
  picomatch = __toESM(picomatch, 1);
33
33
  let css_what = require("css-what");
34
34
  let oxc_resolver = require("oxc-resolver");
35
+ let node_module = require("node:module");
36
+ let node_url = require("node:url");
37
+ let node_util = require("node:util");
38
+ let node_v8 = require("node:v8");
35
39
  require("@parcel/plugin");
36
40
  let node_http = require("node:http");
37
41
  //#region utils/symbol.ts
@@ -224,8 +228,8 @@ function createCssCollector() {
224
228
  add(item) {
225
229
  items.push(item);
226
230
  },
227
- addMany(items) {
228
- items.push(...items);
231
+ addMany(rules) {
232
+ items.push(...rules);
229
233
  },
230
234
  getItems() {
231
235
  return items;
@@ -478,10 +482,10 @@ function createFileCssCache(args) {
478
482
  };
479
483
  }
480
484
  function createFileCssContentHash(code) {
481
- return hash(code);
485
+ return hash$1(code);
482
486
  }
483
487
  function createFileCssConfigHash(config) {
484
- return hash(JSON.stringify(config ?? null));
488
+ return hash$1(JSON.stringify(config ?? null));
485
489
  }
486
490
  function readRecords(filesDir, args) {
487
491
  let entries;
@@ -503,9 +507,9 @@ function readRecords(filesDir, args) {
503
507
  return records;
504
508
  }
505
509
  function hashFilePath(filePath) {
506
- return hash(normalizePath(node_path.default.resolve(filePath)));
510
+ return hash$1(normalizePath(node_path.default.resolve(filePath)));
507
511
  }
508
- function hash(text) {
512
+ function hash$1(text) {
509
513
  return (0, node_crypto.createHash)("sha256").update(text).digest("hex");
510
514
  }
511
515
  //#endregion
@@ -772,7 +776,7 @@ const DEV_CONFIG_DEFAULT = {
772
776
  sourcemapLocationMode: "style",
773
777
  isElementClassNameEnabled: true
774
778
  };
775
- globalData("config.dev.isDev", () => ({ isDev: false }));
779
+ const IS_DEV = globalData("config.dev.isDev", () => ({ isDev: false }));
776
780
  const DEV_CONFIG = globalData("config.dev", () => ({ ...DEV_CONFIG_DEFAULT }));
777
781
  globalData("config.dev.plugin", () => ({ config: null }));
778
782
  globalData("config.dev.base", () => ({ config: null }));
@@ -6104,6 +6108,20 @@ function transformDebug(internal, args, deps) {
6104
6108
  //#endregion
6105
6109
  //#region compiler/utils/file_resolver.ts
6106
6110
  const contentCache = /* @__PURE__ */ new Map();
6111
+ let resolutionObserver = null;
6112
+ /** Synchronous extraction only; restore the previous observer even when extraction throws. */
6113
+ function observeFileResolutions(observer, run) {
6114
+ const previous = resolutionObserver;
6115
+ resolutionObserver = (source, fromFile, result) => {
6116
+ previous?.(source, fromFile, result);
6117
+ observer(source, fromFile, result);
6118
+ };
6119
+ try {
6120
+ return run();
6121
+ } finally {
6122
+ resolutionObserver = previous;
6123
+ }
6124
+ }
6107
6125
  const resolver = new oxc_resolver.ResolverFactory({
6108
6126
  conditionNames: [
6109
6127
  "import",
@@ -6128,6 +6146,11 @@ function clearResolverCache() {
6128
6146
  resolver.clearCache();
6129
6147
  }
6130
6148
  function resolveFile(source, fromFile) {
6149
+ const result = readResolvedFile(source, fromFile);
6150
+ resolutionObserver?.(source, fromFile, result);
6151
+ return result;
6152
+ }
6153
+ function readResolvedFile(source, fromFile) {
6131
6154
  const filePath = resolveFilePath(source, fromFile);
6132
6155
  if (!filePath) return null;
6133
6156
  let stat;
@@ -7637,10 +7660,273 @@ function hasGlobalRuntimeValue(value, seen = /* @__PURE__ */ new Set()) {
7637
7660
  return Object.values(value).some((item) => hasGlobalRuntimeValue(item, seen));
7638
7661
  }
7639
7662
  //#endregion
7663
+ //#region compiler/transform/evaluator/lazy_bindings.ts
7664
+ /** Map-compatible bindings whose initializers run only when their values are read. */
7665
+ var LazyBindings = class LazyBindings extends Map {
7666
+ constructor(..._args) {
7667
+ super(..._args);
7668
+ this.initializers = /* @__PURE__ */ new Map();
7669
+ }
7670
+ setLazy(name, initializer) {
7671
+ this.initializers.set(name, initializer);
7672
+ super.set(name, evalFail(`Circular binding: ${name}`));
7673
+ }
7674
+ /** Capture a declaration environment without forcing pending initializers. */
7675
+ fork() {
7676
+ const bindings = new LazyBindings();
7677
+ for (const [name, value] of super.entries()) bindings.set(name, value);
7678
+ for (const [name, initializer] of this.initializers) bindings.setLazy(name, initializer);
7679
+ return bindings;
7680
+ }
7681
+ set(name, value) {
7682
+ this.initializers.delete(name);
7683
+ return super.set(name, value);
7684
+ }
7685
+ delete(name) {
7686
+ this.initializers.delete(name);
7687
+ return super.delete(name);
7688
+ }
7689
+ clear() {
7690
+ this.initializers.clear();
7691
+ super.clear();
7692
+ }
7693
+ get(name) {
7694
+ const initializer = this.initializers.get(name);
7695
+ if (initializer) {
7696
+ this.initializers.delete(name);
7697
+ super.set(name, initializer());
7698
+ }
7699
+ return super.get(name);
7700
+ }
7701
+ forEach(callback, thisArg) {
7702
+ for (const key of this.keys()) callback.call(thisArg, this.get(key), key, this);
7703
+ }
7704
+ *entries() {
7705
+ for (const key of this.keys()) yield [key, this.get(key)];
7706
+ }
7707
+ *values() {
7708
+ for (const key of this.keys()) yield this.get(key);
7709
+ }
7710
+ [Symbol.iterator]() {
7711
+ return this.entries();
7712
+ }
7713
+ };
7714
+ //#endregion
7715
+ //#region compiler/compiler/cache_identity.ts
7716
+ let identity;
7717
+ /** Fingerprint actual compiler and dependency bytes, including locally patched packages.
7718
+ * Computed once per process: replacing loaded compiler code requires restarting Node.
7719
+ */
7720
+ function getCompilerCacheIdentity() {
7721
+ if (identity !== void 0) return identity;
7722
+ try {
7723
+ const filename = typeof __filename === "string" ? __filename : (0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href);
7724
+ const root = findPackageRoot(filename, "@fluentic/style");
7725
+ const hash = (0, node_crypto.createHash)("sha256");
7726
+ hash.update(JSON.stringify([
7727
+ process.versions,
7728
+ process.platform,
7729
+ process.arch,
7730
+ process.execArgv,
7731
+ process.env.NODE_OPTIONS,
7732
+ process.env.NODE_ENV,
7733
+ process.env.BABEL_ENV
7734
+ ]));
7735
+ const visited = /* @__PURE__ */ new Set();
7736
+ const hashTree = (directory, source = false) => {
7737
+ for (const item of node_fs.readdirSync(directory, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
7738
+ if (item.name === "node_modules" || item.name === ".git") continue;
7739
+ const file = node_path.default.join(directory, item.name);
7740
+ if (item.isDirectory()) hashTree(file, source);
7741
+ else if (item.isFile()) {
7742
+ if (!(source ? /\.(?:[cm]?[jt]sx?|json|node|wasm)$/ : /\.(?:[cm]?js|json|node|wasm)$/).test(item.name)) continue;
7743
+ hash.update(file).update("\0").update(node_fs.readFileSync(file)).update("\0");
7744
+ } else throw new Error("Unsupported package entry");
7745
+ }
7746
+ };
7747
+ const visit = (directory) => {
7748
+ directory = node_fs.realpathSync(directory);
7749
+ if (visited.has(directory)) return;
7750
+ visited.add(directory);
7751
+ hashTree(directory);
7752
+ const manifest = JSON.parse(node_fs.readFileSync(node_path.default.join(directory, "package.json"), "utf8"));
7753
+ const require = (0, node_module.createRequire)(node_path.default.join(directory, "package.json"));
7754
+ const optional = manifest.optionalDependencies ?? {};
7755
+ for (const name of Object.keys({
7756
+ ...manifest.dependencies,
7757
+ ...optional
7758
+ }).sort()) {
7759
+ let dependency;
7760
+ try {
7761
+ dependency = resolvePackageRoot(require, name);
7762
+ } catch (error) {
7763
+ if (name in optional) {
7764
+ hash.update("absent:" + name);
7765
+ continue;
7766
+ }
7767
+ throw error;
7768
+ }
7769
+ visit(dependency);
7770
+ }
7771
+ };
7772
+ const manifest = JSON.parse(node_fs.readFileSync(node_path.default.join(root, "package.json"), "utf8"));
7773
+ hash.update(node_fs.readFileSync(node_path.default.join(root, "package.json")));
7774
+ if (filename.startsWith(node_path.default.join(root, "dist") + node_path.default.sep)) hashTree(node_path.default.join(root, "dist"));
7775
+ else for (const item of manifest.files) {
7776
+ if (item === "dist") continue;
7777
+ const file = node_path.default.join(root, item);
7778
+ if (!node_fs.existsSync(file)) continue;
7779
+ if (node_fs.statSync(file).isDirectory()) hashTree(file, true);
7780
+ else if (/\.[cm]?[jt]sx?$/.test(item)) hash.update(item).update(node_fs.readFileSync(file));
7781
+ }
7782
+ const require = (0, node_module.createRequire)(node_path.default.join(root, "package.json"));
7783
+ for (const name of [
7784
+ "@babel/core",
7785
+ "@jridgewell/trace-mapping",
7786
+ "css-what",
7787
+ "oxc-resolver",
7788
+ "picomatch"
7789
+ ]) visit(resolvePackageRoot(require, name));
7790
+ identity = hash.digest("hex");
7791
+ } catch {
7792
+ identity = null;
7793
+ }
7794
+ return identity;
7795
+ }
7796
+ function resolvePackageRoot(require, name) {
7797
+ for (const directory of require.resolve.paths(name) ?? []) {
7798
+ const root = node_path.default.join(directory, name);
7799
+ if (node_fs.existsSync(node_path.default.join(root, "package.json"))) return node_fs.realpathSync(root);
7800
+ }
7801
+ try {
7802
+ return node_path.default.dirname(require.resolve(name + "/package.json"));
7803
+ } catch {
7804
+ return findPackageRoot(require.resolve(name), name);
7805
+ }
7806
+ }
7807
+ function findPackageRoot(filename, name) {
7808
+ let directory = node_path.default.dirname(filename);
7809
+ while (true) {
7810
+ const manifest = node_path.default.join(directory, "package.json");
7811
+ if (node_fs.existsSync(manifest) && JSON.parse(node_fs.readFileSync(manifest, "utf8")).name === name) return directory;
7812
+ const parent = node_path.default.dirname(directory);
7813
+ if (parent === directory) throw new Error("Package root not found");
7814
+ directory = parent;
7815
+ }
7816
+ }
7817
+ //#endregion
7818
+ //#region compiler/transform/evaluator/metadata_cache.ts
7819
+ const defaultParser = _babel_core.parseSync;
7820
+ const MAX_MEMORY_BYTES = 32 * 1024 * 1024;
7821
+ /** Immutable syntax only. Every consumer gets fresh nodes before annotations/evaluation. */
7822
+ function createTraceMetadataCache(internal) {
7823
+ const memory = /* @__PURE__ */ new Map();
7824
+ let memoryBytes = 0;
7825
+ let memoryVersion = internal.options.cache?.version;
7826
+ const stats = {
7827
+ parses: 0,
7828
+ memoryHits: 0,
7829
+ diskHits: 0,
7830
+ writes: 0
7831
+ };
7832
+ const remember = (filePath, contentHash, json) => {
7833
+ const previous = memory.get(filePath);
7834
+ if (previous) memoryBytes -= previous.json.length * 2;
7835
+ memory.delete(filePath);
7836
+ if (json.length * 2 > MAX_MEMORY_BYTES) return;
7837
+ while (memoryBytes + json.length * 2 > MAX_MEMORY_BYTES) {
7838
+ const oldest = memory.keys().next().value;
7839
+ memoryBytes -= memory.get(oldest).json.length * 2;
7840
+ memory.delete(oldest);
7841
+ }
7842
+ memory.set(filePath, {
7843
+ contentHash,
7844
+ json
7845
+ });
7846
+ memoryBytes += json.length * 2;
7847
+ };
7848
+ const parse = (babel, filePath, content) => {
7849
+ if (!Object.is(memoryVersion, internal.options.cache?.version)) {
7850
+ memory.clear();
7851
+ memoryBytes = 0;
7852
+ memoryVersion = internal.options.cache?.version;
7853
+ }
7854
+ const supportedParser = babel.parseSync === defaultParser;
7855
+ const contentHash = hash(content);
7856
+ const cached = supportedParser ? memory.get(filePath) : void 0;
7857
+ if (cached?.contentHash === contentHash) {
7858
+ stats.memoryHits++;
7859
+ memory.delete(filePath);
7860
+ memory.set(filePath, cached);
7861
+ return JSON.parse(cached.json);
7862
+ }
7863
+ const identity = supportedParser && internal.options.cache?.persistent !== false ? getCompilerCacheIdentity() : null;
7864
+ const filename = identity ? node_path.default.join(internal.cacheDir, "trace-metadata-v1", identity, hash(JSON.stringify(internal.options.cache?.version ?? null)), hash(filePath) + ".json") : null;
7865
+ if (filename) try {
7866
+ const record = JSON.parse(node_fs.readFileSync(filename, "utf8"));
7867
+ if (record.version === 1 && record.filePath === filePath && record.contentHash === contentHash && record.ast?.type === "File" && record.ast.program?.type === "Program" && Array.isArray(record.ast.program.body)) {
7868
+ const json = JSON.stringify(record.ast);
7869
+ if (record.checksum === hash(json)) {
7870
+ remember(filePath, contentHash, json);
7871
+ stats.diskHits++;
7872
+ return record.ast;
7873
+ }
7874
+ }
7875
+ } catch {}
7876
+ let ast;
7877
+ try {
7878
+ stats.parses++;
7879
+ ast = babel.parseSync(content, {
7880
+ ...babelTransformOptions(),
7881
+ filename: filePath
7882
+ });
7883
+ } catch {
7884
+ return null;
7885
+ }
7886
+ if (!ast || !supportedParser) return ast;
7887
+ let temporary;
7888
+ try {
7889
+ const json = JSON.stringify(ast, (_key, value) => {
7890
+ if (typeof value === "number" && (!Number.isFinite(value) || Object.is(value, -0)) || typeof value === "bigint" || typeof value === "function" || typeof value === "symbol") throw new Error("Non-JSON syntax data");
7891
+ return value;
7892
+ });
7893
+ remember(filePath, contentHash, json);
7894
+ if (filename) {
7895
+ const record = {
7896
+ version: 1,
7897
+ filePath,
7898
+ contentHash,
7899
+ checksum: hash(json),
7900
+ ast
7901
+ };
7902
+ node_fs.mkdirSync(node_path.default.dirname(filename), { recursive: true });
7903
+ temporary = filename + "." + (0, node_crypto.randomUUID)() + ".tmp";
7904
+ node_fs.writeFileSync(temporary, JSON.stringify(record), "utf8");
7905
+ node_fs.renameSync(temporary, filename);
7906
+ stats.writes++;
7907
+ }
7908
+ } catch {} finally {
7909
+ if (temporary) try {
7910
+ node_fs.unlinkSync(temporary);
7911
+ } catch {}
7912
+ }
7913
+ return ast;
7914
+ };
7915
+ return {
7916
+ parse,
7917
+ getStats: () => ({ ...stats })
7918
+ };
7919
+ }
7920
+ function hash(content) {
7921
+ return (0, node_crypto.createHash)("sha256").update(content).digest("hex");
7922
+ }
7923
+ //#endregion
7640
7924
  //#region compiler/transform/evaluator/tracer.ts
7641
- const CACHE_TYPE = "transform-trace";
7925
+ const CACHE_TYPE = "transform-trace-links-v2";
7642
7926
  function createTracer(internal) {
7643
7927
  const active = /* @__PURE__ */ new Set();
7928
+ const cyclic = /* @__PURE__ */ new Set();
7929
+ const metadata = createTraceMetadataCache(internal);
7644
7930
  const resolveImport = (babel, source, fromFile) => {
7645
7931
  return traceModuleResult(babel, source, fromFile)?.bindings ?? null;
7646
7932
  };
@@ -7653,35 +7939,55 @@ function createTracer(internal) {
7653
7939
  contentHash,
7654
7940
  cacheType: CACHE_TYPE
7655
7941
  });
7656
- if (cached && areDependenciesFresh(cached.dependencies ?? [])) return {
7942
+ if (cached?.bindings instanceof Map && areDependenciesFresh(cached.dependencies ?? [])) return {
7943
+ source,
7944
+ fromFile,
7657
7945
  filePath: resolved.filePath,
7658
7946
  contentHash,
7659
- bindings: new Map(cached.bindings),
7947
+ bindings: cached.bindings,
7660
7948
  dependencies: cached.dependencies ?? []
7661
7949
  };
7662
- if (active.has(resolved.filePath)) return null;
7950
+ if (active.has(resolved.filePath)) {
7951
+ for (const file of active) cyclic.add(file);
7952
+ return null;
7953
+ }
7663
7954
  active.add(resolved.filePath);
7664
7955
  try {
7665
7956
  const dependencies = /* @__PURE__ */ new Map();
7957
+ const dependencyList = [];
7958
+ const onTrack = () => {
7959
+ dependencyList.splice(0, dependencyList.length, ...dependencies.values());
7960
+ };
7666
7961
  const resolveDependency = (source, fromFile) => {
7962
+ const dependency = resolveFile(source, fromFile);
7963
+ addTraceDependency(dependencies, {
7964
+ source,
7965
+ fromFile,
7966
+ filePath: dependency?.filePath ?? null,
7967
+ contentHash: dependency ? hashContent(dependency.content) : null
7968
+ });
7969
+ onTrack();
7667
7970
  const traced = traceModuleResult(babel, source, fromFile);
7668
7971
  if (!traced) return null;
7669
- return createTrackedBindings(traced, dependencies);
7972
+ return createTrackedBindings(traced, dependencies, onTrack, () => traceModuleResult(babel, source, fromFile));
7670
7973
  };
7671
- const bindings = parseAndExtractModule(internal.projectDir, resolved.filePath, resolved.content, babel, resolveDependency, internal.options);
7974
+ const ast = metadata.parse(babel, resolved.filePath, resolved.content);
7975
+ if (!ast) return null;
7976
+ const bindings = extractModuleBindings(internal.projectDir, resolved.filePath, ast, babel, resolveDependency, internal.options);
7672
7977
  if (!bindings) return null;
7673
- const dependencyList = [...dependencies.values()];
7674
- internal.cache.setItem({
7978
+ if (!cyclic.has(resolved.filePath)) internal.cache.setItem({
7675
7979
  filePath: resolved.filePath,
7676
7980
  contentHash,
7677
7981
  cacheType: CACHE_TYPE,
7678
7982
  persistent: false,
7679
7983
  cacheContent: {
7680
- bindings: [...bindings.entries()],
7984
+ bindings,
7681
7985
  dependencies: dependencyList
7682
7986
  }
7683
7987
  });
7684
7988
  return {
7989
+ source,
7990
+ fromFile,
7685
7991
  filePath: resolved.filePath,
7686
7992
  contentHash,
7687
7993
  bindings,
@@ -7696,23 +8002,18 @@ function createTracer(internal) {
7696
8002
  };
7697
8003
  return {
7698
8004
  resolveImport,
7699
- traceModule
8005
+ traceModule,
8006
+ getMetadataCacheStats: metadata.getStats,
8007
+ beginCompilation() {
8008
+ clearResolverCache();
8009
+ cyclic.clear();
8010
+ }
7700
8011
  };
7701
8012
  }
7702
- function parseAndExtractModule(projectDir, filePath, content, babel, resolveImport, options) {
7703
- let ast = null;
7704
- try {
7705
- ast = babel.parseSync(content, {
7706
- ...babelTransformOptions(),
7707
- filename: filePath
7708
- });
7709
- } catch {
7710
- return null;
7711
- }
7712
- if (!ast) return null;
8013
+ function extractModuleBindings(projectDir, filePath, ast, babel, resolveImport, options) {
7713
8014
  const imports = /* @__PURE__ */ new Map();
7714
8015
  const rawBindings = /* @__PURE__ */ new Map();
7715
- const bindings = /* @__PURE__ */ new Map();
8016
+ const bindings = new LazyBindings();
7716
8017
  const styleNames = /* @__PURE__ */ new Set();
7717
8018
  const styleMetas = /* @__PURE__ */ new Map();
7718
8019
  const fileId = getProjectFileId$1(projectDir, filePath);
@@ -7793,9 +8094,9 @@ function parseAndExtractModule(projectDir, filePath, content, babel, resolveImpo
7793
8094
  }
7794
8095
  if (stmt.type === "ExportAllDeclaration") {
7795
8096
  const exported = resolveImport(stmt.source.value, filePath);
7796
- if (exported) exported.forEach((value, key) => {
7797
- if (key !== "default") bindings.set(key, value);
7798
- });
8097
+ if (exported) {
8098
+ for (const key of exported.keys()) if (key !== "default") bindings.setLazy(key, () => exported.get(key));
8099
+ }
7799
8100
  }
7800
8101
  if (stmt.type === "ExportDefaultDeclaration") rawBindings.set("default", stmt.declaration);
7801
8102
  }
@@ -7811,7 +8112,11 @@ function parseAndExtractModule(projectDir, filePath, content, babel, resolveImpo
7811
8112
  bindingNodes: rawBindings
7812
8113
  };
7813
8114
  rawBindings.forEach((node, name) => {
7814
- bindings.set(name, evaluateResolvedNode(node, scope, styleNames, fileId, options));
8115
+ bindings.setLazy(name, () => {
8116
+ const imported = imports.get(name);
8117
+ if (imported && node.type === "Identifier" && node.name === name) return resolveImport(imported.source, filePath)?.get(imported.name) ?? evalFail(`Cannot resolve export: ${name}`);
8118
+ return evaluateResolvedNode(node, scope, styleNames, fileId, options);
8119
+ });
7815
8120
  });
7816
8121
  return bindings;
7817
8122
  }
@@ -7974,47 +8279,52 @@ function createSlotRef(fileId, loc) {
7974
8279
  };
7975
8280
  }
7976
8281
  function hashContent(content) {
7977
- return node_crypto.createHash("sha256").update(content).digest("hex").slice(0, 16);
8282
+ return node_crypto.createHash("sha256").update(content).digest("hex");
7978
8283
  }
7979
8284
  function addTraceDependency(dependencies, dependency) {
7980
- dependencies.set(dependency.filePath, dependency);
8285
+ dependencies.set(JSON.stringify([dependency.source, dependency.fromFile]), dependency);
7981
8286
  }
7982
- function createTrackedBindings(traced, dependencies) {
8287
+ function createTrackedBindings(traced, dependencies, onTrack, refresh) {
7983
8288
  const track = () => {
7984
8289
  addTraceDependency(dependencies, traced);
7985
8290
  traced.dependencies.forEach((dependency) => addTraceDependency(dependencies, dependency));
7986
- };
7987
- return new class extends Map {
7988
- constructor() {
7989
- super(traced.bindings);
7990
- }
7991
- get(key) {
7992
- const value = super.get(key);
7993
- if (value !== void 0 || super.has(key)) track();
7994
- return value;
7995
- }
7996
- has(key) {
7997
- const result = super.has(key);
7998
- if (result) track();
7999
- return result;
8000
- }
8001
- forEach(callbackfn, thisArg) {
8002
- track();
8003
- super.forEach(callbackfn, thisArg);
8004
- }
8005
- }();
8291
+ onTrack();
8292
+ };
8293
+ const bindings = new LazyBindings();
8294
+ for (const key of traced.bindings.keys()) bindings.setLazy(key, () => {
8295
+ const current = refresh();
8296
+ if (!current) return evalFail(`Cannot resolve export: ${key}`);
8297
+ traced = current;
8298
+ const value = traced.bindings.get(key) ?? evalFail(`Cannot resolve export: ${key}`);
8299
+ track();
8300
+ return value;
8301
+ });
8302
+ track();
8303
+ return bindings;
8006
8304
  }
8007
8305
  function areDependenciesFresh(dependencies) {
8008
- for (const dependency of dependencies) if (hashFileContent(dependency.filePath) !== dependency.contentHash) return false;
8306
+ for (const dependency of dependencies) {
8307
+ const current = resolveFile(dependency.source, dependency.fromFile);
8308
+ if ((current?.filePath ?? null) !== dependency.filePath || (current ? hashContent(current.content) : null) !== dependency.contentHash) return false;
8309
+ }
8009
8310
  return true;
8010
8311
  }
8011
- function hashFileContent(filePath) {
8312
+ //#endregion
8313
+ //#region compiler/utils/check_diagnostics.ts
8314
+ let observer;
8315
+ /** Extraction is synchronous; restore the previous observer for nested compilations. */
8316
+ function observeCheckDiagnostics(onDiagnostic, run) {
8317
+ const previous = observer;
8318
+ observer = onDiagnostic;
8012
8319
  try {
8013
- return hashContent(node_fs.readFileSync(filePath, "utf8"));
8014
- } catch {
8015
- return null;
8320
+ return run();
8321
+ } finally {
8322
+ observer = previous;
8016
8323
  }
8017
8324
  }
8325
+ function recordCheckDiagnostic(diagnostic) {
8326
+ observer?.(diagnostic);
8327
+ }
8018
8328
  //#endregion
8019
8329
  //#region compiler/utils/imports.ts
8020
8330
  function getStyleRuntimeImportPath(mode) {
@@ -8532,7 +8842,7 @@ function createExtractPlugin(args) {
8532
8842
  this.styleNames = /* @__PURE__ */ new Set();
8533
8843
  this.sheetNames = /* @__PURE__ */ new Set();
8534
8844
  this.styleMetas = /* @__PURE__ */ new Map();
8535
- this.bindings = /* @__PURE__ */ new Map();
8845
+ this.bindings = new LazyBindings();
8536
8846
  this.bindingNodes = /* @__PURE__ */ new Map();
8537
8847
  this.imports = /* @__PURE__ */ new Map();
8538
8848
  this.needsExtractImport = false;
@@ -8587,10 +8897,7 @@ function createExtractPlugin(args) {
8587
8897
  annotateTokenDeclaration(decl, state, t);
8588
8898
  annotateAtRuleDeclaration(decl, state, t);
8589
8899
  const name = decl.id.name;
8590
- const scope = getEvalScope(state);
8591
- const result = evaluateNode(decl.init, scope);
8592
- state.bindings.set(name, result);
8593
- state.bindingNodes.set(name, decl.init);
8900
+ recordLazyBinding(state, name, t.cloneNode(decl.init, true));
8594
8901
  });
8595
8902
  },
8596
8903
  ExportNamedDeclaration(path, state) {
@@ -8601,10 +8908,7 @@ function createExtractPlugin(args) {
8601
8908
  annotateTokenDeclaration(decl, state, t);
8602
8909
  annotateAtRuleDeclaration(decl, state, t);
8603
8910
  const name = decl.id.name;
8604
- const scope = getEvalScope(state);
8605
- const result = evaluateNode(decl.init, scope);
8606
- state.bindings.set(name, result);
8607
- state.bindingNodes.set(name, decl.init);
8911
+ recordLazyBinding(state, name, t.cloneNode(decl.init, true));
8608
8912
  });
8609
8913
  },
8610
8914
  TSEnumDeclaration(path, state) {
@@ -8649,6 +8953,10 @@ function createExtractPlugin(args) {
8649
8953
  }
8650
8954
  if (!result) return;
8651
8955
  checkCompiledImportantUsage(result, options.check?.important, (level, message) => {
8956
+ recordCheckDiagnostic({
8957
+ level,
8958
+ message
8959
+ });
8652
8960
  if (level === "error") throw path.buildCodeFrameError(message);
8653
8961
  console.warn("[fluentic-style] " + message);
8654
8962
  });
@@ -8703,6 +9011,18 @@ function createExtractPlugin(args) {
8703
9011
  };
8704
9012
  });
8705
9013
  }
9014
+ function recordLazyBinding(state, name, initializer) {
9015
+ const bindings = state.bindings.fork();
9016
+ const scope = {
9017
+ ...getEvalScope(state),
9018
+ bindings,
9019
+ bindingNodes: new Map(state.bindingNodes),
9020
+ imports: new Map(state.imports)
9021
+ };
9022
+ bindings.setLazy(name, () => evaluateNode(initializer, scope));
9023
+ state.bindings.setLazy(name, () => bindings.get(name));
9024
+ state.bindingNodes.set(name, initializer);
9025
+ }
8706
9026
  function checkCompiledImportantUsage(result, options, report) {
8707
9027
  if (!options) return;
8708
9028
  let hasRawValue = false;
@@ -8979,15 +9299,254 @@ function createPlugin(rewriteSource) {
8979
9299
  });
8980
9300
  }
8981
9301
  //#endregion
9302
+ //#region compiler/compiler/persistent_cache.ts
9303
+ function createPersistentTransformCache(internal) {
9304
+ const stats = {
9305
+ hits: 0,
9306
+ misses: 0,
9307
+ bypasses: 0,
9308
+ writes: 0
9309
+ };
9310
+ const directory = node_path.default.join(internal.cacheDir, "extract-v1");
9311
+ let previousContext = null;
9312
+ const contextFor = () => {
9313
+ if (internal.options.cache?.persistent === false || DEV_CONFIG.isDev) return null;
9314
+ try {
9315
+ const identity = getCompilerCacheIdentity();
9316
+ if (!identity) return null;
9317
+ const options = internal.options;
9318
+ assertDataProperties(options);
9319
+ if (Object.getPrototypeOf(options) !== Object.prototype && Object.getPrototypeOf(options) !== null) throw new Error("Non-plain compiler options");
9320
+ if (options.importSources) assertPlainArray(options.importSources);
9321
+ const importSources = options.importSources?.map((entry) => {
9322
+ assertDataProperties(entry);
9323
+ if (Object.getPrototypeOf(entry) !== Object.prototype && Object.getPrototypeOf(entry) !== null) throw new Error("Non-plain import source");
9324
+ if (entry.styleFn && node_util.types.isProxy(entry.styleFn)) throw new Error("Proxy style function");
9325
+ if (!entry.meta && entry.styleFn) {
9326
+ const metadata = Object.getOwnPropertyDescriptor(entry.styleFn, symbol("style.fn:meta"));
9327
+ if (!metadata || !("value" in metadata)) throw new Error("Dynamic style metadata");
9328
+ }
9329
+ return {
9330
+ ...entry,
9331
+ styleFn: void 0,
9332
+ meta: entry.meta ?? (entry.styleFn ? getStyleFnMeta(entry.styleFn) : null)
9333
+ };
9334
+ });
9335
+ return digest(encode({
9336
+ schema: 1,
9337
+ identity,
9338
+ cwd: process.cwd(),
9339
+ projectDir: internal.projectDir,
9340
+ runtimeMode: internal.runtimeMode,
9341
+ options: {
9342
+ ...options,
9343
+ importSources
9344
+ },
9345
+ globals: {
9346
+ CSS_CONFIG,
9347
+ CSS_EXTRA_CONFIG,
9348
+ DEBUG_CONFIG,
9349
+ DEV_CONFIG,
9350
+ IS_DEV,
9351
+ RUNTIME_CONFIG,
9352
+ CHECK_CONFIG,
9353
+ DEFAULT_CONFIG,
9354
+ PrioritySelectors
9355
+ }
9356
+ }, options.cache?.dynamicConfig !== false));
9357
+ } catch {
9358
+ return null;
9359
+ }
9360
+ };
9361
+ const run = (args, compile) => {
9362
+ const context = contextFor();
9363
+ let key = null;
9364
+ try {
9365
+ if (context) key = digest(encode({
9366
+ context,
9367
+ args
9368
+ }));
9369
+ } catch {}
9370
+ if (!key) {
9371
+ stats.bypasses++;
9372
+ previousContext = null;
9373
+ internal.cache.clear();
9374
+ clearResolverCache();
9375
+ return {
9376
+ result: compile(),
9377
+ hit: false
9378
+ };
9379
+ }
9380
+ const filename = node_path.default.join(directory, getCompilerCacheIdentity(), digest(encode(internal.options.cache?.version)), digest(args.filePath) + ".bin");
9381
+ clearResolverCache();
9382
+ let hit;
9383
+ try {
9384
+ const buffer = node_fs.readFileSync(filename);
9385
+ const body = buffer.subarray(65);
9386
+ if (buffer.subarray(0, 64).toString() === digest(body)) {
9387
+ const record = (0, node_v8.deserialize)(body);
9388
+ if (record.key === key && Array.isArray(record.dependencies) && validRecord(record) && record.dependencies.every(isFresh)) hit = record;
9389
+ }
9390
+ } catch {}
9391
+ if (hit) {
9392
+ stats.hits++;
9393
+ for (const diagnostic of hit.diagnostics) if (diagnostic.level === "warn") console.warn("[fluentic-style] " + diagnostic.message);
9394
+ if (hit.error) {
9395
+ const error = new Error(hit.error.message);
9396
+ error.name = hit.error.name;
9397
+ error.stack = hit.error.stack;
9398
+ throw error;
9399
+ }
9400
+ return {
9401
+ result: hit.result,
9402
+ hit: true
9403
+ };
9404
+ }
9405
+ stats.misses++;
9406
+ clearResolverCache();
9407
+ if (context !== previousContext) internal.cache.clear();
9408
+ previousContext = context;
9409
+ const dependencies = /* @__PURE__ */ new Map();
9410
+ const diagnostics = [];
9411
+ let result = null;
9412
+ let failure = null;
9413
+ try {
9414
+ result = observeCheckDiagnostics((diagnostic) => diagnostics.push(diagnostic), () => observeFileResolutions((source, fromFile, resolved) => {
9415
+ dependencies.set(JSON.stringify([source, fromFile]), {
9416
+ source,
9417
+ fromFile,
9418
+ filePath: resolved?.filePath ?? null,
9419
+ hash: resolved ? digest(resolved.content) : null
9420
+ });
9421
+ }, compile));
9422
+ } catch (error) {
9423
+ if (!(error instanceof Error) || diagnostics[diagnostics.length - 1]?.level !== "error") throw error;
9424
+ failure = error;
9425
+ }
9426
+ const cachedError = failure ? {
9427
+ name: failure.name,
9428
+ message: failure.message,
9429
+ stack: failure.stack
9430
+ } : null;
9431
+ if (result || failure) {
9432
+ let temporary;
9433
+ try {
9434
+ encode(result);
9435
+ const records = [...dependencies.values()];
9436
+ clearResolverCache();
9437
+ if (!records.every(isFresh) || contextFor() !== context) throw new Error("Cache snapshot changed");
9438
+ const body = (0, node_v8.serialize)({
9439
+ key,
9440
+ dependencies: records,
9441
+ result,
9442
+ diagnostics,
9443
+ error: cachedError
9444
+ });
9445
+ node_fs.mkdirSync(node_path.default.dirname(filename), { recursive: true });
9446
+ temporary = filename + "." + (0, node_crypto.randomUUID)() + ".tmp";
9447
+ node_fs.writeFileSync(temporary, Buffer.concat([Buffer.from(digest(body) + "\n"), body]));
9448
+ node_fs.renameSync(temporary, filename);
9449
+ stats.writes++;
9450
+ } catch {} finally {
9451
+ if (temporary) try {
9452
+ node_fs.unlinkSync(temporary);
9453
+ } catch {}
9454
+ }
9455
+ }
9456
+ if (failure) throw failure;
9457
+ return {
9458
+ result,
9459
+ hit: false
9460
+ };
9461
+ };
9462
+ return {
9463
+ run,
9464
+ getStats: () => ({ ...stats })
9465
+ };
9466
+ }
9467
+ function isFresh(dependency) {
9468
+ if (typeof dependency.source !== "string" || typeof dependency.fromFile !== "string") return false;
9469
+ const resolved = resolveFile(dependency.source, dependency.fromFile);
9470
+ return (resolved?.filePath ?? null) === dependency.filePath && (resolved ? digest(resolved.content) : null) === dependency.hash;
9471
+ }
9472
+ function validRecord(record) {
9473
+ if (!Array.isArray(record.diagnostics) || !record.diagnostics.every((item) => item && (item.level === "warn" || item.level === "error") && typeof item.message === "string")) return false;
9474
+ if (record.error) return record.result === null && record.diagnostics[record.diagnostics.length - 1]?.level === "error" && typeof record.error.name === "string" && typeof record.error.message === "string" && (record.error.stack === void 0 || typeof record.error.stack === "string");
9475
+ return record.error === null && record.diagnostics.every((item) => item.level === "warn") && validResult(record.result);
9476
+ }
9477
+ function validResult(result) {
9478
+ return !!result && typeof result.code === "string" && (result.sourcemap === null || typeof result.sourcemap === "string") && Array.isArray(result.rules) && result.rules.every((rule) => typeof rule.css === "string" && typeof rule.dedupe === "string" && typeof rule.className === "string" && Array.isArray(rule.priority));
9479
+ }
9480
+ function digest(value) {
9481
+ return (0, node_crypto.createHash)("sha256").update(value).digest("hex");
9482
+ }
9483
+ function assertDataProperties(value) {
9484
+ if (node_util.types.isProxy(value)) throw new Error("Proxy configuration");
9485
+ for (const key of Reflect.ownKeys(value)) {
9486
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
9487
+ if (typeof key === "symbol" || !("value" in descriptor) || !descriptor.enumerable && !(Array.isArray(value) && key === "length") && !(value instanceof RegExp && key === "lastIndex")) throw new Error("Dynamic configuration");
9488
+ }
9489
+ }
9490
+ function assertPlainArray(value) {
9491
+ assertDataProperties(value);
9492
+ if (Object.getPrototypeOf(value) !== Array.prototype || Object.keys(value).some((key) => !/^(0|[1-9][0-9]*)$/.test(key))) throw new Error("Non-plain array");
9493
+ }
9494
+ /** Tagged, order-preserving encoding: property order can affect generated CSS. */
9495
+ function encode(value, dynamicConfig = false) {
9496
+ return JSON.stringify(encodeValue(value, /* @__PURE__ */ new Set(), dynamicConfig));
9497
+ }
9498
+ function encodeValue(value, seen = /* @__PURE__ */ new Set(), dynamicConfig = false) {
9499
+ if (typeof value === "function" && dynamicConfig) {
9500
+ if (node_util.types.isProxy(value)) throw new Error("Proxy callback");
9501
+ for (const key of Reflect.ownKeys(value)) {
9502
+ if (typeof key !== "string" || ![
9503
+ "length",
9504
+ "name",
9505
+ "prototype",
9506
+ "arguments",
9507
+ "caller"
9508
+ ].includes(key)) throw new Error("Callback with custom properties");
9509
+ if (!("value" in Object.getOwnPropertyDescriptor(value, key))) throw new Error("Callback accessor");
9510
+ }
9511
+ const source = Function.prototype.toString.call(value);
9512
+ if (source.includes("[native code]")) throw new Error("Opaque callback");
9513
+ return ["function", source];
9514
+ }
9515
+ if (value === void 0) return ["undefined"];
9516
+ if (value === null || typeof value === "string" || typeof value === "boolean") return value;
9517
+ if (typeof value === "number" && Number.isFinite(value)) return ["number", Object.is(value, -0) ? "-0" : value];
9518
+ if (typeof value !== "object" || value === null || seen.has(value)) throw new Error("Unsupported cache input");
9519
+ assertDataProperties(value);
9520
+ if (value instanceof RegExp) {
9521
+ if (value.global || value.sticky || Object.getPrototypeOf(value) !== RegExp.prototype || Object.keys(value).length) throw new Error("Dynamic pattern");
9522
+ return [
9523
+ "regexp",
9524
+ value.source,
9525
+ value.flags
9526
+ ];
9527
+ }
9528
+ if (Array.isArray(value)) assertPlainArray(value);
9529
+ if (!Array.isArray(value) && Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) throw new Error("Non-plain cache input");
9530
+ seen.add(value);
9531
+ try {
9532
+ return [Array.isArray(value) ? ["array", value.length] : "object", Object.keys(value).map((key) => [key, encodeValue(value[key], seen, dynamicConfig)])];
9533
+ } finally {
9534
+ seen.delete(value);
9535
+ }
9536
+ }
9537
+ //#endregion
8982
9538
  //#region compiler/compiler/compiler.ts
8983
9539
  function createCompiler(args, options) {
8984
9540
  const internal = createCompilerInternal(args, options);
8985
9541
  const tracer = createTracer(internal);
8986
9542
  const collector = createCssCollector();
9543
+ const persistentCache = createPersistentTransformCache(internal);
8987
9544
  const compileDebug = (args) => {
9545
+ tracer.beginCompilation();
8988
9546
  return rewriteTransformResult(transformDebug(internal, args, { tracer }), internal.runtimeMode, args.code);
8989
9547
  };
8990
9548
  const compileDebugRSC = (args) => {
9549
+ tracer.beginCompilation();
8991
9550
  const debugResult = rewriteTransformResult(transformDebug(internal, args, { tracer }), internal.runtimeMode, args.code);
8992
9551
  if (!debugResult) return null;
8993
9552
  const rscCollector = createCssCollector();
@@ -9008,6 +9567,18 @@ function createCompiler(args, options) {
9008
9567
  };
9009
9568
  };
9010
9569
  const compileExtract = (args) => {
9570
+ const startIndex = collector.getItems().length;
9571
+ try {
9572
+ const cached = persistentCache.run(args, () => compileExtractUncached(args));
9573
+ if (cached.hit && cached.result) collector.addMany(cached.result.rules);
9574
+ return cached.result;
9575
+ } catch (error) {
9576
+ collector.getItems().splice(startIndex);
9577
+ throw error;
9578
+ }
9579
+ };
9580
+ const compileExtractUncached = (args) => {
9581
+ tracer.beginCompilation();
9011
9582
  const startIndex = collector.getItems().length;
9012
9583
  const result = transformExtract(internal, args, {
9013
9584
  collector,
@@ -9034,11 +9605,14 @@ function createCompiler(args, options) {
9034
9605
  compileDebugRSC,
9035
9606
  compileExtract,
9036
9607
  getExtractedCss,
9037
- invalidateFile
9608
+ invalidateFile,
9609
+ getPersistentCacheStats: persistentCache.getStats,
9610
+ getTraceMetadataCacheStats: tracer.getMetadataCacheStats
9038
9611
  };
9039
9612
  }
9040
9613
  function createCompilerInternal(args, options) {
9041
- const { projectDir, cacheDir, runtimeMode } = args;
9614
+ const { projectDir, runtimeMode } = args;
9615
+ const cacheDir = options.cache?.location === void 0 ? args.cacheDir : node_path.default.resolve(projectDir, options.cache.location);
9042
9616
  return {
9043
9617
  projectDir,
9044
9618
  cacheDir,
@@ -9055,6 +9629,7 @@ function rewriteTransformResult(result, runtimeMode, sourceCode) {
9055
9629
  };
9056
9630
  }
9057
9631
  function rewriteCompilerRuntimeImports(code, runtimeMode, sourceCode) {
9632
+ if (!code.includes("@fluentic/style") && !code.includes("\\")) return code;
9058
9633
  const importRuntimeMode = getImportRuntimeMode(runtimeMode, sourceCode);
9059
9634
  return rewriteImportSources(code, (source) => getCompilerRuntimeImportSource(source, runtimeMode, importRuntimeMode));
9060
9635
  }
@@ -9117,6 +9692,7 @@ const CssPropPresets = {
9117
9692
  //#endregion
9118
9693
  //#region plugin/utils/constants.ts
9119
9694
  const PLUGIN_NAME = "fluentic-style";
9695
+ const PLUGIN_CACHE_DIR = "node_modules/.cache/fluentic-style";
9120
9696
  const EXTRACTED_CSS_MARKER = ".__fluentic_style_css_marker__{--fluentic-style:0}";
9121
9697
  //#endregion
9122
9698
  //#region plugin/utils/filter.ts
@@ -9128,13 +9704,16 @@ function normalizeModuleId(id) {
9128
9704
  }
9129
9705
  function createTransformFilter(options = {}) {
9130
9706
  const includes = normalizeMatchers(options.include);
9707
+ const includePackages = createPackagePattern(options.includePackages);
9708
+ const excludePackages = createPackagePattern(options.excludePackages);
9131
9709
  const excludes = normalizeMatchers(options.exclude ?? (options.include ? void 0 : DEFAULT_TRANSFORM_EXCLUDE));
9132
9710
  const cache = /* @__PURE__ */ new Map();
9133
9711
  const filter = ((id) => {
9134
9712
  const filePath = normalizeModuleId(id);
9135
9713
  const cached = cache.get(filePath);
9136
9714
  if (cached !== void 0) return cached;
9137
- const result = shouldTransform(filePath, includes, excludes);
9715
+ const packagePath = normalizePath(filePath);
9716
+ const result = excludePackages?.test(packagePath) ? false : includePackages?.test(packagePath) ? DEFAULT_TRANSFORM_INCLUDE.test(filePath) : shouldTransform(filePath, includes, excludes);
9138
9717
  cache.set(filePath, result);
9139
9718
  return result;
9140
9719
  });
@@ -9161,10 +9740,21 @@ function shouldTransform(id, includes, excludes) {
9161
9740
  for (const include of includes) if (include(id)) return true;
9162
9741
  return false;
9163
9742
  }
9743
+ function createPackagePattern(packages) {
9744
+ const names = typeof packages === "string" ? [packages] : packages ?? [];
9745
+ if (!names.length) return void 0;
9746
+ for (const name of names) if (!/^(?:@[a-zA-Z0-9_][a-zA-Z0-9._-]*\/)?[a-zA-Z0-9_][a-zA-Z0-9._-]*$/.test(name)) throw new Error(`[fluentic-style] Invalid package name in includePackages/excludePackages: ${JSON.stringify(name)}`);
9747
+ const separator = "[/\\\\]";
9748
+ const alternatives = names.map((name) => name.split("/").map(escapeRegExp).join(separator)).join("|");
9749
+ return new RegExp(`^(?:[^?#]*${separator})?node_modules${separator}(?:${alternatives})(?![^?#]*${separator}node_modules${separator})(?:${separator}[^?#]*)?(?:[?#][\\s\\S]*)?$`);
9750
+ }
9751
+ function escapeRegExp(value) {
9752
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
9753
+ }
9164
9754
  //#endregion
9165
9755
  //#region plugin/utils/compiler.ts
9166
9756
  function getPluginCacheDir(projectDir, cacheDir) {
9167
- return cacheDir ?? node_path.default.join(projectDir, "node_modules/.cache/fluentic-style");
9757
+ return cacheDir === void 0 ? node_path.default.join(projectDir, PLUGIN_CACHE_DIR) : node_path.default.resolve(projectDir, cacheDir);
9168
9758
  }
9169
9759
  function createPluginCompiler(args) {
9170
9760
  const dev = args.dev;
@@ -9560,7 +10150,7 @@ let stateKey = "";
9560
10150
  function getParcelState(options, pluginOptions = {}) {
9561
10151
  const projectDir = options.projectRoot ?? process.cwd();
9562
10152
  const dev = options.mode !== "production";
9563
- const cacheDir = getPluginCacheDir(projectDir, pluginOptions.cacheDir);
10153
+ const cacheDir = getPluginCacheDir(projectDir, pluginOptions.cache?.location);
9564
10154
  const key = JSON.stringify({
9565
10155
  projectDir,
9566
10156
  dev,
@@ -9808,4 +10398,4 @@ Object.defineProperty(exports, "writeParcelVirtualRuntimeFile", {
9808
10398
  }
9809
10399
  });
9810
10400
 
9811
- //# sourceMappingURL=shared-DY0kuBcN.cjs.map
10401
+ //# sourceMappingURL=shared-CcB1KDFI.cjs.map