-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from Comandeer/t/13
- Loading branch information
Showing
27 changed files
with
628 additions
and
544 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,7 @@ | |
"mock-fs": "^5.2.0" | ||
}, | ||
"dependencies": { | ||
"execa": "^7.1.1" | ||
"execa": "^7.1.1", | ||
"pathe": "^1.1.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
function isBuiltInModule( { url, format } ) { | ||
if ( format ) { | ||
return format === 'builtin'; | ||
} | ||
|
||
return url.startsWith( 'node:' ); | ||
} | ||
|
||
export default isBuiltInModule; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { isAbsolute } from 'pathe'; | ||
import { relative as getRelativePath } from 'pathe'; | ||
import { fileURLToPath } from 'node:url'; | ||
|
||
function isInsideDir( dir, pathOrURL ) { | ||
const filePath = pathOrURL.startsWith( 'file://' ) ? fileURLToPath( pathOrURL ) : pathOrURL; | ||
const relativePath = getRelativePath( dir, filePath ); | ||
const isNotEmptyPath = relativePath.length > 0; | ||
const isNotOutsideDir = !relativePath.startsWith( '..' ); | ||
const isNotAbsolutePath = !isAbsolute( relativePath ); | ||
|
||
// https://stackoverflow.com/a/45242825/9025529 | ||
return isNotEmptyPath && isNotOutsideDir && isNotAbsolutePath; | ||
} | ||
|
||
export default isInsideDir; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
function isInsideNodeModules( pathOrURL ) { | ||
const npmModulesPathRegex = /[/\\]node_modules[/\\]/gi; | ||
|
||
return npmModulesPathRegex.test( pathOrURL ); | ||
} | ||
|
||
export default isInsideNodeModules; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { readFile } from 'node:fs/promises'; | ||
import { fileURLToPath } from 'node:url'; | ||
|
||
async function loadURL( url ) { | ||
const path = fileURLToPath( url ); | ||
|
||
return readFile( path ); | ||
} | ||
|
||
export default loadURL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { readdir } from 'node:fs/promises'; | ||
import { resolve as resolvePath } from 'pathe'; | ||
|
||
const configFileName = '.esmlmrc'; | ||
const configFileExtensions = [ | ||
'.js', | ||
'.mjs' | ||
]; | ||
|
||
async function resolveConfigFile( startDir, projectRoot ) { | ||
try { | ||
const files = await readdir( startDir ); | ||
|
||
for ( const extension of configFileExtensions ) { | ||
const configFileFullName = `${ configFileName }${ extension }`; | ||
|
||
if ( files.includes( configFileFullName ) ) { | ||
const resolvedConfigFilePath = resolvePath( startDir, configFileFullName ); | ||
|
||
return resolvedConfigFilePath; | ||
} | ||
} | ||
|
||
// Do not go outside of the project root. | ||
if ( startDir === projectRoot ) { | ||
return null; | ||
} | ||
|
||
const dirUp = resolvePath( startDir, '..' ); | ||
|
||
return resolveConfigFile( dirUp ); | ||
} catch { | ||
return null; | ||
} | ||
} | ||
|
||
export default resolveConfigFile; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { readdir } from 'node:fs/promises'; | ||
import { resolve as resolvePath } from 'pathe'; | ||
|
||
async function resolveProjectRoot( startDir ) { | ||
try { | ||
const files = await readdir( startDir ); | ||
|
||
if ( files.includes( 'package.json' ) ) { | ||
return startDir; | ||
} | ||
|
||
const dirUp = resolvePath( startDir, '..' ); | ||
|
||
// If directory one level up is the same as the current on, | ||
// we're at / and there's nowhere to go up. | ||
if ( dirUp === startDir ) { | ||
return null; | ||
} | ||
|
||
return resolveProjectRoot( dirUp ); | ||
} catch { | ||
return null; | ||
} | ||
} | ||
|
||
export default resolveProjectRoot; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { dirname } from 'pathe'; | ||
import { resolve as resolvePath } from 'pathe'; | ||
import { fileURLToPath } from 'node:url'; | ||
|
||
const __dirname = dirname( fileURLToPath( import.meta.url ) ); | ||
const fixtureDirPath = resolvePath( __dirname, '..', '__fixtures__' ); | ||
|
||
export default fixtureDirPath; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.