pgpm 0.2.18 → 0.4.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/README.md +12 -4
- package/commands/cache.d.ts +3 -0
- package/commands/cache.js +32 -0
- package/commands/init/index.d.ts +1 -0
- package/commands/init/index.js +25 -20
- package/commands/init/module.js +19 -25
- package/commands/init/workspace.js +25 -29
- package/commands/update.d.ts +3 -0
- package/commands/update.js +69 -0
- package/commands.js +15 -1
- package/esm/commands/cache.js +30 -0
- package/esm/commands/init/index.js +23 -20
- package/esm/commands/init/module.js +21 -27
- package/esm/commands/init/workspace.js +26 -30
- package/esm/commands/update.js +67 -0
- package/esm/commands.js +15 -1
- package/esm/index.js +1 -0
- package/esm/utils/display.js +3 -1
- package/esm/utils/index.js +3 -0
- package/esm/utils/npm-version.js +46 -0
- package/esm/utils/update-check.js +57 -0
- package/esm/utils/update-config.js +50 -0
- package/index.d.ts +1 -0
- package/index.js +3 -1
- package/package.json +12 -9
- package/utils/display.d.ts +1 -1
- package/utils/display.js +3 -1
- package/utils/index.d.ts +3 -0
- package/utils/index.js +3 -0
- package/utils/npm-version.d.ts +2 -0
- package/utils/npm-version.js +54 -0
- package/utils/update-check.d.ts +10 -0
- package/utils/update-check.js +60 -0
- package/utils/update-config.d.ts +10 -0
- package/utils/update-config.js +60 -0
|
@@ -0,0 +1,60 @@
|
|
|
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.resolveUpdateConfigPath = exports.shouldCheck = void 0;
|
|
7
|
+
exports.readUpdateConfig = readUpdateConfig;
|
|
8
|
+
exports.writeUpdateConfig = writeUpdateConfig;
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const appstash_1 = require("appstash");
|
|
12
|
+
const types_1 = require("@launchql/types");
|
|
13
|
+
const defaultToolName = 'pgpm';
|
|
14
|
+
const getConfigPath = (options = {}) => {
|
|
15
|
+
const toolName = options.toolName ?? defaultToolName;
|
|
16
|
+
const dirs = (0, appstash_1.appstash)(toolName, {
|
|
17
|
+
ensure: true,
|
|
18
|
+
baseDir: options.baseDir
|
|
19
|
+
});
|
|
20
|
+
const configDir = (0, appstash_1.resolve)(dirs, 'config');
|
|
21
|
+
if (!fs_1.default.existsSync(configDir)) {
|
|
22
|
+
fs_1.default.mkdirSync(configDir, { recursive: true });
|
|
23
|
+
}
|
|
24
|
+
const fileName = `${(options.key ?? types_1.UPDATE_CHECK_APPSTASH_KEY).replace(/[^a-z0-9-_]/gi, '_')}.json`;
|
|
25
|
+
return path_1.default.join(configDir, fileName);
|
|
26
|
+
};
|
|
27
|
+
const shouldCheck = (now, lastCheckedAt, ttlMs) => {
|
|
28
|
+
if (!lastCheckedAt)
|
|
29
|
+
return true;
|
|
30
|
+
return now - lastCheckedAt > ttlMs;
|
|
31
|
+
};
|
|
32
|
+
exports.shouldCheck = shouldCheck;
|
|
33
|
+
async function readUpdateConfig(options = {}) {
|
|
34
|
+
const configPath = getConfigPath(options);
|
|
35
|
+
if (!fs_1.default.existsSync(configPath)) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
const contents = await fs_1.default.promises.readFile(configPath, 'utf8');
|
|
40
|
+
const parsed = JSON.parse(contents);
|
|
41
|
+
return parsed;
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
// Corrupted config – clear it
|
|
45
|
+
try {
|
|
46
|
+
await fs_1.default.promises.rm(configPath, { force: true });
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// ignore
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async function writeUpdateConfig(config, options = {}) {
|
|
55
|
+
const configPath = getConfigPath(options);
|
|
56
|
+
await fs_1.default.promises.writeFile(configPath, JSON.stringify(config, null, 2), 'utf8');
|
|
57
|
+
}
|
|
58
|
+
// Exposed for testing to locate the config path for a given namespace/baseDir
|
|
59
|
+
const resolveUpdateConfigPath = (options = {}) => getConfigPath(options);
|
|
60
|
+
exports.resolveUpdateConfigPath = resolveUpdateConfigPath;
|