Skip to content

Commit

Permalink
new hotfix (sorry)
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed May 10, 2023
1 parent 3eda843 commit eceeb42
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 16 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ and this project try to adheres to [Semantic Versioning](https://semver.org/),
but not always is possible (due the use of unstable features from Deno).
Any BREAKING CHANGE between minor versions will be documented here in upper case.

## [1.17.3] - 2023-05-10
### Fixed
- The `lume/` import is not correctly generated with `lume init`.
- File system update in watch mode.

## [1.17.2] - 2023-05-09
### Added
- Option for specifying the init directory [#417].
Expand Down Expand Up @@ -2224,6 +2229,7 @@ The first version.
[#418]: https://github.com/lumeland/lume/issues/418
[#419]: https://github.com/lumeland/lume/issues/419

[1.17.3]: https://github.com/lumeland/lume/compare/v1.17.2...v1.17.3
[1.17.2]: https://github.com/lumeland/lume/compare/v1.17.1...v1.17.2
[1.17.1]: https://github.com/lumeland/lume/compare/v1.17.0...v1.17.1
[1.17.0]: https://github.com/lumeland/lume/compare/v1.16.2...v1.17.0
Expand Down
49 changes: 35 additions & 14 deletions core/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,17 @@ export default class FS {
this.#walkRemote();
}

update(path: string): Entry {
const entry = this.entries.get(path) ||
this.addEntry({ path, type: "file" });
entry.removeCache();
update(path: string): Entry | undefined {
let entry;

// Remove if it doesn't exist
try {
entry = this.entries.get(path) || this.addEntry({ path });
entry.removeCache();
// Remove if it doesn't exist
entry.getInfo();
} catch (error) {
if (error instanceof Deno.errors.NotFound) {
this.removeEntry(entry);
this.removeEntry(path);
}
}

Expand Down Expand Up @@ -150,15 +150,23 @@ export default class FS {
}
}

addEntry(data: { path: string; type: EntryType; src?: string }): Entry {
addEntry(data: { path: string; type?: EntryType; src?: string }): Entry {
const pieces = data.path.split("/").filter((p) => p);
let parent = this.tree;

if (!data.src) {
data.src = posix.join(this.options.root, data.path);
}

if (!data.type) {
const info = Deno.statSync(data.src);
data.type = info.isDirectory ? "directory" : "file";
}

while (pieces.length > 1) {
const name = pieces.shift()!;
const children = parent.children;
const prefix = parent.path === "/" ? "" : parent.path;
const path = `${prefix}/${name}`;
const path = posix.join(parent.path, name);

if (!this.#isValid(path)) {
break;
Expand All @@ -181,17 +189,30 @@ export default class FS {
name,
data.path,
data.type,
data.src || this.options.root + data.path,
data.src,
);
children.set(name, entry);
this.entries.set(entry.path, entry);
return entry;
}

removeEntry(entry: Entry) {
this.entries.delete(entry.path);
const parent = this.entries.get(posix.dirname(entry.path))!;
parent.children.delete(entry.name);
removeEntry(path: string) {
const entry = this.entries.get(path);
const isFolder = entry?.type === "directory";

this.entries.delete(path);
const parent = this.entries.get(posix.dirname(path))!;
const name = posix.basename(path);
parent.children.delete(name);

if (isFolder) {
const prefix = posix.join(path, "/");
for (const childPath of this.entries.keys()) {
if (childPath.startsWith(prefix)) {
this.entries.delete(childPath);
}
}
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion core/site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export default class Site {
}

// Ignore the dest folder by the watcher
this.options.watcher.ignore.push(this.options.dest);
this.options.watcher.ignore.push(normalizePath(this.options.dest));
this.fs.options.ignore = this.options.watcher.ignore;
}

Expand Down Expand Up @@ -539,6 +539,10 @@ export default class Site {
this.formats.deleteCache(file);
const entry = this.fs.update(file);

if (!entry) {
continue;
}

// Remove pages or static files depending on this entry
const pages = this.pages.filter((page) => page.src.entry === entry).map((
page,
Expand Down
2 changes: 1 addition & 1 deletion init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ await Deno.writeTextFile(configFile, code.join("\n"));
console.log();
console.log("Lume configuration file saved:", gray(configFile));

const url = new URL(import.meta.resolve("../"));
const url = new URL(import.meta.resolve("./"));
updateLumeVersion(url, denoConfig);
writeDenoConfig(denoConfig);

Expand Down

0 comments on commit eceeb42

Please sign in to comment.