@anarchitects/nx-typeorm 0.4.1 → 0.4.3
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/generators/bootstrap/generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,IAAI,EAEJ,KAAK,iBAAiB,EACvB,MAAM,YAAY,CAAC;AAkBpB,UAAU,wBAAwB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,EAAE,CAAC,EAAE,iBAAiB,GAAG,YAAY,CAAC;IACtC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAOD,QAAA,MAAM,mBAAmB,gFAOf,CAAC;
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/generators/bootstrap/generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,IAAI,EAEJ,KAAK,iBAAiB,EACvB,MAAM,YAAY,CAAC;AAkBpB,UAAU,wBAAwB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,EAAE,CAAC,EAAE,iBAAiB,GAAG,YAAY,CAAC;IACtC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAOD,QAAA,MAAM,mBAAmB,gFAOf,CAAC;AAUX,KAAK,iBAAiB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;AAmB9D,wBAA8B,kBAAkB,CAC9C,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,wBAAwB,8BA4ClC"}
|
|
@@ -20,7 +20,6 @@ const DEFAULT_MIGRATIONS_DIR = 'src/infrastructure-persistence/migrations';
|
|
|
20
20
|
const DEFAULT_MIGRATION_FILE = '1700000000000_init_schema.ts';
|
|
21
21
|
const APP_MIGRATIONS_DATASOURCE_PATH = 'tools/typeorm/datasource.migrations.ts';
|
|
22
22
|
const APP_CONNECTION_OPTIONS_PATH = 'tools/typeorm/connection-options.ts';
|
|
23
|
-
const runtimeImportPath = './data-source';
|
|
24
23
|
const SUPPORTED_DATABASE_DISPLAY = [...SUPPORTED_DATABASES, 'postgresql'].join(', ');
|
|
25
24
|
const DRIVER_DEPENDENCIES = {
|
|
26
25
|
postgres: { packageName: 'pg', version: '^8.20.0' },
|
|
@@ -147,7 +146,7 @@ function prepareApplication(tree, projectRoot, sourceRoot, options, isNestApplic
|
|
|
147
146
|
}
|
|
148
147
|
}
|
|
149
148
|
if (isNestApplication) {
|
|
150
|
-
patchAppModule(tree, projectRoot, sourceRoot);
|
|
149
|
+
patchAppModule(tree, options.project, projectRoot, sourceRoot);
|
|
151
150
|
}
|
|
152
151
|
else {
|
|
153
152
|
patchMainFile(tree, projectRoot, sourceRoot);
|
|
@@ -234,7 +233,7 @@ function normalizeProjectRelative(pathValue) {
|
|
|
234
233
|
}
|
|
235
234
|
function resolveApplicationBootstrapMode(tree, projectName, projectRoot, sourceRoot) {
|
|
236
235
|
const resolvedSourceRoot = sourceRoot ?? joinPathFragments(projectRoot, 'src');
|
|
237
|
-
if (tree
|
|
236
|
+
if (resolveNestAppModulePath(tree, projectName, resolvedSourceRoot)) {
|
|
238
237
|
return 'nest';
|
|
239
238
|
}
|
|
240
239
|
const mainPath = joinPathFragments(resolvedSourceRoot, 'main.ts');
|
|
@@ -243,20 +242,61 @@ function resolveApplicationBootstrapMode(tree, projectName, projectRoot, sourceR
|
|
|
243
242
|
: null;
|
|
244
243
|
const looksLikeNestApplication = mainSource?.includes('@nestjs/core') || mainSource?.includes('NestFactory');
|
|
245
244
|
if (looksLikeNestApplication) {
|
|
246
|
-
throw new Error(`Project "${projectName}" looks like a NestJS application but is missing "${joinPathFragments(resolvedSourceRoot, 'app.module.ts')}". NestJS apps must wire TypeORM through TypeOrmModule in app.module.ts; bootstrap will not patch main.ts for NestJS apps.`);
|
|
245
|
+
throw new Error(`Project "${projectName}" looks like a NestJS application but is missing an app.module.ts under "${resolvedSourceRoot}" (for example "${joinPathFragments(resolvedSourceRoot, 'app.module.ts')}" or "${joinPathFragments(resolvedSourceRoot, 'app', 'app.module.ts')}"). NestJS apps must wire TypeORM through TypeOrmModule in app.module.ts; bootstrap will not patch main.ts for NestJS apps.`);
|
|
247
246
|
}
|
|
248
247
|
return 'plain';
|
|
249
248
|
}
|
|
250
|
-
function
|
|
249
|
+
function resolveNestAppModulePath(tree, projectName, sourceRoot) {
|
|
250
|
+
const rootModulePath = joinPathFragments(sourceRoot, 'app.module.ts');
|
|
251
|
+
if (tree.exists(rootModulePath)) {
|
|
252
|
+
return rootModulePath;
|
|
253
|
+
}
|
|
254
|
+
const nestedModulePaths = findNestedAppModulePaths(tree, sourceRoot);
|
|
255
|
+
if (nestedModulePaths.length === 0) {
|
|
256
|
+
return undefined;
|
|
257
|
+
}
|
|
258
|
+
if (nestedModulePaths.length === 1) {
|
|
259
|
+
return nestedModulePaths[0];
|
|
260
|
+
}
|
|
261
|
+
const listedPaths = nestedModulePaths
|
|
262
|
+
.map((modulePath) => `"${modulePath}"`)
|
|
263
|
+
.join(', ');
|
|
264
|
+
throw new Error(`Project "${projectName}" has multiple app.module.ts files under "${sourceRoot}": ${listedPaths}. Keep a single NestJS module entrypoint or move the canonical module to "${rootModulePath}".`);
|
|
265
|
+
}
|
|
266
|
+
function findNestedAppModulePaths(tree, rootDirectory) {
|
|
267
|
+
const matches = [];
|
|
268
|
+
function visit(directory) {
|
|
269
|
+
let children;
|
|
270
|
+
try {
|
|
271
|
+
children = [...tree.children(directory)].sort();
|
|
272
|
+
}
|
|
273
|
+
catch {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
for (const child of children) {
|
|
277
|
+
const childPath = joinPathFragments(directory, child);
|
|
278
|
+
if (child === 'app.module.ts' && tree.exists(childPath)) {
|
|
279
|
+
matches.push(childPath);
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
visit(childPath);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
visit(rootDirectory);
|
|
286
|
+
return matches.sort();
|
|
287
|
+
}
|
|
288
|
+
function patchAppModule(tree, projectName, projectRoot, sourceRoot) {
|
|
251
289
|
const resolvedSourceRoot = sourceRoot ?? joinPathFragments(projectRoot, 'src');
|
|
252
|
-
const modulePath =
|
|
253
|
-
if (!tree.exists(modulePath)) {
|
|
290
|
+
const modulePath = resolveNestAppModulePath(tree, projectName, resolvedSourceRoot);
|
|
291
|
+
if (!modulePath || !tree.exists(modulePath)) {
|
|
254
292
|
return;
|
|
255
293
|
}
|
|
256
294
|
const sourceText = tree.read(modulePath, 'utf-8');
|
|
257
295
|
if (!sourceText) {
|
|
258
296
|
return;
|
|
259
297
|
}
|
|
298
|
+
const runtimeDataSourcePath = joinPathFragments(resolvedSourceRoot, 'data-source.ts');
|
|
299
|
+
const runtimeImportPath = importPathFrom(modulePath, runtimeDataSourcePath);
|
|
260
300
|
const project = new Project({
|
|
261
301
|
useInMemoryFileSystem: true,
|
|
262
302
|
skipAddingFilesFromTsConfig: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugin/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAGV,aAAa,EAEd,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugin/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAGV,aAAa,EAEd,MAAM,YAAY,CAAC;AAmUpB,eAAO,MAAM,aAAa,EAAE,aAgB3B,CAAC;AAEF,eAAO,MAAM,IAAI,uCAAuC,CAAC;;;;;AAEzD,wBAGE"}
|
package/dist/plugin/index.js
CHANGED
|
@@ -20,8 +20,9 @@ const LIB_DATASOURCE_CANDIDATES = [
|
|
|
20
20
|
'tools/typeorm/datasource.migrations.js',
|
|
21
21
|
];
|
|
22
22
|
function isRelevantFile(file) {
|
|
23
|
+
const appModuleInSourceRoot = file.endsWith('/app.module.ts') && file.includes('/src/');
|
|
23
24
|
return (file.endsWith('/project.json') ||
|
|
24
|
-
|
|
25
|
+
appModuleInSourceRoot ||
|
|
25
26
|
file.endsWith('/src/data-source.ts') ||
|
|
26
27
|
file.endsWith('/src/data-source.js') ||
|
|
27
28
|
file.endsWith('/src/typeorm.datasource.ts') ||
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anarchitects/nx-typeorm",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "Nx plugin providing TypeORM executors, generators, and schema management utilities.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
"!**/*.tsbuildinfo"
|
|
14
14
|
],
|
|
15
15
|
"publishConfig": {
|
|
16
|
-
"access": "public"
|
|
16
|
+
"access": "public",
|
|
17
|
+
"provenance": false
|
|
17
18
|
},
|
|
18
19
|
"repository": {
|
|
19
20
|
"type": "git",
|
|
@@ -61,11 +62,11 @@
|
|
|
61
62
|
}
|
|
62
63
|
},
|
|
63
64
|
"peerDependencies": {
|
|
64
|
-
"@nx/devkit": ">= 19 < 23",
|
|
65
65
|
"ts-node": "^10.9.1",
|
|
66
66
|
"typeorm": "^0.3.28"
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
|
+
"@nx/devkit": ">= 19 < 23",
|
|
69
70
|
"ts-morph": "^22.0.0",
|
|
70
71
|
"tslib": "^2.8.1"
|
|
71
72
|
}
|