@pagepocket/cli 0.10.1 → 0.11.1
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/dist/commands/archive.js +146 -76
- package/dist/commands/plugin/add.js +19 -25
- package/dist/commands/plugin/doctor.js +22 -28
- package/dist/commands/plugin/ls.js +16 -22
- package/dist/commands/plugin/prune.js +13 -19
- package/dist/commands/plugin/remove.js +16 -22
- package/dist/commands/plugin/set.js +13 -19
- package/dist/commands/plugin/uninstall.js +29 -35
- package/dist/commands/plugin/update.js +22 -28
- package/dist/commands/strategy/add.js +14 -20
- package/dist/commands/strategy/doctor.js +11 -17
- package/dist/commands/strategy/ls.js +22 -0
- package/dist/commands/strategy/pin.js +10 -16
- package/dist/commands/strategy/remove.js +10 -16
- package/dist/commands/strategy/update.js +21 -27
- package/dist/commands/view.js +36 -42
- package/dist/index.js +9 -7
- package/dist/lib/filename.js +1 -5
- package/dist/services/config-service.js +24 -30
- package/dist/services/load-configured-plugins.js +8 -12
- package/dist/services/plugin-installer.js +6 -12
- package/dist/services/plugin-store.js +27 -68
- package/dist/services/strategy/builtin-strategy-registry.js +23 -0
- package/dist/services/strategy/strategy-analyze.js +10 -20
- package/dist/services/strategy/strategy-config.js +6 -13
- package/dist/services/strategy/strategy-fetch.js +11 -18
- package/dist/services/strategy/strategy-io.js +15 -25
- package/dist/services/strategy/strategy-normalize.js +4 -8
- package/dist/services/strategy/strategy-pack-read.js +10 -17
- package/dist/services/strategy/strategy-pack-store.js +12 -18
- package/dist/services/strategy/strategy-service.js +79 -82
- package/dist/services/strategy/types.js +1 -2
- package/dist/services/units/unit-store.js +16 -20
- package/dist/services/units/unit-validate.js +20 -5
- package/dist/services/user-packages/parse-pinned-spec.js +6 -6
- package/dist/services/user-packages/user-package-installer.js +4 -9
- package/dist/services/user-packages/user-package-store.js +19 -57
- package/dist/stages/prepare-output.js +6 -13
- package/dist/units/network-observer-unit.js +7 -10
- package/dist/utils/array.js +3 -0
- package/dist/utils/normalize-argv.js +3 -8
- package/dist/utils/parse-json.js +1 -5
- package/dist/utils/parse-plugin-options.js +1 -5
- package/dist/utils/parse-plugin-spec.js +6 -6
- package/dist/utils/validate-plugin-default-export.js +1 -5
- package/dist/utils/with-spinner.js +3 -10
- package/dist/view.js +12 -19
- package/package.json +12 -11
- package/dist/services/strategy/read-installed-package-version.js +0 -28
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.updatePackageToLatest = exports.installPinnedPackage = void 0;
|
|
4
|
-
const node_child_process_1 = require("node:child_process");
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
5
2
|
const toError = (value) => {
|
|
6
3
|
if (value instanceof Error) {
|
|
7
4
|
return value;
|
|
@@ -9,7 +6,7 @@ const toError = (value) => {
|
|
|
9
6
|
return new Error(String(value));
|
|
10
7
|
};
|
|
11
8
|
const tryRun = (cwd, cmd, args) => {
|
|
12
|
-
const r =
|
|
9
|
+
const r = spawnSync(cmd, args, {
|
|
13
10
|
cwd,
|
|
14
11
|
stdio: "inherit",
|
|
15
12
|
shell: false
|
|
@@ -33,15 +30,13 @@ const installWithFallback = (installDir, packageSpec) => {
|
|
|
33
30
|
}
|
|
34
31
|
throw new Error(`Failed to install ${packageSpec}. Ensure pnpm or npm is available.`);
|
|
35
32
|
};
|
|
36
|
-
const installPinnedPackage = (store, input) => {
|
|
33
|
+
export const installPinnedPackage = (store, input) => {
|
|
37
34
|
store.ensureInstallDirPackageJson(input.packageJsonName);
|
|
38
35
|
const installDir = store.getInstallDir();
|
|
39
36
|
installWithFallback(installDir, input.packageSpec);
|
|
40
37
|
};
|
|
41
|
-
|
|
42
|
-
const updatePackageToLatest = (store, input) => {
|
|
38
|
+
export const updatePackageToLatest = (store, input) => {
|
|
43
39
|
store.ensureInstallDirPackageJson(input.packageJsonName);
|
|
44
40
|
const installDir = store.getInstallDir();
|
|
45
41
|
installWithFallback(installDir, `${input.packageName}@latest`);
|
|
46
42
|
};
|
|
47
|
-
exports.updatePackageToLatest = updatePackageToLatest;
|
|
@@ -1,47 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.UserPackageStore = void 0;
|
|
40
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
41
|
-
const node_module_1 = require("node:module");
|
|
42
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
43
|
-
const node_url_1 = require("node:url");
|
|
44
|
-
const parse_json_1 = require("../../utils/parse-json");
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
import { parseJson } from "../../utils/parse-json.js";
|
|
45
6
|
const isRecord = (value) => {
|
|
46
7
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
47
8
|
};
|
|
@@ -51,21 +12,23 @@ const isStringRecord = (value) => {
|
|
|
51
12
|
}
|
|
52
13
|
return Object.values(value).every((v) => typeof v === "string");
|
|
53
14
|
};
|
|
54
|
-
class UserPackageStore {
|
|
15
|
+
export class UserPackageStore {
|
|
16
|
+
configService;
|
|
17
|
+
kind;
|
|
55
18
|
constructor(configService, kind) {
|
|
56
19
|
this.configService = configService;
|
|
57
20
|
this.kind = kind;
|
|
58
21
|
}
|
|
59
22
|
getInstallDir() {
|
|
60
|
-
return
|
|
23
|
+
return path.join(this.configService.getDataDir(), this.kind);
|
|
61
24
|
}
|
|
62
25
|
ensureInstallDir() {
|
|
63
|
-
|
|
26
|
+
fs.mkdirSync(this.getInstallDir(), { recursive: true });
|
|
64
27
|
}
|
|
65
28
|
ensureInstallDirPackageJson(packageJsonName) {
|
|
66
29
|
this.ensureInstallDir();
|
|
67
|
-
const pkgJsonPath =
|
|
68
|
-
if (
|
|
30
|
+
const pkgJsonPath = path.join(this.getInstallDir(), "package.json");
|
|
31
|
+
if (fs.existsSync(pkgJsonPath)) {
|
|
69
32
|
return pkgJsonPath;
|
|
70
33
|
}
|
|
71
34
|
const pkgJson = {
|
|
@@ -73,12 +36,12 @@ class UserPackageStore {
|
|
|
73
36
|
private: true,
|
|
74
37
|
version: "0.0.0"
|
|
75
38
|
};
|
|
76
|
-
|
|
39
|
+
fs.writeFileSync(pkgJsonPath, `${JSON.stringify(pkgJson, undefined, 2)}\n`, "utf8");
|
|
77
40
|
return pkgJsonPath;
|
|
78
41
|
}
|
|
79
42
|
createRequire(packageJsonName) {
|
|
80
43
|
const pkgJsonPath = this.ensureInstallDirPackageJson(packageJsonName);
|
|
81
|
-
return
|
|
44
|
+
return createRequire(pkgJsonPath);
|
|
82
45
|
}
|
|
83
46
|
resolveInstalledPackageJsonPath(packageJsonName, packageName) {
|
|
84
47
|
const req = this.createRequire(packageJsonName);
|
|
@@ -87,8 +50,8 @@ class UserPackageStore {
|
|
|
87
50
|
readInstalledPackageMeta(packageJsonName, packageName) {
|
|
88
51
|
try {
|
|
89
52
|
const pkgJsonPath = this.resolveInstalledPackageJsonPath(packageJsonName, packageName);
|
|
90
|
-
const text =
|
|
91
|
-
const json =
|
|
53
|
+
const text = fs.readFileSync(pkgJsonPath, "utf8");
|
|
54
|
+
const json = parseJson(text);
|
|
92
55
|
if (!json.ok || !isRecord(json.value)) {
|
|
93
56
|
return { name: packageName };
|
|
94
57
|
}
|
|
@@ -105,8 +68,8 @@ class UserPackageStore {
|
|
|
105
68
|
}
|
|
106
69
|
readInstalledDependencyVersions(packageJsonName) {
|
|
107
70
|
const pkgJsonPath = this.ensureInstallDirPackageJson(packageJsonName);
|
|
108
|
-
const text =
|
|
109
|
-
const parsed =
|
|
71
|
+
const text = fs.readFileSync(pkgJsonPath, "utf8");
|
|
72
|
+
const parsed = parseJson(text);
|
|
110
73
|
if (!parsed.ok || !isRecord(parsed.value)) {
|
|
111
74
|
return {};
|
|
112
75
|
}
|
|
@@ -119,8 +82,7 @@ class UserPackageStore {
|
|
|
119
82
|
async importModule(packageJsonName, packageName) {
|
|
120
83
|
const req = this.createRequire(packageJsonName);
|
|
121
84
|
const resolved = req.resolve(packageName);
|
|
122
|
-
const mod = await
|
|
85
|
+
const mod = await import(pathToFileURL(resolved).href);
|
|
123
86
|
return isRecord(mod) ? mod : {};
|
|
124
87
|
}
|
|
125
88
|
}
|
|
126
|
-
exports.UserPackageStore = UserPackageStore;
|
|
@@ -1,18 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
-
const filename_1 = require("../lib/filename");
|
|
9
|
-
const prepareOutputDir = async (title, outputFlag) => {
|
|
10
|
-
const safeTitle = (0, filename_1.safeFilename)(title || "snapshot");
|
|
11
|
-
const baseDir = outputFlag ? node_path_1.default.resolve(outputFlag) : process.cwd();
|
|
12
|
-
const outputDir = node_path_1.default.join(baseDir, safeTitle);
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { safeFilename } from "../lib/filename.js";
|
|
3
|
+
export const prepareOutputDir = async (title, outputFlag) => {
|
|
4
|
+
const safeTitle = safeFilename(title || "snapshot");
|
|
5
|
+
const baseDir = outputFlag ? path.resolve(outputFlag) : process.cwd();
|
|
6
|
+
const outputDir = path.join(baseDir, safeTitle);
|
|
13
7
|
return {
|
|
14
8
|
safeTitle,
|
|
15
9
|
outputDir
|
|
16
10
|
};
|
|
17
11
|
};
|
|
18
|
-
exports.prepareOutputDir = prepareOutputDir;
|
|
@@ -1,24 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.NetworkObserverUnit = void 0;
|
|
4
|
-
const contracts_1 = require("@pagepocket/contracts");
|
|
5
|
-
const lib_1 = require("@pagepocket/lib");
|
|
1
|
+
import { NETWORK } from "@pagepocket/contracts";
|
|
2
|
+
import { Unit } from "@pagepocket/lib";
|
|
6
3
|
/**
|
|
7
4
|
* Observes the network@1 channel and forwards events to user-provided callbacks.
|
|
8
5
|
*
|
|
9
6
|
* This unit is intentionally UI-agnostic (no CLI/spinner coupling).
|
|
10
7
|
*/
|
|
11
|
-
class NetworkObserverUnit extends
|
|
8
|
+
export class NetworkObserverUnit extends Unit {
|
|
9
|
+
id = "networkObserver";
|
|
10
|
+
kind = "observe.network";
|
|
11
|
+
config;
|
|
12
12
|
constructor(config = {}) {
|
|
13
13
|
super();
|
|
14
|
-
this.id = "networkObserver";
|
|
15
|
-
this.kind = "observe.network";
|
|
16
14
|
this.config = config;
|
|
17
15
|
}
|
|
18
16
|
async run(_ctx, rt) {
|
|
19
17
|
const config = this.config;
|
|
20
18
|
const task = (async () => {
|
|
21
|
-
for await (const event of rt.subscribe(
|
|
19
|
+
for await (const event of rt.subscribe(NETWORK)) {
|
|
22
20
|
await config.onEvent?.(event);
|
|
23
21
|
if (event.type === "request") {
|
|
24
22
|
await config.onRequest?.(event);
|
|
@@ -34,4 +32,3 @@ class NetworkObserverUnit extends lib_1.Unit {
|
|
|
34
32
|
rt.defer(task);
|
|
35
33
|
}
|
|
36
34
|
}
|
|
37
|
-
exports.NetworkObserverUnit = NetworkObserverUnit;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.normalizeArgv = exports.isUrlLike = void 0;
|
|
4
|
-
const isUrlLike = (value) => {
|
|
1
|
+
export const isUrlLike = (value) => {
|
|
5
2
|
try {
|
|
6
3
|
const url = new URL(value);
|
|
7
4
|
return url.protocol === "http:" || url.protocol === "https:";
|
|
@@ -10,8 +7,7 @@ const isUrlLike = (value) => {
|
|
|
10
7
|
return false;
|
|
11
8
|
}
|
|
12
9
|
};
|
|
13
|
-
|
|
14
|
-
const normalizeArgv = (argv) => {
|
|
10
|
+
export const normalizeArgv = (argv) => {
|
|
15
11
|
// pnpm forwards args to scripts by inserting a literal `--`.
|
|
16
12
|
// oclif does not treat that as a flag; strip it if present.
|
|
17
13
|
if (argv[0] === "--") {
|
|
@@ -22,9 +18,8 @@ const normalizeArgv = (argv) => {
|
|
|
22
18
|
}
|
|
23
19
|
const first = argv[0];
|
|
24
20
|
// If the first token is a URL, treat it as implicit `archive`.
|
|
25
|
-
if (first &&
|
|
21
|
+
if (first && isUrlLike(first)) {
|
|
26
22
|
return ["archive", ...argv];
|
|
27
23
|
}
|
|
28
24
|
return argv;
|
|
29
25
|
};
|
|
30
|
-
exports.normalizeArgv = normalizeArgv;
|
package/dist/utils/parse-json.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseJson = void 0;
|
|
4
1
|
const toErrorMessage = (value) => {
|
|
5
2
|
if (value instanceof Error) {
|
|
6
3
|
return value.message;
|
|
@@ -13,7 +10,7 @@ const toErrorMessage = (value) => {
|
|
|
13
10
|
}
|
|
14
11
|
return JSON.stringify(value);
|
|
15
12
|
};
|
|
16
|
-
const parseJson = (text) => {
|
|
13
|
+
export const parseJson = (text) => {
|
|
17
14
|
try {
|
|
18
15
|
return { ok: true, value: JSON.parse(text) };
|
|
19
16
|
}
|
|
@@ -21,4 +18,3 @@ const parseJson = (text) => {
|
|
|
21
18
|
return { ok: false, error: new Error(toErrorMessage(e)) };
|
|
22
19
|
}
|
|
23
20
|
};
|
|
24
|
-
exports.parseJson = parseJson;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parsePluginOptions = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Parse plugin options from argv tokens.
|
|
6
3
|
*
|
|
7
4
|
* Usage:
|
|
8
5
|
* const parsed = parsePluginOptions(["--option-mode", "strict"]);
|
|
9
6
|
*/
|
|
10
|
-
const parsePluginOptions = (argv) => {
|
|
7
|
+
export const parsePluginOptions = (argv) => {
|
|
11
8
|
const tokens = argv.filter(Boolean);
|
|
12
9
|
const pairs = tokens
|
|
13
10
|
.map((t, i) => ({ t, next: tokens[i + 1] }))
|
|
@@ -45,4 +42,3 @@ const parsePluginOptions = (argv) => {
|
|
|
45
42
|
}
|
|
46
43
|
return { kind: "none" };
|
|
47
44
|
};
|
|
48
|
-
exports.parsePluginOptions = parsePluginOptions;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const parsePluginSpec = (spec) => {
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
export const parsePluginSpec = (spec) => {
|
|
5
5
|
const trimmed = spec.trim();
|
|
6
6
|
if (!trimmed) {
|
|
7
7
|
throw new Error("plugin spec is empty");
|
|
8
8
|
}
|
|
9
|
-
const
|
|
9
|
+
const req = createRequire(import.meta.url ? fileURLToPath(import.meta.url) : path.join(process.cwd(), "package.json"));
|
|
10
|
+
const npa = req("npm-package-arg");
|
|
10
11
|
const parsed = npa(trimmed);
|
|
11
12
|
if (!parsed || typeof parsed.name !== "string" || !parsed.name) {
|
|
12
13
|
throw new Error(`Invalid plugin spec: ${trimmed}`);
|
|
13
14
|
}
|
|
14
15
|
return { name: parsed.name, spec: trimmed };
|
|
15
16
|
};
|
|
16
|
-
exports.parsePluginSpec = parsePluginSpec;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validatePluginDefaultExport = void 0;
|
|
4
1
|
const isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
5
2
|
const isPagePocketPlugin = (value) => {
|
|
6
3
|
if (!isRecord(value)) {
|
|
@@ -23,7 +20,7 @@ const toError = (value) => {
|
|
|
23
20
|
}
|
|
24
21
|
return new Error(typeof value === "string" ? value : JSON.stringify(value));
|
|
25
22
|
};
|
|
26
|
-
const validatePluginDefaultExport = (input) => {
|
|
23
|
+
export const validatePluginDefaultExport = (input) => {
|
|
27
24
|
const { pluginName, moduleExports, options } = input;
|
|
28
25
|
const defaultExport = moduleExports.default;
|
|
29
26
|
if (typeof defaultExport !== "function") {
|
|
@@ -51,4 +48,3 @@ const validatePluginDefaultExport = (input) => {
|
|
|
51
48
|
return { ok: false, error: toError(e) };
|
|
52
49
|
}
|
|
53
50
|
};
|
|
54
|
-
exports.validatePluginDefaultExport = validatePluginDefaultExport;
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.withSpinner = void 0;
|
|
7
|
-
const ora_1 = __importDefault(require("ora"));
|
|
8
|
-
const withSpinner = async (run, spinnerText) => {
|
|
9
|
-
const spinner = (0, ora_1.default)(spinnerText).start();
|
|
1
|
+
import ora from "ora";
|
|
2
|
+
export const withSpinner = async (run, spinnerText) => {
|
|
3
|
+
const spinner = ora(spinnerText).start();
|
|
10
4
|
try {
|
|
11
5
|
const result = await run(spinner);
|
|
12
6
|
spinner.succeed(spinnerText.replace(/\.$/, "") || spinnerText);
|
|
@@ -17,4 +11,3 @@ const withSpinner = async (run, spinnerText) => {
|
|
|
17
11
|
throw error;
|
|
18
12
|
}
|
|
19
13
|
};
|
|
20
|
-
exports.withSpinner = withSpinner;
|
package/dist/view.js
CHANGED
|
@@ -1,25 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const koa_1 = __importDefault(require("koa"));
|
|
10
|
-
const koa_send_1 = __importDefault(require("koa-send"));
|
|
11
|
-
const koa_static_1 = __importDefault(require("koa-static"));
|
|
12
|
-
const createViewServer = async (args) => {
|
|
13
|
-
const indexPath = node_path_1.default.join(args.rootDir, "index.html");
|
|
14
|
-
const stat = await node_fs_1.default.promises.stat(args.rootDir).catch(() => undefined);
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import Koa from "koa";
|
|
4
|
+
import send from "koa-send";
|
|
5
|
+
import serve from "koa-static";
|
|
6
|
+
export const createViewServer = async (args) => {
|
|
7
|
+
const indexPath = path.join(args.rootDir, "index.html");
|
|
8
|
+
const stat = await fs.promises.stat(args.rootDir).catch(() => undefined);
|
|
15
9
|
if (!stat || !stat.isDirectory()) {
|
|
16
10
|
throw new Error(`view: directory not found: ${args.rootDir}`);
|
|
17
11
|
}
|
|
18
|
-
const indexStat = await
|
|
12
|
+
const indexStat = await fs.promises.stat(indexPath).catch(() => undefined);
|
|
19
13
|
if (!indexStat || !indexStat.isFile()) {
|
|
20
14
|
throw new Error(`view: index.html not found under: ${args.rootDir}`);
|
|
21
15
|
}
|
|
22
|
-
const app = new
|
|
16
|
+
const app = new Koa();
|
|
23
17
|
// Avoid Koa's generator-function detection (and its dependency chain) by
|
|
24
18
|
// not calling `app.use()`.
|
|
25
19
|
//
|
|
@@ -27,12 +21,12 @@ const createViewServer = async (args) => {
|
|
|
27
21
|
// `is-generator-function` can break ("getGeneratorFunction is not a function")
|
|
28
22
|
// when it tries to require `generator-function`. We don't need generator
|
|
29
23
|
// middleware support here, so bypass it entirely.
|
|
30
|
-
const staticMw = (
|
|
24
|
+
const staticMw = serve(args.rootDir, { index: false });
|
|
31
25
|
app.middleware.push(staticMw);
|
|
32
26
|
app.middleware.push(async (ctx) => {
|
|
33
27
|
// SPA fallback (anything not matched by static middleware)
|
|
34
28
|
ctx.status = 200;
|
|
35
|
-
await (
|
|
29
|
+
await send(ctx, "index.html", {
|
|
36
30
|
root: args.rootDir
|
|
37
31
|
});
|
|
38
32
|
});
|
|
@@ -53,4 +47,3 @@ const createViewServer = async (args) => {
|
|
|
53
47
|
}
|
|
54
48
|
};
|
|
55
49
|
};
|
|
56
|
-
exports.createViewServer = createViewServer;
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pagepocket/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"description": "CLI for capturing offline snapshots of web pages.",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "dist/index.js",
|
|
6
7
|
"bin": {
|
|
7
8
|
"pp": "dist/index.js"
|
|
@@ -21,16 +22,16 @@
|
|
|
21
22
|
"koa-static": "^5.0.0",
|
|
22
23
|
"npm-package-arg": "^13.0.2",
|
|
23
24
|
"ora": "^9.0.0",
|
|
24
|
-
"@pagepocket/build-snapshot-unit": "0.
|
|
25
|
-
"@pagepocket/capture-http-
|
|
26
|
-
"@pagepocket/
|
|
27
|
-
"@pagepocket/capture-http-lighterceptor-unit": "0.
|
|
28
|
-
"@pagepocket/
|
|
29
|
-
"@pagepocket/
|
|
30
|
-
"@pagepocket/
|
|
31
|
-
"@pagepocket/plugin-yt-dlp": "0.
|
|
32
|
-
"@pagepocket/single-file-unit": "0.
|
|
33
|
-
"@pagepocket/write-down-unit": "0.
|
|
25
|
+
"@pagepocket/build-snapshot-unit": "0.11.1",
|
|
26
|
+
"@pagepocket/capture-http-cdp-unit": "0.11.1",
|
|
27
|
+
"@pagepocket/capture-http-puppeteer-unit": "0.11.1",
|
|
28
|
+
"@pagepocket/capture-http-lighterceptor-unit": "0.11.1",
|
|
29
|
+
"@pagepocket/builtin-strategy": "0.11.1",
|
|
30
|
+
"@pagepocket/contracts": "0.11.1",
|
|
31
|
+
"@pagepocket/lib": "0.11.1",
|
|
32
|
+
"@pagepocket/plugin-yt-dlp": "0.11.1",
|
|
33
|
+
"@pagepocket/single-file-unit": "0.11.1",
|
|
34
|
+
"@pagepocket/write-down-unit": "0.11.1"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
37
|
"@types/koa": "^2.15.0",
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.readInstalledPackageVersion = void 0;
|
|
7
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
-
const parse_json_1 = require("../../utils/parse-json");
|
|
9
|
-
const isRecord = (value) => {
|
|
10
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
11
|
-
};
|
|
12
|
-
const readInstalledPackageVersion = (packageName) => {
|
|
13
|
-
const req = globalThis.require;
|
|
14
|
-
if (!req) {
|
|
15
|
-
throw new Error("require is not available in this runtime");
|
|
16
|
-
}
|
|
17
|
-
const pkgJsonPath = req.resolve(`${packageName}/package.json`);
|
|
18
|
-
const text = node_fs_1.default.readFileSync(pkgJsonPath, "utf8");
|
|
19
|
-
const parsed = (0, parse_json_1.parseJson)(text);
|
|
20
|
-
if (!parsed.ok) {
|
|
21
|
-
throw parsed.error;
|
|
22
|
-
}
|
|
23
|
-
if (!isRecord(parsed.value) || typeof parsed.value.version !== "string") {
|
|
24
|
-
throw new Error(`Failed to read package version: ${packageName}`);
|
|
25
|
-
}
|
|
26
|
-
return parsed.value.version;
|
|
27
|
-
};
|
|
28
|
-
exports.readInstalledPackageVersion = readInstalledPackageVersion;
|