1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.createGlobPatternsForDependencies = void 0;
|
4 | const devkit_1 = require("@nrwl/devkit");
|
5 | const workspace_root_1 = require("nx/src/utils/workspace-root");
|
6 | const path_1 = require("path");
|
7 | const project_graph_1 = require("nx/src/project-graph/project-graph");
|
8 | const project_graph_utils_1 = require("nx/src/utils/project-graph-utils");
|
9 | const fs_1 = require("fs");
|
10 | const ignore_1 = require("ignore");
|
11 | function configureIgnore() {
|
12 | let ig;
|
13 | const pathToGitIgnore = (0, path_1.join)(workspace_root_1.workspaceRoot, '.gitignore');
|
14 | if ((0, fs_1.existsSync)(pathToGitIgnore)) {
|
15 | ig = (0, ignore_1.default)();
|
16 | ig.add((0, fs_1.readFileSync)(pathToGitIgnore, { encoding: 'utf-8' }));
|
17 | }
|
18 | return ig;
|
19 | }
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | function createGlobPatternsForDependencies(dirPath, fileGlobPattern) {
|
26 | let ig = configureIgnore();
|
27 | const filenameRelativeToWorkspaceRoot = (0, path_1.relative)(workspace_root_1.workspaceRoot, dirPath);
|
28 | const projectGraph = (0, project_graph_1.readCachedProjectGraph)();
|
29 |
|
30 | let projectName;
|
31 | try {
|
32 | projectName = (0, project_graph_utils_1.getProjectNameFromDirPath)(filenameRelativeToWorkspaceRoot, projectGraph);
|
33 | }
|
34 | catch (e) {
|
35 | throw new Error(`createGlobPatternsForDependencies: Error when trying to determine main project.\n${e === null || e === void 0 ? void 0 : e.message}`);
|
36 | }
|
37 |
|
38 | try {
|
39 | const [projectDirs, warnings] = (0, project_graph_utils_1.getSourceDirOfDependentProjects)(projectName, projectGraph);
|
40 | const dirsToUse = [];
|
41 | const recursiveScanDirs = (dirPath) => {
|
42 | const children = (0, fs_1.readdirSync)(dirPath);
|
43 | for (const child of children) {
|
44 | const childPath = (0, path_1.join)(dirPath, child);
|
45 | if ((ig === null || ig === void 0 ? void 0 : ig.ignores(childPath)) || !(0, fs_1.lstatSync)(childPath).isDirectory()) {
|
46 | continue;
|
47 | }
|
48 | if ((0, fs_1.existsSync)((0, path_1.join)(childPath, 'ng-package.json'))) {
|
49 | dirsToUse.push(childPath);
|
50 | }
|
51 | else {
|
52 | recursiveScanDirs(childPath);
|
53 | }
|
54 | }
|
55 | };
|
56 | for (const srcDir of projectDirs) {
|
57 | dirsToUse.push(srcDir);
|
58 | const root = (0, path_1.dirname)(srcDir);
|
59 | recursiveScanDirs(root);
|
60 | }
|
61 | if (warnings.length > 0) {
|
62 | devkit_1.logger.warn(`
|
63 | [createGlobPatternsForDependencies] Failed to generate glob pattern for the following:
|
64 | ${warnings.join('\n- ')}\n
|
65 | due to missing "sourceRoot" in the dependencies' project configuration
|
66 | `);
|
67 | }
|
68 | return dirsToUse.map((sourceDir) => (0, path_1.resolve)(workspace_root_1.workspaceRoot, (0, devkit_1.joinPathFragments)(sourceDir, fileGlobPattern)));
|
69 | }
|
70 | catch (e) {
|
71 | throw new Error(`createGlobPatternsForDependencies: Error when generating globs.\n${e === null || e === void 0 ? void 0 : e.message}`);
|
72 | }
|
73 | }
|
74 | exports.createGlobPatternsForDependencies = createGlobPatternsForDependencies;
|
75 |
|
\ | No newline at end of file |