@gravity-ui/app-builder 0.28.1-beta.5 → 0.28.1-beta.7

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.
@@ -1,72 +1,59 @@
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
- };
25
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
4
  };
28
5
  Object.defineProperty(exports, "__esModule", { value: true });
29
6
  exports.buildServer = buildServer;
30
- const path = __importStar(require("node:path"));
31
7
  const signal_exit_1 = require("signal-exit");
32
8
  const controllable_script_1 = require("../../../common/child-process/controllable-script");
33
- const logger_1 = require("../../../common/logger");
34
9
  const paths_1 = __importDefault(require("../../../common/paths"));
35
10
  const utils_1 = require("../../../common/utils");
36
- const swc = __importStar(require("../../../common/swc"));
11
+ function createSWCBuildScript(config) {
12
+ return `
13
+ let swcCli;
14
+ try {
15
+ swcCli = require('@swc/cli');
16
+ } catch (e) {
17
+ if (e.code !== 'MODULE_NOT_FOUND') {
18
+ throw e;
19
+ }
20
+ swcCli = require(${JSON.stringify(require.resolve('@swc/cli'))});
21
+ }
22
+ const {swcDir} = swcCli;
23
+ const {Logger} = require(${JSON.stringify(require.resolve('../../../common/logger'))});
24
+ const {compile} = require(${JSON.stringify(require.resolve('../../../common/swc/compile'))});
25
+
26
+ const logger = new Logger('server', ${config.verbose});
27
+ compile(swcDir, {
28
+ logger,
29
+ outputPath: ${JSON.stringify(paths_1.default.appDist)},
30
+ projectPath: ${JSON.stringify(paths_1.default.appServer)},
31
+ });`;
32
+ }
33
+ function createTypescriptBuildScript(config) {
34
+ return `
35
+ let ts;
36
+ try {
37
+ ts = require('typescript');
38
+ } catch (e) {
39
+ if (e.code !== 'MODULE_NOT_FOUND') {
40
+ throw e;
41
+ }
42
+ ts = require(${JSON.stringify(require.resolve('typescript'))});
43
+ }
44
+ const {Logger} = require(${JSON.stringify(require.resolve('../../../common/logger'))});
45
+ const {compile} = require(${JSON.stringify(require.resolve('../../../common/typescript/compile'))});
46
+
47
+ const logger = new Logger('server', ${config.verbose});
48
+ compile(ts, {logger, projectPath: ${JSON.stringify(paths_1.default.appServer)}});`;
49
+ }
37
50
  function buildServer(config) {
38
51
  (0, utils_1.createRunFolder)();
39
- if (config.server.compiler === 'swc') {
40
- // Используем SWC для компиляции
41
- return new Promise((resolve, reject) => {
42
- const logger = new logger_1.Logger('server', config.verbose);
43
- const serverPath = path.resolve(paths_1.default.appDist, 'server');
44
- swc.compile({
45
- projectPath: paths_1.default.appServer,
46
- outputPath: serverPath,
47
- logger,
48
- enableSourceMap: false,
49
- }).then(() => resolve(), (error) => reject(new Error(`SWC compilation failed: ${error}`)));
50
- });
51
- }
52
52
  // Используем TypeScript для компиляции (по умолчанию)
53
53
  return new Promise((resolve, reject) => {
54
- const build = new controllable_script_1.ControllableScript(`
55
- let ts;
56
- try {
57
- ts = require('typescript');
58
- } catch (e) {
59
- if (e.code !== 'MODULE_NOT_FOUND') {
60
- throw e;
61
- }
62
- ts = require(${JSON.stringify(require.resolve('typescript'))});
63
- }
64
- const {Logger} = require(${JSON.stringify(require.resolve('../../../common/logger'))});
65
- const {compile} = require(${JSON.stringify(require.resolve('../../../common/typescript/compile'))});
66
-
67
- const logger = new Logger('server', ${config.verbose});
68
- compile(ts, {logger, projectPath: ${JSON.stringify(paths_1.default.appServer)}});
69
- `, null);
54
+ const build = new controllable_script_1.ControllableScript(config.server.compiler === 'swc'
55
+ ? createSWCBuildScript(config)
56
+ : createTypescriptBuildScript(config), null);
70
57
  build.start().then(() => {
71
58
  build.onExit((code) => {
72
59
  if (code) {
@@ -79,6 +79,7 @@ watch(
79
79
  swcDir,
80
80
  ${JSON.stringify(paths_1.default.appServer)},
81
81
  {
82
+ outputPath: ${JSON.stringify(paths_1.default.appDist)},
82
83
  logger,
83
84
  onAfterFilesEmitted: () => {
84
85
  process.send({type: 'Emitted'});
@@ -5,5 +5,5 @@ interface SwcCompileOptions {
5
5
  logger: Logger;
6
6
  enableSourceMap?: boolean;
7
7
  }
8
- export declare function compile({ projectPath, outputPath, logger, enableSourceMap, }: SwcCompileOptions): Promise<void>;
8
+ export declare function compile(swcDir: any, { projectPath, outputPath, logger, enableSourceMap }: SwcCompileOptions): Promise<void>;
9
9
  export {};
@@ -1,72 +1,62 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.compile = compile;
4
- const rimraf_1 = require("rimraf");
5
- // @ts-ignore - @swc/cli не имеет типов
6
- const cli_1 = require("@swc/cli");
7
4
  const pretty_time_1 = require("../logger/pretty-time");
8
- async function compile({ projectPath, outputPath, logger, enableSourceMap = false, }) {
9
- const start = process.hrtime.bigint();
10
- logger.message('Start SWC compilation');
11
- // Очищаем выходную директорию
12
- rimraf_1.rimraf.sync(outputPath);
13
- const swcConfig = {
5
+ const getSwcConfig = (enableSourceMap = false) => {
6
+ return {
14
7
  module: {
15
8
  type: 'commonjs',
16
9
  },
17
10
  jsc: {
11
+ target: 'es2020',
18
12
  parser: {
19
13
  syntax: 'typescript',
20
- tsx: true,
21
14
  },
22
- target: 'es2020',
23
- transform: {
24
- decoratorMetadata: true,
25
- },
26
- externalHelpers: false,
27
15
  },
28
16
  sourceMaps: enableSourceMap,
29
17
  };
18
+ };
19
+ async function compile(
20
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
+ swcDir, { projectPath, outputPath, logger, enableSourceMap = false }) {
22
+ const start = process.hrtime.bigint();
23
+ logger.message('Start compilation');
24
+ const swcConfig = getSwcConfig(enableSourceMap);
30
25
  const cliOptions = {
31
26
  filenames: [projectPath],
32
27
  outDir: outputPath,
33
28
  watch: false,
34
- quiet: false,
35
29
  sourceMaps: enableSourceMap,
36
- extensions: ['.js', '.jsx', '.ts', '.tsx', '.mjs', '.cjs'],
30
+ extensions: ['.js', '.ts', '.mjs', '.cjs'],
37
31
  stripLeadingPaths: true,
38
- deleteDirOnStart: false,
39
- copyFiles: false,
40
- includeDotfiles: false,
41
32
  sync: false,
42
- workers: 1,
43
33
  };
44
34
  return new Promise((resolve, reject) => {
45
35
  const callbacks = {
46
36
  onSuccess: (_result) => {
47
- logger.success(`SWC compiled successfully in ${(0, pretty_time_1.elapsedTime)(start)}`);
37
+ logger.success(`Compiled successfully in ${(0, pretty_time_1.elapsedTime)(start)}`);
48
38
  resolve();
49
39
  },
50
40
  onFail: (result) => {
51
- logger.error(`SWC compilation failed in ${result.duration}ms`);
41
+ logger.error(`Compilation failed in ${result.duration}ms`);
52
42
  if (result.reasons) {
53
43
  for (const [filename, error] of result.reasons) {
54
44
  logger.error(`${filename}: ${error}`);
55
45
  }
56
46
  }
57
47
  logger.error(`Error compile, elapsed time ${(0, pretty_time_1.elapsedTime)(start)}`);
58
- reject(new Error('SWC compilation failed'));
48
+ reject(new Error('Compilation failed'));
59
49
  },
60
50
  };
61
51
  try {
62
- (0, cli_1.swcDir)({
52
+ swcDir({
63
53
  cliOptions,
64
54
  swcOptions: swcConfig,
65
55
  callbacks,
66
56
  });
67
57
  }
68
58
  catch (error) {
69
- logger.error(`Failed to start SWC compilation: ${error}`);
59
+ logger.error(`Failed to start compilation: ${error}`);
70
60
  reject(error);
71
61
  }
72
62
  });
@@ -1,10 +1,9 @@
1
1
  import type { Logger } from '../logger';
2
2
  interface SwcWatchOptions {
3
- projectPath: string;
4
3
  outputPath: string;
5
4
  logger: Logger;
6
5
  onAfterFilesEmitted?: () => void;
7
6
  enableSourceMap?: boolean;
8
7
  }
9
- export declare function watch(swcDir: any, { projectPath, outputPath, logger, onAfterFilesEmitted, enableSourceMap, }: SwcWatchOptions): Promise<void>;
8
+ export declare function watch(swcDir: any, projectPath: string, { outputPath, logger, onAfterFilesEmitted, enableSourceMap }: SwcWatchOptions): Promise<void>;
10
9
  export {};
@@ -1,46 +1,39 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.watch = watch;
4
- const rimraf_1 = require("rimraf");
5
- const getSwcConfig = () => {
4
+ const getSwcConfig = (enableSourceMap = false) => {
6
5
  return {
6
+ module: {
7
+ type: 'commonjs',
8
+ },
7
9
  jsc: {
8
10
  target: 'es2020',
9
11
  parser: {
10
12
  syntax: 'typescript',
11
- decorators: false,
12
- dynamicImport: false,
13
13
  },
14
14
  },
15
- sourceMaps: true,
15
+ sourceMaps: enableSourceMap,
16
16
  };
17
17
  };
18
18
  async function watch(
19
19
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
- swcDir, { projectPath, outputPath, logger, onAfterFilesEmitted, enableSourceMap = false, }) {
21
- logger.message('Start SWC compilation in watch mode');
22
- // Очищаем выходную директорию
23
- rimraf_1.rimraf.sync(outputPath);
24
- const swcConfig = getSwcConfig();
20
+ swcDir, projectPath, { outputPath, logger, onAfterFilesEmitted, enableSourceMap = false }) {
21
+ logger.message('Start compilation in watch mode');
22
+ const swcConfig = getSwcConfig(enableSourceMap);
25
23
  const cliOptions = {
26
24
  filenames: [projectPath],
27
25
  outDir: outputPath,
28
26
  watch: true,
29
- quiet: false,
30
27
  sourceMaps: enableSourceMap,
31
28
  extensions: ['.js', '.ts', '.mjs', '.cjs'],
32
29
  stripLeadingPaths: true,
33
- deleteDirOnStart: false,
34
- copyFiles: false,
35
- includeDotfiles: false,
36
30
  sync: false,
37
- workers: 1,
38
31
  logWatchCompilation: true,
39
32
  };
40
33
  const callbacks = {
41
34
  onSuccess: (result) => {
42
35
  if (result.filename) {
43
- logger.verbose(`Successfully compiled ${result.filename} in ${result.duration}ms`);
36
+ logger.message(`Successfully compiled ${result.filename} in ${result.duration}ms`);
44
37
  }
45
38
  else {
46
39
  logger.message(`Successfully compiled ${result.compiled || 0} files in ${result.duration}ms`);
@@ -48,7 +41,7 @@ swcDir, { projectPath, outputPath, logger, onAfterFilesEmitted, enableSourceMap
48
41
  onAfterFilesEmitted?.();
49
42
  },
50
43
  onFail: (result) => {
51
- logger.error(`SWC compilation failed in ${result.duration}ms`);
44
+ logger.error(`Compilation failed in ${result.duration}ms`);
52
45
  if (result.reasons) {
53
46
  for (const [filename, error] of result.reasons) {
54
47
  logger.error(`${filename}: ${error}`);
@@ -56,11 +49,10 @@ swcDir, { projectPath, outputPath, logger, onAfterFilesEmitted, enableSourceMap
56
49
  }
57
50
  },
58
51
  onWatchReady: () => {
59
- logger.message('SWC watching for file changes');
52
+ logger.message('Watching for file changes');
60
53
  },
61
54
  };
62
- // Запускаем swcDir
63
- await swcDir({
55
+ swcDir({
64
56
  cliOptions,
65
57
  swcOptions: swcConfig,
66
58
  callbacks,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/app-builder",
3
- "version": "0.28.1-beta.5",
3
+ "version": "0.28.1-beta.7",
4
4
  "description": "Develop and build your React client-server projects, powered by typescript and webpack",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",