Skip to content

feat: add inject-bundle-id command to CLI #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 2, 2025
Merged

Conversation

eskirk
Copy link
Collaborator

@eskirk eskirk commented Mar 21, 2025

For applications that don't use Webpack or Rollup, or in cases where you need to add the bundle ID to already built JavaScript files, you can use the inject-bundle-id command:

npx faro-cli inject-bundle-id \
  --bundle-id "your-bundle-id" \
  --app-name "your-app-name" \
  --files "dist/**/*.js" \
  --verbose

This command will:

  1. Locate all JavaScript files matching the specified glob patterns
  2. Check if each file already has a bundle ID snippet
  3. Prepend the bundle ID snippet to files that don't have it
  4. Export the bundle ID to an environment variable for potential later use with other commands

@eskirk eskirk linked an issue Mar 21, 2025 that may be closed by this pull request
@eskirk eskirk requested a review from Copilot April 2, 2025 00:22
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request introduces a new CLI command (inject-bundle-id) to add a bundle ID snippet to JavaScript files after they are built, without requiring a bundler like Webpack or Rollup. Key changes include:

  • Adding a new function (injectBundleId) to insert the bundle ID snippet into files.
  • Creating tests (bundleId.test.ts) to verify snippet injection, skipping files with an existing snippet, and respecting dry run mode.
  • Updating the CLI (cli.ts) and README.md to support and document the new inject-bundle-id command.

Reviewed Changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/faro-cli/src/test/index.test.ts Added teardown logic (afterAll) to reset and unmock modules after tests.
packages/faro-cli/src/test/bundleId.test.ts New tests covering bundle ID injection behavior and dry run functionality.
packages/faro-cli/src/index.ts Added core implementation of injectBundleId along with related interfaces and documentation.
packages/faro-cli/src/cli.ts Integrated the inject-bundle-id command into the CLI with file globbing and verbose logging.
packages/faro-cli/README.md Updated documentation to include the new command with examples and option details.
Files not reviewed (1)
  • packages/faro-cli/package.json: Language not supported
Comments suppressed due to low confidence (1)

packages/faro-cli/src/test/bundleId.test.ts:41

  • Consider using fs.rmSync(testDir, { recursive: true }) instead of fs.rmdirSync, as the latter may be deprecated in newer Node versions.
fs.rmdirSync(testDir);

@eskirk eskirk merged commit 8b64234 into main Apr 2, 2025
5 checks passed
@app-o11y-kwl-ci app-o11y-kwl-ci bot mentioned this pull request Apr 2, 2025
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.

Missing Angular Documentation
1 participant