@lsst/pik-core 0.5.3 → 0.6.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.js
CHANGED
|
@@ -121,17 +121,56 @@ class Parser {
|
|
|
121
121
|
}
|
|
122
122
|
const optionMatch = line.match(Parser.OPTION_REGEX);
|
|
123
123
|
if (optionMatch && currentSelector) {
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
124
|
+
const isStandalone = this.isStandaloneMarker(line);
|
|
125
|
+
if (isStandalone && i + 1 < lines.length) {
|
|
126
|
+
const contentLine = lines[i + 1];
|
|
127
|
+
const option = {
|
|
128
|
+
name: optionMatch[1],
|
|
129
|
+
line: lineNumber,
|
|
130
|
+
contentLine: lineNumber + 1,
|
|
131
|
+
content: contentLine,
|
|
132
|
+
isActive: !this.isLineCommented(contentLine)
|
|
133
|
+
};
|
|
134
|
+
currentSelector.options.push(option);
|
|
135
|
+
} else {
|
|
136
|
+
const option = {
|
|
137
|
+
name: optionMatch[1],
|
|
138
|
+
line: lineNumber,
|
|
139
|
+
contentLine: lineNumber,
|
|
140
|
+
content: line,
|
|
141
|
+
isActive: !this.isLineCommented(line)
|
|
142
|
+
};
|
|
143
|
+
currentSelector.options.push(option);
|
|
144
|
+
}
|
|
131
145
|
}
|
|
132
146
|
}
|
|
133
147
|
return { selectors, content };
|
|
134
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* Check if a line contains only a standalone marker (no other content)
|
|
151
|
+
* e.g., "<!-- @pik:option Name -->" or "# @pik:option Name"
|
|
152
|
+
*/
|
|
153
|
+
isStandaloneMarker(line) {
|
|
154
|
+
const trimmed = line.trim();
|
|
155
|
+
if (this.commentStyle.hasBlockComments) {
|
|
156
|
+
const { blockOpen, blockClose } = this.commentStyle;
|
|
157
|
+
if (trimmed.startsWith(blockOpen) && trimmed.endsWith(blockClose)) {
|
|
158
|
+
const inner = trimmed.slice(blockOpen.length, -blockClose.length).trim();
|
|
159
|
+
const optionMatch = inner.match(Parser.OPTION_REGEX);
|
|
160
|
+
if (optionMatch && inner === `@pik:option ${optionMatch[1]}`) {
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (trimmed.startsWith(this.commentStyle.lineComment)) {
|
|
166
|
+
const afterComment = trimmed.slice(this.commentStyle.lineComment.length).trim();
|
|
167
|
+
const optionMatch = afterComment.match(Parser.OPTION_REGEX);
|
|
168
|
+
if (optionMatch && afterComment === `@pik:option ${optionMatch[1]}`) {
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
135
174
|
/**
|
|
136
175
|
* Check if a line is commented out
|
|
137
176
|
*/
|
|
@@ -253,11 +292,11 @@ class SingleSwitcher extends Switcher {
|
|
|
253
292
|
this.validateOption(selector, optionName);
|
|
254
293
|
const lines = content.split("\n");
|
|
255
294
|
const useBlockStyle = selector.options.some((opt) => {
|
|
256
|
-
const line = lines[opt.
|
|
295
|
+
const line = lines[opt.contentLine - 1];
|
|
257
296
|
return this.isBlockCommented(line);
|
|
258
297
|
});
|
|
259
298
|
for (const option of selector.options) {
|
|
260
|
-
const lineIndex = option.
|
|
299
|
+
const lineIndex = option.contentLine - 1;
|
|
261
300
|
const line = lines[lineIndex];
|
|
262
301
|
if (option.name === optionName) {
|
|
263
302
|
lines[lineIndex] = this.uncommentLine(line);
|
package/dist/lib/parser.d.ts
CHANGED
|
@@ -16,6 +16,11 @@ export declare class Parser {
|
|
|
16
16
|
* Parse content string for pik selectors and options
|
|
17
17
|
*/
|
|
18
18
|
parse(content: string): ParseResult;
|
|
19
|
+
/**
|
|
20
|
+
* Check if a line contains only a standalone marker (no other content)
|
|
21
|
+
* e.g., "<!-- @pik:option Name -->" or "# @pik:option Name"
|
|
22
|
+
*/
|
|
23
|
+
private isStandaloneMarker;
|
|
19
24
|
/**
|
|
20
25
|
* Check if a line is commented out
|
|
21
26
|
*/
|
package/dist/lib/parser.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/lib/parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAU,WAAW,EAAY,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD;;GAEG;AACH,qBAAa,MAAM;IAIL,OAAO,CAAC,QAAQ,CAAC,YAAY;IAHzC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAyB;IAC7D,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAyB;gBAEhC,YAAY,EAAE,YAAY;IAEvD;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;IAI9C;;OAEG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW;
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/lib/parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAU,WAAW,EAAY,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD;;GAEG;AACH,qBAAa,MAAM;IAIL,OAAO,CAAC,QAAQ,CAAC,YAAY;IAHzC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAyB;IAC7D,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAyB;gBAEhC,YAAY,EAAE,YAAY;IAEvD;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;IAI9C;;OAEG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW;IAuDnC;;;OAGG;IACH,OAAO,CAAC,kBAAkB;IA6B1B;;OAEG;IACH,OAAO,CAAC,eAAe;CAkBxB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"single-switcher.d.ts","sourceRoot":"","sources":["../../src/lib/single-switcher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC;;GAEG;AACH,qBAAa,cAAe,SAAQ,QAAQ;IAC1C;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,cAAc;IAItD;;OAEG;IACH,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM;
|
|
1
|
+
{"version":3,"file":"single-switcher.d.ts","sourceRoot":"","sources":["../../src/lib/single-switcher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC;;GAEG;AACH,qBAAa,cAAe,SAAQ,QAAQ;IAC1C;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,cAAc;IAItD;;OAEG;IACH,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM;CAyBxE"}
|
|
@@ -4,9 +4,11 @@
|
|
|
4
4
|
export interface Option {
|
|
5
5
|
/** Option name (e.g., "DEV", "LOCAL") */
|
|
6
6
|
name: string;
|
|
7
|
-
/** Line number (1-based) */
|
|
7
|
+
/** Line number where the marker is (1-based) */
|
|
8
8
|
line: number;
|
|
9
|
-
/**
|
|
9
|
+
/** Line number where the content is (1-based). Same as `line` for inline markers, next line for standalone markers. */
|
|
10
|
+
contentLine: number;
|
|
11
|
+
/** Full content of the content line */
|
|
10
12
|
content: string;
|
|
11
13
|
/** Whether this option is currently active (not commented out) */
|
|
12
14
|
isActive: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"option.d.ts","sourceRoot":"","sources":["../../../src/lib/types/option.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,
|
|
1
|
+
{"version":3,"file":"option.d.ts","sourceRoot":"","sources":["../../../src/lib/types/option.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,gDAAgD;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,uHAAuH;IACvH,WAAW,EAAE,MAAM,CAAC;IACpB,uCAAuC;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,kEAAkE;IAClE,QAAQ,EAAE,OAAO,CAAC;CACnB"}
|