eslint-plugin-jsdoc 61.1.8 → 61.1.10
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/dist/rules/importsAsDependencies.cjs +1 -7
- package/dist/rules/importsAsDependencies.cjs.map +1 -1
- package/dist/rules/preferImportTag.cjs +1 -1
- package/dist/to-valid-identifier.cjs +261 -0
- package/package.json +14 -4
- package/rollup.config.js +16 -0
- package/src/rules/importsAsDependencies.js +1 -9
|
@@ -79,13 +79,7 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
|
|
|
79
79
|
} catch {
|
|
80
80
|
// Ignore
|
|
81
81
|
}
|
|
82
|
-
|
|
83
|
-
if (!pkg || !pkg.types && !pkg.typings && !resolve.exports(pkg, '.', {
|
|
84
|
-
conditions: ['!default', '!import', '!node', 'types']
|
|
85
|
-
})) {
|
|
86
|
-
mod = `@types/${mod}`;
|
|
87
|
-
}
|
|
88
|
-
} catch {
|
|
82
|
+
if (!pkg || !pkg.types && !pkg.typings && !resolve.types(pkg)) {
|
|
89
83
|
mod = `@types/${mod}`;
|
|
90
84
|
}
|
|
91
85
|
moduleCheck.set(mod, !deps.has(mod));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"importsAsDependencies.cjs","names":["_iterateJsdoc","_interopRequireDefault","require","_jsdoccomment","resolve","_interopRequireWildcard","_nodeFs","_nodeModule","_nodePath","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","deps","setDeps","pkg","JSON","parse","readFileSync","join","process","cwd","Set","dependencies","keys","devDependencies","error","console","log","moduleCheck","Map","_default","exports","iterateJsdoc","jsdoc","settings","utils","undefined","mode","tag","tags","typeAst","tryParse","type","traverse","nde","mod","element","value","replace","test","isBuiltinModule","types","typings","
|
|
1
|
+
{"version":3,"file":"importsAsDependencies.cjs","names":["_iterateJsdoc","_interopRequireDefault","require","_jsdoccomment","resolve","_interopRequireWildcard","_nodeFs","_nodeModule","_nodePath","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","deps","setDeps","pkg","JSON","parse","readFileSync","join","process","cwd","Set","dependencies","keys","devDependencies","error","console","log","moduleCheck","Map","_default","exports","iterateJsdoc","jsdoc","settings","utils","undefined","mode","tag","tags","typeAst","tryParse","type","traverse","nde","mod","element","value","replace","test","isBuiltinModule","types","typings","reportJSDoc","iterateAllJsdocs","meta","docs","description","url","module"],"sources":["../../src/rules/importsAsDependencies.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc.js';\nimport {\n parse,\n traverse,\n tryParse,\n} from '@es-joy/jsdoccomment';\nimport * as resolve from '@es-joy/resolve.exports';\nimport {\n readFileSync,\n} from 'node:fs';\nimport {\n isBuiltin as isBuiltinModule,\n} from 'node:module';\nimport {\n join,\n} from 'node:path';\n\n/**\n * @type {Set<string>|null}\n */\nlet deps;\n\nconst setDeps = function () {\n try {\n const pkg = JSON.parse(\n readFileSync(join(process.cwd(), './package.json'), 'utf8'),\n );\n deps = new Set([\n ...(pkg.dependencies ?\n /* c8 ignore next 2 */\n Object.keys(pkg.dependencies) :\n []),\n ...(pkg.devDependencies ?\n /* c8 ignore next 2 */\n Object.keys(pkg.devDependencies) :\n []),\n ]);\n /* c8 ignore next -- our package.json exists */\n } catch (error) {\n /* c8 ignore next -- our package.json exists */\n deps = null;\n /* c8 ignore next 4 -- our package.json exists */\n /* eslint-disable no-console -- Inform user */\n console.log(error);\n /* eslint-enable no-console -- Inform user */\n }\n};\n\nconst moduleCheck = new Map();\n\nexport default iterateJsdoc(({\n jsdoc,\n settings,\n utils,\n}) => {\n if (deps === undefined) {\n setDeps();\n }\n\n /* c8 ignore next 3 -- our package.json exists */\n if (deps === null) {\n return;\n }\n\n const {\n mode,\n } = settings;\n\n for (const tag of jsdoc.tags) {\n let typeAst;\n try {\n typeAst = mode === 'permissive' ? tryParse(tag.type) : parse(tag.type, mode);\n } catch {\n continue;\n }\n\n // eslint-disable-next-line no-loop-func -- Safe\n traverse(typeAst, (nde) => {\n /* c8 ignore next 3 -- TS guard */\n if (deps === null) {\n return;\n }\n\n if (nde.type === 'JsdocTypeImport') {\n let mod = nde.element.value.replace(\n /^(@[^\\/]+\\/[^\\/]+|[^\\/]+).*$/v, '$1',\n );\n\n if ((/^[.\\/]/v).test(mod)) {\n return;\n }\n\n if (isBuiltinModule(mod)) {\n // mod = '@types/node';\n // moduleCheck.set(mod, !deps.has(mod));\n return;\n } else if (!moduleCheck.has(mod)) {\n let pkg;\n try {\n pkg = JSON.parse(\n readFileSync(join(process.cwd(), 'node_modules', mod, './package.json'), 'utf8'),\n );\n } catch {\n // Ignore\n }\n\n if (!pkg || (!pkg.types && !pkg.typings && !resolve.types(pkg))) {\n mod = `@types/${mod}`;\n }\n\n moduleCheck.set(mod, !deps.has(mod));\n }\n\n if (moduleCheck.get(mod)) {\n utils.reportJSDoc(\n 'import points to package which is not found in dependencies',\n tag,\n );\n }\n }\n });\n }\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: 'Reports if JSDoc `import()` statements point to a package which is not listed in `dependencies` or `devDependencies`',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/imports-as-dependencies.md#repos-sticky-header',\n },\n type: 'suggestion',\n },\n});\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AAKA,IAAAE,OAAA,GAAAC,uBAAA,CAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AAGA,IAAAK,WAAA,GAAAL,OAAA;AAGA,IAAAM,SAAA,GAAAN,OAAA;AAEmB,SAAAG,wBAAAI,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAN,uBAAA,YAAA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|
var _iterateJsdoc = _interopRequireWildcard(require("../iterateJsdoc.cjs"));
|
|
8
8
|
var _jsdoccomment = require("@es-joy/jsdoccomment");
|
|
9
9
|
var _parseImportsExports = require("parse-imports-exports");
|
|
10
|
-
var _toValidIdentifier = _interopRequireDefault(require("to-valid-identifier"));
|
|
10
|
+
var _toValidIdentifier = _interopRequireDefault(require("../to-valid-identifier.cjs"));
|
|
11
11
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
12
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
13
13
|
var _default = exports.default = (0, _iterateJsdoc.default)(({
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// https://262.ecma-international.org/14.0/#sec-keywords-and-reserved-words
|
|
4
|
+
// 14 is ES2023
|
|
5
|
+
const identifiers = [
|
|
6
|
+
// Keywords
|
|
7
|
+
'await',
|
|
8
|
+
'break',
|
|
9
|
+
'case',
|
|
10
|
+
'catch',
|
|
11
|
+
'class',
|
|
12
|
+
'const',
|
|
13
|
+
'continue',
|
|
14
|
+
'debugger',
|
|
15
|
+
'default',
|
|
16
|
+
'delete',
|
|
17
|
+
'do',
|
|
18
|
+
'else',
|
|
19
|
+
'enum',
|
|
20
|
+
'export',
|
|
21
|
+
'extends',
|
|
22
|
+
'false',
|
|
23
|
+
'finally',
|
|
24
|
+
'for',
|
|
25
|
+
'function',
|
|
26
|
+
'if',
|
|
27
|
+
'import',
|
|
28
|
+
'in',
|
|
29
|
+
'instanceof',
|
|
30
|
+
'new',
|
|
31
|
+
'null',
|
|
32
|
+
'return',
|
|
33
|
+
'super',
|
|
34
|
+
'switch',
|
|
35
|
+
'this',
|
|
36
|
+
'throw',
|
|
37
|
+
'true',
|
|
38
|
+
'try',
|
|
39
|
+
'typeof',
|
|
40
|
+
'var',
|
|
41
|
+
'void',
|
|
42
|
+
'while',
|
|
43
|
+
'with',
|
|
44
|
+
'yield',
|
|
45
|
+
|
|
46
|
+
// Future reserved keywords
|
|
47
|
+
'implements',
|
|
48
|
+
'interface',
|
|
49
|
+
'package',
|
|
50
|
+
'private',
|
|
51
|
+
'protected',
|
|
52
|
+
'public',
|
|
53
|
+
|
|
54
|
+
// Not keywords, but still restricted
|
|
55
|
+
'arguments',
|
|
56
|
+
'eval',
|
|
57
|
+
];
|
|
58
|
+
|
|
59
|
+
// https://262.ecma-international.org/14.0/#sec-value-properties-of-the-global-object
|
|
60
|
+
const globalProperties = [
|
|
61
|
+
'globalThis',
|
|
62
|
+
'Infinity',
|
|
63
|
+
'NaN',
|
|
64
|
+
'undefined',
|
|
65
|
+
];
|
|
66
|
+
|
|
67
|
+
function reservedIdentifiers$1({includeGlobalProperties = false} = {}) {
|
|
68
|
+
return new Set([
|
|
69
|
+
...identifiers,
|
|
70
|
+
...(includeGlobalProperties ? globalProperties : []),
|
|
71
|
+
]);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/* eslint-disable no-bitwise */
|
|
75
|
+
|
|
76
|
+
const BASE = 62;
|
|
77
|
+
const BASE_BIGINT = 62n;
|
|
78
|
+
const DEFAULT_ALPHABET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
|
79
|
+
|
|
80
|
+
const cachedEncoder = new globalThis.TextEncoder();
|
|
81
|
+
const cachedDecoder = new globalThis.TextDecoder();
|
|
82
|
+
|
|
83
|
+
function assertString(value, label) {
|
|
84
|
+
if (typeof value !== 'string') {
|
|
85
|
+
throw new TypeError(`The \`${label}\` parameter must be a string, got \`${value}\` (${typeof value}).`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function validateAlphabet(alphabet) {
|
|
90
|
+
if (typeof alphabet !== 'string') {
|
|
91
|
+
throw new TypeError(`The alphabet must be a string, got \`${alphabet}\` (${typeof alphabet}).`);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (alphabet.length !== BASE) {
|
|
95
|
+
throw new TypeError(`The alphabet must be exactly ${BASE} characters long, got ${alphabet.length}.`);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const uniqueCharacters = new Set(alphabet);
|
|
99
|
+
if (uniqueCharacters.size !== BASE) {
|
|
100
|
+
throw new TypeError(`The alphabet must contain ${BASE} unique characters, got ${uniqueCharacters.size}.`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
class Base62 {
|
|
105
|
+
constructor(options = {}) {
|
|
106
|
+
const alphabet = options.alphabet ?? DEFAULT_ALPHABET;
|
|
107
|
+
validateAlphabet(alphabet);
|
|
108
|
+
this.alphabet = [...alphabet];
|
|
109
|
+
this.indices = new Map(this.alphabet.map((character, index) => [character, index]));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
#getIndex(character) {
|
|
113
|
+
const index = this.indices.get(character);
|
|
114
|
+
|
|
115
|
+
if (index === undefined) {
|
|
116
|
+
throw new TypeError(`Unexpected character for Base62 encoding: \`${character}\`.`);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return index;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
encodeString(string) {
|
|
123
|
+
assertString(string, 'string');
|
|
124
|
+
return this.encodeBytes(cachedEncoder.encode(string));
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
decodeString(encodedString) {
|
|
128
|
+
assertString(encodedString, 'encodedString');
|
|
129
|
+
return cachedDecoder.decode(this.decodeBytes(encodedString));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
encodeBytes(bytes) {
|
|
133
|
+
if (!(bytes instanceof Uint8Array)) {
|
|
134
|
+
throw new TypeError('The `bytes` parameter must be an instance of Uint8Array.');
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (bytes.length === 0) {
|
|
138
|
+
return '';
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Prepend 0x01 to the byte array before encoding to ensure the BigInt conversion
|
|
142
|
+
// does not strip any leading zeros and to prevent any byte sequence from being
|
|
143
|
+
// interpreted as a numerically zero value.
|
|
144
|
+
let value = 1n;
|
|
145
|
+
|
|
146
|
+
for (const byte of bytes) {
|
|
147
|
+
value = (value << 8n) | BigInt(byte);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return this.encodeBigInt(value);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
decodeBytes(encodedString) {
|
|
154
|
+
assertString(encodedString, 'encodedString');
|
|
155
|
+
|
|
156
|
+
if (encodedString.length === 0) {
|
|
157
|
+
return new Uint8Array();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
let value = this.decodeBigInt(encodedString);
|
|
161
|
+
|
|
162
|
+
const byteArray = [];
|
|
163
|
+
while (value > 0n) {
|
|
164
|
+
byteArray.push(Number(value & 0xFFn));
|
|
165
|
+
value >>= 8n;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Remove the 0x01 that was prepended during encoding.
|
|
169
|
+
return Uint8Array.from(byteArray.reverse().slice(1));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
encodeInteger(integer) {
|
|
173
|
+
if (!Number.isInteger(integer)) {
|
|
174
|
+
throw new TypeError(`Expected an integer, got \`${integer}\` (${typeof integer}).`);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (integer < 0) {
|
|
178
|
+
throw new TypeError('The integer must be non-negative.');
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (integer === 0) {
|
|
182
|
+
return this.alphabet[0];
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
let encodedString = '';
|
|
186
|
+
while (integer > 0) {
|
|
187
|
+
encodedString = this.alphabet[integer % BASE] + encodedString;
|
|
188
|
+
integer = Math.floor(integer / BASE);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return encodedString;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
decodeInteger(encodedString) {
|
|
195
|
+
assertString(encodedString, 'encodedString');
|
|
196
|
+
|
|
197
|
+
let integer = 0;
|
|
198
|
+
for (const character of encodedString) {
|
|
199
|
+
integer = (integer * BASE) + this.#getIndex(character);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return integer;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
encodeBigInt(bigint) {
|
|
206
|
+
if (typeof bigint !== 'bigint') {
|
|
207
|
+
throw new TypeError(`Expected a bigint, got \`${bigint}\` (${typeof bigint}).`);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (bigint < 0) {
|
|
211
|
+
throw new TypeError('The bigint must be non-negative.');
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (bigint === 0n) {
|
|
215
|
+
return this.alphabet[0];
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
let encodedString = '';
|
|
219
|
+
while (bigint > 0n) {
|
|
220
|
+
encodedString = this.alphabet[Number(bigint % BASE_BIGINT)] + encodedString;
|
|
221
|
+
bigint /= BASE_BIGINT;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return encodedString;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
decodeBigInt(encodedString) {
|
|
228
|
+
assertString(encodedString, 'encodedString');
|
|
229
|
+
|
|
230
|
+
let bigint = 0n;
|
|
231
|
+
for (const character of encodedString) {
|
|
232
|
+
bigint = (bigint * BASE_BIGINT) + BigInt(this.#getIndex(character));
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return bigint;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// Create default instance with standard alphabet
|
|
240
|
+
const defaultBase62 = new Base62();
|
|
241
|
+
const encodeInteger = integer => defaultBase62.encodeInteger(integer);
|
|
242
|
+
|
|
243
|
+
const reservedIdentifiers = reservedIdentifiers$1({includeGlobalProperties: true});
|
|
244
|
+
|
|
245
|
+
const encodeCodePoint = x => `$${encodeInteger(x.codePointAt(0))}$`;
|
|
246
|
+
|
|
247
|
+
function toValidIdentifier(value) {
|
|
248
|
+
if (typeof value !== 'string') {
|
|
249
|
+
throw new TypeError(`Expected a string, got \`${typeof value}\`.`);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (reservedIdentifiers.has(value)) {
|
|
253
|
+
// We prefix with underscore to avoid any potential conflicts with the Base62 encoded string.
|
|
254
|
+
return `$_${value}$`;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return value.replaceAll(/(?<!^)\P{ID_Continue}/gu, encodeCodePoint)
|
|
258
|
+
.replaceAll(/^[^_\p{ID_Start}]/gu, encodeCodePoint);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
module.exports = toValidIdentifier;
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
},
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@es-joy/jsdoccomment": "~0.76.0",
|
|
9
|
-
"@es-joy/resolve.exports": "1.
|
|
9
|
+
"@es-joy/resolve.exports": "1.2.0",
|
|
10
10
|
"are-docs-informative": "^0.0.2",
|
|
11
11
|
"comment-parser": "1.4.1",
|
|
12
12
|
"debug": "^4.4.3",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"@es-joy/jsdoc-eslint-parser": "^0.25.0",
|
|
34
34
|
"@eslint/core": "^0.16.0",
|
|
35
35
|
"@hkdobrev/run-if-changed": "^0.6.3",
|
|
36
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
36
37
|
"@semantic-release/commit-analyzer": "^13.0.1",
|
|
37
38
|
"@semantic-release/github": "^12.0.0",
|
|
38
39
|
"@semantic-release/npm": "^13.1.1",
|
|
@@ -69,8 +70,10 @@
|
|
|
69
70
|
"playwright": "^1.56.1",
|
|
70
71
|
"replace": "^1.2.2",
|
|
71
72
|
"rimraf": "^6.0.1",
|
|
73
|
+
"rollup": "^4.52.5",
|
|
72
74
|
"semantic-release": "^25.0.1",
|
|
73
75
|
"sinon": "^21.0.0",
|
|
76
|
+
"ts-api-utils": "^2.1.0",
|
|
74
77
|
"typescript": "5.9.3",
|
|
75
78
|
"typescript-eslint": "^8.46.2"
|
|
76
79
|
},
|
|
@@ -160,14 +163,21 @@
|
|
|
160
163
|
"pnpm": {
|
|
161
164
|
"overrides": {
|
|
162
165
|
"@types/eslint": "0.0.0-interferes-with-eslint-now"
|
|
163
|
-
}
|
|
166
|
+
},
|
|
167
|
+
"ignoredBuiltDependencies": [
|
|
168
|
+
"core-js",
|
|
169
|
+
"core-js-pure",
|
|
170
|
+
"re2",
|
|
171
|
+
"unrs-resolver"
|
|
172
|
+
]
|
|
164
173
|
},
|
|
165
174
|
"scripts": {
|
|
166
175
|
"ruleTypes": "node ./src/bin/generateRuleTypes.js",
|
|
167
176
|
"tsc": "tsc",
|
|
168
177
|
"tsc-build": "tsc -p tsconfig-prod.json",
|
|
169
178
|
"tsc-cjs": "tsc -p tsconfig-cjs.json",
|
|
170
|
-
"
|
|
179
|
+
"rollup": "rollup -c",
|
|
180
|
+
"build": "node ./src/bin/buildEntryFileForTS.js && rimraf ./dist && pnpm rollup && NODE_ENV=production babel ./src --out-file-extension .cjs --out-dir ./dist --copy-files --source-maps --ignore ./src/bin/*.js --no-copy-ignored && replace 'to-valid-identifier' '../to-valid-identifier.cjs' 'dist' -r --include=\"*.cjs\" && replace 'require\\(\"\\.(.*?)\\.[^.]*?\"\\)' 'require(\".$1.cjs\")' 'dist' -r --include=\"*.cjs\" && pnpm tsc-build && pnpm tsc-cjs",
|
|
171
181
|
"attw": "attw --pack .",
|
|
172
182
|
"check-docs": "node ./src/bin/generateDocs.js --check",
|
|
173
183
|
"create-docs": "pnpm run create-options && node ./src/bin/generateDocs.js && pnpm ruleTypes",
|
|
@@ -182,5 +192,5 @@
|
|
|
182
192
|
"test-cov": "TIMING=1 c8 --reporter text pnpm run test-no-cov",
|
|
183
193
|
"test-index": "pnpm run test-no-cov test/rules/index.js"
|
|
184
194
|
},
|
|
185
|
-
"version": "61.1.
|
|
195
|
+
"version": "61.1.10"
|
|
186
196
|
}
|
package/rollup.config.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
nodeResolve,
|
|
3
|
+
} from '@rollup/plugin-node-resolve';
|
|
4
|
+
|
|
5
|
+
export default [
|
|
6
|
+
{
|
|
7
|
+
input: 'node_modules/to-valid-identifier/index.js',
|
|
8
|
+
output: {
|
|
9
|
+
file: 'dist/to-valid-identifier.cjs',
|
|
10
|
+
format: 'cjs',
|
|
11
|
+
},
|
|
12
|
+
plugins: [
|
|
13
|
+
nodeResolve(),
|
|
14
|
+
],
|
|
15
|
+
},
|
|
16
|
+
];
|
|
@@ -104,15 +104,7 @@ export default iterateJsdoc(({
|
|
|
104
104
|
// Ignore
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
|
|
108
|
-
if (!pkg || (!pkg.types && !pkg.typings && !resolve.exports(pkg, '.', {
|
|
109
|
-
conditions: [
|
|
110
|
-
'!default', '!import', '!node', 'types',
|
|
111
|
-
],
|
|
112
|
-
}))) {
|
|
113
|
-
mod = `@types/${mod}`;
|
|
114
|
-
}
|
|
115
|
-
} catch {
|
|
107
|
+
if (!pkg || (!pkg.types && !pkg.typings && !resolve.types(pkg))) {
|
|
116
108
|
mod = `@types/${mod}`;
|
|
117
109
|
}
|
|
118
110
|
|