@tramvai/cli 2.11.0 → 2.21.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 (130) hide show
  1. package/README.md +12 -0
  2. package/lib/api/analyze/index.d.ts +1 -0
  3. package/lib/api/analyze/index.js.map +1 -1
  4. package/lib/api/build/index.d.ts +1 -0
  5. package/lib/api/build/index.js.map +1 -1
  6. package/lib/api/start/index.d.ts +1 -0
  7. package/lib/api/start/index.js.map +1 -1
  8. package/lib/api/start/utils/banner.js +1 -1
  9. package/lib/api/start/utils/banner.js.map +1 -1
  10. package/lib/api/start-prod/index.d.ts +1 -0
  11. package/lib/api/start-prod/index.js.map +1 -1
  12. package/lib/builder/webpack/providers/analyze/shared.js +23 -24
  13. package/lib/builder/webpack/providers/analyze/shared.js.map +1 -1
  14. package/lib/commands/analyze/command.d.ts +8 -0
  15. package/lib/commands/analyze/command.js +6 -0
  16. package/lib/commands/analyze/command.js.map +1 -1
  17. package/lib/commands/build/command.js +6 -0
  18. package/lib/commands/build/command.js.map +1 -1
  19. package/lib/commands/new/steps/initializationGit.js +2 -2
  20. package/lib/commands/new/steps/initializationGit.js.map +1 -1
  21. package/lib/commands/new/steps/installDependencies.js +10 -6
  22. package/lib/commands/new/steps/installDependencies.js.map +1 -1
  23. package/lib/commands/new/steps/renderTemplate.js +1 -1
  24. package/lib/commands/new/steps/renderTemplate.js.map +1 -1
  25. package/lib/commands/new/utils/applyTemplate.js +1 -1
  26. package/lib/commands/new/utils/applyTemplate.js.map +1 -1
  27. package/lib/commands/start/command.js +6 -0
  28. package/lib/commands/start/command.js.map +1 -1
  29. package/lib/commands/start-prod/command.js +6 -0
  30. package/lib/commands/start-prod/command.js.map +1 -1
  31. package/lib/commands/static/command.d.ts +6 -0
  32. package/lib/commands/static/command.js +6 -0
  33. package/lib/commands/static/command.js.map +1 -1
  34. package/lib/commands/update/dependantLibs.d.ts +2 -0
  35. package/lib/commands/update/dependantLibs.js +43 -0
  36. package/lib/commands/update/dependantLibs.js.map +1 -0
  37. package/lib/commands/update/updatePackageJson.js +7 -24
  38. package/lib/commands/update/updatePackageJson.js.map +1 -1
  39. package/lib/config/configManager.d.ts +3 -0
  40. package/lib/config/configManager.js +10 -7
  41. package/lib/config/configManager.js.map +1 -1
  42. package/lib/external/pages.d.ts +3 -5
  43. package/lib/external/pages.js.map +1 -1
  44. package/lib/library/webpack/application/client/common.js +1 -1
  45. package/lib/library/webpack/application/client/common.js.map +1 -1
  46. package/lib/library/webpack/application/server/common.js +1 -1
  47. package/lib/library/webpack/application/server/common.js.map +1 -1
  48. package/lib/library/webpack/blocks/configToEnv.js +1 -1
  49. package/lib/library/webpack/blocks/configToEnv.js.map +1 -1
  50. package/lib/library/webpack/blocks/filesClient.js +5 -2
  51. package/lib/library/webpack/blocks/filesClient.js.map +1 -1
  52. package/lib/library/webpack/blocks/filesServer.js +9 -5
  53. package/lib/library/webpack/blocks/filesServer.js.map +1 -1
  54. package/lib/library/webpack/blocks/pagesResolve.js +1 -1
  55. package/lib/library/webpack/blocks/pagesResolve.js.map +1 -1
  56. package/lib/library/webpack/common/main.js +17 -16
  57. package/lib/library/webpack/common/main.js.map +1 -1
  58. package/lib/library/webpack/loaders/image-loader/index.d.ts +5 -0
  59. package/lib/library/webpack/loaders/image-loader/index.js +25 -0
  60. package/lib/library/webpack/loaders/image-loader/index.js.map +1 -0
  61. package/lib/schema/autogeneratedSchema.json +165 -294
  62. package/lib/typings/configEntry/common.d.ts +169 -175
  63. package/lib/utils/commands/dependencies/checkVersions.js +3 -11
  64. package/lib/utils/commands/dependencies/checkVersions.js.map +1 -1
  65. package/lib/utils/commands/dependencies/getLatestPackageVersion.d.ts +1 -1
  66. package/lib/utils/commands/dependencies/getLatestPackageVersion.js +2 -6
  67. package/lib/utils/commands/dependencies/getLatestPackageVersion.js.map +1 -1
  68. package/lib/utils/commands/dependencies/getPackageInfo.d.ts +1 -0
  69. package/lib/utils/commands/dependencies/getPackageInfo.js +13 -0
  70. package/lib/utils/commands/dependencies/getPackageInfo.js.map +1 -0
  71. package/lib/utils/commands/dependencies/migrate.js +3 -11
  72. package/lib/utils/commands/dependencies/migrate.js.map +1 -1
  73. package/lib/utils/npmRequire.d.ts +15 -0
  74. package/lib/utils/npmRequire.js +15 -0
  75. package/lib/utils/npmRequire.js.map +1 -1
  76. package/lib/validators/commands/runMigrationsAndCheckVersions.js +3 -7
  77. package/lib/validators/commands/runMigrationsAndCheckVersions.js.map +1 -1
  78. package/package.json +88 -85
  79. package/schema.json +165 -294
  80. package/src/api/analyze/index.ts +1 -0
  81. package/src/api/build/__integration__/__fixtures__/tramvai.json +3 -0
  82. package/src/api/build/__integration__/build.test.ts +1 -0
  83. package/src/api/build/index.ts +1 -0
  84. package/src/api/start/__integration__/__fixtures__/tramvai.json +2 -4
  85. package/src/api/start/index.ts +1 -0
  86. package/src/api/start/utils/banner.ts +1 -1
  87. package/src/api/start-prod/index.ts +1 -0
  88. package/src/builder/webpack/providers/analyze/shared.ts +1 -1
  89. package/src/commands/analyze/command.ts +6 -0
  90. package/src/commands/build/command.ts +6 -0
  91. package/src/commands/new/steps/initializationGit.ts +3 -2
  92. package/src/commands/new/steps/installDependencies.ts +15 -8
  93. package/src/commands/new/steps/renderTemplate.ts +1 -1
  94. package/src/commands/new/templates/app/monorepo/tramvai.json.hbs +2 -4
  95. package/src/commands/new/templates/app/multirepo/tramvai.json.hbs +2 -4
  96. package/src/commands/new/templates/shared/_npmrc.hbs +0 -1
  97. package/src/commands/new/utils/applyTemplate.ts +5 -1
  98. package/src/commands/start/command.ts +6 -0
  99. package/src/commands/start-prod/command.ts +6 -0
  100. package/src/commands/static/command.ts +6 -0
  101. package/src/commands/update/dependantLibs.ts +49 -0
  102. package/src/commands/update/updatePackageJson.spec.ts +99 -0
  103. package/src/commands/update/updatePackageJson.ts +7 -25
  104. package/src/config/configManager.ts +9 -3
  105. package/src/external/pages.ts +3 -5
  106. package/src/library/webpack/application/client/common.ts +1 -3
  107. package/src/library/webpack/application/server/common.ts +1 -3
  108. package/src/library/webpack/blocks/configToEnv.ts +1 -1
  109. package/src/library/webpack/blocks/filesClient.ts +5 -2
  110. package/src/library/webpack/blocks/filesServer.ts +8 -5
  111. package/src/library/webpack/blocks/pagesResolve.ts +1 -1
  112. package/src/library/webpack/common/main.ts +19 -18
  113. package/src/library/webpack/loaders/image-loader/index.ts +26 -0
  114. package/src/schema/autogeneratedSchema.json +165 -294
  115. package/src/schema/tramvai.spec.ts +146 -148
  116. package/src/typings/configEntry/common.ts +171 -175
  117. package/src/utils/commands/dependencies/checkVersions.ts +3 -13
  118. package/src/utils/commands/dependencies/getLatestPackageVersion.ts +2 -7
  119. package/src/utils/commands/dependencies/getPackageInfo.ts +10 -0
  120. package/src/utils/commands/dependencies/migrate.ts +3 -13
  121. package/src/utils/npmRequire.ts +15 -0
  122. package/src/validators/commands/runMigrationsAndCheckVersions.ts +3 -8
  123. package/lib/utils/commands/dependencies/update.d.ts +0 -7
  124. package/lib/utils/commands/dependencies/update.js +0 -19
  125. package/lib/utils/commands/dependencies/update.js.map +0 -1
  126. package/lib/utils/commands/dependencies/updatePackageJson.d.ts +0 -1
  127. package/lib/utils/commands/dependencies/updatePackageJson.js +0 -57
  128. package/lib/utils/commands/dependencies/updatePackageJson.js.map +0 -1
  129. package/src/utils/commands/dependencies/update.ts +0 -31
  130. package/src/utils/commands/dependencies/updatePackageJson.ts +0 -63
