gyp-parser is a JavaScript library dedicated to parsing files written in the GYP (Generate Your Projects) format. GYP is a build system historically used by projects like Chromium and Node.js to generate native project files (e.g., Makefiles, Visual Studio projects). This package provides a robust, pure JavaScript implementation that converts GYP source strings into standard JavaScript objects. It serves as a secure and reliable alternative to using `eval()` for GYP content, adeptly handling complex GYP features such as implicit string concatenation, variable expansion, and dictionary merging that `eval()` might misinterpret or fail to process. The current stable version is 1.0.4, indicating a mature and specific tool that likely has an infrequent release cadence. Its key differentiator is its ability to parse the GYP format comprehensively without relying on `eval()` or performing any I/O operations, making it suitable for secure and isolated parsing tasks within applications.
npm install gyp-parserVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates parsing a complex GYP file string, including nested objects, arrays, variables, and actions, and then logging the resulting JavaScript object.
Always use `gyp-parser`'s `parse` function. It is specifically designed to handle GYP syntax securely and correctly, including features like implicit string concatenation and dictionary merging that `eval()` will not support natively.
You must provide the GYP file content as a string to the `parse` function. Handle file reading (e.g., using `fs.readFileSync` in Node.js) separately before passing the content to `gyp-parser`.
Ensure the input string adheres to the GYP format. Errors for malformed GYP will be thrown as `SyntaxError` by the parser. Consult GYP documentation for exact syntax rules if encountering parsing issues.
Carefully review the GYP input string for any syntax inconsistencies. Ensure all strings are correctly quoted, dictionaries and arrays are properly terminated, and no invalid characters are present according to GYP rules.
For CommonJS, use `const { parse } = require('gyp-parser');`. In ESM, ensure you are using `import { parse } from 'gyp-parser';`.Verify the GYP file content and the property path you are trying to access. Add checks (e.g., `if (parsedData && parsedData.some_key)`) to handle cases where properties might be missing or optional.
No dependency data recorded yet.