require-it 2.0.0 → 2.2.0

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/README.md CHANGED
@@ -1,71 +1,73 @@
1
- # require-it
2
-
3
- [![Build Status](https://travis-ci.org/szikszail/require-it.svg?branch=master)](https://travis-ci.org/szikszail/require-it) [![dependency Status](https://david-dm.org/szikszail/require-it.svg)](https://david-dm.org/szikszail/require-it) [![devDependency Status](https://david-dm.org/szikszail/require-it/dev-status.svg)](https://david-dm.org/szikszail/require-it#info=devDependencies)
4
-
5
- This module extends the default nodejs require with capabilities to require nested modules, independent on where they are nested.
6
-
7
- ## Install
8
-
9
- npm install require-it --save
10
-
11
- ## Example
12
-
13
- myPackage
14
- + node_modules
15
- | + direct-dependecy
16
- | | + node_modules
17
- | | | \ nested-module
18
- | | | + index.js
19
- | | | \ package.json
20
- | | + index.js
21
- | | \ package.json
22
- | + index.js
23
- | \ package.json
24
- + index.js
25
- \ package.json
26
-
27
- `myPackage/index.js`:
28
-
29
- ```javascript
30
- const { requireIt } = require('require-it');
31
- // it will work and won't throw error
32
- const nestedModule = requireIt('nested-module');
33
- ```
34
-
35
- ## API
36
-
37
- ### `requireIt(moduleName)`
38
-
39
- Requires the given local module, indenpendent on which level is it.
40
-
41
- #### `requireIt.resolve(moduleName)`
42
-
43
- Returns the local path which could be required by `require`.
44
-
45
- #### `requireIt.directory(moduleName)`
46
-
47
- Returns the local path wich could be required by `require` without the main JS file, ie. the path to the module's directory.
48
-
49
- ### `requireGlobal(globalModuleName)`
50
-
51
- Requires the given global module.
52
-
53
- #### `requireGlobal.resolve(globalModuleName)`
54
-
55
- Returns the global path which could be required by `require`.
56
-
57
- #### `requireGlobal.directory(globalModuleName)`
58
-
59
- Returns the global path wich could be required by `require` without the main JS file, ie. the path to the module's directory.
60
-
61
- ### `requireFrom(moduleName, root)`
62
-
63
- Requires the given module, found in the given root directory.
64
-
65
- #### `requireFrom.resolve(moduleName, root)`
66
-
67
- Returns the module's path which could be required by `require`, found in the given root directory.
68
-
69
- #### `requireFrom.directory(moduleName, root)`
70
-
71
- Returns the module's path wich could be required by `require` without the main JS file, ie. the path to the module's directory, found in the given root directory.
1
+ # require-it
2
+
3
+ ![Downloads](https://img.shields.io/npm/dw/require-it?style=flat-square)
4
+ ![Version@npm](https://img.shields.io/npm/v/require-it?label=version%40npm&style=flat-square)
5
+ ![Version@git](https://img.shields.io/github/package-json/v/szikszail/require-it/master?label=version%40git&style=flat-square)
6
+
7
+ This module extends the default Node.js require with capabilities to require nested modules, independent of where they are nested.
8
+
9
+ ## Install
10
+
11
+ npm install require-it --save
12
+
13
+ ## Example
14
+
15
+ myPackage
16
+ + node_modules
17
+ | + direct-dependecy
18
+ | | + node_modules
19
+ | | | \ nested-module
20
+ | | | + index.js
21
+ | | | \ package.json
22
+ | | + index.js
23
+ | | \ package.json
24
+ | + index.js
25
+ | \ package.json
26
+ + index.js
27
+ \ package.json
28
+
29
+ `myPackage/index.js`:
30
+
31
+ ```javascript
32
+ const { requireIt } = require('require-it');
33
+ // it will work and won't throw error
34
+ const nestedModule = requireIt('nested-module');
35
+ ```
36
+
37
+ ## API
38
+
39
+ ### `requireIt(moduleName)`
40
+
41
+ Requires the given local module, independent of which level it is.
42
+
43
+ #### `requireIt.resolve(moduleName)`
44
+
45
+ Returns the local path, which could be required by `require`.
46
+
47
+ #### `requireIt.directory(moduleName)`
48
+
49
+ Returns the local path, which could be required by `require` without the main JS file, i.e., the path to the module's directory.
50
+
51
+ ### `requireGlobal(globalModuleName)`
52
+
53
+ Requires the given global module.
54
+
55
+ #### `requireGlobal.resolve(globalModuleName)`
56
+
57
+ Returns the global path, which could be required by `require`.
58
+
59
+ #### `requireGlobal.directory(globalModuleName)`
60
+
61
+ Returns the global path, which could be required by `require` without the main JS file, i.e., the path to the module's directory.
62
+
63
+ ### `requireFrom(moduleName, root)`
64
+
65
+ Requires the given module found in the given root directory.
66
+
67
+ #### `requireFrom.resolve(moduleName, root)`
68
+
69
+ Returns the module's path, which could be required by `require`, found in the given root directory.
70
+
71
+ #### `requireFrom.directory(moduleName, root)`
72
+
73
+ Returns the module's path, which could be required by `require` without the main JS file, i.e., the path to the module's directory, found in the given root directory.
package/index.d.ts CHANGED
@@ -1,15 +1,15 @@
1
- export declare type ResolveFunction = (name: string) => string;
2
- export declare type ResolveFromFunction = (name: string, root?: string) => string;
3
- export declare type RequireFunction = (name: string) => object;
4
- export declare type RequireFromFunction = (name: string, root?: string) => object;
5
- export interface RequireObject extends RequireFunction {
6
- resolve: ResolveFunction;
7
- directory: ResolveFunction;
8
- }
9
- export interface RequireFromObject extends RequireFromFunction {
10
- resolve: ResolveFromFunction;
11
- directory: ResolveFromFunction;
12
- }
13
- export declare const requireIt: RequireObject;
14
- export declare const requireGlobal: RequireObject;
15
- export declare const requireFrom: RequireFromObject;
1
+ export type ResolveFunction = (name: string) => string;
2
+ export type ResolveFromFunction = (name: string, root?: string) => string;
3
+ export type RequireFunction = (name: string) => object;
4
+ export type RequireFromFunction = (name: string, root?: string) => object;
5
+ export interface RequireObject extends RequireFunction {
6
+ resolve: ResolveFunction;
7
+ directory: ResolveFunction;
8
+ }
9
+ export interface RequireFromObject extends RequireFromFunction {
10
+ resolve: ResolveFromFunction;
11
+ directory: ResolveFromFunction;
12
+ }
13
+ export declare const requireIt: RequireObject;
14
+ export declare const requireGlobal: RequireObject;
15
+ export declare const requireFrom: RequireFromObject;
package/index.js CHANGED
@@ -1,90 +1,96 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const child_process_1 = require("child_process");
4
- const path_1 = require("path");
5
- const utils_1 = require("./utils");
6
- let globalRoot;
7
- const getGlobalRoot = () => {
8
- if (!globalRoot) {
9
- globalRoot = child_process_1.execSync("npm root -g", { encoding: "utf8" }).trim().replace(/node_modules$/, "");
10
- }
11
- return globalRoot;
12
- };
13
- const checkScopedNodeModulesOfFolder = (folder, name) => {
14
- const directModules = utils_1.getNodeModulesOfFolder(folder);
15
- const found = directModules.find((subfolder) => {
16
- return utils_1.getFolder(subfolder) === name;
17
- });
18
- if (!found) {
19
- throw Error(`Cannot find module: "${name}"`);
20
- }
21
- return path_1.join(folder, found);
22
- };
23
- const checkNodeModulesOfFolder = (folder, name) => {
24
- const root = path_1.join(folder, "node_modules");
25
- const nodeModules = utils_1.getNodeModulesOfFolder(root);
26
- for (const nodeModule of nodeModules) {
27
- if (utils_1.getFolder(nodeModule) === name) {
28
- return path_1.join(root, nodeModule);
29
- }
30
- utils_1.getNodeModulesOfFolder(path_1.join(root, nodeModule, "node_modules")).forEach((subModule) => {
31
- nodeModules.push(path_1.join(nodeModule, "node_modules", subModule));
32
- });
33
- }
34
- };
35
- const resolveMainFile = (name, root) => {
36
- const names = name.match(/^(@[^/]+)\/(.+)$/);
37
- let pathToFolder;
38
- if (names) {
39
- const pathToModule = checkNodeModulesOfFolder(root, names[1]);
40
- pathToFolder = checkScopedNodeModulesOfFolder(pathToModule, names[2]);
41
- }
42
- else {
43
- pathToFolder = checkNodeModulesOfFolder(root, name);
44
- }
45
- if (pathToFolder) {
46
- return path_1.join(pathToFolder, utils_1.readPackageJSON(pathToFolder).main);
47
- }
48
- };
49
- const resolve = (name, root) => {
50
- if (!root) {
51
- try {
52
- return require.resolve(name);
53
- }
54
- catch (e) {
55
- return resolveMainFile(name, process.cwd());
56
- }
57
- }
58
- return resolveMainFile(name, root);
59
- };
60
- const directory = (name, root) => {
61
- const pathToModule = resolve(name, root);
62
- if (!pathToModule) {
63
- throw Error(`Cannot find module: "${name}"`);
64
- }
65
- name = name.replace("/", path_1.sep);
66
- const pathPieces = pathToModule
67
- .split(name + path_1.sep)
68
- .filter((p) => !/^[/\\]$/.test(p))
69
- .filter((p) => !/\.[^\.\\/]+$/.test(p));
70
- if (pathPieces.length > 1) {
71
- return pathPieces.join(name);
72
- }
73
- return path_1.join(pathPieces[0], name);
74
- };
75
- exports.requireIt = ((name) => {
76
- return require(exports.requireIt.resolve(name));
77
- });
78
- exports.requireIt.resolve = (name) => resolve(name);
79
- exports.requireIt.directory = (name) => directory(name);
80
- exports.requireGlobal = ((name) => {
81
- return require(exports.requireGlobal.resolve(name));
82
- });
83
- exports.requireGlobal.resolve = (name) => resolve(name, getGlobalRoot());
84
- exports.requireGlobal.directory = (name) => directory(name, getGlobalRoot());
85
- exports.requireFrom = ((module, root) => {
86
- return require(resolve(module, root));
87
- });
88
- exports.requireFrom.resolve = resolve;
89
- exports.requireFrom.directory = directory;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.requireFrom = exports.requireGlobal = exports.requireIt = void 0;
4
+ const node_child_process_1 = require("node:child_process");
5
+ const node_path_1 = require("node:path");
6
+ const utils_1 = require("./utils");
7
+ let globalRoot;
8
+ const getGlobalRoot = () => {
9
+ if (!globalRoot) {
10
+ globalRoot = (0, node_child_process_1.execSync)("npm root -g", { encoding: "utf8" })
11
+ .trim()
12
+ .replace(/node_modules$/, "");
13
+ }
14
+ return globalRoot;
15
+ };
16
+ const checkScopedNodeModulesOfFolder = (folder, name) => {
17
+ const directModules = (0, utils_1.getNodeModulesOfFolder)(folder);
18
+ const found = directModules.find((subfolder) => {
19
+ return (0, utils_1.getFolder)(subfolder) === name;
20
+ });
21
+ if (!found) {
22
+ throw Error(`Cannot find module: "${name}"`);
23
+ }
24
+ return (0, node_path_1.join)(folder, found);
25
+ };
26
+ const checkNodeModulesOfFolder = (folder, name) => {
27
+ const root = (0, node_path_1.join)(folder, "node_modules");
28
+ const nodeModules = (0, utils_1.getNodeModulesOfFolder)(root);
29
+ for (const nodeModule of nodeModules) {
30
+ if ((0, utils_1.getFolder)(nodeModule) === name) {
31
+ return (0, node_path_1.join)(root, nodeModule);
32
+ }
33
+ (0, utils_1.getNodeModulesOfFolder)((0, node_path_1.join)(root, nodeModule, "node_modules")).forEach((subModule) => {
34
+ nodeModules.push((0, node_path_1.join)(nodeModule, "node_modules", subModule));
35
+ });
36
+ }
37
+ };
38
+ const resolveMainFile = (name, root) => {
39
+ const names = name.match(/^(@[^/]+)\/(.+)$/);
40
+ let pathToFolder;
41
+ if (names) {
42
+ const pathToModule = checkNodeModulesOfFolder(root, names[1]);
43
+ pathToFolder = checkScopedNodeModulesOfFolder(pathToModule, names[2]);
44
+ }
45
+ else {
46
+ pathToFolder = checkNodeModulesOfFolder(root, name);
47
+ }
48
+ if (!pathToFolder)
49
+ return;
50
+ const packageJSON = (0, utils_1.readPackageJSON)(pathToFolder);
51
+ if (!packageJSON.main)
52
+ return;
53
+ return (0, node_path_1.join)(pathToFolder, packageJSON.main);
54
+ };
55
+ const resolve = (name, root) => {
56
+ if (root) {
57
+ return resolveMainFile(name, root);
58
+ }
59
+ try {
60
+ return require.resolve(name);
61
+ }
62
+ catch (_a) {
63
+ return resolveMainFile(name, process.cwd());
64
+ }
65
+ };
66
+ const directory = (name, root) => {
67
+ const pathToModule = resolve(name, root);
68
+ if (!pathToModule) {
69
+ throw Error(`Cannot find module: "${name}"`);
70
+ }
71
+ name = name.replace("/", node_path_1.sep);
72
+ const pathPieces = pathToModule
73
+ .split(name + node_path_1.sep)
74
+ .filter((p) => !/^[/\\]$/.test(p))
75
+ .filter((p) => !/\.[^\.\\/]+$/.test(p));
76
+ if (pathPieces.length > 1) {
77
+ return pathPieces.join(name);
78
+ }
79
+ return (0, node_path_1.join)(pathPieces[0], name);
80
+ };
81
+ exports.requireIt = ((name) => {
82
+ return require(exports.requireIt.resolve(name));
83
+ });
84
+ exports.requireIt.resolve = (name) => resolve(name);
85
+ exports.requireIt.directory = (name) => directory(name);
86
+ exports.requireGlobal = ((name) => {
87
+ return require(exports.requireGlobal.resolve(name));
88
+ });
89
+ exports.requireGlobal.resolve = (name) => resolve(name, getGlobalRoot());
90
+ exports.requireGlobal.directory = (name) => directory(name, getGlobalRoot());
91
+ exports.requireFrom = ((module, root) => {
92
+ return require(resolve(module, root));
93
+ });
94
+ exports.requireFrom.resolve = resolve;
95
+ exports.requireFrom.directory = directory;
90
96
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,iDAAyC;AACzC,+BAAiC;AACjC,mCAA6E;AAe7E,IAAI,UAAkB,CAAC;AACvB,MAAM,aAAa,GAAG,GAAW,EAAE;IAC/B,IAAI,CAAC,UAAU,EAAE;QACb,UAAU,GAAG,wBAAQ,CAAC,aAAa,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC;KAClG;IACD,OAAO,UAAU,CAAC;AACtB,CAAC,CAAC;AAEF,MAAM,8BAA8B,GAAG,CAAC,MAAc,EAAE,IAAY,EAAU,EAAE;IAC5E,MAAM,aAAa,GAAa,8BAAsB,CAAC,MAAM,CAAC,CAAC;IAC/D,MAAM,KAAK,GAAW,aAAa,CAAC,IAAI,CAAC,CAAC,SAAiB,EAAW,EAAE;QACpE,OAAO,iBAAS,CAAC,SAAS,CAAC,KAAK,IAAI,CAAC;IACzC,CAAC,CAAC,CAAC;IACH,IAAI,CAAC,KAAK,EAAE;QACR,MAAM,KAAK,CAAC,wBAAwB,IAAI,GAAG,CAAC,CAAC;KAChD;IACD,OAAO,WAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAC/B,CAAC,CAAC;AAEF,MAAM,wBAAwB,GAAG,CAAC,MAAc,EAAE,IAAY,EAAU,EAAE;IACtE,MAAM,IAAI,GAAW,WAAI,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAClD,MAAM,WAAW,GAAa,8BAAsB,CAAC,IAAI,CAAC,CAAC;IAC3D,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE;QAClC,IAAI,iBAAS,CAAC,UAAU,CAAC,KAAK,IAAI,EAAE;YAChC,OAAO,WAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;SACjC;QACD,8BAAs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IAC/B,CAAC;IACD,OAAO,IAAA,gBAAI,EAAC,UAAU,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;AACnC,CAAC,CAAC;AAEW,QAAA,SAAS,GAAkB,CAAC,CAAC,IAAY,EAAU,EAAE;IAChE,OAAO,OAAO,CAAC,iBAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AAC1C,CAAC,CAAkB,CAAC;AACpB,iBAAS,CAAC,OAAO,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAC5D,iBAAS,CAAC,SAAS,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AAEnD,QAAA,aAAa,GAAkB,CAAC,CAAC,IAAY,EAAU,EAAE;IACpE,OAAO,OAAO,CAAC,qBAAa,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AAC9C,CAAC,CAAkB,CAAC;AACpB,qBAAa,CAAC,OAAO,GAAG,CAAC,IAAY,EAAU,EAAE,CAC/C,OAAO,CAAC,IAAI,EAAE,aAAa,EAAE,CAAC,CAAC;AACjC,qBAAa,CAAC,SAAS,GAAG,CAAC,IAAY,EAAU,EAAE,CACjD,SAAS,CAAC,IAAI,EAAE,aAAa,EAAE,CAAC,CAAC;AAEtB,QAAA,WAAW,GAAsB,CAAC,CAC7C,MAAc,EACd,IAAa,EACL,EAAE;IACV,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;AACxC,CAAC,CAAkB,CAAC;AACpB,mBAAW,CAAC,OAAO,GAAG,OAAO,CAAC;AAC9B,mBAAW,CAAC,SAAS,GAAG,SAAS,CAAC"}
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "require-it",
3
- "version": "2.0.0",
4
- "description": "This module extends the default nodejs require with capabilities to require nested modules, independent on where they are nested.",
3
+ "version": "2.2.0",
4
+ "description": "This module extends the default Node.js require with capabilities to require nested modules, independent on where they are nested.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
7
7
  "scripts": {
8
8
  "tsc:watch": "tsc -w",
9
9
  "build": "npm run clean && npm run compile && npm run copyToDist && npm test -- --coverage && npm run typedoc",
10
- "buildUpdate": "npm run compile && npm run copyToDist && npm run postbuild",
10
+ "buildUpdate": "npm run compile && npm run copyToDist",
11
11
  "copyToDist": "copyfiles -f *.txt *.md package.json dist",
12
12
  "typedoc": "typedoc --exclude **/bin/**/*.ts --exclude **/cli.ts --out ./dist/docs/api ./src",
13
13
  "clean": "rimraf ./dist",
14
- "test": "cross-env JEST_JUNIT_OUTPUT=./dist/test/reports/junit.xml jest",
14
+ "test": "cross-env JEST_JUNIT_OUTPUT=./dist/reports/junit.xml jest",
15
15
  "tslint": "tslint -c tslint.json ./src/**/*.ts ./tests/**/*.ts",
16
16
  "compile": "tsc && npm run tslint"
17
17
  },
@@ -33,25 +33,24 @@
33
33
  "*.js.map"
34
34
  ],
35
35
  "engines": {
36
- "node": ">=6.0.0"
36
+ "node": ">=12.0.0"
37
37
  },
38
38
  "bugs": {
39
39
  "url": "https://github.com/szikszail/require-it/issues"
40
40
  },
41
41
  "homepage": "https://github.com/szikszail/require-it#readme",
42
42
  "devDependencies": {
43
- "@types/jest": "^22.1.3",
44
- "copyfiles": "^1.2.0",
45
- "cross-env": "^5.1.3",
46
- "jest": "^22.4.0",
47
- "jest-junit": "^3.6.0",
48
- "rimraf": "^2.6.2",
49
- "ts-jest": "^22.0.4",
50
- "tslint": "^5.9.1",
51
- "typedoc": "^0.10.0",
52
- "typescript": "^2.7.2",
53
- "proxyquire": "^2.1.0",
54
- "sinon": "^6.0.0"
43
+ "@types/jest": "^30.0.0",
44
+ "@types/node": "^25.2.1",
45
+ "copyfiles": "^2.4.1",
46
+ "cross-env": "^10.1.0",
47
+ "jest": "^30.0.0",
48
+ "jest-junit": "^16.0.0",
49
+ "rimraf": "^6.1.1",
50
+ "ts-jest": "^29.1.1",
51
+ "tslint": "^6.1.3",
52
+ "typescript": "^5.9.3",
53
+ "typedoc": "^0.28.16"
55
54
  },
56
55
  "jest": {
57
56
  "transform": {
@@ -65,8 +64,11 @@
65
64
  "/node_modules/",
66
65
  "dist"
67
66
  ],
68
- "testResultsProcessor": "jest-junit",
69
- "coverageDirectory": "./dist/test/coverage",
67
+ "reporters": [
68
+ "default",
69
+ "jest-junit"
70
+ ],
71
+ "coverageDirectory": "./dist/reports/coverage",
70
72
  "moduleFileExtensions": [
71
73
  "ts",
72
74
  "js"
@@ -84,4 +86,4 @@
84
86
  }
85
87
  }
86
88
  }
87
- }
89
+ }
package/utils.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- export declare const isFile: (file: string) => boolean;
2
- export declare const isFolder: (folder: string) => boolean;
3
- export declare const isScopedModule: (name: string) => boolean;
4
- export declare const isNodeModule: (name: string) => boolean;
5
- export declare const getNodeModulesOfFolder: (folder: string) => string[];
6
- export interface PackageJSON {
7
- main: string;
8
- }
9
- export declare const getFolder: (path: string) => string;
10
- export declare const readPackageJSON: (folder: string) => PackageJSON;
1
+ export declare const isFile: (file: string) => boolean;
2
+ export declare const isFolder: (folder: string) => boolean;
3
+ export declare const isScopedModule: (name: string) => boolean;
4
+ export declare const isNodeModule: (name: string) => boolean;
5
+ export declare const getNodeModulesOfFolder: (folder: string) => string[];
6
+ export interface PackageJSON {
7
+ main: string;
8
+ }
9
+ export declare const getFolder: (path: string) => string;
10
+ export declare const readPackageJSON: (folder: string) => PackageJSON;
package/utils.js CHANGED
@@ -1,40 +1,49 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const fs_1 = require("fs");
4
- const path_1 = require("path");
5
- exports.isFile = (file) => {
6
- try {
7
- return fs_1.statSync(file).isFile();
8
- }
9
- catch (e) {
10
- return false;
11
- }
12
- };
13
- exports.isFolder = (folder) => {
14
- try {
15
- return fs_1.statSync(folder).isDirectory();
16
- }
17
- catch (e) {
18
- return false;
19
- }
20
- };
21
- exports.isScopedModule = (name) => {
22
- return exports.isFolder(name) && /@[^/\\]*$/.test(name);
23
- };
24
- exports.isNodeModule = (name) => {
25
- return exports.isFolder(name) && (exports.isFolder(path_1.join(name, "node_modules")) || exports.isFile(path_1.join(name, "package.json")));
26
- };
27
- exports.getNodeModulesOfFolder = (folder) => {
28
- try {
29
- return fs_1.readdirSync(folder).filter((subfolder) => {
30
- const path = path_1.join(folder, subfolder);
31
- return exports.isNodeModule(path) || exports.isScopedModule(path);
32
- });
33
- }
34
- catch (e) {
35
- return [];
36
- }
37
- };
38
- exports.getFolder = (path) => path.split(/[\/\\]/).pop();
39
- exports.readPackageJSON = (folder) => require(path_1.join(folder, "package.json"));
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readPackageJSON = exports.getFolder = exports.getNodeModulesOfFolder = exports.isNodeModule = exports.isScopedModule = exports.isFolder = exports.isFile = void 0;
4
+ const node_fs_1 = require("node:fs");
5
+ const node_path_1 = require("node:path");
6
+ const isFile = (file) => {
7
+ try {
8
+ return (0, node_fs_1.statSync)(file).isFile();
9
+ }
10
+ catch (_a) {
11
+ return false;
12
+ }
13
+ };
14
+ exports.isFile = isFile;
15
+ const isFolder = (folder) => {
16
+ try {
17
+ return (0, node_fs_1.statSync)(folder).isDirectory();
18
+ }
19
+ catch (_a) {
20
+ return false;
21
+ }
22
+ };
23
+ exports.isFolder = isFolder;
24
+ const isScopedModule = (name) => {
25
+ return (0, exports.isFolder)(name) && /@[^/\\@]+$/.test(name);
26
+ };
27
+ exports.isScopedModule = isScopedModule;
28
+ const isNodeModule = (name) => {
29
+ return ((0, exports.isFolder)(name) &&
30
+ ((0, exports.isFolder)((0, node_path_1.join)(name, "node_modules")) || (0, exports.isFile)((0, node_path_1.join)(name, "package.json"))));
31
+ };
32
+ exports.isNodeModule = isNodeModule;
33
+ const getNodeModulesOfFolder = (folder) => {
34
+ try {
35
+ return (0, node_fs_1.readdirSync)(folder).filter((subfolder) => {
36
+ const path = (0, node_path_1.join)(folder, subfolder);
37
+ return (0, exports.isNodeModule)(path) || (0, exports.isScopedModule)(path);
38
+ });
39
+ }
40
+ catch (_a) {
41
+ return [];
42
+ }
43
+ };
44
+ exports.getNodeModulesOfFolder = getNodeModulesOfFolder;
45
+ const getFolder = (path) => path.split(/[\/\\]/).pop();
46
+ exports.getFolder = getFolder;
47
+ const readPackageJSON = (folder) => require((0, node_path_1.join)(folder, "package.json"));
48
+ exports.readPackageJSON = readPackageJSON;
40
49
  //# sourceMappingURL=utils.js.map
package/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;AAAA,2BAA2C;AAC3C,+BAA4B;AAEf,QAAA,MAAM,GAAG,CAAC,IAAY,EAAW,EAAE;IAC5C,IAAI;QACA,OAAO,aAAQ,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;KAClC;IAAC,OAAO,CAAC,EAAE;QACR,OAAO,KAAK,CAAC;KAChB;AACL,CAAC,CAAC;AAEW,QAAA,QAAQ,GAAG,CAAC,MAAc,EAAW,EAAE;IAChD,IAAI;QACA,OAAO,aAAQ,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC;KACzC;IAAC,OAAO,CAAC,EAAE;QACR,OAAO,KAAK,CAAC;KAChB;AACL,CAAC,CAAC;AAEW,QAAA,cAAc,GAAG,CAAC,IAAY,EAAW,EAAE;IACpD,OAAO,gBAAQ,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACpD,CAAC,CAAC;AAEW,QAAA,YAAY,GAAG,CAAC,IAAY,EAAW,EAAE;IAClD,OAAO,gBAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAQ,CAAC,WAAI,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC,IAAI,cAAM,CAAC,WAAI,CAAC,IAAI,EAAE,cAAc,CAAC,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