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

Method push

packages/less/lib/less/import-manager.js:40–179  ·  view source on GitHub ↗

* Add an import to be imported * @param path - the raw path * @param tryAppendExtension - whether to try appending a file extension (.less or .js if the path has no extension) * @param currentFileInfo - the current file info (used for instance to work out relative paths)

(path, tryAppendExtension, currentFileInfo, importOptions, callback)

Source from the content-addressed store, hash-verified

38 * @param callback - callback for when it is imported
39 */
40 push(path, tryAppendExtension, currentFileInfo, importOptions, callback) {
41 const importManager = this, pluginLoader = this.context.pluginManager.Loader;
42
43 this.queue.push(path);
44
45 const fileParsedFunc = function (e, root, fullPath) {
46 importManager.queue.splice(importManager.queue.indexOf(path), 1); // Remove the path from the queue
47
48 const importedEqualsRoot = fullPath === importManager.rootFilename;
49 if (importOptions.optional && e) {
50 callback(null, {rules:[]}, false, null);
51 logger.info(`The file ${fullPath} was skipped because it was not found and the import was marked optional.`);
52 }
53 else {
54 // Inline imports aren't cached here.
55 // If we start to cache them, please make sure they won't conflict with non-inline imports of the
56 // same name as they used to do before this comment and the condition below have been added.
57 if (!importManager.files[fullPath] && !importOptions.inline) {
58 importManager.files[fullPath] = { root, options: importOptions };
59 }
60 if (e && !importManager.error) { importManager.error = e; }
61 callback(e, root, importedEqualsRoot, fullPath);
62 }
63 };
64
65 const newFileInfo = {
66 rewriteUrls: this.context.rewriteUrls,
67 entryPath: currentFileInfo.entryPath,
68 rootpath: currentFileInfo.rootpath,
69 rootFilename: currentFileInfo.rootFilename
70 };
71
72 const fileManager = environment.getFileManager(path, currentFileInfo.currentDirectory, this.context, environment);
73
74 if (!fileManager) {
75 fileParsedFunc({ message: `Could not find a file-manager for ${path}` });
76 return;
77 }
78
79 const loadFileCallback = function(loadedFile) {
80 let plugin;
81 const resolvedFilename = loadedFile.filename;
82 const contents = loadedFile.contents.replace(/^\uFEFF/, '');
83
84 // Pass on an updated rootpath if path of imported file is relative and file
85 // is in a (sub|sup) directory
86 //
87 // Examples:
88 // - If path of imported file is 'module/nav/nav.less' and rootpath is 'less/',
89 // then rootpath should become 'less/module/nav/'
90 // - If path of imported file is '../mixins.less' and rootpath is 'less/',
91 // then rootpath should become 'less/../'
92 newFileInfo.currentDirectory = fileManager.getPath(resolvedFilename);
93 if (newFileInfo.rewriteUrls) {
94 newFileInfo.rootpath = fileManager.join(
95 (importManager.context.rootpath || ''),
96 fileManager.pathDiff(newFileInfo.currentDirectory, newFileInfo.entryPath));
97

Callers 15

Gruntfile.cjsFile · 0.80
index.jsFile · 0.80
errorlineFunction · 0.80
loadFileFunction · 0.80
tryWithExtensionFunction · 0.80
getFileDataFunction · 0.80
addPluginMethod · 0.80
addVisitorMethod · 0.80
addFileManagerMethod · 0.80
getPreProcessorsMethod · 0.80
getPostProcessorsMethod · 0.80
addMethod · 0.80

Calls 4

getFileManagerMethod · 0.80
loadFileSyncMethod · 0.80
loadFileMethod · 0.80
cloneMethod · 0.45

Tested by 1

testFunction · 0.64