Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] CommonJS Module Imports esModuleInterop #8679

Merged
merged 5 commits into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@
"migration:generate": "yarn db:migration migration:generate",
"migration:create": "yarn db:migration migration:create",
"migration:command": "cross-env NODE_ENV=development NODE_OPTIONS=--max-old-space-size=12288 yarn --cwd ./packages/core",
"seed": "cross-env NODE_ENV=development NODE_OPTIONS=--max-old-space-size=12288 yarn run config:dev && yarn build:package:all && yarn ts-node -r tsconfig-paths/register --project apps/api/tsconfig.app.json ./apps/api/src/seed.ts",
"seed:ever": "cross-env NODE_ENV=development NODE_OPTIONS=--max-old-space-size=12288 yarn run config:dev && yarn build:package:all && yarn ts-node -r tsconfig-paths/register --project apps/api/tsconfig.app.json ./apps/api/src/seed-ever.ts",
"seed:all": "cross-env NODE_ENV=development NODE_OPTIONS=--max-old-space-size=12288 yarn run config:dev && yarn build:package:all && yarn ts-node -r tsconfig-paths/register --project apps/api/tsconfig.app.json ./apps/api/src/seed-all.ts",
"seed:jobs": "cross-env NODE_ENV=development NODE_OPTIONS=--max-old-space-size=12288 yarn run config:dev && yarn build:package:all && yarn ts-node -r tsconfig-paths/register --project apps/api/tsconfig.app.json ./apps/api/src/seed-jobs.ts",
"seed:module": "cross-env NODE_ENV=development NODE_OPTIONS=--max-old-space-size=12288 yarn run config:dev && yarn build:package:all && yarn ts-node -r tsconfig-paths/register --project apps/api/tsconfig.app.json ./apps/api/src/seed-module.ts --name",
"seed:prod": "cross-env NODE_ENV=production NODE_OPTIONS=--max-old-space-size=12288 yarn build:package:all && yarn run config:prod && yarn ts-node -r tsconfig-paths/register --project apps/api/tsconfig.app.json ./apps/api/src/seed.ts",
"seed:base": "cross-env NODE_OPTIONS=--max-old-space-size=12288 yarn run config:dev && yarn ts-node -r tsconfig-paths/register --project apps/api/tsconfig.app.json",
"seed": "yarn seed:base ./apps/api/src/seed.ts",
"seed:ever": "yarn seed:base ./apps/api/src/seed-ever.ts",
"seed:all": "yarn seed:base ./apps/api/src/seed-all.ts",
"seed:jobs": "yarn seed:base ./apps/api/src/seed-jobs.ts",
"seed:module": "yarn seed:base ./apps/api/src/seed-module.ts --name",
"seed:prod": "cross-env NODE_ENV=production NODE_OPTIONS=--max-old-space-size=12288 yarn build:package:all:prod && yarn run config:prod && yarn ts-node -r tsconfig-paths/register --project apps/api/tsconfig.app.json ./apps/api/src/seed.ts",
"prebuild": "rimraf dist coverage",
"bootstrap": "yarn install --ignore-scripts && yarn postinstall.manual",
"build": "yarn build:package:all && concurrently --raw \"yarn build:api\" \"yarn build:gauzy\"",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/lib/bootstrap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { useContainer } from 'class-validator';
import * as expressSession from 'express-session';
import RedisStore from 'connect-redis';
import { createClient } from 'redis';
import helmet from 'helmet';
import * as helmet from 'helmet';
import * as chalk from 'chalk';
import * as fs from 'fs';
import * as path from 'path';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import multer from 'multer';
import * as multer from 'multer';
import * as path from 'path';
import { FileStorage } from '../file-storage';
import { DirectoryPathGenerator } from './directory-path-generator';
Expand All @@ -8,6 +8,16 @@ import { IDirectoryPathGenerator } from './directory-path-generator.interface';
export class FileStorageFactory {
private static readonly pathGenerator: IDirectoryPathGenerator = new DirectoryPathGenerator();

/**
* Creates a multer storage engine configured with a custom file storage system.
*
* This function generates the base directory and subdirectory paths based on
* the provided `baseDirname`, and returns a `multer.StorageEngine` instance
* that saves files to these paths.
*
* @param {string} baseDirname - The base directory name used to generate the file storage path.
* @returns {multer.StorageEngine} - A multer storage engine configured to store files.
*/
public static create(baseDirname: string): multer.StorageEngine {
const baseDirectory = this.pathGenerator.getBaseDirectory(baseDirname);
const subDirectory = this.pathGenerator.getSubDirectory();
Expand Down
91 changes: 57 additions & 34 deletions packages/core/src/lib/core/seeds/seed-module.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,74 @@
// Modified code from https://github.com/alexitaylor/angular-graphql-nestjs-postgres-starter-kit.
// MIT License, see https://github.com/alexitaylor/angular-graphql-nestjs-postgres-starter-kit/blob/master/LICENSE
// Copyright (c) 2019 Alexi Taylor

import yargs from 'yargs';
import * as chalk from 'chalk';

import { NestFactory } from '@nestjs/core';
import * as yargs from 'yargs';
import * as chalk from 'chalk';
import { ApplicationPluginConfig } from '@gauzy/common';
import { registerPluginConfig } from './../../bootstrap';
import { SeedDataService } from './seed-data.service';
import { SeederModule } from './seeder.module';

/**
* Usage:
* yarn seed:module All
* yarn seed:module Default
* yarn seed:module Jobs
* yarn seed:module Reports
* yarn seed:module Ever
*
*/
export async function seedModule(devConfig: Partial<ApplicationPluginConfig>) {
await registerPluginConfig(devConfig);
* Seeds data for a specified module using the provided configuration.
*
* This function dynamically executes a seeding method in the `SeedDataService`
* based on the module name provided as a command-line argument. The method must
* exist in the `SeedDataService` and be named in the format `run<ModuleName>Seed`.
*
* @param {Partial<ApplicationPluginConfig>} devConfig - The development configuration
* for plugins, which will be registered before running the seeding process.
* @returns {Promise<void>} - A promise that resolves when the seeding process is complete.
*
* ## Usage:
* Run the command with `yarn` and specify the module name:
* ```
* yarn seed:module All
* yarn seed:module Default
* yarn seed:module Jobs
* yarn seed:module Reports
* yarn seed:module Ever
* ```
*/
export async function seedModule(devConfig: Partial<ApplicationPluginConfig>): Promise<void> {
try {
// Register the plugin configuration
await registerPluginConfig(devConfig);

NestFactory.createApplicationContext(SeederModule.forPlugins(), {
logger: ['log', 'error', 'warn', 'debug', 'verbose']
}).then((app) => {
const seeder = app.get(SeedDataService);
const argv: any = yargs(process.argv).argv;
const module = argv.name;
// Create the application context
const app = await NestFactory.createApplicationContext(SeederModule.forPlugins(), {
logger: ['log', 'error', 'warn', 'debug', 'verbose']
});

// Extract the module name from command-line arguments
const { name: module } = yargs(process.argv).argv as { name?: string };
if (!module) {
console.log(chalk.red('No module name provided. Please specify a module name.'));
await app.close();
return;
}

// Build the seed method name dynamically
const methodName = `run${module}Seed`;
const seeder = app.get(SeedDataService);

if (seeder[methodName]) {
seeder[methodName]()
.catch((error) => {
throw error;
})
.finally(() => app.close());
// Check if the method exists in the SeedDataService
if (typeof seeder[methodName] === 'function') {
try {
await seeder[methodName]();
console.log(chalk.green(`Successfully ran seed method: ${methodName}`));
} catch (error) {
console.error(chalk.red(`Error executing ${methodName}: ${error.message}`));
throw error;
}
} else {
console.log(
chalk.red(
`Method ${methodName} not found in SeedDataService`
)
);
app.close();
console.log(chalk.red(`Method ${methodName} not found in SeedDataService`));
}
}).catch((error) => {

// Close the application context
await app.close();
} catch (error) {
console.error(chalk.red(`Failed to seed module: ${error.message}`));
throw error;
});
}
}
2 changes: 1 addition & 1 deletion packages/core/src/lib/email-send/email-send.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BadRequestException, Injectable, InternalServerErrorException, NotFoundException } from "@nestjs/common";
import { IsNull } from "typeorm";
import Email from 'email-templates';
import * as Email from 'email-templates';
import { ISMTPConfig, isEmpty } from "@gauzy/common";
import { IBasePerTenantAndOrganizationEntityModel, IVerifySMTPTransport } from "@gauzy/contracts";
import { CustomSmtp } from "./../core/entities/internal";
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/lib/language/language-utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { faker } from '@faker-js/faker';
import { QueryRunner } from 'typeorm';
import { v4 as uuidV4 } from 'uuid';
import { DatabaseTypeEnum } from '@gauzy/config';
import { ILanguage, LanguagesEnum } from '@gauzy/contracts';
import allLanguages from './all-languages';
import { Language } from './language.entity';
import { faker } from '@faker-js/faker';
import { v4 as uuidV4 } from 'uuid';
import { DatabaseTypeEnum } from '@gauzy/config';

export class LanguageUtils {
private static async addLanguages(queryRunner: QueryRunner, languages: ILanguage[]): Promise<void> {
Expand Down
16 changes: 12 additions & 4 deletions packages/desktop-core/src/lib/concretes/window-config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { BrowserWindowConstructorOptions } from 'electron';
import { Store } from '../electron-helpers'
import { Store, setupElectronLog } from '../electron-helpers';
import { IWindowConfig } from '../interfaces';

// Set up Electron log
setupElectronLog();

export class WindowConfig implements IWindowConfig {
private _options?: BrowserWindowConstructorOptions;
private _path: string;
Expand All @@ -11,7 +14,7 @@ export class WindowConfig implements IWindowConfig {
this._hash = hash;
this._path = path;

this.options = {
this._options = {
webPreferences: {
nodeIntegration: true,
webSecurity: false,
Expand All @@ -21,23 +24,28 @@ export class WindowConfig implements IWindowConfig {
title: '',
show: false,
center: true,
icon: Store.get('filePath')?.iconPath,
icon: Store.get('filePath')?.iconPath,
...options
};
}

// Getter and setter for BrowserWindow options
public get options(): BrowserWindowConstructorOptions | undefined {
return this._options;
}
public set options(value: BrowserWindowConstructorOptions) {
public set options(value: BrowserWindowConstructorOptions | undefined) {
this._options = value;
}

// Getter and setter for the file path
public get path(): string {
return this._path;
}
public set path(value: string) {
this._path = value;
}

// Getter and setter for the hash
public get hash(): string {
return this._hash;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop-core/src/lib/concretes/window.manager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BrowserWindow, WebContents } from 'electron';
import log from 'electron-log';
import * as log from 'electron-log';
import { IWindow, IWindowManager, RegisteredWindow } from '../interfaces/iwindow.manager';

export class WindowManager implements IWindowManager {
Expand Down
21 changes: 13 additions & 8 deletions packages/desktop-core/src/lib/electron-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import * as ElectronLog from 'electron-log';
import { log, functions as logFunctions } from 'electron-log';
import * as ElectronStore from 'electron-store';
import { StoreSchema } from './interfaces/types';

// Set up the logger
console.log = ElectronLog.log;
Object.assign(console, ElectronLog.functions);
/**
* Sets up Electron logging by overriding console methods with Electron Log functions.
*/
const setupElectronLog = (): void => {
Object.assign(console, { ...logFunctions, log });
console.log('Electron logger has been initialized');
};

// Create a typed store instance
const Store = new ElectronStore<StoreSchema>();
/**
* Creates and exports a strongly-typed Electron Store instance.
*/
const store = new ElectronStore<StoreSchema>();

// Export the logger and store
export { ElectronLog, Store };
export { setupElectronLog, store as Store };
15 changes: 15 additions & 0 deletions packages/desktop-core/src/lib/interfaces/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ export interface FilePath {
iconPath: string;
}

/**
* Represents the structure of a project object stored in Electron Store.
*/
export interface StoreProject {
/**
* A note associated with the project.
*/
note: string;
}

/**
* Defines the structure of the Electron Store schema for type safety and consistency.
*
Expand All @@ -29,4 +39,9 @@ export interface StoreSchema {
* Includes the `iconPath` property which specifies the path to an icon.
*/
filePath: FilePath;

/**
* Represents the project configuration stored in the Electron Store.
*/
project: StoreProject;
}
Loading
Loading