Skip to content

Commit 50f5f47

Browse files
committed
Remove the normalize-path package
1 parent cfd7ca4 commit 50f5f47

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

package.json

-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@
3838
},
3939
"bugs": "https://github.com/11ty/eleventy-utils/issues",
4040
"homepage": "https://github.com/11ty/eleventy-utils/",
41-
"dependencies": {
42-
"normalize-path": "^3.0.0"
43-
},
4441
"devDependencies": {
4542
"ava": "^6.1.3"
4643
}

src/TemplatePath.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const path = require("path");
2-
const normalize = require("normalize-path");
32
const fs = require("fs");
43

54
function TemplatePath() {}
@@ -59,7 +58,7 @@ TemplatePath.getLastPathSegment = function (path) {
5958
// Trim a trailing slash if there is one
6059
path = path.replace(/\/$/, "");
6160

62-
return path.substr(path.lastIndexOf("/") + 1);
61+
return path.slice(path.lastIndexOf("/") + 1);
6362
};
6463

6564
/**
@@ -93,22 +92,25 @@ TemplatePath.getAllDirs = function (path) {
9392
* @returns {String} the normalized path.
9493
*/
9594
TemplatePath.normalize = function (thePath) {
96-
return normalize(path.normalize(thePath));
95+
let filePath = path.normalize(thePath);
96+
if(filePath !== path.sep && filePath.endsWith(path.sep)) {
97+
return filePath.slice(0, -1 * path.sep.length);
98+
}
99+
return filePath;
97100
};
98101

99102
/**
100103
* Joins all given path segments together.
101104
*
102-
* It uses Node.js’ [`path.join`][1] method and the [normalize-path][2] package.
105+
* It uses Node.js’ [`path.join`][1] method.
103106
*
104107
* [1]: https://nodejs.org/api/path.html#path_path_join_paths
105-
* [2]: https://www.npmjs.com/package/normalize-path
106108
*
107109
* @param {String[]} paths An arbitrary amount of path segments.
108110
* @returns {String} the normalized and joined path.
109111
*/
110112
TemplatePath.join = function (...paths) {
111-
return normalize(path.join(...paths));
113+
return TemplatePath.normalize(path.join(...paths));
112114
};
113115

114116
/**
@@ -236,7 +238,7 @@ TemplatePath.stripLeadingSubPath = function (path, subPath) {
236238
subPath = TemplatePath.normalize(subPath);
237239

238240
if (subPath !== "." && path.startsWith(subPath)) {
239-
return path.substr(subPath.length + 1);
241+
return path.slice(subPath.length + 1);
240242
}
241243

242244
return path;

0 commit comments

Comments
 (0)