@plumeria/utils 19.2.7 → 19.2.9

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 (2) hide show
  1. package/dist/parser.js +78 -9
  2. package/package.json +1 -1
package/dist/parser.js CHANGED
@@ -1133,7 +1133,46 @@ function stripFileContributions(filePath, cached) {
1133
1133
  }
1134
1134
  }
1135
1135
  }
1136
+ const propEntryKeys = new WeakMap();
1137
+ const propEntryKey = (entry) => JSON.stringify([
1138
+ entry.filePath,
1139
+ entry.spanStart,
1140
+ entry.key,
1141
+ entry.conditions,
1142
+ ]);
1143
+ const statMemo = new Map();
1144
+ let scanning = false;
1145
+ function statFile(filePath) {
1146
+ if (!scanning)
1147
+ return fs.statSync(filePath);
1148
+ const memo = statMemo.get(filePath);
1149
+ if (memo) {
1150
+ if (memo instanceof Error)
1151
+ throw memo;
1152
+ return memo;
1153
+ }
1154
+ try {
1155
+ const stats = fs.statSync(filePath);
1156
+ statMemo.set(filePath, stats);
1157
+ return stats;
1158
+ }
1159
+ catch (e) {
1160
+ statMemo.set(filePath, e);
1161
+ throw e;
1162
+ }
1163
+ }
1136
1164
  function scanAll(scanCwd = process.cwd()) {
1165
+ scanning = true;
1166
+ statMemo.clear();
1167
+ try {
1168
+ return runScan(scanCwd);
1169
+ }
1170
+ finally {
1171
+ scanning = false;
1172
+ statMemo.clear();
1173
+ }
1174
+ }
1175
+ function runScan(scanCwd = process.cwd()) {
1137
1176
  const cwd = path.resolve(scanCwd);
1138
1177
  if (hasComputedOnce &&
1139
1178
  process.env.NODE_ENV === 'production' &&
@@ -1178,6 +1217,7 @@ function scanAll(scanCwd = process.cwd()) {
1178
1217
  if (!currentFiles.has(fp))
1179
1218
  deletedFiles.push(fp);
1180
1219
  }
1220
+ const appeared = files.some((fp) => !knownFiles.has(fp));
1181
1221
  knownFiles = currentFiles;
1182
1222
  const invalidated = new Set();
1183
1223
  const queue = [];
@@ -1219,6 +1259,19 @@ function scanAll(scanCwd = process.cwd()) {
1219
1259
  invalidated.add(fp);
1220
1260
  queue.push(fp);
1221
1261
  }
1262
+ if (appeared) {
1263
+ for (const [filePath, cached] of Object.entries(fileCache)) {
1264
+ if (invalidated.has(filePath) ||
1265
+ !currentFiles.has(filePath) ||
1266
+ !cached.unresolvedImports?.length)
1267
+ continue;
1268
+ const resolves = cached.unresolvedImports.some((specifier) => (0, resolver_1.resolveImportPath)(specifier, filePath));
1269
+ if (resolves) {
1270
+ invalidated.add(filePath);
1271
+ queue.push(filePath);
1272
+ }
1273
+ }
1274
+ }
1222
1275
  for (let head = 0; head < queue.length; head++) {
1223
1276
  const fp = queue[head];
1224
1277
  const deps = dependentsMap.get(fp);
@@ -2065,15 +2118,18 @@ function scanAll(scanCwd = process.cwd()) {
2065
2118
  globalTable[compKey][propName] = [];
2066
2119
  }
2067
2120
  const entries = localComponentPropsTable[compKey][propName];
2121
+ const collected = globalTable[compKey][propName];
2122
+ let taken = propEntryKeys.get(collected);
2123
+ if (!taken) {
2124
+ taken = new Set(collected.map(propEntryKey));
2125
+ propEntryKeys.set(collected, taken);
2126
+ }
2068
2127
  for (const entry of entries) {
2069
- const exists = globalTable[compKey][propName].some((x) => x.spanStart === entry.spanStart &&
2070
- x.filePath === entry.filePath &&
2071
- x.key === entry.key &&
2072
- JSON.stringify(x.conditions) ===
2073
- JSON.stringify(entry.conditions));
2074
- if (!exists) {
2075
- globalTable[compKey][propName].push(entry);
2076
- }
2128
+ const key = propEntryKey(entry);
2129
+ if (taken.has(key))
2130
+ continue;
2131
+ taken.add(key);
2132
+ collected.push(entry);
2077
2133
  }
2078
2134
  }
2079
2135
  }
@@ -2083,6 +2139,7 @@ function scanAll(scanCwd = process.cwd()) {
2083
2139
  dependencies: Array.from(localDependencies),
2084
2140
  exports: fileCache[filePath]?.exports,
2085
2141
  exportsMtimeMs: fileCache[filePath]?.exportsMtimeMs,
2142
+ unresolvedImports: fileCache[filePath]?.unresolvedImports,
2086
2143
  staticTable: localStaticTable,
2087
2144
  keyframesHashTable: localKeyframesHashTable,
2088
2145
  keyframesObjectTable: localKeyframesObjectTable,
@@ -2150,6 +2207,7 @@ function extractAndCacheExports(filePath, ast, mtimeMs) {
2150
2207
  const reExports = {};
2151
2208
  const starExports = [];
2152
2209
  const localDependencies = new Set();
2210
+ const unresolvedImports = [];
2153
2211
  const imports = {};
2154
2212
  for (const node of ast.body) {
2155
2213
  if (node.type === 'ImportDeclaration') {
@@ -2174,6 +2232,9 @@ function extractAndCacheExports(filePath, ast, mtimeMs) {
2174
2232
  if (actualPath) {
2175
2233
  localDependencies.add(actualPath);
2176
2234
  }
2235
+ else if (node.source.value !== '@plumeria/core') {
2236
+ unresolvedImports.push(node.source.value);
2237
+ }
2177
2238
  }
2178
2239
  else if (node.type === 'ExportDeclaration') {
2179
2240
  const decl = node.declaration;
@@ -2202,6 +2263,9 @@ function extractAndCacheExports(filePath, ast, mtimeMs) {
2202
2263
  if (actualPath) {
2203
2264
  localDependencies.add(actualPath);
2204
2265
  }
2266
+ else if (source !== '@plumeria/core') {
2267
+ unresolvedImports.push(source);
2268
+ }
2205
2269
  }
2206
2270
  node.specifiers.forEach((spec) => {
2207
2271
  if (spec.type === 'ExportSpecifier') {
@@ -2232,6 +2296,9 @@ function extractAndCacheExports(filePath, ast, mtimeMs) {
2232
2296
  if (actualPath) {
2233
2297
  localDependencies.add(actualPath);
2234
2298
  }
2299
+ else if (node.source.value !== '@plumeria/core') {
2300
+ unresolvedImports.push(node.source.value);
2301
+ }
2235
2302
  }
2236
2303
  }
2237
2304
  else if (node.type === 'ExportDefaultExpression') {
@@ -2271,6 +2338,7 @@ function extractAndCacheExports(filePath, ast, mtimeMs) {
2271
2338
  mtimeMs: mtimeMs,
2272
2339
  exports: { localExports, reExports, starExports, imports },
2273
2340
  dependencies: newDeps,
2341
+ unresolvedImports,
2274
2342
  staticTable: {},
2275
2343
  keyframesHashTable: {},
2276
2344
  keyframesObjectTable: {},
@@ -2295,6 +2363,7 @@ function extractAndCacheExports(filePath, ast, mtimeMs) {
2295
2363
  imports,
2296
2364
  };
2297
2365
  fileCache[filePath].dependencies = newDeps;
2366
+ fileCache[filePath].unresolvedImports = unresolvedImports;
2298
2367
  }
2299
2368
  fileCache[filePath].exportsMtimeMs = mtimeMs;
2300
2369
  }
@@ -2305,7 +2374,7 @@ function resolveExport(filePath, exportName, visited = new Set()) {
2305
2374
  visited.add(key);
2306
2375
  {
2307
2376
  try {
2308
- const stats = fs.statSync(filePath);
2377
+ const stats = statFile(filePath);
2309
2378
  if ((!fileCache[filePath]?.exports ||
2310
2379
  fileCache[filePath].exportsMtimeMs !== stats.mtimeMs) &&
2311
2380
  stats.isFile()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/utils",
3
- "version": "19.2.7",
3
+ "version": "19.2.9",
4
4
  "description": "Plumeria Utils",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",