Skip to content

Commit fe54a60

Browse files
author
Angular Builds
committed
c2a8bf1 refactor(@angular-devkit/build-angular): move Vite dev-server @angular/build imports into separate file
1 parent fed7c00 commit fe54a60

File tree

12 files changed

+87
-29
lines changed

12 files changed

+87
-29
lines changed

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
22
"name": "@angular-devkit/build-angular",
3-
"version": "18.0.0-next.3+sha-eb8f1fa",
3+
"version": "18.0.0-next.3+sha-c2a8bf1",
44
"description": "Angular Webpack Build Facade",
55
"main": "src/index.js",
66
"typings": "src/index.d.ts",
77
"builders": "builders.json",
88
"dependencies": {
99
"@ampproject/remapping": "2.3.0",
10-
"@angular/build": "18.0.0-next.3+sha-eb8f1fa",
11-
"@angular-devkit/architect": "github:angular/angular-devkit-architect-builds#eb8f1fa",
12-
"@angular-devkit/build-webpack": "github:angular/angular-devkit-build-webpack-builds#eb8f1fa",
13-
"@angular-devkit/core": "github:angular/angular-devkit-core-builds#eb8f1fa",
10+
"@angular/build": "18.0.0-next.3+sha-c2a8bf1",
11+
"@angular-devkit/architect": "github:angular/angular-devkit-architect-builds#c2a8bf1",
12+
"@angular-devkit/build-webpack": "github:angular/angular-devkit-build-webpack-builds#c2a8bf1",
13+
"@angular-devkit/core": "github:angular/angular-devkit-core-builds#c2a8bf1",
1414
"@babel/core": "7.24.4",
1515
"@babel/generator": "7.24.4",
1616
"@babel/helper-annotate-as-pure": "7.22.5",
@@ -21,7 +21,7 @@
2121
"@babel/preset-env": "7.24.4",
2222
"@babel/runtime": "7.24.4",
2323
"@discoveryjs/json-ext": "0.5.7",
24-
"@ngtools/webpack": "github:angular/ngtools-webpack-builds#eb8f1fa",
24+
"@ngtools/webpack": "github:angular/ngtools-webpack-builds#c2a8bf1",
2525
"@vitejs/plugin-basic-ssl": "1.1.0",
2626
"ansi-colors": "4.1.3",
2727
"autoprefixer": "10.4.19",

src/builders/dev-server/builder.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
/// <reference types="node" />
9-
import { type IndexHtmlTransform } from '@angular/build/private';
109
import type { BuilderContext } from '@angular-devkit/architect';
1110
import type { Plugin } from 'esbuild';
1211
import type http from 'node:http';
1312
import { Observable } from 'rxjs';
1413
import type { ExecutionTransformer } from '../../transforms';
14+
import { type IndexHtmlTransform } from './internal';
15+
import type { DevServerBuilderOutput } from './output';
1516
import type { Schema as DevServerBuilderOptions } from './schema';
16-
import type { DevServerBuilderOutput } from './webpack-server';
1717
/**
1818
* A Builder that executes a development server based on the provided browser target option.
1919
*

src/builders/dev-server/builder.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
3131
};
3232
Object.defineProperty(exports, "__esModule", { value: true });
3333
exports.execute = void 0;
34-
const private_1 = require("@angular/build/private");
3534
const rxjs_1 = require("rxjs");
3635
const check_port_1 = require("../../utils/check-port");
36+
const internal_1 = require("./internal");
3737
const options_1 = require("./options");
3838
/**
3939
* A Builder that executes a development server based on the provided browser target option.
@@ -95,7 +95,7 @@ function execute(options, context, transforms = {}, extensions) {
9595
exports.execute = execute;
9696
async function initialize(initialOptions, projectName, context, builderSelector = defaultBuilderSelector) {
9797
// Purge old build disk cache.
98-
await (0, private_1.purgeStaleBuildCache)(context);
98+
await (0, internal_1.purgeStaleBuildCache)(context);
9999
const normalizedOptions = await (0, options_1.normalizeOptions)(context, projectName, initialOptions);
100100
const builderName = builderSelector({
101101
builderName: await context.getBuilderNameForTarget(normalizedOptions.buildTarget),

src/builders/dev-server/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
import { execute } from './builder';
9+
import { DevServerBuilderOutput } from './output';
910
import { Schema as DevServerBuilderOptions } from './schema';
10-
import { DevServerBuilderOutput } from './webpack-server';
1111
export { DevServerBuilderOptions, DevServerBuilderOutput, execute as executeDevServerBuilder };
1212
declare const _default: import("../../../../architect/src/internal").Builder<DevServerBuilderOptions & import("../../../../core/src").JsonObject>;
1313
export default _default;

src/builders/dev-server/internal.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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.io/license
7+
*/
8+
export { BuildOutputFile, BuildOutputFileType } from '@angular/build';
9+
export { type ApplicationBuilderInternalOptions, type ExternalResultMetadata, JavaScriptTransformer, buildApplicationInternal, createRxjsEsmResolutionPlugin, getFeatureSupport, getSupportedBrowsers, isZonelessApp, transformSupportedBrowsersToTargets, type IndexHtmlTransform, purgeStaleBuildCache, } from '@angular/build/private';

src/builders/dev-server/internal.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
*/
9+
Object.defineProperty(exports, "__esModule", { value: true });
10+
exports.purgeStaleBuildCache = exports.transformSupportedBrowsersToTargets = exports.isZonelessApp = exports.getSupportedBrowsers = exports.getFeatureSupport = exports.createRxjsEsmResolutionPlugin = exports.buildApplicationInternal = exports.JavaScriptTransformer = exports.BuildOutputFileType = void 0;
11+
var build_1 = require("@angular/build");
12+
Object.defineProperty(exports, "BuildOutputFileType", { enumerable: true, get: function () { return build_1.BuildOutputFileType; } });
13+
var private_1 = require("@angular/build/private");
14+
Object.defineProperty(exports, "JavaScriptTransformer", { enumerable: true, get: function () { return private_1.JavaScriptTransformer; } });
15+
Object.defineProperty(exports, "buildApplicationInternal", { enumerable: true, get: function () { return private_1.buildApplicationInternal; } });
16+
Object.defineProperty(exports, "createRxjsEsmResolutionPlugin", { enumerable: true, get: function () { return private_1.createRxjsEsmResolutionPlugin; } });
17+
Object.defineProperty(exports, "getFeatureSupport", { enumerable: true, get: function () { return private_1.getFeatureSupport; } });
18+
Object.defineProperty(exports, "getSupportedBrowsers", { enumerable: true, get: function () { return private_1.getSupportedBrowsers; } });
19+
Object.defineProperty(exports, "isZonelessApp", { enumerable: true, get: function () { return private_1.isZonelessApp; } });
20+
Object.defineProperty(exports, "transformSupportedBrowsersToTargets", { enumerable: true, get: function () { return private_1.transformSupportedBrowsersToTargets; } });
21+
Object.defineProperty(exports, "purgeStaleBuildCache", { enumerable: true, get: function () { return private_1.purgeStaleBuildCache; } });

src/builders/dev-server/output.d.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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.io/license
7+
*/
8+
import { BuilderOutput } from '@angular-devkit/architect';
9+
/**
10+
* @experimental Direct usage of this type is considered experimental.
11+
*/
12+
export interface DevServerBuilderOutput extends BuilderOutput {
13+
baseUrl: string;
14+
port?: number;
15+
address?: string;
16+
}

src/builders/dev-server/output.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+
*/
9+
Object.defineProperty(exports, "__esModule", { value: true });

src/builders/dev-server/vite-server.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import { type ExternalResultMetadata, JavaScriptTransformer } from '@angular/build/private';
98
import type { BuilderContext } from '@angular-devkit/architect';
109
import type { Plugin } from 'esbuild';
1110
import type { Connect, DepOptimizationConfig, InlineConfig } from 'vite';
11+
import { type ExternalResultMetadata, JavaScriptTransformer } from './internal';
1212
import type { NormalizedDevServerOptions } from './options';
13-
import type { DevServerBuilderOutput } from './webpack-server';
13+
import type { DevServerBuilderOutput } from './output';
1414
interface OutputFileRecord {
1515
contents: Uint8Array;
1616
size: number;

src/builders/dev-server/vite-server.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3434
};
3535
Object.defineProperty(exports, "__esModule", { value: true });
3636
exports.setupServer = exports.serveWithVite = void 0;
37-
const build_1 = require("@angular/build");
38-
const private_1 = require("@angular/build/private");
3937
const node_assert_1 = __importDefault(require("node:assert"));
4038
const promises_1 = require("node:fs/promises");
4139
const node_path_1 = require("node:path");
4240
const angular_memory_plugin_1 = require("../../tools/vite/angular-memory-plugin");
4341
const i18n_locale_plugin_1 = require("../../tools/vite/i18n-locale-plugin");
4442
const utils_1 = require("../../utils");
4543
const load_esm_1 = require("../../utils/load-esm");
46-
const webpack_browser_config_1 = require("../../utils/webpack-browser-config");
4744
const browser_esbuild_1 = require("../browser-esbuild");
45+
const internal_1 = require("./internal");
4846
/**
4947
* Build options that are also present on the dev server but are only passed
5048
* to the build.
@@ -94,15 +92,20 @@ async function* serveWithVite(serverOptions, builderName, context, transformers,
9492
}
9593
const { vendor: thirdPartySourcemaps } = (0, utils_1.normalizeSourceMaps)(browserOptions.sourceMap ?? false);
9694
// Setup the prebundling transformer that will be shared across Vite prebundling requests
97-
const prebundleTransformer = new private_1.JavaScriptTransformer(
95+
const prebundleTransformer = new internal_1.JavaScriptTransformer(
9896
// Always enable JIT linking to support applications built with and without AOT.
9997
// In a development environment the additional scope information does not
10098
// have a negative effect unlike production where final output size is relevant.
10199
{ sourcemap: true, jit: true, thirdPartySourcemaps }, 1);
102100
// Extract output index from options
103101
// TODO: Provide this info from the build results
104-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
105-
const htmlIndexPath = (0, webpack_browser_config_1.getIndexOutputFile)(browserOptions.index);
102+
let htmlIndexPath = 'index.html';
103+
if (browserOptions.index && typeof browserOptions.index !== 'boolean') {
104+
htmlIndexPath =
105+
typeof browserOptions.index === 'string'
106+
? (0, node_path_1.basename)(browserOptions.index)
107+
: browserOptions.index.output || 'index.html';
108+
}
106109
// dynamically import Vite for ESM compatibility
107110
const { createServer, normalizePath } = await (0, load_esm_1.loadEsmModule)('vite');
108111
let server;
@@ -124,7 +127,7 @@ async function* serveWithVite(serverOptions, builderName, context, transformers,
124127
});
125128
const build = builderName === '@angular-devkit/build-angular:browser-esbuild'
126129
? browser_esbuild_1.buildEsbuildBrowser.bind(undefined, browserOptions, context, { write: false }, extensions?.buildPlugins)
127-
: private_1.buildApplicationInternal.bind(undefined, browserOptions, context, { write: false }, { codePlugins: extensions?.buildPlugins });
130+
: internal_1.buildApplicationInternal.bind(undefined, browserOptions, context, { write: false }, { codePlugins: extensions?.buildPlugins });
128131
// TODO: Switch this to an architect schedule call when infrastructure settings are supported
129132
for await (const result of build()) {
130133
(0, node_assert_1.default)(result.outputFiles, 'Builder did not provide result files.');
@@ -191,13 +194,13 @@ async function* serveWithVite(serverOptions, builderName, context, transformers,
191194
}
192195
const { root = '' } = await context.getProjectMetadata(projectName);
193196
const projectRoot = (0, node_path_1.join)(context.workspaceRoot, root);
194-
const browsers = (0, private_1.getSupportedBrowsers)(projectRoot, context.logger);
195-
const target = (0, private_1.transformSupportedBrowsersToTargets)(browsers);
197+
const browsers = (0, internal_1.getSupportedBrowsers)(projectRoot, context.logger);
198+
const target = (0, internal_1.transformSupportedBrowsersToTargets)(browsers);
196199
const polyfills = Array.isArray((browserOptions.polyfills ??= []))
197200
? browserOptions.polyfills
198201
: [browserOptions.polyfills];
199202
// Setup server and start listening
200-
const serverConfiguration = await setupServer(serverOptions, generatedFiles, assetFiles, browserOptions.preserveSymlinks, externalMetadata, !!browserOptions.ssr, prebundleTransformer, target, (0, private_1.isZonelessApp)(polyfills), browserOptions.loader, extensions?.middleware, transformers?.indexHtml, thirdPartySourcemaps);
203+
const serverConfiguration = await setupServer(serverOptions, generatedFiles, assetFiles, browserOptions.preserveSymlinks, externalMetadata, !!browserOptions.ssr, prebundleTransformer, target, (0, internal_1.isZonelessApp)(polyfills), browserOptions.loader, extensions?.middleware, transformers?.indexHtml, thirdPartySourcemaps);
201204
server = await createServer(serverConfiguration);
202205
await server.listen();
203206
if (serverConfiguration.ssr?.optimizeDeps?.disabled === false) {
@@ -300,7 +303,7 @@ function analyzeResultFiles(normalizePath, htmlIndexPath, resultFiles, generated
300303
if (filePath.endsWith('.map')) {
301304
generatedFiles.set(filePath, {
302305
contents: file.contents,
303-
servable: file.type === build_1.BuildOutputFileType.Browser || file.type === build_1.BuildOutputFileType.Media,
306+
servable: file.type === internal_1.BuildOutputFileType.Browser || file.type === internal_1.BuildOutputFileType.Media,
304307
size: file.contents.byteLength,
305308
updated: false,
306309
});
@@ -320,7 +323,7 @@ function analyzeResultFiles(normalizePath, htmlIndexPath, resultFiles, generated
320323
size: file.contents.byteLength,
321324
hash: file.hash,
322325
updated: true,
323-
servable: file.type === build_1.BuildOutputFileType.Browser || file.type === build_1.BuildOutputFileType.Media,
326+
servable: file.type === internal_1.BuildOutputFileType.Browser || file.type === internal_1.BuildOutputFileType.Media,
324327
});
325328
}
326329
// Clear stale output files
@@ -482,7 +485,7 @@ function getDepOptimizationConfig({ disabled, exclude, include, target, zoneless
482485
},
483486
];
484487
if (ssr) {
485-
plugins.unshift((0, private_1.createRxjsEsmResolutionPlugin)());
488+
plugins.unshift((0, internal_1.createRxjsEsmResolutionPlugin)());
486489
}
487490
return {
488491
// Exclude any explicitly defined dependencies (currently build defined externals)
@@ -495,7 +498,7 @@ function getDepOptimizationConfig({ disabled, exclude, include, target, zoneless
495498
esbuildOptions: {
496499
// Set esbuild supported targets.
497500
target,
498-
supported: (0, private_1.getFeatureSupport)(target, zoneless),
501+
supported: (0, internal_1.getFeatureSupport)(target, zoneless),
499502
plugins,
500503
loader,
501504
},

src/utils/normalize-cache.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
1010
exports.normalizeCacheOptions = void 0;
1111
const node_path_1 = require("node:path");
1212
/** Version placeholder is replaced during the build process with actual package version */
13-
const VERSION = '18.0.0-next.3+sha-eb8f1fa';
13+
const VERSION = '18.0.0-next.3+sha-c2a8bf1';
1414
function hasCacheMetadata(value) {
1515
return (!!value &&
1616
typeof value === 'object' &&

uniqueId

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Thu Apr 18 2024 17:40:04 GMT+0000 (Coordinated Universal Time)
1+
Mon Apr 22 2024 13:11:10 GMT+0000 (Coordinated Universal Time)

0 commit comments

Comments
 (0)