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

Fix bundler issue with webpack 5 #1862

Merged
merged 1 commit into from
May 17, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@
},
"main": "lib/index.js",
"types": "types/index.d.ts",
"browser": {
".": "./dist/cjs/handlebars.js",
"./runtime": "./dist/cjs/handlebars.runtime.js"
},
"browser": "./dist/cjs/handlebars.js",
"bin": {
"handlebars": "bin/handlebars.js"
},
Expand Down
12 changes: 3 additions & 9 deletions tests/integration/webpack-test/package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
{
"name": "webpack-test",
"description": "Various tests with Handlebars and Webpack",
"description": "Various tests with Handlebars and multiple webpack versions",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"build": "webpack --config webpack.config.js",
"test": "node dist/main.js"
},
"private": true,
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {},
"devDependencies": {
"dependencies": {
"handlebars": "file:../../..",
"handlebars-loader": "^1.7.1",
"webpack": "^4.39.3",
"webpack-cli": "^3.3.7"
"handlebars-loader": "^1.7.1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Handlebars from 'handlebars/lib/handlebars';
import { assertEquals } from './lib/assert';

const template = Handlebars.compile('Author: {{author}}');
assertEquals(template({ author: 'Yehuda' }), 'Author: Yehuda');
43 changes: 43 additions & 0 deletions tests/integration/webpack-test/src/handlebars-runtime-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as Handlebars from 'handlebars/runtime';
import { assertEquals } from './lib/assert';

const template = Handlebars.template({
compiler: [8, '>= 4.3.0'],
main: function(container, depth0, helpers, partials, data) {
var helper,
lookupProperty =
container.lookupProperty ||
function(parent, propertyName) {
if (Object.prototype.hasOwnProperty.call(parent, propertyName)) {
return parent[propertyName];
}
return undefined;
};

return (
'Author: ' +
container.escapeExpression(
((helper =
(helper =
lookupProperty(helpers, 'author') ||
(depth0 != null ? lookupProperty(depth0, 'author') : depth0)) !=
null
? helper
: container.hooks.helperMissing),
typeof helper === 'function'
? helper.call(depth0 != null ? depth0 : container.nullContext || {}, {
name: 'author',
hash: {},
data: data,
loc: {
start: { line: 1, column: 8 },
end: { line: 1, column: 18 }
}
})
: helper)
)
);
},
useData: true
});
assertEquals(template({ author: 'Yehuda' }), 'Author: Yehuda');
25 changes: 18 additions & 7 deletions tests/integration/webpack-test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,26 @@

set -e

run_tests () {
for i in dist/*-test.js ; do
echo "----------------------"
echo "-- Running $i"
echo "----------------------"
node "$i"
echo "Success"
done
}

# Cleanup: package-lock and "npm ci" is not working with local dependencies
rm dist package-lock.json -rf
npm install --legacy-peer-deps

# Test with webpack 4
npm install --legacy-peer-deps --no-save webpack@^4 webpack-cli@^3
npm run build
run_tests

for i in dist/*-test.js ; do
echo "----------------------"
echo "-- Running $i"
echo "----------------------"
node "$i"
echo "Success"
done
# Test with webpack 5
npm install --legacy-peer-deps --no-save webpack@^5 webpack-cli@^4
npm run build
run_tests