@ms-cloudpack/path-string-parsing 1.2.0 → 1.2.2
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/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/makeUrl.d.ts +6 -0
- package/lib/makeUrl.d.ts.map +1 -0
- package/lib/makeUrl.js +14 -0
- package/lib/makeUrl.js.map +1 -0
- package/lib/normalizeRelativePath.d.ts +4 -1
- package/lib/normalizeRelativePath.d.ts.map +1 -1
- package/lib/normalizeRelativePath.js +21 -8
- package/lib/normalizeRelativePath.js.map +1 -1
- package/package.json +3 -2
package/lib/index.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ export { normalizeRelativePath } from './normalizeRelativePath.js';
|
|
|
3
3
|
export { slash } from './slash.js';
|
|
4
4
|
export { parseImportString, type ImportStringResult } from './parseImportString.js';
|
|
5
5
|
export { parseNamedImports } from './parseNamedImports.js';
|
|
6
|
+
export { makeUrl } from './makeUrl.js';
|
|
6
7
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,iBAAiB,EAAE,KAAK,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACpF,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,iBAAiB,EAAE,KAAK,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACpF,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -3,4 +3,5 @@ export { normalizeRelativePath } from './normalizeRelativePath.js';
|
|
|
3
3
|
export { slash } from './slash.js';
|
|
4
4
|
export { parseImportString } from './parseImportString.js';
|
|
5
5
|
export { parseNamedImports } from './parseNamedImports.js';
|
|
6
|
+
export { makeUrl } from './makeUrl.js';
|
|
6
7
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,iBAAiB,EAA2B,MAAM,wBAAwB,CAAC;AACpF,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["export { safeRelativePath } from './safeRelativePath.js';\nexport { normalizeRelativePath } from './normalizeRelativePath.js';\nexport { slash } from './slash.js';\nexport { parseImportString, type ImportStringResult } from './parseImportString.js';\nexport { parseNamedImports } from './parseNamedImports.js';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,iBAAiB,EAA2B,MAAM,wBAAwB,CAAC;AACpF,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC","sourcesContent":["export { safeRelativePath } from './safeRelativePath.js';\nexport { normalizeRelativePath } from './normalizeRelativePath.js';\nexport { slash } from './slash.js';\nexport { parseImportString, type ImportStringResult } from './parseImportString.js';\nexport { parseNamedImports } from './parseNamedImports.js';\nexport { makeUrl } from './makeUrl.js';\n"]}
|
package/lib/makeUrl.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attempt to create a URL object from a string, and throw an informative error if it fails.
|
|
3
|
+
* (The URL constructor throws a very generic error.)
|
|
4
|
+
*/
|
|
5
|
+
export declare function makeUrl(input: string, base?: string | URL): URL;
|
|
6
|
+
//# sourceMappingURL=makeUrl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeUrl.d.ts","sourceRoot":"","sources":["../src/makeUrl.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,GAAG,OAOzD"}
|
package/lib/makeUrl.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attempt to create a URL object from a string, and throw an informative error if it fails.
|
|
3
|
+
* (The URL constructor throws a very generic error.)
|
|
4
|
+
*/
|
|
5
|
+
export function makeUrl(input, base) {
|
|
6
|
+
try {
|
|
7
|
+
// eslint-disable-next-line no-restricted-syntax -- this is the function definition
|
|
8
|
+
return new URL(input, base);
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
throw new Error(`Invalid URL: "${input}", base: "${base || ''}"`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=makeUrl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeUrl.js","sourceRoot":"","sources":["../src/makeUrl.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,OAAO,CAAC,KAAa,EAAE,IAAmB;IACxD,IAAI,CAAC;QACH,mFAAmF;QACnF,OAAO,IAAI,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CAAC,iBAAiB,KAAK,aAAa,IAAI,IAAI,EAAE,GAAG,CAAC,CAAC;IACpE,CAAC;AACH,CAAC","sourcesContent":["/**\n * Attempt to create a URL object from a string, and throw an informative error if it fails.\n * (The URL constructor throws a very generic error.)\n */\nexport function makeUrl(input: string, base?: string | URL) {\n try {\n // eslint-disable-next-line no-restricted-syntax -- this is the function definition\n return new URL(input, base);\n } catch {\n throw new Error(`Invalid URL: \"${input}\", base: \"${base || ''}\"`);\n }\n}\n"]}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Normalize a path:
|
|
3
|
-
* - If it's empty, undefined, or
|
|
3
|
+
* - If it's empty, undefined, or `.`, return `.`.
|
|
4
4
|
* - If it's relative, normalize slashes and ensure it starts with `./`.
|
|
5
|
+
* - If it starts with `/`, add a leading `.` (this is an absolute path but is sometimes treated
|
|
6
|
+
* as package-relative)
|
|
7
|
+
* - If it's an absolute Windows path (starts with a drive letter), throw an error.
|
|
5
8
|
* - If it's absolute, throw an error (since this likely indicates a bug in the calling code).
|
|
6
9
|
*
|
|
7
10
|
* Note that this will NOT remove a trailing slash (if present).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalizeRelativePath.d.ts","sourceRoot":"","sources":["../src/normalizeRelativePath.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"normalizeRelativePath.d.ts","sourceRoot":"","sources":["../src/normalizeRelativePath.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CA6B9E"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { slash } from './slash.js';
|
|
2
2
|
/**
|
|
3
3
|
* Normalize a path:
|
|
4
|
-
* - If it's empty, undefined, or
|
|
4
|
+
* - If it's empty, undefined, or `.`, return `.`.
|
|
5
5
|
* - If it's relative, normalize slashes and ensure it starts with `./`.
|
|
6
|
+
* - If it starts with `/`, add a leading `.` (this is an absolute path but is sometimes treated
|
|
7
|
+
* as package-relative)
|
|
8
|
+
* - If it's an absolute Windows path (starts with a drive letter), throw an error.
|
|
6
9
|
* - If it's absolute, throw an error (since this likely indicates a bug in the calling code).
|
|
7
10
|
*
|
|
8
11
|
* Note that this will NOT remove a trailing slash (if present).
|
|
@@ -11,14 +14,24 @@ export function normalizeRelativePath(originalPath) {
|
|
|
11
14
|
if (!originalPath || originalPath === '.') {
|
|
12
15
|
return '.';
|
|
13
16
|
}
|
|
14
|
-
// Throw
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
// Throw on an absolute Windows path: this is definitely absolute regardless of the context it
|
|
18
|
+
// came from, and if the calling code attempts to join it to another path as if it was relative,
|
|
19
|
+
// that will have bad results. It's more likely on Windows that we could unintentionally end up
|
|
20
|
+
// with an absolute path since there's no way to do relative paths across drive letters
|
|
21
|
+
// (path.relative() will return an absolute path), so we throw here to make it clear that
|
|
22
|
+
// Cloudpack needs to have specific handling for any cases where that might be possible.
|
|
23
|
+
if (/^[a-zA-Z]:[\\/]/.test(originalPath)) {
|
|
24
|
+
throw new Error(`Received an absolute path where a relative path was expected: ${originalPath}.\n` +
|
|
25
|
+
'This indicates a bug in Cloudpack, likely due to calling path.relative() with two Windows paths ' +
|
|
26
|
+
'on different drives (which returns an absolute path) and then assuming the result is relative.');
|
|
19
27
|
}
|
|
20
28
|
// Ensure we have the right slashes.
|
|
21
|
-
|
|
22
|
-
|
|
29
|
+
const normalizedPath = slash(originalPath);
|
|
30
|
+
if (normalizedPath[0] === '/') {
|
|
31
|
+
// Technically a path starting with / is absolute, but it's possible that package.json
|
|
32
|
+
// entry points like "main" could also use a leading slash to indicate the package root.
|
|
33
|
+
return '.' + normalizedPath;
|
|
34
|
+
}
|
|
35
|
+
return normalizedPath.startsWith('./') ? normalizedPath : `./${normalizedPath}`;
|
|
23
36
|
}
|
|
24
37
|
//# sourceMappingURL=normalizeRelativePath.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalizeRelativePath.js","sourceRoot":"","sources":["../src/normalizeRelativePath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC
|
|
1
|
+
{"version":3,"file":"normalizeRelativePath.js","sourceRoot":"","sources":["../src/normalizeRelativePath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC;;;;;;;;;;GAUG;AACH,MAAM,UAAU,qBAAqB,CAAC,YAAgC;IACpE,IAAI,CAAC,YAAY,IAAI,YAAY,KAAK,GAAG,EAAE,CAAC;QAC1C,OAAO,GAAG,CAAC;IACb,CAAC;IAED,8FAA8F;IAC9F,gGAAgG;IAChG,+FAA+F;IAC/F,uFAAuF;IACvF,yFAAyF;IACzF,wFAAwF;IACxF,IAAI,iBAAiB,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC;QACzC,MAAM,IAAI,KAAK,CACb,iEAAiE,YAAY,KAAK;YAChF,kGAAkG;YAClG,gGAAgG,CACnG,CAAC;IACJ,CAAC;IAED,oCAAoC;IACpC,MAAM,cAAc,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC;IAE3C,IAAI,cAAc,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;QAC9B,sFAAsF;QACtF,wFAAwF;QACxF,OAAO,GAAG,GAAG,cAAc,CAAC;IAC9B,CAAC;IAED,OAAO,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,KAAK,cAAc,EAAE,CAAC;AAClF,CAAC","sourcesContent":["import { slash } from './slash.js';\n\n/**\n * Normalize a path:\n * - If it's empty, undefined, or `.`, return `.`.\n * - If it's relative, normalize slashes and ensure it starts with `./`.\n * - If it starts with `/`, add a leading `.` (this is an absolute path but is sometimes treated\n * as package-relative)\n * - If it's an absolute Windows path (starts with a drive letter), throw an error.\n * - If it's absolute, throw an error (since this likely indicates a bug in the calling code).\n *\n * Note that this will NOT remove a trailing slash (if present).\n */\nexport function normalizeRelativePath(originalPath: string | undefined): string {\n if (!originalPath || originalPath === '.') {\n return '.';\n }\n\n // Throw on an absolute Windows path: this is definitely absolute regardless of the context it\n // came from, and if the calling code attempts to join it to another path as if it was relative,\n // that will have bad results. It's more likely on Windows that we could unintentionally end up\n // with an absolute path since there's no way to do relative paths across drive letters\n // (path.relative() will return an absolute path), so we throw here to make it clear that\n // Cloudpack needs to have specific handling for any cases where that might be possible.\n if (/^[a-zA-Z]:[\\\\/]/.test(originalPath)) {\n throw new Error(\n `Received an absolute path where a relative path was expected: ${originalPath}.\\n` +\n 'This indicates a bug in Cloudpack, likely due to calling path.relative() with two Windows paths ' +\n 'on different drives (which returns an absolute path) and then assuming the result is relative.',\n );\n }\n\n // Ensure we have the right slashes.\n const normalizedPath = slash(originalPath);\n\n if (normalizedPath[0] === '/') {\n // Technically a path starting with / is absolute, but it's possible that package.json\n // entry points like \"main\" could also use a leading slash to indicate the package root.\n return '.' + normalizedPath;\n }\n\n return normalizedPath.startsWith('./') ? normalizedPath : `./${normalizedPath}`;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/path-string-parsing",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "Common path-related string parsing utilities for Cloudpack",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"test": "cloudpack-scripts test"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@ms-cloudpack/eslint-plugin-internal": "
|
|
27
|
+
"@ms-cloudpack/eslint-plugin-internal": "^0.0.1",
|
|
28
|
+
"@ms-cloudpack/scripts": "^0.0.1"
|
|
28
29
|
},
|
|
29
30
|
"files": [
|
|
30
31
|
"lib/**/!(*.test.*)"
|