@plumeria/utils 18.5.0 → 18.5.2

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.
@@ -36,4 +36,4 @@ export type DynamicStyleResult = {
36
36
  prop: string;
37
37
  }>>;
38
38
  };
39
- export declare const resolveDynamicStyle: (func: StyleFunction, runtimeParams: string[], staticTable: StaticTable, tables: DynamicStyleTables) => DynamicStyleResult | null;
39
+ export declare const resolveDynamicStyle: (func: StyleFunction, runtimeParams: string[], staticTable: StaticTable, tables: DynamicStyleTables, providedParams?: ReadonlySet<string>) => DynamicStyleResult | null;
@@ -143,12 +143,14 @@ const applyVarFallback = (style, cssVar, literal) => {
143
143
  }
144
144
  };
145
145
  exports.applyVarFallback = applyVarFallback;
146
- const resolveDynamicStyle = (func, runtimeParams, staticTable, tables) => {
146
+ const resolveDynamicStyle = (func, runtimeParams, staticTable, tables, providedParams) => {
147
147
  if (func.unsupportedParams)
148
148
  throw new Error('[plumeria] Dynamic styles require named parameters or object destructuring; array and rest parameters are not supported.');
149
149
  const tempStaticTable = { ...staticTable };
150
150
  const resolveBody = () => (0, parser_1.objectExpressionToObject)(func.body, tempStaticTable, tables.keyframesHashTable, tables.viewTransitionHashTable, tables.createThemeHashTable, tables.createThemeObjectTable, tables.createHashTable, tables.createStaticHashTable, tables.createStaticObjectTable, tables.variantsHashTable);
151
- const withDefault = Object.entries(func.defaults ?? {}).filter(([param]) => tempStaticTable[param] === undefined);
151
+ const withDefault = Object.entries(func.defaults ?? {}).filter(([param]) => providedParams
152
+ ? !providedParams.has(param)
153
+ : tempStaticTable[param] === undefined);
152
154
  const cssVars = {};
153
155
  const varParams = Array.from(new Set([...runtimeParams, ...withDefault.map(([param]) => param)]));
154
156
  if (varParams.length > 0) {
package/dist/parser.d.ts CHANGED
@@ -42,7 +42,7 @@ export declare function resolveFileError(actualPath: string, importedName: strin
42
42
  filePath: string;
43
43
  message: string;
44
44
  } | undefined;
45
- export declare function scanAll(): Tables;
45
+ export declare function scanAll(scanCwd?: string): Tables;
46
46
  export declare function getFileDependencies(filePath: string): string[];
47
47
  export declare function resolveExport(filePath: string, exportName: string, visited?: Set<string>): {
48
48
  filePath: string;
package/dist/parser.js CHANGED
@@ -95,9 +95,6 @@ const getRootIdentifier = (node) => {
95
95
  return (0, exports.getRootIdentifier)(callee);
96
96
  }
97
97
  }
98
- if (node.type === 'ParenthesisExpression') {
99
- return (0, exports.getRootIdentifier)(node.expression);
100
- }
101
98
  return null;
102
99
  };
103
100
  exports.getRootIdentifier = getRootIdentifier;
@@ -358,6 +355,9 @@ function collectLocalConsts(ast) {
358
355
  exports.t.isBooleanLiteral(init)) {
359
356
  result = init.value;
360
357
  }
358
+ else if (exports.t.isIdentifier(init)) {
359
+ result = resolveValue(init.value);
360
+ }
361
361
  else if (exports.t.isObjectExpression(init)) {
362
362
  result = objectExpressionToObject(init, localConsts, {}, {}, {}, {}, {}, {}, {}, {}, resolveValue);
363
363
  }
@@ -1024,6 +1024,7 @@ const globalAgregatedTables = {
1024
1024
  };
1025
1025
  let hasComputedOnce = false;
1026
1026
  let resolutionConfigStamp;
1027
+ let scannedCwd;
1027
1028
  const objectTableOwners = new Map();
1028
1029
  const fileObjectContributions = new Map();
1029
1030
  function snapshotTables() {
@@ -1152,12 +1153,16 @@ function stripFileContributions(filePath, cached) {
1152
1153
  }
1153
1154
  }
1154
1155
  }
1155
- function scanAll() {
1156
- if (hasComputedOnce && process.env.NODE_ENV === 'production') {
1156
+ function scanAll(scanCwd = process.cwd()) {
1157
+ const cwd = path.resolve(scanCwd);
1158
+ if (hasComputedOnce &&
1159
+ process.env.NODE_ENV === 'production' &&
1160
+ scannedCwd === cwd) {
1157
1161
  return snapshotTables();
1158
1162
  }
1159
1163
  const localTables = globalAgregatedTables;
1160
- const configPath = path.join(process.cwd(), 'tsconfig.json');
1164
+ scannedCwd = cwd;
1165
+ const configPath = path.join(cwd, 'tsconfig.json');
1161
1166
  let configStamp = configPath;
1162
1167
  try {
1163
1168
  configStamp += `:${fs.statSync(configPath).mtimeMs}`;
@@ -1166,10 +1171,9 @@ function scanAll() {
1166
1171
  }
1167
1172
  const resolutionChanged = resolutionConfigStamp !== undefined &&
1168
1173
  resolutionConfigStamp !== configStamp;
1169
- if (resolutionChanged)
1170
- (0, resolver_1.resetImportResolutionCache)();
1174
+ if (resolutionConfigStamp !== configStamp)
1175
+ (0, resolver_1.resetImportResolutionCache)(cwd);
1171
1176
  resolutionConfigStamp = configStamp;
1172
- const cwd = process.cwd();
1173
1177
  const segments = cwd.split(path.sep);
1174
1178
  const dependencyDirectory = segments.indexOf('node_modules');
1175
1179
  const root = dependencyDirectory < 0
@@ -1771,7 +1775,7 @@ function scanAll() {
1771
1775
  runtime.push(param);
1772
1776
  });
1773
1777
  }
1774
- const resolved = (0, dynamicKey_1.resolveDynamicStyle)(func, runtime, dynamicStaticTable, dynamicStyleTables);
1778
+ const resolved = (0, dynamicKey_1.resolveDynamicStyle)(func, runtime, dynamicStaticTable, dynamicStyleTables, new Set());
1775
1779
  if (!resolved)
1776
1780
  return null;
1777
1781
  const hasVars = runtime.some((param) => (resolved.varGroups.get(param) ?? []).length > 0);
@@ -1786,6 +1790,8 @@ function scanAll() {
1786
1790
  let hasVars = false;
1787
1791
  for (const el of expr.elements) {
1788
1792
  if (el && el.expression) {
1793
+ if (el.spread)
1794
+ return null;
1789
1795
  const res = resolveCallStylePropInScan(el.expression);
1790
1796
  if (!res)
1791
1797
  continue;
@@ -1829,9 +1835,6 @@ function scanAll() {
1829
1835
  }
1830
1836
  }
1831
1837
  }
1832
- if (expr.type === 'ParenthesisExpression') {
1833
- return resolveCallStylePropInScan(expr.expression);
1834
- }
1835
1838
  if (expr.type === 'MemberExpression' &&
1836
1839
  expr.object.type === 'Identifier') {
1837
1840
  const varName = expr.object.value;
@@ -1965,6 +1968,8 @@ function scanAll() {
1965
1968
  if (!alternatives) {
1966
1969
  if (!containsStyleReference(node))
1967
1970
  return;
1971
+ if (node.elements.some((element) => element?.spread))
1972
+ throw new Error('[plumeria] Spread elements in a style array are not supported. List each style explicitly.');
1968
1973
  throw new Error('[plumeria] A style prop array contains an unsupported style expression. Use defined styles, null, false, undefined, or conditional branches of defined styles.');
1969
1974
  }
1970
1975
  if (!containsStyleReference(node))
@@ -1,2 +1,2 @@
1
- export declare function resetImportResolutionCache(): void;
1
+ export declare function resetImportResolutionCache(cwd?: string): void;
2
2
  export declare function resolveImportPath(importPath: string, importerPath: string): string | null;
package/dist/resolver.js CHANGED
@@ -38,8 +38,8 @@ exports.resolveImportPath = resolveImportPath;
38
38
  const fs = __importStar(require("fs"));
39
39
  const path = __importStar(require("path"));
40
40
  let cachedTsConfig = undefined;
41
- function resetImportResolutionCache() {
42
- const configPath = path.join(process.cwd(), 'tsconfig.json');
41
+ function resetImportResolutionCache(cwd = process.cwd()) {
42
+ const configPath = path.join(cwd, 'tsconfig.json');
43
43
  try {
44
44
  const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
45
45
  cachedTsConfig = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/utils",
3
- "version": "18.5.0",
3
+ "version": "18.5.2",
4
4
  "description": "Plumeria Utils",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",