Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"changelog:update": "yarn workspaces foreach --all --no-private --parallel --interlaced --verbose run changelog:update",
"changelog:validate": "yarn workspaces foreach --all --no-private --parallel --interlaced --verbose run changelog:validate",
"create-package": "tsx scripts/create-package",
"generate-method-action-types": "tsx scripts/generate-method-action-types.ts",
"generate-method-action-types": "yarn workspaces foreach --all --parallel --interlaced --verbose run generate-method-action-types",
"lint": "yarn lint:eslint && echo && yarn lint:misc --check && yarn constraints && yarn lint:dependencies && yarn lint:teams && yarn generate-method-action-types --check",
"lint:dependencies": "depcheck && yarn dedupe --check",
"lint:dependencies:fix": "depcheck && yarn dedupe",
Expand Down
2 changes: 2 additions & 0 deletions packages/analytics-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"build:docs": "typedoc",
"changelog:update": "../../scripts/update-changelog.sh @metamask/analytics-controller",
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/analytics-controller",
"generate-method-action-types": "tsx ../../scripts/generate-method-action-types.ts",
"publish:preview": "yarn npm publish --tag preview",
"since-latest-release": "../../scripts/since-latest-release.sh",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
Expand All @@ -59,6 +60,7 @@
"deepmerge": "^4.2.2",
"jest": "^29.7.0",
"ts-jest": "^29.2.5",
"tsx": "^4.20.5",
"typedoc": "^0.25.13",
"typedoc-plugin-missing-exports": "^2.0.0",
"typescript": "~5.3.3"
Expand Down
2 changes: 2 additions & 0 deletions packages/analytics-data-regulation-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"build:docs": "typedoc",
"changelog:update": "../../scripts/update-changelog.sh @metamask/analytics-data-regulation-controller",
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/analytics-data-regulation-controller",
"generate-method-action-types": "tsx ../../scripts/generate-method-action-types.ts",
"publish:preview": "yarn npm publish --tag preview",
"since-latest-release": "../../scripts/since-latest-release.sh",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
Expand All @@ -61,6 +62,7 @@
"jest": "^29.7.0",
"nock": "^13.3.1",
"ts-jest": "^29.2.5",
"tsx": "^4.20.5",
"typedoc": "^0.25.13",
"typedoc-plugin-missing-exports": "^2.0.0",
"typescript": "~5.3.3"
Expand Down
2 changes: 2 additions & 0 deletions packages/assets-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"build:docs": "typedoc",
"changelog:update": "../../scripts/update-changelog.sh @metamask/assets-controller",
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/assets-controller",
"generate-method-action-types": "tsx ../../scripts/generate-method-action-types.ts",
"publish:preview": "yarn npm publish --tag preview",
"since-latest-release": "../../scripts/since-latest-release.sh",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
Expand Down Expand Up @@ -82,6 +83,7 @@
"deepmerge": "^4.2.2",
"jest": "^29.7.0",
"ts-jest": "^29.2.5",
"tsx": "^4.20.5",
"typedoc": "^0.25.13",
"typedoc-plugin-missing-exports": "^2.0.0",
"typescript": "~5.3.3"
Expand Down
2 changes: 2 additions & 0 deletions packages/client-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"build:docs": "typedoc",
"changelog:update": "../../scripts/update-changelog.sh @metamask/client-controller",
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/client-controller",
"generate-method-action-types": "tsx ../../scripts/generate-method-action-types.ts",
"publish:preview": "yarn npm publish --tag preview",
"since-latest-release": "../../scripts/since-latest-release.sh",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
Expand All @@ -59,6 +60,7 @@
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"ts-jest": "^29.2.5",
"tsx": "^4.20.5",
"typedoc": "^0.25.13",
"typedoc-plugin-missing-exports": "^2.0.0",
"typescript": "~5.3.3"
Expand Down
2 changes: 2 additions & 0 deletions packages/compliance-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"build:docs": "typedoc",
"changelog:update": "../../scripts/update-changelog.sh @metamask/compliance-controller",
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/compliance-controller",
"generate-method-action-types": "tsx ../../scripts/generate-method-action-types.ts",
"publish:preview": "yarn npm publish --tag preview",
"since-latest-release": "../../scripts/since-latest-release.sh",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
Expand All @@ -63,6 +64,7 @@
"jest": "^29.7.0",
"nock": "^13.3.1",
"ts-jest": "^29.2.5",
"tsx": "^4.20.5",
"typedoc": "^0.25.13",
"typedoc-plugin-missing-exports": "^2.0.0",
"typescript": "~5.3.3"
Expand Down
2 changes: 2 additions & 0 deletions packages/connectivity-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"build:docs": "typedoc",
"changelog:update": "../../scripts/update-changelog.sh @metamask/connectivity-controller",
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/connectivity-controller",
"generate-method-action-types": "tsx ../../scripts/generate-method-action-types.ts",
"publish:preview": "yarn npm publish --tag preview",
"since-latest-release": "../../scripts/since-latest-release.sh",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
Expand All @@ -58,6 +59,7 @@
"deepmerge": "^4.2.2",
"jest": "^29.7.0",
"ts-jest": "^29.2.5",
"tsx": "^4.20.5",
"typedoc": "^0.25.13",
"typedoc-plugin-missing-exports": "^2.0.0",
"typescript": "~5.3.3"
Expand Down
2 changes: 2 additions & 0 deletions packages/core-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"build:docs": "typedoc",
"changelog:update": "../../scripts/update-changelog.sh @metamask/core-backend",
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/core-backend",
"generate-method-action-types": "tsx ../../scripts/generate-method-action-types.ts",
"publish:preview": "yarn npm publish --tag preview",
"since-latest-release": "../../scripts/since-latest-release.sh",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
Expand All @@ -65,6 +66,7 @@
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"ts-jest": "^29.2.5",
"tsx": "^4.20.5",
"typedoc": "^0.25.13",
"typedoc-plugin-missing-exports": "^2.0.0",
"typescript": "~5.3.3"
Expand Down
2 changes: 2 additions & 0 deletions packages/profile-metrics-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"build:docs": "typedoc",
"changelog:update": "../../scripts/update-changelog.sh @metamask/profile-metrics-controller",
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/profile-metrics-controller",
"generate-method-action-types": "tsx ../../scripts/generate-method-action-types.ts",
"publish:preview": "yarn npm publish --tag preview",
"since-latest-release": "../../scripts/since-latest-release.sh",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
Expand Down Expand Up @@ -68,6 +69,7 @@
"jest": "^29.7.0",
"nock": "^13.3.1",
"ts-jest": "^29.2.5",
"tsx": "^4.20.5",
"typedoc": "^0.25.13",
"typedoc-plugin-missing-exports": "^2.0.0",
"typescript": "~5.3.3"
Expand Down
2 changes: 2 additions & 0 deletions packages/ramps-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"changelog:update": "../../scripts/update-changelog.sh @metamask/ramps-controller",
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/ramps-controller",
"dev": "node dev-watch.js",
"generate-method-action-types": "tsx ../../scripts/generate-method-action-types.ts",
"publish:preview": "yarn npm publish --tag preview",
"since-latest-release": "../../scripts/since-latest-release.sh",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
Expand All @@ -61,6 +62,7 @@
"jest": "^29.7.0",
"nock": "^13.3.1",
"ts-jest": "^29.2.5",
"tsx": "^4.20.5",
"typedoc": "^0.25.13",
"typedoc-plugin-missing-exports": "^2.0.0",
"typescript": "~5.3.3"
Expand Down
2 changes: 2 additions & 0 deletions packages/sample-controllers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"build:docs": "typedoc",
"changelog:update": "../../scripts/update-changelog.sh @metamask/sample-controllers",
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/sample-controllers",
"generate-method-action-types": "tsx ../../scripts/generate-method-action-types.ts",
"publish:preview": "yarn npm publish --tag preview",
"since-latest-release": "../../scripts/since-latest-release.sh",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
Expand All @@ -62,6 +63,7 @@
"jest": "^29.7.0",
"nock": "^13.3.1",
"ts-jest": "^29.2.5",
"tsx": "^4.20.5",
"typedoc": "^0.25.13",
"typedoc-plugin-missing-exports": "^2.0.0",
"typescript": "~5.3.3"
Expand Down
2 changes: 2 additions & 0 deletions packages/storage-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"build:docs": "typedoc",
"changelog:update": "../../scripts/update-changelog.sh @metamask/storage-service",
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/storage-service",
"generate-method-action-types": "tsx ../../scripts/generate-method-action-types.ts",
"publish:preview": "yarn npm publish --tag preview",
"since-latest-release": "../../scripts/since-latest-release.sh",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
Expand All @@ -58,6 +59,7 @@
"deepmerge": "^4.2.2",
"jest": "^29.7.0",
"ts-jest": "^29.2.5",
"tsx": "^4.20.5",
"typedoc": "^0.25.13",
"typedoc-plugin-missing-exports": "^2.0.0",
"typescript": "~5.3.3"
Expand Down
76 changes: 45 additions & 31 deletions scripts/generate-method-action-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ type CommandLineArguments = {
* Whether to fix the action types files.
*/
fix: boolean;
/**
* Optional path to a specific controller to process.
*/
controllerPath: string;
};

