@decocms/start 0.30.3 → 0.30.4
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 +1 -1
- package/package.json +1 -1
- package/src/matchers/builtins.ts +22 -2
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# @decocms/start
|
|
1
|
+
# @decocms/start
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@decocms/start)
|
|
4
4
|
[](https://github.com/decocms/deco-start/blob/main/LICENSE)
|
package/package.json
CHANGED
package/src/matchers/builtins.ts
CHANGED
|
@@ -94,12 +94,29 @@ function isSafePattern(pattern: string): boolean {
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
function pathnameMatcher(rule: Record<string, unknown>, ctx: MatcherContext): boolean {
|
|
97
|
+
const path = ctx.path ?? "";
|
|
98
|
+
|
|
99
|
+
// CMS "case" format: { type: "Includes" | "Equals" | "Not Includes" | "Starts With", pathname: "/..." }
|
|
100
|
+
const caseObj = rule.case as { type?: string; pathname?: string } | undefined;
|
|
101
|
+
if (caseObj?.pathname) {
|
|
102
|
+
switch (caseObj.type) {
|
|
103
|
+
case "Equals":
|
|
104
|
+
return path === caseObj.pathname;
|
|
105
|
+
case "Not Includes":
|
|
106
|
+
return !path.includes(caseObj.pathname);
|
|
107
|
+
case "Starts With":
|
|
108
|
+
return path.startsWith(caseObj.pathname);
|
|
109
|
+
case "Includes":
|
|
110
|
+
default:
|
|
111
|
+
return path.includes(caseObj.pathname);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Standard format: pattern (regex), includes (exact/glob), excludes (exact/glob)
|
|
97
116
|
const pattern = rule.pattern as string | undefined;
|
|
98
117
|
const includes = rule.includes as string[] | undefined;
|
|
99
118
|
const excludes = rule.excludes as string[] | undefined;
|
|
100
119
|
|
|
101
|
-
const path = ctx.path ?? "";
|
|
102
|
-
|
|
103
120
|
if (pattern) {
|
|
104
121
|
if (!isSafePattern(pattern)) {
|
|
105
122
|
console.warn(
|
|
@@ -137,6 +154,9 @@ function pathnameMatcher(rule: Record<string, unknown>, ctx: MatcherContext): bo
|
|
|
137
154
|
if (excluded) return false;
|
|
138
155
|
}
|
|
139
156
|
|
|
157
|
+
// No constraints specified — vacuously true
|
|
158
|
+
if (!pattern && !includes?.length && !excludes?.length) return false;
|
|
159
|
+
|
|
140
160
|
return true;
|
|
141
161
|
}
|
|
142
162
|
|