diff --git a/package.json b/package.json index 3884020..0a7e0ed 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@extollo/lib", - "version": "0.10.2", + "version": "0.10.3", "description": "The framework library that lifts up your code.", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/service/Canonical.ts b/src/service/Canonical.ts index 27f6424..bc4c140 100644 --- a/src/service/Canonical.ts +++ b/src/service/Canonical.ts @@ -119,11 +119,12 @@ export abstract class Canonical extends Unit { } /** - * Get the suffix that files must have to be loaded by this service. - * Determines the runtime file extension based on the Node runtime. + * Returns true if the given file path has the correct suffix to be loaded by this unit. */ - public getScriptSuffix(): string { - return `${this.suffix}${env('NODE_SCRIPT_SUFFIX', '.js')}` + public isValidSuffix(path: string): boolean { + const jsSuffix = `${this.suffix}.js` + const tsSuffix = `${this.suffix}.ts` + return path.endsWith(jsSuffix) || path.endsWith(tsSuffix) } /** @@ -260,7 +261,7 @@ export abstract class Canonical extends Unit { public async up(): Promise { if ( await this.path.exists() ) { for await ( const entry of this.path.walk() ) { - if ( !entry.endsWith(this.getScriptSuffix()) ) { + if ( !this.isValidSuffix(entry) ) { this.logging.debug(`Skipping file with invalid suffix: ${entry}`) continue } @@ -305,7 +306,7 @@ export abstract class Canonical extends Unit { .split('') .reverse() .join('') - .substr(this.getScriptSuffix().length) + .substr(this.suffix.length + 3) // +3 to account for `.js` or `.ts` ending .split('') .reverse() .join('') diff --git a/src/service/Routing.ts b/src/service/Routing.ts index 9afa269..abe0843 100644 --- a/src/service/Routing.ts +++ b/src/service/Routing.ts @@ -39,9 +39,10 @@ export class Routing extends Unit { this.logging.verbose('Registering @extollo view engine namespace.') engine.registerNamespace('extollo', lib().concat('resources', 'views')) - const suffix = `.routes${env('NODE_SCRIPT_SUFFIX', '.js')}` + const jsSuffix = `.routes.js` + const tsSuffix = `.routes.ts` for await ( const entry of this.path.walk() ) { - if ( !entry.endsWith(suffix) ) { + if ( !entry.endsWith(jsSuffix) && !entry.endsWith(tsSuffix) ) { this.logging.debug(`Skipping routes file with invalid suffix: ${entry}`) continue }