Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(repo): fix generate package script #17300

Merged
merged 1 commit into from
Feb 28, 2025
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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"update-project-references": "yarn tsx ./scripts/updateProjectReferences.ts",
"verify-project-references": "yarn update-project-references --test",
"check-workspace-resolutions": "yarn tsx ./scripts/check-workspace-resolutions.ts",
"generate-package": "yarn tsx ./scripts/generatePackage.js",
"generate-package": "yarn workspace @trezor/scripts generate-package",
"deps": "rimraf **/node_modules && yarn",
"depcheck": "yarn nx affected --target=depcheck",
"list-outdated": "./scripts/list-outdated-dependencies/list-outdated-dependencies.sh",
Expand Down Expand Up @@ -139,7 +139,7 @@
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"tslib": "^2.6.2",
"tsx": "^4.16.3",
"tsx": "^4.19.3",
"typescript": "5.5.4",
"version-bump-prompt": "^6.1.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/blockchain-link-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@trezor/utxo-lib": "workspace:*"
},
"devDependencies": {
"tsx": "^4.16.3"
"tsx": "^4.19.3"
},
"peerDependencies": {
"tslib": "^2.6.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/blockchain-link-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@trezor/blockchain-link-types": "workspace:*",
"@trezor/eslint": "workspace:*",
"@trezor/type-utils": "workspace:*",
"tsx": "^4.16.3"
"tsx": "^4.19.3"
},
"peerDependencies": {
"tslib": "^2.6.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/blockchain-link/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"fs-extra": "^11.2.0",
"html-webpack-plugin": "^5.6.0",
"tiny-worker": "^2.3.0",
"tsx": "^4.16.3",
"tsx": "^4.19.3",
"webpack": "^5.97.1",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^5.0.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/connect-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@
"tslib": "^2.6.2"
},
"devDependencies": {
"tsx": "^4.16.3"
"tsx": "^4.19.3"
}
}
2 changes: 1 addition & 1 deletion packages/connect-examples/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
},
"dependencies": {
"@trezor/connect": "workspace:*",
"tsx": "^4.19.2"
"tsx": "^4.19.3"
}
}
2 changes: 1 addition & 1 deletion packages/connect-explorer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"eslint-plugin-mdx": "^3.1.5",
"html-webpack-plugin": "^5.6.0",
"rimraf": "^6.0.1",
"tsx": "^4.16.3",
"tsx": "^4.19.3",
"webpack": "^5.97.1",
"webpack-cli": "^5.1.4"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/connect-mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"prepublish": "yarn tsx ../../scripts/prepublish.js"
},
"devDependencies": {
"tsx": "^4.16.3"
"tsx": "^4.19.3"
},
"dependencies": {
"@trezor/connect": "workspace:^",
Expand Down
2 changes: 1 addition & 1 deletion packages/connect-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"rimraf": "^6.0.1",
"selfsigned": "^2.4.1",
"terser-webpack-plugin": "^5.3.11",
"tsx": "^4.16.3",
"tsx": "^4.19.3",
"webpack": "^5.97.1",
"webpack-cli": "^5.1.4",
"webpack-merge": "^6.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/connect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
"node-fetch": "^2.6.4",
"node-libs-browser": "^2.2.1",
"ts-node": "^10.9.2",
"tsx": "^4.16.3",
"tsx": "^4.19.3",
"web3-utils": "^4.3.2",
"webpack": "^5.97.1",
"ws": "^8.18.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/crypto-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@
"tslib": "^2.6.2"
},
"devDependencies": {
"tsx": "^4.16.3"
"tsx": "^4.19.3"
}
}
2 changes: 1 addition & 1 deletion packages/env-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@
}
},
"devDependencies": {
"tsx": "^4.16.3"
"tsx": "^4.19.3"
}
}
2 changes: 1 addition & 1 deletion packages/protobuf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"devDependencies": {
"protobufjs-cli": "^1.1.3",
"tsx": "^4.16.3"
"tsx": "^4.19.3"
},
"peerDependencies": {
"tslib": "^2.6.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
"tslib": "^2.6.2"
},
"devDependencies": {
"tsx": "^4.16.3"
"tsx": "^4.19.3"
}
}
2 changes: 1 addition & 1 deletion packages/schema-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@sinclair/typebox-codegen": "^0.10.4",
"@trezor/eslint": "workspace:*",
"ts-node": "^10.9.2",
"tsx": "^4.16.3"
"tsx": "^4.19.3"
},
"dependencies": {
"@sinclair/typebox": "^0.33.7",
Expand Down
2 changes: 1 addition & 1 deletion packages/suite-data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"postcss-modules-values": "^4.0.0",
"simple-git": "^3.27.0",
"style-loader": "^3.3.4",
"tsx": "^4.16.3",
"tsx": "^4.19.3",
"webpack": "^5.97.1",
"webpack-cli": "^5.1.4"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/suite-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"rimraf": "^6.0.1",
"stylelint": "^16.14.1",
"stylelint-config-standard": "^36.0.0",
"tsx": "^4.16.3",
"tsx": "^4.19.3",
"webpack": "^5.97.1",
"ws": "^8.18.0",
"yargs": "17.7.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/transport/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"jest": "29.7.0",
"jest-environment-node": "^29.7.0",
"ts-node": "^10.9.2",
"tsx": "^4.16.3"
"tsx": "^4.19.3"
},
"dependencies": {
"@trezor/protobuf": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
"devDependencies": {
"@trezor/eslint": "workspace:*",
"tsx": "^4.16.3"
"tsx": "^4.19.3"
},
"dependencies": {
"bignumber.js": "^9.1.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/utxo-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"@types/events": "^3.0.3",
"@types/wif": "^2.0.5",
"minimaldata": "^1.0.2",
"tsx": "^4.16.3"
"tsx": "^4.19.3"
},
"peerDependencies": {
"tslib": "^2.6.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/websocket-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@
"tslib": "^2.6.2"
},
"devDependencies": {
"tsx": "^4.16.3"
"tsx": "^4.19.3"
}
}
40 changes: 27 additions & 13 deletions scripts/generatePackage.js → scripts/generatePackage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import chalk from 'chalk';
import fs from 'fs';
import fsExtra from 'fs-extra';
import path from 'path';
import prettier from 'prettier';
import sortPackageJson from 'sort-package-json';

