@typeorm/codemod 1.0.0 → 1.0.2
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/README.md +13 -10
- package/dist/cli/print-guide.js +2 -2
- package/dist/cli/print-summary.js +3 -2
- package/dist/cli/print-summary.js.map +1 -1
- package/dist/cli/print-usage.js +2 -1
- package/dist/cli/print-usage.js.map +1 -1
- package/dist/cli/run-transforms.js +181 -79
- package/dist/cli/run-transforms.js.map +1 -1
- package/dist/dependencies/v1.js +23 -9
- package/dist/dependencies/v1.js.map +1 -1
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/transforms/ast-helpers.js +779 -19
- package/dist/transforms/ast-helpers.js.map +1 -1
- package/dist/transforms/stats.js +11 -0
- package/dist/transforms/stats.js.map +1 -1
- package/dist/transforms/todo.js +42 -2
- package/dist/transforms/todo.js.map +1 -1
- package/dist/transforms/v1/column-readonly.js +28 -13
- package/dist/transforms/v1/column-readonly.js.map +1 -1
- package/dist/transforms/v1/column-unsigned-numeric.js +27 -26
- package/dist/transforms/v1/column-unsigned-numeric.js.map +1 -1
- package/dist/transforms/v1/column-width-zerofill.js +2 -1
- package/dist/transforms/v1/column-width-zerofill.js.map +1 -1
- package/dist/transforms/v1/connection-manager.js +82 -0
- package/dist/transforms/v1/connection-manager.js.map +1 -0
- package/dist/transforms/v1/connection-options-reader.js +214 -0
- package/dist/transforms/v1/connection-options-reader.js.map +1 -0
- package/dist/transforms/v1/connection-to-datasource.js +858 -93
- package/dist/transforms/v1/connection-to-datasource.js.map +1 -1
- package/dist/transforms/v1/datasource-expo.js +79 -0
- package/dist/transforms/v1/datasource-expo.js.map +1 -0
- package/dist/transforms/v1/datasource-mongodb.js +103 -64
- package/dist/transforms/v1/datasource-mongodb.js.map +1 -1
- package/dist/transforms/v1/datasource-mssql.js +88 -46
- package/dist/transforms/v1/datasource-mssql.js.map +1 -1
- package/dist/transforms/v1/datasource-mysql-connector.js +25 -6
- package/dist/transforms/v1/datasource-mysql-connector.js.map +1 -1
- package/dist/transforms/v1/datasource-name.js +19 -14
- package/dist/transforms/v1/datasource-name.js.map +1 -1
- package/dist/transforms/v1/datasource-sap.js +51 -26
- package/dist/transforms/v1/datasource-sap.js.map +1 -1
- package/dist/transforms/v1/datasource-sqlite-options.js +48 -13
- package/dist/transforms/v1/datasource-sqlite-options.js.map +1 -1
- package/dist/transforms/v1/datasource-sqlite-type.js +28 -7
- package/dist/transforms/v1/datasource-sqlite-type.js.map +1 -1
- package/dist/transforms/v1/file-logger.js +163 -0
- package/dist/transforms/v1/file-logger.js.map +1 -0
- package/dist/transforms/v1/find-options-join.js +84 -0
- package/dist/transforms/v1/find-options-join.js.map +1 -0
- package/dist/transforms/v1/find-options-lock-modes.js +26 -21
- package/dist/transforms/v1/find-options-lock-modes.js.map +1 -1
- package/dist/transforms/v1/find-options-string-relations.js +75 -9
- package/dist/transforms/v1/find-options-string-relations.js.map +1 -1
- package/dist/transforms/v1/find-options-string-select.js +75 -11
- package/dist/transforms/v1/find-options-string-select.js.map +1 -1
- package/dist/transforms/v1/global-functions.js +150 -64
- package/dist/transforms/v1/global-functions.js.map +1 -1
- package/dist/transforms/v1/index.js +16 -3
- package/dist/transforms/v1/index.js.map +1 -1
- package/dist/transforms/v1/migrations-get-all.js +25 -9
- package/dist/transforms/v1/migrations-get-all.js.map +1 -1
- package/dist/transforms/v1/mongodb-stats.js +21 -11
- package/dist/transforms/v1/mongodb-stats.js.map +1 -1
- package/dist/transforms/v1/mongodb-types.js +59 -2
- package/dist/transforms/v1/mongodb-types.js.map +1 -1
- package/dist/transforms/v1/query-builder-native-parameters.js +2 -0
- package/dist/transforms/v1/query-builder-native-parameters.js.map +1 -1
- package/dist/transforms/v1/query-builder-on-conflict.js +32 -18
- package/dist/transforms/v1/query-builder-on-conflict.js.map +1 -1
- package/dist/transforms/v1/query-builder-or-update.js +8 -4
- package/dist/transforms/v1/query-builder-or-update.js.map +1 -1
- package/dist/transforms/v1/query-builder-print-sql.js +18 -12
- package/dist/transforms/v1/query-builder-print-sql.js.map +1 -1
- package/dist/transforms/v1/query-builder-replace-property-names.js +16 -12
- package/dist/transforms/v1/query-builder-replace-property-names.js.map +1 -1
- package/dist/transforms/v1/query-builder-where-expression.js +29 -12
- package/dist/transforms/v1/query-builder-where-expression.js.map +1 -1
- package/dist/transforms/v1/query-runner-loaded-tables-views.js +1 -6
- package/dist/transforms/v1/query-runner-loaded-tables-views.js.map +1 -1
- package/dist/transforms/v1/relation-count.js +78 -12
- package/dist/transforms/v1/relation-count.js.map +1 -1
- package/dist/transforms/v1/repository-abstract.js +148 -34
- package/dist/transforms/v1/repository-abstract.js.map +1 -1
- package/dist/transforms/v1/repository-exist.js +20 -1
- package/dist/transforms/v1/repository-exist.js.map +1 -1
- package/dist/transforms/v1/repository-find-by-ids.js +67 -27
- package/dist/transforms/v1/repository-find-by-ids.js.map +1 -1
- package/dist/transforms/v1/repository-find-one-by-id.js +6 -0
- package/dist/transforms/v1/repository-find-one-by-id.js.map +1 -1
- package/dist/transforms/v1/use-container.js +65 -15
- package/dist/transforms/v1/use-container.js.map +1 -1
- package/package.json +3 -1
- package/dist/cli/colors.d.ts +0 -7
- package/dist/cli/colors.js +0 -12
- package/dist/cli/colors.js.map +0 -1
- package/dist/cli/error.d.ts +0 -1
- package/dist/cli/error.js +0 -11
- package/dist/cli/error.js.map +0 -1
- package/dist/cli/list-transforms.d.ts +0 -1
- package/dist/cli/parse-args.d.ts +0 -10
- package/dist/cli/print-guide.d.ts +0 -1
- package/dist/cli/print-summary.d.ts +0 -17
- package/dist/cli/print-todos.d.ts +0 -1
- package/dist/cli/print-usage.d.ts +0 -1
- package/dist/cli/run-dependencies.d.ts +0 -6
- package/dist/cli/run-transforms.d.ts +0 -21
- package/dist/cli/run.d.ts +0 -9
- package/dist/dependencies/config.d.ts +0 -24
- package/dist/dependencies/find-package-json.d.ts +0 -5
- package/dist/dependencies/index.d.ts +0 -5
- package/dist/dependencies/upgrade.d.ts +0 -11
- package/dist/dependencies/v1.d.ts +0 -2
- package/dist/index.d.ts +0 -2
- package/dist/lib/colors.d.ts +0 -9
- package/dist/lib/error.d.ts +0 -1
- package/dist/lib/format-time.d.ts +0 -1
- package/dist/lib/highlight.d.ts +0 -1
- package/dist/lib/spinner.d.ts +0 -5
- package/dist/transforms/ast-helpers.d.ts +0 -50
- package/dist/transforms/index.d.ts +0 -7
- package/dist/transforms/resolve.d.ts +0 -1
- package/dist/transforms/scan.d.ts +0 -4
- package/dist/transforms/scan.js +0 -33
- package/dist/transforms/scan.js.map +0 -1
- package/dist/transforms/stats.d.ts +0 -11
- package/dist/transforms/todo.d.ts +0 -2
- package/dist/transforms/transformer.d.ts +0 -8
- package/dist/transforms/v1/column-readonly.d.ts +0 -6
- package/dist/transforms/v1/column-unsigned-numeric.d.ts +0 -6
- package/dist/transforms/v1/column-width-zerofill.d.ts +0 -6
- package/dist/transforms/v1/connection-to-datasource.d.ts +0 -6
- package/dist/transforms/v1/datasource-mongodb.d.ts +0 -7
- package/dist/transforms/v1/datasource-mssql-domain.d.ts +0 -7
- package/dist/transforms/v1/datasource-mssql-domain.js +0 -35
- package/dist/transforms/v1/datasource-mssql-domain.js.map +0 -1
- package/dist/transforms/v1/datasource-mssql.d.ts +0 -7
- package/dist/transforms/v1/datasource-mysql-connector.d.ts +0 -6
- package/dist/transforms/v1/datasource-name.d.ts +0 -6
- package/dist/transforms/v1/datasource-sap.d.ts +0 -6
- package/dist/transforms/v1/datasource-sqlite-options.d.ts +0 -6
- package/dist/transforms/v1/datasource-sqlite-type.d.ts +0 -6
- package/dist/transforms/v1/find-options-lock-modes.d.ts +0 -6
- package/dist/transforms/v1/find-options-string-relations.d.ts +0 -6
- package/dist/transforms/v1/find-options-string-select.d.ts +0 -6
- package/dist/transforms/v1/global-functions.d.ts +0 -7
- package/dist/transforms/v1/index.d.ts +0 -40
- package/dist/transforms/v1/migrations-get-all.d.ts +0 -7
- package/dist/transforms/v1/mongodb-stats.d.ts +0 -7
- package/dist/transforms/v1/mongodb-types.d.ts +0 -6
- package/dist/transforms/v1/query-builder-native-parameters.d.ts +0 -6
- package/dist/transforms/v1/query-builder-on-conflict.d.ts +0 -7
- package/dist/transforms/v1/query-builder-or-update.d.ts +0 -6
- package/dist/transforms/v1/query-builder-print-sql.d.ts +0 -7
- package/dist/transforms/v1/query-builder-replace-property-names.d.ts +0 -7
- package/dist/transforms/v1/query-builder-where-expression.d.ts +0 -6
- package/dist/transforms/v1/query-runner-loaded-tables-views.d.ts +0 -7
- package/dist/transforms/v1/relation-count.d.ts +0 -7
- package/dist/transforms/v1/remove-abstract-repository.d.ts +0 -5
- package/dist/transforms/v1/remove-abstract-repository.js +0 -93
- package/dist/transforms/v1/remove-abstract-repository.js.map +0 -1
- package/dist/transforms/v1/remove-connector-package.d.ts +0 -4
- package/dist/transforms/v1/remove-connector-package.js +0 -19
- package/dist/transforms/v1/remove-connector-package.js.map +0 -1
- package/dist/transforms/v1/remove-datasource-name.d.ts +0 -4
- package/dist/transforms/v1/remove-datasource-name.js +0 -56
- package/dist/transforms/v1/remove-datasource-name.js.map +0 -1
- package/dist/transforms/v1/remove-mongodb-options.d.ts +0 -5
- package/dist/transforms/v1/remove-mongodb-options.js +0 -86
- package/dist/transforms/v1/remove-mongodb-options.js.map +0 -1
- package/dist/transforms/v1/remove-relation-count.d.ts +0 -5
- package/dist/transforms/v1/remove-relation-count.js +0 -49
- package/dist/transforms/v1/remove-relation-count.js.map +0 -1
- package/dist/transforms/v1/remove-replace-property-names.d.ts +0 -5
- package/dist/transforms/v1/remove-replace-property-names.js +0 -35
- package/dist/transforms/v1/remove-replace-property-names.js.map +0 -1
- package/dist/transforms/v1/remove-sap-options.d.ts +0 -4
- package/dist/transforms/v1/remove-sap-options.js +0 -54
- package/dist/transforms/v1/remove-sap-options.js.map +0 -1
- package/dist/transforms/v1/remove-unsigned-numeric.d.ts +0 -4
- package/dist/transforms/v1/remove-unsigned-numeric.js +0 -76
- package/dist/transforms/v1/remove-unsigned-numeric.js.map +0 -1
- package/dist/transforms/v1/remove-use-container.d.ts +0 -5
- package/dist/transforms/v1/remove-use-container.js +0 -63
- package/dist/transforms/v1/remove-use-container.js.map +0 -1
- package/dist/transforms/v1/remove-width-zerofill.d.ts +0 -4
- package/dist/transforms/v1/remove-width-zerofill.js +0 -29
- package/dist/transforms/v1/remove-width-zerofill.js.map +0 -1
- package/dist/transforms/v1/rename-connection-to-datasource.d.ts +0 -4
- package/dist/transforms/v1/rename-connection-to-datasource.js +0 -111
- package/dist/transforms/v1/rename-connection-to-datasource.js.map +0 -1
- package/dist/transforms/v1/rename-exist-to-exists.d.ts +0 -4
- package/dist/transforms/v1/rename-exist-to-exists.js +0 -25
- package/dist/transforms/v1/rename-exist-to-exists.js.map +0 -1
- package/dist/transforms/v1/rename-find-by-ids.d.ts +0 -4
- package/dist/transforms/v1/rename-find-by-ids.js +0 -64
- package/dist/transforms/v1/rename-find-by-ids.js.map +0 -1
- package/dist/transforms/v1/rename-get-all-migrations.d.ts +0 -5
- package/dist/transforms/v1/rename-get-all-migrations.js +0 -32
- package/dist/transforms/v1/rename-get-all-migrations.js.map +0 -1
- package/dist/transforms/v1/rename-loaded-tables-views.d.ts +0 -5
- package/dist/transforms/v1/rename-loaded-tables-views.js +0 -48
- package/dist/transforms/v1/rename-loaded-tables-views.js.map +0 -1
- package/dist/transforms/v1/rename-or-update-overload.d.ts +0 -4
- package/dist/transforms/v1/rename-or-update-overload.js +0 -46
- package/dist/transforms/v1/rename-or-update-overload.js.map +0 -1
- package/dist/transforms/v1/rename-print-sql-to-log-query.d.ts +0 -4
- package/dist/transforms/v1/rename-print-sql-to-log-query.js +0 -25
- package/dist/transforms/v1/rename-print-sql-to-log-query.js.map +0 -1
- package/dist/transforms/v1/replace-global-functions.d.ts +0 -5
- package/dist/transforms/v1/replace-global-functions.js +0 -92
- package/dist/transforms/v1/replace-global-functions.js.map +0 -1
- package/dist/transforms/v1/replace-lock-modes.d.ts +0 -4
- package/dist/transforms/v1/replace-lock-modes.js +0 -75
- package/dist/transforms/v1/replace-lock-modes.js.map +0 -1
- package/dist/transforms/v1/replace-mongodb-stats.d.ts +0 -5
- package/dist/transforms/v1/replace-mongodb-stats.js +0 -54
- package/dist/transforms/v1/replace-mongodb-stats.js.map +0 -1
- package/dist/transforms/v1/replace-mongodb-types.d.ts +0 -4
- package/dist/transforms/v1/replace-mongodb-types.js +0 -72
- package/dist/transforms/v1/replace-mongodb-types.js.map +0 -1
- package/dist/transforms/v1/replace-mssql-domain.d.ts +0 -5
- package/dist/transforms/v1/replace-mssql-domain.js +0 -25
- package/dist/transforms/v1/replace-mssql-domain.js.map +0 -1
- package/dist/transforms/v1/replace-on-conflict.d.ts +0 -5
- package/dist/transforms/v1/replace-on-conflict.js +0 -49
- package/dist/transforms/v1/replace-on-conflict.js.map +0 -1
- package/dist/transforms/v1/replace-readonly-column.d.ts +0 -4
- package/dist/transforms/v1/replace-readonly-column.js +0 -28
- package/dist/transforms/v1/replace-readonly-column.js.map +0 -1
- package/dist/transforms/v1/replace-set-native-parameters.d.ts +0 -4
- package/dist/transforms/v1/replace-set-native-parameters.js +0 -25
- package/dist/transforms/v1/replace-set-native-parameters.js.map +0 -1
- package/dist/transforms/v1/replace-sqlite-options.d.ts +0 -4
- package/dist/transforms/v1/replace-sqlite-options.js +0 -29
- package/dist/transforms/v1/replace-sqlite-options.js.map +0 -1
- package/dist/transforms/v1/replace-sqlite-type.d.ts +0 -4
- package/dist/transforms/v1/replace-sqlite-type.js +0 -22
- package/dist/transforms/v1/replace-sqlite-type.js.map +0 -1
- package/dist/transforms/v1/replace-where-expression-type.d.ts +0 -4
- package/dist/transforms/v1/replace-where-expression-type.js +0 -41
- package/dist/transforms/v1/replace-where-expression-type.js.map +0 -1
- package/dist/transforms/v1/repository-abstract.d.ts +0 -7
- package/dist/transforms/v1/repository-exist.d.ts +0 -6
- package/dist/transforms/v1/repository-find-by-ids.d.ts +0 -6
- package/dist/transforms/v1/repository-find-one-by-id.d.ts +0 -6
- package/dist/transforms/v1/upgrade-dependencies.d.ts +0 -15
- package/dist/transforms/v1/upgrade-dependencies.js +0 -163
- package/dist/transforms/v1/upgrade-dependencies.js.map +0 -1
- package/dist/transforms/v1/use-container.d.ts +0 -7
|
@@ -12,6 +12,16 @@ const propertyNames = new Set(["name"]);
|
|
|
12
12
|
const datasourceName = (file, api) => {
|
|
13
13
|
const j = api.jscodeshift;
|
|
14
14
|
const root = j(file.source);
|
|
15
|
+
if (!(0, ast_helpers_1.fileImportsFrom)(root, j, "typeorm"))
|
|
16
|
+
return undefined;
|
|
17
|
+
// Restrict matches to local bindings that resolve to TypeORM's
|
|
18
|
+
// DataSource/Connection types or `createConnection`. Without this, a
|
|
19
|
+
// user class called `Connection` or a `createConnection` from an unrelated
|
|
20
|
+
// package would have its `{ name }` option silently stripped.
|
|
21
|
+
const dataSourceNames = (0, ast_helpers_1.expandLocalNamesForImports)(root, j, "typeorm", new Set(["DataSource", "Connection"]));
|
|
22
|
+
const createConnectionNames = (0, ast_helpers_1.expandLocalNamesForImports)(root, j, "typeorm", new Set(["createConnection"]));
|
|
23
|
+
if (dataSourceNames.size === 0 && createConnectionNames.size === 0)
|
|
24
|
+
return undefined;
|
|
15
25
|
let hasChanges = false;
|
|
16
26
|
const removeNameFromObject = (arg) => {
|
|
17
27
|
if (arg?.type !== "ObjectExpression")
|
|
@@ -20,22 +30,17 @@ const datasourceName = (file, api) => {
|
|
|
20
30
|
hasChanges = true;
|
|
21
31
|
}
|
|
22
32
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
callee
|
|
26
|
-
|
|
27
|
-
removeNameFromObject(path.node.arguments[0]);
|
|
28
|
-
});
|
|
29
|
-
// new Connection({ name: ... })
|
|
30
|
-
root.find(j.NewExpression, {
|
|
31
|
-
callee: { type: "Identifier", name: "Connection" },
|
|
32
|
-
}).forEach((path) => {
|
|
33
|
+
root.find(j.NewExpression).forEach((path) => {
|
|
34
|
+
const callee = path.node.callee;
|
|
35
|
+
if (callee.type !== "Identifier" || !dataSourceNames.has(callee.name))
|
|
36
|
+
return;
|
|
33
37
|
removeNameFromObject(path.node.arguments[0]);
|
|
34
38
|
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
callee
|
|
38
|
-
|
|
39
|
+
root.find(j.CallExpression).forEach((path) => {
|
|
40
|
+
const callee = path.node.callee;
|
|
41
|
+
if (callee.type !== "Identifier" ||
|
|
42
|
+
!createConnectionNames.has(callee.name))
|
|
43
|
+
return;
|
|
39
44
|
removeNameFromObject(path.node.arguments[0]);
|
|
40
45
|
});
|
|
41
46
|
return hasChanges ? root.toSource() : undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datasource-name.js","sourceRoot":"","sources":["../../../src/transforms/v1/datasource-name.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAE5B,
|
|
1
|
+
{"version":3,"file":"datasource-name.js","sourceRoot":"","sources":["../../../src/transforms/v1/datasource-name.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAE5B,gDAIuB;AAEV,QAAA,IAAI,GAAG,mBAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,mBAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAA;AAC1D,QAAA,WAAW,GACpB,2DAA2D,CAAA;AAE/D,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;AAEhC,MAAM,cAAc,GAAG,CAAC,IAAc,EAAE,GAAQ,EAAE,EAAE;IACvD,MAAM,CAAC,GAAG,GAAG,CAAC,WAAW,CAAA;IACzB,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAE3B,IAAI,CAAC,IAAA,6BAAe,EAAC,IAAI,EAAE,CAAC,EAAE,SAAS,CAAC;QAAE,OAAO,SAAS,CAAA;IAE1D,+DAA+D;IAC/D,qEAAqE;IACrE,2EAA2E;IAC3E,8DAA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K,YAAY;YAC5B,CAAC,qBAAqB,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;YAEvC,OAAM;QACV,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAA;IAChD,CAAC,CAAC,CAAA;IAEF,OAAO,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,SAAS,CAAA;AACnD,CAAC,CAAA;AApDY,QAAA,cAAc,kBAoD1B;AAEY,QAAA,EAAE,GAAG,sBAAc,CAAA;AAChC,kBAAe,UAAE,CAAA"}
|
|
@@ -8,6 +8,25 @@ const node_path_1 = __importDefault(require("node:path"));
|
|
|
8
8
|
const ast_helpers_1 = require("../ast-helpers");
|
|
9
9
|
exports.name = node_path_1.default.basename(__filename, node_path_1.default.extname(__filename));
|
|
10
10
|
exports.description = "rename and remove deprecated SAP HANA connection options";
|
|
11
|
+
const getKeyName = (key) => {
|
|
12
|
+
if (key.type === "Identifier")
|
|
13
|
+
return key.name;
|
|
14
|
+
return (0, ast_helpers_1.getStringValue)(key);
|
|
15
|
+
};
|
|
16
|
+
const renameKey = (key, newName) => {
|
|
17
|
+
if (key.type === "Identifier") {
|
|
18
|
+
key.name = newName;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
(0, ast_helpers_1.setStringValue)(key, newName);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
// Matches `{ type: "sap", ... }` objects — only then are SAP-specific
|
|
25
|
+
// option renames safe to apply (avoids clobbering unrelated user code).
|
|
26
|
+
// Peels TS wrappers so `type: "sap" as const` also matches.
|
|
27
|
+
const isSapOptions = (obj) => obj.properties.some((p) => (p.type === "ObjectProperty" || p.type === "Property") &&
|
|
28
|
+
getKeyName(p.key) === "type" &&
|
|
29
|
+
(0, ast_helpers_1.getStringValue)((0, ast_helpers_1.unwrapTsExpression)(p.value)) === "sap");
|
|
11
30
|
const datasourceSap = (file, api) => {
|
|
12
31
|
const j = api.jscodeshift;
|
|
13
32
|
const root = j(file.source);
|
|
@@ -23,35 +42,41 @@ const datasourceSap = (file, api) => {
|
|
|
23
42
|
idleTimeout: "maxPooledIdleTime",
|
|
24
43
|
};
|
|
25
44
|
const poolRemoves = new Set(["min", "maxWaitingRequests", "checkInterval"]);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (path.node.key.type !== "Identifier")
|
|
29
|
-
return;
|
|
30
|
-
const name = path.node.key.name;
|
|
31
|
-
// Top-level renames
|
|
32
|
-
if (topLevelRenames[name]) {
|
|
33
|
-
path.node.key.name = topLevelRenames[name];
|
|
34
|
-
hasChanges = true;
|
|
45
|
+
root.find(j.ObjectExpression).forEach((objPath) => {
|
|
46
|
+
if (!isSapOptions(objPath.node))
|
|
35
47
|
return;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
grandparent.node.key.type !== "Identifier" ||
|
|
45
|
-
grandparent.node.key.name !== "pool") {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
if (poolRemoves.has(name)) {
|
|
49
|
-
j(path).remove();
|
|
48
|
+
for (const prop of objPath.node.properties) {
|
|
49
|
+
if (prop.type !== "ObjectProperty")
|
|
50
|
+
continue;
|
|
51
|
+
const propName = getKeyName(prop.key);
|
|
52
|
+
if (propName === null)
|
|
53
|
+
continue;
|
|
54
|
+
if (topLevelRenames[propName]) {
|
|
55
|
+
renameKey(prop.key, topLevelRenames[propName]);
|
|
50
56
|
hasChanges = true;
|
|
57
|
+
continue;
|
|
51
58
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
59
|
+
if (propName === "pool" && prop.value.type === "ObjectExpression") {
|
|
60
|
+
const poolObj = prop.value;
|
|
61
|
+
const filtered = poolObj.properties.filter((inner) => {
|
|
62
|
+
if (inner.type !== "ObjectProperty")
|
|
63
|
+
return true;
|
|
64
|
+
const innerName = getKeyName(inner.key);
|
|
65
|
+
if (innerName === null)
|
|
66
|
+
return true;
|
|
67
|
+
if (poolRemoves.has(innerName)) {
|
|
68
|
+
hasChanges = true;
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
if (poolRenames[innerName]) {
|
|
72
|
+
renameKey(inner.key, poolRenames[innerName]);
|
|
73
|
+
hasChanges = true;
|
|
74
|
+
}
|
|
75
|
+
return true;
|
|
76
|
+
});
|
|
77
|
+
if (filtered.length !== poolObj.properties.length) {
|
|
78
|
+
poolObj.properties = filtered;
|
|
79
|
+
}
|
|
55
80
|
}
|
|
56
81
|
}
|
|
57
82
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datasource-sap.js","sourceRoot":"","sources":["../../../src/transforms/v1/datasource-sap.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAE5B,
|
|
1
|
+
{"version":3,"file":"datasource-sap.js","sourceRoot":"","sources":["../../../src/transforms/v1/datasource-sap.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAE5B,gDAKuB;AAEV,QAAA,IAAI,GAAG,mBAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,mBAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAA;AAC1D,QAAA,WAAW,GACpB,0DAA0D,CAAA;AAE9D,MAAM,UAAU,GAAG,CAAC,GAAY,EAAiB,EAAE;IAC/C,IAAI,GAAG,CAAC,IAAI,KAAK,YAAY;QAAE,OAAO,GAAG,CAAC,IAAI,CAAA;IAC9C,OAAO,IAAA,4BAAc,EAAC,GAAG,CAAC,CAAA;AAC9B,CAAC,CAAA;AAED,MAAM,SAAS,GAAG,CAAC,GAAY,EAAE,OAAe,EAAQ,EAAE;IACtD,IAAI,GAAG,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;QAC5B,GAAG,CAAC,IAAI,GAAG,OAAO,CAAA;IACtB,CAAC;SAAM,CAAC;QACJ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,IAAI,QAAQ,CAAC,MAAM,KAAK,OAAO,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC;oBAChD,OAAO,CAAC,UAAU,GAAG,QAAQ,CAAA;gBACjC,CAAC;YACL,CAAC;QACL,CAAC;IACL,CAAC,CAAC,CAAA;IAEF,OAAO,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,SAAS,CAAA;AACnD,CAAC,CAAA;AA1DY,QAAA,aAAa,iBA0DzB;AAEY,QAAA,EAAE,GAAG,qBAAa,CAAA;AAC/B,kBAAe,UAAE,CAAA"}
|
|
@@ -5,27 +5,62 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.fn = exports.datasourceSqliteOptions = exports.description = exports.name = void 0;
|
|
7
7
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const ast_helpers_1 = require("../ast-helpers");
|
|
8
9
|
exports.name = node_path_1.default.basename(__filename, node_path_1.default.extname(__filename));
|
|
9
10
|
exports.description = "rename `busyTimeout` to `timeout` and remove `flags` in SQLite config";
|
|
11
|
+
// TypeORM driver type values that share the SQLite `busyTimeout` / `flags`
|
|
12
|
+
// option shape. Scoping mutations to objects carrying one of these `type`
|
|
13
|
+
// values keeps the transform from touching unrelated configs (e.g. commander
|
|
14
|
+
// options, another library's settings) that happen to reuse the same keys.
|
|
15
|
+
const sqliteFamilyTypes = new Set([
|
|
16
|
+
"sqlite",
|
|
17
|
+
"better-sqlite3",
|
|
18
|
+
"sqljs",
|
|
19
|
+
"capacitor",
|
|
20
|
+
"cordova",
|
|
21
|
+
"react-native",
|
|
22
|
+
"nativescript",
|
|
23
|
+
"expo",
|
|
24
|
+
]);
|
|
25
|
+
const isSqliteOptions = (obj) => {
|
|
26
|
+
for (const prop of obj.properties) {
|
|
27
|
+
if (prop.type !== "Property" && prop.type !== "ObjectProperty") {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const keyName = prop.key.type === "Identifier"
|
|
31
|
+
? prop.key.name
|
|
32
|
+
: (0, ast_helpers_1.getStringValue)(prop.key);
|
|
33
|
+
if (keyName !== "type")
|
|
34
|
+
continue;
|
|
35
|
+
const value = (0, ast_helpers_1.getStringValue)(prop.value);
|
|
36
|
+
return value !== null && sqliteFamilyTypes.has(value);
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
};
|
|
10
40
|
const datasourceSqliteOptions = (file, api) => {
|
|
11
41
|
const j = api.jscodeshift;
|
|
12
42
|
const root = j(file.source);
|
|
13
43
|
let hasChanges = false;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
44
|
+
root.find(j.ObjectExpression).forEach((objPath) => {
|
|
45
|
+
if (!isSqliteOptions(objPath.node))
|
|
46
|
+
return;
|
|
47
|
+
for (const prop of objPath.node.properties) {
|
|
48
|
+
if (prop.type !== "Property" && prop.type !== "ObjectProperty") {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
const keyName = prop.key.type === "Identifier"
|
|
52
|
+
? prop.key.name
|
|
53
|
+
: (0, ast_helpers_1.getStringValue)(prop.key);
|
|
54
|
+
if (keyName !== "busyTimeout")
|
|
55
|
+
continue;
|
|
56
|
+
// Replace the key with an identifier — `"timeout"` doesn't need
|
|
57
|
+
// quoting and prettier would strip the quotes anyway.
|
|
58
|
+
prop.key = j.identifier("timeout");
|
|
59
|
+
hasChanges = true;
|
|
60
|
+
}
|
|
61
|
+
if ((0, ast_helpers_1.removeObjectProperties)(objPath.node, new Set(["flags"]))) {
|
|
20
62
|
hasChanges = true;
|
|
21
63
|
}
|
|
22
|
-
});
|
|
23
|
-
// Remove flags
|
|
24
|
-
root.find(j.ObjectProperty, {
|
|
25
|
-
key: { type: "Identifier", name: "flags" },
|
|
26
|
-
}).forEach((path) => {
|
|
27
|
-
j(path).remove();
|
|
28
|
-
hasChanges = true;
|
|
29
64
|
});
|
|
30
65
|
return hasChanges ? root.toSource() : undefined;
|
|
31
66
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datasource-sqlite-options.js","sourceRoot":"","sources":["../../../src/transforms/v1/datasource-sqlite-options.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;
|
|
1
|
+
{"version":3,"file":"datasource-sqlite-options.js","sourceRoot":"","sources":["../../../src/transforms/v1/datasource-sqlite-options.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAE5B,gDAAuE;AAE1D,QAAA,IAAI,GAAG,mBAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,mBAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAA;AAC1D,QAAA,WAAW,GACpB,uEAAuE,CAAA;AAE3E,2EAA2E;AAC3E,0EAA0E;AAC1E,6EAA6E;AAC7E,2EAA2E;AAC3E,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC;IAC9B,QAAQ;IACR,gBAAgB;IAChB,OAAO;IACP,WAAW;IACX,SAAS;IACT,cAAc;IACd,cAAc;IACd,MAAM;CACT,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,CAAC,GAAqB,EAAW,EAAE;IACvD,KAAK,MAAM,IAAI,IAAI,GAAG,CAAC,UAAU,EAAE,CAAC;QAChC,IAAI,IAAI,CAAC,IAAI,KAAK,UAAU,IAAI,IAAI,CAAC,IAAI,KAAK,gBAAgB,EAAE,CAAC;YAC7D,SAAQ;QACZ,CAAC;QACD,MAAM,OAAO,GACT,IAAI,CAAC,GAAG,CAAC,IAAI,KAAK,YAAY;YAC1B,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI;YACf,CAAC,CAAC,IAAA,4BAAc,EAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAClC,IAAI,OAAO,KAAK,MAAM;YAAE,SAAQ;QAChC,MAAM,KAAK,GAAG,IAAA,4BAAc,EAAC,IAAI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,GAAG,IAAI,CAAA;QACrB,CAAC;IACL,CAAC,CAAC,CAAA;IAEF,OAAO,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,SAAS,CAAA;AACnD,CAAC,CAAA;AA9BY,QAAA,uBAAuB,2BA8BnC;AAEY,QAAA,EAAE,GAAG,+BAAuB,CAAA;AACzC,kBAAe,UAAE,CAAA"}
|
|
@@ -12,13 +12,34 @@ const datasourceSqliteType = (file, api) => {
|
|
|
12
12
|
const j = api.jscodeshift;
|
|
13
13
|
const root = j(file.source);
|
|
14
14
|
let hasChanges = false;
|
|
15
|
-
//
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
// Scope the rename to ObjectExpressions that look like TypeORM sqlite
|
|
16
|
+
// DataSource options — namely, they carry both `type: "sqlite"` and a
|
|
17
|
+
// sibling `database` property. This keeps the transform from mutating
|
|
18
|
+
// unrelated `{ type: "sqlite" }` objects in non-TypeORM configs and still
|
|
19
|
+
// works on ormconfig-style plain exports that do not import from typeorm.
|
|
20
|
+
// Accept both `Property` (Esprima) and `ObjectProperty` (Babel), as well
|
|
21
|
+
// as both identifier (`type:`) and string-literal (`"type":`) keys.
|
|
22
|
+
root.find(j.ObjectExpression).forEach((objPath) => {
|
|
23
|
+
let typeProp = null;
|
|
24
|
+
let hasDatabase = false;
|
|
25
|
+
for (const prop of objPath.node.properties) {
|
|
26
|
+
if (prop.type !== "Property" && prop.type !== "ObjectProperty") {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
const keyName = prop.key.type === "Identifier"
|
|
30
|
+
? prop.key.name
|
|
31
|
+
: (0, ast_helpers_1.getStringValue)(prop.key);
|
|
32
|
+
if (keyName === "type" && (0, ast_helpers_1.getStringValue)(prop.value) === "sqlite") {
|
|
33
|
+
typeProp = prop;
|
|
34
|
+
}
|
|
35
|
+
else if (keyName === "database") {
|
|
36
|
+
hasDatabase = true;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (typeProp && hasDatabase) {
|
|
40
|
+
(0, ast_helpers_1.setStringValue)(typeProp.value, "better-sqlite3");
|
|
41
|
+
hasChanges = true;
|
|
42
|
+
}
|
|
22
43
|
});
|
|
23
44
|
return hasChanges ? root.toSource() : undefined;
|
|
24
45
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datasource-sqlite-type.js","sourceRoot":"","sources":["../../../src/transforms/v1/datasource-sqlite-type.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAE5B,gDAA+
|
|
1
|
+
{"version":3,"file":"datasource-sqlite-type.js","sourceRoot":"","sources":["../../../src/transforms/v1/datasource-sqlite-type.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAE5B,gDAA+D;AAElD,QAAA,IAAI,GAAG,mBAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,mBAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAA;AAC1D,QAAA,WAAW,GAAG,+CAA+C,CAAA;AAEnE,MAAM,oBAAoB,GAAG,CAAC,IAAc,EAAE,GAAQ,EAAE,EAAE;IAC7D,MAAM,CAAC,GAAG,GAAG,CAAC,WAAW,CAAA;IACzB,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAE3B,IAAI,UAAU,GAAG,KAAK,CAAA;IAEtB,sEAAsE;IACtE,sEAAsE;IACtE,sEAAsE;IACtE,0EAA0E;IAC1E,0EAA0E;IAC1E,yEAAyE;IACzE,oEAAoE;IACpE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC9C,IAAI,QAAQ,GAAqC,IAAI,CAAA;QACrD,IAAI,WAAW,GAAG,KAAK,CAAA;QAEvB,KAAK,MAAM,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACzC,IAAI,IAAI,CAAC,IAAI,KAAK,UAAU,IAAI,IAAI,CAAC,IAAI,KAAK,gBAAgB,EAAE,CAAC;gBAC7D,SAAQ;YACZ,CAAC;YAED,MAAM,OAAO,GACT,IAAI,CAAC,GAAG,CAAC,IAAI,KAAK,YAAY;gBAC1B,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI;gBACf,CAAC,CAAC,IAAA,4BAAc,EAAC,IAAI,CAAC,GAAG,CAAC,CAAA;YAElC,IAAI,OAAO,KAAK,MAAM,IAAI,IAAA,4BAAc,EAAC,IAAI,CAAC,KAAK,CAAC,KAAK,QAAQ,EAAE,CAAC;gBAChE,QAAQ,GAAG,IAAI,CAAA;YACnB,CAAC;iBAAM,IAAI,OAAO,KAAK,UAAU,EAAE,CAAC;gBAChC,WAAW,GAAG,IAAI,CAAA;YACtB,CAAC;QACL,CAAC;QAED,IAAI,QAAQ,IAAI,WAAW,EAAE,CAAC;YAC1B,IAAA,4BAAc,EAAC,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAA;YAChD,UAAU,GAAG,IAAI,CAAA;QACrB,CAAC;IACL,CAAC,CAAC,CAAA;IAEF,OAAO,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,SAAS,CAAA;AACnD,CAAC,CAAA;AAzCY,QAAA,oBAAoB,wBAyChC;AAEY,QAAA,EAAE,GAAG,4BAAoB,CAAA;AACtC,kBAAe,UAAE,CAAA"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.fn = exports.fileLogger = exports.manual = exports.description = exports.name = void 0;
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const todo_1 = require("../todo");
|
|
9
|
+
const stats_1 = require("../stats");
|
|
10
|
+
const ast_helpers_1 = require("../ast-helpers");
|
|
11
|
+
exports.name = node_path_1.default.basename(__filename, node_path_1.default.extname(__filename));
|
|
12
|
+
exports.description = "flag `new FileLogger()` usages with non-absolute `logPath` — path is now resolved from `process.cwd()` instead of app root";
|
|
13
|
+
exports.manual = true;
|
|
14
|
+
const isAbsolutePath = (literal) => node_path_1.default.posix.isAbsolute(literal) || node_path_1.default.win32.isAbsolute(literal);
|
|
15
|
+
// Treats `undefined`, `null`, and their literal variants as "no value".
|
|
16
|
+
const isNullishLiteral = (node) => {
|
|
17
|
+
if (node === undefined)
|
|
18
|
+
return true;
|
|
19
|
+
const n = node;
|
|
20
|
+
if (n.type === "Identifier" && n.name === "undefined")
|
|
21
|
+
return true;
|
|
22
|
+
if (n.type === "NullLiteral")
|
|
23
|
+
return true;
|
|
24
|
+
return n.type === "Literal" && n.value === null;
|
|
25
|
+
};
|
|
26
|
+
// Locates the `logPath` property in an options object expression, alongside
|
|
27
|
+
// whether the object also contains a spread (which could contribute the key).
|
|
28
|
+
const findLogPathProperty = (obj) => {
|
|
29
|
+
let hasSpread = false;
|
|
30
|
+
for (const prop of obj.properties) {
|
|
31
|
+
if (prop.type === "SpreadElement") {
|
|
32
|
+
hasSpread = true;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (prop.type !== "ObjectProperty")
|
|
36
|
+
continue;
|
|
37
|
+
const keyName = prop.key.type === "Identifier"
|
|
38
|
+
? prop.key.name
|
|
39
|
+
: (0, ast_helpers_1.getStringValue)(prop.key);
|
|
40
|
+
if (keyName === "logPath")
|
|
41
|
+
return { value: prop.value, hasSpread };
|
|
42
|
+
}
|
|
43
|
+
return { value: undefined, hasSpread };
|
|
44
|
+
};
|
|
45
|
+
const inspectOptionsArg = (argNode) => {
|
|
46
|
+
// Missing / explicit nullish → same as omitting options, flag.
|
|
47
|
+
if (isNullishLiteral(argNode)) {
|
|
48
|
+
return { hasOption: false, isAbsolute: false };
|
|
49
|
+
}
|
|
50
|
+
const unwrapped = (0, ast_helpers_1.unwrapTsExpression)(argNode);
|
|
51
|
+
// Dynamic options (variable, function call, etc.) — trust the user.
|
|
52
|
+
if (unwrapped.type !== "ObjectExpression") {
|
|
53
|
+
return { hasOption: true, isAbsolute: true };
|
|
54
|
+
}
|
|
55
|
+
const { value, hasSpread } = findLogPathProperty(unwrapped);
|
|
56
|
+
// No explicit logPath — a spread could contribute one, so leave alone.
|
|
57
|
+
if (value === undefined) {
|
|
58
|
+
return hasSpread
|
|
59
|
+
? { hasOption: true, isAbsolute: true }
|
|
60
|
+
: { hasOption: false, isAbsolute: false };
|
|
61
|
+
}
|
|
62
|
+
// `logPath: undefined` / `logPath: null` behaves as if omitted.
|
|
63
|
+
if (isNullishLiteral(value)) {
|
|
64
|
+
return { hasOption: false, isAbsolute: false };
|
|
65
|
+
}
|
|
66
|
+
const str = (0, ast_helpers_1.getStringValue)(value);
|
|
67
|
+
if (str !== null) {
|
|
68
|
+
return { hasOption: true, isAbsolute: isAbsolutePath(str) };
|
|
69
|
+
}
|
|
70
|
+
// Non-literal (template, path.resolve(), etc.) — trust the user.
|
|
71
|
+
return { hasOption: true, isAbsolute: true };
|
|
72
|
+
};
|
|
73
|
+
const fileLogger = (file, api) => {
|
|
74
|
+
const j = api.jscodeshift;
|
|
75
|
+
const root = j(file.source);
|
|
76
|
+
let hasChanges = false;
|
|
77
|
+
let hasTodos = false;
|
|
78
|
+
// Delegate the ESM + CJS-destructure scanning for `FileLogger` to the
|
|
79
|
+
// shared helper — it handles both `StringLiteral` and `Literal` string
|
|
80
|
+
// forms consistently (older Babel parses string arguments as `Literal`).
|
|
81
|
+
const localNames = (0, ast_helpers_1.getLocalNamesForImport)(root, j, "typeorm", "FileLogger");
|
|
82
|
+
// Namespace bindings (`import * as typeorm from "typeorm"` or
|
|
83
|
+
// `const typeorm = require("typeorm")`) aren't covered by the shared
|
|
84
|
+
// helper, so collect them here.
|
|
85
|
+
const namespaceNames = new Set();
|
|
86
|
+
root.find(j.ImportDeclaration, {
|
|
87
|
+
source: { value: "typeorm" },
|
|
88
|
+
}).forEach((p) => {
|
|
89
|
+
for (const s of p.node.specifiers ?? []) {
|
|
90
|
+
if (s.type === "ImportNamespaceSpecifier" &&
|
|
91
|
+
s.local?.type === "Identifier") {
|
|
92
|
+
namespaceNames.add(s.local.name);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
root.find(j.VariableDeclarator, {
|
|
97
|
+
init: {
|
|
98
|
+
type: "CallExpression",
|
|
99
|
+
callee: { type: "Identifier", name: "require" },
|
|
100
|
+
},
|
|
101
|
+
}).forEach((p) => {
|
|
102
|
+
const init = p.node.init;
|
|
103
|
+
if (init?.type !== "CallExpression")
|
|
104
|
+
return;
|
|
105
|
+
const [arg] = init.arguments;
|
|
106
|
+
if (!arg || (0, ast_helpers_1.getStringValue)(arg) !== "typeorm")
|
|
107
|
+
return;
|
|
108
|
+
if (p.node.id.type === "Identifier") {
|
|
109
|
+
namespaceNames.add(p.node.id.name);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
if (localNames.size === 0 && namespaceNames.size === 0)
|
|
113
|
+
return undefined;
|
|
114
|
+
const message = "`FileLogger` now resolves `logPath` from `process.cwd()` instead of the app root — use an absolute path if the app is not started from its root folder";
|
|
115
|
+
root.find(j.NewExpression)
|
|
116
|
+
.filter((p) => {
|
|
117
|
+
const callee = p.node.callee;
|
|
118
|
+
if (callee.type === "Identifier" &&
|
|
119
|
+
localNames.has(callee.name)) {
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
if (callee.type === "MemberExpression" &&
|
|
123
|
+
callee.object.type === "Identifier" &&
|
|
124
|
+
namespaceNames.has(callee.object.name) &&
|
|
125
|
+
callee.property.type === "Identifier" &&
|
|
126
|
+
callee.property.name === "FileLogger") {
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
return false;
|
|
130
|
+
})
|
|
131
|
+
.forEach((astPath) => {
|
|
132
|
+
const optionsArg = astPath.node.arguments[1];
|
|
133
|
+
const { hasOption, isAbsolute } = inspectOptionsArg(optionsArg);
|
|
134
|
+
if (hasOption && isAbsolute)
|
|
135
|
+
return;
|
|
136
|
+
let current = astPath.parent;
|
|
137
|
+
while (current) {
|
|
138
|
+
const node = current.node;
|
|
139
|
+
if (node.type === "ExpressionStatement" ||
|
|
140
|
+
node.type === "VariableDeclaration" ||
|
|
141
|
+
node.type === "ReturnStatement" ||
|
|
142
|
+
node.type === "ExportDefaultDeclaration" ||
|
|
143
|
+
node.type === "ExportNamedDeclaration" ||
|
|
144
|
+
node.type === "ClassProperty" ||
|
|
145
|
+
node.type === "PropertyDefinition") {
|
|
146
|
+
if (!(0, todo_1.hasTodoComment)(node, message)) {
|
|
147
|
+
(0, todo_1.addTodoComment)(node, message, j);
|
|
148
|
+
hasChanges = true;
|
|
149
|
+
hasTodos = true;
|
|
150
|
+
}
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
current = current.parent;
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
if (hasTodos)
|
|
157
|
+
stats_1.stats.count.todo(api, exports.name, file);
|
|
158
|
+
return hasChanges ? root.toSource() : undefined;
|
|
159
|
+
};
|
|
160
|
+
exports.fileLogger = fileLogger;
|
|
161
|
+
exports.fn = exports.fileLogger;
|
|
162
|
+
exports.default = exports.fn;
|
|
163
|
+
//# sourceMappingURL=file-logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-logger.js","sourceRoot":"","sources":["../../../src/transforms/v1/file-logger.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAE5B,kCAAwD;AACxD,oCAAgC;AAChC,gDAIuB;AAEV,QAAA,IAAI,GAAG,mBAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,mBAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAA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I,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,SAAS,CAAA;AACnD,CAAC,CAAA;AAxGY,QAAA,UAAU,cAwGtB;AAEY,QAAA,EAAE,GAAG,kBAAU,CAAA;AAC5B,kBAAe,UAAE,CAAA"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.fn = exports.findOptionsJoin = exports.manual = exports.description = exports.name = void 0;
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const ast_helpers_1 = require("../ast-helpers");
|
|
9
|
+
const todo_1 = require("../todo");
|
|
10
|
+
const stats_1 = require("../stats");
|
|
11
|
+
exports.name = node_path_1.default.basename(__filename, node_path_1.default.extname(__filename));
|
|
12
|
+
exports.description = "flag removed `join` find option for manual migration to `relations` or QueryBuilder";
|
|
13
|
+
exports.manual = true;
|
|
14
|
+
const MIGRATION_HINT = "migrate `leftJoinAndSelect` to the `relations` option, or switch to QueryBuilder for `innerJoin`/`innerJoinAndSelect`/`leftJoin`";
|
|
15
|
+
const MESSAGE = `\`join\` find option was removed — ${MIGRATION_HINT}`;
|
|
16
|
+
// Node types on which a leading line-comment survives jscodeshift/recast
|
|
17
|
+
// printing — walking up to one of these keeps the comment visible above
|
|
18
|
+
// the enclosing statement or declaration.
|
|
19
|
+
const isTodoHost = (type) => type.endsWith("Statement") ||
|
|
20
|
+
type === "VariableDeclaration" ||
|
|
21
|
+
type === "ExportDefaultDeclaration" ||
|
|
22
|
+
type === "ExportNamedDeclaration" ||
|
|
23
|
+
type === "ClassProperty" ||
|
|
24
|
+
type === "PropertyDefinition";
|
|
25
|
+
// A find-options `join` property has a value like
|
|
26
|
+
// `{ alias: "...", leftJoinAndSelect: { ... }, ... }`. We look for the
|
|
27
|
+
// `alias` sub-property to distinguish it from unrelated `join` keys.
|
|
28
|
+
// Accept both `ObjectProperty` (Babel) and `Property` (Esprima) node shapes
|
|
29
|
+
// and both identifier (`join:`) and string-literal (`"join":`) keys.
|
|
30
|
+
const isFindOptionsJoinProperty = (prop) => {
|
|
31
|
+
if (prop.type !== "Property" && prop.type !== "ObjectProperty") {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
const keyName = prop.key.type === "Identifier"
|
|
35
|
+
? prop.key.name
|
|
36
|
+
: (0, ast_helpers_1.getStringValue)(prop.key);
|
|
37
|
+
if (keyName !== "join")
|
|
38
|
+
return false;
|
|
39
|
+
if (prop.value.type !== "ObjectExpression")
|
|
40
|
+
return false;
|
|
41
|
+
return prop.value.properties.some((inner) => {
|
|
42
|
+
if (inner.type !== "Property" && inner.type !== "ObjectProperty") {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
const innerKey = inner.key.type === "Identifier"
|
|
46
|
+
? inner.key.name
|
|
47
|
+
: (0, ast_helpers_1.getStringValue)(inner.key);
|
|
48
|
+
return innerKey === "alias";
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
const findOptionsJoin = (file, api) => {
|
|
52
|
+
const j = api.jscodeshift;
|
|
53
|
+
const root = j(file.source);
|
|
54
|
+
if (!(0, ast_helpers_1.fileImportsFrom)(root, j, "typeorm"))
|
|
55
|
+
return undefined;
|
|
56
|
+
let hasChanges = false;
|
|
57
|
+
let hasTodos = false;
|
|
58
|
+
root.find(j.ObjectExpression).forEach((objPath) => {
|
|
59
|
+
const obj = objPath.node;
|
|
60
|
+
const hasJoin = obj.properties.some(isFindOptionsJoinProperty);
|
|
61
|
+
if (!hasJoin)
|
|
62
|
+
return;
|
|
63
|
+
let current = objPath.parent;
|
|
64
|
+
while (current) {
|
|
65
|
+
const node = current.node;
|
|
66
|
+
if (isTodoHost(node.type)) {
|
|
67
|
+
if (!(0, todo_1.hasTodoComment)(node, MESSAGE)) {
|
|
68
|
+
(0, todo_1.addTodoComment)(node, MESSAGE, j);
|
|
69
|
+
hasChanges = true;
|
|
70
|
+
hasTodos = true;
|
|
71
|
+
}
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
current = current.parent;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
if (hasTodos)
|
|
78
|
+
stats_1.stats.count.todo(api, exports.name, file);
|
|
79
|
+
return hasChanges ? root.toSource() : undefined;
|
|
80
|
+
};
|
|
81
|
+
exports.findOptionsJoin = findOptionsJoin;
|
|
82
|
+
exports.fn = exports.findOptionsJoin;
|
|
83
|
+
exports.default = exports.fn;
|
|
84
|
+
//# sourceMappingURL=find-options-join.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find-options-join.js","sourceRoot":"","sources":["../../../src/transforms/v1/find-options-join.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAE5B,gDAAgE;AAChE,kCAAwD;AACxD,oCAAgC;AAEnB,QAAA,IAAI,GAAG,mBAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,mBAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAA;AAC1D,QAAA,WAAW,GACpB,qFAAqF,CAAA;AAC5E,QAAA,MAAM,GAAG,IAAI,CAAA;AAE1B,MAAM,cAAc,GAChB,kIAAkI,CAAA;AAEtI,MAAM,OAAO,GAAG,sCAAsC,cAAc,EAAE,CAAA;AAEtE,yEAAyE;AACzE,wEAAwE;AACxE,0CAA0C;AAC1C,MAAM,UAAU,GAAG,CAAC,IAAY,EAAW,EAAE,CACzC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC;IAC1B,IAAI,KAAK,qBAAqB;IAC9B,IAAI,KAAK,0BAA0B;IACnC,IAAI,KAAK,wBAAwB;IACjC,IAAI,KAAK,eAAe;IACxB,IAAI,KAAK,oBAAoB,CAAA;AAEjC,kDAAkD;AAClD,uEAAuE;AACvE,qEAAqE;AACrE,4EAA4E;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