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 +73 -71
- package/index.d.ts +15 -15
- package/index.js +95 -89
- package/index.js.map +1 -1
- package/package.json +22 -20
- package/utils.d.ts +10 -10
- package/utils.js +48 -39
- package/utils.js.map +1 -1
package/README.md
CHANGED
|
@@ -1,71 +1,73 @@
|
|
|
1
|
-
# require-it
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
|
18
|
-
| |
|
|
19
|
-
| | |
|
|
20
|
-
| | + index.js
|
|
21
|
-
| | \ package.json
|
|
22
|
-
| + index.js
|
|
23
|
-
| \ package.json
|
|
24
|
-
+ index.js
|
|
25
|
-
\ package.json
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
1
|
+
# require-it
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
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
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
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
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
pathToFolder =
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
exports.
|
|
85
|
-
exports.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
exports.
|
|
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":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,2DAA8C;AAC9C,yCAAsC;AACtC,mCAA6E;AAe7E,IAAI,UAAkB,CAAC;AACvB,MAAM,aAAa,GAAG,GAAW,EAAE;IACjC,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,UAAU,GAAG,IAAA,6BAAQ,EAAC,aAAa,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;aACvD,IAAI,EAAE;aACN,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC;IAClC,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAEF,MAAM,8BAA8B,GAAG,CACrC,MAAc,EACd,IAAY,EACJ,EAAE;IACV,MAAM,aAAa,GAAa,IAAA,8BAAsB,EAAC,MAAM,CAAC,CAAC;IAC/D,MAAM,KAAK,GAAW,aAAa,CAAC,IAAI,CAAC,CAAC,SAAiB,EAAW,EAAE;QACtE,OAAO,IAAA,iBAAS,EAAC,SAAS,CAAC,KAAK,IAAI,CAAC;IACvC,CAAC,CAAC,CAAC;IACH,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,KAAK,CAAC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
|
-
"version": "2.
|
|
4
|
-
"description": "This module extends the default
|
|
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
|
|
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/
|
|
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": ">=
|
|
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": "^
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"jest
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"typescript": "^
|
|
53
|
-
"
|
|
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
|
-
"
|
|
69
|
-
|
|
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
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return
|
|
26
|
-
};
|
|
27
|
-
exports.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[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