From 03d387bf8ed7ad5ae078f18a5817ab715429cec3 Mon Sep 17 00:00:00 2001 From: Jakob Linskeseder Date: Thu, 23 Dec 2021 19:57:46 +0100 Subject: [PATCH] Fix rollup warning when importing Handlebars as ESM Closes #1696 --- .github/workflows/ci.yml | 1 + lib/handlebars/internal/proto-access.js | 2 +- tests/integration/rollup-test/.eslintrc.js | 11 +++++++++++ tests/integration/rollup-test/.gitignore | 3 +++ tests/integration/rollup-test/package.json | 14 ++++++++++++++ tests/integration/rollup-test/rollup.config.js | 10 ++++++++++ tests/integration/rollup-test/src/index.js | 8 ++++++++ tests/integration/rollup-test/test.sh | 11 +++++++++++ 8 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 tests/integration/rollup-test/.eslintrc.js create mode 100644 tests/integration/rollup-test/.gitignore create mode 100644 tests/integration/rollup-test/package.json create mode 100644 tests/integration/rollup-test/rollup.config.js create mode 100644 tests/integration/rollup-test/src/index.js create mode 100755 tests/integration/rollup-test/test.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 80dd2a8fc..1c692488d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,6 +56,7 @@ jobs: # https://github.com/webpack/webpack/issues/14532 if: ${{ matrix.node-version != '17' }} run: | + cd ./tests/integration/rollup-test && ./test.sh && cd - cd ./tests/integration/webpack-babel-test && ./test.sh && cd - cd ./tests/integration/webpack-test && ./test.sh && cd - diff --git a/lib/handlebars/internal/proto-access.js b/lib/handlebars/internal/proto-access.js index a8c5394d5..424e0a714 100644 --- a/lib/handlebars/internal/proto-access.js +++ b/lib/handlebars/internal/proto-access.js @@ -1,5 +1,5 @@ import { createNewLookupObject } from './create-new-lookup-object'; -import * as logger from '../logger'; +import logger from '../logger'; const loggedProperties = Object.create(null); diff --git a/tests/integration/rollup-test/.eslintrc.js b/tests/integration/rollup-test/.eslintrc.js new file mode 100644 index 000000000..506a733f4 --- /dev/null +++ b/tests/integration/rollup-test/.eslintrc.js @@ -0,0 +1,11 @@ +module.exports = { + root: true, + extends: ['eslint:recommended', 'prettier'], + env: { + browser: true + }, + parserOptions: { + sourceType: 'module', + ecmaVersion: 6 + } +}; diff --git a/tests/integration/rollup-test/.gitignore b/tests/integration/rollup-test/.gitignore new file mode 100644 index 000000000..3a8ec2b3f --- /dev/null +++ b/tests/integration/rollup-test/.gitignore @@ -0,0 +1,3 @@ +node_modules +dist +package-lock.json \ No newline at end of file diff --git a/tests/integration/rollup-test/package.json b/tests/integration/rollup-test/package.json new file mode 100644 index 000000000..18807a7cd --- /dev/null +++ b/tests/integration/rollup-test/package.json @@ -0,0 +1,14 @@ +{ + "name": "rollup-test", + "description": "Various tests with Handlebars and rollup", + "version": "1.0.0", + "scripts": { + "build": "rollup --config rollup.config.js --failAfterWarnings" + }, + "private": true, + "devDependencies": { + "@rollup/plugin-node-resolve": "^13.1.1", + "handlebars": "file:../../..", + "rollup": "^2.61.1" + } +} diff --git a/tests/integration/rollup-test/rollup.config.js b/tests/integration/rollup-test/rollup.config.js new file mode 100644 index 000000000..bd4a58c9d --- /dev/null +++ b/tests/integration/rollup-test/rollup.config.js @@ -0,0 +1,10 @@ +import { nodeResolve } from '@rollup/plugin-node-resolve'; + +export default { + input: 'src/index.js', + output: { + file: 'dist/bundle.js', + format: 'es' + }, + plugins: [nodeResolve()] +}; diff --git a/tests/integration/rollup-test/src/index.js b/tests/integration/rollup-test/src/index.js new file mode 100644 index 000000000..2929870d9 --- /dev/null +++ b/tests/integration/rollup-test/src/index.js @@ -0,0 +1,8 @@ +import Handlebars from 'handlebars/lib/handlebars'; + +const template = Handlebars.compile('Author: {{author}}'); +const result = template({ author: 'Yehuda' }); + +if (result !== 'Author: Yehuda') { + throw Error('Assertion failed'); +} diff --git a/tests/integration/rollup-test/test.sh b/tests/integration/rollup-test/test.sh new file mode 100755 index 000000000..dabf8043e --- /dev/null +++ b/tests/integration/rollup-test/test.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -e + +# Cleanup: package-lock and "npm ci" is not working with local dependencies +rm dist package-lock.json -rf +npm install +npm run build + +node dist/bundle.js +echo "Success" \ No newline at end of file