Skip to content

Commit

Permalink
fix jest issues with zone.js 0.14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ocombe committed Oct 12, 2023
1 parent 1cb59bc commit c32bc1a
Show file tree
Hide file tree
Showing 32 changed files with 329 additions and 194 deletions.
1 change: 1 addition & 0 deletions angular/devkit/ng-compat/build-angular/browser-schema.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
import { VERSION } from '@angular/cli';

export let BrowserBuilderSchema: any;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
import { VERSION } from '@angular/cli';

export let IndexHtmlWebpackPlugin: any;
Expand Down
1 change: 1 addition & 0 deletions angular/devkit/ng-compat/build-angular/server-schema.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
import { VERSION } from '@angular/cli';

export let OutputHashing: any;
Expand Down
1 change: 1 addition & 0 deletions angular/devkit/ng-compat/build-angular/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
import { json, logging } from '@angular-devkit/core';
import { VERSION } from '@angular/cli';
import { BrowserBuilderSchema } from '../browser-schema';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
import { VERSION } from '@angular/cli';
import { json } from '@angular-devkit/core';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
import { VERSION } from '@angular/cli';

export let generateEntryPoints: (options: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
import { logging } from '@angular-devkit/core';
import { VERSION } from '@angular/cli';
import { Configuration } from '@teambit/webpack';
Expand Down
1 change: 1 addition & 0 deletions angular/devkit/ng-compat/build-angular/webpack/configs.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
import type { Configuration } from 'webpack';
import { VERSION } from '@angular/cli';

Expand Down
1 change: 1 addition & 0 deletions angular/devkit/ng-compat/build-angular/webpack/stats.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
import { WebpackLoggingCallback } from '@angular-devkit/build-webpack';
import { logging } from '@angular-devkit/core';
import { VERSION } from '@angular/cli';
Expand Down
22 changes: 14 additions & 8 deletions angular/devkit/vite/dev-server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -21,8 +21,14 @@ import { getHostAlias } from './utils';
* 4. websocket protocol
*/
export async function configFactory(options: ViteDevServerOptions, aspectContext: ViteDevServerAspectsContext, port: number): Promise<InlineConfig> {
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;
Expand Down Expand Up @@ -71,7 +77,7 @@ export async function configFactory(options: ViteDevServerOptions, aspectContext
},
...hostAlias,
...alias || []
],
]
},
// apply different cache dir for each env
cacheDir,
Expand All @@ -82,15 +88,15 @@ 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: {
strict: false
}
},
optimizeDeps: {
entries,
entries
// exclude: packageList,
},
// TODO: make it replaceable and reusable
Expand All @@ -99,8 +105,8 @@ export async function configFactory(options: ViteDevServerOptions, aspectContext
// react(),
// mdx(mdxOptions),
// htmlPlugin(entries),
...plugins || [],
],
...plugins || []
]
});

// apply transformers
Expand Down
91 changes: 91 additions & 0 deletions angular/devkit/vite/dev-server/types.ts
Original file line number Diff line number Diff line change
@@ -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<BrowserOptions & DevServerOptions>;

/**
* 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<string, any>;

/**
* 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[];
};
2 changes: 2 additions & 0 deletions angular/devkit/vite/dev-server/utils/mdx-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -93,6 +94,7 @@ function extractImports(): Pluggable {
isDefault: importSpecifier.isDefault,
}));
});
// eslint-disable-next-line no-param-reassign
(file.data.imports ||= []).push(...imports);
});

Expand Down
1 change: 1 addition & 0 deletions angular/devkit/vite/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './ng-vite-dev-server';
export * from './dev-server/types';
102 changes: 10 additions & 92 deletions angular/devkit/vite/ng-vite-dev-server.ts
Original file line number Diff line number Diff line change
@@ -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<BrowserOptions & DevServerOptions>;

/**
* 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<string, any>;

/**
* 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';

Expand All @@ -120,7 +38,7 @@ export class NgViteDevServer {

static from(options: NgViteDevServerOptions): AsyncEnvHandler<DevServer> {
return async(context: EnvContext): Promise<DevServer> => {
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<any>('teambit.workspace/workspace');
Expand Down
Loading

0 comments on commit c32bc1a

Please sign in to comment.