@openrewrite/recipes-nodejs 0.51.0 → 0.51.1
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/angular-animations/remove-angular-animations-providers.js +7 -7
- package/dist/migrate/angular-animations/remove-angular-animations-providers.js.map +1 -1
- package/dist/migrate/express-request-id/migrate-express-request-id-to-native.d.ts.map +1 -1
- package/dist/migrate/express-request-id/migrate-express-request-id-to-native.js +3 -2
- package/dist/migrate/express-request-id/migrate-express-request-id-to-native.js.map +1 -1
- package/dist/migrate/express-request-id/remove-unused-express-request-id-dependency.d.ts +3 -6
- package/dist/migrate/express-request-id/remove-unused-express-request-id-dependency.d.ts.map +1 -1
- package/dist/migrate/express-request-id/remove-unused-express-request-id-dependency.js +5 -11
- package/dist/migrate/express-request-id/remove-unused-express-request-id-dependency.js.map +1 -1
- package/dist/migrate/find-process-assert.js +2 -2
- package/dist/migrate/find-process-assert.js.map +1 -1
- package/dist/migrate/fs-extra/migrate-fs-extra-to-node-fs.d.ts.map +1 -1
- package/dist/migrate/fs-extra/migrate-fs-extra-to-node-fs.js +4 -2
- package/dist/migrate/fs-extra/migrate-fs-extra-to-node-fs.js.map +1 -1
- package/dist/migrate/fs-extra/remove-unused-fs-extra-dependency.d.ts +4 -6
- package/dist/migrate/fs-extra/remove-unused-fs-extra-dependency.d.ts.map +1 -1
- package/dist/migrate/fs-extra/remove-unused-fs-extra-dependency.js +6 -14
- package/dist/migrate/fs-extra/remove-unused-fs-extra-dependency.js.map +1 -1
- package/dist/migrate/fs-extra/replace-fs-extra-native-methods.js +1 -1
- package/dist/migrate/fs-extra/replace-fs-extra-native-methods.js.map +1 -1
- package/dist/migrate/hpagent/migrate-hpagent-to-https-proxy-agent.d.ts.map +1 -1
- package/dist/migrate/hpagent/migrate-hpagent-to-https-proxy-agent.js +3 -7
- package/dist/migrate/hpagent/migrate-hpagent-to-https-proxy-agent.js.map +1 -1
- package/dist/migrate/hpagent/replace-hpagent.d.ts.map +1 -1
- package/dist/migrate/hpagent/replace-hpagent.js +68 -2
- package/dist/migrate/hpagent/replace-hpagent.js.map +1 -1
- package/dist/migrate/hpagent/swap-hpagent-dependency.d.ts +3 -15
- package/dist/migrate/hpagent/swap-hpagent-dependency.d.ts.map +1 -1
- package/dist/migrate/hpagent/swap-hpagent-dependency.js +11 -62
- package/dist/migrate/hpagent/swap-hpagent-dependency.js.map +1 -1
- package/dist/migrate/package-json-support.d.ts +6 -0
- package/dist/migrate/package-json-support.d.ts.map +1 -0
- package/dist/migrate/package-json-support.js +31 -0
- package/dist/migrate/package-json-support.js.map +1 -0
- package/dist/migrate/path/remove-path-dependency.js +8 -8
- package/dist/migrate/path/remove-path-dependency.js.map +1 -1
- package/dist/migrate/process-exit-code.js +3 -3
- package/dist/migrate/process-exit-code.js.map +1 -1
- package/dist/migrate/process-features-tls.js +1 -1
- package/dist/migrate/process-features-tls.js.map +1 -1
- package/dist/migrate/prop-types/remove-prop-types.js +8 -8
- package/dist/migrate/prop-types/remove-prop-types.js.map +1 -1
- package/dist/migrate/remove-dependencies.d.ts +6 -0
- package/dist/migrate/remove-dependencies.d.ts.map +1 -0
- package/dist/migrate/remove-dependencies.js +23 -0
- package/dist/migrate/remove-dependencies.js.map +1 -0
- package/dist/migrate/source-map-support/enable-source-maps-at-launch.d.ts +19 -0
- package/dist/migrate/source-map-support/enable-source-maps-at-launch.d.ts.map +1 -0
- package/dist/migrate/source-map-support/enable-source-maps-at-launch.js +311 -0
- package/dist/migrate/source-map-support/enable-source-maps-at-launch.js.map +1 -0
- package/dist/migrate/source-map-support/migrate-source-map-support-to-native.d.ts.map +1 -1
- package/dist/migrate/source-map-support/migrate-source-map-support-to-native.js +9 -4
- package/dist/migrate/source-map-support/migrate-source-map-support-to-native.js.map +1 -1
- package/dist/migrate/source-map-support/register-flag.d.ts +4 -0
- package/dist/migrate/source-map-support/register-flag.d.ts.map +1 -1
- package/dist/migrate/source-map-support/register-flag.js +35 -0
- package/dist/migrate/source-map-support/register-flag.js.map +1 -1
- package/dist/migrate/source-map-support/remove-unused-source-map-support-dependency.d.ts +3 -6
- package/dist/migrate/source-map-support/remove-unused-source-map-support-dependency.d.ts.map +1 -1
- package/dist/migrate/source-map-support/remove-unused-source-map-support-dependency.js +5 -12
- package/dist/migrate/source-map-support/remove-unused-source-map-support-dependency.js.map +1 -1
- package/dist/migrate/source-map-support/source-map-support-rewrites.d.ts.map +1 -1
- package/dist/migrate/source-map-support/source-map-support-rewrites.js +2 -0
- package/dist/migrate/source-map-support/source-map-support-rewrites.js.map +1 -1
- package/dist/migrate/upgrade-node-22.d.ts.map +1 -1
- package/dist/migrate/upgrade-node-22.js +2 -0
- package/dist/migrate/upgrade-node-22.js.map +1 -1
- package/dist/migrate/upgrade-node-24.d.ts.map +1 -1
- package/dist/migrate/upgrade-node-24.js +2 -0
- package/dist/migrate/upgrade-node-24.js.map +1 -1
- package/dist/resources/advisories-npm.csv +278 -20
- package/package.json +2 -2
- package/src/index.ts +2 -0
- package/src/migrate/angular-animations/remove-angular-animations-providers.ts +1 -1
- package/src/migrate/express-request-id/migrate-express-request-id-to-native.ts +3 -2
- package/src/migrate/express-request-id/remove-unused-express-request-id-dependency.ts +5 -13
- package/src/migrate/find-process-assert.ts +2 -2
- package/src/migrate/fs-extra/migrate-fs-extra-to-node-fs.ts +4 -2
- package/src/migrate/fs-extra/remove-unused-fs-extra-dependency.ts +6 -16
- package/src/migrate/fs-extra/replace-fs-extra-native-methods.ts +1 -1
- package/src/migrate/hpagent/migrate-hpagent-to-https-proxy-agent.ts +3 -7
- package/src/migrate/hpagent/replace-hpagent.ts +82 -3
- package/src/migrate/hpagent/swap-hpagent-dependency.ts +13 -68
- package/src/migrate/package-json-support.ts +34 -0
- package/src/migrate/path/remove-path-dependency.ts +1 -1
- package/src/migrate/process-exit-code.ts +3 -3
- package/src/migrate/process-features-tls.ts +1 -1
- package/src/migrate/prop-types/remove-prop-types.ts +1 -1
- package/src/migrate/remove-dependencies.ts +21 -0
- package/src/migrate/source-map-support/enable-source-maps-at-launch.ts +289 -0
- package/src/migrate/source-map-support/migrate-source-map-support-to-native.ts +9 -4
- package/src/migrate/source-map-support/register-flag.ts +48 -0
- package/src/migrate/source-map-support/remove-unused-source-map-support-dependency.ts +5 -14
- package/src/migrate/source-map-support/source-map-support-rewrites.ts +3 -0
- package/src/migrate/upgrade-node-22.ts +2 -0
- package/src/migrate/upgrade-node-24.ts +2 -0
- package/dist/migrate/remove-unused-dependency.d.ts +0 -43
- package/dist/migrate/remove-unused-dependency.d.ts.map +0 -1
- package/dist/migrate/remove-unused-dependency.js +0 -257
- package/dist/migrate/remove-unused-dependency.js.map +0 -1
- package/src/migrate/remove-unused-dependency.ts +0 -275
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.RemoveUnusedDependency = exports.KEPT_REASONS = exports.DependencyKept = void 0;
|
|
19
|
-
exports.dependenciesKept = dependenciesKept;
|
|
20
|
-
exports.dirOf = dirOf;
|
|
21
|
-
exports.isPackageJson = isPackageJson;
|
|
22
|
-
exports.anyBeneath = anyBeneath;
|
|
23
|
-
exports.removeMembers = removeMembers;
|
|
24
|
-
const rewrite_1 = require("@openrewrite/rewrite");
|
|
25
|
-
const json_1 = require("@openrewrite/rewrite/json");
|
|
26
|
-
const javascript_1 = require("@openrewrite/rewrite/javascript");
|
|
27
|
-
const text_1 = require("@openrewrite/rewrite/text");
|
|
28
|
-
const SECTIONS = new Set(['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies']);
|
|
29
|
-
const SOURCE_FILE = /\.[cm]?[jt]sx?$/;
|
|
30
|
-
const CONFIG_FILE = /(^|\/)(package\.json|mocha\.opts|\.mocharc(\.[a-z]+)?|[^/]+\.(json|ya?ml))$/;
|
|
31
|
-
const DOCUMENT = /(\.(md|markdown|mdx|txt|rst|adoc|svg|log|csv|map)|(^|\/)(LICENSE|LICENCE|CHANGELOG|CHANGES|HISTORY|README|AUTHORS|NOTICE)[^/]*|(^|\/)\.(cursor|windsurf|cline)rules)$/i;
|
|
32
|
-
const LOCK_FILE = /(^|\/)(package-lock\.json|npm-shrinkwrap\.json|yarn\.lock|pnpm-lock\.yaml|bun\.lockb?)$/;
|
|
33
|
-
const DECLARATIONS = ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies',
|
|
34
|
-
'peerDependenciesMeta', 'bundledDependencies', 'bundleDependencies', 'overrides', 'resolutions', 'pnpm'];
|
|
35
|
-
const PARSE_ERROR = "org.openrewrite.tree.ParseError";
|
|
36
|
-
const PROJEN_DEPS = /(^|\/)\.projen\/deps\.json$/;
|
|
37
|
-
class DependencyKept {
|
|
38
|
-
}
|
|
39
|
-
exports.DependencyKept = DependencyKept;
|
|
40
|
-
__decorate([
|
|
41
|
-
(0, rewrite_1.Column)({ displayName: "Source path", description: "Path of the `package.json` still declaring the package." })
|
|
42
|
-
], DependencyKept.prototype, "sourcePath", void 0);
|
|
43
|
-
__decorate([
|
|
44
|
-
(0, rewrite_1.Column)({ displayName: "Recipe", description: "Recipe that left the declaration in place." })
|
|
45
|
-
], DependencyKept.prototype, "recipe", void 0);
|
|
46
|
-
__decorate([
|
|
47
|
-
(0, rewrite_1.Column)({ displayName: "Package", description: "The package that was not removed, e.g. `fs-extra`." })
|
|
48
|
-
], DependencyKept.prototype, "package", void 0);
|
|
49
|
-
__decorate([
|
|
50
|
-
(0, rewrite_1.Column)({ displayName: "Reason", description: "Why the declaration couldn't be removed." })
|
|
51
|
-
], DependencyKept.prototype, "reason", void 0);
|
|
52
|
-
__decorate([
|
|
53
|
-
(0, rewrite_1.Column)({ displayName: "Evidence", description: "Files that kept it, up to the first few." })
|
|
54
|
-
], DependencyKept.prototype, "evidence", void 0);
|
|
55
|
-
function dependenciesKept() {
|
|
56
|
-
return new rewrite_1.DataTable("org.openrewrite.node.table.DependenciesKept", "Dependencies kept", "Packages the migration could not remove from a `package.json`, and what kept them.", DependencyKept);
|
|
57
|
-
}
|
|
58
|
-
exports.KEPT_REASONS = {
|
|
59
|
-
projen: (module) => `This package's dependencies are generated by projen: \`.projen/deps.json\` still ` +
|
|
60
|
-
`lists \`${module}\`, and nothing else beneath this \`package.json\` references it. Editing \`package.json\` ` +
|
|
61
|
-
"here would be undone by the next `npx projen`, so it is left alone. Remove the entry from `.projenrc.ts` " +
|
|
62
|
-
"(the arrays passed to the projen project, where it reads as `'" + module + "@<range>'`) and re-run projen.",
|
|
63
|
-
referenced: (module) => `\`${module}\` is still referenced beneath this \`package.json\` once the ` +
|
|
64
|
-
"migration has run — a usage it left in place, a test mock, or tool configuration naming the module. The " +
|
|
65
|
-
"library's own find recipe reports each site.",
|
|
66
|
-
unparsed: "No source beneath this `package.json` was parsed, so there is nothing to judge usage by. A JavaScript " +
|
|
67
|
-
"parse failure or an unbuilt LST leaves the declaration alone rather than guessing.",
|
|
68
|
-
};
|
|
69
|
-
function dirOf(path) {
|
|
70
|
-
const i = path.lastIndexOf('/');
|
|
71
|
-
return i < 0 ? '' : path.substring(0, i);
|
|
72
|
-
}
|
|
73
|
-
function isPackageJson(path) {
|
|
74
|
-
return (path === 'package.json' || path.endsWith('/package.json')) && !path.includes('node_modules/');
|
|
75
|
-
}
|
|
76
|
-
function anyBeneath(dir, files) {
|
|
77
|
-
return files.some(file => dir === '' || file.startsWith(dir + '/'));
|
|
78
|
-
}
|
|
79
|
-
function withoutDeclarations(packageJson) {
|
|
80
|
-
try {
|
|
81
|
-
const parsed = JSON.parse(packageJson);
|
|
82
|
-
for (const section of DECLARATIONS)
|
|
83
|
-
delete parsed[section];
|
|
84
|
-
return JSON.stringify(parsed);
|
|
85
|
-
}
|
|
86
|
-
catch (_a) {
|
|
87
|
-
return packageJson;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
function escapeRegExp(s) {
|
|
91
|
-
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
92
|
-
}
|
|
93
|
-
function removeMembers(obj, keys) {
|
|
94
|
-
const kept = obj.members.filter(rp => { var _a; return !((0, json_1.isMember)(rp.element) && keys.has((_a = (0, json_1.getMemberKeyName)(rp.element)) !== null && _a !== void 0 ? _a : '')); });
|
|
95
|
-
if (kept.length === obj.members.length)
|
|
96
|
-
return obj;
|
|
97
|
-
if (kept.length === 0) {
|
|
98
|
-
const empty = { kind: json_1.Json.Kind.Empty, id: (0, rewrite_1.randomId)(), prefix: (0, json_1.space)(''), markers: rewrite_1.emptyMarkers };
|
|
99
|
-
return Object.assign(Object.assign({}, obj), { members: [(0, json_1.rightPadded)(empty, (0, json_1.space)(''))] });
|
|
100
|
-
}
|
|
101
|
-
const closing = obj.members[obj.members.length - 1].after;
|
|
102
|
-
kept[kept.length - 1] = Object.assign(Object.assign({}, kept[kept.length - 1]), { after: closing });
|
|
103
|
-
return Object.assign(Object.assign({}, obj), { members: kept });
|
|
104
|
-
}
|
|
105
|
-
function declaredPackages(root, packages) {
|
|
106
|
-
var _a, _b;
|
|
107
|
-
const found = [];
|
|
108
|
-
for (const rp of root.members) {
|
|
109
|
-
if (!(0, json_1.isMember)(rp.element))
|
|
110
|
-
continue;
|
|
111
|
-
const member = rp.element;
|
|
112
|
-
if (!SECTIONS.has((_a = (0, json_1.getMemberKeyName)(member)) !== null && _a !== void 0 ? _a : '') || !(0, json_1.isObject)(member.value))
|
|
113
|
-
continue;
|
|
114
|
-
for (const entry of member.value.members) {
|
|
115
|
-
if (!(0, json_1.isMember)(entry.element))
|
|
116
|
-
continue;
|
|
117
|
-
const name = (_b = (0, json_1.getMemberKeyName)(entry.element)) !== null && _b !== void 0 ? _b : '';
|
|
118
|
-
if (packages.has(name) && !found.includes(name))
|
|
119
|
-
found.push(name);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return found;
|
|
123
|
-
}
|
|
124
|
-
function editingRecipes(recipes) {
|
|
125
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
126
|
-
const flat = [];
|
|
127
|
-
for (const r of recipes) {
|
|
128
|
-
if (!(r instanceof rewrite_1.ScanningRecipe))
|
|
129
|
-
flat.push(r);
|
|
130
|
-
flat.push(...yield editingRecipes(yield r.recipeList()));
|
|
131
|
-
}
|
|
132
|
-
return flat;
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
class RemoveUnusedDependency extends rewrite_1.ScanningRecipe {
|
|
136
|
-
replacementModules() {
|
|
137
|
-
return [];
|
|
138
|
-
}
|
|
139
|
-
mockFile() {
|
|
140
|
-
return new RegExp(`(^|/)__mocks__/${escapeRegExp(this.module)}\\.[cm]?[jt]sx?$`);
|
|
141
|
-
}
|
|
142
|
-
constructor(options) {
|
|
143
|
-
var _a;
|
|
144
|
-
super({ accountForMigration: options === null || options === void 0 ? void 0 : options.accountForMigration });
|
|
145
|
-
this.kept = dependenciesKept();
|
|
146
|
-
this.precedingRecipes = (_a = options === null || options === void 0 ? void 0 : options.precedingRecipes) !== null && _a !== void 0 ? _a : [];
|
|
147
|
-
}
|
|
148
|
-
initialValue(_ctx) {
|
|
149
|
-
return { referencingFiles: [], parsedFiles: [], replacementFiles: [] };
|
|
150
|
-
}
|
|
151
|
-
scanner(acc) {
|
|
152
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
153
|
-
const preceding = yield editingRecipes(this.accountForMigration ? this.migrationRecipes() : this.precedingRecipes);
|
|
154
|
-
const reference = new RegExp(`['"\`]${escapeRegExp(this.module)}(/[^'"\`]*)?['"\`]`);
|
|
155
|
-
const configReference = new RegExp(`(^|[\\s'"\`=,:(\\[/])${escapeRegExp(this.module)}(?=[/'"\`\\s,)\\]]|$)`, 'm');
|
|
156
|
-
const mockFile = this.mockFile();
|
|
157
|
-
const replacements = this.replacementModules();
|
|
158
|
-
const replacementReference = replacements.length === 0 ? undefined
|
|
159
|
-
: new RegExp(`['"\`](?:${replacements.map(escapeRegExp).join('|')})(/[^'"\`]*)?['"\`]`);
|
|
160
|
-
return new class extends rewrite_1.TreeVisitor {
|
|
161
|
-
accept(tree, ctx) {
|
|
162
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
163
|
-
var _a;
|
|
164
|
-
const sourcePath = tree.sourcePath;
|
|
165
|
-
if (!sourcePath)
|
|
166
|
-
return tree;
|
|
167
|
-
if (tree.kind === PARSE_ERROR && SOURCE_FILE.test(sourcePath)) {
|
|
168
|
-
acc.referencingFiles.push(sourcePath);
|
|
169
|
-
}
|
|
170
|
-
else if (tree.kind === javascript_1.JS.Kind.CompilationUnit || (!LOCK_FILE.test(sourcePath) && !sourcePath.includes('node_modules/') &&
|
|
171
|
-
(CONFIG_FILE.test(sourcePath) || (tree.kind === text_1.PlainText.Kind.PlainText && !DOCUMENT.test(sourcePath))))) {
|
|
172
|
-
const isSource = tree.kind === javascript_1.JS.Kind.CompilationUnit;
|
|
173
|
-
if (isSource)
|
|
174
|
-
acc.parsedFiles.push(sourcePath);
|
|
175
|
-
let migrated = tree;
|
|
176
|
-
for (const recipe of preceding) {
|
|
177
|
-
const editor = yield recipe.editor();
|
|
178
|
-
if (yield editor.isAcceptable(migrated, ctx)) {
|
|
179
|
-
migrated = (_a = yield editor.visit(migrated, ctx)) !== null && _a !== void 0 ? _a : migrated;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
let printed = yield rewrite_1.TreePrinters.print(migrated);
|
|
183
|
-
if (isPackageJson(sourcePath))
|
|
184
|
-
printed = withoutDeclarations(printed);
|
|
185
|
-
if (isSource ? mockFile.test(sourcePath) || reference.test(printed) : configReference.test(printed)) {
|
|
186
|
-
acc.referencingFiles.push(sourcePath);
|
|
187
|
-
}
|
|
188
|
-
if (replacementReference === null || replacementReference === void 0 ? void 0 : replacementReference.test(printed))
|
|
189
|
-
acc.replacementFiles.push(sourcePath);
|
|
190
|
-
}
|
|
191
|
-
return tree;
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
};
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
editorWithData(acc) {
|
|
198
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
199
|
-
const packages = new Set(this.packages);
|
|
200
|
-
const module = this.module;
|
|
201
|
-
const recipeName = this.name;
|
|
202
|
-
const kept = this.kept;
|
|
203
|
-
return new class extends json_1.JsonVisitor {
|
|
204
|
-
visitDocument(doc, ctx) {
|
|
205
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
206
|
-
const dir = dirOf(doc.sourcePath);
|
|
207
|
-
if (!isPackageJson(doc.sourcePath) || !(0, json_1.isObject)(doc.value))
|
|
208
|
-
return doc;
|
|
209
|
-
const referencing = acc.referencingFiles.filter(file => dir === '' || file.startsWith(dir + '/'));
|
|
210
|
-
if (referencing.length > 0 || !anyBeneath(dir, acc.parsedFiles)) {
|
|
211
|
-
for (const name of declaredPackages(doc.value, packages)) {
|
|
212
|
-
const projen = referencing.length > 0 && referencing.every(file => PROJEN_DEPS.test(file));
|
|
213
|
-
kept.insertRow(ctx, {
|
|
214
|
-
sourcePath: doc.sourcePath,
|
|
215
|
-
recipe: recipeName,
|
|
216
|
-
package: name,
|
|
217
|
-
reason: referencing.length === 0 ? exports.KEPT_REASONS.unparsed
|
|
218
|
-
: projen ? exports.KEPT_REASONS.projen(module)
|
|
219
|
-
: exports.KEPT_REASONS.referenced(module),
|
|
220
|
-
evidence: referencing.slice(0, 5).join(' '),
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
return doc;
|
|
224
|
-
}
|
|
225
|
-
const root = doc.value;
|
|
226
|
-
let changed = false;
|
|
227
|
-
const members = root.members.map(rp => {
|
|
228
|
-
var _a;
|
|
229
|
-
if (!(0, json_1.isMember)(rp.element))
|
|
230
|
-
return rp;
|
|
231
|
-
const member = rp.element;
|
|
232
|
-
if (!SECTIONS.has((_a = (0, json_1.getMemberKeyName)(member)) !== null && _a !== void 0 ? _a : '') || !(0, json_1.isObject)(member.value))
|
|
233
|
-
return rp;
|
|
234
|
-
const section = member.value;
|
|
235
|
-
const updated = removeMembers(section, packages);
|
|
236
|
-
if (updated === section)
|
|
237
|
-
return rp;
|
|
238
|
-
changed = true;
|
|
239
|
-
return Object.assign(Object.assign({}, rp), { element: Object.assign(Object.assign({}, member), { value: updated }) });
|
|
240
|
-
});
|
|
241
|
-
return changed ? Object.assign(Object.assign({}, doc), { value: Object.assign(Object.assign({}, root), { members }) }) : doc;
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
};
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
exports.RemoveUnusedDependency = RemoveUnusedDependency;
|
|
249
|
-
__decorate([
|
|
250
|
-
(0, rewrite_1.Option)({
|
|
251
|
-
displayName: "Account for the migration",
|
|
252
|
-
description: "Judge library usage as it will be once the migration recipes have run, so the dependency " +
|
|
253
|
-
"is dropped in the same run. Only enable alongside those recipes, as the composite migration does.",
|
|
254
|
-
required: false
|
|
255
|
-
})
|
|
256
|
-
], RemoveUnusedDependency.prototype, "accountForMigration", void 0);
|
|
257
|
-
//# sourceMappingURL=remove-unused-dependency.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"remove-unused-dependency.js","sourceRoot":"","sources":["../../src/migrate/remove-unused-dependency.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAiDA,4CAOC;AAcD,sBAGC;AAED,sCAEC;AAED,gCAEC;AAkBD,sCAUC;AAvGD,kDAA8K;AAC9K,oDAAsH;AACtH,gEAAmD;AACnD,oDAAoD;AAEpD,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,CAAC,cAAc,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,kBAAkB,CAAC,CAAC,CAAC;AAC1G,MAAM,WAAW,GAAG,iBAAiB,CAAC;AAEtC,MAAM,WAAW,GAAG,6EAA6E,CAAC;AAElG,MAAM,QAAQ,GAAG,wKAAwK,CAAC;AAC1L,MAAM,SAAS,GAAG,yFAAyF,CAAC;AAE5G,MAAM,YAAY,GAAG,CAAC,cAAc,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,kBAAkB;IAC/F,sBAAsB,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,CAAC,CAAC;AAC7G,MAAM,WAAW,GAAG,iCAAiC,CAAC;AAEtD,MAAM,WAAW,GAAG,6BAA6B,CAAC;AASlD,MAAa,cAAc;CAe1B;AAfD,wCAeC;AAbG;IADC,IAAA,gBAAM,EAAC,EAAC,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,yDAAyD,EAAC,CAAC;kDACzF;AAGpB;IADC,IAAA,gBAAM,EAAC,EAAC,WAAW,EAAE,QAAQ,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E,gCAAI,MAAM,KAAE,KAAK,EAAE,OAAO,GAAgB,IAAE;wBACxE,CAAC,CAAC,CAAC;wBACH,OAAO,OAAO,CAAC,CAAC,CAAC,gCAAI,GAAG,KAAE,KAAK,kCAAM,IAAI,KAAE,OAAO,MAAmB,CAAC,CAAC,CAAC,GAAG,CAAC;oBAChF,CAAC;iBAAA;aACJ,CAAC;QACN,CAAC;KAAA;CACJ;AAnID,wDAmIC;AA7FG;IANC,IAAA,gBAAM,EAAC;QACJ,WAAW,EAAE,2BAA2B;QACxC,WAAW,EAAE,2FAA2F;YACpG,mGAAmG;QACvG,QAAQ,EAAE,KAAK;KAClB,CAAC;mEAC4B"}
|
|
@@ -1,275 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2026 the original author or authors.
|
|
3
|
-
*
|
|
4
|
-
* Moderne Proprietary. Only for use by Moderne customers under the terms of a commercial contract.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import {Column, DataTable, emptyMarkers, ExecutionContext, Option, randomId, Recipe, ScanningRecipe, SourceFile, Tree, TreePrinters, TreeVisitor} from "@openrewrite/rewrite";
|
|
8
|
-
import {getMemberKeyName, isMember, isObject, Json, JsonVisitor, rightPadded, space} from "@openrewrite/rewrite/json";
|
|
9
|
-
import {JS} from "@openrewrite/rewrite/javascript";
|
|
10
|
-
import {PlainText} from "@openrewrite/rewrite/text";
|
|
11
|
-
|
|
12
|
-
const SECTIONS = new Set(['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies']);
|
|
13
|
-
const SOURCE_FILE = /\.[cm]?[jt]sx?$/;
|
|
14
|
-
// Tool configuration can load a library too, e.g. `mocha -r x/register` in scripts or `require: [...]` in `.mocharc.yml`.
|
|
15
|
-
const CONFIG_FILE = /(^|\/)(package\.json|mocha\.opts|\.mocharc(\.[a-z]+)?|[^/]+\.(json|ya?ml))$/;
|
|
16
|
-
// Extensionless scripts (`bin/cli`, Adonis's `ace`), shell scripts and Dockerfiles aren't parsed, so they're read as text; docs and AI assistant rules are skipped.
|
|
17
|
-
const DOCUMENT = /(\.(md|markdown|mdx|txt|rst|adoc|svg|log|csv|map)|(^|\/)(LICENSE|LICENCE|CHANGELOG|CHANGES|HISTORY|README|AUTHORS|NOTICE)[^/]*|(^|\/)\.(cursor|windsurf|cline)rules)$/i;
|
|
18
|
-
const LOCK_FILE = /(^|\/)(package-lock\.json|npm-shrinkwrap\.json|yarn\.lock|pnpm-lock\.yaml|bun\.lockb?)$/;
|
|
19
|
-
// Sections that declare or pin packages rather than use them.
|
|
20
|
-
const DECLARATIONS = ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies',
|
|
21
|
-
'peerDependenciesMeta', 'bundledDependencies', 'bundleDependencies', 'overrides', 'resolutions', 'pnpm'];
|
|
22
|
-
const PARSE_ERROR = "org.openrewrite.tree.ParseError";
|
|
23
|
-
// projen generates `package.json` from `.projenrc.ts`, recording each dependency here as it goes.
|
|
24
|
-
const PROJEN_DEPS = /(^|\/)\.projen\/deps\.json$/;
|
|
25
|
-
|
|
26
|
-
interface Accumulator {
|
|
27
|
-
referencingFiles: string[];
|
|
28
|
-
parsedFiles: string[];
|
|
29
|
-
/** Files that reference one of {@link RemoveUnusedDependency.replacementModules} once migrated. */
|
|
30
|
-
replacementFiles: string[];
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export class DependencyKept {
|
|
34
|
-
@Column({displayName: "Source path", description: "Path of the `package.json` still declaring the package."})
|
|
35
|
-
sourcePath!: string;
|
|
36
|
-
|
|
37
|
-
@Column({displayName: "Recipe", description: "Recipe that left the declaration in place."})
|
|
38
|
-
recipe!: string;
|
|
39
|
-
|
|
40
|
-
@Column({displayName: "Package", description: "The package that was not removed, e.g. `fs-extra`."})
|
|
41
|
-
package!: string;
|
|
42
|
-
|
|
43
|
-
@Column({displayName: "Reason", description: "Why the declaration couldn't be removed."})
|
|
44
|
-
reason!: string;
|
|
45
|
-
|
|
46
|
-
@Column({displayName: "Evidence", description: "Files that kept it, up to the first few."})
|
|
47
|
-
evidence!: string;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function dependenciesKept(): DataTable<DependencyKept> {
|
|
51
|
-
return new DataTable<DependencyKept>(
|
|
52
|
-
"org.openrewrite.node.table.DependenciesKept",
|
|
53
|
-
"Dependencies kept",
|
|
54
|
-
"Packages the migration could not remove from a `package.json`, and what kept them.",
|
|
55
|
-
DependencyKept,
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export const KEPT_REASONS = {
|
|
60
|
-
projen: (module: string) => `This package's dependencies are generated by projen: \`.projen/deps.json\` still ` +
|
|
61
|
-
`lists \`${module}\`, and nothing else beneath this \`package.json\` references it. Editing \`package.json\` ` +
|
|
62
|
-
"here would be undone by the next `npx projen`, so it is left alone. Remove the entry from `.projenrc.ts` " +
|
|
63
|
-
"(the arrays passed to the projen project, where it reads as `'" + module + "@<range>'`) and re-run projen.",
|
|
64
|
-
referenced: (module: string) => `\`${module}\` is still referenced beneath this \`package.json\` once the ` +
|
|
65
|
-
"migration has run — a usage it left in place, a test mock, or tool configuration naming the module. The " +
|
|
66
|
-
"library's own find recipe reports each site.",
|
|
67
|
-
unparsed: "No source beneath this `package.json` was parsed, so there is nothing to judge usage by. A JavaScript " +
|
|
68
|
-
"parse failure or an unbuilt LST leaves the declaration alone rather than guessing.",
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
export function dirOf(path: string): string {
|
|
72
|
-
const i = path.lastIndexOf('/');
|
|
73
|
-
return i < 0 ? '' : path.substring(0, i);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export function isPackageJson(path: string): boolean {
|
|
77
|
-
return (path === 'package.json' || path.endsWith('/package.json')) && !path.includes('node_modules/');
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export function anyBeneath(dir: string, files: string[]): boolean {
|
|
81
|
-
return files.some(file => dir === '' || file.startsWith(dir + '/'));
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/** A `package.json`'s content less the sections declaring packages, which name the library without using it. */
|
|
85
|
-
function withoutDeclarations(packageJson: string): string {
|
|
86
|
-
try {
|
|
87
|
-
const parsed = JSON.parse(packageJson);
|
|
88
|
-
for (const section of DECLARATIONS) delete parsed[section];
|
|
89
|
-
return JSON.stringify(parsed);
|
|
90
|
-
} catch {
|
|
91
|
-
return packageJson;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function escapeRegExp(s: string): string {
|
|
96
|
-
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/** Removes members named in `keys`, handing the removed last member's trailing space to the one before it. */
|
|
100
|
-
export function removeMembers(obj: Json.Object, keys: Set<string>): Json.Object {
|
|
101
|
-
const kept = obj.members.filter(rp => !(isMember(rp.element) && keys.has(getMemberKeyName(rp.element as Json.Member) ?? '')));
|
|
102
|
-
if (kept.length === obj.members.length) return obj;
|
|
103
|
-
if (kept.length === 0) {
|
|
104
|
-
const empty: Json.Empty = {kind: Json.Kind.Empty, id: randomId(), prefix: space(''), markers: emptyMarkers};
|
|
105
|
-
return {...obj, members: [rightPadded(empty, space(''))]};
|
|
106
|
-
}
|
|
107
|
-
const closing = obj.members[obj.members.length - 1].after;
|
|
108
|
-
kept[kept.length - 1] = {...kept[kept.length - 1], after: closing};
|
|
109
|
-
return {...obj, members: kept};
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/** Which of `packages` this `package.json` declares, in any of its dependency sections. */
|
|
113
|
-
function declaredPackages(root: Json.Object, packages: ReadonlySet<string>): string[] {
|
|
114
|
-
const found: string[] = [];
|
|
115
|
-
for (const rp of root.members) {
|
|
116
|
-
if (!isMember(rp.element)) continue;
|
|
117
|
-
const member = rp.element as Json.Member;
|
|
118
|
-
if (!SECTIONS.has(getMemberKeyName(member) ?? '') || !isObject(member.value)) continue;
|
|
119
|
-
for (const entry of (member.value as Json.Object).members) {
|
|
120
|
-
if (!isMember(entry.element)) continue;
|
|
121
|
-
const name = getMemberKeyName(entry.element as Json.Member) ?? '';
|
|
122
|
-
if (packages.has(name) && !found.includes(name)) found.push(name);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return found;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/** The non-scanning recipes `recipes` expands to, in the order a run applies them. */
|
|
129
|
-
async function editingRecipes(recipes: Recipe[]): Promise<Recipe[]> {
|
|
130
|
-
const flat: Recipe[] = [];
|
|
131
|
-
for (const r of recipes) {
|
|
132
|
-
if (!(r instanceof ScanningRecipe)) flat.push(r);
|
|
133
|
-
flat.push(...await editingRecipes(await r.recipeList()));
|
|
134
|
-
}
|
|
135
|
-
return flat;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Removes a library's packages from each `package.json` whose sources no longer reference the
|
|
140
|
-
* library by a quoted module specifier. A reference anywhere beneath a `package.json`'s directory
|
|
141
|
-
* keeps its dependencies, since a monorepo root hoists them for its workspaces, and a package is
|
|
142
|
-
* left alone when any source beneath it failed to parse, or none was parsed at all.
|
|
143
|
-
*/
|
|
144
|
-
export abstract class RemoveUnusedDependency extends ScanningRecipe<Accumulator> {
|
|
145
|
-
/** The module whose quoted specifier (or a subpath of it) counts as a use. */
|
|
146
|
-
protected abstract readonly module: string;
|
|
147
|
-
|
|
148
|
-
/** The packages removed together once `module` is unused, e.g. the library and its `@types`. */
|
|
149
|
-
protected abstract readonly packages: string[];
|
|
150
|
-
|
|
151
|
-
/** The migration recipes whose result the scan judges usage by when `accountForMigration` is set. */
|
|
152
|
-
protected abstract migrationRecipes(): Recipe[];
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Modules the migration introduces, whose appearance in a migrated source is what shows the
|
|
156
|
-
* migration reached this package. A subclass that swaps one dependency for another names the
|
|
157
|
-
* new one here, so it is only declared where something actually came to need it.
|
|
158
|
-
*/
|
|
159
|
-
protected replacementModules(): string[] {
|
|
160
|
-
return [];
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
private readonly kept = dependenciesKept();
|
|
164
|
-
|
|
165
|
-
/** Mock files are named for the module they replace, so they count as a use without quoting it. */
|
|
166
|
-
protected mockFile(): RegExp {
|
|
167
|
-
return new RegExp(`(^|/)__mocks__/${escapeRegExp(this.module)}\\.[cm]?[jt]sx?$`);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Scanning sees sources before any recipe in the same run edits them, and a second cycle isn't
|
|
172
|
-
* triggered by RPC recipes, so the scanner applies the migration itself to judge what remains.
|
|
173
|
-
*/
|
|
174
|
-
private readonly precedingRecipes: Recipe[];
|
|
175
|
-
|
|
176
|
-
@Option({
|
|
177
|
-
displayName: "Account for the migration",
|
|
178
|
-
description: "Judge library usage as it will be once the migration recipes have run, so the dependency " +
|
|
179
|
-
"is dropped in the same run. Only enable alongside those recipes, as the composite migration does.",
|
|
180
|
-
required: false
|
|
181
|
-
})
|
|
182
|
-
accountForMigration?: boolean;
|
|
183
|
-
|
|
184
|
-
constructor(options?: { precedingRecipes?: Recipe[]; accountForMigration?: boolean }) {
|
|
185
|
-
super({accountForMigration: options?.accountForMigration});
|
|
186
|
-
this.precedingRecipes = options?.precedingRecipes ?? [];
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
initialValue(_ctx: ExecutionContext): Accumulator {
|
|
190
|
-
return {referencingFiles: [], parsedFiles: [], replacementFiles: []};
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
async scanner(acc: Accumulator): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
194
|
-
const preceding = await editingRecipes(this.accountForMigration ? this.migrationRecipes() : this.precedingRecipes);
|
|
195
|
-
// Any quoted specifier counts, so bundler `externals` lists and mock factories keep the dependency too.
|
|
196
|
-
const reference = new RegExp(`['"\`]${escapeRegExp(this.module)}(/[^'"\`]*)?['"\`]`);
|
|
197
|
-
// In configuration the module can also sit inside a command line or a path, as in `"test": "mocha -r x/register"` or `node_modules/x/dist`.
|
|
198
|
-
const configReference = new RegExp(`(^|[\\s'"\`=,:(\\[/])${escapeRegExp(this.module)}(?=[/'"\`\\s,)\\]]|$)`, 'm');
|
|
199
|
-
const mockFile = this.mockFile();
|
|
200
|
-
const replacements = this.replacementModules();
|
|
201
|
-
const replacementReference = replacements.length === 0 ? undefined
|
|
202
|
-
: new RegExp(`['"\`](?:${replacements.map(escapeRegExp).join('|')})(/[^'"\`]*)?['"\`]`);
|
|
203
|
-
return new class extends TreeVisitor<Tree, ExecutionContext> {
|
|
204
|
-
protected async accept(tree: Tree, ctx: ExecutionContext): Promise<Tree | undefined> {
|
|
205
|
-
const sourcePath: string | undefined = (tree as any).sourcePath;
|
|
206
|
-
if (!sourcePath) return tree;
|
|
207
|
-
if (tree.kind === PARSE_ERROR && SOURCE_FILE.test(sourcePath)) {
|
|
208
|
-
// Nothing here can tell whether a file that failed to parse uses the library.
|
|
209
|
-
acc.referencingFiles.push(sourcePath);
|
|
210
|
-
} else if (tree.kind === JS.Kind.CompilationUnit || (!LOCK_FILE.test(sourcePath) && !sourcePath.includes('node_modules/') &&
|
|
211
|
-
(CONFIG_FILE.test(sourcePath) || (tree.kind === PlainText.Kind.PlainText && !DOCUMENT.test(sourcePath))))) {
|
|
212
|
-
const isSource = tree.kind === JS.Kind.CompilationUnit;
|
|
213
|
-
if (isSource) acc.parsedFiles.push(sourcePath);
|
|
214
|
-
let migrated = tree as SourceFile;
|
|
215
|
-
for (const recipe of preceding) {
|
|
216
|
-
const editor = await recipe.editor();
|
|
217
|
-
if (await editor.isAcceptable(migrated, ctx)) {
|
|
218
|
-
migrated = await editor.visit<SourceFile>(migrated, ctx) ?? migrated;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
let printed = await TreePrinters.print(migrated);
|
|
222
|
-
if (isPackageJson(sourcePath)) printed = withoutDeclarations(printed);
|
|
223
|
-
if (isSource ? mockFile.test(sourcePath) || reference.test(printed) : configReference.test(printed)) {
|
|
224
|
-
acc.referencingFiles.push(sourcePath);
|
|
225
|
-
}
|
|
226
|
-
if (replacementReference?.test(printed)) acc.replacementFiles.push(sourcePath);
|
|
227
|
-
}
|
|
228
|
-
return tree;
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
async editorWithData(acc: Accumulator): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
234
|
-
const packages = new Set(this.packages);
|
|
235
|
-
const module = this.module;
|
|
236
|
-
const recipeName = this.name;
|
|
237
|
-
const kept = this.kept;
|
|
238
|
-
return new class extends JsonVisitor<ExecutionContext> {
|
|
239
|
-
protected async visitDocument(doc: Json.Document, ctx: ExecutionContext): Promise<Json | undefined> {
|
|
240
|
-
const dir = dirOf(doc.sourcePath);
|
|
241
|
-
if (!isPackageJson(doc.sourcePath) || !isObject(doc.value)) return doc;
|
|
242
|
-
const referencing = acc.referencingFiles.filter(file => dir === '' || file.startsWith(dir + '/'));
|
|
243
|
-
if (referencing.length > 0 || !anyBeneath(dir, acc.parsedFiles)) {
|
|
244
|
-
// Report only where this `package.json` actually declares one of the packages.
|
|
245
|
-
for (const name of declaredPackages(doc.value as Json.Object, packages)) {
|
|
246
|
-
const projen = referencing.length > 0 && referencing.every(file => PROJEN_DEPS.test(file));
|
|
247
|
-
kept.insertRow(ctx, {
|
|
248
|
-
sourcePath: doc.sourcePath,
|
|
249
|
-
recipe: recipeName,
|
|
250
|
-
package: name,
|
|
251
|
-
reason: referencing.length === 0 ? KEPT_REASONS.unparsed
|
|
252
|
-
: projen ? KEPT_REASONS.projen(module)
|
|
253
|
-
: KEPT_REASONS.referenced(module),
|
|
254
|
-
evidence: referencing.slice(0, 5).join(' '),
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
return doc;
|
|
258
|
-
}
|
|
259
|
-
const root = doc.value as Json.Object;
|
|
260
|
-
let changed = false;
|
|
261
|
-
const members = root.members.map(rp => {
|
|
262
|
-
if (!isMember(rp.element)) return rp;
|
|
263
|
-
const member = rp.element as Json.Member;
|
|
264
|
-
if (!SECTIONS.has(getMemberKeyName(member) ?? '') || !isObject(member.value)) return rp;
|
|
265
|
-
const section = member.value as Json.Object;
|
|
266
|
-
const updated = removeMembers(section, packages);
|
|
267
|
-
if (updated === section) return rp;
|
|
268
|
-
changed = true;
|
|
269
|
-
return {...rp, element: {...member, value: updated} as Json.Member};
|
|
270
|
-
});
|
|
271
|
-
return changed ? {...doc, value: {...root, members}} as Json.Document : doc;
|
|
272
|
-
}
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
}
|