@valbuild/eslint-plugin 0.60.25 → 0.60.26
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.
@@ -3,13 +3,20 @@
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
4
4
|
|
5
5
|
var path = require('path');
|
6
|
+
var fs = require('fs');
|
6
7
|
|
7
8
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
8
9
|
|
9
10
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
11
|
+
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
10
12
|
|
11
13
|
// @ts-check
|
12
14
|
|
15
|
+
/**
|
16
|
+
* @type {Record<string, string>}
|
17
|
+
*/
|
18
|
+
var PACKAGE_JSON_DIRS_CACHE = {}; // we cache to avoid having to do as many fs operations. however, it will fail if the user moves package.json / root directories. For now, we accept that bug since performance is considered more important. Maybe there is a way to know when that happens so we avoid those bugs.
|
19
|
+
|
13
20
|
/**
|
14
21
|
* @type {import('eslint').Rule.RuleModule}
|
15
22
|
*/
|
@@ -37,8 +44,16 @@ var noIllegalModuleIds = {
|
|
37
44
|
if ((maybeValConfigImportDeclaration === null || maybeValConfigImportDeclaration === void 0 ? void 0 : maybeValConfigImportDeclaration.type) === "ImportDeclaration" && typeof maybeValConfigImportDeclaration.source.value === "string") {
|
38
45
|
var filename = context.filename || context.getFilename();
|
39
46
|
if (filename !== null && filename !== void 0 && filename.endsWith(".val.ts") || filename !== null && filename !== void 0 && filename.endsWith(".val.js")) {
|
40
|
-
var
|
41
|
-
|
47
|
+
var packageJsonDir = PACKAGE_JSON_DIRS_CACHE[path__default["default"].dirname(filename)];
|
48
|
+
if (!packageJsonDir) {
|
49
|
+
var runtimeRoot = path__default["default"].resolve(context.cwd || process.cwd());
|
50
|
+
packageJsonDir = path__default["default"].resolve(path__default["default"].dirname(filename));
|
51
|
+
while (!fs__default["default"].existsSync(path__default["default"].join(packageJsonDir, "package.json")) && packageJsonDir !== runtimeRoot) {
|
52
|
+
packageJsonDir = path__default["default"].dirname(packageJsonDir);
|
53
|
+
}
|
54
|
+
PACKAGE_JSON_DIRS_CACHE[path__default["default"].dirname(filename)] = packageJsonDir;
|
55
|
+
}
|
56
|
+
var relativePath = path__default["default"].relative(packageJsonDir, filename);
|
42
57
|
expectedValue = "/".concat(relativePath.replace(/\.val\.(ts|js)$/, ""));
|
43
58
|
}
|
44
59
|
}
|
@@ -3,13 +3,20 @@
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
4
4
|
|
5
5
|
var path = require('path');
|
6
|
+
var fs = require('fs');
|
6
7
|
|
7
8
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
8
9
|
|
9
10
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
11
|
+
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
10
12
|
|
11
13
|
// @ts-check
|
12
14
|
|
15
|
+
/**
|
16
|
+
* @type {Record<string, string>}
|
17
|
+
*/
|
18
|
+
var PACKAGE_JSON_DIRS_CACHE = {}; // we cache to avoid having to do as many fs operations. however, it will fail if the user moves package.json / root directories. For now, we accept that bug since performance is considered more important. Maybe there is a way to know when that happens so we avoid those bugs.
|
19
|
+
|
13
20
|
/**
|
14
21
|
* @type {import('eslint').Rule.RuleModule}
|
15
22
|
*/
|
@@ -37,8 +44,16 @@ var noIllegalModuleIds = {
|
|
37
44
|
if ((maybeValConfigImportDeclaration === null || maybeValConfigImportDeclaration === void 0 ? void 0 : maybeValConfigImportDeclaration.type) === "ImportDeclaration" && typeof maybeValConfigImportDeclaration.source.value === "string") {
|
38
45
|
var filename = context.filename || context.getFilename();
|
39
46
|
if (filename !== null && filename !== void 0 && filename.endsWith(".val.ts") || filename !== null && filename !== void 0 && filename.endsWith(".val.js")) {
|
40
|
-
var
|
41
|
-
|
47
|
+
var packageJsonDir = PACKAGE_JSON_DIRS_CACHE[path__default["default"].dirname(filename)];
|
48
|
+
if (!packageJsonDir) {
|
49
|
+
var runtimeRoot = path__default["default"].resolve(context.cwd || process.cwd());
|
50
|
+
packageJsonDir = path__default["default"].resolve(path__default["default"].dirname(filename));
|
51
|
+
while (!fs__default["default"].existsSync(path__default["default"].join(packageJsonDir, "package.json")) && packageJsonDir !== runtimeRoot) {
|
52
|
+
packageJsonDir = path__default["default"].dirname(packageJsonDir);
|
53
|
+
}
|
54
|
+
PACKAGE_JSON_DIRS_CACHE[path__default["default"].dirname(filename)] = packageJsonDir;
|
55
|
+
}
|
56
|
+
var relativePath = path__default["default"].relative(packageJsonDir, filename);
|
42
57
|
expectedValue = "/".concat(relativePath.replace(/\.val\.(ts|js)$/, ""));
|
43
58
|
}
|
44
59
|
}
|
@@ -1,7 +1,13 @@
|
|
1
1
|
import path from 'path';
|
2
|
+
import fs from 'fs';
|
2
3
|
|
3
4
|
// @ts-check
|
4
5
|
|
6
|
+
/**
|
7
|
+
* @type {Record<string, string>}
|
8
|
+
*/
|
9
|
+
var PACKAGE_JSON_DIRS_CACHE = {}; // we cache to avoid having to do as many fs operations. however, it will fail if the user moves package.json / root directories. For now, we accept that bug since performance is considered more important. Maybe there is a way to know when that happens so we avoid those bugs.
|
10
|
+
|
5
11
|
/**
|
6
12
|
* @type {import('eslint').Rule.RuleModule}
|
7
13
|
*/
|
@@ -29,8 +35,16 @@ var noIllegalModuleIds = {
|
|
29
35
|
if ((maybeValConfigImportDeclaration === null || maybeValConfigImportDeclaration === void 0 ? void 0 : maybeValConfigImportDeclaration.type) === "ImportDeclaration" && typeof maybeValConfigImportDeclaration.source.value === "string") {
|
30
36
|
var filename = context.filename || context.getFilename();
|
31
37
|
if (filename !== null && filename !== void 0 && filename.endsWith(".val.ts") || filename !== null && filename !== void 0 && filename.endsWith(".val.js")) {
|
32
|
-
var
|
33
|
-
|
38
|
+
var packageJsonDir = PACKAGE_JSON_DIRS_CACHE[path.dirname(filename)];
|
39
|
+
if (!packageJsonDir) {
|
40
|
+
var runtimeRoot = path.resolve(context.cwd || process.cwd());
|
41
|
+
packageJsonDir = path.resolve(path.dirname(filename));
|
42
|
+
while (!fs.existsSync(path.join(packageJsonDir, "package.json")) && packageJsonDir !== runtimeRoot) {
|
43
|
+
packageJsonDir = path.dirname(packageJsonDir);
|
44
|
+
}
|
45
|
+
PACKAGE_JSON_DIRS_CACHE[path.dirname(filename)] = packageJsonDir;
|
46
|
+
}
|
47
|
+
var relativePath = path.relative(packageJsonDir, filename);
|
34
48
|
expectedValue = "/".concat(relativePath.replace(/\.val\.(ts|js)$/, ""));
|
35
49
|
}
|
36
50
|
}
|
package/package.json
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
// @ts-check
|
2
2
|
import path from "path";
|
3
|
+
import fs from "fs";
|
4
|
+
|
5
|
+
/**
|
6
|
+
* @type {Record<string, string>}
|
7
|
+
*/
|
8
|
+
const PACKAGE_JSON_DIRS_CACHE = {}; // we cache to avoid having to do as many fs operations. however, it will fail if the user moves package.json / root directories. For now, we accept that bug since performance is considered more important. Maybe there is a way to know when that happens so we avoid those bugs.
|
3
9
|
|
4
10
|
/**
|
5
11
|
* @type {import('eslint').Rule.RuleModule}
|
@@ -41,8 +47,21 @@ export default {
|
|
41
47
|
filename?.endsWith(".val.ts") ||
|
42
48
|
filename?.endsWith(".val.js")
|
43
49
|
) {
|
44
|
-
|
45
|
-
|
50
|
+
let packageJsonDir =
|
51
|
+
PACKAGE_JSON_DIRS_CACHE[path.dirname(filename)];
|
52
|
+
if (!packageJsonDir) {
|
53
|
+
const runtimeRoot = path.resolve(context.cwd || process.cwd());
|
54
|
+
packageJsonDir = path.resolve(path.dirname(filename));
|
55
|
+
while (
|
56
|
+
!fs.existsSync(path.join(packageJsonDir, "package.json")) &&
|
57
|
+
packageJsonDir !== runtimeRoot
|
58
|
+
) {
|
59
|
+
packageJsonDir = path.dirname(packageJsonDir);
|
60
|
+
}
|
61
|
+
PACKAGE_JSON_DIRS_CACHE[path.dirname(filename)] =
|
62
|
+
packageJsonDir;
|
63
|
+
}
|
64
|
+
const relativePath = path.relative(packageJsonDir, filename);
|
46
65
|
expectedValue = `/${relativePath.replace(/\.val\.(ts|js)$/, "")}`;
|
47
66
|
}
|
48
67
|
}
|
package/test/plugin.test.js
CHANGED
@@ -67,24 +67,25 @@ export default c.define(
|
|
67
67
|
'"/content/stuff/with/all/test"'
|
68
68
|
);
|
69
69
|
});
|
70
|
-
|
71
|
-
|
70
|
+
// TODO: we can't test this anymore because we do not know the root dir - perhaps the
|
71
|
+
// test("no illegal modules for monorepos (projects that are not at root) - src", async () => {
|
72
|
+
// const code = `import { s, c } from "../../../../val.config";
|
72
73
|
|
73
|
-
export const schema = s.string();
|
74
|
+
// export const schema = s.string();
|
74
75
|
|
75
|
-
export default c.define(
|
76
|
-
"/something",
|
77
|
-
schema,
|
78
|
-
"React Server components also works"
|
79
|
-
);`;
|
80
|
-
|
81
|
-
|
82
|
-
|
76
|
+
// export default c.define(
|
77
|
+
// "/something",
|
78
|
+
// schema,
|
79
|
+
// "React Server components also works"
|
80
|
+
// );`;
|
81
|
+
// const results = await eslint.lintText(code, {
|
82
|
+
// filePath: "./src/content/stuff/with/all/test.val.ts",
|
83
|
+
// });
|
83
84
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
});
|
85
|
+
// expect(results).toHaveLength(1);
|
86
|
+
// expect(results[0].messages).toHaveLength(1);
|
87
|
+
// expect(results[0].messages[0].fix?.text).toEqual(
|
88
|
+
// '"/content/stuff/with/all/test"'
|
89
|
+
// );
|
90
|
+
// });
|
90
91
|
});
|