Skip to content

Commit 17e8706

Browse files
committed
switch to esm-only code and Node v12+
1 parent 1331d82 commit 17e8706

File tree

5 files changed

+35
-31
lines changed

5 files changed

+35
-31
lines changed

.github/workflows/node.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
node-version: [10.x, 14.x]
14+
node-version: [12.x, 14.x]
1515
steps:
1616
- name: Checkout
1717
uses: actions/checkout@v2

cli.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#!/usr/bin/env node
2-
'use strict';
32

4-
const tinyjam = require('./index.js');
5-
const {version} = require('./package.json');
6-
const {performance} = require('perf_hooks');
3+
import tinyjam from './index.js';
4+
import {readFileSync} from 'fs';
5+
import {performance} from 'perf_hooks';
6+
7+
const version = JSON.parse(readFileSync(new URL('./package.json', import.meta.url))).version;
78

89
if (process.argv.length < 3) {
910
console.log(`tinyjam v${version}`);

index.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
'use strict';
1+
import fs from 'fs';
2+
import {join, basename, dirname, extname, relative} from 'path';
23

3-
const fs = require('fs');
4-
const {join, basename, dirname, extname, relative} = require('path');
5-
6-
const {compile} = require('yeahjs');
7-
const fm = require('front-matter');
8-
const marked = require('marked');
9-
const yaml = require('js-yaml');
10-
11-
module.exports = tinyjam;
4+
import {compile} from 'yeahjs';
5+
import fm from 'front-matter';
6+
import marked from 'marked';
7+
import yaml from 'js-yaml';
128

139
const defaultOptions = {
1410
log: false,
@@ -17,7 +13,7 @@ const defaultOptions = {
1713
highlight: null
1814
};
1915

20-
function tinyjam(src, dest = src, options = {}) {
16+
export default function tinyjam(src, dest = src, options = {}) {
2117
options = Object.assign({}, defaultOptions, options);
2218

2319
// Markdown renderer options
@@ -116,7 +112,7 @@ function tinyjam(src, dest = src, options = {}) {
116112

117113
} else if (ext === '.yml' || ext === '.yaml') {
118114
log(`read ${shortPath}`);
119-
data[name] = createCtx(rootPath, yaml.safeLoad(fs.readFileSync(path, 'utf8')));
115+
data[name] = createCtx(rootPath, yaml.load(fs.readFileSync(path, 'utf8')));
120116

121117
} else if (ext === '.ejs') {
122118
if (name[0] === '_') { // skip includes

package.json

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,25 @@
22
"name": "tinyjam",
33
"description": "A zero-configuration static site generator that deliberately has no features",
44
"main": "index.js",
5+
"type": "module",
56
"bin": {
67
"tinyjam": "./cli.js"
78
},
89
"version": "0.2.0",
910
"author": "Vladimir Agafonkin",
1011
"license": "ISC",
1112
"dependencies": {
12-
"front-matter": "^3.1.0",
13-
"js-yaml": "^3.13.1",
14-
"marked": "^1.0.0",
13+
"front-matter": "^4.0.2",
14+
"js-yaml": "^4.0.0",
15+
"marked": "^1.2.7",
1516
"yeahjs": "^0.2.0"
1617
},
1718
"devDependencies": {
18-
"dir-compare": "^2.3.0",
19-
"eslint": "^7.0.0",
19+
"dir-compare": "^2.4.0",
20+
"eslint": "^7.17.0",
2021
"eslint-config-mourner": "^3.0.0",
2122
"rimraf": "^3.0.2",
22-
"tape": "^5.0.0"
23+
"tape": "^5.1.1"
2324
},
2425
"scripts": {
2526
"pretest": "eslint *.js test/test.js",
@@ -28,12 +29,15 @@
2829
"eslintConfig": {
2930
"extends": "mourner",
3031
"parserOptions": {
31-
"ecmaVersion": 2018
32+
"ecmaVersion": 2020
3233
}
3334
},
3435
"files": [
3536
"cli.js"
3637
],
38+
"engines": {
39+
"node": ">= 12.17.0"
40+
},
3741
"keywords": [
3842
"static",
3943
"site",

test/test.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11

2-
const {test} = require('tape');
3-
const dircompare = require('dir-compare');
4-
const rimraf = require('rimraf');
5-
const {join} = require('path');
2+
import {test} from 'tape';
3+
import dircompare from 'dir-compare';
4+
import rimraf from 'rimraf';
5+
import {join, dirname} from 'path';
6+
import {fileURLToPath} from 'url';
67

7-
const tinyjam = require('../index.js');
8+
import tinyjam from '../index.js';
9+
10+
const fixturesDir = join(dirname(fileURLToPath(import.meta.url)), 'fixtures');
811

912
test('example', t => testDir(t, '../../example', 'example_output'));
1013
test('test', t => testDir(t, 'test_input', 'test_output'));
1114

1215
function testDir(t, input, expected) {
13-
const inputPath = join(__dirname, 'fixtures', input);
14-
const expectedPath = join(__dirname, 'fixtures', expected);
16+
const inputPath = join(fixturesDir, input);
17+
const expectedPath = join(fixturesDir, expected);
1518
const actualPath = `${expectedPath}_actual`;
1619

1720
rimraf.sync(actualPath);

0 commit comments

Comments
 (0)