diff --git a/lib/interpolateName.js b/lib/interpolateName.js index 267dd2c..60a898c 100644 --- a/lib/interpolateName.js +++ b/lib/interpolateName.js @@ -51,9 +51,10 @@ function interpolateName(loaderContext, name, options = {}) { directory = resourcePath.replace(/\\/g, "/").replace(/\.\.(\/)?/g, "_$1"); } - if (directory.length === 1) { + if (directory.length <= 1) { directory = ""; - } else if (directory.length > 1) { + } else { + // directory.length > 1 folder = path.basename(directory); } } diff --git a/test/interpolateName.test.js b/test/interpolateName.test.js index d84bf8e..77d9a17 100644 --- a/test/interpolateName.test.js +++ b/test/interpolateName.test.js @@ -308,11 +308,21 @@ describe("interpolateName()", () => { "/path/to/", "should interpolate [path] token", ], + [ + [loaderContext, "[path]", { context: "/path/" }], + "to/", + "should interpolate [path] token with context", + ], [ [loaderContext, "[folder]", {}], "to", "should interpolate [folder] token", ], + [ + [{ resourcePath: "." }, "[folder]", {}], + "", + "should interpolate [folder] token with short resourcePath", + ], ]); });