addImport static method
void
addImport(
- BuildStep buildStep,
- String path
)
Implementation
static void addImport(BuildStep buildStep, String path) {
String result = path;
if (path.startsWith('/${buildStep.inputId.package}/lib/')) {
result =
"package:${buildStep.inputId.package}/${path.replaceFirst('/${buildStep.inputId.package}/lib/', '')}";
} else if (path.startsWith(RegExp('/' + '${buildStep.inputId.package}' + r'/\w+?/lib/'))) {
String prefix = '/${buildStep.inputId.package}/';
String suffix = '/lib/';
int start = path.indexOf(prefix) + prefix.length;
int end = path.indexOf(suffix);
result = 'package:${buildStep.inputId.package}_' + path.substring(start, end) + '/' + path.substring(end + suffix.length);
} else if (path.startsWith('/') && path.contains('/lib/')) {
result = 'package:' + path.replaceFirst('/', '').replaceFirst('/lib/', '/');
}
if (!mergeByBaseUrl) {
if (!importMap.containsKey(result)) {
importMap[result] = true;
print("addImport path[$result]");
imports.add({"path": result});
}
return;
}
Map<String, bool>? map = Collector.inst.importMap[baseUrl];
if (map == null) {
map = Map<String, bool>();
Collector.inst.importMap[baseUrl] = map;
}
if (!map.containsKey(result)) {
map[result] = true;
print("addImport path[$path]");
List<Map<String, dynamic>>? urlImports = Collector.inst.importsMap[baseUrl];
if (urlImports == null) {
urlImports = <Map<String, dynamic>>[];
Collector.inst.importsMap[baseUrl] = urlImports;
}
urlImports.add({"path": result});
}
}