@@ -3,7 +3,6 @@ import { provide } from '@tinkoff/dippy';
3
3
  import chalk from 'chalk';
4
4
  import rimraf from 'rimraf';
5
5
  import webpack from 'webpack';
6
- import { INIT_HANDLER_TOKEN } from '../../../../api/start/tokens';
7
6
  import {
8
7
  CLI_PACKAGE_MANAGER,
9
8
  CLI_ROOT_DIR_TOKEN,
@@ -16,6 +15,7 @@ import { StatoscopeAnalyzePlugin } from '../../analyzePlugins/statoscope';
16
15
  import { WhyBundledAnalyzePlugin } from '../../analyzePlugins/whyBundled';
17
16
  import {
18
17
  CLIENT_CONFIG_MANAGER_TOKEN,
18
+ INIT_HANDLER_TOKEN,
19
19
  CLOSE_HANDLER_TOKEN,
20
20
  PROCESS_HANDLER_TOKEN,
21
21
  WEBPACK_ANALYZE_PLUGIN_NAME_TOKEN,
@@ -28,6 +28,12 @@ class AnalyzeCommand extends CLICommand<Params> {
28
28
  value: '[showConfig]',
29
29
  description: 'Show config with which cli was launched',
30
30
  },
31
+ {
32
+ name: '--fileCache',
33
+ value: '[fileCache]',
34
+ transformer: (value) => value !== 'false',
35
+ description: 'Enable/disable persistent file cache for used cli builder',
36
+ },
31
37
  ];
32
38
 
33
39
  alias = 'a';
@@ -50,6 +50,12 @@ class BuildCommand extends CLICommand<Params> {
50
50
  value: '[forPublish]',
51
51
  description: '<package> Prepare library package.json for publication',
52
52
  },
53
+ {
54
+ name: '--fileCache',
55
+ value: '[fileCache]',
56
+ transformer: (value) => value !== 'false',
57
+ description: 'Enable/disable persistent file cache for used cli builder',
58
+ },
53
59
  ];
