Skip to content

Create TS types in mage build#196

Closed
jfsiii wants to merge 3 commits intoelastic:masterfrom
jfsiii:ts-types
Closed

Create TS types in mage build#196
jfsiii wants to merge 3 commits intoelastic:masterfrom
jfsiii:ts-types

Conversation

@jfsiii
Copy link

@jfsiii jfsiii commented Jan 15, 2020

Uses https://github.com/OneOfOne/struct2ts to generate types.d.ts file from util.Package struct.

Added the minimum features required to support consuming the TS types in EPM. We can build on this with a proper build/release/publish process, new/improved types, etc.

Will add more notes inline.

Created a PR in EPM elastic/kibana#54955 which consumes these types

closes #195

Use github.com/OneOfOne/struct2ts to generate `types.d.ts` file from `util.Package` struct.
@jfsiii jfsiii requested a review from ruflin January 15, 2020 19:31
@@ -0,0 +1,2 @@
"use strict";
Copy link
Author

Choose a reason for hiding this comment

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

Added the bare minimum required to get EPM to be able to import '@elastic/package-registry'.

This is the result when did things The Right Way locally and avoids bringing in TypeScript, running tsc --declaration ..., etc each time.

We can move to that later. For now, new golang structs will still be written to types.d.ts and available to consumers just by running mage build

"description": "Elastic Package Registry (EPR)",
"repository": "git@github.com:elastic/package-registry.git",
"author": " Nicolas Ruflin <spam@ruflin.com>",
"license": "Elastic-License",
Copy link
Author

Choose a reason for hiding this comment

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

npm/yarn print a warning because this is not available in the SPDX License List. Perhaps we could create a PR to be included. Mongo's SSPL is in the list

Copy link
Collaborator

Choose a reason for hiding this comment

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

Or we make the definition itself Apache licensed?

Copy link
Author

Choose a reason for hiding this comment

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

Maybe when/if we split types out to their own project/repo. Or we should change the name/files. This is called @elastic/package-registry and actually brings in all the other repo files so the Elastic license is appropriate for what it's currently doing.

Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@@ -0,0 +1,10 @@
{
"name": "@elastic/package-registry",
"version": "0.2.0",
Copy link
Author

Choose a reason for hiding this comment

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

Ideally this would be linked to the version in BuildRootFile so they're always the same

Copy link
Collaborator

Choose a reason for hiding this comment

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

We probably will have to generate it. Or does it allow linking here?

Copy link
Author

Choose a reason for hiding this comment

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

What I was imagining was BuildRootFile would read package.json to get the version.

package.json would be managed with npm version command or something similar.

The root file would remain synced and the build script doesn't have to take on knowledge of building another artifact.

Version would gain a source of truth that can be read by other tools instead of being inside a script.

Copy link
Collaborator

Choose a reason for hiding this comment

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

+1 on having it in a file. I wonder if package.json is the right place for it considering it is a Golang tool, but in the end it is just JSON, so ... Will figure it out as soon as we automate it.

package.json Outdated
"repository": "git@github.com:elastic/package-registry.git",
"author": " Nicolas Ruflin <spam@ruflin.com>",
"license": "Elastic-License",
"types": "./types.d.ts",
Copy link
Author

Choose a reason for hiding this comment

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

This is the file written by BuildTypesFile. It's currently possible to update the magefile and break the package but I left that linking for a later phase.

@jfsiii jfsiii changed the title Create TS types in mage build #195 Create TS types in mage build closes #195 Jan 15, 2020
@jfsiii jfsiii changed the title Create TS types in mage build closes #195 Create TS types in mage build Jan 15, 2020
Copy link
Collaborator

@ruflin ruflin left a comment

Choose a reason for hiding this comment

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

Left a few question. Code in general LGTM.

I think at one stage we will move the "definition" of a package outside the registry itself and these files will go with it. But for now good to have it all in one place.

@@ -0,0 +1,10 @@
{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need this on the top level? I would prefer to not have generated files in the root.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, package.json needs to be at the root.

I don't think this is a generated file. Or at least it doesn't change as the result of a mage command, for example.

Copy link
Collaborator

Choose a reason for hiding this comment

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

having package.json at the root SGTM

"description": "Elastic Package Registry (EPR)",
"repository": "git@github.com:elastic/package-registry.git",
"author": " Nicolas Ruflin <spam@ruflin.com>",
"license": "Elastic-License",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Or we make the definition itself Apache licensed?

@@ -0,0 +1,59 @@
// this file was automatically generated, DO NOT EDIT
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't like the location of this file. Could we put it with package under npm or js or a similar directory?

Copy link
Author

Choose a reason for hiding this comment

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

I initially put it in docs because I forgot the second part of this comment. I just moved it to a new types directory.

@@ -0,0 +1,2 @@
"use strict";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also going into a sub directory?

Copy link
Author

Choose a reason for hiding this comment

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

same as #196 (comment)

Copy link
Collaborator

@ruflin ruflin left a comment

Choose a reason for hiding this comment

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

Change LGTM. Could you add a changelog entry?

"description": "Elastic Package Registry (EPR)",
"repository": "git@github.com:elastic/package-registry.git",
"author": " Nicolas Ruflin <spam@ruflin.com>",
"license": "Elastic-License",
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@@ -0,0 +1,10 @@
{
"name": "@elastic/package-registry",
"version": "0.2.0",
Copy link
Collaborator

Choose a reason for hiding this comment

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

We probably will have to generate it. Or does it allow linking here?

@@ -0,0 +1,10 @@
{
Copy link
Collaborator

Choose a reason for hiding this comment

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

having package.json at the root SGTM

"author": " Nicolas Ruflin <spam@ruflin.com>",
"license": "Elastic-License",
"types": "./types/types.d.ts",
"main": "./types/types.js"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see we have the path specified here. So if we ever move it around in the repo, we can just update it here 👍

@ruflin
Copy link
Collaborator

ruflin commented Apr 27, 2020

@jfsiii What should we do with this PR? Should we close it for now or get it in?

@ph
Copy link

ph commented May 25, 2020

@jfsiii @ruflin should we close this?

@ruflin
Copy link
Collaborator

ruflin commented May 26, 2020

This ties into elastic/kibana#54955 (comment) Same suggestion, close it but have an issue in Kibana that tracks this idea and also references both PR's.

@ruflin
Copy link
Collaborator

ruflin commented Jun 10, 2020

Closing this PR for now. I think #490 will also be helpful here.

@ruflin ruflin closed this Jun 10, 2020
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.

Generate/publish Typescript types

3 participants