{"id":12835,"library":"ast-metadata-inferer","title":"AST Metadata Inferer","description":"ast-metadata-inferer is a JavaScript library designed to provide comprehensive metadata about browser APIs, primarily for static analysis tools. It aggregates crucial information from sources like `@mdn/browser-compat-data`, offering insights into an API's AST node type (e.g., `MemberExpression`, `CallExpression`), whether it's statically invoked, and its classification as a CSS or JS API. The current stable version is 0.8.1. The package maintains a moderately active release cadence, frequently updating dependencies and refining its build processes. Its key differentiators include a curated, programmatically accessible dataset of browser API characteristics combined with detailed compatibility data, making it an invaluable resource for linters, bundlers, and other tools that need to understand browser API usage patterns and compatibility across various environments.","status":"active","version":"0.8.1","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/amilajack/ast-metadata-inferer","tags":["javascript"],"install":[{"cmd":"npm install ast-metadata-inferer","lang":"bash","label":"npm"},{"cmd":"yarn add ast-metadata-inferer","lang":"bash","label":"yarn"},{"cmd":"pnpm add ast-metadata-inferer","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Provides core browser compatibility information used in the inferred metadata.","package":"@mdn/browser-compat-data","optional":false}],"imports":[{"note":"The library primarily uses ES Module syntax. CommonJS `require` is not directly supported for the default export since the v0.6.0 migration to TypeScript.","wrong":"const AstMetadata = require('ast-metadata-inferer');","symbol":"AstMetadata","correct":"import AstMetadata from 'ast-metadata-inferer';"}],"quickstart":{"code":"import AstMetadata from 'ast-metadata-inferer';\n\n// The library exports an array of metadata records as its default export.\n// You can iterate through it or access specific records.\n\nconst allApiRecords = AstMetadata;\n\nconsole.log(`Total API records available: ${allApiRecords.length}`);\n\n// Accessing the first record for demonstration\nconst [firstRecord] = allApiRecords;\n\nif (firstRecord) {\n  console.log('--- First API Record ---');\n  console.log(`API Proto Chain: ${firstRecord.protoChainId}`);\n  console.log(`AST Node Types: ${firstRecord.astNodeTypes.join(', ')}`);\n  console.log(`Is Statically Invoked: ${firstRecord.isStatic}`);\n  console.log(`Language: ${firstRecord.language}`);\n  if (firstRecord.compat && firstRecord.compat.support && firstRecord.compat.support.chrome) {\n    console.log(`Chrome compatibility (version added): ${firstRecord.compat.support.chrome.version_added}`);\n  }\n} else {\n  console.log('No API records found.');\n}\n\n// Example of finding a specific API, e.g., 'localStorage'\nconst localStorageRecord = allApiRecords.find(record => record.protoChainId === 'localStorage');\n\nif (localStorageRecord) {\n  console.log('\\n--- localStorage API Record ---');\n  console.log(`API Proto Chain: ${localStorageRecord.protoChainId}`);\n  console.log(`AST Node Types: ${localStorageRecord.astNodeTypes.join(', ')}`);\n  console.log(`Is Statically Invoked: ${localStorageRecord.isStatic}`);\n}","lang":"typescript","description":"This quickstart demonstrates how to import and access the `AstMetadata` array, which contains detailed information about various browser APIs and their compatibility data."},"warnings":[{"fix":"Ensure your project uses ES Module syntax (`import`) for consuming the library. If using Node.js, ensure your environment supports ESM or use a transpiler like Babel with appropriate configuration for `node_modules`.","message":"Version 0.6.0 migrated the project from Babel to TypeScript. This change primarily affects the build process and internal tooling, but it might introduce subtle breaking changes for consumers relying on specific CommonJS module resolution or Babel runtime behaviors.","severity":"breaking","affected_versions":">=0.6.0"},{"fix":"Upgrade to version 0.8.1 or later to benefit from fixes addressing proper Puppeteer browser instance closure and forced Node process exits.","message":"Versions prior to 0.8.0-0 and 0.8.1 might have resource management issues, particularly with internal Puppeteer instances not closing correctly or Node processes not exiting cleanly. This could lead to hanging processes or memory leaks in long-running applications or CI environments.","severity":"gotcha","affected_versions":"<0.8.1"},{"fix":"Review the structure of the `compat` object in your application after upgrading to versions 0.5.0+. Consult the `@mdn/browser-compat-data` schema for detailed changes if necessary.","message":"The internal data source for compatibility information migrated to `@mdn/browser-compat-data` in v0.5.0. While the public API aims to remain stable, the structure or specific values within the `compat` object of each record might have subtly changed. If your application relies on a very specific shape or set of properties within `compat`, verify its behavior after upgrading from versions prior to 0.5.0.","severity":"gotcha","affected_versions":"<0.5.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Use ES Module import syntax: `import AstMetadata from 'ast-metadata-inferer';`. If you must use CommonJS, ensure your environment handles ESM interoperability or consider dynamic import: `async function load() { const AstMetadata = (await import('ast-metadata-inferer')).default; ... }`","cause":"Attempting to `require` the default ES Module export in a CommonJS environment without proper interop. The library is primarily ESM-first since v0.6.0.","error":"TypeError: (0 , ast_metadata_inferer_1.default) is not a function"},{"fix":"Upgrade to `ast-metadata-inferer@0.8.1` or newer. These versions include fixes to ensure all internal resources are properly cleaned up.","cause":"Older versions of the library (prior to 0.8.1) sometimes failed to properly close internal resources like Puppeteer browser instances, preventing the Node.js event loop from emptying and the process from exiting.","error":"Node process hangs indefinitely after running script that uses ast-metadata-inferer"},{"fix":"Ensure your Node.js project is configured to use ES Modules by adding `\"type\": \"module\"` to your `package.json`, and use `import AstMetadata from 'ast-metadata-inferer';`. Alternatively, use dynamic `import()` within an `async` function for CommonJS environments if possible.","cause":"This error can occur if your Node.js project is configured as a CommonJS module (`\"type\": \"commonjs\"` in package.json or no `\"type\"` field) and tries to import an ESM-only package using `require()` or if Node's module resolution fails for other reasons.","error":"Error: Cannot find module 'ast-metadata-inferer' from '...' in a Node.js project."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null}