@maverickcer/env-cap 0.7.0 → 0.7.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/dist/build.js CHANGED
@@ -1,13 +1,14 @@
1
- import path6 from 'path';
1
+ import path from 'path';
2
2
  import crypto from 'crypto';
3
3
  import { createRequire } from 'module';
4
4
 
5
5
  // src/build/evidence-snapshot.ts
6
6
  function displayPath(root, filePath) {
7
- if (!path6.isAbsolute(filePath)) return filePath.split(path6.sep).join("/");
8
- const relative = path6.relative(root, filePath);
9
- if (relative.startsWith("..") || path6.isAbsolute(relative)) return filePath;
10
- return relative.split(path6.sep).join("/");
7
+ if (!path.isAbsolute(filePath)) return filePath.split(path.sep).join("/");
8
+ const relative = path.relative(root, filePath);
9
+ if (relative === ".." || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative))
10
+ return filePath;
11
+ return relative.split(path.sep).join("/");
11
12
  }
12
13
 
13
14
  // src/build/source-position.ts
@@ -67,7 +68,7 @@ async function buildCitationSnapshots(activeContracts, previous, root, readFile)
67
68
  let acknowledgment;
68
69
  let contentHash;
69
70
  try {
70
- const content = await readFile(path6.resolve(root, position.file));
71
+ const content = await readFile(path.resolve(root, position.file));
71
72
  contentHash = hashContent(content);
72
73
  const baseline = previousBaselines.get(
73
74
  `${identity}#${position.file}:${position.line}:${position.column}`
@@ -261,7 +262,7 @@ async function readEvidenceSnapshot(snapshotPath, fs) {
261
262
  return { status: "ok", snapshot: parsed };
262
263
  }
263
264
  async function writeEvidenceSnapshot(snapshotPath, snapshot, fs) {
264
- await fs.mkdir(path6.dirname(snapshotPath), { recursive: true });
265
+ await fs.mkdir(path.dirname(snapshotPath), { recursive: true });
265
266
  await fs.writeFile(snapshotPath, `${JSON.stringify(snapshot, null, 2)}
266
267
  `, "utf8");
267
268
  }
@@ -366,24 +367,27 @@ function isAlwaysSkippedDirName(name) {
366
367
  return name === "node_modules" || name === ".git";
367
368
  }
368
369
  var MAX_DISCOVERED_SCHEMA_FILES = 1e3;
369
- async function discoverSchemaFiles(options) {
370
+ async function discoverFiles(options) {
370
371
  const files = await walkDirectory(options.root, options.root, options.exclude, options.fs);
371
- const included = files.filter((file) => {
372
+ return files.filter((file) => {
372
373
  const relativePath = toPosixRelative(options.root, file);
373
374
  return matchesAnyPattern(relativePath, options.include) && !matchesAnyPattern(relativePath, options.exclude);
374
- });
375
+ }).map((file) => path.normalize(file)).sort();
376
+ }
377
+ async function discoverSchemaFiles(options) {
378
+ const included = await discoverFiles(options);
375
379
  if (included.length > MAX_DISCOVERED_SCHEMA_FILES) {
376
380
  throw new Error(
377
381
  `discoverSchemaFiles: found ${String(included.length)} files matching "include" under ${options.root} -- more than the ${String(MAX_DISCOVERED_SCHEMA_FILES)}-file sanity limit. This almost always means "root" (or "include"/"exclude") resolved more broadly than intended -- e.g. an omitted "root" falling back to an unexpectedly large process.cwd() -- rather than a real project genuinely declaring this many contracts. Narrow "root"/"include"/"exclude" to the intended project boundary.`
378
382
  );
379
383
  }
380
- return included.map((file) => path6.normalize(file)).sort();
384
+ return included;
381
385
  }
382
386
  async function walkDirectory(directory, root, exclude, fs) {
383
387
  const entries = await fs.readdir(directory, { withFileTypes: true });
384
388
  const results = [];
385
389
  for (const entry of entries) {
386
- const fullPath = path6.join(directory, entry.name);
390
+ const fullPath = path.join(directory, entry.name);
387
391
  if (entry.isDirectory()) {
388
392
  if (isAlwaysSkippedDirName(entry.name)) continue;
389
393
  const relativeDir = `${toPosixRelative(root, fullPath)}/`;
@@ -398,7 +402,7 @@ async function walkDirectory(directory, root, exclude, fs) {
398
402
  return results;
399
403
  }
400
404
  function toPosixRelative(root, target) {
401
- return path6.relative(root, target).split(path6.sep).join("/");
405
+ return path.relative(root, target).split(path.sep).join("/");
402
406
  }
403
407
  function matchesAnyPattern(filePath, patterns) {
404
408
  return patterns.some((pattern) => globToRegExp(pattern).test(filePath));
@@ -1099,11 +1103,11 @@ function donatedTo(variable) {
1099
1103
  return DONATED.get(variable) ?? /* @__PURE__ */ new Set();
1100
1104
  }
1101
1105
  function isWithinDirectory(baseDir, targetPath) {
1102
- const relative = path6.relative(baseDir, targetPath);
1103
- return relative !== ".." && !relative.startsWith(`..${path6.sep}`) && !path6.isAbsolute(relative);
1106
+ const relative = path.relative(baseDir, targetPath);
1107
+ return relative !== ".." && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);
1104
1108
  }
1105
1109
  function resolveWithinRoot(root, location, optionName, functionName) {
1106
- const resolved = path6.resolve(root, location);
1110
+ const resolved = path.resolve(root, location);
1107
1111
  if (!isWithinDirectory(root, resolved)) {
1108
1112
  return {
1109
1113
  ok: false,
@@ -1126,10 +1130,10 @@ function isRecord2(value) {
1126
1130
  return typeof value === "object" && value !== null;
1127
1131
  }
1128
1132
  async function locatePackageManifest(packageName, root, fs) {
1129
- const req = createRequire(path6.join(root, "package.json"));
1133
+ const req = createRequire(path.join(root, "package.json"));
1130
1134
  try {
1131
1135
  const packageJsonPath = req.resolve(`${packageName}/package.json`);
1132
- return { packageJsonPath, packageDir: path6.dirname(packageJsonPath) };
1136
+ return { packageJsonPath, packageDir: path.dirname(packageJsonPath) };
1133
1137
  } catch {
1134
1138
  }
1135
1139
  let mainFile;
@@ -1138,9 +1142,9 @@ async function locatePackageManifest(packageName, root, fs) {
1138
1142
  } catch {
1139
1143
  return void 0;
1140
1144
  }
1141
- let dir = path6.dirname(mainFile);
1145
+ let dir = path.dirname(mainFile);
1142
1146
  for (let i = 0; i < PACKAGE_JSON_ANCESTOR_SEARCH_LIMIT; i++) {
1143
- const candidate = path6.join(dir, "package.json");
1147
+ const candidate = path.join(dir, "package.json");
1144
1148
  try {
1145
1149
  const parsed = JSON.parse(await fs.readFile(candidate, "utf8"));
1146
1150
  if (isRecord2(parsed) && parsed["name"] === packageName) {
@@ -1148,7 +1152,7 @@ async function locatePackageManifest(packageName, root, fs) {
1148
1152
  }
1149
1153
  } catch {
1150
1154
  }
1151
- const parent = path6.dirname(dir);
1155
+ const parent = path.dirname(dir);
1152
1156
  if (parent === dir) break;
1153
1157
  dir = parent;
1154
1158
  }
@@ -1190,7 +1194,7 @@ async function resolveUncached(packageName, root, fs) {
1190
1194
  reason: `"${packageName}"'s package.json has no "envCap.schema" field (or it is not a string).`
1191
1195
  };
1192
1196
  }
1193
- const lexicallyResolved = path6.resolve(packageDir, declaredField);
1197
+ const lexicallyResolved = path.resolve(packageDir, declaredField);
1194
1198
  if (!isWithinDirectory(packageDir, lexicallyResolved)) {
1195
1199
  return {
1196
1200
  ok: false,
@@ -1333,7 +1337,7 @@ function typescriptPath(file, separator) {
1333
1337
  async function loadTsconfigPaths(product, root, tsconfigOption, fs) {
1334
1338
  if (tsconfigOption === false) return { resolution: void 0, warning: void 0 };
1335
1339
  const isExplicit = tsconfigOption !== void 0;
1336
- const configFile = path6.resolve(root, tsconfigOption ?? "tsconfig.json");
1340
+ const configFile = path.resolve(root, tsconfigOption ?? "tsconfig.json");
1337
1341
  if (!await fileExists(configFile, fs)) {
1338
1342
  if (!isExplicit) return { resolution: void 0, warning: void 0 };
1339
1343
  return {
@@ -1345,10 +1349,19 @@ async function loadTsconfigPaths(product, root, tsconfigOption, fs) {
1345
1349
  };
1346
1350
  }
1347
1351
  assertCompilerApi(product, ts);
1348
- const readResult = ts.readConfigFile(
1349
- typescriptPath(configFile, path6.sep),
1350
- (p) => ts.sys.readFile(p)
1351
- );
1352
+ let text;
1353
+ try {
1354
+ text = await fs.readFile(configFile, "utf8");
1355
+ } catch (error) {
1356
+ return {
1357
+ resolution: void 0,
1358
+ warning: {
1359
+ file: configFile,
1360
+ message: `Could not read "${configFile}": ${error.message}`
1361
+ }
1362
+ };
1363
+ }
1364
+ const readResult = ts.parseConfigFileTextToJson(typescriptPath(configFile, path.sep), text);
1352
1365
  if (readResult.error) {
1353
1366
  const detail = ts.flattenDiagnosticMessageText(readResult.error.messageText, ts.sys.newLine);
1354
1367
  return {
@@ -1359,13 +1372,20 @@ async function loadTsconfigPaths(product, root, tsconfigOption, fs) {
1359
1372
  }
1360
1373
  };
1361
1374
  }
1362
- const parsed = ts.parseJsonConfigFileContent(readResult.config, ts.sys, path6.dirname(configFile));
1375
+ const parsed = ts.parseJsonConfigFileContent(readResult.config, ts.sys, path.dirname(configFile));
1376
+ const problems = parsed.errors.filter((diagnostic) => diagnostic.code !== 18003);
1377
+ const warning = problems.length === 0 ? void 0 : {
1378
+ file: configFile,
1379
+ message: `"${configFile}" has problems the compiler reported: ${problems.map(
1380
+ (diagnostic) => ts.flattenDiagnosticMessageText(diagnostic.messageText, ts.sys.newLine)
1381
+ ).join("; ")}`
1382
+ };
1363
1383
  const { paths, baseUrl } = pathMappingOptions(parsed.options);
1364
1384
  const hasPaths = paths !== void 0 && Object.keys(paths).length > 0;
1365
1385
  if (!hasPaths && baseUrl === void 0) {
1366
- return { resolution: void 0, warning: void 0 };
1386
+ return { resolution: void 0, warning };
1367
1387
  }
1368
- return { resolution: { compilerOptions: parsed.options, configFile }, warning: void 0 };
1388
+ return { resolution: { compilerOptions: parsed.options, configFile }, warning };
1369
1389
  }
1370
1390
  function resolveAliasImport(specifier, importingFile, resolution, cache) {
1371
1391
  const cacheKey = `${importingFile}\0${specifier}`;
@@ -1374,8 +1394,8 @@ function resolveAliasImport(specifier, importingFile, resolution, cache) {
1374
1394
  const resolvedFileName = result.resolvedModule?.resolvedFileName;
1375
1395
  let resolved;
1376
1396
  if (resolvedFileName) {
1377
- const normalized = path6.normalize(resolvedFileName);
1378
- const isInNodeModules = normalized.split(path6.sep).includes("node_modules");
1397
+ const normalized = path.normalize(resolvedFileName);
1398
+ const isInNodeModules = normalized.split(path.sep).includes("node_modules");
1379
1399
  const isTsSource = /\.tsx?$/.test(normalized);
1380
1400
  if (!isInNodeModules && isTsSource) resolved = normalized;
1381
1401
  }
@@ -1392,12 +1412,12 @@ function loadTsconfigPaths2(root, tsconfigOption, fs) {
1392
1412
  async function resolveRelativeImport(importingFile, specifier, fs) {
1393
1413
  if (!specifier.startsWith("./") && !specifier.startsWith("../")) return void 0;
1394
1414
  const withoutExt = specifier.replace(/\.(js|jsx|ts|tsx)$/, "");
1395
- const base = path6.resolve(path6.dirname(importingFile), withoutExt);
1415
+ const base = path.resolve(path.dirname(importingFile), withoutExt);
1396
1416
  for (const candidate of [
1397
1417
  `${base}.ts`,
1398
1418
  `${base}.tsx`,
1399
- path6.join(base, "index.ts"),
1400
- path6.join(base, "index.tsx")
1419
+ path.join(base, "index.ts"),
1420
+ path.join(base, "index.tsx")
1401
1421
  ]) {
1402
1422
  if (await fileExists2(candidate, fs)) return candidate;
1403
1423
  }
@@ -1632,7 +1652,7 @@ async function linkFiles(discoveredFiles, readFile, context, packageOrigins = /*
1632
1652
  }
1633
1653
  function summarizeContract(contract, root) {
1634
1654
  return {
1635
- file: path6.relative(root, contract.file),
1655
+ file: path.relative(root, contract.file),
1636
1656
  exportName: contract.exportName,
1637
1657
  contractName: contract.contractName,
1638
1658
  variableCount: contract.variables.length,
@@ -2630,7 +2650,7 @@ function discoverValidationContexts(contracts) {
2630
2650
  }
2631
2651
  function renderManifest(contracts, outputFile) {
2632
2652
  const sorted = [...contracts].sort((a, b) => a.file.localeCompare(b.file));
2633
- const outputDir = path6.dirname(outputFile);
2653
+ const outputDir = path.dirname(outputFile);
2634
2654
  const usedNames = /* @__PURE__ */ new Set();
2635
2655
  const importLines = [];
2636
2656
  const referenceNames = [];
@@ -2650,7 +2670,7 @@ function renderManifest(contracts, outputFile) {
2650
2670
  specifier = contract.packageOrigin.packageName;
2651
2671
  } else {
2652
2672
  const withoutExt = contract.file.replace(/\.tsx?$/, "");
2653
- specifier = path6.relative(outputDir, withoutExt).split(path6.sep).join("/");
2673
+ specifier = path.relative(outputDir, withoutExt).split(path.sep).join("/");
2654
2674
  if (!specifier.startsWith(".")) specifier = `./${specifier}`;
2655
2675
  }
2656
2676
  const binding = localName === contract.exportName ? contract.exportName : `${contract.exportName} as ${localName}`;
@@ -2714,11 +2734,11 @@ function computeManifest(root, linkResult, onIncompatibility) {
2714
2734
  }
2715
2735
  async function writeManifest(outputPath, activeContracts, fs) {
2716
2736
  const manifestSource = renderManifest(activeContracts, outputPath);
2717
- await fs.mkdir(path6.dirname(outputPath), { recursive: true });
2737
+ await fs.mkdir(path.dirname(outputPath), { recursive: true });
2718
2738
  await fs.writeFile(outputPath, manifestSource, "utf8");
2719
2739
  }
2720
2740
  async function generateEnvManifest(options) {
2721
- const root = path6.resolve(options.root ?? process.cwd());
2741
+ const root = path.resolve(options.root ?? process.cwd());
2722
2742
  const include = options.include ?? defaultInclude();
2723
2743
  const exclude = options.exclude ?? defaultExclude();
2724
2744
  const locationResult = resolveWithinRoot(
@@ -2902,7 +2922,7 @@ function renderUsageReport(computed) {
2902
2922
 
2903
2923
  // src/build/generate-usage.ts
2904
2924
  async function computeScanSurface(root, exclude, origins, fs) {
2905
- const localScanFiles = await discoverSchemaFiles({
2925
+ const localScanFiles = await discoverFiles({
2906
2926
  fs,
2907
2927
  root,
2908
2928
  include: ["**/*.ts", "**/*.tsx"],
@@ -2914,7 +2934,7 @@ async function computeScanSurface(root, exclude, origins, fs) {
2914
2934
  for (const origin of origins.values()) {
2915
2935
  if (seenPackageDirs.has(origin.packageDir)) continue;
2916
2936
  seenPackageDirs.add(origin.packageDir);
2917
- const packageScanFiles = await discoverSchemaFiles({
2937
+ const packageScanFiles = await discoverFiles({
2918
2938
  fs,
2919
2939
  root: origin.packageDir,
2920
2940
  include: ["**/*.ts", "**/*.tsx"],
@@ -2949,20 +2969,20 @@ async function computeUsage(root, contracts, scanFiles, readFile, context, scann
2949
2969
  };
2950
2970
  const dependencyOwnership = graph.contracts.map((c) => ({
2951
2971
  contractName: c.contractName,
2952
- file: path6.relative(root, c.file),
2972
+ file: path.relative(root, c.file),
2953
2973
  owner: ownerFor(c.file, c.exportName),
2954
2974
  variableCount: c.variables.size,
2955
- consumers: c.consumingFiles.map((f) => path6.relative(root, f))
2975
+ consumers: c.consumingFiles.map((f) => path.relative(root, f))
2956
2976
  }));
2957
2977
  const abandonedContracts = findings.abandoned.map((f) => ({
2958
2978
  contractName: f.contractName,
2959
- file: path6.relative(root, f.file),
2979
+ file: path.relative(root, f.file),
2960
2980
  owner: ownerFor(f.file, f.exportName)
2961
2981
  }));
2962
2982
  const unresolvedConsumers = findings.unresolvedConsumers.map(
2963
2983
  (f) => ({
2964
2984
  contractName: f.contractName,
2965
- file: path6.relative(root, f.file),
2985
+ file: path.relative(root, f.file),
2966
2986
  reason: f.reason
2967
2987
  })
2968
2988
  );
@@ -3029,11 +3049,11 @@ async function computeUsage(root, contracts, scanFiles, readFile, context, scann
3029
3049
  }
3030
3050
  async function writeUsageReport(reportPath, computed, fs) {
3031
3051
  const source = renderUsageReport(computed);
3032
- await fs.mkdir(path6.dirname(reportPath), { recursive: true });
3052
+ await fs.mkdir(path.dirname(reportPath), { recursive: true });
3033
3053
  await fs.writeFile(reportPath, source, "utf8");
3034
3054
  }
3035
3055
  async function generateUsageReport(options) {
3036
- const root = path6.resolve(options.root ?? process.cwd());
3056
+ const root = path.resolve(options.root ?? process.cwd());
3037
3057
  const include = options.include ?? defaultInclude();
3038
3058
  const exclude = options.exclude ?? defaultExclude();
3039
3059
  let reportPath;
@@ -4134,7 +4154,7 @@ async function writeEnvExample(contracts, location, fs, options = {}) {
4134
4154
  }
4135
4155
  if (existingContent === void 0) {
4136
4156
  const content2 = renderEnvExample(contracts, []);
4137
- await fs.mkdir(path6.dirname(location), { recursive: true });
4157
+ await fs.mkdir(path.dirname(location), { recursive: true });
4138
4158
  await fs.writeFile(location, content2, "utf8");
4139
4159
  return {
4140
4160
  writtenPath: location,
@@ -4159,7 +4179,7 @@ async function writeEnvExample(contracts, location, fs, options = {}) {
4159
4179
  const content = renderEnvExample(contracts, headerLines);
4160
4180
  const writtenPath = onExisting === "overwrite" ? location : `${location}.${Date.now()}`;
4161
4181
  const skippedExistingPath = onExisting === "overwrite" ? void 0 : location;
4162
- await fs.mkdir(path6.dirname(writtenPath), { recursive: true });
4182
+ await fs.mkdir(path.dirname(writtenPath), { recursive: true });
4163
4183
  await fs.writeFile(writtenPath, content, "utf8");
4164
4184
  return { writtenPath, skippedExistingPath, staleVariables, variablesToComment, variablesToAdd };
4165
4185
  }
@@ -4257,7 +4277,7 @@ async function writeDocumentation(docsPath, envExamplePath, root, contracts, con
4257
4277
  generatedAt,
4258
4278
  previousContent
4259
4279
  });
4260
- await fs.mkdir(path6.dirname(docsPath), { recursive: true });
4280
+ await fs.mkdir(path.dirname(docsPath), { recursive: true });
4261
4281
  await fs.writeFile(docsPath, docsSource, "utf8");
4262
4282
  const envExample = envExamplePath ? (
4263
4283
  // `exactOptionalPropertyTypes` rejects an explicit `undefined`, so the key is omitted when unset.
@@ -4271,7 +4291,7 @@ async function writeDocumentation(docsPath, envExamplePath, root, contracts, con
4271
4291
  return { envExample };
4272
4292
  }
4273
4293
  async function generateDocumentation(options) {
4274
- const root = path6.resolve(options.root ?? process.cwd());
4294
+ const root = path.resolve(options.root ?? process.cwd());
4275
4295
  const include = options.include ?? defaultInclude();
4276
4296
  const exclude = options.exclude ?? defaultExclude();
4277
4297
  const expiringWithinDays = options.expiringWithinDays ?? DEFAULT_EXPIRING_WITHIN_DAYS;
@@ -4475,12 +4495,12 @@ function buildOwnershipModel(contracts, root) {
4475
4495
 
4476
4496
  // src/build/tool-version.ts
4477
4497
  function readToolVersion() {
4478
- return "0.7.0";
4498
+ return "0.7.2";
4479
4499
  }
4480
4500
 
4481
4501
  // src/build/generate-evidence.ts
4482
4502
  async function generateEvidenceModel(options) {
4483
- const root = path6.resolve(options.root ?? process.cwd());
4503
+ const root = path.resolve(options.root ?? process.cwd());
4484
4504
  const include = options.include ?? defaultInclude();
4485
4505
  const exclude = options.exclude ?? defaultExclude();
4486
4506
  const expiringWithinDays = options.expiringWithinDays ?? DEFAULT_EXPIRING_WITHIN_DAYS;
@@ -4622,10 +4642,10 @@ async function writeEvidenceFingerprint(evidencePath, fingerprint, fs) {
4622
4642
  `, "utf8");
4623
4643
  }
4624
4644
  async function getEvidenceModel(options) {
4625
- const root = path6.resolve(options.root ?? process.cwd());
4645
+ const root = path.resolve(options.root ?? process.cwd());
4626
4646
  const include = options.include ?? defaultInclude();
4627
4647
  const exclude = options.exclude ?? defaultExclude();
4628
- const evidencePath = path6.resolve(root, options.location);
4648
+ const evidencePath = path.resolve(root, options.location);
4629
4649
  const fingerprintPath = fingerprintPathFor(evidencePath);
4630
4650
  const recompute = async (missReason) => ({
4631
4651
  evidence: await generateEvidenceModel(options),
@@ -4691,7 +4711,7 @@ function requestedPass(option) {
4691
4711
  return option === false ? void 0 : option;
4692
4712
  }
4693
4713
  async function computeArtifacts(options) {
4694
- const root = path6.resolve(options.root ?? process.cwd());
4714
+ const root = path.resolve(options.root ?? process.cwd());
4695
4715
  const include = options.include ?? defaultInclude();
4696
4716
  const exclude = options.exclude ?? defaultExclude();
4697
4717
  const manifestOptions = requestedPass(options.manifest);
@@ -5044,7 +5064,7 @@ function sarifLocations(finding) {
5044
5064
  function buildSarifLog(findingModel) {
5045
5065
  const ruleIds = [...new Set(findingModel.findings.map((f) => f.code))].sort();
5046
5066
  return {
5047
- $schema: "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/main/Schemata/sarif-schema-2.1.0.json",
5067
+ $schema: "https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json",
5048
5068
  version: "2.1.0",
5049
5069
  runs: [
5050
5070
  {