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

Import runtime as modules #1979

Merged
merged 2 commits into from
May 24, 2016
Merged

Import runtime as modules #1979

merged 2 commits into from
May 24, 2016

Conversation

arv
Copy link
Collaborator

@arv arv commented Jul 23, 2015

This is some work in progress for #1628

For --modules=commonjs it allows using require to import the minimal runtime.

The goal is to allow commonjs target to work without any bin/traceur-runtime.js

@johnjbarton Feedback wanted

@@ -299,7 +302,7 @@ git-update-publish: git-gh-rebase

# ---

prepublish: bin/traceur.js bin/traceur-runtime.js
prepublish: bin/traceur.js bin/traceur-runtime.js commonjs-modules
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure where this change came from

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Figured it out... needed to be runtime/

@arv
Copy link
Collaborator Author

arv commented Apr 15, 2016

I'm back working on this. It works pretty good with commonjs already. We are currently publishing runtime modules at traceur/dist/commonjs/runtime/modules/ but these are in commonjs format. We can use traceur/src/runtime/modules/ for es6 modules but that still depends on nodejs resolving the path correctly.

It might be worth publishing a differnt npm package for the runtime once this work is done.

It might also be worth switching to 1.0 and keep versioning correct from then on.

@arv arv force-pushed the export-as-runtime branch 2 times, most recently from b5da773 to 0520814 Compare April 23, 2016 20:51
@arv arv changed the title Export as runtime Import runtime as modules Apr 23, 2016
@arv
Copy link
Collaborator Author

arv commented Apr 23, 2016

@johnjbarton This is now ready for review

!options.transformOptions.blockBinding ? CONST : VAR;
}

export default function ImportRuntimeTrait(ParseTreeTransformerClass) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gather that this Trait will prepend runtime imports iff option is true (obvious) and the ParseTreeTransformerClass needs the import as indicated by tree !== transformed. The latter is not obvious so I think a comment here or in the top level transform functions would help,

@johnjbarton
Copy link
Contributor

LGTM very cool

@arv
Copy link
Collaborator Author

arv commented Apr 25, 2016

I actually think I need some tests =P

Initially I thought of compiling the feature tests over to a temp directory and then run mocha on that. However, this does not work because different test files have different compile options. If we had rc files #2101 we could move the options out of the headers and into those and then restructure the tests... but that would not work well for in browser tests...

Any ideas?

@johnjbarton
Copy link
Contributor

If you can self-build with the option and w/o the script runtime, then featureTestRunner could check for the global $traceurRuntime (or perhaps some non-trivial properties) and run the tests with the import runtime option added. This execution of the featureTestRunner would not have $traceurRuntime that the tests would see and each time we transformers we would import the runtime needed. So all of the cases would be covered and only one additional run of the suite would be needed (vs lots of compile commands).

@arv
Copy link
Collaborator Author

arv commented Apr 28, 2016

One simple option would be to compile all files in test/features if and only if they do not have an // Options: comment. Then we know that the options we should compile with is the default option. This gives a partial coverage but it might be good enough.

@googlebot
Copy link
Collaborator

We found a Contributor License Agreement for you (the sender of this pull request) and all commit authors, but as best as we can tell these commits were authored by someone else. If that's the case, please add them to this pull request and have them confirm that they're okay with these commits being contributed to Google. If we're mistaken and you did author these commits, just reply here to confirm.

@googlebot
Copy link
Collaborator

CLAs look good, thanks!

@arv
Copy link
Collaborator Author

arv commented May 17, 2016

Almost there with tests. Two failing test; #2118 and something related to __moduleName that I haven't grokked yet.

@arv
Copy link
Collaborator Author

arv commented May 18, 2016

@johnjbarton PTAL

The test should pass when #2120 is merged.

When using `--modules=commonjs --import-runtime` or
`--modules=parse --import-runtime` the generated code will output
require/import statements that import the runtime function as a module.
This means that if you are compiling to commonjs or es6 modules you
can get a minimal runtime and no external runtime file is needed.

Fixes google#1628
@arv
Copy link
Collaborator Author

arv commented May 21, 2016

@johnjbarton

Now with (partial) tests. The tests run mocha --compilers=js:test/cjs-mocha-compiler.js which compiles the files on the fly using --modules=commonjs --import-runtime. This "compiler" wraps the feature test in a mocha test function.

I think this (most long runnning PR in Traceur's history) is ready to land if you want to take a final look.

@@ -118,6 +119,10 @@ test/features: bin/traceur.js bin/traceur-runtime.js $(FEATURE_TESTS)
test/%-run: test/% bin/traceur.js
node_modules/.bin/mocha $(MOCHA_OPTIONS) $<

test/mocha: bin/traceur.js
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe test/module-compiled ? Since we use mocha through out...

@johnjbarton
Copy link
Contributor

LGTM

@arv arv merged commit 4065edc into google:master May 24, 2016
@arv arv deleted the export-as-runtime branch May 24, 2016 00:47
@arv
Copy link
Collaborator Author

arv commented May 24, 2016

Oops, I forgot to update the make rule name... fix coming asap

arv added a commit to arv/traceur-compiler that referenced this pull request May 24, 2016
arv added a commit that referenced this pull request May 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants