rman 0.38.0 → 1.0.2

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 (119) hide show
  1. package/README.md +371 -21
  2. package/cli.js +51 -29
  3. package/commands/build.command.d.ts +3 -0
  4. package/commands/build.command.js +14 -0
  5. package/commands/changed.command.d.ts +3 -0
  6. package/commands/changed.command.js +29 -0
  7. package/commands/changelog.command.d.ts +3 -0
  8. package/commands/changelog.command.js +63 -0
  9. package/commands/ci.command.d.ts +3 -0
  10. package/commands/ci.command.js +30 -0
  11. package/commands/clean.command.d.ts +3 -0
  12. package/commands/clean.command.js +36 -0
  13. package/commands/diff.command.d.ts +3 -0
  14. package/commands/diff.command.js +51 -0
  15. package/commands/exec.command.d.ts +3 -0
  16. package/commands/exec.command.js +83 -0
  17. package/commands/import.command.d.ts +3 -0
  18. package/commands/import.command.js +27 -0
  19. package/commands/info.command.d.ts +3 -0
  20. package/commands/info.command.js +61 -0
  21. package/commands/list.command.d.ts +3 -0
  22. package/commands/list.command.js +113 -0
  23. package/commands/publish.command.d.ts +3 -0
  24. package/commands/publish.command.js +147 -0
  25. package/commands/run.command.d.ts +6 -0
  26. package/commands/run.command.js +80 -0
  27. package/commands/test.command.d.ts +3 -0
  28. package/commands/test.command.js +14 -0
  29. package/commands/version.command.d.ts +3 -0
  30. package/commands/version.command.js +125 -0
  31. package/constants.js +1 -1
  32. package/core/config.d.ts +13 -0
  33. package/core/config.js +61 -0
  34. package/core/package.d.ts +2 -0
  35. package/core/package.js +2 -0
  36. package/core/repository.d.ts +36 -3
  37. package/core/repository.js +90 -45
  38. package/index.d.ts +17 -1
  39. package/index.js +15 -1
  40. package/package.json +8 -4
  41. package/rmanrc.schema.json +202 -0
  42. package/services/changelog.service.d.ts +99 -0
  43. package/services/changelog.service.js +272 -0
  44. package/services/ci.service.d.ts +40 -0
  45. package/services/ci.service.js +204 -0
  46. package/services/clean.service.d.ts +42 -0
  47. package/services/clean.service.js +226 -0
  48. package/services/exec.service.d.ts +35 -0
  49. package/services/exec.service.js +114 -0
  50. package/services/import.service.d.ts +30 -0
  51. package/services/import.service.js +84 -0
  52. package/services/list.service.d.ts +27 -0
  53. package/services/list.service.js +25 -0
  54. package/services/publish.service.d.ts +79 -0
  55. package/services/publish.service.js +199 -0
  56. package/services/run.service.d.ts +99 -0
  57. package/services/run.service.js +432 -0
  58. package/services/system-info.d.ts +16 -0
  59. package/services/system-info.js +25 -0
  60. package/services/version.service.d.ts +95 -0
  61. package/services/version.service.js +450 -0
  62. package/services.d.ts +10 -0
  63. package/services.js +10 -0
  64. package/utils/branch-guard.d.ts +25 -0
  65. package/utils/branch-guard.js +61 -0
  66. package/utils/change-hash.d.ts +55 -0
  67. package/utils/change-hash.js +80 -0
  68. package/utils/conventional-commits.d.ts +39 -0
  69. package/utils/conventional-commits.js +43 -0
  70. package/utils/exec.d.ts +5 -6
  71. package/utils/exec.js +45 -59
  72. package/utils/git.d.ts +86 -0
  73. package/utils/git.js +276 -0
  74. package/utils/live-region.d.ts +16 -0
  75. package/utils/live-region.js +59 -0
  76. package/utils/logger.d.ts +24 -0
  77. package/utils/logger.js +39 -0
  78. package/utils/npm-run-path.d.ts +1 -1
  79. package/utils/npm-run-path.js +10 -10
  80. package/utils/package-filter.d.ts +32 -0
  81. package/utils/package-filter.js +73 -0
  82. package/utils/progress-panel.d.ts +59 -0
  83. package/utils/progress-panel.js +149 -0
  84. package/utils/workspace-range.d.ts +17 -0
  85. package/utils/workspace-range.js +28 -0
  86. package/commands/build-command.d.ts +0 -11
  87. package/commands/build-command.js +0 -26
  88. package/commands/changed-command.d.ts +0 -16
  89. package/commands/changed-command.js +0 -35
  90. package/commands/ci-command.d.ts +0 -24
  91. package/commands/ci-command.js +0 -71
  92. package/commands/execute-command.d.ts +0 -19
  93. package/commands/execute-command.js +0 -75
  94. package/commands/info-command.d.ts +0 -10
  95. package/commands/info-command.js +0 -57
  96. package/commands/list-command.d.ts +0 -38
  97. package/commands/list-command.js +0 -137
  98. package/commands/multi-task-command.d.ts +0 -22
  99. package/commands/multi-task-command.js +0 -68
  100. package/commands/publish-command.d.ts +0 -24
  101. package/commands/publish-command.js +0 -135
  102. package/commands/run-command.d.ts +0 -28
  103. package/commands/run-command.js +0 -134
  104. package/commands/version-command.d.ts +0 -25
  105. package/commands/version-command.js +0 -198
  106. package/core/command.d.ts +0 -35
  107. package/core/command.js +0 -117
  108. package/core/constants.d.ts +0 -1
  109. package/core/constants.js +0 -2
  110. package/core/logger.d.ts +0 -12
  111. package/core/logger.js +0 -2
  112. package/utils/file-utils.d.ts +0 -4
  113. package/utils/file-utils.js +0 -29
  114. package/utils/git-utils.d.ts +0 -25
  115. package/utils/git-utils.js +0 -66
  116. package/utils/npm-utils.d.ts +0 -11
  117. package/utils/npm-utils.js +0 -33
  118. package/utils/package-not-found-error.d.ts +0 -2
  119. package/utils/package-not-found-error.js +0 -2
