@gravity-ui/app-builder 0.6.10 → 0.7.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 (42) hide show
  1. package/README.md +29 -27
  2. package/dist/commands/build/build-service/server.js +1 -1
  3. package/dist/commands/build/index.js +1 -1
  4. package/dist/commands/dev/client.js +33 -10
  5. package/dist/commands/dev/index.js +25 -2
  6. package/dist/commands/dev/server.js +25 -2
  7. package/dist/common/babel/ui-preset.js +7 -0
  8. package/dist/common/child-process/controllable-script.js +4 -2
  9. package/dist/common/child-process/utils.js +5 -8
  10. package/dist/common/config.d.ts +1 -1
  11. package/dist/common/config.js +26 -3
  12. package/dist/common/env.js +2 -2
  13. package/dist/common/library/index.js +77 -55
  14. package/dist/common/links/link.js +42 -19
  15. package/dist/common/links/unlink.js +26 -3
  16. package/dist/common/logger/index.js +79 -79
  17. package/dist/common/models/index.d.ts +3 -3
  18. package/dist/common/package.js +30 -10
  19. package/dist/common/paths.js +26 -6
  20. package/dist/common/s3-upload/compress.js +3 -3
  21. package/dist/common/s3-upload/s3-client.d.ts +1 -1
  22. package/dist/common/s3-upload/s3-client.js +1 -1
  23. package/dist/common/s3-upload/upload.js +1 -1
  24. package/dist/common/s3-upload/webpack-plugin.js +1 -0
  25. package/dist/common/tempData.js +31 -7
  26. package/dist/common/typescript/compile.d.ts +7 -2
  27. package/dist/common/typescript/compile.js +5 -5
  28. package/dist/common/typescript/diagnostic.js +24 -4
  29. package/dist/common/typescript/transformers.js +1 -1
  30. package/dist/common/typescript/utils.d.ts +1 -1
  31. package/dist/common/typescript/utils.js +3 -3
  32. package/dist/common/utils.js +5 -5
  33. package/dist/common/webpack/config.js +33 -23
  34. package/dist/common/webpack/progress-plugin.js +6 -5
  35. package/dist/common/webpack/storybook.js +25 -3
  36. package/dist/common/webpack/utils.js +29 -9
  37. package/dist/common/webpack/worker/worker-loader.js +27 -4
  38. package/dist/create-cli.js +25 -2
  39. package/package.json +14 -11
  40. package/CHANGELOG.md +0 -257
  41. package/dist/common/library/babel-plugin-remove-css-imports.d.ts +0 -6
  42. package/dist/common/library/babel-plugin-remove-css-imports.js +0 -15
package/README.md CHANGED
@@ -57,32 +57,34 @@ If the config needs to be conditionally determined, it can export a function ins
57
57
  ```ts
58
58
  import {defineConfig} from '@gravity-ui/app-builder';
59
59
 
60
- export default defineConfig(async function (
61
- /** @type dev | build */
62
- command,
63
- /**
64
- * values specified with --env flag
65
- *
66
- * @type {[k in string]: string}
67
- *
68
- * @example
69
- * With follow command:
70
- * app-build dev --env=path.to.member1=value1 --env=path.to.member2=value2
71
- * you get:
72
- * env = {path: {to: {member1: 'value1', member2: 'value2'}}}
73
- */
74
- env,
75
- ) {
76
- return {
77
- verbose: command === 'dev',
78
- client: {
79
- // client settings
80
- },
81
- server: {
82
- // server settings
83
- },
84
- };
85
- });
60
+ export default defineConfig(
61
+ async function (
62
+ /** @type dev | build */
63
+ command,
64
+ /**
65
+ * values specified with --env flag
66
+ *
67
+ * @type {[k in string]: string}
68
+ *
69
+ * @example
70
+ * With follow command:
71
+ * app-build dev --env=path.to.member1=value1 --env=path.to.member2=value2
72
+ * you get:
73
+ * env = {path: {to: {member1: 'value1', member2: 'value2'}}}
74
+ */
75
+ env,
76
+ ) {
77
+ return {
78
+ verbose: command === 'dev',
79
+ client: {
80
+ // client settings
81
+ },
82
+ server: {
83
+ // server settings
84
+ },
85
+ };
86
+ },
87
+ );
86
88
 
87
89
  export default config;
88
90
  ```
