@sanity/pkg-utils 1.7.1 → 1.7.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/{__resolveBuildContext-49ce07ba.cjs → __resolveBuildContext-9b0aa9f9.cjs} +214 -102
- package/dist/__resolveBuildContext-9b0aa9f9.cjs.map +1 -0
- package/dist/{_build-9e9eb450.cjs → _build-6e7deb31.cjs} +82 -36
- package/dist/_build-6e7deb31.cjs.map +1 -0
- package/dist/{_buildAction-38c3d2ed.cjs → _buildAction-d8841b41.cjs} +35 -4
- package/dist/_buildAction-d8841b41.cjs.map +1 -0
- package/dist/{_check-4ce1387d.cjs → _check-04a1f749.cjs} +112 -51
- package/dist/_check-04a1f749.cjs.map +1 -0
- package/dist/{_checkAction-2704266e.cjs → _checkAction-09426a13.cjs} +17 -3
- package/dist/_checkAction-09426a13.cjs.map +1 -0
- package/dist/{_index-0e8b664d.cjs → _index-46cab21c.cjs} +331 -202
- package/dist/_index-46cab21c.cjs.map +1 -0
- package/dist/_watch-cf9c717f.cjs +264 -0
- package/dist/_watch-cf9c717f.cjs.map +1 -0
- package/dist/{_watchAction-df30594b.cjs → _watchAction-5941527f.cjs} +38 -4
- package/dist/_watchAction-5941527f.cjs.map +1 -0
- package/dist/cli.cjs +24 -9
- package/dist/cli.cjs.map +1 -1
- package/dist/index.cjs +47 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +726 -457
- package/dist/index.js.map +1 -1
- package/package.json +10 -4
- package/src/node/_core/config/_loadConfig.ts +5 -0
- package/src/node/_resolveBuildTasks.ts +1 -3
- package/src/node/_resolveWatchTasks.ts +1 -3
- package/src/node/_tasks/rollup/_resolveRollupConfig.ts +26 -3
- package/src/node/build.ts +0 -1
- package/dist/__resolveBuildContext-49ce07ba.cjs.map +0 -1
- package/dist/_build-9e9eb450.cjs.map +0 -1
- package/dist/_buildAction-38c3d2ed.cjs.map +0 -1
- package/dist/_check-4ce1387d.cjs.map +0 -1
- package/dist/_checkAction-2704266e.cjs.map +0 -1
- package/dist/_index-0e8b664d.cjs.map +0 -1
- package/dist/_watch-fca55d1f.cjs +0 -219
- package/dist/_watch-fca55d1f.cjs.map +0 -1
- package/dist/_watchAction-df30594b.cjs.map +0 -1
- package/src/node/_resolveEsTarget.ts +0 -39
|
@@ -1,30 +1,56 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
+
|
|
5
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
6
|
+
|
|
7
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
8
|
+
|
|
9
|
+
var _resolveBuildContext = require('./__resolveBuildContext-9b0aa9f9.cjs');
|
|
10
|
+
|
|
4
11
|
require('typescript');
|
|
12
|
+
|
|
5
13
|
var fs = require('fs');
|
|
14
|
+
|
|
6
15
|
var path = require('path');
|
|
7
|
-
|
|
16
|
+
|
|
8
17
|
var chalk = require('chalk');
|
|
9
18
|
|
|
10
|
-
|
|
19
|
+
var index = require('./_index-46cab21c.cjs');
|
|
20
|
+
|
|
21
|
+
function _interopDefaultLegacy(e) {
|
|
22
|
+
return e && typeof e === 'object' && 'default' in e ? e : {
|
|
23
|
+
'default': e
|
|
24
|
+
};
|
|
25
|
+
}
|
|
11
26
|
|
|
12
27
|
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
28
|
+
|
|
13
29
|
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
30
|
+
|
|
14
31
|
var chalk__default = /*#__PURE__*/_interopDefaultLegacy(chalk);
|
|
15
32
|
|
|
16
33
|
function _resolveBuildTasks(ctx) {
|
|
17
34
|
var _a, _b, _c, _d, _e;
|
|
18
|
-
|
|
19
|
-
const
|
|
35
|
+
|
|
36
|
+
const {
|
|
37
|
+
cwd,
|
|
38
|
+
pkg,
|
|
39
|
+
target
|
|
40
|
+
} = ctx;
|
|
20
41
|
const tasks = [];
|
|
21
|
-
const exports = Object.entries(ctx.exports || {}).map(
|
|
22
|
-
|
|
23
|
-
|
|
42
|
+
const exports = Object.entries(ctx.exports || {}).map(_ref => {
|
|
43
|
+
let [_path, exp] = _ref;
|
|
44
|
+
return _objectSpread({
|
|
45
|
+
_path
|
|
46
|
+
}, exp);
|
|
47
|
+
});
|
|
24
48
|
const dtsTasks = {};
|
|
25
49
|
const rollupTasks = {};
|
|
50
|
+
|
|
26
51
|
function _addRollupTaskEntry(format, runtime, entry) {
|
|
27
|
-
const buildId =
|
|
52
|
+
const buildId = "".concat(format, ":").concat(runtime);
|
|
53
|
+
|
|
28
54
|
if (!rollupTasks[buildId]) {
|
|
29
55
|
rollupTasks[buildId] = {
|
|
30
56
|
type: "build:js",
|
|
@@ -32,14 +58,16 @@ function _resolveBuildTasks(ctx) {
|
|
|
32
58
|
entries: [entry],
|
|
33
59
|
runtime,
|
|
34
60
|
format,
|
|
35
|
-
target:
|
|
61
|
+
target: target[runtime]
|
|
36
62
|
};
|
|
37
63
|
} else {
|
|
38
64
|
rollupTasks[buildId].entries.push(entry);
|
|
39
65
|
}
|
|
40
66
|
}
|
|
67
|
+
|
|
41
68
|
for (const exp of exports) {
|
|
42
69
|
const importId = path__default["default"].join(pkg.name, exp._path);
|
|
70
|
+
|
|
43
71
|
if (exp.types) {
|
|
44
72
|
if (!dtsTasks[importId]) {
|
|
45
73
|
dtsTasks[importId] = {
|
|
@@ -52,90 +80,106 @@ function _resolveBuildTasks(ctx) {
|
|
|
52
80
|
}
|
|
53
81
|
}
|
|
54
82
|
}
|
|
83
|
+
|
|
55
84
|
for (const exp of exports) {
|
|
56
85
|
const output = exp.require;
|
|
57
|
-
if (!output)
|
|
58
|
-
|
|
86
|
+
if (!output) continue;
|
|
87
|
+
|
|
59
88
|
_addRollupTaskEntry("commonjs", ctx.runtime, {
|
|
60
89
|
path: exp._path,
|
|
61
90
|
source: exp.source,
|
|
62
91
|
output
|
|
63
92
|
});
|
|
64
93
|
}
|
|
94
|
+
|
|
65
95
|
for (const exp of exports) {
|
|
66
96
|
const output = (_a = exp.browser) == null ? void 0 : _a.require;
|
|
67
|
-
if (!output)
|
|
68
|
-
|
|
97
|
+
if (!output) continue;
|
|
98
|
+
|
|
69
99
|
_addRollupTaskEntry("commonjs", "browser", {
|
|
70
100
|
path: exp._path,
|
|
71
101
|
source: ((_b = exp.browser) == null ? void 0 : _b.source) || exp.source,
|
|
72
102
|
output
|
|
73
103
|
});
|
|
74
104
|
}
|
|
105
|
+
|
|
75
106
|
for (const exp of exports) {
|
|
76
107
|
const output = exp.import;
|
|
77
|
-
if (!output)
|
|
78
|
-
|
|
108
|
+
if (!output) continue;
|
|
109
|
+
|
|
79
110
|
_addRollupTaskEntry("esm", ctx.runtime, {
|
|
80
111
|
path: exp._path,
|
|
81
112
|
source: exp.source,
|
|
82
113
|
output
|
|
83
114
|
});
|
|
84
115
|
}
|
|
116
|
+
|
|
85
117
|
for (const exp of exports) {
|
|
86
118
|
const output = (_c = exp.browser) == null ? void 0 : _c.import;
|
|
87
|
-
if (!output)
|
|
88
|
-
|
|
119
|
+
if (!output) continue;
|
|
120
|
+
|
|
89
121
|
_addRollupTaskEntry("esm", "browser", {
|
|
90
122
|
path: exp._path,
|
|
91
123
|
source: ((_d = exp.browser) == null ? void 0 : _d.source) || exp.source,
|
|
92
124
|
output
|
|
93
125
|
});
|
|
94
126
|
}
|
|
127
|
+
|
|
95
128
|
tasks.push(...Object.values(dtsTasks));
|
|
96
129
|
tasks.push(...Object.values(rollupTasks));
|
|
130
|
+
|
|
97
131
|
for (const exp of exports) {
|
|
98
132
|
if (exp._exported && exp._path !== ".") {
|
|
99
133
|
const relativeTargetPath = (((_e = exp.browser) == null ? void 0 : _e.import) || exp.import || "").replace(/\.[^/.]+$/, "");
|
|
134
|
+
|
|
100
135
|
if (relativeTargetPath) {
|
|
101
|
-
fs__default["default"].writeFileSync(
|
|
102
|
-
path__default["default"].resolve(cwd, `${exp._path}.js`),
|
|
103
|
-
[
|
|
104
|
-
`// AUTO-GENERATED \u2013 DO NOT EDIT`,
|
|
105
|
-
``,
|
|
106
|
-
`export * from '${relativeTargetPath}'`,
|
|
107
|
-
``
|
|
108
|
-
].join("\n")
|
|
109
|
-
);
|
|
136
|
+
fs__default["default"].writeFileSync(path__default["default"].resolve(cwd, "".concat(exp._path, ".js")), ["// AUTO-GENERATED \u2013 DO NOT EDIT", "", "export * from '".concat(relativeTargetPath, "'"), ""].join("\n"));
|
|
110
137
|
}
|
|
111
138
|
}
|
|
112
139
|
}
|
|
140
|
+
|
|
113
141
|
return tasks;
|
|
114
142
|
}
|
|
115
143
|
|
|
116
144
|
function _spinner(msg) {
|
|
117
145
|
const startTime = Date.now();
|
|
118
|
-
console.log(
|
|
146
|
+
console.log("".concat(chalk__default["default"].yellow("run "), " ").concat(msg));
|
|
119
147
|
return {
|
|
120
148
|
complete: () => {
|
|
121
|
-
console.log(
|
|
149
|
+
console.log("".concat(chalk__default["default"].green("ok "), " ").concat(chalk__default["default"].gray("".concat(Date.now() - startTime, "ms"))));
|
|
122
150
|
},
|
|
123
151
|
error: () => {
|
|
124
|
-
console.log(
|
|
152
|
+
console.log("".concat(chalk__default["default"].red("failed"), " ").concat(chalk__default["default"].gray("".concat(Date.now() - startTime, "ms"))));
|
|
125
153
|
}
|
|
126
154
|
};
|
|
127
155
|
}
|
|
128
156
|
|
|
129
157
|
async function build(options) {
|
|
130
|
-
const {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
158
|
+
const {
|
|
159
|
+
cwd,
|
|
160
|
+
tsconfig = "tsconfig.json"
|
|
161
|
+
} = options;
|
|
162
|
+
const pkg = await _resolveBuildContext._loadPkgWithReporting({
|
|
163
|
+
cwd
|
|
164
|
+
});
|
|
165
|
+
const config = await _resolveBuildContext._loadConfig({
|
|
166
|
+
cwd
|
|
167
|
+
});
|
|
168
|
+
const ctx = await _resolveBuildContext._resolveBuildContext({
|
|
169
|
+
config,
|
|
170
|
+
cwd,
|
|
171
|
+
pkg,
|
|
172
|
+
tsconfig
|
|
173
|
+
});
|
|
174
|
+
|
|
134
175
|
const buildTasks = _resolveBuildTasks(ctx);
|
|
176
|
+
|
|
135
177
|
for (const task of buildTasks) {
|
|
136
178
|
const handler = index._buildTaskHandlers[task.type];
|
|
137
179
|
const taskName = handler.name(ctx, task);
|
|
180
|
+
|
|
138
181
|
const spinner = _spinner(taskName);
|
|
182
|
+
|
|
139
183
|
try {
|
|
140
184
|
const result = await handler.exec(ctx, task).toPromise();
|
|
141
185
|
spinner.complete();
|
|
@@ -143,11 +187,13 @@ async function build(options) {
|
|
|
143
187
|
handler.complete(ctx, task, result);
|
|
144
188
|
} catch (err) {
|
|
145
189
|
spinner.error();
|
|
190
|
+
|
|
146
191
|
if (err instanceof Error) {
|
|
147
|
-
const RE_CWD = new RegExp(
|
|
192
|
+
const RE_CWD = new RegExp("".concat(cwd), "g");
|
|
148
193
|
ctx.logger.error(err.message.replace(RE_CWD, "."));
|
|
149
194
|
ctx.logger.log();
|
|
150
195
|
}
|
|
196
|
+
|
|
151
197
|
handler.error(ctx, task, err);
|
|
152
198
|
process.exit(1);
|
|
153
199
|
}
|
|
@@ -156,4 +202,4 @@ async function build(options) {
|
|
|
156
202
|
|
|
157
203
|
exports._resolveBuildTasks = _resolveBuildTasks;
|
|
158
204
|
exports.build = build;
|
|
159
|
-
//# sourceMappingURL=_build-
|
|
205
|
+
//# sourceMappingURL=_build-6e7deb31.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_build-6e7deb31.cjs","sources":["../src/node/_resolveBuildTasks.ts","../src/node/_spinner.ts","../src/node/build.ts"],"sourcesContent":["import fs from 'fs'\nimport path from 'path'\nimport {PkgExport, PkgFormat, PkgRuntime, _BuildContext} from './_core'\nimport {_BuildTask, _DtsTask, _RollupTask, _RollupTaskEntry} from './_tasks'\n\n/** @internal */\nexport function _resolveBuildTasks(ctx: _BuildContext): _BuildTask[] {\n const {cwd, pkg, target} = ctx\n\n const tasks: _BuildTask[] = []\n\n const exports = Object.entries(ctx.exports || {}).map(\n ([_path, exp]) => ({_path, ...exp} as PkgExport & {_path: string})\n )\n\n const dtsTasks: Record<string, _DtsTask> = {}\n const rollupTasks: Record<string, _RollupTask> = {}\n\n function _addRollupTaskEntry(format: PkgFormat, runtime: PkgRuntime, entry: _RollupTaskEntry) {\n const buildId = `${format}:${runtime}`\n\n if (!rollupTasks[buildId]) {\n rollupTasks[buildId] = {\n type: 'build:js',\n buildId,\n entries: [entry],\n runtime,\n format,\n target: target[runtime],\n }\n } else {\n rollupTasks[buildId].entries.push(entry)\n }\n }\n\n // Parse `dts` tasks\n for (const exp of exports) {\n const importId = path.join(pkg.name, exp._path)\n\n if (exp.types) {\n if (!dtsTasks[importId]) {\n dtsTasks[importId] = {\n type: 'build:dts',\n importId,\n exportPath: exp._path,\n sourcePath: exp.source,\n targetPath: exp.types,\n }\n }\n }\n }\n\n // Parse rollup:commonjs:* tasks\n for (const exp of exports) {\n const output = exp.require\n\n if (!output) continue\n\n _addRollupTaskEntry('commonjs', ctx.runtime, {\n path: exp._path,\n source: exp.source,\n output,\n })\n }\n\n // Parse rollup:commonjs:browser tasks\n for (const exp of exports) {\n const output = exp.browser?.require\n\n if (!output) continue\n\n _addRollupTaskEntry('commonjs', 'browser', {\n path: exp._path,\n source: exp.browser?.source || exp.source,\n output,\n })\n }\n\n // Parse rollup:esm:* tasks\n for (const exp of exports) {\n const output = exp.import\n\n if (!output) continue\n\n _addRollupTaskEntry('esm', ctx.runtime, {\n path: exp._path,\n source: exp.source,\n output,\n })\n }\n\n // Parse rollup:esm:browser tasks\n for (const exp of exports) {\n const output = exp.browser?.import\n\n if (!output) continue\n\n _addRollupTaskEntry('esm', 'browser', {\n path: exp._path,\n source: exp.browser?.source || exp.source,\n output,\n })\n }\n\n tasks.push(...Object.values(dtsTasks))\n tasks.push(...Object.values(rollupTasks))\n\n // Parse rollup:esm:browser tasks\n for (const exp of exports) {\n if (exp._exported && exp._path !== '.') {\n const relativeTargetPath = (exp.browser?.import || exp.import || '').replace(/\\.[^/.]+$/, '')\n\n if (relativeTargetPath) {\n fs.writeFileSync(\n path.resolve(cwd, `${exp._path}.js`),\n [\n `// AUTO-GENERATED – DO NOT EDIT`,\n ``,\n // `export {default} from '${relativeTargetPath}'`,\n `export * from '${relativeTargetPath}'`,\n ``,\n ].join('\\n')\n )\n }\n }\n }\n\n return tasks\n}\n","/* eslint-disable no-console */\n\nimport chalk from 'chalk'\n\nexport function _spinner(msg: string): {complete: () => void; error: () => void} {\n const startTime = Date.now()\n\n console.log(`${chalk.yellow('run ')} ${msg}`)\n\n return {\n complete: () => {\n console.log(`${chalk.green('ok ')} ${chalk.gray(`${Date.now() - startTime}ms`)}`)\n },\n error: () => {\n console.log(`${chalk.red(`failed`)} ${chalk.gray(`${Date.now() - startTime}ms`)}`)\n },\n }\n}\n","import {_loadConfig, _loadPkgWithReporting} from './_core'\nimport {_resolveBuildContext} from './_resolveBuildContext'\nimport {_resolveBuildTasks} from './_resolveBuildTasks'\nimport {_spinner} from './_spinner'\nimport {_BuildTask, _TaskHandler, _buildTaskHandlers} from './_tasks'\n\n/** @public */\nexport async function build(options: {cwd: string; tsconfig?: string}): Promise<void> {\n const {cwd, tsconfig = 'tsconfig.json'} = options\n\n const pkg = await _loadPkgWithReporting({cwd})\n const config = await _loadConfig({cwd})\n\n const ctx = await _resolveBuildContext({config, cwd, pkg, tsconfig})\n\n const buildTasks = _resolveBuildTasks(ctx)\n\n for (const task of buildTasks) {\n const handler = _buildTaskHandlers[task.type] as _TaskHandler<_BuildTask>\n const taskName = handler.name(ctx, task)\n\n const spinner = _spinner(taskName)\n\n try {\n const result = await handler.exec(ctx, task).toPromise()\n\n spinner.complete()\n ctx.logger.log()\n\n handler.complete(ctx, task, result)\n } catch (err) {\n spinner.error()\n\n if (err instanceof Error) {\n const RE_CWD = new RegExp(`${cwd}`, 'g')\n\n ctx.logger.error(err.message.replace(RE_CWD, '.'))\n ctx.logger.log()\n }\n\n handler.error(ctx, task, err)\n\n process.exit(1)\n }\n }\n}\n"],"names":["_resolveBuildTasks","ctx","_a","_b","_c","_d","_e","cwd","pkg","target","tasks","exports","Object","entries","map","_path","exp","dtsTasks","rollupTasks","_addRollupTaskEntry","format","runtime","entry","buildId","type","push","importId","path","join","name","types","exportPath","sourcePath","source","targetPath","output","require","browser","import","values","_exported","relativeTargetPath","replace","fs","writeFileSync","resolve","_spinner","msg","startTime","Date","now","console","log","chalk","yellow","complete","green","gray","error","red","build","options","tsconfig","_loadPkgWithReporting","config","_loadConfig","_resolveBuildContext","buildTasks","task","handler","_buildTaskHandlers","taskName","spinner","result","exec","toPromise","logger","err","Error","RE_CWD","RegExp","message","process","exit"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEO,SAASA,kBAAT,CAA4BC,GAA5B,EAAiC;EACtC,IAAIC,EAAJ,EAAQC,EAAR,EAAYC,EAAZ,EAAgBC,EAAhB,EAAoBC,EAApB;;EACA,MAAM;IAAEC,GAAF;IAAOC,GAAP;IAAYC;EAAZ,IAAuBR,GAA7B;EACA,MAAMS,KAAK,GAAG,EAAd;EACA,MAAMC,OAAO,GAAGC,MAAM,CAACC,OAAP,CAAeZ,G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kBmE,IAAlB,CAAjB;;IACA,MAAMI,OAAO,GAAG1B,QAAQ,CAACyB,QAAD,CAAxB;;IACA,IAAI;MACF,MAAME,MAAM,GAAG,MAAMJ,OAAO,CAACK,IAAR,CAAazE,GAAb,EAAkBmE,IAAlB,EAAwBO,SAAxB,EAArB;MACAH,OAAO,CAACjB,QAAR;MACAtD,GAAG,CAAC2E,MAAJ,CAAWxB,GAAX;MACAiB,OAAO,CAACd,QAAR,CAAiBtD,GAAjB,EAAsBmE,IAAtB,EAA4BK,MAA5B;IACD,CALD,CAKE,OAAOI,GAAP,EAAY;MACZL,OAAO,CAACd,KAAR;;MACA,IAAImB,GAAG,YAAYC,KAAnB,EAA0B;QACxB,MAAMC,MAAM,GAAG,IAAIC,MAAJ,WAAczE,GAAd,GAAqB,GAArB,CAAf;QACAN,GAAG,CAAC2E,MAAJ,CAAWlB,KAAX,CAAiBmB,GAAG,CAACI,OAAJ,CAAYvC,OAAZ,CAAoBqC,MAApB,EAA4B,GAA5B,CAAjB;QACA9E,GAAG,CAAC2E,MAAJ,CAAWxB,GAAX;MACD;;MACDiB,OAAO,CAACX,KAAR,CAAczD,GAAd,EAAmBmE,IAAnB,EAAyBS,GAAzB;MACAK,OAAO,CAACC,IAAR,CAAa,CAAb;IACD;EACF;AACH;;;"}
|
|
@@ -1,34 +1,65 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var build = require('./_build-
|
|
4
|
-
|
|
3
|
+
var build = require('./_build-6e7deb31.cjs');
|
|
4
|
+
|
|
5
|
+
require('./__resolveBuildContext-9b0aa9f9.cjs');
|
|
6
|
+
|
|
5
7
|
require('path');
|
|
8
|
+
|
|
6
9
|
require('esbuild-register/dist/node');
|
|
10
|
+
|
|
7
11
|
require('find-config');
|
|
12
|
+
|
|
8
13
|
require('pkg-up');
|
|
14
|
+
|
|
9
15
|
require('chalk');
|
|
16
|
+
|
|
10
17
|
require('zod');
|
|
18
|
+
|
|
11
19
|
require('fs/promises');
|
|
20
|
+
|
|
12
21
|
require('typescript');
|
|
22
|
+
|
|
13
23
|
require('browserslist');
|
|
24
|
+
|
|
14
25
|
require('fs');
|
|
15
|
-
|
|
26
|
+
|
|
27
|
+
require('./_index-46cab21c.cjs');
|
|
28
|
+
|
|
16
29
|
require('rxjs');
|
|
30
|
+
|
|
17
31
|
require('util');
|
|
32
|
+
|
|
18
33
|
require('rimraf');
|
|
34
|
+
|
|
19
35
|
require('@microsoft/api-extractor');
|
|
36
|
+
|
|
20
37
|
require('mkdirp');
|
|
38
|
+
|
|
21
39
|
require('prettier');
|
|
40
|
+
|
|
22
41
|
require('@microsoft/tsdoc-config');
|
|
42
|
+
|
|
23
43
|
require('jsonc-parser');
|
|
44
|
+
|
|
24
45
|
require('rollup');
|
|
46
|
+
|
|
25
47
|
require('@rollup/plugin-alias');
|
|
48
|
+
|
|
49
|
+
require('@rollup/plugin-babel');
|
|
50
|
+
|
|
26
51
|
require('@rollup/plugin-commonjs');
|
|
52
|
+
|
|
27
53
|
require('@rollup/plugin-json');
|
|
54
|
+
|
|
28
55
|
require('@rollup/plugin-node-resolve');
|
|
56
|
+
|
|
29
57
|
require('@rollup/plugin-replace');
|
|
58
|
+
|
|
30
59
|
require('rollup-plugin-esbuild');
|
|
31
60
|
|
|
61
|
+
require('rollup-plugin-terser');
|
|
62
|
+
|
|
32
63
|
async function buildAction(options) {
|
|
33
64
|
return await build.build({
|
|
34
65
|
cwd: process.cwd(),
|
|
@@ -37,4 +68,4 @@ async function buildAction(options) {
|
|
|
37
68
|
}
|
|
38
69
|
|
|
39
70
|
exports.buildAction = buildAction;
|
|
40
|
-
//# sourceMappingURL=_buildAction-
|
|
71
|
+
//# sourceMappingURL=_buildAction-d8841b41.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_buildAction-d8841b41.cjs","sources":["../src/cli/buildAction.ts"],"sourcesContent":["import {build} from '../node/build'\n\nexport async function buildAction(options: {tsconfig?: string}): Promise<void> {\n return await build({\n cwd: process.cwd(),\n tsconfig: options.tsconfig,\n })\n}\n"],"names":["buildAction","options","build","cwd","process","tsconfig"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACO,eAAeA,WAAf,CAA2BC,OAA3B,EAAoC;EACzC,OAAO,MAAMC,KAAAA,CAAAA,KAAAA,CAAM;IACjBC,GAAG,EAAEC,OAAO,CAACD,GAAR,EADY;IAEjBE,QAAQ,EAAEJ,OAAO,CAACI;EAFD,CAANH,CAAb;AAIF;;"}
|
|
@@ -1,21 +1,37 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var path = require('path');
|
|
4
|
+
|
|
4
5
|
var chalk = require('chalk');
|
|
6
|
+
|
|
5
7
|
var esbuild = require('esbuild');
|
|
6
|
-
|
|
8
|
+
|
|
9
|
+
var _resolveBuildContext = require('./__resolveBuildContext-9b0aa9f9.cjs');
|
|
10
|
+
|
|
7
11
|
require('typescript');
|
|
12
|
+
|
|
8
13
|
var fs = require('fs');
|
|
14
|
+
|
|
9
15
|
var treeify = require('treeify');
|
|
16
|
+
|
|
10
17
|
var prettyBytes = require('pretty-bytes');
|
|
11
18
|
|
|
12
|
-
function _interopDefaultLegacy
|
|
19
|
+
function _interopDefaultLegacy(e) {
|
|
20
|
+
return e && typeof e === 'object' && 'default' in e ? e : {
|
|
21
|
+
'default': e
|
|
22
|
+
};
|
|
23
|
+
}
|
|
13
24
|
|
|
14
25
|
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
26
|
+
|
|
15
27
|
var chalk__default = /*#__PURE__*/_interopDefaultLegacy(chalk);
|
|
28
|
+
|
|
16
29
|
var esbuild__default = /*#__PURE__*/_interopDefaultLegacy(esbuild);
|
|
30
|
+
|
|
17
31
|
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
32
|
+
|
|
18
33
|
var treeify__default = /*#__PURE__*/_interopDefaultLegacy(treeify);
|
|
34
|
+
|
|
19
35
|
var prettyBytes__default = /*#__PURE__*/_interopDefaultLegacy(prettyBytes);
|
|
20
36
|
|
|
21
37
|
function _getFilesize(file) {
|
|
@@ -31,93 +47,131 @@ function _fileExists(file) {
|
|
|
31
47
|
return false;
|
|
32
48
|
}
|
|
33
49
|
}
|
|
50
|
+
|
|
34
51
|
function _getFileInfo(cwd, filePath) {
|
|
35
52
|
const p = path__default["default"].resolve(cwd, filePath);
|
|
53
|
+
|
|
36
54
|
const exists = _fileExists(p);
|
|
55
|
+
|
|
37
56
|
const size = exists ? _getFilesize(p) : void 0;
|
|
38
|
-
return {
|
|
57
|
+
return {
|
|
58
|
+
exists,
|
|
59
|
+
size
|
|
60
|
+
};
|
|
39
61
|
}
|
|
62
|
+
|
|
40
63
|
function _printPackageTree(ctx) {
|
|
41
|
-
const {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
64
|
+
const {
|
|
65
|
+
cwd,
|
|
66
|
+
exports,
|
|
67
|
+
logger,
|
|
68
|
+
pkg
|
|
69
|
+
} = ctx;
|
|
70
|
+
if (!exports) return;
|
|
71
|
+
logger.log("".concat(chalk__default["default"].blue(pkg.name), "@").concat(chalk__default["default"].green(pkg.version)));
|
|
45
72
|
const tree = {};
|
|
73
|
+
|
|
46
74
|
if (pkg.bin) {
|
|
47
75
|
tree.bin = pkg.bin;
|
|
48
76
|
}
|
|
77
|
+
|
|
49
78
|
function _fileInfo(file) {
|
|
50
79
|
const info = _getFileInfo(cwd, file);
|
|
80
|
+
|
|
51
81
|
if (!info.size) {
|
|
52
|
-
return
|
|
82
|
+
return "".concat(chalk__default["default"].gray(file), " ").concat(chalk__default["default"].red("does not exist"));
|
|
53
83
|
}
|
|
54
|
-
|
|
84
|
+
|
|
85
|
+
return "".concat(file, " ").concat(chalk__default["default"].gray(info.size));
|
|
55
86
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (entry.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
87
|
+
|
|
88
|
+
tree.exports = Object.fromEntries(Object.entries(exports).filter(_ref => {
|
|
89
|
+
let [, entry] = _ref;
|
|
90
|
+
return entry._exported;
|
|
91
|
+
}).map(_ref2 => {
|
|
92
|
+
let [exportPath, entry] = _ref2;
|
|
93
|
+
const exp = {
|
|
94
|
+
source: entry.source,
|
|
95
|
+
default: entry.default
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
if (entry.browser) {
|
|
99
|
+
exp.browser = {};
|
|
100
|
+
if (entry.browser.import) exp.browser.import = _fileInfo(entry.browser.import);
|
|
101
|
+
if (entry.browser.require) exp.browser.import = _fileInfo(entry.browser.require);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (entry.import) exp.import = _fileInfo(entry.import);
|
|
105
|
+
if (entry.require) exp.require = _fileInfo(entry.require);
|
|
106
|
+
if (entry.types) exp.types = _fileInfo(entry.types);
|
|
107
|
+
exp.default = _fileInfo(entry.default);
|
|
108
|
+
return [chalk__default["default"].green(path__default["default"].join(pkg.name, exportPath)), exp];
|
|
109
|
+
}));
|
|
76
110
|
logger.log(treeify__default["default"].asTree(tree, true, true));
|
|
77
111
|
}
|
|
78
112
|
|
|
79
113
|
async function check(options) {
|
|
80
|
-
const {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
114
|
+
const {
|
|
115
|
+
cwd,
|
|
116
|
+
strict,
|
|
117
|
+
tsconfig = "tsconfig.json"
|
|
118
|
+
} = options;
|
|
119
|
+
const pkg = await _resolveBuildContext._loadPkgWithReporting({
|
|
120
|
+
cwd
|
|
121
|
+
});
|
|
122
|
+
const config = await _resolveBuildContext._loadConfig({
|
|
123
|
+
cwd
|
|
124
|
+
});
|
|
125
|
+
const ctx = await _resolveBuildContext._resolveBuildContext({
|
|
126
|
+
config,
|
|
127
|
+
cwd,
|
|
128
|
+
pkg,
|
|
129
|
+
tsconfig
|
|
130
|
+
});
|
|
131
|
+
|
|
84
132
|
_printPackageTree(ctx);
|
|
133
|
+
|
|
85
134
|
if (strict) {
|
|
86
135
|
const missingFiles = [];
|
|
136
|
+
|
|
87
137
|
for (const [, exp] of Object.entries(ctx.exports || {})) {
|
|
88
138
|
if (exp.source && !_fileExists(path__default["default"].resolve(cwd, exp.source))) {
|
|
89
139
|
missingFiles.push(exp.source);
|
|
90
140
|
}
|
|
141
|
+
|
|
91
142
|
if (exp.require && !_fileExists(path__default["default"].resolve(cwd, exp.require))) {
|
|
92
143
|
missingFiles.push(exp.require);
|
|
93
144
|
}
|
|
145
|
+
|
|
94
146
|
if (exp.import && !_fileExists(path__default["default"].resolve(cwd, exp.import))) {
|
|
95
147
|
missingFiles.push(exp.import);
|
|
96
148
|
}
|
|
149
|
+
|
|
97
150
|
if (exp.types && !_fileExists(path__default["default"].resolve(cwd, exp.types))) {
|
|
98
151
|
missingFiles.push(exp.types);
|
|
99
152
|
}
|
|
100
153
|
}
|
|
154
|
+
|
|
101
155
|
if (missingFiles.length) {
|
|
102
156
|
throw new Error("missing files");
|
|
103
157
|
}
|
|
158
|
+
|
|
104
159
|
const _paths = {
|
|
105
160
|
require: [],
|
|
106
161
|
import: []
|
|
107
162
|
};
|
|
163
|
+
|
|
108
164
|
for (const [exportPath, exp] of Object.entries(ctx.exports || {})) {
|
|
109
|
-
if (!exp._exported)
|
|
110
|
-
|
|
111
|
-
if (exp.
|
|
112
|
-
_paths.require.push(exportPath);
|
|
113
|
-
if (exp.import)
|
|
114
|
-
_paths.import.push(exportPath);
|
|
165
|
+
if (!exp._exported) continue;
|
|
166
|
+
if (exp.require) _paths.require.push(exportPath);
|
|
167
|
+
if (exp.import) _paths.import.push(exportPath);
|
|
115
168
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
169
|
+
|
|
170
|
+
const external = Object.keys(pkg.dependencies || {}).concat(Object.keys(pkg.devDependencies || {}));
|
|
171
|
+
|
|
119
172
|
if (_paths.import.length) {
|
|
120
|
-
const code = _paths.import.map(
|
|
173
|
+
const code = _paths.import.map(id => "import('".concat(id, "')")).join("\n");
|
|
174
|
+
|
|
121
175
|
try {
|
|
122
176
|
const esbuildResult = await esbuild__default["default"].build({
|
|
123
177
|
external,
|
|
@@ -132,29 +186,34 @@ async function check(options) {
|
|
|
132
186
|
outfile: "/dev/null",
|
|
133
187
|
platform: "node"
|
|
134
188
|
});
|
|
189
|
+
|
|
135
190
|
if (esbuildResult.warnings.length > 0) {
|
|
136
191
|
console.warn(...esbuildResult.warnings);
|
|
137
192
|
}
|
|
138
193
|
} catch (err) {
|
|
139
|
-
const {
|
|
194
|
+
const {
|
|
195
|
+
errors
|
|
196
|
+
} = err;
|
|
197
|
+
|
|
140
198
|
for (const _err of errors) {
|
|
141
199
|
if (_err.location) {
|
|
142
200
|
console.log(chalk__default["default"].red("error"), _err.detail || _err.text);
|
|
143
|
-
console.log(
|
|
144
|
-
console.log(
|
|
145
|
-
"in",
|
|
146
|
-
`./${_err.location.file}:${_err.location.line}:${_err.location.column}`
|
|
147
|
-
);
|
|
201
|
+
console.log("".concat(_err.location.line, " | ").concat(_err.location.lineText));
|
|
202
|
+
console.log("in", "./".concat(_err.location.file, ":").concat(_err.location.line, ":").concat(_err.location.column));
|
|
148
203
|
} else {
|
|
149
204
|
console.log(_err.detail || _err.text);
|
|
150
205
|
}
|
|
206
|
+
|
|
151
207
|
console.log();
|
|
152
208
|
}
|
|
209
|
+
|
|
153
210
|
process.exit(1);
|
|
154
211
|
}
|
|
155
212
|
}
|
|
213
|
+
|
|
156
214
|
if (_paths.require.length) {
|
|
157
|
-
const code = _paths.require.map(
|
|
215
|
+
const code = _paths.require.map(id => "require('".concat(id, "')")).join("\n");
|
|
216
|
+
|
|
158
217
|
const esbuildResult = await esbuild__default["default"].build({
|
|
159
218
|
external,
|
|
160
219
|
stdin: {
|
|
@@ -167,9 +226,11 @@ async function check(options) {
|
|
|
167
226
|
outfile: "/dev/null",
|
|
168
227
|
platform: "node"
|
|
169
228
|
});
|
|
229
|
+
|
|
170
230
|
if (esbuildResult.errors.length > 0) {
|
|
171
231
|
throw new Error(esbuildResult.errors.join(", "));
|
|
172
232
|
}
|
|
233
|
+
|
|
173
234
|
if (esbuildResult.warnings.length > 0) {
|
|
174
235
|
console.warn(...esbuildResult.warnings);
|
|
175
236
|
}
|
|
@@ -178,4 +239,4 @@ async function check(options) {
|
|
|
178
239
|
}
|
|
179
240
|
|
|
180
241
|
exports.check = check;
|
|
181
|
-
//# sourceMappingURL=_check-
|
|
242
|
+
//# sourceMappingURL=_check-04a1f749.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_check-04a1f749.cjs","sources":["../src/node/_getFilesize.ts","../src/node/_printPackageTree.ts","../src/node/check.ts"],"sourcesContent":["import {statSync} from 'fs'\nimport prettyBytes from 'pretty-bytes'\n\nexport function _getFilesize(file: string): string {\n const stats = statSync(file)\n\n return prettyBytes(stats.size)\n}\n","import fs from 'fs'\nimport path from 'path'\nimport chalk from 'chalk'\nimport treeify from 'treeify'\nimport {PkgExport, _BuildContext} from './_core'\nimport {_getFilesize} from './_getFilesize'\n\nexport function _fileExists(file: string): boolean {\n try {\n fs.accessSync(file)\n\n return true\n } catch (_) {\n return false\n }\n}\n\nfunction _getFileInfo(cwd: string, filePath: string) {\n const p = path.resolve(cwd, filePath)\n const exists = _fileExists(p)\n const size = exists ? _getFilesize(p) : undefined\n\n return {exists, size}\n}\n\nexport function _printPackageTree(ctx: _BuildContext): void {\n const {cwd, exports, logger, pkg} = ctx\n\n if (!exports) return\n\n logger.log(`${chalk.blue(pkg.name)}@${chalk.green(pkg.version)}`)\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const tree: Record<string, any> = {}\n\n if (pkg.bin) {\n tree.bin = pkg.bin\n }\n\n function _fileInfo(file: string) {\n const info = _getFileInfo(cwd, file)\n\n if (!info.size) {\n return `${chalk.gray(file)} ${chalk.red('does not exist')}`\n }\n\n return `${file} ${chalk.gray(info.size)}`\n }\n\n tree.exports = Object.fromEntries(\n Object.entries(exports)\n .filter(([, entry]) => entry._exported)\n .map(([exportPath, entry]) => {\n const exp: Omit<PkgExport, '_exported'> = {source: entry.source, default: entry.default}\n\n if (entry.browser) {\n exp.browser = {}\n\n if (entry.browser.import) exp.browser.import = _fileInfo(entry.browser.import)\n if (entry.browser.require) exp.browser.import = _fileInfo(entry.browser.require)\n }\n\n if (entry.import) exp.import = _fileInfo(entry.import)\n if (entry.require) exp.require = _fileInfo(entry.require)\n if (entry.types) exp.types = _fileInfo(entry.types)\n\n exp.default = _fileInfo(entry.default)\n\n return [chalk.green(path.join(pkg.name, exportPath)), exp]\n })\n )\n\n logger.log(treeify.asTree(tree, true, true))\n}\n","/* eslint-disable no-console */\n\nimport path from 'path'\nimport chalk from 'chalk'\nimport esbuild, {BuildFailure} from 'esbuild'\nimport {_loadConfig, _loadPkgWithReporting} from './_core'\nimport {_fileExists, _printPackageTree} from './_printPackageTree'\nimport {_resolveBuildContext} from './_resolveBuildContext'\n\n/** @public */\nexport async function check(options: {\n cwd: string\n strict?: boolean\n tsconfig?: string\n}): Promise<void> {\n const {cwd, strict, tsconfig = 'tsconfig.json'} = options\n\n const pkg = await _loadPkgWithReporting({cwd})\n const config = await _loadConfig({cwd})\n const ctx = await _resolveBuildContext({config, cwd, pkg, tsconfig})\n\n _printPackageTree(ctx)\n\n if (strict) {\n const missingFiles: string[] = []\n\n // Check if there are missing files\n for (const [, exp] of Object.entries(ctx.exports || {})) {\n if (exp.source && !_fileExists(path.resolve(cwd, exp.source))) {\n missingFiles.push(exp.source)\n }\n\n if (exp.require && !_fileExists(path.resolve(cwd, exp.require))) {\n missingFiles.push(exp.require)\n }\n\n if (exp.import && !_fileExists(path.resolve(cwd, exp.import))) {\n missingFiles.push(exp.import)\n }\n\n if (exp.types && !_fileExists(path.resolve(cwd, exp.types))) {\n missingFiles.push(exp.types)\n }\n }\n\n if (missingFiles.length) {\n throw new Error('missing files')\n }\n\n // Check if the files are resolved\n const _paths: {require: string[]; import: string[]} = {\n require: [],\n import: [],\n }\n\n for (const [exportPath, exp] of Object.entries(ctx.exports || {})) {\n if (!exp._exported) continue\n if (exp.require) _paths.require.push(exportPath)\n if (exp.import) _paths.import.push(exportPath)\n }\n\n const external = Object.keys(pkg.dependencies || {}).concat(\n Object.keys(pkg.devDependencies || {})\n )\n\n if (_paths.import.length) {\n const code = _paths.import.map((id) => `import('${id}')`).join('\\n')\n\n try {\n const esbuildResult = await esbuild.build({\n external,\n stdin: {\n contents: code,\n loader: 'js',\n resolveDir: cwd,\n },\n format: 'esm',\n bundle: true,\n logLevel: 'silent',\n // otherwise output maps to stdout as we're using stdin\n outfile: '/dev/null',\n platform: 'node',\n })\n\n if (esbuildResult.warnings.length > 0) {\n console.warn(...esbuildResult.warnings)\n }\n } catch (err) {\n const {errors} = err as BuildFailure\n\n for (const _err of errors) {\n if (_err.location) {\n console.log(chalk.red('error'), _err.detail || _err.text)\n console.log(`${_err.location.line} | ${_err.location.lineText}`)\n console.log(\n 'in',\n `./${_err.location.file}:${_err.location.line}:${_err.location.column}`\n )\n } else {\n console.log(_err.detail || _err.text)\n }\n\n console.log()\n }\n\n process.exit(1)\n }\n }\n\n if (_paths.require.length) {\n const code = _paths.require.map((id) => `require('${id}')`).join('\\n')\n\n const esbuildResult = await esbuild.build({\n external,\n stdin: {\n contents: code,\n loader: 'js',\n resolveDir: cwd,\n },\n format: 'cjs',\n bundle: true,\n // otherwise output maps to stdout as we're using stdin\n outfile: '/dev/null',\n platform: 'node',\n })\n\n if (esbuildResult.errors.length > 0) {\n throw new Error(esbuildResult.errors.join(', '))\n }\n\n if (esbuildResult.warnings.length > 0) {\n console.warn(...esbuildResult.warnings)\n }\n }\n }\n}\n"],"names":["_getFilesize","file","stats","statSync","prettyBytes","size","_fileExists","fs","accessSync","_","_getFileInfo","cwd","filePath","p","path","resolve","exists","_printPackageTree","ctx","exports","logger","pkg","log","chalk","blue","name","green","version","tree","bin","_fileInfo","info","gray","red","Object","fromEntries","entries","filter","entry","_exported","map","exportPath","exp","source","default","browser","import","require","types","join","treeify","asTree","check","options","strict","tsconfig","_loadPkgWithReporting","config","_loadConfig","_resolveBuildContext","missingFiles","push","length","Error","_paths","external","keys","dependencies","concat","devDependencies","code","id","esbuildResult","esbuild","build","stdin","contents","loader","resolveDir","format","bundle","logLevel","outfile","platform","warnings","console","warn","err","errors","_err","location","detail","text","line","lineText","column","process","exit"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEO,SAASA,YAAT,CAAsBC,IAAtB,EAA4B;EACjC,MAAMC,KAAK,GAAGC,WAAAA,CAASF,IAATE,CAAd;EACA,OAAOC,oBAAW,CAAA,SAAA,CAAXA,CAAYF,KAAK,CAACG,IAAlBD,CAAP;AACF;;ACAO,SAASE,WAAT,CAAqBL,IAArB,EAA2B;EAChC,IAAI;IACFM,sBAAAA,CAAGC,UAAHD,CAAcN,IAAdM;IACA,OAAO,IAAP;EACD,CAHD,CAGE,OAAOE,CAAP,EAAU;IACV,OAAO,KAAP;EACD;AACF;;AACD,SAASC,YAAT,CAAsBC,GAAtB,EAA2BC,QAA3B,EAAqC;EACnC,MAAMC,CAAC,GAAGC,aAAI,CAAA,SAAA,CAAJA,CAAKC,OAALD,CAAaH,GAAbG,EAAkBF,QAAlBE,CAAV;;EACA,MAAME,MAAM,GAAGV,WAAW,CAACO,CAAD,CAA1B;;EACA,MAAMR,IAAI,GAAGW,MAAM,GAAGhB,YAAY,CAACa,CAAD,CAAf,GAAqB,KAAK,CAA7C;EACA,OAAO;IAAEG,MAAF;IAAUX;EAAV,CAAP;AACD;;AACM,SAASY,iBAAT,CAA2BC,GAA3B,EAAgC;EACrC,MAAM;IAAEP,GAAF;IAAOQ,OAAP;IA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