@ms-cloudpack/path-string-parsing 1.1.3 → 1.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/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/normalizeRelativePath.d.ts +10 -0
- package/lib/normalizeRelativePath.d.ts.map +1 -0
- package/lib/normalizeRelativePath.js +24 -0
- package/lib/normalizeRelativePath.js.map +1 -0
- package/lib/parseImportString.js +2 -2
- package/lib/parseImportString.js.map +1 -1
- package/lib/parseNamedImports.js.map +1 -1
- package/lib/safeRelativePath.d.ts +1 -2
- package/lib/safeRelativePath.d.ts.map +1 -1
- package/lib/safeRelativePath.js +3 -15
- package/lib/safeRelativePath.js.map +1 -1
- package/lib/tsdoc-metadata.json +1 -1
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { safeRelativePath } from './safeRelativePath.js';
|
|
2
|
+
export { normalizeRelativePath } from './normalizeRelativePath.js';
|
|
2
3
|
export { slash } from './slash.js';
|
|
3
4
|
export { parseImportString, type ImportStringResult } from './parseImportString.js';
|
|
4
5
|
export { parseNamedImports } from './parseNamedImports.js';
|
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,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"}
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { safeRelativePath } from './safeRelativePath.js';
|
|
2
|
+
export { normalizeRelativePath } from './normalizeRelativePath.js';
|
|
2
3
|
export { slash } from './slash.js';
|
|
3
4
|
export { parseImportString } from './parseImportString.js';
|
|
4
5
|
export { parseNamedImports } from './parseNamedImports.js';
|
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,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 { 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","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"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalize a path:
|
|
3
|
+
* - If it's empty, undefined, or `'.'`, return `'.'`.
|
|
4
|
+
* - If it's relative, normalize slashes and ensure it starts with `./`.
|
|
5
|
+
* - If it's absolute, throw an error (since this likely indicates a bug in the calling code).
|
|
6
|
+
*
|
|
7
|
+
* Note that this will NOT remove a trailing slash (if present).
|
|
8
|
+
*/
|
|
9
|
+
export declare function normalizeRelativePath(originalPath: string | undefined): string;
|
|
10
|
+
//# sourceMappingURL=normalizeRelativePath.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalizeRelativePath.d.ts","sourceRoot":"","sources":["../src/normalizeRelativePath.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAgB9E"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { slash } from './slash.js';
|
|
2
|
+
/**
|
|
3
|
+
* Normalize a path:
|
|
4
|
+
* - If it's empty, undefined, or `'.'`, return `'.'`.
|
|
5
|
+
* - If it's relative, normalize slashes and ensure it starts with `./`.
|
|
6
|
+
* - If it's absolute, throw an error (since this likely indicates a bug in the calling code).
|
|
7
|
+
*
|
|
8
|
+
* Note that this will NOT remove a trailing slash (if present).
|
|
9
|
+
*/
|
|
10
|
+
export function normalizeRelativePath(originalPath) {
|
|
11
|
+
if (!originalPath || originalPath === '.') {
|
|
12
|
+
return '.';
|
|
13
|
+
}
|
|
14
|
+
// Throw if the path is absolute.
|
|
15
|
+
// NOTE: Don't use the `path` module because this function is used by `parseImportString`, which
|
|
16
|
+
// is used in the browser by the overlay.
|
|
17
|
+
if (originalPath[0] === '/' || /^[a-zA-Z]:[\\/]/.test(originalPath)) {
|
|
18
|
+
throw new Error(`Expected a relative path, but received an absolute path: ${originalPath}`);
|
|
19
|
+
}
|
|
20
|
+
// Ensure we have the right slashes.
|
|
21
|
+
originalPath = slash(originalPath);
|
|
22
|
+
return originalPath.startsWith('./') ? originalPath : `./${originalPath}`;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=normalizeRelativePath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalizeRelativePath.js","sourceRoot":"","sources":["../src/normalizeRelativePath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CAAC,YAAgC;IACpE,IAAI,CAAC,YAAY,IAAI,YAAY,KAAK,GAAG,EAAE,CAAC;QAC1C,OAAO,GAAG,CAAC;IACb,CAAC;IAED,iCAAiC;IACjC,gGAAgG;IAChG,yCAAyC;IACzC,IAAI,YAAY,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,iBAAiB,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC;QACpE,MAAM,IAAI,KAAK,CAAC,4DAA4D,YAAY,EAAE,CAAC,CAAC;IAC9F,CAAC;IAED,oCAAoC;IACpC,YAAY,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC;IAEnC,OAAO,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,YAAY,EAAE,CAAC;AAC5E,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'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 if the path is absolute.\n // NOTE: Don't use the `path` module because this function is used by `parseImportString`, which\n // is used in the browser by the overlay.\n if (originalPath[0] === '/' || /^[a-zA-Z]:[\\\\/]/.test(originalPath)) {\n throw new Error(`Expected a relative path, but received an absolute path: ${originalPath}`);\n }\n\n // Ensure we have the right slashes.\n originalPath = slash(originalPath);\n\n return originalPath.startsWith('./') ? originalPath : `./${originalPath}`;\n}\n"]}
|
package/lib/parseImportString.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { normalizeRelativePath } from './normalizeRelativePath.js';
|
|
2
2
|
/**
|
|
3
3
|
* Parse an import path: usually this will be a standard JS import, but this function also allows
|
|
4
4
|
* an optional `@version` suffix after the package name.
|
|
@@ -18,7 +18,7 @@ export function parseImportString(importString = '') {
|
|
|
18
18
|
return {
|
|
19
19
|
packageName: matches[1] || '.',
|
|
20
20
|
version: matches[2] || '',
|
|
21
|
-
importPath:
|
|
21
|
+
importPath: normalizeRelativePath(matches[3]),
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
//# sourceMappingURL=parseImportString.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseImportString.js","sourceRoot":"","sources":["../src/parseImportString.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"parseImportString.js","sourceRoot":"","sources":["../src/parseImportString.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAanE;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,iBAAiB,CAAC,YAAY,GAAG,EAAE;IACjD,MAAM,OAAO,GACX,YAAY,CAAC,KAAK;IAChB,0DAA0D;IAC1D,gEAAgE,CACjE,IAAI,EAAE,CAAC;IAEV,OAAO;QACL,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,GAAG;QAC9B,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE;QACzB,UAAU,EAAE,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;KAC9C,CAAC;AACJ,CAAC","sourcesContent":["import { normalizeRelativePath } from './normalizeRelativePath.js';\n\nexport type ImportStringResult = {\n packageName: string;\n /** Optional package version (default: empty string) */\n version: string;\n /**\n * Optional import path (default: `'.'`).\n * If this is set to a non-default value, it will be normalized to start with `./`.\n */\n importPath: string;\n};\n\n/**\n * Parse an import path: usually this will be a standard JS import, but this function also allows\n * an optional `@version` suffix after the package name.\n *\n * Examples of supported import strings:\n * - `foo`\n * - `foo@1.2.3`\n * - `foo@1.2.3/path/to/file`\n * - `@foo/bar`\n * - `@foo/bar@1.2.3`\n * - `@foo/bar@1.2.3/path/to/file`\n */\nexport function parseImportString(importString = ''): ImportStringResult {\n const matches =\n importString.match(\n // 1: packageName 2: version 3: importPath\n /^\\/?((?:@[-\\w.:]+\\/)?[-\\w.:]+)(?:@([-\\w.]+))?(?:\\/([-\\w./]+))?/,\n ) || [];\n\n return {\n packageName: matches[1] || '.',\n version: matches[2] || '',\n importPath: normalizeRelativePath(matches[3]),\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseNamedImports.js","sourceRoot":"","sources":["../src/parseNamedImports.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,UAAkB;IAClD,yEAAyE;IACzE,qDAAqD;IACrD,MAAM,OAAO,GAAG,UAAU,CAAC,KAAK,CAC9B,kdAAkd,CACnd,CAAC;IACF,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,mCAAmC;IACnC,IAAI,OAAO,KAAK,IAAI,EAAE;
|
|
1
|
+
{"version":3,"file":"parseNamedImports.js","sourceRoot":"","sources":["../src/parseNamedImports.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,UAAkB;IAClD,yEAAyE;IACzE,qDAAqD;IACrD,MAAM,OAAO,GAAG,UAAU,CAAC,KAAK,CAC9B,kdAAkd,CACnd,CAAC;IACF,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,mCAAmC;IACnC,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACrB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,2DAA2D;IAC3D,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;QACf,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACxB,CAAC;IACD,6DAA6D;IAC7D,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;QACf,kDAAkD;QAClD,MAAM,YAAY,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,oCAAoC,CAAC,CAAC;QAC/E,KAAK,MAAM,WAAW,IAAI,YAAY,EAAE,CAAC;YACvC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;IAED,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;QACf,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAClB,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/**\n * Parses an import string into its component parts.\n * @param importLine - The import string to parse.\n * @returns A string array with the named imports, default and/or '*'.\n */\nexport function parseNamedImports(importLine: string): string[] {\n // Regex from: https://github.com/antonkc/MOR/blob/main/matchJsImports.md\n // With some edits to catch exports * from \"package\".\n const matches = importLine.match(\n /(?<=(?:[\\s\\n;])|^)(?:(?:import|export)[\\s\\n]*((?:(?<=[\\s\\n])type)?)(?=[\\n\\s*{])[\\s\\n]*)((?:(?:[_$\\w][_$\\w0-9]*)(?:[\\s\\n]+(?:as[\\s\\n]+(?:[_$\\w][_$\\w0-9]*)))?(?=(?:[\\n\\s]*,[\\n\\s]*[{*])|(?:[\\n\\s]+from)))?)[\\s\\n,]*((?:\\*[\\n\\s]*(?:as[\\s\\n]+(?:[_$\\w][_$\\w0-9]*))(?=[\\n\\s]+from))?|\\*)[\\s\\n,]*((?:\\{[n\\s]*(?:(?:[_$\\w][_$\\w0-9]*)(?:[\\s\\n]+(?:as[\\s\\n]+(?:[_$\\w][_$\\w0-9]*)))?[\\s\\n]*,?[\\s\\n]*)*\\}(?=[\\n\\s]*from))?)(?:[\\s\\n]*((?:from)?))[\\s\\n]*(?:[\"']([^\"']*)([\"']))[\\s\\n]*?;?/,\n );\n const names: string[] = [];\n // If no matches return empty array\n if (matches === null) {\n return names;\n }\n // If there is a default export, push it to the names array\n if (matches[2]) {\n names.push('default');\n }\n // If there is a namespace export, push it to the names array\n if (matches[4]) {\n // Clean out the braces, whitespace, and get alias\n const namedImports = matches[4].matchAll(/([\\w$]+)(?:\\s+as\\s+[\\w$]+(?:,)?)?/g);\n for (const namedImport of namedImports) {\n names.push(namedImport[1]);\n }\n }\n\n if (matches[3]) {\n names.push('*');\n }\n\n return names;\n}\n"]}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* Returns `.` if the given path is empty or undefined (or already `.`).
|
|
2
|
+
* @deprecated Use `normalizeRelativePath`.
|
|
4
3
|
*/
|
|
5
4
|
export declare function safeRelativePath(originalPath: string | undefined): string;
|
|
6
5
|
//# sourceMappingURL=safeRelativePath.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"safeRelativePath.d.ts","sourceRoot":"","sources":["../src/safeRelativePath.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"safeRelativePath.d.ts","sourceRoot":"","sources":["../src/safeRelativePath.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAEzE"}
|
package/lib/safeRelativePath.js
CHANGED
|
@@ -1,20 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { normalizeRelativePath } from './normalizeRelativePath.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* Returns `.` if the given path is empty or undefined (or already `.`).
|
|
3
|
+
* @deprecated Use `normalizeRelativePath`.
|
|
5
4
|
*/
|
|
6
5
|
export function safeRelativePath(originalPath) {
|
|
7
|
-
|
|
8
|
-
return '.';
|
|
9
|
-
}
|
|
10
|
-
// Ensure we have the right slashes.
|
|
11
|
-
originalPath = slash(originalPath);
|
|
12
|
-
if (originalPath.startsWith('/')) {
|
|
13
|
-
return '.' + originalPath;
|
|
14
|
-
}
|
|
15
|
-
else if (originalPath.startsWith('./')) {
|
|
16
|
-
return originalPath;
|
|
17
|
-
}
|
|
18
|
-
return `./${originalPath}`;
|
|
6
|
+
return normalizeRelativePath(originalPath);
|
|
19
7
|
}
|
|
20
8
|
//# sourceMappingURL=safeRelativePath.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"safeRelativePath.js","sourceRoot":"","sources":["../src/safeRelativePath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"safeRelativePath.js","sourceRoot":"","sources":["../src/safeRelativePath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,YAAgC;IAC/D,OAAO,qBAAqB,CAAC,YAAY,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["import { normalizeRelativePath } from './normalizeRelativePath.js';\n\n/**\n * @deprecated Use `normalizeRelativePath`.\n */\nexport function safeRelativePath(originalPath: string | undefined): string {\n return normalizeRelativePath(originalPath);\n}\n"]}
|
package/lib/tsdoc-metadata.json
CHANGED