@mouse_484/oxc-config 0.8.9 → 0.8.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -2
- package/src/configs/index.js +2 -2
- package/src/configs/opinionated.js +0 -1
- package/src/lib/packages.js +22 -0
- package/src/lib/packages.test.js +59 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mouse_484/oxc-config",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.8.
|
|
4
|
+
"version": "0.8.10",
|
|
5
5
|
"author": "mouse_484",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/mouse484/config/tree/main/packages/oxc",
|
|
@@ -15,12 +15,13 @@
|
|
|
15
15
|
"main": "src/index.js",
|
|
16
16
|
"types": "src/index.d.ts",
|
|
17
17
|
"scripts": {
|
|
18
|
+
"test": "node --test",
|
|
18
19
|
"typegen": "node scripts/typegen.js"
|
|
19
20
|
},
|
|
20
21
|
"dependencies": {
|
|
21
22
|
"eslint-plugin-antfu": "^3.3.1",
|
|
22
23
|
"eslint-plugin-perfectionist": "^5.13.0",
|
|
23
|
-
"
|
|
24
|
+
"exsolve": "^1.0.7",
|
|
24
25
|
"oxfmt": "^0.75.0",
|
|
25
26
|
"oxlint": "^1.90.0",
|
|
26
27
|
"oxlint-tsgolint": "^7.0.2005"
|
package/src/configs/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createPackageDetector } from '../lib/packages.js'
|
|
2
2
|
import eslint from './eslint.js'
|
|
3
3
|
import importConfig from './import.js'
|
|
4
4
|
import javascript from './javascript.js'
|
|
@@ -30,7 +30,7 @@ const CONFIGS = /** @type {const} */[
|
|
|
30
30
|
@returns {import("oxlint").OxlintConfig[]} Generated configs for the enabled options
|
|
31
31
|
*/
|
|
32
32
|
export default function buildConfigs(options) {
|
|
33
|
-
const context = { isPackageExists, options }
|
|
33
|
+
const context = { isPackageExists: createPackageDetector(), options }
|
|
34
34
|
return CONFIGS.flatMap(({ name, build, enable = true }) => {
|
|
35
35
|
const option = options[name]
|
|
36
36
|
if (option === false) {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createResolver } from 'exsolve'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Create a package detector rooted in the consuming project.
|
|
5
|
+
* @param {string} [cwd] Project directory
|
|
6
|
+
* @returns {(name: string) => boolean} Package detector
|
|
7
|
+
*/
|
|
8
|
+
export function createPackageDetector(cwd) {
|
|
9
|
+
const { resolveModulePath } = createResolver({
|
|
10
|
+
from: cwd,
|
|
11
|
+
cache: false,
|
|
12
|
+
conditions: ['node', 'import', 'types'],
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
return (name) => {
|
|
16
|
+
// Check the manifest first to support packages containing only types.
|
|
17
|
+
return Boolean(
|
|
18
|
+
resolveModulePath(`${name}/package.json`, { try: true })
|
|
19
|
+
|| resolveModulePath(name, { try: true }),
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import assert from 'node:assert/strict'
|
|
2
|
+
import { mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'
|
|
3
|
+
import { tmpdir } from 'node:os'
|
|
4
|
+
import path from 'node:path'
|
|
5
|
+
// eslint-disable-next-line test/no-import-node-test -- This package uses the built-in test runner.
|
|
6
|
+
import { test } from 'node:test'
|
|
7
|
+
import { createPackageDetector } from './packages.js'
|
|
8
|
+
|
|
9
|
+
void test('detects packages from the consumer, including import-only and types-only packages', (context) => {
|
|
10
|
+
const root = mkdtempSync(path.join(tmpdir(), 'oxc-package-detection-'))
|
|
11
|
+
context.after(() => rmSync(root, { recursive: true, force: true }))
|
|
12
|
+
|
|
13
|
+
const project = path.join(root, 'project')
|
|
14
|
+
mkdirSync(project)
|
|
15
|
+
const fixtures = {
|
|
16
|
+
'import-only': { exports: { import: './index.js' }, type: 'module' },
|
|
17
|
+
'hidden-manifest': { exports: './index.js', type: 'module' },
|
|
18
|
+
'types-only-export': { exports: { '.': { types: './index.d.ts' } } },
|
|
19
|
+
'@types/example': { types: './index.d.ts' },
|
|
20
|
+
'conditional': { exports: { import: './index.js', require: './missing.cjs' }, type: 'module' },
|
|
21
|
+
}
|
|
22
|
+
for (const [name, manifest] of Object.entries(fixtures)) {
|
|
23
|
+
const directory = path.join(root, 'node_modules', name)
|
|
24
|
+
mkdirSync(directory, { recursive: true })
|
|
25
|
+
writeFileSync(path.join(directory, 'package.json'), JSON.stringify({ name, ...manifest }))
|
|
26
|
+
if (!('types' in manifest)) {
|
|
27
|
+
writeFileSync(path.join(directory, 'index.js'), 'export {}\n')
|
|
28
|
+
}
|
|
29
|
+
writeFileSync(path.join(directory, 'index.d.ts'), 'export {}\n')
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const detect = createPackageDetector(project)
|
|
33
|
+
for (const name of Object.keys(fixtures)) {
|
|
34
|
+
assert.equal(detect(name), true, name)
|
|
35
|
+
}
|
|
36
|
+
assert.equal(detect('missing-package'), false)
|
|
37
|
+
// Packages installed beside the config must not enable consumer presets.
|
|
38
|
+
assert.equal(detect('eslint-plugin-antfu'), false)
|
|
39
|
+
|
|
40
|
+
symlinkSync(path.join(root, 'node_modules/import-only'), path.join(root, 'node_modules/linked-package'), 'junction')
|
|
41
|
+
assert.equal(detect('linked-package'), true)
|
|
42
|
+
|
|
43
|
+
const broken = path.join(root, 'node_modules/broken-export')
|
|
44
|
+
mkdirSync(broken)
|
|
45
|
+
writeFileSync(path.join(broken, 'package.json'), JSON.stringify({ exports: './missing.js' }))
|
|
46
|
+
assert.equal(detect('broken-export'), false)
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
void test('a new detector observes the current project and newly installed packages', (context) => {
|
|
50
|
+
const root = mkdtempSync(path.join(tmpdir(), 'oxc-package-detection-'))
|
|
51
|
+
context.after(() => rmSync(root, { recursive: true, force: true }))
|
|
52
|
+
const detect = createPackageDetector(root)
|
|
53
|
+
assert.equal(detect('react'), false)
|
|
54
|
+
|
|
55
|
+
const directory = path.join(root, 'node_modules/react')
|
|
56
|
+
mkdirSync(directory, { recursive: true })
|
|
57
|
+
writeFileSync(path.join(directory, 'package.json'), JSON.stringify({ name: 'react' }))
|
|
58
|
+
assert.equal(createPackageDetector(root)('react'), true)
|
|
59
|
+
})
|