Replace lerna-get-packages with our own implementation
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import * as depcheckAsync from 'depcheck';
|
||||
import lernaGetPackages = require('lerna-get-packages');
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { constants } from './constants';
|
||||
@@ -13,7 +12,7 @@ const IGNORE_PACKAGES = ['@0xproject/sol-compiler'];
|
||||
(async () => {
|
||||
utils.log('*** NOTE: Not all deps listed here are actually not required. ***');
|
||||
utils.log("*** `depcheck` isn't perfect so double check before actually removing any. ***\n");
|
||||
const lernaPackages = lernaGetPackages(constants.monorepoRootPath);
|
||||
const lernaPackages = utils.getLernaPackages(constants.monorepoRootPath);
|
||||
for (const lernaPackage of lernaPackages) {
|
||||
if (_.includes(IGNORE_PACKAGES, lernaPackage.package.name)) {
|
||||
continue; // skip
|
||||
|
20
packages/monorepo-scripts/src/globals.d.ts
vendored
20
packages/monorepo-scripts/src/globals.d.ts
vendored
@@ -13,23 +13,5 @@ declare module 'semver-sort' {
|
||||
const desc: (versions: string[]) => string[];
|
||||
}
|
||||
|
||||
declare interface LernaPackage {
|
||||
location: string;
|
||||
package: {
|
||||
private?: boolean;
|
||||
version: string;
|
||||
name: string;
|
||||
main?: string;
|
||||
scripts?: { [command: string]: string };
|
||||
config?: {
|
||||
additionalTsTypings?: string[];
|
||||
};
|
||||
};
|
||||
}
|
||||
declare function lernaGetPackages(path: string): LernaPackage[];
|
||||
// lerna-get-packages declarations
|
||||
declare module 'lerna-get-packages' {
|
||||
export = lernaGetPackages;
|
||||
}
|
||||
|
||||
declare module 'promisify-child-process';
|
||||
declare module '@lerna/project';
|
||||
|
@@ -4,6 +4,7 @@ import semver = require('semver');
|
||||
import semverSort = require('semver-sort');
|
||||
|
||||
import { constants } from './constants';
|
||||
import { LernaPackage } from './types';
|
||||
import { changelogUtils } from './utils/changelog_utils';
|
||||
import { npmUtils } from './utils/npm_utils';
|
||||
import { utils } from './utils/utils';
|
||||
|
@@ -11,7 +11,7 @@ import semverDiff = require('semver-diff');
|
||||
import semverSort = require('semver-sort');
|
||||
|
||||
import { constants } from './constants';
|
||||
import { PackageToVersionChange, SemVerIndex, VersionChangelog } from './types';
|
||||
import { LernaPackage, PackageToVersionChange, SemVerIndex, VersionChangelog } from './types';
|
||||
import { changelogUtils } from './utils/changelog_utils';
|
||||
import { utils } from './utils/utils';
|
||||
|
||||
|
@@ -1,7 +1,6 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import * as fs from 'fs';
|
||||
import lernaGetPackages = require('lerna-get-packages');
|
||||
import * as _ from 'lodash';
|
||||
import * as path from 'path';
|
||||
import { exec as execAsync } from 'promisify-child-process';
|
||||
@@ -11,7 +10,7 @@ import { utils } from './utils/utils';
|
||||
|
||||
(async () => {
|
||||
const monorepoRootPath = path.join(__dirname, '../../..');
|
||||
const lernaPackages = lernaGetPackages(monorepoRootPath);
|
||||
const lernaPackages = utils.getLernaPackages(monorepoRootPath);
|
||||
const installablePackages = _.filter(
|
||||
lernaPackages,
|
||||
lernaPackage =>
|
||||
|
@@ -40,3 +40,17 @@ export interface PackageRegistryJson {
|
||||
export interface GitTagsByPackageName {
|
||||
[packageName: string]: string[];
|
||||
}
|
||||
|
||||
export interface LernaPackage {
|
||||
location: string;
|
||||
package: {
|
||||
private?: boolean;
|
||||
version: string;
|
||||
name: string;
|
||||
main?: string;
|
||||
scripts?: { [command: string]: string };
|
||||
config?: {
|
||||
additionalTsTypings?: string[];
|
||||
};
|
||||
};
|
||||
}
|
||||
|
@@ -1,10 +1,10 @@
|
||||
import lernaGetPackages = require('lerna-get-packages');
|
||||
import * as fs from 'fs';
|
||||
import * as _ from 'lodash';
|
||||
import { exec as execAsync } from 'promisify-child-process';
|
||||
import semver = require('semver');
|
||||
|
||||
import { constants } from '../constants';
|
||||
import { GitTagsByPackageName, UpdatedPackage } from '../types';
|
||||
import { GitTagsByPackageName, LernaPackage, UpdatedPackage } from '../types';
|
||||
|
||||
import { changelogUtils } from './changelog_utils';
|
||||
|
||||
@@ -12,11 +12,41 @@ export const utils = {
|
||||
log(...args: any[]): void {
|
||||
console.log(...args); // tslint:disable-line:no-console
|
||||
},
|
||||
getLernaPackages(rootDir: string): LernaPackage[] {
|
||||
const rootPackageJsonString = fs.readFileSync(`${rootDir}/package.json`, 'utf8');
|
||||
const rootPackageJson = JSON.parse(rootPackageJsonString);
|
||||
if (_.isUndefined(rootPackageJson.workspaces)) {
|
||||
throw new Error(`Did not find 'workspaces' key in root package.json`);
|
||||
}
|
||||
const lernaPackages = [];
|
||||
for (const workspace of rootPackageJson.workspaces) {
|
||||
const workspacePath = workspace.replace('*', '');
|
||||
const subpackageNames = fs.readdirSync(`${rootDir}/${workspacePath}`);
|
||||
for (const subpackageName of subpackageNames) {
|
||||
if (_.startsWith(subpackageName, '.')) {
|
||||
continue;
|
||||
}
|
||||
const pathToPackageJson = `${rootDir}/${workspacePath}${subpackageName}`;
|
||||
try {
|
||||
const packageJsonString = fs.readFileSync(`${pathToPackageJson}/package.json`, 'utf8');
|
||||
const packageJson = JSON.parse(packageJsonString);
|
||||
const lernaPackage = {
|
||||
location: pathToPackageJson,
|
||||
package: packageJson,
|
||||
};
|
||||
lernaPackages.push(lernaPackage);
|
||||
} catch (err) {
|
||||
utils.log(`Couldn't find a 'package.json' for ${subpackageName}. Skipping...`);
|
||||
}
|
||||
}
|
||||
}
|
||||
return lernaPackages;
|
||||
},
|
||||
async getUpdatedLernaPackagesAsync(shouldIncludePrivate: boolean): Promise<LernaPackage[]> {
|
||||
const updatedPublicPackages = await utils.getLernaUpdatedPackagesAsync(shouldIncludePrivate);
|
||||
const updatedPackageNames = _.map(updatedPublicPackages, pkg => pkg.name);
|
||||
|
||||
const allLernaPackages = lernaGetPackages(constants.monorepoRootPath);
|
||||
const allLernaPackages = utils.getLernaPackages(constants.monorepoRootPath);
|
||||
const updatedPublicLernaPackages = _.filter(allLernaPackages, pkg => {
|
||||
return _.includes(updatedPackageNames, pkg.package.name);
|
||||
});
|
||||
|
Reference in New Issue
Block a user