rman 0.19.0 → 0.21.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.
@@ -27,27 +27,23 @@ class CleanInstallCommand extends run_command_js_1.RunCommand {
27
27
  await this._fsDelete(path_1.default.join(dirname, 'package-lock.json'));
28
28
  await this._fsDelete(path_1.default.join(dirname, 'yarn-lock.json'));
29
29
  npmlog_1.default.info(this.commandName, chalk_1.default.yellow('installing'), 'Running ' + client + ' install');
30
- return super._exec({
31
- name: 'root',
32
- cwd: this.repository.dirname,
33
- json: { ...this.repository.json },
34
- command: client + ' install',
30
+ return super._exec(this.repository.rootPackage, client + ' install', {
35
31
  stdio: 'inherit'
36
32
  });
37
33
  }, { exclusive: true }));
38
34
  return tasks;
39
35
  }
40
- async _exec(args, ctx) {
36
+ async _exec(pkg, command, args, ctx) {
41
37
  if (args.command === '#') {
42
- if (args.name === 'root')
38
+ if (pkg === this.repository.rootPackage)
43
39
  return { code: 0 };
44
- const { cwd } = args;
40
+ const cwd = args.cwd || pkg.dirname;
45
41
  await this._fsDelete(path_1.default.join(cwd, 'node_modules'));
46
42
  await this._fsDelete(path_1.default.join(cwd, 'package-lock.json'));
47
43
  await this._fsDelete(path_1.default.join(cwd, 'yarn-lock.json'));
48
44
  return { code: 0 };
49
45
  }
50
- return super._exec(args, ctx);
46
+ return super._exec(pkg, command, args, ctx);
51
47
  }
52
48
  async _fsDelete(fileOrDir) {
53
49
  if (await (0, file_utils_js_1.fsExists)(fileOrDir)) {
@@ -57,23 +57,20 @@ class PublishCommand extends run_command_js_1.RunCommand {
57
57
  await Promise.all(promises);
58
58
  return super._prepareTasks(selectedPackages, { newVersions });
59
59
  }
60
- async _exec(args, options) {
61
- if (args.command === '#') {
62
- if (args.name === 'root')
60
+ async _exec(pkg, command, args, options) {
61
+ if (command === '#') {
62
+ if (pkg === this.repository.rootPackage)
63
63
  return { code: 0 };
64
64
  const cwd = this.options.contents
65
- ? path_1.default.resolve(this.repository.dirname, path_1.default.join(this.options.contents, path_1.default.basename(args.cwd)))
66
- : args.cwd;
67
- return super._exec({
65
+ ? path_1.default.resolve(this.repository.dirname, path_1.default.join(this.options.contents, path_1.default.basename(pkg.dirname)))
66
+ : pkg.dirname;
67
+ return super._exec(pkg, 'npm publish' + (this.options.access ? ' --access=' + this.options.access : ''), {
68
68
  ...args,
69
69
  cwd,
70
- command: 'npm publish' + (this.options.access ? ' --access=' + this.options.access : '')
71
- }, {
72
- ...options,
73
- stdio: npmlog_1.default.levelIndex < 1000 ? 'inherit' : 'pipe'
74
- });
70
+ stdio: npmlog_1.default.levelIndex < 1000 ? 'inherit' : 'pipe',
71
+ }, options);
75
72
  }
76
- return super._exec(args, options);
73
+ return super._exec(pkg, command, args, options);
77
74
  }
78
75
  }
79
76
  exports.PublishCommand = PublishCommand;
@@ -21,22 +21,13 @@ class RunCommand extends multi_task_command_js_1.MultiTaskCommand {
21
21
  const packageTasks = [];
22
22
  for (const p of packages) {
23
23
  if (p.json.scripts) {
24
- const childTask = this._prepareScriptTask({
25
- name: p.name,
26
- cwd: p.dirname,
27
- json: p.json,
28
- dependencies: p.dependencies
29
- }, options);
24
+ const childTask = this._prepareScriptTask(p, options);
30
25
  if (childTask) {
31
26
  packageTasks.push(childTask);
32
27
  }
33
28
  }
34
29
  }
35
- const rootTask = this._prepareScriptTask({
36
- name: 'root',
37
- cwd: this.repository.dirname,
38
- json: this.repository.json
39
- });
30
+ const rootTask = this._prepareScriptTask(this.repository.rootPackage);
40
31
  if (!rootTask?.children)
41
32
  return packageTasks;
42
33
  const tasks = [];
@@ -49,57 +40,51 @@ class RunCommand extends multi_task_command_js_1.MultiTaskCommand {
49
40
  tasks.push(...post);
50
41
  return tasks;
51
42
  }
52
- _prepareScriptTask(args, ctx) {
53
- const json = { ...args.json };
43
+ _prepareScriptTask(pkg, options) {
44
+ const json = { ...pkg.json };
54
45
  json.scripts = json.scripts || {};
55
46
  json.scripts[this.script] = json.scripts[this.script] || '#';
56
- let scriptInfo;
57
- try {
58
- scriptInfo = (0, parse_npm_script_1.default)(json, 'npm run ' + this.script);
59
- if (!(scriptInfo && scriptInfo.raw))
60
- return;
61
- }
62
- catch {
47
+ const scriptInfo = (0, parse_npm_script_1.default)(json, 'npm run ' + this.script);
48
+ if (!(scriptInfo && scriptInfo.raw))
63
49
  return;
64
- }
65
50
  const children = [];
66
51
  for (const s of scriptInfo.steps) {
67
52
  const parsed = Array.isArray(s.parsed) ? s.parsed : [s.parsed];
68
53
  for (const cmd of parsed) {
69
54
  const task = new power_tasks_1.Task(async () => {
70
- return await this._exec({
71
- ...args,
72
- command: cmd,
55
+ return await this._exec(pkg, cmd, {
73
56
  stdio: npmlog_1.default.levelIndex < 1000 ? 'inherit' : 'pipe'
74
- }, ctx);
57
+ }, options);
75
58
  }, {
76
- name: args.name + ':' + s.name,
59
+ name: pkg.name + ':' + s.name,
77
60
  dependencies: (this.options.parallel || s.name.startsWith('pre') || s.name.startsWith('post')) ?
78
- undefined : args.dependencies
61
+ undefined : pkg.dependencies
79
62
  });
80
63
  children.push(task);
81
64
  }
82
65
  }
83
66
  if (children.length) {
84
67
  return new power_tasks_1.Task(children, {
85
- name: args.name,
68
+ name: pkg.name,
86
69
  bail: true,
87
70
  serial: true,
88
71
  });
89
72
  }
90
73
  }
91
- async _exec(args, options) {
74
+ async _exec(pkg, command, args, options) {
75
+ const name = pkg === this.repository.rootPackage ? 'root' : pkg.name;
92
76
  const logLevel = args.logLevel == null ? 'info' : args.logLevel;
93
77
  if (logLevel)
94
- npmlog_1.default.verbose(this.commandName, chalk_1.default.cyan(args.name), chalk_1.default.cyanBright.bold('executing'), npmlog_1.default.separator, args.command);
78
+ npmlog_1.default.verbose(this.commandName, chalk_1.default.cyan(name), chalk_1.default.cyanBright.bold('executing'), npmlog_1.default.separator, command);
95
79
  const t = Date.now();
96
- const r = await (0, exec_js_1.exec)(args.command, { cwd: args.cwd, stdio: args.stdio, throwOnError: false });
80
+ const cwd = args.cwd || pkg.dirname;
81
+ const r = await (0, exec_js_1.exec)(command, { cwd, stdio: args.stdio, throwOnError: false });
97
82
  if (logLevel)
98
83
  if (r.error) {
99
- npmlog_1.default.error(this.commandName, chalk_1.default.cyan(args.name), chalk_1.default.red.bold('failed'), npmlog_1.default.separator, args.command, npmlog_1.default.separator, r.error.message.trim() + ('\n' + r.stdout).trim());
84
+ npmlog_1.default.error(this.commandName, chalk_1.default.cyan(name), chalk_1.default.red.bold('failed'), npmlog_1.default.separator, command, npmlog_1.default.separator, r.error.message.trim() + ('\n' + r.stdout).trim());
100
85
  }
101
86
  else
102
- npmlog_1.default.log(logLevel, this.commandName, chalk_1.default.cyan(args.name), chalk_1.default.green.bold('executed'), npmlog_1.default.separator, args.command, chalk_1.default.yellow(' (' + (Date.now() - t) + ' ms)'));
87
+ npmlog_1.default.log(logLevel, this.commandName, chalk_1.default.cyan(name), chalk_1.default.green.bold('executed'), npmlog_1.default.separator, command, chalk_1.default.yellow(' (' + (Date.now() - t) + ' ms)'));
103
88
  if (r.error && !args.noThrow)
104
89
  throw r.error;
105
90
  return r;
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.VersionCommand = void 0;
7
7
  const chalk_1 = __importDefault(require("chalk"));
8
- const promises_1 = __importDefault(require("fs/promises"));
9
8
  const npmlog_1 = __importDefault(require("npmlog"));
10
9
  const path_1 = __importDefault(require("path"));
11
10
  const power_tasks_1 = require("power-tasks");
@@ -19,6 +18,7 @@ class VersionCommand extends run_command_js_1.RunCommand {
19
18
  super(repository, 'version', options);
20
19
  this.repository = repository;
21
20
  this.bump = bump;
21
+ this._updatedPackages = new Set();
22
22
  }
23
23
  async _prepareTasks(packages) {
24
24
  const { repository } = this;
@@ -28,6 +28,7 @@ class VersionCommand extends run_command_js_1.RunCommand {
28
28
  const newVersions = {};
29
29
  let errorCount = 0;
30
30
  const selectedPackages = [];
31
+ const dependentPackages = [];
31
32
  for (const p of packages) {
32
33
  const relDir = path_1.default.relative(repository.dirname, p.dirname);
33
34
  let status = '';
@@ -69,6 +70,10 @@ class VersionCommand extends run_command_js_1.RunCommand {
69
70
  continue;
70
71
  }
71
72
  selectedPackages.push(p);
73
+ packages.forEach(p2 => {
74
+ if (p2.dependencies.includes(p.name) && !dependentPackages.includes(p2))
75
+ dependentPackages.push(p2);
76
+ });
72
77
  }
73
78
  if (errorCount)
74
79
  throw new Error('Unable to bump version due to error(s)');
@@ -78,50 +83,74 @@ class VersionCommand extends run_command_js_1.RunCommand {
78
83
  if (this.options.unified) {
79
84
  Object.keys(newVersions).forEach(k => newVersions[k] = maxVer);
80
85
  }
86
+ dependentPackages.forEach(p2 => {
87
+ if (!selectedPackages.includes(p2))
88
+ selectedPackages.push(p2);
89
+ });
81
90
  const tasks = await super._prepareTasks(selectedPackages, { newVersions });
82
91
  tasks.forEach(t => t.options.exclusive = true);
83
- if (this.options.unified)
92
+ if (!this.options.noTag) {
84
93
  tasks.push(new power_tasks_1.Task(async () => {
85
- try {
86
- await super._exec({
87
- name: 'rman',
88
- command: 'git tag -a "v' + maxVer + '" -m "version ' + maxVer + '"',
89
- cwd: this.repository.dirname,
94
+ while (this._updatedPackages.size) {
95
+ const filenames = [];
96
+ const [first] = this._updatedPackages;
97
+ for (const pkg of this._updatedPackages) {
98
+ if (pkg.version === first.version) {
99
+ filenames.push(path_1.default.relative(this.repository.rootPackage.dirname, pkg.jsonFileName));
100
+ this._updatedPackages.delete(pkg);
101
+ }
102
+ }
103
+ await super._exec(this.repository.rootPackage, 'git commit -m "' + first.version + '" ' + filenames.map(s => '"' + s + '"').join(' '), {
90
104
  stdio: npmlog_1.default.levelIndex < 1000 ? 'inherit' : 'pipe',
91
105
  logLevel: 'silly'
92
106
  });
93
107
  }
94
- catch {
95
- //
96
- }
108
+ if (this.options.unified)
109
+ try {
110
+ await super._exec(this.repository.rootPackage, 'git tag -a "v' + maxVer + '" -m "version ' + maxVer + '"', {
111
+ cwd: this.repository.dirname,
112
+ stdio: npmlog_1.default.levelIndex < 1000 ? 'inherit' : 'pipe',
113
+ logLevel: 'silly'
114
+ });
115
+ }
116
+ catch {
117
+ //
118
+ }
97
119
  }, { exclusive: true }));
120
+ }
98
121
  return tasks;
99
122
  }
100
- async _exec(args, options) {
101
- if (args.name === 'root')
123
+ async _exec(pkg, command, args, options) {
124
+ if (pkg === this.repository.rootPackage)
102
125
  return { code: 0 };
103
- if (args.command === '#') {
126
+ if (command === '#') {
104
127
  const { newVersions } = options;
105
- const oldVer = args.json.version;
106
- const newVer = newVersions[args.name];
107
- args.json.version = newVer;
108
- delete args.json.scripts.version;
109
- const f = path_1.default.join(args.cwd, 'package.json');
110
- const data = JSON.stringify(args.json, undefined, 2);
111
- await promises_1.default.writeFile(f, data, 'utf-8');
112
- if (!this.options.noTag) {
113
- await super._exec({
114
- name: args.name,
115
- command: 'git commit -m "' + newVer + '" package.json',
116
- cwd: args.cwd,
117
- stdio: npmlog_1.default.levelIndex < 1000 ? 'inherit' : 'pipe',
118
- logLevel: 'silly'
119
- });
128
+ pkg.reloadJson();
129
+ const oldVer = pkg.json.version;
130
+ const newVer = newVersions[pkg.name];
131
+ pkg.json.version = newVer;
132
+ delete pkg.json.scripts.version;
133
+ pkg.writeJson();
134
+ if (!this._updatedPackages.has(pkg))
135
+ this._updatedPackages.add(pkg);
136
+ const packages = this.repository.getPackages();
137
+ for (const p of packages) {
138
+ if (p.dependencies.includes(pkg.name)) {
139
+ p.reloadJson();
140
+ for (const k of ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies']) {
141
+ if (p.json[k]?.[pkg.name]) {
142
+ p.json[k][pkg.name] = '^' + newVer;
143
+ }
144
+ }
145
+ p.writeJson();
146
+ if (!this._updatedPackages.has(p))
147
+ this._updatedPackages.add(p);
148
+ }
120
149
  }
121
- npmlog_1.default.info(this.commandName, args.name, npmlog_1.default.separator, 'Version changed from ' + chalk_1.default.cyan(oldVer) + ' to ' + chalk_1.default.cyan(newVer));
150
+ npmlog_1.default.info(this.commandName, pkg.name, npmlog_1.default.separator, 'Version changed from ' + chalk_1.default.cyan(oldVer) + ' to ' + chalk_1.default.cyan(newVer));
122
151
  return { code: 0 };
123
152
  }
124
- return super._exec(args, options);
153
+ return super._exec(pkg, command, args, options);
125
154
  }
126
155
  }
127
156
  exports.VersionCommand = VersionCommand;
@@ -21,13 +21,21 @@ class Package {
21
21
  get json() {
22
22
  return this._json;
23
23
  }
24
+ get jsonFileName() {
25
+ return path_1.default.join(this.dirname, 'package.json');
26
+ }
24
27
  get isPrivate() {
25
28
  return !!this._json.private;
26
29
  }
27
30
  reloadJson() {
28
- const f = path_1.default.join(this.dirname, 'package.json');
31
+ const f = this.jsonFileName;
29
32
  this._json = JSON.parse(fs_1.default.readFileSync(f, 'utf-8'));
30
33
  return this._json;
31
34
  }
35
+ writeJson() {
36
+ const f = this.jsonFileName;
37
+ const data = JSON.stringify(this._json, undefined, 2);
38
+ fs_1.default.writeFileSync(f, data, 'utf-8');
39
+ }
32
40
  }
33
41
  exports.Package = Package;
@@ -17,6 +17,7 @@ class Repository extends package_js_1.Package {
17
17
  this.dirname = dirname;
18
18
  this.config = config;
19
19
  this.packages = packages;
20
+ this.rootPackage = new package_js_1.Package(dirname);
20
21
  }
21
22
  getPackages(options) {
22
23
  const result = [...this.packages];
package/cjs/utils/exec.js CHANGED
@@ -18,6 +18,8 @@ async function exec(command, options) {
18
18
  ...(0, npm_run_path_js_1.npmRunPathEnv)({ cwd: opts.cwd }),
19
19
  ...opts.env
20
20
  };
21
+ if (process.env.TS_NODE_PROJECT)
22
+ delete opts.env.TS_NODE_PROJECT;
21
23
  opts.cwd = opts.cwd || process.cwd();
22
24
  const spawnOptions = {
23
25
  stdio: opts.stdio || 'pipe',
@@ -9,10 +9,8 @@ export declare class CleanInstallCommand extends RunCommand<CleanInstallCommand.
9
9
  static commandName: string;
10
10
  constructor(repository: Repository, options?: CleanInstallCommand.Options);
11
11
  protected _prepareTasks(packages: Package[]): Promise<Task[]>;
12
- protected _exec(args: {
13
- name: string;
14
- json: any;
15
- cwd: string;
12
+ protected _exec(pkg: Package, command: string, args: {
13
+ cwd?: string;
16
14
  dependencies?: string[];
17
15
  command: string;
18
16
  }, ctx?: any): Promise<ExecuteCommandResult>;
@@ -21,27 +21,23 @@ export class CleanInstallCommand extends RunCommand {
21
21
  await this._fsDelete(path.join(dirname, 'package-lock.json'));
22
22
  await this._fsDelete(path.join(dirname, 'yarn-lock.json'));
23
23
  logger.info(this.commandName, chalk.yellow('installing'), 'Running ' + client + ' install');
24
- return super._exec({
25
- name: 'root',
26
- cwd: this.repository.dirname,
27
- json: { ...this.repository.json },
28
- command: client + ' install',
24
+ return super._exec(this.repository.rootPackage, client + ' install', {
29
25
  stdio: 'inherit'
30
26
  });
31
27
  }, { exclusive: true }));
32
28
  return tasks;
33
29
  }
34
- async _exec(args, ctx) {
30
+ async _exec(pkg, command, args, ctx) {
35
31
  if (args.command === '#') {
36
- if (args.name === 'root')
32
+ if (pkg === this.repository.rootPackage)
37
33
  return { code: 0 };
38
- const { cwd } = args;
34
+ const cwd = args.cwd || pkg.dirname;
39
35
  await this._fsDelete(path.join(cwd, 'node_modules'));
40
36
  await this._fsDelete(path.join(cwd, 'package-lock.json'));
41
37
  await this._fsDelete(path.join(cwd, 'yarn-lock.json'));
42
38
  return { code: 0 };
43
39
  }
44
- return super._exec(args, ctx);
40
+ return super._exec(pkg, command, args, ctx);
45
41
  }
46
42
  async _fsDelete(fileOrDir) {
47
43
  if (await fsExists(fileOrDir)) {
@@ -9,13 +9,7 @@ export declare class PublishCommand extends RunCommand<PublishCommand.Options> {
9
9
  static commandName: string;
10
10
  constructor(repository: Repository, options?: PublishCommand.Options);
11
11
  protected _prepareTasks(packages: Package[]): Promise<Task[]>;
12
- protected _exec(args: {
13
- name: string;
14
- json: any;
15
- cwd: string;
16
- dependencies?: string[];
17
- command: string;
18
- }, options?: any): Promise<ExecuteCommandResult>;
12
+ protected _exec(pkg: Package, command: string, args: {}, options?: any): Promise<ExecuteCommandResult>;
19
13
  }
20
14
  export declare namespace PublishCommand {
21
15
  interface Options extends RunCommand.Options {
@@ -51,23 +51,20 @@ export class PublishCommand extends RunCommand {
51
51
  await Promise.all(promises);
52
52
  return super._prepareTasks(selectedPackages, { newVersions });
53
53
  }
54
- async _exec(args, options) {
55
- if (args.command === '#') {
56
- if (args.name === 'root')
54
+ async _exec(pkg, command, args, options) {
55
+ if (command === '#') {
56
+ if (pkg === this.repository.rootPackage)
57
57
  return { code: 0 };
58
58
  const cwd = this.options.contents
59
- ? path.resolve(this.repository.dirname, path.join(this.options.contents, path.basename(args.cwd)))
60
- : args.cwd;
61
- return super._exec({
59
+ ? path.resolve(this.repository.dirname, path.join(this.options.contents, path.basename(pkg.dirname)))
60
+ : pkg.dirname;
61
+ return super._exec(pkg, 'npm publish' + (this.options.access ? ' --access=' + this.options.access : ''), {
62
62
  ...args,
63
63
  cwd,
64
- command: 'npm publish' + (this.options.access ? ' --access=' + this.options.access : '')
65
- }, {
66
- ...options,
67
- stdio: logger.levelIndex < 1000 ? 'inherit' : 'pipe'
68
- });
64
+ stdio: logger.levelIndex < 1000 ? 'inherit' : 'pipe',
65
+ }, options);
69
66
  }
70
- return super._exec(args, options);
67
+ return super._exec(pkg, command, args, options);
71
68
  }
72
69
  }
73
70
  PublishCommand.commandName = 'publish';
@@ -10,18 +10,10 @@ export declare class RunCommand<TOptions extends RunCommand.Options> extends Mul
10
10
  static commandName: string;
11
11
  constructor(repository: Repository, script: string, options?: TOptions);
12
12
  protected _prepareTasks(packages: Package[], options?: any): Task[] | Promise<Task[]>;
13
- protected _prepareScriptTask(args: {
14
- name: string;
15
- json: any;
16
- cwd: string;
17
- dependencies?: string[];
18
- }, ctx?: any): Task | undefined;
19
- protected _exec(args: {
20
- name: string;
21
- cwd: string;
22
- dependencies?: string[];
23
- command: string;
13
+ protected _prepareScriptTask(pkg: Package, options?: any): Task | undefined;
14
+ protected _exec(pkg: Package, command: string, args: {
24
15
  stdio?: 'inherit' | 'pipe';
16
+ cwd?: string;
25
17
  json?: any;
26
18
  logLevel?: string;
27
19
  noThrow?: boolean;
@@ -15,22 +15,13 @@ export class RunCommand extends MultiTaskCommand {
15
15
  const packageTasks = [];
16
16
  for (const p of packages) {
17
17
  if (p.json.scripts) {
18
- const childTask = this._prepareScriptTask({
19
- name: p.name,
20
- cwd: p.dirname,
21
- json: p.json,
22
- dependencies: p.dependencies
23
- }, options);
18
+ const childTask = this._prepareScriptTask(p, options);
24
19
  if (childTask) {
25
20
  packageTasks.push(childTask);
26
21
  }
27
22
  }
28
23
  }
29
- const rootTask = this._prepareScriptTask({
30
- name: 'root',
31
- cwd: this.repository.dirname,
32
- json: this.repository.json
33
- });
24
+ const rootTask = this._prepareScriptTask(this.repository.rootPackage);
34
25
  if (!rootTask?.children)
35
26
  return packageTasks;
36
27
  const tasks = [];
@@ -43,57 +34,51 @@ export class RunCommand extends MultiTaskCommand {
43
34
  tasks.push(...post);
44
35
  return tasks;
45
36
  }
46
- _prepareScriptTask(args, ctx) {
47
- const json = { ...args.json };
37
+ _prepareScriptTask(pkg, options) {
38
+ const json = { ...pkg.json };
48
39
  json.scripts = json.scripts || {};
49
40
  json.scripts[this.script] = json.scripts[this.script] || '#';
50
- let scriptInfo;
51
- try {
52
- scriptInfo = parseNpmScript(json, 'npm run ' + this.script);
53
- if (!(scriptInfo && scriptInfo.raw))
54
- return;
55
- }
56
- catch {
41
+ const scriptInfo = parseNpmScript(json, 'npm run ' + this.script);
42
+ if (!(scriptInfo && scriptInfo.raw))
57
43
  return;
58
- }
59
44
  const children = [];
60
45
  for (const s of scriptInfo.steps) {
61
46
  const parsed = Array.isArray(s.parsed) ? s.parsed : [s.parsed];
62
47
  for (const cmd of parsed) {
63
48
  const task = new Task(async () => {
64
- return await this._exec({
65
- ...args,
66
- command: cmd,
49
+ return await this._exec(pkg, cmd, {
67
50
  stdio: logger.levelIndex < 1000 ? 'inherit' : 'pipe'
68
- }, ctx);
51
+ }, options);
69
52
  }, {
70
- name: args.name + ':' + s.name,
53
+ name: pkg.name + ':' + s.name,
71
54
  dependencies: (this.options.parallel || s.name.startsWith('pre') || s.name.startsWith('post')) ?
72
- undefined : args.dependencies
55
+ undefined : pkg.dependencies
73
56
  });
74
57
  children.push(task);
75
58
  }
76
59
  }
77
60
  if (children.length) {
78
61
  return new Task(children, {
79
- name: args.name,
62
+ name: pkg.name,
80
63
  bail: true,
81
64
  serial: true,
82
65
  });
83
66
  }
84
67
  }
85
- async _exec(args, options) {
68
+ async _exec(pkg, command, args, options) {
69
+ const name = pkg === this.repository.rootPackage ? 'root' : pkg.name;
86
70
  const logLevel = args.logLevel == null ? 'info' : args.logLevel;
87
71
  if (logLevel)
88
- logger.verbose(this.commandName, chalk.cyan(args.name), chalk.cyanBright.bold('executing'), logger.separator, args.command);
72
+ logger.verbose(this.commandName, chalk.cyan(name), chalk.cyanBright.bold('executing'), logger.separator, command);
89
73
  const t = Date.now();
90
- const r = await exec(args.command, { cwd: args.cwd, stdio: args.stdio, throwOnError: false });
74
+ const cwd = args.cwd || pkg.dirname;
75
+ const r = await exec(command, { cwd, stdio: args.stdio, throwOnError: false });
91
76
  if (logLevel)
92
77
  if (r.error) {
93
- logger.error(this.commandName, chalk.cyan(args.name), chalk.red.bold('failed'), logger.separator, args.command, logger.separator, r.error.message.trim() + ('\n' + r.stdout).trim());
78
+ logger.error(this.commandName, chalk.cyan(name), chalk.red.bold('failed'), logger.separator, command, logger.separator, r.error.message.trim() + ('\n' + r.stdout).trim());
94
79
  }
95
80
  else
96
- logger.log(logLevel, this.commandName, chalk.cyan(args.name), chalk.green.bold('executed'), logger.separator, args.command, chalk.yellow(' (' + (Date.now() - t) + ' ms)'));
81
+ logger.log(logLevel, this.commandName, chalk.cyan(name), chalk.green.bold('executed'), logger.separator, command, chalk.yellow(' (' + (Date.now() - t) + ' ms)'));
97
82
  if (r.error && !args.noThrow)
98
83
  throw r.error;
99
84
  return r;
@@ -8,15 +8,10 @@ export declare class VersionCommand extends RunCommand<VersionCommand.Options> {
8
8
  readonly repository: Repository;
9
9
  bump: string;
10
10
  static commandName: string;
11
+ private _updatedPackages;
11
12
  constructor(repository: Repository, bump: string, options?: VersionCommand.Options);
12
13
  protected _prepareTasks(packages: Package[]): Promise<Task[]>;
13
- protected _exec(args: {
14
- name: string;
15
- json: any;
16
- cwd: string;
17
- dependencies?: string[];
18
- command: string;
19
- }, options?: any): Promise<ExecuteCommandResult>;
14
+ protected _exec(pkg: Package, command: string, args: {}, options?: any): Promise<ExecuteCommandResult>;
20
15
  }
21
16
  export declare namespace VersionCommand {
22
17
  interface Options extends RunCommand.Options {
@@ -1,5 +1,4 @@
1
1
  import chalk from 'chalk';
2
- import fs from 'fs/promises';
3
2
  import logger from 'npmlog';
4
3
  import path from 'path';
5
4
  import { Task } from 'power-tasks';
@@ -13,6 +12,7 @@ export class VersionCommand extends RunCommand {
13
12
  super(repository, 'version', options);
14
13
  this.repository = repository;
15
14
  this.bump = bump;
15
+ this._updatedPackages = new Set();
16
16
  }
17
17
  async _prepareTasks(packages) {
18
18
  const { repository } = this;
@@ -22,6 +22,7 @@ export class VersionCommand extends RunCommand {
22
22
  const newVersions = {};
23
23
  let errorCount = 0;
24
24
  const selectedPackages = [];
25
+ const dependentPackages = [];
25
26
  for (const p of packages) {
26
27
  const relDir = path.relative(repository.dirname, p.dirname);
27
28
  let status = '';
@@ -63,6 +64,10 @@ export class VersionCommand extends RunCommand {
63
64
  continue;
64
65
  }
65
66
  selectedPackages.push(p);
67
+ packages.forEach(p2 => {
68
+ if (p2.dependencies.includes(p.name) && !dependentPackages.includes(p2))
69
+ dependentPackages.push(p2);
70
+ });
66
71
  }
67
72
  if (errorCount)
68
73
  throw new Error('Unable to bump version due to error(s)');
@@ -72,50 +77,74 @@ export class VersionCommand extends RunCommand {
72
77
  if (this.options.unified) {
73
78
  Object.keys(newVersions).forEach(k => newVersions[k] = maxVer);
74
79
  }
80
+ dependentPackages.forEach(p2 => {
81
+ if (!selectedPackages.includes(p2))
82
+ selectedPackages.push(p2);
83
+ });
75
84
  const tasks = await super._prepareTasks(selectedPackages, { newVersions });
76
85
  tasks.forEach(t => t.options.exclusive = true);
77
- if (this.options.unified)
86
+ if (!this.options.noTag) {
78
87
  tasks.push(new Task(async () => {
79
- try {
80
- await super._exec({
81
- name: 'rman',
82
- command: 'git tag -a "v' + maxVer + '" -m "version ' + maxVer + '"',
83
- cwd: this.repository.dirname,
88
+ while (this._updatedPackages.size) {
89
+ const filenames = [];
90
+ const [first] = this._updatedPackages;
91
+ for (const pkg of this._updatedPackages) {
92
+ if (pkg.version === first.version) {
93
+ filenames.push(path.relative(this.repository.rootPackage.dirname, pkg.jsonFileName));
94
+ this._updatedPackages.delete(pkg);
95
+ }
96
+ }
97
+ await super._exec(this.repository.rootPackage, 'git commit -m "' + first.version + '" ' + filenames.map(s => '"' + s + '"').join(' '), {
84
98
  stdio: logger.levelIndex < 1000 ? 'inherit' : 'pipe',
85
99
  logLevel: 'silly'
86
100
  });
87
101
  }
88
- catch {
89
- //
90
- }
102
+ if (this.options.unified)
103
+ try {
104
+ await super._exec(this.repository.rootPackage, 'git tag -a "v' + maxVer + '" -m "version ' + maxVer + '"', {
105
+ cwd: this.repository.dirname,
106
+ stdio: logger.levelIndex < 1000 ? 'inherit' : 'pipe',
107
+ logLevel: 'silly'
108
+ });
109
+ }
110
+ catch {
111
+ //
112
+ }
91
113
  }, { exclusive: true }));
114
+ }
92
115
  return tasks;
93
116
  }
94
- async _exec(args, options) {
95
- if (args.name === 'root')
117
+ async _exec(pkg, command, args, options) {
118
+ if (pkg === this.repository.rootPackage)
96
119
  return { code: 0 };
97
- if (args.command === '#') {
120
+ if (command === '#') {
98
121
  const { newVersions } = options;
99
- const oldVer = args.json.version;
100
- const newVer = newVersions[args.name];
101
- args.json.version = newVer;
102
- delete args.json.scripts.version;
103
- const f = path.join(args.cwd, 'package.json');
104
- const data = JSON.stringify(args.json, undefined, 2);
105
- await fs.writeFile(f, data, 'utf-8');
106
- if (!this.options.noTag) {
107
- await super._exec({
108
- name: args.name,
109
- command: 'git commit -m "' + newVer + '" package.json',
110
- cwd: args.cwd,
111
- stdio: logger.levelIndex < 1000 ? 'inherit' : 'pipe',
112
- logLevel: 'silly'
113
- });
122
+ pkg.reloadJson();
123
+ const oldVer = pkg.json.version;
124
+ const newVer = newVersions[pkg.name];
125
+ pkg.json.version = newVer;
126
+ delete pkg.json.scripts.version;
127
+ pkg.writeJson();
128
+ if (!this._updatedPackages.has(pkg))
129
+ this._updatedPackages.add(pkg);
130
+ const packages = this.repository.getPackages();
131
+ for (const p of packages) {
132
+ if (p.dependencies.includes(pkg.name)) {
133
+ p.reloadJson();
134
+ for (const k of ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies']) {
135
+ if (p.json[k]?.[pkg.name]) {
136
+ p.json[k][pkg.name] = '^' + newVer;
137
+ }
138
+ }
139
+ p.writeJson();
140
+ if (!this._updatedPackages.has(p))
141
+ this._updatedPackages.add(p);
142
+ }
114
143
  }
115
- logger.info(this.commandName, args.name, logger.separator, 'Version changed from ' + chalk.cyan(oldVer) + ' to ' + chalk.cyan(newVer));
144
+ logger.info(this.commandName, pkg.name, logger.separator, 'Version changed from ' + chalk.cyan(oldVer) + ' to ' + chalk.cyan(newVer));
116
145
  return { code: 0 };
117
146
  }
118
- return super._exec(args, options);
147
+ return super._exec(pkg, command, args, options);
119
148
  }
120
149
  }
121
150
  VersionCommand.commandName = 'version';
@@ -6,6 +6,8 @@ export declare class Package {
6
6
  get name(): string;
7
7
  get version(): string;
8
8
  get json(): any;
9
+ get jsonFileName(): string;
9
10
  get isPrivate(): boolean;
10
11
  reloadJson(): any;
12
+ writeJson(): void;
11
13
  }
@@ -15,12 +15,20 @@ export class Package {
15
15
  get json() {
16
16
  return this._json;
17
17
  }
18
+ get jsonFileName() {
19
+ return path.join(this.dirname, 'package.json');
20
+ }
18
21
  get isPrivate() {
19
22
  return !!this._json.private;
20
23
  }
21
24
  reloadJson() {
22
- const f = path.join(this.dirname, 'package.json');
25
+ const f = this.jsonFileName;
23
26
  this._json = JSON.parse(fs.readFileSync(f, 'utf-8'));
24
27
  return this._json;
25
28
  }
29
+ writeJson() {
30
+ const f = this.jsonFileName;
31
+ const data = JSON.stringify(this._json, undefined, 2);
32
+ fs.writeFileSync(f, data, 'utf-8');
33
+ }
26
34
  }
@@ -3,6 +3,7 @@ export declare class Repository extends Package {
3
3
  readonly dirname: string;
4
4
  readonly config: any;
5
5
  readonly packages: Package[];
6
+ readonly rootPackage: Package;
6
7
  protected constructor(dirname: string, config: any, packages: Package[]);
7
8
  getPackages(options?: {
8
9
  scope?: string | string[];
@@ -11,6 +11,7 @@ export class Repository extends Package {
11
11
  this.dirname = dirname;
12
12
  this.config = config;
13
13
  this.packages = packages;
14
+ this.rootPackage = new Package(dirname);
14
15
  }
15
16
  getPackages(options) {
16
17
  const result = [...this.packages];
package/esm/utils/exec.js CHANGED
@@ -12,6 +12,8 @@ export async function exec(command, options) {
12
12
  ...npmRunPathEnv({ cwd: opts.cwd }),
13
13
  ...opts.env
14
14
  };
15
+ if (process.env.TS_NODE_PROJECT)
16
+ delete opts.env.TS_NODE_PROJECT;
15
17
  opts.cwd = opts.cwd || process.cwd();
16
18
  const spawnOptions = {
17
19
  stdio: opts.stdio || 'pipe',
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rman",
3
3
  "description": "Monorepo repository manager",
4
- "version": "0.19.0",
4
+ "version": "0.21.0",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
7
7
  "contributors": [