Skip to content
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

Added cache object to node-sass-once-importer #166

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 15 additions & 4 deletions packages/node-sass-once-importer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export = function onceImporter() {
store: new Set(),
};

// cache for resolvedUrls
let resolvedUrlsCache: Map<string, string> = new Map();

return function importer(url: string, prev: string) {
const nodeSassOptions = this.options;
// Create a context for the current importer run.
Expand All @@ -29,14 +32,22 @@ export = function onceImporter() {
// files already imported in a previous importer run
// would be detected as multiple imports of the same file.
const store = this.nodeSassOnceImporterContext.store;
// per instance of new importer created, path resolution is shared

const includePaths = buildIncludePaths(
nodeSassOptions.includePaths,
prev,
);
const resolvedUrl = resolveUrl(
url,
includePaths,
);

// the perf improvement here is avoiding a glob.sync call in resolveUrl
// if we dont need it
if (!resolvedUrlsCache.has(url)) {
resolvedUrlsCache.set(url, resolveUrl(
url,
includePaths,
));
}
const resolvedUrl = resolvedUrlsCache.get(url);

if (store.has(resolvedUrl)) {
return EMPTY_IMPORT;
Expand Down