Skip to content

Update Framework Docs with how Moose Version are Determined in Boreal for Python and Typescript #2465

@jmsuzuki

Description

@jmsuzuki

We need to update our framework docs to include how the version of moose is determined in boreal for python and typescript deployments.

For typescript.

async function getMooseVersionForTypescript() {
  // Try pnpm-lock.yaml first
  const pnpmVersion = await getMooseVersionFromPnpm(repoRootDir, mooseProjectDirectory);
  if (pnpmVersion) {
    return pnpmVersion;
  }

  // Fall back to package-lock.json or package.json
  let packageFile = `${mooseProjectDirectory}/package-lock.json`;
  if (!fs.existsSync(packageFile)) {
    console.log(
      `Could not find package-lock.json, package.json will be used to determine the moose-cli version requirement`
    );
    packageFile = `${mooseProjectDirectory}/package.json`;
  }

  let mooseVerRequirement;
  const packageJson = JSON.parse(fs.readFileSync(packageFile, "utf-8"));
  if (packageFile.endsWith("package-lock.json")) {
    // For package-lock.json, version is under packages['node_modules/@514labs/moose-cli']
    mooseVerRequirement = packageJson.packages[""].dependencies[MOOSE_LIB_TS_PACKAGE];
  } else {
    // For package.json, version is under dependencies directly
    mooseVerRequirement = packageJson.dependencies[MOOSE_LIB_TS_PACKAGE];
  }
  if (mooseVerRequirement === "latest") {
    mooseVerRequirement = "*";
  }

  return mooseVerRequirement;
}

for python

async function getMooseVersionForPython() {
  let content;
  let setupPyPath = `${mooseProjectDirectory}/setup.py`;
  let requirementsTxtPath = `${mooseProjectDirectory}/requirements.txt`;

  // Try to find setup.py or requirements.txt, including in subdirectories
  if (!fs.existsSync(setupPyPath)) {
    // Search for setup.py in subdirectories
    const files = fs.readdirSync(mooseProjectDirectory, { recursive: true });
    const setupPyFile = files.find((file) => file.endsWith("setup.py"));
    if (setupPyFile) {
      setupPyPath = `${mooseProjectDirectory}/${setupPyFile}`;
    }
  }

  if (!fs.existsSync(requirementsTxtPath)) {
    // Search for requirements.txt in subdirectories
    const files = fs.readdirSync(mooseProjectDirectory, { recursive: true });
    const requirementsTxtFile = files.find((file) => file.endsWith("requirements.txt"));
    if (requirementsTxtFile) {
      requirementsTxtPath = `${mooseProjectDirectory}/${requirementsTxtFile}`;
    }
  }

  let mooseVerRequirement = "*";
  // Try setup.py first
  if (fs.existsSync(setupPyPath)) {
    console.log(`Attempting to get moose-cli version requirement for Python from setup.py`);
    content = fs.readFileSync(setupPyPath, "utf8");
    const lines = content.split("\n");
    const mooseLibLine = lines.find((line) => line.includes(`"${MOOSE_LIB_PY_PACKAGE}`));
    const match = mooseLibLine?.match(/==([0-9.]+)/)?.[1];
    if (match) mooseVerRequirement = match;
  }

  // If version is still *, try requirements.txt
  if (mooseVerRequirement === "*" && fs.existsSync(requirementsTxtPath)) {
    console.log(`Attempting to get moose-cli version requirement for Python from requirements.txt`);
    content = fs.readFileSync(requirementsTxtPath, "utf8");
    const lines = content.split("\n");
    const mooseLibLine = lines.find((line) => line.includes(MOOSE_LIB_PY_PACKAGE));
    const match = mooseLibLine?.match(/==([0-9.]+)/)?.[1];
    if (match) mooseVerRequirement = match;
  }

  console.log(`moose-cli version requirement for Python: ${mooseVerRequirement}`);

  return mooseVerRequirement;
}

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions