mirror of
https://github.com/facebook/react.git
synced 2026-11-18 20:15:56 +00:00
[playground] Use standalone prettier
All of these warnings go away: ``` ➜ playground git:(remove-prettier) ✗ yarn dev yarn run v1.22.19 $ NODE_ENV=development && next dev ready - started server on 0.0.0.0:3000, url: http://localhost:3000 warn - You have enabled experimental feature (appDir) in next.config.js. warn - Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use at your own risk. info - Thank you for testing `appDir` please leave your feedback at https://nextjs.link/app-feedback event - compiled client and server successfully in 964 ms (199 modules) wait - compiling /page (client and server)... warn - ../../node_modules/prettier/index.js Critical dependency: the request of a dependency is an expression ../../node_modules/prettier/index.js Critical dependency: require function is used in a way in which dependencies cannot be statically extracted ../../node_modules/prettier/index.js Critical dependency: the request of a dependency is an expression ../../node_modules/prettier/index.js Critical dependency: the request of a dependency is an expression ../../node_modules/prettier/third-party.js Critical dependency: the request of a dependency is an expression wait - compiling... warn - ../../node_modules/prettier/index.js Critical dependency: the request of a dependency is an expression ../../node_modules/prettier/index.js Critical dependency: require function is used in a way in which dependencies cannot be statically extracted ../../node_modules/prettier/index.js Critical dependency: the request of a dependency is an expression ../../node_modules/prettier/index.js Critical dependency: the request of a dependency is an expression ../../node_modules/prettier/third-party.js Critical dependency: the request of a dependency is an expression ``` Standalone prettier is meant to be used in the browser: https://prettier.io/docs/en/browser
This commit is contained in:
1 parent
3d3ad1b9ef
commit
dca54c8932
3 files changed
+32
-22
No files matched your search
@@ -14,13 +14,13 @@ import {
|
||||
} from "@heroicons/react/outline";
|
||||
import MonacoEditor, { DiffEditor } from "@monaco-editor/react";
|
||||
import { type CompilerError } from "babel-plugin-react-forget";
|
||||
import prettier from "prettier";
|
||||
import prettierParserBabel from "prettier/parser-babel";
|
||||
import { memo, useCallback, useMemo, useState } from "react";
|
||||
import parserBabel from "prettier/plugins/babel";
|
||||
import * as prettierPluginEstree from "prettier/plugins/estree";
|
||||
import * as prettier from "prettier/standalone";
|
||||
import { memo, useCallback, useEffect, useState } from "react";
|
||||
import { type Store } from "../../lib/stores";
|
||||
import TabbedWindow from "../TabbedWindow";
|
||||
import { monacoOptions } from "./monacoOptions";
|
||||
|
||||
const MemoizedOutput = memo(Output);
|
||||
|
||||
export default MemoizedOutput;
|
||||
@@ -54,7 +54,7 @@ type Props = {
|
||||
compilerOutput: CompilerOutput;
|
||||
};
|
||||
|
||||
function tabify(source: string, compilerOutput: CompilerOutput) {
|
||||
async function tabify(source: string, compilerOutput: CompilerOutput) {
|
||||
const tabs = new Map<string, React.ReactNode>();
|
||||
const reorderedTabs = new Map<string, React.ReactNode>();
|
||||
const concattedResults = new Map<string, string>();
|
||||
@@ -106,7 +106,7 @@ function tabify(source: string, compilerOutput: CompilerOutput) {
|
||||
output={text}
|
||||
diff={lastPassOutput ?? null}
|
||||
showInfoPanel={true}
|
||||
></TextTabContent>
|
||||
></TextTabContent>,
|
||||
);
|
||||
lastPassOutput = text;
|
||||
}
|
||||
@@ -115,14 +115,14 @@ function tabify(source: string, compilerOutput: CompilerOutput) {
|
||||
// Make a synthetic Program so we can have a single AST with all the top level
|
||||
// FunctionDeclarations
|
||||
const ast = t.program(topLevelFnDecls);
|
||||
const { code, sourceMapUrl } = codegen(ast, source);
|
||||
const { code, sourceMapUrl } = await codegen(ast, source);
|
||||
reorderedTabs.set(
|
||||
"JS",
|
||||
<TextTabContent
|
||||
output={code}
|
||||
diff={null}
|
||||
showInfoPanel={false}
|
||||
></TextTabContent>
|
||||
></TextTabContent>,
|
||||
);
|
||||
if (sourceMapUrl) {
|
||||
reorderedTabs.set(
|
||||
@@ -133,7 +133,7 @@ function tabify(source: string, compilerOutput: CompilerOutput) {
|
||||
className="w-full h-96"
|
||||
title="Generated Code"
|
||||
/>
|
||||
</>
|
||||
</>,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -143,23 +143,23 @@ function tabify(source: string, compilerOutput: CompilerOutput) {
|
||||
return reorderedTabs;
|
||||
}
|
||||
|
||||
function codegen(
|
||||
async function codegen(
|
||||
ast: t.Program,
|
||||
source: string
|
||||
): { code: any; sourceMapUrl: string | null } {
|
||||
source: string,
|
||||
): Promise<{ code: any; sourceMapUrl: string | null }> {
|
||||
const generated = generate(
|
||||
ast,
|
||||
{ sourceMaps: true, sourceFileName: "input.js" },
|
||||
source
|
||||
source,
|
||||
);
|
||||
const sourceMapUrl = getSourceMapUrl(
|
||||
generated.code,
|
||||
JSON.stringify(generated.map)
|
||||
JSON.stringify(generated.map),
|
||||
);
|
||||
const codegenOutput = prettier.format(generated.code, {
|
||||
const codegenOutput = await prettier.format(generated.code, {
|
||||
semi: true,
|
||||
parser: "babel",
|
||||
plugins: [prettierParserBabel],
|
||||
plugins: [parserBabel, prettierPluginEstree],
|
||||
});
|
||||
return { code: codegenOutput, sourceMapUrl };
|
||||
}
|
||||
@@ -172,16 +172,21 @@ function getSourceMapUrl(code: string, map: string): string | null {
|
||||
code = utf16ToUTF8(code);
|
||||
map = utf16ToUTF8(map);
|
||||
return `https://evanw.github.io/source-map-visualization/#${btoa(
|
||||
`${code.length}\0${code}${map.length}\0${map}`
|
||||
`${code.length}\0${code}${map.length}\0${map}`,
|
||||
)}`;
|
||||
}
|
||||
|
||||
function Output({ store, compilerOutput }: Props) {
|
||||
const [tabsOpen, setTabsOpen] = useState<Set<string>>(() => new Set());
|
||||
const tabs = useMemo(
|
||||
() => tabify(store.source, compilerOutput),
|
||||
[store.source, compilerOutput]
|
||||
const [tabs, setTabs] = useState<Map<string, React.ReactNode>>(
|
||||
() => new Map(),
|
||||
);
|
||||
useEffect(() => {
|
||||
tabify(store.source, compilerOutput).then((tabs) => {
|
||||
setTabs(tabs);
|
||||
});
|
||||
}, [store.source, compilerOutput]);
|
||||
|
||||
const consoleLogError = useCallback(() => {
|
||||
if (compilerOutput.kind === "err") {
|
||||
console.error(compilerOutput.error);
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
"monaco-editor": "^0.34.1",
|
||||
"next": "^13.5.6",
|
||||
"notistack": "^3.0.0-alpha.7",
|
||||
"prettier": "^2.8.8",
|
||||
"prettier": "3.0.3",
|
||||
"pretty-format": "^29.3.1",
|
||||
"react": "18.2.0",
|
||||
"react-dom": "18.2.0"
|
||||
|
||||
+6
-1
@@ -9958,11 +9958,16 @@ prelude-ls@~1.1.2:
|
||||
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
|
||||
integrity sha512-ESF23V4SKG6lVSGZgYNpbsiaAkdab6ZgOxe52p7+Kid3W3u3bxR4Vfd/o21dmN7jSt0IwgZ4v5MUd26FEtXE9w==
|
||||
|
||||
prettier@2.8.8, prettier@^2.8.8:
|
||||
prettier@2.8.8:
|
||||
version "2.8.8"
|
||||
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.8.tgz#e8c5d7e98a4305ffe3de2e1fc4aca1a71c28b1da"
|
||||
integrity sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==
|
||||
|
||||
prettier@3.0.3:
|
||||
version "3.0.3"
|
||||
resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.0.3.tgz#432a51f7ba422d1469096c0fdc28e235db8f9643"
|
||||
integrity sha512-L/4pUDMxcNa8R/EthV08Zt42WBO4h1rarVtK0K+QJG0X187OLo7l699jWw0GKuwzkPQ//jMFA/8Xm6Fh3J/DAg==
|
||||
|
||||
pretty-format@^24:
|
||||
version "24.9.0"
|
||||
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-24.9.0.tgz#12fac31b37019a4eea3c11aa9a959eb7628aa7c9"
|
||||
|
||||
Reference in new issue
Block a user