@gjsify/utils 0.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.
- package/lib/cjs/cancel-handler.js +41 -0
- package/lib/cjs/cli.js +40 -0
- package/lib/cjs/error.js +40 -0
- package/lib/cjs/file.js +42 -0
- package/lib/cjs/fs.js +50 -0
- package/lib/cjs/index.js +30 -0
- package/lib/cjs/log.js +188 -0
- package/lib/cjs/message.js +32 -0
- package/lib/cjs/os.js +110 -0
- package/lib/cjs/path.js +79 -0
- package/lib/cjs/process.js +70 -0
- package/lib/cjs/system.js +77 -0
- package/lib/cjs/tty.js +32 -0
- package/lib/cjs/types/cancel-signals.js +15 -0
- package/lib/cjs/types/error-data.js +15 -0
- package/lib/cjs/types/index.js +24 -0
- package/lib/cjs/types/signal-methods.js +15 -0
- package/lib/cjs/types/stack-trace-frame.js +15 -0
- package/lib/cjs/types/structured-log-data.js +15 -0
- package/lib/cjs/types/uncaught-exception-data.js +15 -0
- package/lib/cjs/types/unhandled-rejection-data.js +15 -0
- package/lib/cjs/types/user-info.js +15 -0
- package/lib/cjs/version.js +26 -0
- package/lib/esm/cancel-handler.js +22 -0
- package/lib/esm/cli.js +11 -0
- package/lib/esm/error.js +21 -0
- package/lib/esm/file.js +13 -0
- package/lib/esm/fs.js +21 -0
- package/lib/esm/index.js +14 -0
- package/lib/esm/log.js +159 -0
- package/lib/esm/message.js +13 -0
- package/lib/esm/os.js +81 -0
- package/lib/esm/path.js +50 -0
- package/lib/esm/process.js +41 -0
- package/lib/esm/system.js +47 -0
- package/lib/esm/tty.js +13 -0
- package/lib/esm/types/cancel-signals.js +0 -0
- package/lib/esm/types/error-data.js +0 -0
- package/lib/esm/types/index.js +8 -0
- package/lib/esm/types/signal-methods.js +0 -0
- package/lib/esm/types/stack-trace-frame.js +0 -0
- package/lib/esm/types/structured-log-data.js +0 -0
- package/lib/esm/types/uncaught-exception-data.js +0 -0
- package/lib/esm/types/unhandled-rejection-data.js +0 -0
- package/lib/esm/types/user-info.js +0 -0
- package/lib/esm/version.js +7 -0
- package/lib/types/cancel-handler.d.ts +4 -0
- package/lib/types/cli.d.ts +1 -0
- package/lib/types/error.d.ts +7 -0
- package/lib/types/file.d.ts +1 -0
- package/lib/types/fs.d.ts +3 -0
- package/lib/types/index.d.ts +14 -0
- package/lib/types/log.d.ts +29 -0
- package/lib/types/message.d.ts +2 -0
- package/lib/types/os.d.ts +7 -0
- package/lib/types/path.d.ts +6 -0
- package/lib/types/process.d.ts +6 -0
- package/lib/types/system.d.ts +5 -0
- package/lib/types/tty.d.ts +5 -0
- package/lib/types/types/cancel-signals.d.ts +5 -0
- package/lib/types/types/error-data.d.ts +7 -0
- package/lib/types/types/index.d.ts +8 -0
- package/lib/types/types/signal-methods.d.ts +62 -0
- package/lib/types/types/stack-trace-frame.d.ts +6 -0
- package/lib/types/types/structured-log-data.d.ts +5 -0
- package/lib/types/types/uncaught-exception-data.d.ts +4 -0
- package/lib/types/types/unhandled-rejection-data.d.ts +5 -0
- package/lib/types/types/user-info.d.ts +8 -0
- package/lib/types/version.d.ts +1 -0
- package/package.json +46 -0
- package/src/cancel-handler.ts +24 -0
- package/src/cli.ts +10 -0
- package/src/error.ts +38 -0
- package/src/file.ts +12 -0
- package/src/fs.ts +24 -0
- package/src/index.ts +15 -0
- package/src/log.spec.ts +32 -0
- package/src/log.ts +218 -0
- package/src/message.ts +11 -0
- package/src/os.ts +94 -0
- package/src/path.ts +52 -0
- package/src/process.spec.ts +24 -0
- package/src/process.ts +46 -0
- package/src/system.ts +56 -0
- package/src/test.ts +6 -0
- package/src/tty.spec.ts +10 -0
- package/src/tty.ts +10 -0
- package/src/types/cancel-signals.ts +6 -0
- package/src/types/error-data.ts +8 -0
- package/src/types/index.ts +8 -0
- package/src/types/signal-methods.ts +63 -0
- package/src/types/stack-trace-frame.ts +7 -0
- package/src/types/structured-log-data.ts +5 -0
- package/src/types/uncaught-exception-data.ts +5 -0
- package/src/types/unhandled-rejection-data.ts +6 -0
- package/src/types/user-info.ts +9 -0
- package/src/version.ts +4 -0
- package/test.gjs.js +34793 -0
- package/test.gjs.js.map +7 -0
- package/test.gjs.js.meta.json +1 -0
- package/tsconfig.json +21 -0
- package/tsconfig.types.json +7 -0
- package/tsconfig.types.tsbuildinfo +1 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var process_exports = {};
|
|
29
|
+
__export(process_exports, {
|
|
30
|
+
getLocale: () => getLocale,
|
|
31
|
+
getPid: () => getPid,
|
|
32
|
+
getPpid: () => getPpid,
|
|
33
|
+
getTitle: () => getTitle
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(process_exports);
|
|
36
|
+
var import_gio_2 = __toESM(require("@girs/gio-2.0"), 1);
|
|
37
|
+
var import_glib_2 = __toESM(require("@girs/glib-2.0"), 1);
|
|
38
|
+
let PID = 0;
|
|
39
|
+
let PPID = 0;
|
|
40
|
+
let LOCALE = "";
|
|
41
|
+
const getLocale = () => {
|
|
42
|
+
if (!LOCALE) {
|
|
43
|
+
LOCALE = import_glib_2.default.getenv("LANG").split(".")[0].replace("_", "-");
|
|
44
|
+
}
|
|
45
|
+
return LOCALE;
|
|
46
|
+
};
|
|
47
|
+
const getPid = () => {
|
|
48
|
+
if (!PID) {
|
|
49
|
+
PID = new import_gio_2.default.Credentials().get_unix_pid();
|
|
50
|
+
}
|
|
51
|
+
return PID;
|
|
52
|
+
};
|
|
53
|
+
const getPpid = () => {
|
|
54
|
+
if (!PPID) {
|
|
55
|
+
const path = `/proc/${getPid()}/status`;
|
|
56
|
+
const file = import_gio_2.default.File.new_for_path(path);
|
|
57
|
+
const [success, contents] = file.load_contents(null);
|
|
58
|
+
if (success) {
|
|
59
|
+
const contentStr = new TextDecoder().decode(contents);
|
|
60
|
+
const numStr = contentStr.match(/^PPid:.*$/gm)[0]?.match(/(\d+)$/gm)[0];
|
|
61
|
+
PPID = Number(numStr);
|
|
62
|
+
} else {
|
|
63
|
+
console.error(new Error("Failed to read file: " + path));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return PPID;
|
|
67
|
+
};
|
|
68
|
+
const getTitle = () => {
|
|
69
|
+
return import_glib_2.default.get_prgname();
|
|
70
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var system_exports = {};
|
|
29
|
+
__export(system_exports, {
|
|
30
|
+
getArgs: () => getArgs,
|
|
31
|
+
getArgv: () => getArgv,
|
|
32
|
+
parseArgv: () => parseArgv
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(system_exports);
|
|
35
|
+
var import_glib_2 = __toESM(require("@girs/glib-2.0"), 1);
|
|
36
|
+
var import_gio_2 = __toESM(require("@girs/gio-2.0"), 1);
|
|
37
|
+
var import_fs = require("./fs.js");
|
|
38
|
+
const import_meta = {};
|
|
39
|
+
const File = import_gio_2.default.File;
|
|
40
|
+
const args = [];
|
|
41
|
+
const getArgv = () => {
|
|
42
|
+
if (args.length) {
|
|
43
|
+
return args;
|
|
44
|
+
}
|
|
45
|
+
const [__filename] = import_glib_2.default.filename_from_uri(import_meta.url);
|
|
46
|
+
args.push(__filename);
|
|
47
|
+
ARGV.forEach((arg) => {
|
|
48
|
+
if (arg[0] !== "-") {
|
|
49
|
+
args.push(
|
|
50
|
+
(0, import_fs.existsSync)(arg) ? File.new_for_path(arg).get_path() : arg
|
|
51
|
+
);
|
|
52
|
+
} else {
|
|
53
|
+
args.push(arg);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
return args;
|
|
57
|
+
};
|
|
58
|
+
const getArgs = () => {
|
|
59
|
+
return getArgv().slice(2);
|
|
60
|
+
};
|
|
61
|
+
const parseArgv = (argv) => {
|
|
62
|
+
let result = {};
|
|
63
|
+
let currentKey = null;
|
|
64
|
+
for (let i = 0; i < argv.length; i++) {
|
|
65
|
+
let arg = argv[i];
|
|
66
|
+
if (arg.startsWith("--")) {
|
|
67
|
+
currentKey = arg.substring(2);
|
|
68
|
+
result[currentKey] = true;
|
|
69
|
+
} else if (currentKey !== null) {
|
|
70
|
+
result[currentKey] = arg;
|
|
71
|
+
currentKey = null;
|
|
72
|
+
} else {
|
|
73
|
+
result[arg] = true;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return result;
|
|
77
|
+
};
|
package/lib/cjs/tty.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var tty_exports = {};
|
|
19
|
+
__export(tty_exports, {
|
|
20
|
+
STDERR_FD: () => STDERR_FD,
|
|
21
|
+
STDIN_FD: () => STDIN_FD,
|
|
22
|
+
STDOUT_FD: () => STDOUT_FD,
|
|
23
|
+
existsTty: () => existsTty
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(tty_exports);
|
|
26
|
+
var import_fs = require("./fs.js");
|
|
27
|
+
const STDIN_FD = 0;
|
|
28
|
+
const STDOUT_FD = 1;
|
|
29
|
+
const STDERR_FD = 2;
|
|
30
|
+
const existsTty = () => {
|
|
31
|
+
return (0, import_fs.existsFD)(STDOUT_FD);
|
|
32
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
var cancel_signals_exports = {};
|
|
15
|
+
module.exports = __toCommonJS(cancel_signals_exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
var error_data_exports = {};
|
|
15
|
+
module.exports = __toCommonJS(error_data_exports);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
|
17
|
+
__reExport(types_exports, require("./cancel-signals.js"), module.exports);
|
|
18
|
+
__reExport(types_exports, require("./error-data.js"), module.exports);
|
|
19
|
+
__reExport(types_exports, require("./signal-methods.js"), module.exports);
|
|
20
|
+
__reExport(types_exports, require("./stack-trace-frame.js"), module.exports);
|
|
21
|
+
__reExport(types_exports, require("./structured-log-data.js"), module.exports);
|
|
22
|
+
__reExport(types_exports, require("./uncaught-exception-data.js"), module.exports);
|
|
23
|
+
__reExport(types_exports, require("./unhandled-rejection-data.js"), module.exports);
|
|
24
|
+
__reExport(types_exports, require("./user-info.js"), module.exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
var signal_methods_exports = {};
|
|
15
|
+
module.exports = __toCommonJS(signal_methods_exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
var stack_trace_frame_exports = {};
|
|
15
|
+
module.exports = __toCommonJS(stack_trace_frame_exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
var structured_log_data_exports = {};
|
|
15
|
+
module.exports = __toCommonJS(structured_log_data_exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
var uncaught_exception_data_exports = {};
|
|
15
|
+
module.exports = __toCommonJS(uncaught_exception_data_exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
var unhandled_rejection_data_exports = {};
|
|
15
|
+
module.exports = __toCommonJS(unhandled_rejection_data_exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
var user_info_exports = {};
|
|
15
|
+
module.exports = __toCommonJS(user_info_exports);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var version_exports = {};
|
|
19
|
+
__export(version_exports, {
|
|
20
|
+
getGjsVersion: () => getGjsVersion
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(version_exports);
|
|
23
|
+
const getGjsVersion = () => {
|
|
24
|
+
const v = imports.system.version.toString();
|
|
25
|
+
return `${v[0]}.${+(v[1] + v[2])}.${+(v[3] + v[4])}`;
|
|
26
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
let nextRid = 1;
|
|
2
|
+
const resources = {};
|
|
3
|
+
const createCancelHandler = () => {
|
|
4
|
+
const rid = nextRid++;
|
|
5
|
+
const cancelHandler = {};
|
|
6
|
+
imports.signals.addSignalMethods(cancelHandler);
|
|
7
|
+
resources[rid] = cancelHandler;
|
|
8
|
+
return rid;
|
|
9
|
+
};
|
|
10
|
+
const closeCancelHandler = (rid) => {
|
|
11
|
+
const cancelHandler = getCancelHandler(rid);
|
|
12
|
+
cancelHandler?.emit("close");
|
|
13
|
+
delete resources[rid];
|
|
14
|
+
};
|
|
15
|
+
const getCancelHandler = (rid) => {
|
|
16
|
+
return resources[rid];
|
|
17
|
+
};
|
|
18
|
+
export {
|
|
19
|
+
closeCancelHandler,
|
|
20
|
+
createCancelHandler,
|
|
21
|
+
getCancelHandler
|
|
22
|
+
};
|
package/lib/esm/cli.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import GLib from "@girs/glib-2.0";
|
|
2
|
+
const byteArray = imports.byteArray;
|
|
3
|
+
const cli = (commandLine) => {
|
|
4
|
+
const [res, out, err, status] = GLib.spawn_command_line_sync(commandLine);
|
|
5
|
+
if (err.byteLength)
|
|
6
|
+
throw new Error(byteArray.toString(err));
|
|
7
|
+
return byteArray.toString(out);
|
|
8
|
+
};
|
|
9
|
+
export {
|
|
10
|
+
cli
|
|
11
|
+
};
|
package/lib/esm/error.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const initErrorV8Methods = (ErrorConstructor) => {
|
|
2
|
+
if (!Error.captureStackTrace) {
|
|
3
|
+
Error.captureStackTrace = function(targetObject, constructorOpt) {
|
|
4
|
+
const container = new Error();
|
|
5
|
+
const target = constructorOpt || targetObject;
|
|
6
|
+
Object.defineProperty(target, "stack", {
|
|
7
|
+
configurable: true,
|
|
8
|
+
get: function getStack() {
|
|
9
|
+
var stack = container.stack;
|
|
10
|
+
Object.defineProperty(this, "stack", {
|
|
11
|
+
value: stack
|
|
12
|
+
});
|
|
13
|
+
return stack;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
export {
|
|
20
|
+
initErrorV8Methods
|
|
21
|
+
};
|
package/lib/esm/file.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import GLib from "@girs/glib-2.0";
|
|
2
|
+
const byteArray = imports.byteArray;
|
|
3
|
+
const readJSON = (path) => {
|
|
4
|
+
const [ok, contents] = GLib.file_get_contents(path);
|
|
5
|
+
if (ok) {
|
|
6
|
+
const map = JSON.parse(byteArray.toString(contents));
|
|
7
|
+
return map;
|
|
8
|
+
}
|
|
9
|
+
throw new Error(`Error on require "${path}"`);
|
|
10
|
+
};
|
|
11
|
+
export {
|
|
12
|
+
readJSON
|
|
13
|
+
};
|
package/lib/esm/fs.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import Gio from "@girs/gio-2.0";
|
|
2
|
+
const existsFD = (fd) => {
|
|
3
|
+
try {
|
|
4
|
+
let stream = Gio.UnixInputStream.new(fd, false);
|
|
5
|
+
stream.close(null);
|
|
6
|
+
return true;
|
|
7
|
+
} catch (error) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
function existsSync(path) {
|
|
12
|
+
if (typeof path !== "string" || path === "") {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
const file = Gio.File.new_for_path(path);
|
|
16
|
+
return file.query_exists(null);
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
existsFD,
|
|
20
|
+
existsSync
|
|
21
|
+
};
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from "./types/index.js";
|
|
2
|
+
export * from "./cancel-handler.js";
|
|
3
|
+
export * from "./cli.js";
|
|
4
|
+
export * from "./error.js";
|
|
5
|
+
export * from "./file.js";
|
|
6
|
+
export * from "./fs.js";
|
|
7
|
+
export * from "./log.js";
|
|
8
|
+
export * from "./message.js";
|
|
9
|
+
export * from "./os.js";
|
|
10
|
+
export * from "./path.js";
|
|
11
|
+
export * from "./process.js";
|
|
12
|
+
export * from "./system.js";
|
|
13
|
+
export * from "./tty.js";
|
|
14
|
+
export * from "./version.js";
|
package/lib/esm/log.js
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import GLib from "@girs/glib-2.0";
|
|
2
|
+
const logLevelToString = (logLevel) => {
|
|
3
|
+
switch (logLevel) {
|
|
4
|
+
case GLib.LogLevelFlags.FLAG_FATAL:
|
|
5
|
+
return "FLAG_FATAL";
|
|
6
|
+
case GLib.LogLevelFlags.FLAG_RECURSION:
|
|
7
|
+
return "FLAG_RECURSION";
|
|
8
|
+
case GLib.LogLevelFlags.LEVEL_CRITICAL:
|
|
9
|
+
return "LEVEL_CRITICAL";
|
|
10
|
+
case GLib.LogLevelFlags.LEVEL_DEBUG:
|
|
11
|
+
return "LEVEL_DEBUG";
|
|
12
|
+
case GLib.LogLevelFlags.LEVEL_ERROR:
|
|
13
|
+
return "LEVEL_ERROR";
|
|
14
|
+
case GLib.LogLevelFlags.LEVEL_INFO:
|
|
15
|
+
return "LEVEL_INFO";
|
|
16
|
+
case GLib.LogLevelFlags.LEVEL_MASK:
|
|
17
|
+
return "LEVEL_MASK";
|
|
18
|
+
case GLib.LogLevelFlags.LEVEL_MESSAGE:
|
|
19
|
+
return "LEVEL_MESSAGE";
|
|
20
|
+
case GLib.LogLevelFlags.LEVEL_WARNING:
|
|
21
|
+
return "LEVEL_WARNING";
|
|
22
|
+
default:
|
|
23
|
+
return "UNKNOWN";
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const STACK_TRACE_REGEX = /^.*@(.*):(\d+):(\d+)/;
|
|
27
|
+
const parseStackTrace = (stackTraceLine) => {
|
|
28
|
+
const match = stackTraceLine.match(STACK_TRACE_REGEX);
|
|
29
|
+
if (match) {
|
|
30
|
+
const [, fileName, lineNumber, columnNumber] = match;
|
|
31
|
+
return { fileName, lineNumber: Number(lineNumber), columnNumber: Number(columnNumber), line: stackTraceLine };
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
};
|
|
35
|
+
const getStackTraceStartLineIndex = (lines) => {
|
|
36
|
+
for (let i = 1; i < lines.length; i++) {
|
|
37
|
+
const line = lines[i];
|
|
38
|
+
if (STACK_TRACE_REGEX.test(line)) {
|
|
39
|
+
return i;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return -1;
|
|
43
|
+
};
|
|
44
|
+
const extractErrorData = (errorMessage) => {
|
|
45
|
+
const lines = errorMessage.split("\n");
|
|
46
|
+
for (let line of lines) {
|
|
47
|
+
line = line.trim();
|
|
48
|
+
}
|
|
49
|
+
const endOfErrorType = lines[0].indexOf(": ");
|
|
50
|
+
let errorType = "Error";
|
|
51
|
+
if (endOfErrorType > 0) {
|
|
52
|
+
errorType = lines[0].slice(0, endOfErrorType);
|
|
53
|
+
if (globalThis[errorType]) {
|
|
54
|
+
lines[0] = lines[0].slice(endOfErrorType + 2);
|
|
55
|
+
} else {
|
|
56
|
+
errorType = "Error";
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
let stackTraceLineIndex = getStackTraceStartLineIndex(lines);
|
|
60
|
+
const message = lines.slice(0, stackTraceLineIndex).join("\n");
|
|
61
|
+
const stackTraceLines = lines.slice(stackTraceLineIndex);
|
|
62
|
+
const frames = [];
|
|
63
|
+
for (const stackTraceLine of stackTraceLines) {
|
|
64
|
+
const frame = parseStackTrace(stackTraceLine);
|
|
65
|
+
if (frame) {
|
|
66
|
+
frames.push(frame);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
errorType,
|
|
71
|
+
message,
|
|
72
|
+
frames,
|
|
73
|
+
stackTraceLines
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
const reconstructErrorFromMessage = (errorMessage) => {
|
|
77
|
+
const { errorType, frames, message, stackTraceLines } = extractErrorData(errorMessage);
|
|
78
|
+
const ErrorType = globalThis[errorType];
|
|
79
|
+
const error = new ErrorType();
|
|
80
|
+
error.message = message;
|
|
81
|
+
error.stack = stackTraceLines.join("\n");
|
|
82
|
+
return {
|
|
83
|
+
error,
|
|
84
|
+
errorType,
|
|
85
|
+
frames,
|
|
86
|
+
message,
|
|
87
|
+
stackTraceLines
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
class LogSignals {
|
|
91
|
+
static instance;
|
|
92
|
+
/** This is a singleton because log_set_writer_func may only be called once */
|
|
93
|
+
constructor() {
|
|
94
|
+
this.initHandler();
|
|
95
|
+
}
|
|
96
|
+
static getSingleton() {
|
|
97
|
+
if (LogSignals.instance) {
|
|
98
|
+
return LogSignals.instance;
|
|
99
|
+
}
|
|
100
|
+
LogSignals.instance = new LogSignals();
|
|
101
|
+
return LogSignals.instance;
|
|
102
|
+
}
|
|
103
|
+
initHandler() {
|
|
104
|
+
GLib.log_set_writer_func((level, fields) => {
|
|
105
|
+
const decoder = new TextDecoder("utf-8");
|
|
106
|
+
const message = decoder.decode(fields?.MESSAGE);
|
|
107
|
+
const priority = Number(decoder.decode(fields?.PRIORITY));
|
|
108
|
+
const domain = decoder.decode(fields?.GLIB_DOMAIN);
|
|
109
|
+
const data = {
|
|
110
|
+
message,
|
|
111
|
+
priority,
|
|
112
|
+
domain
|
|
113
|
+
};
|
|
114
|
+
if (!this.handler(level, data)) {
|
|
115
|
+
level |= GLib.LogLevelFlags.FLAG_RECURSION;
|
|
116
|
+
GLib.log_default_handler(domain, level, message, null);
|
|
117
|
+
}
|
|
118
|
+
return GLib.LogWriterOutput.HANDLED;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* A log handler to emit `unhandledRejection` and `uncaughtException` events
|
|
123
|
+
* @param level The log level
|
|
124
|
+
* @param data The structured log data
|
|
125
|
+
* @returns `true` to catch the log or `false` to output the error to the console as usual
|
|
126
|
+
*/
|
|
127
|
+
handler(level, structuredData) {
|
|
128
|
+
if (level === GLib.LogLevelFlags.LEVEL_WARNING && structuredData.domain === "Gjs" && structuredData.message.startsWith("Unhandled promise rejection")) {
|
|
129
|
+
try {
|
|
130
|
+
const errorData = reconstructErrorFromMessage(structuredData.message);
|
|
131
|
+
const fakePromise = new Promise(() => {
|
|
132
|
+
});
|
|
133
|
+
logSignals.emit("unhandledRejection", structuredData, {
|
|
134
|
+
reason: errorData.error,
|
|
135
|
+
promise: fakePromise,
|
|
136
|
+
errorType: errorData.errorType,
|
|
137
|
+
frames: errorData.frames,
|
|
138
|
+
message: errorData.message,
|
|
139
|
+
stackTraceLines: errorData.stackTraceLines
|
|
140
|
+
});
|
|
141
|
+
} catch (error) {
|
|
142
|
+
printerr(error);
|
|
143
|
+
}
|
|
144
|
+
} else if (level === GLib.LogLevelFlags.LEVEL_CRITICAL) {
|
|
145
|
+
const errorData = reconstructErrorFromMessage(structuredData.message);
|
|
146
|
+
logSignals.emit("uncaughtException", structuredData, errorData);
|
|
147
|
+
}
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
imports.signals.addSignalMethods(LogSignals.prototype);
|
|
152
|
+
const logSignals = LogSignals.getSingleton();
|
|
153
|
+
export {
|
|
154
|
+
LogSignals,
|
|
155
|
+
extractErrorData,
|
|
156
|
+
logLevelToString,
|
|
157
|
+
logSignals,
|
|
158
|
+
parseStackTrace
|
|
159
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const notImplemented = (msg) => {
|
|
2
|
+
const message = msg ? `Not implemented: ${msg}` : "Not implemented";
|
|
3
|
+
throw new Error(message);
|
|
4
|
+
};
|
|
5
|
+
const warnNotImplemented = (msg) => {
|
|
6
|
+
const message = msg ? `Not implemented: ${msg}` : "Not implemented";
|
|
7
|
+
console.warn(message);
|
|
8
|
+
return message;
|
|
9
|
+
};
|
|
10
|
+
export {
|
|
11
|
+
notImplemented,
|
|
12
|
+
warnNotImplemented
|
|
13
|
+
};
|