Skip to content

Modernize foresta-js library with NPM build process, latest esprima, comprehensive tests, and CI/CD#2

Merged
joelmartinez merged 3 commits into
masterfrom
copilot/fix-1
Aug 8, 2025
Merged

Modernize foresta-js library with NPM build process, latest esprima, comprehensive tests, and CI/CD#2
joelmartinez merged 3 commits into
masterfrom
copilot/fix-1

Conversation

Copilot AI commented Aug 4, 2025

Copy link
Copy Markdown
Contributor

This PR modernizes the foresta-js JavaScript library to bring it up to current standards with proper NPM build process, latest dependencies, comprehensive testing, and automated CI/CD pipeline.

Key Changes

Fixed Critical Bug

The original code had a critical syntax error on line 11 where part.length = 0 (assignment) was used instead of part.length === 0 (comparison), which would have broken query parsing.

Updated Dependencies

  • Upgraded to esprima 4.0.1 (latest stable)
  • Added compatibility fix for esprima API changes (the fx.defaults property was removed)
  • All functionality now works correctly with the latest esprima version

Modern Project Structure

Restructured the project to follow modern Node.js conventions:

src/           # Source code
test/          # Jest test suite  
dist/          # Built distributions
examples/      # Usage examples

Build System

Added Rollup-based build process that creates three distribution formats:

  • dist/foresta.js - CommonJS for Node.js
  • dist/foresta.esm.js - ES Module for modern bundlers
  • dist/foresta.umd.js - UMD for browsers

Comprehensive Testing

Added Jest test suite with 17 tests covering all functionality described in the README:

  • Basic literal selection: "Literal"
  • Identifier selection: "#theValue"
  • Global variable queries: "Program VariableDeclaration VariableDeclarator"
  • Property modifiers: "ObjectExpression Property #update:parent:value"
  • Edge cases and error handling

Achieves 92% code coverage.

GitHub Actions CI/CD

Added automated CI workflow that:

  • Runs tests on Node.js versions 14.x, 16.x, 18.x, and 20.x
  • Installs dependencies with npm ci
  • Runs Jest tests and coverage reporting
  • Uploads coverage reports to Codecov
  • Triggers on push and pull requests to main/master branches
  • Provides foundation for future NPM publishing automation

Example Usage

const foresta = require('foresta');
const esprima = require('esprima');

const code = `var theValue = 4 + 2;`;
const ast = esprima.parseScript(code);

// Find all literals
const query = new foresta("Literal");
query.visit(ast);
console.log(query.results); // [4, 2]

// Find specific variable
const idQuery = new foresta("#theValue");
idQuery.visit(ast);
console.log(idQuery.results[0].name); // "theValue"

The library is now ready for modern JavaScript development and NPM publishing with automated testing and CI/CD pipeline.

Fixes #1.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…latest esprima, and comprehensive tests

Co-authored-by: joelmartinez <90380+joelmartinez@users.noreply.github.com>
Copilot AI changed the title [WIP] Modernization Modernize foresta-js library with NPM build process, latest esprima, and comprehensive tests Aug 4, 2025
Copilot AI requested a review from joelmartinez August 4, 2025 23:47

@joelmartinez joelmartinez left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a github action that will run the jest tests for now. Eventually it'll be used to publish new builds to npm when there's a checkin to the mainline branch, but for now it can just run the tests.

Co-authored-by: joelmartinez <90380+joelmartinez@users.noreply.github.com>

Copilot AI commented Aug 5, 2025

Copy link
Copy Markdown
Contributor Author

Add a github action that will run the jest tests for now. Eventually it'll be used to publish new builds to npm when there's a checkin to the mainline branch, but for now it can just run the tests.

Added GitHub Actions CI workflow in .github/workflows/ci.yml that runs Jest tests on Node.js versions 14.x, 16.x, 18.x, and 20.x. The workflow triggers on push and pull requests to main/master branches and includes coverage reporting. All tests are passing with 92% coverage. Commit: 0c66a1a

Copilot AI changed the title Modernize foresta-js library with NPM build process, latest esprima, and comprehensive tests Modernize foresta-js library with NPM build process, latest esprima, comprehensive tests, and CI/CD Aug 5, 2025
Copilot AI requested a review from joelmartinez August 5, 2025 01:12
@joelmartinez joelmartinez marked this pull request as ready for review August 8, 2025 10:06
@joelmartinez joelmartinez merged commit 9d00269 into master Aug 8, 2025
@joelmartinez joelmartinez deleted the copilot/fix-1 branch August 8, 2025 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Modernization

2 participants