Skip to content

Commit

Permalink
fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ocombe committed Sep 6, 2023
1 parent 5b7543f commit 4b0e8de
Show file tree
Hide file tree
Showing 66 changed files with 137 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { AngularCompilerOptions } from '@angular/compiler-cli';
import { componentIsApp } from '@teambit/angular-apps';
import type { AngularEnvOptions } from '@teambit/angular-common';
import { getNodeModulesPaths, getWorkspace } from '@teambit/angular-common';
import { RollupCompiler } from './rollup/rollup.compiler';
import { ApplicationAspect, ApplicationMain } from '@teambit/application';
import {
ArtifactDefinition,
Expand All @@ -21,6 +20,7 @@ import { NgccProcessor } from '@teambit/ngcc';
import { Workspace, WorkspaceAspect } from '@teambit/workspace';
import chalk from 'chalk';
import { extname, join } from 'path';
import { RollupCompiler } from './rollup/rollup.compiler';

interface AngularElementsCompilerOptions {
ngPackagrModulePath?: string;
Expand Down Expand Up @@ -109,7 +109,7 @@ Built Angular Compositions
}
// Build compositions
await this.compositionsCompilation(params.component, params.componentDir, params.outputDir, true);
return;

// }
// TODO: implement compilation of components as webcomponents
// throw new Error('not implemented');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const root = document.getElementById('root') as HTMLElement;
* this function can be overridden through ReactAspect.overrideCompositionsMounter() API
* to apply custom logic for component DOM mounting.
*/
export default async (composition: any/*, previewContext: RenderingContext*/) => {
export default async (composition: any/* , previewContext: RenderingContext */) => {
ReactDOM.render(
<div>{await ngToReact([composition])}</div>,
root
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export async function ngcPlugin(options: Options, logger: Logger): Promise<Plugi
// eslint-disable-next-line @typescript-eslint/return-await
const res = await compile({ id: resolve(id).replace(/\\/g, '/'), host, options: opts, files });
// Manually force import the jit compiler at the beginning of the files
res.code = "import '@angular/compiler';\n" + res.code;
res.code = `import '@angular/compiler';\n${ res.code}`;
return res;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import { TransformHook } from 'rollup';
// import { minify } from 'rollup-plugin-esbuild';
// import html from '@rollup/plugin-html';
// import sourcemaps from 'rollup-plugin-sourcemaps';
import type { AngularCompilerOptions } from '@angular/compiler-cli';
import { ngcPlugin } from './ngc-plugin';
// import { ensureUnixPath } from './utils/path';
import { generateKey, readCacheEntry, saveCacheEntry } from './utils/cache';
import { getNodeJSFileSystem, ngBabelLinker, ngCompilerCli, ngccCompilerCli } from './utils/ng-compiler-cli';
import type { AngularCompilerOptions } from '@angular/compiler-cli';

export type OutputFileCache = Map<string, { version: string; content: string }>;

Expand Down Expand Up @@ -51,14 +51,14 @@ export class RollupCompiler {
}

async bundleFiles(opts: RollupOptions) {
const cacheDirectory = opts.cacheDirectory;
const {cacheDirectory} = opts;

/** File system used by the Angular linker plugin. */
const NodeJSFileSystem = await getNodeJSFileSystem();
const fileSystem = new NodeJSFileSystem();

/** Logger used by the Angular linker plugin. */
let ConsoleLogger: any, LogLevel: any;
let ConsoleLogger: any; let LogLevel: any;
const ngCompilerCliApi = await ngCompilerCli() as any;
if (ngCompilerCliApi.ConsoleLogger && ngCompilerCliApi.LogLevel) {
ConsoleLogger = ngCompilerCliApi.ConsoleLogger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import * as fs from 'fs';
import { dirname } from 'path';
import { promisify } from 'util';

export const readFile = fs.promises.readFile;
export const writeFile = fs.promises.writeFile;
export const access = fs.promises.access;
export const mkdir = fs.promises.mkdir;
export const stat = fs.promises.stat;
export const {readFile, writeFile, access, mkdir, stat} = fs.promises;
// @ts-ignore
export const rmdir = fs.promises.rm ?? fs.promises.rmdir;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const NgMultiCompilerTask = {
const description = options.description || 'compiling components using NgMultiCompiler';

return CompilerTask.from({
name: name,
name,
description,
compiler: options.ngMultiCompiler
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export class NgMultiCompiler implements Compiler {
}

private _babelCompiler!: BabelCompiler;

get babelCompiler(): BabelCompiler {
if (!this._babelCompiler) {
this._babelCompiler = this.babelMain.createCompiler({
Expand Down Expand Up @@ -95,9 +96,9 @@ export class NgMultiCompiler implements Compiler {
}
if (params.initiator === CompilationInitiator.PreStart || params.initiator === CompilationInitiator.Start) {
return this.mainCompiler.transpileComponent(params);
} else {
}
return this.ngPackagrCompiler.transpileComponent(params);
}

}

transpileFile(fileContent: string, params: TranspileFileParams): TranspileFileOutput {
Expand All @@ -122,7 +123,7 @@ export class NgMultiCompiler implements Compiler {
*/
async build(context: BuildContext): Promise<BuiltTaskResult> {
const componentsResults: ComponentResult[] = [];
let capsules = context.capsuleNetwork.seedersCapsules;
const capsules = context.capsuleNetwork.seedersCapsules;
// compile all app entry files with babel
const appComponentCapsules = capsules.filter(capsule => componentIsApp(capsule.component, this.application));
appComponentCapsules.forEach((capsule: Capsule) => {
Expand Down Expand Up @@ -200,12 +201,12 @@ export class NgMultiCompiler implements Compiler {
const application = context.getAspect<ApplicationMain>(ApplicationAspect.id);

const ngPackagrCompiler = NgPackagrCompiler.from({
artifactName: artifactName,
distDir: distDir,
distGlobPatterns: distGlobPatterns,
artifactName,
distDir,
distGlobPatterns,
ngEnvOptions: options.ngEnvOptions,
ngPackagrModulePath,
shouldCopyNonSupportedFiles: shouldCopyNonSupportedFiles,
shouldCopyNonSupportedFiles,
tsCompilerOptions: options.tsCompilerOptions
})(context);

Expand Down
14 changes: 7 additions & 7 deletions scopes/dev-services/compiler/ng-packagr/ng-packagr.compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class NgPackagrCompiler implements Compiler {
} else {
// Angular v13+
this.readDefaultTsConfig = async() => {
const initializeTsConfig = module.initializeTsConfig;
const {initializeTsConfig} = module;
const entryPoints: any = [{
data: {
entryPoint: {
Expand Down Expand Up @@ -133,7 +133,7 @@ export class NgPackagrCompiler implements Compiler {
updatePackageJson.exports = packageJson.exports;
props.forEach(prop => {
if (packageJson.exports['.'][prop]) {
updatePackageJson.exports['.'][prop] = './' + posix.join(this.distDir, packageJson.exports['.'][prop]);
updatePackageJson.exports['.'][prop] = `./${ posix.join(this.distDir, packageJson.exports['.'][prop])}`;
}
});
}
Expand All @@ -151,7 +151,7 @@ export class NgPackagrCompiler implements Compiler {
// check for dependencies other than tslib and move them to peer dependencies
// see https://github.com/ng-packagr/ng-packagr/blob/master/docs/dependencies.md#general-recommendation-use-peerdependencies-whenever-possible
const packageJson = PackageJsonFile.loadFromPathSync(pathToOutputFolder, '');
const dependencies = packageJson.packageJsonObject.dependencies;
const {dependencies} = packageJson.packageJsonObject;
// const peerDependencies = packageJson.packageJsonObject.peerDependencies;
const allowedNonPeerDependencies: string[] = [];
const depKeys = Object.keys(dependencies).filter(dep => dep !== 'tslib'); // only tslib is allowed in dependencies
Expand Down Expand Up @@ -228,8 +228,8 @@ export class NgPackagrCompiler implements Compiler {
const dist = join(params.outputDir, this.distDir);
mkdirsSync(dist);
// We do not need to compile using ng-packagr (except for builds) because Angular reads the source files directly
return;
/*const isApp = componentIsApp(params.component, this.application);

/* const isApp = componentIsApp(params.component, this.application);
// No need to compile an app
if (isApp) {
return;
Expand All @@ -251,7 +251,7 @@ export class NgPackagrCompiler implements Compiler {
this.logger.off();
// Build component package
await this.ngPackagrCompilation(params.componentDir, params.outputDir, this.tsCompilerOptions, false);
this.logger.on();*/
this.logger.on(); */
}

private getArtifactDefinition(): ArtifactDefinition[] {
Expand Down Expand Up @@ -289,7 +289,7 @@ export class NgPackagrCompiler implements Compiler {
const componentsResults: ComponentResult[] = [];

for (const capsule of componentCapsules) {
const component = capsule.component;
const {component} = capsule;
const currentComponentResult: ComponentResult = {
component
};
Expand Down
4 changes: 2 additions & 2 deletions scopes/dev-services/compiler/ngcc/ngcc-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class NgccProcessor {

// The hash is used directly in the file name to mitigate potential read/write race
// conditions as well as to only require a file existence check
this.runHashFilePath = path.join(tempFolder, runHash + '.lock');
this.runHashFilePath = path.join(tempFolder, `${runHash }.lock`);

// If the run hash lock file exists, then ngcc was already run against this project state
if (existsSync(this.runHashFilePath)) {
Expand Down Expand Up @@ -101,7 +101,7 @@ export class NgccProcessor {

if (status !== 0) {
const errorMessage = error?.message || '';
throw new Error(errorMessage + `NGCC failed${errorMessage ? ', see above' : ''}.`);
throw new Error(`${errorMessage }NGCC failed${errorMessage ? ', see above' : ''}.`);
}

// ngcc was successful so if a run hash was generated, write it for next time
Expand Down
4 changes: 2 additions & 2 deletions scopes/dev-services/compiler/webpack/ng-webpack-bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class NgWebpackBundler {
const webpackBuildConfigFactory: WebpackBuildConfigFactory = options.ngEnvOptions.webpackConfigFactory;
const name = options.name || 'ng-webpack-bundler';
const logger = context.createLogger(name);
const bundlerContext = options.bundlerContext;
const {bundlerContext} = options;
const workspace = getWorkspace(context);
const pkg = context.getAspect<PkgMain>(PkgAspect.id);
const application = context.getAspect<ApplicationMain>(ApplicationAspect.id);
Expand All @@ -90,7 +90,7 @@ export class NgWebpackBundler {
tempFolder = join(CACHE_ROOT, idName);
}

let appRootPath: string, tsconfigPath: string;
let appRootPath: string; let tsconfigPath: string;
let plugins: WebpackPluginInstance[] = [];
if (isAppBuildContext(bundlerContext)) { // When you use `bit run <app>`
appRootPath = bundlerContext.capsule.path;// this.workspace?.componentDir(context.appComponent.id, {ignoreScopeAndVersion: true, ignoreVersion: true}) || '';
Expand Down
4 changes: 2 additions & 2 deletions scopes/dev-services/compiler/webpack/ng-webpack-dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class NgWebpackDevServer {

const name = options.name || 'ng-webpack-dev-server';
const logger = context.createLogger(name);
const devServerContext = options.devServerContext;
const {devServerContext} = options;
const workspace = getWorkspace(context);
const webpackMain = context.getAspect<WebpackMain>(WebpackAspect.id);
const pkg = context.getAspect<PkgMain>(PkgAspect.id);
Expand All @@ -93,7 +93,7 @@ export class NgWebpackDevServer {
tempFolder = join(CACHE_ROOT, idName);
}

let appRootPath: string, tsconfigPath: string;
let appRootPath: string; let tsconfigPath: string;
let isApp = false;
if (isAppContext(devServerContext)) { // When you use `bit run <app>`
appRootPath = workspace?.componentDir(devServerContext.appComponent.id, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ export class BitDedupeModuleResolvePlugin {
|| V16_ANGULAR_FORMATS.every(f => Object.keys(entryPointPackageJson as JsonObject).includes(f))
) {
return true;
} else {
const metadataPath = this.fs.resolve(entryPointPath, typings.replace(/\.d\.ts$/, '') + '.metadata.json');
}
const metadataPath = this.fs.resolve(entryPointPath, `${typings.replace(/\.d\.ts$/, '') }.metadata.json`);
return this.fs.exists(metadataPath);
}

}

getIssuer(result: any) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,34 +104,43 @@ export class NodeJSPathManipulation implements PathManipulation {
pwd(): AbsoluteFsPath {
return this.normalize(process.cwd()) as AbsoluteFsPath;
}

chdir(dir: AbsoluteFsPath): void {
process.chdir(dir);
}

resolve(...paths: string[]): AbsoluteFsPath {
return this.normalize(p.resolve(...paths)) as AbsoluteFsPath;
}

dirname<T extends string>(file: T): T {
return this.normalize(p.dirname(file)) as T;
}

join<T extends string>(basePath: T, ...paths: string[]): T {
return this.normalize(p.join(basePath, ...paths)) as T;
}

isRoot(path: AbsoluteFsPath): boolean {
return this.dirname(path) === this.normalize(path);
}

isRooted(path: string): boolean {
return p.isAbsolute(path);
}

relative<T extends PathString>(from: T, to: T): PathSegment|AbsoluteFsPath {
return this.normalize(p.relative(from, to)) as PathSegment | AbsoluteFsPath;
}

basename(filePath: string, extension?: string): PathSegment {
return p.basename(filePath, extension) as PathSegment;
}

extname(path: AbsoluteFsPath|PathSegment): string {
return p.extname(path);
}

normalize<T extends string>(path: T): T {
// Convert backslashes to forward slashes
return path.replace(/\\/g, '/') as T;
Expand All @@ -146,21 +155,27 @@ export class NodeJSReadonlyFileSystem extends NodeJSPathManipulation implements
exists(path: AbsoluteFsPath): boolean {
return fs.existsSync(path);
}

readFile(path: AbsoluteFsPath): string {
return fs.readFileSync(path, 'utf8');
}

readFileBuffer(path: AbsoluteFsPath): Uint8Array {
return fs.readFileSync(path);
}

readdir(path: AbsoluteFsPath): PathSegment[] {
return fs.readdirSync(path) as PathSegment[];
}

lstat(path: AbsoluteFsPath): FileStats {
return fs.lstatSync(path);
}

stat(path: AbsoluteFsPath): FileStats {
return fs.statSync(path);
}

realpath(path: AbsoluteFsPath): AbsoluteFsPath {
return this.resolve(fs.realpathSync(path));
}
Expand All @@ -173,18 +188,23 @@ export class NodeJSFileSystem extends NodeJSReadonlyFileSystem implements FileSy
writeFile(path: AbsoluteFsPath, data: string|Uint8Array, exclusive = false): void {
fs.writeFileSync(path, data, exclusive ? {flag: 'wx'} : undefined);
}

removeFile(path: AbsoluteFsPath): void {
fs.unlinkSync(path);
}

symlink(target: AbsoluteFsPath, path: AbsoluteFsPath): void {
fs.symlinkSync(target, path);
}

copyFile(from: AbsoluteFsPath, to: AbsoluteFsPath): void {
fs.copyFileSync(from, to);
}

moveFile(from: AbsoluteFsPath, to: AbsoluteFsPath): void {
fs.renameSync(from, to);
}

ensureDir(path: AbsoluteFsPath): void {
const parents: AbsoluteFsPath[] = [];
while (!this.isRoot(path) && !this.exists(path)) {
Expand All @@ -195,6 +215,7 @@ export class NodeJSFileSystem extends NodeJSReadonlyFileSystem implements FileSy
this.safeMkdir(parents.pop()!);
}
}

removeDeep(path: AbsoluteFsPath): void {
fs.rmdirSync(path, {recursive: true});
}
Expand Down
Loading

0 comments on commit 4b0e8de

Please sign in to comment.