@gravity-ui/app-builder 0.41.0 → 0.42.0-beta.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.
|
@@ -8,7 +8,4 @@ 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;
|
|
14
11
|
export declare function resolveTypescript(): string;
|
|
@@ -6,7 +6,6 @@ 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;
|
|
10
9
|
exports.resolveTypescript = resolveTypescript;
|
|
11
10
|
const node_path_1 = __importDefault(require("node:path"));
|
|
12
11
|
const paths_1 = __importDefault(require("../paths"));
|
|
@@ -61,24 +60,6 @@ function displayFilename(originalFunc, operationName, logger) {
|
|
|
61
60
|
};
|
|
62
61
|
return displayFunction;
|
|
63
62
|
}
|
|
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
|
-
}
|
|
82
63
|
function resolveTypescript() {
|
|
83
64
|
try {
|
|
84
65
|
return require.resolve(node_path_1.default.resolve(paths_1.default.appNodeModules, 'typescript'));
|
|
@@ -9,37 +9,52 @@ function watch(ts, projectPath, { logger, onAfterFilesEmitted, enableSourceMap,
|
|
|
9
9
|
logger.message(`Typescript v${ts.version}`);
|
|
10
10
|
const configPath = (0, utils_1.getTsProjectConfigPath)(ts, projectPath);
|
|
11
11
|
const createProgram = ts.createEmitAndSemanticDiagnosticsBuilderProgram;
|
|
12
|
-
const host = ts.
|
|
12
|
+
const host = ts.createSolutionBuilderWithWatchHost(ts.sys, createProgram, reportDiagnostic, reportDiagnostic, reportWatchStatusChanged);
|
|
13
|
+
const transformPathsToLocalModules = (0, transformers_1.createTransformPathsToLocalModules)(ts);
|
|
14
|
+
// `createSolutionBuilderWithWatch` creates an initial program, watches files, and updates
|
|
15
|
+
// the program over time.
|
|
16
|
+
const solutionBuilder = ts.createSolutionBuilderWithWatch(host, [configPath], {
|
|
13
17
|
noEmit: false,
|
|
14
18
|
noEmitOnError: false,
|
|
15
19
|
inlineSourceMap: enableSourceMap,
|
|
16
20
|
inlineSources: enableSourceMap,
|
|
17
21
|
...(enableSourceMap ? { sourceMap: false } : undefined),
|
|
18
|
-
}, ts.sys, createProgram, reportDiagnostic, reportWatchStatusChanged);
|
|
19
|
-
host.readFile = (0, utils_1.displayFilename)(host.readFile, 'Reading', logger);
|
|
20
|
-
(0, utils_1.onHostEvent)(host, 'createProgram', () => {
|
|
21
|
-
logger.verbose("We're about to create the program");
|
|
22
|
-
// @ts-expect-error
|
|
23
|
-
host.readFile.enableDisplay();
|
|
24
|
-
}, () => {
|
|
25
|
-
// @ts-expect-error
|
|
26
|
-
const count = host.readFile.disableDisplay();
|
|
27
|
-
logger.verbose(`Program created, read ${count} files`);
|
|
28
|
-
});
|
|
29
|
-
(0, utils_1.onHostEvent)(host, 'afterProgramCreate', (program) => {
|
|
30
|
-
logger.verbose('We finished making the program! Emitting...');
|
|
31
|
-
const transformPathsToLocalModules = (0, transformers_1.createTransformPathsToLocalModules)(ts);
|
|
32
|
-
program.emit(undefined, undefined, undefined, undefined, {
|
|
33
|
-
after: [transformPathsToLocalModules],
|
|
34
|
-
afterDeclarations: [transformPathsToLocalModules],
|
|
35
|
-
});
|
|
36
|
-
logger.verbose('Emit completed!');
|
|
37
|
-
}, () => {
|
|
38
|
-
onAfterFilesEmitted?.();
|
|
39
22
|
});
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
+
}
|
|
43
58
|
function reportDiagnostic(diagnostic) {
|
|
44
59
|
const formatHost = {
|
|
45
60
|
getCanonicalFileName: (path) => path,
|
package/package.json
CHANGED