@jsnw/srv-utils 1.0.1 → 1.0.3
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.
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
type UseTsconfigPathsOptions = {
|
|
2
|
+
basePath?: string;
|
|
3
|
+
tsconfigPath: string;
|
|
4
|
+
};
|
|
1
5
|
/**
|
|
2
|
-
* @param {
|
|
3
|
-
* @param {string} tsconfigPath
|
|
6
|
+
* @param {UseTsconfigPathsOptions} options
|
|
4
7
|
*/
|
|
5
|
-
export declare function useTsconfigPaths(
|
|
8
|
+
export declare function useTsconfigPaths({ basePath, tsconfigPath }: UseTsconfigPathsOptions): void;
|
|
9
|
+
export {};
|
package/dist/useTsconfigPaths.js
CHANGED
|
@@ -3,10 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useTsconfigPaths = useTsconfigPaths;
|
|
4
4
|
const node_path_1 = require("node:path");
|
|
5
5
|
/**
|
|
6
|
-
* @param {
|
|
7
|
-
* @param {string} tsconfigPath
|
|
6
|
+
* @param {UseTsconfigPathsOptions} options
|
|
8
7
|
*/
|
|
9
|
-
function useTsconfigPaths(
|
|
8
|
+
function useTsconfigPaths({ basePath, tsconfigPath }) {
|
|
10
9
|
let moduleAlias = null;
|
|
11
10
|
try {
|
|
12
11
|
require('module-alias/register');
|
|
@@ -15,12 +14,17 @@ function useTsconfigPaths(fromPath, tsconfigPath) {
|
|
|
15
14
|
catch (e) {
|
|
16
15
|
throw new Error('module-alias package should be installed to use the function');
|
|
17
16
|
}
|
|
18
|
-
const tsconfig = require(tsconfigPath), tsconfigDirPathname = (0, node_path_1.dirname)(tsconfigPath), paths = {};
|
|
17
|
+
const tsconfig = require((0, node_path_1.resolve)(tsconfigPath)), tsconfigDirPathname = (0, node_path_1.dirname)(tsconfigPath), paths = {};
|
|
18
|
+
if (!basePath && !tsconfig?.compilerOptions?.baseUrl)
|
|
19
|
+
throw new TypeError('Either basePath option should be provided or tsconfig.json should contain compilerOptions.baseUrl property');
|
|
20
|
+
const baseUrl = tsconfig?.compilerOptions?.baseUrl
|
|
21
|
+
? (0, node_path_1.resolve)(tsconfig.compilerOptions.baseUrl)
|
|
22
|
+
: (0, node_path_1.resolve)(basePath);
|
|
19
23
|
Object.entries((tsconfig?.compilerOptions?.paths ?? {}))
|
|
20
24
|
.forEach(([moduleName, pathArray]) => {
|
|
21
25
|
if (pathArray.length === 0)
|
|
22
26
|
return;
|
|
23
|
-
paths[moduleName] = (0, node_path_1.resolve)(tsconfigDirPathname,
|
|
27
|
+
paths[moduleName] = (0, node_path_1.resolve)(tsconfigDirPathname, baseUrl, pathArray[0]);
|
|
24
28
|
});
|
|
25
29
|
moduleAlias.addAliases(paths);
|
|
26
30
|
}
|
package/package.json
CHANGED