mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 04:09:28 +00:00
For each target, allow importing itself
This commit is contained in:
@@ -25,28 +25,52 @@ module.exports = new class {
|
||||
url: 'https://github.com/microsoft/vscode/wiki/Source-Code-Organization'
|
||||
}
|
||||
};
|
||||
this._optionsCache = new WeakMap();
|
||||
}
|
||||
create(context) {
|
||||
const configs = this._processOptions(context.options);
|
||||
const options = context.options;
|
||||
const { configs, warnings } = this._processOptions(options);
|
||||
const relativeFilename = getRelativeFilename(context);
|
||||
if (warnings.length > 0) {
|
||||
// configuration warnings
|
||||
context.report({
|
||||
loc: { line: 1, column: 0 },
|
||||
message: warnings.join('\n')
|
||||
});
|
||||
return {};
|
||||
}
|
||||
for (const config of configs) {
|
||||
if (minimatch(relativeFilename, config.target)) {
|
||||
return (0, utils_1.createImportRuleListener)((node, value) => this._checkImport(context, config, node, value));
|
||||
}
|
||||
}
|
||||
context.report({
|
||||
loc: { line: 1, column: 1 },
|
||||
loc: { line: 1, column: 0 },
|
||||
messageId: 'badFilename'
|
||||
});
|
||||
return {};
|
||||
}
|
||||
_processOptions(options) {
|
||||
const result = [];
|
||||
if (this._optionsCache.has(options)) {
|
||||
return this._optionsCache.get(options);
|
||||
}
|
||||
const configs = [];
|
||||
const warnings = [];
|
||||
for (const option of options) {
|
||||
const target = option.target;
|
||||
const restrictions = (typeof option.restrictions === 'string' ? [option.restrictions] : option.restrictions);
|
||||
result.push({ target, restrictions });
|
||||
const restrictions = (typeof option.restrictions === 'string' ? [option.restrictions] : option.restrictions.slice(0));
|
||||
if (/^src\/vs\/.*\/\*\*/.test(target)) {
|
||||
const amdTarget = target.substring('src/'.length);
|
||||
// Allow importing itself
|
||||
if (restrictions.includes(amdTarget)) {
|
||||
warnings.push(`target ${target}: '${amdTarget}' is automatically included in restrictions.`);
|
||||
}
|
||||
restrictions.push(amdTarget);
|
||||
}
|
||||
configs.push({ target, restrictions });
|
||||
}
|
||||
const result = { configs, warnings };
|
||||
this._optionsCache.set(options, result);
|
||||
return result;
|
||||
}
|
||||
_checkImport(context, config, node, importPath) {
|
||||
|
||||
Reference in New Issue
Block a user