function inspectForGlobals(ast, moduleRecord, packageName, includeDebugInfo) {
    const moduleRefs = MODULE_REFS[ast.program.sourceType]

    const globalObjPrototypeRefs = getOwnPropertyNames(objectPrototype)
    const foundGlobals = inspectGlobals(ast, {
      // browserify commonjs scope
      ignoredRefs: [...moduleRefs, ...globalObjPrototypeRefs],
      // browser global refs + browserify global
      globalRefs: DEFAULT_GLOBAL_THIS_REFS,
    })
    // skip if no results
    if (!foundGlobals.size) {
      return
    }
    // add debug info
    if (includeDebugInfo) {
      const moduleDebug = debugInfo[moduleRecord.specifier]
      moduleDebug.globals = mapToObj(foundGlobals)
    }
    // agregate globals
    if (!packageToGlobals.has(packageName)) {
      packageToGlobals.set(packageName, new Map())
    }
    let packageGlobals = packageToGlobals.get(packageName)

    // XXX temporary fix while we do not have writable global property
    // support at runtime
    // https://github.com/LavaMoat/LavaMoat/issues/1554
    for (const [path, value] of [...packageGlobals, ...foundGlobals]) {
      const pathParts = path.split('.')
      if (pathParts.length > 1 && value === POLICY_WRITE) {
        packageGlobals.set(pathParts[0], true)
      }
    }

    packageGlobals = mergeGlobalsPolicy(packageGlobals, foundGlobals)
    packageToGlobals.set(packageName, packageGlobals)
  }
@param {AST} ast
@param {import('./moduleRecord').LavamoatModuleRecord} moduleRecord
@param {string} packageName
@param {boolean} includeDebugInfo