@cedarjs/internal 6.0.2 → 6.0.3-next.227
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/build/api.d.ts.map +1 -1
- package/dist/build/api.js +5 -19
- package/dist/build/esbuild-plugin-api-graphql.d.ts.map +1 -1
- package/dist/build/esbuild-plugin-api-graphql.js +2 -4
- package/dist/build/esbuild-plugin-handler-als-wrapping.d.ts +1 -3
- package/dist/build/esbuild-plugin-handler-als-wrapping.d.ts.map +1 -1
- package/dist/build/esbuild-plugin-handler-als-wrapping.js +2 -3
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/package.json +21 -28
- package/dist/ts2js.d.ts +0 -40
- package/dist/ts2js.d.ts.map +0 -1
- package/dist/ts2js.js +0 -119
package/dist/build/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/build/api.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAgB,YAAY,EAAe,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/build/api.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAgB,YAAY,EAAe,MAAM,SAAS,CAAA;AAwCtE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAA;AAI9D,eAAO,MAAM,QAAQ,4DAIpB,CAAA;AAED,eAAO,MAAM,UAAU,4DAStB,CAAA;AAED,eAAO,MAAM,aAAa,qBAGzB,CAAA;AA8UD,eAAO,MAAM,gBAAgB,iHA+D5B,CAAA;AAcD,wBAAsB,aAAa,CACjC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAoDf"}
|
package/dist/build/api.js
CHANGED
|
@@ -14,12 +14,7 @@ import {
|
|
|
14
14
|
getApiSideBabelPluginsForVite,
|
|
15
15
|
transformWithBabel
|
|
16
16
|
} from "@cedarjs/babel-config";
|
|
17
|
-
import {
|
|
18
|
-
getConfig,
|
|
19
|
-
getPaths,
|
|
20
|
-
projectSideIsEsm,
|
|
21
|
-
resolveFile
|
|
22
|
-
} from "@cedarjs/project-config";
|
|
17
|
+
import { getConfig, getPaths, resolveFile } from "@cedarjs/project-config";
|
|
23
18
|
import { findApiFiles } from "../files.js";
|
|
24
19
|
import {
|
|
25
20
|
applyGqlormInject,
|
|
@@ -79,7 +74,6 @@ const runCedarBabelTransformsPlugin = {
|
|
|
79
74
|
fileContents = applyJobPathInjector(fileContents, args.path, getPaths().api.jobs) ?? fileContents;
|
|
80
75
|
const normalizedPath = normalizePath(args.path);
|
|
81
76
|
const cedarPaths = getPaths();
|
|
82
|
-
const isEsm = projectSideIsEsm("api");
|
|
83
77
|
const apiBabelConfigPath = getApiSideBabelConfigPath();
|
|
84
78
|
let code = fileContents;
|
|
85
79
|
if (apiBabelConfigPath) {
|
|
@@ -98,9 +92,7 @@ const runCedarBabelTransformsPlugin = {
|
|
|
98
92
|
code = applyImportExtensions(code, args.path);
|
|
99
93
|
const functionsDir = normalizePath(cedarPaths.api.functions);
|
|
100
94
|
if (normalizedPath.startsWith(functionsDir + "/")) {
|
|
101
|
-
code = applyHandlerAlsWrapping(code
|
|
102
|
-
projectIsEsm: isEsm
|
|
103
|
-
}) ?? code;
|
|
95
|
+
code = applyHandlerAlsWrapping(code) ?? code;
|
|
104
96
|
}
|
|
105
97
|
if (normalizedPath.startsWith(normalizePath(cedarPaths.api.src) + "/")) {
|
|
106
98
|
code = applyOtelWrapping(code, args.path, cedarPaths.api.src) ?? code;
|
|
@@ -178,7 +170,6 @@ function createDirectoryNamedImportVitePlugin() {
|
|
|
178
170
|
}
|
|
179
171
|
function createCedarViteApiPlugin() {
|
|
180
172
|
const cedarConfig = getConfig();
|
|
181
|
-
const isEsm = projectSideIsEsm("api");
|
|
182
173
|
return {
|
|
183
174
|
name: "cedar-vite-api-babel-transform",
|
|
184
175
|
enforce: "pre",
|
|
@@ -223,9 +214,7 @@ function createCedarViteApiPlugin() {
|
|
|
223
214
|
outputCode = applyImportExtensions(outputCode, id);
|
|
224
215
|
const functionsDir = normalizePath(cedarPaths.api.functions);
|
|
225
216
|
if (normalizedId.startsWith(functionsDir + "/")) {
|
|
226
|
-
outputCode = applyHandlerAlsWrapping(outputCode
|
|
227
|
-
projectIsEsm: isEsm
|
|
228
|
-
}) ?? outputCode;
|
|
217
|
+
outputCode = applyHandlerAlsWrapping(outputCode) ?? outputCode;
|
|
229
218
|
}
|
|
230
219
|
if (!transformedCode) {
|
|
231
220
|
if (outputCode === code) {
|
|
@@ -245,8 +234,6 @@ function createCedarViteApiPlugin() {
|
|
|
245
234
|
}
|
|
246
235
|
const buildApiWithVite = async () => {
|
|
247
236
|
const cedarPaths = getPaths();
|
|
248
|
-
const isEsm = projectSideIsEsm("api");
|
|
249
|
-
const format = isEsm ? "es" : "cjs";
|
|
250
237
|
const apiFiles = findApiFiles();
|
|
251
238
|
const input = {};
|
|
252
239
|
for (const f of apiFiles) {
|
|
@@ -263,7 +250,7 @@ const buildApiWithVite = async () => {
|
|
|
263
250
|
rollupOptions: {
|
|
264
251
|
input,
|
|
265
252
|
output: {
|
|
266
|
-
format,
|
|
253
|
+
format: "es",
|
|
267
254
|
preserveModules: true,
|
|
268
255
|
preserveModulesRoot: cedarPaths.api.src,
|
|
269
256
|
entryFileNames: "[name].js",
|
|
@@ -344,13 +331,12 @@ async function fixSourceMaps(distDir, srcDir) {
|
|
|
344
331
|
}
|
|
345
332
|
function getEsbuildOptions(files) {
|
|
346
333
|
const cedarPaths = getPaths();
|
|
347
|
-
const format = projectSideIsEsm("api") ? "esm" : "cjs";
|
|
348
334
|
return {
|
|
349
335
|
absWorkingDir: cedarPaths.api.base,
|
|
350
336
|
entryPoints: files,
|
|
351
337
|
platform: "node",
|
|
352
338
|
target: "node24",
|
|
353
|
-
format,
|
|
339
|
+
format: "esm",
|
|
354
340
|
allowOverwrite: true,
|
|
355
341
|
bundle: false,
|
|
356
342
|
// Registration order matters: cedarApiGraphqlPlugin (narrow filter) must
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"esbuild-plugin-api-graphql.d.ts","sourceRoot":"","sources":["../../src/build/esbuild-plugin-api-graphql.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAsB1C,eAAO,MAAM,qBAAqB;;iBAEnB,WAAW;
|
|
1
|
+
{"version":3,"file":"esbuild-plugin-api-graphql.d.ts","sourceRoot":"","sources":["../../src/build/esbuild-plugin-api-graphql.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAsB1C,eAAO,MAAM,qBAAqB;;iBAEnB,WAAW;CA8GzB,CAAA"}
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
getApiSideBabelPluginsForVite,
|
|
6
6
|
transformWithBabel
|
|
7
7
|
} from "@cedarjs/babel-config";
|
|
8
|
-
import { getConfig, getPaths
|
|
8
|
+
import { getConfig, getPaths } from "@cedarjs/project-config";
|
|
9
9
|
import {
|
|
10
10
|
applyGqlormInject,
|
|
11
11
|
applyGraphqlOptionsExtract
|
|
@@ -59,9 +59,7 @@ const cedarApiGraphqlPlugin = {
|
|
|
59
59
|
if (cedarConfig.experimental?.opentelemetry?.enabled && cedarConfig.experimental?.opentelemetry?.wrapApi) {
|
|
60
60
|
code = applyOtelWrapping(code, args.path, getPaths().api.src) ?? code;
|
|
61
61
|
}
|
|
62
|
-
code = applyHandlerAlsWrapping(code
|
|
63
|
-
projectIsEsm: projectSideIsEsm("api")
|
|
64
|
-
}) ?? code;
|
|
62
|
+
code = applyHandlerAlsWrapping(code) ?? code;
|
|
65
63
|
return {
|
|
66
64
|
contents: code,
|
|
67
65
|
// Babel output is always plain JS. Without Babel the contents are
|
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
export declare function applyHandlerAlsWrapping(code: string
|
|
2
|
-
projectIsEsm?: boolean;
|
|
3
|
-
}): string | null;
|
|
1
|
+
export declare function applyHandlerAlsWrapping(code: string): string | null;
|
|
4
2
|
//# sourceMappingURL=esbuild-plugin-handler-als-wrapping.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"esbuild-plugin-handler-als-wrapping.d.ts","sourceRoot":"","sources":["../../src/build/esbuild-plugin-handler-als-wrapping.ts"],"names":[],"mappings":"AAOA,wBAAgB,uBAAuB,
|
|
1
|
+
{"version":3,"file":"esbuild-plugin-handler-als-wrapping.d.ts","sourceRoot":"","sources":["../../src/build/esbuild-plugin-handler-als-wrapping.ts"],"names":[],"mappings":"AAOA,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAsCnE"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function applyHandlerAlsWrapping(code
|
|
1
|
+
function applyHandlerAlsWrapping(code) {
|
|
2
2
|
const handlerRe = /^export\s+(?:const|let|var)\s+handler(?:[^=]|=>)*?=(?![>=])/m;
|
|
3
3
|
const handlerMatch = handlerRe.exec(code);
|
|
4
4
|
if (!handlerMatch) {
|
|
@@ -6,8 +6,7 @@ function applyHandlerAlsWrapping(code, { projectIsEsm = false } = {}) {
|
|
|
6
6
|
}
|
|
7
7
|
const afterEquals = code.slice(handlerMatch.index + handlerMatch[0].length).trimStart();
|
|
8
8
|
const isAsync = /^async(?:\s*[\(\*]|\s+function)/.test(afterEquals);
|
|
9
|
-
const
|
|
10
|
-
const importStatement = `import { getAsyncStoreInstance as __cedar_getAsyncStoreInstance } from '${storePath}'
|
|
9
|
+
const importStatement = `import { getAsyncStoreInstance as __cedar_getAsyncStoreInstance } from '@cedarjs/context/dist/store.js'
|
|
11
10
|
`;
|
|
12
11
|
const handlerStart = handlerMatch.index;
|
|
13
12
|
const before = code.slice(0, handlerStart);
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAA;AAEvC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAA;AAEvC,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAE3B,cAAc,YAAY,CAAA;AAC1B,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAA;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAEzC,cAAc,qBAAqB,CAAA;AAGnC,cAAc,uBAAuB,CAAA;AAErC,OAAO,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAA"}
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/internal",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.3-next.227",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/cedarjs/cedar.git",
|
|
@@ -52,12 +52,6 @@
|
|
|
52
52
|
"default": "./dist/routes.js"
|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
|
-
"./dist/ts2js": {
|
|
56
|
-
"default": {
|
|
57
|
-
"types": "./dist/ts2js.d.ts",
|
|
58
|
-
"default": "./dist/ts2js.js"
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
55
|
"./dist/validateSchema": {
|
|
62
56
|
"default": {
|
|
63
57
|
"types": "./dist/validateSchema.d.ts",
|
|
@@ -119,16 +113,15 @@
|
|
|
119
113
|
"dependencies": {
|
|
120
114
|
"@babel/core": "^7.26.10",
|
|
121
115
|
"@babel/parser": "7.29.8",
|
|
122
|
-
"@babel/plugin-transform-typescript": "^7.26.8",
|
|
123
116
|
"@babel/traverse": "7.29.8",
|
|
124
|
-
"@cedarjs/api": "6.0.
|
|
125
|
-
"@cedarjs/babel-config": "6.0.
|
|
126
|
-
"@cedarjs/cli-helpers": "6.0.
|
|
127
|
-
"@cedarjs/graphql-server": "6.0.
|
|
128
|
-
"@cedarjs/project-config": "6.0.
|
|
129
|
-
"@cedarjs/router": "6.0.
|
|
130
|
-
"@cedarjs/structure": "6.0.
|
|
131
|
-
"@cedarjs/utils": "6.0.
|
|
117
|
+
"@cedarjs/api": "6.0.3-next.227",
|
|
118
|
+
"@cedarjs/babel-config": "6.0.3-next.227",
|
|
119
|
+
"@cedarjs/cli-helpers": "6.0.3-next.227",
|
|
120
|
+
"@cedarjs/graphql-server": "6.0.3-next.227",
|
|
121
|
+
"@cedarjs/project-config": "6.0.3-next.227",
|
|
122
|
+
"@cedarjs/router": "6.0.3-next.227",
|
|
123
|
+
"@cedarjs/structure": "6.0.3-next.227",
|
|
124
|
+
"@cedarjs/utils": "6.0.3-next.227",
|
|
132
125
|
"@graphql-codegen/add": "6.0.1",
|
|
133
126
|
"@graphql-codegen/cli": "6.3.1",
|
|
134
127
|
"@graphql-codegen/client-preset": "5.3.0",
|
|
@@ -140,12 +133,12 @@
|
|
|
140
133
|
"@graphql-codegen/typescript-operations": "5.1.0",
|
|
141
134
|
"@graphql-codegen/typescript-resolvers": "5.1.8",
|
|
142
135
|
"@graphql-codegen/visitor-plugin-common": "6.3.0",
|
|
143
|
-
"@graphql-tools/code-file-loader": "8.1.
|
|
144
|
-
"@graphql-tools/graphql-file-loader": "8.1.
|
|
145
|
-
"@graphql-tools/load": "8.1.
|
|
146
|
-
"@graphql-tools/merge": "9.2.
|
|
147
|
-
"@prisma/dmmf": "7.
|
|
148
|
-
"@prisma/internals": "7.
|
|
136
|
+
"@graphql-tools/code-file-loader": "8.1.39",
|
|
137
|
+
"@graphql-tools/graphql-file-loader": "8.1.20",
|
|
138
|
+
"@graphql-tools/load": "8.1.17",
|
|
139
|
+
"@graphql-tools/merge": "9.2.4",
|
|
140
|
+
"@prisma/dmmf": "7.10.0",
|
|
141
|
+
"@prisma/internals": "7.10.0",
|
|
149
142
|
"@sdl-codegen/node": "2.0.1",
|
|
150
143
|
"ansis": "4.3.1",
|
|
151
144
|
"chokidar": "3.6.0",
|
|
@@ -155,8 +148,8 @@
|
|
|
155
148
|
"graphql": "16.14.2",
|
|
156
149
|
"kill-port": "1.6.1",
|
|
157
150
|
"magic-string": "0.30.21",
|
|
158
|
-
"oxc-parser": "0.
|
|
159
|
-
"prettier": "3.
|
|
151
|
+
"oxc-parser": "0.149.0",
|
|
152
|
+
"prettier": "3.9.6",
|
|
160
153
|
"rimraf": "6.1.3",
|
|
161
154
|
"source-map": "0.8.0",
|
|
162
155
|
"termi-link": "1.1.0",
|
|
@@ -166,12 +159,12 @@
|
|
|
166
159
|
"vite-tsconfig-paths": "^6.1.1"
|
|
167
160
|
},
|
|
168
161
|
"devDependencies": {
|
|
169
|
-
"@cedarjs/framework-tools": "6.0.
|
|
162
|
+
"@cedarjs/framework-tools": "6.0.3-next.227",
|
|
170
163
|
"@jridgewell/trace-mapping": "0.3.31",
|
|
171
|
-
"@oxc-project/types": "^0.
|
|
164
|
+
"@oxc-project/types": "^0.149.0",
|
|
172
165
|
"concurrently": "9.2.4",
|
|
173
|
-
"graphql-tag": "2.12.
|
|
174
|
-
"memfs": "4.
|
|
166
|
+
"graphql-tag": "2.12.7",
|
|
167
|
+
"memfs": "4.76.0",
|
|
175
168
|
"publint": "0.3.24",
|
|
176
169
|
"ts-dedent": "2.3.0",
|
|
177
170
|
"vitest": "4.1.11"
|
package/dist/ts2js.d.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Converts all the TypeScript files in the `api` and `web` sides to JavaScript.
|
|
3
|
-
*
|
|
4
|
-
* @param {string} cwd - The base path to the project.
|
|
5
|
-
*/
|
|
6
|
-
export declare const convertTsProjectToJs: (cwd?: string) => void;
|
|
7
|
-
/**
|
|
8
|
-
* Converts all the TypeScript files in the `api` and `web` sides to JavaScript.
|
|
9
|
-
*
|
|
10
|
-
* @param {string} cwd - The base path to the project.
|
|
11
|
-
*/
|
|
12
|
-
export declare const convertTsScriptsToJs: (cwd?: string) => void;
|
|
13
|
-
/**
|
|
14
|
-
* Converts TypeScript files to JavaScript.
|
|
15
|
-
*
|
|
16
|
-
* @param {string} cwd - Current directory
|
|
17
|
-
* @param {string[]} files - Collection of files to convert
|
|
18
|
-
*/
|
|
19
|
-
export declare const convertTsFilesToJs: (cwd: string, files: string[]) => Promise<void>;
|
|
20
|
-
/**
|
|
21
|
-
* Get all the source code from a Redwood project
|
|
22
|
-
*/
|
|
23
|
-
export declare const typeScriptSourceFiles: (cwd: string, globPattern?: string) => string[];
|
|
24
|
-
/**
|
|
25
|
-
* Read the contents of a TypeScript file, transpile it to JavaScript,
|
|
26
|
-
* but leave the JSX intact and format via Prettier.
|
|
27
|
-
*
|
|
28
|
-
* @param {string} file - The path to the TypeScript file.
|
|
29
|
-
*/
|
|
30
|
-
export declare const transformTSToJS: (file: string) => Promise<string> | undefined;
|
|
31
|
-
export declare const getPrettierConfig: () => Promise<any>;
|
|
32
|
-
/**
|
|
33
|
-
* Prettify `code` according to the extension in `filename`.
|
|
34
|
-
* This will also read a user's `prettier.config.cjs` file if it exists.
|
|
35
|
-
*
|
|
36
|
-
* @param {string} code
|
|
37
|
-
* @param {string} filename
|
|
38
|
-
*/
|
|
39
|
-
export declare const prettify: (code: string, filename: string) => Promise<string>;
|
|
40
|
-
//# sourceMappingURL=ts2js.d.ts.map
|
package/dist/ts2js.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ts2js.d.ts","sourceRoot":"","sources":["../src/ts2js.ts"],"names":[],"mappings":"AASA;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,GAAI,YAAqB,SAGzD,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,GAAI,YAAqB,SAGzD,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAAU,KAAK,MAAM,EAAE,OAAO,MAAM,EAAE,kBAkCpE,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,qBAAqB,GAChC,KAAK,MAAM,EACX,oBAA2C,aAS5C,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,eAAe,GAAI,MAAM,MAAM,gCAwB3C,CAAA;AAED,eAAO,MAAM,iBAAiB,oBAS7B,CAAA;AAsBD;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,GAAU,MAAM,MAAM,EAAE,UAAU,MAAM,oBAa5D,CAAA"}
|
package/dist/ts2js.js
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import { transform } from "@babel/core";
|
|
4
|
-
import fg from "fast-glob";
|
|
5
|
-
import { format } from "prettier";
|
|
6
|
-
import { getPaths } from "@cedarjs/project-config";
|
|
7
|
-
const convertTsProjectToJs = (cwd = getPaths().base) => {
|
|
8
|
-
const files = typeScriptSourceFiles(cwd);
|
|
9
|
-
convertTsFilesToJs(cwd, files);
|
|
10
|
-
};
|
|
11
|
-
const convertTsScriptsToJs = (cwd = getPaths().base) => {
|
|
12
|
-
const files = typeScriptSourceFiles(cwd, "scripts/*.{ts,tsx}");
|
|
13
|
-
convertTsFilesToJs(cwd, files);
|
|
14
|
-
};
|
|
15
|
-
const convertTsFilesToJs = async (cwd, files) => {
|
|
16
|
-
if (files.length === 0) {
|
|
17
|
-
console.log("No TypeScript files found to convert to JS in this project.");
|
|
18
|
-
}
|
|
19
|
-
for (const f of files) {
|
|
20
|
-
const code = await transformTSToJS(f);
|
|
21
|
-
if (code) {
|
|
22
|
-
fs.writeFileSync(
|
|
23
|
-
path.join(cwd, f.replace(".tsx", ".jsx").replace(".ts", ".js")),
|
|
24
|
-
code,
|
|
25
|
-
"utf8"
|
|
26
|
-
);
|
|
27
|
-
fs.unlinkSync(path.join(cwd, f));
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
if (fs.existsSync(path.join(cwd, "api/tsconfig.json"))) {
|
|
31
|
-
fs.renameSync(
|
|
32
|
-
path.join(cwd, "api/tsconfig.json"),
|
|
33
|
-
path.join(cwd, "api/jsconfig.json")
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
if (fs.existsSync(path.join(cwd, "web/tsconfig.json"))) {
|
|
37
|
-
fs.renameSync(
|
|
38
|
-
path.join(cwd, "web/tsconfig.json"),
|
|
39
|
-
path.join(cwd, "web/jsconfig.json")
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
if (fs.existsSync(path.join(cwd, "scripts/tsconfig.json"))) {
|
|
43
|
-
fs.renameSync(
|
|
44
|
-
path.join(cwd, "scripts/tsconfig.json"),
|
|
45
|
-
path.join(cwd, "scripts/jsconfig.json")
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
const typeScriptSourceFiles = (cwd, globPattern = "{api,web}/src/**/*.{ts,tsx}") => {
|
|
50
|
-
console.log(globPattern);
|
|
51
|
-
return fg.sync(globPattern, {
|
|
52
|
-
cwd,
|
|
53
|
-
ignore: ["node_modules"]
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
const transformTSToJS = (file) => {
|
|
57
|
-
const tsCode = fs.readFileSync(file, "utf8");
|
|
58
|
-
const filename = path.basename(file);
|
|
59
|
-
const result = transform(tsCode, {
|
|
60
|
-
filename,
|
|
61
|
-
cwd: getPaths().base,
|
|
62
|
-
configFile: false,
|
|
63
|
-
plugins: [
|
|
64
|
-
[
|
|
65
|
-
"@babel/plugin-transform-typescript",
|
|
66
|
-
{
|
|
67
|
-
isTSX: true,
|
|
68
|
-
allExtensions: true
|
|
69
|
-
}
|
|
70
|
-
]
|
|
71
|
-
],
|
|
72
|
-
retainLines: true
|
|
73
|
-
});
|
|
74
|
-
if (!result?.code) {
|
|
75
|
-
return void 0;
|
|
76
|
-
}
|
|
77
|
-
return prettify(result.code, filename.replace(/\.ts$/, ".js"));
|
|
78
|
-
};
|
|
79
|
-
const getPrettierConfig = async () => {
|
|
80
|
-
try {
|
|
81
|
-
const { default: prettierConfig } = await import(`file://${path.join(getPaths().base, "prettier.config.cjs")}`);
|
|
82
|
-
return prettierConfig;
|
|
83
|
-
} catch {
|
|
84
|
-
return void 0;
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
const prettierParser = (filename) => {
|
|
88
|
-
switch (path.extname(filename.replace(".template", ""))) {
|
|
89
|
-
case ".css":
|
|
90
|
-
return "css";
|
|
91
|
-
case ".js":
|
|
92
|
-
return "babel";
|
|
93
|
-
case ".ts":
|
|
94
|
-
case ".tsx":
|
|
95
|
-
return "babel-ts";
|
|
96
|
-
default:
|
|
97
|
-
return void 0;
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
const prettify = async (code, filename) => {
|
|
101
|
-
const parser = prettierParser(filename);
|
|
102
|
-
if (typeof parser === "undefined") {
|
|
103
|
-
return code;
|
|
104
|
-
}
|
|
105
|
-
const prettierConfig = await getPrettierConfig();
|
|
106
|
-
return format(code, {
|
|
107
|
-
...prettierConfig,
|
|
108
|
-
parser
|
|
109
|
-
});
|
|
110
|
-
};
|
|
111
|
-
export {
|
|
112
|
-
convertTsFilesToJs,
|
|
113
|
-
convertTsProjectToJs,
|
|
114
|
-
convertTsScriptsToJs,
|
|
115
|
-
getPrettierConfig,
|
|
116
|
-
prettify,
|
|
117
|
-
transformTSToJS,
|
|
118
|
-
typeScriptSourceFiles
|
|
119
|
-
};
|