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

feat: add transistor config schema file #18

Merged
merged 14 commits into from
Aug 4, 2023
Merged

feat: add transistor config schema file #18

merged 14 commits into from
Aug 4, 2023

Conversation

francinelucca
Copy link
Contributor

@francinelucca francinelucca commented Aug 2, 2023

Adds a schema file for transistor config with npm and jsx scope typings.

Note for @jdharvey-ibm I made some constraints here that I felt made sense like:

  • require top-level "collect" and "projectId" keys
  • require at least 1 scope to be defined
  • require at least 1 property to be defined per scope
  • require at least 1 attribute if allowedAtrributeNames is defined
  • require at least 1 string value if allowedAttributeStringValues is define

Changelog

New

  • Added transistor config schema file: src/schemas/transistor-config.schema.json
  • Added dedicated per-scope schema files

Testing / reviewing

test out adding and removing keys from test.yml or creating your own file

TODO: remove test.yml file

Copy link
Collaborator

@mattrosno mattrosno left a comment

Choose a reason for hiding this comment

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

I like how we are using a published package for the Carbon Platform schema to validate YAML config files. E.g.

# yaml-language-server: $schema=https://unpkg.com/@carbon-platform/schemas@v1/carbon-resources.schema.json
designKits:
  carbon-white-sketch:
    name: Sketch white theme

Do we want the schema to live in its own package?

Or, if we want to publish it as part of this package (e.g. @ibm/transistor-js), what would we need to do to expose the schema as part of the top level package so an instrumented code package could use unpkg to use a versioned schema file? E.g.:

# yaml-language-server: $schema=https://unpkg.com/@ibm/transistor-js@v1/transistor-config.schema.json
collect:
    npm:
        dependencies:

Said differently, how could we achieve this:

https://unpkg.com/@ibm/transistor-js@v1/transistor-config.schema.json

Instead of depending on the internal directory structure:

https://unpkg.com/@ibm/transistor-js@v1/src/schemas/transistor-config.schema.json?

Copy link
Collaborator

@mattrosno mattrosno left a comment

Choose a reason for hiding this comment

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

With top-level collect and projectId keys, we're dependent on the YAML file names like transistor.yml to find and parse the config.

I'm wondering if we should nest everything inside a top-level transistor key, e.g.:

transistor:
  collect:
    npm:
      dependencies:
  projectId: "1234"

Would this enable potential future config and indexing consolidation? Let's say the future has one ibm.yml config to both instrument for metrics and index for website catalogs:

assets:
  accordion:
    name: Accordion
  aspect-ratio:
    name: Aspect ratio
libraries:
  carbon-react:
    name: Carbon React
    assets:
      $ref: '#/assets'
transistor:
  collect:
    npm:
      dependencies:
  projectId: "1234"

Or... if collect and projectId are unique and have no foreseen conflicts with Carbon Platform and InnerSource indexing... then we're good and we don't need the top level transistor key?

CC @jdharvey-ibm

@francinelucca
Copy link
Contributor Author

Schema location/urls:

Schema will eventually live in it's own package for reusability's sake since other emitters will also depend on it. The schema will be served alongside emitters' published code. How emitters consume the schema from it's standalone repository could go to ways:
a) we publish the schema as it's own package to npm and the emitters consume it by installing it
b) the packages download the schema from it's repository location directly and bundle it into their build without going through npm

To make a decision between these two approaches we'll need to construct POCs and evaluate.


Top level transistor key and file dependency

we will not depend on a transistor.yml file. Instead, we will require packages to tell us via a command on the postinstall script (or whatever the entry point is in the language that is being used) to tell use where their configuration file lives.

we will not add a top level key at this point and can easily do so shall the time come in the future when this and other libraries and schemas are more mature.


We are going to split out scopes into individual scope files and pull them in into the broader schema file by reference

@francinelucca
Copy link
Contributor Author

changed required properties for minProperties: 1 instead and moved scope schemas into their own files. ready for re-rev @jdharvey-ibm @mattrosno

Copy link
Collaborator

@mattrosno mattrosno left a comment

Choose a reason for hiding this comment

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

Just some description prose cleanup.

src/schemas/scopes/jsx.schema.json Outdated Show resolved Hide resolved
src/schemas/scopes/jsx.schema.json Outdated Show resolved Hide resolved
src/schemas/scopes/npm.schema.json Outdated Show resolved Hide resolved
src/schemas/transistor-config.schema.json Outdated Show resolved Hide resolved
src/schemas/transistor-config.schema.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
src/schemas/Schema.ts Outdated Show resolved Hide resolved
src/schemas/Schema.ts Outdated Show resolved Hide resolved
src/schemas/transistor-config.schema.json Outdated Show resolved Hide resolved
Copy link
Collaborator

@mattrosno mattrosno left a comment

Choose a reason for hiding this comment

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

Comments in Schema.ts LGTM.

francinelucca and others added 6 commits August 4, 2023 10:03
Co-authored-by: Joe Harvey <51208233+jdharvey-ibm@users.noreply.github.com>
Co-authored-by: Joe Harvey <51208233+jdharvey-ibm@users.noreply.github.com>
Co-authored-by: Joe Harvey <51208233+jdharvey-ibm@users.noreply.github.com>
src/schemas/Schema.ts Outdated Show resolved Hide resolved
Co-authored-by: Joe Harvey <51208233+jdharvey-ibm@users.noreply.github.com>
@francinelucca francinelucca merged commit 75c20e4 into main Aug 4, 2023
2 checks passed
@francinelucca francinelucca deleted the feat/schema branch August 4, 2023 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants