Skip to content

Commit

Permalink
chore: migrate to yarn v3 (#935)
Browse files Browse the repository at this point in the history
#### Details

This PR migrates the repo from Yarn v1 to Yarn v3 for dependency
management. The main migration followed the steps in [Yarn's migration
guide](https://yarnpkg.com/getting-started/migration) for a
non-zero-installs configuration, similar to the migrations in
accessibility-insights-service and accessibility-insights-action.

Besides the required/mechanical steps, this PR also includes:

* Updating the resolutions used by this repo to use versioned
resolutions, similar to
microsoft/accessibility-insights-action#1596
* Modifying the `test-resources` generator setup to work as a run script
from the root directory instead of using a separate `package.json` in
`src/test-resources/generator`. This avoided what would have otherwise
required a more complicated setup using either multiple checked in
copies of yarn or a more complicated workspace setup, and slightly
simplifies the steps for using the generator. I updated the README
instructions accordingly.
* The new `!dist/test-resources` entry in the `files` field of
`package.json` ensures that there is no change to the package
as-distributed because of this update.

As part of these changes, I verified manually that `yarn
generate-test-resources` regenerates the current versions of the test
resource files successfully.

##### Motivation

* Consistency with other repos
* Allows use of versioned resolutions (see
microsoft/accessibility-insights-action#1596 for
why we want them)

##### Context

Similar PRs in other repos:

* microsoft/accessibility-insights-service#2210
* microsoft/accessibility-insights-action#1559

#### Pull request checklist
<!-- If a checklist item is not applicable to this change, write "n/a"
in the checkbox -->
- [x] PR title respects [Conventional
Commits](https://www.conventionalcommits.org) (starts with `fix:`,
`feat:`, etc, and is suitable for user-facing release notes)
- [x] PR contains no breaking changes, **OR** description of both PR
**and final merge commit** starts with `BREAKING CHANGE:`
- [n/a] (if applicable) Addresses issue: #0000
- [n/a] Added relevant unit tests for your changes
- [x] Ran `yarn precheckin`
- [n/a] Verified code coverage for the changes made
  • Loading branch information
dbjorge authored Mar 29, 2023
1 parent b642f35 commit c84b061
Show file tree
Hide file tree
Showing 14 changed files with 9,714 additions and 6,984 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,12 @@ typings/
/dist/
/src/test-resources/generator/*.js
/test-results/

# yarn non-zero-installs setup
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.DS_Store
.github/
.yarn/
.prettierignore
**/*.gitattributes
**/*.gitignore
Expand Down
873 changes: 873 additions & 0 deletions .yarn/releases/yarn-3.5.0.cjs

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

nodeLinker: node-modules
yarnPath: .yarn/releases/yarn-3.5.0.cjs
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,23 @@ change, so we're waiting to change this until we would need to make a breaking c
To update the package and test cases to account for a new axe-core version:
1. Update the version of axe-core in `yarn.lock` (_not_ `package.json`); usually dependabot will cover this. If updating to the latest version, this can be accomplished using `yarn upgrade axe-core`.
1. In `package.json`, update the version numbers of the following components:
- `devDependencies` entries for `@axe-core/cli` and `@axe-core/puppeteer`
- `resolutions` entries for `axe-core` and `@axe-core/cli/chromedriver`
- **NOT** the `dependencies` entry for `@axe-core`!
1. Build the repo with:
```
yarn install
yarn build
```
1. Update the versions of @axe-core/cli, @axe-core/puppeteer, and axe-core in `src/test-resources/generator/package.json`
1. Generate test resource files for the new version with:
```
cd src/test-resources/generator
yarn install
yarn generate
yarn generate-test-resources
```
1. Manually compare the diff of `/src/test-resources/basic-axe-vPREVIOUS.sarif` and `/src/test-resources/basic-axe-vNEW.sarif`; the only differences should be the version numbers.
Expand Down
4 changes: 2 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
versionSpec: '14.18.3'
displayName: use node 14.18.3

- script: yarn install --frozen-lockfile
- script: yarn install --immutable
displayName: yarn install

- script: yarn lint
Expand All @@ -33,7 +33,7 @@ jobs:
- script: yarn build
displayName: yarn build

- script: yarn test -- --ci
- script: yarn test --ci
displayName: yarn test

- task: PublishTestResults@2
Expand Down
1 change: 1 addition & 0 deletions copyright-header.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
".gitattributes",
".gitignore",
".prettierignore",
".yarn/",
"src/test-resources/",
"test-results/",
"yarn.lock",
Expand Down
16 changes: 13 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,25 @@
"types": "dist/index.d.js",
"files": [
"dist/",
"!dist/test-resources/",
"LICENSE",
"README.md"
],
"engines": {
"node": ">= 8"
},
"packageManager": "[email protected]",
"dependencies": {
"@types/sarif": ">=2.1.1 <=2.1.4",
"axe-core": "^3.2.2 || ^4.0.0",
"yargs": "^17.0.0"
},
"devDependencies": {
"@axe-core/cli": "^4.6.0",
"@axe-core/puppeteer": "^4.6.0",
"@types/jest": "^27.4.0",
"@types/lodash": "^4.14.136",
"@types/node": "^14.0.1",
"@types/node": "^14.18.38",
"@types/yargs": "^17.0.8",
"@typescript-eslint/eslint-plugin": "^4.0.1",
"@typescript-eslint/parser": "^4.0.1",
Expand All @@ -32,14 +36,17 @@
"license-check-and-add": "^4.0.1",
"lodash": "^4.17.15",
"prettier": "^2.0.1",
"puppeteer": "^13.7.0",
"rimraf": "^4.0.4",
"semantic-release": "^19.0.2",
"ts-jest": "^27.0.2",
"typemoq": "^2.1.0",
"typescript": "^4.0.2"
},
"resolutions": {
"ansi-regex": "^5.0.1"
"@axe-core/cli/chromedriver@^109.0.0": "^111.0.0",
"ansi-regex@^4.1.0": "^5.0.1",
"axe-core": "4.6.3"
},
"scripts": {
"prebuild": "yarn clean",
Expand All @@ -53,7 +60,10 @@
"precheckin": "yarn format-check && yarn lint && yarn build && yarn test && yarn copyrightheaders",
"watch:build": "tsc -p . --watch",
"watch:test": "jest --watch --coverage false --colors",
"semantic-release": "semantic-release"
"semantic-release": "semantic-release",
"generate-test-resources": "yarn generate-axe-core-resources && yarn generate-axe-cli-resources",
"generate-axe-cli-resources": "node dist/test-resources/generator/generate-axe-cli-resources.js",
"generate-axe-core-resources": "node dist/test-resources/generator/generate-axe-core-resources.js"
},
"repository": {
"type": "git",
Expand Down
12 changes: 6 additions & 6 deletions src/test-resources/generator/generate-axe-cli-resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import * as url from 'url';

const axeCoreVersion = (axe as any).version;
const axeSourcePath = require.resolve('axe-core/axe.min.js');
const testResourcesDir = path.join(__dirname, '../');
const axeCliBin = `${__dirname}/node_modules/.bin/axe`;
const rootDir = path.join(__dirname, '..', '..', '..');
const testResourcesDir = path.join(rootDir, 'src', 'test-resources');

const testUrls: Record<string, string> = {
'w3citylights': 'https://www.w3.org/WAI/demos/bad/before/home.html',
Expand All @@ -18,16 +18,16 @@ const testUrls: Record<string, string> = {
function generateResources() {
for (const testUrlIdentifier of Object.keys(testUrls)) {
const testUrl = testUrls[testUrlIdentifier];
const axeCliVersion = child_process.execSync(`${axeCliBin} --version`).toString().trim();
const axeCliVersion = child_process.execSync(`yarn run axe --version`).toString().trim();
const axeCliOutputFile = path.join(testResourcesDir, `${testUrlIdentifier}-axe-v${axeCoreVersion}.axe-cli-v${axeCliVersion}.json`);
console.log(`Writing test resource: ${axeCliOutputFile}`);

const axeCliOutputFileRelativePath = path.relative(__dirname, axeCliOutputFile);
let axeCliCommand = `${axeCliBin} ${testUrl} --show-errors --save ${axeCliOutputFileRelativePath} --axe-source ${axeSourcePath}`;
const axeCliOutputFileRelativeToRoot = path.relative(rootDir, axeCliOutputFile);
let axeCliCommand = `yarn run axe ${testUrl} --show-errors --save ${axeCliOutputFileRelativeToRoot} --axe-source ${axeSourcePath}`;
if (testUrlIdentifier === 'basic') {
axeCliCommand += ' --rules document-title';
}
console.log(`Invoking @axe-core/cli v${axeCliVersion} with: ${axeCliCommand}`);
console.log(`Invoking @axe-core/cli v${axeCliVersion} with: ${axeCliCommand}`, { cwd: rootDir });

child_process.execSync(axeCliCommand);
}
Expand Down
8 changes: 4 additions & 4 deletions src/test-resources/generator/generate-axe-core-resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import * as fs from 'fs';
import * as path from 'path';
import * as Puppeteer from 'puppeteer';
import * as url from 'url';
import { convertAxeToSarif } from '../../../dist/index';
import { testResourceTimestampPlaceholder } from '../../../dist/test-resource-constants';
import { convertAxeToSarif } from '../../index';
import { testResourceTimestampPlaceholder } from '../../test-resource-constants';

const axeVersion: string = (axe as any).version;
const axeSource: string = axe.source

const testResourcesDir = path.join(__dirname, '../');
const rootDir = path.join(__dirname, '..', '..', '..');
const testResourcesDir = path.join(rootDir, 'src', 'test-resources');

const axeReporters: string[] = ['v1', 'v2', 'raw'];
const testUrls: Record<string, string> = {
Expand Down
22 changes: 0 additions & 22 deletions src/test-resources/generator/package.json

This file was deleted.

Loading

0 comments on commit c84b061

Please sign in to comment.