@tramvai/cli 5.53.94 → 5.53.112

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 (58) hide show
  1. package/bin/const.js +5 -0
  2. package/bin/platform.js +12 -6
  3. package/bin/spawn.js +6 -0
  4. package/lib/builder/webpack/tokens.d.ts +2 -0
  5. package/lib/builder/webpack/tokens.d.ts.map +1 -1
  6. package/lib/commands/update/checkVersionValidator.d.ts +1 -1
  7. package/lib/commands/update/checkVersionValidator.d.ts.map +1 -1
  8. package/lib/commands/update/checkVersionValidator.js +3 -2
  9. package/lib/commands/update/checkVersionValidator.js.map +1 -1
  10. package/lib/commands/update/command.d.ts +1 -1
  11. package/lib/commands/update/dependantLibs.d.ts +1 -1
  12. package/lib/commands/update/dependantLibs.d.ts.map +1 -1
  13. package/lib/commands/update/dependantLibs.js +3 -2
  14. package/lib/commands/update/dependantLibs.js.map +1 -1
  15. package/lib/commands/update/update.d.ts.map +1 -1
  16. package/lib/commands/update/update.js +6 -3
  17. package/lib/commands/update/update.js.map +1 -1
  18. package/lib/commands/update/updatePackageJson.d.ts +1 -1
  19. package/lib/commands/update/updatePackageJson.d.ts.map +1 -1
  20. package/lib/commands/update/updatePackageJson.js +7 -7
  21. package/lib/commands/update/updatePackageJson.js.map +1 -1
  22. package/lib/di/tokens/config.d.ts +1 -0
  23. package/lib/di/tokens/config.d.ts.map +1 -1
  24. package/lib/library/webpack/blocks/css.d.ts.map +1 -1
  25. package/lib/library/webpack/blocks/css.js +42 -15
  26. package/lib/library/webpack/blocks/css.js.map +1 -1
  27. package/lib/library/webpack/utils/browserslist.d.ts +4 -0
  28. package/lib/library/webpack/utils/browserslist.d.ts.map +1 -0
  29. package/lib/library/webpack/utils/browserslist.js +27 -0
  30. package/lib/library/webpack/utils/browserslist.js.map +1 -0
  31. package/lib/library/webpack/utils/transpiler.d.ts.map +1 -1
  32. package/lib/library/webpack/utils/transpiler.js +3 -16
  33. package/lib/library/webpack/utils/transpiler.js.map +1 -1
  34. package/lib/schema/autogeneratedSchema.json +27 -15
  35. package/lib/typings/configEntry/cli.d.ts +4 -0
  36. package/lib/typings/configEntry/cli.d.ts.map +1 -1
  37. package/lib/utils/commands/dependencies/getLatestPackageVersion.d.ts +1 -1
  38. package/lib/utils/commands/dependencies/getLatestPackageVersion.d.ts.map +1 -1
  39. package/lib/utils/commands/dependencies/getLatestPackageVersion.js +4 -2
  40. package/lib/utils/commands/dependencies/getLatestPackageVersion.js.map +1 -1
  41. package/lib/utils/commands/dependencies/packageHasVersion.d.ts +1 -1
  42. package/lib/utils/commands/dependencies/packageHasVersion.d.ts.map +1 -1
  43. package/lib/utils/commands/dependencies/packageHasVersion.js +3 -2
  44. package/lib/utils/commands/dependencies/packageHasVersion.js.map +1 -1
  45. package/package.json +15 -13
  46. package/schema.json +27 -15
  47. package/src/commands/update/checkVersionValidator.ts +4 -2
  48. package/src/commands/update/dependantLibs.ts +3 -1
  49. package/src/commands/update/update.ts +6 -3
  50. package/src/commands/update/updatePackageJson.spec.ts +19 -3
  51. package/src/commands/update/updatePackageJson.ts +7 -2
  52. package/src/library/webpack/blocks/css.ts +52 -16
  53. package/src/library/webpack/utils/browserslist.ts +29 -0
  54. package/src/library/webpack/utils/transpiler.ts +3 -18
  55. package/src/schema/autogeneratedSchema.json +27 -15
  56. package/src/typings/configEntry/cli.ts +5 -0
  57. package/src/utils/commands/dependencies/getLatestPackageVersion.ts +4 -1
  58. package/src/utils/commands/dependencies/packageHasVersion.ts +7 -2
@@ -1,11 +1,12 @@
1
- import applyOrReturn from '@tinkoff/utils/function/applyOrReturn';
2
1
  import path from 'path';
3
2
  import type Config from 'webpack-chain';
4
3
  import ExtractCssChunks from 'mini-css-extract-plugin';
5
4
  import { createGenerator } from '@tinkoff/minicss-class-generator';
5
+
6
6
  import { safeRequire } from '../../../utils/safeRequire';
7
7
  import type { ConfigManager } from '../../../config/configManager';
8
8
  import type { CliConfigEntry } from '../../../typings/configEntry/cli';
9
+ import { getActualTarget, getBrowserslistTargets } from '../utils/browserslist';
9
10
 
10
11
  const cssLocalIdentNameDevDefault = '[name]__[local]_[minicss]';
11
12
  const cssLocalIdentNameProdDefault = '[minicss]';
@@ -21,8 +22,9 @@ interface Options {
21
22
  export const cssWebpackRulesFactory =
22
23
  (configManager: ConfigManager<CliConfigEntry>, options: Options = {}) =>
23
24
  (config: Config) => {
24
- const { env, sourceMap, buildType } = configManager;
25
+ const { env, sourceMap, buildType, experiments, target } = configManager;
25
26
  const {
27
+ rootDir,
26
28
  postcss: {
27
29
  config: postcssConfig,
28
30
  cssLocalIdentName = env === 'production'
@@ -31,6 +33,9 @@ export const cssWebpackRulesFactory =
31
33
  cssModulePattern,
32
34
  },
33
35
  } = configManager;
36
+ const isServer = configManager.buildType === 'server';
37
+ const actualTarget = getActualTarget(target, isServer);
38
+ const browsersListTargets = getBrowserslistTargets(rootDir, actualTarget);
34
39
  const localIdentName = options.localIdentName ?? cssLocalIdentName;
35
40
 
36
41
  const configCssLoader = (cfg) => {
@@ -73,17 +78,33 @@ export const cssWebpackRulesFactory =
73
78
  typeof postcssConfig === 'undefined'
74
79
  ) ?? {};
75
80
 
76
- const postcssOptionsFn = (...args) => ({
77
- ...postcssCfg,
78
- plugins: [
79
- require('postcss-modules-tilda'),
80
- require('postcss-modules-values-replace')({ importsAsModuleRequests: true }),
81
+ // https://github.com/webpack-contrib/postcss-loader/blob/master/src/config.d.ts
82
+ const postcssOptionsFn = (loaderContext: any) => {
83
+ const isFnConfig = typeof postcssCfg === 'function';
84
+ // TODO: async config fn support?
85
+ const defaultConfig = isFnConfig ? postcssCfg(loaderContext) : postcssCfg;
86
+ // eslint-disable-next-line no-nested-ternary
87
+ const defaultPlugins = defaultConfig.plugins ? defaultConfig.plugins : [];
88
+
89
+ return {
90
+ config: false,
91
+ ...defaultConfig,
81
92
  // TODO: придумать как прокинуть настройки browserslist в autoprefixer - сейчас autoprefixer добавляется в самом приложении и из
82
93
  // конфига нет возможности задавать динамический env в зависимости от сборки. Подсунуть в сам autoprefixer после его инициализации тоже
83
94
  // тоже не получится - https://github.com/postcss/autoprefixer/blob/10.3.1/lib/autoprefixer.js#L108
84
- ...(applyOrReturn(args, postcssCfg.plugins) || []),
85
- ],
86
- });
95
+ plugins: Array.isArray(defaultPlugins)
96
+ ? [
97
+ require('postcss-modules-tilda'),
98
+ require('postcss-modules-values-replace')({ importsAsModuleRequests: true }),
99
+ ...defaultPlugins,
100
+ ]
101
+ : {
102
+ 'postcss-modules-tilda': {},
103
+ 'postcss-modules-values-replace': { importsAsModuleRequests: true },
104
+ ...defaultPlugins,
105
+ },
106
+ };
107
+ };
87
108
 
88
109
  // otherwise postcss-loader will use cosmiconfig to resolve postcss configuration file
89
110
  // https://github.com/webpack-contrib/postcss-loader/blob/6f470db420f6febbea729080921050e8fe353226/src/index.js#L38
@@ -93,12 +114,27 @@ export const cssWebpackRulesFactory =
93
114
  .rule('css')
94
115
  .test(/\.css$/)
95
116
  .batch(configCssLoader)
96
- .use('postcss')
97
- .loader('postcss-loader')
98
- .options({
99
- sourceMap,
100
- postcssOptions: postcssOptionsFn,
101
- });
117
+ .when(
118
+ experiments.lightningcss,
119
+ (cfg) => {
120
+ const lightningcss = require('lightningcss');
121
+
122
+ return cfg
123
+ .use('lightningcss')
124
+ .loader('lightningcss-loader')
125
+ .options({
126
+ options: {
127
+ implementation: lightningcss,
128
+ targets: browsersListTargets,
129
+ },
130
+ });
131
+ },
132
+ (cfg) =>
133
+ cfg.use('postcss').loader('postcss-loader').options({
134
+ sourceMap,
135
+ postcssOptions: postcssOptionsFn,
136
+ })
137
+ );
102
138
  };
103
139
 
104
140
  export default cssWebpackRulesFactory;
@@ -0,0 +1,29 @@
1
+ import envTargets from '@tinkoff/browserslist-config';
2
+ import browserslist from 'browserslist';
3
+
4
+ import type { Target } from '../../../typings/target';
5
+
6
+ export function getBrowserslistTargets(rootDir: string, actualTarget: Target) {
7
+ const browserslistConfigRaw = browserslist.findConfig(rootDir);
8
+
9
+ // Set defaults if the explicit config for browserslist was not found or the config does not contain the necessary targets
10
+ const browserslistQuery =
11
+ browserslistConfigRaw?.[actualTarget] ?? envTargets[actualTarget] ?? envTargets.defaults;
12
+
13
+ return browserslist(browserslistQuery, {
14
+ mobileToDesktop: true,
15
+ env: actualTarget,
16
+ });
17
+ }
18
+
19
+ export function getActualTarget(target, isServer) {
20
+ let actualTarget = target;
21
+
22
+ if (!target) {
23
+ if (isServer) {
24
+ actualTarget = 'node';
25
+ }
26
+ }
27
+
28
+ return actualTarget;
29
+ }
@@ -8,6 +8,7 @@ import { babelConfigFactory } from '../../babel';
8
8
  import type { Env } from '../../../typings/Env';
9
9
  import type { Target } from '../../../typings/target';
10
10
  import type { CliConfigEntry, ReactCompilerOptions } from '../../../typings/configEntry/cli';
11
+ import { getActualTarget, getBrowserslistTargets } from './browserslist';
11
12
 
12
13
  export type TranspilerConfig = {
13
14
  env: Env;
@@ -84,24 +85,8 @@ export const getTranspilerConfig = (
84
85
  Just check or add configuration to your tsconfig file and remove alias from tramvai.json`);
85
86
  }
86
87
 
87
- let actualTarget = target;
88
-
89
- if (!target) {
90
- if (isServer) {
91
- actualTarget = 'node';
92
- }
93
- }
94
-
95
- const browserslistConfigRaw = browserslist.findConfig(rootDir);
96
-
97
- // Set defaults if the explicit config for browserslist was not found or the config does not contain the necessary targets
98
- const browserslistQuery =
99
- browserslistConfigRaw?.[actualTarget] ?? envTargets[actualTarget] ?? envTargets.defaults;
100
-
101
- const browsersListTargets = browserslist(browserslistQuery, {
102
- mobileToDesktop: true,
103
- env: actualTarget,
104
- });
88
+ const actualTarget = getActualTarget(target, isServer);
89
+ const browsersListTargets = getBrowserslistTargets(rootDir, actualTarget);
105
90
 
106
91
  return {
107
92
  isServer,
@@ -846,6 +846,10 @@
846
846
  },
847
847
  "additionalProperties": false
848
848
  },
849
+ "lightningcss": {
850
+ "title": "experimental css building by [lightningcss](https://lightningcss.dev/)",
851
+ "type": "boolean"
852
+ },
849
853
  "transpilation": {
850
854
  "title": "experimental settings for code transpilation",
851
855
  "default": {},
@@ -1325,23 +1329,23 @@
1325
1329
  "dotAll": {
1326
1330
  "type": "boolean"
1327
1331
  },
1328
- "__@match@8175": {
1332
+ "__@match@8181": {
1329
1333
  "type": "object",
1330
1334
  "additionalProperties": false
1331
1335
  },
1332
- "__@replace@8177": {
1336
+ "__@replace@8183": {
1333
1337
  "type": "object",
1334
1338
  "additionalProperties": false
1335
1339
  },
1336
- "__@search@8180": {
1340
+ "__@search@8186": {
1337
1341
  "type": "object",
1338
1342
  "additionalProperties": false
1339
1343
  },
1340
- "__@split@8182": {
1344
+ "__@split@8188": {
1341
1345
  "type": "object",
1342
1346
  "additionalProperties": false
1343
1347
  },
1344
- "__@matchAll@8184": {
1348
+ "__@matchAll@8190": {
1345
1349
  "type": "object",
1346
1350
  "additionalProperties": false
1347
1351
  }
@@ -1784,6 +1788,10 @@
1784
1788
  },
1785
1789
  "additionalProperties": false
1786
1790
  },
1791
+ "lightningcss": {
1792
+ "title": "experimental css building by [lightningcss](https://lightningcss.dev/)",
1793
+ "type": "boolean"
1794
+ },
1787
1795
  "transpilation": {
1788
1796
  "title": "experimental settings for code transpilation",
1789
1797
  "default": {},
@@ -2156,23 +2164,23 @@
2156
2164
  "dotAll": {
2157
2165
  "type": "boolean"
2158
2166
  },
2159
- "__@match@8175": {
2167
+ "__@match@8181": {
2160
2168
  "type": "object",
2161
2169
  "additionalProperties": false
2162
2170
  },
2163
- "__@replace@8177": {
2171
+ "__@replace@8183": {
2164
2172
  "type": "object",
2165
2173
  "additionalProperties": false
2166
2174
  },
2167
- "__@search@8180": {
2175
+ "__@search@8186": {
2168
2176
  "type": "object",
2169
2177
  "additionalProperties": false
2170
2178
  },
2171
- "__@split@8182": {
2179
+ "__@split@8188": {
2172
2180
  "type": "object",
2173
2181
  "additionalProperties": false
2174
2182
  },
2175
- "__@matchAll@8184": {
2183
+ "__@matchAll@8190": {
2176
2184
  "type": "object",
2177
2185
  "additionalProperties": false
2178
2186
  }
@@ -2615,6 +2623,10 @@
2615
2623
  },
2616
2624
  "additionalProperties": false
2617
2625
  },
2626
+ "lightningcss": {
2627
+ "title": "experimental css building by [lightningcss](https://lightningcss.dev/)",
2628
+ "type": "boolean"
2629
+ },
2618
2630
  "transpilation": {
2619
2631
  "title": "experimental settings for code transpilation",
2620
2632
  "default": {},
@@ -2987,23 +2999,23 @@
2987
2999
  "dotAll": {
2988
3000
  "type": "boolean"
2989
3001
  },
2990
- "__@match@8175": {
3002
+ "__@match@8181": {
2991
3003
  "type": "object",
2992
3004
  "additionalProperties": false
2993
3005
  },
2994
- "__@replace@8177": {
3006
+ "__@replace@8183": {
2995
3007
  "type": "object",
2996
3008
  "additionalProperties": false
2997
3009
  },
2998
- "__@search@8180": {
3010
+ "__@search@8186": {
2999
3011
  "type": "object",
3000
3012
  "additionalProperties": false
3001
3013
  },
3002
- "__@split@8182": {
3014
+ "__@split@8188": {
3003
3015
  "type": "object",
3004
3016
  "additionalProperties": false
3005
3017
  },
3006
- "__@matchAll@8184": {
3018
+ "__@matchAll@8190": {
3007
3019
  "type": "object",
3008
3020
  "additionalProperties": false
3009
3021
  }
@@ -95,6 +95,11 @@ export interface Experiments {
95
95
  */
96
96
  minicss: MinicssExperiments;
97
97
 
98
+ /**
99
+ * @title experimental css building by [lightningcss](https://lightningcss.dev/)
100
+ */
101
+ lightningcss?: boolean;
102
+
98
103
  /**
99
104
  * @title experimental settings for code transpilation
100
105
  * @default {}
@@ -3,6 +3,7 @@ import latestVersion from 'latest-version';
3
3
 
4
4
  export const getLatestPackageVersion = async (
5
5
  packageName: string,
6
+ registryUrl: string,
6
7
  version = 'latest',
7
8
  silent = false
8
9
  ) => {
@@ -11,7 +12,9 @@ export const getLatestPackageVersion = async (
11
12
  : ora(`Resolving the highest version satifying to ${version}`).start();
12
13
 
13
14
  try {
14
- const result = await latestVersion(packageName, { version });
15
+ // underlying `registry-url` package uses only `.npmrc` file to resolve registry URL
16
+ // @ts-expect-error uncomplete type definition, `registryUrl` is supported
17
+ const result = await latestVersion(packageName, { version, registryUrl });
15
18
 
16
19
  return result;
17
20
  } finally {
@@ -1,8 +1,13 @@
1
1
  import latestVersion from 'latest-version';
2
2
 
3
- export const packageHasVersion = async (packageName: string, version: string): Promise<boolean> => {
3
+ export const packageHasVersion = async (
4
+ packageName: string,
5
+ version: string,
6
+ registryUrl: string
7
+ ): Promise<boolean> => {
4
8
  try {
5
- await latestVersion(packageName, { version });
9
+ // @ts-expect-error uncomplete type definition, `registryUrl` is supported
10
+ await latestVersion(packageName, { version, registryUrl });
6
11
  return true;
7
12
  } catch (e) {
8
13
  return false;