Skip to content

Commit

Permalink
Use private props for internal vars
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Dec 17, 2024
1 parent 4bd827b commit 8dc464b
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/AssetCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ const Sources = require("./Sources.js");
const debug = require("debug")("Eleventy:Fetch");

class AssetCache {
#source;
#hash;
#customFilename;
#hasSaved = false;
#cache;
#cacheDirectory;
#cacheLocationDirty = false;
#dirEnsured = false;

constructor(source, cacheDirectory, options = {}) {
if(!Sources.isValidSource(source)) {
Expand Down Expand Up @@ -107,35 +112,35 @@ class AssetCache {
}

get source() {
return this._source;
return this.#source;
}

set source(source) {
this._source = source;
this.#source = source;
}

get hash() {
return this._hash;
return this.#hash;
}

set hash(value) {
if (value !== this._hash) {
if (value !== this.#hash) {
this.#cacheLocationDirty = true;
}

this._hash = value;
this.#hash = value;
}

get cacheDirectory() {
return this._cacheDirectory;
return this.#cacheDirectory;
}

set cacheDirectory(dir) {
if (dir !== this._cacheDirectory) {
if (dir !== this.#cacheDirectory) {
this.#cacheLocationDirty = true;
}

this._cacheDirectory = dir;
this.#cacheDirectory = dir;
}

get cacheFilename() {
Expand Down Expand Up @@ -170,16 +175,16 @@ class AssetCache {
}

get cache() {
if (!this._cache || this.#cacheLocationDirty) {
if (!this.#cache || this.#cacheLocationDirty) {
let cache = FlatCacheCreate({
cacheId: this.cacheFilename,
cacheDir: this.rootDir,
});

this._cache = cache;
this.#cache = cache;
this.#cacheLocationDirty = false;
}
return this._cache;
return this.#cache;
}

getDurationMs(duration = "0s") {
Expand Down Expand Up @@ -214,15 +219,15 @@ class AssetCache {
}

get isDirEnsured() {
return this._dirEnsured;
return this.#dirEnsured;
}

ensureDir() {
if (this.options.dryRun || this._dirEnsured) {
if (this.options.dryRun || this.#dirEnsured) {
return;
}

this._dirEnsured = true;
this.#dirEnsured = true;

fs.mkdirSync(this.cacheDirectory, {
recursive: true,
Expand Down

0 comments on commit 8dc464b

Please sign in to comment.