@gravity-ui/app-builder 0.29.3-beta.0 → 0.30.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 (64) hide show
  1. package/README.md +138 -0
  2. package/dist/cli.js +17 -22
  3. package/dist/commands/build/build-lib.js +5 -8
  4. package/dist/commands/build/build-service/client.js +3 -6
  5. package/dist/commands/build/build-service/index.js +4 -7
  6. package/dist/commands/build/build-service/server.js +11 -17
  7. package/dist/commands/build/index.js +3 -6
  8. package/dist/commands/dev/client.js +34 -63
  9. package/dist/commands/dev/index.js +26 -47
  10. package/dist/commands/dev/server.js +13 -42
  11. package/dist/common/babel/index.js +1 -4
  12. package/dist/common/babel/ui-preset.d.ts +1 -1
  13. package/dist/common/babel/ui-preset.js +0 -1
  14. package/dist/common/child-process/controllable-script.js +5 -32
  15. package/dist/common/child-process/utils.js +4 -30
  16. package/dist/common/command.js +1 -2
  17. package/dist/common/config.js +36 -45
  18. package/dist/common/env.js +3 -5
  19. package/dist/common/library/babel-plugin-replace-paths.js +2 -4
  20. package/dist/common/library/index.js +66 -95
  21. package/dist/common/logger/colors.js +2 -8
  22. package/dist/common/logger/index.js +17 -24
  23. package/dist/common/logger/log-config.js +3 -6
  24. package/dist/common/logger/pretty-time.js +2 -6
  25. package/dist/common/models/index.d.ts +66 -1
  26. package/dist/common/models/index.js +3 -8
  27. package/dist/common/paths.js +3 -28
  28. package/dist/common/s3-upload/compress.js +8 -12
  29. package/dist/common/s3-upload/create-plugin.js +9 -7
  30. package/dist/common/s3-upload/index.js +3 -9
  31. package/dist/common/s3-upload/s3-client.js +11 -37
  32. package/dist/common/s3-upload/upload.js +9 -38
  33. package/dist/common/s3-upload/webpack-plugin.js +5 -9
  34. package/dist/common/swc/compile.js +9 -12
  35. package/dist/common/swc/index.js +2 -7
  36. package/dist/common/swc/utils.js +6 -13
  37. package/dist/common/swc/watch.js +6 -9
  38. package/dist/common/typescript/compile.js +11 -14
  39. package/dist/common/typescript/diagnostic.js +11 -37
  40. package/dist/common/typescript/transformers.js +3 -29
  41. package/dist/common/typescript/utils.js +8 -18
  42. package/dist/common/typescript/watch.js +10 -13
  43. package/dist/common/utils.d.ts +3 -1
  44. package/dist/common/utils.js +16 -22
  45. package/dist/common/webpack/compile.js +16 -22
  46. package/dist/common/webpack/config.d.ts +0 -2
  47. package/dist/common/webpack/config.js +187 -137
  48. package/dist/common/webpack/node-externals.js +5 -34
  49. package/dist/common/webpack/progress-plugin.js +3 -6
  50. package/dist/common/webpack/public-path.d.ts +0 -1
  51. package/dist/common/webpack/public-path.js +1 -1
  52. package/dist/common/webpack/rspack.js +1 -5
  53. package/dist/common/webpack/runtime-versioning-plugin.d.ts +5 -0
  54. package/dist/common/webpack/runtime-versioning-plugin.js +20 -0
  55. package/dist/common/webpack/storybook.js +21 -53
  56. package/dist/common/webpack/utils.js +9 -36
  57. package/dist/common/webpack/worker/public-path.worker.d.ts +0 -1
  58. package/dist/common/webpack/worker/public-path.worker.js +2 -1
  59. package/dist/common/webpack/worker/worker-loader.js +4 -34
  60. package/dist/create-cli.d.ts +2 -2
  61. package/dist/create-cli.js +19 -48
  62. package/dist/index.d.ts +1 -1
  63. package/dist/index.js +5 -27
  64. package/package.json +9 -6
