@gravity-ui/app-builder 0.14.0-beta.1 → 0.14.0-beta.3
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.
- package/dist/common/typescript/compile.js +10 -18
- package/dist/common/typescript/utils.d.ts +2 -1
- package/dist/common/typescript/utils.js +20 -2
- package/dist/common/typescript/watch.js +1 -1
- package/dist/common/webpack/config.js +9 -3
- package/dist/common/webpack/utils.d.ts +5 -2
- package/dist/common/webpack/utils.js +16 -19
- package/package.json +1 -1
|
@@ -10,24 +10,11 @@ function compile(ts, { projectPath, configFileName = 'tsconfig.json', optionsToE
|
|
|
10
10
|
logger.message('Start compilation');
|
|
11
11
|
logger.message(`Typescript v${ts.version}`);
|
|
12
12
|
logger.verbose(`Searching for the ${configFileName} in ${projectPath}`);
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
};
|
|
19
|
-
const parseConfigFileHost = {
|
|
20
|
-
getCurrentDirectory: ts.sys.getCurrentDirectory,
|
|
21
|
-
useCaseSensitiveFileNames: ts.sys.useCaseSensitiveFileNames,
|
|
22
|
-
readDirectory: ts.sys.readDirectory,
|
|
23
|
-
fileExists: ts.sys.fileExists,
|
|
24
|
-
readFile: ts.sys.readFile,
|
|
25
|
-
onUnRecoverableConfigFileDiagnostic: reportDiagnostic,
|
|
26
|
-
};
|
|
27
|
-
const parsedConfig = ts.getParsedCommandLineOfConfigFile(configPath, { noEmit: false, noEmitOnError: true, ...optionsToExtend }, parseConfigFileHost);
|
|
28
|
-
if (!parsedConfig) {
|
|
29
|
-
throw new Error(`Invalid '${configFileName}'`);
|
|
30
|
-
}
|
|
13
|
+
const parsedConfig = (0, utils_1.getTsProjectConfig)(ts, projectPath, configFileName, {
|
|
14
|
+
noEmit: false,
|
|
15
|
+
noEmitOnError: true,
|
|
16
|
+
...optionsToExtend,
|
|
17
|
+
});
|
|
31
18
|
logger.verbose('Config found and parsed');
|
|
32
19
|
logger.verbose("We're about to create the program");
|
|
33
20
|
const compilerHost = ts.createCompilerHost(parsedConfig.options);
|
|
@@ -57,6 +44,11 @@ function compile(ts, { projectPath, configFileName = 'tsconfig.json', optionsToE
|
|
|
57
44
|
else {
|
|
58
45
|
logger.success(`Compiled successfully in ${(0, pretty_time_1.elapsedTime)(start)}`);
|
|
59
46
|
}
|
|
47
|
+
const formatHost = {
|
|
48
|
+
getCanonicalFileName: (path) => path,
|
|
49
|
+
getCurrentDirectory: ts.sys.getCurrentDirectory,
|
|
50
|
+
getNewLine: () => ts.sys.newLine,
|
|
51
|
+
};
|
|
60
52
|
function reportDiagnostic(diagnostic) {
|
|
61
53
|
if (logger.isVerbose) {
|
|
62
54
|
logger.message(ts.formatDiagnosticsWithColorAndContext([diagnostic], formatHost));
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type Typescript from 'typescript';
|
|
2
2
|
import type { Logger } from '../logger';
|
|
3
|
-
export declare function
|
|
3
|
+
export declare function getTsProjectConfigPath(ts: typeof Typescript, projectPath: string, filename?: string): string;
|
|
4
|
+
export declare function getTsProjectConfig(ts: typeof Typescript, projectPath: string, filename?: string, optionsToExtend?: Typescript.CompilerOptions): Typescript.ParsedCommandLine;
|
|
4
5
|
export declare function displayFilename(originalFunc: (path: string, encoding?: string) => string | undefined, operationName: string, logger: Logger): {
|
|
5
6
|
(path: string, encoding?: string | undefined): string | undefined;
|
|
6
7
|
originalFunc: (path: string, encoding?: string) => string | undefined;
|
|
@@ -3,19 +3,37 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.getTsProjectConfigPath = getTsProjectConfigPath;
|
|
7
|
+
exports.getTsProjectConfig = getTsProjectConfig;
|
|
7
8
|
exports.displayFilename = displayFilename;
|
|
8
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"));
|
|
12
|
-
function
|
|
13
|
+
function getTsProjectConfigPath(ts, projectPath, filename = 'tsconfig.json') {
|
|
13
14
|
const configPath = ts.findConfigFile(projectPath, ts.sys.fileExists, filename);
|
|
14
15
|
if (!configPath) {
|
|
15
16
|
throw new Error(`Could not find a valid '${filename}'.`);
|
|
16
17
|
}
|
|
17
18
|
return configPath;
|
|
18
19
|
}
|
|
20
|
+
function getTsProjectConfig(ts, projectPath, filename = 'tsconfig.json', optionsToExtend) {
|
|
21
|
+
const configPath = getTsProjectConfigPath(ts, projectPath, filename);
|
|
22
|
+
const parseConfigFileHost = {
|
|
23
|
+
getCurrentDirectory: ts.sys.getCurrentDirectory,
|
|
24
|
+
useCaseSensitiveFileNames: ts.sys.useCaseSensitiveFileNames,
|
|
25
|
+
readDirectory: ts.sys.readDirectory,
|
|
26
|
+
fileExists: ts.sys.fileExists,
|
|
27
|
+
readFile: ts.sys.readFile,
|
|
28
|
+
// this is required in types but not used
|
|
29
|
+
onUnRecoverableConfigFileDiagnostic: () => { },
|
|
30
|
+
};
|
|
31
|
+
const parsedConfig = ts.getParsedCommandLineOfConfigFile(configPath, optionsToExtend, parseConfigFileHost);
|
|
32
|
+
if (!parsedConfig) {
|
|
33
|
+
throw new Error(`Invalid config file '${configPath}'`);
|
|
34
|
+
}
|
|
35
|
+
return parsedConfig;
|
|
36
|
+
}
|
|
19
37
|
function displayFilename(originalFunc, operationName, logger) {
|
|
20
38
|
let displayEnabled = false;
|
|
21
39
|
let count = 0;
|
|
@@ -7,7 +7,7 @@ const diagnostic_1 = require("./diagnostic");
|
|
|
7
7
|
function watch(ts, projectPath, { logger, onAfterFilesEmitted, enableSourceMap, }) {
|
|
8
8
|
logger.message('Start compilation in watch mode');
|
|
9
9
|
logger.message(`Typescript v${ts.version}`);
|
|
10
|
-
const configPath = (0, utils_1.
|
|
10
|
+
const configPath = (0, utils_1.getTsProjectConfigPath)(ts, projectPath);
|
|
11
11
|
const createProgram = ts.createEmitAndSemanticDiagnosticsBuilderProgram;
|
|
12
12
|
const formatHost = {
|
|
13
13
|
getCanonicalFileName: (path) => path,
|
|
@@ -192,7 +192,7 @@ function configureResolve({ isEnvProduction, config }) {
|
|
|
192
192
|
alias['react-dom$'] = 'react-dom/profiling';
|
|
193
193
|
alias['scheduler/tracing'] = 'scheduler/tracing-profiling';
|
|
194
194
|
}
|
|
195
|
-
const { aliases, modules = [] } = (0, utils_1.
|
|
195
|
+
const { aliases, modules = [] } = (0, utils_1.resolveTsConfigPathsToAlias)(paths_1.default.appClient);
|
|
196
196
|
return {
|
|
197
197
|
alias: {
|
|
198
198
|
...aliases,
|
|
@@ -404,11 +404,17 @@ function getCssLoaders({ isEnvDevelopment, isEnvProduction, config, isSsr }, add
|
|
|
404
404
|
},
|
|
405
405
|
});
|
|
406
406
|
if (isEnvProduction) {
|
|
407
|
-
loaders.unshift({
|
|
407
|
+
loaders.unshift({
|
|
408
|
+
loader: mini_css_extract_plugin_1.default.loader,
|
|
409
|
+
options: { emit: isSsr ? false : undefined },
|
|
410
|
+
});
|
|
408
411
|
}
|
|
409
412
|
if (isEnvDevelopment) {
|
|
410
413
|
if (isSsr || config.ssr) {
|
|
411
|
-
loaders.unshift({
|
|
414
|
+
loaders.unshift({
|
|
415
|
+
loader: mini_css_extract_plugin_1.default.loader,
|
|
416
|
+
options: { emit: isSsr ? false : undefined },
|
|
417
|
+
});
|
|
412
418
|
}
|
|
413
419
|
else {
|
|
414
420
|
loaders.unshift({
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type webpack from 'webpack';
|
|
2
2
|
import type { Logger } from '../logger';
|
|
3
3
|
export declare function webpackCompilerHandlerFactory(logger: Logger, onCompilationEnd?: () => void): (err?: Error | null, stats?: webpack.MultiStats) => Promise<void>;
|
|
4
|
-
export declare function
|
|
4
|
+
export declare function resolveTsConfigPathsToAlias(projectPath: string, filename?: string): {
|
|
5
|
+
aliases?: undefined;
|
|
6
|
+
modules?: undefined;
|
|
7
|
+
} | {
|
|
5
8
|
aliases: Record<string, string[]>;
|
|
6
9
|
modules: string[];
|
|
7
|
-
}
|
|
10
|
+
};
|
|
@@ -24,10 +24,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.webpackCompilerHandlerFactory = webpackCompilerHandlerFactory;
|
|
27
|
-
exports.
|
|
27
|
+
exports.resolveTsConfigPathsToAlias = resolveTsConfigPathsToAlias;
|
|
28
28
|
const path = __importStar(require("node:path"));
|
|
29
|
-
const
|
|
29
|
+
const ts = __importStar(require("typescript"));
|
|
30
30
|
const pretty_time_1 = require("../logger/pretty-time");
|
|
31
|
+
const utils_1 = require("../typescript/utils");
|
|
31
32
|
function webpackCompilerHandlerFactory(logger, onCompilationEnd) {
|
|
32
33
|
return async (err, stats) => {
|
|
33
34
|
if (err) {
|
|
@@ -65,15 +66,22 @@ function webpackCompilerHandlerFactory(logger, onCompilationEnd) {
|
|
|
65
66
|
};
|
|
66
67
|
}
|
|
67
68
|
const endStarRe = /\/?\*$/;
|
|
68
|
-
function
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
function resolveTsConfigPathsToAlias(projectPath, filename = 'tsconfig.json') {
|
|
70
|
+
let parsed;
|
|
71
|
+
try {
|
|
72
|
+
parsed = (0, utils_1.getTsProjectConfig)(ts, projectPath, filename);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return {};
|
|
71
76
|
}
|
|
72
|
-
|
|
77
|
+
if (parsed.errors.length > 0) {
|
|
78
|
+
return {};
|
|
79
|
+
}
|
|
80
|
+
const { paths = {}, baseUrl } = parsed.options;
|
|
73
81
|
if (!baseUrl) {
|
|
74
|
-
return
|
|
82
|
+
return {};
|
|
75
83
|
}
|
|
76
|
-
const basePath = path.resolve(path.dirname(
|
|
84
|
+
const basePath = path.resolve(path.dirname(projectPath), baseUrl);
|
|
77
85
|
const aliases = {};
|
|
78
86
|
const modules = [basePath];
|
|
79
87
|
for (const [key, value] of Object.entries(paths)) {
|
|
@@ -89,14 +97,3 @@ function resolveTsconfigPathsToAlias(tsConfigPath) {
|
|
|
89
97
|
}
|
|
90
98
|
return { aliases, modules };
|
|
91
99
|
}
|
|
92
|
-
function readJsonConfig(pathname) {
|
|
93
|
-
try {
|
|
94
|
-
const json = fs.readFileSync(pathname, 'utf-8');
|
|
95
|
-
return {
|
|
96
|
-
...JSON.parse(json),
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
catch {
|
|
100
|
-
throw new Error(`Couldn't read config ${pathname}`);
|
|
101
|
-
}
|
|
102
|
-
}
|
package/package.json
CHANGED