Registry / testing / ast-metadata-inferer

ast-metadata-inferer

JSON →
library0.8.1jsnpmunverified

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.

npm install ast-metadata-inferer
INSTALL
IMPORT
SIG · AST-METADATA-INFER
A
ast-metadata-inferer
testingjavascriptv0.8.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

AstMetadata
import AstMetadata from 'ast-metadata-inferer';
const AstMetadata = require('ast-metadata-inferer');
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.

This quickstart demonstrates how to import and access the `AstMetadata` array, which contains detailed information about various browser APIs and their compatibility data.

import AstMetadata from 'ast-metadata-inferer'; // The library exports an array of metadata records as its default export. // You can iterate through it or access specific records. const allApiRecords = AstMetadata; console.log(`Total API records available: ${allApiRecords.length}`); // Accessing the first record for demonstration const [firstRecord] = allApiRecords; if (firstRecord) { console.log('--- First API Record ---'); console.log(`API Proto Chain: ${firstRecord.protoChainId}`); console.log(`AST Node Types: ${firstRecord.astNodeTypes.join(', ')}`); console.log(`Is Statically Invoked: ${firstRecord.isStatic}`); console.log(`Language: ${firstRecord.language}`); if (firstRecord.compat && firstRecord.compat.support && firstRecord.compat.support.chrome) { console.log(`Chrome compatibility (version added): ${firstRecord.compat.support.chrome.version_added}`); } } else { console.log('No API records found.'); } // Example of finding a specific API, e.g., 'localStorage' const localStorageRecord = allApiRecords.find(record => record.protoChainId === 'localStorage'); if (localStorageRecord) { console.log('\n--- localStorage API Record ---'); console.log(`API Proto Chain: ${localStorageRecord.protoChainId}`); console.log(`AST Node Types: ${localStorageRecord.astNodeTypes.join(', ')}`); console.log(`Is Statically Invoked: ${localStorageRecord.isStatic}`); }
Debug
Known issues
breakingVersion 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.
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`.
affects: >=0.6.0
gotchaVersions 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.
fix
Upgrade to version 0.8.1 or later to benefit from fixes addressing proper Puppeteer browser instance closure and forced Node process exits.
affects: <0.8.1
gotchaThe 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.
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.
affects: <0.5.0
Errors
Common errors & fixes
TypeError: (0 , ast_metadata_inferer_1.default) is not a function
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.
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; ... }`
Node process hangs indefinitely after running script that uses ast-metadata-inferer
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.
fix
Upgrade to `ast-metadata-inferer@0.8.1` or newer. These versions include fixes to ensure all internal resources are properly cleaned up.
Error: Cannot find module 'ast-metadata-inferer' from '...' in a Node.js project.
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.
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.
Upgrade
Version history
0.8.1latest on npm
Audit
Dependencies
@mdn/browser-compat-datarequiredProvides core browser compatibility information used in the inferred metadata.
Agent activity
19 hits · last 30 days
node
16
Amazon
1
OpenAI (training)
1
Resources
ast-metadata-inferer — npm install ast-metadata-inferer · libregistry