
Security News
Bun 1.2.19 Adds Isolated Installs for Better Monorepo Support
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.
Determine the inheritance of template and style files.
Most HTML and CSS preprocessors use a synchronous API to access file system and don't use cache for already read files. It degrades performance and increases the time required to compile the code.
Also, when your project is very large and has a large number of dependencies between blocks (e.g. many mixins) — compiles all files of a project may take seconds or even minutes. This is unacceptable if you are working with a "watch" mode.
Solution?
This module allows you to compile only those files that depend on the changed file and require compilation.
For example, if you have the following files:
a.pug
— depends on b.pug
b.pug
c.pug
If you change the c.pug
file, then will be compiled only it. If you change the b.pug
file, then will be compiled a.pug
file.
$ npm i -D emitty
const emitty = require('emitty').setup('templates', 'jade');
emitty.scan().then(() => {
console.log(emitty.storage());
// {
// 'a.pug': {
// dependencies: ['components/b.pug'],
// ctime: new Date()
// },
// 'components/b.pug': {
// dependencies: [],
// ctime: new Date()
// }
// }
}
});
Creates API for emitty.
string
null
Directory to start from.
string
or object
null
The settings for the language that you want to use. For more details see «Language» section.
object
{}
For more details see «Options» section.
const emitty = require('emitty').setup('templates', 'pug');
Returns a snapshot of the Storage.
console.log(emitty.storage());
// {
// 'a.pug': {
// dependencies: ['components/b.pug'],
// ctime: new Date()
// },
// 'components/b.pug': {
// dependencies: [],
// ctime: new Date()
// }
// }
Returns the keys of the Storage.
console.log(emitty.keys());
// ['a.pug', 'components/b.pug']
Clears the Storage and loads the new data.
emitty.load({
'c.pug': {
dependencies: ['nope.pug'],
ctime: new Date()
}
});
// console.log(emitty.keys());
// ['c.pug']
Scans directory and updates the Storage. If you specify a filepath
, then only that file will be scanned. Also you can specify stats
of file (to avoid doing unnecessary actions inside emitty).
emitty.scan().then(() => {
// console.log(emitty.keys());
// ['a.pug', 'b.pug']
});
Returns all files that depends on the specified file.
emitty.scan().then(() => {
console.log(emitty.getDependencies('a.pug'));
// ['components/b.pug']
});
Returns True if A depends on B.
emitty.scan().then(() => {
console.log(emitty.getDependencies('a.pug'));
// ['components/b.pug']
console.log(emitty.checkDependencies('a.pug', 'components/b.pug'));
// true
console.log(emitty.checkDependencies('a.pug', 'nope.pug'));
// false
});
Is scan method, but for Stream and combines scan
+ resolver
.
Scans directory or file and updates the Storage. Then, if file in stream depends on the changed file — pass it further. Else skip it.
const stream = emitty.stream();
stream.on('end', () => {
// console.log(emitty.keys());
// ['a.pug', 'b.pug']
});
stream.end();
object
{}
You can load the previous state of the project in the Storage using this option.
function
(filepath) => console.log
Only for Stream mode. The function that will be called if the file needs to be compiled.
number
null
Time interval over which the Storage will be cleared of obsolete items.
Tip
Recommended for projects of more than 1000 template files or projects, where often remove the template files (more than once in 10 minutes).
number
30
This option can affect performance. The maximum number of nested directories to scan.
strin[]
['.git', '**/node_modules', '**/bower_components']
This option can affect performance. List of Glob-patterns for directories that are excluded when scanning.
The emitty contains built-in configs for the following instruments:
jade
— now it's Pugpug
nunjucks
posthtml
— with posthtml-include
and/or posthtml-extend
plugin.sugarml
— with posthtml-include
and/or posthtml-extend
plugin.You can use them when you configure emitty:
const emitty = require('emitty');
const emittyJade = emitty.setup('templates', 'pug');
const emittySugarml = emitty.setup('templates', 'sugarml');
// ...
Instead of use built-in config you can specify your own config.
For example, config for Slm:
const emitty = require('emitty').setup('templates', {
extensions: ['.slm'],
matcher: /=?=\s(?:partial|extend)\(['"]([^'"]+)['"].*?\)/,
comments: {
start: '/',
end: ''
},
indentBased: true
});
string
null
The name of built-in config, which will be basis for this config. If you specify this property, you can specify other properties as needed.
string[]
null
List of file extensions to be included in Storage when scanning.
RegExp
null
Regexp to run on each line of source code to match dependency references.
object
null
{
start: '//', // The start of a comment
end: '' // The end of a comment
}
boolean
false
The syntax of the language is based on indentation?
// npm i gulpjs/gulp#4.0 gulp-if gulp-pug emitty
const gulp = require('gulp');
const gulpif = require('gulp-if');
const emitty = require('emitty').setup('app/templates', 'pug');
const pug = require('gulp-pug');
// Your "watch" task
gulp.task('watch', () => {
// Shows that run "watch" mode
global.watch = true;
gulp.watch('app/templates/**/*.pug', gulp.series('templates'))
.on('all', (event, filepath) => {
global.emittyChangedFile = filepath;
});
});
gulp.task('templates', () =>
gulp.src('app/templates/*.pug')
.pipe(gulpif(global.watch, emitty.stream(global.emittyChangedFile)))
.pipe(pug({ pretty: true }))
.pipe(gulp.dest('build'))
);
See the Releases section of our GitHub project for changelogs for each release version.
This software is released under the terms of the MIT license.
FAQs
Determine the inheritance of template and style files
The npm package emitty receives a total of 129 weekly downloads. As such, emitty popularity was classified as not popular.
We found that emitty demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.
Security News
Popular npm packages like eslint-config-prettier were compromised after a phishing attack stole a maintainer’s token, spreading malicious updates.
Security News
/Research
A phishing attack targeted developers using a typosquatted npm domain (npnjs.com) to steal credentials via fake login pages - watch out for similar scams.