chore(repo): use root-level scripts

This commit is contained in:
Victor Savkin 2022-11-18 11:19:58 -05:00
parent bf4f6c0a76
commit ffd40af446
9 changed files with 544 additions and 757 deletions

View File

@ -176,7 +176,7 @@ jobs:
- run: npx nx-cloud start-ci-run --stop-agents-after="e2e"
- run:
name: Check Documentation
command: npx nx-cloud record yarn documentation
command: npx nx documentation --no-dte
no_output_timeout: 20m
- run:
name: Run Checks/Lint/Test/Build
@ -184,12 +184,12 @@ jobs:
command: |
pids=()
(npx nx-cloud record yarn check-imports &&
npx nx-cloud record yarn nx format:check --base=$NX_BASE --head=$NX_HEAD &&
npx nx-cloud record yarn check-commit &&
npx nx-cloud record yarn check-lock-files &&
npx nx-cloud record yarn nx workspace-lint &&
npx nx-cloud record yarn depcheck) &
(npx nx check-imports --no-dte &&
npx nx-cloud record -- nx format:check --base=$NX_BASE --head=$NX_HEAD &&
npx nx check-commit --no-dte &&
npx nx check-lock-files --no-dte &&
npx nx lint --no-dte &&
npx nx depcheck --no-dte ) &
pids+=($!)
yarn nx affected --target=lint --base=$NX_BASE --head=$NX_HEAD --parallel=3 &

View File

@ -14,6 +14,8 @@ packages/react/src/schematics/**/files/**/*.json
packages/jest/src/schematics/**/files/**/*.json
packages/**/schematics/**/files/**/*.html
packages/**/generators/**/files/**/*.html
nx-dev/nx-dev/.next/
docs/generated/
/.vscode
/.idea
/.github

View File

@ -250,7 +250,7 @@ Please follow the following guidelines:
- Debug with `node --inspect-brk ./node_modules/jest/bin/jest.js build/packages/angular/src/utils/ast-utils.spec.js`
- Make sure e2e tests pass (this can take a while, so you can always let CI check those) (`nx affected --target=e2e`)
- Target a specific e2e test with `nx e2e e2e-cypress`
- Make sure you run `yarn format`
- Make sure you run `nx format`
- Update documentation with `yarn documentation`. For documentation, check for spelling and grammatical errors.
- Update your commit message to follow the guidelines below (use `yarn commit` to automate compliance)
- `yarn check-commit` will check to make sure your commit messages are formatted correctly

File diff suppressed because it is too large Load Diff

View File

