From 50af541c2174e468531cad8f026ef23c2d77e72a Mon Sep 17 00:00:00 2001 From: Sunny Luo Date: Mon, 3 Jul 2023 14:15:22 +0800 Subject: [PATCH] fix: use json-stringify-safe (#3174) --- package.json | 3 ++- packages/ext/development/devUtils.js | 18 ++++++------------ yarn.lock | 17 +++++++++-------- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index 987e0f50cd4..ed9938a07eb 100644 --- a/package.json +++ b/package.json @@ -84,7 +84,6 @@ "expo": "^48.0.19", "expo-device": "^5.0.0", "fast-json-stable-stringify": "^2.1.0", - "json-complete": "^2.0.1", "jsrsasign": "^10.7.1", "memoizee": "^0.4.15", "mime-types": "^2.1.35", @@ -103,6 +102,7 @@ "@pmmmwh/react-refresh-webpack-plugin": "^0.5.10", "@types/chrome": "^0.0.161", "@types/jest": "^29.2.3", + "@types/json-stringify-safe": "^5", "@types/jsrsasign": "^10", "@types/memoizee": "^0.4.8", "@types/mime-types": "^2.1.1", @@ -149,6 +149,7 @@ "jest-environment-jsdom": "^29.3.1", "jest-expo": "^47.0.1", "jest-html-reporter": "^3.7.0", + "json-stringify-safe": "^5.0.1", "lint-staged": "^11.2.6", "node-notifier": "^10.0.0", "patch-package": "^7.0.0", diff --git a/packages/ext/development/devUtils.js b/packages/ext/development/devUtils.js index 8feb0f623a5..3681dc9858e 100644 --- a/packages/ext/development/devUtils.js +++ b/packages/ext/development/devUtils.js @@ -4,7 +4,8 @@ const lodash = require('lodash'); const childProcess = require('child_process'); const path = require('path'); // const util = require('util'); -const jsonComplete = require('json-complete'); +const stringify = require('json-stringify-safe'); +const prettier = require('prettier'); const manifest = require('../src/manifest'); // TODO move to developmentConsts.js @@ -63,17 +64,10 @@ function writePreviewWebpackConfigJson(webpackConfig, filename) { // return `[ Function ${this.name}() ] ${this.toString()} `; return `[ Function ${this.name}() ]`; }; - try { - fse.writeJsonSync(filename, webpackConfig, { spaces: 2 }); - } catch (error) { - console.error(error); - console.log('>>>>>>>> Fallback to jsonComplete.encode <<<<<<<<<'); - fse.writeJsonSync(filename, jsonComplete.encode(webpackConfig), { - spaces: 2, - }); - } finally { - // noop - } + fse.writeFileSync( + filename, + prettier.format(stringify(webpackConfig), { parser: 'json' }), + ); // fs.writeFileSync(filename, util.inspect(webpackConfig), { // encoding: 'utf-8', // }); diff --git a/yarn.lock b/yarn.lock index 1bfc0a57241..b3cae8caf52 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5197,6 +5197,7 @@ __metadata: "@starcoin/starcoin": 2.1.5 "@types/chrome": ^0.0.161 "@types/jest": ^29.2.3 + "@types/json-stringify-safe": ^5 "@types/jsrsasign": ^10 "@types/memoizee": ^0.4.8 "@types/mime-types": ^2.1.1 @@ -5255,7 +5256,7 @@ __metadata: jest-environment-jsdom: ^29.3.1 jest-expo: ^47.0.1 jest-html-reporter: ^3.7.0 - json-complete: ^2.0.1 + json-stringify-safe: ^5.0.1 jsrsasign: ^10.7.1 lint-staged: ^11.2.6 memoizee: ^0.4.15 @@ -8717,6 +8718,13 @@ __metadata: languageName: node linkType: hard +"@types/json-stringify-safe@npm:^5": + version: 5.0.0 + resolution: "@types/json-stringify-safe@npm:5.0.0" + checksum: 2822c9341119f53ded3b98b9686199bf13f9ff25ebeeab409ceb02167c2d5872455bdad2a2fcc0d88bd71b35696bf63d3378c7b9ab0e3f09ebbf9775e46cefdd + languageName: node + linkType: hard + "@types/json5@npm:^0.0.29": version: 0.0.29 resolution: "@types/json5@npm:0.0.29" @@ -22105,13 +22113,6 @@ __metadata: languageName: node linkType: hard -"json-complete@npm:^2.0.1": - version: 2.0.1 - resolution: "json-complete@npm:2.0.1" - checksum: b96269a916b85298416ea44fef3a93b5c8fccecfe51c5e3b2f2c1c280f7c897545127e801ae13ef00944968b8f461bf85fad8b591c8fdd6747d263193b34ecf6 - languageName: node - linkType: hard - "json-parse-better-errors@npm:^1.0.1, json-parse-better-errors@npm:^1.0.2": version: 1.0.2 resolution: "json-parse-better-errors@npm:1.0.2"