rman 0.29.1 → 0.30.0

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.
Files changed (58) hide show
  1. package/cjs/cli.js +3 -3
  2. package/cjs/commands/ci-command.js +3 -3
  3. package/cjs/commands/execute-command.js +3 -3
  4. package/cjs/commands/info-command.js +7 -7
  5. package/cjs/commands/list-command.js +5 -5
  6. package/cjs/commands/publish-command.js +7 -7
  7. package/cjs/commands/run-command.js +4 -4
  8. package/cjs/commands/version-command.js +6 -6
  9. package/cjs/core/command.js +3 -3
  10. package/cjs/utils/npm-run-path.js +14 -5
  11. package/esm/cli.js +40 -36
  12. package/esm/commands/build-command.js +9 -5
  13. package/esm/commands/changed-command.js +10 -6
  14. package/esm/commands/ci-command.js +28 -23
  15. package/esm/commands/execute-command.js +20 -15
  16. package/esm/commands/info-command.js +20 -15
  17. package/esm/commands/list-command.js +30 -25
  18. package/esm/commands/multi-task-command.js +16 -11
  19. package/esm/commands/publish-command.js +28 -23
  20. package/esm/commands/run-command.js +24 -19
  21. package/esm/commands/version-command.js +35 -30
  22. package/esm/core/command.js +24 -19
  23. package/esm/core/constants.js +4 -1
  24. package/esm/core/logger.js +5 -2
  25. package/esm/core/package.js +11 -6
  26. package/esm/core/repository.js +33 -28
  27. package/esm/index.js +4 -1
  28. package/esm/utils/exec.js +10 -7
  29. package/esm/utils/file-utils.js +17 -11
  30. package/esm/utils/get-dirname.js +13 -8
  31. package/esm/utils/git-utils.js +14 -9
  32. package/esm/utils/npm-run-path.js +30 -16
  33. package/esm/utils/npm-utils.js +9 -4
  34. package/package.json +34 -35
  35. package/types/cli.d.ts +4 -0
  36. package/types/commands/build-command.d.ts +11 -0
  37. package/types/commands/changed-command.d.ts +16 -0
  38. package/types/commands/ci-command.d.ts +24 -0
  39. package/types/commands/execute-command.d.ts +19 -0
  40. package/types/commands/info-command.d.ts +10 -0
  41. package/types/commands/list-command.d.ts +38 -0
  42. package/types/commands/multi-task-command.d.ts +22 -0
  43. package/types/commands/publish-command.d.ts +22 -0
  44. package/types/commands/run-command.d.ts +28 -0
  45. package/types/commands/version-command.d.ts +25 -0
  46. package/types/core/command.d.ts +35 -0
  47. package/types/core/constants.d.ts +1 -0
  48. package/types/core/logger.d.ts +12 -0
  49. package/types/core/package.d.ts +13 -0
  50. package/types/core/repository.d.ts +19 -0
  51. package/types/index.d.ts +1 -0
  52. package/types/utils/exec.d.ts +18 -0
  53. package/types/utils/file-utils.d.ts +4 -0
  54. package/types/utils/get-dirname.d.ts +2 -0
  55. package/types/utils/git-utils.d.ts +25 -0
  56. package/types/utils/npm-run-path.d.ts +67 -0
  57. package/types/utils/npm-utils.d.ts +11 -0
  58. package/cjs/package.json +0 -3
