From 562e4443d8b6a8b38225c268430ad238182b21a7 Mon Sep 17 00:00:00 2001 From: rochdev Date: Wed, 8 Jan 2025 12:29:42 -0500 Subject: [PATCH 1/2] install plugin modules without npm view --- scripts/install_plugin_modules.js | 80 +++++++++++++++---------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/scripts/install_plugin_modules.js b/scripts/install_plugin_modules.js index 212dc5928ed..2496d8abc91 100644 --- a/scripts/install_plugin_modules.js +++ b/scripts/install_plugin_modules.js @@ -6,7 +6,6 @@ const path = require('path') const crypto = require('crypto') const semver = require('semver') const exec = require('./helpers/exec') -const childProcess = require('child_process') const externals = require('../packages/dd-trace/test/plugins/externals') const { getInstrumentation } = require('../packages/dd-trace/test/setup/helpers/load-inst') @@ -16,7 +15,6 @@ const requirePackageJsonPath = require.resolve('../packages/dd-trace/src/require // Can remove couchbase after removing support for couchbase <= 3.2.0 const excludeList = os.arch() === 'arm64' ? ['aerospike', 'couchbase', 'grpc', 'oracledb'] : [] const workspaces = new Set() -const versionLists = {} const deps = {} const filter = process.env.hasOwnProperty('PLUGINS') && process.env.PLUGINS.split('|') @@ -43,6 +41,8 @@ async function run () { // Some native addon packages rely on libraries that are not supported on ARM64 excludeList.forEach(pkg => delete workspaces[pkg]) install() + assertPeerDependencies(path.join(__dirname, '..', 'versions')) + install() } async function assertVersions () { @@ -107,9 +107,6 @@ function assertFolder (name, version) { async function assertPackage (name, version, dependencyVersionRange, external) { const dependencies = { [name]: dependencyVersionRange } - if (deps[name]) { - await addDependencies(dependencies, name, dependencyVersionRange) - } const pkg = { name: [name, sha1(name).substr(0, 8), sha1(version)].filter(val => val).join('-'), version: '1.0.0', @@ -132,45 +129,47 @@ async function assertPackage (name, version, dependencyVersionRange, external) { fs.writeFileSync(filename(name, version, 'package.json'), JSON.stringify(pkg, null, 2) + '\n') } -async function addDependencies (dependencies, name, versionRange) { - const versionList = await getVersionList(name) - const version = semver.maxSatisfying(versionList, versionRange) - const pkgJson = await npmView(`${name}@${version}`) - for (const dep of deps[name]) { - for (const section of ['devDependencies', 'peerDependencies']) { - if (pkgJson[section] && dep in pkgJson[section]) { - if (pkgJson[section][dep].includes('||')) { - // Use the first version in the list (as npm does by default) - dependencies[dep] = pkgJson[section][dep].split('||')[0].trim() - } else { - // Only one version available so use that. - dependencies[dep] = pkgJson[section][dep] - } - break - } +async function assertPeerDependencies (rootFolder, parent) { + const entries = fs.readdirSync(rootFolder) + + for (const entry of entries) { + const folder = path.join(rootFolder, entry) + + if (!fs.lstatSync(folder).isDirectory()) continue + if (entry === 'node_modules') continue + if (entry.startsWith('@')) { + assertPeerDependencies(folder, entry) + continue } - } -} -async function getVersionList (name) { - if (versionLists[name]) { - return versionLists[name] - } - const list = await npmView(`${name} versions`) - versionLists[name] = list - return list -} + const name = [parent, entry.split('@')[0]].filter(v => v).join('/') -function npmView (input) { - return new Promise((resolve, reject) => { - childProcess.exec(`npm view ${input} --json`, (err, stdout) => { - if (err) { - reject(err) - return + if (!deps[name]) continue + + const versionPkgJsonPath = path.join(folder, 'package.json') + const versionPkgJson = require(versionPkgJsonPath) + + for (const dep of deps[name]) { + const pkgJsonPath = require(folder).pkgJsonPath() + const pkgJson = require(pkgJsonPath) + + for (const section of ['devDependencies', 'peerDependencies']) { + if (pkgJson[section] && dep in pkgJson[section]) { + const peerVersion = pkgJson[section][dep].includes('||') + // Use the first version in the list (as npm does by default) + ? pkgJson[section][dep].split('||')[0].trim() + // Only one version available so use that. + : pkgJson[section][dep] + + versionPkgJson.dependencies[dep] = peerVersion + + fs.writeFileSync(versionPkgJsonPath, JSON.stringify(versionPkgJson, null, 2)) + + break + } } - resolve(JSON.parse(stdout.toString('utf8'))) - }) - }) + } + } } function assertIndex (name, version) { @@ -181,6 +180,7 @@ const requirePackageJson = require('${requirePackageJsonPath}') module.exports = { get (id) { return require(id || '${name}') }, getPath (id) { return require.resolve(id || '${name}' ) }, + pkgJsonPath (id) { return require.resolve((id || '${name}') + '/package.json') }, version () { return requirePackageJson('${name}', module).version } } ` From 52e72d15a9a1ee8c352b798c5f9724f2b9f8e66a Mon Sep 17 00:00:00 2001 From: rochdev Date: Wed, 8 Jan 2025 12:38:47 -0500 Subject: [PATCH 2/2] remove usage of npm show --- .../test/llmobs/sdk/typescript/index.spec.js | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/packages/dd-trace/test/llmobs/sdk/typescript/index.spec.js b/packages/dd-trace/test/llmobs/sdk/typescript/index.spec.js index b792a4fbdb7..5c136e97fc6 100644 --- a/packages/dd-trace/test/llmobs/sdk/typescript/index.spec.js +++ b/packages/dd-trace/test/llmobs/sdk/typescript/index.spec.js @@ -67,22 +67,14 @@ const testCases = [ } ] -// a bit of devex to show the version we're actually testing -// so we don't need to know ahead of time -function getLatestVersion (range) { - const command = `npm show typescript@${range} version` - const output = execSync(command, { encoding: 'utf-8' }).trim() - const versions = output.split('\n').map(line => line.split(' ')[1].replace(/'/g, '')) - return versions[versions.length - 1] -} - describe('typescript', () => { let agent let proc let sandbox for (const version of testVersions) { - context(`with version ${getLatestVersion(version)}`, () => { + // TODO: Figure out the real version without using `npm show` as it's broken. + context(`with version ${version}`, () => { before(async function () { this.timeout(20000) sandbox = await createSandbox(