From 241f7ac3c26c2525faa22cbf9ebf6dc36bbf7879 Mon Sep 17 00:00:00 2001 From: Valentine Date: Fri, 14 Nov 2025 18:43:09 +0300 Subject: [PATCH 1/2] Fix foreign.js command implementation --- src/commands/foreign.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/commands/foreign.js b/src/commands/foreign.js index c02f04a4..6209d4a4 100644 --- a/src/commands/foreign.js +++ b/src/commands/foreign.js @@ -12,10 +12,16 @@ const fs = require('fs'); * @param {Hash} opts - All options */ module.exports = function(opts) { - const file = path.resolve(opts.target, 'eo-foreign.json'), - all = JSON.parse(fs.readFileSync(file, 'utf8')); - console.info('There are %d objects in %s:', all.length, rel(file)); - all.forEach((obj) => { - console.info(' %s', obj.id); - }); + const file = path.resolve(opts.target, 'eo-foreign.json'); + try { + let content = fs.readFileSync(file, "utf8"); + content = content.replace(/\r\n/g, "\n").replace(/\r/g, "\n"); + const all = JSON.parse(content); + console.info('There are %d objects in %s:', all.length, rel(file)); + all.forEach((obj) => { + console.info(' %s', obj.id); + }); + } catch (error) { + throw new Error(`Parsing a document fails:`, error); + } }; From 58f9ec0c54c5e76e8bfc57e39cca3c55e8ab630e Mon Sep 17 00:00:00 2001 From: Valentine Date: Fri, 14 Nov 2025 21:49:57 +0300 Subject: [PATCH 2/2] compare the specific problem --- src/commands/foreign.js | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/commands/foreign.js b/src/commands/foreign.js index 6209d4a4..55742134 100644 --- a/src/commands/foreign.js +++ b/src/commands/foreign.js @@ -13,15 +13,9 @@ const fs = require('fs'); */ module.exports = function(opts) { const file = path.resolve(opts.target, 'eo-foreign.json'); - try { - let content = fs.readFileSync(file, "utf8"); - content = content.replace(/\r\n/g, "\n").replace(/\r/g, "\n"); - const all = JSON.parse(content); - console.info('There are %d objects in %s:', all.length, rel(file)); - all.forEach((obj) => { - console.info(' %s', obj.id); - }); - } catch (error) { - throw new Error(`Parsing a document fails:`, error); - } + const all = JSON.parse(fs.readFileSync(file, 'utf8')); + console.info('There are %d objects in %s:', all.length, rel(file)); + all.forEach((obj) => { + console.info(' %s', obj.id); + }); };