@tsed/cli-core 3.19.1 → 3.19.4

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.
@@ -9,13 +9,13 @@ export { Configuration, Constant, Container, DITest, Inject, Injectable, Injecto
9
9
  import { __decorate, __metadata, __param } from 'tslib';
10
10
  import { Command as Command$1, Argument } from 'commander';
11
11
  import { Listr, Logger as Logger$1 } from 'listr2';
12
- import Fs, { existsSync } from 'fs-extra';
13
12
  import { join, dirname, relative, resolve } from 'path';
14
- import readPkgUp from 'read-pkg-up';
15
13
  import { EMPTY, throwError, Observable } from 'rxjs';
16
14
  import { merge, filter, catchError } from 'rxjs/operators';
17
15
  import semver$1 from 'semver';
18
16
  import execa from 'execa';
17
+ import Fs, { existsSync } from 'fs-extra';
18
+ import readPkgUp from 'read-pkg-up';
19
19
  import axios from 'axios';
20
20
  import querystring from 'querystring';
21
21
  import tunnel from 'tunnel';
@@ -245,6 +245,17 @@ let CliFs = class CliFs {
245
245
  };
246
246
  CliFs = __decorate([Injectable()], CliFs);
247
247
 
248
+ function isValidVersion(version) {
249
+ version = version.replace(/[~>=<]/gi, "");
250
+ return !!semver$1.valid(version);
251
+ }
252
+
253
+ function useReadPkgUp(configuration) {
254
+ var _configuration$projec;
255
+
256
+ return !(process.argv.includes("init") && !Fs.existsSync(join(String((_configuration$projec = configuration.project) == null ? void 0 : _configuration$projec.rootDir), "package.json")));
257
+ }
258
+
248
259
  function getEmptyPackageJson(configuration) {
249
260
  return {
250
261
  name: configuration.name,
@@ -256,12 +267,6 @@ function getEmptyPackageJson(configuration) {
256
267
  };
257
268
  }
258
269
 
259
- function useReadPkgUp(configuration) {
260
- var _configuration$projec;
261
-
262
- return !(process.argv.includes("init") && !Fs.existsSync(join(String((_configuration$projec = configuration.project) == null ? void 0 : _configuration$projec.rootDir), "package.json")));
263
- }
264
-
265
270
  function getPackageJson(configuration) {
266
271
  if (useReadPkgUp(configuration)) {
267
272
  var _configuration$projec2;
@@ -271,8 +276,12 @@ function getPackageJson(configuration) {
271
276
  });
272
277
 
273
278
  if (result && result.path) {
274
- configuration.set("project.root", dirname(result.path));
275
- return _extends({}, getEmptyPackageJson(configuration), result.packageJson);
279
+ const pkgPath = dirname(result.path);
280
+ configuration.set("project.root", pkgPath);
281
+ const pkg = Fs.readJsonSync(result.path, {
282
+ encoding: "utf8"
283
+ });
284
+ return _extends({}, getEmptyPackageJson(configuration), pkg);
276
285
  }
277
286
  }
278
287
 
@@ -299,7 +308,7 @@ function sortKeys(obj) {
299
308
 
300
309
  function mapPackagesWithValidVersion(deps) {
301
310
  return Object.entries(deps).reduce((deps, [key, version]) => {
302
- if (semver$1.valid(version)) {
311
+ if (isValidVersion(version)) {
303
312
  return _extends({}, deps, {
304
313
  [key]: version
305
314
  });
@@ -396,7 +405,9 @@ let ProjectPackageJson = class ProjectPackageJson {
396
405
  }
397
406
 
398
407
  read() {
399
- this.setRaw(getPackageJson(this.configuration));
408
+ const pkg = this.getPackageJson();
409
+ this.setRaw(pkg);
410
+ return this;
400
411
  }
401
412
 
402
413
  setRaw(pkg) {
@@ -491,20 +502,19 @@ let ProjectPackageJson = class ProjectPackageJson {
491
502
  }
492
503
 
493
504
  write() {
494
- this.raw.devDependencies = sortKeys(this.raw.devDependencies);
495
- this.raw.dependencies = sortKeys(this.raw.dependencies);
505
+ const originalPkg = this.getPackageJson();
496
506
  this.rewrite = false;
497
-
498
- const json = _extends({}, this.raw, {
499
- dependencies: _extends({}, mapPackagesWithValidVersion(this.raw.dependencies)),
500
- devDependencies: _extends({}, mapPackagesWithValidVersion(this.raw.devDependencies)),
507
+ this.raw = _extends({}, originalPkg, this.raw, {
508
+ scripts: _extends({}, originalPkg.scripts || {}, this.raw.scripts || {}),
509
+ dependencies: sortKeys(_extends({}, originalPkg.dependencies, mapPackagesWithValidVersion(this.raw.dependencies))),
510
+ devDependencies: sortKeys(_extends({}, originalPkg.devDependencies, mapPackagesWithValidVersion(this.raw.devDependencies))),
501
511
  readme: undefined,
502
512
  _id: undefined
503
513
  });
504
-
505
- return this.fs.writeFileSync(this.path, JSON.stringify(json, null, 2), {
514
+ this.fs.writeFileSync(this.path, JSON.stringify(this.raw, null, 2), {
506
515
  encoding: "utf8"
507
516
  });
517
+ return this;
508
518
  }
509
519
 
510
520
  hasYarn() {
@@ -536,7 +546,9 @@ let ProjectPackageJson = class ProjectPackageJson {
536
546
  return [{
537
547
  title: "Write package.json",
538
548
  enabled: () => this.rewrite,
539
- task: () => this.write()
549
+ task: () => {
550
+ this.write();
551
+ }
540
552
  }, ...tasks, {
541
553
  title: "Clean",
542
554
  task: () => {
@@ -683,6 +695,10 @@ let ProjectPackageJson = class ProjectPackageJson {
683
695
  }];
684
696
  }
685
697
 
698
+ getPackageJson() {
699
+ return getPackageJson(this.configuration);
700
+ }
701
+
686
702
  };
687
703
 
688
704
  __decorate([Inject(CliExeca), __metadata("design:type", CliExeca)], ProjectPackageJson.prototype, "cliExeca", void 0);