Lines 1-68javascript
3const os = require('os')
4const packageJson = require('./package.json')
MediumDynamic Require
Package source references dynamic require/import behavior.
index.jsView on unpkg · L2 6// Check if DEBUG environment variable is set
7const isDebugMode = process.env.DEBUG && (
8 process.env.DEBUG.toLowerCase() === 'true' ||
9 process.env.DEBUG.includes('mcp') ||
10 process.env.DEBUG === '*'
13// Helper function for debug logging
14function debugLog(...args) {
16 console.error(...args)
20debugLog('\nWrapper package starting')
22process.argv.forEach((val, index) => {
23 debugLog(`${index}: ${val}`)
26const platform = os.platform()
29const packageName = packageJson.name
30const packageVersion = packageJson.version
31const platformPackageName = `${packageName}-${platform}-${arch}`
33// Try to load the platform package
36 debugLog(`Attempting to require platform package: ${platformPackageName}`)
37 platformPackage = require(platformPackageName)
39 debugLog(`Failed to require ${platformPackageName}, attempting auto-install: ${err.message}`)
41 // Try to automatically install the missing platform package
43 const { execSync } = require('child_process')
45 console.error(`Installing missing platform package: ${platformPackageName}`)
47 // Try to install the platform package
49 execSync(`npm install ${platformPackageName}@${packageVersion}`, {
50 stdio: ['inherit', 'inherit', 'pipe'], // Only pipe stderr to capture errors
HighRuntime Package Install
Package source invokes a package manager install command at runtime.
index.jsView on unpkg · L48 51 timeout: 60000 // 60 second timeout
54 // If npm install fails, try with --no-save and different install strategies
55 debugLog(`npm install failed, trying alternative installation methods: ${npmErr.message}`)
57 // Try with --no-save and --prefer-online
58 execSync(`npm install ${platformPackageName}@${packageVersion} --no-save --prefer-online`, {
59 stdio: ['inherit', 'inherit', 'pipe'],
64 // Clear module cache and try to require again after installation
65 Object.keys(require.cache).forEach(key => {
66 if (key.includes(platformPackageName)) {
67 delete require.cache[key]