@@ -227,7 +229,7 @@ With this `{rootDir}/src/ui/tsconfig.json`:
227
229
 
228
230
  ##### Optimization
229
231
 
230
- - `vendors` (`string[]`) — additional libraries for vendor chunk
232
+ - `vendors` (`string[] | (defaultVendors: string[]) => string[]`) — additional libraries or a function returning libraries for a vendor chunk;
231
233
  - `momentTz` — [settings](https://www.npmjs.com/package/moment-timezone-data-webpack-plugin) for moment-timezone (by default data is truncated);
232
234
  - `contextReplacement` (`object`)
233
235
  - `highlight.js` (`string[]`) — list of language names to include, e.g. `['javascript', 'python', 'bash']`;
@@ -17,7 +17,7 @@ function buildServer(config) {
17
17
  const {compile} = require(${JSON.stringify(require.resolve('../../../common/typescript/compile'))});
18
18
 
19
19
  const logger = new Logger('server', ${config.verbose});
20
- compile(ts, ${JSON.stringify(paths_1.default.appServer)}, {logger});
20
+ compile(ts, {logger, projectPath: ${JSON.stringify(paths_1.default.appServer)}});
21
21
  `, null);
22
22
  build.start();
23
23
  build.onExit((code) => {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const models_1 = require("../../common/models");
4
4
  async function default_1(config) {
5
5
  process.env.NODE_ENV = 'production';
6
- // eslint-disable-next-line global-require, security/detect-non-literal-require
6
+ // eslint-disable-next-line security/detect-non-literal-require
7
7
  const { default: build } = require((0, models_1.isLibraryConfig)(config) ? './build-lib' : './build-service');
8
8
  return build(config);
9
9
  }
@@ -1,11 +1,34 @@
1
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
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
5
28
  Object.defineProperty(exports, "__esModule", { value: true });
6
29
  exports.watchClientCompilation = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- const fs_1 = __importDefault(require("fs"));
30
+ const path = __importStar(require("node:path"));
31
+ const fs = __importStar(require("node:fs"));
9
32
  const webpack_1 = __importDefault(require("webpack"));
10
33
  const webpack_dev_server_1 = __importDefault(require("webpack-dev-server"));
11
34
  const webpack_manifest_plugin_1 = require("webpack-manifest-plugin");
@@ -21,13 +44,13 @@ async function watchClientCompilation(config, onCompilationEnd) {
21
44
  exports.watchClientCompilation = watchClientCompilation;
22
45
  async function buildWebpackServer(config) {
23
46
  const logger = new logger_1.Logger('webpack', config.verbose);
24
- const { webSocketPath = path_1.default.normalize(`/${config.client.publicPathPrefix}/build/sockjs-node`), ...devServer } = config.client.devServer || {};
47
+ const { webSocketPath = path.normalize(`/${config.client.publicPathPrefix}/build/sockjs-node`), ...devServer } = config.client.devServer || {};
25
48
  const normalizedConfig = { ...config.client, devServer: { ...devServer, webSocketPath } };
26
49
  const webpackConfig = (0, config_1.webpackConfigFactory)("development" /* WebpackMode.Dev */, normalizedConfig, { logger });
27
50
  const options = {
28
- static: path_1.default.resolve(paths_1.default.appDist, 'public'),
51
+ static: path.resolve(paths_1.default.appDist, 'public'),
29
52
  devMiddleware: {
30
- publicPath: path_1.default.normalize(config.client.publicPathPrefix + '/build/'),
53
+ publicPath: path.normalize(config.client.publicPathPrefix + '/build/'),
31
54
  stats: 'errors-warnings',
32
55
  },
33
56
  liveReload: false,
@@ -56,7 +79,7 @@ async function buildWebpackServer(config) {
56
79
  };
57
80
  const listenOn = options.port || options.ipc;
58
81
  if (!listenOn) {
59
- options.ipc = path_1.default.resolve(paths_1.default.appDist, 'run/client.sock');
82
+ options.ipc = path.resolve(paths_1.default.appDist, 'run/client.sock');
60
83
  }
61
84
  if (config.client.lazyCompilation) {
62
85
  options.proxy = {
@@ -77,11 +100,11 @@ async function buildWebpackServer(config) {
77
100
  return null;
78
101
  }
79
102
  const pathname = req.path.replace(/^\//, '');
80
- const filepath = path_1.default.resolve(paths_1.default.appDist, 'public', pathname);
81
- if (!fs_1.default.existsSync(filepath)) {
103
+ const filepath = path.resolve(paths_1.default.appDist, 'public', pathname);
104
+ if (!fs.existsSync(filepath)) {
82
105
  return null;
83
106
  }
84
- const stat = fs_1.default.statSync(filepath);
107
+ const stat = fs.statSync(filepath);
85
108
  if (!stat.isFile()) {
86
109
  return null;
87
110
  }
@@ -99,7 +122,7 @@ async function buildWebpackServer(config) {
99
122
  logger.logError(e);
100
123
  }
101
124
  if (options.ipc && typeof options.ipc === 'string') {
102
- fs_1.default.chmod(options.ipc, 0o666, (e) => logger.logError('', e));
125
+ fs.chmod(options.ipc, 0o666, (e) => logger.logError('', e));
103
126
  }
104
127
  return server;
105
128
  }
@@ -1,9 +1,32 @@
1
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
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
5
28
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const node_path_1 = __importDefault(require("node:path"));
29
+ const path = __importStar(require("node:path"));
7
30
  const nodemon_1 = __importDefault(require("nodemon"));
8
31
  const signal_exit_1 = require("signal-exit");
9
32
  const rimraf_1 = require("rimraf");
@@ -20,7 +43,7 @@ async function default_1(config) {
20
43
  let clientCompiled = !shouldCompileClient;
21
44
  let serverCompiled = !shouldCompileServer;
22
45
  let needToStartNodemon = shouldCompileServer;
23
- const serverPath = node_path_1.default.resolve(paths_1.default.appDist, 'server');
46
+ const serverPath = path.resolve(paths_1.default.appDist, 'server');
24
47
  const { inspect, inspectBrk } = config.server;
25
48
  const startNodemon = () => {
26
49
  if (needToStartNodemon && serverCompiled && clientCompiled) {
@@ -1,16 +1,39 @@
1
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
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
5
28
  Object.defineProperty(exports, "__esModule", { value: true });
6
29
  exports.watchServerCompilation = void 0;
7
- const node_path_1 = __importDefault(require("node:path"));
30
+ const path = __importStar(require("node:path"));
8
31
  const rimraf_1 = require("rimraf");
9
32
  const controllable_script_1 = require("../../common/child-process/controllable-script");
10
33
  const utils_1 = require("../../common/utils");
11
34
  const paths_1 = __importDefault(require("../../common/paths"));
12
35
  function watchServerCompilation(config) {
13
- const serverPath = node_path_1.default.resolve(paths_1.default.appDist, 'server');
36
+ const serverPath = path.resolve(paths_1.default.appDist, 'server');
14
37
  rimraf_1.rimraf.sync(serverPath);
15
38
  (0, utils_1.createRunFolder)();
16
39
  const build = new controllable_script_1.ControllableScript(`
@@ -46,6 +46,13 @@ module.exports = function (_context, options = {}) {
46
46
  const plugins = [
47
47
  // Polyfills the runtime needed for async/await and generators
48
48
  [require.resolve('@babel/plugin-transform-runtime'), runtimeOptions],
49
+ /**
50
+ * Safari 15 has a buggy implementation of class properties,
51
+ * but @babel/compat-data marks it as stable.
52
+ * Can be removed once the issue is fixed and released.
53
+ * @see https://github.com/babel/babel/issues/14289
54
+ */
55
+ [require.resolve('@babel/plugin-transform-class-properties')],
49
56
  isEnvProduction && [
50
57
  require.resolve('babel-plugin-transform-react-remove-prop-types'),
51
58
  {
@@ -29,9 +29,11 @@ const fs = __importStar(require("fs-extra"));
29
29
  const execa = __importStar(require("execa"));
30
30
  const utils_2 = require("../utils");
31
31
  class ControllableScript {
32
+ isRunning = false;
33
+ process;
34
+ script = '';
35
+ debugInfo;
32
36
  constructor(script, debugInfo) {
33
- this.isRunning = false;
34
- this.script = '';
35
37
  this.script = script;
36
38
  this.debugInfo = debugInfo;
37
39
  }
@@ -22,13 +22,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
25
  Object.defineProperty(exports, "__esModule", { value: true });
29
26
  exports.tmpNameSync = void 0;
30
- const crypto_1 = __importDefault(require("crypto"));
31
- const path_1 = __importDefault(require("path"));
27
+ const crypto = __importStar(require("node:crypto"));
28
+ const path = __importStar(require("node:path"));
32
29
  const fs = __importStar(require("fs-extra"));
33
30
  const RANDOM_CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
34
31
  function randomChars(howMany) {
@@ -36,11 +33,11 @@ function randomChars(howMany) {
36
33
  let rnd = null;
37
34
  // make sure that we do not fail because we ran out of entropy
38
35
  try {
39
- rnd = crypto_1.default.randomBytes(howMany);
36
+ rnd = crypto.randomBytes(howMany);
40
37
  }
41
38
  catch (e) {
42
39
  // eslint-disable-next-line security/detect-pseudoRandomBytes
43
- rnd = crypto_1.default.pseudoRandomBytes(howMany);
40
+ rnd = crypto.pseudoRandomBytes(howMany);
44
41
  }
45
42
  for (let i = 0; i < howMany; i++) {
46
43
  value.push(RANDOM_CHARS[(rnd[i] ?? 0) % RANDOM_CHARS.length] ?? '0');
@@ -49,7 +46,7 @@ function randomChars(howMany) {
49
46
  }
50
47
  function generateTmpName(tmpDir) {
51
48
  const name = ['tmp', '-', process.pid, '-', randomChars(12)].join('');
52
- return path_1.default.join(tmpDir, name);
49
+ return path.join(tmpDir, name);
53
50
  }
54
51
  function tmpNameSync(tmpDir, retries = 3) {
55
52
  let tries = retries;
@@ -1,4 +1,4 @@
1
- import type { NormalizedServiceConfig, ServiceConfig, LibraryConfig } from './models';
1
+ import type { LibraryConfig, NormalizedServiceConfig, ServiceConfig } from './models';
2
2
  import type { CliArgs } from '../create-cli';
3
3
  export declare function getProjectConfig(command: string, { env, storybook, ...argv }: Partial<CliArgs> & {
4
4
  storybook?: boolean;
@@ -1,10 +1,33 @@
1
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
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
5
28
  Object.defineProperty(exports, "__esModule", { value: true });
6
29
  exports.normalizeConfig = exports.getProjectConfig = void 0;
7
- const path_1 = __importDefault(require("path"));
30
+ const path = __importStar(require("node:path"));
8
31
  const lodash_1 = __importDefault(require("lodash"));
9
32
  const cosmiconfig_1 = require("cosmiconfig");
10
33
  const cosmiconfig_typescript_loader_1 = require("cosmiconfig-typescript-loader");
@@ -14,7 +37,7 @@ function splitPaths(paths) {
14
37
  return (Array.isArray(paths) ? paths : [paths]).flatMap((p) => p.split(','));
15
38
  }
16
39
  function remapPaths(paths) {
17
- return splitPaths(paths).map((p) => path_1.default.resolve(process.cwd(), p));
40
+ return splitPaths(paths).map((p) => path.resolve(process.cwd(), p));
18
41
  }
19
42
  function omitUndefined(obj) {
20
43
  return lodash_1.default.omitBy(obj, lodash_1.default.isUndefined);
@@ -92,7 +115,7 @@ async function getProjectConfig(command, { env, storybook, ...argv }) {
92
115
  inspect: argv.inspect,
93
116
  inspectBrk: argv.inspectBrk,
94
117
  };
95
- const config = { ...(await cfg?.config) };
118
+ const config = { verbose: false, ...(await cfg?.config) };
96
119
  if ((0, models_1.isLibraryConfig)(config)) {
97
120
  return normalizeConfig({
98
121
  ...config,
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const path_1 = require("path");
3
+ const node_path_1 = require("node:path");
4
4
  const dotenv_1 = require("dotenv");
5
- (0, dotenv_1.config)({ path: (0, path_1.resolve)(process.cwd(), '.env') });
5
+ (0, dotenv_1.config)({ path: (0, node_path_1.resolve)(process.cwd(), '.env') });