@pkgr/core 0.1.1 → 0.1.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/constants.d.ts +1 -2
- package/lib/helpers.d.ts +1 -1
- package/lib/helpers.js +10 -8
- package/lib/helpers.js.map +1 -1
- package/lib/index.cjs +8 -6
- package/package.json +3 -3
package/lib/constants.d.ts
CHANGED
package/lib/helpers.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const tryPkg: (pkg: string) => string | undefined;
|
|
2
2
|
export declare const isPkgAvailable: (pkg: string) => boolean;
|
|
3
|
-
export declare const tryFile: (
|
|
3
|
+
export declare const tryFile: (filename?: string[] | string, includeDir?: boolean, base?: string) => string;
|
|
4
4
|
export declare const tryExtensions: (filepath: string, extensions?: string[]) => string;
|
|
5
5
|
export declare const findUp: (searchEntry: string, searchFileOrIncludeDir?: boolean | string, includeDir?: boolean) => string;
|
package/lib/helpers.js
CHANGED
|
@@ -8,16 +8,18 @@ export const tryPkg = (pkg) => {
|
|
|
8
8
|
catch (_a) { }
|
|
9
9
|
};
|
|
10
10
|
export const isPkgAvailable = (pkg) => !!tryPkg(pkg);
|
|
11
|
-
export const tryFile = (
|
|
12
|
-
if (typeof
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
export const tryFile = (filename, includeDir = false, base = CWD) => {
|
|
12
|
+
if (typeof filename === 'string') {
|
|
13
|
+
const filepath = path.resolve(base, filename);
|
|
14
|
+
return fs.existsSync(filepath) &&
|
|
15
|
+
(includeDir || fs.statSync(filepath).isFile())
|
|
16
|
+
? filepath
|
|
16
17
|
: '';
|
|
17
18
|
}
|
|
18
|
-
for (const file of
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
for (const file of filename !== null && filename !== void 0 ? filename : []) {
|
|
20
|
+
const filepath = tryFile(file, includeDir, base);
|
|
21
|
+
if (filepath) {
|
|
22
|
+
return filepath;
|
|
21
23
|
}
|
|
22
24
|
}
|
|
23
25
|
return '';
|
package/lib/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE5D,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,GAAW,EAAE,EAAE;IACpC,IAAI,CAAC;QACH,OAAO,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IAChC,CAAC;IAAC,WAAM,CAAC,CAAA,CAAC;AACZ,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;AAE5D,MAAM,CAAC,MAAM,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE5D,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,GAAW,EAAE,EAAE;IACpC,IAAI,CAAC;QACH,OAAO,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IAChC,CAAC;IAAC,WAAM,CAAC,CAAA,CAAC;AACZ,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;AAE5D,MAAM,CAAC,MAAM,OAAO,GAAG,CACrB,QAA4B,EAC5B,UAAU,GAAG,KAAK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,CAAC,WAAW,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAChE,CAAC;QACD,OAAO,EAAE,CAAA;IACX,CAAC;IAED,WAAW,GAAG,IAAI,CAAC,OAAO,CACxB,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,WAAW,EAAE;QACpC,CAAC,CAAC,WAAW;QACb,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC,CACpC,CAAA;IAED,MAAM,YAAY,GAAG,OAAO,sBAAsB,KAAK,QAAQ,CAAA;IAE/D,MAAM,UAAU,GAAG,YAAY,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,cAAc,CAAA;IAEzE,GAAG,CAAC;QACF,MAAM,QAAQ,GAAG,OAAO,CACtB,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,UAAU,CAAC,EACrC,YAAY,IAAI,UAAU,CAC3B,CAAA;QACD,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,QAAQ,CAAA;QACjB,CAAC;QACD,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC,CAAA;IAC/C,CAAC,QAAQ,WAAW,KAAK,GAAG,IAAI,WAAW,CAAC,UAAU,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,EAAC;IAEvE,OAAO,EAAE,CAAA;AACX,CAAC,CAAA"}
|
package/lib/index.cjs
CHANGED
|
@@ -16,13 +16,15 @@ const tryPkg = (pkg) => {
|
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
18
|
const isPkgAvailable = (pkg) => !!tryPkg(pkg);
|
|
19
|
-
const tryFile = (
|
|
20
|
-
if (typeof
|
|
21
|
-
|
|
19
|
+
const tryFile = (filename, includeDir = false, base = CWD) => {
|
|
20
|
+
if (typeof filename === "string") {
|
|
21
|
+
const filepath = path.resolve(base, filename);
|
|
22
|
+
return fs.existsSync(filepath) && (includeDir || fs.statSync(filepath).isFile()) ? filepath : "";
|
|
22
23
|
}
|
|
23
|
-
for (const file of
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
for (const file of filename != null ? filename : []) {
|
|
25
|
+
const filepath = tryFile(file, includeDir, base);
|
|
26
|
+
if (filepath) {
|
|
27
|
+
return filepath;
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
30
|
return "";
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pkgr/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Shared core module for `@pkgr` packages or any package else",
|
|
6
|
-
"repository": "
|
|
6
|
+
"repository": "https://github.com/un-ts/pkgr.git",
|
|
7
7
|
"homepage": "https://github.com/un-ts/pkgr/blob/master/packages/core",
|
|
8
|
-
"author": "JounQin (https://www.1stG.me)
|
|
8
|
+
"author": "JounQin <admin@1stg.me> (https://www.1stG.me)",
|
|
9
9
|
"funding": "https://opencollective.com/unts",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"engines": {
|