@adobe/helix-config 5.6.6 → 5.6.7

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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [5.6.7](https://github.com/adobe/helix-config/compare/v5.6.6...v5.6.7) (2025-09-29)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * ensure no node dependencies ([#320](https://github.com/adobe/helix-config/issues/320)) ([d1dec47](https://github.com/adobe/helix-config/commit/d1dec472f67bae6ebfb92105e4e1324c6fb37056))
7
+
1
8
  ## [5.6.6](https://github.com/adobe/helix-config/compare/v5.6.5...v5.6.6) (2025-09-25)
2
9
 
3
10
 
package/eslint.config.js CHANGED
@@ -18,10 +18,6 @@ export default defineConfig([
18
18
  'coverage/*',
19
19
  ]),
20
20
  {
21
- rules: {
22
- // see https://github.com/import-js/eslint-plugin-import/issues/1868
23
- 'import/no-unresolved': ['error', { ignore: ['@adobe/helix-shared-config/modifiers'] }]
24
- },
25
21
  plugins: {
26
22
  import: recommended.plugins.import,
27
23
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-config",
3
- "version": "5.6.6",
3
+ "version": "5.6.7",
4
4
  "description": "Helix Config",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
@@ -55,7 +55,6 @@
55
55
  "*.cjs": "eslint"
56
56
  },
57
57
  "dependencies": {
58
- "@adobe/helix-shared-config": "11.1.10",
59
58
  "@adobe/helix-shared-server-timing": "1.0.0",
60
59
  "@adobe/helix-shared-utils": "3.0.2"
61
60
  }
@@ -0,0 +1,177 @@
1
+ /*
2
+ * Copyright 2022 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ /**
14
+ * Converts all non-valid characters to `-`.
15
+ * @param {string} text input text
16
+ * @returns {string} the meta name
17
+ */
18
+ function toMetaName(text) {
19
+ return text
20
+ .toLowerCase()
21
+ .replace(/[^0-9a-z:_]/gi, '-');
22
+ }
23
+
24
+ /**
25
+ * The modifiers class help manage the metadata and headers modifiers.
26
+ */
27
+ export class ModifiersConfig {
28
+ /**
29
+ * Converts a globbing expression to regexp. Note that only `*` and `**` are supported yet.
30
+ * @param {string} glob
31
+ * @returns {RegExp}
32
+ */
33
+ static globToRegExp(glob) {
34
+ const reString = glob
35
+ .replaceAll('**', '|')
36
+ .replaceAll('*', '[^/]*')
37
+ .replaceAll('|', '.*');
38
+ return new RegExp(`^${reString}$`);
39
+ }
40
+
41
+ /**
42
+ * Converts all keys in a row object to lowercase
43
+ * @param {Object} obj A row of data from a sheet
44
+ * @returns {Object} A row with all keys converted to lowercase
45
+ */
46
+ static toLowerKeys(obj) {
47
+ return Object.keys(obj).reduce((prev, key) => {
48
+ // eslint-disable-next-line no-param-reassign
49
+ prev[key.toLowerCase()] = obj[key];
50
+ return prev;
51
+ }, Object.create(null));
52
+ }
53
+
54
+ /**
55
+ * Empty modifiers
56
+ * @type {ModifiersConfig}
57
+ */
58
+ static EMPTY = new ModifiersConfig({});
59
+
60
+ /**
61
+ * Parses a sheet that is in a modifier format into a list of key/value pairs
62
+ *
63
+ * @example
64
+ *
65
+ * | url | key | value | Title | Description |
66
+ * |-------|-----|-------|---------|----------------|
67
+ * | "/*" | "A" | "B" | "" | "" |
68
+ * | "/*" | "C" | "D" | "" | "" |
69
+ * | "/f" | "" | "" | "Hero" | "Once upon..." |
70
+ *
71
+ * becomes:
72
+ *
73
+ * {
74
+ * "/*": [
75
+ * { "key": "A", "value": "B" },
76
+ * { "key": "C", "value": "D" },
77
+ * ],
78
+ * "/f": [
79
+ * { "key": "title", "value": "Hero" },
80
+ * { "key": "description", "value": "Once upon..." },
81
+ * ]
82
+ * }
83
+ *
84
+ *
85
+ * @param {object[]} sheet The sheet to parse
86
+ * @param {ModifierKeyFilter} keyFilter filter to apply on keys
87
+ * @returns {ModifierMap} An object containing an array of key/value pairs for every glob
88
+ */
89
+ static parseModifierSheet(sheet, keyFilter = () => true) {
90
+ /** @type ModifierMap */
91
+ const res = Object.create(null);
92
+ for (let row of sheet) {
93
+ row = ModifiersConfig.toLowerKeys(row);
94
+ const {
95
+ url, key, value, ...rest
96
+ } = row;
97
+ if (url) {
98
+ const put = (k, v) => {
99
+ if (keyFilter(k)) {
100
+ let entry = res[url];
101
+ if (!entry) {
102
+ entry = Object.create(null);
103
+ res[url] = entry;
104
+ }
105
+ entry[k] = v;
106
+ }
107
+ };
108
+
109
+ // note that all values are strings, i.e. never another falsy value
110
+ if ('key' in row && 'value' in row && key && value) {
111
+ put(key.toLowerCase(), value);
112
+ } else {
113
+ Object.entries(rest).forEach(([k, v]) => {
114
+ if (k && v) {
115
+ put(k, v);
116
+ }
117
+ });
118
+ }
119
+ }
120
+ }
121
+ // convert res back to key/value pairs
122
+ for (const [url, mods] of Object.entries(res)) {
123
+ res[url] = Object.entries(mods).map(([key, value]) => ({ key, value }));
124
+ }
125
+ return res;
126
+ }
127
+
128
+ /**
129
+ * Creates a new `ModifiersConfig` from the given sheet.
130
+ *
131
+ * @see ModifiersConfig.parseModifierSheet
132
+ * @param {object[]} sheet The sheet to parse
133
+ * @param {ModifierKeyFilter} keyFilter filter to apply on keys
134
+ * @returns {ModifiersConfig} A ModifiersConfig instance.
135
+ */
136
+ static fromModifierSheet(sheet, keyFilter) {
137
+ return new ModifiersConfig(ModifiersConfig.parseModifierSheet(sheet, keyFilter));
138
+ }
139
+
140
+ /**
141
+ * Creates a new ModifiersConfig class.
142
+ * @param {ModifierMap} [map] The modifier map.
143
+ * @param {ModifierKeyFilter} keyFilter filter to apply on modifier keys
144
+ */
145
+ constructor(map, keyFilter = () => true) {
146
+ if (!map) {
147
+ return;
148
+ }
149
+ this.modifiers = Object.entries(map).map(([url, mods]) => {
150
+ const pat = url.indexOf('*') >= 0 ? ModifiersConfig.globToRegExp(url) : url;
151
+ return {
152
+ pat,
153
+ mods: mods.filter(({ key }) => keyFilter(key)),
154
+ };
155
+ });
156
+ }
157
+
158
+ /**
159
+ * Returns the modifier object for the given path.
160
+ * @param {string} path
161
+ * @return {object} the modifiers
162
+ */
163
+ getModifiers(path) {
164
+ if (!this.modifiers) {
165
+ return Object.create(null);
166
+ }
167
+ const modifiers = Object.create(null);
168
+ for (const { pat, mods } of this.modifiers) {
169
+ if (pat === path || (pat instanceof RegExp && pat.test(path))) {
170
+ for (const { key, value } of mods) {
171
+ modifiers[toMetaName(key)] = value;
172
+ }
173
+ }
174
+ }
175
+ return modifiers;
176
+ }
177
+ }
@@ -9,7 +9,6 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
- import { ModifiersConfig } from '@adobe/helix-shared-config/modifiers';
13
12
  import { computeSurrogateKey } from '@adobe/helix-shared-utils';
14
13
  // eslint-disable-next-line import/no-unresolved
15
14
  import { PipelineResponse } from './PipelineResponse.js';
@@ -22,6 +21,7 @@ import {
22
21
  import { resolveLegacyConfig, fetchRobotsTxt, toArray } from './config-legacy.js';
23
22
  import { deepGetOrCreate, prune } from './utils.js';
24
23
  import { ConfigObject } from './config-object.js';
24
+ import { ModifiersConfig } from './ModifiersConfig.js';
25
25
 
26
26
  /**
27
27
  * @typedef Config
@@ -11,8 +11,8 @@
11
11
  */
12
12
  /* eslint-disable no-continue,no-param-reassign */
13
13
  import { logLevelForStatusCode, propagateStatusCode } from '@adobe/helix-shared-utils';
14
- import { ModifiersConfig } from '@adobe/helix-shared-config';
15
14
  import { flatJson2object } from './flatJson2Object.js';
15
+ import { ModifiersConfig } from './ModifiersConfig.js';
16
16
 
17
17
  export const CONFIG_JSON_PATH = '/.helix/config.json';
18
18