question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nice work @fabiandev; I’m really excited to test this out at some point!

Anyway, just throwing this idea out there in case you or anyone else have time for it at some point: a webpack plugin to automatically handle inserting the import into each source file and building with tsr.

In addition to making it a lot simpler to get started by piggybacking on existing tooling, this would abstract away most of the work required for integrations like https://github.com/angular/angular-cli/issues/6763 (at least for non-prod builds; some extra work might be needed to integrate tsr into Angular’s AOT compiler).

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:2
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
fabiandevcommented, Jun 22, 2017

Okay, great!

Just to make it clearer, when transforming a file with the following code:

let a: string;

this is what you get by default:

import './tsr-declarations';
import _t from 'ts-runtime/lib';

let _aType = _t.string(), a;

What I’ll have to change is, that tsr-declarations.js should not be imported/emitted if it is empty. However, it may be turned off in any case with --excludeDeclarationFile via the CLI. Also it should be possible to opt out of the ts-runtime/lib import, I think.

Just noticed, that I will also have to align the CLI options with the API options. The project is still work in progress, but I’m glad for any feedback or issues spotted 😃

0reactions
Venryxcommented, Sep 30, 2020

I’m considering working on this some myself, though am not sure yet whether the complexity level makes it feasible for me to complete with the motivation level I have.

In any case, I thought I’d join the conversation, and try to get a picture on what challenges are left to solve for a proper webpack loader to be created.

Regarding:

The second issue being I dont know if I can properly escape all valid javascript into a query parameter.

Couldn’t you simply encode each character in the Javascript code into its number/character-code, separated by some known-safe character?

For example:

function EncodeAsQuerySafeString(code) {
    const codeAsNumbers = code.split("").map(ch=>ch.charCodeAt(0));
    return codeAsNumbers.join(",");
}
EncodeAsQuerySafeString("alert('test1');");
// result: "97,108,101,114,116,40,39,116,101,115,116,49,39,41,59"

And to decode:

function DecodeQuerySafeString(str) {
    return str.split(",").map(charCode=>String.fromCharCode(charCode)).join("");
}
DecodeQuerySafeString("97,108,101,114,116,40,39,116,101,115,116,49,39,41,59");
// result: "alert('test1');"

EDIT: You should also be able to use base64 encoding, which is more compact: https://stackoverflow.com/a/2820329/2441655

Read more comments on GitHub >

github_iconTop Results From Across the Web

Plugins - webpack
A webpack plugin is a JavaScript object that has an apply method. This apply method is called by the webpack compiler, giving access...
Read more >
Plugins - webpack
webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable...
Read more >
Plugins - webpack
The plugins option is used to customize the webpack build process in a variety of ways. Webpack comes with a variety built-in plugins...
Read more >
Writing a Plugin - webpack
webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable...
Read more >
InstallWebpackPlugin | webpack
webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found