Blog
release_workspace script in langchainjs source code.

release_workspace script in langchainjs source code.

In this article, we will review release_workspace script in langchainjs source code. we will look at:

  1. release script in package.json

  2. release_workspace.js file

release script in package.json

You will find the below code in langchainjs/package.json file 

   "release": "node release_workspace.js --workspace"

When you run this below command

npm run release

release_workspace.js is executed.

release_workspace.js file

In the langchainjs/release_workspace.json file, at line 507, you will find this below code:

main().catch((error) => {
  console.error(error);
  process.exit(1);
});

main function is defined in the same file at line 422.

async function main() {
  const program = new Command();
  program
    .description("Release a new workspace version to NPM.")
    .option("--workspace <workspace>", "Workspace name, eg @langchain/core")
    .option(
      "--bump-deps",
      "Whether or not to bump other workspaces that depend on this one."
    )
    .option("--tag <tag>", "Optionally specify a tag to publish to.");

  program.parse();

  /**
   * @type {{ workspace: string, bumpDeps?: boolean, tag?: string }}
   */
  const options = program.opts();
  if (!options.workspace) {
    throw new Error("--workspace is a required flag.");
  }

commanderjs is used to create cli as shown below:

 const program = new Command();

command is imported as shown below:

const { Command } = require("commander");

Below are the functions called in this main function:

  1. hasUncommittedChanges

  2. getAllWorkspaces

  3. checkoutReleaseBranch

  4. execSyncWithErrorHandling

  5. getUserInput

  6. getWorkspaceVersion

  7. runYarnRelease

  8. hasStagedChanges

  9. hasUncommittedChanges

  10. bumpDeps

Let’s take a closer look at execSyncWithErrorHandling function.

execSyncErrorHandling

This function is defined in the same file at line 18:

/**
 * Handles execSync errors and logs them in a readable format.
 * @param {string} command
 * @param {{ doNotExit?: boolean }} [options] - Optional configuration
 * @param {boolean} [options.doNotExit] - Whether or not to exit the process on error
 */
function execSyncWithErrorHandling(command, options = {}) {
  try {
    execSync(
      command,
      { stdio: "inherit" } // This will stream output in real-time
    );
  } catch (error) {
    console.error(error.message);
    if (!options.doNotExit) {
      process.exit(1);
    }
  }
}

execsync is imported as shown below:

const { execSync } = require("child_process");

About me

Hey, my name is Ramu Narasinga. I study codebase architecture in large open-source projects.

Email: ramu.narasinga@gmail.com

Build Shadcn CLI from scratch.

References:

  1. https://github.com/langchain-ai/langchainjs/blob/main/package.json#L43

  2. https://github.com/langchain-ai/langchainjs/blob/main/release_workspace.js#L507

  3. https://github.com/langchain-ai/langchainjs/blob/main/release_workspace.js#L422

  4. https://github.com/langchain-ai/langchainjs/blob/main/release_workspace.js#L391

  5. https://github.com/langchain-ai/langchainjs/blob/main/release_workspace.js#L352

  6. https://github.com/langchain-ai/langchainjs/blob/main/release_workspace.js#L140

We use cookies
We use cookies to ensure you get the best experience on our website. For more information on how we use cookies, please see our cookie policy.

By clicking "Accept", you agree to our use of cookies.

Learn more