@@ -1,198 +0,0 @@
1
- import colors from 'ansi-colors';
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 * as yargs from 'yargs';
8
- import { Command } from '../core/command.js';
9
- import { Package } from '../core/package.js';
10
- import { Repository } from '../core/repository.js';
11
- import { GitHelper } from '../utils/git-utils.js';
12
- import { RunCommand } from './run-command.js';
13
- export class VersionCommand extends RunCommand {
14
- repository;
15
- bump;
16
- static commandName = 'version';
17
- _updatedPackages = new Set();
18
- constructor(repository, bump, options) {
19
- super(repository, 'version', options);
20
- this.repository = repository;
21
- this.bump = bump;
22
- }
23
- async _prepareTasks(packages) {
24
- const { repository } = this;
25
- const git = new GitHelper({ cwd: repository.dirname });
26
- const dirtyFiles = await git.listDirtyFiles();
27
- const committedFiles = await git.listCommittedFiles();
28
- const newVersions = {};
29
- let errorCount = 0;
30
- const selectedPackages = [];
31
- const dependentPackages = [];
32
- for (const p of packages) {
33
- const relDir = path.relative(repository.dirname, p.dirname);
34
- let status = '';
35
- let message = '';
36
- let newVer = '';
37
- const logPkgName = colors.yellow(p.name);
38
- if (!this.options.noTag) {
39
- const isDirty = dirtyFiles.find(f => !path.relative(relDir, f).startsWith('..'));
40
- if (isDirty) {
41
- if (!this.options.ignoreDirty)
42
- errorCount++;
43
- status = this.options.ignoreDirty ? colors.cyan.bold('skip') : colors.redBright.bold('error');
44
- message = 'Git directory is not clean';
45
- }
46
- }
47
- if (!status) {
48
- const isChanged = committedFiles.find(f => !path.relative(relDir, f).startsWith('..'));
49
- newVer =
50
- isChanged || this.options.all || this.options.unified
51
- ? semver.inc(p.version, this.bump)
52
- : undefined;
53
- if (newVer)
54
- newVersions[p.name] = newVer;
55
- else {
56
- status = colors.cyanBright.bold('no-change');
57
- message = 'No change detected';
58
- }
59
- }
60
- if (status) {
61
- if (this.options.json) {
62
- logger.info(this.commandName, '%j', {
63
- package: p.name,
64
- version: p.version,
65
- newVersion: newVer,
66
- status: stripColor(status),
67
- message: stripColor(message),
68
- });
69
- }
70
- else {
71
- logger.log(this.options.ignoreDirty ? 'info' : 'error', this.commandName, logPkgName, colors.whiteBright(p.version), status, logger.separator, message);
72
- }
73
- continue;
74
- }
75
- selectedPackages.push(p);
76
- packages.forEach(p2 => {
77
- if (p2.dependencies.includes(p.name) && !dependentPackages.includes(p2))
78
- dependentPackages.push(p2);
79
- });
80
- }
81
- if (errorCount)
82
- throw new Error('Unable to bump version due to error(s)');
83
- const maxVer = Object.values(newVersions).reduce((m, v) => (semver.gt(m, v) ? m : v), '0.0.0');
84
- if (this.options.unified) {
85
- Object.keys(newVersions).forEach(k => (newVersions[k] = maxVer));
86
- }
87
- dependentPackages.forEach(p2 => {
88
- if (!selectedPackages.includes(p2))
89
- selectedPackages.push(p2);
90
- });
91
- const tasks = await super._prepareTasks(selectedPackages, { newVersions });
92
- tasks.forEach(t => (t.options.exclusive = true));
93
- if (!this.options.noTag) {
94
- tasks.push(new Task(async () => {
95
- while (this._updatedPackages.size) {
96
- const filenames = [];
97
- const [first] = this._updatedPackages;
98
- for (const pkg of this._updatedPackages) {
99
- if (pkg.version === first.version) {
100
- filenames.push(path.relative(this.repository.rootPackage.dirname, pkg.jsonFileName));
101
- this._updatedPackages.delete(pkg);
102
- }
103
- }
104
- await super._exec(this.repository.rootPackage, 'git commit -m "' + first.version + '" ' + filenames.map(s => '"' + s + '"').join(' '), {
105
- stdio: logger.levelIndex < 1000 ? 'inherit' : 'pipe',
106
- logLevel: 'silly',
107
- });
108
- }
109
- if (this.options.unified) {
110
- try {
111
- await super._exec(this.repository.rootPackage, 'git tag -a "v' + maxVer + '" -m "version ' + maxVer + '"', {
112
- cwd: this.repository.dirname,
113
- stdio: logger.levelIndex < 1000 ? 'inherit' : 'pipe',
114
- logLevel: 'silly',
115
- });
116
- }
117
- catch {
118
- //
119
- }
120
- }
121
- }, { exclusive: true }));
122
- }
123
- return tasks;
124
- }
125
- async _exec(pkg, command, args, options) {
126
- if (pkg === this.repository.rootPackage)
127
- return { code: 0 };
128
- if (command === '#') {
129
- const { newVersions } = options;
130
- pkg.reloadJson();
131
- const oldVer = pkg.json.version;
132
- const newVer = newVersions[pkg.name];
133
- pkg.json.version = newVer;
134
- delete pkg.json.scripts.version;
135
- pkg.writeJson();
136
- if (!this._updatedPackages.has(pkg))
137
- this._updatedPackages.add(pkg);
138
- const packages = this.repository.getPackages();
139
- for (const p of packages) {
140
- if (p.dependencies.includes(pkg.name)) {
141
- p.reloadJson();
142
- for (const k of ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies']) {
143
- if (p.json[k]?.[pkg.name]) {
144
- p.json[k][pkg.name] = '^' + newVer;
145
- }
146
- }
147
- p.writeJson();
148
- if (!this._updatedPackages.has(p))
149
- this._updatedPackages.add(p);
150
- }
151
- }
152
- logger.info(this.commandName, pkg.name, logger.separator, 'Version changed from ' + colors.cyan(oldVer) + ' to ' + colors.cyan(newVer));
153
- return { code: 0 };
154
- }
155
- return super._exec(pkg, command, args, options);
156
- }
157
- }
158
- (function (VersionCommand) {
159
- VersionCommand.cliCommandOptions = {
160
- unified: {
161
- alias: 'u',
162
- describe: '# Keep all package versions same',
163
- type: 'boolean',
164
- },
165
- all: {
166
- alias: 'a',
167
- describe: '# Bump version for all packages even no commits',
168
- type: 'boolean',
169
- },
170
- 'ignore-dirty': {
171
- alias: 'i',
172
- describe: '# Do not bump version for dirty packages',
173
- type: 'boolean',
174
- },
175
- 'no-tag': {
176
- alias: 'n',
177
- describe: '# Do not crate git version tag. (Ignores dirty check)',
178
- type: 'boolean',
179
- },
180
- };
181
- function initCli(repository, program) {
182
- program.command({
183
- command: 'version [bump] [...options]',
184
- describe: 'Bump version of packages',
185
- builder: cmd => cmd
186
- .example('$0 version patch', '# semver keyword')
187
- .example('$0 version 1.0.1', '# explicit')
188
- .conflicts('ignore-dirty', ['force-dirty', 'unified'])
189
- .option(VersionCommand.cliCommandOptions),
190
- handler: async (args) => {
191
- const bump = args.bump;
192
- const options = Command.composeOptions(VersionCommand.commandName, args, repository.config);
193
- await new VersionCommand(repository, bump, options).execute();
194
- },
195
- });
196
- }
197
- VersionCommand.initCli = initCli;
198
- })(VersionCommand || (VersionCommand = {}));
package/core/command.d.ts DELETED
@@ -1,35 +0,0 @@
1
- import './logger.js';
2
- import npmlog from 'npmlog';
3
- import * as yargs from 'yargs';
4
- export interface CommandEvents {
5
- start: () => void | Promise<void>;
6
- finish: (error?: any, result?: any) => void | Promise<void>;
7
- error: (e: unknown) => void | Promise<void>;
8
- }
9
- declare const Command_base: import("strict-typed-events").Type<import("strict-typed-events").TypedEventEmitter<any, CommandEvents, CommandEvents>>;
10
- export declare abstract class Command<TOptions extends Command.GlobalOptions = Command.GlobalOptions> extends Command_base {
11
- protected _started: boolean;
12
- protected _finished: boolean;
13
- protected _options: TOptions;
14
- logger: npmlog.Logger;
15
- static commandName: string;
16
- constructor(options?: TOptions);
17
- get options(): TOptions;
18
- get commandName(): string;
19
- execute(): Promise<any>;
20
- protected enableProgress(): Promise<void>;
21
- protected disableProgress(): void;
22
- protected abstract _execute(): Promise<any>;
23
- protected _preExecute(): Promise<void>;
24
- protected _postExecute?(): Promise<void>;
25
- }
26
- export declare namespace Command {
27
- interface GlobalOptions {
28
- logLevel?: string;
29
- json?: boolean;
30
- ci?: boolean;
31
- }
32
- const globalOptions: Record<string, yargs.Options>;
33
- function composeOptions<TOptions extends GlobalOptions = GlobalOptions>(commandName: string, yargArgs: any, config: any): Partial<TOptions>;
34
- }
35
- export {};
package/core/command.js DELETED
@@ -1,117 +0,0 @@
1
- import './logger.js';
2
- import colors from 'ansi-colors';
3
- import isCi from 'is-ci';
4
- import npmlog from 'npmlog';
5
- import merge from 'putil-merge';
6
- import { AsyncEventEmitter, TypedEventEmitterClass } from 'strict-typed-events';
7
- import * as yargs from 'yargs';
8
- import { isTTY } from './constants.js';
9
- const noOp = () => undefined;
10
- const lineVerticalDashed0 = '┆';
11
- export class Command extends TypedEventEmitterClass(AsyncEventEmitter) {
12
- _started = false;
13
- _finished = false;
14
- _options;
15
- logger = npmlog;
16
- static commandName;
17
- constructor(options) {
18
- super();
19
- this._options = options || {};
20
- if (isCi)
21
- this.options.ci = true;
22
- this.logger.separator = colors.gray(lineVerticalDashed0);
23
- Object.defineProperty(this.logger, 'levelIndex', {
24
- get() {
25
- return npmlog.levels[npmlog.level] || 0;
26
- },
27
- });
28
- }
29
- get options() {
30
- return this._options;
31
- }
32
- get commandName() {
33
- return Object.getPrototypeOf(this).constructor.commandName;
34
- }
35
- async execute() {
36
- if (this._finished) {
37
- this._finished = false;
38
- this._started = false;
39
- }
40
- if (!this._started) {
41
- this._started = true;
42
- await this.emitAsync('start');
43
- }
44
- this._started = true;
45
- try {
46
- this.logger.level = this.options.logLevel || (this.options.ci ? 'error' : 'info');
47
- if (this.options.ci || !isTTY) {
48
- this.logger.disableColor();
49
- this.logger.disableUnicode();
50
- }
51
- else {
52
- this.logger.enableColor();
53
- this.logger.enableUnicode();
54
- }
55
- if (this._preExecute)
56
- await this._preExecute();
57
- const v = await this._execute();
58
- if (this._postExecute)
59
- await this._postExecute();
60
- await this.emitAsync('finish', undefined, v).catch(noOp);
61
- this.disableProgress();
62
- this.logger.resume();
63
- this.logger.info('', 'Command completed');
64
- return v;
65
- }
66
- catch (e) {
67
- this.disableProgress();
68
- await this.emitAsync('finish', e).catch(noOp);
69
- if (this.listenerCount('error'))
70
- await this.emitAsync('error', e).catch(noOp);
71
- this.logger.resume();
72
- this.logger.error(this.commandName, this.logger.separator, e.message.trim());
73
- e.logged = true;
74
- throw e;
75
- }
76
- finally {
77
- this._finished = true;
78
- }
79
- }
80
- async enableProgress() {
81
- // if (this.options.ci || !isTTY || (this._screen && this._screen.visible)) return;
82
- }
83
- disableProgress() {
84
- //
85
- }
86
- async _preExecute() {
87
- npmlog.info('rman', `Executing "${this.commandName}" command`);
88
- }
89
- }
90
- (function (Command) {
91
- Command.globalOptions = {
92
- 'log-level': {
93
- defaultDescription: 'info',
94
- describe: 'Set log level',
95
- choices: ['silly', 'verbose', 'info', 'output', 'notice', 'success', 'warn', 'error', 'silent'],
96
- requiresArg: true,
97
- },
98
- json: {
99
- alias: 'j',
100
- describe: '# Stream log as json',
101
- type: 'boolean',
102
- },
103
- ci: {
104
- hidden: true,
105
- type: 'boolean',
106
- },
107
- };
108
- function composeOptions(commandName, yargArgs, config) {
109
- const result = merge({}, config, { filter: (_, key) => key !== 'command' });
110
- merge(result, yargArgs);
111
- const cfgCmd = config.command && typeof config.command === 'object' ? config.command[commandName] : undefined;
112
- if (cfgCmd && typeof cfgCmd === 'object')
113
- merge(result, cfgCmd);
114
- return result;
115
- }
116
- Command.composeOptions = composeOptions;
117
- })(Command || (Command = {}));
@@ -1 +0,0 @@
1
- export declare const isTTY: boolean;
package/core/constants.js DELETED
@@ -1,2 +0,0 @@
1
- // export const DOTS = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
2
- export const isTTY = process.stdout.isTTY && process.env.TERM !== 'dumb';
package/core/logger.d.ts DELETED
@@ -1,12 +0,0 @@
1
- declare module 'npmlog' {
2
- interface Logger {
3
- output(prefix: string, message: string, ...args: any[]): void;
4
- success(prefix: string, message: string, ...args: any[]): void;
5
- disp: Record<string, string>;
6
- showProgress(): any;
7
- hideProgress(): any;
8
- separator: string;
9
- levelIndex: number;
10
- }
11
- }
12
- export {};
package/core/logger.js DELETED
@@ -1,2 +0,0 @@
1
- import logger from 'npmlog';
2
- logger.addLevel('output', 3300, {}, '');
@@ -1,4 +0,0 @@
1
- import { Stats } from 'node:fs';
2
- export declare function fsExists(s: string): Promise<boolean>;
3
- export declare function tryStat(s: any): Promise<Stats | undefined>;
4
- export declare function fsDelete(fileOrDir: string): Promise<boolean>;
@@ -1,29 +0,0 @@
1
- import { Stats } from 'node:fs';
2
- import fsa from 'fs/promises';
3
- import path from 'path';
4
- export async function fsExists(s) {
5
- return fsa
6
- .lstat(s)
7
- .then(() => true)
8
- .catch(() => false);
9
- }
10
- export async function tryStat(s) {
11
- return fsa.lstat(s).catch(() => undefined);
12
- }
13
- export async function fsDelete(fileOrDir) {
14
- const stat = await tryStat(fileOrDir);
15
- if (stat) {
16
- if (stat.isFile() || stat.isSymbolicLink()) {
17
- await fsa.unlink(fileOrDir);
18
- return true;
19
- }
20
- if (stat.isDirectory()) {
21
- const list = await fsa.readdir(fileOrDir);
22
- for (const file of list)
23
- await fsDelete(path.join(fileOrDir, file));
24
- await fsa.rmdir(fileOrDir);
25
- return true;
26
- }
27
- }
28
- return false;
29
- }
@@ -1,25 +0,0 @@
1
- export declare namespace GitHelper {
2
- interface FileStatus {
3
- filename: string;
4
- status: string;
5
- }
6
- }
7
- export interface GitOptions {
8
- cwd?: string;
9
- }
10
- export declare class GitHelper {
11
- cwd: string;
12
- constructor(options?: GitOptions);
13
- listDirtyFileStatus(options?: {
14
- absolute?: boolean;
15
- }): Promise<GitHelper.FileStatus[]>;
16
- listDirtyFiles(options?: {
17
- absolute?: boolean;
18
- }): Promise<string[]>;
19
- listCommitSha(): Promise<string[]>;
20
- listCommittedFiles(options?: {
21
- absolute?: boolean;
22
- commits?: string | string[];
23
- }): Promise<string[]>;
24
- readFileLastPublished(filePath: string, commitSha?: string): Promise<string>;
25
- }
@@ -1,66 +0,0 @@
1
- import path from 'path';
2
- import { exec } from './exec.js';
3
- export class GitHelper {
4
- cwd;
5
- constructor(options) {
6
- this.cwd = options?.cwd || process.cwd();
7
- }
8
- async listDirtyFileStatus(options) {
9
- const x = await exec('git', {
10
- cwd: this.cwd,
11
- argv: ['status', '--porcelain'],
12
- });
13
- const result = [];
14
- const files = x.stdout ? x.stdout.trim().split(/\s*\n\s*/) : [];
15
- for (const f of files) {
16
- const m = f.match(/^(\w+) (.+)$/);
17
- if (m) {
18
- result.push({
19
- filename: options?.absolute ? path.join(this.cwd, m[2]) : m[2],
20
- status: m[1],
21
- });
22
- }
23
- }
24
- return result;
25
- }
26
- async listDirtyFiles(options) {
27
- return (await this.listDirtyFileStatus(options)).map(x => x.filename);
28
- }
29
- async listCommitSha() {
30
- const x = await exec('git', {
31
- cwd: this.cwd,
32
- argv: ['cherry'],
33
- });
34
- const matches = x.stdout ? x.stdout.matchAll(/([a-f0-9]+)/gi) : [];
35
- const result = [];
36
- for (const m of matches) {
37
- result.push(m[1]);
38
- }
39
- return result;
40
- }
41
- async listCommittedFiles(options) {
42
- const shaArr = options?.commits
43
- ? Array.isArray(options?.commits)
44
- ? options?.commits
45
- : [options?.commits]
46
- : await this.listCommitSha();
47
- let result = [];
48
- for (const s of shaArr) {
49
- const x = await exec('git', {
50
- cwd: this.cwd,
51
- argv: ['show', s, '--name-only', '--pretty="format:"'],
52
- });
53
- result.push(...(x.stdout ? x.stdout.trim().split(/\s*\n\s*/) : []));
54
- }
55
- if (options?.absolute)
56
- result = result.map(f => path.join(this.cwd, f));
57
- return result;
58
- }
59
- async readFileLastPublished(filePath, commitSha) {
60
- const x = await exec('git', {
61
- cwd: this.cwd,
62
- argv: ['show', (commitSha || 'HEAD') + ':"' + filePath + '"'],
63
- });
64
- return x.stdout || '';
65
- }
66
- }
@@ -1,11 +0,0 @@
1
- export declare namespace NpmHelper { }
2
- export interface NpmOptions {
3
- cwd?: string;
4
- userconfig?: string;
5
- }
6
- export declare class NpmHelper {
7
- cwd: string;
8
- userconfig?: string;
9
- constructor(options?: NpmOptions);
10
- getPackageInfo(packageName: string): Promise<any>;
11
- }
@@ -1,33 +0,0 @@
1
- import path from 'path';
2
- import { exec } from './exec.js';
3
- import { PackageNotFoundError } from './package-not-found-error.js';
4
- export class NpmHelper {
5
- cwd;
6
- userconfig;
7
- constructor(options) {
8
- this.cwd = options?.cwd || process.cwd();
9
- this.userconfig = options?.userconfig ? path.resolve(this.cwd, options.userconfig) : undefined;
10
- }
11
- async getPackageInfo(packageName) {
12
- const argv = ['view', packageName, '--json'];
13
- if (this.userconfig)
14
- argv.push('--userconfig', this.userconfig);
15
- const x = await exec('npm', { cwd: this.cwd, argv });
16
- if (x && x.stdout) {
17
- if (x.code && x.stdout.includes('404')) {
18
- throw new PackageNotFoundError('Package ' + packageName + ' not found in repository');
19
- }
20
- const b = x.stdout.indexOf('{');
21
- const e = x.stdout.lastIndexOf('}');
22
- const s = x.stdout.substring(b, e + 1);
23
- try {
24
- if (s)
25
- return JSON.parse(s);
26
- }
27
- catch {
28
- //
29
- }
30
- }
31
- throw new Error('Unable to fetch version info');
32
- }
33
- }
@@ -1,2 +0,0 @@
1
- export declare class PackageNotFoundError extends Error {
2
- }
@@ -1,2 +0,0 @@
1
- export class PackageNotFoundError extends Error {
2
- }