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

Add a couple named types for BsConfig #716

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

elliot-nelson
Copy link
Contributor

SUMMARY

  • Add some named types for BsConfig
    • BsConfigFileEntry
    • BsConfigFileEntryOrShortcut
    • BsConfigDiagnosticFilter
    • BsConfigDiagnosticFilerOrShortcut

DETAILS

When writing a bsc plugin, it can get awkward to write functions that interface with entries that have type algebra (you're copying inline into your own plugin code).

I'm putting my thumb on the scale with these names by suggesting the "real" interface for BsConfigFileEntry and BsConfigDiagnosticFilter, but also providing a type for the shortcutting versions. You could imagine a plugin doing some transforms like so:

import {
  BsConfig,
  BsConfigFileEntry,
  BsConfigFileEntryOrShortcut,
  ProgramBuilder
} from 'brighterscript';

function transformFiles(files: BsConfigFileEntryOrShortcut): BsConfigFileEntry[] {
  // do a bunch of stuff
}

function beforeProgramCreate(builder: ProgramBuilder): void {
  builder.options.files = transformFiles(builder.options.files || []);
}

(Open to a different naming scheme! Just sharing my thought process.)

TESTING

  • Existing unit tests pass.

Comment on lines +3 to +16
export interface BsConfigFileEntry {
src: string | string[];
dest?: string;
}

export type BsConfigFileEntryOrShortcut = string | BsConfigFileEntry;

export interface BsConfigDiagnosticFilter {
src?: string;
codes?: Array<number | string>;
}

export type BsConfigDiagnosticFilterOrShortcut = string | number | BsConfigDiagnosticFilter;

Copy link
Member

Choose a reason for hiding this comment

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

Let's drop the BsConfig prefix. If a plugin needs to prefix these, they can do that with the import { FileEntry as BsConfigFileEntry } from 'brighterscript' syntax.

Also, for a while now I've been wanting the term FileEntry to represent a single { src: string; dest: string; } object. BrighterScript currently has an interface named FileObj for that, which is a terrible name. In roku-deploy, we already have a definition for your BsConfigFileEntry interface here, and then the { src: string; dest: string; } interface is named StandardizedFileEntry, which is also a terrible name. I'd love to come up with good names for those two, and use them across all the RokuCommunity projects.

Any thoughts on a better name?

export interface FileEntry { 
    src: string; 
    dest: string; 
}
//what should this be named? FilePathOptions? FilesEntry? MultiFileEntry? 
export interface ComplexFileEntry {
    src: string | string[];
    dest?: string;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The FileEntry makes sense to me given that it's a single file path and its destination (no globs).

The second is usually made of globs so you could make that explicit with FileGlobEntry or FileGlobMapping (to turn a FileGlobEntry into a FileEntry[], it's clear you need to resolve globs).

You could opt instead to make it clear the second one is an input... FileEntryInput or FileEntryConfig, something like that.

Naming is hard 😆

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, what about FileMap and FileEntry? Is that too similar?

Copy link
Member

Choose a reason for hiding this comment

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

@elliot-nelson I haven't forgotten about this. I've been busy with the roku conference presentation, and naming is still hard. @chrisdp and I had a talk about some of these today, but still haven't landed on the final naming.

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.

2 participants