HEX
Server: LiteSpeed
System: Linux houston.panomity.com 6.8.0-100-generic #100-Ubuntu SMP PREEMPT_DYNAMIC Tue Jan 13 16:40:06 UTC 2026 x86_64
User: nudepix (1011)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //opt/coauthor/node_modules/.bin/0gentesthtml
#!/usr/bin/env node
import * as fs from 'fs'
import * as object from '../object.js'
import * as env from '../environment.js'

const script = env.getParam('--script', './test.js')

/**
 * @type {Object<string,string>}
 */
const exports = {}
/**
 * @type {Object<string,Object<string,string>>}
 */
const scopes = {}

/**
 * @param {any} v
 * @param {string} k
 * @param {string} pkgName
 * @param {string} pathPrefix
 * @param {Object<string,string>} importMap
 */
const extractModMap = (v, k, pkgName, pathPrefix, importMap) => {
  if (k[0] !== '.') return
  if (typeof v === 'object') {
    extractModMap(v.browser || v.module || v.default || v.import, k, pkgName, pathPrefix, importMap)
  } else if (v && v[0] === '.') {
    importMap[pkgName + k.slice(1)] = pathPrefix + v.slice(1)
  }
}

/**
 * @param {any} pkgJson
 * @param {string} pathPrefix
 * @param {Object<string,string>} importMap
 */
const readPkg = (pkgJson, pathPrefix, importMap) => {
  object.forEach(pkgJson.exports, (v, k) => extractModMap(v, k, pkgJson.name, pathPrefix, importMap))
  object.forEach(pkgJson.dependencies, (_v, depName) => {
    const nextImportMap = pathPrefix === '.' ? exports : (scopes[pathPrefix + '/'] = {})
    const prefix = `./node_modules/${depName}`
    const depPkgJson = JSON.parse(fs.readFileSync(prefix + '/package.json', { encoding: 'utf8' }))
    readPkg(depPkgJson, prefix, nextImportMap)
  })
}

const rootPkgJson = JSON.parse(fs.readFileSync('./package.json', { encoding: 'utf8' }))
readPkg(rootPkgJson, '.', exports)

const testHtml = `
<!DOCTYPE html>
<html>
<head>
  <title>Testing ${rootPkgJson.name}</title>
  <script type="importmap">
    {
      "imports": ${JSON.stringify(exports, null, 2)},
      "scopes": ${JSON.stringify(scopes, null, 2)}
    }
  </script>
</head>
<body>
  <script type="module" src="${script}"></script>
</body>
</html>
`

console.log(testHtml)