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