babel-plugin-canyon

raw JSON →
2.0.58 verified Sat Apr 25 auth: no javascript

A Babel plugin that cooperates with Istanbul to report code coverage data to Canyon's coverage backend. This plugin instruments JavaScript code during Babel transformation, capturing coverage information that can be sent to Canyon's server for aggregation and visualization. The current stable version is v3.0.10 and is actively maintained. It is designed specifically for use with the Canyon coverage platform, differentiating itself by tight integration with Canyon's API and support for incremental coverage reports. It requires axios as a peer dependency to communicate with the Canyon server. The plugin is suitable for CI/CD pipelines where coverage reporting is needed.

error TypeError: Cannot read properties of undefined (reading 'coverage')
cause Axios peer dependency is missing or not properly configured.
fix
Install axios (npm install axios) and ensure it is available at runtime.
error Error: Could not find plugin "canyon". Ensure there is an entry in ./node_modules/babel-plugin-canyon.
cause The package is not installed or Babel cannot resolve it.
fix
Run 'npm install --save-dev babel-plugin-canyon' and check that the package is in node_modules.
error Error: [BABEL] unknown plugin "canyon" specified in "..."
cause The plugin name in Babel config is incorrect.
fix
Use 'canyon' as the plugin name (e.g., plugins: ['canyon']).
breaking Version 2.x uses a different API than v3.x. The plugin configuration options changed in v3.0.0.
fix Upgrade to v3.x and update plugin options according to the new documentation (https://docs.canyonjs.io/cn/docs/ecosystem/babel-plugin-canyon).
deprecated The package is transitioning to @canyonjs/babel-plugin in future releases. The npm package 'babel-plugin-canyon' will be deprecated.
fix Migrate to @canyonjs/babel-plugin when available.
gotcha The plugin requires axios as a peer dependency. If not installed, coverage reporting will fail silently.
fix Install axios: npm install axios.
gotcha The plugin only works with Babel 7+. Older Babel versions are not supported.
fix Ensure your project uses Babel 7 or later.
npm install babel-plugin-canyon
yarn add babel-plugin-canyon
pnpm add babel-plugin-canyon

Shows how to install and configure the Babel plugin in a project to instrument code and send coverage to Canyon server.

// Install the plugin
npm install --save-dev babel-plugin-canyon

// Configure Babel (e.g., in babel.config.js)
module.exports = {
  presets: ['@babel/preset-env'],
  plugins: [
    ['canyon', {
      // Optional: specify a coverage report endpoint
      endpoint: 'https://canyon.example.com/api/coverage',
      // Optional: include CI/CD environment variables
      repoName: process.env.CI_PROJECT_NAME || 'my-repo',
      commitSha: process.env.CI_COMMIT_SHA || ''
    }]
  ]
};

// Run your tests with Babel
npx babel src --out-dir lib

// Or use with Jest: add to jest.config.js
// transform: { '^.+\\.js$': 'babel-jest' }