@tramvai/cli 5.22.0 → 5.40.0

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.
Files changed (122) hide show
  1. package/README.md +38 -0
  2. package/bin/platform.js +26 -1
  3. package/bin/spawn.js +36 -8
  4. package/lib/api/start-prod/providers/application.js +2 -2
  5. package/lib/api/start-prod/providers/application.js.map +1 -1
  6. package/lib/builder/webpack/devServer/pool/process/pool.d.ts.map +1 -1
  7. package/lib/builder/webpack/devServer/pool/process/pool.js +2 -1
  8. package/lib/builder/webpack/devServer/pool/process/pool.js.map +1 -1
  9. package/lib/builder/webpack/devServer/pool/thread/pool.d.ts.map +1 -1
  10. package/lib/builder/webpack/devServer/pool/thread/pool.js +2 -1
  11. package/lib/builder/webpack/devServer/pool/thread/pool.js.map +1 -1
  12. package/lib/builder/webpack/devServer/server.d.ts.map +1 -1
  13. package/lib/builder/webpack/devServer/server.js +31 -2
  14. package/lib/builder/webpack/devServer/server.js.map +1 -1
  15. package/lib/builder/webpack/tokens.d.ts +3 -3
  16. package/lib/cli/CLI.d.ts +1 -1
  17. package/lib/cli/CLI.d.ts.map +1 -1
  18. package/lib/cli/CLI.js +2 -2
  19. package/lib/cli/CLI.js.map +1 -1
  20. package/lib/cli/index.d.ts.map +1 -1
  21. package/lib/cli/index.js +1 -2
  22. package/lib/cli/index.js.map +1 -1
  23. package/lib/commands/add/add.d.ts +3 -2
  24. package/lib/commands/add/add.d.ts.map +1 -1
  25. package/lib/commands/add/add.js +8 -2
  26. package/lib/commands/add/add.js.map +1 -1
  27. package/lib/commands/add/checkPackageValidator.d.ts +1 -1
  28. package/lib/commands/add/checkPackageValidator.d.ts.map +1 -1
  29. package/lib/commands/add/checkPackageValidator.js +7 -2
  30. package/lib/commands/add/checkPackageValidator.js.map +1 -1
  31. package/lib/commands/add/command.d.ts +8 -3
  32. package/lib/commands/add/command.d.ts.map +1 -1
  33. package/lib/commands/add/command.js +6 -1
  34. package/lib/commands/add/command.js.map +1 -1
  35. package/lib/commands/new/new.d.ts.map +1 -1
  36. package/lib/commands/new/new.js +22 -20
  37. package/lib/commands/new/new.js.map +1 -1
  38. package/lib/commands/new/steps/installDependencies.d.ts +4 -3
  39. package/lib/commands/new/steps/installDependencies.d.ts.map +1 -1
  40. package/lib/commands/new/steps/installDependencies.js +58 -20
  41. package/lib/commands/new/steps/installDependencies.js.map +1 -1
  42. package/lib/commands/update/update.d.ts.map +1 -1
  43. package/lib/commands/update/update.js +14 -3
  44. package/lib/commands/update/update.js.map +1 -1
  45. package/lib/commands/update/updatePackageJson.d.ts +1 -1
  46. package/lib/commands/update/updatePackageJson.d.ts.map +1 -1
  47. package/lib/commands/update/updatePackageJson.js +5 -11
  48. package/lib/commands/update/updatePackageJson.js.map +1 -1
  49. package/lib/config/configManager.d.ts +1 -1
  50. package/lib/config/configManager.d.ts.map +1 -1
  51. package/lib/config/constants.d.ts +0 -1
  52. package/lib/config/constants.d.ts.map +1 -1
  53. package/lib/config/constants.js +1 -2
  54. package/lib/config/constants.js.map +1 -1
  55. package/lib/config/utils.d.ts +2 -0
  56. package/lib/config/utils.d.ts.map +1 -0
  57. package/lib/config/utils.js +19 -0
  58. package/lib/config/utils.js.map +1 -0
  59. package/lib/di/tokens/config.d.ts +1 -1
  60. package/lib/library/webpack/application/client/dev.js +1 -1
  61. package/lib/library/webpack/application/client/dev.js.map +1 -1
  62. package/lib/library/webpack/application/client/prod/optimization/splitChunks.d.ts.map +1 -1
  63. package/lib/library/webpack/application/client/prod/optimization/splitChunks.js +51 -1
  64. package/lib/library/webpack/application/client/prod/optimization/splitChunks.js.map +1 -1
  65. package/lib/library/webpack/application/server/dev.js +1 -1
  66. package/lib/library/webpack/application/server/dev.js.map +1 -1
  67. package/lib/library/webpack/utils/threadLoader.d.ts.map +1 -1
  68. package/lib/library/webpack/utils/threadLoader.js +1 -0
  69. package/lib/library/webpack/utils/threadLoader.js.map +1 -1
  70. package/lib/models/context.d.ts +3 -3
  71. package/lib/models/context.d.ts.map +1 -1
  72. package/lib/models/context.js +1 -2
  73. package/lib/models/context.js.map +1 -1
  74. package/lib/schema/autogeneratedSchema.json +29 -24
  75. package/lib/typings/configEntry/application.d.ts +5 -0
  76. package/lib/typings/configEntry/application.d.ts.map +1 -1
  77. package/lib/typings/configEntry/cli.d.ts +1 -1
  78. package/lib/typings/configEntry/cli.d.ts.map +1 -1
  79. package/lib/utils/commands/dependencies/findTramvaiVersion.js +1 -1
  80. package/lib/utils/commands/dependencies/findTramvaiVersion.js.map +1 -1
  81. package/lib/utils/commands/dependencies/getWorkspaceRootByAppName.d.ts +3 -0
  82. package/lib/utils/commands/dependencies/getWorkspaceRootByAppName.d.ts.map +1 -0
  83. package/lib/utils/commands/dependencies/getWorkspaceRootByAppName.js +8 -0
  84. package/lib/utils/commands/dependencies/getWorkspaceRootByAppName.js.map +1 -0
  85. package/lib/utils/npmRequire.js +1 -1
  86. package/lib/utils/npmRequire.js.map +1 -1
  87. package/package.json +5 -4
  88. package/schema.json +29 -24
  89. package/src/api/start-prod/providers/application.ts +2 -2
  90. package/src/builder/webpack/devServer/pool/process/pool.ts +3 -2
  91. package/src/builder/webpack/devServer/pool/thread/pool.ts +3 -2
  92. package/src/builder/webpack/devServer/server.ts +38 -2
  93. package/src/cli/CLI.ts +1 -3
  94. package/src/cli/index.ts +1 -3
  95. package/src/commands/add/add.ts +17 -3
  96. package/src/commands/add/checkPackageValidator.ts +6 -2
  97. package/src/commands/add/command.ts +6 -1
  98. package/src/commands/new/new.ts +34 -21
  99. package/src/commands/new/steps/installDependencies.ts +75 -27
  100. package/src/commands/new/templates/monorepo-block/package.json.hbs +5 -0
  101. package/src/commands/new/templates/shared/package.json.hbs +2 -1
  102. package/src/commands/update/update.ts +26 -3
  103. package/src/commands/update/updatePackageJson.spec.ts +16 -10
  104. package/src/commands/update/updatePackageJson.ts +10 -15
  105. package/src/config/configManager.ts +1 -1
  106. package/src/config/constants.ts +0 -2
  107. package/src/config/utils.ts +18 -0
  108. package/src/library/swc/__integration__/swc.start.test.ts +3 -0
  109. package/src/library/webpack/application/client/dev.ts +1 -1
  110. package/src/library/webpack/application/client/prod/optimization/splitChunks.ts +66 -2
  111. package/src/library/webpack/application/server/dev.ts +1 -1
  112. package/src/library/webpack/utils/threadLoader.ts +1 -0
  113. package/src/models/config.spec.ts +2 -0
  114. package/src/models/context.ts +3 -2
  115. package/src/schema/autogeneratedSchema.json +29 -24
  116. package/src/schema/tramvai.spec.ts +1 -0
  117. package/src/typings/configEntry/application.ts +5 -0
  118. package/src/typings/configEntry/cli.ts +6 -1
  119. package/src/typings/webpack-chain/index.d.ts +1 -0
  120. package/src/utils/commands/dependencies/findTramvaiVersion.ts +1 -1
  121. package/src/utils/commands/dependencies/getWorkspaceRootByAppName.ts +5 -0
  122. package/src/utils/npmRequire.ts +1 -1
