MCPcopy Index your code
hub / github.com/webpack/less-loader / loadFileSync

Method loadFileSync

src/utils.js:121–168  ·  view source on GitHub ↗

* @param {string} filename filename * @param {string} currentDirectory current directory * @param {LoadFileOptions} options options * @param {Environment} environment environment * @returns {LoadFileResult} loaded file

(filename, currentDirectory, options, environment)

Source from the content-addressed store, hash-verified

119 * @returns {LoadFileResult} loaded file
120 */
121 loadFileSync(filename, currentDirectory, options, environment) {
122 // The default Less `loadFileSync` internally dispatches to
123 // `this.loadFile` with `options.syncImport = true`. Because we
124 // override `loadFile` (async), dynamic dispatch would land back in
125 // our async version and break the sync contract. Invoke the parent
126 // `loadFile` directly with the sync flag instead.
127 // @ts-expect-error bad types in less
128 const result = /** @type {LoadFileResult} */ (
129 super.loadFile(
130 filename,
131 currentDirectory,
132 { ...options, syncImport: true },
133 environment,
134 )
135 );
136
137 if (result && result.filename) {
138 loaderContext.addDependency(
139 path.normalize(
140 path.isAbsolute(result.filename)
141 ? result.filename
142 : path.resolve(currentDirectory || ".", result.filename),
143 ),
144 );
145 }
146
147 // Also try to resolve via webpack so aliases / custom resolvers can
148 // contribute dependencies. The resolved content is discarded - we
149 // only need the file path to track as a dependency.
150 pendingDependencyTasks.push(
151 this.resolveFilename(filename, currentDirectory)
152 .then((resolved) => {
153 const absoluteFilename = path.isAbsolute(resolved)
154 ? resolved
155 : path.resolve(".", resolved);
156
157 loaderContext.addDependency(path.normalize(absoluteFilename));
158 })
159 .catch(() => {
160 // Webpack may legitimately fail to resolve paths that Less's
161 // default sync manager handled (e.g. node-style relative
162 // lookups). The sync result above is what Less consumes, so
163 // ignore the async failure.
164 }),
165 );
166
167 return result;
168 }
169
170 /**
171 * @param {string} filename filename

Callers

nothing calls this directly

Calls 2

resolveFilenameMethod · 0.95
loadFileMethod · 0.45

Tested by

no test coverage detected