54
60
 
55
61
  alias = 'b';
@@ -2,6 +2,7 @@ import execa from 'execa';
2
2
  import chalk from 'chalk';
3
3
 
4
4
  export async function initializationGit(localDir) {
5
- console.log(chalk.blue('[START]'), 'Initializing git');
6
- await execa('git', ['init'], { cwd: localDir }).then(() => 'git is initialized');
5
+ console.log(`${chalk.blue('[GIT]')} Initializing git`);
6
+
7
+ await execa('git', ['init'], { cwd: localDir, stdio: 'inherit' });
7
8
  }
@@ -1,6 +1,6 @@
1
+ import type { Options } from 'execa';
1
2
  import execa from 'execa';
2
3
  import chalk from 'chalk';
3
- import ora from 'ora';
4
4
  import type { PackageManagers } from '../questions/packageManager';
5
5
  import type { TestingFrameworks } from '../questions/testingFramework';
6
6
  import type { Type } from '../questions/type';
@@ -92,23 +92,30 @@ export async function installDependencies({
92
92
  packageManager: PackageManagers;
93
93
  testingFramework: TestingFrameworks;
94
94
  }) {
95
- const spinner = ora({
96
- prefixText: `${chalk.blue('[START]')} Install dependencies`,
97
- }).start();
98
-
99
95
  const installCommands = packagesInstallCommands[packageManager];
100
- const options = { cwd: localDir, env: { SKIP_TRAMVAI_MIGRATIONS: 'true' } };
96
+ const options: Options = {
97
+ cwd: localDir,
98
+ env: {
99
+ SKIP_TRAMVAI_MIGRATIONS: 'true',
100
+ },
101
+ stdio: 'inherit',
102
+ };
103
+
104
+ console.log(`${chalk.blue('[DEPENDENCIES]')} Installing app dependencies`);
101
105
 
102
106
  await execa(packageManager, [...installCommands.deps, ...DEPS[type].dependencies], options);
107
+
108
+ console.log(`${chalk.blue('[DEPENDENCIES]')} Installing dev dependencies`);
109
+
103
110
  await execa(packageManager, [...installCommands.devDeps, ...devDependencies], options);
104
111
 
105
112
  if (testingFramework === 'jest') {
113
+ console.log(`${chalk.blue('[DEPENDENCIES]')} Installing jest dependencies`);
114
+
106
115
  await execa(
107
116
  packageManager,
108
117
  [...installCommands.devDeps, ...DEPS[type].jestDevDependencies],
109
118
  options
110
119
  );
111
120
  }
112
-
113
- spinner.stop();
114
121
  }
