@ms-cloudpack/path-utilities 2.7.39 → 2.7.40
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/intermediateToSourcePath.d.ts +1 -1
- package/lib/intermediateToSourcePath.d.ts.map +1 -1
- package/lib/intermediateToSourcePath.js +27 -33
- package/lib/intermediateToSourcePath.js.map +1 -1
- package/lib/sourceToIntermediatePath.d.ts +1 -1
- package/lib/sourceToIntermediatePath.d.ts.map +1 -1
- package/lib/sourceToIntermediatePath.js +9 -16
- package/lib/sourceToIntermediatePath.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Takes a relative intermediate content path (e.g. "lib/foo/bar.js") and resolves it to a source content path
|
|
3
|
-
* (e.g. "
|
|
3
|
+
* (e.g. "./src/foo/foo.tsx"). Note: source files must exist so that the utility can resolve the source.
|
|
4
4
|
*/
|
|
5
5
|
export declare function intermediateToSourcePath(relativeIntermediatePath: string, rootPath: string): string | undefined;
|
|
6
6
|
//# sourceMappingURL=intermediateToSourcePath.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intermediateToSourcePath.d.ts","sourceRoot":"","sources":["../src/intermediateToSourcePath.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"intermediateToSourcePath.d.ts","sourceRoot":"","sources":["../src/intermediateToSourcePath.ts"],"names":[],"mappings":"AASA;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,wBAAwB,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CA4C/G"}
|
|
@@ -1,51 +1,45 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { isFileSync } from './isFileSync.js';
|
|
3
|
-
import {
|
|
3
|
+
import { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';
|
|
4
4
|
import { sourceExtensions } from './sourceExtensions.js';
|
|
5
|
+
// TODO: this assumption won't work for all repos (tracked by https://github.com/microsoft/cloudpack/issues/2366)
|
|
5
6
|
const intermediateFolderNames = ['lib', 'lib-amd', 'lib-esm', 'lib-commonjs', 'dist'];
|
|
6
7
|
const sourceFolderName = 'src';
|
|
7
8
|
/**
|
|
8
9
|
* Takes a relative intermediate content path (e.g. "lib/foo/bar.js") and resolves it to a source content path
|
|
9
|
-
* (e.g. "
|
|
10
|
+
* (e.g. "./src/foo/foo.tsx"). Note: source files must exist so that the utility can resolve the source.
|
|
10
11
|
*/
|
|
11
12
|
export function intermediateToSourcePath(relativeIntermediatePath, rootPath) {
|
|
12
|
-
const candidates = [];
|
|
13
13
|
const originalExt = path.extname(relativeIntermediatePath);
|
|
14
|
-
const
|
|
14
|
+
const originalDir = path.dirname(relativeIntermediatePath);
|
|
15
15
|
const basename = path.basename(relativeIntermediatePath, sourceExtensions.includes(originalExt) ? originalExt : undefined);
|
|
16
|
-
//
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
16
|
+
// Normalize to get rid of leading ./ or any other extra segments, then split into parts.
|
|
17
|
+
const dirParts = path.normalize(originalDir).split(/[\\/]/g);
|
|
18
|
+
if (dirParts[0] === sourceFolderName && isFileSync(path.resolve(rootPath, relativeIntermediatePath))) {
|
|
19
|
+
// This is already a complete source path. Use it as-is.
|
|
20
|
+
return normalizeRelativePath(relativeIntermediatePath);
|
|
21
|
+
}
|
|
22
|
+
const candidates = [];
|
|
23
|
+
// Find the first non-'..' folder name. If it's a known intermediate folder name, then we can
|
|
24
|
+
// replace it with the source folder name and add candidate paths for all extensions.
|
|
25
|
+
const firstDirIndex = dirParts.findIndex((part) => part !== '..');
|
|
26
|
+
if (firstDirIndex !== -1 && intermediateFolderNames.includes(dirParts[firstDirIndex])) {
|
|
27
|
+
// Join the parts back together, replacing the part with the source folder name.
|
|
28
|
+
dirParts[firstDirIndex] = sourceFolderName;
|
|
29
|
+
const newDir = dirParts.join('/');
|
|
30
|
+
// Push all possible source extensions.
|
|
31
|
+
candidates.push(...sourceExtensions.map((ext) => path.join(newDir, basename + ext)));
|
|
32
|
+
// Push the original.
|
|
33
|
+
candidates.push(path.join(newDir, basename));
|
|
34
34
|
}
|
|
35
35
|
// Push the original path with all supported source extensions.
|
|
36
|
-
candidates.push(...sourceExtensions.map((ext) => path.join(
|
|
37
|
-
// And finally push the original path with the original extension in case it wasn't
|
|
38
|
-
// covered.
|
|
36
|
+
candidates.push(...sourceExtensions.map((ext) => path.join(originalDir, basename + ext)));
|
|
37
|
+
// And finally push the original path with the original extension in case it wasn't covered.
|
|
39
38
|
candidates.push(relativeIntermediatePath);
|
|
40
|
-
|
|
41
|
-
// Ensure correct path direction.
|
|
39
|
+
const match = candidates.find((candidate) => isFileSync(path.resolve(rootPath, candidate)));
|
|
42
40
|
if (match) {
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
// Re-add the leading period.
|
|
46
|
-
if (match && !match.startsWith('./')) {
|
|
47
|
-
match = './' + match;
|
|
41
|
+
return normalizeRelativePath(match);
|
|
48
42
|
}
|
|
49
|
-
return
|
|
43
|
+
return undefined;
|
|
50
44
|
}
|
|
51
45
|
//# sourceMappingURL=intermediateToSourcePath.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intermediateToSourcePath.js","sourceRoot":"","sources":["../src/intermediateToSourcePath.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"intermediateToSourcePath.js","sourceRoot":"","sources":["../src/intermediateToSourcePath.ts"],"names":[],"mappings":"AAAA,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AAa,KAAK,CAAC,CAAC,IAAI,uBAAuB,CAAC,QAAQ,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,EAAE,CAAC;QACtF,gFAAgF;QAChF,QAAQ,CAAC,aAAa,CAAC,GAAG,gBAAgB,CAAC;QAC3C,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAElC,uCAAuC;QACvC,UAAU,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;QAErF,qBAAqB;QACrB,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC/C,CAAC;IAED,+DAA+D;IAC/D,UAAU,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,QAAQ,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;IAE1F,4FAA4F;IAC5F,UAAU,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;IAE1C,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IAC5F,IAAI,KAAK,EAAE,CAAC;QACV,OAAO,qBAAqB,CAAC,KAAK,CAAC,CAAC;IACtC,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import path from 'path';\nimport { isFileSync } from './isFileSync.js';\nimport { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';\nimport { sourceExtensions } from './sourceExtensions.js';\n\n// TODO: this assumption won't work for all repos (tracked by https://github.com/microsoft/cloudpack/issues/2366)\nconst intermediateFolderNames = ['lib', 'lib-amd', 'lib-esm', 'lib-commonjs', 'dist'];\nconst sourceFolderName = 'src';\n\n/**\n * Takes a relative intermediate content path (e.g. \"lib/foo/bar.js\") and resolves it to a source content path\n * (e.g. \"./src/foo/foo.tsx\"). Note: source files must exist so that the utility can resolve the source.\n */\nexport function intermediateToSourcePath(relativeIntermediatePath: string, rootPath: string): string | undefined {\n const originalExt = path.extname(relativeIntermediatePath);\n const originalDir = path.dirname(relativeIntermediatePath);\n const basename = path.basename(\n relativeIntermediatePath,\n sourceExtensions.includes(originalExt) ? originalExt : undefined,\n );\n\n // Normalize to get rid of leading ./ or any other extra segments, then split into parts.\n const dirParts = path.normalize(originalDir).split(/[\\\\/]/g);\n if (dirParts[0] === sourceFolderName && isFileSync(path.resolve(rootPath, relativeIntermediatePath))) {\n // This is already a complete source path. Use it as-is.\n return normalizeRelativePath(relativeIntermediatePath);\n }\n\n const candidates: string[] = [];\n\n // Find the first non-'..' folder name. If it's a known intermediate folder name, then we can\n // replace it with the source folder name and add candidate paths for all extensions.\n const firstDirIndex = dirParts.findIndex((part) => part !== '..');\n if (firstDirIndex !== -1 && intermediateFolderNames.includes(dirParts[firstDirIndex])) {\n // Join the parts back together, replacing the part with the source folder name.\n dirParts[firstDirIndex] = sourceFolderName;\n const newDir = dirParts.join('/');\n\n // Push all possible source extensions.\n candidates.push(...sourceExtensions.map((ext) => path.join(newDir, basename + ext)));\n\n // Push the original.\n candidates.push(path.join(newDir, basename));\n }\n\n // Push the original path with all supported source extensions.\n candidates.push(...sourceExtensions.map((ext) => path.join(originalDir, basename + ext)));\n\n // And finally push the original path with the original extension in case it wasn't covered.\n candidates.push(relativeIntermediatePath);\n\n const match = candidates.find((candidate) => isFileSync(path.resolve(rootPath, candidate)));\n if (match) {\n return normalizeRelativePath(match);\n }\n\n return undefined;\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Takes a relative source path (e.g. "src/foo/bar.ts") and resolves it to an intermediate content path
|
|
3
|
-
* (e.g. "
|
|
3
|
+
* (e.g. "./lib/foo/bar.js").
|
|
4
4
|
*/
|
|
5
5
|
export declare function sourceToIntermediatePath(sourcePath: string): string;
|
|
6
6
|
//# sourceMappingURL=sourceToIntermediatePath.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sourceToIntermediatePath.d.ts","sourceRoot":"","sources":["../src/sourceToIntermediatePath.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"sourceToIntermediatePath.d.ts","sourceRoot":"","sources":["../src/sourceToIntermediatePath.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAiBnE"}
|
|
@@ -1,30 +1,23 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
-
import {
|
|
2
|
+
import { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';
|
|
3
3
|
/**
|
|
4
4
|
* Takes a relative source path (e.g. "src/foo/bar.ts") and resolves it to an intermediate content path
|
|
5
|
-
* (e.g. "
|
|
5
|
+
* (e.g. "./lib/foo/bar.js").
|
|
6
6
|
*/
|
|
7
7
|
export function sourceToIntermediatePath(sourcePath) {
|
|
8
8
|
let ext = path.extname(sourcePath);
|
|
9
9
|
const basename = path.basename(sourcePath, ext);
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
if (['.ts', '.tsx', '.jsx'].includes(ext)) {
|
|
18
|
-
// Handle js replacement extensions
|
|
19
|
-
ext = '.js';
|
|
20
|
-
}
|
|
21
|
-
else if (ext === '.mts') {
|
|
22
|
-
ext = '.mjs';
|
|
10
|
+
// TODO: this assumption won't work for all repos (tracked by https://github.com/microsoft/cloudpack/issues/2366)
|
|
11
|
+
const newDir = path.normalize(path.dirname(sourcePath)).replace(/^src([\\/]|$)/, 'lib/');
|
|
12
|
+
// Handle js replacement extensions (keep the c or m if present)
|
|
13
|
+
const jsMatch = ext.match(/\.([cm])?[jt]sx?$/);
|
|
14
|
+
if (jsMatch) {
|
|
15
|
+
ext = `.${jsMatch[1] || ''}js`;
|
|
23
16
|
}
|
|
24
17
|
else if (ext === '.scss') {
|
|
25
18
|
// Handle js appends
|
|
26
19
|
ext += '.js';
|
|
27
20
|
}
|
|
28
|
-
return
|
|
21
|
+
return normalizeRelativePath(path.join(newDir, basename + ext));
|
|
29
22
|
}
|
|
30
23
|
//# sourceMappingURL=sourceToIntermediatePath.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sourceToIntermediatePath.js","sourceRoot":"","sources":["../src/sourceToIntermediatePath.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"sourceToIntermediatePath.js","sourceRoot":"","sources":["../src/sourceToIntermediatePath.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAE1E;;;GAGG;AACH,MAAM,UAAU,wBAAwB,CAAC,UAAkB;IACzD,IAAI,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACnC,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;IAEhD,iHAAiH;IACjH,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;IAEzF,gEAAgE;IAChE,MAAM,OAAO,GAAG,GAAG,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;IAC/C,IAAI,OAAO,EAAE,CAAC;QACZ,GAAG,GAAG,IAAI,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC;IACjC,CAAC;SAAM,IAAI,GAAG,KAAK,OAAO,EAAE,CAAC;QAC3B,oBAAoB;QACpB,GAAG,IAAI,KAAK,CAAC;IACf,CAAC;IAED,OAAO,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,GAAG,GAAG,CAAC,CAAC,CAAC;AAClE,CAAC","sourcesContent":["import path from 'path';\nimport { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';\n\n/**\n * Takes a relative source path (e.g. \"src/foo/bar.ts\") and resolves it to an intermediate content path\n * (e.g. \"./lib/foo/bar.js\").\n */\nexport function sourceToIntermediatePath(sourcePath: string): string {\n let ext = path.extname(sourcePath);\n const basename = path.basename(sourcePath, ext);\n\n // TODO: this assumption won't work for all repos (tracked by https://github.com/microsoft/cloudpack/issues/2366)\n const newDir = path.normalize(path.dirname(sourcePath)).replace(/^src([\\\\/]|$)/, 'lib/');\n\n // Handle js replacement extensions (keep the c or m if present)\n const jsMatch = ext.match(/\\.([cm])?[jt]sx?$/);\n if (jsMatch) {\n ext = `.${jsMatch[1] || ''}js`;\n } else if (ext === '.scss') {\n // Handle js appends\n ext += '.js';\n }\n\n return normalizeRelativePath(path.join(newDir, basename + ext));\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/path-utilities",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.40",
|
|
4
4
|
"description": "Utilities for resolving paths between source/intermediate/output locations in Cloudpack.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"fast-glob": "^3.2.12"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@ms-cloudpack/common-types": "^0.19.
|
|
31
|
+
"@ms-cloudpack/common-types": "^0.19.3",
|
|
32
32
|
"@ms-cloudpack/eslint-plugin-internal": "^0.0.1",
|
|
33
33
|
"@ms-cloudpack/scripts": "^0.0.1",
|
|
34
34
|
"@ms-cloudpack/test-utilities": "^0.5.0"
|