-
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.
feat(extension): rudimentary extends implementation
- Loading branch information
Showing
10 changed files
with
71 additions
and
25 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
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
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,35 @@ | ||
import { existsSync } from 'node:fs' | ||
import { join } from 'node:path' | ||
import { it } from 'avait' | ||
import type { Configuration } from './types' | ||
|
||
const isExtension = async (value: string) => { | ||
// NOTE dynamic import in tests will resolve relative to project node_modules and not fixture. | ||
const { error } = await it(import(value)) | ||
if (!error) return true | ||
const paths = [value, join(process.cwd(), value), join(process.cwd(), 'node_modules', value)] | ||
const fileExists = paths.some(existsSync) | ||
if (fileExists) return true | ||
return false | ||
} | ||
|
||
export async function parse(value: string | object | boolean, configuration: Configuration['configuration']) { | ||
// Template. | ||
if (typeof value === 'string' && Object.hasOwn(configuration.templates, value)) { | ||
const configurationTemplate = configuration.templates[value as keyof typeof configuration.templates] | ||
return configuration.createFile(configurationTemplate) | ||
} | ||
|
||
// File extension. | ||
if (typeof value === 'string' && (await isExtension(value)) && typeof configuration.extension === 'function') { | ||
return configuration.createFile(configuration.extension(value)) | ||
} | ||
|
||
if (typeof value === 'object') { | ||
return configuration.createFile(value) | ||
} | ||
|
||
if (value === true) { | ||
return configuration.createFile() | ||
} | ||
} |
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,7 @@ | ||
{ | ||
"name": "extends", | ||
"configuration": { | ||
"eslint": "eslint-config-airbnb", | ||
"typescript": "my-shared-tsconfig/tsconfig.json" | ||
} | ||
} |
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