@gravity-ui/app-builder 0.28.1-beta.6 → 0.28.1-beta.8
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/README.md +2 -0
- package/dist/commands/build/build-service/server.js +33 -16
- package/dist/commands/dev/server.js +48 -26
- package/dist/common/config.js +1 -0
- package/dist/common/models/index.d.ts +8 -1
- package/dist/common/swc/compile.d.ts +9 -0
- package/dist/common/swc/compile.js +63 -0
- package/dist/common/swc/index.d.ts +2 -0
- package/dist/common/swc/index.js +7 -0
- package/dist/common/swc/watch.d.ts +9 -0
- package/dist/common/swc/watch.js +60 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -143,6 +143,8 @@ All server settings are used only in dev mode:
|
|
|
143
143
|
- `watchThrottle` (`number`) — use to add an extra throttle, or delay restarting.
|
|
144
144
|
- `inspect/inspectBrk` (`number | true`) — listen for a debugging client on specified port.
|
|
145
145
|
If specified `true`, try to listen on `9229`.
|
|
146
|
+
- `compiler` (`'typescript' | 'swc'`) — choose TypeScript compiler for server code compilation.
|
|
147
|
+
Default is `'typescript'`. Set to `'swc'` for faster compilation with SWC.
|
|
146
148
|
|
|
147
149
|
### Client
|
|
148
150
|
|
|
@@ -8,25 +8,42 @@ const signal_exit_1 = require("signal-exit");
|
|
|
8
8
|
const controllable_script_1 = require("../../../common/child-process/controllable-script");
|
|
9
9
|
const paths_1 = __importDefault(require("../../../common/paths"));
|
|
10
10
|
const utils_1 = require("../../../common/utils");
|
|
11
|
+
function createSWCBuildScript(config) {
|
|
12
|
+
return `
|
|
13
|
+
const {Logger} = require(${JSON.stringify(require.resolve('../../../common/logger'))});
|
|
14
|
+
const {compile} = require(${JSON.stringify(require.resolve('../../../common/swc/compile'))});
|
|
15
|
+
|
|
16
|
+
const logger = new Logger('server', ${config.verbose});
|
|
17
|
+
compile({
|
|
18
|
+
logger,
|
|
19
|
+
outputPath: ${JSON.stringify(paths_1.default.appDist)},
|
|
20
|
+
projectPath: ${JSON.stringify(paths_1.default.appServer)},
|
|
21
|
+
});`;
|
|
22
|
+
}
|
|
23
|
+
function createTypescriptBuildScript(config) {
|
|
24
|
+
return `
|
|
25
|
+
let ts;
|
|
26
|
+
try {
|
|
27
|
+
ts = require('typescript');
|
|
28
|
+
} catch (e) {
|
|
29
|
+
if (e.code !== 'MODULE_NOT_FOUND') {
|
|
30
|
+
throw e;
|
|
31
|
+
}
|
|
32
|
+
ts = require(${JSON.stringify(require.resolve('typescript'))});
|
|
33
|
+
}
|
|
34
|
+
const {Logger} = require(${JSON.stringify(require.resolve('../../../common/logger'))});
|
|
35
|
+
const {compile} = require(${JSON.stringify(require.resolve('../../../common/typescript/compile'))});
|
|
36
|
+
|
|
37
|
+
const logger = new Logger('server', ${config.verbose});
|
|
38
|
+
compile(ts, {logger, projectPath: ${JSON.stringify(paths_1.default.appServer)}});`;
|
|
39
|
+
}
|
|
11
40
|
function buildServer(config) {
|
|
12
41
|
(0, utils_1.createRunFolder)();
|
|
42
|
+
// Используем TypeScript для компиляции (по умолчанию)
|
|
13
43
|
return new Promise((resolve, reject) => {
|
|
14
|
-
const build = new controllable_script_1.ControllableScript(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
ts = require('typescript');
|
|
18
|
-
} catch (e) {
|
|
19
|
-
if (e.code !== 'MODULE_NOT_FOUND') {
|
|
20
|
-
throw e;
|
|
21
|
-
}
|
|
22
|
-
ts = require(${JSON.stringify(require.resolve('typescript'))});
|
|
23
|
-
}
|
|
24
|
-
const {Logger} = require(${JSON.stringify(require.resolve('../../../common/logger'))});
|
|
25
|
-
const {compile} = require(${JSON.stringify(require.resolve('../../../common/typescript/compile'))});
|
|
26
|
-
|
|
27
|
-
const logger = new Logger('server', ${config.verbose});
|
|
28
|
-
compile(ts, {logger, projectPath: ${JSON.stringify(paths_1.default.appServer)}});
|
|
29
|
-
`, null);
|
|
44
|
+
const build = new controllable_script_1.ControllableScript(config.server.compiler === 'swc'
|
|
45
|
+
? createSWCBuildScript(config)
|
|
46
|
+
: createTypescriptBuildScript(config), null);
|
|
30
47
|
build.start().then(() => {
|
|
31
48
|
build.onExit((code) => {
|
|
32
49
|
if (code) {
|
|
@@ -32,36 +32,58 @@ const rimraf_1 = require("rimraf");
|
|
|
32
32
|
const controllable_script_1 = require("../../common/child-process/controllable-script");
|
|
33
33
|
const utils_1 = require("../../common/utils");
|
|
34
34
|
const paths_1 = __importDefault(require("../../common/paths"));
|
|
35
|
+
function createTypescriptBuildScript(config) {
|
|
36
|
+
return `
|
|
37
|
+
let ts;
|
|
38
|
+
try {
|
|
39
|
+
ts = require('typescript');
|
|
40
|
+
} catch (e) {
|
|
41
|
+
if (e.code !== 'MODULE_NOT_FOUND') {
|
|
42
|
+
throw e;
|
|
43
|
+
}
|
|
44
|
+
ts = require(${JSON.stringify(require.resolve('typescript'))});
|
|
45
|
+
}
|
|
46
|
+
const {Logger} = require(${JSON.stringify(require.resolve('../../common/logger'))});
|
|
47
|
+
const {watch} = require(${JSON.stringify(require.resolve('../../common/typescript/watch'))});
|
|
48
|
+
|
|
49
|
+
const logger = new Logger('server', ${config.verbose});
|
|
50
|
+
watch(
|
|
51
|
+
ts,
|
|
52
|
+
${JSON.stringify(paths_1.default.appServer)},
|
|
53
|
+
{
|
|
54
|
+
logger,
|
|
55
|
+
onAfterFilesEmitted: () => {
|
|
56
|
+
process.send({type: 'Emitted'});
|
|
57
|
+
},
|
|
58
|
+
enableSourceMap: true
|
|
59
|
+
}
|
|
60
|
+
);`;
|
|
61
|
+
}
|
|
62
|
+
function createSWCBuildScript(config) {
|
|
63
|
+
return `
|
|
64
|
+
const {Logger} = require(${JSON.stringify(require.resolve('../../common/logger'))});
|
|
65
|
+
const {watch} = require(${JSON.stringify(require.resolve('../../common/swc/watch'))});
|
|
66
|
+
|
|
67
|
+
const logger = new Logger('server', ${config.verbose});
|
|
68
|
+
watch(
|
|
69
|
+
${JSON.stringify(paths_1.default.appServer)},
|
|
70
|
+
{
|
|
71
|
+
outputPath: ${JSON.stringify(paths_1.default.appDist)},
|
|
72
|
+
logger,
|
|
73
|
+
onAfterFilesEmitted: () => {
|
|
74
|
+
process.send({type: 'Emitted'});
|
|
75
|
+
},
|
|
76
|
+
enableSourceMap: true
|
|
77
|
+
}
|
|
78
|
+
);`;
|
|
79
|
+
}
|
|
35
80
|
async function watchServerCompilation(config) {
|
|
36
81
|
const serverPath = path.resolve(paths_1.default.appDist, 'server');
|
|
37
82
|
rimraf_1.rimraf.sync(serverPath);
|
|
38
83
|
(0, utils_1.createRunFolder)();
|
|
39
|
-
const build = new controllable_script_1.ControllableScript(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
ts = require('typescript');
|
|
43
|
-
} catch (e) {
|
|
44
|
-
if (e.code !== 'MODULE_NOT_FOUND') {
|
|
45
|
-
throw e;
|
|
46
|
-
}
|
|
47
|
-
ts = require(${JSON.stringify(require.resolve('typescript'))});
|
|
48
|
-
}
|
|
49
|
-
const {Logger} = require(${JSON.stringify(require.resolve('../../common/logger'))});
|
|
50
|
-
const {watch} = require(${JSON.stringify(require.resolve('../../common/typescript/watch'))});
|
|
51
|
-
|
|
52
|
-
const logger = new Logger('server', ${config.verbose});
|
|
53
|
-
watch(
|
|
54
|
-
ts,
|
|
55
|
-
${JSON.stringify(paths_1.default.appServer)},
|
|
56
|
-
{
|
|
57
|
-
logger,
|
|
58
|
-
onAfterFilesEmitted: () => {
|
|
59
|
-
process.send({type: 'Emitted'});
|
|
60
|
-
},
|
|
61
|
-
enableSourceMap: true
|
|
62
|
-
}
|
|
63
|
-
);
|
|
64
|
-
`, null);
|
|
84
|
+
const build = new controllable_script_1.ControllableScript(config.server.compiler === 'swc'
|
|
85
|
+
? createSWCBuildScript(config)
|
|
86
|
+
: createTypescriptBuildScript(config), null);
|
|
65
87
|
await build.start();
|
|
66
88
|
return build;
|
|
67
89
|
}
|
package/dist/common/config.js
CHANGED
|
@@ -18,6 +18,7 @@ import type { TerserOptions } from 'terser-webpack-plugin';
|
|
|
18
18
|
import type { ReactRefreshPluginOptions } from '@pmmmwh/react-refresh-webpack-plugin/types/lib/types';
|
|
19
19
|
type Bundler = 'webpack' | 'rspack';
|
|
20
20
|
type JavaScriptLoader = 'babel' | 'swc';
|
|
21
|
+
type ServerCompiler = 'typescript' | 'swc';
|
|
21
22
|
export type SwcConfig = Swc.Config & Pick<Swc.Options, 'isModule'>;
|
|
22
23
|
export interface Entities<T> {
|
|
23
24
|
data: Record<string, T>;
|
|
@@ -266,6 +267,11 @@ export interface ServerConfig {
|
|
|
266
267
|
watchThrottle?: number;
|
|
267
268
|
inspect?: number | true;
|
|
268
269
|
inspectBrk?: number | true;
|
|
270
|
+
/**
|
|
271
|
+
* Compiler for server code compilation
|
|
272
|
+
* @default 'typescript'
|
|
273
|
+
*/
|
|
274
|
+
compiler?: ServerCompiler;
|
|
269
275
|
}
|
|
270
276
|
export interface ServiceConfig {
|
|
271
277
|
target?: 'client' | 'server';
|
|
@@ -306,11 +312,12 @@ export type NormalizedClientConfig = Omit<ClientConfig, 'publicPathPrefix' | 'pu
|
|
|
306
312
|
}) => SwcConfig | Promise<SwcConfig>;
|
|
307
313
|
reactRefresh: NonNullable<ClientConfig['reactRefresh']>;
|
|
308
314
|
};
|
|
309
|
-
export type NormalizedServerConfig = Omit<ServerConfig, 'port' | 'inspect' | 'inspectBrk'> & {
|
|
315
|
+
export type NormalizedServerConfig = Omit<ServerConfig, 'port' | 'inspect' | 'inspectBrk' | 'compiler'> & {
|
|
310
316
|
port?: number;
|
|
311
317
|
verbose?: boolean;
|
|
312
318
|
inspect?: number;
|
|
313
319
|
inspectBrk?: number;
|
|
320
|
+
compiler: ServerCompiler;
|
|
314
321
|
};
|
|
315
322
|
export type NormalizedServiceConfig = Omit<ServiceConfig, 'client' | 'server'> & {
|
|
316
323
|
client: NormalizedClientConfig;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Logger } from '../logger';
|
|
2
|
+
interface SwcCompileOptions {
|
|
3
|
+
projectPath: string;
|
|
4
|
+
outputPath: string;
|
|
5
|
+
logger: Logger;
|
|
6
|
+
enableSourceMap?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare function compile({ projectPath, outputPath, logger, enableSourceMap, }: SwcCompileOptions): Promise<void>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.compile = compile;
|
|
4
|
+
const pretty_time_1 = require("../logger/pretty-time");
|
|
5
|
+
// @ts-ignore @swc/cli is not typed
|
|
6
|
+
const cli_1 = require("@swc/cli");
|
|
7
|
+
const getSwcConfig = (enableSourceMap = false) => {
|
|
8
|
+
return {
|
|
9
|
+
module: {
|
|
10
|
+
type: 'commonjs',
|
|
11
|
+
},
|
|
12
|
+
jsc: {
|
|
13
|
+
target: 'es2020',
|
|
14
|
+
parser: {
|
|
15
|
+
syntax: 'typescript',
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
sourceMaps: enableSourceMap,
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
async function compile({ projectPath, outputPath, logger, enableSourceMap = false, }) {
|
|
22
|
+
const start = process.hrtime.bigint();
|
|
23
|
+
logger.message('Start compilation');
|
|
24
|
+
const swcConfig = getSwcConfig(enableSourceMap);
|
|
25
|
+
const cliOptions = {
|
|
26
|
+
filenames: [projectPath],
|
|
27
|
+
outDir: outputPath,
|
|
28
|
+
watch: false,
|
|
29
|
+
sourceMaps: enableSourceMap,
|
|
30
|
+
extensions: ['.js', '.ts', '.mjs', '.cjs'],
|
|
31
|
+
stripLeadingPaths: true,
|
|
32
|
+
sync: false,
|
|
33
|
+
};
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
const callbacks = {
|
|
36
|
+
onSuccess: (_result) => {
|
|
37
|
+
logger.success(`Compiled successfully in ${(0, pretty_time_1.elapsedTime)(start)}`);
|
|
38
|
+
resolve();
|
|
39
|
+
},
|
|
40
|
+
onFail: (result) => {
|
|
41
|
+
logger.error(`Compilation failed in ${result.duration}ms`);
|
|
42
|
+
if (result.reasons) {
|
|
43
|
+
for (const [filename, error] of result.reasons) {
|
|
44
|
+
logger.error(`${filename}: ${error}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
logger.error(`Error compile, elapsed time ${(0, pretty_time_1.elapsedTime)(start)}`);
|
|
48
|
+
reject(new Error('Compilation failed'));
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
try {
|
|
52
|
+
(0, cli_1.swcDir)({
|
|
53
|
+
cliOptions,
|
|
54
|
+
swcOptions: swcConfig,
|
|
55
|
+
callbacks,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
logger.error(`Failed to start compilation: ${error}`);
|
|
60
|
+
reject(error);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.watch = exports.compile = void 0;
|
|
4
|
+
var compile_1 = require("./compile");
|
|
5
|
+
Object.defineProperty(exports, "compile", { enumerable: true, get: function () { return compile_1.compile; } });
|
|
6
|
+
var watch_1 = require("./watch");
|
|
7
|
+
Object.defineProperty(exports, "watch", { enumerable: true, get: function () { return watch_1.watch; } });
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Logger } from '../logger';
|
|
2
|
+
interface SwcWatchOptions {
|
|
3
|
+
outputPath: string;
|
|
4
|
+
logger: Logger;
|
|
5
|
+
onAfterFilesEmitted?: () => void;
|
|
6
|
+
enableSourceMap?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare function watch(projectPath: string, { outputPath, logger, onAfterFilesEmitted, enableSourceMap }: SwcWatchOptions): Promise<void>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.watch = watch;
|
|
4
|
+
// @ts-ignore @swc/cli is not typed
|
|
5
|
+
const cli_1 = require("@swc/cli");
|
|
6
|
+
const getSwcConfig = (enableSourceMap = false) => {
|
|
7
|
+
return {
|
|
8
|
+
module: {
|
|
9
|
+
type: 'commonjs',
|
|
10
|
+
},
|
|
11
|
+
jsc: {
|
|
12
|
+
target: 'es2020',
|
|
13
|
+
parser: {
|
|
14
|
+
syntax: 'typescript',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
sourceMaps: enableSourceMap,
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
async function watch(projectPath, { outputPath, logger, onAfterFilesEmitted, enableSourceMap = false }) {
|
|
21
|
+
logger.message('Start compilation in watch mode');
|
|
22
|
+
const swcConfig = getSwcConfig(enableSourceMap);
|
|
23
|
+
const cliOptions = {
|
|
24
|
+
filenames: [projectPath],
|
|
25
|
+
outDir: outputPath,
|
|
26
|
+
watch: true,
|
|
27
|
+
sourceMaps: enableSourceMap,
|
|
28
|
+
extensions: ['.js', '.ts', '.mjs', '.cjs'],
|
|
29
|
+
stripLeadingPaths: true,
|
|
30
|
+
sync: false,
|
|
31
|
+
logWatchCompilation: true,
|
|
32
|
+
};
|
|
33
|
+
const callbacks = {
|
|
34
|
+
onSuccess: (result) => {
|
|
35
|
+
if (result.filename) {
|
|
36
|
+
logger.message(`Successfully compiled ${result.filename} in ${result.duration}ms`);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
logger.message(`Successfully compiled ${result.compiled || 0} files in ${result.duration}ms`);
|
|
40
|
+
}
|
|
41
|
+
onAfterFilesEmitted?.();
|
|
42
|
+
},
|
|
43
|
+
onFail: (result) => {
|
|
44
|
+
logger.error(`Compilation failed in ${result.duration}ms`);
|
|
45
|
+
if (result.reasons) {
|
|
46
|
+
for (const [filename, error] of result.reasons) {
|
|
47
|
+
logger.error(`${filename}: ${error}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
onWatchReady: () => {
|
|
52
|
+
logger.message('Watching for file changes');
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
(0, cli_1.swcDir)({
|
|
56
|
+
cliOptions,
|
|
57
|
+
swcOptions: swcConfig,
|
|
58
|
+
callbacks,
|
|
59
|
+
});
|
|
60
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravity-ui/app-builder",
|
|
3
|
-
"version": "0.28.1-beta.
|
|
3
|
+
"version": "0.28.1-beta.8",
|
|
4
4
|
"description": "Develop and build your React client-server projects, powered by typescript and webpack",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -75,13 +75,14 @@
|
|
|
75
75
|
"@rspack/core": "1.3.9",
|
|
76
76
|
"@rspack/dev-server": "^1.1.1",
|
|
77
77
|
"@rspack/plugin-react-refresh": "^1.4.1",
|
|
78
|
-
"@statoscope/webpack-plugin": "^5.29.0",
|
|
79
78
|
"@statoscope/stats": "^5.28.1",
|
|
80
79
|
"@statoscope/stats-extension-compressed": "^5.28.1",
|
|
81
80
|
"@statoscope/webpack-model": "^5.29.0",
|
|
81
|
+
"@statoscope/webpack-plugin": "^5.29.0",
|
|
82
82
|
"@svgr/core": "^8.1.0",
|
|
83
83
|
"@svgr/plugin-jsx": "^8.1.0",
|
|
84
84
|
"@svgr/webpack": "^8.1.0",
|
|
85
|
+
"@swc/cli": "^0.7.8",
|
|
85
86
|
"@swc/core": "1.11.24",
|
|
86
87
|
"@swc/plugin-transform-imports": "7.0.3",
|
|
87
88
|
"babel-loader": "^9.2.1",
|