@cjser/locate-path__v7_2_0 7.2.0-cjser.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.
@@ -0,0 +1,99 @@
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
+
29
+ // packages/@cjser/locate-path__v7_2_0.tmp-26-1778149398450/index.js
30
+ var index_exports = {};
31
+ __export(index_exports, {
32
+ locatePath: () => locatePath,
33
+ locatePathSync: () => locatePathSync
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+ var import_node_process = __toESM(require("node:process"), 1);
37
+ var import_node_path = __toESM(require("node:path"), 1);
38
+ var import_node_fs = __toESM(require("node:fs"), 1);
39
+ var import_node_url = require("node:url");
40
+ var import_p_locate_v6_0_0 = __toESM(require("@cjser/p-locate__v6_0_0"), 1);
41
+ var typeMappings = {
42
+ directory: "isDirectory",
43
+ file: "isFile"
44
+ };
45
+ function checkType(type) {
46
+ if (Object.hasOwnProperty.call(typeMappings, type)) {
47
+ return;
48
+ }
49
+ throw new Error(`Invalid type specified: ${type}`);
50
+ }
51
+ var matchType = (type, stat) => stat[typeMappings[type]]();
52
+ var toPath = (urlOrPath) => urlOrPath instanceof URL ? (0, import_node_url.fileURLToPath)(urlOrPath) : urlOrPath;
53
+ async function locatePath(paths, {
54
+ cwd = import_node_process.default.cwd(),
55
+ type = "file",
56
+ allowSymlinks = true,
57
+ concurrency,
58
+ preserveOrder
59
+ } = {}) {
60
+ checkType(type);
61
+ cwd = toPath(cwd);
62
+ const statFunction = allowSymlinks ? import_node_fs.promises.stat : import_node_fs.promises.lstat;
63
+ return (0, import_p_locate_v6_0_0.default)(paths, async (path_) => {
64
+ try {
65
+ const stat = await statFunction(import_node_path.default.resolve(cwd, path_));
66
+ return matchType(type, stat);
67
+ } catch {
68
+ return false;
69
+ }
70
+ }, { concurrency, preserveOrder });
71
+ }
72
+ function locatePathSync(paths, {
73
+ cwd = import_node_process.default.cwd(),
74
+ type = "file",
75
+ allowSymlinks = true
76
+ } = {}) {
77
+ checkType(type);
78
+ cwd = toPath(cwd);
79
+ const statFunction = allowSymlinks ? import_node_fs.default.statSync : import_node_fs.default.lstatSync;
80
+ for (const path_ of paths) {
81
+ try {
82
+ const stat = statFunction(import_node_path.default.resolve(cwd, path_), {
83
+ throwIfNoEntry: false
84
+ });
85
+ if (!stat) {
86
+ continue;
87
+ }
88
+ if (matchType(type, stat)) {
89
+ return path_;
90
+ }
91
+ } catch {
92
+ }
93
+ }
94
+ }
95
+ // Annotate the CommonJS export names for ESM import in node:
96
+ 0 && (module.exports = {
97
+ locatePath,
98
+ locatePathSync
99
+ });
package/index.d.ts ADDED
@@ -0,0 +1,92 @@
1
+ export interface Options {
2
+ /**
3
+ The current working directory.
4
+
5
+ @default process.cwd()
6
+ */
7
+ readonly cwd?: URL | string;
8
+
9
+ /**
10
+ The type of path to match.
11
+
12
+ @default 'file'
13
+ */
14
+ readonly type?: 'file' | 'directory';
15
+
16
+ /**
17
+ Allow symbolic links to match if they point to the requested path type.
18
+
19
+ @default true
20
+ */
21
+ readonly allowSymlinks?: boolean;
22
+ }
23
+
24
+ export interface AsyncOptions extends Options {
25
+ /**
26
+ The number of concurrently pending promises.
27
+
28
+ Minimum: `1`
29
+
30
+ @default Infinity
31
+ */
32
+ readonly concurrency?: number;
33
+
34
+ /**
35
+ Preserve `paths` order when searching.
36
+
37
+ Disable this to improve performance if you don't care about the order.
38
+
39
+ @default true
40
+ */
41
+ readonly preserveOrder?: boolean;
42
+ }
43
+
44
+ /**
45
+ Get the first path that exists on disk of multiple paths.
46
+
47
+ @param paths - The paths to check.
48
+ @returns The first path that exists or `undefined` if none exists.
49
+
50
+ @example
51
+ ```
52
+ import {locatePath} from '@cjser/locate-path__v7_2_0';
53
+
54
+ const files = [
55
+ 'unicorn.png',
56
+ 'rainbow.png', // Only this one actually exists on disk
57
+ 'pony.png'
58
+ ];
59
+
60
+ console(await locatePath(files));
61
+ //=> 'rainbow'
62
+ ```
63
+ */
64
+ export function locatePath(
65
+ paths: Iterable<string>,
66
+ options?: AsyncOptions
67
+ ): Promise<string | undefined>;
68
+
69
+ /**
70
+ Synchronously get the first path that exists on disk of multiple paths.
71
+
72
+ @param paths - The paths to check.
73
+ @returns The first path that exists or `undefined` if none exists.
74
+
75
+ @example
76
+ ```
77
+ import {locatePathSync} from '@cjser/locate-path__v7_2_0';
78
+
79
+ const files = [
80
+ 'unicorn.png',
81
+ 'rainbow.png', // Only this one actually exists on disk
82
+ 'pony.png'
83
+ ];
84
+
85
+ console(locatePathSync(files));
86
+ //=> 'rainbow'
87
+ ```
88
+ */
89
+ export function locatePathSync(
90
+ paths: Iterable<string>,
91
+ options?: Options
92
+ ): string | undefined;
package/index.js ADDED
@@ -0,0 +1,77 @@
1
+ import process from 'node:process';
2
+ import path from 'node:path';
3
+ import fs, {promises as fsPromises} from 'node:fs';
4
+ import {fileURLToPath} from 'node:url';
5
+ import pLocate from '@cjser/p-locate__v6_0_0';
6
+
7
+ const typeMappings = {
8
+ directory: 'isDirectory',
9
+ file: 'isFile',
10
+ };
11
+
12
+ function checkType(type) {
13
+ if (Object.hasOwnProperty.call(typeMappings, type)) {
14
+ return;
15
+ }
16
+
17
+ throw new Error(`Invalid type specified: ${type}`);
18
+ }
19
+
20
+ const matchType = (type, stat) => stat[typeMappings[type]]();
21
+
22
+ const toPath = urlOrPath => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
23
+
24
+ export async function locatePath(
25
+ paths,
26
+ {
27
+ cwd = process.cwd(),
28
+ type = 'file',
29
+ allowSymlinks = true,
30
+ concurrency,
31
+ preserveOrder,
32
+ } = {},
33
+ ) {
34
+ checkType(type);
35
+ cwd = toPath(cwd);
36
+
37
+ const statFunction = allowSymlinks ? fsPromises.stat : fsPromises.lstat;
38
+
39
+ return pLocate(paths, async path_ => {
40
+ try {
41
+ const stat = await statFunction(path.resolve(cwd, path_));
42
+ return matchType(type, stat);
43
+ } catch {
44
+ return false;
45
+ }
46
+ }, {concurrency, preserveOrder});
47
+ }
48
+
49
+ export function locatePathSync(
50
+ paths,
51
+ {
52
+ cwd = process.cwd(),
53
+ type = 'file',
54
+ allowSymlinks = true,
55
+ } = {},
56
+ ) {
57
+ checkType(type);
58
+ cwd = toPath(cwd);
59
+
60
+ const statFunction = allowSymlinks ? fs.statSync : fs.lstatSync;
61
+
62
+ for (const path_ of paths) {
63
+ try {
64
+ const stat = statFunction(path.resolve(cwd, path_), {
65
+ throwIfNoEntry: false,
66
+ });
67
+
68
+ if (!stat) {
69
+ continue;
70
+ }
71
+
72
+ if (matchType(type, stat)) {
73
+ return path_;
74
+ }
75
+ } catch {}
76
+ }
77
+ }
package/license ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,76 @@
1
+ {
2
+ "name": "@cjser/locate-path__v7_2_0",
3
+ "version": "7.2.0-cjser.2",
4
+ "description": "Get the first path that exists on disk of multiple paths",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://code.moenext.com/3rdeye/cjser.git"
9
+ },
10
+ "funding": "https://github.com/sponsors/sindresorhus",
11
+ "author": {
12
+ "name": "Sindre Sorhus",
13
+ "email": "sindresorhus@gmail.com",
14
+ "url": "https://sindresorhus.com"
15
+ },
16
+ "type": "module",
17
+ "exports": {
18
+ "require": "./dist-cjser/index.cjs",
19
+ "default": "./index.js"
20
+ },
21
+ "engines": {
22
+ "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
23
+ },
24
+ "scripts": {
25
+ "test": "xo && ava && tsd"
26
+ },
27
+ "files": [
28
+ "index.js",
29
+ "index.d.ts",
30
+ "dist-cjser"
31
+ ],
32
+ "keywords": [
33
+ "locate",
34
+ "path",
35
+ "paths",
36
+ "file",
37
+ "files",
38
+ "exists",
39
+ "find",
40
+ "finder",
41
+ "search",
42
+ "searcher",
43
+ "array",
44
+ "iterable",
45
+ "iterator"
46
+ ],
47
+ "dependencies": {
48
+ "@cjser/p-locate__v6_0_0": "6.0.0-cjser.2"
49
+ },
50
+ "devDependencies": {
51
+ "ava": "^3.15.0",
52
+ "tsd": "^0.17.0",
53
+ "xo": "^0.44.0"
54
+ },
55
+ "main": "./dist-cjser/index.cjs",
56
+ "cjser": {
57
+ "sourceVersion": "7.2.0",
58
+ "cjserVersion": 2,
59
+ "original": {
60
+ "name": "locate-path",
61
+ "version": "7.2.0",
62
+ "exports": "./index.js",
63
+ "repository": "sindresorhus/locate-path",
64
+ "dependencies": {
65
+ "p-locate": "^6.0.0"
66
+ },
67
+ "files": [
68
+ "index.js",
69
+ "index.d.ts"
70
+ ],
71
+ "scripts": {
72
+ "test": "xo && ava && tsd"
73
+ }
74
+ }
75
+ }
76
+ }
package/readme.md ADDED
@@ -0,0 +1,128 @@
1
+ # locate-path
2
+
3
+ > Get the first path that exists on disk of multiple paths
4
+
5
+ ## Install
6
+
7
+ ```
8
+ $ npm install locate-path
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ Here we find the first file that exists on disk, in array order.
14
+
15
+ ```js
16
+ import {locatePath} from 'locate-path';
17
+
18
+ const files = [
19
+ 'unicorn.png',
20
+ 'rainbow.png', // Only this one actually exists on disk
21
+ 'pony.png'
22
+ ];
23
+
24
+ console(await locatePath(files));
25
+ //=> 'rainbow'
26
+ ```
27
+
28
+ ## API
29
+
30
+ ### locatePath(paths, options?)
31
+
32
+ Returns a `Promise<string>` for the first path that exists or `undefined` if none exists.
33
+
34
+ #### paths
35
+
36
+ Type: `Iterable<string>`
37
+
38
+ The paths to check.
39
+
40
+ #### options
41
+
42
+ Type: `object`
43
+
44
+ ##### concurrency
45
+
46
+ Type: `number`\
47
+ Default: `Infinity`\
48
+ Minimum: `1`
49
+
50
+ The number of concurrently pending promises.
51
+
52
+ ##### preserveOrder
53
+
54
+ Type: `boolean`\
55
+ Default: `true`
56
+
57
+ Preserve `paths` order when searching.
58
+
59
+ Disable this to improve performance if you don't care about the order.
60
+
61
+ ##### cwd
62
+
63
+ Type: `URL | string`\
64
+ Default: `process.cwd()`
65
+
66
+ The current working directory.
67
+
68
+ ##### type
69
+
70
+ Type: `string`\
71
+ Default: `'file'`\
72
+ Values: `'file' | 'directory'`
73
+
74
+ The type of paths that can match.
75
+
76
+ ##### allowSymlinks
77
+
78
+ Type: `boolean`\
79
+ Default: `true`
80
+
81
+ Allow symbolic links to match if they point to the chosen path type.
82
+
83
+ ### locatePathSync(paths, options?)
84
+
85
+ Returns the first path that exists or `undefined` if none exists.
86
+
87
+ #### paths
88
+
89
+ Type: `Iterable<string>`
90
+
91
+ The paths to check.
92
+
93
+ #### options
94
+
95
+ Type: `object`
96
+
97
+ ##### cwd
98
+
99
+ Same as above.
100
+
101
+ ##### type
102
+
103
+ Same as above.
104
+
105
+ ##### allowSymlinks
106
+
107
+ Same as above.
108
+
109
+ ## Related
110
+
111
+ - [path-exists](https://github.com/sindresorhus/path-exists) - Check if a path exists
112
+
113
+ ---
114
+
115
+ <div align="center">
116
+ <b>
117
+ <a href="https://tidelift.com/subscription/pkg/npm-locate-path?utm_source=npm-locate-path&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
118
+ </b>
119
+ <br>
120
+ <sub>
121
+ Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
122
+ </sub>
123
+ </div>
124
+
125
+ ## cjser
126
+
127
+ This package is a CommonJS-compatible build generated by cjser for projects that still need `require()` support. The source version matches the original npm package version, with a cjser prerelease suffix for this generated build.
128
+ Original repository: https://github.com/sindresorhus/locate-path