@ms-cloudpack/eslint-plugin 0.8.0 → 0.9.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.
Files changed (61) hide show
  1. package/lib/configs/index.d.ts +93 -0
  2. package/lib/configs/index.d.ts.map +1 -0
  3. package/lib/configs/index.js +36 -0
  4. package/lib/configs/index.js.map +1 -0
  5. package/lib/index.d.ts +105 -0
  6. package/lib/index.d.ts.map +1 -0
  7. package/lib/index.js +7 -0
  8. package/lib/index.js.map +1 -0
  9. package/lib/plugin.d.ts +15 -0
  10. package/lib/plugin.d.ts.map +1 -0
  11. package/lib/plugin.js +16 -0
  12. package/lib/plugin.js.map +1 -0
  13. package/lib/rules/no-test-exports.d.ts +18 -0
  14. package/lib/rules/no-test-exports.d.ts.map +1 -0
  15. package/lib/rules/no-test-exports.js +131 -0
  16. package/lib/rules/no-test-exports.js.map +1 -0
  17. package/lib/rules/no-unsupported-imports.d.ts +14 -0
  18. package/lib/rules/no-unsupported-imports.d.ts.map +1 -0
  19. package/lib/rules/no-unsupported-imports.js +172 -0
  20. package/lib/rules/no-unsupported-imports.js.map +1 -0
  21. package/lib/utils/PackageJson.d.ts +43 -0
  22. package/lib/utils/PackageJson.d.ts.map +1 -0
  23. package/lib/utils/PackageJson.js +3 -0
  24. package/lib/utils/PackageJson.js.map +1 -0
  25. package/lib/utils/createRule.d.ts +41 -0
  26. package/lib/utils/createRule.d.ts.map +1 -0
  27. package/lib/utils/createRule.js +21 -0
  28. package/lib/utils/createRule.js.map +1 -0
  29. package/lib/utils/getImportPathLiteralNode.d.ts +11 -0
  30. package/lib/utils/getImportPathLiteralNode.d.ts.map +1 -0
  31. package/lib/utils/getImportPathLiteralNode.js +44 -0
  32. package/lib/utils/getImportPathLiteralNode.js.map +1 -0
  33. package/lib/utils/getPackageInfo.d.ts +16 -0
  34. package/lib/utils/getPackageInfo.d.ts.map +1 -0
  35. package/lib/utils/getPackageInfo.js +57 -0
  36. package/lib/utils/getPackageInfo.js.map +1 -0
  37. package/lib/utils/getRegexpsFromStrings.d.ts +6 -0
  38. package/lib/utils/getRegexpsFromStrings.d.ts.map +1 -0
  39. package/lib/utils/getRegexpsFromStrings.js +8 -0
  40. package/lib/utils/getRegexpsFromStrings.js.map +1 -0
  41. package/lib/utils/testExports/extractIdentifiersFromExport.d.ts +6 -0
  42. package/lib/utils/testExports/extractIdentifiersFromExport.d.ts.map +1 -0
  43. package/lib/utils/testExports/extractIdentifiersFromExport.js +54 -0
  44. package/lib/utils/testExports/extractIdentifiersFromExport.js.map +1 -0
  45. package/lib/utils/testExports/isIncludedIndexFile.d.ts +10 -0
  46. package/lib/utils/testExports/isIncludedIndexFile.d.ts.map +1 -0
  47. package/lib/utils/testExports/isIncludedIndexFile.js +24 -0
  48. package/lib/utils/testExports/isIncludedIndexFile.js.map +1 -0
  49. package/lib/utils/unsupportedImports/parseImportIfRelevant.d.ts +19 -0
  50. package/lib/utils/unsupportedImports/parseImportIfRelevant.d.ts.map +1 -0
  51. package/lib/utils/unsupportedImports/parseImportIfRelevant.js +35 -0
  52. package/lib/utils/unsupportedImports/parseImportIfRelevant.js.map +1 -0
  53. package/lib/utils/unsupportedImports/pathSatisfiesAnyExport.d.ts +8 -0
  54. package/lib/utils/unsupportedImports/pathSatisfiesAnyExport.d.ts.map +1 -0
  55. package/lib/utils/unsupportedImports/pathSatisfiesAnyExport.js +34 -0
  56. package/lib/utils/unsupportedImports/pathSatisfiesAnyExport.js.map +1 -0
  57. package/lib/utils/unsupportedImports/resolvePackageRoot.d.ts +7 -0
  58. package/lib/utils/unsupportedImports/resolvePackageRoot.d.ts.map +1 -0
  59. package/lib/utils/unsupportedImports/resolvePackageRoot.js +45 -0
  60. package/lib/utils/unsupportedImports/resolvePackageRoot.js.map +1 -0
  61. package/package.json +11 -4
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Checks whether the given file is an index file, is not under an ignored path, and is not
3
+ * nested too deep in the package.
4
+ */
5
+ export declare function isIncludedIndexFile(params: {
6
+ filename: string;
7
+ ignorePaths: RegExp[];
8
+ maxDepth: number;
9
+ }): boolean;
10
+ //# sourceMappingURL=isIncludedIndexFile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isIncludedIndexFile.d.ts","sourceRoot":"","sources":["../../../src/utils/testExports/isIncludedIndexFile.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,EAAE,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAoBlH"}
@@ -0,0 +1,24 @@
1
+ import path from 'path';
2
+ import { getPackageInfo } from "../getPackageInfo.js";
3
+ /**
4
+ * Checks whether the given file is an index file, is not under an ignored path, and is not
5
+ * nested too deep in the package.
6
+ */
7
+ export function isIncludedIndexFile(params) {
8
+ const { filename, ignorePaths, maxDepth } = params;
9
+ // ignore non index files
10
+ if (!filename || !/^index\.[cm]?[jt]sx?$/.test(path.basename(filename))) {
11
+ return false;
12
+ }
13
+ const packageInfo = getPackageInfo(filename);
14
+ if (packageInfo) {
15
+ const relativePath = path.normalize(filename).replace(packageInfo.path, '').slice(1).replace(/\\/g, '/');
16
+ // Ignore index files that are too deep, or if the relative path (within the package)
17
+ // matches an ignore path
18
+ if (relativePath.split('/').length > maxDepth + 1 || ignorePaths.some((re) => re.test('./' + relativePath))) {
19
+ return false;
20
+ }
21
+ }
22
+ return true;
23
+ }
24
+ //# sourceMappingURL=isIncludedIndexFile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isIncludedIndexFile.js","sourceRoot":"","sources":["../../../src/utils/testExports/isIncludedIndexFile.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAqE;IACvG,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC;IAEnD,yBAAyB;IACzB,IAAI,CAAC,QAAQ,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;QACxE,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,WAAW,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC;IAC7C,IAAI,WAAW,EAAE,CAAC;QAChB,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAEzG,qFAAqF;QACrF,yBAAyB;QACzB,IAAI,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,QAAQ,GAAG,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC,CAAC,EAAE,CAAC;YAC5G,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import path from 'path';\nimport { getPackageInfo } from '../getPackageInfo.ts';\n\n/**\n * Checks whether the given file is an index file, is not under an ignored path, and is not\n * nested too deep in the package.\n */\nexport function isIncludedIndexFile(params: { filename: string; ignorePaths: RegExp[]; maxDepth: number }): boolean {\n const { filename, ignorePaths, maxDepth } = params;\n\n // ignore non index files\n if (!filename || !/^index\\.[cm]?[jt]sx?$/.test(path.basename(filename))) {\n return false;\n }\n\n const packageInfo = getPackageInfo(filename);\n if (packageInfo) {\n const relativePath = path.normalize(filename).replace(packageInfo.path, '').slice(1).replace(/\\\\/g, '/');\n\n // Ignore index files that are too deep, or if the relative path (within the package)\n // matches an ignore path\n if (relativePath.split('/').length > maxDepth + 1 || ignorePaths.some((re) => re.test('./' + relativePath))) {\n return false;\n }\n }\n\n return true;\n}\n"]}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Verify that the import is relevant for the very specific purposes of the `no-unsupported-imports` rule,
3
+ * and if so, find the package name and sub-path.
4
+ */
5
+ export declare function parseImportIfRelevant(importPath: string, ignorePatterns: RegExp[]): {
6
+ packageName: string;
7
+ subPath: string;
8
+ } | null;
9
+ /**
10
+ * Parse a module ID which is assumed to point to an actual file in a package (no loader prefixes,
11
+ * relative paths, node builtins, or data URIs).
12
+ * @returns Package name and sub-path (if any). Sub-path does *not* include a leading `./`,
13
+ * e.g. `@foo/bar/baz` returns `{ packageName: '@foo/bar', subPath: 'baz' }`.
14
+ */
15
+ export declare function parseModuleId(moduleId: string): {
16
+ packageName: string;
17
+ subPath: string;
18
+ };
19
+ //# sourceMappingURL=parseImportIfRelevant.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseImportIfRelevant.d.ts","sourceRoot":"","sources":["../../../src/utils/unsupportedImports/parseImportIfRelevant.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,MAAM,EAAE,GACvB;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAiBjD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAOxF"}
@@ -0,0 +1,35 @@
1
+ import { builtinModules } from 'module';
2
+ /**
3
+ * Verify that the import is relevant for the very specific purposes of the `no-unsupported-imports` rule,
4
+ * and if so, find the package name and sub-path.
5
+ */
6
+ export function parseImportIfRelevant(importPath, ignorePatterns) {
7
+ // Remove any webpack loader prefix
8
+ // (* is greedy, so it will work even if multiple loaders are specified)
9
+ const normalizedImport = importPath.replace(/.*!/, '');
10
+ // Ignore relative imports, internal imports, builtins, and data URLs
11
+ // (builtinModules includes valid sub-paths like "fs/promises")
12
+ if (!/^([.#]|node:|data:)/.test(normalizedImport) && !builtinModules.includes(normalizedImport)) {
13
+ // Find the package name and sub-path (if any)
14
+ const { packageName, subPath } = parseModuleId(normalizedImport);
15
+ // Ignore top-level imports, or anything from an ignored package
16
+ if (subPath && !ignorePatterns.some((r) => r.test(normalizedImport))) {
17
+ return { packageName, subPath };
18
+ }
19
+ }
20
+ return null;
21
+ }
22
+ /**
23
+ * Parse a module ID which is assumed to point to an actual file in a package (no loader prefixes,
24
+ * relative paths, node builtins, or data URIs).
25
+ * @returns Package name and sub-path (if any). Sub-path does *not* include a leading `./`,
26
+ * e.g. `@foo/bar/baz` returns `{ packageName: '@foo/bar', subPath: 'baz' }`.
27
+ */
28
+ export function parseModuleId(moduleId) {
29
+ const nameParts = moduleId.split('/');
30
+ const hasScope = nameParts.length >= 2 && nameParts[0][0] === '@';
31
+ const packageName = hasScope ? `${nameParts[0]}/${nameParts[1]}` : nameParts[0];
32
+ const subPath = nameParts.slice(hasScope ? 2 : 1).join('/');
33
+ return { packageName, subPath };
34
+ }
35
+ //# sourceMappingURL=parseImportIfRelevant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseImportIfRelevant.js","sourceRoot":"","sources":["../../../src/utils/unsupportedImports/parseImportIfRelevant.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAExC;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CACnC,UAAkB,EAClB,cAAwB;IAExB,mCAAmC;IACnC,wEAAwE;IACxE,MAAM,gBAAgB,GAAG,UAAU,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAEvD,qEAAqE;IACrE,+DAA+D;IAC/D,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,CAAC;QAChG,8CAA8C;QAC9C,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,aAAa,CAAC,gBAAgB,CAAC,CAAC;QAEjE,gEAAgE;QAChE,IAAI,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,EAAE,CAAC;YACrE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC;QAClC,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,QAAgB;IAC5C,MAAM,SAAS,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACtC,MAAM,QAAQ,GAAG,SAAS,CAAC,MAAM,IAAI,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC;IAElE,MAAM,WAAW,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAChF,MAAM,OAAO,GAAG,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC5D,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC;AAClC,CAAC","sourcesContent":["import { builtinModules } from 'module';\n\n/**\n * Verify that the import is relevant for the very specific purposes of the `no-unsupported-imports` rule,\n * and if so, find the package name and sub-path.\n */\nexport function parseImportIfRelevant(\n importPath: string,\n ignorePatterns: RegExp[],\n): { packageName: string; subPath: string } | null {\n // Remove any webpack loader prefix\n // (* is greedy, so it will work even if multiple loaders are specified)\n const normalizedImport = importPath.replace(/.*!/, '');\n\n // Ignore relative imports, internal imports, builtins, and data URLs\n // (builtinModules includes valid sub-paths like \"fs/promises\")\n if (!/^([.#]|node:|data:)/.test(normalizedImport) && !builtinModules.includes(normalizedImport)) {\n // Find the package name and sub-path (if any)\n const { packageName, subPath } = parseModuleId(normalizedImport);\n\n // Ignore top-level imports, or anything from an ignored package\n if (subPath && !ignorePatterns.some((r) => r.test(normalizedImport))) {\n return { packageName, subPath };\n }\n }\n return null;\n}\n\n/**\n * Parse a module ID which is assumed to point to an actual file in a package (no loader prefixes,\n * relative paths, node builtins, or data URIs).\n * @returns Package name and sub-path (if any). Sub-path does *not* include a leading `./`,\n * e.g. `@foo/bar/baz` returns `{ packageName: '@foo/bar', subPath: 'baz' }`.\n */\nexport function parseModuleId(moduleId: string): { packageName: string; subPath: string } {\n const nameParts = moduleId.split('/');\n const hasScope = nameParts.length >= 2 && nameParts[0][0] === '@';\n\n const packageName = hasScope ? `${nameParts[0]}/${nameParts[1]}` : nameParts[0];\n const subPath = nameParts.slice(hasScope ? 2 : 1).join('/');\n return { packageName, subPath };\n}\n"]}
@@ -0,0 +1,8 @@
1
+ import type { PackageExports } from '../PackageJson.ts';
2
+ /**
3
+ * Determine whether `importSubPath` might satisfy any sub-path from the exports map,
4
+ * disregarding conditions and file existence.
5
+ * @param importSubPath Sub-path such as `lib/foo`
6
+ */
7
+ export declare function pathSatisfiesAnyExport(exportsMap: PackageExports | undefined, importSubPath: string): boolean;
8
+ //# sourceMappingURL=pathSatisfiesAnyExport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pathSatisfiesAnyExport.d.ts","sourceRoot":"","sources":["../../../src/utils/unsupportedImports/pathSatisfiesAnyExport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAExD;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,cAAc,GAAG,SAAS,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CA8B7G"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Determine whether `importSubPath` might satisfy any sub-path from the exports map,
3
+ * disregarding conditions and file existence.
4
+ * @param importSubPath Sub-path such as `lib/foo`
5
+ */
6
+ export function pathSatisfiesAnyExport(exportsMap, importSubPath) {
7
+ // If the exports map is a string, it's a shorthand for a single export.
8
+ // If it's an array, the contents are fallbacks for a single export.
9
+ if (!exportsMap || typeof exportsMap === 'string' || Array.isArray(exportsMap)) {
10
+ return false;
11
+ }
12
+ importSubPath = `./${importSubPath}`;
13
+ return (
14
+ // Check for very basic exclusions. (Technically a path could also be excluded by setting
15
+ // a condition to null, or by setting a later wildcard to override an earlier one.
16
+ // Handling for this can be added later if needed.)
17
+ exportsMap[importSubPath] !== null &&
18
+ Object.keys(exportsMap).some((key) => {
19
+ // . is the root import, not a sub-path.
20
+ // Starting character other than . means this is a condition, not a path.
21
+ if (key === '.' || key[0] !== '.') {
22
+ return false;
23
+ }
24
+ if (key.includes('*')) {
25
+ return new RegExp(`^${key.replace(/\./g, '\\.').replace(/\*/g, '.*')}$`).test(importSubPath);
26
+ }
27
+ if (key.endsWith('/')) {
28
+ return importSubPath.startsWith(key);
29
+ }
30
+ // Check if the path is a literal match for this key
31
+ return key === importSubPath;
32
+ }));
33
+ }
34
+ //# sourceMappingURL=pathSatisfiesAnyExport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pathSatisfiesAnyExport.js","sourceRoot":"","sources":["../../../src/utils/unsupportedImports/pathSatisfiesAnyExport.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CAAC,UAAsC,EAAE,aAAqB;IAClG,wEAAwE;IACxE,oEAAoE;IACpE,IAAI,CAAC,UAAU,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QAC/E,OAAO,KAAK,CAAC;IACf,CAAC;IAED,aAAa,GAAG,KAAK,aAAa,EAAE,CAAC;IAErC,OAAO;IACL,yFAAyF;IACzF,kFAAkF;IAClF,mDAAmD;IAClD,UAAsC,CAAC,aAAa,CAAC,KAAK,IAAI;QAC/D,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;YACnC,wCAAwC;YACxC,yEAAyE;YACzE,IAAI,GAAG,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;gBAClC,OAAO,KAAK,CAAC;YACf,CAAC;YACD,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;gBACtB,OAAO,IAAI,MAAM,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;YAC/F,CAAC;YACD,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;gBACtB,OAAO,aAAa,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;YACvC,CAAC;YACD,oDAAoD;YACpD,OAAO,GAAG,KAAK,aAAa,CAAC;QAC/B,CAAC,CAAC,CACH,CAAC;AACJ,CAAC","sourcesContent":["import type { PackageExports } from '../PackageJson.ts';\n\n/**\n * Determine whether `importSubPath` might satisfy any sub-path from the exports map,\n * disregarding conditions and file existence.\n * @param importSubPath Sub-path such as `lib/foo`\n */\nexport function pathSatisfiesAnyExport(exportsMap: PackageExports | undefined, importSubPath: string): boolean {\n // If the exports map is a string, it's a shorthand for a single export.\n // If it's an array, the contents are fallbacks for a single export.\n if (!exportsMap || typeof exportsMap === 'string' || Array.isArray(exportsMap)) {\n return false;\n }\n\n importSubPath = `./${importSubPath}`;\n\n return (\n // Check for very basic exclusions. (Technically a path could also be excluded by setting\n // a condition to null, or by setting a later wildcard to override an earlier one.\n // Handling for this can be added later if needed.)\n (exportsMap as Record<string, unknown>)[importSubPath] !== null &&\n Object.keys(exportsMap).some((key) => {\n // . is the root import, not a sub-path.\n // Starting character other than . means this is a condition, not a path.\n if (key === '.' || key[0] !== '.') {\n return false;\n }\n if (key.includes('*')) {\n return new RegExp(`^${key.replace(/\\./g, '\\\\.').replace(/\\*/g, '.*')}$`).test(importSubPath);\n }\n if (key.endsWith('/')) {\n return importSubPath.startsWith(key);\n }\n // Check if the path is a literal match for this key\n return key === importSubPath;\n })\n );\n}\n"]}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Resolve the root directory of `packageName` starting from `fromDir`, with caching.
3
+ * This uses the basic `resolve` package (which doesn't respect exports maps) to resolve
4
+ * `${packageName}/package.json`, which should always exist.
5
+ */
6
+ export declare function resolvePackageRoot(fromDir: string, packageName: string, debug: boolean): string | null;
7
+ //# sourceMappingURL=resolvePackageRoot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolvePackageRoot.d.ts","sourceRoot":"","sources":["../../../src/utils/unsupportedImports/resolvePackageRoot.ts"],"names":[],"mappings":"AAgBA;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAyBtG"}
@@ -0,0 +1,45 @@
1
+ import path from 'path';
2
+ import _resolve from 'resolve';
3
+ // 'resolve' index.js looks like this:
4
+ // var async = require('./lib/async');
5
+ // async.sync = require('./lib/sync');
6
+ // module.exports = async;
7
+ // This does not play nicely with at least one transpilation or interop step, possibly on specific
8
+ // Node versions: `import * as resolve` *usually* gives the `resolve` function, but sometimes it
9
+ // gives an object with property `default`... This is a workaround for either case.
10
+ // eslint-disable-next-line
11
+ const resolveSync = _resolve.sync || _resolve.default?.sync;
12
+ const getCacheKey = (fromDir, packageName) => `${fromDir}::${packageName}`;
13
+ const resolveCache = new Map();
14
+ /**
15
+ * Resolve the root directory of `packageName` starting from `fromDir`, with caching.
16
+ * This uses the basic `resolve` package (which doesn't respect exports maps) to resolve
17
+ * `${packageName}/package.json`, which should always exist.
18
+ */
19
+ export function resolvePackageRoot(fromDir, packageName, debug) {
20
+ const cacheKey = getCacheKey(fromDir, packageName);
21
+ const cached = resolveCache.get(cacheKey);
22
+ if (cached !== undefined) {
23
+ return cached;
24
+ }
25
+ const resolvePath = `${packageName}/package.json`;
26
+ let resolved = null;
27
+ try {
28
+ resolved = path.dirname(resolveSync(resolvePath, { basedir: fromDir, preserveSymlinks: false }));
29
+ }
30
+ catch (err) {
31
+ if (debug) {
32
+ // eslint-disable-next-line
33
+ if (err?.code === 'MODULE_NOT_FOUND') {
34
+ console.error(`Failed to resolve ${resolvePath} from ${fromDir} (module not found)`);
35
+ }
36
+ else {
37
+ console.error(`Failed to resolve ${resolvePath} from ${fromDir}: ${err.message || err}`);
38
+ }
39
+ }
40
+ }
41
+ // Cache even if resolution failed so we don't waste time trying again
42
+ resolveCache.set(cacheKey, resolved);
43
+ return resolved;
44
+ }
45
+ //# sourceMappingURL=resolvePackageRoot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolvePackageRoot.js","sourceRoot":"","sources":["../../../src/utils/unsupportedImports/resolvePackageRoot.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,QAAQ,MAAM,SAAS,CAAC;AAE/B,sCAAsC;AACtC,0CAA0C;AAC1C,0CAA0C;AAC1C,8BAA8B;AAC9B,kGAAkG;AAClG,gGAAgG;AAChG,mFAAmF;AACnF,2BAA2B;AAC3B,MAAM,WAAW,GAAyB,QAAQ,CAAC,IAAI,IAAK,QAAgB,CAAC,OAAO,EAAE,IAAI,CAAC;AAE3F,MAAM,WAAW,GAAG,CAAC,OAAe,EAAE,WAAmB,EAAU,EAAE,CAAC,GAAG,OAAO,KAAK,WAAW,EAAE,CAAC;AACnG,MAAM,YAAY,GAAG,IAAI,GAAG,EAAyB,CAAC;AAEtD;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAe,EAAE,WAAmB,EAAE,KAAc;IACrF,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IACnD,MAAM,MAAM,GAAG,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC1C,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,WAAW,GAAG,GAAG,WAAW,eAAe,CAAC;IAClD,IAAI,QAAQ,GAAkB,IAAI,CAAC;IACnC,IAAI,CAAC;QACH,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,WAAW,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;IACnG,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,KAAK,EAAE,CAAC;YACV,2BAA2B;YAC3B,IAAK,GAAW,EAAE,IAAI,KAAK,kBAAkB,EAAE,CAAC;gBAC9C,OAAO,CAAC,KAAK,CAAC,qBAAqB,WAAW,SAAS,OAAO,qBAAqB,CAAC,CAAC;YACvF,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,KAAK,CAAC,qBAAqB,WAAW,SAAS,OAAO,KAAM,GAAa,CAAC,OAAO,IAAI,GAAG,EAAE,CAAC,CAAC;YACtG,CAAC;QACH,CAAC;IACH,CAAC;IAED,sEAAsE;IACtE,YAAY,CAAC,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACrC,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import path from 'path';\nimport _resolve from 'resolve';\n\n// 'resolve' index.js looks like this:\n// var async = require('./lib/async');\n// async.sync = require('./lib/sync');\n// module.exports = async;\n// This does not play nicely with at least one transpilation or interop step, possibly on specific\n// Node versions: `import * as resolve` *usually* gives the `resolve` function, but sometimes it\n// gives an object with property `default`... This is a workaround for either case.\n// eslint-disable-next-line\nconst resolveSync: typeof _resolve.sync = _resolve.sync || (_resolve as any).default?.sync;\n\nconst getCacheKey = (fromDir: string, packageName: string): string => `${fromDir}::${packageName}`;\nconst resolveCache = new Map<string, string | null>();\n\n/**\n * Resolve the root directory of `packageName` starting from `fromDir`, with caching.\n * This uses the basic `resolve` package (which doesn't respect exports maps) to resolve\n * `${packageName}/package.json`, which should always exist.\n */\nexport function resolvePackageRoot(fromDir: string, packageName: string, debug: boolean): string | null {\n const cacheKey = getCacheKey(fromDir, packageName);\n const cached = resolveCache.get(cacheKey);\n if (cached !== undefined) {\n return cached;\n }\n\n const resolvePath = `${packageName}/package.json`;\n let resolved: string | null = null;\n try {\n resolved = path.dirname(resolveSync(resolvePath, { basedir: fromDir, preserveSymlinks: false }));\n } catch (err) {\n if (debug) {\n // eslint-disable-next-line\n if ((err as any)?.code === 'MODULE_NOT_FOUND') {\n console.error(`Failed to resolve ${resolvePath} from ${fromDir} (module not found)`);\n } else {\n console.error(`Failed to resolve ${resolvePath} from ${fromDir}: ${(err as Error).message || err}`);\n }\n }\n }\n\n // Cache even if resolution failed so we don't waste time trying again\n resolveCache.set(cacheKey, resolved);\n return resolved;\n}\n"]}
package/package.json CHANGED
@@ -1,10 +1,16 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/eslint-plugin",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "A set of ESLint rules for Cloudpack",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
- "exports": "./src/index.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./lib/index.d.ts",
10
+ "import": "./lib/index.js"
11
+ }
12
+ },
13
+ "publishConfig": {},
8
14
  "engines": {
9
15
  "node": ">=22.18.0"
10
16
  },
@@ -22,7 +28,7 @@
22
28
  },
23
29
  "peerDependencies": {
24
30
  "@rnx-kit/eslint-plugin": "^0.9.9",
25
- "eslint": "^8.0.0 || ^9.0.0 || ^10.0.0",
31
+ "eslint": "^9.0.0 || ^10.0.0",
26
32
  "typescript": ">=5.0.0",
27
33
  "typescript-eslint": "^8.0.0"
28
34
  },
@@ -43,5 +49,6 @@
43
49
  },
44
50
  "files": [
45
51
  "lib/**/!(*.test.*)"
46
- ]
52
+ ],
53
+ "types": "./lib/index.d.ts"
47
54
  }