@pkgr/core 0.3.4 → 0.3.5
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 +0 -2
- package/lib/constants.js +1 -6
- package/lib/constants.js.map +1 -1
- package/lib/helpers.js +3 -3
- package/lib/helpers.js.map +1 -1
- package/lib/index.cjs +8 -8
- package/package.json +1 -1
package/lib/constants.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" preserve="true" />
|
|
2
|
-
export declare const CWD: string;
|
|
3
2
|
export interface CjsRequire extends NodeJS.Require {
|
|
4
3
|
<T>(id: string): T;
|
|
5
4
|
}
|
|
6
5
|
export declare const cjsRequire: CjsRequire;
|
|
7
|
-
export declare const EVAL_FILENAMES: Set<string>;
|
|
8
6
|
export declare const EXTENSIONS: string[];
|
package/lib/constants.js
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
|
-
export const
|
|
3
|
-
const importMetaUrl = import.meta.url;
|
|
4
|
-
export const cjsRequire = importMetaUrl
|
|
5
|
-
? createRequire(importMetaUrl)
|
|
6
|
-
: require;
|
|
7
|
-
export const EVAL_FILENAMES = new Set(['[eval]', '[worker eval]']);
|
|
2
|
+
export const cjsRequire = typeof require === 'function' ? require : createRequire(import.meta.url);
|
|
8
3
|
export const EXTENSIONS = ['.ts', '.tsx', ...Object.keys(cjsRequire.extensions)];
|
|
9
4
|
//# sourceMappingURL=constants.js.map
|
package/lib/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAM3C,MAAM,CAAC,MAAM,UAAU,GACrB,OAAO,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAG1E,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAA"}
|
package/lib/helpers.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs, {} from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import {
|
|
3
|
+
import { EXTENSIONS, cjsRequire } from './constants.js';
|
|
4
4
|
export const tryPkg = (pkg) => {
|
|
5
5
|
try {
|
|
6
6
|
return cjsRequire.resolve(pkg);
|
|
@@ -10,7 +10,7 @@ export const tryPkg = (pkg) => {
|
|
|
10
10
|
export const isPkgAvailable = (pkg) => Boolean(tryPkg(pkg));
|
|
11
11
|
const ANY_FILE_TYPES = new Set(['any', true]);
|
|
12
12
|
const isAnyFileType = (type) => ANY_FILE_TYPES.has(type);
|
|
13
|
-
export const tryFileStats = (filename, type = 'file', base =
|
|
13
|
+
export const tryFileStats = (filename, type = 'file', base = process.cwd()) => {
|
|
14
14
|
if (!type) {
|
|
15
15
|
type = 'file';
|
|
16
16
|
}
|
|
@@ -49,7 +49,7 @@ export const findUp = (entryOrOptions, options) => {
|
|
|
49
49
|
else if (entryOrOptions) {
|
|
50
50
|
options = options ? { ...entryOrOptions, ...options } : entryOrOptions;
|
|
51
51
|
}
|
|
52
|
-
let { entry =
|
|
52
|
+
let { entry = process.cwd(), search = 'package.json', type, stop, } = options ?? {};
|
|
53
53
|
search = Array.isArray(search) ? search : [search];
|
|
54
54
|
do {
|
|
55
55
|
const searched = tryFile(search, type, entry);
|
package/lib/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"help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
|
var path = require('node:path');
|
|
6
6
|
|
|
7
7
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
8
|
-
const
|
|
9
|
-
const importMetaUrl = (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href));
|
|
10
|
-
const cjsRequire = importMetaUrl ? node_module.createRequire(importMetaUrl) : require;
|
|
11
|
-
const EVAL_FILENAMES = /* @__PURE__ */ new Set(["[eval]", "[worker eval]"]);
|
|
8
|
+
const cjsRequire = typeof require === "function" ? require : node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
|
|
12
9
|
const EXTENSIONS = [".ts", ".tsx", ...Object.keys(cjsRequire.extensions)];
|
|
13
10
|
|
|
14
11
|
const tryPkg = (pkg) => {
|
|
@@ -20,7 +17,7 @@ const tryPkg = (pkg) => {
|
|
|
20
17
|
const isPkgAvailable = (pkg) => Boolean(tryPkg(pkg));
|
|
21
18
|
const ANY_FILE_TYPES = /* @__PURE__ */ new Set(["any", true]);
|
|
22
19
|
const isAnyFileType = (type) => ANY_FILE_TYPES.has(type);
|
|
23
|
-
const tryFileStats = (filename, type = "file", base =
|
|
20
|
+
const tryFileStats = (filename, type = "file", base = process.cwd()) => {
|
|
24
21
|
if (!type) {
|
|
25
22
|
type = "file";
|
|
26
23
|
}
|
|
@@ -56,7 +53,12 @@ const findUp = (entryOrOptions, options) => {
|
|
|
56
53
|
} else if (entryOrOptions) {
|
|
57
54
|
options = options ? { ...entryOrOptions, ...options } : entryOrOptions;
|
|
58
55
|
}
|
|
59
|
-
let {
|
|
56
|
+
let {
|
|
57
|
+
entry = process.cwd(),
|
|
58
|
+
search = "package.json",
|
|
59
|
+
type,
|
|
60
|
+
stop
|
|
61
|
+
} = options ?? {};
|
|
60
62
|
search = Array.isArray(search) ? search : [search];
|
|
61
63
|
do {
|
|
62
64
|
const searched = tryFile(search, type, entry);
|
|
@@ -72,8 +74,6 @@ const findUp = (entryOrOptions, options) => {
|
|
|
72
74
|
return "";
|
|
73
75
|
};
|
|
74
76
|
|
|
75
|
-
exports.CWD = CWD;
|
|
76
|
-
exports.EVAL_FILENAMES = EVAL_FILENAMES;
|
|
77
77
|
exports.EXTENSIONS = EXTENSIONS;
|
|
78
78
|
exports.cjsRequire = cjsRequire;
|
|
79
79
|
exports.findUp = findUp;
|