toolcrib 0.11.1 → 0.11.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toolcrib",
3
- "version": "0.11.1",
3
+ "version": "0.11.2",
4
4
  "description": "Bootstrap the toolcrib UI toolkit into your project",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -80,6 +80,23 @@ async function postExport(options) {
80
80
  .filter((d) => d.isDirectory())
81
81
  .map((d) => d.name)
82
82
  .sort();
83
+ // The README was written at export time; the user may have deleted folders since.
84
+ const readmePath = path.join(outDir, 'README.md');
85
+ if (fs.existsSync(readmePath)) {
86
+ const listed = new Set();
87
+ for (const line of fs.readFileSync(readmePath, 'utf8').split(/\r?\n/)) {
88
+ const m = /^\|\s*(\d+-[^\s|]+)\s*\|/.exec(line);
89
+ if (m) listed.add(m[1]);
90
+ }
91
+ const missing = [...listed].filter((f) => !folders.includes(f)).sort();
92
+ const unlisted = folders.filter((f) => !listed.has(f));
93
+ if (missing.length) {
94
+ p.log.warn(`README.md lists contribution(s) whose folder is missing (not posted): ${missing.join(', ')}`);
95
+ }
96
+ if (unlisted.length) {
97
+ p.log.warn(`Folder(s) present but not listed in README.md: ${unlisted.join(', ')}`);
98
+ }
99
+ }
83
100
  const plans = [];
84
101
  for (const folder of folders) {
85
102
  const dir = path.join(outDir, folder);
package/src/index.js CHANGED
File without changes
@@ -177,6 +177,8 @@ export function renderReadme({ baseVersion, entries, notExported, regeneratedUps
177
177
  '',
178
178
  "Fill in each contribution's `intent:` lines in its SUMMARY.md before posting.",
179
179
  '',
180
+ 'This README describes the export as generated. If you delete a contribution folder you do not want to send, this file is not updated; `--post` sends only the folders still present.',
181
+ '',
180
182
  '## Contributions',
181
183
  '',
182
184
  ];
@@ -30,6 +30,38 @@ export const VALID_CATEGORIES = ['Layout Primitives', 'Containers', 'Overlays',
30
30
 
31
31
  const INFRA_DIRS = ['theme', 'eventBus', 'observer'];
32
32
  const CODE_FILE = /\.[cm]?[jt]sx?$/;
33
+
34
+ const escapeRegExp = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
35
+
36
+ /**
37
+ * The binding names imported from `specifier` across every import/export
38
+ * statement naming it: default, named (by their exported name), `*`, and
39
+ * `side-effect` for a bare `import 'x'` or a dynamic import. Whitespace and
40
+ * order don't matter, so reformatting an import line changes nothing.
41
+ */
42
+ function importedNames(source, specifier) {
43
+ const code = stripComments(source);
44
+ const q = `['"]${escapeRegExp(specifier)}['"]`;
45
+ const names = new Set();
46
+ const re = new RegExp(`\\b(?:import|export)\\s+(?:type\\s+)?([^'";]*?)\\s*from\\s*${q}`, 'g');
47
+ let m;
48
+ while ((m = re.exec(code))) {
49
+ const clause = m[1];
50
+ const braces = /\{([^}]*)\}/.exec(clause);
51
+ if (braces) {
52
+ for (const part of braces[1].split(',')) {
53
+ const name = part.trim().replace(/^type\s+/, '').split(/\s+as\s+/)[0].trim();
54
+ if (name) names.add(name);
55
+ }
56
+ }
57
+ const outside = clause.replace(/\{[^}]*\}/, '');
58
+ if (/\*/.test(outside)) names.add('*');
59
+ const def = outside.replace(/\*(\s*as\s+\w+)?/, '').replace(/,/g, ' ').trim();
60
+ if (def) names.add('default');
61
+ }
62
+ if (new RegExp(`\\bimport\\s*(?:\\(\\s*)?${q}`).test(code)) names.add('side-effect');
63
+ return names;
64
+ }
33
65
  const MANIFEST_BLOCK_RE = /\/\*\*((?:(?!\*\/)[\s\S])*)\*\/\s*export\s+(?:const|function)\s+(\w+)/g;
34
66
  const EXPORT_DECL_RE = /\bexport\s+(?:declare\s+)?(?:abstract\s+)?(?:const|let|var|function|class|interface|type|enum)\s+(\w+)/g;
35
67
  /** Raw React prop types that carry style/className, as an extends, intersection or alias. */
@@ -265,6 +297,31 @@ export function analyzeExport({ releaseFiles, localFiles }) {
265
297
  const isInfraCandidate = (p) => changed.has(p) && INFRA_DIRS.includes(topSegment(p)) && !unitOf.has(p);
266
298
  const reachedBy = new Map(); // candidate relPath -> Set(unit key)
267
299
  const reachedPerUnit = new Map();
300
+ const dependencyPerUnit = new Map();
301
+ const relHas = (p) => rel.has(p);
302
+ // Resolved import target -> the names imported from it (see importedNames).
303
+ const resolvedImports = (content, relPath, exists) => {
304
+ const out = new Map();
305
+ if (content === undefined || !CODE_FILE.test(relPath)) return out;
306
+ for (const spec of extractImports(content)) {
307
+ const resolved = resolveRelativeImport(relPath, spec, exists);
308
+ if (!resolved) continue;
309
+ if (!out.has(resolved)) out.set(resolved, new Set());
310
+ for (const n of importedNames(content, spec)) out.get(resolved).add(n);
311
+ }
312
+ return out;
313
+ };
314
+ // Import targets the unit's own change introduced: a target the release
315
+ // version didn't import, or one it now imports a name from that it didn't
316
+ // before (a new export used through an import line that already existed).
317
+ // An added file counts all its imports; a deleted file contributes none.
318
+ const newImportTargets = (relPath) => {
319
+ const before = resolvedImports(rel.get(relPath), relPath, relHas);
320
+ const after = resolvedImports(loc.get(relPath), relPath, localHas);
321
+ return [...after]
322
+ .filter(([t, names]) => !before.has(t) || [...names].some((n) => !before.get(t).has(n)))
323
+ .map(([t]) => t);
324
+ };
268
325
  for (const [key, unit] of units) {
269
326
  const seen = new Set(unit.paths);
270
327
  const stack = [...unit.paths];
@@ -286,6 +343,22 @@ export function analyzeExport({ releaseFiles, localFiles }) {
286
343
  }
287
344
  }
288
345
  reachedPerUnit.set(key, reached);
346
+ // Dependency, as opposed to reachability: only what the unit's own change newly imports.
347
+ const dependencySeen = new Set(unit.paths);
348
+ const dependencyStack = [];
349
+ for (const f of unit.paths) dependencyStack.push(...newImportTargets(f));
350
+ const dependsOnFiles = new Set();
351
+ while (dependencyStack.length) {
352
+ const d = dependencyStack.pop();
353
+ if (dependencySeen.has(d)) continue;
354
+ dependencySeen.add(d);
355
+ if (SHARED_FILES.includes(d)) continue;
356
+ const owner = unitOf.get(d);
357
+ if (owner !== undefined && owner !== key) continue; // another unit's own files
358
+ if (isInfraCandidate(d)) dependsOnFiles.add(d);
359
+ for (const n of deps(d)) dependencyStack.push(n);
360
+ }
361
+ dependencyPerUnit.set(key, dependsOnFiles);
289
362
  unit.missingDependencies = [...missing].sort();
290
363
  for (const d of reached) {
291
364
  if (!reachedBy.has(d)) reachedBy.set(d, new Set());
@@ -335,7 +408,7 @@ export function analyzeExport({ releaseFiles, localFiles }) {
335
408
  infra.sort((a, b) => a.name.localeCompare(b.name));
336
409
  for (const [key, unit] of units) {
337
410
  const names = new Set();
338
- for (const d of reachedPerUnit.get(key)) {
411
+ for (const d of dependencyPerUnit.get(key)) {
339
412
  if (infraOfFile.has(d)) names.add(infraOfFile.get(d).name);
340
413
  }
341
414
  unit.dependsOn = [...names].sort();