Registry / serialization / gradle-to-js

gradle-to-js

JSON →
library2.0.1jsnpmunverified

gradle-to-js is a JavaScript library designed to parse Gradle build files (`.gradle`) into plain JavaScript objects. Currently at version 2.0.1, it offers a 'quick & dirty' approach, focusing on extracting key-value pairs and block structures rather than executing or accurately representing runtime evaluations within the Gradle script. This means complex logic, closures, or dynamic expressions found in Gradle files will not be processed, resulting in a simplified, static representation. The library primarily supports CommonJS imports and is best suited for scenarios where a basic, structural understanding of a Gradle file is needed, rather than a full, executable interpretation. Its release cadence appears infrequent, and it is likely in maintenance mode, reflecting its specific and somewhat limited parsing scope.

npm install gradle-to-js
INSTALL
IMPORT
SIG · GRADLE-TO-JS
G
gradle-to-js
serializationjavascriptv2.0.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.

parser
const g2js = require('gradle-to-js/lib/parser');
import g2js from 'gradle-to-js/lib/parser';
The library primarily uses CommonJS `require()`. Direct ESM `import` may require bundler configuration or dynamic import, and is not officially supported.
parseFile
g2js.parseFile('path/to/buildfile').then(...);
const { parseFile } = require('gradle-to-js/lib/parser');
The `parser` module is imported as a single object (e.g., `g2js`), and `parseFile` is a method on that object, not a named export. Promises are used for asynchronous operations.
parseText
g2js.parseText('key "value"').then(...);
const { parseText } = require('gradle-to-js/lib/parser');
Similar to `parseFile`, `parseText` is a method of the imported `parser` object, not a named export. It parses a Gradle-like string directly.

This example demonstrates how to parse a Gradle build file into a JavaScript object using `parseFile` and then logs the structured representation. It includes setup for a temporary file and error handling.

const g2js = require('gradle-to-js/lib/parser'); const fs = require('fs'); const path = require('path'); // Create a dummy Gradle file for demonstration const tempGradleFile = path.join(__dirname, 'temp.gradle'); fs.writeFileSync(tempGradleFile, ` apply plugin: 'java' sourceCompatibility = 1.8 targetCompatibility = 1.8 repositories { mavenCentral() } dependencies { implementation 'org.slf4j:slf4j-api:1.7.30' testImplementation 'junit:junit:4.13' } myBlock { key1 "value1" key2 123 } `); g2js.parseFile(tempGradleFile) .then(function(representation) { console.log('Parsed Gradle file representation:'); console.log(JSON.stringify(representation, null, 2)); }) .catch(function(error) { console.error('Error parsing Gradle file:', error); }) .finally(() => { // Clean up the dummy file fs.unlinkSync(tempGradleFile); });
Debug
Known issues
gotchaThe parser is explicitly 'quick & dirty' and does not evaluate Gradle runtime logic, Groovy closures, or dynamic expressions within the build file. It produces a static, structural representation, which may not fully reflect the build file's behavior during actual Gradle execution.
fix
Understand that this library is for static structural parsing only. For full Gradle script evaluation, consider using Gradle itself or a more sophisticated Groovy/Kotlin parser.
affects: >=1.0.0
gotchaThis library is primarily a CommonJS module. Direct `import` statements (ESM syntax) will likely lead to `SyntaxError: Cannot use import statement outside a module` in Node.js projects not explicitly configured for CJS/ESM interoperation.
fix
Use CommonJS `require()` syntax: `const g2js = require('gradle-to-js/lib/parser');`. If you must use it in an ESM context, consider dynamic `import('gradle-to-js/lib/parser')` or a bundler.
affects: >=1.0.0
gotchaThe primary entry point for the parser functionality is `gradle-to-js/lib/parser`, not the root `gradle-to-js` package. Attempting to `require('gradle-to-js')` directly will likely result in an object without the `parseFile` or `parseText` methods.
fix
Always import the specific parser module: `require('gradle-to-js/lib/parser')`.
affects: >=1.0.0
gotchaThe CLI usage examples demonstrate running the `index.js` directly via `./index.js` or `node ./index.js`. This implies the CLI might not be installed as a globally available command without manual `npm link` or an explicit `bin` entry in `package.json`.
fix
For CLI usage, execute `node node_modules/gradle-to-js/index.js <path-to-file>` or verify `package.json` for a `bin` entry and use the appropriate command.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: g2js.parseFile is not a function
Attempting to call `parseFile` on an object imported from the root `gradle-to-js` package instead of the `lib/parser` module.
fix
Ensure you are importing from the correct path: `const g2js = require('gradle-to-js/lib/parser');`
SyntaxError: Cannot use import statement outside a module
Trying to use ESM `import` syntax for `gradle-to-js` in a Node.js environment that expects CommonJS modules.
fix
Use CommonJS `require()` syntax: `const g2js = require('gradle-to-js/lib/parser');`
Error: ENOENT: no such file or directory, open 'path/to/buildfile'
The file path provided to `g2js.parseFile()` does not point to an existing or accessible file.
fix
Double-check the file path. Ensure it's correct and that the Node.js process has read permissions for the specified file.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
gradle-to-js — npm install gradle-to-js · libregistry