Skip to content

Commit aafdf12

Browse files
F3n67utargos
authored andcommitted
tools: refactor tools/license2rtf to ESM
This reverts commit 331088f. PR-URL: #43232 Refs: #43213 Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: LiviaMedeiros <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
1 parent ca5af0d commit aafdf12

File tree

3 files changed

+22
-24
lines changed

3 files changed

+22
-24
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,7 @@ endif
10961096
$(MACOSOUTDIR)/dist/npm/usr/local/lib/node_modules
10971097
unlink $(MACOSOUTDIR)/dist/node/usr/local/bin/npm
10981098
unlink $(MACOSOUTDIR)/dist/node/usr/local/bin/npx
1099-
$(NODE) tools/license2rtf.js < LICENSE > \
1099+
$(NODE) tools/license2rtf.mjs < LICENSE > \
11001100
$(MACOSOUTDIR)/installer/productbuild/Resources/license.rtf
11011101
cp doc/osx_installer_logo.png $(MACOSOUTDIR)/installer/productbuild/Resources
11021102
pkgbuild --version $(FULLVERSION) \

tools/license2rtf.js tools/license2rtf.mjs

+16-18
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
'use strict';
2-
3-
const assert = require('assert');
4-
const Stream = require('stream');
5-
1+
import assert from 'node:assert';
2+
import Stream from 'node:stream';
3+
import { pipeline } from 'node:stream/promises';
4+
import { stdin, stdout } from 'node:process';
65

76
/*
87
* This filter consumes a stream of characters and emits one string per line.
@@ -28,6 +27,7 @@ class LineSplitter extends Stream {
2827
if (this.buffer) {
2928
this.emit('data', this.buffer);
3029
}
30+
this.writable = false;
3131
this.emit('end');
3232
}
3333
}
@@ -53,6 +53,7 @@ class ParagraphParser extends Stream {
5353
if (data)
5454
this.parseLine(data + '');
5555
this.flushParagraph();
56+
this.writable = false;
5657
this.emit('end');
5758
}
5859

@@ -212,6 +213,7 @@ class Unwrapper extends Stream {
212213
end(data) {
213214
if (data)
214215
this.write(data);
216+
this.writable = false;
215217
this.emit('end');
216218
}
217219
}
@@ -273,6 +275,7 @@ class RtfGenerator extends Stream {
273275
this.write(data);
274276
if (this.didWriteAnything)
275277
this.emitFooter();
278+
this.writable = false;
276279
this.emit('end');
277280
}
278281

@@ -287,19 +290,14 @@ class RtfGenerator extends Stream {
287290
}
288291
}
289292

290-
291-
const stdin = process.stdin;
292-
const stdout = process.stdout;
293-
const lineSplitter = new LineSplitter();
294-
const paragraphParser = new ParagraphParser();
295-
const unwrapper = new Unwrapper();
296-
const rtfGenerator = new RtfGenerator();
297-
298293
stdin.setEncoding('utf-8');
299294
stdin.resume();
300295

301-
stdin.pipe(lineSplitter);
302-
lineSplitter.pipe(paragraphParser);
303-
paragraphParser.pipe(unwrapper);
304-
unwrapper.pipe(rtfGenerator);
305-
rtfGenerator.pipe(stdout);
296+
await pipeline(
297+
stdin,
298+
new LineSplitter(),
299+
new ParagraphParser(),
300+
new Unwrapper(),
301+
new RtfGenerator(),
302+
stdout,
303+
);

vcbuild.bat

+5-5
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ if errorlevel 1 echo "Could not create junction to 'out\%config%'." & exit /B
405405
if not defined sign goto licensertf
406406

407407
call tools\sign.bat Release\node.exe
408-
if errorlevel 1 echo Failed to sign exe&goto exit
408+
if errorlevel 1 echo Failed to sign exe, got error code %errorlevel%&goto exit
409409

410410
:licensertf
411411
@rem Skip license.rtf generation if not requested.
@@ -426,12 +426,12 @@ if "%use_x64_node_exe%"=="true" (
426426
set exit_code=1
427427
goto exit
428428
)
429-
%x64_node_exe% tools\license2rtf.js < LICENSE > %config%\license.rtf
429+
%x64_node_exe% tools\license2rtf.mjs < LICENSE > %config%\license.rtf
430430
) else (
431-
%node_exe% tools\license2rtf.js < LICENSE > %config%\license.rtf
431+
%node_exe% tools\license2rtf.mjs < LICENSE > %config%\license.rtf
432432
)
433433

434-
if errorlevel 1 echo Failed to generate license.rtf&goto exit
434+
if errorlevel 1 echo Failed to generate license.rtf, got error code %errorlevel%&goto exit
435435

436436
:stage_package
437437
if not defined stage_package goto install-doctools
@@ -538,7 +538,7 @@ if errorlevel 1 goto exit
538538

539539
if not defined sign goto upload
540540
call tools\sign.bat node-v%FULLVERSION%-%target_arch%.msi
541-
if errorlevel 1 echo Failed to sign msi&goto exit
541+
if errorlevel 1 echo Failed to sign msi, got error code %errorlevel%&goto exit
542542

543543
:upload
544544
@rem Skip upload if not requested

0 commit comments

Comments
 (0)