refactor(connect): new replace-imports.sh script using babel

This commit is contained in:
Jiri Zbytovsky
2025-11-26 19:36:02 +01:00
committed by Jiri Zbytovsky
parent e1c0af9cbd
commit 2128d273f3
37 changed files with 213 additions and 130 deletions

View File

@@ -15,7 +15,7 @@
"test:unit": "yarn g:jest -c ../../jest.config.base.js",
"depcheck": "yarn g:depcheck",
"type-check": "yarn g:tsc --build",
"build:lib": "yarn g:rimraf lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/replace-imports.sh ./lib"
"build:lib": "yarn g:rimraf lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/publish/replace-imports.sh ./lib cjs"
},
"dependencies": {
"@trezor/env-utils": "workspace:*",

View File

@@ -9,7 +9,7 @@
"depcheck": "yarn g:depcheck",
"type-check": "yarn g:tsc --build",
"dev": "yarn g:tsx watch ./src/index.ts",
"build": "yarn g:rimraf ./lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/replace-imports.sh ./lib",
"build": "yarn g:rimraf ./lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/publish/replace-imports.sh ./lib cjs",
"start": "node ./lib/index.js"
},
"dependencies": {

View File

@@ -14,9 +14,9 @@
"scripts": {
"depcheck": "yarn g:depcheck",
"type-check": "yarn g:tsc --build",
"build:lib": "yarn g:rimraf ./lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/replace-imports.sh ./lib",
"prepublishOnly": "yarn tsx ../../scripts/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/prepublish.js"
"build:lib": "yarn g:rimraf ./lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/publish/replace-imports.sh ./lib cjs",
"prepublishOnly": "yarn tsx ../../scripts/publish/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/publish/prepublish.js"
},
"dependencies": {
"@trezor/utils": "workspace:*",

View File

@@ -15,9 +15,9 @@
"test:unit": "yarn g:jest -c ../../jest.config.base.js",
"depcheck": "yarn g:depcheck",
"type-check": "yarn g:tsc --build",
"build:lib": "yarn g:rimraf ./lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/replace-imports.sh ./lib",
"prepublishOnly": "yarn tsx ../../scripts/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/prepublish.js"
"build:lib": "yarn g:rimraf ./lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/publish/replace-imports.sh ./lib cjs",
"prepublishOnly": "yarn tsx ../../scripts/publish/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/publish/prepublish.js"
},
"dependencies": {
"@mobily/ts-belt": "^3.13.1",

View File

@@ -48,15 +48,15 @@
"dev": "webpack serve --config ./webpack/dev.js",
"dev:electrum": "yarn g:tsx watch ./src/workers/electrum/devrun.ts",
"dev:module": "USE_MODULES=true webpack serve --config ./webpack/dev.js",
"build:lib": "yarn g:rimraf lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/replace-imports.sh ./lib",
"build:lib": "yarn g:rimraf lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/publish/replace-imports.sh ./lib cjs",
"build:workers": "yarn g:rimraf build && yarn build:workers-web && yarn build:workers-module",
"build:workers-web": "webpack --config ./webpack/workers.web.js",
"build:workers-module": "webpack --config ./webpack/workers.module.js",
"test:unit": "yarn g:jest --verbose -c jest.config.unit.js",
"test:integration": "yarn g:jest -c jest.config.integration.js",
"type-check": "yarn g:tsc --build tsconfig.json",
"prepublishOnly": "yarn tsx ../../scripts/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/prepublish.js",
"prepublishOnly": "yarn tsx ../../scripts/publish/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/publish/prepublish.js",
"depcheck": "yarn g:depcheck"
},
"devDependencies": {

View File

@@ -14,7 +14,7 @@
"scripts": {
"depcheck": "yarn g:depcheck",
"type-check": "yarn g:tsc --build",
"build:lib": "yarn g:rimraf lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/replace-imports.sh ./lib"
"build:lib": "yarn g:rimraf lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/publish/replace-imports.sh ./lib cjs"
},
"dependencies": {
"@trezor/analytics": "workspace:*"

View File

@@ -32,10 +32,10 @@
},
"scripts": {
"test:unit": "yarn g:jest",
"build:lib": "yarn g:rimraf lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/replace-imports.sh ./lib",
"build:lib": "yarn g:rimraf lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/publish/replace-imports.sh ./lib cjs",
"type-check": "yarn g:tsc --build tsconfig.json",
"prepublishOnly": "yarn tsx ../../scripts/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/prepublish.js",
"prepublishOnly": "yarn tsx ../../scripts/publish/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/publish/prepublish.js",
"validate-releases.json": "./scripts/check-all-firmware-revisions.sh",
"depcheck": "yarn g:depcheck"
},

View File

@@ -14,9 +14,9 @@
"scripts": {
"depcheck": "yarn g:depcheck",
"type-check": "yarn g:tsc --build",
"build:lib": "yarn g:rimraf ./lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/replace-imports.sh ./lib",
"prepublishOnly": "yarn tsx ../../scripts/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/prepublish.js"
"build:lib": "yarn g:rimraf ./lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/publish/replace-imports.sh ./lib cjs",
"prepublishOnly": "yarn tsx ../../scripts/publish/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/publish/prepublish.js"
},
"devDependencies": {
"tsx": "^4.20.3"

View File

@@ -45,8 +45,8 @@
"test:unit": "yarn g:jest -c ../../jest.config.base.js",
"type-check": "yarn g:tsc --build tsconfig.json",
"build:lib": "yarn build:lib:cjs && yarn build:lib:esm",
"build:lib:cjs": "yarn g:rimraf ./lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/replace-imports.sh ./lib",
"build:lib:esm": "yarn g:rimraf ./libESM && yarn g:tsc --build tsconfig.libESM.json && ../../scripts/replace-imports.sh ./libESM libESM",
"build:lib:cjs": "yarn g:rimraf ./lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/publish/replace-imports.sh ./lib cjs",
"build:lib:esm": "yarn g:rimraf ./libESM && yarn g:tsc --build tsconfig.libESM.json && ../../scripts/publish/replace-imports.sh ./libESM esm",
"depcheck": "yarn g:depcheck"
}
}

View File

@@ -50,8 +50,8 @@
"test:unit": "jest -c ../../jest.config.base.js",
"type-check": "yarn g:tsc --build tsconfig.json",
"build:lib": "yarn build:lib:cjs && yarn build:lib:esm",
"build:lib:cjs": "yarn g:rimraf ./lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/replace-imports.sh ./lib",
"build:lib:esm": "yarn g:rimraf ./libESM && yarn g:tsc --build tsconfig.libESM.json && ../../scripts/replace-imports.sh ./libESM libESM",
"build:lib:cjs": "yarn g:rimraf ./lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/publish/replace-imports.sh ./lib cjs",
"build:lib:esm": "yarn g:rimraf ./libESM && yarn g:tsc --build tsconfig.libESM.json && ../../scripts/publish/replace-imports.sh ./libESM esm",
"depcheck": "yarn g:depcheck"
}
}

