chore: update webpack and babel

This commit is contained in:
Nils Knappmeier
2019-11-24 00:03:02 +01:00
parent 1ade5a0892
commit 9888569dcb
14 changed files with 5123 additions and 1433 deletions
+2
View File
@@ -0,0 +1,2 @@
dist
node_modules
+2 -1
View File
@@ -1,7 +1,8 @@
module.exports = {
"extends": ["eslint:recommended","plugin:compat/recommended"],
"globals": {
"self": false
"self": false,
"SOURCE_MAPS": true
},
"env": {
"node": true,
+7 -74
View File
@@ -43,16 +43,17 @@ module.exports = function(grunt) {
]
}
},
webpack: {
build: require('./webpack.config')
},
babel: {
options: {
sourceMaps: 'inline',
loose: ['es6.modules'],
auxiliaryCommentBefore: 'istanbul ignore next'
},
amd: {
options: {
modules: 'amd'
plugins: ['@babel/plugin-transform-modules-amd']
},
files: [{
expand: true,
@@ -64,7 +65,7 @@ module.exports = function(grunt) {
cjs: {
options: {
modules: 'common'
plugins: ['@babel/plugin-transform-modules-commonjs']
},
files: [{
cwd: 'lib/',
@@ -74,72 +75,6 @@ module.exports = function(grunt) {
}]
}
},
webpack: {
options: {
context: __dirname,
module: {
loaders: [
// the optional 'runtime' transformer tells babel to require the runtime instead of inlining it.
{ test: /\.jsx?$/, exclude: /node_modules/, loader: 'babel-loader?optional=runtime&loose=es6.modules&auxiliaryCommentBefore=istanbul%20ignore%20next' }
]
},
output: {
path: 'dist/',
library: 'Handlebars',
libraryTarget: 'umd'
}
},
handlebars: {
entry: './lib/handlebars.js',
output: {
filename: 'handlebars.js'
}
},
runtime: {
entry: './lib/handlebars.runtime.js',
output: {
filename: 'handlebars.runtime.js'
}
}
},
requirejs: {
options: {
optimize: 'none',
baseUrl: 'dist/amd/'
},
dist: {
options: {
name: 'handlebars',
out: 'dist/handlebars.amd.js'
}
},
runtime: {
options: {
name: 'handlebars.runtime',
out: 'dist/handlebars.runtime.amd.js'
}
}
},
uglify: {
options: {
mangle: true,
compress: true,
preserveComments: /(?:^!|@(?:license|preserve|cc_on))/
},
dist: {
files: [{
cwd: 'dist/',
expand: true,
src: ['handlebars*.js', '!*.min.js'],
dest: 'dist/',
rename: function(dest, src) {
return dest + src.replace(/\.js$/, '.min.js');
}
}]
}
},
concat: {
tests: {
@@ -221,20 +156,18 @@ module.exports = function(grunt) {
'node',
'globals']);
this.registerTask('amd', ['babel:amd', 'requirejs']);
this.registerTask('amd', ['babel:amd']);
this.registerTask('node', ['babel:cjs']);
this.registerTask('globals', ['webpack']);
this.registerTask('tests', ['concat:tests']);
this.registerTask('release', 'Build final packages', ['eslint', 'amd', 'uglify', 'test:min', 'copy:dist', 'copy:components', 'copy:cdnjs']);
this.registerTask('release', 'Build final packages', ['eslint', 'amd', 'test:min', 'copy:dist', 'copy:components', 'copy:cdnjs']);
// Load tasks from npm
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-requirejs');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-babel');
grunt.loadNpmTasks('grunt-bg-shell');
+7
View File
@@ -0,0 +1,7 @@
module.exports = function(api) {
api.cache(false);
return {
presets: ['@babel/preset-env'],
plugins: ['@babel/plugin-transform-runtime']
};
};
+3 -3
View File
@@ -5,7 +5,7 @@ import * as base from './handlebars/base';
import SafeString from './handlebars/safe-string';
import Exception from './handlebars/exception';
import * as Utils from './handlebars/utils';
import * as runtime from './handlebars/runtime';
import {checkRevision, template, wrapProgram, resolvePartial, invokePartial, noop} from './handlebars/runtime';
import noConflict from './handlebars/no-conflict';
@@ -19,9 +19,9 @@ function create() {
hb.Utils = Utils;
hb.escapeExpression = Utils.escapeExpression;
hb.VM = runtime;
hb.VM = {checkRevision, template, wrapProgram, resolvePartial, invokePartial, noop};
hb.template = function(spec) {
return runtime.template(spec, hb);
return template(spec, hb);
};
return hb;
+3 -8
View File
@@ -1,16 +1,11 @@
/* global define */
import {isArray} from '../utils';
let SourceNode;
try {
/* istanbul ignore next */
if (typeof define !== 'function' || !define.amd) {
// We don't support this in AMD environments. For these environments, we asusme that
// they are running on the browser and thus have no need for the source-map library.
let SourceMap = require('source-map');
SourceNode = SourceMap.SourceNode;
}
// the 'source-map' map package is ignored in 'umd' and 'amd' builds (via webpack-config)
let SourceMap = require('source-map');
SourceNode = SourceMap.SourceNode;
} catch (err) {
/* NOP */
}
+9 -9
View File
@@ -1,4 +1,4 @@
import * as Utils from './utils';
import {extend, escapeExpression} from './utils';
import Exception from './exception';
import {COMPILER_REVISION, createFrame, LAST_COMPATIBLE_COMPILER_REVISION, REVISION_CHANGES} from './base';
import {moveHelperToHooks} from './helpers';
@@ -44,14 +44,14 @@ export function template(templateSpec, env) {
function invokePartialWrapper(partial, context, options) {
if (options.hash) {
context = Utils.extend({}, context, options.hash);
context = extend({}, context, options.hash);
if (options.ids) {
options.ids[0] = true;
}
}
partial = env.VM.resolvePartial.call(this, partial, context, options);
let optionsWithHooks = Utils.extend({}, options, {hooks: this.hooks});
let optionsWithHooks = extend({}, options, {hooks: this.hooks});
let result = env.VM.invokePartial.call(this, partial, context, optionsWithHooks);
@@ -97,7 +97,7 @@ export function template(templateSpec, env) {
return typeof current === 'function' ? current.call(context) : current;
},
escapeExpression: Utils.escapeExpression,
escapeExpression: escapeExpression,
invokePartial: invokePartialWrapper,
fn: function(i) {
@@ -158,13 +158,13 @@ export function template(templateSpec, env) {
ret._setup = function(options) {
if (!options.partial) {
container.helpers = Utils.extend({}, env.helpers, options.helpers);
container.helpers = extend({}, env.helpers, options.helpers);
if (templateSpec.usePartial) {
container.partials = Utils.extend({}, env.partials, options.partials);
container.partials = extend({}, env.partials, options.partials);
}
if (templateSpec.usePartial || templateSpec.useDecorators) {
container.decorators = Utils.extend({}, env.decorators, options.decorators);
container.decorators = extend({}, env.decorators, options.decorators);
}
container.hooks = {};
@@ -258,7 +258,7 @@ export function invokePartial(partial, context, options) {
return fn(context, options);
};
if (fn.partials) {
options.partials = Utils.extend({}, options.partials, fn.partials);
options.partials = extend({}, options.partials, fn.partials);
}
}
@@ -287,7 +287,7 @@ function executeDecorators(fn, prog, container, depths, data, blockParams) {
if (fn.decorator) {
let props = {};
prog = fn.decorator(prog, props, container, depths && depths[0], data, blockParams, depths);
Utils.extend(prog, props);
extend(prog, props);
}
return prog;
}
+15 -10
View File
@@ -33,18 +33,23 @@ export let toString = Object.prototype.toString;
// Sourced from lodash
// https://github.com/bestiejs/lodash/blob/master/LICENSE.txt
/* eslint-disable func-style */
let isFunction = function(value) {
return typeof value === 'function';
};
// fallback for older versions of Chrome and Safari
/* istanbul ignore next */
if (isFunction(/x/)) {
isFunction = function(value) {
return typeof value === 'function' && toString.call(value) === '[object Function]';
export const isFunction = createIsFunction();
function createIsFunction() {
// istanbul ignore next
// eslint-disable-next-line no-constant-condition
if (typeof /x/ === 'function') {
// fallback for older chrome/firefox versions
return function isFunction(value) {
return typeof value === 'function' && toString.call(value) === '[object Function]';
};
}
return function isFunction(value) {
return typeof value === 'function';
};
}
export {isFunction};
/* eslint-enable func-style */
/* istanbul ignore next */
export const isArray = Array.isArray || function(value) {
+1 -1
View File
@@ -1,7 +1,7 @@
/* eslint-disable no-console */
import Async from 'neo-async';
import fs from 'fs';
import * as Handlebars from './handlebars';
import Handlebars from './handlebars';
import {basename} from 'path';
import {SourceMapConsumer, SourceNode} from 'source-map';
+4923 -1317
View File
File diff suppressed because it is too large Load Diff
+11 -8
View File
@@ -29,10 +29,15 @@
"uglify-js": "^3.1.4"
},
"devDependencies": {
"@babel/core": "^7.7.4",
"@babel/plugin-transform-modules-amd": "^7.7.4",
"@babel/plugin-transform-modules-commonjs": "^7.7.4",
"@babel/plugin-transform-runtime": "^7.7.4",
"@babel/preset-env": "^7.7.4",
"@babel/runtime": "^7.7.4",
"@knappi/grunt-saucelabs": "^9.0.2",
"aws-sdk": "^2.1.49",
"babel-loader": "^5.0.0",
"babel-runtime": "^5.1.10",
"babel-loader": "^8.0.6",
"benchmark": "~1.0",
"chai": "^4.2.0",
"dirty-chai": "^2.0.1",
@@ -42,18 +47,16 @@
"eslint-plugin-compat": "^3.3.0",
"eslint-plugin-es5": "^1.4.1",
"grunt": "^1.0.3",
"grunt-babel": "^5.0.0",
"grunt-babel": "^8.0.0",
"grunt-bg-shell": "^2.3.3",
"grunt-cli": "^1",
"grunt-contrib-clean": "^1",
"grunt-contrib-concat": "^1",
"grunt-contrib-connect": "^1",
"grunt-contrib-copy": "^1",
"grunt-contrib-requirejs": "^1",
"grunt-contrib-uglify": "^1",
"grunt-contrib-watch": "^1.1.0",
"grunt-eslint": "^20.1.0",
"grunt-webpack": "^1.0.8",
"grunt-webpack": "^3.1.3",
"istanbul": "^0.3.0",
"jison": "~0.3.0",
"mocha": "^5",
@@ -63,8 +66,8 @@
"sinon": "^7.5.0",
"typescript": "^3.4.3",
"underscore": "^1.5.1",
"webpack": "^1.12.6",
"webpack-dev-server": "^1.12.1"
"webpack": "^4.41.2",
"webpack-dev-server": "^3.9.0"
},
"main": "lib/index.js",
"types": "types/index.d.ts",
+5 -1
View File
@@ -39,7 +39,11 @@ if (global.minimizedTest) {
function run(env, callback) {
if (errors > 0) {
throw new Error('Errors have been detected before');
}
var mocha = new Mocha();
mocha.bail();
mocha.ui('bdd');
mocha.files = files.slice();
if (grep) {
@@ -54,6 +58,6 @@ function run(env, callback) {
require(env);
mocha.run(function(errorCount) {
errors += errorCount;
callback();
callback();
});
}
+1 -1
View File
@@ -22,7 +22,7 @@ vm.runInThisContext(fs.readFileSync(__dirname + '/../../' + filename), filename)
var parse = require('../../dist/cjs/handlebars/compiler/base').parse;
var compiler = require('../../dist/cjs/handlebars/compiler/compiler');
var JavaScriptCompiler = require('../../dist/cjs/handlebars/compiler/javascript-compiler');
var JavaScriptCompiler = require('../../dist/cjs/handlebars/compiler/javascript-compiler')['default'];
global.CompilerContext = {
browser: true,
+134
View File
@@ -0,0 +1,134 @@
const path = require('path');
const webpack = require('webpack');
const assert = require('assert');
module.exports = [
createBuild({
name: 'umd-compiler-runtime',
entry: './lib/handlebars.js',
output: buildUmdOutput('handlebars.js'),
shouldHandlebarsSupportSourceMaps: false,
minimize: false
}),
createBuild({
name: 'umd-compiler-runtime-min',
entry: './lib/handlebars.js',
output: buildUmdOutput('handlebars.min.js'),
shouldHandlebarsSupportSourceMaps: false,
minimize: true
}),
createBuild({
name: 'umd-runtime',
entry: './lib/handlebars.runtime.js',
output: buildUmdOutput('handlebars.runtime.js'),
shouldHandlebarsSupportSourceMaps: false,
minimize: false
}),
createBuild({
name: 'umd-runtime',
entry: './lib/handlebars.runtime.js',
output: buildUmdOutput('handlebars.runtime.min.js'),
shouldHandlebarsSupportSourceMaps: false,
minimize: true
}),
createBuild({
name: 'amd-compiler-runtime',
entry: './lib/handlebars.js',
output: buildAmdOutput('handlebars.amd.js'),
shouldHandlebarsSupportSourceMaps: false,
minimize: false
}),
createBuild({
name: 'amd-compiler-runtime-min',
entry: './lib/handlebars.js',
output: buildAmdOutput('handlebars.amd.min.js'),
shouldHandlebarsSupportSourceMaps: false,
minimize: true
}),
createBuild({
name: 'amd-runtime',
entry: './lib/handlebars.runtime.js',
output: buildAmdOutput('handlebars.runtime.amd.js'),
shouldHandlebarsSupportSourceMaps: false,
minimize: false
}),
createBuild({
name: 'amd-runtime-min',
entry: './lib/handlebars.runtime.js',
output: buildAmdOutput('handlebars.runtime.amd.min.js'),
shouldHandlebarsSupportSourceMaps: false,
minimize: true
})
];
function createBuild({name, entry, shouldHandlebarsSupportSourceMaps, output, minimize}) {
assert(output != null);
assert(name != null);
assert(entry != null);
assert(shouldHandlebarsSupportSourceMaps != null);
assert(minimize != null);
return {
name,
module: {
rules: [
{
test: /\.m?js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
}
]
},
plugins: buildPluginConfig(shouldHandlebarsSupportSourceMaps),
mode: 'production',
devtool: false,
optimization: {
minimize
},
entry,
output
};
}
function buildPluginConfig(shouldHandlebarsSupportSourceMaps) {
const plugins = [];
if (!shouldHandlebarsSupportSourceMaps) {
plugins.push(
new webpack.IgnorePlugin({
resourceRegExp: /source-map/
})
);
}
return plugins;
}
function buildAmdOutput(outputFile) {
return {
path: path.resolve(__dirname, 'dist'),
library: 'Handlebars',
libraryTarget: 'amd',
filename: outputFile,
globalObject: 'this',
sourceMapFilename: '[file].map',
libraryExport: 'default'
};
}
function buildUmdOutput(outputFile) {
return {
path: path.resolve(__dirname, 'dist'),
library: 'Handlebars',
libraryTarget: 'umd',
filename: outputFile,
globalObject: 'this',
sourceMapFilename: '[file].map',
libraryExport: 'default'
};
}