MCPcopy Create free account
hub / github.com/webpack/less-loader / WebpackFileManager

Class WebpackFileManager

src/utils.js:82–279  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80 });
81
82 class WebpackFileManager extends implementation.FileManager {
83 /**
84 * @param {string} filename filename
85 * @returns {boolean} true when filename is supported, otherwise false
86 */
87 supports(filename) {
88 if (filename[0] === "/" || IS_NATIVE_WIN32_PATH.test(filename)) {
89 return true;
90 }
91
92 if (this.isPathAbsolute(filename)) {
93 return false;
94 }
95
96 return true;
97 }
98
99 // Sync loading is used by `data-uri()` and any custom Less function
100 // (including those installed via `@plugin`). Webpack doesn't expose a
101 // sync resolver, so we fulfil the sync read by delegating to Less's
102 // default file manager (which can only handle native filesystem paths)
103 // and, in parallel, kick off an async webpack resolve so the loaded
104 // file is tracked as a webpack file dependency. Without this, webpack's
105 // persistent cache won't invalidate when a sync-loaded file changes.
106 // See https://github.com/webpack/less-loader/issues/492.
107 /**
108 * @returns {boolean} true when support sync, otherwise false
109 */
110 supportsSync() {
111 return true;
112 }
113
114 /**
115 * @param {string} filename filename
116 * @param {string} currentDirectory current directory
117 * @param {LoadFileOptions} options options
118 * @param {Environment} environment environment
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(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…