Triggering update from beforeUpdate
See original GitHub issueI have some js that I bundle with esbuild. Writing a plugin for it, I ended up with something like:
const built = new Set();
site.loadAssets([".js"], async filename => {
built.add(path.relative(site.src(), filename));
// call esbuild on file
return {content: esbuildOutput.content };
});
I make sure that all the dependencies are in an ignored dir, and everything works fine.
Now I want to update the main bundle when one of the deps change. I did something like:
site.addEventListener("beforeUpdate", async ev => {
for (const filename of ev.files) {
if (!filename.endsWith(".js")) continue;
if (built.has(filename)) continue;
await site.update(built);
return;
}
});
This “works”, except that this triggers the whole update cycle twice (including all afterUpdate
events). If instead of doing this, I simply add the files to ev.files
, it doesn’t work because the beforeUpdate
of core/source
doesn’t get called on the new files.
So now I’m stuck: there’s no way to restart or cancel the current update, and no way to ask source to clean the cache just for this file. What would be a good idea here?
Issue Analytics
- State:
- Created 2 years ago
- Comments:14 (14 by maintainers)
Top Results From Across the Web
MySQL BEFORE UPDATE Trigger By Practical Examples
In a BEFORE UPDATE trigger, you can update the NEW values but cannot update the OLD values. MySQL BEFORE UPDATE Trigger. MySQL BEFORE...
Read more >Oracle / PLSQL: BEFORE UPDATE Trigger - TechOnTheNet
A BEFORE UPDATE Trigger means that Oracle will fire this trigger before the UPDATE operation is executed. Syntax. The syntax to create a...
Read more >MySQL BEFORE UPDATE Trigger - Javatpoint
BEFORE UPDATE Trigger in MySQL is invoked automatically whenever an update operation is fired on the table associated with the trigger.
Read more >BEFORE UPDATE triggers - Sybase Infocenter
A solution is to use a BEFORE UPDATE trigger. A BEFORE UPDATE trigger does not make any change to the database tables, but...
Read more >After Update and Before Update Trigger - YouTube
After Update and Before Update Trigger on contact object which will track the changes in email field of sobject.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeah. The Deno blunder is not even close to good enough for this (to be fair, it’s not designed for this). I need inline source map, minification (and keeping top names, because of WebComponents), tree-shaking, backward compatibility js version support, etc.
I’ll try Asset/process version, I think I tried it before and failed, but I’ll report back.
I love to hear good ideas for Lume, so don’t worry 😃
Your idea of the
Format
type sounds great, but I’m not sure if it covers all use cases. For example:loader
assigned, a function responsive to read the file content. You can see the different loaders here..js
files can be loaded as text files, because they aren’t executed, but bundled, minified, etc._data.js
or_data/site.js
) are loaded as javascript modules, because they need to be executed at the build time.about-me.njk
uses the Nunjucks template engine.layout: main.pug
uses the Pug template engine to render the layout file in_includes
.templateEngine: njk,md
will be rendered twice, first using Nunjucks and then markdown see this.css
files:.scss
) that ouputs.css
is processed, because the extension is present in the dest file..css
file is processed too because the extension is present in the src file.File extensions can cover all these casuistry with a single api (just prefix the format at the end of the file name) and it works in both directions (you can register anything (loader, processor, etc) for all files of the same extension; and you can assign a extension to a individual file). In addition to that, you don’t need to see the code in the
_config.js
file to find out how a file will be loaded and processed, because it’s clear in the file extension that, for example, a.md
file is a markdown file that will be loaded and render as markdown.Your proposal could work as a low level API to handle this but I see some limitations, for example how to use
my format
(in your example) as a format for layouts stored in_includes
? or for processors/preprocessors? The format priority to resolve conflicts sounds a bit hacky…Anyway, I’ll keep thinking about this and open for suggestions.