Repository navigation
Expand file tree
/
Copy path.dependency-cruiser.cjs
More file actions
172 lines (166 loc) · 5.5 KB
/
Copy path.dependency-cruiser.cjs
File metadata and controls
172 lines (166 loc) · 5.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
const fs = require('fs');
const path = require('path');
const tsconfigDepcruisePath = path.join(__dirname, 'tsconfig.depcruise.json');
const appLib = 'packages/app/lib';
const packagesDir = path.join(__dirname, 'packages');
const packageNames = fs
.readdirSync(packagesDir)
.filter(
entry =>
fs.statSync(path.join(packagesDir, entry)).isDirectory() &&
fs.existsSync(path.join(packagesDir, entry, 'lib')),
);
const paths = {
'@react-native-firebase/app/dist/module/common/*': [`${appLib}/common/*`],
'@react-native-firebase/app/dist/module/common': [`${appLib}/common`],
'@react-native-firebase/app/dist/module/internal/web/*': [`${appLib}/internal/web/*`],
'@react-native-firebase/app/dist/module/internal/*': [`${appLib}/internal/*`],
'@react-native-firebase/app/dist/module/internal': [`${appLib}/internal`],
'@react-native-firebase/app/dist/module/types/internal': [`${appLib}/types/internal`],
'@react-native-firebase/app/dist/module/types/common': [`${appLib}/types/common`],
'@react-native-firebase/app': [appLib],
};
for (const pkg of packageNames) {
if (pkg === 'app') {
continue;
}
const lib = `packages/${pkg}/lib`;
paths[`@react-native-firebase/${pkg}`] = [lib];
paths[`@react-native-firebase/${pkg}/*`] = [`${lib}/*`];
}
fs.writeFileSync(
tsconfigDepcruisePath,
`${JSON.stringify(
{
extends: './tsconfig.packages.base.json',
compilerOptions: {
baseUrl: '.',
moduleResolution: 'node',
noEmit: true,
paths,
},
include: ['packages/*/lib/**/*.ts'],
exclude: [
'node_modules',
'packages/*/__tests__',
'packages/*/e2e',
'packages/*/plugin',
'**/*.test.ts',
],
},
null,
2,
)}\n`,
);
/** @type {import('dependency-cruiser').IConfiguration} */
module.exports = {
forbidden: [
{
name: 'no-circular',
severity: 'error',
scope: 'folder',
comment: 'Circular dependencies bloat bundle size and break module initialization order.',
from: { path: '^packages/[^/]+/lib$' },
to: { circular: true },
},
{
name: 'not-to-own-dist',
severity: 'error',
scope: 'module',
comment:
'Do not import your own package built output via relative ../dist or ./dist paths. ' +
'The hub API @react-native-firebase/app/dist/module/... is mapped to lib and is allowed.',
from: { path: '^packages/([^/]+)/lib' },
to: { path: '^packages/$1/dist' },
},
{
name: 'hub-no-internal',
severity: 'error',
comment: 'app is the hub — it must not import other internal packages.',
from: { path: '^packages/app/lib/' },
to: {
path: '^packages/[^/]+/lib/',
pathNot: '^packages/app/lib/',
dependencyTypesNot: ['type-only'],
},
},
{
name: 'satellites-only-hub',
severity: 'error',
comment: 'Plain satellites may import @react-native-firebase/app (and its subpaths) only.',
from: {
path: '^packages/([^/]+)/lib/',
pathNot: '^packages/(?:app|ai|vertexai)/lib/',
},
to: {
path: '^packages/([^/]+)/lib/',
pathNot: ['^packages/$1/lib/', '^packages/app/lib/'],
dependencyTypesNot: ['type-only', 'require'],
},
},
{
name: 'satellites-no-platform-split-subpath',
severity: 'error',
comment:
"Import getReactNativeModule / setReactNativeModule from '@react-native-firebase/app/dist/module/internal', " +
"not '.../internal/nativeModule'. A package exports target is an exact file, so bundlers that apply exports " +
'(Re.Pack / webpack) load the web nativeModule.js instead of nativeModule.android.js / nativeModule.ios.js.',
from: { path: '^packages/[^/]+/lib/', pathNot: '^packages/app/lib/' },
to: { path: '^packages/app/lib/internal/nativeModule\\.ts$' },
},
{
name: 'satellites-only-hub-require',
severity: 'error',
comment:
'Dynamic require between satellites is forbidden (crashlytics→analytics optional integration excluded).',
from: {
path: '^packages/([^/]+)/lib/',
pathNot: '^packages/(?:app|ai|vertexai|crashlytics)/lib/',
},
to: {
path: '^packages/([^/]+)/lib/',
pathNot: ['^packages/$1/lib/', '^packages/app/lib/'],
dependencyTypes: ['require'],
},
},
{
name: 'ai-graph',
severity: 'error',
comment: 'ai may import app, auth, and app-check (and their subpaths).',
from: { path: '^packages/ai/lib/' },
to: {
path: '^packages/([^/]+)/lib/',
pathNot: '^packages/(?:app|auth|app-check|ai)/lib/',
dependencyTypesNot: ['type-only'],
},
},
{
name: 'vertexai-graph',
severity: 'error',
comment: 'vertexai may import ai (and hub app transitively); not other satellites.',
from: { path: '^packages/vertexai/lib/' },
to: {
path: '^packages/([^/]+)/lib/',
pathNot: '^packages/(?:ai|app|vertexai)/lib/',
dependencyTypesNot: ['type-only'],
},
},
],
options: {
doNotFollow: {
path: 'node_modules|packages/[^/]+/(dist|__tests__|e2e|plugin)',
},
includeOnly: {
path: '^packages/[^/]+/(lib|dist)/',
},
exclude: {
path: 'packages/app/lib/internal/web/memidb',
},
tsPreCompilationDeps: true,
tsConfig: { fileName: 'tsconfig.depcruise.json' },
enhancedResolveOptions: {
exportsFields: ['exports'],
conditionNames: ['import', 'require', 'node', 'default'],
},
},
};