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

Changed templating-tools to require uglify-js from NPM #234

Merged
merged 19 commits into from Feb 25, 2017
Merged
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 packages/spacebars-compiler/.npm/package/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
7 changes: 7 additions & 0 deletions packages/spacebars-compiler/.npm/package/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This directory and the files immediately inside it are automatically generated
when you change this package's NPM dependencies. Commit the files in this
directory (npm-shrinkwrap.json, .gitignore, and this README) to source control
so that others run the same versions of sub-dependencies.

You should NOT check in the node_modules directory that Meteor automatically
creates; if you are using git, the .gitignore file tells git to ignore it.
94 changes: 94 additions & 0 deletions packages/spacebars-compiler/.npm/package/npm-shrinkwrap.json

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

6 changes: 5 additions & 1 deletion packages/spacebars-compiler/compile_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ Tinytest.add("spacebars-compiler - compiler output", function (test) {
// but let's at least do some sort of test without it.
// These regexes may have to be adjusted if new tests are added.

// ======================== !!NOTE!! =================================
// Since we are bringing uglify-js in from NPM, this code should no
// longer ever be needed. Leaving it just in case.
// ==================================+================================

// Remove single-line comments, including line nums from build system.
string = string.replace(/\/\/.*$/mg, '');
string = string.replace(/\s+/g, ''); // kill whitespace
Expand All @@ -47,7 +52,6 @@ coffee = {
runCompilerOutputTests: null // implemented in compiler_output_tests.coffee
};


Tinytest.add("spacebars-compiler - compiler errors", function (test) {

var getError = function (input) {
Expand Down
35 changes: 17 additions & 18 deletions packages/spacebars-compiler/compiler.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var UglifyJSMinify = Npm.require('uglify-js').minify;

SpacebarsCompiler.parse = function (input) {

Expand Down Expand Up @@ -95,22 +96,20 @@ SpacebarsCompiler.codeGen = function (parseTree, options) {
};

SpacebarsCompiler._beautify = function (code) {
if (Package['minifier-js'] && Package['minifier-js'].UglifyJSMinify) {
var result = Package['minifier-js'].UglifyJSMinify(
code,
{ fromString: true,
mangle: false,
compress: false,
output: { beautify: true,
indent_level: 2,
width: 80 } });
var output = result.code;
// Uglify interprets our expression as a statement and may add a semicolon.
// Strip trailing semicolon.
output = output.replace(/;$/, '');
return output;
} else {
// don't actually beautify; no UglifyJS
return code;
}
var result = UglifyJSMinify(code, {
fromString: true,
mangle: false,
compress: false,
output: {
beautify: true,
indent_level: 2,
width: 80
}
});

var output = result.code;
// Uglify interprets our expression as a statement and may add a semicolon.
// Strip trailing semicolon.
output = output.replace(/;$/, '');
return output;
};
13 changes: 9 additions & 4 deletions packages/spacebars-compiler/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ Package.describe({

Package.onUse(function (api) {
api.use('underscore@1.0.9');
// The templating plugin will pull in minifier-js, so that generated code will
// be beautified. But it's a weak dependency so that eg boilerplate-generator
// doesn't pull in the minifier.
api.use('minifier-js@1.2.14', ['server'], { weak: true });

api.export('SpacebarsCompiler');

Expand All @@ -25,6 +21,11 @@ Package.onUse(function (api) {
'codegen.js',
'compiler.js'
]);

// Pull in uglify-js from NPM
Npm.depends({
'uglify-js': '2.7.5'
});
});

Package.onTest(function (api) {
Expand All @@ -46,4 +47,8 @@ Package.onTest(function (api) {
'compile_tests.js',
'compiler_output_tests.coffee'
]);

Npm.depends({
'uglify-js': '2.7.5'
})
});