-
-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide system to force reload of files #135
Comments
Hi, @amatiasq Cached filesAs you know, Lume has an internal caching system in the Source class. This is useful for pages that have the same dependencies. For example, several pages that use the same layout. Any file loaded with This internal cache manages automatically file changes. So we could use the same internal cache system for modules. At this moment, all modules are loaded using a My proposal is load the files and all dependencies and use the existing cache file to store that. To make it, we can change the signature of the loaders, addding a second argument with the Source instance. This allows to load all dependencies and save the content in the cache: import textLoader from "lume/core/loaders/text.ts";
// Fake code, for illustration purposes:
export default async function loader(path: string, sources: Source): Data {
const content = await textLoader(path);
// Get all dependencies of this file
const depsContent = getDependencies(content, async (dependencyPath) => {
// We load the dependencies with the Source instance
// so they are automatically cached and downloaded only once
return await sources.load(dependencyPath, textLoader);
});
return compileAndRun(content, depsContent);
} The idea is that one loader can invoke other loaders using the source instance, to load other dependencies that could be cached. This means that if DependenciesI think your approach of save the dependencies in the Source file, in a private import textLoader from "lume/core/loaders/text.ts";
// Load a file using a textLoader
sources.load("a.ts", textLoader);
// Load a dependency of a.ts
sources.load("b.ts", textLoader, "a.ts");
// Load another dependency of a.ts
sources.load("c.ts", textLoader, "a.ts");
// Load the same file again (it's cached, so won't be loaded)
// But has a different dependant, so it will be saved
sources.load("c.ts", textLoader, "d.ts"); This would save, automatically the dependencies relations, and we know that "b.ts" and "c.ts" are dependencies of "a.ts" and "c.ts" is a dependency of "a.ts" and "d.ts". Note: we don't need to save the exact dependency tree. Just the relation of the main entry point (the initial file loaded) with the dependencies, no matter if they are direct dependencies or sub-dependencies. So, in the previous example, we only have to include the main dependent path for all dependencies: import textLoader from "lume/core/loaders/text.ts";
// Fake code, for illustration purposes:
export default async function loader(path: string, sources: Source): Data {
const content = await textLoader(path);
// Get all dependencies of this file
const depsContent = getDependencies(content, async (dependencyPath) => {
// We load the dependencies with the Source instance
// so they are automatically cached and downloaded only once
// WARNING: The third argument indicates that this file is a dependency of the main entry point (path)
return await sources.load(dependencyPath, textLoader, path);
});
return compileAndRun(content, depsContent);
} Watch modeThe function to reload a file in So, the idea is that calling Thoughts? |
Oh i see, you're proposing to split the Readding From Disk from execution
of the files.
We can use url parsing to evaluate the module's code but without the
sourcemaps we won't have the list of dependencies of the files. We could
use that rust library you mentioned before.
I was also considering we could check if the loaded file is outside 'src'
(but inside 'cwd()'?) and watch them too.
|
Yes, exactly. The same dependency can be used several times, but we only read it once.
I think it's better because the rust library only return the graph of dependencies (is the equivalent to run the comand
This can't be done. The watcher only see changes in the src directory. The idea is that all src files needed to build the site are in this directory. The cwd can change (you can build the same site from different cwd). Any external file (outside of this directory or a remote dependency) won't be watched. |
I am just jumping into the middle of this and don't know anything, but I'm curious if doing the source maps helps with debugging? Ideally, it would be nice when having trouble to be able to step through code even in templates. I know that nunjucks is supposed to be adding source maps support at some point. |
SourceMaps were not used as such, we were using them just as a medium to
get the module's dependencies.
|
@amatiasq I just created a branch implementing a new way to watch files, compatible with javascript modules:
This system has two drawbacks:
I've added this mode under the what do you think? |
@oscarotero running the code in a Worker is a great improvement regarding modules isolation! I'll need time to carefully read and understand the new code so I can understand why those limitations apply, sadly I doubt I can get half as much time as last week. |
Don't worry, no rush :) |
The new version 1.1.1 was released. It includes the new experimental watcher (enabled with |
Following #134, we need a way to force lume to reload a file.
Example use case is if we know
a.ts
depends onb.ts
whenever we receive abeforeUpdate
event becauseb.ts
has changed we want Lume to also re-evaluatea.ts
.We can add
a.ts
toevent.files
but that won't trigger a re-evaluation because ofSource
internal cache.The text was updated successfully, but these errors were encountered: