@angular/build 19.1.0-next.2 → 19.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/builders.json +5 -0
- package/index.d.ts +8 -0
- package/index.js +24 -0
- package/package.json +20 -16
- package/private/index.d.ts +8 -0
- package/private/index.js +24 -0
- package/src/builders/application/build-action.d.ts +1 -0
- package/src/builders/application/build-action.js +93 -11
- package/src/builders/application/execute-build.js +5 -2
- package/src/builders/application/index.d.ts +5 -12
- package/src/builders/application/index.js +35 -21
- package/src/builders/application/options.d.ts +6 -0
- package/src/builders/application/options.js +1 -0
- package/src/builders/application/results.d.ts +4 -1
- package/src/builders/application/setup-bundling.d.ts +2 -1
- package/src/builders/application/setup-bundling.js +2 -2
- package/src/builders/dev-server/index.d.ts +4 -2
- package/src/builders/dev-server/index.js +2 -1
- package/src/builders/dev-server/vite-server.d.ts +5 -1
- package/src/builders/dev-server/vite-server.js +101 -77
- package/src/builders/extract-i18n/index.d.ts +4 -2
- package/src/builders/extract-i18n/index.js +2 -1
- package/src/builders/ng-packagr/builder.d.ts +19 -0
- package/src/builders/ng-packagr/builder.js +103 -0
- package/src/builders/ng-packagr/index.d.ts +14 -0
- package/src/builders/ng-packagr/index.js +15 -0
- package/src/builders/ng-packagr/schema.d.ts +21 -0
- package/src/builders/ng-packagr/schema.js +4 -0
- package/src/builders/ng-packagr/schema.json +27 -0
- package/src/index.d.ts +2 -1
- package/src/index.js +3 -1
- package/src/private.d.ts +4 -7
- package/src/private.js +4 -1
- package/src/tools/babel/plugins/pure-toplevel-functions.js +14 -3
- package/src/tools/esbuild/angular/compiler-plugin.d.ts +2 -4
- package/src/tools/esbuild/angular/compiler-plugin.js +21 -10
- package/src/tools/esbuild/angular-localize-init-warning-plugin.d.ts +16 -0
- package/src/tools/esbuild/angular-localize-init-warning-plugin.js +49 -0
- package/src/tools/esbuild/application-code-bundle.d.ts +2 -1
- package/src/tools/esbuild/application-code-bundle.js +37 -26
- package/src/tools/esbuild/bundler-execution-result.d.ts +10 -3
- package/src/tools/esbuild/bundler-execution-result.js +13 -10
- package/src/tools/esbuild/compiler-plugin-options.js +0 -1
- package/src/tools/esbuild/javascript-transformer.js +8 -4
- package/src/tools/vite/middlewares/assets-middleware.d.ts +2 -2
- package/src/tools/vite/middlewares/assets-middleware.js +4 -4
- package/src/tools/vite/plugins/angular-memory-plugin.js +10 -5
- package/src/tools/vite/plugins/setup-middlewares-plugin.d.ts +2 -2
- package/src/tools/vite/utils.d.ts +5 -1
- package/src/tools/vite/utils.js +2 -1
- package/src/utils/bundle-calculator.d.ts +1 -0
- package/src/utils/bundle-calculator.js +5 -4
- package/src/utils/environment-options.js +1 -1
- package/src/utils/i18n-options.js +3 -3
- package/src/utils/normalize-cache.js +1 -1
- package/src/utils/server-rendering/fetch-patch.js +2 -2
- package/tsconfig-build.json +0 -6
|
@@ -103,13 +103,14 @@ async function* serveWithVite(serverOptions, builderName, builderAction, context
|
|
|
103
103
|
// https://nodejs.org/api/process.html#processsetsourcemapsenabledval
|
|
104
104
|
process.setSourceMapsEnabled(true);
|
|
105
105
|
}
|
|
106
|
-
// Enable to support link-based component style hot reloading (`NG_HMR_CSTYLES=
|
|
106
|
+
// Enable to support link-based component style hot reloading (`NG_HMR_CSTYLES=1` can be used to enable)
|
|
107
107
|
browserOptions.externalRuntimeStyles =
|
|
108
108
|
serverOptions.liveReload && serverOptions.hmr && environment_options_1.useComponentStyleHmr;
|
|
109
109
|
// Enable to support component template hot replacement (`NG_HMR_TEMPLATE=0` can be used to disable selectively)
|
|
110
110
|
// This will also replace file-based/inline styles as code if external runtime styles are not enabled.
|
|
111
111
|
browserOptions.templateUpdates =
|
|
112
112
|
serverOptions.liveReload && serverOptions.hmr && environment_options_1.useComponentTemplateHmr;
|
|
113
|
+
browserOptions.incrementalResults = true;
|
|
113
114
|
// Setup the prebundling transformer that will be shared across Vite prebundling requests
|
|
114
115
|
const prebundleTransformer = new internal_1.JavaScriptTransformer(
|
|
115
116
|
// Always enable JIT linking to support applications built with and without AOT.
|
|
@@ -179,10 +180,12 @@ async function* serveWithVite(serverOptions, builderName, builderAction, context
|
|
|
179
180
|
: baseHref;
|
|
180
181
|
}
|
|
181
182
|
assetFiles.clear();
|
|
183
|
+
componentStyles.clear();
|
|
184
|
+
generatedFiles.clear();
|
|
182
185
|
for (const [outputPath, file] of Object.entries(result.files)) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
+
updateResultRecord(outputPath, file, normalizePath, htmlIndexPath, generatedFiles, assetFiles, componentStyles,
|
|
187
|
+
// The initial build will not yet have a server setup
|
|
188
|
+
!server);
|
|
186
189
|
}
|
|
187
190
|
// Invalidate SSR module graph to ensure that only new rebuild is used and not stale component updates
|
|
188
191
|
if (server && browserOptions.ssr && templateUpdates.size > 0) {
|
|
@@ -190,12 +193,20 @@ async function* serveWithVite(serverOptions, builderName, builderAction, context
|
|
|
190
193
|
}
|
|
191
194
|
// Clear stale template updates on code rebuilds
|
|
192
195
|
templateUpdates.clear();
|
|
193
|
-
// Analyze result files for changes
|
|
194
|
-
analyzeResultFiles(normalizePath, htmlIndexPath, result.files, generatedFiles, componentStyles);
|
|
195
196
|
break;
|
|
196
197
|
case results_1.ResultKind.Incremental:
|
|
197
198
|
(0, node_assert_1.default)(server, 'Builder must provide an initial full build before incremental results.');
|
|
198
|
-
|
|
199
|
+
for (const removed of result.removed) {
|
|
200
|
+
const filePath = '/' + normalizePath(removed.path);
|
|
201
|
+
generatedFiles.delete(filePath);
|
|
202
|
+
assetFiles.delete(filePath);
|
|
203
|
+
}
|
|
204
|
+
for (const modified of result.modified) {
|
|
205
|
+
updateResultRecord(modified, result.files[modified], normalizePath, htmlIndexPath, generatedFiles, assetFiles, componentStyles);
|
|
206
|
+
}
|
|
207
|
+
for (const added of result.added) {
|
|
208
|
+
updateResultRecord(added, result.files[added], normalizePath, htmlIndexPath, generatedFiles, assetFiles, componentStyles);
|
|
209
|
+
}
|
|
199
210
|
break;
|
|
200
211
|
case results_1.ResultKind.ComponentUpdate:
|
|
201
212
|
(0, node_assert_1.default)(serverOptions.hmr, 'Component updates are only supported with HMR enabled.');
|
|
@@ -246,9 +257,12 @@ async function* serveWithVite(serverOptions, builderName, builderAction, context
|
|
|
246
257
|
if (server) {
|
|
247
258
|
// Update fs allow list to include any new assets from the build option.
|
|
248
259
|
server.config.server.fs.allow = [
|
|
249
|
-
...new Set([
|
|
260
|
+
...new Set([
|
|
261
|
+
...server.config.server.fs.allow,
|
|
262
|
+
...[...assetFiles.values()].map(({ source }) => source),
|
|
263
|
+
]),
|
|
250
264
|
];
|
|
251
|
-
await handleUpdate(normalizePath, generatedFiles, server, serverOptions, context.logger, componentStyles);
|
|
265
|
+
await handleUpdate(normalizePath, generatedFiles, assetFiles, server, serverOptions, context.logger, componentStyles);
|
|
252
266
|
}
|
|
253
267
|
else {
|
|
254
268
|
const projectName = context.target?.project;
|
|
@@ -286,7 +300,7 @@ async function* serveWithVite(serverOptions, builderName, builderAction, context
|
|
|
286
300
|
});
|
|
287
301
|
}
|
|
288
302
|
// Setup server and start listening
|
|
289
|
-
const serverConfiguration = await setupServer(serverOptions, generatedFiles, assetFiles, browserOptions.preserveSymlinks, externalMetadata, ssrMode, prebundleTransformer, target, (0, internal_1.isZonelessApp)(polyfills), componentStyles, templateUpdates, browserOptions.loader, extensions?.middleware, transformers?.indexHtml, thirdPartySourcemaps);
|
|
303
|
+
const serverConfiguration = await setupServer(serverOptions, generatedFiles, assetFiles, browserOptions.preserveSymlinks, externalMetadata, ssrMode, prebundleTransformer, target, (0, internal_1.isZonelessApp)(polyfills), componentStyles, templateUpdates, browserOptions.loader, browserOptions.define, extensions?.middleware, transformers?.indexHtml, thirdPartySourcemaps);
|
|
290
304
|
server = await createServer(serverConfiguration);
|
|
291
305
|
await server.listen();
|
|
292
306
|
const urls = server.resolvedUrls;
|
|
@@ -321,15 +335,24 @@ async function* serveWithVite(serverOptions, builderName, builderAction, context
|
|
|
321
335
|
}
|
|
322
336
|
await new Promise((resolve) => (deferred = resolve));
|
|
323
337
|
}
|
|
324
|
-
async function handleUpdate(normalizePath, generatedFiles, server, serverOptions, logger, componentStyles) {
|
|
338
|
+
async function handleUpdate(normalizePath, generatedFiles, assetFiles, server, serverOptions, logger, componentStyles) {
|
|
325
339
|
const updatedFiles = [];
|
|
326
|
-
|
|
340
|
+
// Invalidate any updated asset
|
|
341
|
+
for (const [file, record] of assetFiles) {
|
|
342
|
+
if (!record.updated) {
|
|
343
|
+
continue;
|
|
344
|
+
}
|
|
345
|
+
record.updated = false;
|
|
346
|
+
updatedFiles.push(file);
|
|
347
|
+
}
|
|
327
348
|
// Invalidate any updated files
|
|
328
|
-
|
|
329
|
-
|
|
349
|
+
let destroyAngularServerAppCalled = false;
|
|
350
|
+
for (const [file, record] of generatedFiles) {
|
|
351
|
+
if (!record.updated) {
|
|
330
352
|
continue;
|
|
331
353
|
}
|
|
332
|
-
|
|
354
|
+
record.updated = false;
|
|
355
|
+
if (record.type === internal_1.BuildOutputFileType.ServerApplication && !destroyAngularServerAppCalled) {
|
|
333
356
|
// Clear the server app cache
|
|
334
357
|
// This must be done before module invalidation.
|
|
335
358
|
const { ɵdestroyAngularServerApp } = (await server.ssrLoadModule('/main.server.mjs'));
|
|
@@ -402,79 +425,75 @@ async function handleUpdate(normalizePath, generatedFiles, server, serverOptions
|
|
|
402
425
|
logger.info('Page reload sent to client(s).');
|
|
403
426
|
}
|
|
404
427
|
}
|
|
405
|
-
function
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
contents: file.contents,
|
|
426
|
-
servable,
|
|
427
|
-
size: file.contents.byteLength,
|
|
428
|
-
hash: file.hash,
|
|
429
|
-
type: file.type,
|
|
430
|
-
updated: false,
|
|
431
|
-
});
|
|
432
|
-
continue;
|
|
433
|
-
}
|
|
434
|
-
const existingRecord = generatedFiles.get(filePath);
|
|
435
|
-
if (existingRecord &&
|
|
436
|
-
existingRecord.size === file.contents.byteLength &&
|
|
437
|
-
existingRecord.hash === file.hash) {
|
|
438
|
-
// Same file
|
|
439
|
-
existingRecord.updated = false;
|
|
440
|
-
continue;
|
|
441
|
-
}
|
|
442
|
-
// New or updated file
|
|
428
|
+
function updateResultRecord(outputPath, file, normalizePath, htmlIndexPath, generatedFiles, assetFiles, componentStyles, initial = false) {
|
|
429
|
+
if (file.origin === 'disk') {
|
|
430
|
+
assetFiles.set('/' + normalizePath(outputPath), {
|
|
431
|
+
source: normalizePath(file.inputPath),
|
|
432
|
+
updated: !initial,
|
|
433
|
+
});
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
let filePath;
|
|
437
|
+
if (outputPath === htmlIndexPath) {
|
|
438
|
+
// Convert custom index output path to standard index path for dev-server usage.
|
|
439
|
+
// This mimics the Webpack dev-server behavior.
|
|
440
|
+
filePath = '/index.html';
|
|
441
|
+
}
|
|
442
|
+
else {
|
|
443
|
+
filePath = '/' + normalizePath(outputPath);
|
|
444
|
+
}
|
|
445
|
+
const servable = file.type === internal_1.BuildOutputFileType.Browser || file.type === internal_1.BuildOutputFileType.Media;
|
|
446
|
+
// Skip analysis of sourcemaps
|
|
447
|
+
if (filePath.endsWith('.map')) {
|
|
443
448
|
generatedFiles.set(filePath, {
|
|
444
449
|
contents: file.contents,
|
|
450
|
+
servable,
|
|
445
451
|
size: file.contents.byteLength,
|
|
446
452
|
hash: file.hash,
|
|
447
|
-
updated: true,
|
|
448
453
|
type: file.type,
|
|
449
|
-
|
|
454
|
+
updated: false,
|
|
450
455
|
});
|
|
451
|
-
|
|
452
|
-
if (filePath.endsWith('.css') && /^\/[a-f0-9]{64}\.css$/.test(filePath)) {
|
|
453
|
-
const componentStyle = componentStyles.get(filePath);
|
|
454
|
-
if (componentStyle) {
|
|
455
|
-
componentStyle.rawContent = file.contents;
|
|
456
|
-
}
|
|
457
|
-
else {
|
|
458
|
-
componentStyles.set(filePath, {
|
|
459
|
-
rawContent: file.contents,
|
|
460
|
-
});
|
|
461
|
-
}
|
|
462
|
-
}
|
|
456
|
+
return;
|
|
463
457
|
}
|
|
464
|
-
//
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
458
|
+
// New or updated file
|
|
459
|
+
generatedFiles.set(filePath, {
|
|
460
|
+
contents: file.contents,
|
|
461
|
+
size: file.contents.byteLength,
|
|
462
|
+
hash: file.hash,
|
|
463
|
+
// Consider the files updated except on the initial build result
|
|
464
|
+
updated: !initial,
|
|
465
|
+
type: file.type,
|
|
466
|
+
servable,
|
|
467
|
+
});
|
|
468
|
+
// Record any external component styles
|
|
469
|
+
if (filePath.endsWith('.css') && /^\/[a-f0-9]{64}\.css$/.test(filePath)) {
|
|
470
|
+
const componentStyle = componentStyles.get(filePath);
|
|
471
|
+
if (componentStyle) {
|
|
472
|
+
componentStyle.rawContent = file.contents;
|
|
473
|
+
}
|
|
474
|
+
else {
|
|
475
|
+
componentStyles.set(filePath, {
|
|
476
|
+
rawContent: file.contents,
|
|
477
|
+
});
|
|
469
478
|
}
|
|
470
479
|
}
|
|
471
480
|
}
|
|
472
|
-
async function setupServer(serverOptions, outputFiles, assets, preserveSymlinks, externalMetadata, ssrMode, prebundleTransformer, target, zoneless, componentStyles, templateUpdates, prebundleLoaderExtensions, extensionMiddleware, indexHtmlTransformer, thirdPartySourcemaps = false) {
|
|
481
|
+
async function setupServer(serverOptions, outputFiles, assets, preserveSymlinks, externalMetadata, ssrMode, prebundleTransformer, target, zoneless, componentStyles, templateUpdates, prebundleLoaderExtensions, define, extensionMiddleware, indexHtmlTransformer, thirdPartySourcemaps = false) {
|
|
473
482
|
const proxy = await (0, utils_2.loadProxyConfiguration)(serverOptions.workspaceRoot, serverOptions.proxyConfig);
|
|
474
483
|
// dynamically import Vite for ESM compatibility
|
|
475
484
|
const { normalizePath } = await (0, load_esm_1.loadEsmModule)('vite');
|
|
476
485
|
// Path will not exist on disk and only used to provide separate path for Vite requests
|
|
477
486
|
const virtualProjectRoot = normalizePath((0, node_path_1.join)(serverOptions.workspaceRoot, `.angular/vite-root`, serverOptions.buildTarget.project));
|
|
487
|
+
// Files used for SSR warmup.
|
|
488
|
+
let ssrFiles;
|
|
489
|
+
switch (ssrMode) {
|
|
490
|
+
case plugins_1.ServerSsrMode.InternalSsrMiddleware:
|
|
491
|
+
ssrFiles = ['./main.server.mjs'];
|
|
492
|
+
break;
|
|
493
|
+
case plugins_1.ServerSsrMode.ExternalSsrMiddleware:
|
|
494
|
+
ssrFiles = ['./main.server.mjs', './server.mjs'];
|
|
495
|
+
break;
|
|
496
|
+
}
|
|
478
497
|
const cacheDir = (0, node_path_1.join)(serverOptions.cacheOptions.path, serverOptions.buildTarget.project, 'vite');
|
|
479
498
|
const configuration = {
|
|
480
499
|
configFile: false,
|
|
@@ -505,7 +524,7 @@ async function setupServer(serverOptions, outputFiles, assets, preserveSymlinks,
|
|
|
505
524
|
},
|
|
506
525
|
server: {
|
|
507
526
|
warmup: {
|
|
508
|
-
ssrFiles
|
|
527
|
+
ssrFiles,
|
|
509
528
|
},
|
|
510
529
|
port: serverOptions.port,
|
|
511
530
|
strictPort: true,
|
|
@@ -533,7 +552,11 @@ async function setupServer(serverOptions, outputFiles, assets, preserveSymlinks,
|
|
|
533
552
|
// The first two are required for Vite to function in prebundling mode (the default) and to load
|
|
534
553
|
// the Vite client-side code for browser reloading. These would be available by default but when
|
|
535
554
|
// the `allow` option is explicitly configured, they must be included manually.
|
|
536
|
-
allow: [
|
|
555
|
+
allow: [
|
|
556
|
+
cacheDir,
|
|
557
|
+
(0, node_path_1.join)(serverOptions.workspaceRoot, 'node_modules'),
|
|
558
|
+
...[...assets.values()].map(({ source }) => source),
|
|
559
|
+
],
|
|
537
560
|
},
|
|
538
561
|
// This is needed when `externalDependencies` is used to prevent Vite load errors.
|
|
539
562
|
// NOTE: If Vite adds direct support for externals, this can be removed.
|
|
@@ -557,6 +580,7 @@ async function setupServer(serverOptions, outputFiles, assets, preserveSymlinks,
|
|
|
557
580
|
target,
|
|
558
581
|
loader: prebundleLoaderExtensions,
|
|
559
582
|
thirdPartySourcemaps,
|
|
583
|
+
define,
|
|
560
584
|
}),
|
|
561
585
|
},
|
|
562
586
|
plugins: [
|
|
@@ -594,12 +618,13 @@ async function setupServer(serverOptions, outputFiles, assets, preserveSymlinks,
|
|
|
594
618
|
zoneless,
|
|
595
619
|
loader: prebundleLoaderExtensions,
|
|
596
620
|
thirdPartySourcemaps,
|
|
621
|
+
define,
|
|
597
622
|
}),
|
|
598
623
|
};
|
|
599
624
|
if (serverOptions.ssl) {
|
|
600
625
|
if (serverOptions.sslCert && serverOptions.sslKey) {
|
|
626
|
+
configuration.server ??= {};
|
|
601
627
|
// server configuration is defined above
|
|
602
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
603
628
|
configuration.server.https = {
|
|
604
629
|
cert: await (0, promises_1.readFile)(serverOptions.sslCert),
|
|
605
630
|
key: await (0, promises_1.readFile)(serverOptions.sslKey),
|
|
@@ -607,7 +632,6 @@ async function setupServer(serverOptions, outputFiles, assets, preserveSymlinks,
|
|
|
607
632
|
}
|
|
608
633
|
else {
|
|
609
634
|
const { default: basicSslPlugin } = await Promise.resolve().then(() => __importStar(require('@vitejs/plugin-basic-ssl')));
|
|
610
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
611
635
|
configuration.plugins ??= [];
|
|
612
636
|
configuration.plugins.push(basicSslPlugin());
|
|
613
637
|
}
|
|
@@ -5,8 +5,10 @@
|
|
|
5
5
|
* Use of this source code is governed by an MIT-style license that can be
|
|
6
6
|
* found in the LICENSE file at https://angular.dev/license
|
|
7
7
|
*/
|
|
8
|
+
import { Builder } from '@angular-devkit/architect';
|
|
9
|
+
import { json } from '@angular-devkit/core';
|
|
8
10
|
import { execute } from './builder';
|
|
9
11
|
import type { Schema as ExtractI18nBuilderOptions } from './schema';
|
|
10
12
|
export { ExtractI18nBuilderOptions, execute };
|
|
11
|
-
declare const
|
|
12
|
-
export default
|
|
13
|
+
declare const builder: Builder<ExtractI18nBuilderOptions & json.JsonObject>;
|
|
14
|
+
export default builder;
|
|
@@ -11,4 +11,5 @@ exports.execute = void 0;
|
|
|
11
11
|
const architect_1 = require("@angular-devkit/architect");
|
|
12
12
|
const builder_1 = require("./builder");
|
|
13
13
|
Object.defineProperty(exports, "execute", { enumerable: true, get: function () { return builder_1.execute; } });
|
|
14
|
-
|
|
14
|
+
const builder = (0, architect_1.createBuilder)(builder_1.execute);
|
|
15
|
+
exports.default = builder;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
7
|
+
*/
|
|
8
|
+
import type { BuilderContext, BuilderOutput } from '@angular-devkit/architect';
|
|
9
|
+
import type { Schema as NgPackagrBuilderOptions } from './schema';
|
|
10
|
+
/**
|
|
11
|
+
* A Builder that executes the `ng-packagr` tool to build an Angular library.
|
|
12
|
+
*
|
|
13
|
+
* @param options The builder options as defined by the JSON schema.
|
|
14
|
+
* @param context A BuilderContext instance.
|
|
15
|
+
* @returns A BuilderOutput object.
|
|
16
|
+
*
|
|
17
|
+
* @experimental Direct usage of this function is considered experimental.
|
|
18
|
+
*/
|
|
19
|
+
export declare function execute(options: NgPackagrBuilderOptions, context: BuilderContext): AsyncIterableIterator<BuilderOutput>;
|
|
@@ -0,0 +1,103 @@
|
|
|
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.dev/license
|
|
8
|
+
*/
|
|
9
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
12
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
13
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
14
|
+
}
|
|
15
|
+
Object.defineProperty(o, k2, desc);
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
+
}) : function(o, v) {
|
|
23
|
+
o["default"] = v;
|
|
24
|
+
});
|
|
25
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
26
|
+
var ownKeys = function(o) {
|
|
27
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
28
|
+
var ar = [];
|
|
29
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
30
|
+
return ar;
|
|
31
|
+
};
|
|
32
|
+
return ownKeys(o);
|
|
33
|
+
};
|
|
34
|
+
return function (mod) {
|
|
35
|
+
if (mod && mod.__esModule) return mod;
|
|
36
|
+
var result = {};
|
|
37
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
38
|
+
__setModuleDefault(result, mod);
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
41
|
+
})();
|
|
42
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
+
exports.execute = execute;
|
|
44
|
+
const node_path_1 = require("node:path");
|
|
45
|
+
const error_1 = require("../../utils/error");
|
|
46
|
+
const normalize_cache_1 = require("../../utils/normalize-cache");
|
|
47
|
+
const purge_cache_1 = require("../../utils/purge-cache");
|
|
48
|
+
/**
|
|
49
|
+
* A Builder that executes the `ng-packagr` tool to build an Angular library.
|
|
50
|
+
*
|
|
51
|
+
* @param options The builder options as defined by the JSON schema.
|
|
52
|
+
* @param context A BuilderContext instance.
|
|
53
|
+
* @returns A BuilderOutput object.
|
|
54
|
+
*
|
|
55
|
+
* @experimental Direct usage of this function is considered experimental.
|
|
56
|
+
*/
|
|
57
|
+
async function* execute(options, context) {
|
|
58
|
+
// Purge old build disk cache.
|
|
59
|
+
await (0, purge_cache_1.purgeStaleBuildCache)(context);
|
|
60
|
+
const root = context.workspaceRoot;
|
|
61
|
+
let packager;
|
|
62
|
+
try {
|
|
63
|
+
packager = (await Promise.resolve().then(() => __importStar(require('ng-packagr')))).ngPackagr();
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
(0, error_1.assertIsError)(error);
|
|
67
|
+
if (error.code === 'MODULE_NOT_FOUND') {
|
|
68
|
+
return {
|
|
69
|
+
success: false,
|
|
70
|
+
error: 'The "ng-packagr" package was not found. To correct this error, ensure this package is installed in the project.',
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
packager.forProject((0, node_path_1.resolve)(root, options.project));
|
|
76
|
+
if (options.tsConfig) {
|
|
77
|
+
packager.withTsConfig((0, node_path_1.resolve)(root, options.tsConfig));
|
|
78
|
+
}
|
|
79
|
+
const projectName = context.target?.project;
|
|
80
|
+
if (!projectName) {
|
|
81
|
+
throw new Error('The builder requires a target.');
|
|
82
|
+
}
|
|
83
|
+
const metadata = await context.getProjectMetadata(projectName);
|
|
84
|
+
const { enabled: cacheEnabled, path: cacheDirectory } = (0, normalize_cache_1.normalizeCacheOptions)(metadata, context.workspaceRoot);
|
|
85
|
+
const ngPackagrOptions = {
|
|
86
|
+
cacheEnabled,
|
|
87
|
+
poll: options.poll,
|
|
88
|
+
cacheDirectory: (0, node_path_1.join)(cacheDirectory, 'ng-packagr'),
|
|
89
|
+
};
|
|
90
|
+
try {
|
|
91
|
+
if (options.watch) {
|
|
92
|
+
await packager.watch(ngPackagrOptions).toPromise();
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
await packager.build(ngPackagrOptions);
|
|
96
|
+
}
|
|
97
|
+
yield { success: true };
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
(0, error_1.assertIsError)(error);
|
|
101
|
+
yield { success: false, error: error.message };
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
7
|
+
*/
|
|
8
|
+
import { Builder } from '@angular-devkit/architect';
|
|
9
|
+
import { json } from '@angular-devkit/core';
|
|
10
|
+
import { execute } from './builder';
|
|
11
|
+
import type { Schema as NgPackagrBuilderOptions } from './schema';
|
|
12
|
+
export { type NgPackagrBuilderOptions, execute };
|
|
13
|
+
declare const builder: Builder<NgPackagrBuilderOptions & json.JsonObject>;
|
|
14
|
+
export default builder;
|
|
@@ -0,0 +1,15 @@
|
|
|
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.dev/license
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.execute = void 0;
|
|
11
|
+
const architect_1 = require("@angular-devkit/architect");
|
|
12
|
+
const builder_1 = require("./builder");
|
|
13
|
+
Object.defineProperty(exports, "execute", { enumerable: true, get: function () { return builder_1.execute; } });
|
|
14
|
+
const builder = (0, architect_1.createBuilder)(builder_1.execute);
|
|
15
|
+
exports.default = builder;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ng-packagr target options for Build Architect. Use to build library projects.
|
|
3
|
+
*/
|
|
4
|
+
export interface Schema {
|
|
5
|
+
/**
|
|
6
|
+
* Enable and define the file watching poll time period in milliseconds.
|
|
7
|
+
*/
|
|
8
|
+
poll?: number;
|
|
9
|
+
/**
|
|
10
|
+
* The file path for the ng-packagr configuration file, relative to the current workspace.
|
|
11
|
+
*/
|
|
12
|
+
project: string;
|
|
13
|
+
/**
|
|
14
|
+
* The full path for the TypeScript configuration file, relative to the current workspace.
|
|
15
|
+
*/
|
|
16
|
+
tsConfig?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Run build when files change.
|
|
19
|
+
*/
|
|
20
|
+
watch?: boolean;
|
|
21
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema",
|
|
3
|
+
"title": "ng-packagr Target",
|
|
4
|
+
"description": "ng-packagr target options for Build Architect. Use to build library projects.",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"project": {
|
|
8
|
+
"type": "string",
|
|
9
|
+
"description": "The file path for the ng-packagr configuration file, relative to the current workspace."
|
|
10
|
+
},
|
|
11
|
+
"tsConfig": {
|
|
12
|
+
"type": "string",
|
|
13
|
+
"description": "The full path for the TypeScript configuration file, relative to the current workspace."
|
|
14
|
+
},
|
|
15
|
+
"watch": {
|
|
16
|
+
"type": "boolean",
|
|
17
|
+
"description": "Run build when files change.",
|
|
18
|
+
"default": false
|
|
19
|
+
},
|
|
20
|
+
"poll": {
|
|
21
|
+
"type": "number",
|
|
22
|
+
"description": "Enable and define the file watching poll time period in milliseconds."
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"additionalProperties": false,
|
|
26
|
+
"required": ["project"]
|
|
27
|
+
}
|
package/src/index.d.ts
CHANGED
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
* Use of this source code is governed by an MIT-style license that can be
|
|
6
6
|
* found in the LICENSE file at https://angular.dev/license
|
|
7
7
|
*/
|
|
8
|
-
export { buildApplication, type ApplicationBuilderOptions
|
|
8
|
+
export { buildApplication, type ApplicationBuilderOptions } from './builders/application';
|
|
9
9
|
export type { ApplicationBuilderExtensions } from './builders/application/options';
|
|
10
10
|
export { type BuildOutputFile, BuildOutputFileType } from './tools/esbuild/bundler-context';
|
|
11
11
|
export type { BuildOutputAsset } from './tools/esbuild/bundler-execution-result';
|
|
12
12
|
export { executeDevServerBuilder, type DevServerBuilderOptions, type DevServerBuilderOutput, } from './builders/dev-server';
|
|
13
13
|
export { execute as executeExtractI18nBuilder, type ExtractI18nBuilderOptions, } from './builders/extract-i18n';
|
|
14
|
+
export { execute as executeNgPackagrBuilder, type NgPackagrBuilderOptions, } from './builders/ng-packagr';
|
package/src/index.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* found in the LICENSE file at https://angular.dev/license
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.executeExtractI18nBuilder = exports.executeDevServerBuilder = exports.BuildOutputFileType = exports.buildApplication = void 0;
|
|
10
|
+
exports.executeNgPackagrBuilder = exports.executeExtractI18nBuilder = exports.executeDevServerBuilder = exports.BuildOutputFileType = exports.buildApplication = void 0;
|
|
11
11
|
var application_1 = require("./builders/application");
|
|
12
12
|
Object.defineProperty(exports, "buildApplication", { enumerable: true, get: function () { return application_1.buildApplication; } });
|
|
13
13
|
var bundler_context_1 = require("./tools/esbuild/bundler-context");
|
|
@@ -16,3 +16,5 @@ var dev_server_1 = require("./builders/dev-server");
|
|
|
16
16
|
Object.defineProperty(exports, "executeDevServerBuilder", { enumerable: true, get: function () { return dev_server_1.executeDevServerBuilder; } });
|
|
17
17
|
var extract_i18n_1 = require("./builders/extract-i18n");
|
|
18
18
|
Object.defineProperty(exports, "executeExtractI18nBuilder", { enumerable: true, get: function () { return extract_i18n_1.execute; } });
|
|
19
|
+
var ng_packagr_1 = require("./builders/ng-packagr");
|
|
20
|
+
Object.defineProperty(exports, "executeNgPackagrBuilder", { enumerable: true, get: function () { return ng_packagr_1.execute; } });
|
package/src/private.d.ts
CHANGED
|
@@ -5,12 +5,6 @@
|
|
|
5
5
|
* Use of this source code is governed by an MIT-style license that can be
|
|
6
6
|
* found in the LICENSE file at https://angular.dev/license
|
|
7
7
|
*/
|
|
8
|
-
/**
|
|
9
|
-
* @fileoverview
|
|
10
|
-
* Private exports intended only for use with the @angular-devkit/build-angular package.
|
|
11
|
-
* All exports are not supported for external use, do not provide SemVer guarantees, and
|
|
12
|
-
* their existence may change in any future version.
|
|
13
|
-
*/
|
|
14
8
|
import { CompilerPluginOptions } from './tools/esbuild/angular/compiler-plugin';
|
|
15
9
|
import { BundleStylesheetOptions } from './tools/esbuild/stylesheets/bundle-options';
|
|
16
10
|
export { buildApplicationInternal } from './builders/application';
|
|
@@ -25,7 +19,10 @@ export { SassWorkerImplementation } from './tools/sass/sass-service';
|
|
|
25
19
|
export { SourceFileCache } from './tools/esbuild/angular/source-file-cache';
|
|
26
20
|
export { createJitResourceTransformer } from './tools/angular/transformers/jit-resource-transformer';
|
|
27
21
|
export { JavaScriptTransformer } from './tools/esbuild/javascript-transformer';
|
|
28
|
-
export declare function createCompilerPlugin(pluginOptions: CompilerPluginOptions
|
|
22
|
+
export declare function createCompilerPlugin(pluginOptions: CompilerPluginOptions & {
|
|
23
|
+
browserOnlyBuild?: boolean;
|
|
24
|
+
noopTypeScriptCompilation?: boolean;
|
|
25
|
+
}, styleOptions: BundleStylesheetOptions & {
|
|
29
26
|
inlineStyleLanguage: string;
|
|
30
27
|
}): import('esbuild').Plugin;
|
|
31
28
|
export * from './utils/bundle-calculator';
|
package/src/private.js
CHANGED
|
@@ -29,6 +29,7 @@ exports.createCompilerPlugin = createCompilerPlugin;
|
|
|
29
29
|
* All exports are not supported for external use, do not provide SemVer guarantees, and
|
|
30
30
|
* their existence may change in any future version.
|
|
31
31
|
*/
|
|
32
|
+
const compilation_1 = require("./tools/angular/compilation");
|
|
32
33
|
const compiler_plugin_1 = require("./tools/esbuild/angular/compiler-plugin");
|
|
33
34
|
const component_stylesheets_1 = require("./tools/esbuild/angular/component-stylesheets");
|
|
34
35
|
// Builders
|
|
@@ -53,7 +54,9 @@ Object.defineProperty(exports, "createJitResourceTransformer", { enumerable: tru
|
|
|
53
54
|
var javascript_transformer_1 = require("./tools/esbuild/javascript-transformer");
|
|
54
55
|
Object.defineProperty(exports, "JavaScriptTransformer", { enumerable: true, get: function () { return javascript_transformer_1.JavaScriptTransformer; } });
|
|
55
56
|
function createCompilerPlugin(pluginOptions, styleOptions) {
|
|
56
|
-
return (0, compiler_plugin_1.createCompilerPlugin)(pluginOptions,
|
|
57
|
+
return (0, compiler_plugin_1.createCompilerPlugin)(pluginOptions, pluginOptions.noopTypeScriptCompilation
|
|
58
|
+
? new compilation_1.NoopCompilation()
|
|
59
|
+
: () => (0, compilation_1.createAngularCompilation)(!!pluginOptions.jit, !!pluginOptions.browserOnlyBuild), new component_stylesheets_1.ComponentStylesheetBundler(styleOptions, styleOptions.inlineStyleLanguage, pluginOptions.incremental));
|
|
57
60
|
}
|
|
58
61
|
// Utilities
|
|
59
62
|
__exportStar(require("./utils/bundle-calculator"), exports);
|
|
@@ -64,6 +64,16 @@ function isTslibHelperName(name) {
|
|
|
64
64
|
}
|
|
65
65
|
return tslibHelpers.has(originalName);
|
|
66
66
|
}
|
|
67
|
+
const babelHelpers = new Set(['_defineProperty']);
|
|
68
|
+
/**
|
|
69
|
+
* Determinates whether an identifier name matches one of the Babel helper function names.
|
|
70
|
+
*
|
|
71
|
+
* @param name The identifier name to check.
|
|
72
|
+
* @returns True, if the name matches a Babel helper name; otherwise, false.
|
|
73
|
+
*/
|
|
74
|
+
function isBabelHelperName(name) {
|
|
75
|
+
return babelHelpers.has(name);
|
|
76
|
+
}
|
|
67
77
|
/**
|
|
68
78
|
* A babel plugin factory function for adding the PURE annotation to top-level new and call expressions.
|
|
69
79
|
*
|
|
@@ -82,9 +92,10 @@ function default_1() {
|
|
|
82
92
|
path.node.arguments.length !== 0) {
|
|
83
93
|
return;
|
|
84
94
|
}
|
|
85
|
-
// Do not annotate TypeScript helpers emitted by the TypeScript compiler.
|
|
86
|
-
//
|
|
87
|
-
if (callee.isIdentifier() &&
|
|
95
|
+
// Do not annotate TypeScript helpers emitted by the TypeScript compiler or Babel helpers.
|
|
96
|
+
// They are intended to cause side effects.
|
|
97
|
+
if (callee.isIdentifier() &&
|
|
98
|
+
(isTslibHelperName(callee.node.name) || isBabelHelperName(callee.node.name))) {
|
|
88
99
|
return;
|
|
89
100
|
}
|
|
90
101
|
(0, helper_annotate_as_pure_1.default)(path);
|