@gravity-ui/app-builder 0.42.0-beta.0 → 0.42.0-beta.1

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.
@@ -8,4 +8,7 @@ export declare function displayFilename(originalFunc: (path: string, encoding?:
8
8
  enableDisplay(): void;
9
9
  disableDisplay(): number;
10
10
  };
11
+ export declare function onHostEvent<F extends string, T extends {
12
+ [key in F]?: (...args: any[]) => any;
13
+ }>(host: T, functionName: F, before?: (...args: Parameters<NonNullable<T[F]>>) => void, after?: (res: ReturnType<NonNullable<T[F]>>) => void): void;
11
14
  export declare function resolveTypescript(): string;
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getTsProjectConfigPath = getTsProjectConfigPath;
7
7
  exports.getTsProjectConfig = getTsProjectConfig;
8
8
  exports.displayFilename = displayFilename;
9
+ exports.onHostEvent = onHostEvent;
9
10
  exports.resolveTypescript = resolveTypescript;
10
11
  const node_path_1 = __importDefault(require("node:path"));
11
12
  const paths_1 = __importDefault(require("../paths"));
@@ -60,6 +61,24 @@ function displayFilename(originalFunc, operationName, logger) {
60
61
  };
61
62
  return displayFunction;
62
63
  }
64
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
65
+ function onHostEvent(host, functionName, before, after) {
66
+ const originalFunction = host[functionName];
67
+ // eslint-disable-next-line no-param-reassign
68
+ host[functionName] = ((...args) => {
69
+ if (before) {
70
+ before(...args);
71
+ }
72
+ let result;
73
+ if (typeof originalFunction === 'function') {
74
+ result = originalFunction(...args);
75
+ }
76
+ if (after) {
77
+ after(result);
78
+ }
79
+ return result;
80
+ });
81
+ }
63
82
  function resolveTypescript() {
64
83
  try {
65
84
  return require.resolve(node_path_1.default.resolve(paths_1.default.appNodeModules, 'typescript'));
@@ -10,7 +10,21 @@ function watch(ts, projectPath, { logger, onAfterFilesEmitted, enableSourceMap,
10
10
  const configPath = (0, utils_1.getTsProjectConfigPath)(ts, projectPath);
11
11
  const createProgram = ts.createEmitAndSemanticDiagnosticsBuilderProgram;
12
12
  const host = ts.createSolutionBuilderWithWatchHost(ts.sys, createProgram, reportDiagnostic, reportDiagnostic, reportWatchStatusChanged);
13
- const transformPathsToLocalModules = (0, transformers_1.createTransformPathsToLocalModules)(ts);
13
+ host.readFile = (0, utils_1.displayFilename)(host.readFile, 'Reading', logger);
14
+ (0, utils_1.onHostEvent)(host, 'createProgram', () => {
15
+ logger.verbose("We're about to create the program");
16
+ // @ts-expect-error
17
+ host.readFile.enableDisplay();
18
+ }, () => {
19
+ // @ts-expect-error
20
+ const count = host.readFile.disableDisplay();
21
+ logger.verbose(`Program created, read ${count} files`);
22
+ });
23
+ (0, utils_1.onHostEvent)(host, 'afterProgramEmitAndDiagnostics', () => {
24
+ logger.verbose('Emit completed!');
25
+ }, () => {
26
+ onAfterFilesEmitted?.();
27
+ });
14
28
  // `createSolutionBuilderWithWatch` creates an initial program, watches files, and updates
15
29
  // the program over time.
16
30
  const solutionBuilder = ts.createSolutionBuilderWithWatch(host, [configPath], {
@@ -20,41 +34,11 @@ function watch(ts, projectPath, { logger, onAfterFilesEmitted, enableSourceMap,
20
34
  inlineSources: enableSourceMap,
21
35
  ...(enableSourceMap ? { sourceMap: false } : undefined),
22
36
  });
23
- let project = solutionBuilder.getNextInvalidatedProject();
24
- do {
25
- if (project?.kind === ts.InvalidatedProjectKind.Build) {
26
- const projectConfigPath = project.project.replace(process.cwd(), '');
27
- const originalReadFile = host.readFile;
28
- host.readFile = (0, utils_1.displayFilename)(originalReadFile, 'Reading', logger);
29
- logger.verbose("We're about to create the program");
30
- // @ts-expect-error We invoke method from overrided function
31
- host.readFile.enableDisplay();
32
- const program = project.getProgram();
33
- if (!program) {
34
- logger.verbose(`Program was not created, skip emitting for ${projectConfigPath}`);
35
- // @ts-expect-error We invoke method from overrided function
36
- host.readFile.disableDisplay();
37
- host.readFile = originalReadFile;
38
- logger.verbose(`We finished making the program for ${projectConfigPath}! Emitting...`);
39
- next();
40
- continue;
41
- }
42
- // @ts-expect-error
43
- const count = host.readFile.disableDisplay();
44
- host.readFile = originalReadFile;
45
- logger.verbose(`Program created, read ${count} files`);
46
- project.emit(undefined, undefined, undefined, undefined, {
47
- after: [transformPathsToLocalModules],
48
- afterDeclarations: [transformPathsToLocalModules],
49
- });
50
- logger.verbose('Emit completed!');
51
- next();
52
- }
53
- } while (project);
54
- onAfterFilesEmitted?.();
55
- function next() {
56
- project = solutionBuilder.getNextInvalidatedProject();
57
- }
37
+ const transformPathsToLocalModules = (0, transformers_1.createTransformPathsToLocalModules)(ts);
38
+ solutionBuilder.build(undefined, undefined, undefined, () => ({
39
+ after: [transformPathsToLocalModules],
40
+ afterDeclarations: [transformPathsToLocalModules],
41
+ }));
58
42
  function reportDiagnostic(diagnostic) {
59
43
  const formatHost = {
60
44
  getCanonicalFileName: (path) => path,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/app-builder",
3
- "version": "0.42.0-beta.0",
3
+ "version": "0.42.0-beta.1",
4
4
  "description": "Develop and build your React client-server projects, powered by typescript and webpack",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",