source: trip-planner-front/node_modules/@angular-devkit/architect/node/node-modules-architect-host.js@ 8d391a1

Last change on this file since 8d391a1 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 7.9 KB
RevLine 
[6a3a178]1"use strict";
2/**
3 * @license
4 * Copyright Google LLC All Rights Reserved.
5 *
6 * Use of this source code is governed by an MIT-style license that can be
7 * found in the LICENSE file at https://angular.io/license
8 */
9var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10 if (k2 === undefined) k2 = k;
11 Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
12}) : (function(o, m, k, k2) {
13 if (k2 === undefined) k2 = k;
14 o[k2] = m[k];
15}));
16var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17 Object.defineProperty(o, "default", { enumerable: true, value: v });
18}) : function(o, v) {
19 o["default"] = v;
20});
21var __importStar = (this && this.__importStar) || function (mod) {
22 if (mod && mod.__esModule) return mod;
23 var result = {};
24 if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25 __setModuleDefault(result, mod);
26 return result;
27};
28Object.defineProperty(exports, "__esModule", { value: true });
29exports.WorkspaceNodeModulesArchitectHost = void 0;
30const path = __importStar(require("path"));
31const v8_1 = require("v8");
32const internal_1 = require("../src/internal");
33function clone(obj) {
34 try {
35 return v8_1.deserialize(v8_1.serialize(obj));
36 }
37 catch {
38 return JSON.parse(JSON.stringify(obj));
39 }
40}
41function findProjectTarget(workspace, project, target) {
42 const projectDefinition = workspace.projects.get(project);
43 if (!projectDefinition) {
44 throw new Error(`Project "${project}" does not exist.`);
45 }
46 const targetDefinition = projectDefinition.targets.get(target);
47 if (!targetDefinition) {
48 throw new Error('Project target does not exist.');
49 }
50 return targetDefinition;
51}
52class WorkspaceNodeModulesArchitectHost {
53 constructor(workspaceOrHost, _root) {
54 this._root = _root;
55 if ('getBuilderName' in workspaceOrHost) {
56 this.workspaceHost = workspaceOrHost;
57 }
58 else {
59 this.workspaceHost = {
60 async getBuilderName(project, target) {
61 const targetDefinition = findProjectTarget(workspaceOrHost, project, target);
62 return targetDefinition.builder;
63 },
64 async getOptions(project, target, configuration) {
65 var _a, _b, _c, _d;
66 const targetDefinition = findProjectTarget(workspaceOrHost, project, target);
67 if (configuration === undefined) {
68 return ((_a = targetDefinition.options) !== null && _a !== void 0 ? _a : {});
69 }
70 if (!((_b = targetDefinition.configurations) === null || _b === void 0 ? void 0 : _b[configuration])) {
71 throw new Error(`Configuration '${configuration}' is not set in the workspace.`);
72 }
73 return ((_d = (_c = targetDefinition.configurations) === null || _c === void 0 ? void 0 : _c[configuration]) !== null && _d !== void 0 ? _d : {});
74 },
75 async getMetadata(project) {
76 const projectDefinition = workspaceOrHost.projects.get(project);
77 if (!projectDefinition) {
78 throw new Error(`Project "${project}" does not exist.`);
79 }
80 return {
81 root: projectDefinition.root,
82 sourceRoot: projectDefinition.sourceRoot,
83 prefix: projectDefinition.prefix,
84 ...clone(projectDefinition.extensions),
85 };
86 },
87 async hasTarget(project, target) {
88 var _a;
89 return !!((_a = workspaceOrHost.projects.get(project)) === null || _a === void 0 ? void 0 : _a.targets.has(target));
90 },
91 async getDefaultConfigurationName(project, target) {
92 var _a, _b;
93 return (_b = (_a = workspaceOrHost.projects.get(project)) === null || _a === void 0 ? void 0 : _a.targets.get(target)) === null || _b === void 0 ? void 0 : _b.defaultConfiguration;
94 },
95 };
96 }
97 }
98 async getBuilderNameForTarget(target) {
99 return this.workspaceHost.getBuilderName(target.project, target.target);
100 }
101 /**
102 * Resolve a builder. This needs to be a string which will be used in a dynamic `import()`
103 * clause. This should throw if no builder can be found. The dynamic import will throw if
104 * it is unsupported.
105 * @param builderStr The name of the builder to be used.
106 * @returns All the info needed for the builder itself.
107 */
108 resolveBuilder(builderStr) {
109 const [packageName, builderName] = builderStr.split(':', 2);
110 if (!builderName) {
111 throw new Error('No builder name specified.');
112 }
113 const packageJsonPath = require.resolve(packageName + '/package.json', {
114 paths: [this._root],
115 });
116 const packageJson = require(packageJsonPath);
117 if (!packageJson['builders']) {
118 throw new Error(`Package ${JSON.stringify(packageName)} has no builders defined.`);
119 }
120 const builderJsonPath = path.resolve(path.dirname(packageJsonPath), packageJson['builders']);
121 const builderJson = require(builderJsonPath);
122 const builder = builderJson.builders && builderJson.builders[builderName];
123 if (!builder) {
124 throw new Error(`Cannot find builder ${JSON.stringify(builderStr)}.`);
125 }
126 const importPath = builder.implementation;
127 if (!importPath) {
128 throw new Error('Could not find the implementation for builder ' + builderStr);
129 }
130 return Promise.resolve({
131 name: builderStr,
132 builderName,
133 description: builder['description'],
134 optionSchema: require(path.resolve(path.dirname(builderJsonPath), builder.schema)),
135 import: path.resolve(path.dirname(builderJsonPath), importPath),
136 });
137 }
138 async getCurrentDirectory() {
139 return process.cwd();
140 }
141 async getWorkspaceRoot() {
142 return this._root;
143 }
144 async getOptionsForTarget(target) {
145 if (!(await this.workspaceHost.hasTarget(target.project, target.target))) {
146 return null;
147 }
148 let options = await this.workspaceHost.getOptions(target.project, target.target);
149 const targetConfiguration = target.configuration ||
150 (await this.workspaceHost.getDefaultConfigurationName(target.project, target.target));
151 if (targetConfiguration) {
152 const configurations = targetConfiguration.split(',').map((c) => c.trim());
153 for (const configuration of configurations) {
154 options = {
155 ...options,
156 ...(await this.workspaceHost.getOptions(target.project, target.target, configuration)),
157 };
158 }
159 }
160 return clone(options);
161 }
162 async getProjectMetadata(target) {
163 const projectName = typeof target === 'string' ? target : target.project;
164 const metadata = this.workspaceHost.getMetadata(projectName);
165 return metadata;
166 }
167 async loadBuilder(info) {
168 const builder = (await Promise.resolve().then(() => __importStar(require(info.import)))).default;
169 if (builder[internal_1.BuilderSymbol]) {
170 return builder;
171 }
172 // Default handling code is for old builders that incorrectly export `default` with non-ESM module
173 if (builder === null || builder === void 0 ? void 0 : builder.default[internal_1.BuilderSymbol]) {
174 return builder.default;
175 }
176 throw new Error('Builder is not a builder');
177 }
178}
179exports.WorkspaceNodeModulesArchitectHost = WorkspaceNodeModulesArchitectHost;
Note: See TracBrowser for help on using the repository browser.