@angular-devkit/build-angular
Version:
Angular Webpack Build Facade
189 lines • 7.66 kB
JavaScript
;
/**
* @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.dev/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 () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = default_1;
exports.requiresLinking = requiresLinking;
const node_assert_1 = __importDefault(require("node:assert"));
const node_fs_1 = __importDefault(require("node:fs"));
const node_path_1 = __importDefault(require("node:path"));
/**
* Cached instance of the compiler-cli linker's needsLinking function.
*/
let needsLinking;
function createI18nDiagnostics(reporter) {
const diagnostics = new (class {
messages = [];
hasErrors = false;
add(type, message) {
if (type === 'ignore') {
return;
}
this.messages.push({ type, message });
this.hasErrors ||= type === 'error';
reporter?.(type, message);
}
error(message) {
this.add('error', message);
}
warn(message) {
this.add('warning', message);
}
merge(other) {
for (const diagnostic of other.messages) {
this.add(diagnostic.type, diagnostic.message);
}
}
formatDiagnostics() {
node_assert_1.default.fail('@angular/localize Diagnostics formatDiagnostics should not be called from within babel.');
}
})();
return diagnostics;
}
function createI18nPlugins(locale, translation, missingTranslationBehavior, diagnosticReporter, pluginCreators) {
const diagnostics = createI18nDiagnostics(diagnosticReporter);
const plugins = [];
const { makeEs2015TranslatePlugin, makeLocalePlugin } = pluginCreators;
if (translation) {
plugins.push(makeEs2015TranslatePlugin(diagnostics, translation, {
missingTranslation: missingTranslationBehavior,
}));
}
plugins.push(makeLocalePlugin(locale));
return plugins;
}
function createNgtscLogger(reporter) {
return {
level: 1, // Info level
debug(...args) { },
info(...args) {
reporter?.('info', args.join());
},
warn(...args) {
reporter?.('warning', args.join());
},
error(...args) {
reporter?.('error', args.join());
},
};
}
function default_1(api, options) {
const presets = [];
const plugins = [];
let needRuntimeTransform = false;
if (options.angularLinker?.shouldLink) {
plugins.push(options.angularLinker.linkerPluginCreator({
linkerJitMode: options.angularLinker.jitMode,
// This is a workaround until https://github.com/angular/angular/issues/42769 is fixed.
sourceMapping: false,
logger: createNgtscLogger(options.diagnosticReporter),
fileSystem: {
resolve: node_path_1.default.resolve,
exists: node_fs_1.default.existsSync,
dirname: node_path_1.default.dirname,
relative: node_path_1.default.relative,
readFile: node_fs_1.default.readFileSync,
// Node.JS types don't overlap the Compiler types.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
},
}));
}
// Applications code ES version can be controlled using TypeScript's `target` option.
// However, this doesn't effect libraries and hence we use preset-env to downlevel ES features
// based on the supported browsers in browserslist.
if (options.supportedBrowsers) {
presets.push([
require('@babel/preset-env').default,
{
bugfixes: true,
modules: false,
targets: options.supportedBrowsers,
exclude: ['transform-typeof-symbol'],
},
]);
needRuntimeTransform = true;
}
if (options.i18n) {
const { locale, missingTranslationBehavior, pluginCreators, translation } = options.i18n;
const i18nPlugins = createI18nPlugins(locale, translation, missingTranslationBehavior || 'ignore', options.diagnosticReporter, pluginCreators);
plugins.push(...i18nPlugins);
}
if (options.forceAsyncTransformation) {
// Always transform async/await to support Zone.js
plugins.push(require('@babel/plugin-transform-async-to-generator').default, require('@babel/plugin-transform-async-generator-functions').default);
needRuntimeTransform = true;
}
if (options.optimize) {
const { adjustStaticMembers, adjustTypeScriptEnums, elideAngularMetadata, markTopLevelPure, } = require('@angular/build/private');
plugins.push([markTopLevelPure, { topLevelSafeMode: options.optimize.topLevelSafeMode }], elideAngularMetadata, adjustTypeScriptEnums, [adjustStaticMembers, { wrapDecorators: options.optimize.wrapDecorators }]);
}
if (options.instrumentCode) {
plugins.push(require('../plugins/add-code-coverage').default);
}
if (needRuntimeTransform) {
// Babel equivalent to TypeScript's `importHelpers` option
plugins.push([
require('@babel/plugin-transform-runtime').default,
{
useESModules: true,
version: require('@babel/runtime/package.json').version,
absoluteRuntime: node_path_1.default.dirname(require.resolve('@babel/runtime/package.json')),
},
]);
}
return { presets, plugins };
}
async function requiresLinking(path, source) {
// @angular/core and @angular/compiler will cause false positives
// Also, TypeScript files do not require linking
if (/[\\/]@angular[\\/](?:compiler|core)|\.tsx?$/.test(path)) {
return false;
}
if (!needsLinking) {
const linkerModule = await Promise.resolve().then(() => __importStar(require('@angular/compiler-cli/linker')));
needsLinking = linkerModule.needsLinking;
}
return needsLinking(path, source);
}
//# sourceMappingURL=application.js.map