@rife/cli 0.0.6-beta.1 → 0.0.6-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/pnpmfile.js +11 -2
- package/dist/sync.js +1 -0
- package/dist/sync.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +11 -15
- package/src/cli.ts +19 -19
- package/src/index.ts +3 -3
- package/src/logger.ts +34 -34
- package/src/plugin/commander.ts +44 -44
- package/src/plugin/compiler/swc.ts +55 -55
- package/src/plugin/compiler/tsc.ts +101 -101
- package/src/plugin/release.ts +32 -32
- package/src/pnpmfile.ts +147 -121
- package/src/runner.ts +88 -88
- package/src/sync.ts +63 -62
- package/src/test/pnpmfile.test.ts +223 -223
- package/dist/compiler.js +0 -82
- package/dist/compiler.js.map +0 -1
- package/dist/plugin/package copy.js +0 -32
- package/dist/plugin/package copy.js.map +0 -1
- package/dist/plugin.js +0 -161
- package/dist/plugin.js.map +0 -1
- package/dist/swc.js +0 -78
- package/dist/swc.js.map +0 -1
- package/dist/tsc.js +0 -94
- package/dist/tsc.js.map +0 -1
package/dist/plugin.js
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.pluginPackage = pluginPackage;
|
|
4
|
-
exports.pluginConfig = pluginConfig;
|
|
5
|
-
exports.pluginCommander = pluginCommander;
|
|
6
|
-
exports.pluginCompiler = pluginCompiler;
|
|
7
|
-
const tslib_1 = require("tslib");
|
|
8
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
9
|
-
const compiler_1 = require("./compiler");
|
|
10
|
-
function pluginPackage() {
|
|
11
|
-
const plugin = {
|
|
12
|
-
name: pluginPackage.name,
|
|
13
|
-
apply: runner => {
|
|
14
|
-
const { logger, hook, fs } = runner;
|
|
15
|
-
const log = logger.withTag(pluginPackage.name);
|
|
16
|
-
hook.loadPackage.tapPromise(pluginPackage.name, async () => {
|
|
17
|
-
const fileName = 'package.json';
|
|
18
|
-
const filePath = path_1.default.resolve(fileName);
|
|
19
|
-
if (!fs.existsSync(filePath)) {
|
|
20
|
-
log.error(`找不到文件 ${fileName}`);
|
|
21
|
-
process.exit(1);
|
|
22
|
-
}
|
|
23
|
-
try {
|
|
24
|
-
const data = require(filePath);
|
|
25
|
-
runner.package = data;
|
|
26
|
-
}
|
|
27
|
-
catch (e) {
|
|
28
|
-
log.error(`读取文件失败`, e.message);
|
|
29
|
-
process.exit(1);
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
return plugin;
|
|
35
|
-
}
|
|
36
|
-
function pluginConfig() {
|
|
37
|
-
const plugin = {
|
|
38
|
-
name: pluginConfig.name,
|
|
39
|
-
apply: runner => {
|
|
40
|
-
const { logger, hook, config, fs, z } = runner;
|
|
41
|
-
const log = logger.withTag(pluginConfig.name);
|
|
42
|
-
hook.loadConfig.tapPromise(pluginConfig.name, async () => {
|
|
43
|
-
const fileName = '.app.mjs';
|
|
44
|
-
const filePath = path_1.default.posix.resolve(fileName);
|
|
45
|
-
log.debug(`filePath %s`, filePath);
|
|
46
|
-
if (!fs.existsSync(filePath)) {
|
|
47
|
-
log.error(`找不到配置文件 ${fileName}`);
|
|
48
|
-
process.exit(1);
|
|
49
|
-
}
|
|
50
|
-
const all = (await import(filePath)).default;
|
|
51
|
-
runner.config.all = all;
|
|
52
|
-
});
|
|
53
|
-
hook.validateConfig.tapPromise(pluginConfig.name, async () => {
|
|
54
|
-
const validation = z
|
|
55
|
-
.array(z.object({
|
|
56
|
-
name: z.string().trim().min(1),
|
|
57
|
-
}))
|
|
58
|
-
.min(1)
|
|
59
|
-
.safeParse(config.all);
|
|
60
|
-
if (!validation.success) {
|
|
61
|
-
log.error(validation.error.message);
|
|
62
|
-
process.exit(1);
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
hook.applyConfig.tapPromise(pluginConfig.name, async (options) => {
|
|
66
|
-
const result = z
|
|
67
|
-
.object({
|
|
68
|
-
name: z.string().trim().optional(),
|
|
69
|
-
})
|
|
70
|
-
.safeParse(options);
|
|
71
|
-
const name = result.data?.name;
|
|
72
|
-
if (!name) {
|
|
73
|
-
config.current = config.all[0];
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
const find = config.all.find(t => t.name === name);
|
|
77
|
-
if (!find) {
|
|
78
|
-
log.error(`未找到 name '%s'`, name);
|
|
79
|
-
process.exit(1);
|
|
80
|
-
}
|
|
81
|
-
config.current = find;
|
|
82
|
-
}
|
|
83
|
-
config.current.plugins.forEach(plugin => plugin.apply(runner));
|
|
84
|
-
});
|
|
85
|
-
},
|
|
86
|
-
};
|
|
87
|
-
return plugin;
|
|
88
|
-
}
|
|
89
|
-
function pluginCommander() {
|
|
90
|
-
const plugin = {
|
|
91
|
-
name: pluginCommander.name,
|
|
92
|
-
apply: runner => {
|
|
93
|
-
const { hook, config, z } = runner;
|
|
94
|
-
hook.runCommand.tapPromise(pluginCommander.name, async () => {
|
|
95
|
-
const { Command } = require('commander');
|
|
96
|
-
const program = new Command();
|
|
97
|
-
program
|
|
98
|
-
.command('dev')
|
|
99
|
-
.option('-n, --name <string>', '', '')
|
|
100
|
-
.description('启动开发')
|
|
101
|
-
.action(async (options) => {
|
|
102
|
-
await hook.applyConfig.promise(options);
|
|
103
|
-
await hook.dev.promise();
|
|
104
|
-
});
|
|
105
|
-
program
|
|
106
|
-
.command('build')
|
|
107
|
-
.option('-n, --name <string>', '', '')
|
|
108
|
-
.description('构建项目')
|
|
109
|
-
.action(async (options) => {
|
|
110
|
-
await hook.applyConfig.promise(options);
|
|
111
|
-
await hook.build.promise();
|
|
112
|
-
});
|
|
113
|
-
program.parseAsync(process.argv);
|
|
114
|
-
});
|
|
115
|
-
},
|
|
116
|
-
};
|
|
117
|
-
return plugin;
|
|
118
|
-
}
|
|
119
|
-
function pluginCompiler(options) {
|
|
120
|
-
const plugin = {
|
|
121
|
-
name: pluginCompiler.name,
|
|
122
|
-
apply: runner => {
|
|
123
|
-
const { hook, logger, z, tapable } = runner;
|
|
124
|
-
const log = logger.withTag(pluginCompiler.name);
|
|
125
|
-
const validation = z
|
|
126
|
-
.object({
|
|
127
|
-
tsx: z
|
|
128
|
-
.object({
|
|
129
|
-
type: z.enum(['tsc', 'swc']).default('swc'),
|
|
130
|
-
rootDir: z.string().trim().min(1).default('.'),
|
|
131
|
-
outDir: z.string().trim().min(1).default('./dist/'),
|
|
132
|
-
clean: z.boolean().default(true),
|
|
133
|
-
options: z.object({}).passthrough().optional(),
|
|
134
|
-
})
|
|
135
|
-
.default({}),
|
|
136
|
-
})
|
|
137
|
-
.optional()
|
|
138
|
-
.default({})
|
|
139
|
-
.safeParse(options);
|
|
140
|
-
if (!validation.success) {
|
|
141
|
-
log.error('配置错误\n', validation.error.message);
|
|
142
|
-
process.exit(1);
|
|
143
|
-
}
|
|
144
|
-
runner.compiler = {
|
|
145
|
-
hook: {
|
|
146
|
-
tsxSuccess: new tapable.AsyncSeriesHook(),
|
|
147
|
-
},
|
|
148
|
-
};
|
|
149
|
-
hook.dev.tapPromise(pluginCompiler.name, async () => {
|
|
150
|
-
const tsxConfig = validation.data.tsx;
|
|
151
|
-
(0, compiler_1.compileTs)(runner, tsxConfig, { watch: true });
|
|
152
|
-
});
|
|
153
|
-
hook.build.tapPromise(pluginCompiler.name, async () => {
|
|
154
|
-
const tsxConfig = validation.data.tsx;
|
|
155
|
-
(0, compiler_1.compileTs)(runner, tsxConfig, { watch: false });
|
|
156
|
-
});
|
|
157
|
-
},
|
|
158
|
-
};
|
|
159
|
-
return plugin;
|
|
160
|
-
}
|
|
161
|
-
//# sourceMappingURL=plugin.js.map
|
package/dist/plugin.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":";;AAOA,sCAwBC;AAED,oCA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AAC;YAEF,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,cAAc,CAAC,IAAI,EAAE,KAAK,IAAI,EAAE;gBAChD,MAAM,SAAS,GAAc,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC;gBACjD,IAAA,oBAAS,EAAC,MAAM,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;YAClD,CAAC,CAAC,CAAC;YAEH,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,cAAc,CAAC,IAAI,EAAE,KAAK,IAAI,EAAE;gBAClD,MAAM,SAAS,GAAc,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC;gBACjD,IAAA,oBAAS,EAAC,MAAM,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;YACnD,CAAC,CAAC,CAAC;QACP,CAAC;KACJ,CAAC;IACF,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
package/dist/swc.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.swc = swc;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
6
|
-
async function swc(options) {
|
|
7
|
-
const { watch = false, outDir } = options;
|
|
8
|
-
const { swcDir } = require('@swc/cli');
|
|
9
|
-
const swcOptions = {
|
|
10
|
-
jsc: {
|
|
11
|
-
target: 'esnext',
|
|
12
|
-
externalHelpers: true,
|
|
13
|
-
},
|
|
14
|
-
module: {
|
|
15
|
-
type: 'commonjs',
|
|
16
|
-
},
|
|
17
|
-
sourceMaps: true,
|
|
18
|
-
};
|
|
19
|
-
const { tsTypeCheck } = createTsTypeChecker();
|
|
20
|
-
let first = true;
|
|
21
|
-
await swcDir({
|
|
22
|
-
cliOptions: {
|
|
23
|
-
outDir,
|
|
24
|
-
watch,
|
|
25
|
-
filenames: ['./src'],
|
|
26
|
-
extensions: ['.ts', '.tsx'],
|
|
27
|
-
stripLeadingPaths: true,
|
|
28
|
-
},
|
|
29
|
-
swcOptions,
|
|
30
|
-
callbacks: {
|
|
31
|
-
onSuccess: ({ duration }) => {
|
|
32
|
-
options?.onComplieSuccess?.({ watch, first, duration });
|
|
33
|
-
options?.onTypeCheckFinish?.(tsTypeCheck());
|
|
34
|
-
first = false;
|
|
35
|
-
},
|
|
36
|
-
onFail: (e) => {
|
|
37
|
-
options?.onComplieFail?.({ ...e, watch, first });
|
|
38
|
-
if (watch) {
|
|
39
|
-
// 不退出,下次修复报错后清空屏幕
|
|
40
|
-
first = false;
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
process.exit(1);
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
onWatchReady: () => { },
|
|
47
|
-
},
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
function createTsTypeChecker() {
|
|
51
|
-
// perf.start(createTsTypeChecker);
|
|
52
|
-
const ts = require('typescript');
|
|
53
|
-
const tsConfigPath = path_1.default.resolve('tsconfig.json');
|
|
54
|
-
// 解析 tsconfig.json 文件
|
|
55
|
-
const configFile = ts.readConfigFile(tsConfigPath, ts.sys.readFile);
|
|
56
|
-
if (configFile.error) {
|
|
57
|
-
const message = ts.flattenDiagnosticMessageText(configFile.error.messageText, '\n');
|
|
58
|
-
console.error(`Error reading tsconfig: ${message}`);
|
|
59
|
-
process.exit(1);
|
|
60
|
-
}
|
|
61
|
-
// 解析编译选项和文件列表
|
|
62
|
-
const parsedCommandLine = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path_1.default.dirname(tsConfigPath));
|
|
63
|
-
const tsTypeCheck = () => {
|
|
64
|
-
const perfStart = performance.now();
|
|
65
|
-
// 创建 Program
|
|
66
|
-
const program = ts.createProgram({
|
|
67
|
-
rootNames: parsedCommandLine.fileNames,
|
|
68
|
-
options: { ...parsedCommandLine.options, tsBuildInfoFile: './dist/.tsbuildinfo' },
|
|
69
|
-
});
|
|
70
|
-
// 获取所有诊断信息
|
|
71
|
-
const diagnostics = ts.getPreEmitDiagnostics(program);
|
|
72
|
-
const duration = performance.now() - perfStart;
|
|
73
|
-
return { diagnostics, duration };
|
|
74
|
-
};
|
|
75
|
-
// perf.end(createTsTypeChecker);
|
|
76
|
-
return { tsTypeCheck };
|
|
77
|
-
}
|
|
78
|
-
//# sourceMappingURL=swc.js.map
|
package/dist/swc.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"swc.js","sourceRoot":"","sources":["../src/swc.ts"],"names":[],"mappings":";;AAcA,kBA8CC;;AA5DD,wDAAwB;AAcjB,KAAK,UAAU,GAAG,CAAC,OAAkB;IACxC,MAAM,EAAE,KAAK,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC1C,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAEvC,MAAM,UAAU,GAAG;QACf,GAAG,EAAE;YACD,MAAM,EAAE,QAAQ;YAChB,eAAe,EAAE,IAAI;SACxB;QACD,MAAM,EAAE;YACJ,IAAI,EAAE,UAAU;SACnB;QACD,UAAU,EAAE,IAAI;KACnB,CAAC;IAEF,MAAM,EAAE,WAAW,EAAE,GAAG,mBAAmB,EAAE,CAAC;IAE9C,IAAI,KAAK,GAAG,IAAI,CAAC;IAEjB,MAAM,MAAM,CAAC;QACT,UAAU,EAAE;YACR,MAAM;YACN,KAAK;YACL,SAAS,EAAE,CAAC,OAAO,CAAC;YACpB,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC;YAC3B,iBAAiB,EAAE,IAAI;SAC1B;QACD,UAAU;QACV,SAAS,EAAE;YACP,SAAS,EAAE,CAAC,EAAE,QAAQ,EAAO,EAAE,EAAE;gBAC7B,OAAO,EAAE,gBAAgB,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;gBACxD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AE;QACrB,MAAM,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;QAEpC,aAAa;QACb,MAAM,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC;YAC7B,SAAS,EAAE,iBAAiB,CAAC,SAAS;YACtC,OAAO,EAAE,EAAE,GAAG,iBAAiB,CAAC,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE;SACpF,CAAC,CAAC;QAEH,WAAW;QACX,MAAM,WAAW,GAAG,EAAE,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC;QAEtD,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;QAE/C,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;IACrC,CAAC,CAAC;IAEF,iCAAiC;IAEjC,OAAO,EAAE,WAAW,EAAE,CAAC;AAC3B,CAAC"}
|
package/dist/tsc.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.tsc = tsc;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
6
|
-
function tsc(config) {
|
|
7
|
-
const logger = console;
|
|
8
|
-
const ts = require('typescript');
|
|
9
|
-
// https://github.com/microsoft/TypeScript/wiki/Using-the-Compiler-API#writing-an-incremental-program-watcher
|
|
10
|
-
const rootDir = config.rootDir || '.';
|
|
11
|
-
const formatHost = {
|
|
12
|
-
getCanonicalFileName: path => path,
|
|
13
|
-
getCurrentDirectory: ts.sys.getCurrentDirectory,
|
|
14
|
-
getNewLine: () => ts.sys.newLine,
|
|
15
|
-
};
|
|
16
|
-
function reportDiagnostic(diagnostic) {
|
|
17
|
-
const file = diagnostic.file;
|
|
18
|
-
const start = diagnostic.start;
|
|
19
|
-
if (!file || !start)
|
|
20
|
-
return;
|
|
21
|
-
const { line, character } = file.getLineAndCharacterOfPosition(start);
|
|
22
|
-
logger.error(`${file.fileName}(${line + 1},${character + 1}) ${diagnostic.messageText}`);
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Prints a diagnostic every time the watch status changes.
|
|
26
|
-
* This is mainly for messages like "Starting compilation" or "Compilation completed".
|
|
27
|
-
*/
|
|
28
|
-
let a;
|
|
29
|
-
function reportWatchStatusChanged(diagnostic) {
|
|
30
|
-
logger.info(`${ts.formatDiagnostic(diagnostic, formatHost)}`.trimEnd());
|
|
31
|
-
const messageText = diagnostic?.messageText;
|
|
32
|
-
const noErrorsMessage = '0 errors';
|
|
33
|
-
if (messageText?.includes(noErrorsMessage)) {
|
|
34
|
-
if (config.main) {
|
|
35
|
-
// 有启动文件
|
|
36
|
-
const { fork } = require('child_process');
|
|
37
|
-
a?.kill();
|
|
38
|
-
a = fork(config.main, { stdio: 'inherit' });
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
const configPath = ts.findConfigFile(rootDir, ts.sys.fileExists, 'tsconfig.json');
|
|
43
|
-
if (!configPath) {
|
|
44
|
-
throw new Error('找不到tsconfig.json');
|
|
45
|
-
}
|
|
46
|
-
const createProgram = ts.createSemanticDiagnosticsBuilderProgram;
|
|
47
|
-
if (config.watch) {
|
|
48
|
-
const host = ts.createWatchCompilerHost(configPath, {
|
|
49
|
-
...config.options,
|
|
50
|
-
outDir: config.outDir,
|
|
51
|
-
noEmit: false,
|
|
52
|
-
incremental: true,
|
|
53
|
-
}, ts.sys, createProgram, reportDiagnostic, reportWatchStatusChanged);
|
|
54
|
-
ts.createWatchProgram(host);
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
// 读取 tsconfig.json 文件
|
|
58
|
-
const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
59
|
-
// 解析 tsconfig.json 文件
|
|
60
|
-
const compilerOptions = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path_1.default.dirname(configPath), {
|
|
61
|
-
...config.options,
|
|
62
|
-
outDir: config.outDir,
|
|
63
|
-
noEmit: false,
|
|
64
|
-
incremental: false,
|
|
65
|
-
});
|
|
66
|
-
// 获取编译器实例
|
|
67
|
-
const host = ts.createCompilerHost(compilerOptions.options);
|
|
68
|
-
const program = ts.createProgram(compilerOptions.fileNames, compilerOptions.options, host);
|
|
69
|
-
// 执行编译
|
|
70
|
-
const emitResult = program.emit();
|
|
71
|
-
// 处理编译结果
|
|
72
|
-
const diagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
|
73
|
-
if (diagnostics.length > 0) {
|
|
74
|
-
// 输出错误信息
|
|
75
|
-
diagnostics.forEach(diagnostic => {
|
|
76
|
-
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
|
|
77
|
-
if (diagnostic.file) {
|
|
78
|
-
const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
|
|
79
|
-
console.error(`Error ${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
console.error(`Error: ${message}`);
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
// 编译失败
|
|
86
|
-
logger.error('编译失败');
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
// 编译成功
|
|
90
|
-
logger.info('编译成功');
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
//# sourceMappingURL=tsc.js.map
|
package/dist/tsc.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tsc.js","sourceRoot":"","sources":["../src/tsc.ts"],"names":[],"mappings":";;AAYA,kBA0GC;;AArHD,wDAAwB;AAWxB,SAAgB,GAAG,CAAC,MAAiB;IACjC,MAAM,MAAM,GAAG,OAAO,CAAC;IACvB,MAAM,EAAE,GAAgC,OAAO,CAAC,YAAY,CAAC,CAAC;IAC9D,6GAA6G;IAE7G,MAAM,OAAO,GAAG,MAAM,CA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