Skip to content

[CLI/core] custom compilers #321

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

Merged
merged 2 commits into from
Sep 15, 2020
Merged

Conversation

relu91
Copy link
Member

@relu91 relu91 commented Sep 9, 2020

This PR add supports for custom compilers in the Servient runtime. Currently, I tested only ts-node but in principle also others might work. I managed to run this simple script inside node-wot:

/// <reference types="../types/wot" />

WoT.produce({}).then( (thing:WoT.ExposedThing) => {
    console.log(thing.getThingDescription().id)
})

to run it: npm i ts-node && wot-servient --compiler ts-node main.ts

Notice: I used wam typescript project template (i.e. custom type definitions) and I needed to use /// <reference types="../types/wot" /> (see point 2 below).

.However, there still a couple of open points:

  1. cli.ts is getting pretty messy. I think It wasn't originally designed to be a simple interface, now it is evolved in a quite complex command-line tool. Probably it needs a refactor.
  2. typescript examples still not work. The problem is how ts-node handles types (see here) and how we defined our API type definitions. There still an open issue on the scripting-api repo so I did not go ahead and I'll wait until we make a final decision there.
  3. if this PR will be merged, PR fix(cli): allow loading of files transpiled from typescript #240 is obsolete.

@danielpeintner
Copy link
Member

@relu91 thank you for your work!

Some thoughts below

  • typescript examples still not work. The problem is how ts-node handles types (see here) and how we defined our API type definitions. There still an open issue on the scripting-api repo so I did not go ahead and I'll wait until we make a final decision there.

This is sad :-(

I think the overall issue #171 is just half-solved. I think there are more aspects:

  1. allow loading transpiled TS files directly -> solved
  2. Unfortunately the _original TS file is not supported (which would be the ultimate/ideal solution)
  3. (related to 2.) we still should have an automated approach to transpile TS to JavaScript

Anyway I am OK with merging this improvement.
@sebastiankb @egekorkan do you have any concerns doing so?

@relu91
Copy link
Member Author

relu91 commented Sep 10, 2020

This is sad :-(

I know 😢 , I did my best to solve the issue but, finally, I didn't have the time to find a good solution.

I think the overall issue #171 is just half-solved. I think there are more >aspects:

  1. allow loading transpiled TS files directly -> solved

  2. Unfortunately the _original TS file is not supported (which would be the ultimate/ideal solution)

  3. (related to 2.) we still should have an automated approach to transpile TS to JavaScript

allow loading transpiled TS files directly -> solved
Unfortunately the _original TS file is not supported (which would be the ultimate/ideal solution)
(related to 2.) we still should have an automated approach to transpile TS to JavaScript

Right, the issue is still open. I think that fixing the typings might help. If we do not need to import wot-typescript-definitions then we don't have in the output file those lines:

Object.defineProperty(exports, "__esModule", { value: true }); // maybe this will stay
require("wot-typescript-definitions");
let WoT;
let WoTHelpers;

Then in ts-node, we could use typesRoot option which removes the requirement for /// .

Anyway I am OK with merging this improvement.

Thanks, one step at a time and we'll get there 👍

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