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 typescript support #68

Open
sleeyax opened this issue Feb 26, 2020 · 10 comments
Open

Add typescript support #68

sleeyax opened this issue Feb 26, 2020 · 10 comments

Comments

@sleeyax
Copy link
Contributor

sleeyax commented Feb 26, 2020

I have an addon written in typescript that I'd like to run locally. Typescript is nothing more than a superset of javascript that compiles to javascript.

PimpMyStremio could check if an addon repo contains .ts files and compile them before starting the addon.

@sleeyax
Copy link
Contributor Author

sleeyax commented Mar 1, 2020

We could add the ts-loader and typescript dependencies and add the following configuration snippet to the bundler, according to the webpack docs.

 module: {
	rules: [
	  {
		test: /\.ts?$/,
		use: 'ts-loader'
	  },
	],
  },
  resolve: {
	extensions: ['.ts', '.js', '.json'],
  },
...

And then to check if a repo contains a .ts or .js index file:

const entry = path.join(dest, fs.existsSync(path.join(dest, 'index.ts')) ? 'index.ts' : 'index.js')
const bundled = await bundle(repoData.repo, entry, dest, vm.allModules())

I haven't tested this yet, but I think it's a good starting point.

@sleeyax
Copy link
Contributor Author

sleeyax commented Mar 1, 2020

Another option would be to give the programmer the freedom to compile the code to javascript and attach it as an asset on the releases page. Then we could look for a specific asset name (e.g build.zip), so PimpMyStremio can download that instead of downloading the whole source (i.e zipball_url).

This is probably easier to implement, doesn't require additional dependencies and also works with any other transpiler like babel or coffeescript.

The only downside is that the developer could potentially add unwanted (or in the worst case scenario harmful) content to the zipped build.

@sungshon
Copy link
Owner

sungshon commented Mar 5, 2020

The only downside is that the developer could potentially add unwanted (or in the worst case scenario harmful) content to the zipped build.

That's a pretty big downside.. User security should be the priority in all cases, so I can't agree with this..

I would like to support any and all transpilers if possible, but adding them all to PMS might create quite a serious bloat, and then again favoring (or discriminating) a transpiler would be unfair.. I'm really worried about the bloat size here as transpilers and other build tools should normally not be part of released applications, so they may be heavy repositories.

This could obviously also be solved by processing the code before release (to some build folder or something) and prioritising build/index.js (if available) over index.js, yet some devs might not agree with having processed code in their repo..

I'm not entirely sure how to handle this need best.. but everything that causes possible security issues should definitely be avoided. I will think about it..

@sungshon
Copy link
Owner

sungshon commented Mar 5, 2020

I have to say that it breaks my heart that there's an addon out there that isn't in PMS due to transpiling limitations..

@sleeyax
Copy link
Contributor Author

sleeyax commented Mar 5, 2020

I have to say that it breaks my heart that there's an addon out there that isn't in PMS due to transpiling limitations..

Too bad I happen to have 3+ addons for PMS written in TypeScript, stored in a monorepo 😅 (#69 - nice)

@sungshon
Copy link
Owner

sungshon commented Mar 5, 2020

I checked, ts-loader + typescript add 16mb to the weight of the binary, which is about a 13% increase in size.

But PMS is a platform for creators, and u are one such creator. Although imo the best place for transpilers to be used would be before releasing on GitHub, as it would add zero weight and all transpilers are obviously supported that way.. If u say u need this, and you seem to have a good idea about where it should be added already and have addons to test this with, if u make a PR for it, i'll accept it.

@danamag
Copy link
Contributor

danamag commented Mar 11, 2020

So what if we create separate repos for each transpiler:

  • pms-typescript-addons
  • pms-babel-addons
  • ...

With a list of addons and a script. The script could download addons and transpile them, then we could use monorepos to point to each transpiled addon folder.

@sungshon
Copy link
Owner

That can work if @sleeyax thinks it's sufficient. We already have most of the logic to make something like:

  • Set addons in addonsList.json
  • Update addons: lib/addon.js (update and install methods)
  • Webpack addons: lib/bundle.js

We're just missing the monorepos feature.

@sungshon
Copy link
Owner

@danamag I think I added support for monorepos, but did not test it at all. If you have any way of testing, I would appreciate it.

@sleeyax
Copy link
Contributor Author

sleeyax commented Mar 11, 2020

I've made my monorepo public for testing: https://github.com/sleeyax/stremio-addons

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

No branches or pull requests

3 participants