@ms-cloudpack/eslint-plugin 0.6.1 → 0.7.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/README.md +47 -52
- package/package.json +12 -21
- package/lib/configs/classic.d.ts +0 -9
- package/lib/configs/classic.d.ts.map +0 -1
- package/lib/configs/classic.js +0 -32
- package/lib/configs/classic.js.map +0 -1
- package/lib/configs/flat.d.ts +0 -4
- package/lib/configs/flat.d.ts.map +0 -1
- package/lib/configs/flat.js +0 -24
- package/lib/configs/flat.js.map +0 -1
- package/lib/flat.d.mts +0 -12
- package/lib/flat.d.mts.map +0 -1
- package/lib/flat.mjs +0 -8
- package/lib/flat.mjs.map +0 -1
- package/lib/index.d.ts +0 -13
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -10
- package/lib/index.js.map +0 -1
- package/lib/plugin.d.ts +0 -6
- package/lib/plugin.d.ts.map +0 -1
- package/lib/plugin.js +0 -19
- package/lib/plugin.js.map +0 -1
- package/lib/rules/no-test-exports.d.ts +0 -18
- package/lib/rules/no-test-exports.d.ts.map +0 -1
- package/lib/rules/no-test-exports.js +0 -133
- package/lib/rules/no-test-exports.js.map +0 -1
- package/lib/rules/no-unsupported-imports.d.ts +0 -14
- package/lib/rules/no-unsupported-imports.d.ts.map +0 -1
- package/lib/rules/no-unsupported-imports.js +0 -174
- package/lib/rules/no-unsupported-imports.js.map +0 -1
- package/lib/utils/PackageJson.d.ts +0 -43
- package/lib/utils/PackageJson.d.ts.map +0 -1
- package/lib/utils/PackageJson.js +0 -4
- package/lib/utils/PackageJson.js.map +0 -1
- package/lib/utils/createRule.d.ts +0 -41
- package/lib/utils/createRule.d.ts.map +0 -1
- package/lib/utils/createRule.js +0 -32
- package/lib/utils/createRule.js.map +0 -1
- package/lib/utils/getImportPathLiteralNode.d.ts +0 -11
- package/lib/utils/getImportPathLiteralNode.d.ts.map +0 -1
- package/lib/utils/getImportPathLiteralNode.js +0 -44
- package/lib/utils/getImportPathLiteralNode.js.map +0 -1
- package/lib/utils/getPackageInfo.d.ts +0 -16
- package/lib/utils/getPackageInfo.d.ts.map +0 -1
- package/lib/utils/getPackageInfo.js +0 -60
- package/lib/utils/getPackageInfo.js.map +0 -1
- package/lib/utils/getRegexpsFromStrings.d.ts +0 -6
- package/lib/utils/getRegexpsFromStrings.d.ts.map +0 -1
- package/lib/utils/getRegexpsFromStrings.js +0 -11
- package/lib/utils/getRegexpsFromStrings.js.map +0 -1
- package/lib/utils/testExports/extractIdentifiersFromExport.d.ts +0 -6
- package/lib/utils/testExports/extractIdentifiersFromExport.d.ts.map +0 -1
- package/lib/utils/testExports/extractIdentifiersFromExport.js +0 -57
- package/lib/utils/testExports/extractIdentifiersFromExport.js.map +0 -1
- package/lib/utils/testExports/isIncludedIndexFile.d.ts +0 -10
- package/lib/utils/testExports/isIncludedIndexFile.d.ts.map +0 -1
- package/lib/utils/testExports/isIncludedIndexFile.js +0 -27
- package/lib/utils/testExports/isIncludedIndexFile.js.map +0 -1
- package/lib/utils/unsupportedImports/parseImportIfRelevant.d.ts +0 -19
- package/lib/utils/unsupportedImports/parseImportIfRelevant.d.ts.map +0 -1
- package/lib/utils/unsupportedImports/parseImportIfRelevant.js +0 -39
- package/lib/utils/unsupportedImports/parseImportIfRelevant.js.map +0 -1
- package/lib/utils/unsupportedImports/pathSatisfiesAnyExport.d.ts +0 -8
- package/lib/utils/unsupportedImports/pathSatisfiesAnyExport.d.ts.map +0 -1
- package/lib/utils/unsupportedImports/pathSatisfiesAnyExport.js +0 -37
- package/lib/utils/unsupportedImports/pathSatisfiesAnyExport.js.map +0 -1
- package/lib/utils/unsupportedImports/resolvePackageRoot.d.ts +0 -7
- package/lib/utils/unsupportedImports/resolvePackageRoot.d.ts.map +0 -1
- package/lib/utils/unsupportedImports/resolvePackageRoot.js +0 -48
- package/lib/utils/unsupportedImports/resolvePackageRoot.js.map +0 -1
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.rule = void 0;
|
|
4
|
-
const getImportPathLiteralNode_1 = require("../utils/getImportPathLiteralNode");
|
|
5
|
-
const getPackageInfo_1 = require("../utils/getPackageInfo");
|
|
6
|
-
const parseImportIfRelevant_1 = require("../utils/unsupportedImports/parseImportIfRelevant");
|
|
7
|
-
const pathSatisfiesAnyExport_1 = require("../utils/unsupportedImports/pathSatisfiesAnyExport");
|
|
8
|
-
const resolvePackageRoot_1 = require("../utils/unsupportedImports/resolvePackageRoot");
|
|
9
|
-
const getRegexpsFromStrings_1 = require("../utils/getRegexpsFromStrings");
|
|
10
|
-
const createRule_1 = require("../utils/createRule");
|
|
11
|
-
const preferTopLevel = 'prefer importing directly from "{{packageName}}" if possible';
|
|
12
|
-
const noExports = '"{{packageName}}" doesn\'t have an exports map, so deep imports aren\'t allowed; ' + preferTopLevel;
|
|
13
|
-
const notExported = 'Path "{{subPath}}" is not exported by "{{packageName}}", according to its exports map; ' + preferTopLevel;
|
|
14
|
-
const localMessage = '(Consider updating "{{packageName}}" to export additional identifiers if needed, ' +
|
|
15
|
-
'or if deep imports are strictly necessary, add an exports map.)';
|
|
16
|
-
exports.rule = (0, createRule_1.createRule)({
|
|
17
|
-
name: 'no-unsupported-imports',
|
|
18
|
-
meta: {
|
|
19
|
-
type: 'problem',
|
|
20
|
-
docs: {
|
|
21
|
-
description: 'ban importing from non-exported paths',
|
|
22
|
-
},
|
|
23
|
-
hasSuggestions: true,
|
|
24
|
-
messages: {
|
|
25
|
-
noExports,
|
|
26
|
-
noExportsLocal: `${noExports}. ${localMessage}`,
|
|
27
|
-
notExported,
|
|
28
|
-
notExportedLocal: `${notExported}. ${localMessage}`,
|
|
29
|
-
useTopLevel: 'Import directly from "{{packageName}}", if possible',
|
|
30
|
-
},
|
|
31
|
-
schema: [
|
|
32
|
-
{
|
|
33
|
-
type: 'object',
|
|
34
|
-
properties: {
|
|
35
|
-
ignorePatterns: {
|
|
36
|
-
type: 'array',
|
|
37
|
-
description: 'Ignore imports matching these regular expression patterns.',
|
|
38
|
-
items: { type: 'string' },
|
|
39
|
-
},
|
|
40
|
-
debug: { type: 'boolean' },
|
|
41
|
-
},
|
|
42
|
-
additionalProperties: false,
|
|
43
|
-
},
|
|
44
|
-
],
|
|
45
|
-
},
|
|
46
|
-
create: (ruleContext) => {
|
|
47
|
-
const options = ruleContext.options?.[0] || {};
|
|
48
|
-
const context = {
|
|
49
|
-
ruleContext,
|
|
50
|
-
debug: options.debug ?? false,
|
|
51
|
-
ignorePatterns: (0, getRegexpsFromStrings_1.getRegexpsFromStrings)(options.ignorePatterns),
|
|
52
|
-
};
|
|
53
|
-
return {
|
|
54
|
-
// import foo from 'foo'
|
|
55
|
-
// import * as foo from 'foo'
|
|
56
|
-
// import { foo } from 'foo'
|
|
57
|
-
// import { foo as bar } from 'foo'
|
|
58
|
-
// import 'foo'
|
|
59
|
-
ImportDeclaration: (node) => checkImportOrExport(context, node),
|
|
60
|
-
// await import('foo')
|
|
61
|
-
ImportExpression: (node) => checkImportOrExport(context, node),
|
|
62
|
-
// import foo = require('foo')
|
|
63
|
-
TSImportEqualsDeclaration: (node) => {
|
|
64
|
-
// Skip "export import foo = require('foo')" because that will be handled by ExportNamedDeclaration
|
|
65
|
-
if (node.parent.type !== 'ExportNamedDeclaration') {
|
|
66
|
-
checkImportOrExport(context, node);
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
// export { foo } from 'foo'
|
|
70
|
-
// export { foo as bar } from 'foo'
|
|
71
|
-
ExportNamedDeclaration: (node) => checkImportOrExport(context, node),
|
|
72
|
-
// export * from 'foo'
|
|
73
|
-
// export * as foo from 'foo'
|
|
74
|
-
ExportAllDeclaration: (node) => checkImportOrExport(context, node),
|
|
75
|
-
// require('foo')
|
|
76
|
-
// require.resolve('foo')
|
|
77
|
-
CallExpression: (node) => checkImportOrExport(context, node),
|
|
78
|
-
};
|
|
79
|
-
},
|
|
80
|
-
});
|
|
81
|
-
function checkImportOrExport(context, node) {
|
|
82
|
-
const { ruleContext } = context;
|
|
83
|
-
const { importPath, pathNode } = (0, getImportPathLiteralNode_1.getImportPathLiteralNode)(node) || {};
|
|
84
|
-
if (!(pathNode && importPath)) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
const errorData = checkImportPath(context, importPath);
|
|
88
|
-
if (!errorData) {
|
|
89
|
-
return; // Import is fine
|
|
90
|
-
}
|
|
91
|
-
// At this point, the import is probably invalid, so report it.
|
|
92
|
-
// (Might still be a false positive if it's a local package that hasn't been built yet.)
|
|
93
|
-
const { messageId, data } = errorData;
|
|
94
|
-
// For named imports/exports or import *, suggest importing from the package root.
|
|
95
|
-
// This is just a suggestion, so it doesn't have to be correct, but we also want to avoid
|
|
96
|
-
// suggesting when it's likely to be misleading or might cause issues; for example:
|
|
97
|
-
// - Default imports may refer to an actual default export or the entire module
|
|
98
|
-
// - Side effect imports are likely specific to a particular file
|
|
99
|
-
// - Async import()
|
|
100
|
-
// - export * from an entire package might export a lot more things
|
|
101
|
-
// - require() could be used in many ways (would have to look at more context)
|
|
102
|
-
// - require.resolve() is typically used to find the path to a specific file
|
|
103
|
-
let suggestion;
|
|
104
|
-
if (
|
|
105
|
-
// import { foo } from 'foo/bar'
|
|
106
|
-
(node.type === 'ImportDeclaration' && node.specifiers[0]?.type === 'ImportSpecifier') ||
|
|
107
|
-
// import * as foo from 'foo/bar'
|
|
108
|
-
(node.type === 'ImportDeclaration' && node.specifiers[0]?.type === 'ImportNamespaceSpecifier') ||
|
|
109
|
-
// import foo = require('foo/bar')
|
|
110
|
-
node.type === 'TSImportEqualsDeclaration' ||
|
|
111
|
-
// export { foo } from 'foo/bar'
|
|
112
|
-
node.type === 'ExportNamedDeclaration') {
|
|
113
|
-
suggestion = {
|
|
114
|
-
messageId: 'useTopLevel',
|
|
115
|
-
data,
|
|
116
|
-
fix: (fixer) => fixer.replaceTextRange(
|
|
117
|
-
// Keep the quotes
|
|
118
|
-
[pathNode.range[0] + 1, pathNode.range[1] - 1], data.packageName),
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
ruleContext.report({
|
|
122
|
-
node: pathNode,
|
|
123
|
-
messageId,
|
|
124
|
-
data,
|
|
125
|
-
suggest: suggestion ? [suggestion] : undefined,
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
function checkImportPath(context, importPath) {
|
|
129
|
-
const { ignorePatterns, debug, ruleContext } = context;
|
|
130
|
-
const importParts = (0, parseImportIfRelevant_1.parseImportIfRelevant)(importPath, ignorePatterns);
|
|
131
|
-
if (!importParts) {
|
|
132
|
-
// Import is relative, top-level, built-in, or ignored
|
|
133
|
-
return null;
|
|
134
|
-
}
|
|
135
|
-
const { packageName, subPath } = importParts;
|
|
136
|
-
// Find the root of the current file's package and read its package.json
|
|
137
|
-
const currentPkg = (0, getPackageInfo_1.getPackageInfo)(ruleContext.filename, debug);
|
|
138
|
-
if (!currentPkg || currentPkg.json.name === packageName) {
|
|
139
|
-
// - If package.json for the current file's package wasn't found, ignore the import
|
|
140
|
-
// (getPackageInfo already logged a debug message about it)
|
|
141
|
-
// - If the import is a self-reference, ignore it
|
|
142
|
-
return null;
|
|
143
|
-
}
|
|
144
|
-
// Resolve packageName's top-level import so we can find the package.json.
|
|
145
|
-
// (This resolution must be done in the context of the current package in case eslint is running
|
|
146
|
-
// in a different directory, e.g. monorepo root, where the package may not be installed or a
|
|
147
|
-
// different version may be installed.)
|
|
148
|
-
const resolvedPkgRoot = (0, resolvePackageRoot_1.resolvePackageRoot)(currentPkg.path, packageName, debug);
|
|
149
|
-
if (!resolvedPkgRoot) {
|
|
150
|
-
// Maybe an optional dep?
|
|
151
|
-
return null;
|
|
152
|
-
}
|
|
153
|
-
// Read packageName's package.json
|
|
154
|
-
const importPkg = (0, getPackageInfo_1.getPackageInfo)(resolvedPkgRoot, debug);
|
|
155
|
-
if (!importPkg) {
|
|
156
|
-
return null;
|
|
157
|
-
}
|
|
158
|
-
if (!importPkg.json.exports) {
|
|
159
|
-
// Deep imports are always an error if there's no exports map
|
|
160
|
-
return {
|
|
161
|
-
messageId: importPkg.isLocal ? 'noExportsLocal' : 'noExports',
|
|
162
|
-
data: { subPath, packageName },
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
// Check if subPath matches any paths from exports (disregarding conditions)
|
|
166
|
-
if (!(0, pathSatisfiesAnyExport_1.pathSatisfiesAnyExport)(importPkg.json.exports, subPath)) {
|
|
167
|
-
return {
|
|
168
|
-
messageId: importPkg.isLocal ? 'notExportedLocal' : 'notExported',
|
|
169
|
-
data: { subPath, packageName },
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
return null;
|
|
173
|
-
}
|
|
174
|
-
//# sourceMappingURL=no-unsupported-imports.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"no-unsupported-imports.js","sourceRoot":"","sources":["../../src/rules/no-unsupported-imports.ts"],"names":[],"mappings":";;;AAAA,gFAAkG;AAClG,4DAAyD;AACzD,6FAA0F;AAC1F,+FAA4F;AAC5F,uFAAoF;AACpF,0EAAuE;AACvE,oDAAqH;AA2BrH,MAAM,cAAc,GAAG,8DAA8D,CAAC;AACtF,MAAM,SAAS,GAAG,mFAAmF,GAAG,cAAc,CAAC;AACvH,MAAM,WAAW,GACf,yFAAyF,GAAG,cAAc,CAAC;AAC7G,MAAM,YAAY,GAChB,mFAAmF;IACnF,iEAAiE,CAAC;AAEvD,QAAA,IAAI,GAAG,IAAA,uBAAU,EAAqC;IACjE,IAAI,EAAE,wBAAwB;IAC9B,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EAAE,uCAAuC;SACrD;QACD,cAAc,EAAE,IAAI;QACpB,QAAQ,EAAE;YACR,SAAS;YACT,cAAc,EAAE,GAAG,SAAS,KAAK,YAAY,EAAE;YAC/C,WAAW;YACX,gBAAgB,EAAE,GAAG,WAAW,KAAK,YAAY,EAA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GAAgG;IAChG,4FAA4F;IAC5F,uCAAuC;IACvC,MAAM,eAAe,GAAG,IAAA,uCAAkB,EAAC,UAAU,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;IAChF,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,yBAAyB;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,kCAAkC;IAClC,MAAM,SAAS,GAAG,IAAA,+BAAc,EAAC,eAAe,EAAE,KAAK,CAAC,CAAC;IACzD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QAC5B,6DAA6D;QAC7D,OAAO;YACL,SAAS,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,WAAW;YAC7D,IAAI,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE;SAC/B,CAAC;IACJ,CAAC;IAED,4EAA4E;IAC5E,IAAI,CAAC,IAAA,+CAAsB,EAAC,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC;QAC7D,OAAO;YACL,SAAS,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,aAAa;YACjE,IAAI,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE;SAC/B,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { getImportPathLiteralNode, type ImportLikeNode } from '../utils/getImportPathLiteralNode';\nimport { getPackageInfo } from '../utils/getPackageInfo';\nimport { parseImportIfRelevant } from '../utils/unsupportedImports/parseImportIfRelevant';\nimport { pathSatisfiesAnyExport } from '../utils/unsupportedImports/pathSatisfiesAnyExport';\nimport { resolvePackageRoot } from '../utils/unsupportedImports/resolvePackageRoot';\nimport { getRegexpsFromStrings } from '../utils/getRegexpsFromStrings';\nimport { createRule, type SuggestionDescriptor, type RuleContext, type ReportDescriptor } from '../utils/createRule';\n\n/** Rule options as specified in the config */\nexport type RuleOptions = {\n ignorePatterns?: string[];\n debug?: boolean;\n};\n\ntype Context = {\n /** Original rule context */\n ruleContext: RuleContext<RuleOptions, MessageIds, ErrorData>;\n /** Processed ignore patterns */\n ignorePatterns: RegExp[];\n debug: boolean;\n};\n\nexport type ErrorMessageIds = 'noExports' | 'noExportsLocal' | 'notExported' | 'notExportedLocal';\nexport type SuggestMessageIds = 'useTopLevel';\nexport type MessageIds = ErrorMessageIds | SuggestMessageIds;\n\nexport type ErrorData = {\n packageName: string;\n subPath?: string;\n};\n\ntype ErrorResult = Pick<ReportDescriptor<ErrorMessageIds, ErrorData>, 'messageId' | 'data'>;\n\nconst preferTopLevel = 'prefer importing directly from \"{{packageName}}\" if possible';\nconst noExports = '\"{{packageName}}\" doesn\\'t have an exports map, so deep imports aren\\'t allowed; ' + preferTopLevel;\nconst notExported =\n 'Path \"{{subPath}}\" is not exported by \"{{packageName}}\", according to its exports map; ' + preferTopLevel;\nconst localMessage =\n '(Consider updating \"{{packageName}}\" to export additional identifiers if needed, ' +\n 'or if deep imports are strictly necessary, add an exports map.)';\n\nexport const rule = createRule<RuleOptions, MessageIds, ErrorData>({\n name: 'no-unsupported-imports',\n meta: {\n type: 'problem',\n docs: {\n description: 'ban importing from non-exported paths',\n },\n hasSuggestions: true,\n messages: {\n noExports,\n noExportsLocal: `${noExports}. ${localMessage}`,\n notExported,\n notExportedLocal: `${notExported}. ${localMessage}`,\n useTopLevel: 'Import directly from \"{{packageName}}\", if possible',\n },\n schema: [\n {\n type: 'object',\n properties: {\n ignorePatterns: {\n type: 'array',\n description: 'Ignore imports matching these regular expression patterns.',\n items: { type: 'string' },\n },\n debug: { type: 'boolean' },\n },\n additionalProperties: false,\n },\n ],\n },\n create: (ruleContext) => {\n const options = ruleContext.options?.[0] || {};\n const context: Context = {\n ruleContext,\n debug: options.debug ?? false,\n ignorePatterns: getRegexpsFromStrings(options.ignorePatterns),\n };\n\n return {\n // import foo from 'foo'\n // import * as foo from 'foo'\n // import { foo } from 'foo'\n // import { foo as bar } from 'foo'\n // import 'foo'\n ImportDeclaration: (node) => checkImportOrExport(context, node),\n // await import('foo')\n ImportExpression: (node) => checkImportOrExport(context, node),\n // import foo = require('foo')\n TSImportEqualsDeclaration: (node) => {\n // Skip \"export import foo = require('foo')\" because that will be handled by ExportNamedDeclaration\n if (node.parent.type !== 'ExportNamedDeclaration') {\n checkImportOrExport(context, node);\n }\n },\n // export { foo } from 'foo'\n // export { foo as bar } from 'foo'\n ExportNamedDeclaration: (node) => checkImportOrExport(context, node),\n // export * from 'foo'\n // export * as foo from 'foo'\n ExportAllDeclaration: (node) => checkImportOrExport(context, node),\n // require('foo')\n // require.resolve('foo')\n CallExpression: (node) => checkImportOrExport(context, node),\n };\n },\n});\n\nfunction checkImportOrExport(context: Context, node: ImportLikeNode): void {\n const { ruleContext } = context;\n\n const { importPath, pathNode } = getImportPathLiteralNode(node) || {};\n if (!(pathNode && importPath)) {\n return;\n }\n\n const errorData = checkImportPath(context, importPath);\n if (!errorData) {\n return; // Import is fine\n }\n\n // At this point, the import is probably invalid, so report it.\n // (Might still be a false positive if it's a local package that hasn't been built yet.)\n const { messageId, data } = errorData;\n\n // For named imports/exports or import *, suggest importing from the package root.\n // This is just a suggestion, so it doesn't have to be correct, but we also want to avoid\n // suggesting when it's likely to be misleading or might cause issues; for example:\n // - Default imports may refer to an actual default export or the entire module\n // - Side effect imports are likely specific to a particular file\n // - Async import()\n // - export * from an entire package might export a lot more things\n // - require() could be used in many ways (would have to look at more context)\n // - require.resolve() is typically used to find the path to a specific file\n let suggestion: SuggestionDescriptor<SuggestMessageIds, ErrorData> | undefined;\n if (\n // import { foo } from 'foo/bar'\n (node.type === 'ImportDeclaration' && node.specifiers[0]?.type === 'ImportSpecifier') ||\n // import * as foo from 'foo/bar'\n (node.type === 'ImportDeclaration' && node.specifiers[0]?.type === 'ImportNamespaceSpecifier') ||\n // import foo = require('foo/bar')\n node.type === 'TSImportEqualsDeclaration' ||\n // export { foo } from 'foo/bar'\n node.type === 'ExportNamedDeclaration'\n ) {\n suggestion = {\n messageId: 'useTopLevel',\n data,\n fix: (fixer) =>\n fixer.replaceTextRange(\n // Keep the quotes\n [pathNode.range[0] + 1, pathNode.range[1] - 1],\n data.packageName,\n ),\n };\n }\n\n ruleContext.report({\n node: pathNode,\n messageId,\n data,\n suggest: suggestion ? [suggestion] : undefined,\n });\n}\n\nfunction checkImportPath(context: Context, importPath: string): ErrorResult | null {\n const { ignorePatterns, debug, ruleContext } = context;\n\n const importParts = parseImportIfRelevant(importPath, ignorePatterns);\n if (!importParts) {\n // Import is relative, top-level, built-in, or ignored\n return null;\n }\n const { packageName, subPath } = importParts;\n\n // Find the root of the current file's package and read its package.json\n const currentPkg = getPackageInfo(ruleContext.filename, debug);\n if (!currentPkg || currentPkg.json.name === packageName) {\n // - If package.json for the current file's package wasn't found, ignore the import\n // (getPackageInfo already logged a debug message about it)\n // - If the import is a self-reference, ignore it\n return null;\n }\n\n // Resolve packageName's top-level import so we can find the package.json.\n // (This resolution must be done in the context of the current package in case eslint is running\n // in a different directory, e.g. monorepo root, where the package may not be installed or a\n // different version may be installed.)\n const resolvedPkgRoot = resolvePackageRoot(currentPkg.path, packageName, debug);\n if (!resolvedPkgRoot) {\n // Maybe an optional dep?\n return null;\n }\n\n // Read packageName's package.json\n const importPkg = getPackageInfo(resolvedPkgRoot, debug);\n if (!importPkg) {\n return null;\n }\n\n if (!importPkg.json.exports) {\n // Deep imports are always an error if there's no exports map\n return {\n messageId: importPkg.isLocal ? 'noExportsLocal' : 'noExports',\n data: { subPath, packageName },\n };\n }\n\n // Check if subPath matches any paths from exports (disregarding conditions)\n if (!pathSatisfiesAnyExport(importPkg.json.exports, subPath)) {\n return {\n messageId: importPkg.isLocal ? 'notExportedLocal' : 'notExported',\n data: { subPath, packageName },\n };\n }\n return null;\n}\n"]}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
type PathLiteral = '.' | `./${string}`;
|
|
2
|
-
/**
|
|
3
|
-
* The module path that is resolved when this specifier is imported.
|
|
4
|
-
* Set to `null` to disallow importing this module.
|
|
5
|
-
*/
|
|
6
|
-
type PackageExportsEntryPath = PathLiteral | null;
|
|
7
|
-
type PackageExportsEntry = PackageExportsEntryPath | PackageExportsConditionsObject;
|
|
8
|
-
/**
|
|
9
|
-
* Used to allow fallbacks in case this environment doesn't support the preceding entries.
|
|
10
|
-
* Fallbacks are not supported by all implementations.
|
|
11
|
-
*/
|
|
12
|
-
type PackageExportsFallback = PackageExportsEntry[];
|
|
13
|
-
type PackageExportsEntryOrFallback = PackageExportsEntry | PackageExportsFallback;
|
|
14
|
-
/** Used to specify conditional exports */
|
|
15
|
-
type PackageExportsConditionsObject = {
|
|
16
|
-
[condition: string]: PackageExportsEntryOrFallback;
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Each key is the module path that is resolved when the module specifier starts with "name/".
|
|
20
|
-
* Special case: `"."` defines the primary entry point (shadows the `main` field).
|
|
21
|
-
* The key `"./*"` allows external modules to import any subpath (not recommended).
|
|
22
|
-
*/
|
|
23
|
-
type PackageExportsPathsObject = {
|
|
24
|
-
[path in PathLiteral]?: PackageExportsEntryOrFallback;
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* The `exports` field allows defining the entry points of a package.
|
|
28
|
-
* - If a single string: load this module when the package name is imported
|
|
29
|
-
* (shadows the `main` field)
|
|
30
|
-
* - If an array: load the first one that exists (fallbacks are not supported by all implementations)
|
|
31
|
-
* - If an object where *all* keys start with `.`: see `PackageExportsPathsObject`
|
|
32
|
-
* - If an object where *no* keys start with `.`: see `PackageExportsConditionsObject`
|
|
33
|
-
* - Objects mixing paths and conditions are not valid
|
|
34
|
-
*/
|
|
35
|
-
export type PackageExports = PackageExportsEntryPath | PackageExportsPathsObject | PackageExportsConditionsObject | PackageExportsFallback;
|
|
36
|
-
/** Relevant package.json contents for checking the exports map */
|
|
37
|
-
export type PackageJson = {
|
|
38
|
-
name: string;
|
|
39
|
-
exports?: PackageExports;
|
|
40
|
-
[key: string]: unknown;
|
|
41
|
-
};
|
|
42
|
-
export {};
|
|
43
|
-
//# sourceMappingURL=PackageJson.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PackageJson.d.ts","sourceRoot":"","sources":["../../src/utils/PackageJson.ts"],"names":[],"mappings":"AAEA,KAAK,WAAW,GAAG,GAAG,GAAG,KAAK,MAAM,EAAE,CAAC;AAEvC;;;GAGG;AACH,KAAK,uBAAuB,GAAG,WAAW,GAAG,IAAI,CAAC;AAElD,KAAK,mBAAmB,GAAG,uBAAuB,GAAG,8BAA8B,CAAC;AAEpF;;;GAGG;AACH,KAAK,sBAAsB,GAAG,mBAAmB,EAAE,CAAC;AAEpD,KAAK,6BAA6B,GAAG,mBAAmB,GAAG,sBAAsB,CAAC;AAElF,0CAA0C;AAC1C,KAAK,8BAA8B,GAAG;IACpC,CAAC,SAAS,EAAE,MAAM,GAAG,6BAA6B,CAAC;CACpD,CAAC;AAEF;;;;GAIG;AACH,KAAK,yBAAyB,GAAG;KAC9B,IAAI,IAAI,WAAW,CAAC,CAAC,EAAE,6BAA6B;CACtD,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,cAAc,GACtB,uBAAuB,GACvB,yBAAyB,GACzB,8BAA8B,GAC9B,sBAAsB,CAAC;AAG3B,kEAAkE;AAClE,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC"}
|
package/lib/utils/PackageJson.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PackageJson.js","sourceRoot":"","sources":["../../src/utils/PackageJson.ts"],"names":[],"mappings":";AAAA,gHAAgH","sourcesContent":["// These types are more precisely based on the schema and should replace the ones in bundler-types in another PR\n\ntype PathLiteral = '.' | `./${string}`;\n\n/**\n * The module path that is resolved when this specifier is imported.\n * Set to `null` to disallow importing this module.\n */\ntype PackageExportsEntryPath = PathLiteral | null;\n\ntype PackageExportsEntry = PackageExportsEntryPath | PackageExportsConditionsObject;\n\n/**\n * Used to allow fallbacks in case this environment doesn't support the preceding entries.\n * Fallbacks are not supported by all implementations.\n */\ntype PackageExportsFallback = PackageExportsEntry[];\n\ntype PackageExportsEntryOrFallback = PackageExportsEntry | PackageExportsFallback;\n\n/** Used to specify conditional exports */\ntype PackageExportsConditionsObject = {\n [condition: string]: PackageExportsEntryOrFallback;\n};\n\n/**\n * Each key is the module path that is resolved when the module specifier starts with \"name/\".\n * Special case: `\".\"` defines the primary entry point (shadows the `main` field).\n * The key `\"./*\"` allows external modules to import any subpath (not recommended).\n */\ntype PackageExportsPathsObject = {\n [path in PathLiteral]?: PackageExportsEntryOrFallback;\n};\n\n/**\n * The `exports` field allows defining the entry points of a package.\n * - If a single string: load this module when the package name is imported\n * (shadows the `main` field)\n * - If an array: load the first one that exists (fallbacks are not supported by all implementations)\n * - If an object where *all* keys start with `.`: see `PackageExportsPathsObject`\n * - If an object where *no* keys start with `.`: see `PackageExportsConditionsObject`\n * - Objects mixing paths and conditions are not valid\n */\nexport type PackageExports =\n | PackageExportsEntryPath\n | PackageExportsPathsObject\n | PackageExportsConditionsObject\n | PackageExportsFallback;\n\n// this is a basic type which should not be copied elsewhere\n/** Relevant package.json contents for checking the exports map */\nexport type PackageJson = {\n name: string;\n exports?: PackageExports;\n [key: string]: unknown;\n};\n"]}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { ESLintUtils, TSESLint, TSESTree } from '@typescript-eslint/utils';
|
|
2
|
-
type Writable<T> = {
|
|
3
|
-
-readonly [K in keyof T]: T[K];
|
|
4
|
-
};
|
|
5
|
-
/**
|
|
6
|
-
* Problem report descriptor with strongly typed error and suggestion data.
|
|
7
|
-
* (This assumes all error/suggestion messages share a common data type.)
|
|
8
|
-
*/
|
|
9
|
-
export type ReportDescriptor<TMessageIds extends string, TErrorData> = Omit<Writable<TSESLint.ReportDescriptor<TMessageIds>>, 'data' | 'node' | 'suggest'> & {
|
|
10
|
-
data: TErrorData;
|
|
11
|
-
node: TSESTree.Node;
|
|
12
|
-
suggest?: SuggestionDescriptor<TMessageIds, TErrorData>[] | null;
|
|
13
|
-
};
|
|
14
|
-
/** Fix suggestion with strongly typed data. */
|
|
15
|
-
export type SuggestionDescriptor<TMessageIds extends string, TErrorData> = Omit<ReportDescriptor<TMessageIds, TErrorData>, 'suggest' | 'node'>;
|
|
16
|
-
/**
|
|
17
|
-
* Rule context with strongly typed `report`.
|
|
18
|
-
* (This assumes all error/suggestion messages share a common data type.)
|
|
19
|
-
*/
|
|
20
|
-
export type RuleContext<TOptions, TMessageIds extends string, TErrorData> = Omit<TSESLint.RuleContext<TMessageIds, TOptions[]>, 'report'> & {
|
|
21
|
-
report: (descriptor: ReportDescriptor<TMessageIds, TErrorData>) => void;
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* Rule info with better {@link RuleContext} type for the `create` function.
|
|
25
|
-
* (This assumes all error/suggestion messages share a common data type.)
|
|
26
|
-
*/
|
|
27
|
-
type CreateRuleOptions<TOptions, TMessageIds extends string, TErrorData> = Omit<ESLintUtils.RuleWithMetaAndName<TOptions[], TMessageIds>, 'create' | 'defaultOptions'> & {
|
|
28
|
-
create(this: void, context: Readonly<RuleContext<TOptions, TMessageIds, TErrorData>>): TSESLint.RuleListener;
|
|
29
|
-
};
|
|
30
|
-
/**
|
|
31
|
-
* This exported alias is just to avoid an error when exporting the `rule` returned from `createRule`
|
|
32
|
-
* ("the inferred type of 'rule' cannot be named without a reference to ...").
|
|
33
|
-
*/
|
|
34
|
-
export type RuleModule<TOptions, TMessageIds extends string> = ESLintUtils.RuleModule<TMessageIds, TOptions[]>;
|
|
35
|
-
/**
|
|
36
|
-
* Create a lint rule, with strongly typed data in `context.report`.
|
|
37
|
-
* (This assumes all error/suggestion messages share a common data type.)
|
|
38
|
-
*/
|
|
39
|
-
export declare function createRule<TOptions, TMessageIds extends string, TErrorData>(params: CreateRuleOptions<TOptions, TMessageIds, TErrorData>): RuleModule<TOptions, TMessageIds>;
|
|
40
|
-
export {};
|
|
41
|
-
//# sourceMappingURL=createRule.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createRule.d.ts","sourceRoot":"","sources":["../../src/utils/createRule.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEhF,KAAK,QAAQ,CAAC,CAAC,IAAI;IAAE,CAAC,UAAU,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC;AAEtD;;;GAGG;AACH,MAAM,MAAM,gBAAgB,CAAC,WAAW,SAAS,MAAM,EAAE,UAAU,IAAI,IAAI,CAEzE,QAAQ,CAAC,QAAQ,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,EAChD,MAAM,GAAG,MAAM,GAAG,SAAS,CAC5B,GAAG;IACF,IAAI,EAAE,UAAU,CAAC;IAEjB,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC;IACpB,OAAO,CAAC,EAAE,oBAAoB,CAAC,WAAW,EAAE,UAAU,CAAC,EAAE,GAAG,IAAI,CAAC;CAClE,CAAC;AAEF,+CAA+C;AAC/C,MAAM,MAAM,oBAAoB,CAAC,WAAW,SAAS,MAAM,EAAE,UAAU,IAAI,IAAI,CAC7E,gBAAgB,CAAC,WAAW,EAAE,UAAU,CAAC,EACzC,SAAS,GAAG,MAAM,CACnB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,WAAW,CAAC,QAAQ,EAAE,WAAW,SAAS,MAAM,EAAE,UAAU,IAAI,IAAI,CAC9E,QAAQ,CAAC,WAAW,CAAC,WAAW,EAAE,QAAQ,EAAE,CAAC,EAC7C,QAAQ,CACT,GAAG;IACF,MAAM,EAAE,CAAC,UAAU,EAAE,gBAAgB,CAAC,WAAW,EAAE,UAAU,CAAC,KAAK,IAAI,CAAC;CACzE,CAAC;AAEF;;;GAGG;AACH,KAAK,iBAAiB,CAAC,QAAQ,EAAE,WAAW,SAAS,MAAM,EAAE,UAAU,IAAI,IAAI,CAC7E,WAAW,CAAC,mBAAmB,CAAC,QAAQ,EAAE,EAAE,WAAW,CAAC,EAMxD,QAAQ,GAAG,gBAAgB,CAC5B,GAAG;IACF,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,WAAW,CAAC,QAAQ,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC,GAAG,QAAQ,CAAC,YAAY,CAAC;CAC9G,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,UAAU,CAAC,QAAQ,EAAE,WAAW,SAAS,MAAM,IAAI,WAAW,CAAC,UAAU,CAAC,WAAW,EAAE,QAAQ,EAAE,CAAC,CAAC;AAE/G;;;GAGG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,WAAW,SAAS,MAAM,EAAE,UAAU,EACzE,MAAM,EAAE,iBAAiB,CAAC,QAAQ,EAAE,WAAW,EAAE,UAAU,CAAC,GAC3D,UAAU,CAAC,QAAQ,EAAE,WAAW,CAAC,CAyBnC"}
|
package/lib/utils/createRule.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createRule = createRule;
|
|
4
|
-
/**
|
|
5
|
-
* Create a lint rule, with strongly typed data in `context.report`.
|
|
6
|
-
* (This assumes all error/suggestion messages share a common data type.)
|
|
7
|
-
*/
|
|
8
|
-
function createRule(params) {
|
|
9
|
-
return {
|
|
10
|
-
...params,
|
|
11
|
-
meta: {
|
|
12
|
-
...params.meta,
|
|
13
|
-
docs: {
|
|
14
|
-
...params.meta.docs,
|
|
15
|
-
url: `https://www.npmjs.com/package/@ms-cloudpack/eslint-plugin#${params.name}`,
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
defaultOptions: [],
|
|
19
|
-
create: (context) => {
|
|
20
|
-
const contextCopy = { ...context };
|
|
21
|
-
// Fill in properties that were added in eslint 8.40.0
|
|
22
|
-
/* eslint-disable etc/no-deprecated */
|
|
23
|
-
contextCopy.cwd ??= context.getCwd?.();
|
|
24
|
-
contextCopy.filename ??= context.getFilename?.();
|
|
25
|
-
contextCopy.physicalFilename ??= context.getPhysicalFilename?.();
|
|
26
|
-
contextCopy.sourceCode ??= context.getSourceCode?.();
|
|
27
|
-
/* eslint-enable etc/no-deprecated */
|
|
28
|
-
return params.create(contextCopy);
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=createRule.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createRule.js","sourceRoot":"","sources":["../../src/utils/createRule.ts"],"names":[],"mappings":";;AAiEA,gCA2BC;AA/BD;;;GAGG;AACH,SAAgB,UAAU,CACxB,MAA4D;IAE5D,OAAO;QACL,GAAG,MAAM;QACT,IAAI,EAAE;YACJ,GAAG,MAAM,CAAC,IAAI;YACd,IAAI,EAAE;gBACJ,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI;gBACnB,GAAG,EAAE,6DAA6D,MAAM,CAAC,IAAI,EAAE;aAChF;SACF;QACD,cAAc,EAAE,EAAE;QAClB,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE;YAClB,MAAM,WAAW,GAAG,EAAE,GAAG,OAAO,EAAE,CAAC;YAEnC,sDAAsD;YACtD,sCAAsC;YACtC,WAAW,CAAC,GAAG,KAAK,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;YACvC,WAAW,CAAC,QAAQ,KAAK,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;YACjD,WAAW,CAAC,gBAAgB,KAAK,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC;YACjE,WAAW,CAAC,UAAU,KAAK,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC;YACrD,qCAAqC;YAErC,OAAO,MAAM,CAAC,MAAM,CAAC,WAA6D,CAAC,CAAC;QACtF,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["//\n// This file contains wrappers for rule creation and related types.\n//\nimport type { ESLintUtils, TSESLint, TSESTree } from '@typescript-eslint/utils';\n\ntype Writable<T> = { -readonly [K in keyof T]: T[K] };\n\n/**\n * Problem report descriptor with strongly typed error and suggestion data.\n * (This assumes all error/suggestion messages share a common data type.)\n */\nexport type ReportDescriptor<TMessageIds extends string, TErrorData> = Omit<\n // Make the descriptor writable for convenience (like conditionally adding a fix)\n Writable<TSESLint.ReportDescriptor<TMessageIds>>,\n 'data' | 'node' | 'suggest'\n> & {\n data: TErrorData;\n // have to re-declare `node` due to an oddity with union types (built-in ReportDescriptor is a union) and omit\n node: TSESTree.Node;\n suggest?: SuggestionDescriptor<TMessageIds, TErrorData>[] | null;\n};\n\n/** Fix suggestion with strongly typed data. */\nexport type SuggestionDescriptor<TMessageIds extends string, TErrorData> = Omit<\n ReportDescriptor<TMessageIds, TErrorData>,\n 'suggest' | 'node'\n>;\n\n/**\n * Rule context with strongly typed `report`.\n * (This assumes all error/suggestion messages share a common data type.)\n */\nexport type RuleContext<TOptions, TMessageIds extends string, TErrorData> = Omit<\n TSESLint.RuleContext<TMessageIds, TOptions[]>,\n 'report'\n> & {\n report: (descriptor: ReportDescriptor<TMessageIds, TErrorData>) => void;\n};\n\n/**\n * Rule info with better {@link RuleContext} type for the `create` function.\n * (This assumes all error/suggestion messages share a common data type.)\n */\ntype CreateRuleOptions<TOptions, TMessageIds extends string, TErrorData> = Omit<\n ESLintUtils.RuleWithMetaAndName<TOptions[], TMessageIds>,\n // Why remove defaultOptions (array): typescript-eslint merges this array with the original\n // options array and passes the merged array as the second argument to `create`. However,\n // this isn't reflected in the types, and its behavior is kind of weird (an empty `defaultOptions`\n // array will cause the provided options to be ignored). So remove it from the types\n // and fill in a default value in `createRule` instead.\n 'create' | 'defaultOptions'\n> & {\n create(this: void, context: Readonly<RuleContext<TOptions, TMessageIds, TErrorData>>): TSESLint.RuleListener;\n};\n\n/**\n * This exported alias is just to avoid an error when exporting the `rule` returned from `createRule`\n * (\"the inferred type of 'rule' cannot be named without a reference to ...\").\n */\nexport type RuleModule<TOptions, TMessageIds extends string> = ESLintUtils.RuleModule<TMessageIds, TOptions[]>;\n\n/**\n * Create a lint rule, with strongly typed data in `context.report`.\n * (This assumes all error/suggestion messages share a common data type.)\n */\nexport function createRule<TOptions, TMessageIds extends string, TErrorData>(\n params: CreateRuleOptions<TOptions, TMessageIds, TErrorData>,\n): RuleModule<TOptions, TMessageIds> {\n return {\n ...params,\n meta: {\n ...params.meta,\n docs: {\n ...params.meta.docs,\n url: `https://www.npmjs.com/package/@ms-cloudpack/eslint-plugin#${params.name}`,\n },\n },\n defaultOptions: [],\n create: (context) => {\n const contextCopy = { ...context };\n\n // Fill in properties that were added in eslint 8.40.0\n /* eslint-disable etc/no-deprecated */\n contextCopy.cwd ??= context.getCwd?.();\n contextCopy.filename ??= context.getFilename?.();\n contextCopy.physicalFilename ??= context.getPhysicalFilename?.();\n contextCopy.sourceCode ??= context.getSourceCode?.();\n /* eslint-enable etc/no-deprecated */\n\n return params.create(contextCopy as RuleContext<TOptions, TMessageIds, TErrorData>);\n },\n };\n}\n"]}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { TSESTree } from '@typescript-eslint/utils';
|
|
2
|
-
export type ImportLikeNode = TSESTree.CallExpression | TSESTree.ExportAllDeclaration | TSESTree.ExportNamedDeclaration | TSESTree.ImportDeclaration | TSESTree.ImportExpression | TSESTree.TSImportEqualsDeclaration;
|
|
3
|
-
/**
|
|
4
|
-
* Verifies that the given node contains a string literal import path, and if so, returns the path node.
|
|
5
|
-
* (For `CallExpression` nodes, also verifies that the callee is `require` or `require.resolve`.)
|
|
6
|
-
*/
|
|
7
|
-
export declare function getImportPathLiteralNode(node: ImportLikeNode): {
|
|
8
|
-
pathNode: TSESTree.StringLiteral | TSESTree.TemplateLiteral;
|
|
9
|
-
importPath: string;
|
|
10
|
-
} | null;
|
|
11
|
-
//# sourceMappingURL=getImportPathLiteralNode.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getImportPathLiteralNode.d.ts","sourceRoot":"","sources":["../../src/utils/getImportPathLiteralNode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEzD,MAAM,MAAM,cAAc,GACtB,QAAQ,CAAC,cAAc,GACvB,QAAQ,CAAC,oBAAoB,GAC7B,QAAQ,CAAC,sBAAsB,GAC/B,QAAQ,CAAC,iBAAiB,GAC1B,QAAQ,CAAC,gBAAgB,GACzB,QAAQ,CAAC,yBAAyB,CAAC;AAEvC;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,cAAc,GACnB;IAAE,QAAQ,EAAE,QAAQ,CAAC,aAAa,GAAG,QAAQ,CAAC,eAAe,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAwC5F"}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getImportPathLiteralNode = getImportPathLiteralNode;
|
|
4
|
-
/**
|
|
5
|
-
* Verifies that the given node contains a string literal import path, and if so, returns the path node.
|
|
6
|
-
* (For `CallExpression` nodes, also verifies that the callee is `require` or `require.resolve`.)
|
|
7
|
-
*/
|
|
8
|
-
function getImportPathLiteralNode(node) {
|
|
9
|
-
let pathNode = null;
|
|
10
|
-
if (node.type === 'CallExpression') {
|
|
11
|
-
const isRequire = node.callee.type === 'Identifier' && node.callee.name === 'require';
|
|
12
|
-
const isRequireResolve = node.callee.type === 'MemberExpression' &&
|
|
13
|
-
node.callee.object.type === 'Identifier' &&
|
|
14
|
-
node.callee.object.name === 'require' &&
|
|
15
|
-
node.callee.property.type === 'Identifier' &&
|
|
16
|
-
node.callee.property.name === 'resolve';
|
|
17
|
-
if ((isRequire || isRequireResolve) && node.arguments.length === 1) {
|
|
18
|
-
pathNode = node.arguments[0];
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
else if (node.type === 'TSImportEqualsDeclaration') {
|
|
22
|
-
if (node.moduleReference.type === 'TSExternalModuleReference') {
|
|
23
|
-
// import foo = require('foo');
|
|
24
|
-
pathNode = node.moduleReference.expression;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
else if (node.type === 'ExportNamedDeclaration' &&
|
|
28
|
-
node.declaration?.type === 'TSImportEqualsDeclaration' &&
|
|
29
|
-
node.declaration.moduleReference.type === 'TSExternalModuleReference') {
|
|
30
|
-
// export import foo = require('foo');
|
|
31
|
-
pathNode = node.declaration.moduleReference.expression;
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
pathNode = node.source;
|
|
35
|
-
}
|
|
36
|
-
if (pathNode?.type === 'Literal' && typeof pathNode.value === 'string') {
|
|
37
|
-
return { pathNode, importPath: pathNode.value };
|
|
38
|
-
}
|
|
39
|
-
if (pathNode?.type === 'TemplateLiteral' && pathNode.expressions.length === 0 && pathNode.quasis.length === 1) {
|
|
40
|
-
return { pathNode, importPath: pathNode.quasis[0].value.cooked };
|
|
41
|
-
}
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
//# sourceMappingURL=getImportPathLiteralNode.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getImportPathLiteralNode.js","sourceRoot":"","sources":["../../src/utils/getImportPathLiteralNode.ts"],"names":[],"mappings":";;AAcA,4DA0CC;AA9CD;;;GAGG;AACH,SAAgB,wBAAwB,CACtC,IAA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,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC;IACzB,CAAC;IAED,IAAI,QAAQ,EAAE,IAAI,KAAK,SAAS,IAAI,OAAO,QAAQ,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;QACvE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC;IAClD,CAAC;IAED,IAAI,QAAQ,EAAE,IAAI,KAAK,iBAAiB,IAAI,QAAQ,CAAC,WAAW,CAAC,MAAM,KAAK,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC9G,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;IACnE,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import type { TSESTree } from '@typescript-eslint/utils';\n\nexport type ImportLikeNode =\n | TSESTree.CallExpression\n | TSESTree.ExportAllDeclaration\n | TSESTree.ExportNamedDeclaration\n | TSESTree.ImportDeclaration\n | TSESTree.ImportExpression\n | TSESTree.TSImportEqualsDeclaration;\n\n/**\n * Verifies that the given node contains a string literal import path, and if so, returns the path node.\n * (For `CallExpression` nodes, also verifies that the callee is `require` or `require.resolve`.)\n */\nexport function getImportPathLiteralNode(\n node: ImportLikeNode,\n): { pathNode: TSESTree.StringLiteral | TSESTree.TemplateLiteral; importPath: string } | null {\n let pathNode: TSESTree.Node | null = null;\n\n if (node.type === 'CallExpression') {\n const isRequire = node.callee.type === 'Identifier' && node.callee.name === 'require';\n const isRequireResolve =\n node.callee.type === 'MemberExpression' &&\n node.callee.object.type === 'Identifier' &&\n node.callee.object.name === 'require' &&\n node.callee.property.type === 'Identifier' &&\n node.callee.property.name === 'resolve';\n\n if ((isRequire || isRequireResolve) && node.arguments.length === 1) {\n pathNode = node.arguments[0];\n }\n } else if (node.type === 'TSImportEqualsDeclaration') {\n if (node.moduleReference.type === 'TSExternalModuleReference') {\n // import foo = require('foo');\n pathNode = node.moduleReference.expression;\n }\n } else if (\n node.type === 'ExportNamedDeclaration' &&\n node.declaration?.type === 'TSImportEqualsDeclaration' &&\n node.declaration.moduleReference.type === 'TSExternalModuleReference'\n ) {\n // export import foo = require('foo');\n pathNode = node.declaration.moduleReference.expression;\n } else {\n pathNode = node.source;\n }\n\n if (pathNode?.type === 'Literal' && typeof pathNode.value === 'string') {\n return { pathNode, importPath: pathNode.value };\n }\n\n if (pathNode?.type === 'TemplateLiteral' && pathNode.expressions.length === 0 && pathNode.quasis.length === 1) {\n return { pathNode, importPath: pathNode.quasis[0].value.cooked };\n }\n\n return null;\n}\n"]}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { PackageJson } from './PackageJson';
|
|
2
|
-
export type PackageInfo = {
|
|
3
|
-
/** Path to the package root directory */
|
|
4
|
-
path: string;
|
|
5
|
-
/** Whether this is a package locally developed in the same monorepo */
|
|
6
|
-
isLocal: boolean;
|
|
7
|
-
/** package.json contents */
|
|
8
|
-
json: PackageJson;
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Find the package root directory relative to the given file (based on the presence of a
|
|
12
|
-
* package.json file) and read the package.json.
|
|
13
|
-
* @param startPath Search up starting from this file or directory
|
|
14
|
-
*/
|
|
15
|
-
export declare function getPackageInfo(startPath: string, debug?: boolean): PackageInfo | null;
|
|
16
|
-
//# sourceMappingURL=getPackageInfo.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getPackageInfo.d.ts","sourceRoot":"","sources":["../../src/utils/getPackageInfo.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD,MAAM,MAAM,WAAW,GAAG;IACxB,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,uEAAuE;IACvE,OAAO,EAAE,OAAO,CAAC;IACjB,4BAA4B;IAC5B,IAAI,EAAE,WAAW,CAAC;CACnB,CAAC;AAGF;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,WAAW,GAAG,IAAI,CAmDrF"}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPackageInfo = getPackageInfo;
|
|
4
|
-
const fs = require("fs");
|
|
5
|
-
const path = require("path");
|
|
6
|
-
const packageInfoCache = new Map();
|
|
7
|
-
/**
|
|
8
|
-
* Find the package root directory relative to the given file (based on the presence of a
|
|
9
|
-
* package.json file) and read the package.json.
|
|
10
|
-
* @param startPath Search up starting from this file or directory
|
|
11
|
-
*/
|
|
12
|
-
function getPackageInfo(startPath, debug) {
|
|
13
|
-
if (!path.isAbsolute(startPath) || !fs.existsSync(startPath)) {
|
|
14
|
-
// prevent unexpected results if a test or other code passes a relative or nonexistent path
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
// Use the realpath in case this is a linked package in a monorepo
|
|
18
|
-
startPath = fs.realpathSync(startPath);
|
|
19
|
-
const root = path.parse(startPath).root;
|
|
20
|
-
const startDir = path.normalize(fs.statSync(startPath).isDirectory() ? startPath : path.dirname(startPath));
|
|
21
|
-
let dir = startDir;
|
|
22
|
-
let packageJsonPath = '';
|
|
23
|
-
let found = false;
|
|
24
|
-
while (dir !== root && !found) {
|
|
25
|
-
const cachedInfo = packageInfoCache.get(dir);
|
|
26
|
-
if (cachedInfo !== undefined) {
|
|
27
|
-
packageInfoCache.set(startDir, cachedInfo);
|
|
28
|
-
return cachedInfo;
|
|
29
|
-
}
|
|
30
|
-
packageJsonPath = path.join(dir, 'package.json');
|
|
31
|
-
if (fs.existsSync(packageJsonPath)) {
|
|
32
|
-
found = true;
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
dir = path.dirname(dir);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
if (!found) {
|
|
39
|
-
debug && console.error(`no package.json found searching up from ${startPath}`);
|
|
40
|
-
packageInfoCache.set(startDir, null);
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
let packageInfo = null;
|
|
44
|
-
try {
|
|
45
|
-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
46
|
-
packageInfo = {
|
|
47
|
-
path: dir,
|
|
48
|
-
// TODO may not work with yarn 3?
|
|
49
|
-
isLocal: !/[\\/]node_modules[\\/]/.test(dir),
|
|
50
|
-
json: packageJson,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
catch (err) {
|
|
54
|
-
debug && console.error(`error reading or parsing ${packageJsonPath}:`, err);
|
|
55
|
-
}
|
|
56
|
-
packageInfoCache.set(dir, packageInfo);
|
|
57
|
-
packageInfoCache.set(startDir, packageInfo);
|
|
58
|
-
return packageInfo;
|
|
59
|
-
}
|
|
60
|
-
//# sourceMappingURL=getPackageInfo.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getPackageInfo.js","sourceRoot":"","sources":["../../src/utils/getPackageInfo.ts"],"names":[],"mappings":";;AAmBA,wCAmDC;AAtED,yBAAyB;AACzB,6BAA6B;AAY7B,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAA8B,CAAC;AAC/D;;;;GAIG;AACH,SAAgB,cAAc,CAAC,SAAiB,EAAE,KAAe;IAC/D,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QAC7D,2FAA2F;QAC3F,OAAO,IAAI,CAAC;IACd,CAAC;IAED,kEAAkE;IAClE,SAAS,GAAG,EAAE,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;IACvC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,IAAI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,WAAW,GAAG;YACZ,IAAI,EAAE,GAAG;YACT,iCAAiC;YACjC,OAAO,EAAE,CAAC,wBAAwB,CAAC,IAAI,CAAC,GAAG,CAAC;YAC5C,IAAI,EAAE,WAAW;SAClB,CAAC;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC,4BAA4B,eAAe,GAAG,EAAE,GAAG,CAAC,CAAC;IAC9E,CAAC;IACD,gBAAgB,CAAC,GAAG,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;IACvC,gBAAgB,CAAC,GAAG,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;IAC5C,OAAO,WAAW,CAAC;AACrB,CAAC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport type { PackageJson } from './PackageJson';\n\nexport type PackageInfo = {\n /** Path to the package root directory */\n path: string;\n /** Whether this is a package locally developed in the same monorepo */\n isLocal: boolean;\n /** package.json contents */\n json: PackageJson;\n};\n\nconst packageInfoCache = new Map<string, PackageInfo | null>();\n/**\n * Find the package root directory relative to the given file (based on the presence of a\n * package.json file) and read the package.json.\n * @param startPath Search up starting from this file or directory\n */\nexport function getPackageInfo(startPath: string, debug?: boolean): PackageInfo | null {\n if (!path.isAbsolute(startPath) || !fs.existsSync(startPath)) {\n // prevent unexpected results if a test or other code passes a relative or nonexistent path\n return null;\n }\n\n // Use the realpath in case this is a linked package in a monorepo\n startPath = fs.realpathSync(startPath);\n const root = path.parse(startPath).root;\n\n const startDir = path.normalize(fs.statSync(startPath).isDirectory() ? startPath : path.dirname(startPath));\n\n let dir = startDir;\n let packageJsonPath = '';\n let found = false;\n while (dir !== root && !found) {\n const cachedInfo = packageInfoCache.get(dir);\n if (cachedInfo !== undefined) {\n packageInfoCache.set(startDir, cachedInfo);\n return cachedInfo;\n }\n\n packageJsonPath = path.join(dir, 'package.json');\n if (fs.existsSync(packageJsonPath)) {\n found = true;\n } else {\n dir = path.dirname(dir);\n }\n }\n\n if (!found) {\n debug && console.error(`no package.json found searching up from ${startPath}`);\n packageInfoCache.set(startDir, null);\n return null;\n }\n\n let packageInfo: PackageInfo | null = null;\n try {\n const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')) as PackageJson;\n packageInfo = {\n path: dir,\n // TODO may not work with yarn 3?\n isLocal: !/[\\\\/]node_modules[\\\\/]/.test(dir),\n json: packageJson,\n };\n } catch (err) {\n debug && console.error(`error reading or parsing ${packageJsonPath}:`, err);\n }\n packageInfoCache.set(dir, packageInfo);\n packageInfoCache.set(startDir, packageInfo);\n return packageInfo;\n}\n"]}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get an array of regular expressions from an array of strings, replacing the `...` string with
|
|
3
|
-
* the default values (if provided). If `strs` is undefined, returns `defaults` or an empty array.
|
|
4
|
-
*/
|
|
5
|
-
export declare function getRegexpsFromStrings(strs: string[] | undefined, defaults?: RegExp[]): RegExp[];
|
|
6
|
-
//# sourceMappingURL=getRegexpsFromStrings.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getRegexpsFromStrings.d.ts","sourceRoot":"","sources":["../../src/utils/getRegexpsFromStrings.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,SAAS,EAAE,QAAQ,GAAE,MAAM,EAAO,GAAG,MAAM,EAAE,CAEnG"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getRegexpsFromStrings = getRegexpsFromStrings;
|
|
4
|
-
/**
|
|
5
|
-
* Get an array of regular expressions from an array of strings, replacing the `...` string with
|
|
6
|
-
* the default values (if provided). If `strs` is undefined, returns `defaults` or an empty array.
|
|
7
|
-
*/
|
|
8
|
-
function getRegexpsFromStrings(strs, defaults = []) {
|
|
9
|
-
return strs?.map((str) => (str === '...' ? defaults : new RegExp(str))).flat() || defaults;
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=getRegexpsFromStrings.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getRegexpsFromStrings.js","sourceRoot":"","sources":["../../src/utils/getRegexpsFromStrings.ts"],"names":[],"mappings":";;AAIA,sDAEC;AAND;;;GAGG;AACH,SAAgB,qBAAqB,CAAC,IAA0B,EAAE,WAAqB,EAAE;IACvF,OAAO,IAAI,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,QAAQ,CAAC;AAC7F,CAAC","sourcesContent":["/**\n * Get an array of regular expressions from an array of strings, replacing the `...` string with\n * the default values (if provided). If `strs` is undefined, returns `defaults` or an empty array.\n */\nexport function getRegexpsFromStrings(strs: string[] | undefined, defaults: RegExp[] = []): RegExp[] {\n return strs?.map((str) => (str === '...' ? defaults : new RegExp(str))).flat() || defaults;\n}\n"]}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { TSESTree } from '@typescript-eslint/utils';
|
|
2
|
-
/**
|
|
3
|
-
* Extract identifiers from an export declaration.
|
|
4
|
-
*/
|
|
5
|
-
export declare function extractIdentifiersFromExport(node: TSESTree.ExportAllDeclaration | TSESTree.ExportNamedDeclaration): TSESTree.Identifier[];
|
|
6
|
-
//# sourceMappingURL=extractIdentifiersFromExport.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extractIdentifiersFromExport.d.ts","sourceRoot":"","sources":["../../../src/utils/testExports/extractIdentifiersFromExport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEzD;;GAEG;AACH,wBAAgB,4BAA4B,CAC1C,IAAI,EAAE,QAAQ,CAAC,oBAAoB,GAAG,QAAQ,CAAC,sBAAsB,GACpE,QAAQ,CAAC,UAAU,EAAE,CAkDvB"}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractIdentifiersFromExport = extractIdentifiersFromExport;
|
|
4
|
-
/**
|
|
5
|
-
* Extract identifiers from an export declaration.
|
|
6
|
-
*/
|
|
7
|
-
function extractIdentifiersFromExport(node) {
|
|
8
|
-
if (node.type === 'ExportAllDeclaration') {
|
|
9
|
-
// export * as foo from 'foo'
|
|
10
|
-
return node.exported ? [node.exported] : [];
|
|
11
|
-
}
|
|
12
|
-
if (node.specifiers.length) {
|
|
13
|
-
// export { a, b }
|
|
14
|
-
// export { a, b } from 'foo'
|
|
15
|
-
return node.specifiers.map((s) => s.exported).filter((s) => s.type === 'Identifier');
|
|
16
|
-
}
|
|
17
|
-
if (node.declaration && node.declaration?.type !== 'VariableDeclaration') {
|
|
18
|
-
// export import foo = require('foo')
|
|
19
|
-
// also class, function, type, interface...
|
|
20
|
-
return node.declaration.id?.type === 'Identifier' ? [node.declaration.id] : [];
|
|
21
|
-
}
|
|
22
|
-
const ids = [];
|
|
23
|
-
const declarations = node.declaration?.declarations || [];
|
|
24
|
-
for (const decl of declarations) {
|
|
25
|
-
if (decl.id.type === 'Identifier') {
|
|
26
|
-
// export const foo = 'foo'
|
|
27
|
-
ids.push(decl.id);
|
|
28
|
-
}
|
|
29
|
-
else if (decl.id.type === 'ArrayPattern') {
|
|
30
|
-
// Unlikely array destructuring export (ignore any nested variants)
|
|
31
|
-
// export const [foo, bar] = ['foo', 'bar']
|
|
32
|
-
for (const elem of decl.id.elements) {
|
|
33
|
-
if (elem?.type === 'Identifier') {
|
|
34
|
-
ids.push(elem);
|
|
35
|
-
}
|
|
36
|
-
else if (elem?.type === 'RestElement' && elem.argument.type === 'Identifier') {
|
|
37
|
-
ids.push(elem.argument);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
// Unlikely object destructuring export (ignore any nested variants)
|
|
43
|
-
// export const { foo, bar } = { foo: 'foo', bar: 'bar' }
|
|
44
|
-
for (const prop of decl.id.properties) {
|
|
45
|
-
if (prop.type === 'Property' && prop.value.type === 'Identifier') {
|
|
46
|
-
// .value instead of .key handles renaming and prevents including non-exported nested keys
|
|
47
|
-
ids.push(prop.value);
|
|
48
|
-
}
|
|
49
|
-
else if (prop.type === 'RestElement' && prop.argument.type === 'Identifier') {
|
|
50
|
-
ids.push(prop.argument);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return ids;
|
|
56
|
-
}
|
|
57
|
-
//# sourceMappingURL=extractIdentifiersFromExport.js.map
|