@tsed/cli-core 3.19.3 → 3.19.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js
CHANGED
|
@@ -5,13 +5,13 @@ var di = require('@tsed/di');
|
|
|
5
5
|
var tslib = require('tslib');
|
|
6
6
|
var commander = require('commander');
|
|
7
7
|
var listr2 = require('listr2');
|
|
8
|
-
var Fs = require('fs-extra');
|
|
9
8
|
var path = require('path');
|
|
10
|
-
var readPkgUp = require('read-pkg-up');
|
|
11
9
|
var rxjs = require('rxjs');
|
|
12
10
|
var operators = require('rxjs/operators');
|
|
13
11
|
var semver$1 = require('semver');
|
|
14
12
|
var execa = require('execa');
|
|
13
|
+
var Fs = require('fs-extra');
|
|
14
|
+
var readPkgUp = require('read-pkg-up');
|
|
15
15
|
var axios = require('axios');
|
|
16
16
|
var querystring = require('querystring');
|
|
17
17
|
var tunnel = require('tunnel');
|
|
@@ -47,10 +47,10 @@ function _interopNamespace(e) {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
var Inquirer__default = /*#__PURE__*/_interopDefaultLegacy(Inquirer);
|
|
50
|
-
var Fs__default = /*#__PURE__*/_interopDefaultLegacy(Fs);
|
|
51
|
-
var readPkgUp__default = /*#__PURE__*/_interopDefaultLegacy(readPkgUp);
|
|
52
50
|
var semver__default = /*#__PURE__*/_interopDefaultLegacy(semver$1);
|
|
53
51
|
var execa__default = /*#__PURE__*/_interopDefaultLegacy(execa);
|
|
52
|
+
var Fs__default = /*#__PURE__*/_interopDefaultLegacy(Fs);
|
|
53
|
+
var readPkgUp__default = /*#__PURE__*/_interopDefaultLegacy(readPkgUp);
|
|
54
54
|
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
55
55
|
var querystring__default = /*#__PURE__*/_interopDefaultLegacy(querystring);
|
|
56
56
|
var tunnel__default = /*#__PURE__*/_interopDefaultLegacy(tunnel);
|
|
@@ -279,6 +279,17 @@ exports.CliFs = class CliFs {
|
|
|
279
279
|
};
|
|
280
280
|
exports.CliFs = tslib.__decorate([di.Injectable()], exports.CliFs);
|
|
281
281
|
|
|
282
|
+
function isValidVersion(version) {
|
|
283
|
+
version = version.replace(/[~>=<]/gi, "");
|
|
284
|
+
return !!semver__default['default'].valid(version);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function useReadPkgUp(configuration) {
|
|
288
|
+
var _configuration$projec;
|
|
289
|
+
|
|
290
|
+
return !(process.argv.includes("init") && !Fs__default['default'].existsSync(path.join(String((_configuration$projec = configuration.project) == null ? void 0 : _configuration$projec.rootDir), "package.json")));
|
|
291
|
+
}
|
|
292
|
+
|
|
282
293
|
function getEmptyPackageJson(configuration) {
|
|
283
294
|
return {
|
|
284
295
|
name: configuration.name,
|
|
@@ -290,12 +301,6 @@ function getEmptyPackageJson(configuration) {
|
|
|
290
301
|
};
|
|
291
302
|
}
|
|
292
303
|
|
|
293
|
-
function useReadPkgUp(configuration) {
|
|
294
|
-
var _configuration$projec;
|
|
295
|
-
|
|
296
|
-
return !(process.argv.includes("init") && !Fs__default['default'].existsSync(path.join(String((_configuration$projec = configuration.project) == null ? void 0 : _configuration$projec.rootDir), "package.json")));
|
|
297
|
-
}
|
|
298
|
-
|
|
299
304
|
function getPackageJson(configuration) {
|
|
300
305
|
if (useReadPkgUp(configuration)) {
|
|
301
306
|
var _configuration$projec2;
|
|
@@ -305,8 +310,12 @@ function getPackageJson(configuration) {
|
|
|
305
310
|
});
|
|
306
311
|
|
|
307
312
|
if (result && result.path) {
|
|
308
|
-
|
|
309
|
-
|
|
313
|
+
const pkgPath = path.dirname(result.path);
|
|
314
|
+
configuration.set("project.root", pkgPath);
|
|
315
|
+
const pkg = Fs__default['default'].readJsonSync(result.path, {
|
|
316
|
+
encoding: "utf8"
|
|
317
|
+
});
|
|
318
|
+
return _extends({}, getEmptyPackageJson(configuration), pkg);
|
|
310
319
|
}
|
|
311
320
|
}
|
|
312
321
|
|
|
@@ -333,7 +342,7 @@ function sortKeys(obj) {
|
|
|
333
342
|
|
|
334
343
|
function mapPackagesWithValidVersion(deps) {
|
|
335
344
|
return Object.entries(deps).reduce((deps, [key, version]) => {
|
|
336
|
-
if (
|
|
345
|
+
if (isValidVersion(version)) {
|
|
337
346
|
return _extends({}, deps, {
|
|
338
347
|
[key]: version
|
|
339
348
|
});
|
|
@@ -430,7 +439,9 @@ exports.ProjectPackageJson = class ProjectPackageJson {
|
|
|
430
439
|
}
|
|
431
440
|
|
|
432
441
|
read() {
|
|
433
|
-
this.
|
|
442
|
+
const pkg = this.getPackageJson();
|
|
443
|
+
this.setRaw(pkg);
|
|
444
|
+
return this;
|
|
434
445
|
}
|
|
435
446
|
|
|
436
447
|
setRaw(pkg) {
|
|
@@ -525,20 +536,19 @@ exports.ProjectPackageJson = class ProjectPackageJson {
|
|
|
525
536
|
}
|
|
526
537
|
|
|
527
538
|
write() {
|
|
528
|
-
|
|
529
|
-
this.raw.dependencies = sortKeys(this.raw.dependencies);
|
|
539
|
+
const originalPkg = this.getPackageJson();
|
|
530
540
|
this.rewrite = false;
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
dependencies: _extends({}, mapPackagesWithValidVersion(this.raw.dependencies)),
|
|
534
|
-
devDependencies: _extends({}, mapPackagesWithValidVersion(this.raw.devDependencies)),
|
|
541
|
+
this.raw = _extends({}, originalPkg, this.raw, {
|
|
542
|
+
scripts: _extends({}, originalPkg.scripts || {}, this.raw.scripts || {}),
|
|
543
|
+
dependencies: sortKeys(_extends({}, originalPkg.dependencies, mapPackagesWithValidVersion(this.raw.dependencies))),
|
|
544
|
+
devDependencies: sortKeys(_extends({}, originalPkg.devDependencies, mapPackagesWithValidVersion(this.raw.devDependencies))),
|
|
535
545
|
readme: undefined,
|
|
536
546
|
_id: undefined
|
|
537
547
|
});
|
|
538
|
-
|
|
539
|
-
return this.fs.writeFileSync(this.path, JSON.stringify(json, null, 2), {
|
|
548
|
+
this.fs.writeFileSync(this.path, JSON.stringify(this.raw, null, 2), {
|
|
540
549
|
encoding: "utf8"
|
|
541
550
|
});
|
|
551
|
+
return this;
|
|
542
552
|
}
|
|
543
553
|
|
|
544
554
|
hasYarn() {
|
|
@@ -570,7 +580,9 @@ exports.ProjectPackageJson = class ProjectPackageJson {
|
|
|
570
580
|
return [{
|
|
571
581
|
title: "Write package.json",
|
|
572
582
|
enabled: () => this.rewrite,
|
|
573
|
-
task: () =>
|
|
583
|
+
task: () => {
|
|
584
|
+
this.write();
|
|
585
|
+
}
|
|
574
586
|
}, ...tasks, {
|
|
575
587
|
title: "Clean",
|
|
576
588
|
task: () => {
|
|
@@ -717,6 +729,10 @@ exports.ProjectPackageJson = class ProjectPackageJson {
|
|
|
717
729
|
}];
|
|
718
730
|
}
|
|
719
731
|
|
|
732
|
+
getPackageJson() {
|
|
733
|
+
return getPackageJson(this.configuration);
|
|
734
|
+
}
|
|
735
|
+
|
|
720
736
|
};
|
|
721
737
|
|
|
722
738
|
tslib.__decorate([di.Inject(exports.CliExeca), tslib.__metadata("design:type", exports.CliExeca)], exports.ProjectPackageJson.prototype, "cliExeca", void 0);
|