Skip to content

Commit

Permalink
Merge pull request #169 from AthennaIO/develop
Browse files Browse the repository at this point in the history
chore(npm): update dependencies
  • Loading branch information
jlenon7 authored Apr 17, 2023
2 parents 2252e55 + d8e3365 commit e3cee30
Show file tree
Hide file tree
Showing 13 changed files with 345 additions and 273 deletions.
460 changes: 250 additions & 210 deletions package-lock.json

Large diffs are not rendered by default.

19 changes: 9 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@athenna/core",
"version": "3.7.0",
"version": "3.8.0",
"description": "The plug and play Node.js framework.",
"license": "MIT",
"author": "João Lenon <[email protected]>",
Expand Down Expand Up @@ -62,19 +62,18 @@
"semver": "^7.3.8"
},
"devDependencies": {
"@athenna/artisan": "^3.8.0",
"@athenna/common": "^3.5.1",
"@athenna/config": "^3.5.0",
"@athenna/http": "^3.9.0",
"@athenna/ioc": "^3.3.0",
"@athenna/logger": "^3.3.0",
"@athenna/test": "^3.5.1",
"@athenna/view": "^3.2.0",
"@athenna/artisan": "^3.9.0",
"@athenna/common": "^3.6.0",
"@athenna/config": "^3.6.0",
"@athenna/http": "^3.10.0",
"@athenna/ioc": "^3.4.0",
"@athenna/logger": "^3.4.0",
"@athenna/test": "^3.6.0",
"@athenna/view": "^3.3.0",
"@swc/core": "^1.3.27",
"@typescript-eslint/eslint-plugin": "^5.56.0",
"@typescript-eslint/parser": "^5.56.0",
"c8": "^7.12.0",
"cls-rtracer": "^2.6.2",
"commitizen": "^4.2.6",
"cross-env": "^7.0.3",
"cz-conventional-changelog": "^3.3.0",
Expand Down
5 changes: 4 additions & 1 deletion src/Commands/BuildCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ export class BuildCommand extends BaseCommand {
const tsConfig = await this.getTsConfig()

await this.logger.promiseSpinner(
() => Exec.command(`${Path.bin('tsc')} --project ${tsConfig.path}`),
() =>
Exec.command(
`${Path.nodeModulesBin('tsc')} --project ${tsConfig.path}`,
),
{
stream: process.stdout,
text: 'Compiling all .ts files from your application',
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/MakeExceptionCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class MakeExceptionCommand extends BaseCommand {
private getDestinationPath(): string {
let destination = Config.get(
'rc.commands.make:exception.destination',
Path.app('Exceptions'),
Path.exceptions(),
)

if (!isAbsolute(destination)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/MakeServiceCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class MakeServiceCommand extends BaseCommand {
private getDestinationPath(): string {
let destination = Config.get(
'rc.commands.make:service.destination',
Path.app('Services'),
Path.services(),
)

if (!isAbsolute(destination)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/ReplCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class ReplCommand extends BaseCommand {

const entrypoint = Config.get(
'rc.commands.repl.entrypoint',
'#bootstrap/repl',
Path.bootstrap(`repl.${Path.ext()}`),
)

await Module.resolve(entrypoint, Config.get('rc.meta'))
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/ServeCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class ServeCommand extends BaseCommand {

const entrypoint = Config.get(
'rc.commands.serve.entrypoint',
'#bootstrap/main',
Path.bootstrap(`main.${Path.ext()}`),
)

await Module.resolve(entrypoint, Config.get('rc.meta'))
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/TestCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class TestCommand extends BaseCommand {

const entrypoint = Config.get(
'rc.commands.test.entrypoint',
'#bootstrap/test',
Path.bootstrap(`test.${Path.ext()}`),
)

process.argv.splice(2, 1)
Expand Down
83 changes: 49 additions & 34 deletions src/Ignite/Ignite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
*/

import { Ioc } from '@athenna/ioc'
import { EnvHelper, Rc } from '@athenna/config'
import { Http } from '#src/Applications/Http'
import { Repl } from '#src/Applications/Repl'
import { PrettyREPLServer } from 'pretty-repl'
import { EnvHelper, Rc } from '@athenna/config'
import { resolve, isAbsolute } from 'node:path'
import { SemverNode } from '#src/Types/SemverNode'
import { Artisan } from '#src/Applications/Artisan'
Expand Down Expand Up @@ -58,7 +58,6 @@ export class Ignite {
bootLogs: true,
shutdownLogs: true,
loadConfigSafe: true,
configPath: './config',
athennaRcPath: './.athennarc.json',
uncaughtExceptionHandler: this.handleError,
})
Expand All @@ -67,10 +66,14 @@ export class Ignite {
this.setApplicationRootPath()

this.options.envPath = this.resolvePath(this.options.envPath)
this.options.configPath = this.resolvePath(this.options.configPath)
this.options.athennaRcPath = this.resolvePath(this.options.athennaRcPath)

await this.setRcContentAndAppVars()

Path.mergeDirs(Config.get('rc.directories', {}))

this.setApplicationBeforePath()

this.verifyNodeEngineVersion()
this.registerItselfToTheContainer()
this.setApplicationSignals()
Expand Down Expand Up @@ -196,35 +199,17 @@ export class Ignite {
* where the application is running (JavaScript or TypeScript).
*
* This method will determine if the application is using TypeScript by the meta url.
* Also, if the application IS NOT using TypeScript, the "beforePath" (second argument
* of this method) will be defined as value of "Path.defaultBeforePath" method.
*
* Let's check this example when application is running in TypeScript environment:
*
* @example
* ```ts
* const meta = import.meta.url // 'file:///Users/jlenon7/Development/Athenna/AthennaIO/artisan.ts'
*
* this.setApplicationRootPath(meta, '/build')
* this.setApplicationRootPath()
*
* console.log(Path.ext()) // ts
* console.log(Path.pwd()) // /Users/jlenon7/Development/Athenna/AthennaIO
* console.log(Path.config(`app.${Path.ext()}`)) // /Users/jlenon7/Development/Athenna/AthennaIO/config/app.ts
* ```
*
* Now let's suppose that we have transpiled our code to JavaScript inside "/build" folder. "Path.pwd"
* will end with "/build" at the end:
*
* @example
* ```ts
* const meta = import.meta.url // 'file:///Users/jlenon7/Development/Athenna/AthennaIO/build/artisan.js'
*
* this.setApplicationRootPath(meta, '/build')
*
* console.log(Path.ext()) // js
* console.log(Path.pwd()) // /Users/jlenon7/Development/Athenna/AthennaIO/build
* console.log(Path.config(`app.${Path.ext()}`)) // /Users/jlenon7/Development/Athenna/AthennaIO/build/config/app.js
* ```
*/
public setApplicationRootPath(): void {
if (!Config.exists('rc.callPath')) {
Expand All @@ -241,10 +226,43 @@ export class Ignite {
* If env IS_TS is already set, then we cant change it.
*/
if (Env('IS_TS') === undefined) {
Path.resolveEnvironment(this.meta, this.options.beforePath)
if (this.meta.endsWith('.ts')) {
process.env.IS_TS = 'true'
} else {
process.env.IS_TS = 'false'
}
}
}

/**
* Set the application before path, in all directories of Path class unless
* the nodeModules and nodeModulesBin directories.
*
* @example
* ```ts
* this.setApplicationBeforePath()
*
* console.log(Path.config(`app.${Path.ext()}`)) // /Users/jlenon7/Development/Athenna/AthennaIO/config/build/app.ts
* ```
*/
public setApplicationBeforePath(): void {
if (Env('IS_TS') || !this.options.beforePath) {
return
}

Object.keys(Path.dirs).forEach(dir => {
if (dir === 'nodeModules') {
return
}

if (dir === 'nodeModulesBin') {
return
}

Path.dirs[dir] = this.options.beforePath + '/' + Path.dirs[dir]
})
}

/**
* Set the env file that the application will use. The env file path will be
* automatically resolved by Athenna (using the NODE_ENV variable) if any
Expand Down Expand Up @@ -314,9 +332,7 @@ export class Ignite {
*/
public async setRcContentAndAppVars() {
const file = new File(this.options.athennaRcPath, '')
const pkgJson = await new File(
Path.originalPwd('package.json'),
).getContentAsJson()
const pkgJson = await new File(Path.pwd('package.json')).getContentAsJson()
const corePkgJson = await new File('../../package.json').getContentAsJson()
const coreSemverVersion = this.parseVersion(corePkgJson.version)

Expand All @@ -327,11 +343,11 @@ export class Ignite {
const athennaRc = {
meta: this.meta,
typescript: Env('IS_TS', false),
isInPackageJson: false,
version: coreSemverVersion,
version: process.env.APP_VERSION,
athennaVersion: process.env.ATHENNA_VERSION,
engines: pkgJson.engines || {},
commands: {},
directories: {},
services: [],
preloads: [],
providers: [],
Expand Down Expand Up @@ -374,8 +390,7 @@ export class Ignite {
return
}

athennaRc.isInPackageJson = true
this.options.athennaRcPath = Path.originalPwd('package.json')
this.options.athennaRcPath = Path.pwd('package.json')

Config.set('rc', {
...athennaRc,
Expand All @@ -401,14 +416,14 @@ export class Ignite {
*
* @example
* ```ts
* await this.setConfigurationFiles(Path.config())
* await this.setConfigurationFiles()
*
* console.log(Path.config('user.database.url')) // some-url
* console.log(Path.config('customer.database.url')) // some-different-url
* console.log(Config('user.database.url')) // some-url
* console.log(Config('customer.database.url')) // some-different-url
* ```
*/
public async setConfigurationFiles(): Promise<void> {
await Config.loadAll(this.options.configPath, this.options.loadConfigSafe)
await Config.loadAll(Path.config(), this.options.loadConfigSafe)
}

/**
Expand Down
7 changes: 0 additions & 7 deletions src/Types/IgniteOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ export type IgniteOptions = {
*/
envPath?: string

/**
* The configuration files path.
*
* @default './config'
*/
configPath?: string

/**
* Load the configurations file safelly. If this option is true, Athenna
* will not reload configuration files that are already loaded.
Expand Down
3 changes: 2 additions & 1 deletion tests/Helpers/BaseTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { ExitFaker, BeforeEach, AfterEach } from '@athenna/test'
import { HttpRouteProvider, HttpServerProvider } from '@athenna/http'

export class BaseTest {
public originalDirs = Json.copy(Path.dirs)
public originalEnv = Json.copy(process.env)
public originalKill = Json.copy(process.kill)
public originalPJson = new File(Path.pwd('package.json')).getContentAsJsonSync()
Expand Down Expand Up @@ -51,8 +52,8 @@ export class BaseTest {
ExitFaker.release()
LoadHelper.providers = []
LoadHelper.alreadyPreloaded = []
Path.defaultBeforePath = ''
process.kill = this.originalKill
Path.dirs = this.originalDirs
process.env = Json.copy(this.originalEnv)

process.removeAllListeners('SIGINT')
Expand Down
8 changes: 8 additions & 0 deletions tests/Stubs/.athennarc-dirs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"directories": {
"controllers": "src/http/controllers",
"middlewares": "src/http/middlewares",
"interceptors": "src/http/interceptors",
"terminators": "src/http/terminators"
}
}
23 changes: 18 additions & 5 deletions tests/Unit/Ignite/IgniteTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export default class IgniteTest extends BaseTest {
shutdownLogs: true,
beforePath: '',
envPath: undefined,
configPath: Path.config(),
loadConfigSafe: true,
athennaRcPath: Path.pwd('package.json'),
})
Expand All @@ -54,7 +53,7 @@ export default class IgniteTest extends BaseTest {
const ignite = await new Ignite().load(meta, { beforePath: '/dist' })

assert.isFalse(Env('IS_TS', true))
assert.isTrue(Path.pwd().includes('dist'))
assert.isTrue(Path.app().includes('dist'))
assert.equal(ignite.meta, meta)
assert.containsSubset(ignite.options, { beforePath: '/dist' })
}
Expand Down Expand Up @@ -106,10 +105,10 @@ export default class IgniteTest extends BaseTest {
@Test()
public async shouldBeAbleToFireTheIgniteClassLoadingAllTheRestOfTheApplication({ assert }: TestContext) {
Config.set('rc.environments', ['other'])
Config.set('rc.directories', { config: 'tests/Stubs/igniteConfig' })

const ignite = await new Ignite().load(Config.get('meta'), {
envPath: Path.stubs('.env'),
configPath: Path.stubs('igniteConfig'),
})

await ignite.fire(['console'])
Expand All @@ -134,8 +133,9 @@ export default class IgniteTest extends BaseTest {

process.env.OVERRIDE_ENV = 'true'
Config.set('rc.environments', ['other'])
Config.set('rc.directories', { config: 'tests/Stubs/igniteConfig' })

const ignite = await new Ignite().load(Config.get('meta'), { configPath: Path.stubs('igniteConfig') })
const ignite = await new Ignite().load(Config.get('meta'))

await ignite.fire(['console'])

Expand All @@ -152,7 +152,9 @@ export default class IgniteTest extends BaseTest {

@Test()
public async shouldBeAbleToHandleSyntaxErrorExceptionsOfConfigsUsingTheDefaultIgniteHandler({ assert }: TestContext) {
const ignite = await new Ignite().load(Config.get('meta'), { configPath: Path.stubs('syntaxErrorConfig') })
Config.set('rc.directories', { config: 'tests/Stubs/syntaxErrorConfig' })

const ignite = await new Ignite().load(Config.get('meta'))

await ignite.fire(['console'])

Expand Down Expand Up @@ -301,4 +303,15 @@ export default class IgniteTest extends BaseTest {
assert.isTrue(ioc.hasDependency('decoratedWelcomeService'))
assert.isTrue(ioc.hasDependency('App/Services/DecoratedWelcomeService'))
}

@Test()
public async shouldBeAbleToIgniteTheApplicationWithDifferentDirectoriesRegistered({ assert }: TestContext) {
await new Ignite().load(Config.get('meta'), { athennaRcPath: Path.stubs('.athennarc-dirs.json') })

assert.equal(Path.app(), Path.pwd('app'))
assert.equal(Path.controllers(), Path.pwd('src/http/controllers'))
assert.equal(Path.middlewares(), Path.pwd('src/http/middlewares'))
assert.equal(Path.interceptors(), Path.pwd('src/http/interceptors'))
assert.equal(Path.terminators(), Path.pwd('src/http/terminators'))
}
}

0 comments on commit e3cee30

Please sign in to comment.