Skip to content

feat: Add a cli tool to assist with testing configurations#68

Open
jsumners-nr wants to merge 1 commit into
nodejs:mainfrom
jsumners-nr:cli-tool
Open

feat: Add a cli tool to assist with testing configurations#68
jsumners-nr wants to merge 1 commit into
nodejs:mainfrom
jsumners-nr:cli-tool

Conversation

@jsumners-nr
Copy link
Copy Markdown
Contributor

This commit adds a new CLI tool to apply transforms to a script and write the resulting transform to standard out. This allows for quicker testing when writing transformation configurations.


I let the bot write this. I don't know the right format for adding a commit trailer, and I couldn't find it easily in core's contributing docs. 🤷‍♂️


Given two input files:

`transform.js`
module.exports = [{
  channelName: 'example',
  module: {
    name: 'example-module',
    versionRange: '>=1.0.0',
    filePath: 'index.js'
  },
  functionQuery: {
    expressionName: 'foo',
    kind: 'Sync'
  }
}]
`target.js`
module.exports = () => {
  const foo = () => {
    console.log('foo')
  }

  return { foo }
}

Running npx @apm-js-collab/code-transformer transform.js target.js will result in:

Output
const tr_ch_apm_dc = require("diagnostics_channel");
const {tracingChannel: tr_ch_apm_tracingChannel} = tr_ch_apm_dc;
const tr_ch_apm$example_fetch = tr_ch_apm_tracingChannel("orchestrion:example-module:example-fetch");
const tr_ch_apm_hasSubscribers = ch => ch.start.hasSubscribers || ch.end.hasSubscribers || ch.asyncStart.hasSubscribers || ch.asyncEnd.hasSubscribers || ch.error.hasSubscribers;
module.exports = () => {
  const foo = (...__apm$args) => {
    const __apm$arguments = [...__apm$args];
    const __apm$ctx = {
      arguments: __apm$arguments,
      self: this,
      moduleVersion: "1.0.0"
    };
    const __apm$traced = () => {
      const __apm$wrapped = function () {
        console.log('foo');
      };
      return __apm$wrapped.apply(this, __apm$arguments);
    };
    if (!tr_ch_apm_hasSubscribers(tr_ch_apm$example_fetch)) return __apm$traced();
    return tr_ch_apm$example_fetch.start.runStores(__apm$ctx, () => {
      try {
        const result = __apm$traced();
        __apm$ctx.result = result;
        return result;
      } catch (err) {
        __apm$ctx.error = err;
        tr_ch_apm$example_fetch.error.publish(__apm$ctx);
        throw err;
      } finally {
        __apm$ctx.self ??= this;
        tr_ch_apm$example_fetch.end.publish(__apm$ctx);
      }
    });
  };
  return {
    foo
  };
};

This commit adds a new CLI tool to apply transforms to a script
and write the resulting transform to standard out. This allows
for quicker testing when writing transformation configurations.
@jsumners-nr jsumners-nr marked this pull request as ready for review April 22, 2026 16:48
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.

1 participant