@@ -1,5 +1,7 @@
1
1
  import noop from '@tinkoff/utils/function/noop';
2
2
  import eachObj from '@tinkoff/utils/object/each';
3
+ import chokidar from 'chokidar';
4
+ import chalk from 'chalk';
3
5
  import path from 'path';
4
6
  import type webpack from 'webpack';
5
7
  import type Config from 'webpack-chain';
@@ -72,6 +74,7 @@ export const serverRunner = ({
72
74
  }
73
75
 
74
76
  const fs = serverCompiler.outputFileSystem as any;
77
+
75
78
  // ThreadWorkerPool is experimental
76
79
  // it doesn't work well when running integration tests in tramvai repo
77
80
  // mostly because of the some problems with `babel-plugin-lodash`
@@ -85,6 +88,7 @@ export const serverRunner = ({
85
88
  ? ThreadWorkerBridge
86
89
  : ProcessWorkerBridge
87
90
  );
91
+
88
92
  let worker: Worker | null;
89
93
  let serverInvalidated = true;
90
94
  let workerPort: number | null;
@@ -260,14 +264,14 @@ export const serverRunner = ({
260
264
  }
261
265
  });
262
266
 
263
- compiler.hooks.done.tap(HOOK_NAME, async (stats) => {
267
+ async function runWorker(stats?: any) {
264
268
  if (serverInvalidated) {
265
269
  workerPort = null;
266
270
  workerPortPromise = null;
267
271
 
268
272
  serverInvalidated = false;
269
273
 
270
- if (stats.hasErrors()) {
274
+ if (stats?.hasErrors()) {
271
275
  // всплыли ошибки при сборке - просто игнорим калбек чтобы не падать ниже и дать возможность выполнить пересборку
272
276
  return;
273
277
  }
@@ -313,6 +317,38 @@ export const serverRunner = ({
313
317
 
314
318
  await send(worker, 'script', { filename: realFilename, script });
315
319
  }
320
+ }
321
+
322
+ // отключаем watch за при выключенном rebuild
323
+ if (!configManager.noServerRebuild) {
324
+ const watchedFileName = 'env.development.js';
325
+ try {
326
+ const envPath = path.resolve(process.cwd(), watchedFileName);
327
+ const watchHandler = (_changedFilePath) => {
328
+ console.log(chalk.yellow(`${envPath} changed, restart server...`));
329
+ serverInvalidated = true;
330
+ runWorker();
331
+ };
332
+
333
+ const watcher = chokidar.watch(envPath);
334
+ watcher.on('change', watchHandler);
335
+
336
+ di.register({
337
+ provide: CLOSE_HANDLER_TOKEN,
338
+ multi: true,
339
+ useValue: () => {
340
+ watcher.close();
341
+ },
342
+ });
343
+ } catch (err) {
344
+ console.error(
345
+ `Something went wrong while watching for changes in ${watchedFileName}: ${err}`
346
+ );
347
+ }
348
+ }
349
+
350
+ compiler.hooks.done.tap(HOOK_NAME, async (stats) => {
351
+ runWorker(stats);
316
352
  });
317
353
  };
318
354
  };
package/src/cli/CLI.ts CHANGED
@@ -49,8 +49,7 @@ export class CLI {
49
49
  config: ConfigManager,
50
50
  analytics: Analytics,
51
51
  cliRootDir: string,
52
- cliPackageManager: PackageManager,
53
- packageManager: PackageManager
52
+ cliPackageManager: PackageManager
54
53
  ) {
55
54
  this.context = new Context(
56
55
  config,
@@ -58,7 +57,6 @@ export class CLI {
58
57
  analytics,
59
58
  cliRootDir,
60
59
  cliPackageManager,
61
- packageManager,
62
60
  this.runTask,
63
61
  this.runCommand,
64
62
  this.getTasks,
package/src/cli/index.ts CHANGED
@@ -77,7 +77,6 @@ export async function cliInitialized(cliArgs = process.argv) {
77
77
  });
78
78
 
79
79
  const configManager = new ConfigManager({ config, syncConfigFile: syncJsonFile });
80
- const packageManager = resolvePackageManager({ rootDir: process.cwd() });
81
80
 
82
81
  const cliRootDir = path.resolve(__dirname, '../', '../');
83
82
  const cliPackageManager = new NpmPackageManager({
@@ -91,8 +90,7 @@ export async function cliInitialized(cliArgs = process.argv) {
91
90
  configManager,
92
91
  analytic,
93
92
  cliRootDir,
94
- cliPackageManager,
95
- packageManager
93
+ cliPackageManager
96
94
  );
97
95
 
98
96
  return await cliInstance.run(cliArgs);
@@ -3,13 +3,18 @@ import type { CommandResult } from '../../models/command';
3
3
  import { migrate } from '../../utils/commands/dependencies/migrate';
4
4
  import { findTramvaiVersion } from '../../utils/commands/dependencies/findTramvaiVersion';
5
5
  import { checkVersions } from '../../utils/commands/dependencies/checkVersions';
6
+ import { getWorkspaceRootByAppName } from '../../utils/commands/dependencies/getWorkspaceRootByAppName';
6
7
 
7
8
  export type Params = {
8
- packageName: string;
9
+ packageNames: string | string[];
9
10
  dev?: boolean;
11
+ app?: string;
10
12
  };
11
13
 
12
- export default async (context: Context, { packageName, dev }: Params): Promise<CommandResult> => {
14
+ export default async (
15
+ context: Context,
16
+ { packageNames, dev, app }: Params
17
+ ): Promise<CommandResult> => {
13
18
  const version = await findTramvaiVersion();
14
19
 
15
20
  if (!version) {
@@ -18,10 +23,19 @@ export default async (context: Context, { packageName, dev }: Params): Promise<C
18
23
  );
19
24
  }
20
25
 
26
+ const workspace = app ? getWorkspaceRootByAppName(context, app) : undefined;
27
+
28
+ if (workspace && !context.packageManager.isWorkspaceExists(workspace)) {
29
+ throw new Error(
30
+ `Workspace ${workspace} for app ${app} is not exists. Check your package.json and tramvai.json`
31
+ );
32
+ }
33
+
21
34
  await context.packageManager.install({
22
- name: packageName,
35
+ packageNames,
23
36
  version,
24
37
  devDependency: dev,
38
+ workspace,
25
39
  stdio: 'inherit',
26
40
  });
27
41
 
@@ -1,8 +1,12 @@
1
1
  import latestVersion from 'latest-version';
2
2
  import type { Params } from './add';
3
3
 
4
- export const checkPackage = async (_, { packageName }: Params) => {
5
- await latestVersion(packageName);
4
+ export const checkPackage = async (_, { packageNames }: Params) => {
5
+ if (Array.isArray(packageNames)) {
6
+ await Promise.all(packageNames.map((packageName) => latestVersion(packageName)));
7
+ } else {
8
+ await latestVersion(packageNames);
9
+ }
6
10
 
7
11
  return {
8
12
  name: 'checkPackage',
@@ -7,13 +7,18 @@ class AddCommand extends CLICommand {
7
7
 
8
8
  description = 'Tramvai package install command';
9
9
 
10
- command = 'add <packageName>';
10
+ command = 'add <packageNames...>';
11
11
 
12
12
  options = [
13
13
  {
14
14
  name: '-D, --dev',
15
15
  description: 'Save package to devDependencies',
16
16
  },
17
+ {
18
+ name: '-a, --app',
19
+ value: '[app]',
20
+ description: 'Install package in app-specific workspace',
21
+ },
17
22
  ];
18
23
 
19
24
  alias = '';
@@ -1,6 +1,7 @@
1
1
  import path from 'path';
2
2
  import chalk from 'chalk';
3
3
  import inquirer from 'inquirer';
4
+ import { packageManagerFactory } from '@tinkoff/package-manager-wrapper';
4
5
  import type { Context } from '../../models/context';
5
6
  import type { CommandResult } from '../../models/command';
6
7
  import type { Params } from './typings';
@@ -64,41 +65,53 @@ export default async function createNew(context: Context, params: Params): Promi
64
65
  const templateDir = getPathToTemplate(type, template);
65
66
  const sharedDir = getPathToShared();
66
67
  const blockDir = getPathToBlock(type);
67
- const isNpm = packageManager === 'npm';
68
- const isYarn = packageManager === 'yarn';
69
- const isJest = testingFramework === 'jest';
70
-
68
+ const isMonorepo = template === 'monorepo';
69
+ const baseDir = type === 'app' ? 'apps' : 'child-apps';
71
70
  const blockDirectoryName = {
72
- monorepo: path.join(type === 'app' ? 'apps' : 'child-apps', name),
71
+ monorepo: path.join(baseDir, name),
73
72
  multirepo: 'src',
74
73
  }[template];
75
74
 
76
- await renderTemplate(templateDir, directoryName, { configEntry, isJest, isNpm, isYarn });
77
- await renderTemplate(sharedDir, directoryName, { configEntry, isJest, isNpm, isYarn });
78
- await renderTemplate(blockDir, path.join(directoryName, blockDirectoryName), {
75
+ const templateData = {
79
76
  configEntry,
80
- isJest,
81
- isNpm,
82
- isYarn,
83
- });
77
+ isJest: testingFramework === 'jest',
78
+ isNpm: packageManager === 'npm',
79
+ isYarn: packageManager === 'yarn',
80
+ workspaceBaseDir: isMonorepo ? baseDir : undefined,
81
+ };
82
+
83
+ await renderTemplate(templateDir, directoryName, templateData);
84
+ await renderTemplate(sharedDir, directoryName, templateData);
85
+ await renderTemplate(blockDir, path.join(directoryName, blockDirectoryName), templateData);
84
86
  if (template === 'monorepo') {
85
87
  const monorepoBlockDir = getPathToMonorepoBlock();
86
88
 
87
- await renderTemplate(monorepoBlockDir, path.join(directoryName, blockDirectoryName), {
88
- configEntry,
89
- isJest,
90
- });
89
+ await renderTemplate(
90
+ monorepoBlockDir,
91
+ path.join(directoryName, blockDirectoryName),
92
+ templateData
93
+ );
91
94
  }
92
95
 
93
96
  if (testingFramework !== 'none') {
94
- await renderTemplate(getPathToTestingFramework(type, testingFramework), directoryName, {
95
- configEntry,
96
- isJest,
97
- });
97
+ await renderTemplate(
98
+ getPathToTestingFramework(type, testingFramework),
99
+ directoryName,
100
+ templateData
101
+ );
98
102
  }
99
103
 
100
104
  await initializationGit(directoryName);
101
- await installDependencies({ localDir: directoryName, type, packageManager, testingFramework });
105
+ await installDependencies({
106
+ localDir: directoryName,
107
+ type,
108
+ packageManager: packageManagerFactory(
109
+ { rootDir: path.resolve(process.cwd(), directoryName) },
110
+ packageManager
111
+ ),
112
+ testingFramework,
113
+ workspace: isMonorepo ? blockDirectoryName : undefined,
114
+ });
102
115
 
103
116
  console.log(
104
117
  `\n\n Project ${name} has been successfully created. To run the project, enter in the terminal`,
@@ -1,7 +1,5 @@
1
- import type { Options } from 'execa';
2
- import execa from 'execa';
3
1
  import chalk from 'chalk';
4
- import type { PackageManagers } from '../questions/packageManager';
2
+ import type { InstallOptions, PackageManager } from '@tinkoff/package-manager-wrapper';
5
3
  import type { TestingFrameworks } from '../questions/testingFramework';
6
4
  import type { Type } from '../questions/type';
7
5
 
@@ -57,7 +55,6 @@ const devDependencies = [
57
55
  '@tinkoff/eslint-config',
58
56
  '@tinkoff/eslint-config-react',
59
57
  '@tinkoff/eslint-plugin-tramvai',
60
- '@tramvai/cli',
61
58
  '@types/react',
62
59
  'postcss-custom-media',
63
60
  'postcss-custom-properties',
@@ -69,56 +66,107 @@ const devDependencies = [
69
66
  'typescript',
70
67
  ];
71
68
 
72
- const packagesInstallCommands: Record<PackageManagers, { deps: string[]; devDeps: string[] }> = {
73
- npm: {
74
- deps: ['install', '--save', '--package-lock', '--legacy-peer-deps'],
75
- devDeps: ['install', '--save-dev', '--legacy-peer-deps'],
76
- },
77
- yarn: {
78
- deps: ['add'],
79
- devDeps: ['add', '--dev'],
80
- },
81
- pnpm: {
82
- deps: ['add'],
83
- devDeps: ['add', '--save-dev'],
84
- },
69
+ const rootDependencies = {
70
+ devDependencies: ['@tramvai/cli'],
71
+ dependencies: [],
85
72
  };
86
73
 
74
+ function getBaseDeps(type: Type, isDev: boolean) {
75
+ const depsMap = DEPS[type];
76
+ const jestDeps = depsMap.jestDevDependencies;
77
+ const baseDeps = isDev ? devDependencies : depsMap.dependencies;
78
+ const rootDeps = rootDependencies[isDev ? 'devDependencies' : 'dependencies'];
79
+
80
+ return { rootDeps, baseDeps, jestDeps };
81
+ }
82
+
83
+ function getDeps(type: Type, options?: { isDev?: boolean; isRoot?: boolean }) {
84
+ const { rootDeps, baseDeps } = getBaseDeps(type, options?.isDev);
85
+
86
+ return [...rootDeps, ...baseDeps];
87
+ }
88
+
89
+ function getDepsWorkspace(type: Type, options?: { isDev?: boolean; isRoot?: boolean }) {
90
+ const { rootDeps, baseDeps } = getBaseDeps(type, options?.isDev);
91
+
92
+ if (options?.isRoot) {
93
+ return rootDeps;
94
+ }
95
+
96
+ return baseDeps;
97
+ }
98
+
99
+ function jestDeps(type: Type) {
100
+ return getBaseDeps(type, true).jestDeps;
101
+ }
102
+
87
103
  export async function installDependencies({
88
104
  localDir,
89
105
  type,
90
106
  packageManager,
91
107
  testingFramework,
108
+ workspace,
92
109
  }: {
93
110
  localDir: string;
94
111
  type: Type;
95
- packageManager: PackageManagers;
112
+ packageManager: PackageManager;
96
113
  testingFramework: TestingFrameworks;
114
+ workspace?: string;
97
115
  }) {
98
- const installCommands = packagesInstallCommands[packageManager];
99
- const options: Options = {
116
+ const deps = workspace ? getDepsWorkspace : getDeps;
117
+
118
+ const options: InstallOptions = {
100
119
  cwd: localDir,
101
120
  env: {
102
121
  SKIP_TRAMVAI_MIGRATIONS: 'true',
103
122
  },
104
123
  stdio: 'inherit',
124
+ workspace,
105
125
  };
106
126
 
127
+ // Install cli and core packages into the root of repository if using workspaces for update command to work correctly
128
+ if (workspace !== undefined) {
129
+ console.log(`${chalk.blue('[DEPENDENCIES]')} Installing root dependencies`);
130
+
131
+ await packageManager.install({
132
+ packageNames: deps(type, { isDev: true, isRoot: true }),
133
+ devDependency: true,
134
+ ...options,
135
+ workspace: undefined,
136
+ });
137
+
138
+ console.log(`${chalk.blue('[DEPENDENCIES]')} Installing root dev dependencies`);
139
+
140
+ await packageManager.install({
141
+ packageNames: deps(type, { isDev: false, isRoot: true }),
142
+ devDependency: false,
143
+ ...options,
144
+ workspace: undefined,
145
+ });
146
+ }
147
+
107
148
  console.log(`${chalk.blue('[DEPENDENCIES]')} Installing app dependencies`);
108
149
 
109
- await execa(packageManager, [...installCommands.deps, ...DEPS[type].dependencies], options);
150
+ await packageManager.install({
151
+ packageNames: deps(type),
152
+ ...options,
153
+ });
110
154
 
111
155
  console.log(`${chalk.blue('[DEPENDENCIES]')} Installing dev dependencies`);
112
156
 
113
- await execa(packageManager, [...installCommands.devDeps, ...devDependencies], options);
157
+ await packageManager.install({
158
+ packageNames: deps(type, { isDev: true }),
159
+ devDependency: true,
160
+ ...options,
161
+ });
114
162
 
115
163
  if (testingFramework === 'jest') {
116
164
  console.log(`${chalk.blue('[DEPENDENCIES]')} Installing jest dependencies`);
117
165
 
118
- await execa(
119
- packageManager,
120
- [...installCommands.devDeps, ...DEPS[type].jestDevDependencies],
121
- options
122
- );
166
+ await packageManager.install({
167
+ packageNames: jestDeps(type),
168
+ devDependency: true,
169
+ ...options,
170
+ });
123
171
  }
124
172
  }
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "{{configEntry.name}}",
3
+ "version": "0.0.0-stub",
4
+ "private": true
5
+ }
@@ -22,5 +22,6 @@
22
22
  "*.{js,jsx,ts,tsx}": [
23
23
  "eslint --fix"
24
24
  ]
25
- }
25
+ }{{#if workspaceBaseDir}},
26
+ "workspaces": ["{{workspaceBaseDir}}/*"]{{/if}}
26
27
  }
@@ -4,6 +4,8 @@ import { getLatestPackageVersion } from '../../utils/commands/dependencies/getLa
4
4
  import { migrate } from '../../utils/commands/dependencies/migrate';
5
5
  import { updatePackageJson } from './updatePackageJson';
6
6
  import { checkVersions } from '../../utils/commands/dependencies/checkVersions';
7
+ import moduleVersion from '../../utils/moduleVersion';
8
+ import { findTramvaiVersion } from '../../utils/commands/dependencies/findTramvaiVersion';
7
9
 
8
10
  export type Params = {
9
11
  to: string;
@@ -13,15 +15,36 @@ export default async (
13
15
  context: Context,
14
16
  { to: version = 'latest' }: Params
15
17
  ): Promise<CommandResult> => {
16
- const versionNumber = await getLatestPackageVersion('@tramvai/core', version);
18
+ const targetVersion = await getLatestPackageVersion('@tramvai/cli', version);
19
+ const currentVersion = await findTramvaiVersion();
20
+
21
+ if (!currentVersion) {
22
+ throw new Error(
23
+ 'Could not resolve tramvai version from package.json. Do you have @tramvai/core installed?'
24
+ );
25
+ }
26
+
27
+ if (currentVersion === version) {
28
+ throw new Error(
29
+ 'The installed version is equal to the current version, no update is required.'
30
+ );
31
+ }
17
32
 
18
33
  context.logger.event({
19
34
  type: 'info',
20
35
  event: 'resolving-version',
21
- message: `Tramvai version resolved to ${versionNumber}`,
36
+ message: `Tramvai version resolved to ${targetVersion}`,
22
37
  });
23
38
 
24
- await updatePackageJson(versionNumber, version === 'prerelease');
39
+ if (context.packageManager.workspaces) {
40
+ await Promise.all(
41
+ context.packageManager.workspaces.map((directory) =>
42
+ updatePackageJson(targetVersion, currentVersion, version === 'prerelease', directory)
43
+ )
44
+ );
45
+ }
46
+
47
+ await updatePackageJson(targetVersion, currentVersion, version === 'prerelease');
25
48
 
26
49
  context.logger.event({
27
50
  type: 'info',
@@ -1,8 +1,12 @@
1
+ import { resolve } from 'path';
1
2
  import { updatePackageJson } from './updatePackageJson';
2
3
 
3
4
  const LATEST_TRAMVAI_VERSION = '1.115.6';
4
5
  const LATEST_LIB_VERSION = '0.8.23';
5
6
  const PRERELEASE_LIB_VERSION = '2.0.1';
7
+ const CURRENT_TRAMVAI_VERSION = '1.93.2';
8
+
9
+ const packageJsonPath = resolve('package.json');
6
10
 
7
11
  let mockPackageJson: Record<string, any>;
8
12
  const mockFsWrite = jest.fn();
@@ -38,13 +42,13 @@ beforeEach(() => {
38
42
  it('should update tramvai deps to latest versions', async () => {
39
43
  mockPackageJson = {
40
44
  dependencies: {
41
- '@tramvai/core': '1.93.2',
42
- '@tramvai/module-common': '1.93.2',
45
+ '@tramvai/core': CURRENT_TRAMVAI_VERSION,
46
+ '@tramvai/module-common': CURRENT_TRAMVAI_VERSION,
43
47
  '@tinkoff/router': '^0.2.3',
44
48
  '@tinkoff/url': '0.3.2',
45
49
  },
46
50
  devDependencies: {
47
- '@tramvai/cli': '1.93.2',
51
+ '@tramvai/cli': CURRENT_TRAMVAI_VERSION,
48
52
  },
49
53
  peerDependencies: {
50
54
  '@tinkoff/dippy': '0.7.10',
@@ -72,11 +76,12 @@ it('should update tramvai deps to latest versions', async () => {
72
76
  return {};
73
77
  });
74
78
 
75
- await updatePackageJson(LATEST_TRAMVAI_VERSION);
79
+ await updatePackageJson(LATEST_TRAMVAI_VERSION, CURRENT_TRAMVAI_VERSION);
76
80
 
81
+ // eslint-disable-next-line jest/no-interpolation-in-snapshots
77
82
  expect(mockFsWrite.mock.calls[0]).toMatchInlineSnapshot(`
78
83
  [
79
- "package.json",
84
+ "${packageJsonPath}",
80
85
  "{
81
86
  "dependencies": {
82
87
  "@tramvai/core": "1.115.6",
@@ -98,14 +103,14 @@ it('should update tramvai deps to latest versions', async () => {
98
103
  it('prerelease should be used for dependant libs', async () => {
99
104
  mockPackageJson = {
100
105
  dependencies: {
101
- '@tramvai/core': '1.93.2',
102
- '@tramvai/module-common': '1.93.2',
106
+ '@tramvai/core': CURRENT_TRAMVAI_VERSION,
107
+ '@tramvai/module-common': CURRENT_TRAMVAI_VERSION,
103
108
  '@tinkoff/router': '^0.2.3',
104
109
  '@tinkoff/url': '0.3.2',
105
110
  '@tinkoff/pack-polyfills': '1.0.0',
106
111
  },
107
112
  devDependencies: {
108
- '@tramvai/cli': '1.93.2',
113
+ '@tramvai/cli': CURRENT_TRAMVAI_VERSION,
109
114
  },
110
115
  peerDependencies: {
111
116
  '@tinkoff/dippy': '0.7.10',
@@ -133,11 +138,12 @@ it('prerelease should be used for dependant libs', async () => {
133
138
  return {};
134
139
  });
135
140
 
136
- await updatePackageJson(LATEST_TRAMVAI_VERSION, true);
141
+ await updatePackageJson(LATEST_TRAMVAI_VERSION, CURRENT_TRAMVAI_VERSION, true);
137
142
 
143
+ // eslint-disable-next-line jest/no-interpolation-in-snapshots
138
144
  expect(mockFsWrite.mock.calls[0]).toMatchInlineSnapshot(`
139
145
  [
140
- "package.json",
146
+ "${packageJsonPath}",
141
147
  "{
142
148
  "dependencies": {
143
149
  "@tramvai/core": "1.115.6",
@@ -3,6 +3,7 @@ import fs from 'fs';
3
3
  import pMap from 'p-map';
4
4
  import type { Ora } from 'ora';
5
5
  import ora from 'ora';
6
+ import { resolve } from 'path';
6
7
  import { packageHasVersion } from '../../utils/commands/dependencies/packageHasVersion';
7
8
  import { getLibPackageVersion } from './dependantLibs';
8
9
  import { isDependantLib, isUnifiedVersion } from '../../utils/tramvaiVersions';
@@ -61,21 +62,15 @@ const updateDependencies = (
61
62
  );
62
63
  };
63
64
 
64
- export const updatePackageJson = async (version: string, prerelease?: boolean) => {
65
- const file = fs.readFileSync('package.json');
65
+ export const updatePackageJson = async (
66
+ version: string,
67
+ currentVersion: string,
68
+ prerelease?: boolean,
69
+ path = '.'
70
+ ) => {
71
+ const packageJsonPath = resolve(path, 'package.json');
72
+ const file = fs.readFileSync(packageJsonPath);
66
73
  const content = JSON.parse(file.toString());
67
- const currentVersion = getVersionFromDep(content.dependencies['@tramvai/core']);
68
-
69
- if (!currentVersion) {
70
- throw new Error(
71
- "Couldn't resolve current tramvai version, do you have '@tramvai/core' package in your dependencies?"
72
- );
73
- }
74
-
75
- if (currentVersion === version) {
76
- console.error('The installed version is equal to the current version, no update is required.');
77
- return;
78
- }
79
74
 
80
75
  const spinner = ora(`Updating package.json versions`).start();
81
76
 
@@ -90,7 +85,7 @@ export const updatePackageJson = async (version: string, prerelease?: boolean) =
90
85
  spinner
91
86
  );
92
87
 
93
- fs.writeFileSync('package.json', JSON.stringify(content, null, 2));
88
+ fs.writeFileSync(packageJsonPath, JSON.stringify(content, null, 2));
94
89
  } finally {
95
90
  spinner.stop();
96
91
  }
@@ -25,7 +25,7 @@ export interface Settings<E extends Env> {
25
25
  rootDir?: string;
26
26
  version?: string;
27
27
  buildType?: BuildType;
28
- debug?: boolean;
28
+ debug?: string | boolean;
29
29
  verboseWebpack?: boolean;
30
30
  trace?: boolean;
31
31
  sourceMap?: boolean;
@@ -1,5 +1,3 @@
1
1
  export const extensions = ['.mjs', '.js', '.jsx', '.ts', '.tsx'];
2
2
 
3
- export const DEBUG_ARGV = ['--inspect', '-r', 'source-map-support/register'];
4
-
5
3
  export const TRACE_ARGV = ['--trace-warnings', '--trace-uncaught'];
@@ -0,0 +1,18 @@
1
+ export function getDebugArg(debugEnv: boolean | string | undefined) {
2
+ if (!debugEnv) {
3
+ return [];
4
+ }
5
+
6
+ const sourceMapsArg = ['-r', 'source-map-support/register'];
7
+ const baseDebugArgs = ['--inspect', ...sourceMapsArg];
8
+
9
+ if (debugEnv === 'wait') {
10
+ return ['--inspect-wait', ...sourceMapsArg];
11
+ }
12
+
13
+ if (debugEnv === 'break') {
14
+ return ['--inspect-brk', ...sourceMapsArg];
15
+ }
16
+
17
+ return baseDebugArgs;
18
+ }
@@ -33,6 +33,9 @@ beforeAll(async () => {
33
33
  strictErrorHandle: true,
34
34
  config: {
35
35
  name: 'swc-app',
36
+ webpack: {
37
+ devtool: 'eval',
38
+ },
36
39
  type: 'application',
37
40
  root: './',
38
41
  experiments: {
@@ -45,7 +45,7 @@ export const webpackClientConfig = ({
45
45
 
46
46
  config.mode('development');
47
47
 
48
- config.devtool(configManager.webpack.devtool ?? 'eval');
48
+ config.devtool(configManager.webpack.devtool ?? false);
49
49
 
50
50
  if (configManager.sourceMap) {
51
51
  config.batch(sourcemaps(configManager));