tools: refactor tools/license2rtf to ESM

PR-URL: https://github.com/nodejs/node/pull/43101
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
This commit is contained in:
Feng Yu 2022-05-25 23:11:42 +08:00 committed by GitHub
parent b5ed1bd33a
commit 30cb1bf8b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 21 deletions

View File

@ -1096,7 +1096,7 @@ endif
$(MACOSOUTDIR)/dist/npm/usr/local/lib/node_modules
unlink $(MACOSOUTDIR)/dist/node/usr/local/bin/npm
unlink $(MACOSOUTDIR)/dist/node/usr/local/bin/npx
$(NODE) tools/license2rtf.js < LICENSE > \
$(NODE) tools/license2rtf.mjs < LICENSE > \
$(MACOSOUTDIR)/installer/productbuild/Resources/license.rtf
cp doc/osx_installer_logo.png $(MACOSOUTDIR)/installer/productbuild/Resources
pkgbuild --version $(FULLVERSION) \

View File

@ -1,8 +1,7 @@
'use strict';
const assert = require('assert');
const Stream = require('stream');
import assert from 'node:assert';
import Stream from 'node:stream';
import { pipeline } from 'node:stream/promises';
import { stdin, stdout } from 'node:process';
/*
* This filter consumes a stream of characters and emits one string per line.
@ -287,19 +286,14 @@ class RtfGenerator extends Stream {
}
}
const stdin = process.stdin;
const stdout = process.stdout;
const lineSplitter = new LineSplitter();
const paragraphParser = new ParagraphParser();
const unwrapper = new Unwrapper();
const rtfGenerator = new RtfGenerator();
stdin.setEncoding('utf-8');
stdin.resume();
stdin.pipe(lineSplitter);
lineSplitter.pipe(paragraphParser);
paragraphParser.pipe(unwrapper);
unwrapper.pipe(rtfGenerator);
rtfGenerator.pipe(stdout);
await pipeline(
stdin,
new LineSplitter(),
new ParagraphParser(),
new Unwrapper(),
new RtfGenerator(),
stdout,
);

View File

@ -420,9 +420,9 @@ if "%use_x64_node_exe%"=="true" (
set exit_code=1
goto exit
)
%x64_node_exe% tools\license2rtf.js < LICENSE > %config%\license.rtf
%x64_node_exe% tools\license2rtf.mjs < LICENSE > %config%\license.rtf
) else (
%node_exe% tools\license2rtf.js < LICENSE > %config%\license.rtf
%node_exe% tools\license2rtf.mjs < LICENSE > %config%\license.rtf
)
if errorlevel 1 echo Failed to generate license.rtf&goto exit