@ -35,24 +35,25 @@ In this case, you can mock it up.
Example:
```typescript
mockSchematicsForTesting({
'mycollection:myschematic': (tree, params) => {
tree.write('README.md');
},
});
mockSchematicsForTesting({
'mycollection:myschematic': (tree, params) => {
tree.write('README.md');
}
});
```
#### Parameters
| Name | Type |
| :----------- | :------- |
| Name | Type |
| :------ | :------ |
| `schematics` | `Object` |
#### Returns
`void`
---
___
### overrideCollectionResolutionForTesting
@ -67,38 +68,36 @@ This function can can be used to override the resolution behaviour.
Example:
```typescript
overrideCollectionResolutionForTesting({
'@nrwl/workspace': path.join(
__dirname,
'../../../../workspace/generators.json'
),
'@nrwl/angular': path.join(__dirname, '../../../../angular/generators.json'),
'@nrwl/linter': path.join(__dirname, '../../../../linter/generators.json'),
});
overrideCollectionResolutionForTesting({
'@nrwl/workspace': path.join(__dirname, '../../../../workspace/generators.json'),
'@nrwl/angular': path.join(__dirname, '../../../../angular/generators.json'),
'@nrwl/linter': path.join(__dirname, '../../../../linter/generators.json')
});
```
#### Parameters
| Name | Type |
| :------------ | :------- |
| Name | Type |
| :------ | :------ |
| `collections` | `Object` |
#### Returns
`void`
---
___
### wrapAngularDevkitSchematic
**wrapAngularDevkitSchematic**(`collectionName`, `generatorName`): (`host`: [`Tree`](../../devkit/index#tree), `generatorOptions`: { [k: string]: `any`; }) => `Promise`<`any`\>
**wrapAngularDevkitSchematic**(`collectionName`, `generatorName`): (`host`: [`Tree`](../../devkit/index#tree), `generatorOptions`: { [k: string]: `any`; }) => `Promise`<`any`\>
#### Parameters
| Name | Type |
| :--------------- | :------- |
| Name | Type |
| :------ | :------ |
| `collectionName` | `string` |
| `generatorName` | `string` |
| `generatorName` | `string` |
#### Returns
@ -108,10 +107,10 @@ overrideCollectionResolutionForTesting({
##### Parameters
| Name | Type |
| :----------------- | :-------------------------------- |
| `host` | [`Tree`](../../devkit/index#tree) |
| `generatorOptions` | `Object` |
| Name | Type |
| :------ | :------ |
| `host` | [`Tree`](../../devkit/index#tree) |
| `generatorOptions` | `Object` |
##### Returns

File diff suppressed because one or more lines are too long

13
nx.json
View File

@ -3,7 +3,6 @@
"affected": {
"defaultBase": "master"
},
"npmScope": "nrwl",
"tasksRunnerOptions": {
"default": {
"runner": "@nrwl/nx-cloud",
@ -25,10 +24,6 @@
}
}
},
"workspaceLayout": {
"libsDir": "",
"appsDir": ""
},
"namedInputs": {
"default": ["{projectRoot}/**/*", "sharedGlobals"],
"production": [
@ -86,11 +81,5 @@
"inputs": ["default", "^production", "{workspaceRoot}/.storybook/**/*"]
}
},
"generators": {
"@nrwl/react": {
"application": {
"babel": true
}
}
}
"defaultProject": "@nrwl/nx-source"
}

View File

@ -10,11 +10,9 @@
"check-format": "nx format:check --all",
"check-imports": "node ./scripts/check-imports.js",
"check-lock-files": "node ./scripts/check-lock-files.js",
"check-versions": "ts-node -P ./scripts/tsconfig.scripts.json ./scripts/check-versions.ts",
"check-documentation-map": "ts-node -P ./scripts/tsconfig.scripts.json ./scripts/documentation/map-link-checker.ts",
"e2e-start-local-registry": "node ./scripts/e2e-start-local-registry.js",
"e2e-build-package-publish": "ts-node -P ./scripts/tsconfig.e2e.json ./scripts/e2e-build-package-publish.ts",
"format": "nx format",
"nx-release": "ts-node -P ./scripts/tsconfig.scripts.json ./scripts/nx-release",
"prepublishOnly": "node ./scripts/update-package-group.js",
"version": "npx prettier lerna.json --write",
@ -23,7 +21,8 @@
"documentation": "ts-node -P scripts/tsconfig.scripts.json ./scripts/documentation/documentation.ts && yarn check-documentation-map",
"submit-plugin": "node ./scripts/submit-plugin.js",
"prepare": "is-ci || husky install",
"echo": "echo 123458"
"echo": "echo 123458",
"lint": "nx workspace-lint"
},
"devDependencies": {
"@angular-devkit/architect": "~0.1500.0",
@ -308,6 +307,17 @@
"**/xmlhttprequest-ssl": "~1.6.2",
"minimist": "^1.2.6",
"underscore": "^1.12.1"
},
"nx": {
"includeScripts": [
"echo",
"check-format",
"check-imports",
"check-lock-files",
"depcheck",
"documentation",
"lint"
]
}
}

View File

@ -1,196 +0,0 @@
/*
* This script checks if new versions of node modules are available.
* It uses naming conventions to transform constants to matching node module name.
*
* Usage:
* yarn check-versions [file|package]
*
* Positional arg:
* - [file]: relative or absolute file path to the versions file.
*
* Example:
* yarn check-versions react
*/
import { join, relative } from 'path';
import { gt } from 'semver';
import { readJsonSync, writeJsonSync } from 'fs-extra';
import * as chalk from 'chalk';
import { dasherize } from '../packages/workspace/src/utils/strings';
import * as glob from 'glob';
import { execSync } from 'child_process';
import { readFileSync, writeFileSync } from 'fs';
const root = join(__dirname, '..');
const excluded = ['nxVersion'];
const scoped = [
'babel',
'emotion',
'reduxjs',
'swc',
'testing-library',
'types',
];
try {
const files = process.argv[2]
? [normalize(process.argv[2])]
: glob.sync('packages/**/*/versions.ts').map((x) => relative(root, x));
checkFiles(files);
} catch (e) {
console.log(chalk.red(e.message));
process.exitCode = 1;
}
function normalize(x: string) {
if (x.endsWith('.ts')) {
return x;
} else {
return join('packages', x, 'src/utils/versions.ts');
}
}
// -----------------------------------------------------------------------------
function checkFiles(files: string[]) {
console.log(chalk.blue(`Checking versions in the following files...\n`));
console.log(` - ${files.join('\n - ')}\n`);
const maxFileNameLength = Math.max(...files.map((f) => f.length));
let hasError = false;
files.forEach((f) => {
const projectRoot = f.split('/src/')[0];
const migrationsPath = join(projectRoot, 'migrations.json');
const migrationsJson = readJsonSync(migrationsPath);
let versionsContent = readFileSync(f).toString();
const versions = getVersions(f);
const npmPackages = getPackages(versions);
const results = npmPackages.map(([p, v, o]) => getVersionData(p, v, o));
const logContext = `${f.padEnd(maxFileNameLength)}`;
const packageUpdates = {};
results.forEach((r) => {
if (r.outdated) {
console.log(
`${logContext}${chalk.bold(
r.package
)} has new version ${chalk.bold(r.latest)} (current: ${r.prev})`
);
versionsContent = versionsContent.replace(
`${r.variable} = '${r.prev}'`,
`${r.variable} = '${r.latest}'`
);
packageUpdates[r.package] = {
version: r.latest,
alwaysAddToPackageJson: false,
};
}
if (r.invalid) {
hasError = true;
console.log(
`${logContext} ⚠️ ${chalk.bold(r.package)} has an invalid version (${
r.prev
}) specified. Latest is ${r.latest}.`
);
}
});
if (Object.keys(packageUpdates).length > 0) {
migrationsJson.packageJsonUpdates['x.y.z'] = {
version: 'x.y.z',
packages: packageUpdates,
};
writeFileSync(f, versionsContent);
writeJsonSync(migrationsPath, migrationsJson, { spaces: 2 });
}
});
if (hasError) {
throw new Error('Invalid versions of packages found (please see above).');
}
}
function getVersions(path: string) {
const versionsPath =
path.startsWith('.') || path.startsWith('packages')
? join(__dirname, '..', path)
: path;
try {
return require(versionsPath);
} catch {
throw new Error(`Could not load ${path}. Please make sure it is valid.`);
}
}
function getPackages(versions: Record<string, string>): string[][] {
return Object.entries(versions).reduce((acc, [name, version]) => {
if (!excluded.includes(name)) {
const npmName = getNpmName(name);
acc.push([npmName, version, name]);
}
return acc;
}, [] as string[][]);
}
function getNpmName(name: string): string {
const dashedName = dasherize(name.replace(/Version$/, ''));
const scope = scoped.find((s) => dashedName.startsWith(`${s}-`));
if (scope) {
const rest = dashedName.split(`${scope}-`)[1];
return `@${scope}/${rest}`;
} else {
return dashedName;
}
}
function getVersionData(
p: string,
v: string,
o: string
): {
variable: string;
package: string;
outdated: boolean;
invalid: boolean;
latest: string;
prev?: string;
} {
try {
const latest = JSON.parse(
execSync(`npm view ${p} version --json --silent`, {
stdio: ['ignore'],
}).toString('utf-8')
);
if (gt(latest, v)) {
return {
variable: o,
package: p,
outdated: true,
invalid: false,
latest,
prev: v,
};
}
if (gt(v, latest)) {
return {
variable: o,
package: p,
outdated: false,
invalid: true,
latest,
prev: v,
};
}
} catch {
// ignored
}
return {
variable: o,
package: p,
outdated: false,
invalid: false,
latest: v,
};
}