-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[CS2] Add webpack support #4501
Changes from 12 commits
78ae25e
6cde4b5
665eba1
ca93686
882ff5c
eb8ef8e
45cbdd7
c8df38f
ffac681
def9e25
298bb21
6ab07aa
4bea2c0
e68a622
e776d78
62a9315
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
fs = require 'fs' | ||
os = require 'os' | ||
path = require 'path' | ||
_ = require 'underscore' | ||
{ spawn, exec, execSync } = require 'child_process' | ||
|
@@ -51,14 +52,8 @@ run = (args, callback) -> | |
buildParser = -> | ||
helpers.extend global, require 'util' | ||
require 'jison' | ||
parser = require('./lib/coffeescript/grammar').parser.generate() | ||
# Patch Jison’s output, until https://github.com/zaach/jison/pull/339 is accepted, | ||
# to ensure that require('fs') is only called where it exists. | ||
parser = parser.replace "var source = require('fs')", """ | ||
var source = ''; | ||
var fs = require('fs'); | ||
if (typeof fs !== 'undefined' && fs !== null) | ||
source = fs""" | ||
# We don't need `moduleMain`, since the parser is unlikely to be run standalone. | ||
parser = require('./lib/coffeescript/grammar').parser.generate(moduleMain: ->) | ||
fs.writeFileSync 'lib/coffeescript/parser.js', parser | ||
|
||
buildExceptParser = (callback) -> | ||
|
@@ -135,7 +130,7 @@ task 'build:browser', 'merge the built scripts into a single file for use in a b | |
var CoffeeScript = function() { | ||
function require(path){ return require[path]; } | ||
#{code} | ||
return require['./coffeescript']; | ||
return require['./browser']; | ||
}(); | ||
|
||
if (typeof define === 'function' && define.amd) { | ||
|
@@ -368,7 +363,7 @@ task 'bench', 'quick benchmark of compilation time', -> | |
|
||
# Run the CoffeeScript test suite. | ||
runTests = (CoffeeScript) -> | ||
CoffeeScript.register() | ||
CoffeeScript.register() unless global.testingBrowser | ||
startTime = Date.now() | ||
|
||
# These are attached to `global` so that they’re accessible from within | ||
|
@@ -440,3 +435,17 @@ task 'test:browser', 'run the test suite against the merged browser script', -> | |
(-> eval source).call result | ||
testResults = runTests result.CoffeeScript | ||
process.exit 1 unless testResults | ||
|
||
task 'test:webpack', 'run webpack test', -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than this be its own Cake task, can you create a The top of the file should have |
||
args = [ | ||
"./node_modules/webpack/bin/webpack.js" | ||
"--entry=./lib/coffeescript/browser.js", | ||
"--output-path=#{os.tmpdir()}", | ||
"--output-filename=coffeescript.js" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can Webpack be configured to output to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See https://github.com/webpack/docs/wiki/webpack-for-browserify-users#usage.
|
||
] | ||
|
||
console.log 'webpack', args.slice(1).join(' ') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please avoid |
||
|
||
spawnNodeProcess args, 'both', (status) -> | ||
console.log "webpack exits with #{status}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the context of the test file, this should be |
||
process.exit(status) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please end all files with a newline. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
# `text/coffeescript` script tags, source maps via data-URLs, and so on. | ||
|
||
CoffeeScript = require './coffeescript' | ||
CoffeeScript.require = require | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for catching this. |
||
compile = CoffeeScript.compile | ||
|
||
# Use standard JavaScript `eval` to eval code. | ||
|
@@ -18,11 +17,15 @@ CoffeeScript.run = (code, options = {}) -> | |
options.shiftLine = on | ||
Function(compile code, options)() | ||
|
||
# If we're not in a browser environment, we're finished with the public API. | ||
# Export this more limited `CoffeeScript` than what is exported by | ||
# `index.coffee`, which is intended for a Node environment. | ||
module.exports = CoffeeScript | ||
|
||
# If we’re not in a browser environment, we’re finished with the public API. | ||
return unless window? | ||
|
||
# Include source maps where possible. If we've got a base64 encoder, a | ||
# JSON serializer, and tools for escaping unicode characters, we're good to go. | ||
# Include source maps where possible. If we’ve got a base64 encoder, a | ||
# JSON serializer, and tools for escaping unicode characters, we’re good to go. | ||
# Ported from https://developer.mozilla.org/en-US/docs/DOM/window.btoa | ||
if btoa? and JSON? | ||
compile = (code, options = {}) -> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain this? Why
browser
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for logic consistency. Since
browser.js
is already used as the entry for bower and webpack. It could avoid unnecessary confusion to use it for all browser related situations.