@@ -1,37 +1,8 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.watchServerCompilation = watchServerCompilation;
30
- const path = __importStar(require("node:path"));
31
- const rimraf_1 = require("rimraf");
32
- const controllable_script_1 = require("../../common/child-process/controllable-script");
33
- const utils_1 = require("../../common/utils");
34
- const paths_1 = __importDefault(require("../../common/paths"));
1
+ import * as path from 'node:path';
2
+ import { rimraf } from 'rimraf';
3
+ import { ControllableScript } from '../../common/child-process/controllable-script';
4
+ import { createRunFolder } from '../../common/utils';
5
+ import paths from '../../common/paths';
35
6
  function createTypescriptBuildScript(config) {
36
7
  return `
37
8
  let ts;
@@ -49,7 +20,7 @@ const {watch} = require(${JSON.stringify(require.resolve('../../common/typescrip
49
20
  const logger = new Logger('server', ${config.verbose});
50
21
  watch(
51
22
  ts,
52
- ${JSON.stringify(paths_1.default.appServer)},
23
+ ${JSON.stringify(paths.appServer)},
53
24
  {
54
25
  logger,
55
26
  onAfterFilesEmitted: () => {
@@ -66,9 +37,9 @@ const {watch} = require(${JSON.stringify(require.resolve('../../common/swc/watch
66
37
 
67
38
  const logger = new Logger('server', ${config.verbose});
68
39
  watch(
69
- ${JSON.stringify(paths_1.default.appServer)},
40
+ ${JSON.stringify(paths.appServer)},
70
41
  {
71
- outputPath: ${JSON.stringify(paths_1.default.appDist)},
42
+ outputPath: ${JSON.stringify(paths.appDist)},
72
43
  logger,
73
44
  onAfterFilesEmitted: () => {
74
45
  process.send({type: 'Emitted'});
@@ -76,11 +47,11 @@ watch(
76
47
  }
77
48
  );`;
78
49
  }
79
- async function watchServerCompilation(config) {
80
- const serverPath = path.resolve(paths_1.default.appDist, 'server');
81
- rimraf_1.rimraf.sync(serverPath);
82
- (0, utils_1.createRunFolder)();
83
- const build = new controllable_script_1.ControllableScript(config.server.compiler === 'swc'
50
+ export async function watchServerCompilation(config) {
51
+ const serverPath = path.resolve(paths.appDist, 'server');
52
+ rimraf.sync(serverPath);
53
+ createRunFolder(config);
54
+ const build = new ControllableScript(config.server.compiler === 'swc'
84
55
  ? createSWCBuildScript(config)
85
56
  : createTypescriptBuildScript(config), null);
86
57
  await build.start();
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.babelPreset = babelPreset;
4
- function babelPreset(config) {
1
+ export function babelPreset(config) {
5
2
  return [
6
3
  require.resolve('./ui-preset'),
7
4
  {
@@ -1 +1 @@
1
- export {};
1
+ declare function getOption<T>(value: T, defaultValue: T): T;
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
2
  function getOption(value, defaultValue) {
4
3
  if (typeof value === 'undefined') {
5
4
  return defaultValue;
@@ -1,33 +1,7 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.ControllableScript = void 0;
27
- const utils_1 = require("./utils");
28
- const fs = __importStar(require("fs-extra"));
29
- const utils_2 = require("../utils");
30
- class ControllableScript {
1
+ import { tmpNameSync } from './utils';
2
+ import * as fs from 'fs-extra';
3
+ import { getCacheDir } from '../utils';
4
+ export class ControllableScript {
31
5
  isRunning = false;
32
6
  process;
33
7
  script = '';
@@ -38,7 +12,7 @@ class ControllableScript {
38
12
  }
39
13
  async start() {
40
14
  const args = [];
41
- const tmpFileName = (0, utils_1.tmpNameSync)(await (0, utils_2.getCacheDir)());
15
+ const tmpFileName = tmpNameSync(await getCacheDir());
42
16
  fs.outputFileSync(tmpFileName, this.script);
43
17
  this.isRunning = true;
44
18
  // Passing --inspect isn't necessary for the child process to launch a port, but it allows some editors to automatically attach
@@ -123,4 +97,3 @@ class ControllableScript {
123
97
  this.process.send(msg);
124
98
  }
125
99
  }
126
- exports.ControllableScript = ControllableScript;
@@ -1,32 +1,6 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.tmpNameSync = tmpNameSync;
27
- const crypto = __importStar(require("node:crypto"));
28
- const path = __importStar(require("node:path"));
29
- const fs = __importStar(require("fs-extra"));
1
+ import * as crypto from 'node:crypto';
2
+ import * as path from 'node:path';
3
+ import * as fs from 'fs-extra';
30
4
  const RANDOM_CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
31
5
  function randomChars(howMany) {
32
6
  const value = [];
@@ -48,7 +22,7 @@ function generateTmpName(tmpDir) {
48
22
  const name = ['tmp', '-', process.pid, '-', randomChars(12)].join('');
49
23
  return path.join(tmpDir, name);
50
24
  }
51
- function tmpNameSync(tmpDir, retries = 3) {
25
+ export function tmpNameSync(tmpDir, retries = 3) {
52
26
  let tries = retries;
53
27
  do {
54
28
  const name = generateTmpName(tmpDir);
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,35 +1,10 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getProjectConfig = getProjectConfig;
27
- exports.normalizeConfig = normalizeConfig;
28
- const path = __importStar(require("node:path"));
29
- const cosmiconfig_1 = require("cosmiconfig");
30
- const cosmiconfig_typescript_loader_1 = require("cosmiconfig-typescript-loader");
31
- const models_1 = require("./models");
32
- const utils_1 = require("./utils");
1
+ import * as path from 'node:path';
2
+ import { cosmiconfigSync } from 'cosmiconfig';
3
+ import { TypeScriptLoader as getTsLoader } from 'cosmiconfig-typescript-loader';
4
+ import { stripIndent } from 'common-tags';
5
+ import { isLibraryConfig, isServiceConfig } from './models';
6
+ import { getPort } from './utils';
7
+ import logger from './logger';
33
8
  function splitPaths(paths) {
34
9
  return (Array.isArray(paths) ? paths : [paths]).flatMap((p) => p.split(','));
35
10
  }
@@ -47,7 +22,7 @@ function omitUndefined(obj) {
47
22
  }
48
23
  function getModuleLoader({ storybook } = {}) {
49
24
  if (!storybook) {
50
- return (0, cosmiconfig_typescript_loader_1.TypeScriptLoader)();
25
+ return getTsLoader();
51
26
  }
52
27
  // storybook 7 uses esbuild-register to compile ts to cjs
53
28
  // https://github.com/storybookjs/storybook/blob/c1ec290b3a74ce05b23f74250539ae571bffaa66/code/lib/core-common/src/utils/interpret-require.ts#L11
@@ -61,10 +36,10 @@ function getModuleLoader({ storybook } = {}) {
61
36
  };
62
37
  }
63
38
  else {
64
- return (0, cosmiconfig_typescript_loader_1.TypeScriptLoader)();
39
+ return getTsLoader();
65
40
  }
66
41
  }
67
- async function getProjectConfig(command, { env, storybook, ...argv }) {
42
+ export async function getProjectConfig(command, { env, storybook, ...argv }) {
68
43
  function getLoader(loader) {
69
44
  return async (pathname, content) => {
70
45
  const config = loader(pathname, content);
@@ -76,7 +51,7 @@ async function getProjectConfig(command, { env, storybook, ...argv }) {
76
51
  }
77
52
  const tsLoader = getLoader(getModuleLoader({ storybook }));
78
53
  const moduleName = 'app-builder';
79
- const explorer = (0, cosmiconfig_1.cosmiconfigSync)(moduleName, {
54
+ const explorer = cosmiconfigSync(moduleName, {
80
55
  cache: false,
81
56
  stopDir: process.cwd(),
82
57
  searchPlaces: [
@@ -106,7 +81,7 @@ async function getProjectConfig(command, { env, storybook, ...argv }) {
106
81
  cfg = explorer.search();
107
82
  }
108
83
  const config = { verbose: false, ...(await cfg?.config) };
109
- if ((0, models_1.isLibraryConfig)(config)) {
84
+ if (isLibraryConfig(config)) {
110
85
  return normalizeConfig({
111
86
  ...config,
112
87
  ...omitUndefined({ verbose: argv.verbose }),
@@ -141,8 +116,8 @@ async function getProjectConfig(command, { env, storybook, ...argv }) {
141
116
  };
142
117
  return normalizeConfig(projectConfig, command);
143
118
  }
144
- async function normalizeConfig(userConfig, mode) {
145
- if ((0, models_1.isServiceConfig)(userConfig)) {
119
+ export async function normalizeConfig(userConfig, mode) {
120
+ if (isServiceConfig(userConfig)) {
146
121
  const clientConfig = typeof userConfig.client === 'object' ? userConfig.client : {};
147
122
  const client = await normalizeClientConfig(clientConfig, mode);
148
123
  client.verbose = userConfig.verbose;
@@ -158,7 +133,7 @@ async function normalizeConfig(userConfig, mode) {
158
133
  };
159
134
  if (mode === 'dev') {
160
135
  if (serverConfig.port === true) {
161
- server.port = await (0, utils_1.getPort)({ port: 3000 });
136
+ server.port = await getPort({ port: 3000 });
162
137
  }
163
138
  else {
164
139
  server.port = serverConfig.port;
@@ -183,6 +158,18 @@ async function normalizeConfig(userConfig, mode) {
183
158
  return config;
184
159
  }
185
160
  async function normalizeClientConfig(client, mode) {
161
+ let publicPath = client.publicPath || path.normalize(`${client.publicPathPrefix || ''}/build/`);
162
+ if (client.moduleFederation) {
163
+ publicPath = path.normalize(`${publicPath}${client.moduleFederation.name}/`);
164
+ }
165
+ let transformCssWithLightningCss = Boolean(client.transformCssWithLightningCss);
166
+ if (client.moduleFederation?.isolateStyles && transformCssWithLightningCss) {
167
+ transformCssWithLightningCss = false;
168
+ logger.warning(stripIndent `
169
+ transformCssWithLightningCss option is disabled because moduleFederation.isolateStyles is enabled.
170
+ postcss loader will be used instead.
171
+ `);
172
+ }
186
173
  const normalizedConfig = {
187
174
  ...client,
188
175
  forkTsChecker: client.disableForkTsChecker ? false : client.forkTsChecker,
@@ -190,14 +177,18 @@ async function normalizeClientConfig(client, mode) {
190
177
  ? false
191
178
  : (client.reactRefresh ?? ((options) => options)),
192
179
  newJsxTransform: client.newJsxTransform ?? true,
193
- publicPath: client.publicPath || path.normalize(`${client.publicPathPrefix || ''}/build/`),
194
- assetsManifestFile: client.assetsManifestFile || 'assets-manifest.json',
180
+ publicPath,
181
+ assetsManifestFile: client.assetsManifestFile ||
182
+ (client.moduleFederation?.version
183
+ ? `assets-manifest-${client.moduleFederation.version}.json`
184
+ : 'assets-manifest.json'),
195
185
  modules: client.modules && remapPaths(client.modules),
196
186
  includes: client.includes && remapPaths(client.includes),
197
187
  images: client.images && remapPaths(client.images),
198
188
  hiddenSourceMap: client.hiddenSourceMap ?? true,
199
189
  svgr: client.svgr ?? {},
200
190
  entryFilter: client.entryFilter && splitPaths(client.entryFilter),
191
+ transformCssWithLightningCss,
201
192
  webpack: typeof client.webpack === 'function' ? client.webpack : (config) => config,
202
193
  rspack: typeof client.rspack === 'function' ? client.rspack : (config) => config,
203
194
  babel: typeof client.babel === 'function' ? client.babel : (config) => config,
@@ -211,20 +202,20 @@ async function normalizeClientConfig(client, mode) {
211
202
  if (client.lazyCompilation) {
212
203
  if (client.lazyCompilation === true) {
213
204
  normalizedConfig.lazyCompilation = {
214
- port: await (0, utils_1.getPort)({ port: 6000 }),
205
+ port: await getPort({ port: 6000 }),
215
206
  };
216
207
  }
217
208
  else {
218
209
  normalizedConfig.lazyCompilation = client.lazyCompilation;
219
210
  }
220
211
  if (!normalizedConfig.lazyCompilation.port) {
221
- normalizedConfig.lazyCompilation.port = await (0, utils_1.getPort)({ port: 6000 });
212
+ normalizedConfig.lazyCompilation.port = await getPort({ port: 6000 });
222
213
  }
223
214
  }
224
215
  const devServer = client.devServer?.port
225
216
  ? {
226
217
  port: client.devServer.port === true
227
- ? await (0, utils_1.getPort)({ port: 8000 })
218
+ ? await getPort({ port: 8000 })
228
219
  : client.devServer.port,
229
220
  ipc: undefined,
230
221
  }
@@ -1,5 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const node_path_1 = require("node:path");
4
- const dotenv_1 = require("dotenv");
5
- (0, dotenv_1.config)({ path: (0, node_path_1.resolve)(process.cwd(), '.env') });
1
+ import { resolve } from 'node:path';
2
+ import { config } from 'dotenv';
3
+ config({ path: resolve(process.cwd(), '.env') });
@@ -1,9 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
1
  /* eslint-disable no-param-reassign */
4
- const helper_plugin_utils_1 = require("@babel/helper-plugin-utils");
2
+ import { declare } from '@babel/helper-plugin-utils';
5
3
  const svgPathRe = /^\.\.\/(.*)\/assets\/(.*)\.svg$/;
6
- exports.default = (0, helper_plugin_utils_1.declare)(function (api) {
4
+ export default declare(function (api) {
7
5
  return {
8
6
  visitor: {
9
7
  ImportDeclaration(path) {