@gravity-ui/app-builder 0.13.0 → 0.13.2
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/commands/dev/index.js +5 -3
- 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 +39 -34
- package/dist/common/webpack/utils.d.ts +5 -2
- package/dist/common/webpack/utils.js +16 -19
- package/package.json +1 -1
|
@@ -49,6 +49,10 @@ async function default_1(config) {
|
|
|
49
49
|
const startNodemon = () => {
|
|
50
50
|
if (needToStartNodemon && serverCompiled && clientCompiled) {
|
|
51
51
|
logger_1.default.message('Starting application at', serverPath);
|
|
52
|
+
const nodeArgs = ['--enable-source-maps'];
|
|
53
|
+
if (inspect || inspectBrk) {
|
|
54
|
+
nodeArgs.push(`--${inspect ? 'inspect' : 'inspect-brk'}=:::${inspect || inspectBrk}`);
|
|
55
|
+
}
|
|
52
56
|
const serverWatch = config.server.watch ?? [];
|
|
53
57
|
const delay = config.server.watchThrottle;
|
|
54
58
|
const nodemonInstance = (0, nodemon_1.default)({
|
|
@@ -58,9 +62,7 @@ async function default_1(config) {
|
|
|
58
62
|
env: {
|
|
59
63
|
...(config.server.port ? { APP_PORT: config.server.port } : undefined),
|
|
60
64
|
},
|
|
61
|
-
nodeArgs
|
|
62
|
-
? [`--${inspect ? 'inspect' : 'inspect-brk'}=:::${inspect || inspectBrk}`]
|
|
63
|
-
: undefined,
|
|
65
|
+
nodeArgs,
|
|
64
66
|
watch: [serverPath, ...serverWatch],
|
|
65
67
|
delay,
|
|
66
68
|
});
|
|
@@ -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,
|
|
@@ -174,7 +174,7 @@ function configureResolve({ isEnvProduction, config }) {
|
|
|
174
174
|
alias['react-dom$'] = 'react-dom/profiling';
|
|
175
175
|
alias['scheduler/tracing'] = 'scheduler/tracing-profiling';
|
|
176
176
|
}
|
|
177
|
-
const { aliases, modules = [] } = (0, utils_1.
|
|
177
|
+
const { aliases, modules = [] } = (0, utils_1.resolveTsConfigPathsToAlias)(paths_1.default.appClient);
|
|
178
178
|
return {
|
|
179
179
|
alias: {
|
|
180
180
|
...aliases,
|
|
@@ -308,22 +308,23 @@ function createWorkerRule(options) {
|
|
|
308
308
|
};
|
|
309
309
|
}
|
|
310
310
|
function createSassStylesRule(options) {
|
|
311
|
-
const loaders = getCssLoaders(options
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
311
|
+
const loaders = getCssLoaders(options, [
|
|
312
|
+
{
|
|
313
|
+
loader: require.resolve('resolve-url-loader'),
|
|
314
|
+
options: {
|
|
315
|
+
sourceMap: !options.config.disableSourceMapGeneration,
|
|
316
|
+
},
|
|
316
317
|
},
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
318
|
+
{
|
|
319
|
+
loader: require.resolve('sass-loader'),
|
|
320
|
+
options: {
|
|
321
|
+
sourceMap: true, // must be always true for work with resolve-url-loader
|
|
322
|
+
sassOptions: {
|
|
323
|
+
loadPaths: [paths_1.default.appClient],
|
|
324
|
+
},
|
|
324
325
|
},
|
|
325
326
|
},
|
|
326
|
-
|
|
327
|
+
]);
|
|
327
328
|
return {
|
|
328
329
|
test: /\.scss$/,
|
|
329
330
|
sideEffects: options.isEnvProduction ? true : undefined,
|
|
@@ -338,22 +339,32 @@ function createStylesRule(options) {
|
|
|
338
339
|
use: loaders,
|
|
339
340
|
};
|
|
340
341
|
}
|
|
341
|
-
function getCssLoaders({ isEnvDevelopment, isEnvProduction, config }) {
|
|
342
|
+
function getCssLoaders({ isEnvDevelopment, isEnvProduction, config }, additionalRules) {
|
|
342
343
|
const loaders = [];
|
|
343
|
-
if (
|
|
344
|
-
loaders.push(mini_css_extract_plugin_1.default.loader);
|
|
345
|
-
}
|
|
346
|
-
if (isEnvDevelopment) {
|
|
344
|
+
if (!config.transformCssWithLightningCss) {
|
|
347
345
|
loaders.push({
|
|
348
|
-
loader: require.resolve('
|
|
346
|
+
loader: require.resolve('postcss-loader'),
|
|
347
|
+
options: {
|
|
348
|
+
sourceMap: !config.disableSourceMapGeneration,
|
|
349
|
+
postcssOptions: {
|
|
350
|
+
config: false,
|
|
351
|
+
plugins: [
|
|
352
|
+
[require.resolve('postcss-preset-env'), { enableClientSidePolyfills: false }],
|
|
353
|
+
],
|
|
354
|
+
},
|
|
355
|
+
},
|
|
349
356
|
});
|
|
350
357
|
}
|
|
351
|
-
|
|
358
|
+
if (Array.isArray(additionalRules) && additionalRules.length > 0) {
|
|
359
|
+
loaders.push(...additionalRules);
|
|
360
|
+
}
|
|
361
|
+
const importLoaders = loaders.length;
|
|
362
|
+
loaders.unshift({
|
|
352
363
|
loader: require.resolve('css-loader'),
|
|
353
364
|
options: {
|
|
354
365
|
esModule: false,
|
|
355
366
|
sourceMap: !config.disableSourceMapGeneration,
|
|
356
|
-
importLoaders
|
|
367
|
+
importLoaders,
|
|
357
368
|
modules: {
|
|
358
369
|
auto: true,
|
|
359
370
|
localIdentName: '[name]__[local]--[hash:base64:5]',
|
|
@@ -361,18 +372,12 @@ function getCssLoaders({ isEnvDevelopment, isEnvProduction, config }) {
|
|
|
361
372
|
},
|
|
362
373
|
},
|
|
363
374
|
});
|
|
364
|
-
if (
|
|
365
|
-
loaders.
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
config: false,
|
|
371
|
-
plugins: [
|
|
372
|
-
[require.resolve('postcss-preset-env'), { enableClientSidePolyfills: false }],
|
|
373
|
-
],
|
|
374
|
-
},
|
|
375
|
-
},
|
|
375
|
+
if (isEnvProduction) {
|
|
376
|
+
loaders.unshift(mini_css_extract_plugin_1.default.loader);
|
|
377
|
+
}
|
|
378
|
+
if (isEnvDevelopment) {
|
|
379
|
+
loaders.unshift({
|
|
380
|
+
loader: require.resolve('style-loader'),
|
|
376
381
|
});
|
|
377
382
|
}
|
|
378
383
|
return loaders;
|
|
@@ -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.Stats) => 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) {
|
|
@@ -60,15 +61,22 @@ function webpackCompilerHandlerFactory(logger, onCompilationEnd) {
|
|
|
60
61
|
};
|
|
61
62
|
}
|
|
62
63
|
const endStarRe = /\/?\*$/;
|
|
63
|
-
function
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
function resolveTsConfigPathsToAlias(projectPath, filename = 'tsconfig.json') {
|
|
65
|
+
let parsed;
|
|
66
|
+
try {
|
|
67
|
+
parsed = (0, utils_1.getTsProjectConfig)(ts, projectPath, filename);
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return {};
|
|
66
71
|
}
|
|
67
|
-
|
|
72
|
+
if (parsed.errors.length > 0) {
|
|
73
|
+
return {};
|
|
74
|
+
}
|
|
75
|
+
const { paths = {}, baseUrl } = parsed.options;
|
|
68
76
|
if (!baseUrl) {
|
|
69
|
-
return
|
|
77
|
+
return {};
|
|
70
78
|
}
|
|
71
|
-
const basePath = path.resolve(path.dirname(
|
|
79
|
+
const basePath = path.resolve(path.dirname(projectPath), baseUrl);
|
|
72
80
|
const aliases = {};
|
|
73
81
|
const modules = [basePath];
|
|
74
82
|
for (const [key, value] of Object.entries(paths)) {
|
|
@@ -84,14 +92,3 @@ function resolveTsconfigPathsToAlias(tsConfigPath) {
|
|
|
84
92
|
}
|
|
85
93
|
return { aliases, modules };
|
|
86
94
|
}
|
|
87
|
-
function readJsonConfig(pathname) {
|
|
88
|
-
try {
|
|
89
|
-
const json = fs.readFileSync(pathname, 'utf-8');
|
|
90
|
-
return {
|
|
91
|
-
...JSON.parse(json),
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
catch {
|
|
95
|
-
throw new Error(`Couldn't read config ${pathname}`);
|
|
96
|
-
}
|
|
97
|
-
}
|