Skip to content

Commit

Permalink
build: enabled isolated modules TypeScript option
Browse files Browse the repository at this point in the history
The TypeScript `isolatedModules` option is now enabled for all TypeScript
code within the repository. As a result, all packages will now be built
with the option enabled. This does not affect projects created with the CLI
and is only related to the building of the actual Angular CLI code.
The `isolatedModules` option ensures that code can be emitted without the
TypeScript typechecker and allows tools other than TypeScript to potentially
be used. Code was updated to correct all errors after the option was enabled.
Additionally, some early code fixes were done to add function and accessor
return types to prepare for future `isolatedDeclarations` usage. More changes
would be needed to consider turning on `isolatedDeclarations`, however.
  • Loading branch information
clydin authored and alan-agius4 committed Jun 23, 2024
1 parent 8fc62d0 commit 39f946a
Show file tree
Hide file tree
Showing 33 changed files with 128 additions and 85 deletions.
31 changes: 28 additions & 3 deletions .yarn/patches/@bazel-concatjs-npm-5.8.1-1bf81df846.patch
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,38 @@ index 9e5cda684f0456b61d1b6c0f9c56ae021594713f..6c45196bda5880531d32618dfca0dee4

_DEVMODE_TARGET_DEFAULT = "es2015"
diff --git a/internal/common/tsconfig.bzl b/internal/common/tsconfig.bzl
index b01c999f5e02b388f51a508b0b608cf69db9b664..ec3e4ccb321fa230546e34c1c2ea87f7457fa108 100755
index b01c999f5e02b388f51a508b0b608cf69db9b664..847c23fe4829d0c847e9b4bd1ad698e1ccea720e 100755
--- a/internal/common/tsconfig.bzl
+++ b/internal/common/tsconfig.bzl
@@ -278,11 +278,6 @@ def create_tsconfig(
@@ -211,9 +211,6 @@ def create_tsconfig(
# will convert that to goog.module syntax.
"module": "umd" if devmode_manifest or has_node_runtime else "esnext",

- # Has no effect in closure/ES2015 mode. Always true just for simplicity.
- "downlevelIteration": True,
-
# Do not type-check the lib.*.d.ts.
# We think this shouldn't be necessary but haven't figured out why yet
# and builds are faster with the setting on.
@@ -248,13 +245,6 @@ def create_tsconfig(
# "short name" mappings for npm packages, such as "@angular/core"
"paths": mapped_module_roots,

- # Inline const enums.
- "preserveConstEnums": False,
-
- # permit `@Decorator` syntax and allow runtime reflection on their types.
- "experimentalDecorators": True,
- "emitDecoratorMetadata": True,
-
# Interpret JSX as React calls (until someone asks for something different)
"jsx": "react",

@@ -277,12 +267,6 @@ def create_tsconfig(
# always emit declaration files in the same location as outDir.
"declarationDir": "/".join([workspace_path, outdir_path]),
"stripInternal": True,
-
- # Embed source maps and sources in .js outputs
- "inlineSourceMap": True,
- "inlineSources": True,
Expand Down
2 changes: 1 addition & 1 deletion modules/testing/builder/src/file-watching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ export class WatcherNotifier implements BuilderWatcherFactory {
}
}

export { BuilderWatcherFactory };
export type { BuilderWatcherFactory };
10 changes: 7 additions & 3 deletions modules/testing/builder/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@

export {
BuilderHarness,
BuilderHarnessExecutionOptions,
BuilderHarnessExecutionResult,
type BuilderHarnessExecutionOptions,
type BuilderHarnessExecutionResult,
} from './builder-harness';
export { HarnessFileMatchers, JasmineBuilderHarness, describeBuilder } from './jasmine-helpers';
export {
type HarnessFileMatchers,
JasmineBuilderHarness,
describeBuilder,
} from './jasmine-helpers';
export * from './test-utils';
2 changes: 1 addition & 1 deletion packages/angular/build/src/builders/application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from './options';
import { Schema as ApplicationBuilderOptions } from './schema';

export { ApplicationBuilderOptions };
export type { ApplicationBuilderOptions };

export async function* buildApplicationInternal(
options: ApplicationBuilderInternalOptions,
Expand Down
10 changes: 7 additions & 3 deletions packages/angular/build/src/builders/dev-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@

import { createBuilder } from '@angular-devkit/architect';
import { execute } from './builder';
import { DevServerBuilderOutput } from './output';
import { Schema as DevServerBuilderOptions } from './schema';
import type { DevServerBuilderOutput } from './output';
import type { Schema as DevServerBuilderOptions } from './schema';

export { DevServerBuilderOptions, DevServerBuilderOutput, execute as executeDevServerBuilder };
export {
type DevServerBuilderOptions,
type DevServerBuilderOutput,
execute as executeDevServerBuilder,
};
export default createBuilder<DevServerBuilderOptions, DevServerBuilderOutput>(execute);

// Temporary export to support specs
Expand Down
6 changes: 3 additions & 3 deletions packages/angular/build/src/builders/dev-server/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.dev/license
*/

export { BuildOutputFile, BuildOutputFileType } from '@angular/build';
export { type BuildOutputFile, BuildOutputFileType } from '@angular/build';
export { createRxjsEsmResolutionPlugin } from '../../tools/esbuild/rxjs-esm-resolution-plugin';
export { JavaScriptTransformer } from '../../tools/esbuild/javascript-transformer';
export { getFeatureSupport, isZonelessApp } from '../../tools/esbuild/utils';
Expand All @@ -16,5 +16,5 @@ export { purgeStaleBuildCache } from '../../utils/purge-cache';
export { getSupportedBrowsers } from '../../utils/supported-browsers';
export { transformSupportedBrowsersToTargets } from '../../tools/esbuild/utils';
export { buildApplicationInternal } from '../../builders/application';
export { ApplicationBuilderInternalOptions } from '../../builders/application/options';
export { ExternalResultMetadata } from '../../tools/esbuild/bundler-execution-result';
export type { ApplicationBuilderInternalOptions } from '../../builders/application/options';
export type { ExternalResultMetadata } from '../../tools/esbuild/bundler-execution-result';
6 changes: 3 additions & 3 deletions packages/angular/build/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ export type { BuildOutputAsset } from './tools/esbuild/bundler-execution-result'

export {
executeDevServerBuilder,
DevServerBuilderOptions,
DevServerBuilderOutput,
type DevServerBuilderOptions,
type DevServerBuilderOutput,
} from './builders/dev-server';

export {
execute as executeExtractI18nBuilder,
ExtractI18nBuilderOptions,
type ExtractI18nBuilderOptions,
} from './builders/extract-i18n';
8 changes: 4 additions & 4 deletions packages/angular/build/src/private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@

// Builders
export { buildApplicationInternal } from './builders/application';
export { ApplicationBuilderInternalOptions } from './builders/application/options';
export type { ApplicationBuilderInternalOptions } from './builders/application/options';
export { serveWithVite } from './builders/dev-server/vite-server';

// Tools
export * from './tools/babel/plugins';
export { ExternalResultMetadata } from './tools/esbuild/bundler-execution-result';
export type { ExternalResultMetadata } from './tools/esbuild/bundler-execution-result';
export { emitFilesToDisk } from './tools/esbuild/utils';
export { transformSupportedBrowsersToTargets } from './tools/esbuild/utils';
export { SassWorkerImplementation } from './tools/sass/sass-service';
Expand All @@ -34,7 +34,7 @@ export { createCompilerPlugin } from './tools/esbuild/angular/compiler-plugin';
export * from './utils/bundle-calculator';
export { checkPort } from './utils/check-port';
export { deleteOutputDir } from './utils/delete-output-dir';
export { I18nOptions, createI18nOptions, loadTranslations } from './utils/i18n-options';
export { type I18nOptions, createI18nOptions, loadTranslations } from './utils/i18n-options';
export {
IndexHtmlGenerator,
type IndexHtmlGeneratorOptions,
Expand All @@ -51,6 +51,6 @@ export { loadProxyConfiguration } from './utils/load-proxy-config';
export { type TranslationLoader, createTranslationLoader } from './utils/load-translations';
export { purgeStaleBuildCache } from './utils/purge-cache';
export { augmentAppWithServiceWorker } from './utils/service-worker';
export { BundleStats, generateBuildStatsTable } from './utils/stats-table';
export { type BundleStats, generateBuildStatsTable } from './utils/stats-table';
export { getSupportedBrowsers } from './utils/supported-browsers';
export { assertCompatibleAngularVersion } from './utils/version';
2 changes: 1 addition & 1 deletion packages/angular/build/src/utils/bundle-calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Budget as BudgetEntry, Type as BudgetType } from '../builders/applicati
import { formatSize } from './format-bytes';

// Re-export to avoid direct schema importing throughout code
export { BudgetEntry, BudgetType };
export { type BudgetEntry, BudgetType };

interface Size {
size: number;
Expand Down
6 changes: 5 additions & 1 deletion packages/angular/ssr/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@
* found in the LICENSE file at https://angular.dev/license
*/

export { CommonEngine, CommonEngineRenderOptions, CommonEngineOptions } from './src/common-engine';
export {
CommonEngine,
type CommonEngineRenderOptions,
type CommonEngineOptions,
} from './src/common-engine';
2 changes: 1 addition & 1 deletion packages/angular_devkit/architect/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import * as jobs from './jobs';

export * from './api';
export { Architect, ScheduleOptions } from './architect';
export { Architect, type ScheduleOptions } from './architect';
export { createBuilder } from './create-builder';

export { jobs };
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import { createBuilder } from '@angular-devkit/architect';
import { execute } from './builder';
import { Schema as DevServerBuilderOptions } from './schema';

export { DevServerBuilderOptions, DevServerBuilderOutput, execute as executeDevServerBuilder };
export {
type DevServerBuilderOptions,
type DevServerBuilderOutput,
execute as executeDevServerBuilder,
};
export default createBuilder<DevServerBuilderOptions, DevServerBuilderOutput>(execute);

// Temporary export to support specs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ function getBuiltInKarmaConfig(
};
}

export { KarmaBuilderOptions };
export type { KarmaBuilderOptions };
export default createBuilder<Record<string, string> & KarmaBuilderOptions>(execute);

function getBuiltInMainFile(): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ export function execute(
);
}

export { NgPackagrBuilderOptions };
export type { NgPackagrBuilderOptions };
export default createBuilder<Record<string, string> & NgPackagrBuilderOptions>(execute);
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async function updateWebdriver() {
} as unknown as JSON);
}

