@spartacus/schematics
Version:
Spartacus schematics
39 lines • 2.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.migrateMissingPackage = void 0;
const dependencies_1 = require("@schematics/angular/utility/dependencies");
const program_1 = require("../../../shared/utils/program");
const project_tsconfig_paths_1 = require("../../../shared/utils/project-tsconfig-paths");
const workspace_utils_1 = require("../../../shared/utils/workspace-utils");
function migrateMissingPackage(tree, context, missingPackageConfig) {
var _a;
const project = workspace_utils_1.getDefaultProjectNameFromWorkspace(tree);
const { buildPaths } = project_tsconfig_paths_1.getProjectTsConfigPaths(tree, project);
const basePath = process.cwd();
let foundImport = false;
for (const tsconfigPath of buildPaths) {
const { appSourceFiles } = program_1.createProgram(tree, basePath, tsconfigPath);
for (const sourceFile of appSourceFiles) {
const importDeclarations = sourceFile.getImportDeclarations();
for (const id of importDeclarations) {
if (id.getModuleSpecifierValue().startsWith(missingPackageConfig.package)) {
foundImport = true;
break;
}
}
if (foundImport) {
break;
}
}
}
if (foundImport) {
const packagePresent = dependencies_1.getPackageJsonDependency(tree, missingPackageConfig.package);
if (!packagePresent) {
const comment = (_a = missingPackageConfig === null || missingPackageConfig === void 0 ? void 0 : missingPackageConfig.comment) !== null && _a !== void 0 ? _a : `We've found imports from ${missingPackageConfig.package} package which is not installed. If you are using feature from this library you can configure it by running schematics \`ng add ${missingPackageConfig.package}\`. If you only need to install package add it with npm (\`npm i ${missingPackageConfig.package}\`) or yarn (\`yarn add ${missingPackageConfig.package}\`). If you are not using this package check why you have imports from this library.`;
context.logger.warn(`${comment}\n`);
}
}
return tree;
}
exports.migrateMissingPackage = migrateMissingPackage;
//# sourceMappingURL=missing-packages.js.map