Skip to content

Commit eb091c3

Browse files
committed
feat(path): add this method to path
1 parent 241f767 commit eb091c3

File tree

6 files changed

+113
-150
lines changed

6 files changed

+113
-150
lines changed

index.d.ts

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -438,59 +438,61 @@ export declare class Parser {
438438
export declare class Path {
439439
static defaultBeforePath: string
440440

441-
static pwd(subPath?: string, beforePath?: string): string
441+
static pwd(subPath?: string): string
442442

443-
static app(subPath?: string, beforePath?: string): string
443+
static app(subPath?: string): string
444444

445-
static bootstrap(subPath?: string, beforePath?: string): string
445+
static bootstrap(subPath?: string): string
446446

447-
static config(subPath?: string, beforePath?: string): string
447+
static config(subPath?: string): string
448448

449-
static database(subPath?: string, beforePath?: string): string
449+
static database(subPath?: string): string
450450

451-
static lang(subPath?: string, beforePath?: string): string
451+
static lang(subPath?: string): string
452452

453-
static nodeModules(subPath?: string, beforePath?: string): string
453+
static nodeModules(subPath?: string): string
454454

455-
static providers(subPath?: string, beforePath?: string): string
455+
static providers(subPath?: string): string
456456

457-
static public(subPath?: string, beforePath?: string): string
457+
static public(subPath?: string): string
458458

459-
static resources(subPath?: string, beforePath?: string): string
459+
static resources(subPath?: string): string
460460

461-
static routes(subPath?: string, beforePath?: string): string
461+
static routes(subPath?: string): string
462462

463-
static storage(subPath?: string, beforePath?: string): string
463+
static storage(subPath?: string): string
464464

465-
static tests(subPath?: string, beforePath?: string): string
465+
static tests(subPath?: string): string
466466

467-
static logs(subPath?: string, beforePath?: string): string
467+
static logs(subPath?: string): string
468468

469-
static views(subPath?: string, beforePath?: string): string
469+
static views(subPath?: string): string
470470

471-
static assets(subPath?: string, beforePath?: string): string
471+
static assets(subPath?: string): string
472472

473-
static locales(subPath?: string, beforePath?: string): string
473+
static locales(subPath?: string): string
474474

475-
static facades(subPath?: string, beforePath?: string): string
475+
static facades(subPath?: string): string
476476

477-
static stubs(subPath?: string, beforePath?: string): string
477+
static stubs(subPath?: string): string
478478

479-
static http(subPath?: string, beforePath?: string): string
479+
static http(subPath?: string): string
480480

481-
static console(subPath?: string, beforePath?: string): string
481+
static console(subPath?: string): string
482482

483-
static services(subPath?: string, beforePath?: string): string
483+
static services(subPath?: string): string
484484

485-
static migrations(subPath?: string, beforePath?: string): string
485+
static migrations(subPath?: string): string
486486

487-
static seeders(subPath?: string, beforePath?: string): string
487+
static seeders(subPath?: string): string
488488

489-
static bin(subPath?: string, beforePath?: string): string
489+
static bin(subPath?: string): string
490490

491-
static vmTmp(subPath?: string, beforePath?: string): string
491+
static vmTmp(subPath?: string): string
492492

493-
static vmHome(subPath?: string, beforePath?: string): string
493+
static vmHome(subPath?: string): string
494+
495+
static this(subPath?: string, stackIndex?: number): string
494496
}
495497

496498
export declare class Route {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@secjs/utils",
3-
"version": "1.8.5",
3+
"version": "1.8.6",
44
"description": "Utils functions and classes for Node.js",
55
"license": "MIT",
66
"author": "João Lenon <[email protected]>",

src/File.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
* file that was distributed with this source code.
88
*/
99

10-
import callSite from 'callsite'
1110
import prependFile from 'prepend-file'
1211

1312
import {
@@ -25,13 +24,14 @@ import {
2524

2625
import { lookup } from 'mime-types'
2726
import { randomBytes } from 'node:crypto'
28-
import { dirname, isAbsolute, parse, resolve, sep } from 'node:path'
27+
import { isAbsolute, parse, sep } from 'node:path'
2928

3029
import { Json } from '#src/Json'
3130
import { Debug } from '#src/Debug'
3231
import { Parser } from '#src/Parser'
3332
import { Options } from '#src/Options'
3433
import { NotFoundFileException } from '#src/Exceptions/NotFoundFileException'
34+
import { Path } from '#src/Path'
3535

3636
export class File {
3737
/**
@@ -186,10 +186,7 @@ export class File {
186186
*/
187187
static #parsePath(filePath) {
188188
if (!isAbsolute(filePath)) {
189-
const stack = callSite()
190-
const requester = dirname(stack[2].getFileName()).concat(sep)
191-
192-
filePath = resolve(requester.concat(filePath))
189+
filePath = Path.this(filePath, 3)
193190
}
194191

195192
const { base, dir, root } = parse(filePath)

src/Folder.js

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
* file that was distributed with this source code.
88
*/
99

10-
import callSite from 'callsite'
1110
import minimatch from 'minimatch'
1211

1312
import {
@@ -20,21 +19,14 @@ import {
2019
} from 'node:fs'
2120

2221
import { randomBytes } from 'node:crypto'
23-
import {
24-
dirname,
25-
isAbsolute,
26-
join,
27-
normalize,
28-
parse,
29-
resolve,
30-
sep,
31-
} from 'node:path'
22+
import { isAbsolute, join, parse, resolve, sep } from 'node:path'
3223

3324
import { Json } from '#src/Json'
3425
import { File } from '#src/File'
3526
import { Parser } from '#src/Parser'
3627
import { Options } from '#src/Options'
3728
import { NotFoundFolderException } from '#src/Exceptions/NotFoundFolderException'
29+
import { Path } from '#src/Path'
3830

3931
export class Folder {
4032
/**
@@ -239,10 +231,7 @@ export class Folder {
239231
*/
240232
static #parsePath(folderPath) {
241233
if (!isAbsolute(folderPath)) {
242-
const stack = callSite()
243-
const requester = dirname(stack[2].getFileName()).concat(sep)
244-
245-
folderPath = resolve(requester.concat(normalize(folderPath)))
234+
folderPath = Path.this(folderPath, 3)
246235
}
247236

248237
const { dir, name, ext } = parse(folderPath)

0 commit comments

Comments
 (0)