querysub 0.722.0 → 0.723.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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "querysub",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.723.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"note1": "note on node-forge fork, see https://github.com/digitalbazaar/forge/issues/744 for details",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"port-mappings": "yarn typenode ./src/diagnostics/network/portMappingsMain.ts",
|
|
34
34
|
"log-search": "yarn typenode ./src/diagnostics/network/logSearchMain.ts",
|
|
35
35
|
"log-files": "yarn typenode ./src/diagnostics/network/logFilesMain.ts",
|
|
36
|
+
"publish-querysub": "yarn typenode ./src/deployManager/publishQuerysubMain.ts",
|
|
36
37
|
"parameters-timeline": "yarn typenode ./src/deployManager/parametersTimelineMain.ts",
|
|
37
38
|
"setup-machine": "yarn typenode ./src/deployManager/setupMachineMain.ts",
|
|
38
39
|
"stop-machine": "yarn typenode ./src/deployManager/stopMachineMain.ts",
|
|
@@ -23,6 +23,7 @@ import { FunctionSpec, functionSchema } from "../3-path-functions/PathFunctionRu
|
|
|
23
23
|
import { Querysub } from "../4-querysub/Querysub";
|
|
24
24
|
import { green, red } from "socket-function/src/formatting/logColors";
|
|
25
25
|
import { fsExistsAsync } from "../fs";
|
|
26
|
+
import { publishQuerysubAsync, waitForPublishOtpAsync } from "./publishQuerysub";
|
|
26
27
|
|
|
27
28
|
const SERVICE_FOLDER_NAME = "machine-services";
|
|
28
29
|
export const SERVICE_FOLDER = `${SERVICE_FOLDER_NAME}/`;
|
|
@@ -521,13 +522,9 @@ export class MachineServiceControllerBase {
|
|
|
521
522
|
throw new Error(`Querysub folder does not exist at ${querysubFolder}`);
|
|
522
523
|
}
|
|
523
524
|
|
|
524
|
-
|
|
525
|
-
await runPromise("yarn version --minor --no-git-tag-version", { cwd: querysubFolder });
|
|
526
|
-
await runPromise("yarn publish --non-interactive", { cwd: querysubFolder });
|
|
525
|
+
let newVersion = await publishQuerysubAsync({ querysubFolder, getOtp: waitForPublishOtpAsync });
|
|
527
526
|
|
|
528
527
|
// Update package.json reference in our actual repo (version only, no install)
|
|
529
|
-
let querysubPackageJson = JSON.parse(fs.readFileSync(path.join(querysubFolder, "package.json"), "utf8"));
|
|
530
|
-
let newVersion = querysubPackageJson.version;
|
|
531
528
|
|
|
532
529
|
let currentPackageJsonPath = path.join(".", "package.json");
|
|
533
530
|
let currentPackageJson = JSON.parse(fs.readFileSync(currentPackageJsonPath, "utf8"));
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import child_process from "child_process";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import os from "os";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import readline from "readline";
|
|
6
|
+
import { runPromise } from "socket-function/src/runPromise";
|
|
7
|
+
import { magenta, yellow } from "socket-function/src/formatting/logColors";
|
|
8
|
+
import { delay } from "socket-function/src/batching";
|
|
9
|
+
|
|
10
|
+
export const PUBLISH_OTP_FILE = path.join(os.tmpdir(), "querysub-publish-otp.txt");
|
|
11
|
+
const OTP_FILE_POLL_INTERVAL = 1000;
|
|
12
|
+
const LOGIN_URL_PATTERN = /Open (https:\/\/www\.npmjs\.com\/login\/\S+)/;
|
|
13
|
+
const PUBLISH_SUCCESS_TEXT = "success Published";
|
|
14
|
+
|
|
15
|
+
/** Bumps the minor version (unless the current one was never published), then publishes with yarn. npm requires a one-time code for every publish: yarn prints a login link, and the code that page hands out has to come back through getOtp. */
|
|
16
|
+
export async function publishQuerysubAsync(config: {
|
|
17
|
+
querysubFolder: string;
|
|
18
|
+
getOtp: (loginUrl: string) => Promise<string>;
|
|
19
|
+
}): Promise<string> {
|
|
20
|
+
let { querysubFolder } = config;
|
|
21
|
+
let version = readVersion(querysubFolder);
|
|
22
|
+
let published = (await runPromise(`npm view querysub@${version} version`, { quiet: true, nothrow: true })).trim();
|
|
23
|
+
if (published === version) {
|
|
24
|
+
await runPromise("yarn version --minor --no-git-tag-version", { cwd: querysubFolder });
|
|
25
|
+
version = readVersion(querysubFolder);
|
|
26
|
+
}
|
|
27
|
+
console.log(magenta(`Publishing querysub ${version}`));
|
|
28
|
+
|
|
29
|
+
let output = await runPromise("yarn publish --non-interactive", { cwd: querysubFolder, nothrow: true, includeStderrInOutput: true });
|
|
30
|
+
if (output.includes(PUBLISH_SUCCESS_TEXT)) return version;
|
|
31
|
+
let loginUrl = LOGIN_URL_PATTERN.exec(output)?.[1];
|
|
32
|
+
if (!loginUrl) {
|
|
33
|
+
throw new Error(`yarn publish of querysub ${version} failed without giving a login link:\n${output}`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let otp = await config.getOtp(loginUrl);
|
|
37
|
+
output = await runPromise(`yarn publish --non-interactive --otp ${otp}`, { cwd: querysubFolder, nothrow: true, includeStderrInOutput: true });
|
|
38
|
+
if (!output.includes(PUBLISH_SUCCESS_TEXT)) {
|
|
39
|
+
throw new Error(`yarn publish of querysub ${version} with the one-time code failed:\n${output}`);
|
|
40
|
+
}
|
|
41
|
+
return version;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function readVersion(querysubFolder: string): string {
|
|
45
|
+
return String(JSON.parse(fs.readFileSync(path.join(querysubFolder, "package.json"), "utf8")).version);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Opens the login link, explains the LastPass passkey dance, and waits for the code: typed into this terminal, or written to PUBLISH_OTP_FILE (for when something other than a person is running the publish). */
|
|
49
|
+
export async function waitForPublishOtpAsync(loginUrl: string): Promise<string> {
|
|
50
|
+
await fs.promises.rm(PUBLISH_OTP_FILE, { force: true });
|
|
51
|
+
openInBrowser(loginUrl);
|
|
52
|
+
console.log(yellow(`npm needs a one-time code to publish. Opened ${loginUrl}`));
|
|
53
|
+
console.log(yellow(`LastPass is NOT enabled on npmjs.com by default: click the LastPass icon, enable it for this site, then sign in with the passkey from LastPass. Copy the code the page gives you.`));
|
|
54
|
+
console.log(yellow(`Type the code here and press enter, or write it to ${PUBLISH_OTP_FILE}`));
|
|
55
|
+
|
|
56
|
+
let done = false;
|
|
57
|
+
let fromTerminal = new Promise<string>(resolve => {
|
|
58
|
+
if (!process.stdin.isTTY) return;
|
|
59
|
+
let reader = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
60
|
+
reader.question("One-time code: ", answer => {
|
|
61
|
+
reader.close();
|
|
62
|
+
resolve(answer);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
let fromFile = (async () => {
|
|
66
|
+
while (!done) {
|
|
67
|
+
let text = await fs.promises.readFile(PUBLISH_OTP_FILE, "utf8").catch(() => "");
|
|
68
|
+
if (text.trim()) return text;
|
|
69
|
+
await delay(OTP_FILE_POLL_INTERVAL);
|
|
70
|
+
}
|
|
71
|
+
return "";
|
|
72
|
+
})();
|
|
73
|
+
let code = (await Promise.race([fromTerminal, fromFile])).trim();
|
|
74
|
+
done = true;
|
|
75
|
+
await fs.promises.rm(PUBLISH_OTP_FILE, { force: true });
|
|
76
|
+
if (!/^\w+$/.test(code)) {
|
|
77
|
+
throw new Error(`Expected a one-time code of letters and digits, was ${JSON.stringify(code)}`);
|
|
78
|
+
}
|
|
79
|
+
return code;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function openInBrowser(url: string) {
|
|
83
|
+
let child = process.platform === "win32"
|
|
84
|
+
? child_process.spawn("cmd", ["/c", "start", "", url], { detached: true, stdio: "ignore" })
|
|
85
|
+
: child_process.spawn("xdg-open", [url], { detached: true, stdio: "ignore" });
|
|
86
|
+
child.unref();
|
|
87
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
module.hotreload = false;
|
|
2
|
+
|
|
3
|
+
{
|
|
4
|
+
let argv = process.argv;
|
|
5
|
+
let cwdIdx = argv.indexOf("--cwd");
|
|
6
|
+
if (cwdIdx >= 0 && argv[cwdIdx + 1]) {
|
|
7
|
+
process.chdir(argv[cwdIdx + 1]);
|
|
8
|
+
argv.splice(cwdIdx, 2);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
import "../inject";
|
|
13
|
+
|
|
14
|
+
import yargs from "yargs";
|
|
15
|
+
import { green } from "socket-function/src/formatting/logColors";
|
|
16
|
+
import { disablePathAuditer } from "../diagnostics/pathAuditerCallback";
|
|
17
|
+
import { MachineServiceControllerBase } from "./machineSchema";
|
|
18
|
+
|
|
19
|
+
let args = yargs(process.argv.slice(2))
|
|
20
|
+
.option("message", { type: "string", demandOption: true, describe: "commit message for both querysub and the service repo" })
|
|
21
|
+
.strict()
|
|
22
|
+
.argv;
|
|
23
|
+
|
|
24
|
+
async function main() {
|
|
25
|
+
disablePathAuditer();
|
|
26
|
+
let controller = new MachineServiceControllerBase();
|
|
27
|
+
await controller.commitPushAndPublishQuerysub(args.message);
|
|
28
|
+
await controller.commitPushService(args.message);
|
|
29
|
+
console.log(green(`Published querysub, pointed ${process.cwd()} at it, and pushed both repos`));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
main().then(
|
|
33
|
+
() => process.exit(),
|
|
34
|
+
e => {
|
|
35
|
+
console.error((e as Error).stack || e);
|
|
36
|
+
process.exit(1);
|
|
37
|
+
},
|
|
38
|
+
);
|