Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function importsToResolve(url) {
const request = utils.urlToRequest(url);
// Keep in mind: ext can also be something like '.datepicker' when the true extension is omitted and the filename contains a dot.
// @see https://github.com/webpack-contrib/sass-loader/issues/167
const ext = path.extname(request);
if (matchModuleImport.test(url)) {
return [request, url];
}
// libsass' import algorithm works like this:
// In case there is a file extension...
// - If the file is a CSS-file, do not include it all, but just link it via @import url().
// - The exact file name must match (no auto-resolving of '_'-modules).
if (ext === ".css") {
return [];
}
err.file = entry
throw err
}
let imports = getImportsToResolve(originalImport, includePaths, transformers)
let resolvedImport
for (let i = 0; i < imports.length; i++) {
// if imports[i] is absolute path, then use it directly
if (path.isAbsolute(imports[i]) && fs.existsSync(imports[i])) {
resolvedImport = imports[i]
} else {
try {
const reqFile = loaderUtils.urlToRequest(imports[i], opts.root)
resolvedImport = yield resolve(entryDir, reqFile)
break
} catch (err) {
// skip
}
}
}
if (!resolvedImport) {
let err = new Error(`import file cannot be resolved: "${total}" @${entry}`)
err.file = entry
throw err
}
async.forEach(pages, (page, callback) => {
const rawPage = page
if (resolveMode === 'native') {
page = loaderUtils.urlToRequest(page, projectRoot)
}
const name = getPageName(tarRoot, rawPage)
const pagePath = '/' + toPosix(name)
resolve(path.join(context, srcRoot), page, (err, resource) => {
if (err) return callback(err)
const { resourcePath, queryObj } = parseRequest(resource)
// 如果存在page命名冲突,return err
for (let key in pagesMap) {
if (pagesMap[key] === pagePath && key !== resourcePath) {
return callback(new Error(`Resources in ${resourcePath} and ${key} are registered with same page path ${pagePath}, which is not allowed!`))
}
}
if (pagesMap[resourcePath]) return callback()
pagesMap[resourcePath] = pagePath
localPagesMap[pagePath] = {
resource: addQuery(resource, { page: true }),
// resolve symlink
let realPath: string
// mina or classic
let isClassical: boolean
try {
({ realPath, isClassical } = resolveRealPath(extensions, currentContext, resourceUrl))
} catch (error) {
// Do not throw an exception when the module does not exist.
// Just mark it up and move on to the next module.
errors.push(error)
return
}
// relative path from rootContext, used to generate entry request or name
const relativeRealPath = path.relative(rootContext, realPath)
const relativeRealRequest = urlToRequest(relativeRealPath)
// generte request
let request: string
if (isClassical) {
request = `!${minaLoader}?${JSON.stringify(
minaLoaderOptions
)}!${virtualMinaLoader}?${JSON.stringify({
extensions,
})}!${relativeRealRequest}`
} else {
request = relativeRealRequest
}
// entry name for SingleEntryPlugin
// `../../path/to/comp` => `_/_/path/to/comp`
const name = compose(
return `module.exports = ${JSON.stringify(keyedContent).replace(llRegex, (match) => {
const request = utils.urlToRequest(replacements[match])
const path = utils.stringifyRequest(this, request)
// Ensure loader cache is busted when the image changes
this.addDependency(path)
// Double quotes are used to "escape" from the JSON.stringify()'ed content
return `" + require(${path}) +"`
})};`
}
const resolveRealPath = (
extensions: Extensions,
context: string,
originalUrl: string
) => {
const originalRequest = urlToRequest(originalUrl)
try {
let resourcePath: string
let isClassical: boolean
// mina component
try {
resourcePath = resolve.sync(originalRequest, {
basedir: context,
extensions: [],
})
isClassical = false
} catch (error) {
// classic component
resourcePath = resolve.sync(originalRequest, {
basedir: context,
extensions: extensions.resolve,
})
constructor (diagnostic: ts.Diagnostic, context: string, TS: typeof ts) {
this.message = formatDiagnostic(diagnostic, TS)
if (diagnostic.file) {
this.file = urlToRequest(relative(context, diagnostic.file.fileName))
}
}
}
rewriteUrl: function(global, url) {
if(parserOptions.url){
url = url.trim();
if(!url.replace(/\s/g, '').length || !loaderUtils.isUrlRequest(url, root)) {
return url;
}
if(global) {
return loaderUtils.urlToRequest(url, root);
}
}
return url;
}
}),
rewriteUrl: function(global, url) {
if(parserOptions.url){
url = url.trim();
if(!url.replace(/\s/g, '').length || !loaderUtils.isUrlRequest(url, root)) {
return url;
}
if(global) {
return loaderUtils.urlToRequest(url, root);
}
}
return url;
}
}),
css.walkAtRules(/^import$/i, function(rule) {
var values = Tokenizer.parseValues(rule.params);
var url = values.nodes[0].nodes[0];
if(url && url.type === "url") {
url = url.url;
} else if(url && url.type === "string") {
url = url.value;
} else throw rule.error("Unexpected format " + rule.params);
if (!url.replace(/\s/g, '').length) {
return;
}
values.nodes[0].nodes.shift();
var mediaQuery = Tokenizer.stringifyValues(values);
if(loaderUtils.isUrlRequest(url, options.root)) {
url = loaderUtils.urlToRequest(url, options.root);
}
importItems.push({
url: url,
mediaQuery: mediaQuery
});
rule.remove();
});
}