@quilted/create 0.1.21 → 0.1.24

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.
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index.cjs');
4
- var path = require('path');
5
- var fs = require('fs');
6
- var url = require('url');
3
+ var path = require('node:path');
4
+ var fs = require('node:fs');
5
+ var node_url = require('node:url');
6
+ require('./index.cjs');
7
7
 
8
8
  function _interopNamespace(e) {
9
9
  if (e && e.__esModule) return e;
@@ -26,296 +26,84 @@ function _interopNamespace(e) {
26
26
  var path__namespace = /*#__PURE__*/_interopNamespace(path);
27
27
  var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
28
28
 
29
- function _arrayWithHoles(arr) {
30
- if (Array.isArray(arr)) return arr;
31
- }
32
-
33
- function _iterableToArrayLimit(arr, i) {
34
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
35
-
36
- if (_i == null) return;
37
- var _arr = [];
38
- var _n = true;
39
- var _d = false;
40
-
41
- var _s, _e;
42
-
43
- try {
44
- for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
45
- _arr.push(_s.value);
46
-
47
- if (i && _arr.length === i) break;
48
- }
49
- } catch (err) {
50
- _d = true;
51
- _e = err;
52
- } finally {
53
- try {
54
- if (!_n && _i["return"] != null) _i["return"]();
55
- } finally {
56
- if (_d) throw _e;
57
- }
58
- }
59
-
60
- return _arr;
61
- }
62
-
63
- function _arrayLikeToArray$3(arr, len) {
64
- if (len == null || len > arr.length) len = arr.length;
65
-
66
- for (var i = 0, arr2 = new Array(len); i < len; i++) {
67
- arr2[i] = arr[i];
68
- }
69
-
70
- return arr2;
71
- }
72
-
73
- function _unsupportedIterableToArray$3(o, minLen) {
74
- if (!o) return;
75
- if (typeof o === "string") return _arrayLikeToArray$3(o, minLen);
76
- var n = Object.prototype.toString.call(o).slice(8, -1);
77
- if (n === "Object" && o.constructor) n = o.constructor.name;
78
- if (n === "Map" || n === "Set") return Array.from(o);
79
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$3(o, minLen);
80
- }
81
-
82
- function _nonIterableRest() {
83
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
84
- }
85
-
86
- function _slicedToArray(arr, i) {
87
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray$3(arr, i) || _nonIterableRest();
88
- }
89
-
90
- function _createForOfIteratorHelper$2(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$2(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
91
-
92
- function _unsupportedIterableToArray$2(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$2(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$2(o, minLen); }
93
-
94
- function _arrayLikeToArray$2(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
95
29
  function loadTemplate(name) {
96
- var templateRootPromise;
30
+ let templateRootPromise;
97
31
  return {
98
- copy: function copy(to, handleFile) {
99
- return index._asyncToGenerator( /*#__PURE__*/index.regenerator.mark(function _callee() {
100
- var _templateRootPromise;
101
-
102
- var templateRoot, targetRoot, files, _iterator, _step, _file, targetPath;
103
-
104
- return index.regenerator.wrap(function _callee$(_context) {
105
- while (1) {
106
- switch (_context.prev = _context.next) {
107
- case 0:
108
- (_templateRootPromise = templateRootPromise) !== null && _templateRootPromise !== void 0 ? _templateRootPromise : templateRootPromise = templateDirectory(name);
109
- _context.next = 3;
110
- return templateRootPromise;
111
-
112
- case 3:
113
- templateRoot = _context.sent;
114
- targetRoot = path__namespace.resolve(to);
115
- files = fs__namespace.readdirSync(templateRoot).filter(function (file) {
116
- return !path__namespace.basename(file).startsWith('.');
117
- });
118
- _iterator = _createForOfIteratorHelper$2(files);
119
- _context.prev = 7;
120
-
121
- _iterator.s();
122
-
123
- case 9:
124
- if ((_step = _iterator.n()).done) {
125
- _context.next = 18;
126
- break;
127
- }
128
-
129
- _file = _step.value;
130
-
131
- if (!handleFile) {
132
- _context.next = 14;
133
- break;
134
- }
135
-
136
- if (handleFile(_file)) {
137
- _context.next = 14;
138
- break;
139
- }
140
-
141
- return _context.abrupt("continue", 16);
142
-
143
- case 14:
144
- targetPath = path__namespace.join(targetRoot, _file.startsWith('_') ? ".".concat(_file.slice(1)) : _file);
145
-
146
- _copy(path__namespace.join(templateRoot, _file), targetPath);
147
-
148
- case 16:
149
- _context.next = 9;
150
- break;
151
-
152
- case 18:
153
- _context.next = 23;
154
- break;
155
-
156
- case 20:
157
- _context.prev = 20;
158
- _context.t0 = _context["catch"](7);
159
-
160
- _iterator.e(_context.t0);
161
-
162
- case 23:
163
- _context.prev = 23;
32
+ async copy(to, handleFile) {
33
+ var _templateRootPromise;
34
+
35
+ (_templateRootPromise = templateRootPromise) !== null && _templateRootPromise !== void 0 ? _templateRootPromise : templateRootPromise = templateDirectory(name);
36
+ const templateRoot = await templateRootPromise;
37
+ const targetRoot = path__namespace.resolve(to);
38
+ const files = fs__namespace.readdirSync(templateRoot).filter(file => !path__namespace.basename(file).startsWith('.'));
39
+
40
+ for (const file of files) {
41
+ if (handleFile) {
42
+ if (!handleFile(file)) {
43
+ continue;
44
+ }
45
+ }
164
46
 
165
- _iterator.f();
47
+ const targetPath = path__namespace.join(targetRoot, file.startsWith('_') ? `.${file.slice(1)}` : file);
48
+ copy(path__namespace.join(templateRoot, file), targetPath);
49
+ }
50
+ },
166
51
 
167
- return _context.finish(23);
52
+ async read(file) {
53
+ var _templateRootPromise2;
168
54
 
169
- case 26:
170
- case "end":
171
- return _context.stop();
172
- }
173
- }
174
- }, _callee, null, [[7, 20, 23, 26]]);
175
- }))();
176
- },
177
- read: function read(file) {
178
- return index._asyncToGenerator( /*#__PURE__*/index.regenerator.mark(function _callee2() {
179
- var _templateRootPromise2;
180
-
181
- var templateRoot;
182
- return index.regenerator.wrap(function _callee2$(_context2) {
183
- while (1) {
184
- switch (_context2.prev = _context2.next) {
185
- case 0:
186
- (_templateRootPromise2 = templateRootPromise) !== null && _templateRootPromise2 !== void 0 ? _templateRootPromise2 : templateRootPromise = templateDirectory(name);
187
- _context2.next = 3;
188
- return templateRootPromise;
189
-
190
- case 3:
191
- templateRoot = _context2.sent;
192
- return _context2.abrupt("return", fs__namespace.readFileSync(path__namespace.join(templateRoot, file), {
193
- encoding: 'utf8'
194
- }));
195
-
196
- case 5:
197
- case "end":
198
- return _context2.stop();
199
- }
200
- }
201
- }, _callee2);
202
- }))();
55
+ (_templateRootPromise2 = templateRootPromise) !== null && _templateRootPromise2 !== void 0 ? _templateRootPromise2 : templateRootPromise = templateDirectory(name);
56
+ const templateRoot = await templateRootPromise;
57
+ return fs__namespace.readFileSync(path__namespace.join(templateRoot, file), {
58
+ encoding: 'utf8'
59
+ });
203
60
  }
61
+
204
62
  };
205
63
  }
206
64
  function createOutputTarget(target) {
207
65
  return {
208
66
  root: target,
209
- read: function read(file) {
67
+
68
+ read(file) {
210
69
  return fs__namespace.promises.readFile(path__namespace.resolve(target, file), {
211
70
  encoding: 'utf8'
212
71
  });
213
72
  },
214
- write: function write(file, content) {
215
- return index._asyncToGenerator( /*#__PURE__*/index.regenerator.mark(function _callee3() {
216
- return index.regenerator.wrap(function _callee3$(_context3) {
217
- while (1) {
218
- switch (_context3.prev = _context3.next) {
219
- case 0:
220
- _context3.next = 2;
221
- return writeFile(path__namespace.resolve(target, file), content);
222
-
223
- case 2:
224
- case "end":
225
- return _context3.stop();
226
- }
227
- }
228
- }, _callee3);
229
- }))();
73
+
74
+ async write(file, content) {
75
+ await writeFile(path__namespace.resolve(target, file), content);
230
76
  }
77
+
231
78
  };
232
79
  }
233
- var packageRootPromise;
80
+ let packageRootPromise;
234
81
 
235
- function templateDirectory(_x) {
236
- return _templateDirectory.apply(this, arguments);
82
+ async function templateDirectory(name) {
83
+ return path__namespace.join(await getPackageRoot(), 'templates', name);
237
84
  }
238
85
 
239
- function _templateDirectory() {
240
- _templateDirectory = index._asyncToGenerator( /*#__PURE__*/index.regenerator.mark(function _callee4(name) {
241
- return index.regenerator.wrap(function _callee4$(_context4) {
242
- while (1) {
243
- switch (_context4.prev = _context4.next) {
244
- case 0:
245
- _context4.t0 = path__namespace;
246
- _context4.next = 3;
247
- return getPackageRoot();
248
-
249
- case 3:
250
- _context4.t1 = _context4.sent;
251
- _context4.t2 = name;
252
- return _context4.abrupt("return", _context4.t0.join.call(_context4.t0, _context4.t1, 'templates', _context4.t2));
253
-
254
- case 6:
255
- case "end":
256
- return _context4.stop();
257
- }
258
- }
259
- }, _callee4);
260
- }));
261
- return _templateDirectory.apply(this, arguments);
262
- }
86
+ async function getPackageRoot() {
87
+ if (!packageRootPromise) {
88
+ packageRootPromise = (async () => {
89
+ const {
90
+ packageDirectory
91
+ } = await Promise.resolve().then(function () { return require('./index2.cjs'); });
92
+ return packageDirectory({
93
+ cwd: path__namespace.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('package-manager.cjs', document.baseURI).href))))
94
+ });
95
+ })();
96
+ }
263
97
 
264
- function getPackageRoot() {
265
- return _getPackageRoot.apply(this, arguments);
266
- }
267
-
268
- function _getPackageRoot() {
269
- _getPackageRoot = index._asyncToGenerator( /*#__PURE__*/index.regenerator.mark(function _callee6() {
270
- return index.regenerator.wrap(function _callee6$(_context6) {
271
- while (1) {
272
- switch (_context6.prev = _context6.next) {
273
- case 0:
274
- if (!packageRootPromise) {
275
- packageRootPromise = index._asyncToGenerator( /*#__PURE__*/index.regenerator.mark(function _callee5() {
276
- var _yield$import, packageDirectory;
277
-
278
- return index.regenerator.wrap(function _callee5$(_context5) {
279
- while (1) {
280
- switch (_context5.prev = _context5.next) {
281
- case 0:
282
- _context5.next = 2;
283
- return Promise.resolve().then(function () { return require('./index2.cjs'); });
284
-
285
- case 2:
286
- _yield$import = _context5.sent;
287
- packageDirectory = _yield$import.packageDirectory;
288
- return _context5.abrupt("return", packageDirectory({
289
- cwd: path__namespace.dirname(url.fileURLToPath((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('package-manager.cjs', document.baseURI).href))))
290
- }));
291
-
292
- case 5:
293
- case "end":
294
- return _context5.stop();
295
- }
296
- }
297
- }, _callee5);
298
- }))();
299
- }
300
-
301
- return _context6.abrupt("return", packageRootPromise);
302
-
303
- case 2:
304
- case "end":
305
- return _context6.stop();
306
- }
307
- }
308
- }, _callee6);
309
- }));
310
- return _getPackageRoot.apply(this, arguments);
98
+ return packageRootPromise;
311
99
  }
312
100
 
313
101
  function toValidPackageName(projectName) {
314
102
  return projectName.trim().toLowerCase().replace(/\s+/g, '-').replace(/^[._]/, '').replace(/[^a-z0-9-~@/]+/g, '-');
315
103
  }
316
104
 
317
- function _copy(source, destination) {
318
- var stat = fs__namespace.statSync(source);
105
+ function copy(source, destination) {
106
+ const stat = fs__namespace.statSync(source);
319
107
 
320
108
  if (stat.isDirectory()) {
321
109
  copyDirectory(source, destination);
@@ -324,578 +112,212 @@ function _copy(source, destination) {
324
112
  }
325
113
  }
326
114
 
327
- function copyDirectory(_x2, _x3) {
328
- return _copyDirectory.apply(this, arguments);
329
- }
330
-
331
- function _copyDirectory() {
332
- _copyDirectory = index._asyncToGenerator( /*#__PURE__*/index.regenerator.mark(function _callee7(source, destination) {
333
- var _iterator2, _step2, _file2, srcFile, destFile;
334
-
335
- return index.regenerator.wrap(function _callee7$(_context7) {
336
- while (1) {
337
- switch (_context7.prev = _context7.next) {
338
- case 0:
339
- fs__namespace.mkdirSync(destination, {
340
- recursive: true
341
- });
342
- _iterator2 = _createForOfIteratorHelper$2(fs__namespace.readdirSync(source));
343
-
344
- try {
345
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
346
- _file2 = _step2.value;
347
- srcFile = path__namespace.resolve(source, _file2);
348
- destFile = path__namespace.resolve(destination, _file2);
349
-
350
- _copy(srcFile, destFile);
351
- }
352
- } catch (err) {
353
- _iterator2.e(err);
354
- } finally {
355
- _iterator2.f();
356
- }
357
-
358
- case 3:
359
- case "end":
360
- return _context7.stop();
361
- }
362
- }
363
- }, _callee7);
364
- }));
365
- return _copyDirectory.apply(this, arguments);
366
- }
367
-
368
- function writeFile(_x4, _x5) {
369
- return _writeFile.apply(this, arguments);
370
- }
115
+ async function copyDirectory(source, destination) {
116
+ fs__namespace.mkdirSync(destination, {
117
+ recursive: true
118
+ });
371
119
 
372
- function _writeFile() {
373
- _writeFile = index._asyncToGenerator( /*#__PURE__*/index.regenerator.mark(function _callee8(file, content) {
374
- return index.regenerator.wrap(function _callee8$(_context8) {
375
- while (1) {
376
- switch (_context8.prev = _context8.next) {
377
- case 0:
378
- _context8.next = 2;
379
- return fs__namespace.promises.writeFile(file, content);
380
-
381
- case 2:
382
- case "end":
383
- return _context8.stop();
384
- }
385
- }
386
- }, _callee8);
387
- }));
388
- return _writeFile.apply(this, arguments);
120
+ for (const file of fs__namespace.readdirSync(source)) {
121
+ const srcFile = path__namespace.resolve(source, file);
122
+ const destFile = path__namespace.resolve(destination, file);
123
+ copy(srcFile, destFile);
124
+ }
389
125
  }
390
126
 
391
- function isEmpty(_x6) {
392
- return _isEmpty.apply(this, arguments);
127
+ async function writeFile(file, content) {
128
+ await fs__namespace.promises.writeFile(file, content);
393
129
  }
394
-
395
- function _isEmpty() {
396
- _isEmpty = index._asyncToGenerator( /*#__PURE__*/index.regenerator.mark(function _callee9(path) {
397
- return index.regenerator.wrap(function _callee9$(_context9) {
398
- while (1) {
399
- switch (_context9.prev = _context9.next) {
400
- case 0:
401
- return _context9.abrupt("return", fs__namespace.readdirSync(path).length === 0);
402
-
403
- case 1:
404
- case "end":
405
- return _context9.stop();
406
- }
407
- }
408
- }, _callee9);
409
- }));
410
- return _isEmpty.apply(this, arguments);
411
- }
412
-
413
- function emptyDirectory(_x7) {
414
- return _emptyDirectory.apply(this, arguments);
130
+ async function isEmpty(path) {
131
+ return fs__namespace.readdirSync(path).length === 0;
415
132
  }
133
+ async function emptyDirectory(dir) {
134
+ if (!fs__namespace.existsSync(dir)) {
135
+ return;
136
+ }
416
137
 
417
- function _emptyDirectory() {
418
- _emptyDirectory = index._asyncToGenerator( /*#__PURE__*/index.regenerator.mark(function _callee10(dir) {
419
- var _iterator3, _step3, _file3;
420
-
421
- return index.regenerator.wrap(function _callee10$(_context10) {
422
- while (1) {
423
- switch (_context10.prev = _context10.next) {
424
- case 0:
425
- if (fs__namespace.existsSync(dir)) {
426
- _context10.next = 2;
427
- break;
428
- }
429
-
430
- return _context10.abrupt("return");
431
-
432
- case 2:
433
- _iterator3 = _createForOfIteratorHelper$2(fs__namespace.readdirSync(dir));
434
-
435
- try {
436
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
437
- _file3 = _step3.value;
438
- fs__namespace.rmSync(path__namespace.resolve(dir, _file3), {
439
- force: true,
440
- recursive: true
441
- });
442
- }
443
- } catch (err) {
444
- _iterator3.e(err);
445
- } finally {
446
- _iterator3.f();
447
- }
448
-
449
- case 4:
450
- case "end":
451
- return _context10.stop();
452
- }
453
- }
454
- }, _callee10);
455
- }));
456
- return _emptyDirectory.apply(this, arguments);
138
+ for (const file of fs__namespace.readdirSync(dir)) {
139
+ fs__namespace.rmSync(path__namespace.resolve(dir, file), {
140
+ force: true,
141
+ recursive: true
142
+ });
143
+ }
457
144
  }
458
-
459
145
  function relativeDirectoryForDisplay(relativeDirectory) {
460
- return relativeDirectory.startsWith('.') ? relativeDirectory : ".".concat(path__namespace.sep).concat(relativeDirectory);
461
- }
462
- function format(_x8, _x9) {
463
- return _format.apply(this, arguments);
464
- }
465
-
466
- function _format() {
467
- _format = index._asyncToGenerator( /*#__PURE__*/index.regenerator.mark(function _callee11(content, _ref) {
468
- var parser, _yield$Promise$all, _yield$Promise$all2, format, babel, yaml;
469
-
470
- return index.regenerator.wrap(function _callee11$(_context11) {
471
- while (1) {
472
- switch (_context11.prev = _context11.next) {
473
- case 0:
474
- parser = _ref.as;
475
- _context11.next = 3;
476
- return Promise.all([Promise.resolve().then(function () { return require('./standalone.cjs'); }).then(function (n) { return n.standalone; }), Promise.resolve().then(function () { return require('./parser-babel.cjs'); }).then(function (n) { return n.parserBabel; }), Promise.resolve().then(function () { return require('./parser-yaml.cjs'); }).then(function (n) { return n.parserYaml; })]);
477
-
478
- case 3:
479
- _yield$Promise$all = _context11.sent;
480
- _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 3);
481
- format = _yield$Promise$all2[0].format;
482
- babel = _yield$Promise$all2[1]["default"];
483
- yaml = _yield$Promise$all2[2]["default"];
484
- return _context11.abrupt("return", format(content, {
485
- arrowParens: 'always',
486
- bracketSpacing: false,
487
- singleQuote: true,
488
- trailingComma: 'all',
489
- parser: parser,
490
- plugins: [babel, yaml]
491
- }));
492
-
493
- case 9:
494
- case "end":
495
- return _context11.stop();
496
- }
497
- }
498
- }, _callee11);
499
- }));
500
- return _format.apply(this, arguments);
501
- }
502
-
503
- function _createForOfIteratorHelper$1(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$1(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
146
+ return relativeDirectory.startsWith('.') ? relativeDirectory : `.${path__namespace.sep}${relativeDirectory}`;
147
+ }
148
+ async function format(content, {
149
+ as: parser
150
+ }) {
151
+ const [{
152
+ format
153
+ }, {
154
+ default: babel
155
+ }, {
156
+ default: typescript
157
+ }, {
158
+ default: yaml
159
+ }] = await Promise.all([Promise.resolve().then(function () { return require('./standalone.cjs'); }).then(function (n) { return n.standalone; }), Promise.resolve().then(function () { return require('./parser-babel.cjs'); }).then(function (n) { return n.parserBabel; }), Promise.resolve().then(function () { return require('./parser-typescript.cjs'); }).then(function (n) { return n.parserTypescript; }), Promise.resolve().then(function () { return require('./parser-yaml.cjs'); }).then(function (n) { return n.parserYaml; })]);
160
+ return format(content, {
161
+ arrowParens: 'always',
162
+ bracketSpacing: false,
163
+ singleQuote: true,
164
+ trailingComma: 'all',
165
+ parser,
166
+ plugins: [babel, typescript, yaml]
167
+ });
168
+ }
169
+ function mergeDependencies(first = {}, second = {}) {
170
+ const all = { ...first,
171
+ ...second
172
+ };
173
+ const merged = {};
504
174
 
505
- function _unsupportedIterableToArray$1(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$1(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$1(o, minLen); }
175
+ for (const [key, value] of Object.entries(all).sort(([keyOne], [keyTwo]) => keyOne.localeCompare(keyTwo))) {
176
+ merged[key] = value;
177
+ }
506
178
 
507
- function _arrayLikeToArray$1(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
508
- var ENDS_WITH_TSCONFIG = /[/]?tsconfig[.a-z0-9]*[.]json/i;
509
- function addToTsConfig(_x, _x2) {
510
- return _addToTsConfig.apply(this, arguments);
179
+ return merged;
511
180
  }
512
181
 
513
- function _addToTsConfig() {
514
- _addToTsConfig = index._asyncToGenerator( /*#__PURE__*/index.regenerator.mark(function _callee(directory, output) {
515
- var _tsconfig$references;
516
-
517
- var tsconfig, relativePath, relativeForDisplay, hasExistingReference, referenceFormat, _iterator, _step, _path, path$1;
518
-
519
- return index.regenerator.wrap(function _callee$(_context) {
520
- while (1) {
521
- switch (_context.prev = _context.next) {
522
- case 0:
523
- _context.t0 = JSON;
524
- _context.next = 3;
525
- return output.read('tsconfig.json');
526
-
527
- case 3:
528
- _context.t1 = _context.sent;
529
- tsconfig = _context.t0.parse.call(_context.t0, _context.t1);
530
- (_tsconfig$references = tsconfig.references) !== null && _tsconfig$references !== void 0 ? _tsconfig$references : tsconfig.references = [];
531
- relativePath = path.relative(output.root, directory);
532
- relativeForDisplay = relativeDirectoryForDisplay(relativePath);
533
-
534
- if (!(tsconfig.references.length === 0)) {
535
- _context.next = 12;
536
- break;
537
- }
538
-
539
- tsconfig.references.push({
540
- path: relativeForDisplay
541
- });
542
- _context.next = 53;
543
- break;
544
-
545
- case 12:
546
- hasExistingReference = false;
547
- referenceFormat = 'pretty-relative';
548
- _iterator = _createForOfIteratorHelper$1(tsconfig.references);
549
- _context.prev = 15;
550
-
551
- _iterator.s();
182
+ const ENDS_WITH_TSCONFIG = /[/]?tsconfig[.a-z0-9]*[.]json/i;
183
+ async function addToTsConfig(directory, output) {
184
+ var _tsconfig$references;
552
185
 
553
- case 17:
554
- if ((_step = _iterator.n()).done) {
555
- _context.next = 44;
556
- break;
557
- }
186
+ const tsconfig = JSON.parse(await output.read('tsconfig.json'));
187
+ (_tsconfig$references = tsconfig.references) !== null && _tsconfig$references !== void 0 ? _tsconfig$references : tsconfig.references = [];
188
+ const relativePath = path.relative(output.root, directory);
189
+ const relativeForDisplay = relativeDirectoryForDisplay(relativePath);
558
190
 
559
- _path = _step.value.path;
560
-
561
- if (!_path.startsWith('./')) {
562
- _context.next = 31;
563
- break;
564
- }
565
-
566
- if (!ENDS_WITH_TSCONFIG.test(_path)) {
567
- _context.next = 25;
568
- break;
569
- }
570
-
571
- referenceFormat = 'pretty-tsconfig';
572
-
573
- if (!(_path === "".concat(relativeForDisplay, "/tsconfig.json"))) {
574
- _context.next = 25;
575
- break;
576
- }
577
-
578
- hasExistingReference = true;
579
- return _context.abrupt("break", 44);
580
-
581
- case 25:
582
- referenceFormat = 'pretty-relative';
583
-
584
- if (!(_path === relativeForDisplay)) {
585
- _context.next = 29;
586
- break;
587
- }
588
-
589
- hasExistingReference = true;
590
- return _context.abrupt("break", 44);
591
-
592
- case 29:
593
- _context.next = 42;
594
- break;
595
-
596
- case 31:
597
- if (!ENDS_WITH_TSCONFIG.test(_path)) {
598
- _context.next = 38;
599
- break;
600
- }
601
-
602
- referenceFormat = 'tsconfig';
191
+ if (tsconfig.references.length === 0) {
192
+ tsconfig.references.push({
193
+ path: relativeForDisplay
194
+ });
195
+ } else {
196
+ let hasExistingReference = false;
197
+ let referenceFormat = 'pretty-relative';
603
198
 
604
- if (!(_path === "".concat(relativePath, "/tsconfig.json"))) {
605
- _context.next = 36;
606
- break;
607
- }
199
+ for (const {
200
+ path
201
+ } of tsconfig.references) {
202
+ if (path.startsWith('./')) {
203
+ if (ENDS_WITH_TSCONFIG.test(path)) {
204
+ referenceFormat = 'pretty-tsconfig';
608
205
 
206
+ if (path === `${relativeForDisplay}/tsconfig.json`) {
609
207
  hasExistingReference = true;
610
- return _context.abrupt("break", 44);
611
-
612
- case 36:
613
- _context.next = 42;
614
208
  break;
209
+ }
210
+ }
615
211
 
616
- case 38:
617
- referenceFormat = 'relative';
618
-
619
- if (!(_path === relativePath)) {
620
- _context.next = 42;
621
- break;
622
- }
623
-
624
- hasExistingReference = true;
625
- return _context.abrupt("break", 44);
212
+ referenceFormat = 'pretty-relative';
626
213
 
627
- case 42:
628
- _context.next = 17;
629
- break;
214
+ if (path === relativeForDisplay) {
215
+ hasExistingReference = true;
216
+ break;
217
+ }
218
+ } else if (ENDS_WITH_TSCONFIG.test(path)) {
219
+ referenceFormat = 'tsconfig';
630
220
 
631
- case 44:
632
- _context.next = 49;
633
- break;
221
+ if (path === `${relativePath}/tsconfig.json`) {
222
+ hasExistingReference = true;
223
+ break;
224
+ }
225
+ } else {
226
+ referenceFormat = 'relative';
634
227
 
635
- case 46:
636
- _context.prev = 46;
637
- _context.t2 = _context["catch"](15);
638
-
639
- _iterator.e(_context.t2);
640
-
641
- case 49:
642
- _context.prev = 49;
643
-
644
- _iterator.f();
645
-
646
- return _context.finish(49);
647
-
648
- case 52:
649
- if (!hasExistingReference) {
650
- if (referenceFormat === 'pretty-tsconfig') {
651
- path$1 = "".concat(relativeForDisplay, "/tsconfig.json");
652
- } else if (referenceFormat === 'pretty-relative') {
653
- path$1 = relativeForDisplay;
654
- } else if (referenceFormat === 'tsconfig') {
655
- path$1 = "".concat(relativePath, "/tsconfig.json");
656
- } else {
657
- path$1 = relativePath;
658
- }
659
-
660
- tsconfig.references.push({
661
- path: path$1
662
- });
663
- }
664
-
665
- case 53:
666
- tsconfig.references = tsconfig.references.sort(function (_ref, _ref2) {
667
- var pathOne = _ref.path;
668
- var pathTwo = _ref2.path;
669
- return pathOne.localeCompare(pathTwo);
670
- });
671
- _context.t3 = output;
672
- _context.next = 57;
673
- return format(JSON.stringify(tsconfig), {
674
- as: 'json'
675
- });
676
-
677
- case 57:
678
- _context.t4 = _context.sent;
679
- _context.next = 60;
680
- return _context.t3.write.call(_context.t3, 'tsconfig.json', _context.t4);
681
-
682
- case 60:
683
- case "end":
684
- return _context.stop();
228
+ if (path === relativePath) {
229
+ hasExistingReference = true;
230
+ break;
685
231
  }
686
232
  }
687
- }, _callee, null, [[15, 46, 49, 52]]);
688
- }));
689
- return _addToTsConfig.apply(this, arguments);
690
- }
691
-
692
- function _arrayWithoutHoles(arr) {
693
- if (Array.isArray(arr)) return _arrayLikeToArray$3(arr);
694
- }
695
-
696
- function _iterableToArray(iter) {
697
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
698
- }
699
-
700
- function _nonIterableSpread() {
701
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
702
- }
703
-
704
- function _toConsumableArray(arr) {
705
- return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray$3(arr) || _nonIterableSpread();
706
- }
707
-
708
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
709
-
710
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
233
+ }
711
234
 
712
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
713
- function addToPackageManagerWorkspaces(_x, _x2, _x3) {
714
- return _addToPackageManagerWorkspaces.apply(this, arguments);
715
- }
235
+ if (!hasExistingReference) {
236
+ let path;
237
+
238
+ if (referenceFormat === 'pretty-tsconfig') {
239
+ path = `${relativeForDisplay}/tsconfig.json`;
240
+ } else if (referenceFormat === 'pretty-relative') {
241
+ path = relativeForDisplay;
242
+ } else if (referenceFormat === 'tsconfig') {
243
+ path = `${relativePath}/tsconfig.json`;
244
+ } else {
245
+ path = relativePath;
246
+ }
716
247
 
717
- function _addToPackageManagerWorkspaces() {
718
- _addToPackageManagerWorkspaces = index._asyncToGenerator( /*#__PURE__*/index.regenerator.mark(function _callee(directory, output, packageManager) {
719
- var _workspaceYaml$packag, _yield$import, parse, stringify, workspaceYaml, _packageJson$workspac, packageJson;
720
-
721
- return index.regenerator.wrap(function _callee$(_context) {
722
- while (1) {
723
- switch (_context.prev = _context.next) {
724
- case 0:
725
- if (!(packageManager === 'pnpm')) {
726
- _context.next = 22;
727
- break;
728
- }
729
-
730
- _context.next = 3;
731
- return Promise.resolve().then(function () { return require('./index3.cjs'); });
732
-
733
- case 3:
734
- _yield$import = _context.sent;
735
- parse = _yield$import.parse;
736
- stringify = _yield$import.stringify;
737
- _context.t0 = parse;
738
- _context.next = 9;
739
- return output.read('pnpm-workspace.yaml');
740
-
741
- case 9:
742
- _context.t1 = _context.sent;
743
- workspaceYaml = (0, _context.t0)(_context.t1);
744
- _context.next = 13;
745
- return addToWorkspaces(path.relative(output.root, directory), (_workspaceYaml$packag = workspaceYaml.packages) !== null && _workspaceYaml$packag !== void 0 ? _workspaceYaml$packag : []);
746
-
747
- case 13:
748
- workspaceYaml.packages = _context.sent;
749
- _context.t2 = output;
750
- _context.next = 17;
751
- return format(stringify(workspaceYaml), {
752
- as: 'yaml'
753
- });
754
-
755
- case 17:
756
- _context.t3 = _context.sent;
757
- _context.next = 20;
758
- return _context.t2.write.call(_context.t2, 'pnpm-workspace.yaml', _context.t3);
759
-
760
- case 20:
761
- _context.next = 36;
762
- break;
248
+ tsconfig.references.push({
249
+ path
250
+ });
251
+ }
252
+ }
763
253
 
764
- case 22:
765
- _context.t4 = JSON;
766
- _context.next = 25;
767
- return output.read('package.json');
768
-
769
- case 25:
770
- _context.t5 = _context.sent;
771
- packageJson = _context.t4.parse.call(_context.t4, _context.t5);
772
- _context.next = 29;
773
- return addToWorkspaces(path.relative(output.root, directory), (_packageJson$workspac = packageJson.workspaces) !== null && _packageJson$workspac !== void 0 ? _packageJson$workspac : []);
774
-
775
- case 29:
776
- packageJson.workspaces = _context.sent;
777
- _context.t6 = output;
778
- _context.next = 33;
779
- return format(JSON.stringify(packageJson), {
780
- as: 'json-stringify'
781
- });
782
-
783
- case 33:
784
- _context.t7 = _context.sent;
785
- _context.next = 36;
786
- return _context.t6.write.call(_context.t6, 'package.json', _context.t7);
787
-
788
- case 36:
789
- case "end":
790
- return _context.stop();
791
- }
792
- }
793
- }, _callee);
254
+ tsconfig.references = tsconfig.references.sort(({
255
+ path: pathOne
256
+ }, {
257
+ path: pathTwo
258
+ }) => pathOne.localeCompare(pathTwo));
259
+ await output.write('tsconfig.json', await format(JSON.stringify(tsconfig), {
260
+ as: 'json'
794
261
  }));
795
- return _addToPackageManagerWorkspaces.apply(this, arguments);
796
262
  }
797
263
 
798
- function addToWorkspaces(_x4, _x5) {
799
- return _addToWorkspaces.apply(this, arguments);
800
- }
264
+ async function addToPackageManagerWorkspaces(directory, output, packageManager) {
265
+ if (packageManager === 'pnpm') {
266
+ var _workspaceYaml$packag;
801
267
 
802
- function _addToWorkspaces() {
803
- _addToWorkspaces = index._asyncToGenerator( /*#__PURE__*/index.regenerator.mark(function _callee2(relative, workspaces) {
804
- var pretty, hasMatch, _yield$import2, minimatch, _iterator, _step, pattern, normalizedPattern;
805
-
806
- return index.regenerator.wrap(function _callee2$(_context2) {
807
- while (1) {
808
- switch (_context2.prev = _context2.next) {
809
- case 0:
810
- if (!(workspaces.length === 0)) {
811
- _context2.next = 2;
812
- break;
813
- }
814
-
815
- return _context2.abrupt("return", [relative]);
816
-
817
- case 2:
818
- // Default documentation seems to generally exclude leading `./` on paths
819
- pretty = false;
820
- hasMatch = false;
821
- _context2.next = 6;
822
- return Promise.resolve().then(function () { return require('./minimatch.cjs'); }).then(function (n) { return n.minimatch; });
823
-
824
- case 6:
825
- _yield$import2 = _context2.sent;
826
- minimatch = _yield$import2["default"];
827
- _iterator = _createForOfIteratorHelper(workspaces);
828
- _context2.prev = 9;
829
-
830
- _iterator.s();
831
-
832
- case 11:
833
- if ((_step = _iterator.n()).done) {
834
- _context2.next = 20;
835
- break;
836
- }
837
-
838
- pattern = _step.value;
839
- normalizedPattern = pattern;
840
-
841
- if (pattern.startsWith('./')) {
842
- pretty = true;
843
- normalizedPattern = pattern.slice(2);
844
- }
845
-
846
- if (!minimatch(relative, normalizedPattern)) {
847
- _context2.next = 18;
848
- break;
849
- }
850
-
851
- hasMatch = true;
852
- return _context2.abrupt("break", 20);
853
-
854
- case 18:
855
- _context2.next = 11;
856
- break;
857
-
858
- case 20:
859
- _context2.next = 25;
860
- break;
268
+ const {
269
+ parse,
270
+ stringify
271
+ } = await Promise.resolve().then(function () { return require('./index3.cjs'); }).then(function (n) { return n.index; });
272
+ const workspaceYaml = parse(await output.read('pnpm-workspace.yaml'));
273
+ workspaceYaml.packages = await addToWorkspaces(path.relative(output.root, directory), (_workspaceYaml$packag = workspaceYaml.packages) !== null && _workspaceYaml$packag !== void 0 ? _workspaceYaml$packag : []);
274
+ await output.write('pnpm-workspace.yaml', await format(stringify(workspaceYaml), {
275
+ as: 'yaml'
276
+ }));
277
+ } else {
278
+ var _packageJson$workspac;
861
279
 
862
- case 22:
863
- _context2.prev = 22;
864
- _context2.t0 = _context2["catch"](9);
280
+ const packageJson = JSON.parse(await output.read('package.json'));
281
+ packageJson.workspaces = await addToWorkspaces(path.relative(output.root, directory), (_packageJson$workspac = packageJson.workspaces) !== null && _packageJson$workspac !== void 0 ? _packageJson$workspac : []);
282
+ await output.write('package.json', await format(JSON.stringify(packageJson), {
283
+ as: 'json-stringify'
284
+ }));
285
+ }
286
+ }
865
287
 
866
- _iterator.e(_context2.t0);
288
+ async function addToWorkspaces(relative, workspaces) {
289
+ if (workspaces.length === 0) {
290
+ return [relative];
291
+ } // Default documentation seems to generally exclude leading `./` on paths
867
292
 
868
- case 25:
869
- _context2.prev = 25;
870
293
 
871
- _iterator.f();
294
+ let pretty = false;
295
+ let hasMatch = false;
296
+ const {
297
+ default: minimatch
298
+ } = await Promise.resolve().then(function () { return require('./minimatch.cjs'); }).then(function (n) { return n.minimatch; });
872
299
 
873
- return _context2.finish(25);
300
+ for (const pattern of workspaces) {
301
+ let normalizedPattern = pattern;
874
302
 
875
- case 28:
876
- if (!hasMatch) {
877
- _context2.next = 30;
878
- break;
879
- }
303
+ if (pattern.startsWith('./')) {
304
+ pretty = true;
305
+ normalizedPattern = pattern.slice(2);
306
+ }
880
307
 
881
- return _context2.abrupt("return", workspaces);
308
+ if (minimatch(relative, normalizedPattern)) {
309
+ hasMatch = true;
310
+ break;
311
+ }
312
+ }
882
313
 
883
- case 30:
884
- return _context2.abrupt("return", [].concat(_toConsumableArray(workspaces), [pretty ? relativeDirectoryForDisplay(relative) : relative]).sort(function (patternOne, patternTwo) {
885
- return patternOne.localeCompare(patternTwo);
886
- }));
314
+ if (hasMatch) {
315
+ return workspaces;
316
+ }
887
317
 
888
- case 31:
889
- case "end":
890
- return _context2.stop();
891
- }
892
- }
893
- }, _callee2, null, [[9, 22, 25, 28]]);
894
- }));
895
- return _addToWorkspaces.apply(this, arguments);
318
+ return [...workspaces, pretty ? relativeDirectoryForDisplay(relative) : relative].sort((patternOne, patternTwo) => patternOne.localeCompare(patternTwo));
896
319
  }
897
320
 
898
- exports._slicedToArray = _slicedToArray;
899
321
  exports.addToPackageManagerWorkspaces = addToPackageManagerWorkspaces;
900
322
  exports.addToTsConfig = addToTsConfig;
901
323
  exports.createOutputTarget = createOutputTarget;
@@ -903,5 +325,6 @@ exports.emptyDirectory = emptyDirectory;
903
325
  exports.format = format;
904
326
  exports.isEmpty = isEmpty;
905
327
  exports.loadTemplate = loadTemplate;
328
+ exports.mergeDependencies = mergeDependencies;
906
329
  exports.relativeDirectoryForDisplay = relativeDirectoryForDisplay;
907
330
  exports.toValidPackageName = toValidPackageName;