/**
Expand All @@ -40,7 +44,22 @@ type CommandLineArguments = {
* @returns The command line arguments.
*/
async function parseCommandLineArguments(): Promise<CommandLineArguments> {
const { check, fix } = await yargs(process.argv.slice(2))
const {
check,
fix,
path: controllerPath,
} = await yargs(process.argv.slice(2))
.command(
'$0 [path]',
'Generate method action types for a controller messenger',
(yargsInstance) => {
yargsInstance.positional('path', {
type: 'string',
description: 'Path to the folder where controllers are located',
default: 'src',
});
},
)
.option('check', {
type: 'boolean',
description: 'Check if generated action type files are up to date',
Expand All @@ -59,7 +78,12 @@ async function parseCommandLineArguments(): Promise<CommandLineArguments> {
return true;
}).argv;

return { check, fix };
return {
check,
fix,
// TypeScript doesn't narrow the type of `controllerPath` even though we defined it as a string in yargs, so we need to cast it here.
controllerPath: controllerPath as string,
};
}

/**
Expand Down Expand Up @@ -181,11 +205,11 @@ async function checkActionTypesFiles(
* Main entry point for the script.
*/
async function main(): Promise<void> {
const { fix } = await parseCommandLineArguments();
const { fix, controllerPath } = await parseCommandLineArguments();

console.log('🔍 Searching for controllers with MESSENGER_EXPOSED_METHODS...');

const controllers = await findControllersWithExposedMethods();
const controllers = await findControllersWithExposedMethods(controllerPath);

if (controllers.length === 0) {
console.log('⚠️ No controllers found with MESSENGER_EXPOSED_METHODS');
Expand Down Expand Up @@ -237,43 +261,33 @@ async function isDirectory(pathValue: string): Promise<boolean> {
/**
* Finds all controller files that have MESSENGER_EXPOSED_METHODS constants.
*
* @param controllerPath - Path to the folder where controllers are located.
* @returns A list of controller information objects.
*/
async function findControllersWithExposedMethods(): Promise<ControllerInfo[]> {
const packagesDir = path.resolve(__dirname, '../packages');
async function findControllersWithExposedMethods(
controllerPath: string,
): Promise<ControllerInfo[]> {
const srcPath = path.resolve(process.cwd(), controllerPath);
const controllers: ControllerInfo[] = [];

const packageDirs = await fs.promises.readdir(packagesDir, {
withFileTypes: true,
});

for (const packageDir of packageDirs) {
if (!packageDir.isDirectory()) {
continue;
}
if (!(await isDirectory(srcPath))) {
throw new Error(`The specified path is not a directory: ${srcPath}`);
}

const packagePath = path.join(packagesDir, packageDir.name);
const srcPath = path.join(packagePath, 'src');
const srcFiles = await fs.promises.readdir(srcPath);

if (!(await isDirectory(srcPath))) {
for (const file of srcFiles) {
if (!file.endsWith('.ts') || file.endsWith('.test.ts')) {
continue;
}

const srcFiles = await fs.promises.readdir(srcPath);

for (const file of srcFiles) {
if (!file.endsWith('.ts') || file.endsWith('.test.ts')) {
continue;
}

const filePath = path.join(srcPath, file);
const content = await fs.promises.readFile(filePath, 'utf8');
const filePath = path.join(srcPath, file);
const content = await fs.promises.readFile(filePath, 'utf8');

if (content.includes('MESSENGER_EXPOSED_METHODS')) {
const controllerInfo = await parseControllerFile(filePath);
if (controllerInfo) {
controllers.push(controllerInfo);
}
if (content.includes('MESSENGER_EXPOSED_METHODS')) {
const controllerInfo = await parseControllerFile(filePath);
if (controllerInfo) {
controllers.push(controllerInfo);
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2415,6 +2415,7 @@ __metadata:
deepmerge: "npm:^4.2.2"
jest: "npm:^29.7.0"
ts-jest: "npm:^29.2.5"
tsx: "npm:^4.20.5"
typedoc: "npm:^0.25.13"
typedoc-plugin-missing-exports: "npm:^2.0.0"
typescript: "npm:~5.3.3"
Expand All @@ -2436,6 +2437,7 @@ __metadata:
jest: "npm:^29.7.0"
nock: "npm:^13.3.1"
ts-jest: "npm:^29.2.5"
tsx: "npm:^4.20.5"
typedoc: "npm:^0.25.13"
typedoc-plugin-missing-exports: "npm:^2.0.0"
typescript: "npm:~5.3.3"
Expand Down Expand Up @@ -2542,6 +2544,7 @@ __metadata:
jest: "npm:^29.7.0"
lodash: "npm:^4.17.21"
ts-jest: "npm:^29.2.5"
tsx: "npm:^4.20.5"
typedoc: "npm:^0.25.13"
typedoc-plugin-missing-exports: "npm:^2.0.0"
typescript: "npm:~5.3.3"
Expand Down Expand Up @@ -2871,6 +2874,7 @@ __metadata:
jest: "npm:^29.7.0"
jest-environment-jsdom: "npm:^29.7.0"
ts-jest: "npm:^29.2.5"
tsx: "npm:^4.20.5"
typedoc: "npm:^0.25.13"
typedoc-plugin-missing-exports: "npm:^2.0.0"
typescript: "npm:~5.3.3"
Expand All @@ -2894,6 +2898,7 @@ __metadata:
nock: "npm:^13.3.1"
reselect: "npm:^5.1.1"
ts-jest: "npm:^29.2.5"
tsx: "npm:^4.20.5"
typedoc: "npm:^0.25.13"
typedoc-plugin-missing-exports: "npm:^2.0.0"
typescript: "npm:~5.3.3"
Expand Down Expand Up @@ -2932,6 +2937,7 @@ __metadata:
deepmerge: "npm:^4.2.2"
jest: "npm:^29.7.0"
ts-jest: "npm:^29.2.5"
tsx: "npm:^4.20.5"
typedoc: "npm:^0.25.13"
typedoc-plugin-missing-exports: "npm:^2.0.0"
typescript: "npm:~5.3.3"
Expand Down Expand Up @@ -3012,6 +3018,7 @@ __metadata:
jest: "npm:^29.7.0"
jest-environment-jsdom: "npm:^29.7.0"
ts-jest: "npm:^29.2.5"
tsx: "npm:^4.20.5"
typedoc: "npm:^0.25.13"
typedoc-plugin-missing-exports: "npm:^2.0.0"
typescript: "npm:~5.3.3"
Expand Down Expand Up @@ -4488,6 +4495,7 @@ __metadata:
jest: "npm:^29.7.0"
nock: "npm:^13.3.1"
ts-jest: "npm:^29.2.5"
tsx: "npm:^4.20.5"
typedoc: "npm:^0.25.13"
typedoc-plugin-missing-exports: "npm:^2.0.0"
typescript: "npm:~5.3.3"
Expand Down Expand Up @@ -4570,6 +4578,7 @@ __metadata:
jest: "npm:^29.7.0"
nock: "npm:^13.3.1"
ts-jest: "npm:^29.2.5"
tsx: "npm:^4.20.5"
typedoc: "npm:^0.25.13"
typedoc-plugin-missing-exports: "npm:^2.0.0"
typescript: "npm:~5.3.3"
Expand Down Expand Up @@ -4652,6 +4661,7 @@ __metadata:
jest: "npm:^29.7.0"
nock: "npm:^13.3.1"
ts-jest: "npm:^29.2.5"
tsx: "npm:^4.20.5"
typedoc: "npm:^0.25.13"
typedoc-plugin-missing-exports: "npm:^2.0.0"
typescript: "npm:~5.3.3"
Expand Down Expand Up @@ -4960,6 +4970,7 @@ __metadata:
deepmerge: "npm:^4.2.2"
jest: "npm:^29.7.0"
ts-jest: "npm:^29.2.5"
tsx: "npm:^4.20.5"
typedoc: "npm:^0.25.13"
typedoc-plugin-missing-exports: "npm:^2.0.0"
typescript: "npm:~5.3.3"
Expand Down