@@ -2,6 +2,6 @@ import chalk from 'chalk';
2
2
  import { applyTemplate } from '../utils/applyTemplate';
3
3
 
4
4
  export async function renderTemplate(templateDir: string, projectDir: string, templateData) {
5
- console.log(chalk.blue('[START]'), 'Copying files');
5
+ console.log(chalk.blue('[TEMPLATE]'), 'Copying files');
6
6
  return applyTemplate(templateDir, projectDir, templateData);
7
7
  }
@@ -26,10 +26,8 @@
26
26
  "~processes": "./apps/{{configEntry.name}}/processes",
27
27
  "~app": "./apps/{{configEntry.name}}/app"
28
28
  },
29
- "experiments": {
30
- "fileSystemPages": {
31
- "enable": true
32
- }
29
+ "fileSystemPages": {
30
+ "enable": true
33
31
  }
34
32
  }
35
33
  },
@@ -26,10 +26,8 @@
26
26
  "~processes": "./src/processes",
27
27
  "~app": "./src/app"
28
28
  },
29
- "experiments": {
30
- "fileSystemPages": {
31
- "enable": true
32
- }
29
+ "fileSystemPages": {
30
+ "enable": true
33
31
  }
34
32
  }
35
33
  },
@@ -1,3 +1,2 @@
1
1
  registry = https://registry.npmjs.org/
2
2
  strict-ssl = false
