MCPcopy
hub / github.com/less/less.js / loadStyleSheet

Function loadStyleSheet

packages/less/lib/less-browser/index.js:84–144  ·  view source on GitHub ↗
(sheet, callback, reload, remaining, modifyVars)

Source from the content-addressed store, hash-verified

82 }
83
84 function loadStyleSheet(sheet, callback, reload, remaining, modifyVars) {
85
86 const instanceOptions = clone(options);
87 addDataAttr(instanceOptions, sheet);
88 instanceOptions.mime = sheet.type;
89
90 if (modifyVars) {
91 instanceOptions.modifyVars = modifyVars;
92 }
93
94 function loadInitialFileCallback(loadedFile) {
95 const data = loadedFile.contents;
96 const path = loadedFile.filename;
97 const webInfo = loadedFile.webInfo;
98
99 const newFileInfo = {
100 currentDirectory: fileManager.getPath(path),
101 filename: path,
102 rootFilename: path,
103 rewriteUrls: instanceOptions.rewriteUrls
104 };
105
106 newFileInfo.entryPath = newFileInfo.currentDirectory;
107 newFileInfo.rootpath = instanceOptions.rootpath || newFileInfo.currentDirectory;
108
109 if (webInfo) {
110 webInfo.remaining = remaining;
111
112 const css = cache.getCSS(path, webInfo, instanceOptions.modifyVars);
113 if (!reload && css) {
114 webInfo.local = true;
115 callback(null, css, data, sheet, webInfo, path);
116 return;
117 }
118
119 }
120
121 // TODO add tests around how this behaves when reloading
122 errors.remove(path);
123
124 instanceOptions.rootFileInfo = newFileInfo;
125 less.render(data, instanceOptions, (e, result) => {
126 if (e) {
127 e.href = path;
128 callback(e);
129 } else {
130 cache.setCSS(sheet.href, webInfo.lastModified, instanceOptions.modifyVars, result.css);
131 callback(null, result.css, data, sheet, webInfo, path);
132 }
133 });
134 }
135
136 fileManager.loadFile(sheet.href, null, instanceOptions, environment)
137 .then(loadedFile => {
138 loadInitialFileCallback(loadedFile);
139 }).catch(err => {
140 console.log(err);
141 callback(err);

Callers 1

loadStyleSheetsFunction · 0.85

Calls 4

addDataAttrFunction · 0.90
loadInitialFileCallbackFunction · 0.85
loadFileMethod · 0.80
cloneFunction · 0.70

Tested by

no test coverage detected