Skip to content
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

initial poc of adding a dynamic prefix to app dev output #3797

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

nickwesselman
Copy link
Contributor

WHY are these changes introduced?

Fixes #0000

WHAT is this pull request doing?

How to test your changes?

Post-release steps

Measuring impact

How do we know this change was effective? Please choose one:

  • n/a - this doesn't need measurement, e.g. a linting rule or a bug-fix
  • Existing analytics will cater for this addition
  • PR includes analytics changes to measure impact

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes
  • I've made sure that any changes to dev or deploy have been reflected in the internal flowchart.

Copy link
Contributor

Thanks for your contribution!

Depending on what you are working on, you may want to request a review from a Shopify team:

  • Themes: @shopify/advanced-edits
  • UI extensions: @shopify/ui-extensions-cli
    • Checkout UI extensions: @shopify/checkout-ui-extensions-api-stewardship
  • Hydrogen: @shopify/hydrogen
  • Other: @shopify/app-management

Comment on lines +135 to +139
const parsedLog : ParsedLog = parseLog(chunk.toString('utf8'))
const prefix = parsedLog.prefix ?? process.prefix
const index = addPrefix(prefix, prefixes)

const lines = stripAnsi(parsedLog.log.replace(/(\n)$/, '')).split(/\n/)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we are parsing before splitting lines, do we assume chunk === line?
Could we receive log lines from different functions in the same chunk?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 I don't think so? Though we could add support for that later I think by looking for the prefix marker at the start of any line?

* add dynamic prefix to some build commands
},
[concurrentColors],
)
const writableStream = useCallback(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@isaacroldan The use of useCallback here seemed unnecessary and I ended up removing it while I was iterating on state management for the seen prefixes. I could probably reintroduce it now, but is it actually needed?

@@ -71,49 +77,95 @@ function currentTime() {
*/
const ConcurrentOutput: FunctionComponent<ConcurrentOutputProps> = ({
processes,
prefixColumnSize = 12,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should our default minimum be?

@@ -193,10 +195,14 @@ const Dev: FunctionComponent<DevProps> = ({
const season = now.getMonth() > 3 ? 'Summer' : 'Winter'
const year = now.getFullYear()

const maxPrefixLength = Math.max(...errorHandledProcesses.map((process) => process.prefix.length), ...app.extensions.map((extension) => extension.handle.length));
const prefixColumnSize = Math.min(maxPrefixLength, 25);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where should we put this default max? override by env var?

[lineColor],
)

const concurrentColors = [
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these colors appear too dark in ITerm.

Copy link
Contributor

Differences in type declarations

We detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:

  • Some seemingly private modules might be re-exported through public modules.
  • If the branch is behind main you might see odd diffs, rebase main into this branch.

New type declarations

We found no new type declarations in this PR

Existing type declarations

packages/cli-kit/dist/public/node/ui/components.d.ts
@@ -1 +1 @@
-export { ConcurrentOutput } from '../../../private/node/ui/components/ConcurrentOutput.js';
\ No newline at end of file
+export { ConcurrentOutput, prefixLog } from '../../../private/node/ui/components/ConcurrentOutput.js';
\ No newline at end of file
packages/cli-kit/dist/private/node/ui/components/ConcurrentOutput.d.ts
@@ -3,10 +3,18 @@ import { AbortSignal } from '../../../../public/node/abort.js';
 import { FunctionComponent } from 'react';
 export interface ConcurrentOutputProps {
     processes: OutputProcess[];
+    prefixColumnSize?: number;
     abortSignal: AbortSignal;
     showTimestamps?: boolean;
     keepRunningAfterProcessesResolve?: boolean;
 }
+/**
+ * Allows users of ConcurrentOutput to format logs with a prefix column override.
+ *
+ * @param prefix The override value for the prefix column
+ * @param log The log to prefix
+ */
+declare function prefixLog(prefix: string, log: string): string;
 /**
  * Renders output from concurrent processes to the terminal.
  * Output will be divided in a three column layout
@@ -20,4 +28,4 @@ export interface ConcurrentOutputProps {
  * rsnode backend/index.js
  */
 declare const ConcurrentOutput: FunctionComponent<ConcurrentOutputProps>;
-export { ConcurrentOutput };
\ No newline at end of file
+export { ConcurrentOutput, prefixLog };
\ No newline at end of file

@nickwesselman
Copy link
Contributor Author

Needs unit tests

@nickwesselman
Copy link
Contributor Author

Need to review other uses of ConcurrentOutput as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants