@optique/discover 1.2.0-dev.2167 → 1.2.0-dev.2179

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.
@@ -0,0 +1,60 @@
1
+ const require_chunk = require('./chunk-CUT6urMc.cjs');
2
+ const node_url = require_chunk.__toESM(require("node:url"));
3
+ const node_fs = require_chunk.__toESM(require("node:fs"));
4
+
5
+ //#region src/main-check.ts
6
+ /**
7
+ * Checks whether a module is the current process entry point.
8
+ *
9
+ * @param options Main-module check inputs.
10
+ * @returns Whether the module should run as the process entry point.
11
+ * @internal
12
+ * @since 1.2.0
13
+ */
14
+ function isMainModule(options) {
15
+ if (options.importMetaMain != null) return options.importMetaMain;
16
+ if (options.argvEntry == null) return false;
17
+ const realpath = options.realpath ?? node_fs.realpathSync;
18
+ return realpathOrOriginal(options.argvEntry, realpath) === realpathOrOriginal(options.modulePath, realpath);
19
+ }
20
+ /**
21
+ * Checks whether a module URL is the current process entry point.
22
+ *
23
+ * Non-file module URLs rely on `import.meta.main` because process entry points
24
+ * are file-system paths.
25
+ *
26
+ * @param options Main-module URL check inputs.
27
+ * @returns Whether the module should run as the process entry point.
28
+ * @internal
29
+ * @since 1.2.0
30
+ */
31
+ function isMainModuleUrl(options) {
32
+ if (options.importMetaMain != null) return options.importMetaMain;
33
+ if (!options.moduleUrl.startsWith("file:")) return false;
34
+ return isMainModule({
35
+ modulePath: (0, node_url.fileURLToPath)(options.moduleUrl),
36
+ argvEntry: options.argvEntry,
37
+ realpath: options.realpath
38
+ });
39
+ }
40
+ function realpathOrOriginal(path, realpath) {
41
+ try {
42
+ return realpath(path);
43
+ } catch {
44
+ return path;
45
+ }
46
+ }
47
+
48
+ //#endregion
49
+ Object.defineProperty(exports, 'isMainModule', {
50
+ enumerable: true,
51
+ get: function () {
52
+ return isMainModule;
53
+ }
54
+ });
55
+ Object.defineProperty(exports, 'isMainModuleUrl', {
56
+ enumerable: true,
57
+ get: function () {
58
+ return isMainModuleUrl;
59
+ }
60
+ });
@@ -0,0 +1,48 @@
1
+ import { fileURLToPath } from "node:url";
2
+ import { realpathSync } from "node:fs";
3
+
4
+ //#region src/main-check.ts
5
+ /**
6
+ * Checks whether a module is the current process entry point.
7
+ *
8
+ * @param options Main-module check inputs.
9
+ * @returns Whether the module should run as the process entry point.
10
+ * @internal
11
+ * @since 1.2.0
12
+ */
13
+ function isMainModule(options) {
14
+ if (options.importMetaMain != null) return options.importMetaMain;
15
+ if (options.argvEntry == null) return false;
16
+ const realpath = options.realpath ?? realpathSync;
17
+ return realpathOrOriginal(options.argvEntry, realpath) === realpathOrOriginal(options.modulePath, realpath);
18
+ }
19
+ /**
20
+ * Checks whether a module URL is the current process entry point.
21
+ *
22
+ * Non-file module URLs rely on `import.meta.main` because process entry points
23
+ * are file-system paths.
24
+ *
25
+ * @param options Main-module URL check inputs.
26
+ * @returns Whether the module should run as the process entry point.
27
+ * @internal
28
+ * @since 1.2.0
29
+ */
30
+ function isMainModuleUrl(options) {
31
+ if (options.importMetaMain != null) return options.importMetaMain;
32
+ if (!options.moduleUrl.startsWith("file:")) return false;
33
+ return isMainModule({
34
+ modulePath: fileURLToPath(options.moduleUrl),
35
+ argvEntry: options.argvEntry,
36
+ realpath: options.realpath
37
+ });
38
+ }
39
+ function realpathOrOriginal(path, realpath) {
40
+ try {
41
+ return realpath(path);
42
+ } catch {
43
+ return path;
44
+ }
45
+ }
46
+
47
+ //#endregion
48
+ export { isMainModule, isMainModuleUrl };
@@ -0,0 +1,4 @@
1
+ const require_main_check = require('./main-check-CwunSNpK.cjs');
2
+
3
+ exports.isMainModule = require_main_check.isMainModule;
4
+ exports.isMainModuleUrl = require_main_check.isMainModuleUrl;
@@ -0,0 +1,72 @@
1
+ //#region src/main-check.d.ts
2
+ /**
3
+ * Options for checking whether an ESM module is the process entry point.
4
+ *
5
+ * @internal
6
+ * @since 1.2.0
7
+ */
8
+ interface MainModuleOptions {
9
+ /**
10
+ * `import.meta.main` when the current runtime provides it.
11
+ */
12
+ readonly importMetaMain?: boolean;
13
+ /**
14
+ * Path to the current module.
15
+ */
16
+ readonly modulePath: string;
17
+ /**
18
+ * Process entry-point path.
19
+ */
20
+ readonly argvEntry?: string;
21
+ /**
22
+ * Function used to resolve symlinks.
23
+ */
24
+ readonly realpath?: (path: string) => string;
25
+ }
26
+ /**
27
+ * Options for checking whether an ESM module URL is the process entry point.
28
+ *
29
+ * @internal
30
+ * @since 1.2.0
31
+ */
32
+ interface MainModuleUrlOptions {
33
+ /**
34
+ * `import.meta.main` when the current runtime provides it.
35
+ */
36
+ readonly importMetaMain?: boolean;
37
+ /**
38
+ * URL of the current module.
39
+ */
40
+ readonly moduleUrl: string;
41
+ /**
42
+ * Process entry-point path.
43
+ */
44
+ readonly argvEntry?: string;
45
+ /**
46
+ * Function used to resolve symlinks.
47
+ */
48
+ readonly realpath?: (path: string) => string;
49
+ }
50
+ /**
51
+ * Checks whether a module is the current process entry point.
52
+ *
53
+ * @param options Main-module check inputs.
54
+ * @returns Whether the module should run as the process entry point.
55
+ * @internal
56
+ * @since 1.2.0
57
+ */
58
+ declare function isMainModule(options: MainModuleOptions): boolean;
59
+ /**
60
+ * Checks whether a module URL is the current process entry point.
61
+ *
62
+ * Non-file module URLs rely on `import.meta.main` because process entry points
63
+ * are file-system paths.
64
+ *
65
+ * @param options Main-module URL check inputs.
66
+ * @returns Whether the module should run as the process entry point.
67
+ * @internal
68
+ * @since 1.2.0
69
+ */
70
+ declare function isMainModuleUrl(options: MainModuleUrlOptions): boolean;
71
+ //#endregion
72
+ export { MainModuleOptions, MainModuleUrlOptions, isMainModule, isMainModuleUrl };
@@ -0,0 +1,72 @@
1
+ //#region src/main-check.d.ts
2
+ /**
3
+ * Options for checking whether an ESM module is the process entry point.
4
+ *
5
+ * @internal
6
+ * @since 1.2.0
7
+ */
8
+ interface MainModuleOptions {
9
+ /**
10
+ * `import.meta.main` when the current runtime provides it.
11
+ */
12
+ readonly importMetaMain?: boolean;
13
+ /**
14
+ * Path to the current module.
15
+ */
16
+ readonly modulePath: string;
17
+ /**
18
+ * Process entry-point path.
19
+ */
20
+ readonly argvEntry?: string;
21
+ /**
22
+ * Function used to resolve symlinks.
23
+ */
24
+ readonly realpath?: (path: string) => string;
25
+ }
26
+ /**
27
+ * Options for checking whether an ESM module URL is the process entry point.
28
+ *
29
+ * @internal
30
+ * @since 1.2.0
31
+ */
32
+ interface MainModuleUrlOptions {
33
+ /**
34
+ * `import.meta.main` when the current runtime provides it.
35
+ */
36
+ readonly importMetaMain?: boolean;
37
+ /**
38
+ * URL of the current module.
39
+ */
40
+ readonly moduleUrl: string;
41
+ /**
42
+ * Process entry-point path.
43
+ */
44
+ readonly argvEntry?: string;
45
+ /**
46
+ * Function used to resolve symlinks.
47
+ */
48
+ readonly realpath?: (path: string) => string;
49
+ }
50
+ /**
51
+ * Checks whether a module is the current process entry point.
52
+ *
53
+ * @param options Main-module check inputs.
54
+ * @returns Whether the module should run as the process entry point.
55
+ * @internal
56
+ * @since 1.2.0
57
+ */
58
+ declare function isMainModule(options: MainModuleOptions): boolean;
59
+ /**
60
+ * Checks whether a module URL is the current process entry point.
61
+ *
62
+ * Non-file module URLs rely on `import.meta.main` because process entry points
63
+ * are file-system paths.
64
+ *
65
+ * @param options Main-module URL check inputs.
66
+ * @returns Whether the module should run as the process entry point.
67
+ * @internal
68
+ * @since 1.2.0
69
+ */
70
+ declare function isMainModuleUrl(options: MainModuleUrlOptions): boolean;
71
+ //#endregion
72
+ export { MainModuleOptions, MainModuleUrlOptions, isMainModule, isMainModuleUrl };
@@ -0,0 +1,3 @@
1
+ import { isMainModule, isMainModuleUrl } from "./main-check-mMnKfUZs.js";
2
+
3
+ export { isMainModule, isMainModuleUrl };