Create TS types in mage build#196
Create TS types in mage build#196jfsiii wants to merge 3 commits intoelastic:masterfrom jfsiii:ts-types
mage build#196Conversation
Use github.com/OneOfOne/struct2ts to generate `types.d.ts` file from `util.Package` struct.
| @@ -0,0 +1,2 @@ | |||
| "use strict"; | |||
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Or we make the definition itself Apache licensed?
There was a problem hiding this comment.
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.
| @@ -0,0 +1,10 @@ | |||
| { | |||
| "name": "@elastic/package-registry", | |||
| "version": "0.2.0", | |||
There was a problem hiding this comment.
Ideally this would be linked to the version in BuildRootFile so they're always the same
There was a problem hiding this comment.
We probably will have to generate it. Or does it allow linking here?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
+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", |
There was a problem hiding this comment.
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.
mage build #195mage build closes #195
mage build closes #195mage build
ruflin
left a comment
There was a problem hiding this comment.
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 @@ | |||
| { | |||
There was a problem hiding this comment.
Do we need this on the top level? I would prefer to not have generated files in the root.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
Or we make the definition itself Apache licensed?
| @@ -0,0 +1,59 @@ | |||
| // this file was automatically generated, DO NOT EDIT | |||
There was a problem hiding this comment.
I don't like the location of this file. Could we put it with package under npm or js or a similar directory?
There was a problem hiding this comment.
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"; | |||
There was a problem hiding this comment.
Also going into a sub directory?
ruflin
left a comment
There was a problem hiding this comment.
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", |
| @@ -0,0 +1,10 @@ | |||
| { | |||
| "name": "@elastic/package-registry", | |||
| "version": "0.2.0", | |||
There was a problem hiding this comment.
We probably will have to generate it. Or does it allow linking here?
| @@ -0,0 +1,10 @@ | |||
| { | |||
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
I see we have the path specified here. So if we ever move it around in the repo, we can just update it here 👍
|
@jfsiii What should we do with this PR? Should we close it for now or get it in? |
|
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. |
|
Closing this PR for now. I think #490 will also be helpful here. |
Uses https://github.com/OneOfOne/struct2ts to generate
types.d.tsfile fromutil.Packagestruct.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