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
Please document how to generate a commonJS/systemJS/AMD JS module from python using transcrypt for loading using require.js or node/etc. #495
Comments
I don't currently don't know enough from JS module systems to describe this properly. |
I know enough (I think :) to write it up. However, there are a couple things that transcrypt needs before it can happen.
From what I can see, the two above items are everything needed to make module creation happen. |
On Thu, 08 Mar 2018 10:10:31 -0800 Conan Albrecht ***@***.***> wrote:
I know enough (I think :) to write it up. However, there are a couple things
that transcrypt needs before it can happen.
1. We need to be able to do JS imports and exports at the top level of the
file. Right now, transcrypt doesn't provide a way to place code outside the
containing function. The JS (ES6) standard for the import statement says it
has to happen *outside* any function--in the main space of the .js file.
2. We need to be able to disable placing the function in the global `window`
object (very last line of the generated JS). In other words, we need to
disable calling the function entirely. Just create the function and let the
`exports` code (that goes in the top level of the file (#1 above) export the
function according to the AMD, CommonJS, etc. ways.
From what I can see, the two above items are everything needed to make module
creation happen.
thanks for the insights, Conan!
…--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
http://www.shlomifish.org/humour/bits/Google-Discontinues-Services/
Yesterday I asked one of my students if she knew what an encyclopedia is, and
she said: “Is it something like Wikipedia?”.
— http://twitter.com/alisonclement/status/8421314259
Please reply to list if it's a mailing list post - http://shlom.in/reply .
|
Could you manually modify a simple, generated JS file, e.g. hello.js (compiled from hello.py in the demos) to lay down exactly what is needed. You can use the |
Will do! |
Wow. So I totally forgot that I already did this with an earlier project and published the plugin on Here's the repo: https://github.com/doconix/autotimers The code is a little different than the common pattern used in JS. Most modules follow this pattern: https://github.com/umdjs/umd/blob/master/templates/returnExports.js. I modified it because using Python code syntax makes it quite a bit simpler and easier. To my view, my code does the exact thing, just with a refactored way. The good news for @JdeH is no changes are needed in Transcrypt. Although I will note that using |
@doconix Do you mean the following point of @shlomif :
So if Transcrypt would offer the possibility to have code before and after the main function definition, that would help, right? |
On Thu, 08 Mar 2018 15:17:33 -0800 Conan Albrecht ***@***.***> wrote:
Wow. So I totally forgot that I already did this with an earlier project and
published the plugin on `npm`. I'm getting old.
Here's the repo: https://github.com/doconix/autotimers
In particular, check out the exports at the bottom of the main file:
https://github.com/doconix/autotimers/blob/master/src/main.py#L117
thanks, Conan! Will it be possible to write a tool to automate this process?
… The code is a little different than the common pattern used in JS. Most
modules follow this pattern: https://github.com/umdjs/umd. I modified it
because using Python code syntax makes it quite a bit simpler and easier. To
my view, my code does the exact thing, just with a refactored way.
The good news for @JdeH is no changes are needed in Transcrypt. Although I
will note that using `npm` modules from Transcrypt code is difficult because
of #1 above. The workaround is to use the deprecated `require()` function.
Since the npm repository seems to be the future of JS modules, it might be a
good thing to support `import` in Transcrypt. The issue deserves its own
page instead of this paragraph, but I'll leave any development at @JdeH
discretion.
--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
https://youtu.be/GoEn1YfYTBM - Tiffany Alvord - “Fall Together”
“The best time to plant a tree was 20 years ago. The second best time is now.”
– A Reported Proverb
Please reply to list if it's a mailing list post - http://shlom.in/reply .
|
Investigating adding ES6 modules to TS. |
Regarding "#1" above, we need to be able to add the The
AFAIK, the following is not valid in JS (although it is just fine in regular python):
|
I see from your SO question that you are working on exporting ES6 modules. That's the right approach to work for. The solution I referenced above (https://github.com/doconix/autotimers/blob/master/src/main.py#L117) implements the "universal module definition". It supports the different methods that have been competing for the last few years: CommonJS, AMD (requirejs), etc. ES6 modules are the result of this competition and is the future. So while my solution works well right now, the way you are going is the standards approach. I should have suggested this rather than the universal one I did. Just wanted to validate where you are headed with it. |
Your solution is very useful, since it addresses the currently popular modules systems. |
That's beautiful. Imports aren't fully into the browsers yet, so that's one possible reason it's difficult. In any case, almost all people working with ES6+ code right now are transpiling back to 5 with webpack, babel, etc. So in my mind, the real question is whether babel can handle the imports. I'm sure you know, but note also that the new Tough to hit a moving target... |
I would definitely love to see the prologue/epilogue pragmas as a stopgap until the ES6 module stuff is done. Any pointers on how I could get started on that? |
I've already built in and removed it again, since it messed up the sourcemaps. (linenumbers are offset).
From the code:
Releasing a pragma suggests it will be a permanent facility, which I want to avoid, because taking it out again will break user code. |
Can someone provide a script or whatever to automate the process as a gist or similar? I don't fully understand what to do. |
@shlomif I scaled down my project and posted to https://github.com/doconix/transcrypt_module/. Please see the src/main.py for the code on making a UMD. This should work with 1) browser, 2) AMD, and 3) CommonJS. I have tested my original project with these three, but I've only had time today to test the first. It should work with all three, though, because the code is essentially the same. Note that this does NOT make the module work with the ES6 standard. UMD and ES6 are not really compatible, from what I see. An ES6 module would need to But in any case, the code I posted will work with today's tech: webpack, gulp, browserify, node, etc. |
Also note that it needs to be built with specific transcrypt options. I created the |
On Tue, 13 Mar 2018 15:11:07 +0000 (UTC) Conan Albrecht ***@***.***> wrote:
@shlomif I scaled down my project and posted to
https://github.com/doconix/transcrypt_module/. Please see the src/main.py
for the code on making a UMD.
many thanks - I shall take a look at it soon.
… This should work with 1) browser, 2) AMD, and 3) CommonJS. I have tested my
original project with these three, but I've only had time today to test the
first. It should work with all three, though, because the code is
essentially the same.
Note that this does NOT make the module work with the ES6 standard. UMD and
ES6 are not really compatible, from what I see. An ES6 module would need to
`export default ...`. I'm not sure if that can be done with Transcrypt yet.
But in any case, the code I posted will work with today's tech: webpack,
gulp, browserify, node, etc.
--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
UNIX Fortune Cookies - http://www.shlomifish.org/humour/fortunes/
Chuck Norris read the entire English Wikipedia in 24 hours. Twice.
— http://www.shlomifish.org/humour/bits/facts/Chuck-Norris/
Please reply to list if it's a mailing list post - http://shlom.in/reply .
|
@doconix : can you please add a LICENSE/etc. file to the repo so it won't be ARR? See https://github.com/shlomif/Freenode-programming-channel-FAQ/blob/master/FAQ.mdwn#i-want-to-release-my-code---which-open-source-licence-should-i-use . I hope I don't seem too needy and picky. |
@shlomif Done |
On Tue, 13 Mar 2018 18:02:09 +0000 (UTC) Conan Albrecht ***@***.***> wrote:
@shlomif Done
awesome, thanks!
…--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
Original Riddles - http://www.shlomifish.org/puzzles/
Barth's Distinction: There are two types of people: those who divide people
into two types, and those who don't.
— via fortune-mod.
Please reply to list if it's a mailing list post - http://shlom.in/reply .
|
@doconix : it looks very good, thanks - I'll let you know what evolves next. |
@doconix : thanks again, the code is now used live at http://fc-solve.shlomifish.org/js-fc-solve/find-deal/ . There still is some polish to be done , but it is not related to transcrypt. |
ES6 modules are now available in the 3.7.1 alpha prerelease. |
On Mon, 09 Apr 2018 07:04:35 -0700 Jacques de Hooge ***@***.***> wrote:
ES6 modules are now available in the 3.7.1.alpha prerelease.
thanks!
…--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
Emma Watson Factoids - http://shlom.in/emwatson-facts
Chuck Norris helps God help those that help themselves.
— http://www.shlomifish.org/humour/bits/facts/Chuck-Norris/
Please reply to list if it's a mailing list post - http://shlom.in/reply .
|
Hi!
Please document how to generate a commonJS/systemJS/AMD JS module from python using transcrypt for loading using require.js or node/etc.
I saw this discussion - #94 - but I do not understand how to do it based on that.
The text was updated successfully, but these errors were encountered: