virmator 4.3.0 → 4.3.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.
@@ -11,7 +11,7 @@
11
11
  "preview": "virmator frontend preview",
12
12
  "spellcheck": "virmator spellcheck",
13
13
  "start": "npm install && virmator frontend",
14
- "test": "virmator test && npm run test:types",
14
+ "test": "virmator test",
15
15
  "test:all": "npm run test:types && npm test && npm run spellcheck && npm run test:format && npm run test:docs",
16
16
  "test:docs": "virmator code-in-markdown check",
17
17
  "test:format": "virmator format check",
@@ -1,7 +1,9 @@
1
1
  export declare function askQuestion(questionToAsk: string, timeoutMs?: number): Promise<string>;
2
- export declare function askQuestionUntilConditionMet({ questionToAsk, conditionCallback, invalidInputMessage, tryCountMax, }: {
2
+ export declare function askQuestionUntilConditionMet({ questionToAsk, conditionCallback, invalidInputMessage, tryCountMax, timeoutMs, }: {
3
3
  questionToAsk: string;
4
4
  conditionCallback: (response: string) => boolean | Promise<boolean>;
5
5
  invalidInputMessage: string;
6
6
  tryCountMax?: number;
7
+ /** Set to 0 to disable the timeout */
8
+ timeoutMs?: number;
7
9
  }): Promise<string>;
@@ -8,23 +8,28 @@ async function askQuestion(questionToAsk, timeoutMs = 60000) {
8
8
  output: process.stdout,
9
9
  });
10
10
  return new Promise((resolve, reject) => {
11
+ const timeoutId = timeoutMs
12
+ ? setTimeout(() => {
13
+ cliInterface.close();
14
+ reject(`Took too long to response (over "${timeoutMs / 1000}" seconds)`);
15
+ }, timeoutMs)
16
+ : undefined;
11
17
  cliInterface.question(questionToAsk + ' ', (response) => {
18
+ if (timeoutId != undefined) {
19
+ clearTimeout(timeoutId);
20
+ }
12
21
  cliInterface.close();
13
22
  resolve(response);
14
23
  });
15
- setTimeout(() => {
16
- cliInterface.close();
17
- reject(`Took too long to response (over "${timeoutMs / 1000}" seconds)`);
18
- }, timeoutMs);
19
24
  });
20
25
  }
21
26
  exports.askQuestion = askQuestion;
22
- async function askQuestionUntilConditionMet({ questionToAsk, conditionCallback, invalidInputMessage, tryCountMax = 5, }) {
27
+ async function askQuestionUntilConditionMet({ questionToAsk, conditionCallback, invalidInputMessage, tryCountMax = 5, timeoutMs = 60000, }) {
23
28
  let wasConditionMet = false;
24
29
  let retryCount = 0;
25
30
  let response = '';
26
31
  while (!wasConditionMet && retryCount <= tryCountMax) {
27
- response = (await askQuestion(questionToAsk)).trim();
32
+ response = (await askQuestion(questionToAsk, timeoutMs)).trim();
28
33
  wasConditionMet = await conditionCallback(response);
29
34
  if (!wasConditionMet) {
30
35
  console.error(invalidInputMessage);
@@ -41,8 +41,8 @@ exports.publishCommandDefinition = (0, define_command_1.defineCommand)({
41
41
  throw new Error(`git changes detected in "${packageJsonPath}". Cannot run publish command with changes, commit them first.`);
42
42
  }
43
43
  const workspaceDirs = getWorkspaceDirs(packageJson, packageJsonPath);
44
- if (await isCurrentVersionPublished(packageJson)) {
45
- await bumpPackageVersion(packageJson, packageJsonPath, workspaceDirs);
44
+ if (await isCurrentVersionPublished(packageJson, workspaceDirs)) {
45
+ await bumpPackageVersion(packageJson, packageJsonPath);
46
46
  }
47
47
  await updateWorkspaceVersions(packageJsonPath, workspaceDirs);
48
48
  await publishPackages(workspaceDirs, packageJsonPath);
@@ -74,6 +74,10 @@ async function updateWorkspaceVersions(packageJsonPath, workspaceDirPaths) {
74
74
  newWorkspacePackageJson.version = newVersion;
75
75
  await (0, promises_1.writeFile)(workspacePackageJsonPath, JSON.stringify(newWorkspacePackageJson, null, 4) + '\n');
76
76
  });
77
+ await (0, node_only_1.runShellCommand)(`npm i`, {
78
+ rejectOnError: true,
79
+ cwd: (0, path_1.dirname)(packageJsonPath),
80
+ });
77
81
  }
78
82
  async function publishPackages(workspaceDirPaths, packageJsonPath) {
79
83
  const packagePath = (0, path_1.dirname)(packageJsonPath);
@@ -106,8 +110,15 @@ async function publishPackages(workspaceDirPaths, packageJsonPath) {
106
110
  });
107
111
  }
108
112
  }
109
- async function isCurrentVersionPublished(packageJson) {
110
- const output = await (0, node_only_1.runShellCommand)(`npm show ${packageJson.name}@${packageJson.version}`);
113
+ async function isCurrentVersionPublished(packageJson, workspaceDirs) {
114
+ const arePublished = await Promise.all(workspaceDirs.map(async (workspaceDirPath) => {
115
+ const workspacePackageJson = await (0, npm_1.readPackageJson)((0, path_1.join)(workspaceDirPath, 'package.json'));
116
+ return await isPublished(workspacePackageJson);
117
+ }));
118
+ return arePublished.some((entry) => entry) || (await isPublished(packageJson));
119
+ }
120
+ async function isPublished({ name, version }) {
121
+ const output = await (0, node_only_1.runShellCommand)(`npm show ${name}@${version}`);
111
122
  return output.exitCode === 0;
112
123
  }
113
124
  // this is just used to ensure we have every release type
@@ -122,13 +133,14 @@ const releaseTypesObject = {
122
133
  };
123
134
  const releaseTypeOptions = (0, augment_vir_1.getObjectTypedKeys)(releaseTypesObject);
124
135
  const releaseTypeMessage = `Choose a release type: ${(0, augment_vir_1.joinWithFinalConjunction)(releaseTypeOptions, 'or')}:`;
125
- async function bumpPackageVersion(packageJson, packageJsonPath, workspaceDirPaths) {
136
+ async function bumpPackageVersion(packageJson, packageJsonPath) {
126
137
  const releaseType = (await (0, console_1.askQuestionUntilConditionMet)({
127
138
  conditionCallback: (input) => {
128
139
  return releaseTypeOptions.includes(input.toLowerCase());
129
140
  },
130
141
  invalidInputMessage: `Invalid release type. Expected ${(0, augment_vir_1.joinWithFinalConjunction)(releaseTypeOptions, 'or')}.`,
131
142
  questionToAsk: releaseTypeMessage,
143
+ timeoutMs: 0,
132
144
  }));
133
145
  const newVersion = (0, semver_1.inc)(packageJson.version, releaseType);
134
146
  if (!newVersion) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "virmator",
3
- "version": "4.3.0",
3
+ "version": "4.3.2",
4
4
  "description": "Handle all the stuffs in one package.",
5
5
  "keywords": [
6
6
  "automation",