Skip to content

Commit bc9e058

Browse files
committed
fix(nx-infra-plugin): address PR review comments
- normalizeEol: also replace standalone CR (\r) for full EOL coverage - vectormap buildData: add ensureTrailingNewline for consistency with buildUtilsVariant - compress: fail loudly when terser produces no output instead of silently returning uncompressed content
1 parent c4e3970 commit bc9e058

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

packages/nx-infra-plugin/src/executors/compress/executor.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ async function minify(content: string, eulaUrl?: string): Promise<string> {
3939
},
4040
});
4141

42-
return result.code || content;
42+
if (result.code == null) {
43+
throw new Error('Terser minification produced no output');
44+
}
45+
46+
return result.code;
4347
}
4448

4549
async function beautify(content: string, eulaUrl?: string): Promise<string> {
@@ -72,7 +76,11 @@ async function beautify(content: string, eulaUrl?: string): Promise<string> {
7276
},
7377
});
7478

75-
return jsBeautify(uglifyResult.code || content);
79+
if (uglifyResult.code == null) {
80+
throw new Error('Terser beautification produced no output');
81+
}
82+
83+
return jsBeautify(uglifyResult.code);
7684
}
7785

7886
function stripDebugBlocks(content: string): string {

packages/nx-infra-plugin/src/executors/vectormap/executor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ async function buildData(
142142
const rawData = await readFileText(filePath);
143143
let wrapped = compiled({ data: rawData });
144144
wrapped = USE_STRICT_HEADER + wrapped;
145-
wrapped = normalizeEol(wrapped);
145+
wrapped = ensureTrailingNewline(normalizeEol(wrapped));
146146
await writeFileText(filePath, wrapped);
147147
}
148148
}

packages/nx-infra-plugin/src/utils/file-operations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export async function copyRecursive(from: string, to: string): Promise<void> {
6666
}
6767

6868
export function normalizeEol(content: string): string {
69-
return content.replace(/\r\n/g, '\n');
69+
return content.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
7070
}
7171

7272
export function ensureTrailingNewline(content: string): string {

0 commit comments

Comments
 (0)