export { ProtractorBuilderOptions };
export type { ProtractorBuilderOptions };

/**
* @experimental Direct usage of this function is considered experimental.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export type ServerBuilderOutput = BuilderOutput & {
}[];
};

export { ServerBuilderOptions };
export type { ServerBuilderOptions };

/**
* @experimental Direct usage of this function is considered experimental.
Expand Down
35 changes: 18 additions & 17 deletions packages/angular_devkit/build_angular/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,61 +8,62 @@

export * from './transforms';

export {
export { CrossOrigin, OutputHashing, Type } from './builders/browser/schema';
export type {
AssetPattern,
AssetPatternClass as AssetPatternObject,
Budget,
CrossOrigin,
FileReplacement,
OptimizationClass as OptimizationObject,
OptimizationUnion,
OutputHashing,
Schema as BrowserBuilderOptions,
SourceMapClass as SourceMapObject,
SourceMapUnion,
StylePreprocessorOptions,
Type,
} from './builders/browser/schema';

export {
buildWebpackBrowser as executeBrowserBuilder,
BrowserBuilderOutput,
type BrowserBuilderOutput,
} from './builders/browser';

export { buildApplication, ApplicationBuilderOptions } from '@angular/build';
export { buildApplication, type ApplicationBuilderOptions } from '@angular/build';

export {
executeDevServerBuilder,
DevServerBuilderOptions,
DevServerBuilderOutput,
type DevServerBuilderOptions,
type DevServerBuilderOutput,
} from './builders/dev-server';

export {
execute as executeExtractI18nBuilder,
ExtractI18nBuilderOptions,
type ExtractI18nBuilderOptions,
} from './builders/extract-i18n';

export {
execute as executeKarmaBuilder,
KarmaBuilderOptions,
KarmaConfigOptions,
type KarmaBuilderOptions,
type KarmaConfigOptions,
} from './builders/karma';

export {
execute as executeProtractorBuilder,
ProtractorBuilderOptions,
type ProtractorBuilderOptions,
} from './builders/protractor';

export {
execute as executeServerBuilder,
ServerBuilderOptions,
ServerBuilderOutput,
type ServerBuilderOptions,
type ServerBuilderOutput,
} from './builders/server';

export {
execute as executeSSRDevServerBuilder,
SSRDevServerBuilderOptions,
SSRDevServerBuilderOutput,
type SSRDevServerBuilderOptions,
type SSRDevServerBuilderOutput,
} from './builders/ssr-dev-server';

export { execute as executeNgPackagrBuilder, NgPackagrBuilderOptions } from './builders/ng-packagr';
export {
execute as executeNgPackagrBuilder,
type NgPackagrBuilderOptions,
} from './builders/ng-packagr';
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

// Exports the webpack plugins we use internally.
export { AnyComponentStyleBudgetChecker } from './any-component-style-budget-checker';
export { ScriptsWebpackPlugin, ScriptsWebpackPluginOptions } from './scripts-webpack-plugin';
export { ScriptsWebpackPlugin, type ScriptsWebpackPluginOptions } from './scripts-webpack-plugin';
export { SuppressExtractedTextChunksWebpackPlugin } from './suppress-entry-chunks-webpack-plugin';
export { RemoveHashPlugin, RemoveHashPluginOptions } from './remove-hash-plugin';
export { RemoveHashPlugin, type RemoveHashPluginOptions } from './remove-hash-plugin';
export { DedupeModuleResolvePlugin } from './dedupe-module-resolve-plugin';
export { CommonJsUsageWarnPlugin } from './common-js-usage-warn-plugin';
export { JsonStatsPlugin } from './json-stats-plugin';
export { JavaScriptOptimizerPlugin } from './javascript-optimizer-plugin';
export {
default as PostcssCliResources,
PostcssCliResourcesOptions,
type PostcssCliResourcesOptions,
} from './postcss-cli-resources';
2 changes: 1 addition & 1 deletion packages/angular_devkit/build_webpack/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@

export * from './builders/webpack';
export * from './builders/webpack-dev-server';
export { EmittedFiles } from './utils';
export type { EmittedFiles } from './utils';
2 changes: 1 addition & 1 deletion packages/angular_devkit/core/src/virtual-fs/host/alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import { ResolverHost } from './resolver';
export class AliasHost<StatsT extends object = {}> extends ResolverHost<StatsT> {
protected _aliases = new Map<Path, Path>();

protected _resolve(path: Path) {
protected _resolve(path: Path): Path {
let maybeAlias = this._aliases.get(path);
const sp = split(path);
const remaining: PathFragment[] = [];
Expand Down
4 changes: 2 additions & 2 deletions packages/angular_devkit/core/src/virtual-fs/host/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ export class SimpleMemoryHost implements Host<{}> {
this._cache.set(normalize('/'), this._newDirStats());
}

protected _toAbsolute(path: Path) {
protected _toAbsolute(path: Path): Path {
return isAbsolute(path) ? path : normalize('/' + path);
}

protected _updateWatchers(path: Path, type: HostWatchEventType) {
protected _updateWatchers(path: Path, type: HostWatchEventType): void {
const time = new Date();
let currentPath = path;
let parent: Path | null = null;
Expand Down
4 changes: 2 additions & 2 deletions packages/angular_devkit/core/src/virtual-fs/host/pattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ export type ReplacementFunction = (path: Path) => Path;
export class PatternMatchingHost<StatsT extends object = {}> extends ResolverHost<StatsT> {
protected _patterns = new Map<RegExp, ReplacementFunction>();

addPattern(pattern: string | string[], replacementFn: ReplacementFunction) {
addPattern(pattern: string | string[], replacementFn: ReplacementFunction): void {
const patterns = Array.isArray(pattern) ? pattern : [pattern];
for (const glob of patterns) {
const { output } = parseGlob(glob);
this._patterns.set(new RegExp(`^${output}$`), replacementFn);
}
}

protected _resolve(path: Path) {
protected _resolve(path: Path): Path {
let newPath = path;
this._patterns.forEach((fn, re) => {
if (re.test(path)) {
Expand Down
10 changes: 5 additions & 5 deletions packages/angular_devkit/core/src/virtual-fs/host/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,19 +400,19 @@ export class CordHost extends SimpleMemoryHost {
return null;
}

willCreate(path: Path) {
willCreate(path: Path): boolean {
return this._filesToCreate.has(path);
}
willOverwrite(path: Path) {
willOverwrite(path: Path): boolean {
return this._filesToOverwrite.has(path);
}
willDelete(path: Path) {
willDelete(path: Path): boolean {
return this._filesToDelete.has(path);
}
willRename(path: Path) {
willRename(path: Path): boolean {
return this._filesToRename.has(path);
}
willRenameTo(path: Path, to: Path) {
willRenameTo(path: Path, to: Path): boolean {
return this._filesToRename.get(path) === to;
}
}
Loading

0 comments on commit 39f946a

Please sign in to comment.