Skip to content

Commit c1ad76c

Browse files
committed
makes ESM module
1 parent e39147d commit c1ad76c

11 files changed

+64
-57
lines changed

.eleventy.js

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
module.exports = {
1+
export default {
22
files: ["tests/**/*", "!tests/utils.js"],
33
watchMode: {
44
ignoreChanges: ["tests/output/**"],
55
},
6-
};
6+
};

eslint.config.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1-
const { defineConfig } = require("eslint/config");
2-
const prettier = require("eslint-plugin-prettier");
3-
const globals = require("globals");
4-
const js = require("@eslint/js");
5-
const { FlatCompat } = require("@eslint/eslintrc");
1+
import { FlatCompat } from "@eslint/eslintrc";
2+
import js from "@eslint/js";
3+
import prettier from "eslint-plugin-prettier";
4+
import { defineConfig } from "eslint/config";
5+
import globals from "globals";
6+
import path from "path";
7+
import { fileURLToPath } from "url";
8+
9+
// Mimic CommonJS variables -- not needed if using CommonJS
10+
const __filename = fileURLToPath(import.meta.url);
11+
const __dirname = path.dirname(__filename);
612

713
const compat = new FlatCompat({
814
baseDirectory: __dirname,
915
recommendedConfig: js.configs.recommended,
1016
allConfig: js.configs.all,
1117
});
1218

13-
module.exports = defineConfig([
19+
export default defineConfig([
1420
{
1521
extends: compat.extends("xo-space", "plugin:prettier/recommended"),
1622

index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// @ts-check
2+
import getCollectionNewestGitCommitDate from "./src/getCollectionNewestGitCommitDate.js";
3+
import getGitCommitDateFromPath from "./src/getGitCommitDateFromPath.js";
4+
5+
export default function (eleventyConfig) {
6+
eleventyConfig.addFilter(
7+
"getGitCommitDateFromPath",
8+
getGitCommitDateFromPath,
9+
);
10+
eleventyConfig.addFilter(
11+
"getCollectionNewestGitCommitDate",
12+
getCollectionNewestGitCommitDate,
13+
);
14+
}
15+
16+
export { getCollectionNewestGitCommitDate, getGitCommitDateFromPath };

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"name": "eleventy-plugin-git-commit-date",
33
"version": "0.1.3",
44
"description": "Eleventy plugin to get Git commit time of a file, or a Eleventy collection.",
5-
"main": ".eleventy.js",
5+
"main": "index.js",
6+
"type": "module",
67
"repository": {
78
"type": "git",
89
"url": "git+https://github.com:saneef/eleventy-plugin-git-commit-date.git"

prettier.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ const config = {
33
plugins: ["prettier-plugin-jsdoc"],
44
};
55

6-
module.exports = config;
6+
export default config;

src/getCollectionNewestGitCommitDate.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// @ts-check
2-
3-
const getGitCommitDateFromPath = require("./getGitCommitDateFromPath");
4-
const memoize = require("./utils/memoize");
2+
import getGitCommitDateFromPath from "./getGitCommitDateFromPath.js";
3+
import memoize from "./utils/memoize.js";
54

65
/**
76
* Gets the collection's newest Git commit date.
@@ -26,4 +25,4 @@ function getCollectionNewestGitCommitDate(collection) {
2625
}
2726
}
2827

29-
module.exports = memoize(getCollectionNewestGitCommitDate);
28+
export default memoize(getCollectionNewestGitCommitDate);

src/getGitCommitDateFromPath.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @ts-check
2-
const path = require("path");
3-
const spawn = require("cross-spawn");
4-
const memoize = require("./utils/memoize");
2+
import spawn from "cross-spawn";
3+
import path from "node:path";
4+
import memoize from "./utils/memoize.js";
55

66
/**
77
* Gets the Git commit date from path.
@@ -36,4 +36,4 @@ function getGitCommitDateFromPath(filePath) {
3636
}
3737
}
3838

39-
module.exports = memoize(getGitCommitDateFromPath);
39+
export default memoize(getGitCommitDateFromPath);

src/utils/memoize.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @param {Function} fn The function to memoize
88
* @returns {Function}
99
*/
10-
function memoize(fn) {
10+
export default function memoize(fn) {
1111
const cache = new Map();
1212

1313
return (...args) => {
@@ -25,5 +25,3 @@ function memoize(fn) {
2525
return cache.get(cacheKey);
2626
};
2727
}
28-
29-
module.exports = memoize;

tests/getCollectionNewestGitCommitDate.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
const test = require("ava");
2-
const path = require("path");
3-
const fs = require("fs/promises");
4-
const { rimraf } = require("rimraf");
5-
const getCollectionNewestGitCommitDate = require("../src/getCollectionNewestGitCommitDate.js");
1+
import test from "ava";
2+
import { mkdir, writeFile } from "node:fs/promises";
3+
import path from "node:path";
4+
import { rimraf } from "rimraf";
5+
import { fileURLToPath } from "url";
6+
import { getCollectionNewestGitCommitDate } from "../index.js";
67

7-
const outputBase = path.join("tests/output/");
8+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
89

910
test("Get newest commit date of collection", (t) => {
1011
const collection = [
@@ -23,15 +24,16 @@ test("Shouldn't get commit date from an empty collection", async (t) => {
2324
});
2425

2526
test("Shouldn't get commit date from collection of uncommited files", async (t) => {
27+
const outputBase = path.join("tests/output/");
2628
const collection = [
2729
{ inputPath: path.join(outputBase, "test-01.md") },
2830
{ inputPath: path.join(outputBase, "test-02.md") },
2931
];
3032

3133
await rimraf(outputBase);
3234

33-
await fs.mkdir(outputBase, { recursive: true });
34-
await Promise.all(collection.map((p) => fs.writeFile(p.inputPath, "")));
35+
await mkdir(outputBase, { recursive: true });
36+
await Promise.all(collection.map((p) => writeFile(p.inputPath, "")));
3537

3638
t.is(getCollectionNewestGitCommitDate(collection), undefined);
3739

0 commit comments

Comments
 (0)