Skip to content

Commit 70b8f11

Browse files
authored
feat: migrate to RSPack (#2131)
* Migrate to RSPack * Add tests to CI, address coverage * fix: Restore AWS sdk * add simple serve
1 parent 2f68d94 commit 70b8f11

24 files changed

Lines changed: 13241 additions & 13987 deletions

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ Generally we like to see pull requests that
99
- [ ] Have tests
1010
- [ ] Have the [typings](https://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html) (types/index.d.ts) updated on every API change. If you need help, updating those, please mention that in the PR description.
1111
- [ ] Don't significantly decrease the current code coverage (see coverage/lcov-report/index.html)
12-
- [ ] Currently, the `4.x`-branch contains the latest version. Please target that branch in the PR.
12+
- [ ] Please target the `master` branch in the PR.

.github/workflows/ci.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,9 @@ jobs:
5252
- name: Test
5353
run: npm run test
5454

55-
# TODO: Re-enable integration tests once webpack/rollup compatibility is resolved
56-
# - name: Test (Integration)
57-
# run: |
58-
# cd ./tests/integration/rollup-test && ./test.sh && cd -
59-
# cd ./tests/integration/webpack-babel-test && ./test.sh && cd -
60-
# cd ./tests/integration/webpack-test && ./test.sh && cd -
55+
- name: Test (Integration)
56+
if: matrix.operating-system == 'ubuntu-latest'
57+
run: npm run test:integration
6158

6259
browser:
6360
name: Test (Browser)
@@ -82,7 +79,7 @@ jobs:
8279
npx playwright install
8380
8481
- name: Build
85-
run: npx grunt prepare
82+
run: npm run build
8683

8784
- name: Test
8885
run: |

.swcrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"$schema": "https://swc.rs/schema.json",
3+
"module": {
4+
"type": "commonjs",
5+
"importInterop": "swc"
6+
},
7+
"sourceMaps": "inline"
8+
}

CONTRIBUTING.md

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,8 @@ Documentation issues on the [handlebarsjs.com](https://handlebarsjs.com) site sh
1818

1919
## Branches
2020

21-
- The branch `4.x` contains the currently released version. Bugfixes should be made in this branch.
22-
- The branch `master` contains the next version. A release date is not yet specified. Maintainers
23-
should merge the branch `4.x` into the master branch regularly.
24-
- The branch `3.x` contains the legacy version `3.x`. Bugfixes are applied separately (if needed). The branch will not
25-
be merged with any of the other branches.
21+
- The branch `master` contains the current development version (v5).
22+
- The branch `4.x` contains the previous stable version. Only critical bugfixes are backported there.
2623

2724
## Pull Requests
2825

@@ -38,21 +35,13 @@ Generally we like to see pull requests that
3835

3936
## Building
4037

41-
To build Handlebars.js you'll need a few things installed.
42-
43-
- Node.js
44-
- [Grunt](http://gruntjs.com/getting-started)
38+
To build Handlebars.js you'll need Node.js installed.
4539

4640
Before building, you need to make sure that the Git submodule `spec/mustache` is included (i.e. the directory `spec/mustache` should not be empty). To include it, if using Git version 1.6.5 or newer, use `git clone --recursive` rather than `git clone`. Or, if you already cloned without `--recursive`, use `git submodule update --init`.
4741

4842
Project dependencies may be installed via `npm install`.
4943

50-
To build Handlebars.js from scratch, you'll want to run `grunt`
51-
in the root of the project. That will build Handlebars and output the
52-
results to the dist/ folder. To re-run tests, run `grunt test` or `npm test`.
53-
You can also run our set of benchmarks with `grunt bench`.
54-
55-
The `grunt dev` implements watching for tests and allows for in browser testing at `http://localhost:9999/spec/`.
44+
To build Handlebars.js from scratch, run `npm run build` in the root of the project. That will compile CJS modules via SWC and bundle UMD distributions via rspack, outputting results to the dist/ folder. To run tests, use `npm test`.
5645

5746
If you notice any problems, please report them to the GitHub issue tracker at
5847
[http://github.com/handlebars-lang/handlebars.js/issues](http://github.com/handlebars-lang/handlebars.js/issues).
@@ -81,21 +70,16 @@ npm test
8170

8271
## Linting and Formatting
8372

84-
Handlebars uses `eslint` to enforce best-practices and `prettier` to auto-format files.
85-
We do linting and formatting in two phases:
86-
87-
- Committed files are linted and formatted in a pre-commit hook. In this stage eslint-errors are forbidden,
88-
while warnings are allowed.
89-
- The GitHub CI job also lints all files and checks if they are formatted correctly. In this stage, warnings
90-
are forbidden.
73+
Handlebars uses `oxlint` for linting, `oxfmt` for formatting, and `eslint` (with `eslint-plugin-compat`) for browser API compatibility checks.
74+
Committed files are linted and formatted in a pre-commit hook.
9175

9276
You can use the following scripts to make sure that the CI job does not fail:
9377

94-
- **npm run lint** will run `eslint` and fail on warnings
95-
- **npm run format** will run `prettier` on all files
96-
- **npm run check-before-pull-request** will perform all most checks that our CI job does in its build-job, excluding the "integration-test".
97-
- **npm run test:integration** will run integration tests (using old NodeJS versions and integrations with webpack, babel and so on)
98-
These tests only work on a Linux-machine with `nvm` installed (for running tests in multiple versions of NodeJS).
78+
- **npm run lint** will run all linters and fail on warnings
79+
- **npm run format** will format all files
80+
- **npm run check-before-pull-request** will perform all checks that our CI job does, excluding integration tests.
81+
- **npm run test:integration** will run integration tests (bundler compatibility with webpack, rollup, etc.)
82+
These tests only work on Linux.
9983

10084
## Releasing the latest version
10185

@@ -113,12 +97,8 @@ A full release may be completed with the following:
11397

11498
```
11599
npm ci
116-
npx grunt
100+
npm run build
117101
npm publish
118-
119-
cd dist/components/
120-
gem build handlebars-source.gemspec
121-
gem push handlebars-source-*.gem
122102
```
123103

124104
After the release, you should check that all places have really been updated. Especially verify that the `latest`-tags

Gruntfile.js

Lines changed: 2 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -1,174 +1,9 @@
1-
/* eslint-disable no-process-env */
1+
// Legacy Gruntfile — kept only for the 'metrics' and 'version' tasks.
2+
// The main build pipeline uses rspack + swc (see rspack.config.js and .swcrc).
23
module.exports = function (grunt) {
34
grunt.initConfig({
45
pkg: grunt.file.readJSON('package.json'),
5-
6-
clean: ['tmp', 'dist', 'tests/integration/**/node_modules'],
7-
8-
copy: {
9-
dist: {
10-
options: {
11-
processContent: function (content) {
12-
return (
13-
grunt.template.process(
14-
'/**!\n\n @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt Expat\n <%= pkg.name %> v<%= pkg.version %>\n\n<%= grunt.file.read("LICENSE") %>\n*/\n'
15-
) +
16-
content +
17-
'\n// @license-end\n'
18-
);
19-
},
20-
},
21-
files: [{ expand: true, cwd: 'dist/', src: ['*.js'], dest: 'dist/' }],
22-
},
23-
components: {
24-
files: [
25-
{
26-
expand: true,
27-
cwd: 'components/',
28-
src: ['**'],
29-
dest: 'dist/components',
30-
},
31-
{
32-
expand: true,
33-
cwd: 'dist/',
34-
src: ['*.js'],
35-
dest: 'dist/components',
36-
},
37-
],
38-
},
39-
},
40-
41-
babel: {
42-
options: {
43-
sourceMaps: 'inline',
44-
loose: ['es6.modules'],
45-
auxiliaryCommentBefore: 'istanbul ignore next',
46-
},
47-
cjs: {
48-
files: [
49-
{
50-
cwd: 'lib/',
51-
expand: true,
52-
src: '**/!(index).js',
53-
dest: 'dist/cjs/',
54-
},
55-
],
56-
},
57-
},
58-
webpack: {
59-
options: {
60-
context: __dirname,
61-
output: {
62-
path: 'dist/',
63-
library: 'Handlebars',
64-
libraryTarget: 'umd',
65-
},
66-
},
67-
handlebars: {
68-
entry: './dist/cjs/handlebars.js',
69-
output: {
70-
filename: 'handlebars.js',
71-
},
72-
},
73-
runtime: {
74-
entry: './dist/cjs/handlebars.runtime.js',
75-
output: {
76-
filename: 'handlebars.runtime.js',
77-
},
78-
},
79-
},
80-
81-
uglify: {
82-
options: {
83-
mangle: true,
84-
compress: true,
85-
preserveComments: /(?:^!|@(?:license|preserve|cc_on))/,
86-
},
87-
dist: {
88-
files: [
89-
{
90-
cwd: 'dist/',
91-
expand: true,
92-
src: ['handlebars*.js', '!*.min.js'],
93-
dest: 'dist/',
94-
rename: function (dest, src) {
95-
return dest + src.replace(/\.js$/, '.min.js');
96-
},
97-
},
98-
],
99-
},
100-
},
101-
102-
concat: {
103-
tests: {
104-
src: ['spec/!(require).js'],
105-
dest: 'tmp/tests.js',
106-
},
107-
},
108-
109-
connect: {
110-
server: {
111-
options: {
112-
base: '.',
113-
hostname: '*',
114-
port: 9999,
115-
},
116-
},
117-
},
118-
119-
shell: {
120-
integrationTests: {
121-
command: './tests/integration/run-integration-tests.sh',
122-
},
123-
},
124-
125-
watch: {
126-
scripts: {
127-
options: {
128-
atBegin: true,
129-
},
130-
131-
files: ['src/*', 'lib/**/*.js', 'spec/**/*.js'],
132-
tasks: ['on-file-change'],
133-
},
134-
},
1356
});
1367

137-
// Load tasks from npm
138-
grunt.loadNpmTasks('grunt-contrib-clean');
139-
grunt.loadNpmTasks('grunt-contrib-concat');
140-
grunt.loadNpmTasks('grunt-contrib-connect');
141-
grunt.loadNpmTasks('grunt-contrib-copy');
142-
grunt.loadNpmTasks('grunt-contrib-uglify');
143-
grunt.loadNpmTasks('grunt-contrib-watch');
144-
grunt.loadNpmTasks('grunt-babel');
145-
grunt.loadNpmTasks('grunt-shell');
146-
grunt.loadNpmTasks('grunt-webpack');
147-
1488
grunt.task.loadTasks('tasks');
149-
150-
grunt.registerTask('node', ['babel:cjs']);
151-
grunt.registerTask('globals', ['webpack']);
152-
grunt.registerTask('release', 'Build final packages', [
153-
'uglify',
154-
'copy:dist',
155-
'copy:components',
156-
]);
157-
158-
grunt.registerTask('on-file-change', ['build', 'concat:tests']);
159-
160-
// === Primary tasks ===
161-
grunt.registerTask('dev', ['clean', 'connect', 'watch']);
162-
grunt.registerTask('default', ['clean', 'build', 'release']);
163-
grunt.registerTask('bench', ['metrics']);
164-
grunt.registerTask('prepare', ['build', 'concat:tests']);
165-
grunt.registerTask(
166-
'build',
167-
'Builds a distributable version of the current project',
168-
['node', 'globals']
169-
);
170-
grunt.registerTask('integration-tests', [
171-
'default',
172-
'shell:integrationTests',
173-
]);
1749
};

lib/handlebars.runtime.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ function create() {
1919
hb.Utils = Utils;
2020
hb.escapeExpression = Utils.escapeExpression;
2121

22-
hb.VM = runtime;
22+
// Spread into a plain object so that runtime functions (e.g. checkRevision)
23+
// can be overridden by consumers. ES module namespace objects are sealed with
24+
// getter-only properties per spec, which would prevent monkey-patching.
25+
hb.VM = { ...runtime };
2326
hb.template = function (spec) {
2427
return runtime.template(spec, hb);
2528
};

lib/precompiler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable no-console */
22
import Async from 'neo-async';
33
import fs from 'fs';
4-
import * as Handlebars from './handlebars';
4+
import Handlebars from './handlebars';
55
import { basename } from 'path';
66
import { SourceMapConsumer, SourceNode } from 'source-map';
77

0 commit comments

Comments
 (0)