Skip to content
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

[core] Standardize npm scripts #16248

Merged
merged 9 commits into from
Jul 9, 2021

Conversation

deyaaeldeen
Copy link
Member

@deyaaeldeen deyaaeldeen commented Jul 7, 2021

Fixes #15679.

This PR standardizes the list of npm scripts across core packages and the template package. It also standardizes the content of the scripts as possible.

To do this, this PR also does the following:

  • switch most packages to use dev-tool's shared rollup config when possible. core-amqp is a notable exception, it needs some special rollup handling but I believe there is room for improvement there. @witemple-msft perhaps you might be interested in looking at it.
  • standardize the assertion library used to be chai instead of assert because the shared rollup config only understands chai and there is no reason to use two assertion libraries AFAICT.

I wrote a small script to do the comparison between the template package and any other package which could be helpful if we want to do enforcement in CI:

function getExtraScripts(scripts1, scripts2) {
  const scripts1Names = Object.keys(scripts1);
  const scripts2Names = Object.keys(scripts2);
  return [computeDifference(scripts1Names, scripts2Names), computeDifference(scripts2Names, scripts1Names)]
}

function computeDifference(list1, list2) {
  const set1 = new Set(list1);
  const set2 = new Set(list2);
  return new Set([...set1].filter(x => !set2.has(x)));
}

function computeIntersect(list1, list2) {
  const set1 = new Set(list1);
  const set2 = new Set(list2);
  return new Set([...set1].filter(x => set2.has(x)));
}

function getCommonScripts(scripts1, scripts2) {
  const scripts1Names = Object.keys(scripts1);
  const scripts2Names = Object.keys(scripts2);
  return computeIntersect(scripts1Names, scripts2Names)
}

function comparePackagesScriptNames(pkg1Name, pkg1Path, pkg2Name, pkg2Path) {
  const templateScripts = require(`${pkg1Path}/package.json`).scripts
  const targetPackageScripts = require(`./${pkg2Path}/package.json`).scripts
  const diffs = getExtraScripts(templateScripts, targetPackageScripts);
  console.log(`${pkg1Name} has: ${[...diffs[0]]}`)
  console.log(`${pkg2Name} has: ${[...diffs[1]]}`)
}

function comparePackagesScripts(pkg1Name, pkg1Path, pkg2Name, pkg2Path) {
  const templateScripts = require(`${pkg1Path}/package.json`).scripts
  const targetPackageScripts = require(`./${pkg2Path}/package.json`).scripts
  const scripts = getCommonScripts(templateScripts, targetPackageScripts);
  for (const s of scripts) {
    if (templateScripts[s] !== targetPackageScripts[s]) {
      console.log(`${templateScripts[s]} | ${s} | ${pkg1Name}`)
      console.log(`${targetPackageScripts[s]} | ${s} | ${pkg2Name}`)
      console.log(`============================================================================================================`)
    }
  }
}

function main(args) {
  if (args.length !== 3) {
    throw new Error(
      "Expected exactly one command-line argument for the path of the package to be updated"
    );
  }
  const pkgPath = args[2];
  const pkgName = pkgPath.split("/")[2];
  comparePackagesScriptNames("Template", "./sdk/template/template", pkgName, pkgPath);
  comparePackagesScripts("Template", "./sdk/template/template", pkgName, pkgPath);
}
main(process.argv);

@deyaaeldeen deyaaeldeen requested a review from ramya-rao-a July 7, 2021 03:07
@ghost ghost added Azure.Core EngSys This issue is impacting the engineering system. labels Jul 7, 2021
@deyaaeldeen deyaaeldeen requested a review from witemple-msft July 7, 2021 17:16
Copy link
Member

@xirzec xirzec left a comment

Choose a reason for hiding this comment

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

Thank you for working on this! I am very excited to get these scripts standardized (and perhaps have some tooling to keep them in sync.)

sdk/core/abort-controller/test/aborter.spec.ts Outdated Show resolved Hide resolved
sdk/core/core-amqp/package.json Show resolved Hide resolved
sdk/core/core-amqp/package.json Show resolved Hide resolved
@@ -35,29 +35,29 @@
],
"scripts": {
"audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit",
"build:samples": "echo skipped",
"build:samples": "echo Obsolete",
"build:test": "tsc -p . && rollup -c rollup.test.config.js 2>&1",
Copy link
Member

Choose a reason for hiding this comment

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

I think it's out of scope for this PR, but I'd love us to consider getting rid of this step. Having separate build steps for the lib and for tests causes a bunch of unnecessary churn in CI since usually we end up running tsc twice

Copy link
Member Author

Choose a reason for hiding this comment

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

Perhaps CI should run rushx build && rushx unit-test. cc @praveenkuttappan

sdk/core/core-client/package.json Show resolved Hide resolved
Copy link
Member

@xirzec xirzec left a comment

Choose a reason for hiding this comment

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

One last remark, but I think I'm good with trying this change out.

sdk/core/core-asynciterator-polyfill/package.json Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Azure.Core EngSys This issue is impacting the engineering system.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Script standardization for core to make them follow only Track2
4 participants