225 lines
30 KiB
JavaScript
225 lines
30 KiB
JavaScript
"use strict";
|
|
/**
|
|
* @license
|
|
* Copyright Google LLC All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.io/license
|
|
*/
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
}
|
|
Object.defineProperty(o, k2, desc);
|
|
}) : (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
o[k2] = m[k];
|
|
}));
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
}) : function(o, v) {
|
|
o["default"] = v;
|
|
});
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
if (mod && mod.__esModule) return mod;
|
|
var result = {};
|
|
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
__setModuleDefault(result, mod);
|
|
return result;
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.WorkspaceNodeModulesArchitectHost = void 0;
|
|
const path = __importStar(require("path"));
|
|
const url_1 = require("url");
|
|
const v8_1 = require("v8");
|
|
const internal_1 = require("../src/internal");
|
|
function clone(obj) {
|
|
try {
|
|
return (0, v8_1.deserialize)((0, v8_1.serialize)(obj));
|
|
}
|
|
catch {
|
|
return JSON.parse(JSON.stringify(obj));
|
|
}
|
|
}
|
|
function findProjectTarget(workspace, project, target) {
|
|
const projectDefinition = workspace.projects.get(project);
|
|
if (!projectDefinition) {
|
|
throw new Error(`Project "${project}" does not exist.`);
|
|
}
|
|
const targetDefinition = projectDefinition.targets.get(target);
|
|
if (!targetDefinition) {
|
|
throw new Error('Project target does not exist.');
|
|
}
|
|
return targetDefinition;
|
|
}
|
|
class WorkspaceNodeModulesArchitectHost {
|
|
constructor(workspaceOrHost, _root) {
|
|
this._root = _root;
|
|
if ('getBuilderName' in workspaceOrHost) {
|
|
this.workspaceHost = workspaceOrHost;
|
|
}
|
|
else {
|
|
this.workspaceHost = {
|
|
async getBuilderName(project, target) {
|
|
const targetDefinition = findProjectTarget(workspaceOrHost, project, target);
|
|
return targetDefinition.builder;
|
|
},
|
|
async getOptions(project, target, configuration) {
|
|
const targetDefinition = findProjectTarget(workspaceOrHost, project, target);
|
|
if (configuration === undefined) {
|
|
return (targetDefinition.options ?? {});
|
|
}
|
|
if (!targetDefinition.configurations?.[configuration]) {
|
|
throw new Error(`Configuration '${configuration}' is not set in the workspace.`);
|
|
}
|
|
return (targetDefinition.configurations?.[configuration] ?? {});
|
|
},
|
|
async getMetadata(project) {
|
|
const projectDefinition = workspaceOrHost.projects.get(project);
|
|
if (!projectDefinition) {
|
|
throw new Error(`Project "${project}" does not exist.`);
|
|
}
|
|
return {
|
|
root: projectDefinition.root,
|
|
sourceRoot: projectDefinition.sourceRoot,
|
|
prefix: projectDefinition.prefix,
|
|
...clone(workspaceOrHost.extensions),
|
|
...clone(projectDefinition.extensions),
|
|
};
|
|
},
|
|
async hasTarget(project, target) {
|
|
return !!workspaceOrHost.projects.get(project)?.targets.has(target);
|
|
},
|
|
async getDefaultConfigurationName(project, target) {
|
|
return workspaceOrHost.projects.get(project)?.targets.get(target)?.defaultConfiguration;
|
|
},
|
|
};
|
|
}
|
|
}
|
|
async getBuilderNameForTarget(target) {
|
|
return this.workspaceHost.getBuilderName(target.project, target.target);
|
|
}
|
|
/**
|
|
* Resolve a builder. This needs to be a string which will be used in a dynamic `import()`
|
|
* clause. This should throw if no builder can be found. The dynamic import will throw if
|
|
* it is unsupported.
|
|
* @param builderStr The name of the builder to be used.
|
|
* @returns All the info needed for the builder itself.
|
|
*/
|
|
resolveBuilder(builderStr) {
|
|
const [packageName, builderName] = builderStr.split(':', 2);
|
|
if (!builderName) {
|
|
throw new Error('No builder name specified.');
|
|
}
|
|
const packageJsonPath = require.resolve(packageName + '/package.json', {
|
|
paths: [this._root],
|
|
});
|
|
const packageJson = require(packageJsonPath);
|
|
if (!packageJson['builders']) {
|
|
throw new Error(`Package ${JSON.stringify(packageName)} has no builders defined.`);
|
|
}
|
|
const builderJsonPath = path.resolve(path.dirname(packageJsonPath), packageJson['builders']);
|
|
const builderJson = require(builderJsonPath);
|
|
const builder = builderJson.builders && builderJson.builders[builderName];
|
|
if (!builder) {
|
|
throw new Error(`Cannot find builder ${JSON.stringify(builderStr)}.`);
|
|
}
|
|
const importPath = builder.implementation;
|
|
if (!importPath) {
|
|
throw new Error('Could not find the implementation for builder ' + builderStr);
|
|
}
|
|
return Promise.resolve({
|
|
name: builderStr,
|
|
builderName,
|
|
description: builder['description'],
|
|
optionSchema: require(path.resolve(path.dirname(builderJsonPath), builder.schema)),
|
|
import: path.resolve(path.dirname(builderJsonPath), importPath),
|
|
});
|
|
}
|
|
async getCurrentDirectory() {
|
|
return process.cwd();
|
|
}
|
|
async getWorkspaceRoot() {
|
|
return this._root;
|
|
}
|
|
async getOptionsForTarget(target) {
|
|
if (!(await this.workspaceHost.hasTarget(target.project, target.target))) {
|
|
return null;
|
|
}
|
|
let options = await this.workspaceHost.getOptions(target.project, target.target);
|
|
const targetConfiguration = target.configuration ||
|
|
(await this.workspaceHost.getDefaultConfigurationName(target.project, target.target));
|
|
if (targetConfiguration) {
|
|
const configurations = targetConfiguration.split(',').map((c) => c.trim());
|
|
for (const configuration of configurations) {
|
|
options = {
|
|
...options,
|
|
...(await this.workspaceHost.getOptions(target.project, target.target, configuration)),
|
|
};
|
|
}
|
|
}
|
|
return clone(options);
|
|
}
|
|
async getProjectMetadata(target) {
|
|
const projectName = typeof target === 'string' ? target : target.project;
|
|
const metadata = this.workspaceHost.getMetadata(projectName);
|
|
return metadata;
|
|
}
|
|
async loadBuilder(info) {
|
|
const builder = await getBuilder(info.import);
|
|
if (builder[internal_1.BuilderSymbol]) {
|
|
return builder;
|
|
}
|
|
// Default handling code is for old builders that incorrectly export `default` with non-ESM module
|
|
if (builder?.default[internal_1.BuilderSymbol]) {
|
|
return builder.default;
|
|
}
|
|
throw new Error('Builder is not a builder');
|
|
}
|
|
}
|
|
exports.WorkspaceNodeModulesArchitectHost = WorkspaceNodeModulesArchitectHost;
|
|
/**
|
|
* This uses a dynamic import to load a module which may be ESM.
|
|
* CommonJS code can load ESM code via a dynamic import. Unfortunately, TypeScript
|
|
* will currently, unconditionally downlevel dynamic import into a require call.
|
|
* require calls cannot load ESM code and will result in a runtime error. To workaround
|
|
* this, a Function constructor is used to prevent TypeScript from changing the dynamic import.
|
|
* Once TypeScript provides support for keeping the dynamic import this workaround can
|
|
* be dropped.
|
|
*
|
|
* @param modulePath The path of the module to load.
|
|
* @returns A Promise that resolves to the dynamically imported module.
|
|
*/
|
|
function loadEsmModule(modulePath) {
|
|
return new Function('modulePath', `return import(modulePath);`)(modulePath);
|
|
}
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
async function getBuilder(builderPath) {
|
|
switch (path.extname(builderPath)) {
|
|
case '.mjs':
|
|
// Load the ESM configuration file using the TypeScript dynamic import workaround.
|
|
// Once TypeScript provides support for keeping the dynamic import this workaround can be
|
|
// changed to a direct dynamic import.
|
|
return (await loadEsmModule((0, url_1.pathToFileURL)(builderPath))).default;
|
|
case '.cjs':
|
|
return require(builderPath);
|
|
default:
|
|
// The file could be either CommonJS or ESM.
|
|
// CommonJS is tried first then ESM if loading fails.
|
|
try {
|
|
return require(builderPath);
|
|
}
|
|
catch (e) {
|
|
if (e.code === 'ERR_REQUIRE_ESM') {
|
|
// Load the ESM configuration file using the TypeScript dynamic import workaround.
|
|
// Once TypeScript provides support for keeping the dynamic import this workaround can be
|
|
// changed to a direct dynamic import.
|
|
return (await loadEsmModule((0, url_1.pathToFileURL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WN0VGFyZ2V0KHdvcmtzcGFjZU9ySG9zdCwgcHJvamVjdCwgdGFyZ2V0KTtcblxuICAgICAgICAgIGlmIChjb25maWd1cmF0aW9uID09PSB1bmRlZmluZWQpIHtcbiAgICAgICAgICAgIHJldHVybiAodGFyZ2V0RGVmaW5pdGlvbi5vcHRpb25zID8/IHt9KSBhcyBqc29uLkpzb25PYmplY3Q7XG4gICAgICAgICAgfVxuXG4gICAgICAgICAgaWYgKCF0YXJnZXREZWZpbml0aW9uLmNvbmZpZ3VyYXRpb25zPy5bY29uZmlndXJhdGlvbl0pIHtcbiAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcihgQ29uZmlndXJhdGlvbiAnJHtjb25maWd1cmF0aW9ufScgaXMgbm90IHNldCBpbiB0aGUgd29ya3NwYWNlLmApO1xuICAgICAgICAgIH1cblxuICAgICAgICAgIHJldHVybiAodGFyZ2V0RGVmaW5pdGlvbi5jb25maWd1cmF0aW9ucz8uW2NvbmZpZ3VyYXRpb25dID8/IHt9KSBhcyBqc29uLkpzb25PYmplY3Q7XG4gICAgICAgIH0sXG4gICAgICAgIGFzeW5jIGdldE1ldGFkYXRhKHByb2plY3QpIHtcbiAgICAgICAgICBjb25zdCBwcm9qZWN0RGVmaW5pdGlvbiA9IHdvcmtzcGFjZU9ySG9zdC5wcm9qZWN0cy5nZXQocHJvamVjdCk7XG4gICAgICAgICAgaWYgKCFwcm9qZWN0RGVmaW5pdGlvbikge1xuICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKGBQcm9qZWN0IFwiJHtwcm9qZWN0fVwiIGRvZXMgbm90IGV4aXN0LmApO1xuICAgICAgICAgIH1cblxuICAgICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICByb290OiBwcm9qZWN0RGVmaW5pdGlvbi5yb290LFxuICAgICAgICAgICAgc291cmNlUm9vdDogcHJvamVjdERlZmluaXRpb24uc291cmNlUm9vdCxcbiAgICAgICAgICAgIHByZWZpeDogcHJvamVjdERlZmluaXRpb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