3
- ca = ''
@@ -125,7 +125,11 @@ export function applyTemplate(
125
125
  let warnings = 0;
126
126
  templateFiles.forEach((templateFile) => {
127
127
  if (processFileFromTemplate(templateFile, templateDir, projectDir, templateData)) {
128
- console.log(chalk.green('CREATE'), transformOutputPath(replaceHbs(templateFile)));
128
+ console.log(
129
+ chalk.blue('[TEMPLATE]'),
130
+ chalk.green('CREATE'),
131
+ transformOutputPath(replaceHbs(templateFile))
132
+ );
129
133
  ++processed;
130
134
  } else {
131
135
  ++warnings;
@@ -98,6 +98,12 @@ export class StartCommand extends CLICommand<Params> {
98
98
  description:
99
99
  'Specify the names of the bundles that need to be collected, other bundles will not be collected and their request will fail with an error',
100
100
  },
101
+ {
102
+ name: '--fileCache',
103
+ value: '[fileCache]',
104
+ transformer: (value) => value !== 'false',
105
+ description: 'Enable/disable persistent file cache for used cli builder',
106
+ },
101
107
  ];
102
108
 
103
109
  alias = 's';
@@ -72,6 +72,12 @@ export class StartProdCommand extends CLICommand<Params> {
72
72
  value: '[showConfig]',
73
73
  description: 'Show config with which cli was launched',
74
74
  },
75
+ {
76
+ name: '--fileCache',
77
+ value: '[fileCache]',
78
+ transformer: (value) => value !== 'false',
79
+ description: 'Enable/disable persistent file cache for used cli builder',
80
+ },
75
81
  ];
76
82
 
77
83
  alias = 'sp';
@@ -40,6 +40,12 @@ export class StaticCommand extends CLICommand<Params> {
40
40
  transformer: (value: string) => value.split(','),
41
41
  description: 'Specify the comma separated paths list for static HTML generation',
42
42
  },
43
+ {
44
+ name: '--fileCache',
45
+ value: '[fileCache]',
46
+ transformer: (value) => value !== 'false',
47
+ description: 'Enable/disable persistent file cache for used cli builder',
48
+ },
43
49
  ];
44
50
 
45
51
  alias = 'st';
@@ -0,0 +1,49 @@
1
+ import { getLatestPackageVersion } from '../../utils/commands/dependencies/getLatestPackageVersion';
2
+ import { getPackageInfo } from '../../utils/commands/dependencies/getPackageInfo';
3
+
4
+ // map of packages that is not in unified versioning
5
+ // but we still want to update it
6
+ // actual version to update will be calculated from the some of the @tramvai/module
7
+ const DEPENDANT_LIBS_MAP = new Map([
8
+ ['@tinkoff/logger', '@tramvai/module-log'],
9
+ ['@tinkoff/dippy', '@tramvai/core'],
10
+ ['@tinkoff/router', '@tramvai/module-router'],
11
+ ['@tinkoff/url', '@tramvai/module-common'],
12
+ ['@tinkoff/errors', '@tramvai/module-common'],
13
+ ['@tinkoff/roles', '@tramvai/module-authenticate'],
14
+ ['@tinkoff/pubsub', '@tramvai/module-common'],
15
+ ['@tinkoff/hook-runner', '@tramvai/module-common'],
16
+ ['@tinkoff/htmlpagebuilder', '@tramvai/module-render'],
17
+ ['@tinkoff/browser-timings', '@tramvai/module-metrics'],
18
+ ['@tinkoff/meta-tags-generate', '@tramvai/module-render'],
19
+ ['@tinkoff/pack-polyfills', ''],
20
+ ['@tinkoff/browserslist-config', '@tramvai/cli'],
21
+ ]);
22
+
23
+ export const isDependantLib = (name: string) => {
24
+ return DEPENDANT_LIBS_MAP.has(name);
25
+ };
26
+
27
+ export const getLibPackageVersion = async (
28
+ name: string,
29
+ unifiedVersion: string
30
+ ): Promise<string | undefined> => {
31
+ const unifiedModule = DEPENDANT_LIBS_MAP.get(name);
32
+
33
+ if (!unifiedModule) {
34
+ return getLatestPackageVersion(name);
35
+ }
36
+
37
+ const deps = await getPackageInfo(`${unifiedModule}@${unifiedVersion}`, 'dependencies');
38
+
39
+ if (!deps[name]) {
40
+ console.warn(
41
+ `⚠️ cannot resolve proper version for the "${name}" package.
42
+ You have to update this package by yourself.`
43
+ );
44
+
45
+ return;
46
+ }
47
+
48
+ return deps[name];
49
+ };
@@ -0,0 +1,99 @@
1
+ import { updatePackageJson } from './updatePackageJson';
2
+
3
+ const LATEST_TRAMVAI_VERSION = '1.115.6';
4
+ const LATEST_LIB_VERSION = '0.8.23';
5
+
6
+ let mockPackageJson: Record<string, any>;
7
+ const mockFsWrite = jest.fn();
8
+ const mockPackageInfoDependencies = jest.fn<Record<string, string | undefined>, [string]>();
9
+
10
+ jest.mock('../../utils/commands/dependencies/packageHasVersion', () => ({
11
+ packageHasVersion: () => true,
12
+ }));
13
+ jest.mock('../../utils/commands/dependencies/getLatestPackageVersion', () => ({
14
+ getLatestPackageVersion: (dep: string) => {
15
+ if (dep.startsWith('@tramvai')) {
16
+ return LATEST_TRAMVAI_VERSION;
17
+ }
18
+
19
+ return LATEST_LIB_VERSION;
20
+ },
21
+ }));
22
+
23
+ jest.mock('../../utils/commands/dependencies/getPackageInfo', () => ({
24
+ getPackageInfo: (packageName: string, field?: string) => {
25
+ if (field === 'dependencies') {
26
+ return mockPackageInfoDependencies(packageName);
27
+ }
28
+ },
29
+ }));
30
+
31
+ jest.mock('fs', () => ({
32
+ readFileSync: () => JSON.stringify(mockPackageJson),
33
+ writeFileSync: (...args: string[]) => mockFsWrite(...args),
34
+ }));
35
+
36
+ beforeEach(() => {
37
+ mockFsWrite.mockClear();
38
+ mockPackageInfoDependencies.mockClear();
39
+ });
40
+
41
+ it('should update tramvai deps to latest versions', async () => {
42
+ mockPackageJson = {
43
+ dependencies: {
44
+ '@tramvai/core': '1.93.2',
45
+ '@tramvai/module-common': '1.93.2',
46
+ '@tinkoff/router': '^0.2.3',
47
+ '@tinkoff/url': '0.3.2',
48
+ },
49
+ devDependencies: {
50
+ '@tramvai/cli': '1.93.2',
51
+ },
52
+ peerDependencies: {
53
+ '@tinkoff/dippy': '0.7.10',
54
+ },
55
+ };
56
+
57
+ mockPackageInfoDependencies.mockImplementation((dep) => {
58
+ switch (dep) {
59
+ case '@tramvai/core@1.115.6':
60
+ return { '@tinkoff/dippy': '0.7.44', '@tinkoff/utils': '^2.1.0' };
61
+ case '@tramvai/module-common@1.115.6':
62
+ return {
63
+ '@tinkoff/error': '0.6.1',
64
+ '@tinkoff/url': '0.4.1',
65
+ };
66
+ case '@tramvai/cli@1.115.6':
67
+ return {};
68
+ case '@tramvai/module-router@1.115.6':
69
+ return {
70
+ '@tinkoff/router': '0.4.3',
71
+ '@tinkoff/url': '0.4.1',
72
+ };
73
+ }
74
+
75
+ return {};
76
+ });
77
+
78
+ await updatePackageJson(LATEST_TRAMVAI_VERSION);
79
+
80
+ expect(mockFsWrite.mock.calls[0]).toMatchInlineSnapshot(`
81
+ Array [
82
+ "package.json",
83
+ "{
84
+ \\"dependencies\\": {
85
+ \\"@tramvai/core\\": \\"1.115.6\\",
86
+ \\"@tramvai/module-common\\": \\"1.115.6\\",
87
+ \\"@tinkoff/router\\": \\"0.4.3\\",
88
+ \\"@tinkoff/url\\": \\"0.4.1\\"
89
+ },
90
+ \\"devDependencies\\": {
91
+ \\"@tramvai/cli\\": \\"1.115.6\\"
92
+ },
93
+ \\"peerDependencies\\": {
94
+ \\"@tinkoff/dippy\\": \\"0.7.44\\"
95
+ }
96
+ }",
97
+ ]
98
+ `);
99
+ });
@@ -1,29 +1,11 @@
1
1
  import { parse, minVersion } from 'semver';
2
2
  import fs from 'fs';
3
3
  import pMap from 'p-map';
4
- import { getLatestPackageVersion } from '../../utils/commands/dependencies/getLatestPackageVersion';
5
4
  import { packageHasVersion } from '../../utils/commands/dependencies/packageHasVersion';
5
+ import { getLibPackageVersion, isDependantLib } from './dependantLibs';
6
6
 
7
- // Список пакетов, не начинающихся с @tramvai,
8
- // которые мы также хотим обновить
9
- const packagesToUpdate = [
10
- '@tinkoff/logger',
11
- '@tinkoff/dippy',
12
- '@tinkoff/router',
13
- '@tinkoff/url',
14
- '@tinkoff/errors',
15
- '@tinkoff/roles',
16
- '@tinkoff/pubsub',
17
- '@tinkoff/hook-runner',
18
- '@tinkoff/htmlpagebuilder',
19
- '@tinkoff/browser-timings',
20
- '@tinkoff/meta-tags-generate',
21
- '@tinkoff/pack-polyfills',
22
- '@tinkoff/browserslist-config',
23
- ];
24
-
25
- const shouldUpdateDependency = (name: string) => {
26
- return name.startsWith('@tramvai') || packagesToUpdate.includes(name);
7
+ const isUnifiedVersion = (name: string) => {
8
+ return name.startsWith('@tramvai');
27
9
  };
28
10
 
29
11
  const getVersionFromDep = (dep) => parse(dep)?.version || minVersion(dep)?.version;
@@ -35,11 +17,11 @@ const updateEntry = async (
35
17
  ) => {
36
18
  let nextVersion: string;
37
19
 
38
- if (dep.startsWith('@tramvai') && getVersionFromDep(deps[dep]) === currentVersion) {
20
+ if (isUnifiedVersion(dep) && getVersionFromDep(deps[dep]) === currentVersion) {
39
21
  nextVersion = version;
40
- } else if (shouldUpdateDependency(dep)) {
41
- const latestPackageVersion = await getLatestPackageVersion(dep);
42
- nextVersion = latestPackageVersion;
22
+ } else if (isDependantLib(dep)) {
23
+ const libVersion = await getLibPackageVersion(dep, version);
24
+ nextVersion = libVersion;
43
25
  }
44
26
 
45
27
  if (nextVersion) {
@@ -3,7 +3,7 @@ import prop from '@tinkoff/utils/object/prop';
3
3
  import { resolve } from 'path';
4
4
  import type { ProjectType, BuildType } from '../typings/projectType';
5
5
  import type { Env } from '../typings/Env';
6
- import type { ConfigEntry, Experiments } from '../typings/configEntry/common';
6
+ import type { ConfigEntry } from '../typings/configEntry/common';
7
7
  import { validate } from './validate';
8
8
  import moduleVersion from '../utils/moduleVersion';
9
9
  import { packageVersion } from '../utils/packageVersion';
@@ -32,6 +32,7 @@ export interface Settings<E extends Env> {
32
32
  showConfig?: boolean;
33
33
  onlyBundles?: string[];
34
34
  disableProdOptimization?: boolean;
35
+ fileCache?: boolean;
35
36
  }
36
37
 
37
38
  const getOption = <T>(optionName: string, cfgs: any[], dflt?: T): T => {
@@ -108,6 +109,8 @@ export class ConfigManager<T extends ConfigEntry = ConfigEntry, E extends Env =
108
109
 
109
110
  public target: Target;
110
111
 
112
+ public fileCache: boolean;
113
+
111
114
  public experiments: T['commands'][E extends 'development'
112
115
  ? 'serve'
113
116
  : 'build']['configurations']['experiments'];
@@ -120,7 +123,7 @@ export class ConfigManager<T extends ConfigEntry = ConfigEntry, E extends Env =
120
123
  this.type = configEntry.type;
121
124
  this.root = configEntry.root;
122
125
  this.build = configEntry.commands.build || {};
123
- this.serve = configEntry.commands.serve || configEntry.serve || {};
126
+ this.serve = configEntry.commands.serve || {};
124
127
 
125
128
  this.settings = settings;
126
129
  this.env = settings.env || ('development' as E);
@@ -156,7 +159,7 @@ export class ConfigManager<T extends ConfigEntry = ConfigEntry, E extends Env =
156
159
  settings,
157
160
  this.env === 'development' ? this.serve.configurations : this.build.configurations,
158
161
  ],
159
- false
162
+ true
160
163
  );
161
164
  this.dedupe = this.build.configurations?.dedupe;
162
165
  this.dedupeIgnore = this.build.configurations?.dedupeIgnore?.map(
@@ -168,6 +171,9 @@ export class ConfigManager<T extends ConfigEntry = ConfigEntry, E extends Env =
168
171
  this.disableProdOptimization = settings.disableProdOptimization ?? false;
169
172
  this.onlyBundles = settings.onlyBundles;
170
173
  this.target = this.resolveTarget();
174
+ // according to measures fileCache in webpack doesn't affect
175
+ // performance much so enable it by default as it always was before
176
+ this.fileCache = settings.fileCache ?? true;
171
177
  this.experiments =
172
178
  (this.env === 'development'
173
179
  ? this.serve.configurations?.experiments
@@ -1,12 +1,10 @@
1
- export interface Page {
2
- default?: any;
3
- }
1
+ import type { LazyComponentWrapper, PageComponent } from '@tramvai/react';
4
2
 
5
3
  // eslint-disable-next-line import/no-default-export
6
4
  export default {
7
5
  routes: {},
8
6
  pages: {},
9
7
  } as {
10
- routes: Record<string, Page>;
11
- pages: Record<string, Page>;
8
+ routes: Record<string, LazyComponentWrapper<PageComponent>>;
9
+ pages: Record<string, LazyComponentWrapper<PageComponent>>;
12
10
  };
@@ -22,9 +22,7 @@ import { configToEnv } from '../../blocks/configToEnv';
22
22
  export default (configManager: ConfigManager<ApplicationConfigEntry>) => (config: Config) => {
23
23
  const {
24
24
  options: { polyfill = '' } = {},
25
- configurations: {
26
- experiments: { fileSystemPages },
27
- },
25
+ configurations: { fileSystemPages },
28
26
  } = configManager.build;
29
27
 
30
28
  config.name('client');
@@ -22,9 +22,7 @@ import { extractCssPluginFactory } from '../../blocks/extractCssPlugin';
22
22
  export default (configManager: ConfigManager<ApplicationConfigEntry>) => (config: Config) => {
23
23
  const {
24
24
  options: { server = '', outputServer = '' } = {},
25
- configurations: {
26
- experiments: { fileSystemPages },
27
- },
25
+ configurations: { fileSystemPages },
28
26
  } = configManager.build;
29
27
 
30
28
  config.name('server');
@@ -4,7 +4,7 @@ import type { ConfigEntry } from '../../../typings/configEntry/common';
4
4
  import { shouldUseReactRoot } from '../../../utils/shouldUseReactRoot';
5
5
 
6
6
  export const configToEnv = (configManager: ConfigManager<ConfigEntry>) => (config: Config) => {
7
- const { fileSystemPages } = configManager.build.configurations.experiments;
7
+ const { fileSystemPages } = configManager.build.configurations;
8
8
 
9
9
  config.plugin('define').tap((args) => [
10
10
  {
@@ -1,3 +1,4 @@
1
+ import path from 'path';
1
2
  import type Config from 'webpack-chain';
2
3
  import SparkMD5 from 'spark-md5';
3
4
  import type { ConfigManager } from '../../../config/configManager';
@@ -33,9 +34,11 @@ export const filesClientWebackRulesFactory = (configManager: ConfigManager) => (
33
34
  });
34
35
 
35
36
  config.module
36
- .rule('image')
37
+ .rule('tramvai-image')
37
38
  .test(/\.(png|jpe?g|gif|webp)$/)
38
- .set('type', 'asset');
39
+ .use('file')
40
+ .loader(path.resolve(__dirname, '../loaders/image-loader'))
41
+ .end();
39
42
 
40
43
  config.module
41
44
  .rule('video')
@@ -1,3 +1,4 @@
1
+ import path from 'path';
1
2
  import type Config from 'webpack-chain';
2
3
  import type { ConfigManager } from '../../../config/configManager';
3
4
 
@@ -28,12 +29,14 @@ export default (configManager: ConfigManager) => (config: Config) => {
28
29
  });
29
30
 
30
31
  config.module
31
- .rule('image')
32
+ .rule('tramvai-image')
32
33
  .test(/\.(png|jpe?g|gif|webp)$/)
33
- .set('type', 'asset')
34
- .set('generator', {
35
- emit: false,
36
- });
34
+ .use('file')
35
+ .loader(path.resolve(__dirname, '../loaders/image-loader'))
36
+ .options({
37
+ emitFile: false,
38
+ })
39
+ .end();
37
40
 
38
41
  config.module
39
42
  .rule('video')
@@ -6,7 +6,7 @@ import type { ApplicationConfigEntry } from '../../../typings/configEntry/applic
6
6
  export const pagesResolve = (configManager: ConfigManager<ApplicationConfigEntry>) => (
7
7
  config: Config
8
8
  ) => {
9
- const { fileSystemPages } = configManager.build.configurations.experiments;
9
+ const { fileSystemPages } = configManager.build.configurations;
10
10
 
11
11
  config.module
12
12
  .rule('file-system-pages')
@@ -42,24 +42,25 @@ export default (configManager: ConfigManager) => (config: Config) => {
42
42
  // https://webpack.js.org/configuration/output/#outputhashfunction . When release webpack 6 would need to remove
43
43
  config.output.set('hashFunction', 'xxhash64');
44
44
 
45
- // TODO: отключать в CI
46
- config.cache({
47
- type: 'filesystem',
48
- name: `${env}-${configManager.type}-${configManager.buildType}-${configManager.name}${
49
- configManager.buildType === 'client' && configManager.modern ? '-modern' : ''
50
- }`,
51
- cacheDirectory: findCacheDir({ cwd: configManager.rootDir, name: 'webpack' }),
52
- buildDependencies: {
53
- cli: ['@tramvai/cli'],
54
- webpack: ['webpack/lib'],
55
- // first check that config exists. If it is passed to webpack, but file is not exist the cache will not be created at all.
56
- // It may be missing in cases when cli is running programmaticaly
57
- config: filterNonExisted([path.resolve(configManager.rootDir, 'tramvai.json')]),
58
- css: filterNonExisted([
59
- postcssConfig && safeRequireResolve(path.resolve(configManager.rootDir, postcssConfig)),
60
- ]),
61
- },
62
- });
45
+ if (configManager.fileCache) {
46
+ config.cache({
47
+ type: 'filesystem',
48
+ name: `${env}-${configManager.type}-${configManager.buildType}-${configManager.name}${
49
+ configManager.buildType === 'client' && configManager.modern ? '-modern' : ''
50
+ }`,
51
+ cacheDirectory: findCacheDir({ cwd: configManager.rootDir, name: 'webpack' }),
52
+ buildDependencies: {
53
+ cli: ['@tramvai/cli'],
54
+ webpack: ['webpack/lib'],
55
+ // first check that config exists. If it is passed to webpack, but file is not exist the cache will not be created at all.
56
+ // It may be missing in cases when cli is running programmaticaly
57
+ config: filterNonExisted([path.resolve(configManager.rootDir, 'tramvai.json')]),
58
+ css: filterNonExisted([
59
+ postcssConfig && safeRequireResolve(path.resolve(configManager.rootDir, postcssConfig)),
60
+ ]),
61
+ },
62
+ });
63
+ }
63
64
 
64
65
  config.set('snapshot', {
65
66
  // отключаем дефолты для managedPaths т.к. из-за них нельзя дебажить node_modules,
@@ -0,0 +1,26 @@
1
+ import sizeOf from 'image-size';
2
+
3
+ /**
4
+ * Reuse file-loader logic, but return a object with src and size of image
5
+ */
6
+ export default function (content) {
7
+ const result = require('file-loader').call(this, content);
8
+
9
+ const dimensions = sizeOf(this.resourcePath);
10
+
11
+ // @todo: image blur placeholder in Base64, sharp or imagemin or jimp?
12
+ return result.replace(
13
+ /^export default (__webpack_public_path__ \+ .+);$/,
14
+ `const path = $1;
15
+
16
+ export default path;
17
+
18
+ export const image = {
19
+ src: $1,
20
+ width: ${JSON.stringify(dimensions.width)},
21
+ height: ${JSON.stringify(dimensions.height)},
22
+ };`
23
+ );
24
+ }
25
+
26
+ export const raw = true;