ng-packagr
Version:
Compile and package Angular libraries in Angular Package Format (APF)
66 lines • 3.07 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.compileNgcTransformFactory = void 0;
const node_path_1 = require("node:path");
const ora_1 = __importDefault(require("ora"));
const typescript_1 = __importDefault(require("typescript"));
const select_1 = require("../../graph/select");
const transform_1 = require("../../graph/transform");
const compile_source_files_1 = require("../../ngc/compile-source-files");
const tsconfig_1 = require("../../ts/tsconfig");
const nodes_1 = require("../nodes");
const compileNgcTransformFactory = (StylesheetProcessor, options) => {
return (0, transform_1.transformFromPromise)(async (graph) => {
const spinner = (0, ora_1.default)({
hideCursor: false,
discardStdin: false,
});
const entryPoints = [];
let entryPoint;
let ngPackageNode;
for (const node of graph.values()) {
if ((0, nodes_1.isEntryPoint)(node)) {
entryPoints.push(node);
if ((0, select_1.isInProgress)(node)) {
entryPoint = node;
}
}
else if ((0, nodes_1.isPackage)(node)) {
ngPackageNode = node;
}
}
const projectBasePath = ngPackageNode.data.primary.basePath;
try {
// Add paths mappings for dependencies
const tsConfig = (0, tsconfig_1.setDependenciesTsConfigPaths)(entryPoint.data.tsConfig, entryPoints);
// Compile TypeScript sources
const { esm2022: esm2022, declarations } = entryPoint.data.destinationFiles;
const { basePath, cssUrl, styleIncludePaths, sass } = entryPoint.data.entryPoint;
const { moduleResolutionCache } = entryPoint.cache;
spinner.start(`Compiling with Angular sources in ${tsConfig.options.compilationMode || 'full'} compilation mode.`);
entryPoint.cache.stylesheetProcessor ??= new StylesheetProcessor(projectBasePath, basePath, cssUrl, styleIncludePaths, sass, options.cacheEnabled && options.cacheDirectory, options.watch);
await (0, compile_source_files_1.compileSourceFiles)(graph, tsConfig, moduleResolutionCache, options, {
outDir: (0, node_path_1.dirname)(esm2022),
declarationDir: (0, node_path_1.dirname)(declarations),
declaration: true,
target: typescript_1.default.ScriptTarget.ES2022,
}, entryPoint.cache.stylesheetProcessor);
}
catch (error) {
spinner.fail();
throw error;
}
finally {
if (!options.watch) {
entryPoint.cache.stylesheetProcessor?.destroy();
}
}
spinner.succeed();
return graph;
});
};
exports.compileNgcTransformFactory = compileNgcTransformFactory;
//# sourceMappingURL=compile-ngc.transform.js.map