@pnpm/plugin-commands-setup 2.0.9 → 2.0.12
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/lib/setup.js +37 -81
- package/lib/setup.js.map +1 -1
- package/package.json +6 -6
- package/lib/errors.d.ts +0 -17
- package/lib/errors.js +0 -26
- package/lib/errors.js.map +0 -1
- package/lib/setupOnWindows.d.ts +0 -3
- package/lib/setupOnWindows.js +0 -106
- package/lib/setupOnWindows.js.map +0 -1
package/lib/setup.js
CHANGED
|
@@ -5,13 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.handler = exports.help = exports.commandNames = exports.shorthands = exports.cliOptionsTypes = exports.rcOptionsTypes = void 0;
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const os_1 = __importDefault(require("os"));
|
|
9
8
|
const path_1 = __importDefault(require("path"));
|
|
10
9
|
const cli_utils_1 = require("@pnpm/cli-utils");
|
|
11
10
|
const logger_1 = __importDefault(require("@pnpm/logger"));
|
|
11
|
+
const os_env_path_extender_1 = require("@pnpm/os.env.path-extender");
|
|
12
12
|
const render_help_1 = __importDefault(require("render-help"));
|
|
13
|
-
const setupOnWindows_1 = require("./setupOnWindows");
|
|
14
|
-
const errors_1 = require("./errors");
|
|
15
13
|
const rcOptionsTypes = () => ({});
|
|
16
14
|
exports.rcOptionsTypes = rcOptionsTypes;
|
|
17
15
|
const cliOptionsTypes = () => ({
|
|
@@ -65,89 +63,47 @@ async function handler(opts) {
|
|
|
65
63
|
if (execPath.match(/\.[cm]?js$/) == null) {
|
|
66
64
|
copyCli(execPath, opts.pnpmHomeDir);
|
|
67
65
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (process.env.ZSH_VERSION)
|
|
77
|
-
return 'zsh';
|
|
78
|
-
if (process.env.BASH_VERSION)
|
|
79
|
-
return 'bash';
|
|
80
|
-
if (process.env.FISH_VERSION)
|
|
81
|
-
return 'fish';
|
|
82
|
-
return typeof process.env.SHELL === 'string' ? path_1.default.basename(process.env.SHELL) : null;
|
|
83
|
-
}
|
|
84
|
-
async function updateShell(currentShell, pnpmHomeDir, opts) {
|
|
85
|
-
switch (currentShell) {
|
|
86
|
-
case 'bash':
|
|
87
|
-
case 'zsh': {
|
|
88
|
-
return reportShellChange(await setupShell(currentShell, pnpmHomeDir, opts));
|
|
89
|
-
}
|
|
90
|
-
case 'fish': {
|
|
91
|
-
return reportShellChange(await setupFishShell(pnpmHomeDir, opts));
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
if (process.platform === 'win32') {
|
|
95
|
-
return (0, setupOnWindows_1.setupWindowsEnvironmentPath)(pnpmHomeDir, opts);
|
|
66
|
+
try {
|
|
67
|
+
const report = await (0, os_env_path_extender_1.addDirToEnvPath)(opts.pnpmHomeDir, {
|
|
68
|
+
configSectionName: 'pnpm',
|
|
69
|
+
proxyVarName: 'PNPM_HOME',
|
|
70
|
+
overwrite: opts.force,
|
|
71
|
+
position: 'start',
|
|
72
|
+
});
|
|
73
|
+
return renderSetupOutput(report);
|
|
96
74
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
75
|
+
catch (err) { // eslint-disable-line
|
|
76
|
+
switch (err.code) {
|
|
77
|
+
case 'ERR_PNPM_BAD_ENV_FOUND':
|
|
78
|
+
err.hint = 'If you want to override the existing env variable, use the --force option';
|
|
79
|
+
break;
|
|
80
|
+
case 'ERR_PNPM_BAD_SHELL_SECTION':
|
|
81
|
+
err.hint = 'If you want to override the existing configuration section, use the --force option';
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
throw err;
|
|
105
85
|
}
|
|
106
86
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
export PATH="$PNPM_HOME:$PATH"
|
|
112
|
-
# pnpm end`;
|
|
113
|
-
return {
|
|
114
|
-
action: await updateShellConfig(configFile, content, opts),
|
|
115
|
-
configFile,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
async function setupFishShell(pnpmHomeDir, opts) {
|
|
119
|
-
const configFile = path_1.default.join(os_1.default.homedir(), '.config/fish/config.fish');
|
|
120
|
-
const content = `# pnpm
|
|
121
|
-
set -gx PNPM_HOME "${pnpmHomeDir}"
|
|
122
|
-
set -gx PATH "$PNPM_HOME" $PATH
|
|
123
|
-
# pnpm end`;
|
|
124
|
-
return {
|
|
125
|
-
action: await updateShellConfig(configFile, content, opts),
|
|
126
|
-
configFile,
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
async function updateShellConfig(configFile, newContent, opts) {
|
|
130
|
-
if (!fs_1.default.existsSync(configFile)) {
|
|
131
|
-
await fs_1.default.promises.writeFile(configFile, newContent, 'utf8');
|
|
132
|
-
return 'created';
|
|
133
|
-
}
|
|
134
|
-
const configContent = await fs_1.default.promises.readFile(configFile, 'utf8');
|
|
135
|
-
const match = configContent.match(/# pnpm[\s\S]*# pnpm end/);
|
|
136
|
-
if (!match) {
|
|
137
|
-
await fs_1.default.promises.appendFile(configFile, `\n${newContent}`, 'utf8');
|
|
138
|
-
return 'added';
|
|
87
|
+
exports.handler = handler;
|
|
88
|
+
function renderSetupOutput(report) {
|
|
89
|
+
if (report.oldSettings === report.newSettings) {
|
|
90
|
+
return 'No changes to the environment were made. Everything is already up-to-date.';
|
|
139
91
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
const newConfigContent = replaceSection(configContent, newContent);
|
|
145
|
-
await fs_1.default.promises.writeFile(configFile, newConfigContent, 'utf8');
|
|
146
|
-
return 'updated';
|
|
92
|
+
const output = [];
|
|
93
|
+
if (report.configFile) {
|
|
94
|
+
output.push(reportConfigChange(report.configFile));
|
|
147
95
|
}
|
|
148
|
-
|
|
96
|
+
output.push(`Next configuration changes were made:
|
|
97
|
+
${report.newSettings}`);
|
|
98
|
+
output.push('Setup complete. Open a new terminal to start using pnpm.');
|
|
99
|
+
return output.join('\n\n');
|
|
149
100
|
}
|
|
150
|
-
function
|
|
151
|
-
|
|
101
|
+
function reportConfigChange(configReport) {
|
|
102
|
+
switch (configReport.changeType) {
|
|
103
|
+
case 'created': return `Created ${configReport.path}`;
|
|
104
|
+
case 'appended': return `Appended new lines to ${configReport.path}`;
|
|
105
|
+
case 'modified': return `Replaced configuration in ${configReport.path}`;
|
|
106
|
+
case 'skipped': return `Configuration already up-to-date in ${configReport.path}`;
|
|
107
|
+
}
|
|
152
108
|
}
|
|
153
109
|
//# sourceMappingURL=setup.js.map
|
package/lib/setup.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAmB;AACnB,
|
|
1
|
+
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAmB;AACnB,gDAAuB;AACvB,+CAAyC;AACzC,0DAAiC;AACjC,qEAImC;AACnC,8DAAoC;AAE7B,MAAM,cAAc,GAAG,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAA;AAA3B,QAAA,cAAc,kBAAa;AAEjC,MAAM,eAAe,GAAG,GAAG,EAAE,CAAC,CAAC;IACpC,KAAK,EAAE,OAAO;CACf,CAAC,CAAA;AAFW,QAAA,eAAe,mBAE1B;AAEW,QAAA,UAAU,GAAG,EAAE,CAAA;AAEf,QAAA,YAAY,GAAG,CAAC,OAAO,CAAC,CAAA;AAErC,SAAgB,IAAI;IAClB,OAAO,IAAA,qBAAU,EAAC;QAChB,WAAW,EAAE,cAAc;QAC3B,gBAAgB,EAA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,EAAE;QACjC,KAAK,SAAS,CAAC,CAAC,OAAO,WAAW,YAAY,CAAC,IAAI,EAAE,CAAA;QACrD,KAAK,UAAU,CAAC,CAAC,OAAO,yBAAyB,YAAY,CAAC,IAAI,EAAE,CAAA;QACpE,KAAK,UAAU,CAAC,CAAC,OAAO,6BAA6B,YAAY,CAAC,IAAI,EAAE,CAAA;QACxE,KAAK,SAAS,CAAC,CAAC,OAAO,uCAAuC,YAAY,CAAC,IAAI,EAAE,CAAA;KAChF;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pnpm/plugin-commands-setup",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.12",
|
|
4
4
|
"description": "pnpm commands for setting up pnpm",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -23,9 +23,8 @@
|
|
|
23
23
|
},
|
|
24
24
|
"homepage": "https://github.com/pnpm/pnpm/blob/main/packages/plugin-commands-setup#readme",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@pnpm/cli-utils": "0.7.
|
|
27
|
-
"@pnpm/
|
|
28
|
-
"execa": "npm:safe-execa@^0.1.1",
|
|
26
|
+
"@pnpm/cli-utils": "0.7.11",
|
|
27
|
+
"@pnpm/os.env.path-extender": "^0.2.3",
|
|
29
28
|
"render-help": "^1.0.1"
|
|
30
29
|
},
|
|
31
30
|
"funding": "https://opencollective.com/pnpm",
|
|
@@ -33,9 +32,10 @@
|
|
|
33
32
|
"@pnpm/logger": "^4.0.0"
|
|
34
33
|
},
|
|
35
34
|
"devDependencies": {
|
|
35
|
+
"@pnpm/error": "3.0.1",
|
|
36
36
|
"@pnpm/logger": "^4.0.0",
|
|
37
|
-
"@pnpm/plugin-commands-setup": "2.0.
|
|
38
|
-
"@pnpm/prepare": "0.0.
|
|
37
|
+
"@pnpm/plugin-commands-setup": "2.0.12",
|
|
38
|
+
"@pnpm/prepare": "0.0.42"
|
|
39
39
|
},
|
|
40
40
|
"exports": {
|
|
41
41
|
".": "./lib/index.js"
|
package/lib/errors.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import PnpmError from '@pnpm/error';
|
|
2
|
-
export declare class BadEnvVariableError extends PnpmError {
|
|
3
|
-
constructor({ envName, wantedValue, currentValue }: {
|
|
4
|
-
envName: string;
|
|
5
|
-
wantedValue: string;
|
|
6
|
-
currentValue: string;
|
|
7
|
-
});
|
|
8
|
-
}
|
|
9
|
-
export declare class BadShellSectionError extends PnpmError {
|
|
10
|
-
current: string;
|
|
11
|
-
wanted: string;
|
|
12
|
-
constructor({ wanted, current, configFile }: {
|
|
13
|
-
wanted: string;
|
|
14
|
-
current: string;
|
|
15
|
-
configFile: string;
|
|
16
|
-
});
|
|
17
|
-
}
|
package/lib/errors.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.BadShellSectionError = exports.BadEnvVariableError = void 0;
|
|
7
|
-
const error_1 = __importDefault(require("@pnpm/error"));
|
|
8
|
-
class BadEnvVariableError extends error_1.default {
|
|
9
|
-
constructor({ envName, wantedValue, currentValue }) {
|
|
10
|
-
super('BAD_ENV_FOUND', `Currently '${envName}' is set to '${wantedValue}'`, {
|
|
11
|
-
hint: `If you want to override the existing ${envName} env variable, use the --force option`,
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.BadEnvVariableError = BadEnvVariableError;
|
|
16
|
-
class BadShellSectionError extends error_1.default {
|
|
17
|
-
constructor({ wanted, current, configFile }) {
|
|
18
|
-
super('BAD_SHELL_SECTION', `The config file at "${configFile} already contains a pnpm section but with other configuration`, {
|
|
19
|
-
hint: 'If you want to override the existing configuration section, use the --force option',
|
|
20
|
-
});
|
|
21
|
-
this.current = current;
|
|
22
|
-
this.wanted = wanted;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
exports.BadShellSectionError = BadShellSectionError;
|
|
26
|
-
//# sourceMappingURL=errors.js.map
|
package/lib/errors.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;;;;AAAA,wDAAmC;AAEnC,MAAa,mBAAoB,SAAQ,eAAS;IAChD,YAAa,EAAE,OAAO,EAAE,WAAW,EAAE,YAAY,EAAkE;QACjH,KAAK,CAAC,eAAe,EAAE,cAAc,OAAO,gBAAgB,WAAW,GAAG,EAAE;YAC1E,IAAI,EAAE,wCAAwC,OAAO,uCAAuC;SAC7F,CAAC,CAAA;IACJ,CAAC;CACF;AAND,kDAMC;AAED,MAAa,oBAAqB,SAAQ,eAAS;IAGjD,YAAa,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAA2D;QACnG,KAAK,CAAC,mBAAmB,EAAE,uBAAuB,UAAU,+DAA+D,EAAE;YAC3H,IAAI,EAAE,oFAAoF;SAC3F,CAAC,CAAA;QACF,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;CACF;AAVD,oDAUC"}
|
package/lib/setupOnWindows.d.ts
DELETED
package/lib/setupOnWindows.js
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.setupWindowsEnvironmentPath = void 0;
|
|
7
|
-
const error_1 = __importDefault(require("@pnpm/error"));
|
|
8
|
-
const path_1 = require("path");
|
|
9
|
-
const execa_1 = __importDefault(require("execa"));
|
|
10
|
-
const errors_1 = require("./errors");
|
|
11
|
-
const REG_KEY = 'HKEY_CURRENT_USER\\Environment';
|
|
12
|
-
async function setupWindowsEnvironmentPath(pnpmHomeDir, opts) {
|
|
13
|
-
// Use `chcp` to make `reg` use utf8 encoding for output.
|
|
14
|
-
// Otherwise, the non-ascii characters in the environment variables will become garbled characters.
|
|
15
|
-
const chcpResult = await (0, execa_1.default)('chcp');
|
|
16
|
-
const cpMatch = /\d+/.exec(chcpResult.stdout) ?? [];
|
|
17
|
-
const cpBak = parseInt(cpMatch[0]);
|
|
18
|
-
if (chcpResult.failed || !(cpBak > 0)) {
|
|
19
|
-
return `exec chcp failed: ${cpBak}, ${chcpResult.stderr}`;
|
|
20
|
-
}
|
|
21
|
-
await (0, execa_1.default)('chcp', ['65001']);
|
|
22
|
-
try {
|
|
23
|
-
return await _setupWindowsEnvironmentPath(path_1.win32.normalize(pnpmHomeDir), opts);
|
|
24
|
-
}
|
|
25
|
-
finally {
|
|
26
|
-
await (0, execa_1.default)('chcp', [cpBak.toString()]);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
exports.setupWindowsEnvironmentPath = setupWindowsEnvironmentPath;
|
|
30
|
-
async function _setupWindowsEnvironmentPath(pnpmHomeDir, opts) {
|
|
31
|
-
const registryOutput = await getRegistryOutput();
|
|
32
|
-
const logger = [];
|
|
33
|
-
logger.push(logEnvUpdate(await updateEnvVariable(registryOutput, 'PNPM_HOME', pnpmHomeDir, opts), 'PNPM_HOME'));
|
|
34
|
-
logger.push(logEnvUpdate(await prependToPath(registryOutput, '%PNPM_HOME%'), 'Path'));
|
|
35
|
-
return logger.join('\n');
|
|
36
|
-
}
|
|
37
|
-
function logEnvUpdate(envUpdateResult, envName) {
|
|
38
|
-
switch (envUpdateResult) {
|
|
39
|
-
case 'skipped': return `${envName} was already up-to-date`;
|
|
40
|
-
case 'updated': return `${envName} was updated`;
|
|
41
|
-
}
|
|
42
|
-
return '';
|
|
43
|
-
}
|
|
44
|
-
async function updateEnvVariable(registryOutput, name, value, opts) {
|
|
45
|
-
const currentValue = await getEnvValueFromRegistry(registryOutput, name);
|
|
46
|
-
if (currentValue && !opts.force) {
|
|
47
|
-
if (currentValue !== value) {
|
|
48
|
-
throw new errors_1.BadEnvVariableError({ envName: name, currentValue, wantedValue: value });
|
|
49
|
-
}
|
|
50
|
-
return 'skipped';
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
await setEnvVarInRegistry(name, value);
|
|
54
|
-
return 'updated';
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
async function prependToPath(registryOutput, prependDir) {
|
|
58
|
-
const pathData = await getEnvValueFromRegistry(registryOutput, 'Path');
|
|
59
|
-
if (pathData === undefined || pathData == null || pathData.trim() === '') {
|
|
60
|
-
throw new error_1.default('NO_PATH', '"Path" environment variable is not found in the registry');
|
|
61
|
-
}
|
|
62
|
-
else if (pathData.split(path_1.win32.delimiter).includes(prependDir)) {
|
|
63
|
-
return 'skipped';
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
const newPathValue = `${prependDir}${path_1.win32.delimiter}${pathData}`;
|
|
67
|
-
await setEnvVarInRegistry('Path', newPathValue);
|
|
68
|
-
return 'updated';
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
// `windowsHide` in `execa` is true by default, which will cause `chcp` to have no effect.
|
|
72
|
-
const EXEC_OPTS = { windowsHide: false };
|
|
73
|
-
/**
|
|
74
|
-
* We read all the registry values and then pick the keys that we need.
|
|
75
|
-
* This is done because if we would try to pick a key that is not in the registry, the command would fail.
|
|
76
|
-
* And it is hard to identify the real cause of the command failure.
|
|
77
|
-
*/
|
|
78
|
-
async function getRegistryOutput() {
|
|
79
|
-
try {
|
|
80
|
-
const queryResult = await (0, execa_1.default)('reg', ['query', REG_KEY], EXEC_OPTS);
|
|
81
|
-
return queryResult.stdout;
|
|
82
|
-
}
|
|
83
|
-
catch (err) { // eslint-disable-line
|
|
84
|
-
throw new error_1.default('REG_READ', 'win32 registry environment values could not be retrieved');
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
async function getEnvValueFromRegistry(registryOutput, envVarName) {
|
|
88
|
-
const regexp = new RegExp(`^ {4}(?<name>${envVarName}) {4}(?<type>\\w+) {4}(?<data>.*)$`, 'gim');
|
|
89
|
-
const match = Array.from(registryOutput.matchAll(regexp))[0];
|
|
90
|
-
return match?.groups.data;
|
|
91
|
-
}
|
|
92
|
-
async function setEnvVarInRegistry(envVarName, envVarValue) {
|
|
93
|
-
try {
|
|
94
|
-
await (0, execa_1.default)('reg', ['add', REG_KEY, '/v', envVarName, '/t', 'REG_EXPAND_SZ', '/d', envVarValue, '/f'], EXEC_OPTS);
|
|
95
|
-
}
|
|
96
|
-
catch (err) { // eslint-disable-line
|
|
97
|
-
throw new error_1.default('FAILED_SET_ENV', `Failed to set "${envVarName}" to "${envVarValue}": ${err.stderr}`);
|
|
98
|
-
}
|
|
99
|
-
// When setting environment variables through the registry, they will not be recognized immediately.
|
|
100
|
-
// There is a workaround though, to set at least one environment variable with `setx`.
|
|
101
|
-
// We have some redundancy here because we run it for each env var.
|
|
102
|
-
// It would be enough also to run it only for the last changed env var.
|
|
103
|
-
// Read more at: https://bit.ly/39OlQnF
|
|
104
|
-
await (0, execa_1.default)('setx', [envVarName, envVarValue], EXEC_OPTS);
|
|
105
|
-
}
|
|
106
|
-
//# sourceMappingURL=setupOnWindows.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setupOnWindows.js","sourceRoot":"","sources":["../src/setupOnWindows.ts"],"names":[],"mappings":";;;;;;AAAA,wDAAmC;AACnC,+BAAoC;AACpC,kDAAyB;AACzB,qCAA8C;AAI9C,MAAM,OAAO,GAAG,gCAAgC,CAAA;AAEzC,KAAK,UAAU,2BAA2B,CAAE,WAAmB,EAAE,IAAwB;IAC9F,yDAAyD;IACzD,mGAAmG;IACnG,M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