-
Notifications
You must be signed in to change notification settings - Fork 666
[lockfile-explorer] Isolate .pnpmcfile.cjs execution and add syntax highlighter #5366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
775f982
e03c5b0
717043a
0f8393f
0342885
6f24527
2d5b7b8
ce37f18
2c7c7b3
3fa4702
b86e85d
e45e089
a387e75
4c95005
fa57502
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. | ||
| // See LICENSE in the project root for license information. | ||
|
|
||
| import React from 'react'; | ||
|
|
||
| import { Highlight, themes } from 'prism-react-renderer'; | ||
|
|
||
| // Generate this list by doing console.log(Object.keys(Prism.languages)) | ||
| // BUT THEN DELETE the APIs that are bizarrely mixed into this namespace: | ||
| // "extend", "insertBefore", "DFS" | ||
| export type PrismLanguage = | ||
| | 'plain' | ||
| | 'plaintext' | ||
| | 'text' | ||
| | 'txt' | ||
| | 'markup' | ||
| | 'html' | ||
| | 'mathml' | ||
| | 'svg' | ||
| | 'xml' | ||
| | 'ssml' | ||
| | 'atom' | ||
| | 'rss' | ||
| | 'regex' | ||
| | 'clike' | ||
| | 'javascript' | ||
| | 'js' | ||
| | 'actionscript' | ||
| | 'coffeescript' | ||
| | 'coffee' | ||
| | 'javadoclike' | ||
| | 'css' | ||
| | 'yaml' | ||
| | 'yml' | ||
| | 'markdown' | ||
| | 'md' | ||
| | 'graphql' | ||
| | 'sql' | ||
| | 'typescript' | ||
| | 'ts' | ||
| | 'jsdoc' | ||
| | 'flow' | ||
| | 'n4js' | ||
| | 'n4jsd' | ||
| | 'jsx' | ||
| | 'tsx' | ||
| | 'swift' | ||
| | 'kotlin' | ||
| | 'kt' | ||
| | 'kts' | ||
| | 'c' | ||
| | 'objectivec' | ||
| | 'objc' | ||
| | 'reason' | ||
| | 'rust' | ||
| | 'go' | ||
| | 'cpp' | ||
| | 'python' | ||
| | 'py' | ||
| | 'json' | ||
| | 'webmanifest'; | ||
|
|
||
| export const CodeBox = (props: { code: string; language: PrismLanguage }): JSX.Element => { | ||
| return ( | ||
| <Highlight theme={themes.vsLight} code={props.code} language={props.language}> | ||
| {({ className, style, tokens, getLineProps, getTokenProps }) => ( | ||
| <pre style={style}> | ||
| {tokens.map((line, i) => ( | ||
| <div key={i} {...getLineProps({ line })}> | ||
| {line.map((token, key) => ( | ||
| <span key={key} {...getTokenProps({ token })} /> | ||
| ))} | ||
| </div> | ||
| ))} | ||
| </pre> | ||
| )} | ||
| </Highlight> | ||
| ); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,8 +2,8 @@ | |
| // See LICENSE in the project root for license information. | ||
|
|
||
| import React, { useCallback, useEffect, useState } from 'react'; | ||
|
|
||
| import { readPnpmfileAsync, readPackageSpecAsync, readPackageJsonAsync } from '../../helpers/lfxApiClient'; | ||
| import styles from './styles.scss'; | ||
| import { useAppDispatch, useAppSelector } from '../../store/hooks'; | ||
| import { selectCurrentEntry } from '../../store/slices/entrySlice'; | ||
| import type { IPackageJson } from '../../types/IPackageJson'; | ||
|
|
@@ -13,6 +13,9 @@ import { displaySpecChanges } from '../../helpers/displaySpecChanges'; | |
| import { isEntryModified } from '../../helpers/isEntryModified'; | ||
| import { ScrollArea, Tabs, Text } from '@rushstack/rush-themed-ui'; | ||
| import { LfxGraphEntryKind } from '../../packlets/lfx-shared'; | ||
| import { CodeBox } from './CodeBox'; | ||
|
|
||
| import styles from './styles.scss'; | ||
|
|
||
| const PackageView: { [key: string]: string } = { | ||
| PACKAGE_JSON: 'PACKAGE_JSON', | ||
|
|
@@ -48,9 +51,9 @@ export const PackageJsonViewer = (): JSX.Element => { | |
|
|
||
| useEffect(() => { | ||
| async function loadPackageDetailsAsync(packageName: string): Promise<void> { | ||
| const packageJSONFile = await readPackageJsonAsync(packageName); | ||
| const packageJSONFile: IPackageJson | undefined = await readPackageJsonAsync(packageName); | ||
| setPackageJSON(packageJSONFile); | ||
| const parsedJSON = await readPackageSpecAsync(packageName); | ||
| const parsedJSON: IPackageJson | undefined = await readPackageSpecAsync(packageName); | ||
| setParsedPackageJSON(parsedJSON); | ||
|
Comment on lines
+54
to
57
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Parallelize these with
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably premature optimization at this point. |
||
|
|
||
| if (packageJSONFile && parsedJSON) { | ||
|
|
@@ -161,7 +164,7 @@ export const PackageJsonViewer = (): JSX.Element => { | |
| Please select a Project or Package to view it's package.json | ||
| </Text> | ||
| ); | ||
| return <pre>{JSON.stringify(packageJSON, null, 2)}</pre>; | ||
| return <CodeBox code={JSON.stringify(packageJSON, null, 2)} language="json" />; | ||
| case PackageView.PACKAGE_SPEC: | ||
| if (!pnpmfile) { | ||
| return ( | ||
|
|
@@ -171,7 +174,7 @@ export const PackageJsonViewer = (): JSX.Element => { | |
| </Text> | ||
| ); | ||
| } | ||
| return <pre>{pnpmfile}</pre>; | ||
| return <CodeBox code={pnpmfile} language="js" />; | ||
| case PackageView.PARSED_PACKAGE_JSON: | ||
| if (!parsedPackageJSON) | ||
| return ( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,11 +17,11 @@ module.exports = function createConfig(env, argv) { | |
| } | ||
| }, | ||
| performance: { | ||
| hints: env.production ? 'error' : false | ||
| hints: env.production ? 'error' : false, | ||
| // This specifies the bundle size limit that will trigger Webpack's warning saying: | ||
| // "The following entrypoint(s) combined asset size exceeds the recommended limit." | ||
| // maxEntrypointSize: 500000, | ||
| // maxAssetSize: 500000 | ||
| maxEntrypointSize: Infinity, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you're setting these to infinity, why not just turn off performance?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @iclanton Is there a better way to do that? I tried
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's |
||
| maxAssetSize: Infinity | ||
| }, | ||
| devServer: { | ||
| port: 8096, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. | ||
| // See LICENSE in the project root for license information. | ||
|
|
||
| import type { IPackageJson } from '@rushstack/node-core-library'; | ||
|
|
||
| export interface IReadPackageContext { | ||
| log: (message: string) => void; | ||
| } | ||
|
|
||
| export type IReadPackageHook = ( | ||
| packageJson: IPackageJson, | ||
| context: IReadPackageContext | ||
| ) => IPackageJson | Promise<IPackageJson>; | ||
|
|
||
| export interface IPnpmHooks { | ||
| readPackage?: IReadPackageHook; | ||
| } | ||
|
|
||
| /** | ||
| * Type of the `.pnpmfile.cjs` module. | ||
| */ | ||
| export interface IPnpmfileModule { | ||
| hooks?: IPnpmHooks; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These strings are not expressed in the Prism .d.ts file. They are apparently only available at runtime.