View File

@@ -32,14 +32,14 @@
"depcheck": "yarn g:depcheck",
"type-check": "yarn g:tsc --build",
"test:unit": "yarn g:jest",
"build:lib": "yarn g:rimraf ./lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/replace-imports.sh ./lib && cp ./src/webextension/trezor-usb-permissions.html ./lib/webextension/trezor-usb-permissions.html",
"build:lib": "yarn g:rimraf ./lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/publish/replace-imports.sh ./lib cjs && cp ./src/webextension/trezor-usb-permissions.html ./lib/webextension/trezor-usb-permissions.html",
"dev": "yarn g:rimraf build && TS_NODE_PROJECT=\"tsconfig.lib.json\" yarn webpack --config ./webpack/dev.webpack.config.ts",
"build:inline": "TS_NODE_PROJECT=\"tsconfig.lib.json\" webpack --config ./webpack/inline.webpack.config.ts",
"build:webextension": "TS_NODE_PROJECT=\"tsconfig.lib.json\" webpack --config ./webpack/prod.webpack.config.ts",
"build": "rm -rf build && yarn build:inline && yarn build:webextension",
"test:e2e": "yarn playwright install && yarn xvfb-maybe -- playwright test --config=./e2e/playwright.config.ts",
"prepublishOnly": "yarn tsx ../../scripts/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/prepublish.js"
"prepublishOnly": "yarn tsx ../../scripts/publish/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/publish/prepublish.js"
},
"dependencies": {
"@trezor/connect": "workspace:*",

View File

@@ -30,7 +30,7 @@
"!lib/proxy"
],
"scripts": {
"build:lib": "yarn g:rimraf ./lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/replace-imports.sh ./lib",
"build:lib": "yarn g:rimraf ./lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/publish/replace-imports.sh ./lib cjs",
"build:content-script": "TS_NODE_PROJECT=\"tsconfig.lib.json\" webpack --config ./webpack/content-script.webpack.config.ts",
"build:inline": "TS_NODE_PROJECT=\"tsconfig.lib.json\" webpack --config ./webpack/inline.webpack.config.ts",
"build": "yarn g:rimraf build && yarn build:content-script && yarn build:inline && node ./webpack/inline-content-script.js",

View File

@@ -55,7 +55,7 @@
"test:unit": "jest --version && jest",
"depcheck": "yarn g:depcheck",
"type-check": "yarn g:tsc --build",
"build:lib": "yarn g:rimraf ./lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/replace-imports.sh ./lib",
"build:lib": "yarn g:rimraf ./lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/publish/replace-imports.sh ./lib cjs",
"version:prerelease": "yarn g:tsx scripts/bump-version.ts prerelease",
"version:patch": "yarn g:tsx scripts/bump-version.ts patch",
"version:prepatch": "yarn g:tsx scripts/bump-version.ts prepatch",
@@ -64,8 +64,8 @@
"version:major": "yarn g:tsx scripts/bump-version.ts major",
"test:e2e:web": "ts-node -O '{\"module\": \"commonjs\", \"moduleResolution\": \"node\"}' ./e2e/run.ts web",
"test:e2e:node": "ts-node -O '{\"module\": \"commonjs\", \"moduleResolution\": \"node\"}' ./e2e/run.ts node",
"prepublishOnly": "yarn tsx ../../scripts/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/prepublish.js"
"prepublishOnly": "yarn tsx ../../scripts/publish/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/publish/prepublish.js"
},
"dependencies": {
"@ethereumjs/common": "^10.1.0",

View File

@@ -28,11 +28,11 @@
"main": "lib/index.js"
},
"scripts": {
"build:lib": "yarn g:rimraf lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/replace-imports.sh ./lib",
"build:lib": "yarn g:rimraf lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/publish/replace-imports.sh ./lib cjs",
"depcheck": "yarn g:depcheck",
"type-check": "yarn g:tsc --build",
"prepublishOnly": "yarn tsx ../../scripts/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/prepublish.js"
"prepublishOnly": "yarn tsx ../../scripts/publish/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/publish/prepublish.js"
},
"peerDependencies": {
"tslib": "^2.6.2"

View File

@@ -32,14 +32,14 @@
],
"scripts": {
"build:lib": "yarn build:lib:cjs && yarn build:lib:esm",
"build:lib:cjs": "yarn g:rimraf ./lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/replace-imports.sh ./lib",
"build:lib:esm": "yarn g:rimraf ./libESM && yarn g:tsc --build tsconfig.libESM.json && ../../scripts/replace-imports.sh ./libESM libESM",
"build:lib:cjs": "yarn g:rimraf ./lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/publish/replace-imports.sh ./lib cjs",
"build:lib:esm": "yarn g:rimraf ./libESM && yarn g:tsc --build tsconfig.libESM.json && ../../scripts/publish/replace-imports.sh ./libESM esm",
"depcheck": "yarn g:depcheck",
"type-check": "yarn g:tsc --build",
"test:unit": "yarn g:jest",
"lint:js": "yarn g:eslint '**/*.{ts,tsx,js}'",
"prepublishOnly": "yarn tsx ../../scripts/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/prepublish.js"
"prepublishOnly": "yarn tsx ../../scripts/publish/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/publish/prepublish.js"
},
"dependencies": {
"@noble/curves": "^2.0.1",

View File

@@ -12,12 +12,12 @@
"!**/*.map"
],
"scripts": {
"build:lib": "yarn g:rimraf -rf lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/replace-imports.sh ./lib",
"build:lib": "yarn g:rimraf -rf lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/publish/replace-imports.sh ./lib cjs",
"depcheck": "yarn g:depcheck",
"type-check": "yarn g:tsc --build",
"test:unit": "yarn g:jest -c ../../jest.config.base.js --passWithNoTests",
"prepublishOnly": "yarn tsx ../../scripts/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/prepublish.js"
"prepublishOnly": "yarn tsx ../../scripts/publish/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/publish/prepublish.js"
},
"devDependencies": {
"tsx": "^4.20.3"

View File

@@ -25,9 +25,9 @@
"type-check": "yarn g:tsc --build",
"test:unit": "yarn g:jest",
"test-unit:watch": "yarn g:jest -o --watch",
"build:lib": "yarn g:rimraf ./lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/replace-imports.sh ./lib",
"prepublishOnly": "yarn tsx ../../scripts/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/prepublish.js"
"build:lib": "yarn g:rimraf ./lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/publish/replace-imports.sh ./lib cjs",
"prepublishOnly": "yarn tsx ../../scripts/publish/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/publish/prepublish.js"
},
"dependencies": {
"ua-parser-js": "^2.0.4"

View File

@@ -27,11 +27,11 @@
"test:unit": "yarn g:jest -c ../../jest.config.base.js",
"depcheck": "yarn g:depcheck",
"type-check": "yarn g:tsc --build",
"build:lib": "yarn g:rimraf ./lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/replace-imports.sh ./lib",
"build:lib": "yarn g:rimraf ./lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/publish/replace-imports.sh ./lib cjs",
"update:schema": "yarn workspace @trezor/schema-utils codegen $(pwd)/src/messages.ts > src/messages-schema.ts && yarn g:eslint --fix src/messages-schema.ts && yarn g:prettier --write src/messages-schema.ts",
"update:protobuf": "./scripts/protobuf-build.sh",
"prepublishOnly": "yarn tsx ../../scripts/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/prepublish.js"
"prepublishOnly": "yarn tsx ../../scripts/publish/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/publish/prepublish.js"
},
"dependencies": {
"@trezor/schema-utils": "workspace:*",

View File

@@ -23,9 +23,9 @@
"test:unit": "yarn g:jest -c ../../jest.config.base.js",
"depcheck": "yarn g:depcheck",
"type-check": "yarn g:tsc --build",
"build:lib": "yarn g:rimraf ./lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/replace-imports.sh ./lib",
"prepublishOnly": "yarn tsx ../../scripts/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/prepublish.js"
"build:lib": "yarn g:rimraf ./lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/publish/replace-imports.sh ./lib cjs",
"prepublishOnly": "yarn tsx ../../scripts/publish/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/publish/prepublish.js"
},
"peerDependencies": {
"tslib": "^2.6.2"

View File

@@ -15,10 +15,10 @@
"test:unit": "yarn g:jest",
"depcheck": "yarn g:depcheck",
"type-check": "yarn g:tsc --build",
"build:lib": "yarn g:rimraf ./lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/replace-imports.sh ./lib",
"build:lib": "yarn g:rimraf ./lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/publish/replace-imports.sh ./lib cjs",
"codegen": "ts-node --skip-project ./src/codegen.ts",
"prepublishOnly": "yarn tsx ../../scripts/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/prepublish.js"
"prepublishOnly": "yarn tsx ../../scripts/publish/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/publish/prepublish.js"
},
"devDependencies": {
"@sinclair/typebox-codegen": "^0.10.4",

View File

@@ -46,11 +46,11 @@
"scripts": {
"depcheck": "yarn g:depcheck",
"type-check": "yarn g:tsc --build tsconfig.json",
"build:lib": "yarn g:rimraf -rf lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/replace-imports.sh ./lib",
"build:lib": "yarn g:rimraf -rf lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/publish/replace-imports.sh ./lib cjs",
"publish:lib": "./scripts/publish-lib.sh",
"test:unit": "jest",
"prepublishOnly": "yarn tsx ../../scripts/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/prepublish.js"
"prepublishOnly": "yarn tsx ../../scripts/publish/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/publish/prepublish.js"
},
"devDependencies": {
"@babel/preset-env": "7.28.5",

View File

@@ -21,11 +21,11 @@
"!**/*.map"
],
"scripts": {
"build:lib": "yarn g:rimraf ./lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/replace-imports.sh ./lib",
"build:lib": "yarn g:rimraf ./lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/publish/replace-imports.sh ./lib cjs",
"depcheck": "yarn g:depcheck",
"type-check": "yarn g:tsc --build",
"prepublishOnly": "yarn tsx ../../scripts/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/prepublish.js"
"prepublishOnly": "yarn tsx ../../scripts/publish/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/publish/prepublish.js"
},
"devDependencies": {
"tsx": "^4.20.3"

View File

@@ -34,10 +34,10 @@
"test:unit": "yarn g:jest --verbose -c ./jest.config.js",
"type-check": "yarn g:tsc --build tsconfig.json",
"build:lib": "yarn build:lib:cjs && yarn build:lib:esm",
"build:lib:cjs": "yarn g:rimraf ./lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/replace-imports.sh ./lib",
"build:lib:esm": "yarn g:rimraf ./libESM && yarn g:tsc --build tsconfig.libESM.json && ../../scripts/replace-imports.sh ./libESM libESM",
"prepublishOnly": "yarn tsx ../../scripts/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/prepublish.js",
"build:lib:cjs": "yarn g:rimraf ./lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/publish/replace-imports.sh ./lib cjs",
"build:lib:esm": "yarn g:rimraf ./libESM && yarn g:tsc --build tsconfig.libESM.json && ../../scripts/publish/replace-imports.sh ./libESM esm",
"prepublishOnly": "yarn tsx ../../scripts/publish/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/publish/prepublish.js",
"depcheck": "yarn g:depcheck"
},
"peerDependencies": {

View File

@@ -34,9 +34,9 @@
"depcheck": "yarn g:depcheck",
"test:unit": "yarn g:jest --verbose -c jest.config.js",
"type-check": "yarn g:tsc --build tsconfig.json",
"build:lib": "yarn g:rimraf lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/replace-imports.sh ./lib",
"prepublishOnly": "yarn tsx ../../scripts/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/prepublish.js"
"build:lib": "yarn g:rimraf lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/publish/replace-imports.sh ./lib cjs",
"prepublishOnly": "yarn tsx ../../scripts/publish/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/publish/prepublish.js"
},
"dependencies": {
"@trezor/utils": "workspace:*",

View File

@@ -42,9 +42,9 @@
"depcheck": "yarn g:depcheck",
"test:unit": "yarn g:jest -c ../../jest.config.base.js",
"type-check": "yarn g:tsc --build",
"build:lib": "yarn g:rimraf lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/replace-imports.sh ./lib",
"prepublishOnly": "yarn tsx ../../scripts/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/prepublish.js"
"build:lib": "yarn g:rimraf lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/publish/replace-imports.sh ./lib cjs",
"prepublishOnly": "yarn tsx ../../scripts/publish/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/publish/prepublish.js"
},
"dependencies": {
"@trezor/utils": "workspace:*",

View File

@@ -15,8 +15,9 @@ const packagesPath = path.join(rootPath, 'packages');
const args = process.argv.slice(2);
if (args.length < 2)
if (args.length < 2) {
throw new Error('Usage: yarn tsx check-npm-dependencies.ts <packageName> <semanticVersion>');
}
const [packageName, semanticVersion] = args;
const allowedSemvers = ['patch', 'prepatch', 'minor', 'preminor', 'prerelease'];

View File

@@ -6,6 +6,7 @@ export default [
rules: {
'no-console': 'off',
'@typescript-eslint/no-shadow': 'off', // Todo: shall be fixed
'import/no-default-export': 'off', // in scripts this is OK, some of them are expected to work that way
},
},
];

View File

@@ -8,6 +8,7 @@
"generate-package": "tsx generatePackage.ts"
},
"dependencies": {
"@babel/cli": "7.28.3",
"@mobily/ts-belt": "^3.13.1",
"chalk": "^5.6.2",
"cross-fetch": "^4.0.0",

View File

@@ -0,0 +1,34 @@
import path from 'node:path';
// only rewrite: "./x", "../x", "./x/y", but not "./x.js", "../x.ts", "lodash", "@trezor/lib"
const shouldAddExtension = src => src.startsWith('.') && !path.extname(src);
/**
* Babel plugin to add .js extension to import/export statements, used for valid ESM builds.
* This way we can keep our codebase with moduleResolution: bundler (imports without extensions).
*/
const addJSExtensionPlugin = ({ types }) => {
const modifyPath = path => {
const src = path.node.source?.value;
if (src && shouldAddExtension(src)) {
path.node.source = types.stringLiteral(src + '.js');
}
};
return {
name: 'add-js-extension',
visitor: {
ImportDeclaration(path) {
modifyPath(path);
},
ExportAllDeclaration(path) {
modifyPath(path);
},
ExportNamedDeclaration(path) {
modifyPath(path);
},
},
};
};
export default addJSExtensionPlugin;

View File

@@ -0,0 +1,59 @@
const sanitizeInternalImports = (src, moduleType) => {
const searchValue = new RegExp('@trezor/([^/]+)/src', 'g');
const replaceValue = `@trezor/$1/${moduleType === 'esm' ? 'libESM' : 'lib'}`;
return src.replace(searchValue, replaceValue);
};
/**
* Babel plugin to sanitize non-index internal imports, from src to the built lib or libESM folder.
* e.g. @trezor/utils/src/bufferUtils → @trezor/utils/lib/bufferUtils
*/
const sanitizeInternalImportsPlugin = ({ types }) => {
const modifyESMImportPath = path => {
const src = path.node.source?.value;
if (!src) return;
path.node.source = types.stringLiteral(sanitizeInternalImports(src, 'esm'));
};
const modifyCJSRequireArg = path => {
const args = path.node.arguments;
if (!args || args.length === 0) return;
const first = args[0];
if (!types.isStringLiteral(first)) return;
first.value = sanitizeInternalImports(first.value, 'cjs');
};
return {
name: 'sanitize-internal-imports',
visitor: {
// handle ESM import/export statements
ImportDeclaration(path) {
modifyESMImportPath(path);
},
ExportAllDeclaration(path) {
modifyESMImportPath(path);
},
ExportNamedDeclaration(path) {
modifyESMImportPath(path);
},
// handle CJS require(...) and require.resolve('...') statements
CallExpression(path) {
const { callee } = path.node;
if (types.isIdentifier(callee) && callee.name === 'require') {
modifyCJSRequireArg(path);
} else if (
types.isMemberExpression(callee) &&
types.isIdentifier(callee.object) &&
callee.object.name === 'require' &&
types.isIdentifier(callee.property) &&
callee.property.name === 'resolve'
) {
modifyCJSRequireArg(path);
}
},
},
};
};
export default sanitizeInternalImportsPlugin;

View File

@@ -0,0 +1,6 @@
{
"presets": [],
"plugins": ["./babel-plugin-sanitize-internal-imports.js"],
"comments": true,
"sourceMaps": true
}

View File

@@ -0,0 +1,9 @@
{
"presets": [],
"plugins": [
"./babel-plugin-sanitize-internal-imports.js",
"./babel-plugin-add-js-extension.js"
],
"comments": true,
"sourceMaps": true
}

View File

@@ -14,15 +14,7 @@ if (!isValidPackageName) {
throw new Error(`Invalid package name: ${packageName}`);
}
// test all d.ts files for existence of non-resolvable imports such as:
// import("packages/protobuf/lib").MessageType
// in the example "packages" segment is not resolvable. "packages" is a folder in the monorepo root and typescript
// compiler does not replace it with absolute import starting with "@trezor".
// there were issues with this in the past: https://github.com/trezor/trezor-suite/issues/10389
// There are two ways to fix this:
// 1. rename "packages" folder in monorepo to "@trezor"
// 2. find and replace all the problematic occurrences before actual release.
// not very good solution and yarn advices against doing it https://yarnpkg.com/advanced/lifecycle-scripts
// Run babel with custom plugins to fix non-index internal imports and add .js extensions.
const scriptPath = path.join(__dirname, 'replace-imports.sh');
const args = [path.join(__dirname, '..', 'packages', packageName, 'lib')];
execFileSync(scriptPath, args, {

View File

@@ -0,0 +1,32 @@
#!/usr/bin/env bash
set -euxo pipefail
# Usage:
# bash replace-imports.sh <directory> [module-type]
#
# Arguments:
# <directory> The path to the directory containing files to modify.
# <module-type> (Optional) The module system to use: "cjs" | "esm"
#
# Example:
# To replace imports in the ./lib directory using the CJS module typ:
# bash replace-imports.sh ./lib cjs
#
# To replace imports in the ./libESM directory using the ESM module type:
# bash replace-imports.sh ./libESM esm
if [ "$#" -ne 2 ]; then
echo "Error, needs 2 arguments. Usage: $0 <directory> <module-type>"
exit 1
fi
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [ "$2" == "esm" ]; then
BABEL_CONFIG="$SCRIPT_DIR/babel.config.esm.json"
else
BABEL_CONFIG="$SCRIPT_DIR/babel.config.cjs.json"
fi
babel "$1" --out-dir "$1" --extensions ".js" --config-file "$BABEL_CONFIG"

View File

@@ -1,53 +0,0 @@
#!/usr/bin/env bash
set -euxo pipefail
# Usage:
# bash replace-imports.sh <directory> [lib-type]
#
# Arguments:
# <directory> The path to the directory containing files to modify.
# [lib-type] (Optional) The type of library to use. Defaults to "lib" if not provided.
# Use "libESM" for ESM libraries.
#
# Example:
# To replace imports in the ./lib directory using the default library type:
# bash replace-imports.sh ./lib
#
# To replace imports in the ./libESM directory using the "libESM" library type:
# bash replace-imports.sh ./libESM libESM
# By default set to "lib" but when providing second argument it uses it.
if [ $# -ge 2 ]; then
LIB_TYPE="$2"
else
LIB_TYPE="lib"
fi
# Set the regex based on the LIB_TYPE argument
if [[ "$LIB_TYPE" == "libESM" ]]; then
REGEX="s/@trezor\/([^/]+)\/src/@trezor\/\1\/libESM/g"
else
REGEX="s/@trezor\/([^/]+)\/src/@trezor\/\1\/lib/g"
fi
# Determine the operating system
OS="$(uname)"
# Execute the appropriate command based on the OS
if [[ "$OS" == "Darwin" ]]; then
# macOS command with -i '' for in-place editing without backup and -E for extended regex
find "$1" -type f -exec sed -i '' -E "$REGEX" {} +
else
# Linux command with -i and -E for in-place editing without backup (GNU sed syntax) and extended regex
find "$1" -type f -exec sed -i -E "$REGEX" {} +
fi
# Safety check to ensure that all occurrences of '@trezor/*/src' have been replaced
SEARCH_PATTERN="@trezor\/[^/]+\/src"
if grep -Rl "$SEARCH_PATTERN" "$1"; then
echo "Error: Some files still contain '@trezor/*/src'. Please review the replacements."
exit 1
else
echo "All occurrences of '@trezor/*/src' have been successfully replaced."
fi

View File

@@ -14490,6 +14490,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@trezor/scripts@workspace:scripts"
dependencies:
"@babel/cli": "npm:7.28.3"
"@mobily/ts-belt": "npm:^3.13.1"
"@trezor/eslint": "workspace:*"
"@types/semver": "npm:^7.7.0"