scripts: refactor to use get-packages

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2022-01-07 13:30:59 +01:00
parent 7946418729
commit 61261079cc
3 changed files with 18 additions and 22 deletions
+1
View File
@@ -55,6 +55,7 @@
},
"version": "1.0.0",
"dependencies": {
"@manypkg/get-packages": "^1.1.3",
"@microsoft/api-documenter": "^7.13.77",
"@microsoft/api-extractor": "^7.19.2",
"@microsoft/api-extractor-model": "^7.15.1",
+13 -16
View File
@@ -20,13 +20,10 @@ const { resolve: resolvePath } = require('path');
// Cba polluting root package.json, we'll have this
// eslint-disable-next-line import/no-extraneous-dependencies
const chalk = require('chalk');
const { getPackages } = require('@manypkg/get-packages');
async function main() {
// This is from lerna, and cba polluting root package.json
// eslint-disable-next-line import/no-extraneous-dependencies
const { Project } = require('@lerna/project');
const project = new Project(resolvePath('.'));
const packages = await project.getPackages();
const { packages } = await getPackages(resolvePath('.'));
let hadErrors = false;
@@ -38,7 +35,7 @@ async function main() {
if (errors.length) {
hadErrors = true;
console.error(
`Incorrect type dependencies in ${chalk.yellow(pkg.name)}:`,
`Incorrect type dependencies in ${chalk.yellow(pkg.packageJson.name)}:`,
);
for (const error of errors) {
if (error.name === 'WrongDepError') {
@@ -71,8 +68,8 @@ async function main() {
function shouldCheckTypes(pkg) {
return (
!pkg.private &&
pkg.get('types') &&
fs.existsSync(resolvePath(pkg.location, 'dist/index.d.ts'))
pkg.packageJson.types &&
fs.existsSync(resolvePath(pkg.dir, 'dist/index.d.ts'))
);
}
@@ -82,7 +79,7 @@ function shouldCheckTypes(pkg) {
*/
function checkTypes(pkg) {
const typeDecl = fs.readFileSync(
resolvePath(pkg.location, 'dist/index.d.ts'),
resolvePath(pkg.dir, 'dist/index.d.ts'),
'utf8',
);
const allDeps = (typeDecl.match(/from '.*'/g) || [])
@@ -114,21 +111,21 @@ function checkTypes(pkg) {
*/
function findTypesPackage(dep, pkg) {
try {
require.resolve(`@types/${dep}/package.json`, { paths: [pkg.location] });
require.resolve(`@types/${dep}/package.json`, { paths: [pkg.dir] });
return `@types/${dep}`;
} catch {
try {
require.resolve(dep, { paths: [pkg.location] });
require.resolve(dep, { paths: [pkg.dir] });
return undefined;
} catch {
try {
// Some type-only modules don't have a working main field, so try resolving package.json too
require.resolve(`${dep}/package.json`, { paths: [pkg.location] });
require.resolve(`${dep}/package.json`, { paths: [pkg.dir] });
return undefined;
} catch {
try {
// Finally check if it's just a .d.ts file
require.resolve(`${dep}.d.ts`, { paths: [pkg.location] });
require.resolve(`${dep}.d.ts`, { paths: [pkg.dir] });
return undefined;
} catch {
throw mkErr('MissingDepError', `No types for ${dep}`, { dep });
@@ -142,10 +139,10 @@ function findTypesPackage(dep, pkg) {
* Figures out what type dependencies are missing, or should be moved between dep types
*/
function findTypeDepErrors(typeDeps, pkg) {
const devDeps = mkTypeDepSet(pkg.get('devDependencies'));
const devDeps = mkTypeDepSet(pkg.packageJson.devDependencies);
const deps = mkTypeDepSet({
...pkg.get('dependencies'),
...pkg.get('peerDependencies'),
...pkg.packageJson.dependencies,
...pkg.packageJson.peerDependencies,
});
const errors = [];
+4 -6
View File
@@ -17,8 +17,7 @@
const path = require('path');
const childProcess = require('child_process');
// eslint-disable-next-line import/no-extraneous-dependencies
const { Project } = require('@lerna/project');
const { getPackages } = require('@manypkg/get-packages');
// Prepare a release of the provided packages, e.g. @backstage/core
async function main(args) {
@@ -28,11 +27,10 @@ async function main(args) {
process.exit(1);
}
const project = new Project(__dirname);
const packages = await project.getPackages();
const { packages } = await getPackages(__dirname);
const ignoreArgs = packages
.filter(p => !args.includes(p.name))
.flatMap(p => ['--ignore', p.name]);
.filter(p => !args.includes(p.packageJson.name))
.flatMap(p => ['--ignore', p.packageJson.name]);
const { status } = childProcess.spawnSync(
'yarn',