comment-variables 0.6.0 → 0.6.2
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 +13 -27
- package/comments.config.js +0 -26
- package/library/index.js +1 -1
- package/package.json +2 -3
- package/library/_commons/utilities/find-all-imports.js +0 -163
package/README.md
CHANGED
|
@@ -80,13 +80,12 @@ const data = {
|
|
|
80
80
|
"The flow that resolves $COMMENT#* placeholders intro actual comments.", // $COMMENT#JSDOC#DEFINITIONS#RESOLVECOMMENTSFLOW
|
|
81
81
|
compressCommentsFlow:
|
|
82
82
|
"The flow that compresses actual comments into $COMMENT#* placeholders.", // $COMMENT#JSDOC#DEFINITIONS#COMPRESSCOMMENTSFLOW
|
|
83
|
-
findAllImports:
|
|
84
|
-
"Finds all import paths recursively related to a given file path.", // $COMMENT#JSDOC#DEFINITIONS#FINDALLIMPORTS
|
|
85
|
-
processImport: "Processes recursively and resolves a single import path.", // $COMMENT#JSDOC#DEFINITIONS#PROCESSIMPORT
|
|
86
83
|
flattenConfigData:
|
|
87
84
|
"Flattens the config's data property into a one-dimensional object of $COMMENT-*-like keys and string values.", // $COMMENT#JSDOC#DEFINITIONS#FLATTENCONFIGDATA
|
|
88
85
|
resolveConfig:
|
|
89
86
|
"Verifies, validates and resolves the config path to retrieve the config's data and ignores.", // $COMMENT#JSDOC#DEFINITIONS#RESOLVECONFIG
|
|
87
|
+
logError:
|
|
88
|
+
'Logs an error to the console depending on its type. (`"error"` or `"warning"`.)', // $COMMENT#JSDOC#DEFINITIONS#LOGERROR
|
|
90
89
|
}),
|
|
91
90
|
params: Object.freeze({
|
|
92
91
|
string: "The string.", // $COMMENT#JSDOC#PARAMS#STRING
|
|
@@ -100,26 +99,17 @@ const data = {
|
|
|
100
99
|
"The array of paths and globs for the flow's ESLint instance to ignore.", // $COMMENT#JSDOC#PARAMS#IGNORES
|
|
101
100
|
eitherFlattenedConfigData:
|
|
102
101
|
"Either the flattened config data or the reversed flattened config data, since they share the same structure.", // $COMMENT#JSDOC#PARAMS#EITHERFLATTENEDCONFIGDATA
|
|
103
|
-
filePath:
|
|
104
|
-
"The absolute path of the file whose imports are being recursively found, such as that of a project's `comments.config.js` file.", // $COMMENT#JSDOC#PARAMS#FILEPATH
|
|
105
|
-
cwd: "The current working directory, set as `process.cwd()` by default.", // $COMMENT#JSDOC#PARAMS#CWD
|
|
106
|
-
visitedSet:
|
|
107
|
-
"The set of strings tracking the import paths that have already been visited, instantiated as a `new Set()` by default.", // $COMMENT#JSDOC#PARAMS#VISITEDSET
|
|
108
|
-
depth:
|
|
109
|
-
"The current depth of the recursion, instantiated at `0` by default.", // $COMMENT#JSDOC#PARAMS#DEPTH
|
|
110
|
-
maxDepth:
|
|
111
|
-
"The maximum depth allowed for the recursion, instantiated at `100` by default.", // $COMMENT#JSDOC#PARAMS#MAXDEPTH
|
|
112
|
-
importPath: "The import path currently being addressed.", // $COMMENT#JSDOC#PARAMS#IMPORTPATH
|
|
113
|
-
currentDir:
|
|
114
|
-
"The directory containing the import path currently being addressed.", // $COMMENT#JSDOC#PARAMS#CURRENTDIR
|
|
115
102
|
configData:
|
|
116
|
-
"The config's data property. (Values are typed `
|
|
117
|
-
|
|
118
|
-
"The map housing the flattened keys with their values and sources through recursion, instantiated as a `new Map()`.", // $COMMENT#JSDOC#PARAMS#
|
|
119
|
-
|
|
120
|
-
"The list of keys that are parent to the key at hand given the recursive nature of the config's data's data structure, instantiated as an empty array of strings.", // $COMMENT#JSDOC#PARAMS#
|
|
103
|
+
"The config's data property. (Values are typed `unknown` given the limitations in typing recursive values in JSDoc.)", // $COMMENT#JSDOC#PARAMS#CONFIGDATA
|
|
104
|
+
configDataMapOption:
|
|
105
|
+
"The map housing the flattened keys with their values and sources through recursion, instantiated as a `new Map()`.", // $COMMENT#JSDOC#PARAMS#CONFIGDATAMAPOPTION
|
|
106
|
+
parentKeysOption:
|
|
107
|
+
"The list of keys that are parent to the key at hand given the recursive nature of the config's data's data structure, instantiated as an empty array of strings (`[]`).", // $COMMENT#JSDOC#PARAMS#PARENTKEYSOPTION
|
|
121
108
|
configPath:
|
|
122
|
-
|
|
109
|
+
'The path of the config from `comments.config.js`, or from a config passed via the `--config` flag in the CLI, or from one passed via `"commentVariables.config": true` in `.vscode/settings.json` for the VS Code Extension.', // $COMMENT#JSDOC#PARAMS#CONFIGPATH
|
|
110
|
+
options: "The additional options as follows:", // $COMMENT#JSDOC#PARAMS#OPTIONS
|
|
111
|
+
settings: "The required settings as follows:", // $COMMENT#JSDOC#PARAMS#SETTINGS
|
|
112
|
+
error: "The error object being handle for the logging.", // $COMMENT#JSDOC#PARAMS#ERROR
|
|
123
113
|
}),
|
|
124
114
|
returns: Object.freeze({
|
|
125
115
|
exitDueToFailure:
|
|
@@ -128,14 +118,10 @@ const data = {
|
|
|
128
118
|
makeRuleResolve: "The resolve rule based on the flattened config data.", // $COMMENT#JSDOC#RETURNS#MAKERULERESOLVE
|
|
129
119
|
makeRuleCompress:
|
|
130
120
|
"The compress rule based on the reversed flattened config data.", // $COMMENT#JSDOC#RETURNS#MAKERULECOMPRESS
|
|
131
|
-
findAllImports:
|
|
132
|
-
"The complete set of strings of import paths recursively related to the given file path, or `null` if an issue has arisen.", // $COMMENT#JSDOC#RETURNS#FINDALLIMPORTS
|
|
133
|
-
processImport:
|
|
134
|
-
"`true` to skip unresolved paths, `false` if resolution fails at any level.", // $COMMENT#JSDOC#RETURNS#PROCESSIMPORT
|
|
135
121
|
flattenConfigData:
|
|
136
|
-
"Both the flattened config data and its reversed version to ensure the strict reversibility of the `resolve` and `compress` commands.", // $COMMENT#JSDOC#RETURNS#FLATTENCONFIGDATA
|
|
122
|
+
"Both the flattened config data and its reversed version to ensure the strict reversibility of the `resolve` and `compress` commands in a success object (`success: true`). Errors are bubbled up during failures so they can be reused differently on the CLI and the VS Code Extension in a failure object (`success: false`).", // $COMMENT#JSDOC#RETURNS#FLATTENCONFIGDATA
|
|
137
123
|
resolveConfig:
|
|
138
|
-
"The flattened config data, the reverse flattened config data, the verified config path, the raw passed ignores, and the original config.", // $COMMENT#JSDOC#RETURNS#RESOLVECONFIG
|
|
124
|
+
"The flattened config data, the reverse flattened config data, the verified config path, the raw passed ignores, and the original config. Errors are returned during failures so they can be reused differently on the CLI and the VS Code Extension.", // $COMMENT#JSDOC#RETURNS#RESOLVECONFIG
|
|
139
125
|
}),
|
|
140
126
|
}),
|
|
141
127
|
};
|
package/comments.config.js
CHANGED
|
@@ -29,10 +29,6 @@ const data = {
|
|
|
29
29
|
"The flow that resolves $COMMENT#* placeholders intro actual comments.", // $COMMENT#JSDOC#DEFINITIONS#RESOLVECOMMENTSFLOW
|
|
30
30
|
compressCommentsFlow:
|
|
31
31
|
"The flow that compresses actual comments into $COMMENT#* placeholders.", // $COMMENT#JSDOC#DEFINITIONS#COMPRESSCOMMENTSFLOW
|
|
32
|
-
findAllImports:
|
|
33
|
-
"Finds all import paths recursively related to a given file path.", // $COMMENT#JSDOC#DEFINITIONS#FINDALLIMPORTS
|
|
34
|
-
processImport:
|
|
35
|
-
"Processes recursively and resolves a single import path. (Unlike `findAllImports`, here `currentDir`, `cwd`, `visitedSet`, `depth`, and `maxDepth` aren't options because they are mandatory and not pre-parameterized.)", // $COMMENT#JSDOC#DEFINITIONS#PROCESSIMPORT
|
|
36
32
|
flattenConfigData:
|
|
37
33
|
"Flattens the config's data property into a one-dimensional object of $COMMENT-*-like keys and string values.", // $COMMENT#JSDOC#DEFINITIONS#FLATTENCONFIGDATA
|
|
38
34
|
resolveConfig:
|
|
@@ -52,24 +48,6 @@ const data = {
|
|
|
52
48
|
"The array of paths and globs for the flow's ESLint instance to ignore.", // $COMMENT#JSDOC#PARAMS#IGNORES
|
|
53
49
|
eitherFlattenedConfigData:
|
|
54
50
|
"Either the flattened config data or the reversed flattened config data, since they share the same structure.", // $COMMENT#JSDOC#PARAMS#EITHERFLATTENEDCONFIGDATA
|
|
55
|
-
filePath:
|
|
56
|
-
"The absolute path of the file whose imports are being recursively found, such as that of a project's `comments.config.js` file.", // $COMMENT#JSDOC#PARAMS#FILEPATH
|
|
57
|
-
cwdOption:
|
|
58
|
-
"The current working directory, set as `process.cwd()` by default.", // $COMMENT#JSDOC#PARAMS#CWDOPTION
|
|
59
|
-
visitedSetOption:
|
|
60
|
-
"The set of strings tracking the import paths that have already been visited, instantiated as a `new Set()` by default.", // $COMMENT#JSDOC#PARAMS#VISITEDSETOPTION
|
|
61
|
-
depthOption:
|
|
62
|
-
"The current depth of the recursion, instantiated at `0` by default.", // $COMMENT#JSDOC#PARAMS#DEPTHOPTION
|
|
63
|
-
maxDepthOption:
|
|
64
|
-
"The maximum depth allowed for the recursion, instantiated at `100` by default.", // $COMMENT#JSDOC#PARAMS#MAXDEPTHOPTION
|
|
65
|
-
importPath: "The import path currently being addressed.", // $COMMENT#JSDOC#PARAMS#IMPORTPATH
|
|
66
|
-
currentDirSetting:
|
|
67
|
-
"The directory containing the import path currently being addressed.", // $COMMENT#JSDOC#PARAMS#CURRENTDIRSETTING
|
|
68
|
-
cwdSetting: "The current working directory.", // $COMMENT#JSDOC#PARAMS#CWDSETTING
|
|
69
|
-
visitedSetSetting:
|
|
70
|
-
"The set of strings tracking the import paths that have already been visited.", // $COMMENT#JSDOC#PARAMS#VISITEDSETSETTING
|
|
71
|
-
depthSetting: "The current depth of the recursion.", // $COMMENT#JSDOC#PARAMS#DEPTHSETTING
|
|
72
|
-
maxDepthSetting: "The maximum depth allowed for the recursion.", // $COMMENT#JSDOC#PARAMS#MAXDEPTHSETTING
|
|
73
51
|
configData:
|
|
74
52
|
"The config's data property. (Values are typed `unknown` given the limitations in typing recursive values in JSDoc.)", // $COMMENT#JSDOC#PARAMS#CONFIGDATA
|
|
75
53
|
configDataMapOption:
|
|
@@ -89,10 +67,6 @@ const data = {
|
|
|
89
67
|
makeRuleResolve: "The resolve rule based on the flattened config data.", // $COMMENT#JSDOC#RETURNS#MAKERULERESOLVE
|
|
90
68
|
makeRuleCompress:
|
|
91
69
|
"The compress rule based on the reversed flattened config data.", // $COMMENT#JSDOC#RETURNS#MAKERULECOMPRESS
|
|
92
|
-
findAllImports:
|
|
93
|
-
"The complete set of strings of import paths recursively related to the given file path in a success object (`success: true`). Errors are bubbled up during failures in a failure object (`success: false`).", // $COMMENT#JSDOC#RETURNS#FINDALLIMPORTS
|
|
94
|
-
processImport:
|
|
95
|
-
"`true` to continue to the next operation, `false` to stop the whole `findAllImports` process.", // $COMMENT#JSDOC#RETURNS#PROCESSIMPORT
|
|
96
70
|
flattenConfigData:
|
|
97
71
|
"Both the flattened config data and its reversed version to ensure the strict reversibility of the `resolve` and `compress` commands in a success object (`success: true`). Errors are bubbled up during failures so they can be reused differently on the CLI and the VS Code Extension in a failure object (`success: false`).", // $COMMENT#JSDOC#RETURNS#FLATTENCONFIGDATA
|
|
98
72
|
resolveConfig:
|
package/library/index.js
CHANGED
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
|
|
19
19
|
import { exitDueToFailure, logError } from "./_commons/utilities/helpers.js";
|
|
20
20
|
import { resolveConfig } from "./_commons/utilities/resolve-config.js"; // shared
|
|
21
|
-
import { findAllImports } from "
|
|
21
|
+
import { findAllImports } from "find-all-js-imports"; // own package
|
|
22
22
|
import {
|
|
23
23
|
resolveCommentsFlow,
|
|
24
24
|
compressCommentsFlow,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "comment-variables",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "A CLI tool for configuring, managing and maintaining JavaScript comments as JavaScript variables.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"jscomments": "./library/index.js",
|
|
@@ -27,8 +27,7 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@eslint/markdown": "^6.5.0",
|
|
29
29
|
"eslint": "^9.29.0",
|
|
30
|
-
"
|
|
31
|
-
"resolve-importing-path": "^1.0.3",
|
|
30
|
+
"find-all-js-imports": "^1.0.0",
|
|
32
31
|
"tsconfig-paths": "^4.2.0",
|
|
33
32
|
"typescript-eslint": "^8.34.1",
|
|
34
33
|
"zod": "^3.25.67"
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
|
|
4
|
-
import { resolveImportingPath } from "resolve-importing-path";
|
|
5
|
-
import { getSourceCodeFromFilePath } from "get-sourcecode-from-file-path";
|
|
6
|
-
|
|
7
|
-
import { successFalse, successTrue, typeWarning } from "../constants/bases.js";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @typedef {{
|
|
11
|
-
* success: false;
|
|
12
|
-
* errors: Array<{ message: string; type: "warning";}>;
|
|
13
|
-
* } | {
|
|
14
|
-
* success: true;
|
|
15
|
-
* visitedSet: Set<string>;
|
|
16
|
-
* }} FindAllImportsResults
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
// IMPORTANT. findAllImports needs to be able to take a callback function that it can play at every recursion to find the corresponding value for go-to-definitions. But that's on the roadmap, not in the first release. The first implementation of this pinpoint go-to-definition mechanism will be made by analyzing each path obtained rather than by doing so as the paths are being obtained.
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Processes recursively and resolves a single import path. (Unlike `findAllImports`, here `currentDir`, `cwd`, `visitedSet`, `depth`, and `maxDepth` aren't options because they are mandatory and not pre-parameterized.)
|
|
23
|
-
* @param {string} importPath The import path currently being addressed.
|
|
24
|
-
* @param {Object} settings The required settings as follows:
|
|
25
|
-
* @param {string} settings.currentDir The directory containing the import path currently being addressed.
|
|
26
|
-
* @param {string} settings.cwd The current working directory.
|
|
27
|
-
* @param {Set<string>} settings.visitedSet The set of strings tracking the import paths that have already been visited.
|
|
28
|
-
* @param {number} settings.depth The current depth of the recursion.
|
|
29
|
-
* @param {number} settings.maxDepth The maximum depth allowed for the recursion.
|
|
30
|
-
* @returns `true` to continue to the next operation, `false` to stop the whole `findAllImports` process. //
|
|
31
|
-
*/
|
|
32
|
-
const processImport = (
|
|
33
|
-
importPath,
|
|
34
|
-
{ currentDir, cwd, visitedSet, depth, maxDepth }
|
|
35
|
-
) => {
|
|
36
|
-
// Resolves the provided import path.
|
|
37
|
-
const resolvedPath = resolveImportingPath(currentDir, importPath, cwd);
|
|
38
|
-
// Returns true early to skip processing on unresolved paths.
|
|
39
|
-
if (!resolvedPath) return { ...successTrue, visitedSet };
|
|
40
|
-
|
|
41
|
-
// Establishes the options for the next round of findAllImports.
|
|
42
|
-
const findAllImportsOptions = {
|
|
43
|
-
cwd,
|
|
44
|
-
visitedSet,
|
|
45
|
-
depth: depth + 1,
|
|
46
|
-
maxDepth,
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
// Runs findAllImports on the imported path resolved, thus recursively.
|
|
50
|
-
const findAllImportsResults = /** @type {FindAllImportsResults} */ (
|
|
51
|
-
findAllImports(resolvedPath, findAllImportsOptions)
|
|
52
|
-
);
|
|
53
|
-
// Returns true if the round of findAllImports succeeded, false if it failed.
|
|
54
|
-
return findAllImportsResults;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Finds all import paths recursively related to a given file path.
|
|
59
|
-
* @param {string} filePath The absolute path of the file whose imports are being recursively found, such as that of a project's `comments.config.js` file.
|
|
60
|
-
* @param {Object} options The additional options as follows:
|
|
61
|
-
* @param {string} [options.cwd] The current working directory, set as `process.cwd()` by default.
|
|
62
|
-
* @param {Set<string>} [options.visitedSet] The current working directory, set as `process.cwd()` by default.
|
|
63
|
-
* @param {number} [options.depth] The current depth of the recursion, instantiated at `0` by default.
|
|
64
|
-
* @param {number} [options.maxDepth] The maximum depth allowed for the recursion, instantiated at `100` by default.
|
|
65
|
-
* @returns The complete set of strings of import paths recursively related to the given file path in a success object (`success: true`). Errors are bubbled up during failures in a failure object (`success: false`).
|
|
66
|
-
*/
|
|
67
|
-
export const findAllImports = (
|
|
68
|
-
filePath,
|
|
69
|
-
{
|
|
70
|
-
cwd = process.cwd(),
|
|
71
|
-
visitedSet = new Set(),
|
|
72
|
-
depth = 0,
|
|
73
|
-
maxDepth = 100,
|
|
74
|
-
} = {}
|
|
75
|
-
) => {
|
|
76
|
-
// Fails early if max depth is recursively reached.
|
|
77
|
-
if (depth > maxDepth) {
|
|
78
|
-
return {
|
|
79
|
-
...successFalse,
|
|
80
|
-
errors: [
|
|
81
|
-
{
|
|
82
|
-
...typeWarning,
|
|
83
|
-
message: `WARNING. Max depth ${maxDepth} reached at ${filePath}.`,
|
|
84
|
-
},
|
|
85
|
-
],
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
// Fails early if no file is found.
|
|
89
|
-
if (!fs.existsSync(filePath)) {
|
|
90
|
-
return {
|
|
91
|
-
...successFalse,
|
|
92
|
-
errors: [
|
|
93
|
-
{
|
|
94
|
-
...typeWarning,
|
|
95
|
-
message: `WARNING. File not found at ${filePath}.`,
|
|
96
|
-
},
|
|
97
|
-
],
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
// Returns the existing set directly if a path has already been visited.
|
|
101
|
-
if (visitedSet.has(filePath)) {
|
|
102
|
-
return { ...successTrue, visitedSet };
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// Updates the visited set.
|
|
106
|
-
visitedSet.add(filePath);
|
|
107
|
-
|
|
108
|
-
// Parses the file's source code AST.
|
|
109
|
-
const sourceCode = getSourceCodeFromFilePath(filePath);
|
|
110
|
-
// Fails early there is no AST.
|
|
111
|
-
if (!sourceCode?.ast) {
|
|
112
|
-
return {
|
|
113
|
-
...successFalse,
|
|
114
|
-
errors: [
|
|
115
|
-
{
|
|
116
|
-
...typeWarning,
|
|
117
|
-
message: `WARNING. Failed to parse AST for ${filePath}.`,
|
|
118
|
-
},
|
|
119
|
-
],
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// Makes the joint settings for the conditional calls of processImport.
|
|
124
|
-
const processImportSettings = {
|
|
125
|
-
currentDir: path.dirname(filePath),
|
|
126
|
-
cwd,
|
|
127
|
-
visitedSet,
|
|
128
|
-
depth,
|
|
129
|
-
maxDepth,
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
// Processes all imports.
|
|
133
|
-
for (const node of sourceCode.ast.body) {
|
|
134
|
-
// ES Modules (import x from 'y')
|
|
135
|
-
if (node.type === "ImportDeclaration") {
|
|
136
|
-
const processImportResults = processImport(
|
|
137
|
-
node.source.value,
|
|
138
|
-
processImportSettings
|
|
139
|
-
);
|
|
140
|
-
if (!processImportResults) {
|
|
141
|
-
return processImportResults;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// CommonJS (require('x'))
|
|
146
|
-
if (
|
|
147
|
-
node.type === "ExpressionStatement" &&
|
|
148
|
-
node.expression.type === "CallExpression" &&
|
|
149
|
-
node.expression.callee.name === "require" &&
|
|
150
|
-
node.expression.arguments[0]?.type === "Literal"
|
|
151
|
-
) {
|
|
152
|
-
const processImportResults = processImport(
|
|
153
|
-
node.expression.arguments[0].value,
|
|
154
|
-
processImportSettings
|
|
155
|
-
);
|
|
156
|
-
if (!processImportResults) {
|
|
157
|
-
return processImportResults;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
return { ...successTrue, visitedSet };
|
|
163
|
-
};
|