@objectstack/lint 11.7.0 → 11.10.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/dist/index.cjs +38 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +35 -7
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// src/index.ts
|
|
@@ -782,7 +772,21 @@ function validateJsxPages(stack, opts = {}) {
|
|
|
782
772
|
}
|
|
783
773
|
|
|
784
774
|
// src/validate-react-pages.ts
|
|
785
|
-
var
|
|
775
|
+
var import_node_module = require("module");
|
|
776
|
+
var import_meta = {};
|
|
777
|
+
var cachedTransform = null;
|
|
778
|
+
function loadSucraseTransform() {
|
|
779
|
+
if (cachedTransform) return cachedTransform;
|
|
780
|
+
const anchor = typeof import_meta !== "undefined" && import_meta.url ? import_meta.url : typeof __filename !== "undefined" ? __filename : process.cwd() + "/";
|
|
781
|
+
try {
|
|
782
|
+
cachedTransform = (0, import_node_module.createRequire)(anchor)("sucrase").transform;
|
|
783
|
+
} catch (err) {
|
|
784
|
+
throw new Error(
|
|
785
|
+
`@objectstack/lint: validating a kind:'react' page requires the "sucrase" package, which could not be loaded (${err instanceof Error ? err.message : String(err)}). It is a declared dependency of @objectstack/lint \u2014 if this deployment prunes packages, keep "sucrase" in the image; it is only loaded when a react-source page is validated.`
|
|
786
|
+
);
|
|
787
|
+
}
|
|
788
|
+
return cachedTransform;
|
|
789
|
+
}
|
|
786
790
|
var asArray5 = (v) => Array.isArray(v) ? v : [];
|
|
787
791
|
function validateReactPages(stack) {
|
|
788
792
|
const findings = [];
|
|
@@ -803,8 +807,9 @@ function validateReactPages(stack) {
|
|
|
803
807
|
});
|
|
804
808
|
continue;
|
|
805
809
|
}
|
|
810
|
+
const transform = loadSucraseTransform();
|
|
806
811
|
try {
|
|
807
|
-
|
|
812
|
+
transform(source, { transforms: ["jsx", "typescript"], production: true });
|
|
808
813
|
} catch (err) {
|
|
809
814
|
const message = err instanceof Error ? err.message : String(err);
|
|
810
815
|
findings.push({
|
|
@@ -821,8 +826,22 @@ function validateReactPages(stack) {
|
|
|
821
826
|
}
|
|
822
827
|
|
|
823
828
|
// src/validate-react-page-props.ts
|
|
824
|
-
var
|
|
829
|
+
var import_node_module2 = require("module");
|
|
825
830
|
var import_ui = require("@objectstack/spec/ui");
|
|
831
|
+
var import_meta2 = {};
|
|
832
|
+
var cachedTs = null;
|
|
833
|
+
function loadTypeScript() {
|
|
834
|
+
if (cachedTs) return cachedTs;
|
|
835
|
+
const anchor = typeof import_meta2 !== "undefined" && import_meta2.url ? import_meta2.url : typeof __filename !== "undefined" ? __filename : process.cwd() + "/";
|
|
836
|
+
try {
|
|
837
|
+
cachedTs = (0, import_node_module2.createRequire)(anchor)("typescript");
|
|
838
|
+
} catch (err) {
|
|
839
|
+
throw new Error(
|
|
840
|
+
`@objectstack/lint: validating a kind:'react' page requires the "typescript" package, which could not be loaded (${err instanceof Error ? err.message : String(err)}). It is a declared dependency of @objectstack/lint \u2014 if this deployment prunes packages, keep "typescript" in the image; it is only loaded when a react-source page is validated.`
|
|
841
|
+
);
|
|
842
|
+
}
|
|
843
|
+
return cachedTs;
|
|
844
|
+
}
|
|
826
845
|
var asArray6 = (v) => Array.isArray(v) ? v : [];
|
|
827
846
|
var BLOCKS = new Map(
|
|
828
847
|
import_ui.REACT_BLOCKS.map((b) => [
|
|
@@ -869,25 +888,26 @@ function validateReactPageProps(stack) {
|
|
|
869
888
|
const source = page.source;
|
|
870
889
|
if (typeof source !== "string" || source.trim() === "") continue;
|
|
871
890
|
const name = String(page.name ?? `#${p}`);
|
|
891
|
+
const tsc = loadTypeScript();
|
|
872
892
|
let sf;
|
|
873
893
|
try {
|
|
874
|
-
sf =
|
|
894
|
+
sf = tsc.createSourceFile("page.tsx", source, tsc.ScriptTarget.Latest, true, tsc.ScriptKind.TSX);
|
|
875
895
|
} catch {
|
|
876
896
|
continue;
|
|
877
897
|
}
|
|
878
898
|
const visit = (node) => {
|
|
879
|
-
if (
|
|
899
|
+
if (tsc.isJsxOpeningElement(node) || tsc.isJsxSelfClosingElement(node)) {
|
|
880
900
|
const tag = node.tagName.getText(sf);
|
|
881
901
|
const block = BLOCKS.get(tag);
|
|
882
902
|
if (block) {
|
|
883
903
|
let hasSpread = false;
|
|
884
904
|
const used = /* @__PURE__ */ new Set();
|
|
885
905
|
for (const a of node.attributes.properties) {
|
|
886
|
-
if (
|
|
906
|
+
if (tsc.isJsxSpreadAttribute(a)) {
|
|
887
907
|
hasSpread = true;
|
|
888
908
|
continue;
|
|
889
909
|
}
|
|
890
|
-
if (
|
|
910
|
+
if (tsc.isJsxAttribute(a)) used.add(a.name.getText(sf));
|
|
891
911
|
}
|
|
892
912
|
const where = `page "${name}" \u203A <${tag}>`;
|
|
893
913
|
const path = `pages[${p}].source`;
|
|
@@ -920,7 +940,7 @@ function validateReactPageProps(stack) {
|
|
|
920
940
|
}
|
|
921
941
|
}
|
|
922
942
|
}
|
|
923
|
-
|
|
943
|
+
tsc.forEachChild(node, visit);
|
|
924
944
|
};
|
|
925
945
|
visit(sf);
|
|
926
946
|
}
|