Skip to content

Commit

Permalink
add dependency info
Browse files Browse the repository at this point in the history
  • Loading branch information
seemk committed Jan 19, 2024
1 parent c5bb8ae commit 29882b6
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ jobs:
fetch-depth: 1
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
- name: Install npm dependencies
run: npm ci
- name: Build
Expand Down
65 changes: 63 additions & 2 deletions scripts/generate-metadata-yaml.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { join } = require("path");
const { readFile } = require("node:fs/promises");
const { join, dirname } = require("path");
const { access, readFile, constants } = require("node:fs/promises");

const { getInstrumentations } = require('../lib/instrumentations');

Expand Down Expand Up @@ -277,6 +277,66 @@ function populateResourceDetectors(writer) {
writer.push("support: supported");
writer.popIndent();
}

writer.popIndent();
}

async function findPackageJson(packageName, maxDepth) {
if (maxDepth === undefined) {
maxDepth = 3;
}

let basepath = dirname(require.resolve(packageName));
for (let i = 0; i < maxDepth; i++) {
const packageJsonPath = join(basepath, "package.json");
try {
await access(packageJsonPath, constants.F_OK);
return packageJsonPath;
} catch (e) {
basepath = join(basepath, "..");
}
}

return undefined;
}

function isExperimental(dependency, version) {
return dependency.startsWith("@opentelemetry") && version.startsWith("0");
}

async function populateDependencyInfo(dependency, version, writer) {
const status = isExperimental(dependency, version) ? "experimental" : "stable";

const pkgJsonPath = await findPackageJson(dependency);

let url = undefined;

if (pkgJsonPath) {
const pkgJson = JSON.parse(await readFile(pkgJsonPath, { encoding: "utf-8" }));
url = pkgJson.homepage;
}

writer.push(`- name: "${dependency}"`);
writer.pushIndent(2);
writer.push(`version: "${version}"`);
writer.push(`stability: ${status}`);

if (url) {
writer.push(`source_href: "${url}"`);
}

writer.popIndent();
}

async function populateDependencies(writer) {
const deps = require(join(__dirname, "../package.json")).dependencies;
writer.push("dependencies:")
writer.pushIndent(2);

const promises = Object.keys(deps).map(dep => populateDependencyInfo(dep, deps[dep], writer));
await Promise.all(promises);

writer.popIndent();
}

async function genMetadata() {
Expand All @@ -289,6 +349,7 @@ async function genMetadata() {
populateSettings(writer);
await populateInstrumentations(writer);
populateResourceDetectors(writer);
await populateDependencies(writer);

const yaml = writer.join();
process.stdout.write(yaml);
Expand Down

0 comments on commit 29882b6

Please sign in to comment.