@@ -1,13 +1,17 @@
1
- import chalk from 'chalk';
2
- import logger from 'npmlog';
3
- import path from 'path';
4
- import { Task } from 'power-tasks';
5
- import semver from 'semver';
6
- import stripColor from 'strip-color';
7
- import { Command } from '../core/command.js';
8
- import { GitHelper } from '../utils/git-utils.js';
9
- import { RunCommand } from './run-command.js';
10
- export class VersionCommand extends RunCommand {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VersionCommand = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const ansi_colors_1 = tslib_1.__importDefault(require("ansi-colors"));
6
+ const npmlog_1 = tslib_1.__importDefault(require("npmlog"));
7
+ const path_1 = tslib_1.__importDefault(require("path"));
8
+ const power_tasks_1 = require("power-tasks");
9
+ const semver_1 = tslib_1.__importDefault(require("semver"));
10
+ const strip_color_1 = tslib_1.__importDefault(require("strip-color"));
11
+ const command_js_1 = require("../core/command.js");
12
+ const git_utils_js_1 = require("../utils/git-utils.js");
13
+ const run_command_js_1 = require("./run-command.js");
14
+ class VersionCommand extends run_command_js_1.RunCommand {
11
15
  constructor(repository, bump, options) {
12
16
  super(repository, 'version', options);
13
17
  this.repository = repository;
@@ -16,7 +20,7 @@ export class VersionCommand extends RunCommand {
16
20
  }
17
21
  async _prepareTasks(packages) {
18
22
  const { repository } = this;
19
- const git = new GitHelper({ cwd: repository.dirname });
23
+ const git = new git_utils_js_1.GitHelper({ cwd: repository.dirname });
20
24
  const dirtyFiles = await git.listDirtyFiles();
21
25
  const committedFiles = await git.listCommittedFiles();
22
26
  const newVersions = {};
@@ -24,45 +28,45 @@ export class VersionCommand extends RunCommand {
24
28
  const selectedPackages = [];
25
29
  const dependentPackages = [];
26
30
  for (const p of packages) {
27
- const relDir = path.relative(repository.dirname, p.dirname);
31
+ const relDir = path_1.default.relative(repository.dirname, p.dirname);
28
32
  let status = '';
29
33
  let message = '';
30
34
  let newVer = '';
31
- const logPkgName = chalk.yellow(p.name);
35
+ const logPkgName = ansi_colors_1.default.yellow(p.name);
32
36
  if (!this.options.noTag) {
33
- const isDirty = dirtyFiles.find(f => !path.relative(relDir, f).startsWith('..'));
37
+ const isDirty = dirtyFiles.find(f => !path_1.default.relative(relDir, f).startsWith('..'));
34
38
  if (isDirty) {
35
39
  if (!this.options.ignoreDirty)
36
40
  errorCount++;
37
- status = this.options.ignoreDirty ? chalk.cyan.bold('skip') : chalk.redBright.bold('error');
41
+ status = this.options.ignoreDirty ? ansi_colors_1.default.cyan.bold('skip') : ansi_colors_1.default.redBright.bold('error');
38
42
  message = 'Git directory is not clean';
39
43
  }
40
44
  }
41
45
  if (!status) {
42
- const isChanged = committedFiles.find(f => !path.relative(relDir, f).startsWith('..'));
46
+ const isChanged = committedFiles.find(f => !path_1.default.relative(relDir, f).startsWith('..'));
43
47
  newVer =
44
48
  isChanged || this.options.all || this.options.unified
45
- ? semver.inc(p.version, this.bump)
49
+ ? semver_1.default.inc(p.version, this.bump)
46
50
  : undefined;
47
51
  if (newVer)
48
52
  newVersions[p.name] = newVer;
49
53
  else {
50
- status = chalk.cyanBright.bold('no-change');
54
+ status = ansi_colors_1.default.cyanBright.bold('no-change');
51
55
  message = 'No change detected';
52
56
  }
53
57
  }
54
58
  if (status) {
55
59
  if (this.options.json) {
56
- logger.info(this.commandName, '%j', {
60
+ npmlog_1.default.info(this.commandName, '%j', {
57
61
  package: p.name,
58
62
  version: p.version,
59
63
  newVersion: newVer,
60
- status: stripColor(status),
61
- message: stripColor(message),
64
+ status: (0, strip_color_1.default)(status),
65
+ message: (0, strip_color_1.default)(message),
62
66
  });
63
67
  }
64
68
  else {
65
- logger.log(this.options.ignoreDirty ? 'info' : 'error', this.commandName, logPkgName, chalk.whiteBright(p.version), status, logger.separator, message);
69
+ npmlog_1.default.log(this.options.ignoreDirty ? 'info' : 'error', this.commandName, logPkgName, ansi_colors_1.default.whiteBright(p.version), status, npmlog_1.default.separator, message);
66
70
  }
67
71
  continue;
68
72
  }
@@ -74,7 +78,7 @@ export class VersionCommand extends RunCommand {
74
78
  }
75
79
  if (errorCount)
76
80
  throw new Error('Unable to bump version due to error(s)');
77
- const maxVer = Object.values(newVersions).reduce((m, v) => (semver.gt(m, v) ? m : v), '0.0.0');
81
+ const maxVer = Object.values(newVersions).reduce((m, v) => (semver_1.default.gt(m, v) ? m : v), '0.0.0');
78
82
  if (this.options.unified) {
79
83
  Object.keys(newVersions).forEach(k => (newVersions[k] = maxVer));
80
84
  }
@@ -85,18 +89,18 @@ export class VersionCommand extends RunCommand {
85
89
  const tasks = await super._prepareTasks(selectedPackages, { newVersions });
86
90
  tasks.forEach(t => (t.options.exclusive = true));
87
91
  if (!this.options.noTag) {
88
- tasks.push(new Task(async () => {
92
+ tasks.push(new power_tasks_1.Task(async () => {
89
93
  while (this._updatedPackages.size) {
90
94
  const filenames = [];
91
95
  const [first] = this._updatedPackages;
92
96
  for (const pkg of this._updatedPackages) {
93
97
  if (pkg.version === first.version) {
94
- filenames.push(path.relative(this.repository.rootPackage.dirname, pkg.jsonFileName));
98
+ filenames.push(path_1.default.relative(this.repository.rootPackage.dirname, pkg.jsonFileName));
95
99
  this._updatedPackages.delete(pkg);
96
100
  }
97
101
  }
98
102
  await super._exec(this.repository.rootPackage, 'git commit -m "' + first.version + '" ' + filenames.map(s => '"' + s + '"').join(' '), {
99
- stdio: logger.levelIndex < 1000 ? 'inherit' : 'pipe',
103
+ stdio: npmlog_1.default.levelIndex < 1000 ? 'inherit' : 'pipe',
100
104
  logLevel: 'silly',
101
105
  });
102
106
  }
@@ -104,7 +108,7 @@ export class VersionCommand extends RunCommand {
104
108
  try {
105
109
  await super._exec(this.repository.rootPackage, 'git tag -a "v' + maxVer + '" -m "version ' + maxVer + '"', {
106
110
  cwd: this.repository.dirname,
107
- stdio: logger.levelIndex < 1000 ? 'inherit' : 'pipe',
111
+ stdio: npmlog_1.default.levelIndex < 1000 ? 'inherit' : 'pipe',
108
112
  logLevel: 'silly',
109
113
  });
110
114
  }
@@ -143,12 +147,13 @@ export class VersionCommand extends RunCommand {
143
147
  this._updatedPackages.add(p);
144
148
  }
145
149
  }
146
- logger.info(this.commandName, pkg.name, logger.separator, 'Version changed from ' + chalk.cyan(oldVer) + ' to ' + chalk.cyan(newVer));
150
+ npmlog_1.default.info(this.commandName, pkg.name, npmlog_1.default.separator, 'Version changed from ' + ansi_colors_1.default.cyan(oldVer) + ' to ' + ansi_colors_1.default.cyan(newVer));
147
151
  return { code: 0 };
148
152
  }
149
153
  return super._exec(pkg, command, args, options);
150
154
  }
151
155
  }
156
+ exports.VersionCommand = VersionCommand;
152
157
  VersionCommand.commandName = 'version';
153
158
  (function (VersionCommand) {
154
159
  VersionCommand.cliCommandOptions = {
@@ -184,10 +189,10 @@ VersionCommand.commandName = 'version';
184
189
  .option(VersionCommand.cliCommandOptions),
185
190
  handler: async (args) => {
186
191
  const bump = args.bump;
187
- const options = Command.composeOptions(VersionCommand.commandName, args, repository.config);
192
+ const options = command_js_1.Command.composeOptions(VersionCommand.commandName, args, repository.config);
188
193
  await new VersionCommand(repository, bump, options).execute();
189
194
  },
190
195
  });
191
196
  }
192
197
  VersionCommand.initCli = initCli;
193
- })(VersionCommand || (VersionCommand = {}));
198
+ })(VersionCommand || (exports.VersionCommand = VersionCommand = {}));
@@ -1,25 +1,29 @@
1
- import './logger.js';
2
- import chalk from 'chalk';
3
- import figures from 'figures';
4
- import isCi from 'is-ci';
5
- import npmlog from 'npmlog';
6
- import merge from 'putil-merge';
7
- import { AsyncEventEmitter, TypedEventEmitterClass } from 'strict-typed-events';
8
- import { isTTY } from './constants.js';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Command = void 0;
4
+ const tslib_1 = require("tslib");
5
+ require("./logger.js");
6
+ const ansi_colors_1 = tslib_1.__importDefault(require("ansi-colors"));
7
+ const is_ci_1 = tslib_1.__importDefault(require("is-ci"));
8
+ const npmlog_1 = tslib_1.__importDefault(require("npmlog"));
9
+ const putil_merge_1 = tslib_1.__importDefault(require("putil-merge"));
10
+ const strict_typed_events_1 = require("strict-typed-events");
11
+ const constants_js_1 = require("./constants.js");
9
12
  const noOp = () => undefined;
10
- export class Command extends TypedEventEmitterClass(AsyncEventEmitter) {
13
+ const lineVerticalDashed0 = '┆';
14
+ class Command extends (0, strict_typed_events_1.TypedEventEmitterClass)(strict_typed_events_1.AsyncEventEmitter) {
11
15
  constructor(options) {
12
16
  super();
13
17
  this._started = false;
14
18
  this._finished = false;
15
- this.logger = npmlog;
19
+ this.logger = npmlog_1.default;
16
20
  this._options = options || {};
17
- if (isCi)
21
+ if (is_ci_1.default)
18
22
  this.options.ci = true;
19
- this.logger.separator = chalk.gray(figures.lineVerticalDashed0);
23
+ this.logger.separator = ansi_colors_1.default.gray(lineVerticalDashed0);
20
24
  Object.defineProperty(this.logger, 'levelIndex', {
21
25
  get() {
22
- return npmlog.levels[npmlog.level] || 0;
26
+ return npmlog_1.default.levels[npmlog_1.default.level] || 0;
23
27
  },
24
28
  });
25
29
  }
@@ -41,7 +45,7 @@ export class Command extends TypedEventEmitterClass(AsyncEventEmitter) {
41
45
  this._started = true;
42
46
  try {
43
47
  this.logger.level = this.options.logLevel || (this.options.ci ? 'error' : 'info');
44
- if (this.options.ci || !isTTY) {
48
+ if (this.options.ci || !constants_js_1.isTTY) {
45
49
  this.logger.disableColor();
46
50
  this.logger.disableUnicode();
47
51
  }
@@ -81,9 +85,10 @@ export class Command extends TypedEventEmitterClass(AsyncEventEmitter) {
81
85
  //
82
86
  }
83
87
  async _preExecute() {
84
- npmlog.info('rman', `Executing "${this.commandName}" command`);
88
+ npmlog_1.default.info('rman', `Executing "${this.commandName}" command`);
85
89
  }
86
90
  }
91
+ exports.Command = Command;
87
92
  (function (Command) {
88
93
  Command.globalOptions = {
89
94
  'log-level': {
@@ -103,12 +108,12 @@ export class Command extends TypedEventEmitterClass(AsyncEventEmitter) {
103
108
  },
104
109
  };
105
110
  function composeOptions(commandName, yargArgs, config) {
106
- const result = merge({}, config, { filter: (_, key) => key !== 'command' });
107
- merge(result, yargArgs);
111
+ const result = (0, putil_merge_1.default)({}, config, { filter: (_, key) => key !== 'command' });
112
+ (0, putil_merge_1.default)(result, yargArgs);
108
113
  const cfgCmd = config.command && typeof config.command === 'object' ? config.command[commandName] : undefined;
109
114
  if (cfgCmd && typeof cfgCmd === 'object')
110
- merge(result, cfgCmd);
115
+ (0, putil_merge_1.default)(result, cfgCmd);
111
116
  return result;
112
117
  }
113
118
  Command.composeOptions = composeOptions;
114
- })(Command || (Command = {}));
119
+ })(Command || (exports.Command = Command = {}));
@@ -1,2 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isTTY = void 0;
1
4
  // export const DOTS = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
2
- export const isTTY = process.stdout.isTTY && process.env.TERM !== 'dumb';
5
+ exports.isTTY = process.stdout.isTTY && process.env.TERM !== 'dumb';
@@ -1,2 +1,5 @@
1
- import logger from 'npmlog';
2
- logger.addLevel('output', 3300, {}, '');
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const npmlog_1 = tslib_1.__importDefault(require("npmlog"));
5
+ npmlog_1.default.addLevel('output', 3300, {}, '');
@@ -1,6 +1,10 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- export class Package {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Package = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs_1 = tslib_1.__importDefault(require("fs"));
6
+ const path_1 = tslib_1.__importDefault(require("path"));
7
+ class Package {
4
8
  constructor(dirname) {
5
9
  this.dirname = dirname;
6
10
  this.dependencies = [];
@@ -16,19 +20,20 @@ export class Package {
16
20
  return this._json;
17
21
  }
18
22
  get jsonFileName() {
19
- return path.join(this.dirname, 'package.json');
23
+ return path_1.default.join(this.dirname, 'package.json');
20
24
  }
21
25
  get isPrivate() {
22
26
  return !!this._json.private;
23
27
  }
24
28
  reloadJson() {
25
29
  const f = this.jsonFileName;
26
- this._json = JSON.parse(fs.readFileSync(f, 'utf-8'));
30
+ this._json = JSON.parse(fs_1.default.readFileSync(f, 'utf-8'));
27
31
  return this._json;
28
32
  }
29
33
  writeJson() {
30
34
  const f = this.jsonFileName;
31
35
  const data = JSON.stringify(this._json, undefined, 2);
32
- fs.writeFileSync(f, data, 'utf-8');
36
+ fs_1.default.writeFileSync(f, data, 'utf-8');
33
37
  }
34
38
  }
39
+ exports.Package = Package;
@@ -1,17 +1,21 @@
1
- import glob from 'fast-glob';
2
- import fs from 'fs';
3
- import yaml from 'js-yaml';
4
- import path from 'path';
5
- import merge from 'putil-merge';
6
- import { getPackageJson } from '../utils/get-dirname.js';
7
- import { Package } from './package.js';
8
- export class Repository extends Package {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Repository = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fast_glob_1 = tslib_1.__importDefault(require("fast-glob"));
6
+ const fs_1 = tslib_1.__importDefault(require("fs"));
7
+ const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
8
+ const path_1 = tslib_1.__importDefault(require("path"));
9
+ const putil_merge_1 = tslib_1.__importDefault(require("putil-merge"));
10
+ const get_dirname_js_1 = require("../utils/get-dirname.js");
11
+ const package_js_1 = require("./package.js");
12
+ class Repository extends package_js_1.Package {
9
13
  constructor(dirname, config, packages) {
10
14
  super(dirname);
11
15
  this.dirname = dirname;
12
16
  this.config = config;
13
17
  this.packages = packages;
14
- this.rootPackage = new Package(dirname);
18
+ this.rootPackage = new package_js_1.Package(dirname);
15
19
  }
16
20
  getPackages(options) {
17
21
  const result = [...this.packages];
@@ -70,10 +74,10 @@ export class Repository extends Package {
70
74
  static create(root, options) {
71
75
  let dirname = root || process.cwd();
72
76
  let deep = options?.deep ?? 10;
73
- while (deep-- >= 0 && fs.existsSync(dirname)) {
74
- const f = path.join(dirname, 'package.json');
75
- if (fs.existsSync(f)) {
76
- const pkgJson = JSON.parse(fs.readFileSync(f, 'utf-8'));
77
+ while (deep-- >= 0 && fs_1.default.existsSync(dirname)) {
78
+ const f = path_1.default.join(dirname, 'package.json');
79
+ if (fs_1.default.existsSync(f)) {
80
+ const pkgJson = JSON.parse(fs_1.default.readFileSync(f, 'utf-8'));
77
81
  if (Array.isArray(pkgJson.workspaces)) {
78
82
  const packages = this._resolvePackages(dirname, pkgJson.workspaces);
79
83
  const config = this._readConfig(dirname);
@@ -82,47 +86,48 @@ export class Repository extends Package {
82
86
  return repo;
83
87
  }
84
88
  }
85
- dirname = path.resolve(dirname, '..');
89
+ dirname = path_1.default.resolve(dirname, '..');
86
90
  }
87
91
  throw new Error('No monorepo project detected');
88
92
  }
89
93
  static _resolvePackages(dirname, patterns) {
90
94
  const packages = [];
91
95
  for (const pattern of patterns) {
92
- const dirs = glob.sync(pattern, {
96
+ const dirs = fast_glob_1.default.sync(pattern, {
93
97
  cwd: dirname,
94
98
  absolute: true,
95
99
  deep: 0,
96
100
  onlyDirectories: true,
97
101
  });
98
102
  for (const dir of dirs) {
99
- const f = path.join(dir, 'package.json');
100
- if (fs.existsSync(f))
101
- packages.push(new Package(dir));
103
+ const f = path_1.default.join(dir, 'package.json');
104
+ if (fs_1.default.existsSync(f))
105
+ packages.push(new package_js_1.Package(dir));
102
106
  }
103
107
  }
104
108
  return packages;
105
109
  }
106
110
  static _readConfig(dirname) {
107
111
  const result = {};
108
- const pkgJson = getPackageJson(dirname);
112
+ const pkgJson = (0, get_dirname_js_1.getPackageJson)(dirname);
109
113
  if (pkgJson && typeof pkgJson.rman === 'object')
110
- merge(result, pkgJson.rman, { deep: true });
111
- let filename = path.resolve(dirname, '.rman.yml');
112
- if (fs.existsSync(filename)) {
113
- const obj = yaml.load(fs.readFileSync(filename, 'utf-8'));
114
+ (0, putil_merge_1.default)(result, pkgJson.rman, { deep: true });
115
+ let filename = path_1.default.resolve(dirname, '.rman.yml');
116
+ if (fs_1.default.existsSync(filename)) {
117
+ const obj = js_yaml_1.default.load(fs_1.default.readFileSync(filename, 'utf-8'));
114
118
  if (obj && typeof obj === 'object')
115
- merge(result, obj, { deep: true });
119
+ (0, putil_merge_1.default)(result, obj, { deep: true });
116
120
  }
117
- filename = path.resolve(dirname, '.rmanrc');
118
- if (fs.existsSync(filename)) {
119
- const obj = JSON.parse(fs.readFileSync(filename, 'utf-8'));
121
+ filename = path_1.default.resolve(dirname, '.rmanrc');
122
+ if (fs_1.default.existsSync(filename)) {
123
+ const obj = JSON.parse(fs_1.default.readFileSync(filename, 'utf-8'));
120
124
  if (obj && typeof obj === 'object')
121
- merge(result, obj, { deep: true });
125
+ (0, putil_merge_1.default)(result, obj, { deep: true });
122
126
  }
123
127
  return result;
124
128
  }
125
129
  }
130
+ exports.Repository = Repository;
126
131
  function topoSortPackages(packages) {
127
132
  packages.sort((a, b) => {
128
133
  if (b.dependencies.includes(a.name))
package/esm/index.js CHANGED
@@ -1 +1,4 @@
1
- export * from './core/repository.js';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./core/repository.js"), exports);
package/esm/utils/exec.js CHANGED
@@ -1,15 +1,18 @@
1
- import { spawn } from 'child_process';
2
- import { onExit } from 'signal-exit';
3
- import { npmRunPathEnv } from './npm-run-path.js';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.exec = exec;
4
+ const child_process_1 = require("child_process");
5
+ const signal_exit_1 = require("signal-exit");
6
+ const npm_run_path_js_1 = require("./npm-run-path.js");
4
7
  const runningChildren = new Map();
5
- export async function exec(command, options) {
8
+ async function exec(command, options) {
6
9
  const opts = {
7
10
  shell: true,
8
11
  throwOnError: true,
9
12
  ...options,
10
13
  };
11
14
  opts.env = {
12
- ...npmRunPathEnv({ cwd: opts.cwd }),
15
+ ...(0, npm_run_path_js_1.npmRunPathEnv)({ cwd: opts.cwd }),
13
16
  ...opts.env,
14
17
  };
15
18
  if (process.env.TS_NODE_PROJECT)
@@ -46,7 +49,7 @@ export async function exec(command, options) {
46
49
  }
47
50
  buffer = chunk;
48
51
  };
49
- const child = spawn(command, opts.argv || [], spawnOptions);
52
+ const child = (0, child_process_1.spawn)(command, opts.argv || [], spawnOptions);
50
53
  if (child.pid) {
51
54
  runningChildren.set(child.pid, child);
52
55
  if (opts.onSpawn)
@@ -99,7 +102,7 @@ export async function exec(command, options) {
99
102
  });
100
103
  });
101
104
  }
102
- onExit(() => {
105
+ (0, signal_exit_1.onExit)(() => {
103
106
  runningChildren.forEach(child => {
104
107
  child.kill();
105
108
  });
@@ -1,26 +1,32 @@
1
- import fsa from 'fs/promises';
2
- import path from 'path';
3
- export async function fsExists(s) {
4
- return fsa
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fsExists = fsExists;
4
+ exports.tryStat = tryStat;
5
+ exports.fsDelete = fsDelete;
6
+ const tslib_1 = require("tslib");
7
+ const promises_1 = tslib_1.__importDefault(require("fs/promises"));
8
+ const path_1 = tslib_1.__importDefault(require("path"));
9
+ async function fsExists(s) {
10
+ return promises_1.default
5
11
  .lstat(s)
6
12
  .then(() => true)
7
13
  .catch(() => false);
8
14
  }
9
- export async function tryStat(s) {
10
- return fsa.lstat(s).catch(() => undefined);
15
+ async function tryStat(s) {
16
+ return promises_1.default.lstat(s).catch(() => undefined);
11
17
  }
12
- export async function fsDelete(fileOrDir) {
18
+ async function fsDelete(fileOrDir) {
13
19
  const stat = await tryStat(fileOrDir);
14
20
  if (stat) {
15
21
  if (stat.isFile() || stat.isSymbolicLink()) {
16
- await fsa.unlink(fileOrDir);
22
+ await promises_1.default.unlink(fileOrDir);
17
23
  return true;
18
24
  }
19
25
  if (stat.isDirectory()) {
20
- const list = await fsa.readdir(fileOrDir);
26
+ const list = await promises_1.default.readdir(fileOrDir);
21
27
  for (const file of list)
22
- await fsDelete(path.join(fileOrDir, file));
23
- await fsa.rmdir(fileOrDir);
28
+ await fsDelete(path_1.default.join(fileOrDir, file));
29
+ await promises_1.default.rmdir(fileOrDir);
24
30
  return true;
25
31
  }
26
32
  }
@@ -1,6 +1,11 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- export function getDirname() {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDirname = getDirname;
4
+ exports.getPackageJson = getPackageJson;
5
+ const tslib_1 = require("tslib");
6
+ const fs_1 = tslib_1.__importDefault(require("fs"));
7
+ const path_1 = tslib_1.__importDefault(require("path"));
8
+ function getDirname() {
4
9
  const pst = Error.prepareStackTrace;
5
10
  Error.prepareStackTrace = function (_, stack) {
6
11
  Error.prepareStackTrace = pst;
@@ -14,13 +19,13 @@ export function getDirname() {
14
19
  const frame = stack.shift();
15
20
  const filename = frame && frame.getFileName();
16
21
  if (filename)
17
- return path.dirname(filename).replace('file://', '');
22
+ return path_1.default.dirname(filename).replace('file://', '');
18
23
  }
19
24
  throw Error('Can not parse stack');
20
25
  }
21
- export function getPackageJson(dirname) {
22
- const f = path.resolve(dirname, 'package.json');
23
- if (!fs.existsSync(f))
26
+ function getPackageJson(dirname) {
27
+ const f = path_1.default.resolve(dirname, 'package.json');
28
+ if (!fs_1.default.existsSync(f))
24
29
  return;
25
- return JSON.parse(fs.readFileSync(f, 'utf-8'));
30
+ return JSON.parse(fs_1.default.readFileSync(f, 'utf-8'));
26
31
  }
@@ -1,11 +1,15 @@
1
- import path from 'path';
2
- import { exec } from './exec.js';
3
- export class GitHelper {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GitHelper = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const path_1 = tslib_1.__importDefault(require("path"));
6
+ const exec_js_1 = require("./exec.js");
7
+ class GitHelper {
4
8
  constructor(options) {
5
9
  this.cwd = options?.cwd || process.cwd();
6
10
  }
7
11
  async listDirtyFileStatus(options) {
8
- const x = await exec('git', {
12
+ const x = await (0, exec_js_1.exec)('git', {
9
13
  cwd: this.cwd,
10
14
  argv: ['status', '--porcelain'],
11
15
  });
@@ -15,7 +19,7 @@ export class GitHelper {
15
19
  const m = f.match(/^(\w+) (.+)$/);
16
20
  if (m) {
17
21
  result.push({
18
- filename: options?.absolute ? path.join(this.cwd, m[2]) : m[2],
22
+ filename: options?.absolute ? path_1.default.join(this.cwd, m[2]) : m[2],
19
23
  status: m[1],
20
24
  });
21
25
  }
@@ -26,7 +30,7 @@ export class GitHelper {
26
30
  return (await this.listDirtyFileStatus(options)).map(x => x.filename);
27
31
  }
28
32
  async listCommitSha() {
29
- const x = await exec('git', {
33
+ const x = await (0, exec_js_1.exec)('git', {
30
34
  cwd: this.cwd,
31
35
  argv: ['cherry'],
32
36
  });
@@ -45,21 +49,22 @@ export class GitHelper {
45
49
  : await this.listCommitSha();
46
50
  let result = [];
47
51
  for (const s of shaArr) {
48
- const x = await exec('git', {
52
+ const x = await (0, exec_js_1.exec)('git', {
49
53
  cwd: this.cwd,
50
54
  argv: ['show', s, '--name-only', '--pretty="format:"'],
51
55
  });
52
56
  result.push(...(x.stdout ? x.stdout.trim().split(/\s*\n\s*/) : []));
53
57
  }
54
58
  if (options?.absolute)
55
- result = result.map(f => path.join(this.cwd, f));
59
+ result = result.map(f => path_1.default.join(this.cwd, f));
56
60
  return result;
57
61
  }
58
62
  async readFileLastPublished(filePath, commitSha) {
59
- const x = await exec('git', {
63
+ const x = await (0, exec_js_1.exec)('git', {
60
64
  cwd: this.cwd,
61
65
  argv: ['show', (commitSha || 'HEAD') + ':"' + filePath + '"'],
62
66
  });
63
67
  return x.stdout || '';
64
68
  }
65
69
  }
70
+ exports.GitHelper = GitHelper;