redux-toolkit icon indicating copy to clipboard operation
redux-toolkit copied to clipboard

Expose codegen CLI from the package exports

Open markerikson opened this issue 6 months ago • 1 comments

@markerikson we are calling the cli programmatically like this

const cliPath = require.resolve('@rtk-query/codegen-openapi/lib/bin/cli');

const runReduxCodegen = async (specUrl: string | undefined, configPath: string, outputPath: string): Promise<void> => (
  new Promise((resolve, reject) => {
    exec(
      `tsx ${cliPath} ${configPath}`,
      {
        env: {
          ...process.env,
          SPEC_URL: specUrl,
          STORE_ROOT_PATH: outputPath,
        },
      },
      (error, stdout, stderr) => {
        if (error) {
          console.error(`exec error: ${error}`);
          reject(new Error(`Execution failed with error: ${stderr || 'Unknown error'}`));
        } else {
          console.log(stdout);

          if (stderr) {
            reject(new Error(`Execution produced errors: ${stderr}`));
          } else {
            resolve();
          }
        }
      },
    );
  })
);

when upgrading from 1.2.0 to 2.0.0, the error message is that /lib/bin/cli is not in exports of the package

nodeLinker is pnp

Originally posted by @maddrag0n in #4974

markerikson avatar May 08 '25 15:05 markerikson

workaround until https://github.com/reduxjs/redux-toolkit/pull/4977 is merged and released:

const cliPath = require.resolve('@rtk-query/codegen-openapi')
  .split('/')
  .slice(0, -1)
  .join('/')
  + '/bin/cli.mjs';

maddrag0n avatar May 12 '25 12:05 maddrag0n