@comet/upgrade 1.75.0 → 1.77.0

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.
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stage = void 0;
4
+ const ts_morph_1 = require("ts-morph");
5
+ exports.stage = "never";
6
+ async function ignoreRestrictedImportsAdmin() {
7
+ const project = new ts_morph_1.Project({ tsConfigFilePath: "./admin/tsconfig.json" });
8
+ const sourceFiles = project.getSourceFiles("admin/src/**/*.tsx");
9
+ for (const sourceFile of sourceFiles) {
10
+ const imports = sourceFile.getImportDeclarations();
11
+ for (const imp of imports) {
12
+ const module = imp.getModuleSpecifierValue();
13
+ if (module === "@mui/material") {
14
+ const namedImports = imp.getNamedImports().map((ni) => ni.getName());
15
+ if (namedImports.includes("Button") || namedImports.includes("Dialog")) {
16
+ // Check for existing comments above
17
+ const statements = imp.getLeadingCommentRanges().map((r) => r.getText());
18
+ const hasEslintComment = statements.some((s) => s.includes("eslint-disable-next-line no-restricted-imports"));
19
+ if (!hasEslintComment) {
20
+ imp.replaceWithText(`// TODO v8: remove eslint-disable-next-line\n// eslint-disable-next-line no-restricted-imports\n${imp.getText()}`);
21
+ }
22
+ }
23
+ }
24
+ }
25
+ }
26
+ await project.save();
27
+ }
28
+ exports.default = ignoreRestrictedImportsAdmin;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stage = void 0;
4
+ const ts_morph_1 = require("ts-morph");
5
+ exports.stage = "never";
6
+ async function removeV8EslintDisableCommentsAdmin() {
7
+ const project = new ts_morph_1.Project({ tsConfigFilePath: "./admin/tsconfig.json" });
8
+ const sourceFiles = project.getSourceFiles("admin/src/**/*.tsx");
9
+ for (const sourceFile of sourceFiles) {
10
+ const imports = sourceFile.getImportDeclarations();
11
+ // Store comments to remove as [start, end] tuples
12
+ const commentRangesToRemove = [];
13
+ for (const imp of imports) {
14
+ const leadingComments = imp.getLeadingCommentRanges();
15
+ for (let i = 0; i < leadingComments.length - 1; i++) {
16
+ const first = leadingComments[i];
17
+ const second = leadingComments[i + 1];
18
+ const firstText = first.getText();
19
+ const secondText = second.getText();
20
+ if (firstText.includes("TODO v8: remove eslint-disable-next-line") &&
21
+ secondText.includes("eslint-disable-next-line no-restricted-imports")) {
22
+ // Mark both comments for removal
23
+ commentRangesToRemove.push([second.getPos(), second.getEnd()]);
24
+ commentRangesToRemove.push([first.getPos(), first.getEnd()]);
25
+ }
26
+ }
27
+ }
28
+ // Remove all comments from the file, in reverse order
29
+ commentRangesToRemove
30
+ .sort((a, b) => b[0] - a[0]) // Sort descending by start index
31
+ .forEach(([start, end]) => {
32
+ sourceFile.removeText(start, end);
33
+ });
34
+ }
35
+ await project.save();
36
+ }
37
+ exports.default = removeV8EslintDisableCommentsAdmin;
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const ts_morph_1 = require("ts-morph");
4
+ /**
5
+ * Update the configuration of the DamModule and BlobStorageModule and add ImgproxyModule to app.module.ts
6
+ *
7
+ * - Adds `cacheDirectory` to `BlobStorageModule.register`
8
+ * - Adds `ImgproxyModule` import
9
+ * - Add `maxSrcResolution` to `DamModule.register`
10
+ * - Removes `cacheDirectory` and `imgproxyConfig` from `DamModule.register`
11
+ */
12
+ async function updateDamConfiguration() {
13
+ const project = new ts_morph_1.Project();
14
+ const filePath = "api/src/app.module.ts"; // Update this path to your actual file path
15
+ const sourceFile = project.addSourceFileAtPath(filePath);
16
+ // Update BlobStorageModule configuration
17
+ const blobStorageModuleCall = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression).find((call) => {
18
+ const expression = call.getExpression();
19
+ return expression.getText() === "BlobStorageModule.register";
20
+ });
21
+ if (blobStorageModuleCall) {
22
+ const args = blobStorageModuleCall.getArguments();
23
+ if (args.length > 0 && args[0].getKind() === ts_morph_1.SyntaxKind.ObjectLiteralExpression) {
24
+ const objectLiteral = args[0];
25
+ const cacheDirectoryProperty = objectLiteral.getProperty("cacheDirectory");
26
+ if (!cacheDirectoryProperty) {
27
+ objectLiteral.addPropertyAssignment({
28
+ name: "cacheDirectory",
29
+ initializer: "`${config.blob.storageDirectoryPrefix}-cache`",
30
+ });
31
+ }
32
+ }
33
+ }
34
+ // Add ImgproxyModule import
35
+ sourceFile.addImportDeclaration({
36
+ namedImports: ["ImgproxyModule"],
37
+ moduleSpecifier: "@comet/cms-api",
38
+ });
39
+ // Add ImgproxyModule configuration
40
+ const importsArray = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.ArrayLiteralExpression).find((array) => {
41
+ const parent = array.getParent();
42
+ return parent && parent.getKind() === ts_morph_1.SyntaxKind.PropertyAssignment && parent.getName() === "imports";
43
+ });
44
+ if (importsArray) {
45
+ const imgproxyModuleCall = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression).find((call) => {
46
+ const expression = call.getExpression();
47
+ return expression.getText() === "ImgproxyModule.register";
48
+ });
49
+ if (!imgproxyModuleCall) {
50
+ importsArray.addElement("ImgproxyModule.register(config.imgproxy)");
51
+ }
52
+ }
53
+ // Update DamModule configuration
54
+ const damModuleCall = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression).find((call) => {
55
+ const expression = call.getExpression();
56
+ return expression.getText() === "DamModule.register";
57
+ });
58
+ if (damModuleCall) {
59
+ const args = damModuleCall.getArguments();
60
+ if (args.length > 0 && args[0].getKind() === ts_morph_1.SyntaxKind.ObjectLiteralExpression) {
61
+ const objectLiteral = args[0];
62
+ const damConfigProperty = objectLiteral.getProperty("damConfig");
63
+ if (damConfigProperty && damConfigProperty.getKind() === ts_morph_1.SyntaxKind.PropertyAssignment) {
64
+ const damConfigObject = damConfigProperty.getInitializerIfKind(ts_morph_1.SyntaxKind.ObjectLiteralExpression);
65
+ if (damConfigObject) {
66
+ const maxSrcResolutionProperty = damConfigObject.getProperty("maxSrcResolution");
67
+ if (!maxSrcResolutionProperty) {
68
+ damConfigObject.addPropertyAssignment({
69
+ name: "maxSrcResolution",
70
+ initializer: "config.dam.maxSrcResolution",
71
+ });
72
+ }
73
+ const cacheDirectoryProperty = damConfigObject.getProperty("cacheDirectory");
74
+ if (cacheDirectoryProperty) {
75
+ cacheDirectoryProperty.remove();
76
+ }
77
+ }
78
+ }
79
+ const imgproxyConfigProperty = objectLiteral.getProperty("imgproxyConfig");
80
+ if (imgproxyConfigProperty) {
81
+ imgproxyConfigProperty.remove();
82
+ }
83
+ }
84
+ }
85
+ await project.save();
86
+ }
87
+ exports.default = updateDamConfiguration;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comet/upgrade",
3
- "version": "1.75.0",
3
+ "version": "1.77.0",
4
4
  "description": "Upgrade scripts for Comet DXP",
5
5
  "homepage": "https://github.com/vivid-planet/comet-upgrade#readme",
6
6
  "bugs": {