From c32bc1ac209348f1c111cd30dfd76b6fc8c8ae09 Mon Sep 17 00:00:00 2001 From: Olivier Combe Date: Thu, 12 Oct 2023 11:53:20 +0200 Subject: [PATCH] fix jest issues with zone.js 0.14.0 --- .../ng-compat/build-angular/browser-schema.ts | 1 + .../index-html-webpack-plugin.ts | 1 + .../ng-compat/build-angular/server-schema.ts | 1 + .../ng-compat/build-angular/utils/index.ts | 1 + .../build-angular/utils/normalize-cache.ts | 1 + .../build-angular/utils/package-chunk-sort.ts | 1 + .../utils/webpack-browser-config.ts | 1 + .../build-angular/webpack/configs.ts | 1 + .../ng-compat/build-angular/webpack/stats.ts | 1 + angular/devkit/vite/dev-server/config.ts | 22 +-- angular/devkit/vite/dev-server/types.ts | 91 ++++++++++++ .../vite/dev-server/utils/mdx-config.ts | 2 + angular/devkit/vite/index.ts | 1 + angular/devkit/vite/ng-vite-dev-server.ts | 102 ++------------ .../plugins/index-file/augment-index-html.ts | 129 ++++++++++-------- .../index-file/index-html-generator.ts | 38 +++--- .../plugins/index-file/package-chunk-sort.ts | 8 +- .../devkit/vite/plugins/index-html.plugin.ts | 8 +- .../webpack/webpack-plugins/stats-logger.ts | 1 + .../envs/angular-v12-env/jest/setup-jest.js | 9 ++ .../envs/angular-v12-env/jest/setup-jest.ts | 1 - .../envs/angular-v13-env/jest/jest.config.ts | 2 +- .../envs/angular-v13-env/jest/setup-jest.js | 9 ++ angular/envs/angular-v13-env/tsconfig.json | 5 + .../envs/angular-v14-env/jest/jest.config.ts | 2 +- .../envs/angular-v14-env/jest/setup-jest.js | 29 ++++ .../envs/angular-v15-env/jest/jest.config.ts | 2 +- .../envs/angular-v15-env/jest/setup-jest.js | 42 ++++++ .../angular-v16-env.bit-env.ts | 2 +- .../angular-v17-env.bit-env.ts | 2 +- .../envs/base-env/angular-base-env.bit-env.ts | 6 +- angular/envs/base-env/preview/mounter.ts | 1 + 32 files changed, 329 insertions(+), 194 deletions(-) create mode 100644 angular/devkit/vite/dev-server/types.ts create mode 100644 angular/envs/angular-v12-env/jest/setup-jest.js delete mode 100644 angular/envs/angular-v12-env/jest/setup-jest.ts create mode 100644 angular/envs/angular-v13-env/jest/setup-jest.js create mode 100644 angular/envs/angular-v13-env/tsconfig.json create mode 100644 angular/envs/angular-v14-env/jest/setup-jest.js create mode 100644 angular/envs/angular-v15-env/jest/setup-jest.js diff --git a/angular/devkit/ng-compat/build-angular/browser-schema.ts b/angular/devkit/ng-compat/build-angular/browser-schema.ts index cc3fb24a..f1833cb8 100644 --- a/angular/devkit/ng-compat/build-angular/browser-schema.ts +++ b/angular/devkit/ng-compat/build-angular/browser-schema.ts @@ -1,3 +1,4 @@ +/* eslint-disable */ import { VERSION } from '@angular/cli'; export let BrowserBuilderSchema: any; diff --git a/angular/devkit/ng-compat/build-angular/index-html-webpack-plugin.ts b/angular/devkit/ng-compat/build-angular/index-html-webpack-plugin.ts index f5fe0fbf..554b796e 100644 --- a/angular/devkit/ng-compat/build-angular/index-html-webpack-plugin.ts +++ b/angular/devkit/ng-compat/build-angular/index-html-webpack-plugin.ts @@ -1,3 +1,4 @@ +/* eslint-disable */ import { VERSION } from '@angular/cli'; export let IndexHtmlWebpackPlugin: any; diff --git a/angular/devkit/ng-compat/build-angular/server-schema.ts b/angular/devkit/ng-compat/build-angular/server-schema.ts index d3778023..848c44ac 100644 --- a/angular/devkit/ng-compat/build-angular/server-schema.ts +++ b/angular/devkit/ng-compat/build-angular/server-schema.ts @@ -1,3 +1,4 @@ +/* eslint-disable */ import { VERSION } from '@angular/cli'; export let OutputHashing: any; diff --git a/angular/devkit/ng-compat/build-angular/utils/index.ts b/angular/devkit/ng-compat/build-angular/utils/index.ts index 31891a37..78823414 100644 --- a/angular/devkit/ng-compat/build-angular/utils/index.ts +++ b/angular/devkit/ng-compat/build-angular/utils/index.ts @@ -1,3 +1,4 @@ +/* eslint-disable */ import { json, logging } from '@angular-devkit/core'; import { VERSION } from '@angular/cli'; import { BrowserBuilderSchema } from '../browser-schema'; diff --git a/angular/devkit/ng-compat/build-angular/utils/normalize-cache.ts b/angular/devkit/ng-compat/build-angular/utils/normalize-cache.ts index 00d4cc53..31131203 100644 --- a/angular/devkit/ng-compat/build-angular/utils/normalize-cache.ts +++ b/angular/devkit/ng-compat/build-angular/utils/normalize-cache.ts @@ -1,3 +1,4 @@ +/* eslint-disable */ import { VERSION } from '@angular/cli'; import { json } from '@angular-devkit/core'; diff --git a/angular/devkit/ng-compat/build-angular/utils/package-chunk-sort.ts b/angular/devkit/ng-compat/build-angular/utils/package-chunk-sort.ts index 9c2277ff..55fa9c8b 100644 --- a/angular/devkit/ng-compat/build-angular/utils/package-chunk-sort.ts +++ b/angular/devkit/ng-compat/build-angular/utils/package-chunk-sort.ts @@ -1,3 +1,4 @@ +/* eslint-disable */ import { VERSION } from '@angular/cli'; export let generateEntryPoints: (options: { diff --git a/angular/devkit/ng-compat/build-angular/utils/webpack-browser-config.ts b/angular/devkit/ng-compat/build-angular/utils/webpack-browser-config.ts index d905b5cd..c4221c56 100644 --- a/angular/devkit/ng-compat/build-angular/utils/webpack-browser-config.ts +++ b/angular/devkit/ng-compat/build-angular/utils/webpack-browser-config.ts @@ -1,3 +1,4 @@ +/* eslint-disable */ import { logging } from '@angular-devkit/core'; import { VERSION } from '@angular/cli'; import { Configuration } from '@teambit/webpack'; diff --git a/angular/devkit/ng-compat/build-angular/webpack/configs.ts b/angular/devkit/ng-compat/build-angular/webpack/configs.ts index 383b0fe4..5c6e665a 100644 --- a/angular/devkit/ng-compat/build-angular/webpack/configs.ts +++ b/angular/devkit/ng-compat/build-angular/webpack/configs.ts @@ -1,3 +1,4 @@ +/* eslint-disable */ import type { Configuration } from 'webpack'; import { VERSION } from '@angular/cli'; diff --git a/angular/devkit/ng-compat/build-angular/webpack/stats.ts b/angular/devkit/ng-compat/build-angular/webpack/stats.ts index eff2ae74..7962341b 100644 --- a/angular/devkit/ng-compat/build-angular/webpack/stats.ts +++ b/angular/devkit/ng-compat/build-angular/webpack/stats.ts @@ -1,3 +1,4 @@ +/* eslint-disable */ import { WebpackLoggingCallback } from '@angular-devkit/build-webpack'; import { logging } from '@angular-devkit/core'; import { VERSION } from '@angular/cli'; diff --git a/angular/devkit/vite/dev-server/config.ts b/angular/devkit/vite/dev-server/config.ts index 4dc2f7d3..7ee424f2 100644 --- a/angular/devkit/vite/dev-server/config.ts +++ b/angular/devkit/vite/dev-server/config.ts @@ -5,7 +5,7 @@ import 'node-stdlib-browser'; import { relative } from 'path'; import { defineConfig, InlineConfig } from 'vite'; import { nodePolyfills } from 'vite-plugin-node-polyfills'; -import { ViteDevServerAspectsContext, ViteDevServerOptions } from '../ng-vite-dev-server'; +import { ViteDevServerAspectsContext, ViteDevServerOptions } from './types'; import { getHostAlias } from './utils'; // import react from "@vitejs/plugin-react"; // import mdx from "vite-plugin-mdx"; @@ -21,8 +21,14 @@ import { getHostAlias } from './utils'; * 4. websocket protocol */ export async function configFactory(options: ViteDevServerOptions, aspectContext: ViteDevServerAspectsContext, port: number): Promise { - const { devServerContext: { publicPath, entry, id, rootPath, envRuntime, }, define, alias, plugins, transformers, } = options; - const { workspace, pubsub } = aspectContext; + const { + devServerContext: { publicPath, entry, rootPath, envRuntime }, + define, + alias, + plugins, + transformers + } = options; + const { workspace } = aspectContext; const entries = entry; const root = options.root ?? workspace.path; @@ -71,7 +77,7 @@ export async function configFactory(options: ViteDevServerOptions, aspectContext }, ...hostAlias, ...alias || [] - ], + ] }, // apply different cache dir for each env cacheDir, @@ -82,7 +88,7 @@ export async function configFactory(options: ViteDevServerOptions, aspectContext // 2. entry files // 3. local packages ignored: [ - ...packageList.map(p => `!**/node_modules/${p}/**`), + ...packageList.map(p => `!**/node_modules/${p}/**`) ] }, fs: { @@ -90,7 +96,7 @@ export async function configFactory(options: ViteDevServerOptions, aspectContext } }, optimizeDeps: { - entries, + entries // exclude: packageList, }, // TODO: make it replaceable and reusable @@ -99,8 +105,8 @@ export async function configFactory(options: ViteDevServerOptions, aspectContext // react(), // mdx(mdxOptions), // htmlPlugin(entries), - ...plugins || [], - ], + ...plugins || [] + ] }); // apply transformers diff --git a/angular/devkit/vite/dev-server/types.ts b/angular/devkit/vite/dev-server/types.ts new file mode 100644 index 00000000..44db8edc --- /dev/null +++ b/angular/devkit/vite/dev-server/types.ts @@ -0,0 +1,91 @@ +import { + AngularEnvOptions, + BrowserOptions, + DevServerOptions +} from '@bitdev/angular.dev-services.common'; +import type { DevServerContext } from '@teambit/bundler'; +import { Logger } from '@teambit/logger'; +import { PubsubMain } from '@teambit/pubsub'; +import type { Workspace } from '@teambit/workspace'; +// @ts-ignore +import type { Alias, InlineConfig, PluginOption } from 'vite'; + + +export type ViteConfigTransformer = (config: InlineConfig) => void; + +export type ViteDevServerAspectsContext = { + logger: Logger; + workspace: Workspace; + pubsub: PubsubMain; +}; + +export type NgViteDevServerOptions = { + angularOptions: Partial; + + /** + * context of the dev server execution. + */ + devServerContext: DevServerContext; + + /** + * name of the dev server. + */ + name?: string; + + ngEnvOptions: AngularEnvOptions; + + sourceRoot?: string; + + // TODO: fix type once we can support preview with vite + transformers?: (ViteConfigTransformer | any)[]; + + // TODO: remove this once we can support preview with vite + [key: string]: any; +}; + +export type ViteDevServerOptions = { + /** + * name of the dev server. + */ + name?: string; + + /** + * context of the dev server execution. + */ + devServerContext: DevServerContext; + + /** + * optimize entries before passing them to Vite. + */ + optimizeEntries?: (entries: string[], context: ViteDevServerAspectsContext) => string[]; + + /** + * root path of the dev server. + */ + root?: string; + + /** + * base URL to use for all relative URLs in a document + */ + base?: string; + + /** + * variables to be injected to the dev server. + */ + define?: Record; + + /** + * alias to be injected to the dev server. + */ + alias?: Alias[]; + + /** + * list of plugins to be injected to the dev server. + */ + plugins?: PluginOption[]; + + /** + * list of transformers to modify Vite config in an advanced way. + */ + transformers?: ViteConfigTransformer[]; +}; diff --git a/angular/devkit/vite/dev-server/utils/mdx-config.ts b/angular/devkit/vite/dev-server/utils/mdx-config.ts index 010f7696..331d4765 100644 --- a/angular/devkit/vite/dev-server/utils/mdx-config.ts +++ b/angular/devkit/vite/dev-server/utils/mdx-config.ts @@ -67,6 +67,7 @@ function extractMetadata(): Pluggable { return function transformer(tree, file) { visit(tree, 'yaml', (node: any) => { try { + // eslint-disable-next-line no-param-reassign file.data.frontmatter = yaml.parse(node.value, { prettyErrors: true }); } catch (err: any) { throw new Error( @@ -93,6 +94,7 @@ function extractImports(): Pluggable { isDefault: importSpecifier.isDefault, })); }); + // eslint-disable-next-line no-param-reassign (file.data.imports ||= []).push(...imports); }); diff --git a/angular/devkit/vite/index.ts b/angular/devkit/vite/index.ts index 55424c8a..025081cb 100644 --- a/angular/devkit/vite/index.ts +++ b/angular/devkit/vite/index.ts @@ -1 +1,2 @@ export * from './ng-vite-dev-server'; +export * from './dev-server/types'; diff --git a/angular/devkit/vite/ng-vite-dev-server.ts b/angular/devkit/vite/ng-vite-dev-server.ts index dbe6e55b..75762bfd 100644 --- a/angular/devkit/vite/ng-vite-dev-server.ts +++ b/angular/devkit/vite/ng-vite-dev-server.ts @@ -1,103 +1,21 @@ +// eslint-disable-next-line import/no-named-default import { default as ngVitePlugin } from '@analogjs/vite-plugin-angular'; -import { - AngularEnvOptions, - BrowserOptions, - DevServerOptions, - isAppDevContext -} from '@bitdev/angular.dev-services.common'; -import type { DevServer, DevServerContext } from '@teambit/bundler'; +import { isAppDevContext } from '@bitdev/angular.dev-services.common'; +import type { DevServer } from '@teambit/bundler'; import type { AsyncEnvHandler, EnvContext } from '@teambit/envs'; -import type { Logger } from '@teambit/logger'; -import type { PubsubMain } from '@teambit/pubsub'; import type { Workspace } from '@teambit/workspace'; import type { Server } from 'http'; import { posix } from 'path'; // @ts-ignore -import type { Alias, InlineConfig, Plugin, PluginOption } from 'vite'; +import type { InlineConfig, Plugin } from 'vite'; import { configFactory } from './dev-server/config'; +import { + NgViteDevServerOptions, + ViteDevServerAspectsContext, + ViteDevServerOptions +} from './dev-server/types'; import { htmlPlugin } from './plugins/index-html.plugin'; - -export type NgViteDevServerOptions = { - angularOptions: Partial; - - /** - * context of the dev server execution. - */ - devServerContext: DevServerContext; - - /** - * name of the dev server. - */ - name?: string; - - ngEnvOptions: AngularEnvOptions; - - sourceRoot?: string; - - // TODO: fix type once we can support preview with vite - transformers?: (ViteConfigTransformer | any)[]; - - // TODO: remove this once we can support preview with vite - [key: string]: any; -}; - - -export type ViteConfigTransformer = (config: InlineConfig) => void; - -export type ViteDevServerAspectsContext = { - logger: Logger; - workspace: Workspace; - pubsub: PubsubMain; -}; - -export type ViteDevServerOptions = { - /** - * name of the dev server. - */ - name?: string; - - /** - * context of the dev server execution. - */ - devServerContext: DevServerContext; - - /** - * optimize entries before passing them to Vite. - */ - optimizeEntries?: (entries: string[], context: ViteDevServerAspectsContext) => string[]; - - /** - * root path of the dev server. - */ - root?: string; - - /** - * base URL to use for all relative URLs in a document - */ - base?: string; - - /** - * variables to be injected to the dev server. - */ - define?: Record; - - /** - * alias to be injected to the dev server. - */ - alias?: Alias[]; - - /** - * list of plugins to be injected to the dev server. - */ - plugins?: PluginOption[]; - - /** - * list of transformers to modify Vite config in an advanced way. - */ - transformers?: ViteConfigTransformer[]; -}; - export class NgViteDevServer { id = 'ng-vite-dev-server'; @@ -120,7 +38,7 @@ export class NgViteDevServer { static from(options: NgViteDevServerOptions): AsyncEnvHandler { return async(context: EnvContext): Promise => { - const rootPath = options.devServerContext.rootPath; + const {rootPath} = options.devServerContext; const name = options.name || 'vite-dev-server'; const logger = context.createLogger(name); const workspace: Workspace = context.getAspect('teambit.workspace/workspace'); diff --git a/angular/devkit/vite/plugins/index-file/augment-index-html.ts b/angular/devkit/vite/plugins/index-file/augment-index-html.ts index c8f2dd48..20f907c5 100644 --- a/angular/devkit/vite/plugins/index-file/augment-index-html.ts +++ b/angular/devkit/vite/plugins/index-file/augment-index-html.ts @@ -6,9 +6,9 @@ * found in the LICENSE file at https://angular.io/license */ +import { loadEsmModule } from '@bitdev/angular.dev-services.common'; import { extname } from 'path'; import { htmlRewritingStream } from './html-rewriting-stream'; -import { loadEsmModule } from '@bitdev/angular.dev-services.common'; import { EntryPointsType } from './package-chunk-sort'; export type CrossOriginValue = 'none' | 'anonymous' | 'use-credentials'; @@ -27,6 +27,64 @@ export interface AugmentIndexHtmlOptions { hints?: { url: string; mode: string; as?: string }[]; } +function isString(value: unknown): value is string { + return typeof value === 'string'; +} + +async function getLanguageDirectionFromLocales(locale: string): Promise { + try { + const localeData = ( + await loadEsmModule( + `@angular/common/locales/${locale}`, + ) + ).default; + + const dir = localeData[localeData.length - 2]; + + return isString(dir) ? dir : undefined; + } catch { + // In some cases certain locales might map to files which are named only with language id. + // Example: `en-US` -> `en`. + const [languageId] = locale.split('-', 1); + if (languageId !== locale) { + return getLanguageDirectionFromLocales(languageId); + } + } + + return undefined; +} + +async function getLanguageDirection( + locale: string, + warnings: string[], +): Promise { + const dir = await getLanguageDirectionFromLocales(locale); + + if (!dir) { + warnings.push( + `Locale data for '${locale}' cannot be found. 'dir' attribute will not be set for this locale.`, + ); + } + + return dir; +} + +function updateAttribute( + tag: { attrs: { name: string; value: string }[] }, + name: string, + value: string, +): void { + const index = tag.attrs.findIndex((a) => a.name === name); + const newValue = { name, value }; + + if (index === -1) { + tag.attrs.push(newValue); + } else { + // eslint-disable-next-line no-param-reassign + tag.attrs[index] = newValue; + } +} + /* * Helper function used by the IndexHtmlWebpackPlugin. * Can also be directly used by builder, e.g. in order to generate an index.html @@ -41,15 +99,17 @@ export async function augmentIndexHtml( const warnings: string[] = []; const errors: string[] = []; - let { crossOrigin = 'none' } = params; + const { crossOrigin = 'none' } = params; const stylesheets = new Set(); const scripts = new Map(); // Sort files in the order we want to insert them by entrypoint + // eslint-disable-next-line no-restricted-syntax for (const [file, isModule] of entrypoints) { const extension = extname(file); if (scripts.has(file) || stylesheets.has(file)) { + // eslint-disable-next-line no-continue continue; } @@ -58,6 +118,7 @@ export async function augmentIndexHtml( case '.jsx': case '.ts': case '.tsx': + default: // Also, non entrypoints need to be loaded as no module as they can contain problematic code. scripts.set(file, isModule); break; @@ -80,6 +141,7 @@ export async function augmentIndexHtml( } let scriptTags: string[] = []; + // eslint-disable-next-line no-restricted-syntax for (const [src, isModule] of scripts) { const attrs = [`src="${deployUrl}${src}"`]; @@ -98,6 +160,7 @@ export async function augmentIndexHtml( } let linkTags: string[] = []; + // eslint-disable-next-line no-restricted-syntax for (const src of stylesheets) { const attrs = [`rel="stylesheet"`, `href="${deployUrl}${src}"`]; @@ -109,6 +172,7 @@ export async function augmentIndexHtml( } if (params.hints?.length) { + // eslint-disable-next-line no-restricted-syntax for (const hint of params.hints) { const attrs = [`rel="${hint.mode}"`, `href="${deployUrl}${hint.url}"`]; @@ -143,6 +207,7 @@ export async function augmentIndexHtml( rewriter .on('startTag', (tag) => { + // eslint-disable-next-line default-case switch (tag.tagName) { case 'html': // Adjust document locale if specified @@ -174,8 +239,10 @@ export async function augmentIndexHtml( rewriter.emitStartTag(tag); }) .on('endTag', (tag) => { + // eslint-disable-next-line default-case switch (tag.tagName) { case 'head': + // eslint-disable-next-line no-restricted-syntax for (const linkTag of linkTags) { rewriter.emitRaw(linkTag); } @@ -184,6 +251,7 @@ export async function augmentIndexHtml( break; case 'body': // Add script tags + // eslint-disable-next-line no-restricted-syntax for (const scriptTag of scriptTags) { rewriter.emitRaw(scriptTag); } @@ -207,60 +275,3 @@ export async function augmentIndexHtml( errors, }; } - -function updateAttribute( - tag: { attrs: { name: string; value: string }[] }, - name: string, - value: string, -): void { - const index = tag.attrs.findIndex((a) => a.name === name); - const newValue = { name, value }; - - if (index === -1) { - tag.attrs.push(newValue); - } else { - tag.attrs[index] = newValue; - } -} - -function isString(value: unknown): value is string { - return typeof value === 'string'; -} - -async function getLanguageDirection( - locale: string, - warnings: string[], -): Promise { - const dir = await getLanguageDirectionFromLocales(locale); - - if (!dir) { - warnings.push( - `Locale data for '${locale}' cannot be found. 'dir' attribute will not be set for this locale.`, - ); - } - - return dir; -} - -async function getLanguageDirectionFromLocales(locale: string): Promise { - try { - const localeData = ( - await loadEsmModule( - `@angular/common/locales/${locale}`, - ) - ).default; - - const dir = localeData[localeData.length - 2]; - - return isString(dir) ? dir : undefined; - } catch { - // In some cases certain locales might map to files which are named only with language id. - // Example: `en-US` -> `en`. - const [languageId] = locale.split('-', 1); - if (languageId !== locale) { - return getLanguageDirectionFromLocales(languageId); - } - } - - return undefined; -} diff --git a/angular/devkit/vite/plugins/index-file/index-html-generator.ts b/angular/devkit/vite/plugins/index-file/index-html-generator.ts index 0b4f7f78..3330f4d5 100644 --- a/angular/devkit/vite/plugins/index-file/index-html-generator.ts +++ b/angular/devkit/vite/plugins/index-file/index-html-generator.ts @@ -39,6 +39,24 @@ export interface IndexHtmlTransformResult { errors: string[]; } +function augmentIndexHtmlPlugin(generator: IndexHtmlGenerator): IndexHtmlGeneratorPlugin { + const { deployUrl, crossOrigin, entrypoints } = generator.options; + + return async (html, options) => { + const { lang, baseHref, hints } = options; + + return augmentIndexHtml({ + html, + baseHref, + deployUrl, + crossOrigin, + lang, + entrypoints, + hints, + }); + }; +} + export class IndexHtmlGenerator { private readonly plugins: IndexHtmlGeneratorPlugin[]; @@ -53,7 +71,9 @@ export class IndexHtmlGenerator { const warnings: string[] = []; const errors: string[] = []; + // eslint-disable-next-line no-restricted-syntax for (const plugin of this.plugins) { + // eslint-disable-next-line no-await-in-loop const result = await plugin(content, options); if (typeof result === 'string') { content = result; @@ -81,21 +101,3 @@ export class IndexHtmlGenerator { return fs.promises.readFile(path, 'utf-8'); } } - -function augmentIndexHtmlPlugin(generator: IndexHtmlGenerator): IndexHtmlGeneratorPlugin { - const { deployUrl, crossOrigin, entrypoints } = generator.options; - - return async (html, options) => { - const { lang, baseHref, hints } = options; - - return augmentIndexHtml({ - html, - baseHref, - deployUrl, - crossOrigin, - lang, - entrypoints, - hints, - }); - }; -} diff --git a/angular/devkit/vite/plugins/index-file/package-chunk-sort.ts b/angular/devkit/vite/plugins/index-file/package-chunk-sort.ts index 4ac6a1ae..5d979939 100644 --- a/angular/devkit/vite/plugins/index-file/package-chunk-sort.ts +++ b/angular/devkit/vite/plugins/index-file/package-chunk-sort.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import path from 'path'; +import {parse} from 'path'; // import { ScriptElement, StyleElement } from '@angular-devkit/build-angular/src/builders/browser/schema'; import type { BrowserBuilderOptions } from '@angular-devkit/build-angular'; @@ -37,7 +37,7 @@ export function normalizeExtraEntryPoints( bundleName = entry.bundleName; } else if (!inject) { // Lazy entry points use the file name as bundle name. - bundleName = path.parse(entry.input).name; + bundleName = parse(entry.input).name; } else { bundleName = defaultBundleName; } @@ -55,10 +55,10 @@ export function generateEntryPoints(options: { }): EntryPointsType[] { // Add all styles/scripts, except lazy-loaded ones. const extraEntryPoints = ( - extraEntryPoints: (ScriptElement | StyleElement)[], + eePoints: (ScriptElement | StyleElement)[], defaultBundleName: string, ) => { - const entryPoints = normalizeExtraEntryPoints(extraEntryPoints, defaultBundleName) + const entryPoints = normalizeExtraEntryPoints(eePoints, defaultBundleName) .filter((entry) => entry.inject) .map((entry) => entry.input); diff --git a/angular/devkit/vite/plugins/index-html.plugin.ts b/angular/devkit/vite/plugins/index-html.plugin.ts index 7479e4a1..71d09e49 100644 --- a/angular/devkit/vite/plugins/index-html.plugin.ts +++ b/angular/devkit/vite/plugins/index-html.plugin.ts @@ -1,6 +1,6 @@ import type { BrowserBuilderOptions } from '@angular-devkit/build-angular'; import type { ServerResponse } from 'http'; -import { default as memoize } from 'memoizee'; +import memoize from 'memoizee'; import { join } from 'path'; import type { Connect, Plugin, ViteDevServer } from 'vite'; import { IndexHtmlGenerator } from './index-file/index-html-generator'; @@ -9,14 +9,13 @@ import { generateEntryPoints } from './index-file/package-chunk-sort'; export function getIndexInputFile(index: BrowserBuilderOptions['index']): string { if (typeof index === 'string') { return index; - } else { - return index.input; } + return index.input; } const cleanUrl = (url: string) => url.replace(/#.*$/s, '').replace(/\?.*$/s, ''); -const genHtml = async function(options: Partial, rootPath: string, sourceRoot = 'src') { +async function genHtml(options: Partial, rootPath: string, sourceRoot = 'src') { const entrypoints = generateEntryPoints({ main: options.main ?? `./${join(sourceRoot, `main.ts`)}`, polyfills: options.polyfills ?? `./${join(sourceRoot, `polyfills.ts`)}`, @@ -38,6 +37,7 @@ const genHtml = async function(options: Partial, rootPath }); if (warnings.length) { + // eslint-disable-next-line no-console warnings.forEach((warning) => console.warn(warning)); } diff --git a/angular/devkit/webpack/webpack-plugins/stats-logger.ts b/angular/devkit/webpack/webpack-plugins/stats-logger.ts index 94787267..01e78516 100644 --- a/angular/devkit/webpack/webpack-plugins/stats-logger.ts +++ b/angular/devkit/webpack/webpack-plugins/stats-logger.ts @@ -17,6 +17,7 @@ export class StatsLoggerPlugin { }); } catch (e) { // if it fails, just continue (we don't need logging to break the build) + // eslint-disable-next-line no-console console.log('Failed to load @bitdev/angular.dev-services.ng-compat', e); } } diff --git a/angular/envs/angular-v12-env/jest/setup-jest.js b/angular/envs/angular-v12-env/jest/setup-jest.js new file mode 100644 index 00000000..7eacc2fd --- /dev/null +++ b/angular/envs/angular-v12-env/jest/setup-jest.js @@ -0,0 +1,9 @@ +/* eslint-disable */ +require('jest-preset-angular/build/utils/reflect-metadata'); +require('zone.js'); +require('zone.js/bundles/zone-testing.umd'); +const getTestBed = require('@angular/core/testing').getTestBed; +const BrowserDynamicTestingModule = require('@angular/platform-browser-dynamic/testing').BrowserDynamicTestingModule; +const platformBrowserDynamicTesting = require('@angular/platform-browser-dynamic/testing') + .platformBrowserDynamicTesting; +getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting()); diff --git a/angular/envs/angular-v12-env/jest/setup-jest.ts b/angular/envs/angular-v12-env/jest/setup-jest.ts deleted file mode 100644 index 1100b3e8..00000000 --- a/angular/envs/angular-v12-env/jest/setup-jest.ts +++ /dev/null @@ -1 +0,0 @@ -import 'jest-preset-angular/setup-jest'; diff --git a/angular/envs/angular-v13-env/jest/jest.config.ts b/angular/envs/angular-v13-env/jest/jest.config.ts index 5d04b4b6..d7dbe042 100644 --- a/angular/envs/angular-v13-env/jest/jest.config.ts +++ b/angular/envs/angular-v13-env/jest/jest.config.ts @@ -5,7 +5,7 @@ const packagesToExclude: string[] = ['@angular', '@ngrx']; export default { preset: 'jest-preset-angular', reporters: ['default'], - setupFilesAfterEnv: [require.resolve('jest-preset-angular/setup-jest')], + setupFilesAfterEnv: [require.resolve('./setup-jest')], testPathIgnorePatterns: ['/.*/e2e/'], globals: { 'ts-jest': { diff --git a/angular/envs/angular-v13-env/jest/setup-jest.js b/angular/envs/angular-v13-env/jest/setup-jest.js new file mode 100644 index 00000000..7eacc2fd --- /dev/null +++ b/angular/envs/angular-v13-env/jest/setup-jest.js @@ -0,0 +1,9 @@ +/* eslint-disable */ +require('jest-preset-angular/build/utils/reflect-metadata'); +require('zone.js'); +require('zone.js/bundles/zone-testing.umd'); +const getTestBed = require('@angular/core/testing').getTestBed; +const BrowserDynamicTestingModule = require('@angular/platform-browser-dynamic/testing').BrowserDynamicTestingModule; +const platformBrowserDynamicTesting = require('@angular/platform-browser-dynamic/testing') + .platformBrowserDynamicTesting; +getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting()); diff --git a/angular/envs/angular-v13-env/tsconfig.json b/angular/envs/angular-v13-env/tsconfig.json new file mode 100644 index 00000000..ee229f3a --- /dev/null +++ b/angular/envs/angular-v13-env/tsconfig.json @@ -0,0 +1,5 @@ +// bit-generated-typescript-config + +{ + "extends": "./../../../node_modules/.cache/tsconfig.bit.f3b87b1c18fb9e87952d48c4888ed71964a4999d.json" +} \ No newline at end of file diff --git a/angular/envs/angular-v14-env/jest/jest.config.ts b/angular/envs/angular-v14-env/jest/jest.config.ts index 068e6bc9..a9238741 100644 --- a/angular/envs/angular-v14-env/jest/jest.config.ts +++ b/angular/envs/angular-v14-env/jest/jest.config.ts @@ -6,7 +6,7 @@ export default { preset: 'jest-preset-angular', globalSetup: 'jest-preset-angular/global-setup', reporters: ['default'], - setupFilesAfterEnv: [require.resolve('jest-preset-angular/setup-jest')], + setupFilesAfterEnv: [require.resolve('./setup-jest')], testPathIgnorePatterns: ['/.*/e2e/'], globals: { ngJest: { diff --git a/angular/envs/angular-v14-env/jest/setup-jest.js b/angular/envs/angular-v14-env/jest/setup-jest.js new file mode 100644 index 00000000..a39549fe --- /dev/null +++ b/angular/envs/angular-v14-env/jest/setup-jest.js @@ -0,0 +1,29 @@ +/* eslint-disable */ +require('zone.js'); +require('zone.js/testing'); +const { getTestBed } = require('@angular/core/testing'); +const { + BrowserDynamicTestingModule, + platformBrowserDynamicTesting, +} = require('@angular/platform-browser-dynamic/testing'); + +let teardown = globalThis.ngJest?.teardown; +const configuredDestroyAfterEach = globalThis.ngJest?.destroyAfterEach; +if (configuredDestroyAfterEach) { + console.warn( + 'Passing destroyAfterEach for configuring the test environment has been deprecated.' + + ' Please pass a `teardown` object with ModuleTeardownOptions interface instead,' + + ' see https://github.com/angular/angular/blob/6952a0a3e68481564b2bc4955afb3ac186df6e34/packages/core/testing/src/test_bed_common.ts#L98' + ); + teardown = { + destroyAfterEach: true, + }; +} + +if (teardown !== undefined) { + getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting(), { + teardown, + }); +} else { + getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting()); +} diff --git a/angular/envs/angular-v15-env/jest/jest.config.ts b/angular/envs/angular-v15-env/jest/jest.config.ts index 068e6bc9..a9238741 100644 --- a/angular/envs/angular-v15-env/jest/jest.config.ts +++ b/angular/envs/angular-v15-env/jest/jest.config.ts @@ -6,7 +6,7 @@ export default { preset: 'jest-preset-angular', globalSetup: 'jest-preset-angular/global-setup', reporters: ['default'], - setupFilesAfterEnv: [require.resolve('jest-preset-angular/setup-jest')], + setupFilesAfterEnv: [require.resolve('./setup-jest')], testPathIgnorePatterns: ['/.*/e2e/'], globals: { ngJest: { diff --git a/angular/envs/angular-v15-env/jest/setup-jest.js b/angular/envs/angular-v15-env/jest/setup-jest.js new file mode 100644 index 00000000..9d8088df --- /dev/null +++ b/angular/envs/angular-v15-env/jest/setup-jest.js @@ -0,0 +1,42 @@ +/* eslint-disable */ +require('zone.js'); +require('zone.js/testing'); +const { getTestBed } = require('@angular/core/testing'); +const { + BrowserDynamicTestingModule, + platformBrowserDynamicTesting, +} = require('@angular/platform-browser-dynamic/testing'); + +let testEnvironmentOptions = globalThis.ngJest?.testEnvironmentOptions ?? Object.create(null); + +const configuredDestroyAfterEach = globalThis.ngJest?.destroyAfterEach; +if (configuredDestroyAfterEach) { + console.warn( + 'Passing destroyAfterEach for configuring the test environment has been deprecated.' + + ' Please pass a `testEnvironmentOptions` object with TestEnvironmentOptions interface instead,' + + ' see https://angular.io/api/core/testing/TestEnvironmentOptions' + ); + + testEnvironmentOptions = { + ...testEnvironmentOptions, + teardown: { + destroyAfterEach: true, + }, + }; +} + +const configuredTeardown = globalThis.ngJest?.teardown; +if (configuredTeardown) { + console.warn( + 'Passing teardown for configuring the test environment has been deprecated.' + + ' Please pass a `testEnvironmentOptions` object with TestEnvironmentOptions interface instead,' + + ' see https://angular.io/api/core/testing/TestEnvironmentOptions' + ); + + testEnvironmentOptions = { + ...testEnvironmentOptions, + teardown: configuredTeardown, + }; +} + +getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting(), testEnvironmentOptions); diff --git a/angular/envs/angular-v16-env/angular-v16-env.bit-env.ts b/angular/envs/angular-v16-env/angular-v16-env.bit-env.ts index 871d0973..db8cfb49 100644 --- a/angular/envs/angular-v16-env/angular-v16-env.bit-env.ts +++ b/angular/envs/angular-v16-env/angular-v16-env.bit-env.ts @@ -58,7 +58,7 @@ export class AngularV16Env extends AngularBaseEnv { ngEnvOptions, sourceRoot, transformers, - webpackOptions: webpackOptions as any + webpackOptions }); } return super.getDevServer(devServerContext, ngEnvOptions, transformers as WebpackConfigTransformer[], angularOptions, webpackOptions, sourceRoot); diff --git a/angular/envs/angular-v17-env/angular-v17-env.bit-env.ts b/angular/envs/angular-v17-env/angular-v17-env.bit-env.ts index 72cb2e0c..73e14527 100644 --- a/angular/envs/angular-v17-env/angular-v17-env.bit-env.ts +++ b/angular/envs/angular-v17-env/angular-v17-env.bit-env.ts @@ -58,7 +58,7 @@ export class AngularV17Env extends AngularBaseEnv { ngEnvOptions, sourceRoot, transformers, - webpackOptions: webpackOptions as any + webpackOptions }); } return super.getDevServer(devServerContext, ngEnvOptions, transformers as WebpackConfigTransformer[], angularOptions, webpackOptions, sourceRoot); diff --git a/angular/envs/base-env/angular-base-env.bit-env.ts b/angular/envs/base-env/angular-base-env.bit-env.ts index 59923f0b..07b1f54d 100644 --- a/angular/envs/base-env/angular-base-env.bit-env.ts +++ b/angular/envs/base-env/angular-base-env.bit-env.ts @@ -42,7 +42,7 @@ import { SchemaExtractor } from '@teambit/schema'; import { Tester } from '@teambit/tester'; import { TypeScriptExtractor } from '@teambit/typescript'; import { TypescriptConfigWriter } from '@teambit/typescript.typescript-compiler'; -import { WebpackConfigTransformer, WebpackConfigWithDevServer } from '@teambit/webpack'; +import { WebpackConfigTransformer } from '@teambit/webpack'; import { ConfigWriterList } from '@teambit/workspace-config-files'; import { ESLint as ESLintLib } from 'eslint'; import { merge } from 'lodash'; @@ -157,7 +157,7 @@ export abstract class AngularBaseEnv implements AngularEnvInterface { ngEnvOptions, sourceRoot, transformers, - webpackOptions: webpackOptions + webpackOptions }); } @@ -175,7 +175,7 @@ export abstract class AngularBaseEnv implements AngularEnvInterface { ngEnvOptions, sourceRoot, transformers, - webpackOptions: webpackOptions + webpackOptions }); } diff --git a/angular/envs/base-env/preview/mounter.ts b/angular/envs/base-env/preview/mounter.ts index 2d648776..a682a523 100644 --- a/angular/envs/base-env/preview/mounter.ts +++ b/angular/envs/base-env/preview/mounter.ts @@ -10,6 +10,7 @@ import { Component, ViewEncapsulation } from '@angular/core'; */ @Component({ selector: 'bit-wrapper', + // @ts-ignore standalone: true, imports: [], encapsulation: ViewEncapsulation.None,