Expand All @@ -25,13 +26,20 @@ const scopes = {
templatePath: 'package-template/',
templatePackageJson: templatePackageJsonWeb,
},
};
} as const;

const exitWithErrorMessage = errorMessage => {
const exitWithErrorMessage = (errorMessage: string) => {
console.error(errorMessage);
process.exit(1);
};

const isValidScope = (scope: string): scope is keyof typeof scopes =>
Object.keys(scopes).includes(scope);

// Get the directory of the current file
const currentDir = path.dirname(__filename);
const rootDir = path.resolve(currentDir, '..');

(async () => {
const newPackage = process.argv?.[2];
if (!newPackage || typeof newPackage !== 'string' || !newPackage.includes('/')) {
Expand All @@ -44,19 +52,22 @@ const exitWithErrorMessage = errorMessage => {

const [packageScope, packageName] = newPackage.split('/');

const validScopes = Object.keys(scopes);
if (!validScopes.includes(packageScope)) {
if (!isValidScope(packageScope)) {
exitWithErrorMessage(
chalk.bold.red(
`Invalid scope ${packageScope}. Please use one of the supported scopes: ${validScopes.join(
', ',
)}`,
`Invalid scope ${packageScope}. Please use one of the supported scopes: ${Object.keys(
scopes,
).join(', ')}`,
),
);
}

const { path, templatePath, templatePackageJson } = scopes[packageScope];
const packagePath = `${path}/${packageName}`;
const {
path: scopePath,
templatePath,
templatePackageJson,
} = scopes[packageScope as keyof typeof scopes];
const packagePath = path.join(rootDir, scopePath, packageName);

const workspacesNames = Object.keys(getWorkspacesList());
if (fs.existsSync(packagePath)) {
Expand All @@ -76,12 +87,15 @@ const exitWithErrorMessage = errorMessage => {
});

const prettierConfig = await getPrettierConfig();
const serializeConfig = config =>
const serializeConfig = (config: Record<string, unknown>) =>
prettier.format(JSON.stringify(config).replace(/\\\\/g, '/'), prettierConfig);

try {
fsExtra.copySync(`./scripts/${templatePath}`, packagePath);
fs.writeFileSync(`${packagePath}/package.json`, await serializeConfig(packageJson));
const templateSourcePath = path.join(currentDir, templatePath);
fsExtra.copySync(templateSourcePath, packagePath);
fs.writeFileSync(
path.join(packagePath, 'package.json'),
await serializeConfig(packageJson),
);
} catch (error) {
exitWithErrorMessage(`${error}\n${chalk.bold.red('Package creation failed.')}`);
}
Expand Down
4 changes: 3 additions & 1 deletion scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"scripts": {
"depcheck": "yarn g:depcheck",
"type-check": "yarn g:tsc --build",
"run:analytics": "tsx githubAnalytics.ts"
"run:analytics": "tsx githubAnalytics.ts",
"generate-package": "tsx generatePackage.ts"
},
"dependencies": {
"@mobily/ts-belt": "^3.13.1",
Expand All @@ -16,6 +17,7 @@
"octokit": "3.1.2",
"prettier": "^3.3.2",
"sort-package-json": "^1.57.0",
"tsx": "^4.19.3",
"yargs": "17.7.2"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion suite-common/message-system/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"devDependencies": {
"@suite-common/test-utils": "workspace:*",
"@types/fs-extra": "^11.0.4",
"tsx": "^4.16.3"
"tsx": "^4.19.3"
},
"nx": {
"targets": {
Expand Down
Loading
Loading