@maverickcer/env-cap 0.7.0 → 0.7.1

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
  }
@@ -377,13 +378,13 @@ async function discoverSchemaFiles(options) {
377
378
  `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
379
  );
379
380
  }
380
- return included.map((file) => path6.normalize(file)).sort();
381
+ return included.map((file) => path.normalize(file)).sort();
381
382
  }
382
383
  async function walkDirectory(directory, root, exclude, fs) {
383
384
  const entries = await fs.readdir(directory, { withFileTypes: true });
384
385
  const results = [];
385
386
  for (const entry of entries) {
386
- const fullPath = path6.join(directory, entry.name);
387
+ const fullPath = path.join(directory, entry.name);
387
388
  if (entry.isDirectory()) {
388
389
  if (isAlwaysSkippedDirName(entry.name)) continue;
389
390
  const relativeDir = `${toPosixRelative(root, fullPath)}/`;
@@ -398,7 +399,7 @@ async function walkDirectory(directory, root, exclude, fs) {
398
399
  return results;
399
400
  }
400
401
  function toPosixRelative(root, target) {
401
- return path6.relative(root, target).split(path6.sep).join("/");
402
+ return path.relative(root, target).split(path.sep).join("/");
402
403
  }
403
404
  function matchesAnyPattern(filePath, patterns) {
404
405
  return patterns.some((pattern) => globToRegExp(pattern).test(filePath));
@@ -1099,11 +1100,11 @@ function donatedTo(variable) {
1099
1100
  return DONATED.get(variable) ?? /* @__PURE__ */ new Set();
1100
1101
  }
1101
1102
  function isWithinDirectory(baseDir, targetPath) {
1102
- const relative = path6.relative(baseDir, targetPath);
1103
- return relative !== ".." && !relative.startsWith(`..${path6.sep}`) && !path6.isAbsolute(relative);
1103
+ const relative = path.relative(baseDir, targetPath);
1104
+ return relative !== ".." && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);
1104
1105
  }
1105
1106
  function resolveWithinRoot(root, location, optionName, functionName) {
1106
- const resolved = path6.resolve(root, location);
1107
+ const resolved = path.resolve(root, location);
1107
1108
  if (!isWithinDirectory(root, resolved)) {
1108
1109
  return {
1109
1110
  ok: false,
@@ -1126,10 +1127,10 @@ function isRecord2(value) {
1126
1127
  return typeof value === "object" && value !== null;
1127
1128
  }
1128
1129
  async function locatePackageManifest(packageName, root, fs) {
1129
- const req = createRequire(path6.join(root, "package.json"));
1130
+ const req = createRequire(path.join(root, "package.json"));
1130
1131
  try {
1131
1132
  const packageJsonPath = req.resolve(`${packageName}/package.json`);
1132
- return { packageJsonPath, packageDir: path6.dirname(packageJsonPath) };
1133
+ return { packageJsonPath, packageDir: path.dirname(packageJsonPath) };
1133
1134
  } catch {
1134
1135
  }
1135
1136
  let mainFile;
@@ -1138,9 +1139,9 @@ async function locatePackageManifest(packageName, root, fs) {
1138
1139
  } catch {
1139
1140
  return void 0;
1140
1141
  }
1141
- let dir = path6.dirname(mainFile);
1142
+ let dir = path.dirname(mainFile);
1142
1143
  for (let i = 0; i < PACKAGE_JSON_ANCESTOR_SEARCH_LIMIT; i++) {
1143
- const candidate = path6.join(dir, "package.json");
1144
+ const candidate = path.join(dir, "package.json");
1144
1145
  try {
1145
1146
  const parsed = JSON.parse(await fs.readFile(candidate, "utf8"));
1146
1147
  if (isRecord2(parsed) && parsed["name"] === packageName) {
@@ -1148,7 +1149,7 @@ async function locatePackageManifest(packageName, root, fs) {
1148
1149
  }
1149
1150
  } catch {
1150
1151
  }
1151
- const parent = path6.dirname(dir);
1152
+ const parent = path.dirname(dir);
1152
1153
  if (parent === dir) break;
1153
1154
  dir = parent;
1154
1155
  }
@@ -1190,7 +1191,7 @@ async function resolveUncached(packageName, root, fs) {
1190
1191
  reason: `"${packageName}"'s package.json has no "envCap.schema" field (or it is not a string).`
1191
1192
  };
