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

Simplify ESLint configurations #761

Draft
wants to merge 41 commits into
base: version-4
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
a4770b8
docs: add missing closing parenthesis in async option description (#766)
adnantabda Jul 23, 2024
b659895
Begin work on version 4
mde Apr 28, 2024
76a059a
Compile task, updated linting
mde May 1, 2024
b17c423
Updated lint config
mde May 1, 2024
5ecf4be
Get tests working
mde May 1, 2024
b077e66
Get build working
mde May 1, 2024
c808a78
Replace `let` in code-generation strings for CJS
mde May 1, 2024
8836459
Support Nodes back to 0.12
mde May 1, 2024
33e876e
Removed old doc file
mde May 1, 2024
45c828d
Updated JSDoc path
mde May 1, 2024
ad2ea9e
Updated docs
mde May 1, 2024
d60d4d6
Build before test again
mde May 1, 2024
19e8a75
Updated deps
mde May 1, 2024
715af2c
Updated docs
mde May 1, 2024
777ebc8
Updated docs
mde May 1, 2024
ad9f5ae
Updated docs
mde May 1, 2024
d8a1f82
testOnly task for running tests without building
mde May 1, 2024
278849b
Cleaner keyword replacement
mde May 1, 2024
50bf11b
Namespace Node builtins
mde May 2, 2024
ad56e7e
Updated Jake version
mde May 3, 2024
e7650b5
Bake in version string during packaging
mde May 3, 2024
5608b92
Removed unused import
mde May 3, 2024
8cc8c64
Removed version and name
mde May 4, 2024
da763a7
Replace Travis CI with GitHub Actions
phanect May 9, 2024
d1dd8e8
Build on CI process
phanect May 10, 2024
564ad2d
Update `engines` in package.json
phanect May 9, 2024
11c0c08
Remove unnecessary `npx` in npm scripts
phanect May 10, 2024
ad9e68c
Update package-lock.json
phanect May 9, 2024
445a128
Gitignore lib/cjs/
phanect May 10, 2024
1b58fc3
Use consistent name for `fs.readFileSync()`
phanect May 10, 2024
37f6e09
Sort devDependencies
phanect May 10, 2024
2774e00
Remove no longer used comment for JSHint
phanect May 10, 2024
92943e7
Fully migrate to ES Modules
phanect May 10, 2024
edabe2e
Use promisified Node.js APIs
phanect May 10, 2024
860d83c
Merge ESLint configs to a single file
phanect May 10, 2024
f88e008
Do not use unnecessary `@babel/eslint-parser` on ESLint
phanect May 10, 2024
326ccfc
Migrate to ESLint Stylistic
phanect May 10, 2024
e3919eb
Remove no longer required `eslint-env`
phanect May 10, 2024
48eab22
Lint
phanect May 10, 2024
5731786
Lint on CI instead of Jake's build process
phanect May 9, 2024
ced5214
Update package-lock.json
phanect May 9, 2024
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
4 changes: 0 additions & 4 deletions .eslintignore

This file was deleted.

48 changes: 0 additions & 48 deletions .eslintrc.json

This file was deleted.

33 changes: 33 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: GitHub Actions

on:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version:
- 18
- 20
- 21
- 22
steps:
- uses: actions/checkout@v4
- name: Use Node.js v${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: npm

- run: npm ci
- run: npm run build
- run: npm test
- run: npm run lint
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ npm-debug.log
doc/
test/tmp
coverage/

# CommonJS code compiled from ES Modules
/lib/cjs/

/ejs.js
/ejs.min.js
out/
Expand Down
6 changes: 0 additions & 6 deletions .travis.yml

This file was deleted.

46 changes: 34 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,27 @@ app.get('/', (req, res) => {
$ npm install ejs
```

### Import or require

Supports both CommonJS and ES Modules.

```javascript
import ejs from 'ejs';
// Or
const ejs = require('ejs');
```

### Compatibility

Server: CommonJS approach (`require`) supports Node versions at least
back to v0.12, likely older versions too. ES Modules approach (`import`)
requires a Node version that supports ESM.

CLI: Requires Node v8 or newer.

Browser: EJS supports all modern browsers, but is very likely to work even
in very, very old browsers. Your mileage may vary.

## Features

* Control flow with `<% %>`
Expand Down Expand Up @@ -51,7 +72,7 @@ Try EJS online at: https://ionicabizau.github.io/ejs-playground/.
## Basic usage

```javascript
let template = ejs.compile(str, options);
const template = ejs.compile(str, options);
template(data);
// => Rendered HTML string

Expand All @@ -70,7 +91,7 @@ add an option with the same name as one of your data object's properties.
Therefore, we do not recommend using this shortcut.

### Important
You should never give end-users unfettered access to the EJS render method, If you do so you are using EJS in an inherently un-secure way.
You should never give end-users unfettered access to the EJS render method, If you do so you are using EJS in an inherently un-secure way.

### Options

Expand Down Expand Up @@ -106,7 +127,7 @@ You should never give end-users unfettered access to the EJS render method, If y
- `outputFunctionName` Set to a string (e.g., 'echo' or 'print') for a function to print
output inside scriptlet tags.
- `async` When `true`, EJS will use an async function for rendering. (Depends
on async/await support in the JS runtime.
on async/await support in the JS runtime).
- `includer` Custom function to handle EJS includes, receives `(originalPath, parsedPath)`
parameters, where `originalPath` is the path in include as-is and `parsedPath` is the
previously resolved path. Should return an object `{ filename, template }`,
Expand Down Expand Up @@ -167,8 +188,8 @@ not supported in v3.0+.
Custom delimiters can be applied on a per-template basis, or globally:

```javascript
let ejs = require('ejs'),
users = ['geddy', 'neil', 'alex'];
import ejs from 'ejs';
const users = ['geddy', 'neil', 'alex'];

// Just one template
ejs.render('<p>[?= users.join(" | "); ?]</p>', {users: users}, {delimiter: '?', openDelimiter: '[', closeDelimiter: ']'});
Expand All @@ -189,9 +210,10 @@ functions used to render templates. It's easy to plug in LRU caching using
Node's `lru-cache` library:

```javascript
let ejs = require('ejs'),
LRU = require('lru-cache');
ejs.cache = LRU(100); // LRU cache with 100-item limit
import ejs from 'ejs';
import { LRUCache } from 'lru-cache';

ejs.cache = LRUCache({max: 100}); // LRU cache with 100-item limit
```

If you want to clear the EJS cache, call `ejs.clearCache`. If you're using the
Expand All @@ -203,8 +225,9 @@ of the LRU.
The default file loader is `fs.readFileSync`, if you want to customize it, you can set ejs.fileLoader.

```javascript
let ejs = require('ejs');
let myFileLoad = function (filePath) {
import ejs from 'ejs';

const myFileLoad = function (filePath) {
return 'myFileLoad: ' + fs.readFileSync(filePath);
};

Expand All @@ -218,7 +241,6 @@ With this feature, you can preprocess the template before reading it.
EJS does not specifically support blocks, but layouts can be implemented by
including headers and footers, like so:


```ejs
<%- include('header') -%>
<h1>
Expand All @@ -234,7 +256,7 @@ including headers and footers, like so:

Go to the [Latest Release](https://github.com/mde/ejs/releases/latest), download
`./ejs.js` or `./ejs.min.js`. Alternately, you can compile it yourself by cloning
the repository and running `jake build` (or `$(npm bin)/jake build` if jake is
the repository and running `jake build` (or `npx jake build` if jake is
not installed globally).

Include one of these files on your page, and `ejs` should be available globally.
Expand Down
4 changes: 2 additions & 2 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ let program = require('jake').program;
delete global.jake; // NO NOT WANT
program.setTaskNames = function (n) { this.taskNames = n; };

let ejs = require('../lib/ejs');
let { hyphenToCamel } = require('../lib/utils');
let ejs = require('../lib/cjs/ejs');
let { hyphenToCamel } = require('../lib/cjs/utils');
let fs = require('fs');
let args = process.argv.slice(2);
let usage = fs.readFileSync(`${__dirname}/../usage.txt`).toString();
Expand Down
Loading