@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,41 @@
|
|
|
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 cancel_handler_exports = {};
|
|
19
|
+
__export(cancel_handler_exports, {
|
|
20
|
+
closeCancelHandler: () => closeCancelHandler,
|
|
21
|
+
createCancelHandler: () => createCancelHandler,
|
|
22
|
+
getCancelHandler: () => getCancelHandler
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(cancel_handler_exports);
|
|
25
|
+
let nextRid = 1;
|
|
26
|
+
const resources = {};
|
|
27
|
+
const createCancelHandler = () => {
|
|
28
|
+
const rid = nextRid++;
|
|
29
|
+
const cancelHandler = {};
|
|
30
|
+
imports.signals.addSignalMethods(cancelHandler);
|
|
31
|
+
resources[rid] = cancelHandler;
|
|
32
|
+
return rid;
|
|
33
|
+
};
|
|
34
|
+
const closeCancelHandler = (rid) => {
|
|
35
|
+
const cancelHandler = getCancelHandler(rid);
|
|
36
|
+
cancelHandler?.emit("close");
|
|
37
|
+
delete resources[rid];
|
|
38
|
+
};
|
|
39
|
+
const getCancelHandler = (rid) => {
|
|
40
|
+
return resources[rid];
|
|
41
|
+
};
|
package/lib/cjs/cli.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
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 cli_exports = {};
|
|
29
|
+
__export(cli_exports, {
|
|
30
|
+
cli: () => cli
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(cli_exports);
|
|
33
|
+
var import_glib_2 = __toESM(require("@girs/glib-2.0"), 1);
|
|
34
|
+
const byteArray = imports.byteArray;
|
|
35
|
+
const cli = (commandLine) => {
|
|
36
|
+
const [res, out, err, status] = import_glib_2.default.spawn_command_line_sync(commandLine);
|
|
37
|
+
if (err.byteLength)
|
|
38
|
+
throw new Error(byteArray.toString(err));
|
|
39
|
+
return byteArray.toString(out);
|
|
40
|
+
};
|
package/lib/cjs/error.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
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 error_exports = {};
|
|
19
|
+
__export(error_exports, {
|
|
20
|
+
initErrorV8Methods: () => initErrorV8Methods
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(error_exports);
|
|
23
|
+
const initErrorV8Methods = (ErrorConstructor) => {
|
|
24
|
+
if (!Error.captureStackTrace) {
|
|
25
|
+
Error.captureStackTrace = function(targetObject, constructorOpt) {
|
|
26
|
+
const container = new Error();
|
|
27
|
+
const target = constructorOpt || targetObject;
|
|
28
|
+
Object.defineProperty(target, "stack", {
|
|
29
|
+
configurable: true,
|
|
30
|
+
get: function getStack() {
|
|
31
|
+
var stack = container.stack;
|
|
32
|
+
Object.defineProperty(this, "stack", {
|
|
33
|
+
value: stack
|
|
34
|
+
});
|
|
35
|
+
return stack;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
};
|
package/lib/cjs/file.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
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 file_exports = {};
|
|
29
|
+
__export(file_exports, {
|
|
30
|
+
readJSON: () => readJSON
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(file_exports);
|
|
33
|
+
var import_glib_2 = __toESM(require("@girs/glib-2.0"), 1);
|
|
34
|
+
const byteArray = imports.byteArray;
|
|
35
|
+
const readJSON = (path) => {
|
|
36
|
+
const [ok, contents] = import_glib_2.default.file_get_contents(path);
|
|
37
|
+
if (ok) {
|
|
38
|
+
const map = JSON.parse(byteArray.toString(contents));
|
|
39
|
+
return map;
|
|
40
|
+
}
|
|
41
|
+
throw new Error(`Error on require "${path}"`);
|
|
42
|
+
};
|
package/lib/cjs/fs.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
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 fs_exports = {};
|
|
29
|
+
__export(fs_exports, {
|
|
30
|
+
existsFD: () => existsFD,
|
|
31
|
+
existsSync: () => existsSync
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(fs_exports);
|
|
34
|
+
var import_gio_2 = __toESM(require("@girs/gio-2.0"), 1);
|
|
35
|
+
const existsFD = (fd) => {
|
|
36
|
+
try {
|
|
37
|
+
let stream = import_gio_2.default.UnixInputStream.new(fd, false);
|
|
38
|
+
stream.close(null);
|
|
39
|
+
return true;
|
|
40
|
+
} catch (error) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
function existsSync(path) {
|
|
45
|
+
if (typeof path !== "string" || path === "") {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
const file = import_gio_2.default.File.new_for_path(path);
|
|
49
|
+
return file.query_exists(null);
|
|
50
|
+
}
|
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
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 src_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(src_exports);
|
|
17
|
+
__reExport(src_exports, require("./types/index.js"), module.exports);
|
|
18
|
+
__reExport(src_exports, require("./cancel-handler.js"), module.exports);
|
|
19
|
+
__reExport(src_exports, require("./cli.js"), module.exports);
|
|
20
|
+
__reExport(src_exports, require("./error.js"), module.exports);
|
|
21
|
+
__reExport(src_exports, require("./file.js"), module.exports);
|
|
22
|
+
__reExport(src_exports, require("./fs.js"), module.exports);
|
|
23
|
+
__reExport(src_exports, require("./log.js"), module.exports);
|
|
24
|
+
__reExport(src_exports, require("./message.js"), module.exports);
|
|
25
|
+
__reExport(src_exports, require("./os.js"), module.exports);
|
|
26
|
+
__reExport(src_exports, require("./path.js"), module.exports);
|
|
27
|
+
__reExport(src_exports, require("./process.js"), module.exports);
|
|
28
|
+
__reExport(src_exports, require("./system.js"), module.exports);
|
|
29
|
+
__reExport(src_exports, require("./tty.js"), module.exports);
|
|
30
|
+
__reExport(src_exports, require("./version.js"), module.exports);
|
package/lib/cjs/log.js
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
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 log_exports = {};
|
|
29
|
+
__export(log_exports, {
|
|
30
|
+
LogSignals: () => LogSignals,
|
|
31
|
+
extractErrorData: () => extractErrorData,
|
|
32
|
+
logLevelToString: () => logLevelToString,
|
|
33
|
+
logSignals: () => logSignals,
|
|
34
|
+
parseStackTrace: () => parseStackTrace
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(log_exports);
|
|
37
|
+
var import_glib_2 = __toESM(require("@girs/glib-2.0"), 1);
|
|
38
|
+
const logLevelToString = (logLevel) => {
|
|
39
|
+
switch (logLevel) {
|
|
40
|
+
case import_glib_2.default.LogLevelFlags.FLAG_FATAL:
|
|
41
|
+
return "FLAG_FATAL";
|
|
42
|
+
case import_glib_2.default.LogLevelFlags.FLAG_RECURSION:
|
|
43
|
+
return "FLAG_RECURSION";
|
|
44
|
+
case import_glib_2.default.LogLevelFlags.LEVEL_CRITICAL:
|
|
45
|
+
return "LEVEL_CRITICAL";
|
|
46
|
+
case import_glib_2.default.LogLevelFlags.LEVEL_DEBUG:
|
|
47
|
+
return "LEVEL_DEBUG";
|
|
48
|
+
case import_glib_2.default.LogLevelFlags.LEVEL_ERROR:
|
|
49
|
+
return "LEVEL_ERROR";
|
|
50
|
+
case import_glib_2.default.LogLevelFlags.LEVEL_INFO:
|
|
51
|
+
return "LEVEL_INFO";
|
|
52
|
+
case import_glib_2.default.LogLevelFlags.LEVEL_MASK:
|
|
53
|
+
return "LEVEL_MASK";
|
|
54
|
+
case import_glib_2.default.LogLevelFlags.LEVEL_MESSAGE:
|
|
55
|
+
return "LEVEL_MESSAGE";
|
|
56
|
+
case import_glib_2.default.LogLevelFlags.LEVEL_WARNING:
|
|
57
|
+
return "LEVEL_WARNING";
|
|
58
|
+
default:
|
|
59
|
+
return "UNKNOWN";
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const STACK_TRACE_REGEX = /^.*@(.*):(\d+):(\d+)/;
|
|
63
|
+
const parseStackTrace = (stackTraceLine) => {
|
|
64
|
+
const match = stackTraceLine.match(STACK_TRACE_REGEX);
|
|
65
|
+
if (match) {
|
|
66
|
+
const [, fileName, lineNumber, columnNumber] = match;
|
|
67
|
+
return { fileName, lineNumber: Number(lineNumber), columnNumber: Number(columnNumber), line: stackTraceLine };
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
};
|
|
71
|
+
const getStackTraceStartLineIndex = (lines) => {
|
|
72
|
+
for (let i = 1; i < lines.length; i++) {
|
|
73
|
+
const line = lines[i];
|
|
74
|
+
if (STACK_TRACE_REGEX.test(line)) {
|
|
75
|
+
return i;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return -1;
|
|
79
|
+
};
|
|
80
|
+
const extractErrorData = (errorMessage) => {
|
|
81
|
+
const lines = errorMessage.split("\n");
|
|
82
|
+
for (let line of lines) {
|
|
83
|
+
line = line.trim();
|
|
84
|
+
}
|
|
85
|
+
const endOfErrorType = lines[0].indexOf(": ");
|
|
86
|
+
let errorType = "Error";
|
|
87
|
+
if (endOfErrorType > 0) {
|
|
88
|
+
errorType = lines[0].slice(0, endOfErrorType);
|
|
89
|
+
if (globalThis[errorType]) {
|
|
90
|
+
lines[0] = lines[0].slice(endOfErrorType + 2);
|
|
91
|
+
} else {
|
|
92
|
+
errorType = "Error";
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
let stackTraceLineIndex = getStackTraceStartLineIndex(lines);
|
|
96
|
+
const message = lines.slice(0, stackTraceLineIndex).join("\n");
|
|
97
|
+
const stackTraceLines = lines.slice(stackTraceLineIndex);
|
|
98
|
+
const frames = [];
|
|
99
|
+
for (const stackTraceLine of stackTraceLines) {
|
|
100
|
+
const frame = parseStackTrace(stackTraceLine);
|
|
101
|
+
if (frame) {
|
|
102
|
+
frames.push(frame);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
errorType,
|
|
107
|
+
message,
|
|
108
|
+
frames,
|
|
109
|
+
stackTraceLines
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
const reconstructErrorFromMessage = (errorMessage) => {
|
|
113
|
+
const { errorType, frames, message, stackTraceLines } = extractErrorData(errorMessage);
|
|
114
|
+
const ErrorType = globalThis[errorType];
|
|
115
|
+
const error = new ErrorType();
|
|
116
|
+
error.message = message;
|
|
117
|
+
error.stack = stackTraceLines.join("\n");
|
|
118
|
+
return {
|
|
119
|
+
error,
|
|
120
|
+
errorType,
|
|
121
|
+
frames,
|
|
122
|
+
message,
|
|
123
|
+
stackTraceLines
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
class LogSignals {
|
|
127
|
+
static instance;
|
|
128
|
+
/** This is a singleton because log_set_writer_func may only be called once */
|
|
129
|
+
constructor() {
|
|
130
|
+
this.initHandler();
|
|
131
|
+
}
|
|
132
|
+
static getSingleton() {
|
|
133
|
+
if (LogSignals.instance) {
|
|
134
|
+
return LogSignals.instance;
|
|
135
|
+
}
|
|
136
|
+
LogSignals.instance = new LogSignals();
|
|
137
|
+
return LogSignals.instance;
|
|
138
|
+
}
|
|
139
|
+
initHandler() {
|
|
140
|
+
import_glib_2.default.log_set_writer_func((level, fields) => {
|
|
141
|
+
const decoder = new TextDecoder("utf-8");
|
|
142
|
+
const message = decoder.decode(fields?.MESSAGE);
|
|
143
|
+
const priority = Number(decoder.decode(fields?.PRIORITY));
|
|
144
|
+
const domain = decoder.decode(fields?.GLIB_DOMAIN);
|
|
145
|
+
const data = {
|
|
146
|
+
message,
|
|
147
|
+
priority,
|
|
148
|
+
domain
|
|
149
|
+
};
|
|
150
|
+
if (!this.handler(level, data)) {
|
|
151
|
+
level |= import_glib_2.default.LogLevelFlags.FLAG_RECURSION;
|
|
152
|
+
import_glib_2.default.log_default_handler(domain, level, message, null);
|
|
153
|
+
}
|
|
154
|
+
return import_glib_2.default.LogWriterOutput.HANDLED;
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* A log handler to emit `unhandledRejection` and `uncaughtException` events
|
|
159
|
+
* @param level The log level
|
|
160
|
+
* @param data The structured log data
|
|
161
|
+
* @returns `true` to catch the log or `false` to output the error to the console as usual
|
|
162
|
+
*/
|
|
163
|
+
handler(level, structuredData) {
|
|
164
|
+
if (level === import_glib_2.default.LogLevelFlags.LEVEL_WARNING && structuredData.domain === "Gjs" && structuredData.message.startsWith("Unhandled promise rejection")) {
|
|
165
|
+
try {
|
|
166
|
+
const errorData = reconstructErrorFromMessage(structuredData.message);
|
|
167
|
+
const fakePromise = new Promise(() => {
|
|
168
|
+
});
|
|
169
|
+
logSignals.emit("unhandledRejection", structuredData, {
|
|
170
|
+
reason: errorData.error,
|
|
171
|
+
promise: fakePromise,
|
|
172
|
+
errorType: errorData.errorType,
|
|
173
|
+
frames: errorData.frames,
|
|
174
|
+
message: errorData.message,
|
|
175
|
+
stackTraceLines: errorData.stackTraceLines
|
|
176
|
+
});
|
|
177
|
+
} catch (error) {
|
|
178
|
+
printerr(error);
|
|
179
|
+
}
|
|
180
|
+
} else if (level === import_glib_2.default.LogLevelFlags.LEVEL_CRITICAL) {
|
|
181
|
+
const errorData = reconstructErrorFromMessage(structuredData.message);
|
|
182
|
+
logSignals.emit("uncaughtException", structuredData, errorData);
|
|
183
|
+
}
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
imports.signals.addSignalMethods(LogSignals.prototype);
|
|
188
|
+
const logSignals = LogSignals.getSingleton();
|
|
@@ -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 message_exports = {};
|
|
19
|
+
__export(message_exports, {
|
|
20
|
+
notImplemented: () => notImplemented,
|
|
21
|
+
warnNotImplemented: () => warnNotImplemented
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(message_exports);
|
|
24
|
+
const notImplemented = (msg) => {
|
|
25
|
+
const message = msg ? `Not implemented: ${msg}` : "Not implemented";
|
|
26
|
+
throw new Error(message);
|
|
27
|
+
};
|
|
28
|
+
const warnNotImplemented = (msg) => {
|
|
29
|
+
const message = msg ? `Not implemented: ${msg}` : "Not implemented";
|
|
30
|
+
console.warn(message);
|
|
31
|
+
return message;
|
|
32
|
+
};
|
package/lib/cjs/os.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
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 os_exports = {};
|
|
29
|
+
__export(os_exports, {
|
|
30
|
+
getArch: () => getArch,
|
|
31
|
+
getEnv: () => getEnv,
|
|
32
|
+
getOs: () => getOs,
|
|
33
|
+
getTarget: () => getTarget,
|
|
34
|
+
getUserInfo: () => getUserInfo,
|
|
35
|
+
getVendor: () => getVendor
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(os_exports);
|
|
38
|
+
var import_cli = require("./cli.js");
|
|
39
|
+
var import_glib_2 = __toESM(require("@girs/glib-2.0"), 1);
|
|
40
|
+
var import_gio_2 = __toESM(require("@girs/gio-2.0"), 1);
|
|
41
|
+
let _arch = "";
|
|
42
|
+
let _os = "";
|
|
43
|
+
let _target = "";
|
|
44
|
+
const userInfo = {};
|
|
45
|
+
const getArch = () => {
|
|
46
|
+
if (_arch) {
|
|
47
|
+
return _arch;
|
|
48
|
+
}
|
|
49
|
+
_arch = (0, import_cli.cli)("uname -m").trim();
|
|
50
|
+
return _arch;
|
|
51
|
+
};
|
|
52
|
+
const getOs = () => {
|
|
53
|
+
if (_os) {
|
|
54
|
+
return _os;
|
|
55
|
+
}
|
|
56
|
+
const os = (0, import_cli.cli)("uname -o").trim();
|
|
57
|
+
if (/\bDarwin\b/i.test(os)) {
|
|
58
|
+
_os = "darwin";
|
|
59
|
+
return _os;
|
|
60
|
+
}
|
|
61
|
+
if (/\bLinux\b/i.test(os)) {
|
|
62
|
+
_os = "linux";
|
|
63
|
+
return _os;
|
|
64
|
+
}
|
|
65
|
+
_os = "win32";
|
|
66
|
+
return _os;
|
|
67
|
+
};
|
|
68
|
+
const getVendor = () => "gjsify";
|
|
69
|
+
const getEnv = () => "gnu";
|
|
70
|
+
const getTarget = () => {
|
|
71
|
+
if (_target) {
|
|
72
|
+
return _target;
|
|
73
|
+
}
|
|
74
|
+
_target = `${getArch()}-${getVendor()}-${getOs()}-${getEnv()}`;
|
|
75
|
+
return _target;
|
|
76
|
+
};
|
|
77
|
+
const extractUserInfo = (passwd, username) => {
|
|
78
|
+
const lines = passwd.split("\n");
|
|
79
|
+
for (const line of lines) {
|
|
80
|
+
const parts = line.split(":");
|
|
81
|
+
if (parts[0] === username) {
|
|
82
|
+
return {
|
|
83
|
+
username: parts[0],
|
|
84
|
+
// password: parts[1],
|
|
85
|
+
userId: parseInt(parts[2], 10),
|
|
86
|
+
groupId: parseInt(parts[3], 10),
|
|
87
|
+
userInfo: parts[4],
|
|
88
|
+
homeDirectory: parts[5],
|
|
89
|
+
shell: parts[6]
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return null;
|
|
94
|
+
};
|
|
95
|
+
const getUserInfo = (username) => {
|
|
96
|
+
const file = import_gio_2.default.File.new_for_path("/etc/passwd");
|
|
97
|
+
if (!username) {
|
|
98
|
+
username = import_glib_2.default.get_user_name();
|
|
99
|
+
}
|
|
100
|
+
if (userInfo[username]) {
|
|
101
|
+
return userInfo[username];
|
|
102
|
+
}
|
|
103
|
+
const [success, contents] = file.load_contents(null);
|
|
104
|
+
if (!success) {
|
|
105
|
+
throw new Error(`Failed to load ${file.get_path()}`);
|
|
106
|
+
}
|
|
107
|
+
const contentStr = new TextDecoder().decode(contents);
|
|
108
|
+
userInfo[username] = extractUserInfo(contentStr, username);
|
|
109
|
+
return userInfo[username];
|
|
110
|
+
};
|
package/lib/cjs/path.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
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 path_exports = {};
|
|
29
|
+
__export(path_exports, {
|
|
30
|
+
getNodeModulesPath: () => getNodeModulesPath,
|
|
31
|
+
getPathSeparator: () => getPathSeparator,
|
|
32
|
+
getProgramDir: () => getProgramDir,
|
|
33
|
+
getProgramExe: () => getProgramExe,
|
|
34
|
+
resolve: () => resolve
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(path_exports);
|
|
37
|
+
var import_gio_2 = __toESM(require("@girs/gio-2.0"), 1);
|
|
38
|
+
var import_glib_2 = __toESM(require("@girs/glib-2.0"), 1);
|
|
39
|
+
const { File } = import_gio_2.default;
|
|
40
|
+
const _getProgramDir = (programFile) => {
|
|
41
|
+
const info = programFile.query_info("standard::", import_gio_2.default.FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null);
|
|
42
|
+
if (info.get_is_symlink()) {
|
|
43
|
+
const symlinkFile = programFile.get_parent().resolve_relative_path(info.get_symlink_target());
|
|
44
|
+
return symlinkFile.get_parent();
|
|
45
|
+
} else {
|
|
46
|
+
return programFile.get_parent();
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const resolve = (dir, ...filenames) => {
|
|
50
|
+
let file = File.new_for_path(dir);
|
|
51
|
+
for (const filename of filenames) {
|
|
52
|
+
file = file.resolve_relative_path(filename);
|
|
53
|
+
}
|
|
54
|
+
return file;
|
|
55
|
+
};
|
|
56
|
+
const getProgramExe = () => {
|
|
57
|
+
const currentDir = import_glib_2.default.get_current_dir();
|
|
58
|
+
return File.new_for_path(currentDir).resolve_relative_path(imports.system.programInvocationName);
|
|
59
|
+
};
|
|
60
|
+
const getProgramDir = () => {
|
|
61
|
+
return _getProgramDir(getProgramExe()).get_path();
|
|
62
|
+
};
|
|
63
|
+
const getPathSeparator = () => {
|
|
64
|
+
const currentDir = import_glib_2.default.get_current_dir();
|
|
65
|
+
return /^\//.test(currentDir) ? "/" : "\\";
|
|
66
|
+
};
|
|
67
|
+
const getNodeModulesPath = () => {
|
|
68
|
+
let dir = File.new_for_path(getProgramDir());
|
|
69
|
+
let found = false;
|
|
70
|
+
do {
|
|
71
|
+
dir = dir.resolve_relative_path("..");
|
|
72
|
+
const nodeModulesDir = dir.resolve_relative_path("node_modules");
|
|
73
|
+
found = nodeModulesDir.query_exists(null);
|
|
74
|
+
if (found) {
|
|
75
|
+
dir = nodeModulesDir;
|
|
76
|
+
}
|
|
77
|
+
} while (dir.has_parent(null) && !found);
|
|
78
|
+
return dir;
|
|
79
|
+
};
|