Merge pull request #3486 from ethereum/prettier

lazy load prettier
pull/5370/head
yann300 2 years ago committed by GitHub
commit 8035fe2da8
  1. 25
      apps/remix-ide/src/app/plugins/code-format.ts
  2. 2
      package.json
  3. 8
      yarn.lock

@ -1,12 +1,7 @@
'use strict' 'use strict'
import { Plugin } from '@remixproject/engine' import { Plugin } from '@remixproject/engine'
import prettier from 'prettier/standalone'
import { Options } from 'prettier'; import { Options } from 'prettier';
import sol from './code-format/index' import sol from './code-format/index'
import * as ts from 'prettier/parser-typescript'
import * as babel from 'prettier/parser-babel'
import * as espree from 'prettier/parser-espree'
import * as yml from 'prettier/parser-yaml'
import path from 'path' import path from 'path'
import yaml from 'js-yaml' import yaml from 'js-yaml'
import toml from 'toml' import toml from 'toml'
@ -67,12 +62,28 @@ const defaultOptions = {
export class CodeFormat extends Plugin { export class CodeFormat extends Plugin {
prettier: any
ts: any
babel: any
espree: any
yml: any
sol: any
constructor() { constructor() {
super(profile) super(profile)
} }
async format(file: string) { async format(file: string) {
// lazy load
if (!this.prettier) {
this.prettier = await import('prettier/standalone')
this.ts = await import('prettier/parser-typescript')
this.babel = await import('prettier/parser-babel')
this.espree = await import('prettier/parser-espree')
this.yml = await import('prettier/parser-yaml')
}
try { try {
const content = await this.call('fileManager', 'readFile', file) const content = await this.call('fileManager', 'readFile', file)
if (!content) return if (!content) return
@ -241,8 +252,8 @@ export class CodeFormat extends Plugin {
} }
const result = prettier.format(content, { const result = this.prettier.format(content, {
plugins: [sol as any, ts, babel, espree, yml], plugins: [sol as any, this.ts, this.babel, this.espree, this.yml],
parser: parserName, parser: parserName,
...options ...options
}) })

@ -176,7 +176,7 @@
"merge": "^2.1.1", "merge": "^2.1.1",
"npm-install-version": "^6.0.2", "npm-install-version": "^6.0.2",
"path-browserify": "^1.0.1", "path-browserify": "^1.0.1",
"prettier": "^2.7.1", "prettier": "^2.8.4",
"prettier-plugin-solidity": "^1.0.0-beta.24", "prettier-plugin-solidity": "^1.0.0-beta.24",
"raw-loader": "^4.0.2", "raw-loader": "^4.0.2",
"react": "^17.0.2", "react": "^17.0.2",

@ -22237,10 +22237,10 @@ prettier-plugin-solidity@^1.0.0-beta.24:
solidity-comments-extractor "^0.0.7" solidity-comments-extractor "^0.0.7"
string-width "^4.2.3" string-width "^4.2.3"
prettier@^2.7.1: prettier@^2.8.4:
version "2.7.1" version "2.8.4"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.7.1.tgz#e235806850d057f97bb08368a4f7d899f7760c64" resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.4.tgz#34dd2595629bfbb79d344ac4a91ff948694463c3"
integrity sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g== integrity sha512-vIS4Rlc2FNh0BySk3Wkd6xmwxB0FpOndW5fisM5H8hsZSxU2VWVB5CWIkIjWvrHjIhxk2g3bfMKM87zNTrZddw==
pretty-format@^27.0.0: pretty-format@^27.0.0:
version "27.2.5" version "27.2.5"

Loading…
Cancel
Save