@ms-cloudpack/path-utilities 2.8.3 → 3.0.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/lib/resolve.d.ts +6 -2
- package/lib/resolve.d.ts.map +1 -1
- package/lib/resolve.js +10 -6
- package/lib/resolve.js.map +1 -1
- package/lib/resolveModule.d.ts +28 -5
- package/lib/resolveModule.d.ts.map +1 -1
- package/lib/resolveModule.js +5 -7
- package/lib/resolveModule.js.map +1 -1
- package/package.json +2 -2
package/lib/resolve.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Resolves a package
|
|
2
|
+
* Resolves a package name given the parent path. This uses the `resolve` package (which does not
|
|
3
|
+
* respect exports maps) to resolve `${packageName}/package.json`.
|
|
4
|
+
*
|
|
5
|
+
* (To resolve a path respecting exports maps, use `resolveModule` instead.)
|
|
6
|
+
*
|
|
3
7
|
* @param packageName - The package name.
|
|
4
8
|
* @param parentPath - The parent path.
|
|
5
|
-
* @returns The resolved absolute package
|
|
9
|
+
* @returns The resolved absolute path to the package root, or undefined if it couldn't be resolved.
|
|
6
10
|
*/
|
|
7
11
|
export declare function resolve(packageName: string, parentPath: string): Promise<string | undefined>;
|
|
8
12
|
//# sourceMappingURL=resolve.d.ts.map
|
package/lib/resolve.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAGA
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AACH,wBAAsB,OAAO,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAgBlG"}
|
package/lib/resolve.js
CHANGED
|
@@ -1,26 +1,30 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import resolvePackage from 'resolve';
|
|
3
3
|
/**
|
|
4
|
-
* Resolves a package
|
|
4
|
+
* Resolves a package name given the parent path. This uses the `resolve` package (which does not
|
|
5
|
+
* respect exports maps) to resolve `${packageName}/package.json`.
|
|
6
|
+
*
|
|
7
|
+
* (To resolve a path respecting exports maps, use `resolveModule` instead.)
|
|
8
|
+
*
|
|
5
9
|
* @param packageName - The package name.
|
|
6
10
|
* @param parentPath - The parent path.
|
|
7
|
-
* @returns The resolved absolute package
|
|
11
|
+
* @returns The resolved absolute path to the package root, or undefined if it couldn't be resolved.
|
|
8
12
|
*/
|
|
9
13
|
export async function resolve(packageName, parentPath) {
|
|
10
14
|
const packageRootImport = path.join(packageName, 'package.json');
|
|
11
|
-
return new Promise((
|
|
15
|
+
return new Promise((promiseResolve) => {
|
|
12
16
|
try {
|
|
13
17
|
resolvePackage(packageRootImport, { basedir: parentPath, preserveSymlinks: false }, (err, resolvedPath) => {
|
|
14
18
|
if (err || !resolvedPath) {
|
|
15
|
-
|
|
19
|
+
promiseResolve(undefined);
|
|
16
20
|
}
|
|
17
21
|
else {
|
|
18
|
-
|
|
22
|
+
promiseResolve(path.dirname(resolvedPath));
|
|
19
23
|
}
|
|
20
24
|
});
|
|
21
25
|
}
|
|
22
26
|
catch (e) {
|
|
23
|
-
|
|
27
|
+
promiseResolve(undefined);
|
|
24
28
|
}
|
|
25
29
|
});
|
|
26
30
|
}
|
package/lib/resolve.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,cAAc,MAAM,SAAS,CAAC;AAErC
|
|
1
|
+
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,cAAc,MAAM,SAAS,CAAC;AAErC;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,WAAmB,EAAE,UAAkB;IACnE,MAAM,iBAAiB,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;IAEjE,OAAO,IAAI,OAAO,CAAC,CAAC,cAAc,EAAE,EAAE;QACpC,IAAI,CAAC;YACH,cAAc,CAAC,iBAAiB,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,KAAK,EAAE,EAAE,CAAC,GAAG,EAAE,YAAY,EAAE,EAAE;gBACxG,IAAI,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;oBACzB,cAAc,CAAC,SAAS,CAAC,CAAC;gBAC5B,CAAC;qBAAM,CAAC;oBACN,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC;gBAC7C,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,cAAc,CAAC,SAAS,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import path from 'path';\nimport resolvePackage from 'resolve';\n\n/**\n * Resolves a package name given the parent path. This uses the `resolve` package (which does not\n * respect exports maps) to resolve `${packageName}/package.json`.\n *\n * (To resolve a path respecting exports maps, use `resolveModule` instead.)\n *\n * @param packageName - The package name.\n * @param parentPath - The parent path.\n * @returns The resolved absolute path to the package root, or undefined if it couldn't be resolved.\n */\nexport async function resolve(packageName: string, parentPath: string): Promise<string | undefined> {\n const packageRootImport = path.join(packageName, 'package.json');\n\n return new Promise((promiseResolve) => {\n try {\n resolvePackage(packageRootImport, { basedir: parentPath, preserveSymlinks: false }, (err, resolvedPath) => {\n if (err || !resolvedPath) {\n promiseResolve(undefined);\n } else {\n promiseResolve(path.dirname(resolvedPath));\n }\n });\n } catch (e) {\n promiseResolve(undefined);\n }\n });\n}\n"]}
|
package/lib/resolveModule.d.ts
CHANGED
|
@@ -1,9 +1,32 @@
|
|
|
1
|
+
interface ResolveModuleCommonParams {
|
|
2
|
+
/** Specifier to resolve */
|
|
3
|
+
importSpecifier: string;
|
|
4
|
+
/** If true, keep symlinks instead of resolving them */
|
|
5
|
+
preserveSymlinks?: boolean;
|
|
6
|
+
}
|
|
1
7
|
/**
|
|
2
|
-
* Resolve a module specifier to a file
|
|
3
|
-
*
|
|
8
|
+
* Resolve a module specifier to a file URL using `import-meta-resolve` (which respects exports maps).
|
|
9
|
+
* Throws if it can't be resolved.
|
|
10
|
+
* (The parent to start resolution from can be specified as either a file path or URL.)
|
|
11
|
+
*
|
|
12
|
+
* WARNING: As of writing, this only uses Node-appropriate export conditions, and so is only
|
|
13
|
+
* intended to be used for resolving things such as config files and webpack loaders.
|
|
14
|
+
*
|
|
15
|
+
* @returns The resolved file URL.
|
|
4
16
|
*/
|
|
5
|
-
export declare function resolveModule(params: {
|
|
6
|
-
|
|
17
|
+
export declare function resolveModule(params: ResolveModuleCommonParams & {
|
|
18
|
+
/**
|
|
19
|
+
* Parent file path **(not URL)** to start resolving from.
|
|
20
|
+
* (Use `parentUrl` for a file URL.)
|
|
21
|
+
*/
|
|
22
|
+
parentPath: string;
|
|
23
|
+
}): URL;
|
|
24
|
+
export declare function resolveModule(params: ResolveModuleCommonParams & {
|
|
25
|
+
/**
|
|
26
|
+
* Parent URL to start resolving from, such as `import.meta.url` of the calling file.
|
|
27
|
+
* (Use `parentPath` for a file path.)
|
|
28
|
+
*/
|
|
7
29
|
parentUrl: string;
|
|
8
|
-
}):
|
|
30
|
+
}): URL;
|
|
31
|
+
export {};
|
|
9
32
|
//# sourceMappingURL=resolveModule.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveModule.d.ts","sourceRoot":"","sources":["../src/resolveModule.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"resolveModule.d.ts","sourceRoot":"","sources":["../src/resolveModule.ts"],"names":[],"mappings":"AAQA,UAAU,yBAAyB;IACjC,2BAA2B;IAC3B,eAAe,EAAE,MAAM,CAAC;IACxB,uDAAuD;IACvD,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,yBAAyB,GAAG;IAClC;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAC;CACpB,GAEA,GAAG,CAAC;AACP,wBAAgB,aAAa,CAC3B,MAAM,EAAE,yBAAyB,GAAG;IAClC;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;CACnB,GACA,GAAG,CAAC"}
|
package/lib/resolveModule.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
+
import { makeUrl } from '@ms-cloudpack/path-string-parsing';
|
|
1
2
|
import { moduleResolve } from 'import-meta-resolve';
|
|
2
3
|
import { pathToFileURL } from 'url';
|
|
3
4
|
// Conditions used for resolution if the package has an exports map.
|
|
4
5
|
// More could be added later if desired ("default" is implicitly included).
|
|
5
6
|
const conditions = new Set(['import', 'require', 'node']);
|
|
6
|
-
/**
|
|
7
|
-
* Resolve a module specifier to a file url (with protocol ie: file:). Throws if it can't be resolved.
|
|
8
|
-
* @returns - The resolved file url as a string.
|
|
9
|
-
*/
|
|
10
7
|
export function resolveModule(params) {
|
|
11
|
-
const { importSpecifier,
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
const { importSpecifier, preserveSymlinks } = params;
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- types verify one or the other is set
|
|
10
|
+
const parentUrl = params.parentPath ? pathToFileURL(params.parentPath) : makeUrl(params.parentUrl);
|
|
11
|
+
return moduleResolve(importSpecifier, parentUrl, conditions, preserveSymlinks);
|
|
14
12
|
}
|
|
15
13
|
//# sourceMappingURL=resolveModule.js.map
|
package/lib/resolveModule.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveModule.js","sourceRoot":"","sources":["../src/resolveModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,oEAAoE;AACpE,2EAA2E;AAC3E,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"resolveModule.js","sourceRoot":"","sources":["../src/resolveModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,oEAAoE;AACpE,2EAA2E;AAC3E,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC;AAsC1D,MAAM,UAAU,aAAa,CAC3B,MAGC;IAED,MAAM,EAAE,eAAe,EAAE,gBAAgB,EAAE,GAAG,MAAM,CAAC;IACrD,4GAA4G;IAC5G,MAAM,SAAS,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,SAAU,CAAC,CAAC;IAEpG,OAAO,aAAa,CAAC,eAAe,EAAE,SAAS,EAAE,UAAU,EAAE,gBAAgB,CAAC,CAAC;AACjF,CAAC","sourcesContent":["import { makeUrl } from '@ms-cloudpack/path-string-parsing';\nimport { moduleResolve } from 'import-meta-resolve';\nimport { pathToFileURL } from 'url';\n\n// Conditions used for resolution if the package has an exports map.\n// More could be added later if desired (\"default\" is implicitly included).\nconst conditions = new Set(['import', 'require', 'node']);\n\ninterface ResolveModuleCommonParams {\n /** Specifier to resolve */\n importSpecifier: string;\n /** If true, keep symlinks instead of resolving them */\n preserveSymlinks?: boolean;\n}\n\n/**\n * Resolve a module specifier to a file URL using `import-meta-resolve` (which respects exports maps).\n * Throws if it can't be resolved.\n * (The parent to start resolution from can be specified as either a file path or URL.)\n *\n * WARNING: As of writing, this only uses Node-appropriate export conditions, and so is only\n * intended to be used for resolving things such as config files and webpack loaders.\n *\n * @returns The resolved file URL.\n */\nexport function resolveModule(\n params: ResolveModuleCommonParams & {\n /**\n * Parent file path **(not URL)** to start resolving from.\n * (Use `parentUrl` for a file URL.)\n */\n parentPath: string;\n },\n // Returning a URL object makes it clear that the result is a file URL, not a path.\n): URL;\nexport function resolveModule(\n params: ResolveModuleCommonParams & {\n /**\n * Parent URL to start resolving from, such as `import.meta.url` of the calling file.\n * (Use `parentPath` for a file path.)\n */\n parentUrl: string;\n },\n): URL;\nexport function resolveModule(\n params: ResolveModuleCommonParams & {\n parentPath?: string;\n parentUrl?: string;\n },\n): URL {\n const { importSpecifier, preserveSymlinks } = params;\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- types verify one or the other is set\n const parentUrl = params.parentPath ? pathToFileURL(params.parentPath) : makeUrl(params.parentUrl!);\n\n return moduleResolve(importSpecifier, parentUrl, conditions, preserveSymlinks);\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/path-utilities",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Path utilities for Cloudpack.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"workspace-tools": "^0.38.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@ms-cloudpack/common-types": "^0.24.
|
|
34
|
+
"@ms-cloudpack/common-types": "^0.24.3",
|
|
35
35
|
"@ms-cloudpack/eslint-plugin-internal": "^0.0.1",
|
|
36
36
|
"@ms-cloudpack/scripts": "^0.0.1",
|
|
37
37
|
"@ms-cloudpack/test-utilities": "^0.5.0"
|