@openrewrite/recipes-nodejs 0.35.0-20251205-084301 → 0.35.0-20251205-093309
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/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/migrate/fs-stats-constructor.d.ts +9 -0
- package/dist/migrate/fs-stats-constructor.d.ts.map +1 -0
- package/dist/migrate/fs-stats-constructor.js +132 -0
- package/dist/migrate/fs-stats-constructor.js.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/migrate/fs-stats-constructor.ts +123 -0
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,sBAAsB,CAAC;AAsBpD,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,cAAc,QAoBhD"}
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,7 @@ const process_features_tls_1 = require("./migrate/process-features-tls");
|
|
|
7
7
|
const crypto_constructors_1 = require("./migrate/crypto-constructors");
|
|
8
8
|
const util_log_1 = require("./migrate/util-log");
|
|
9
9
|
const util_extend_1 = require("./migrate/util-extend");
|
|
10
|
+
const fs_stats_constructor_1 = require("./migrate/fs-stats-constructor");
|
|
10
11
|
const crypto_fips_1 = require("./migrate/crypto-fips");
|
|
11
12
|
const slow_buffer_1 = require("./migrate/slow-buffer");
|
|
12
13
|
const fs_access_constants_1 = require("./migrate/fs-access-constants");
|
|
@@ -26,6 +27,7 @@ function activate(registry) {
|
|
|
26
27
|
registry.register(crypto_constructors_1.ReplaceCryptoConstructors);
|
|
27
28
|
registry.register(util_log_1.ReplaceUtilLog);
|
|
28
29
|
registry.register(util_extend_1.ReplaceUtilExtend);
|
|
30
|
+
registry.register(fs_stats_constructor_1.ReplaceFsStatsConstructor);
|
|
29
31
|
registry.register(crypto_fips_1.ReplaceCryptoFips);
|
|
30
32
|
registry.register(slow_buffer_1.ReplaceSlowBuffer);
|
|
31
33
|
registry.register(fs_access_constants_1.ReplaceFsAccessConstants);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAsBA,4BAoBC;AAzCD,qEAA0E;AAC1E,yDAAoE;AACpE,yEAAwF;AACxF,uEAAwE;AACxE,iDAAkD;AAClD,uDAAwD;AACxD,yEAAyE;AACzE,uDAAwD;AACxD,uDAAwD;AACxD,uEAAuE;AACvE,yEAAwE;AACxE,mEAA4E;AAC5E,uDAAwD;AACxD,+DAA6E;AAC7E,+DAA+D;AAC/D,uDAA8D;AAC9D,iFAAiF;AACjF,+DAAwD;AACxD,+DAAwD;AAGxD,SAAgB,QAAQ,CAAC,QAAwB;IAC7C,QAAQ,CAAC,QAAQ,CAAC,iDAA4B,CAAC,CAAC;IAChD,QAAQ,CAAC,QAAQ,CAAC,2CAA4B,CAAC,CAAC;IAChD,QAAQ,CAAC,QAAQ,CAAC,+DAAwC,CAAC,CAAC;IAC5D,QAAQ,CAAC,QAAQ,CAAC,+CAAyB,CAAC,CAAC;IAC7C,QAAQ,CAAC,QAAQ,CAAC,yBAAc,CAAC,CAAC;IAClC,QAAQ,CAAC,QAAQ,CAAC,+BAAiB,CAAC,CAAC;IACrC,QAAQ,CAAC,QAAQ,CAAC,gDAAyB,CAAC,CAAC;IAC7C,QAAQ,CAAC,QAAQ,CAAC,+BAAiB,CAAC,CAAC;IACrC,QAAQ,CAAC,QAAQ,CAAC,+BAAiB,CAAC,CAAC;IACrC,QAAQ,CAAC,QAAQ,CAAC,8CAAwB,CAAC,CAAC;IAC5C,QAAQ,CAAC,QAAQ,CAAC,+CAAwB,CAAC,CAAC;IAC5C,QAAQ,CAAC,QAAQ,CAAC,mDAA+B,CAAC,CAAC;IACnD,QAAQ,CAAC,QAAQ,CAAC,+BAAiB,CAAC,CAAC;IACrC,QAAQ,CAAC,QAAQ,CAAC,oDAAkC,CAAC,CAAC;IACtD,QAAQ,CAAC,QAAQ,CAAC,sCAAoB,CAAC,CAAC;IACxC,QAAQ,CAAC,QAAQ,CAAC,qCAAuB,CAAC,CAAC;IAC3C,QAAQ,CAAC,QAAQ,CAAC,wDAA6B,CAAC,CAAC;IACjD,QAAQ,CAAC,QAAQ,CAAC,+BAAa,CAAC,CAAC;IACjC,QAAQ,CAAC,QAAQ,CAAC,+BAAa,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ExecutionContext, Recipe, TreeVisitor } from "@openrewrite/rewrite";
|
|
2
|
+
export declare class ReplaceFsStatsConstructor extends Recipe {
|
|
3
|
+
readonly name = "org.openrewrite.node.migrate.fs.replace-stats-constructor";
|
|
4
|
+
readonly displayName: string;
|
|
5
|
+
readonly description: string;
|
|
6
|
+
readonly tags: string[];
|
|
7
|
+
editor(): Promise<TreeVisitor<any, ExecutionContext>>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=fs-stats-constructor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fs-stats-constructor.d.ts","sourceRoot":"","sources":["../../src/migrate/fs-stats-constructor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAE,MAAM,EAAE,WAAW,EAAC,MAAM,sBAAsB,CAAC;AAW3E,qBAAa,yBAA0B,SAAQ,MAAM;IACjD,QAAQ,CAAC,IAAI,+DAA8D;IAC3E,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAmE;IAC/F,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAwI;IACpK,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,CAAe;IAEhC,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;CAyG9D"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ReplaceFsStatsConstructor = void 0;
|
|
13
|
+
const rewrite_1 = require("@openrewrite/rewrite");
|
|
14
|
+
const javascript_1 = require("@openrewrite/rewrite/javascript");
|
|
15
|
+
const java_1 = require("@openrewrite/rewrite/java");
|
|
16
|
+
class ReplaceFsStatsConstructor extends rewrite_1.Recipe {
|
|
17
|
+
constructor() {
|
|
18
|
+
super(...arguments);
|
|
19
|
+
this.name = "org.openrewrite.node.migrate.fs.replace-stats-constructor";
|
|
20
|
+
this.displayName = "Replace deprecated `fs.Stats` constructor with object literal";
|
|
21
|
+
this.description = "Replace deprecated `new fs.Stats()` constructor calls with an object literal containing Stats properties initialized to undefined.";
|
|
22
|
+
this.tags = ["DEP0180"];
|
|
23
|
+
}
|
|
24
|
+
editor() {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
return new class extends javascript_1.JavaScriptVisitor {
|
|
27
|
+
constructor() {
|
|
28
|
+
super(...arguments);
|
|
29
|
+
this.isItTypescript = false;
|
|
30
|
+
}
|
|
31
|
+
visitJsCompilationUnit(compilationUnit, p) {
|
|
32
|
+
const ret = super.visitJsCompilationUnit(compilationUnit, p);
|
|
33
|
+
if (compilationUnit.sourcePath.endsWith(".ts") || compilationUnit.sourcePath.endsWith(".tsx")) {
|
|
34
|
+
this.isItTypescript = true;
|
|
35
|
+
}
|
|
36
|
+
return ret;
|
|
37
|
+
}
|
|
38
|
+
visitNewClass(newClass, p) {
|
|
39
|
+
const _super = Object.create(null, {
|
|
40
|
+
visitNewClass: { get: () => super.visitNewClass }
|
|
41
|
+
});
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
var _a;
|
|
44
|
+
const clazz = newClass.class;
|
|
45
|
+
let shouldReplace = false;
|
|
46
|
+
if (clazz && clazz.kind === java_1.J.Kind.FieldAccess) {
|
|
47
|
+
if (((_a = clazz.type) === null || _a === void 0 ? void 0 : _a.kind) == java_1.Type.Kind.Class) {
|
|
48
|
+
const fullyQualifiedName = clazz.type.fullyQualifiedName;
|
|
49
|
+
if (fullyQualifiedName == "fs.Stats") {
|
|
50
|
+
shouldReplace = true;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (clazz && clazz.kind === java_1.J.Kind.Identifier) {
|
|
55
|
+
const constructorType = newClass.constructorType;
|
|
56
|
+
if ((constructorType === null || constructorType === void 0 ? void 0 : constructorType.declaringType.kind) == java_1.Type.Kind.Class
|
|
57
|
+
&& constructorType.declaringType.fullyQualifiedName == "fs") {
|
|
58
|
+
if (constructorType.name == "Stats") {
|
|
59
|
+
shouldReplace = true;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (shouldReplace) {
|
|
64
|
+
if (this.isItTypescript) {
|
|
65
|
+
return yield (0, javascript_1.template) `({
|
|
66
|
+
dev: 0,
|
|
67
|
+
mode: 0,
|
|
68
|
+
nlink: 0,
|
|
69
|
+
uid: 0,
|
|
70
|
+
gid: 0,
|
|
71
|
+
rdev: 0,
|
|
72
|
+
blksize: 0,
|
|
73
|
+
ino: 0,
|
|
74
|
+
size: 0,
|
|
75
|
+
blocks: 0,
|
|
76
|
+
atimeMs: 0,
|
|
77
|
+
mtimeMs: 0,
|
|
78
|
+
ctimeMs: 0,
|
|
79
|
+
birthtimeMs: 0,
|
|
80
|
+
atime: new Date(0),
|
|
81
|
+
mtime: new Date(0),
|
|
82
|
+
ctime: new Date(0),
|
|
83
|
+
birthtime: new Date(0),
|
|
84
|
+
isFile: () => false,
|
|
85
|
+
isDirectory: () => false,
|
|
86
|
+
isBlockDevice: () => false,
|
|
87
|
+
isCharacterDevice: () => false,
|
|
88
|
+
isSymbolicLink: () => false,
|
|
89
|
+
isFIFO: () => false,
|
|
90
|
+
isSocket: () => false
|
|
91
|
+
} satisfies fs.Stats)`.apply(newClass, this.cursor);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
(0, javascript_1.maybeRemoveImport)(this, "fs", "Stats");
|
|
95
|
+
return yield (0, javascript_1.template) `({
|
|
96
|
+
dev: 0,
|
|
97
|
+
mode: 0,
|
|
98
|
+
nlink: 0,
|
|
99
|
+
uid: 0,
|
|
100
|
+
gid: 0,
|
|
101
|
+
rdev: 0,
|
|
102
|
+
blksize: 0,
|
|
103
|
+
ino: 0,
|
|
104
|
+
size: 0,
|
|
105
|
+
blocks: 0,
|
|
106
|
+
atimeMs: 0,
|
|
107
|
+
mtimeMs: 0,
|
|
108
|
+
ctimeMs: 0,
|
|
109
|
+
birthtimeMs: 0,
|
|
110
|
+
atime: new Date(0),
|
|
111
|
+
mtime: new Date(0),
|
|
112
|
+
ctime: new Date(0),
|
|
113
|
+
birthtime: new Date(0),
|
|
114
|
+
isFile: () => false,
|
|
115
|
+
isDirectory: () => false,
|
|
116
|
+
isBlockDevice: () => false,
|
|
117
|
+
isCharacterDevice: () => false,
|
|
118
|
+
isSymbolicLink: () => false,
|
|
119
|
+
isFIFO: () => false,
|
|
120
|
+
isSocket: () => false
|
|
121
|
+
})`.apply(newClass, this.cursor);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return _super.visitNewClass.call(this, newClass, p);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
exports.ReplaceFsStatsConstructor = ReplaceFsStatsConstructor;
|
|
132
|
+
//# sourceMappingURL=fs-stats-constructor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fs-stats-constructor.js","sourceRoot":"","sources":["../../src/migrate/fs-stats-constructor.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAA2E;AAC3E,gEAIyC;AACzC,oDAAkD;AAKlD,MAAa,yBAA0B,SAAQ,gBAAM;IAArD;;QACa,SAAI,GAAG,2DAA2D,CAAA;QAClE,gBAAW,GAAW,+DAA+D,CAAC;QACtF,gBAAW,GAAW,oIAAoI,CAAC;QAC3J,SAAI,GAAa,CAAC,SAAS,CAAC,CAAC;IA2G1C,CAAC;IAzGS,MAAM;;YACR,OAAO,IAAI,KAAM,SAAQ,8BAAmC;gBAAjD;;oBAEC,mBAAc,GAAG,KAAK,CAAC;gBAoGnC,CAAC;gBAlGa,sBAAsB,CAAC,eAAmC,EAAE,CAAmB;oBACrF,MAAM,GAAG,GAAG,KAAK,CAAC,sBAAsB,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC;oBAC7D,IAAI,eAAe,CAAC,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,eAAe,CAAC,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;wBAC5F,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;oBAC/B,CAAC;oBACD,OAAO,GAAG,CAAC;gBACf,CAAC;gBAEe,aAAa,CAAC,QAAoB,EAAE,CAAmB;;;;;;wBACnE,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;wBAC7B,IAAI,aAAa,GAAG,KAAK,CAAC;wBAG1B,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,QAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;4BAC7C,IAAI,CAAA,MAAC,KAAuB,CAAC,IAAI,0CAAE,IAAI,KAAI,WAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;gCACzD,MAAM,kBAAkB,GAAK,KAAuB,CAAC,IAAmB,CAAC,kBAAkB,CAAC;gCAE5F,IAAI,kBAAkB,IAAI,UAAU,EAAE,CAAC;oCACnC,aAAa,GAAG,IAAI,CAAC;gCACzB,CAAC;4BACL,CAAC;wBACL,CAAC;wBAGD,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,QAAC,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;4BAC5C,MAAM,eAAe,GAAG,QAAQ,CAAC,eAAe,CAAC;4BACjD,IAAI,CAAA,eAAe,aAAf,eAAe,uBAAf,eAAe,CAAE,aAAa,CAAC,IAAI,KAAI,WAAI,CAAC,IAAI,CAAC,KAAK;mCAClD,eAAe,CAAC,aAA4B,CAAC,kBAAkB,IAAI,IAAI,EAAE,CAAC;gCAE9E,IAAI,eAAe,CAAC,IAAI,IAAI,OAAO,EAAE,CAAC;oCAClC,aAAa,GAAG,IAAI,CAAC;gCACzB,CAAC;4BACL,CAAC;wBACL,CAAC;wBAED,IAAI,aAAa,EAAE,CAAC;4BAChB,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;gCACtB,OAAO,MAAM,IAAA,qBAAQ,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;8CA0BC,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;4BACxD,CAAC;iCAAM,CAAC;gCACJ,IAAA,8BAAiB,EAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;gCACvC,OAAO,MAAM,IAAA,qBAAQ,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;2BA0BlB,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;4BACrC,CAAC;wBACL,CAAC;wBAED,OAAO,OAAM,aAAa,YAAC,QAAQ,EAAE,CAAC,EAAE;oBAC5C,CAAC;iBAAA;aACJ,CAAC;QACN,CAAC;KAAA;CACJ;AA/GD,8DA+GC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openrewrite/recipes-nodejs",
|
|
3
|
-
"version": "0.35.0-20251205-
|
|
3
|
+
"version": "0.35.0-20251205-093309",
|
|
4
4
|
"license": "Moderne Source Available License",
|
|
5
5
|
"description": "OpenRewrite recipes for Node.js library migrations.",
|
|
6
6
|
"homepage": "https://github.com/moderneinc/rewrite-node",
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {RemoveUsageOfProcessFeaturesTlsConstants} from "./migrate/process-featur
|
|
|
5
5
|
import {ReplaceCryptoConstructors} from "./migrate/crypto-constructors";
|
|
6
6
|
import {ReplaceUtilLog} from "./migrate/util-log";
|
|
7
7
|
import {ReplaceUtilExtend} from "./migrate/util-extend";
|
|
8
|
+
import {ReplaceFsStatsConstructor} from "./migrate/fs-stats-constructor";
|
|
8
9
|
import {ReplaceCryptoFips} from "./migrate/crypto-fips";
|
|
9
10
|
import {ReplaceSlowBuffer} from "./migrate/slow-buffer";
|
|
10
11
|
import {ReplaceFsAccessConstants} from "./migrate/fs-access-constants";
|
|
@@ -26,6 +27,7 @@ export function activate(registry: RecipeRegistry) {
|
|
|
26
27
|
registry.register(ReplaceCryptoConstructors);
|
|
27
28
|
registry.register(ReplaceUtilLog);
|
|
28
29
|
registry.register(ReplaceUtilExtend);
|
|
30
|
+
registry.register(ReplaceFsStatsConstructor);
|
|
29
31
|
registry.register(ReplaceCryptoFips);
|
|
30
32
|
registry.register(ReplaceSlowBuffer);
|
|
31
33
|
registry.register(ReplaceFsAccessConstants);
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import {ExecutionContext, Recipe, TreeVisitor} from "@openrewrite/rewrite";
|
|
2
|
+
import {
|
|
3
|
+
JavaScriptVisitor, JS, maybeAddImport,
|
|
4
|
+
maybeRemoveImport,
|
|
5
|
+
template
|
|
6
|
+
} from "@openrewrite/rewrite/javascript";
|
|
7
|
+
import {J, Type} from "@openrewrite/rewrite/java";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Replace deprecated fs.Stats constructor with object literal
|
|
11
|
+
*/
|
|
12
|
+
export class ReplaceFsStatsConstructor extends Recipe {
|
|
13
|
+
readonly name = "org.openrewrite.node.migrate.fs.replace-stats-constructor"
|
|
14
|
+
readonly displayName: string = "Replace deprecated `fs.Stats` constructor with object literal";
|
|
15
|
+
readonly description: string = "Replace deprecated `new fs.Stats()` constructor calls with an object literal containing Stats properties initialized to undefined.";
|
|
16
|
+
readonly tags: string[] = ["DEP0180"];
|
|
17
|
+
|
|
18
|
+
async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
19
|
+
return new class extends JavaScriptVisitor<ExecutionContext> {
|
|
20
|
+
|
|
21
|
+
private isItTypescript = false;
|
|
22
|
+
|
|
23
|
+
protected visitJsCompilationUnit(compilationUnit: JS.CompilationUnit, p: ExecutionContext): Promise<J | undefined> {
|
|
24
|
+
const ret = super.visitJsCompilationUnit(compilationUnit, p);
|
|
25
|
+
if (compilationUnit.sourcePath.endsWith(".ts") || compilationUnit.sourcePath.endsWith(".tsx")) {
|
|
26
|
+
this.isItTypescript = true;
|
|
27
|
+
}
|
|
28
|
+
return ret;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
protected async visitNewClass(newClass: J.NewClass, p: ExecutionContext): Promise<J | undefined> {
|
|
32
|
+
const clazz = newClass.class;
|
|
33
|
+
let shouldReplace = false;
|
|
34
|
+
|
|
35
|
+
// Case 1: new fs.Stats() or new identifier.Stats()
|
|
36
|
+
if (clazz && clazz.kind === J.Kind.FieldAccess) {
|
|
37
|
+
if ((clazz as J.FieldAccess).type?.kind == Type.Kind.Class) {
|
|
38
|
+
const fullyQualifiedName = ((clazz as J.FieldAccess).type as Type.Class).fullyQualifiedName;
|
|
39
|
+
|
|
40
|
+
if (fullyQualifiedName == "fs.Stats") {
|
|
41
|
+
shouldReplace = true;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Case 2: new Stats() - direct import
|
|
47
|
+
if (clazz && clazz.kind === J.Kind.Identifier) {
|
|
48
|
+
const constructorType = newClass.constructorType;
|
|
49
|
+
if (constructorType?.declaringType.kind == Type.Kind.Class
|
|
50
|
+
&& (constructorType.declaringType as Type.Class).fullyQualifiedName == "fs") {
|
|
51
|
+
|
|
52
|
+
if (constructorType.name == "Stats") {
|
|
53
|
+
shouldReplace = true;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (shouldReplace) {
|
|
59
|
+
if (this.isItTypescript) {
|
|
60
|
+
return await template`({
|
|
61
|
+
dev: 0,
|
|
62
|
+
mode: 0,
|
|
63
|
+
nlink: 0,
|
|
64
|
+
uid: 0,
|
|
65
|
+
gid: 0,
|
|
66
|
+
rdev: 0,
|
|
67
|
+
blksize: 0,
|
|
68
|
+
ino: 0,
|
|
69
|
+
size: 0,
|
|
70
|
+
blocks: 0,
|
|
71
|
+
atimeMs: 0,
|
|
72
|
+
mtimeMs: 0,
|
|
73
|
+
ctimeMs: 0,
|
|
74
|
+
birthtimeMs: 0,
|
|
75
|
+
atime: new Date(0),
|
|
76
|
+
mtime: new Date(0),
|
|
77
|
+
ctime: new Date(0),
|
|
78
|
+
birthtime: new Date(0),
|
|
79
|
+
isFile: () => false,
|
|
80
|
+
isDirectory: () => false,
|
|
81
|
+
isBlockDevice: () => false,
|
|
82
|
+
isCharacterDevice: () => false,
|
|
83
|
+
isSymbolicLink: () => false,
|
|
84
|
+
isFIFO: () => false,
|
|
85
|
+
isSocket: () => false
|
|
86
|
+
} satisfies fs.Stats)`.apply(newClass, this.cursor);
|
|
87
|
+
} else {
|
|
88
|
+
maybeRemoveImport(this, "fs", "Stats");
|
|
89
|
+
return await template`({
|
|
90
|
+
dev: 0,
|
|
91
|
+
mode: 0,
|
|
92
|
+
nlink: 0,
|
|
93
|
+
uid: 0,
|
|
94
|
+
gid: 0,
|
|
95
|
+
rdev: 0,
|
|
96
|
+
blksize: 0,
|
|
97
|
+
ino: 0,
|
|
98
|
+
size: 0,
|
|
99
|
+
blocks: 0,
|
|
100
|
+
atimeMs: 0,
|
|
101
|
+
mtimeMs: 0,
|
|
102
|
+
ctimeMs: 0,
|
|
103
|
+
birthtimeMs: 0,
|
|
104
|
+
atime: new Date(0),
|
|
105
|
+
mtime: new Date(0),
|
|
106
|
+
ctime: new Date(0),
|
|
107
|
+
birthtime: new Date(0),
|
|
108
|
+
isFile: () => false,
|
|
109
|
+
isDirectory: () => false,
|
|
110
|
+
isBlockDevice: () => false,
|
|
111
|
+
isCharacterDevice: () => false,
|
|
112
|
+
isSymbolicLink: () => false,
|
|
113
|
+
isFIFO: () => false,
|
|
114
|
+
isSocket: () => false
|
|
115
|
+
})`.apply(newClass, this.cursor);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return super.visitNewClass(newClass, p);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
}
|