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

[CS2] Add webpack support #4501

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ test/*.js
parser.output
/node_modules
npm-debug.log*
test/webpack/coffeescript.js
42 changes: 32 additions & 10 deletions Cakefile
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'
Expand Down Expand Up @@ -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) ->
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -440,3 +435,30 @@ 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 'build:webpack', 'build webpack test bundle', ->
args = [
"./node_modules/webpack/bin/webpack.js"
"--entry=./test/webpack/entry.js",
"--output-path=test/webpack",
"--output-filename=coffeescript.js"
]

spawnNodeProcess args, 'both', (status) ->
process.exit(status)

task 'test:webpack', 'run test suite against the webpack test bundle', ->
loader = """
var __exports__ = {};
(function (__exports__) {
#{fs.readFileSync './test/webpack/coffeescript.js'}
})(__exports__)
return __exports__.CoffeeScript;
"""

CoffeeScript = new Function(loader)()

global.testingBrowser = yes

testResults = runTests CoffeeScript
process.exit 1 unless testResults
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "coffeescript",
"main": [
"lib/coffeescript/coffeescript.js"
"lib/coffeescript/browser.js"
],
"description": "Unfancy JavaScript",
"keywords": [
Expand Down
4 changes: 2 additions & 2 deletions lib/coffeescript/browser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/coffeescript/cake.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

129 changes: 6 additions & 123 deletions lib/coffeescript/coffeescript.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/coffeescript/command.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading