@luxfi/biome-config 1.0.0
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/base.jsonc +1047 -0
- package/package.json +25 -0
- package/project.json +27 -0
- package/scripts/generate.js +81 -0
- package/src/extractor.js +44 -0
- package/src/extractor.test.js +138 -0
- package/src/fixtures/array-merge-config.jsonc +52 -0
- package/src/fixtures/no-markers-config.jsonc +37 -0
- package/src/fixtures/off-override-config.jsonc +41 -0
- package/src/fixtures/simple-config.jsonc +45 -0
- package/src/merger.js +100 -0
- package/src/merger.test.js +178 -0
- package/src/processor.js +121 -0
- package/src/processor.test.js +336 -0
- package/src/universePackages.js +144 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
const { readCachedProjectGraph, readProjectsConfigurationFromProjectGraph } = require('@nx/devkit')
|
|
2
|
+
const path = require('node:path')
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Detects all @luxfi/* packages using NX project graph
|
|
6
|
+
* @returns {Array<{dir: string, name: string, fullName: string}>} Array of package info objects
|
|
7
|
+
*/
|
|
8
|
+
function detectUniversePackages() {
|
|
9
|
+
try {
|
|
10
|
+
// Read the NX project graph (cached for performance)
|
|
11
|
+
const projectGraph = readCachedProjectGraph()
|
|
12
|
+
const projectsConfig = readProjectsConfigurationFromProjectGraph(projectGraph)
|
|
13
|
+
|
|
14
|
+
const universePackages = []
|
|
15
|
+
|
|
16
|
+
// Iterate through all projects in the workspace
|
|
17
|
+
for (const [projectName, config] of Object.entries(projectsConfig.projects)) {
|
|
18
|
+
// NX project names are the same as package names (from package.json)
|
|
19
|
+
if (projectName.startsWith('@luxfi/')) {
|
|
20
|
+
// Extract the package name without @luxfi/ prefix
|
|
21
|
+
const shortName = projectName.replace('@luxfi/', '')
|
|
22
|
+
|
|
23
|
+
// Extract directory name from root path (e.g., "pkgs/api" -> "api")
|
|
24
|
+
const dir = path.basename(config.root)
|
|
25
|
+
|
|
26
|
+
universePackages.push({
|
|
27
|
+
dir,
|
|
28
|
+
name: shortName,
|
|
29
|
+
fullName: projectName,
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return universePackages
|
|
35
|
+
} catch (error) {
|
|
36
|
+
console.warn(`Warning: Could not read project graph: ${error.message}`)
|
|
37
|
+
console.warn('Falling back to empty package list')
|
|
38
|
+
return []
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Generates override configurations for @luxfi/* packages
|
|
44
|
+
* Each package gets an override that:
|
|
45
|
+
* - Applies to files within that package
|
|
46
|
+
* - Allows the package to deep-import into itself
|
|
47
|
+
*
|
|
48
|
+
* @param {Array<{dir: string, name: string, fullName: string}>} universePackages - Detected packages
|
|
49
|
+
* @param {Array<Object>} globalPatterns - Global restriction patterns
|
|
50
|
+
* @returns {Array<Object>} Array of override configurations
|
|
51
|
+
*/
|
|
52
|
+
function generateUniversePackageOverrides(universePackages, globalPatterns) {
|
|
53
|
+
const overrides = []
|
|
54
|
+
|
|
55
|
+
for (const pkg of universePackages) {
|
|
56
|
+
// For each @luxfi/* package, we need to:
|
|
57
|
+
// 1. Allow deep imports to ITSELF (@luxfi/api can use @luxfi/api/src/...)
|
|
58
|
+
// 2. Block deep imports to OTHER @luxfi/* packages
|
|
59
|
+
//
|
|
60
|
+
// Strategy: Replace the wildcard pattern @luxfi/*/src with explicit patterns
|
|
61
|
+
// for all OTHER packages (excluding the current package)
|
|
62
|
+
|
|
63
|
+
const filteredPatterns = globalPatterns
|
|
64
|
+
.map((pattern) => {
|
|
65
|
+
if (!pattern.group || !Array.isArray(pattern.group)) {
|
|
66
|
+
return pattern // Keep non-group patterns as-is
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Check if this is the @luxfi/* wildcard pattern
|
|
70
|
+
const hasUniverseWildcard = pattern.group.some((g) => g.includes('@luxfi/*/src') || g === '@luxfi/*/src/*')
|
|
71
|
+
|
|
72
|
+
if (!hasUniverseWildcard) {
|
|
73
|
+
return pattern // Keep other patterns unchanged
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Replace wildcard with explicit patterns for OTHER @luxfi/* packages
|
|
77
|
+
const otherPackages = universePackages.filter((p) => p.name !== pkg.name)
|
|
78
|
+
const explicitGroup = []
|
|
79
|
+
|
|
80
|
+
for (const otherPkg of otherPackages) {
|
|
81
|
+
explicitGroup.push(`@luxfi/${otherPkg.name}/src`)
|
|
82
|
+
explicitGroup.push(`@luxfi/${otherPkg.name}/src/*`)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Return new pattern with explicit group (or empty if no other packages)
|
|
86
|
+
return explicitGroup.length > 0
|
|
87
|
+
? {
|
|
88
|
+
...pattern,
|
|
89
|
+
group: explicitGroup,
|
|
90
|
+
}
|
|
91
|
+
: null // Will be filtered out below
|
|
92
|
+
})
|
|
93
|
+
.filter((p) => p !== null) // Remove null entries
|
|
94
|
+
|
|
95
|
+
const override = {
|
|
96
|
+
includes: [
|
|
97
|
+
`pkgs/${pkg.dir}/**`,
|
|
98
|
+
`!pkgs/${pkg.dir}/.eslintrc.js`,
|
|
99
|
+
`!pkgs/${pkg.dir}/**/__generated__/**`,
|
|
100
|
+
`!pkgs/${pkg.dir}/scripts/**`,
|
|
101
|
+
],
|
|
102
|
+
linter: {
|
|
103
|
+
rules: {
|
|
104
|
+
style: {
|
|
105
|
+
noRestrictedImports: {
|
|
106
|
+
level: 'error',
|
|
107
|
+
options: {
|
|
108
|
+
paths: {
|
|
109
|
+
__INCLUDE_GLOBAL_VALUES__: true,
|
|
110
|
+
},
|
|
111
|
+
patterns: filteredPatterns,
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
overrides.push(override)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return overrides
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Gets the global noRestrictedImports patterns from the config
|
|
127
|
+
* @param {Object} config - The base configuration
|
|
128
|
+
* @returns {Array<Object>} Array of pattern objects
|
|
129
|
+
*/
|
|
130
|
+
function getGlobalRestrictedImportPatterns(config) {
|
|
131
|
+
const patterns = config?.linter?.rules?.style?.noRestrictedImports?.options?.patterns
|
|
132
|
+
|
|
133
|
+
if (!Array.isArray(patterns)) {
|
|
134
|
+
return []
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return patterns
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
module.exports = {
|
|
141
|
+
detectUniversePackages,
|
|
142
|
+
generateUniversePackageOverrides,
|
|
143
|
+
getGlobalRestrictedImportPatterns,
|
|
144
|
+
}
|