1192
1193
  }
1193
- const lexicallyResolved = path6.resolve(packageDir, declaredField);
1194
+ const lexicallyResolved = path.resolve(packageDir, declaredField);
1194
1195
  if (!isWithinDirectory(packageDir, lexicallyResolved)) {
1195
1196
  return {
1196
1197
  ok: false,
@@ -1333,7 +1334,7 @@ function typescriptPath(file, separator) {
1333
1334
  async function loadTsconfigPaths(product, root, tsconfigOption, fs) {
1334
1335
  if (tsconfigOption === false) return { resolution: void 0, warning: void 0 };
1335
1336
  const isExplicit = tsconfigOption !== void 0;
1336
- const configFile = path6.resolve(root, tsconfigOption ?? "tsconfig.json");
1337
+ const configFile = path.resolve(root, tsconfigOption ?? "tsconfig.json");
1337
1338
  if (!await fileExists(configFile, fs)) {
1338
1339
  if (!isExplicit) return { resolution: void 0, warning: void 0 };
1339
1340
  return {
@@ -1345,10 +1346,19 @@ async function loadTsconfigPaths(product, root, tsconfigOption, fs) {
1345
1346
  };
1346
1347
  }
1347
1348
  assertCompilerApi(product, ts);
1348
- const readResult = ts.readConfigFile(
1349
- typescriptPath(configFile, path6.sep),
1350
- (p) => ts.sys.readFile(p)
1351
- );
1349
+ let text;
1350
+ try {
1351
+ text = await fs.readFile(configFile, "utf8");
1352
+ } catch (error) {
1353
+ return {
1354
+ resolution: void 0,
1355
+ warning: {
1356
+ file: configFile,
1357
+ message: `Could not read "${configFile}": ${error.message}`
1358
+ }
1359
+ };
1360
+ }
1361
+ const readResult = ts.parseConfigFileTextToJson(typescriptPath(configFile, path.sep), text);
1352
1362
  if (readResult.error) {
1353
1363
  const detail = ts.flattenDiagnosticMessageText(readResult.error.messageText, ts.sys.newLine);
1354
1364
  return {
@@ -1359,13 +1369,20 @@ async function loadTsconfigPaths(product, root, tsconfigOption, fs) {
1359
1369
  }
1360
1370
  };
1361
1371
  }
1362
- const parsed = ts.parseJsonConfigFileContent(readResult.config, ts.sys, path6.dirname(configFile));
1372
+ const parsed = ts.parseJsonConfigFileContent(readResult.config, ts.sys, path.dirname(configFile));
1373
+ const problems = parsed.errors.filter((diagnostic) => diagnostic.code !== 18003);
1374
+ const warning = problems.length === 0 ? void 0 : {
1375
+ file: configFile,
1376
+ message: `"${configFile}" has problems the compiler reported: ${problems.map(
1377
+ (diagnostic) => ts.flattenDiagnosticMessageText(diagnostic.messageText, ts.sys.newLine)
1378
+ ).join("; ")}`
1379
+ };
1363
1380
  const { paths, baseUrl } = pathMappingOptions(parsed.options);
1364
1381
  const hasPaths = paths !== void 0 && Object.keys(paths).length > 0;
1365
1382
  if (!hasPaths && baseUrl === void 0) {
1366
- return { resolution: void 0, warning: void 0 };
1383
+ return { resolution: void 0, warning };
1367
1384
  }
1368
- return { resolution: { compilerOptions: parsed.options, configFile }, warning: void 0 };
1385
+ return { resolution: { compilerOptions: parsed.options, configFile }, warning };
1369
1386
  }
1370
1387
  function resolveAliasImport(specifier, importingFile, resolution, cache) {
1371
1388
  const cacheKey = `${importingFile}\0${specifier}`;
@@ -1374,8 +1391,8 @@ function resolveAliasImport(specifier, importingFile, resolution, cache) {
1374
1391
  const resolvedFileName = result.resolvedModule?.resolvedFileName;
1375
1392
  let resolved;
1376
1393
  if (resolvedFileName) {
1377
- const normalized = path6.normalize(resolvedFileName);
1378
- const isInNodeModules = normalized.split(path6.sep).includes("node_modules");
1394
+ const normalized = path.normalize(resolvedFileName);
1395
+ const isInNodeModules = normalized.split(path.sep).includes("node_modules");
1379
1396
  const isTsSource = /\.tsx?$/.test(normalized);
1380
1397
  if (!isInNodeModules && isTsSource) resolved = normalized;
1381
1398
  }
@@ -1392,12 +1409,12 @@ function loadTsconfigPaths2(root, tsconfigOption, fs) {
1392
1409
  async function resolveRelativeImport(importingFile, specifier, fs) {
1393
1410
  if (!specifier.startsWith("./") && !specifier.startsWith("../")) return void 0;
1394
1411
  const withoutExt = specifier.replace(/\.(js|jsx|ts|tsx)$/, "");
1395
- const base = path6.resolve(path6.dirname(importingFile), withoutExt);
1412
+ const base = path.resolve(path.dirname(importingFile), withoutExt);
1396
1413
  for (const candidate of [
1397
1414
  `${base}.ts`,
1398
1415
  `${base}.tsx`,
1399
- path6.join(base, "index.ts"),
1400
- path6.join(base, "index.tsx")
1416
+ path.join(base, "index.ts"),
1417
+ path.join(base, "index.tsx")
1401
1418
  ]) {
1402
1419
  if (await fileExists2(candidate, fs)) return candidate;
1403
1420
  }
@@ -1632,7 +1649,7 @@ async function linkFiles(discoveredFiles, readFile, context, packageOrigins = /*
1632
1649
  }
1633
1650
  function summarizeContract(contract, root) {
1634
1651
  return {
1635
- file: path6.relative(root, contract.file),
1652
+ file: path.relative(root, contract.file),
1636
1653
  exportName: contract.exportName,
1637
1654
  contractName: contract.contractName,
1638
1655
  variableCount: contract.variables.length,
@@ -2630,7 +2647,7 @@ function discoverValidationContexts(contracts) {
2630
2647
  }
2631
2648
  function renderManifest(contracts, outputFile) {
2632
2649
  const sorted = [...contracts].sort((a, b) => a.file.localeCompare(b.file));
2633
- const outputDir = path6.dirname(outputFile);
2650
+ const outputDir = path.dirname(outputFile);
2634
2651
  const usedNames = /* @__PURE__ */ new Set();
2635
2652
  const importLines = [];
2636
2653
  const referenceNames = [];
@@ -2650,7 +2667,7 @@ function renderManifest(contracts, outputFile) {
2650
2667
  specifier = contract.packageOrigin.packageName;
2651
2668
  } else {
2652
2669
  const withoutExt = contract.file.replace(/\.tsx?$/, "");
2653
- specifier = path6.relative(outputDir, withoutExt).split(path6.sep).join("/");
2670
+ specifier = path.relative(outputDir, withoutExt).split(path.sep).join("/");
2654
2671
  if (!specifier.startsWith(".")) specifier = `./${specifier}`;
2655
2672
  }
2656
2673
  const binding = localName === contract.exportName ? contract.exportName : `${contract.exportName} as ${localName}`;
@@ -2714,11 +2731,11 @@ function computeManifest(root, linkResult, onIncompatibility) {
2714
2731
  }
2715
2732
  async function writeManifest(outputPath, activeContracts, fs) {
2716
2733
  const manifestSource = renderManifest(activeContracts, outputPath);
2717
- await fs.mkdir(path6.dirname(outputPath), { recursive: true });
2734
+ await fs.mkdir(path.dirname(outputPath), { recursive: true });
2718
2735
  await fs.writeFile(outputPath, manifestSource, "utf8");
2719
2736
  }
2720
2737
  async function generateEnvManifest(options) {
2721
- const root = path6.resolve(options.root ?? process.cwd());
2738
+ const root = path.resolve(options.root ?? process.cwd());
2722
2739
  const include = options.include ?? defaultInclude();
2723
2740
  const exclude = options.exclude ?? defaultExclude();
2724
2741
  const locationResult = resolveWithinRoot(
@@ -2949,20 +2966,20 @@ async function computeUsage(root, contracts, scanFiles, readFile, context, scann
2949
2966
  };
2950
2967
  const dependencyOwnership = graph.contracts.map((c) => ({
2951
2968
  contractName: c.contractName,
2952
- file: path6.relative(root, c.file),
2969
+ file: path.relative(root, c.file),
2953
2970
  owner: ownerFor(c.file, c.exportName),
2954
2971
  variableCount: c.variables.size,
2955
- consumers: c.consumingFiles.map((f) => path6.relative(root, f))
2972
+ consumers: c.consumingFiles.map((f) => path.relative(root, f))
2956
2973
  }));
2957
2974
  const abandonedContracts = findings.abandoned.map((f) => ({
2958
2975
  contractName: f.contractName,
2959
- file: path6.relative(root, f.file),
2976
+ file: path.relative(root, f.file),
2960
2977
  owner: ownerFor(f.file, f.exportName)
2961
2978
  }));
2962
2979
  const unresolvedConsumers = findings.unresolvedConsumers.map(
2963
2980
  (f) => ({
2964
2981
  contractName: f.contractName,
2965
- file: path6.relative(root, f.file),
2982
+ file: path.relative(root, f.file),
2966
2983
  reason: f.reason
2967
2984
  })
2968
2985
  );
@@ -3029,11 +3046,11 @@ async function computeUsage(root, contracts, scanFiles, readFile, context, scann
3029
3046
  }
3030
3047
  async function writeUsageReport(reportPath, computed, fs) {
3031
3048
  const source = renderUsageReport(computed);
3032
- await fs.mkdir(path6.dirname(reportPath), { recursive: true });
3049
+ await fs.mkdir(path.dirname(reportPath), { recursive: true });
3033
3050
  await fs.writeFile(reportPath, source, "utf8");
3034
3051
  }
3035
3052
  async function generateUsageReport(options) {
3036
- const root = path6.resolve(options.root ?? process.cwd());
3053
+ const root = path.resolve(options.root ?? process.cwd());
3037
3054
  const include = options.include ?? defaultInclude();
3038
3055
  const exclude = options.exclude ?? defaultExclude();
3039
3056
  let reportPath;
@@ -4134,7 +4151,7 @@ async function writeEnvExample(contracts, location, fs, options = {}) {
4134
4151
  }
4135
4152
  if (existingContent === void 0) {
4136
4153
  const content2 = renderEnvExample(contracts, []);
4137
- await fs.mkdir(path6.dirname(location), { recursive: true });
4154
+ await fs.mkdir(path.dirname(location), { recursive: true });
4138
4155
  await fs.writeFile(location, content2, "utf8");
4139
4156
  return {
4140
4157
  writtenPath: location,
@@ -4159,7 +4176,7 @@ async function writeEnvExample(contracts, location, fs, options = {}) {
4159
4176
  const content = renderEnvExample(contracts, headerLines);
4160
4177
  const writtenPath = onExisting === "overwrite" ? location : `${location}.${Date.now()}`;
4161
4178
  const skippedExistingPath = onExisting === "overwrite" ? void 0 : location;
4162
- await fs.mkdir(path6.dirname(writtenPath), { recursive: true });
4179
+ await fs.mkdir(path.dirname(writtenPath), { recursive: true });
4163
4180
  await fs.writeFile(writtenPath, content, "utf8");
4164
4181
  return { writtenPath, skippedExistingPath, staleVariables, variablesToComment, variablesToAdd };
4165
4182
  }
@@ -4257,7 +4274,7 @@ async function writeDocumentation(docsPath, envExamplePath, root, contracts, con
4257
4274
  generatedAt,
4258
4275
  previousContent
4259
4276
  });
4260
- await fs.mkdir(path6.dirname(docsPath), { recursive: true });
4277
+ await fs.mkdir(path.dirname(docsPath), { recursive: true });
4261
4278
  await fs.writeFile(docsPath, docsSource, "utf8");
4262
4279
  const envExample = envExamplePath ? (
4263
4280
  // `exactOptionalPropertyTypes` rejects an explicit `undefined`, so the key is omitted when unset.
@@ -4271,7 +4288,7 @@ async function writeDocumentation(docsPath, envExamplePath, root, contracts, con
4271
4288
  return { envExample };
4272
4289
  }
4273
4290
  async function generateDocumentation(options) {
4274
- const root = path6.resolve(options.root ?? process.cwd());
4291
+ const root = path.resolve(options.root ?? process.cwd());
4275
4292
  const include = options.include ?? defaultInclude();
4276
4293
  const exclude = options.exclude ?? defaultExclude();
4277
4294
  const expiringWithinDays = options.expiringWithinDays ?? DEFAULT_EXPIRING_WITHIN_DAYS;
@@ -4475,12 +4492,12 @@ function buildOwnershipModel(contracts, root) {
4475
4492
 
4476
4493
  // src/build/tool-version.ts
4477
4494
  function readToolVersion() {
4478
- return "0.7.0";
4495
+ return "0.7.1";
4479
4496
  }
4480
4497
 
4481
4498
  // src/build/generate-evidence.ts
4482
4499
  async function generateEvidenceModel(options) {
4483
- const root = path6.resolve(options.root ?? process.cwd());
4500
+ const root = path.resolve(options.root ?? process.cwd());
4484
4501
  const include = options.include ?? defaultInclude();
4485
4502
  const exclude = options.exclude ?? defaultExclude();
4486
4503
  const expiringWithinDays = options.expiringWithinDays ?? DEFAULT_EXPIRING_WITHIN_DAYS;
@@ -4622,10 +4639,10 @@ async function writeEvidenceFingerprint(evidencePath, fingerprint, fs) {
4622
4639
  `, "utf8");
4623
4640
  }
4624
4641
  async function getEvidenceModel(options) {
4625
- const root = path6.resolve(options.root ?? process.cwd());
4642
+ const root = path.resolve(options.root ?? process.cwd());
4626
4643
  const include = options.include ?? defaultInclude();
4627
4644
  const exclude = options.exclude ?? defaultExclude();
4628
- const evidencePath = path6.resolve(root, options.location);
4645
+ const evidencePath = path.resolve(root, options.location);
4629
4646
  const fingerprintPath = fingerprintPathFor(evidencePath);
4630
4647
  const recompute = async (missReason) => ({
4631
4648
  evidence: await generateEvidenceModel(options),
@@ -4691,7 +4708,7 @@ function requestedPass(option) {
4691
4708
  return option === false ? void 0 : option;
4692
4709
  }
4693
4710
  async function computeArtifacts(options) {
4694
- const root = path6.resolve(options.root ?? process.cwd());
4711
+ const root = path.resolve(options.root ?? process.cwd());
4695
4712
  const include = options.include ?? defaultInclude();
4696
4713
  const exclude = options.exclude ?? defaultExclude();
4697
4714
  const manifestOptions = requestedPass(options.manifest);
@@ -5044,7 +5061,7 @@ function sarifLocations(finding) {
5044
5061
  function buildSarifLog(findingModel) {
5045
5062
  const ruleIds = [...new Set(findingModel.findings.map((f) => f.code))].sort();
5046
5063
  return {
5047
- $schema: "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/main/Schemata/sarif-schema-2.1.0.json",
5064
+ $schema: "https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json",
5048
5065
  version: "2.1.0",
5049
5066
  runs: [
5050
5067
  {