@cedarjs/codemods 5.0.0-canary.13899 → 5.0.0-canary.13907
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,38 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
+
function transformTsConfigModule(source) {
|
|
3
|
+
if (/["']module["']\s*:\s*["']node20["']/i.test(source)) {
|
|
4
|
+
return source;
|
|
5
|
+
}
|
|
6
|
+
const overwritten = source.replace(/("module"\s*:\s*)"[^"]*"/, '$1"node20"');
|
|
7
|
+
if (overwritten !== source) {
|
|
8
|
+
return overwritten;
|
|
9
|
+
}
|
|
10
|
+
const afterTarget = source.replace(
|
|
11
|
+
/("target"\s*:\s*"[^"]*")(,?)(\s*\n)/,
|
|
12
|
+
(match, prop, comma, ws) => {
|
|
13
|
+
const lineStart = source.lastIndexOf("\n", source.indexOf(match)) + 1;
|
|
14
|
+
const indentMatch = source.slice(lineStart).match(/^([ \t]+)/);
|
|
15
|
+
const indent = indentMatch ? indentMatch[1] : " ";
|
|
16
|
+
const trailingComma = comma || ",";
|
|
17
|
+
return `${prop}${trailingComma}${ws}${indent}"module": "node20",
|
|
18
|
+
`;
|
|
19
|
+
}
|
|
20
|
+
);
|
|
21
|
+
if (afterTarget !== source) {
|
|
22
|
+
return afterTarget;
|
|
23
|
+
}
|
|
24
|
+
return source.replace(
|
|
25
|
+
/("compilerOptions"\s*:\s*\{)(\s*\n)/,
|
|
26
|
+
(match, open, ws) => {
|
|
27
|
+
const lineStart = source.lastIndexOf("\n", source.indexOf(match)) + 1;
|
|
28
|
+
const indentMatch = source.slice(lineStart).match(/^([ \t]+)/);
|
|
29
|
+
const outerIndent = indentMatch ? indentMatch[1] : " ";
|
|
30
|
+
const innerIndent = outerIndent + " ";
|
|
31
|
+
return `${open}${ws}${innerIndent}"module": "node20",
|
|
32
|
+
`;
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
}
|
|
2
36
|
function transformTsConfig(source) {
|
|
3
37
|
if (/["']allowImportingTsExtensions["']/.test(source)) {
|
|
4
38
|
return source;
|
|
@@ -58,9 +92,22 @@ async function updateTsConfig(tsConfigPath) {
|
|
|
58
92
|
fs.writeFileSync(tsConfigPath, transformed, "utf-8");
|
|
59
93
|
return "updated";
|
|
60
94
|
}
|
|
95
|
+
async function updateApiTsConfig(tsConfigPath) {
|
|
96
|
+
if (!fs.existsSync(tsConfigPath)) {
|
|
97
|
+
return "skipped";
|
|
98
|
+
}
|
|
99
|
+
const source = fs.readFileSync(tsConfigPath, "utf-8");
|
|
100
|
+
const withExtensions = transformTsConfig(source);
|
|
101
|
+
const withModule = transformTsConfigModule(withExtensions);
|
|
102
|
+
if (withModule === source) {
|
|
103
|
+
return "unmodified";
|
|
104
|
+
}
|
|
105
|
+
fs.writeFileSync(tsConfigPath, withModule, "utf-8");
|
|
106
|
+
return "updated";
|
|
107
|
+
}
|
|
61
108
|
async function updateTsConfigs(paths) {
|
|
62
109
|
const [api, scripts, web] = await Promise.all([
|
|
63
|
-
|
|
110
|
+
updateApiTsConfig(paths.apiTsConfig),
|
|
64
111
|
updateTsConfig(paths.scriptsTsConfig),
|
|
65
112
|
updateTsConfig(paths.webTsConfig)
|
|
66
113
|
]);
|
|
@@ -68,6 +115,8 @@ async function updateTsConfigs(paths) {
|
|
|
68
115
|
}
|
|
69
116
|
export {
|
|
70
117
|
transformTsConfig,
|
|
118
|
+
transformTsConfigModule,
|
|
119
|
+
updateApiTsConfig,
|
|
71
120
|
updateTsConfig,
|
|
72
121
|
updateTsConfigs
|
|
73
122
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/codemods",
|
|
3
|
-
"version": "5.0.0-canary.
|
|
3
|
+
"version": "5.0.0-canary.13907+714061f63e",
|
|
4
4
|
"description": "Codemods to ease upgrading a CedarJS Project",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"@babel/parser": "7.29.2",
|
|
30
30
|
"@babel/plugin-transform-typescript": "^7.26.8",
|
|
31
31
|
"@babel/traverse": "7.29.0",
|
|
32
|
-
"@cedarjs/cli-helpers": "5.0.0-canary.
|
|
33
|
-
"@cedarjs/project-config": "5.0.0-canary.
|
|
32
|
+
"@cedarjs/cli-helpers": "5.0.0-canary.13907",
|
|
33
|
+
"@cedarjs/project-config": "5.0.0-canary.13907",
|
|
34
34
|
"@svgr/core": "8.1.0",
|
|
35
35
|
"@svgr/plugin-jsx": "8.1.0",
|
|
36
36
|
"@vscode/ripgrep": "1.17.1",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"yargs": "17.7.2"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@cedarjs/framework-tools": "5.0.0-canary.
|
|
51
|
+
"@cedarjs/framework-tools": "5.0.0-canary.13907",
|
|
52
52
|
"@types/babel__core": "7.20.5",
|
|
53
53
|
"@types/jscodeshift": "17.3.0",
|
|
54
54
|
"@types/yargs": "17.0.35",
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"publishConfig": {
|
|
65
65
|
"access": "public"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "714061f63e2f5172793ddd35345b782c2cd00572"
|
|
68
68
|
}
|