|
8 | 8 | /* eslint-env es2021, node */
|
9 | 9 |
|
10 | 10 | import _ from 'lodash';
|
11 |
| -import deeps from 'deeps'; |
12 | 11 |
|
13 | 12 | import os from 'node:os';
|
14 | 13 | import fs from 'node:fs';
|
@@ -61,27 +60,6 @@ const npmjsConfigVersion = '1.0.2'; // Bump when config changes in routines belo
|
61 | 60 |
|
62 | 61 | const c10nLogo = path.resolve(__dirname, '../../assets/brands/c10n/logo.png');
|
63 | 62 |
|
64 |
| -$obj.mc.addOperation('$default', (current, defaults) => { |
65 |
| - const paths = Object.keys(defaults); |
66 |
| - |
67 |
| - for (const path of paths) { |
68 |
| - if (undefined === deeps.get(current, path, '.')) { |
69 |
| - deeps.set(current, path, defaults[path], true, '.'); |
70 |
| - } |
71 |
| - } |
72 |
| - return paths.length > 0; |
73 |
| -}); |
74 |
| -$obj.mc.addOperation('$ꓺdefault', (current, defaults) => { |
75 |
| - const paths = Object.keys(defaults); |
76 |
| - |
77 |
| - for (const path of paths) { |
78 |
| - if (undefined === deeps.get(current, path, 'ꓺ')) { |
79 |
| - deeps.set(current, path, defaults[path], true, 'ꓺ'); |
80 |
| - } |
81 |
| - } |
82 |
| - return paths.length > 0; |
83 |
| -}); |
84 |
| - |
85 | 63 | /**
|
86 | 64 | * Utilities.
|
87 | 65 | */
|
@@ -182,53 +160,36 @@ export default class u {
|
182 | 160 | }
|
183 | 161 | }
|
184 | 162 |
|
185 |
| - static async updatePkg(propsOrPath, value = undefined, delimiter = '.') { |
| 163 | + static async updatePkg(propsOrPath = {}, value = undefined, delimiter = '.') { |
186 | 164 | const pkg = await u.pkg(); // Parses current `./package.json` file.
|
187 | 165 |
|
188 | 166 | if (typeof propsOrPath === 'string') {
|
189 | 167 | const path = propsOrPath; // String path.
|
190 |
| - deeps.set(pkg, path, value, true, delimiter); |
| 168 | + $obj.mc.u.set(pkg, path, value, false, delimiter); |
191 | 169 | //
|
192 | 170 | } else if (_.isPlainObject(propsOrPath)) {
|
193 | 171 | const props = propsOrPath; // Object props.
|
194 | 172 | $obj.mc.patch(pkg, props); // Potentially declarative ops.
|
195 | 173 | } else {
|
196 | 174 | throw new Error('u.updatePkg: Invalid arguments.');
|
197 | 175 | }
|
198 |
| - await fsp.writeFile(pkgFile, JSON.stringify(pkg, null, 4)); |
199 |
| - await u.prettifyPkg(); // Sorts and runs prettier. |
200 |
| - } |
201 |
| - |
202 |
| - static async prettifyPkg() { |
203 |
| - const pkg = {}; // Sorted `./package.json`; i.e., using insertion order. |
204 |
| - const curPkg = await u.pkg(); // Parses current `./package.json` file. |
205 |
| - |
206 | 176 | const updatesFile = path.resolve(projDir, './dev/.files/bin/updater/data/package.json/updates.json');
|
207 |
| - const sortOrderFile = path.resolve(projDir, './dev/.files/bin/updater/data/package.json/sort-order.json'); |
208 |
| - |
209 | 177 | const updates = JSON.parse((await fsp.readFile(updatesFile)).toString());
|
210 |
| - const sortOrder = JSON.parse((await fsp.readFile(sortOrderFile)).toString()); |
211 | 178 |
|
212 | 179 | if (!_.isPlainObject(updates)) {
|
213 |
| - throw new Error('u.prettifyPkg: Unable to parse `' + updatesFile + '`.'); |
214 |
| - } |
215 |
| - if (!Array.isArray(sortOrder)) { |
216 |
| - throw new Error('u.prettifyPkg: Unable to parse `' + sortOrderFile + '`.'); |
| 180 | + throw new Error('u.updatePkg: Unable to parse `' + updatesFile + '`.'); |
217 | 181 | }
|
218 | 182 | if (await u.isPkgRepo('clevercanyon/skeleton-dev-deps')) {
|
219 | 183 | if (updates.$ꓺdefault?.['devDependenciesꓺ@clevercanyon/skeleton-dev-deps']) {
|
220 | 184 | delete updates.$ꓺdefault['devDependenciesꓺ@clevercanyon/skeleton-dev-deps'];
|
221 | 185 | }
|
| 186 | + if (Array.isArray(updates.$ꓺunset)) { |
| 187 | + updates.$ꓺunset.push('devDependenciesꓺ@clevercanyon/skeleton-dev-deps'); |
| 188 | + } else { |
| 189 | + updates.$ꓺunset = ['devDependenciesꓺ@clevercanyon/skeleton-dev-deps']; |
| 190 | + } |
222 | 191 | }
|
223 |
| - $obj.mc.patch(curPkg, updates); // Potentially declarative ops. |
224 |
| - |
225 |
| - for (const path of sortOrder) { |
226 |
| - const value = deeps.get(curPkg, path, 'ꓺ'); |
227 |
| - if (undefined !== value) deeps.set(pkg, path, value, true, 'ꓺ'); |
228 |
| - } |
229 |
| - for (const [path, value] of Object.entries(deeps.flatten(curPkg, 'ꓺ'))) { |
230 |
| - if (undefined === deeps.get(pkg, path, 'ꓺ')) deeps.set(pkg, path, value, true, 'ꓺ'); |
231 |
| - } |
| 192 | + $obj.mc.patch(pkg, updates); // Potentially declarative ops. |
232 | 193 | const pkgPrettierCfg = { ...(await prettier.resolveConfig(pkgFile)), parser: 'json' };
|
233 | 194 | await fsp.writeFile(pkgFile, prettier.format(JSON.stringify(pkg, null, 4), pkgPrettierCfg));
|
234 | 195 | }
|
@@ -1092,7 +1053,7 @@ export default class u {
|
1092 | 1053 |
|
1093 | 1054 | static async npmUpdate() {
|
1094 | 1055 | await u.spawn('npm', ['update', '--save'], { stdio: 'inherit' });
|
1095 |
| - await u.prettifyPkg(); // To our standards. |
| 1056 | + await u.updatePkg(); // To our standards. |
1096 | 1057 | }
|
1097 | 1058 |
|
1098 | 1059 | static async npmPublish(opts = { dryRun: false }) {
|
|
0 commit comments