@tramvai/cli 5.50.0 → 5.53.78
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__migrations__/d2023-02-01b-tramvai-config-refactoring.js +78 -80
- package/__migrations__/d2025-04-11b-tramvai-config-remove-modern.js +13 -0
- package/bin/spawn.js +69 -3
- package/lib/api/analyze/index.d.ts +0 -1
- package/lib/api/analyze/index.d.ts.map +1 -1
- package/lib/api/analyze/index.js +2 -2
- package/lib/api/analyze/index.js.map +1 -1
- package/lib/api/build/application.d.ts.map +1 -1
- package/lib/api/build/application.js +2 -5
- package/lib/api/build/application.js.map +1 -1
- package/lib/api/build/child-app.d.ts.map +1 -1
- package/lib/api/build/child-app.js +1 -5
- package/lib/api/build/child-app.js.map +1 -1
- package/lib/api/build/index.d.ts +0 -2
- package/lib/api/build/index.d.ts.map +1 -1
- package/lib/api/build/index.js.map +1 -1
- package/lib/api/build/module.d.ts.map +1 -1
- package/lib/api/build/module.js +1 -3
- package/lib/api/build/module.js.map +1 -1
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +0 -4
- package/lib/api/index.js.map +1 -1
- package/lib/api/start/index.d.ts +0 -1
- package/lib/api/start/index.d.ts.map +1 -1
- package/lib/api/start/index.js.map +1 -1
- package/lib/api/start/utils/banner.d.ts.map +1 -1
- package/lib/api/start/utils/banner.js +0 -1
- package/lib/api/start/utils/banner.js.map +1 -1
- package/lib/api/start/utils/tips/tips.d.ts.map +1 -1
- package/lib/api/start/utils/tips/tips.js +0 -8
- package/lib/api/start/utils/tips/tips.js.map +1 -1
- package/lib/builder/webpack/devServer/pool/process/pool.d.ts.map +1 -1
- package/lib/builder/webpack/devServer/pool/process/pool.js +0 -2
- package/lib/builder/webpack/devServer/pool/process/pool.js.map +1 -1
- package/lib/builder/webpack/devServer/server.d.ts.map +1 -1
- package/lib/builder/webpack/devServer/server.js +4 -0
- package/lib/builder/webpack/devServer/server.js.map +1 -1
- package/lib/builder/webpack/index.d.ts.map +1 -1
- package/lib/builder/webpack/index.js +3 -5
- package/lib/builder/webpack/index.js.map +1 -1
- package/lib/builder/webpack/providers/build/client.d.ts.map +1 -1
- package/lib/builder/webpack/providers/build/client.js +0 -1
- package/lib/builder/webpack/providers/build/client.js.map +1 -1
- package/lib/builder/webpack/providers/build/clientShared.d.ts.map +1 -1
- package/lib/builder/webpack/providers/build/clientShared.js +4 -6
- package/lib/builder/webpack/providers/build/clientShared.js.map +1 -1
- package/lib/builder/webpack/providers/client.d.ts.map +1 -1
- package/lib/builder/webpack/providers/client.js +0 -13
- package/lib/builder/webpack/providers/client.js.map +1 -1
- package/lib/builder/webpack/providers/shared.d.ts.map +1 -1
- package/lib/builder/webpack/providers/shared.js +2 -8
- package/lib/builder/webpack/providers/shared.js.map +1 -1
- package/lib/builder/webpack/tokens.d.ts +4 -139
- package/lib/builder/webpack/tokens.d.ts.map +1 -1
- package/lib/builder/webpack/tokens.js +1 -4
- package/lib/builder/webpack/tokens.js.map +1 -1
- package/lib/builder/webpack/utils/copyStatsJsonFile.d.ts.map +1 -1
- package/lib/builder/webpack/utils/copyStatsJsonFile.js +0 -11
- package/lib/builder/webpack/utils/copyStatsJsonFile.js.map +1 -1
- package/lib/cli/CLI.d.ts +2 -2
- package/lib/cli/CLI.d.ts.map +1 -1
- package/lib/cli/CLI.js +2 -2
- package/lib/cli/CLI.js.map +1 -1
- package/lib/cli/index.d.ts.map +1 -1
- package/lib/cli/index.js +28 -7
- package/lib/cli/index.js.map +1 -1
- package/lib/cli/runCLI.d.ts +3 -0
- package/lib/cli/runCLI.d.ts.map +1 -1
- package/lib/cli/runCLI.js +18 -6
- package/lib/cli/runCLI.js.map +1 -1
- package/lib/commands/build/command.d.ts +1 -1
- package/lib/commands/build/command.d.ts.map +1 -1
- package/lib/commands/build/command.js +41 -13
- package/lib/commands/build/command.js.map +1 -1
- package/lib/commands/createApp.d.ts.map +1 -1
- package/lib/commands/createApp.js +0 -1
- package/lib/commands/createApp.js.map +1 -1
- package/lib/commands/new/new.d.ts.map +1 -1
- package/lib/commands/new/new.js +28 -3
- package/lib/commands/new/new.js.map +1 -1
- package/lib/commands/start/command.d.ts +1 -1
- package/lib/commands/start/command.d.ts.map +1 -1
- package/lib/commands/start/command.js +39 -7
- package/lib/commands/start/command.js.map +1 -1
- package/lib/commands/start/start.d.ts +1 -1
- package/lib/commands/start/start.d.ts.map +1 -1
- package/lib/commands/start/start.js +2 -1
- package/lib/commands/start/start.js.map +1 -1
- package/lib/commands/static/application.d.ts.map +1 -1
- package/lib/commands/static/application.js +0 -1
- package/lib/commands/static/application.js.map +1 -1
- package/lib/commands/update/command.d.ts +6 -1
- package/lib/commands/update/command.d.ts.map +1 -1
- package/lib/commands/update/command.js +8 -1
- package/lib/commands/update/command.js.map +1 -1
- package/lib/commands/update/dependantLibs.d.ts +2 -1
- package/lib/commands/update/dependantLibs.d.ts.map +1 -1
- package/lib/commands/update/dependantLibs.js +17 -4
- package/lib/commands/update/dependantLibs.js.map +1 -1
- package/lib/commands/update/update.d.ts +2 -1
- package/lib/commands/update/update.d.ts.map +1 -1
- package/lib/commands/update/update.js +6 -6
- package/lib/commands/update/update.js.map +1 -1
- package/lib/commands/update/updatePackageJson.d.ts +1 -1
- package/lib/commands/update/updatePackageJson.d.ts.map +1 -1
- package/lib/commands/update/updatePackageJson.js +10 -14
- package/lib/commands/update/updatePackageJson.js.map +1 -1
- package/lib/config/configManager.d.ts +0 -1
- package/lib/config/configManager.d.ts.map +1 -1
- package/lib/config/configManager.js +2 -17
- package/lib/config/configManager.js.map +1 -1
- package/lib/config/validate.d.ts.map +1 -1
- package/lib/config/validate.js +8 -1
- package/lib/config/validate.js.map +1 -1
- package/lib/di/providers/index.d.ts +0 -1
- package/lib/di/providers/index.d.ts.map +1 -1
- package/lib/di/providers/index.js +0 -1
- package/lib/di/providers/index.js.map +1 -1
- package/lib/di/tokens/config.d.ts +2 -0
- package/lib/di/tokens/config.d.ts.map +1 -1
- package/lib/di/tokens/index.d.ts +0 -1
- package/lib/di/tokens/index.d.ts.map +1 -1
- package/lib/di/tokens/index.js +0 -1
- package/lib/di/tokens/index.js.map +1 -1
- package/lib/library/babel/index.d.ts +0 -44
- package/lib/library/babel/index.d.ts.map +1 -1
- package/lib/library/babel/index.js +6 -13
- package/lib/library/babel/index.js.map +1 -1
- package/lib/library/swc/index.js +1 -1
- package/lib/library/swc/index.js.map +1 -1
- package/lib/library/typescript/index.d.ts +0 -23
- package/lib/library/typescript/index.d.ts.map +1 -1
- package/lib/library/typescript/index.js +1 -2
- package/lib/library/typescript/index.js.map +1 -1
- package/lib/library/webpack/application/client/common.d.ts.map +1 -1
- package/lib/library/webpack/application/client/common.js +40 -6
- package/lib/library/webpack/application/client/common.js.map +1 -1
- package/lib/library/webpack/application/client/dev.js +2 -2
- package/lib/library/webpack/application/client/dev.js.map +1 -1
- package/lib/library/webpack/application/client/prod.d.ts.map +1 -1
- package/lib/library/webpack/application/client/prod.js +1 -2
- package/lib/library/webpack/application/client/prod.js.map +1 -1
- package/lib/library/webpack/application/common.js +1 -1
- package/lib/library/webpack/application/common.js.map +1 -1
- package/lib/library/webpack/application/server/common.js +1 -1
- package/lib/library/webpack/application/server/common.js.map +1 -1
- package/lib/library/webpack/application/server/dev.js +1 -1
- package/lib/library/webpack/application/server/dev.js.map +1 -1
- package/lib/library/webpack/application/server/prod.js +1 -1
- package/lib/library/webpack/application/server/prod.js.map +1 -1
- package/lib/library/webpack/blocks/css.d.ts.map +1 -1
- package/lib/library/webpack/blocks/css.js +15 -11
- package/lib/library/webpack/blocks/css.js.map +1 -1
- package/lib/library/webpack/blocks/optimize.js +2 -2
- package/lib/library/webpack/blocks/optimize.js.map +1 -1
- package/lib/library/webpack/blocks/pwa/client.d.ts.map +1 -1
- package/lib/library/webpack/blocks/pwa/client.js +2 -5
- package/lib/library/webpack/blocks/pwa/client.js.map +1 -1
- package/lib/library/webpack/blocks/pwa/shared.d.ts.map +1 -1
- package/lib/library/webpack/blocks/pwa/shared.js +2 -3
- package/lib/library/webpack/blocks/pwa/shared.js.map +1 -1
- package/lib/library/webpack/blocks/resolve.js +2 -2
- package/lib/library/webpack/blocks/resolve.js.map +1 -1
- package/lib/library/webpack/blocks/serverInline.d.ts.map +1 -1
- package/lib/library/webpack/blocks/serverInline.js +1 -2
- package/lib/library/webpack/blocks/serverInline.js.map +1 -1
- package/lib/library/webpack/blocks/sourcemaps.d.ts +1 -1
- package/lib/library/webpack/blocks/sourcemaps.d.ts.map +1 -1
- package/lib/library/webpack/blocks/sourcemaps.js +4 -2
- package/lib/library/webpack/blocks/sourcemaps.js.map +1 -1
- package/lib/library/webpack/child-app/client/common.d.ts.map +1 -1
- package/lib/library/webpack/child-app/client/common.js +8 -3
- package/lib/library/webpack/child-app/client/common.js.map +1 -1
- package/lib/library/webpack/child-app/client/dev.d.ts.map +1 -1
- package/lib/library/webpack/child-app/client/dev.js +5 -1
- package/lib/library/webpack/child-app/client/dev.js.map +1 -1
- package/lib/library/webpack/child-app/client/prod.d.ts.map +1 -1
- package/lib/library/webpack/child-app/client/prod.js +4 -0
- package/lib/library/webpack/child-app/client/prod.js.map +1 -1
- package/lib/library/webpack/child-app/common.d.ts.map +1 -1
- package/lib/library/webpack/child-app/common.js +1 -5
- package/lib/library/webpack/child-app/common.js.map +1 -1
- package/lib/library/webpack/child-app/server/dev.d.ts.map +1 -1
- package/lib/library/webpack/child-app/server/dev.js +4 -0
- package/lib/library/webpack/child-app/server/dev.js.map +1 -1
- package/lib/library/webpack/child-app/server/prod.d.ts.map +1 -1
- package/lib/library/webpack/child-app/server/prod.js +4 -0
- package/lib/library/webpack/child-app/server/prod.js.map +1 -1
- package/lib/library/webpack/common/client/prod.js +1 -1
- package/lib/library/webpack/common/client/prod.js.map +1 -1
- package/lib/library/webpack/common/main.d.ts.map +1 -1
- package/lib/library/webpack/common/main.js +1 -2
- package/lib/library/webpack/common/main.js.map +1 -1
- package/lib/library/webpack/constants/stats.d.ts.map +1 -1
- package/lib/library/webpack/constants/stats.js +2 -0
- package/lib/library/webpack/constants/stats.js.map +1 -1
- package/lib/library/webpack/loaders/image-loader/getImageMiniatureURL.js +1 -1
- package/lib/library/webpack/loaders/image-loader/getImageMiniatureURL.js.map +1 -1
- package/lib/library/webpack/module/client/common.js +1 -1
- package/lib/library/webpack/module/client/common.js.map +1 -1
- package/lib/library/webpack/module/externals.js +1 -1
- package/lib/library/webpack/module/externals.js.map +1 -1
- package/lib/library/webpack/module/server/common.js +1 -1
- package/lib/library/webpack/module/server/common.js.map +1 -1
- package/lib/library/webpack/plugins/AssetsIntegritiesPlugin.d.ts +8 -0
- package/lib/library/webpack/plugins/AssetsIntegritiesPlugin.d.ts.map +1 -0
- package/lib/library/webpack/plugins/AssetsIntegritiesPlugin.js +29 -0
- package/lib/library/webpack/plugins/AssetsIntegritiesPlugin.js.map +1 -0
- package/lib/library/webpack/plugins/PurifyStatsPlugin.d.ts +15 -0
- package/lib/library/webpack/plugins/PurifyStatsPlugin.d.ts.map +1 -0
- package/lib/library/webpack/plugins/PurifyStatsPlugin.js +47 -0
- package/lib/library/webpack/plugins/PurifyStatsPlugin.js.map +1 -0
- package/lib/library/webpack/plugins/RuntimePathPlugin.d.ts.map +1 -1
- package/lib/library/webpack/plugins/RuntimePathPlugin.js +7 -3
- package/lib/library/webpack/plugins/RuntimePathPlugin.js.map +1 -1
- package/lib/library/webpack/utils/transpiler.d.ts +0 -1
- package/lib/library/webpack/utils/transpiler.d.ts.map +1 -1
- package/lib/library/webpack/utils/transpiler.js +1 -5
- package/lib/library/webpack/utils/transpiler.js.map +1 -1
- package/lib/models/analytics/analytics.d.ts +156 -0
- package/lib/models/analytics/analytics.d.ts.map +1 -0
- package/lib/models/analytics/analytics.js +259 -0
- package/lib/models/analytics/analytics.js.map +1 -0
- package/lib/models/analytics/analytics.worker.d.ts +5 -0
- package/lib/models/analytics/analytics.worker.d.ts.map +1 -0
- package/lib/models/analytics/analytics.worker.js +87 -0
- package/lib/models/analytics/analytics.worker.js.map +1 -0
- package/lib/models/analytics/utils.d.ts +15 -0
- package/lib/models/analytics/utils.d.ts.map +1 -0
- package/lib/models/analytics/utils.js +85 -0
- package/lib/models/analytics/utils.js.map +1 -0
- package/lib/models/command.d.ts.map +1 -1
- package/lib/models/command.js +1 -7
- package/lib/models/command.js.map +1 -1
- package/lib/models/context.d.ts +4 -4
- package/lib/models/context.d.ts.map +1 -1
- package/lib/models/context.js +3 -2
- package/lib/models/context.js.map +1 -1
- package/lib/models/logger.d.ts +1 -0
- package/lib/models/logger.d.ts.map +1 -1
- package/lib/models/logger.js +2 -1
- package/lib/models/logger.js.map +1 -1
- package/lib/models/task.d.ts.map +1 -1
- package/lib/models/task.js +1 -7
- package/lib/models/task.js.map +1 -1
- package/lib/schema/autogeneratedSchema.json +161 -20
- package/lib/schema/topLevelSchema.d.ts +14 -0
- package/lib/schema/topLevelSchema.d.ts.map +1 -1
- package/lib/schema/topLevelSchema.js +14 -0
- package/lib/schema/topLevelSchema.js.map +1 -1
- package/lib/typings/build/Builder.d.ts +2 -6
- package/lib/typings/build/Builder.d.ts.map +1 -1
- package/lib/typings/configEntry/application.d.ts +10 -5
- package/lib/typings/configEntry/application.d.ts.map +1 -1
- package/lib/typings/configEntry/cli.d.ts +13 -0
- package/lib/typings/configEntry/cli.d.ts.map +1 -1
- package/lib/typings/projectType.d.ts +5 -0
- package/lib/typings/projectType.d.ts.map +1 -1
- package/lib/typings/target.d.ts +1 -1
- package/lib/typings/target.d.ts.map +1 -1
- package/lib/utils/commands/dependencies/findTramvaiVersion.d.ts +1 -1
- package/lib/utils/commands/dependencies/findTramvaiVersion.d.ts.map +1 -1
- package/lib/utils/commands/dependencies/findTramvaiVersion.js +4 -11
- package/lib/utils/commands/dependencies/findTramvaiVersion.js.map +1 -1
- package/lib/utils/commands/dependencies/getLatestPackageVersion.d.ts +1 -1
- package/lib/utils/commands/dependencies/getLatestPackageVersion.d.ts.map +1 -1
- package/lib/utils/commands/dependencies/getLatestPackageVersion.js +7 -3
- package/lib/utils/commands/dependencies/getLatestPackageVersion.js.map +1 -1
- package/lib/utils/cpu-profile.d.ts +3 -0
- package/lib/utils/cpu-profile.d.ts.map +1 -1
- package/lib/utils/cpu-profile.js +8 -3
- package/lib/utils/cpu-profile.js.map +1 -1
- package/lib/utils/errors.d.ts +7 -0
- package/lib/utils/errors.d.ts.map +1 -0
- package/lib/utils/errors.js +43 -0
- package/lib/utils/errors.js.map +1 -0
- package/lib/utils/memoryUsage.d.ts +20 -0
- package/lib/utils/memoryUsage.d.ts.map +1 -0
- package/lib/utils/memoryUsage.js +51 -0
- package/lib/utils/memoryUsage.js.map +1 -0
- package/lib/utils/safeRequire.d.ts +1 -1
- package/lib/utils/safeRequire.d.ts.map +1 -1
- package/lib/utils/safeRequire.js +13 -3
- package/lib/utils/safeRequire.js.map +1 -1
- package/package.json +13 -15
- package/schema.json +175 -20
- package/src/api/analyze/index.ts +2 -3
- package/src/api/benchmark/__integration__/__fixtures__/tramvai.json +3 -0
- package/src/api/build/__integration__/__fixtures__/tramvai.json +4 -2
- package/src/api/build/__integration__/build.test.ts +0 -1
- package/src/api/build/application.ts +2 -5
- package/src/api/build/child-app.ts +1 -5
- package/src/api/build/index.ts +0 -2
- package/src/api/build/module.ts +1 -3
- package/src/api/index.ts +1 -10
- package/src/api/start/__integration__/__fixtures__/app/server.tsx +1 -0
- package/src/api/start/__integration__/__fixtures__/package.json +0 -3
- package/src/api/start/__integration__/__fixtures__/tramvai.json +3 -0
- package/src/api/start/__integration__/start.test.ts +2 -1
- package/src/api/start/index.ts +0 -1
- package/src/api/start/utils/banner.ts +0 -1
- package/src/api/start/utils/tips/tips.ts +0 -9
- package/src/builder/webpack/devServer/pool/process/pool.ts +0 -2
- package/src/builder/webpack/devServer/server.ts +5 -0
- package/src/builder/webpack/index.ts +3 -5
- package/src/builder/webpack/providers/build/client.ts +0 -1
- package/src/builder/webpack/providers/build/clientShared.ts +5 -11
- package/src/builder/webpack/providers/client.ts +1 -19
- package/src/builder/webpack/providers/shared.ts +2 -9
- package/src/builder/webpack/tokens.ts +0 -9
- package/src/builder/webpack/utils/copyStatsJsonFile.ts +0 -17
- package/src/cli/CLI.ts +6 -4
- package/src/cli/index.ts +33 -8
- package/src/cli/runCLI.ts +26 -5
- package/src/commands/build/command.ts +45 -13
- package/src/commands/createApp.ts +0 -2
- package/src/commands/new/new.ts +39 -7
- package/src/commands/new/templates/packageManagerConfig/yarnPackageManagerConfig/_yarnrc.yml.hbs +9 -0
- package/src/commands/new/templates/shared/_gitignore.hbs +10 -0
- package/src/commands/new/templates/shared/package.json.hbs +5 -1
- package/src/commands/start/command.ts +42 -7
- package/src/commands/start/start.ts +7 -1
- package/src/commands/static/application.ts +0 -1
- package/src/commands/update/command.ts +9 -1
- package/src/commands/update/dependantLibs.ts +23 -8
- package/src/commands/update/update.ts +7 -6
- package/src/commands/update/updatePackageJson.spec.ts +66 -3
- package/src/commands/update/updatePackageJson.ts +28 -16
- package/src/config/__integration__/__fixtures__/relative/src/index.ts +0 -0
- package/src/config/__integration__/__fixtures__/relative/src/polyfill.ts +0 -0
- package/src/config/__integration__/validate.test.ts +94 -0
- package/src/config/configManager.ts +2 -19
- package/src/config/validate.ts +8 -1
- package/src/di/providers/index.ts +0 -1
- package/src/di/tokens/index.ts +0 -1
- package/src/library/babel/index.ts +8 -14
- package/src/library/babel/plugins/__snapshots__/create-token-pure.spec.ts.snap +6 -6
- package/src/library/babel/plugins/__snapshots__/fill-declare-action-name.spec.ts.snap +24 -26
- package/src/library/babel/plugins/__snapshots__/provider-stack.spec.ts.snap +40 -59
- package/src/library/babel/plugins/lazy-component/lazy-component.spec.ts +0 -1
- package/src/library/babel/plugins/lazy-component/legacy-universal-replace.spec.ts +0 -1
- package/src/library/swc/__integration__/__snapshots__/swc.build.test.ts.snap +15 -208
- package/src/library/swc/__integration__/__snapshots__/swc.start.test.ts.snap +7 -10
- package/src/library/swc/__integration__/swc.build.test.ts +1 -13
- package/src/library/swc/__integration__/swc.start.test.ts +3 -0
- package/src/library/swc/index.ts +1 -1
- package/src/library/typescript/index.ts +1 -3
- package/src/library/webpack/application/client/common.ts +63 -6
- package/src/library/webpack/application/client/dev.ts +2 -2
- package/src/library/webpack/application/client/prod.ts +1 -2
- package/src/library/webpack/application/common.ts +1 -1
- package/src/library/webpack/application/server/common.ts +1 -1
- package/src/library/webpack/application/server/dev.ts +1 -1
- package/src/library/webpack/application/server/prod.ts +1 -1
- package/src/library/webpack/blocks/css.ts +17 -11
- package/src/library/webpack/blocks/optimize.ts +2 -2
- package/src/library/webpack/blocks/pwa/client.ts +1 -6
- package/src/library/webpack/blocks/pwa/shared.ts +1 -3
- package/src/library/webpack/blocks/resolve.ts +2 -2
- package/src/library/webpack/blocks/serverInline.ts +1 -2
- package/src/library/webpack/blocks/sourcemaps.ts +4 -2
- package/src/library/webpack/child-app/client/common.ts +9 -3
- package/src/library/webpack/child-app/client/dev.ts +6 -1
- package/src/library/webpack/child-app/client/prod.ts +5 -0
- package/src/library/webpack/child-app/common.ts +1 -7
- package/src/library/webpack/child-app/server/dev.ts +5 -0
- package/src/library/webpack/child-app/server/prod.ts +5 -0
- package/src/library/webpack/common/client/prod.ts +1 -1
- package/src/library/webpack/common/main.ts +1 -5
- package/src/library/webpack/constants/stats.ts +2 -0
- package/src/library/webpack/loaders/image-loader/getImageMiniatureURL.ts +1 -1
- package/src/library/webpack/module/client/common.ts +1 -1
- package/src/library/webpack/module/externals.ts +1 -1
- package/src/library/webpack/module/server/common.ts +1 -1
- package/src/library/webpack/plugins/AssetsIntegritiesPlugin.ts +34 -0
- package/src/library/webpack/plugins/PurifyStatsPlugin.ts +57 -0
- package/src/library/webpack/plugins/RuntimePathPlugin.ts +8 -3
- package/src/library/webpack/utils/polyfills/__integration__/__snapshots__/condition.test.ts.snap +16 -16
- package/src/library/webpack/utils/transpiler.ts +1 -5
- package/src/models/analytics/analytics.ts +488 -0
- package/src/models/analytics/analytics.worker.ts +102 -0
- package/src/models/analytics/utils.ts +122 -0
- package/src/models/command.ts +1 -8
- package/src/models/config.spec.ts +6 -2
- package/src/models/context.ts +4 -5
- package/src/models/logger.ts +2 -0
- package/src/models/task.ts +1 -7
- package/src/schema/autogeneratedSchema.json +161 -20
- package/src/schema/topLevelSchema.js +14 -0
- package/src/schema/tramvai.spec.ts +3 -1
- package/src/typings/build/Builder.ts +3 -8
- package/src/typings/configEntry/application.ts +11 -6
- package/src/typings/configEntry/cli.ts +14 -0
- package/src/typings/projectType.ts +5 -0
- package/src/typings/target.ts +1 -1
- package/src/utils/commands/dependencies/findTramvaiVersion.ts +5 -12
- package/src/utils/commands/dependencies/getLatestPackageVersion.ts +11 -3
- package/src/utils/cpu-profile.ts +14 -3
- package/src/utils/errors.ts +39 -0
- package/src/utils/memoryUsage.ts +58 -0
- package/src/utils/safeRequire.spec.ts +36 -0
- package/src/utils/safeRequire.ts +12 -3
- package/lib/builder/webpack/providers/build/clientModern.d.ts +0 -3
- package/lib/builder/webpack/providers/build/clientModern.d.ts.map +0 -1
- package/lib/builder/webpack/providers/build/clientModern.js +0 -60
- package/lib/builder/webpack/providers/build/clientModern.js.map +0 -1
- package/lib/di/providers/analytics.d.ts +0 -3
- package/lib/di/providers/analytics.d.ts.map +0 -1
- package/lib/di/providers/analytics.js +0 -20
- package/lib/di/providers/analytics.js.map +0 -1
- package/lib/di/tokens/analytics.d.ts +0 -14
- package/lib/di/tokens/analytics.d.ts.map +0 -1
- package/lib/di/tokens/analytics.js +0 -8
- package/lib/di/tokens/analytics.js.map +0 -1
- package/lib/models/analytics.d.ts +0 -31
- package/lib/models/analytics.d.ts.map +0 -1
- package/lib/models/analytics.js +0 -79
- package/lib/models/analytics.js.map +0 -1
- package/src/builder/webpack/providers/build/clientModern.ts +0 -64
- package/src/di/providers/analytics.ts +0 -22
- package/src/di/tokens/analytics.ts +0 -8
- package/src/models/analytics.ts +0 -116
- /package/src/commands/new/templates/{shared → packageManagerConfig/defaultPackageManagerConfig}/_npmrc.hbs +0 -0
|
@@ -0,0 +1,488 @@
|
|
|
1
|
+
import os from 'node:os';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import crypto from 'node:crypto';
|
|
4
|
+
import { Worker } from 'node:worker_threads';
|
|
5
|
+
import { PackageManager } from '@tinkoff/package-manager-wrapper';
|
|
6
|
+
import { Logger } from '../logger';
|
|
7
|
+
import { createMemoryMonitor } from '../../utils/memoryUsage';
|
|
8
|
+
import { enumerateErrorProperties } from '../../utils/errors';
|
|
9
|
+
|
|
10
|
+
declare global {
|
|
11
|
+
// eslint-disable-next-line no-var, vars-on-top
|
|
12
|
+
var __TRAMVAI_EXIT_HANDLERS__: Array<() => Promise<any>>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type LEVEL = 'INFO' | 'WARN' | 'ERROR';
|
|
16
|
+
|
|
17
|
+
export type COMMANDS =
|
|
18
|
+
| 'start'
|
|
19
|
+
| 'build'
|
|
20
|
+
| 'start-prod'
|
|
21
|
+
| 'static'
|
|
22
|
+
| 'analyze'
|
|
23
|
+
| 'new'
|
|
24
|
+
| 'add'
|
|
25
|
+
| 'update';
|
|
26
|
+
|
|
27
|
+
export type Event = {
|
|
28
|
+
/**
|
|
29
|
+
* @description ISO-8601 + timezone
|
|
30
|
+
*/
|
|
31
|
+
timestamp: string;
|
|
32
|
+
/**
|
|
33
|
+
* @description Unique identifier for the current cli execution
|
|
34
|
+
*/
|
|
35
|
+
'x-command-id': string;
|
|
36
|
+
level: LEVEL;
|
|
37
|
+
event: string;
|
|
38
|
+
message: string;
|
|
39
|
+
system: string;
|
|
40
|
+
tramvai: TramvaiProperties;
|
|
41
|
+
os: SystemProperties;
|
|
42
|
+
// process.env.CI
|
|
43
|
+
vcs?: VcsProperties;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export type ProjectProperties = {
|
|
47
|
+
name: string;
|
|
48
|
+
type?: 'application' | 'child-app' | 'module' | 'package' | 'unknown';
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export type TramvaiProperties = {
|
|
52
|
+
name: '@tramvai/cli';
|
|
53
|
+
version: string;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export type DependenciesProperties = {
|
|
57
|
+
react?: string;
|
|
58
|
+
webpack?: string;
|
|
59
|
+
babel?: string;
|
|
60
|
+
swc?: string;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export type SystemProperties = {
|
|
64
|
+
nodeVersion: string;
|
|
65
|
+
packageManager: {
|
|
66
|
+
name: string;
|
|
67
|
+
};
|
|
68
|
+
platform: string;
|
|
69
|
+
arch: string;
|
|
70
|
+
cpus: {
|
|
71
|
+
model: string;
|
|
72
|
+
count: number;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export type FeaturesProperties = {
|
|
77
|
+
swc?: boolean;
|
|
78
|
+
fileSystemRouting?: boolean;
|
|
79
|
+
reactCompiler?: boolean;
|
|
80
|
+
devTools?: boolean;
|
|
81
|
+
moduleImage?: boolean;
|
|
82
|
+
modulePwa?: boolean;
|
|
83
|
+
viewTransitions?: boolean;
|
|
84
|
+
transitionsRouterProvider?: boolean;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export type VcsProperties = {
|
|
88
|
+
// process.env.CI_PROJECT_NAMESPACE
|
|
89
|
+
tenant?: string;
|
|
90
|
+
// process.env.CI_PROJECT_NAME
|
|
91
|
+
repository?: string;
|
|
92
|
+
// process.env.CI_PIPELINE_URL
|
|
93
|
+
pipelineUrl?: string;
|
|
94
|
+
// process.env.CI_JOB_URL
|
|
95
|
+
jobUrl?: string;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export type MemoryUsageProperties = {
|
|
99
|
+
// in bytes
|
|
100
|
+
maxHeapTotal: number;
|
|
101
|
+
// in bytes
|
|
102
|
+
maxHeapUsed: number;
|
|
103
|
+
// in bytes
|
|
104
|
+
maxRss: number;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export type AnalyticsEvents = {
|
|
108
|
+
'cli:init': {
|
|
109
|
+
event: 'cli:init';
|
|
110
|
+
level: 'INFO';
|
|
111
|
+
message: string;
|
|
112
|
+
arguments: string[];
|
|
113
|
+
/**
|
|
114
|
+
* @description CLI uptime in milliseconds before the AnalyticsService was initialized
|
|
115
|
+
*/
|
|
116
|
+
uptime: number;
|
|
117
|
+
// TODO: max used old space size flag
|
|
118
|
+
// TODO: detect cold start?
|
|
119
|
+
dependencies: DependenciesProperties;
|
|
120
|
+
};
|
|
121
|
+
'cli:error': {
|
|
122
|
+
event: 'cli:error';
|
|
123
|
+
level: 'ERROR';
|
|
124
|
+
message: string;
|
|
125
|
+
arguments: string[];
|
|
126
|
+
error: Error;
|
|
127
|
+
/**
|
|
128
|
+
* @description CLI uptime in milliseconds before the AnalyticsService was initialized
|
|
129
|
+
*/
|
|
130
|
+
uptime: number;
|
|
131
|
+
};
|
|
132
|
+
'cli:command:start': {
|
|
133
|
+
event: 'cli:command:start';
|
|
134
|
+
level: 'INFO';
|
|
135
|
+
message: string;
|
|
136
|
+
command: COMMANDS;
|
|
137
|
+
parameters: Record<string, any>;
|
|
138
|
+
project?: ProjectProperties;
|
|
139
|
+
features?: FeaturesProperties;
|
|
140
|
+
};
|
|
141
|
+
'cli:command:end': {
|
|
142
|
+
event: 'cli:command:end';
|
|
143
|
+
level: 'INFO';
|
|
144
|
+
message: string;
|
|
145
|
+
command: COMMANDS;
|
|
146
|
+
/**
|
|
147
|
+
* @description duration in milliseconds
|
|
148
|
+
*/
|
|
149
|
+
duration: number;
|
|
150
|
+
memoryUsage?: MemoryUsageProperties;
|
|
151
|
+
parameters: Record<string, any>;
|
|
152
|
+
project: ProjectProperties;
|
|
153
|
+
};
|
|
154
|
+
'cli:command:build:stats': {
|
|
155
|
+
event: 'cli:command:build:stats';
|
|
156
|
+
level: 'INFO';
|
|
157
|
+
message: string;
|
|
158
|
+
command: 'build';
|
|
159
|
+
// TODO: compilation and stats info
|
|
160
|
+
parameters: Record<string, any>;
|
|
161
|
+
project: ProjectProperties;
|
|
162
|
+
};
|
|
163
|
+
'cli:command:error': {
|
|
164
|
+
event: 'cli:command:error';
|
|
165
|
+
level: 'ERROR';
|
|
166
|
+
message: string;
|
|
167
|
+
command: COMMANDS;
|
|
168
|
+
/**
|
|
169
|
+
* @description duration in milliseconds
|
|
170
|
+
*/
|
|
171
|
+
duration: number;
|
|
172
|
+
memoryUsage?: MemoryUsageProperties;
|
|
173
|
+
error: Error;
|
|
174
|
+
parameters: Record<string, any>;
|
|
175
|
+
project?: ProjectProperties;
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
export class AnalyticsService {
|
|
180
|
+
#enabled: boolean;
|
|
181
|
+
#endpoint: string;
|
|
182
|
+
#system: string;
|
|
183
|
+
#debug: boolean;
|
|
184
|
+
#dryRun: boolean;
|
|
185
|
+
#logger: Logger;
|
|
186
|
+
#packageManager: PackageManager;
|
|
187
|
+
#xCommandId: string;
|
|
188
|
+
#worker: Worker | null = null;
|
|
189
|
+
|
|
190
|
+
memoryMonitor: ReturnType<typeof createMemoryMonitor> | null = null;
|
|
191
|
+
|
|
192
|
+
constructor({
|
|
193
|
+
enabled = true,
|
|
194
|
+
endpoint = '',
|
|
195
|
+
system,
|
|
196
|
+
logger,
|
|
197
|
+
packageManager,
|
|
198
|
+
}: {
|
|
199
|
+
enabled?: boolean;
|
|
200
|
+
endpoint?: string;
|
|
201
|
+
system?: string;
|
|
202
|
+
logger: Logger;
|
|
203
|
+
packageManager: PackageManager;
|
|
204
|
+
}) {
|
|
205
|
+
this.#enabled = process.env.TRAMVAI_ANALYTICS_DISABLED
|
|
206
|
+
? process.env.TRAMVAI_ANALYTICS_DISABLED !== 'true'
|
|
207
|
+
: enabled;
|
|
208
|
+
this.#endpoint = process.env.TRAMVAI_ANALYTICS_ENDPOINT ?? endpoint;
|
|
209
|
+
this.#system = process.env.TRAMVAI_ANALYTICS_SYSTEM ?? system ?? 'tramvai-cli';
|
|
210
|
+
this.#debug = process.env.TRAMVAI_ANALYTICS_DEBUG === 'true';
|
|
211
|
+
this.#dryRun = process.env.TRAMVAI_ANALYTICS_DRY_RUN === 'true';
|
|
212
|
+
this.#logger = logger;
|
|
213
|
+
this.#packageManager = packageManager;
|
|
214
|
+
this.#xCommandId = crypto.randomUUID();
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
async init() {
|
|
218
|
+
if (!this.#worker && this.#enabled && this.#endpoint) {
|
|
219
|
+
await this.#spawnWorker();
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (!this.memoryMonitor) {
|
|
223
|
+
this.#initMemoryMonitor();
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
this.#initErrorHandlers();
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
#initMemoryMonitor() {
|
|
230
|
+
this.memoryMonitor = createMemoryMonitor({ sampleInterval: 250 });
|
|
231
|
+
this.memoryMonitor.start();
|
|
232
|
+
|
|
233
|
+
// CLI will wait for this handlers before exiting
|
|
234
|
+
// @reference `packages/cli/src/cli/runCLI.ts`
|
|
235
|
+
if (!global.__TRAMVAI_EXIT_HANDLERS__) {
|
|
236
|
+
global.__TRAMVAI_EXIT_HANDLERS__ = [];
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
global.__TRAMVAI_EXIT_HANDLERS__.push(async () => {
|
|
240
|
+
this.memoryMonitor?.stop();
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
#initErrorHandlers() {
|
|
245
|
+
const sendErrorEvent = async (message: string, error: Error) => {
|
|
246
|
+
await this?.send({
|
|
247
|
+
event: 'cli:error',
|
|
248
|
+
message,
|
|
249
|
+
level: 'ERROR',
|
|
250
|
+
arguments: process.argv.slice(2),
|
|
251
|
+
error,
|
|
252
|
+
uptime: performance.now(),
|
|
253
|
+
});
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
process.on('uncaughtException', (error) => {
|
|
257
|
+
sendErrorEvent('uncaughtException', error);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
process.on('unhandledRejection', (error) => {
|
|
261
|
+
sendErrorEvent('unhandledRejection', error as Error);
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
async send<E extends keyof AnalyticsEvents>(event: AnalyticsEvents[E]): Promise<void> {
|
|
266
|
+
return this.sendRawEvent(event);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
async sendRawEvent(
|
|
270
|
+
rawEvent: Pick<Event, 'event' | 'message' | 'level'> & Record<string, any>
|
|
271
|
+
): Promise<void> {
|
|
272
|
+
if (!this.#enabled || !this.#endpoint) {
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
try {
|
|
277
|
+
const event: Event & Record<string, any> = {
|
|
278
|
+
...rawEvent,
|
|
279
|
+
timestamp: new Date().toISOString(),
|
|
280
|
+
'x-command-id': this.#xCommandId,
|
|
281
|
+
system: this.#system,
|
|
282
|
+
tramvai: getTramvaiProperties(),
|
|
283
|
+
os: getOsProperties({ packageManager: this.#packageManager }),
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
if (process.env.CI) {
|
|
287
|
+
event.vcs = getVcsProperties();
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
if ('error' in event && event.error instanceof Error) {
|
|
291
|
+
enumerateErrorProperties(event.error);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (!this.#worker) {
|
|
295
|
+
await this.#spawnWorker();
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
this.#worker?.postMessage({
|
|
299
|
+
event: 'SEND_EVENT',
|
|
300
|
+
payload: event,
|
|
301
|
+
});
|
|
302
|
+
} catch (error) {
|
|
303
|
+
this.#logger.event({
|
|
304
|
+
type: 'error',
|
|
305
|
+
event: 'analytics-send-failed',
|
|
306
|
+
message: `Error sending analytics data: ${error instanceof Error ? error.message : String(error)}`,
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
async #spawnWorker() {
|
|
312
|
+
this.#worker = new Worker(path.resolve(__dirname, './analytics.worker.js'), {
|
|
313
|
+
workerData: {
|
|
314
|
+
endpoint: this.#endpoint,
|
|
315
|
+
debug: this.#debug,
|
|
316
|
+
dryRun: this.#dryRun,
|
|
317
|
+
},
|
|
318
|
+
name: 'analytics-worker',
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
this.#worker.on('error', (err) => {
|
|
322
|
+
this.#logger.event({
|
|
323
|
+
type: `error`,
|
|
324
|
+
event: 'analytics-worker-error',
|
|
325
|
+
message: `[analytics] worker error: ${err instanceof Error ? err.message : String(err)}`,
|
|
326
|
+
});
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
this.#worker.on('exit', (code) => {
|
|
330
|
+
if (code !== 0) {
|
|
331
|
+
this.#logger.event({
|
|
332
|
+
type: `error`,
|
|
333
|
+
event: 'analytics-worker-exit',
|
|
334
|
+
message: `[analytics] worker exit with code: ${code}`,
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
// CLI will wait for this handlers before exiting
|
|
340
|
+
// @reference `packages/cli/src/cli/runCLI.ts`
|
|
341
|
+
if (!global.__TRAMVAI_EXIT_HANDLERS__) {
|
|
342
|
+
global.__TRAMVAI_EXIT_HANDLERS__ = [];
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// We need to ensure that the analytics is sent before the process exits.
|
|
346
|
+
// To ensure that, we implement a graceful worker shutdown:
|
|
347
|
+
// - send `EXIT` message to the worker
|
|
348
|
+
// - wait for the worker to respond with `SHUTDOWN_COMPLETE` message
|
|
349
|
+
// - worker will wait for all pending requests, send `SHUTDOWN_COMPLETE` to the parent and exit
|
|
350
|
+
global.__TRAMVAI_EXIT_HANDLERS__.push(async () => {
|
|
351
|
+
this.#logger.event({
|
|
352
|
+
type: 'info',
|
|
353
|
+
event: 'analytics-worker-exit',
|
|
354
|
+
message: 'Process shutting down, waiting for pending analytics to be sent',
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
const promise = new Promise<void>((resolve) => {
|
|
358
|
+
this.#worker?.on('message', async (message) => {
|
|
359
|
+
if (message.event === 'SHUTDOWN_COMPLETE') {
|
|
360
|
+
this.#worker = null;
|
|
361
|
+
resolve();
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
this.#worker?.postMessage({
|
|
367
|
+
event: 'EXIT',
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
await Promise.race([promise, new Promise<void>((resolve) => setTimeout(resolve, 5000))]);
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
await new Promise((resolve) => {
|
|
374
|
+
this.#worker?.once('online', resolve);
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
const cache: {
|
|
380
|
+
tramvaiProperties?: TramvaiProperties;
|
|
381
|
+
osProperties?: SystemProperties;
|
|
382
|
+
vcsProperties?: VcsProperties;
|
|
383
|
+
dependenciesProperties?: DependenciesProperties;
|
|
384
|
+
} = {};
|
|
385
|
+
|
|
386
|
+
function getTramvaiProperties(): TramvaiProperties {
|
|
387
|
+
if (cache.tramvaiProperties) {
|
|
388
|
+
return cache.tramvaiProperties;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
const packageJson = require(path.resolve(__dirname, '../../../package.json'));
|
|
392
|
+
|
|
393
|
+
const tramvaiProperties: TramvaiProperties = {
|
|
394
|
+
name: '@tramvai/cli',
|
|
395
|
+
version: packageJson.version,
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
cache.tramvaiProperties = tramvaiProperties;
|
|
399
|
+
|
|
400
|
+
return tramvaiProperties;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
function getOsProperties({ packageManager }: { packageManager: PackageManager }): SystemProperties {
|
|
404
|
+
if (cache.osProperties) {
|
|
405
|
+
return cache.osProperties;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
const osProperties = {
|
|
409
|
+
nodeVersion: process.version,
|
|
410
|
+
packageManager: {
|
|
411
|
+
name: packageManager.name,
|
|
412
|
+
},
|
|
413
|
+
platform: os.platform(),
|
|
414
|
+
arch: os.arch(),
|
|
415
|
+
cpus: {
|
|
416
|
+
model: os.cpus()[0].model,
|
|
417
|
+
count: os.cpus().length,
|
|
418
|
+
},
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
cache.osProperties = osProperties;
|
|
422
|
+
|
|
423
|
+
return osProperties;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
function getVcsProperties(): VcsProperties {
|
|
427
|
+
if (cache.vcsProperties) {
|
|
428
|
+
return cache.vcsProperties;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
const vcsProperties: VcsProperties = {};
|
|
432
|
+
|
|
433
|
+
if (process.env.CI_PROJECT_NAMESPACE) {
|
|
434
|
+
vcsProperties.tenant = process.env.CI_PROJECT_NAMESPACE;
|
|
435
|
+
}
|
|
436
|
+
if (process.env.CI_PROJECT_NAME) {
|
|
437
|
+
vcsProperties.repository = process.env.CI_PROJECT_NAME;
|
|
438
|
+
}
|
|
439
|
+
if (process.env.CI_PIPELINE_URL) {
|
|
440
|
+
vcsProperties.pipelineUrl = process.env.CI_PIPELINE_URL;
|
|
441
|
+
}
|
|
442
|
+
if (process.env.CI_JOB_URL) {
|
|
443
|
+
vcsProperties.jobUrl = process.env.CI_JOB_URL;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
cache.vcsProperties = vcsProperties;
|
|
447
|
+
|
|
448
|
+
return vcsProperties;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
export function resolveDependenciesProperties(): DependenciesProperties {
|
|
452
|
+
if (cache.dependenciesProperties) {
|
|
453
|
+
return cache.dependenciesProperties;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
const dependencies: DependenciesProperties = {};
|
|
457
|
+
|
|
458
|
+
try {
|
|
459
|
+
dependencies.react = require('react/package.json').version;
|
|
460
|
+
} catch (e) {
|
|
461
|
+
// do nothing
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
try {
|
|
465
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
466
|
+
dependencies.webpack = require('webpack/package.json').version;
|
|
467
|
+
} catch (e) {
|
|
468
|
+
// do nothing
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
try {
|
|
472
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
473
|
+
dependencies.babel = require('@babel/core/package.json').version;
|
|
474
|
+
} catch (e) {
|
|
475
|
+
// do nothing
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
try {
|
|
479
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
480
|
+
dependencies.swc = require('@swc/core/package.json').version;
|
|
481
|
+
} catch (e) {
|
|
482
|
+
// do nothing
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
cache.dependenciesProperties = dependencies;
|
|
486
|
+
|
|
487
|
+
return dependencies;
|
|
488
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { parentPort, workerData } from 'node:worker_threads';
|
|
2
|
+
import { logger } from '../logger';
|
|
3
|
+
import { enumerateErrorProperties } from '../../utils/errors';
|
|
4
|
+
|
|
5
|
+
declare global {
|
|
6
|
+
// eslint-disable-next-line no-var, vars-on-top
|
|
7
|
+
var __TRAMVAI_EXIT_HANDLERS__: Array<() => Promise<any>>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const { endpoint, debug, dryRun } = workerData;
|
|
11
|
+
|
|
12
|
+
const queue: Promise<any>[] = [];
|
|
13
|
+
|
|
14
|
+
parentPort?.on('message', async (message) => {
|
|
15
|
+
switch (message.event) {
|
|
16
|
+
case 'SEND_EVENT': {
|
|
17
|
+
sendEvent(message.payload);
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
case 'EXIT': {
|
|
21
|
+
await Promise.allSettled(queue);
|
|
22
|
+
parentPort?.postMessage({ event: 'SHUTDOWN_COMPLETE' });
|
|
23
|
+
process.exit(0);
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
async function sendEvent(event: Record<string, any>) {
|
|
30
|
+
try {
|
|
31
|
+
if (debug || dryRun) {
|
|
32
|
+
logger.event({
|
|
33
|
+
type: event.level.toLowerCase() as 'error' | 'warning' | 'info',
|
|
34
|
+
event: event.event,
|
|
35
|
+
message: event.message,
|
|
36
|
+
payload: event,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if ('error' in event && event.error instanceof Error) {
|
|
41
|
+
enumerateErrorProperties(event.error);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!dryRun) {
|
|
45
|
+
const abortController = new AbortController();
|
|
46
|
+
setTimeout(() => abortController.abort(new Error('request timeout')), 5000);
|
|
47
|
+
|
|
48
|
+
const request = fetch(endpoint, {
|
|
49
|
+
method: 'POST',
|
|
50
|
+
headers: { 'Content-Type': 'application/json' },
|
|
51
|
+
body: JSON.stringify([event]),
|
|
52
|
+
signal: abortController.signal,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
queue.push(request);
|
|
56
|
+
|
|
57
|
+
const response = await request;
|
|
58
|
+
|
|
59
|
+
if (!response.ok || response.status >= 400) {
|
|
60
|
+
logger.event({
|
|
61
|
+
type: 'error',
|
|
62
|
+
event: 'analytics-send-failed',
|
|
63
|
+
message: `Error sending analytics data, response with status: ${response.status}`,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// prevent infinite loop in case of error
|
|
67
|
+
if (event.event !== 'cli:analytics:send-failed') {
|
|
68
|
+
sendEvent({
|
|
69
|
+
event: 'cli:analytics:send-failed',
|
|
70
|
+
level: 'ERROR',
|
|
71
|
+
message: `Error sending analytics data, response with status: ${response.status}`,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
} catch (error) {
|
|
77
|
+
logger.event({
|
|
78
|
+
type: 'error',
|
|
79
|
+
event: 'analytics-send-failed',
|
|
80
|
+
message: `Error sending analytics data: ${error instanceof Error ? error.message : String(error)}`,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// prevent infinite loop in case of error
|
|
84
|
+
if (event.event !== 'cli:analytics:send-failed') {
|
|
85
|
+
sendEvent({
|
|
86
|
+
event: 'cli:analytics:send-failed',
|
|
87
|
+
level: 'ERROR',
|
|
88
|
+
message: `Error sending analytics data: ${error instanceof Error ? error.message : String(error)}`,
|
|
89
|
+
error,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async function runExitHandlersAndQuit(code: number) {
|
|
96
|
+
if (global.__TRAMVAI_EXIT_HANDLERS__) {
|
|
97
|
+
await Promise.allSettled(global.__TRAMVAI_EXIT_HANDLERS__.map((handler) => handler()));
|
|
98
|
+
}
|
|
99
|
+
process.exit(code);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
process.on('exit', async (code) => runExitHandlersAndQuit(code));
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { FeaturesProperties, ProjectProperties } from './analytics';
|
|
2
|
+
import { ConfigEntry } from '../../typings/configEntry/common';
|
|
3
|
+
import { ConfigManager } from '../config';
|
|
4
|
+
import { ApplicationConfigEntry, ChildAppConfigEntry } from '../../api';
|
|
5
|
+
|
|
6
|
+
const projectCache: { [key: string]: ProjectProperties } = {};
|
|
7
|
+
const featuresCache: { [key: string]: FeaturesProperties } = {};
|
|
8
|
+
|
|
9
|
+
const safeRequireResolve = (path: string) => {
|
|
10
|
+
try {
|
|
11
|
+
return require.resolve(path);
|
|
12
|
+
} catch (error) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export function getProjectProperties({
|
|
18
|
+
parameters,
|
|
19
|
+
configManager,
|
|
20
|
+
}: {
|
|
21
|
+
parameters: { target?: string };
|
|
22
|
+
configManager: ConfigManager;
|
|
23
|
+
}): ProjectProperties {
|
|
24
|
+
const projectName = parameters.target ?? 'unknown';
|
|
25
|
+
let project: ConfigEntry;
|
|
26
|
+
|
|
27
|
+
if (projectCache[projectName]) {
|
|
28
|
+
return projectCache[projectName];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
project = configManager.getProject(projectName);
|
|
33
|
+
} catch (error) {
|
|
34
|
+
// do nothing
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
projectCache[projectName] = {
|
|
38
|
+
name: project.name,
|
|
39
|
+
type: project?.type ?? 'unknown',
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
return projectCache[projectName];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function getFeaturesProperties({
|
|
46
|
+
parameters,
|
|
47
|
+
configManager,
|
|
48
|
+
}: {
|
|
49
|
+
parameters: { target?: string };
|
|
50
|
+
configManager: ConfigManager;
|
|
51
|
+
}): FeaturesProperties {
|
|
52
|
+
const projectName = parameters.target ?? 'unknown';
|
|
53
|
+
let project: ConfigEntry;
|
|
54
|
+
|
|
55
|
+
if (featuresCache[projectName]) {
|
|
56
|
+
return featuresCache[projectName];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
project = configManager.getProject(projectName);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
// do nothing
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
featuresCache[projectName] = {};
|
|
66
|
+
|
|
67
|
+
if (project) {
|
|
68
|
+
if (project.type === 'application') {
|
|
69
|
+
const applicationProject = project as ApplicationConfigEntry;
|
|
70
|
+
const transpilationLoader = applicationProject.experiments?.transpilation?.loader;
|
|
71
|
+
|
|
72
|
+
featuresCache[projectName].swc =
|
|
73
|
+
// @ts-expect-error incorrect branded type
|
|
74
|
+
(transpilationLoader === 'swc' ||
|
|
75
|
+
transpilationLoader?.development === 'swc' ||
|
|
76
|
+
transpilationLoader?.production === 'swc') ??
|
|
77
|
+
false;
|
|
78
|
+
|
|
79
|
+
featuresCache[projectName].fileSystemRouting =
|
|
80
|
+
applicationProject.fileSystemPages?.enabled ?? false;
|
|
81
|
+
|
|
82
|
+
featuresCache[projectName].reactCompiler =
|
|
83
|
+
!!applicationProject.experiments?.reactCompiler ?? false;
|
|
84
|
+
|
|
85
|
+
featuresCache[projectName].devTools = !!safeRequireResolve('@tramvai/module-dev-tools');
|
|
86
|
+
|
|
87
|
+
featuresCache[projectName].moduleImage = !!safeRequireResolve(
|
|
88
|
+
'@tramvai-tinkoff/module-image'
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
featuresCache[projectName].modulePwa = !!safeRequireResolve(
|
|
92
|
+
'@tramvai/module-progressive-web-app'
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
featuresCache[projectName].viewTransitions =
|
|
96
|
+
!!applicationProject.experiments?.viewTransitions ?? false;
|
|
97
|
+
|
|
98
|
+
featuresCache[projectName].transitionsRouterProvider =
|
|
99
|
+
!!(
|
|
100
|
+
applicationProject.experiments?.viewTransitions ||
|
|
101
|
+
applicationProject.experiments?.reactTransitions
|
|
102
|
+
) ?? false;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (project.type === 'child-app') {
|
|
106
|
+
const childAppProject = project as ChildAppConfigEntry;
|
|
107
|
+
const transpilationLoader = childAppProject.experiments?.transpilation?.loader;
|
|
108
|
+
|
|
109
|
+
featuresCache[projectName].swc =
|
|
110
|
+
// @ts-expect-error incorrect branded type
|
|
111
|
+
(transpilationLoader === 'swc' ||
|
|
112
|
+
transpilationLoader?.development === 'swc' ||
|
|
113
|
+
transpilationLoader?.production === 'swc') ??
|
|
114
|
+
false;
|
|
115
|
+
|
|
116
|
+
featuresCache[projectName].reactCompiler =
|
|
117
|
+
!!childAppProject.experiments?.reactCompiler ?? false;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return featuresCache[projectName];
|
|
122
|
+
}
|