@cedarjs/cli-helpers 7.0.0-canary.3009 → 7.0.0-canary.3012

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 CHANGED
@@ -4,6 +4,7 @@ export { loadEnvFiles } from './lib/loadEnvFiles.js';
4
4
  export { loadDefaultEnvFiles, loadNodeEnvDerivedEnvFile, loadUserSpecifiedEnvFiles, } from './lib/loadEnvFiles.js';
5
5
  export * from './lib/paths.js';
6
6
  export * from './lib/project.js';
7
+ export * from './lib/transpileTSToJS.js';
7
8
  export * from './lib/version.js';
8
9
  export * from './auth/setupHelpers.js';
9
10
  export type { AuthHandlerArgs, AuthGeneratorCtx } from './auth/setupHelpers.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACpD,OAAO,EACL,mBAAmB,EACnB,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,uBAAuB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA;AAChC,cAAc,wBAAwB,CAAA;AACtC,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAE/E,cAAc,yBAAyB,CAAA;AAEvC,cAAc,sBAAsB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACpD,OAAO,EACL,mBAAmB,EACnB,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,uBAAuB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kBAAkB,CAAA;AAChC,cAAc,0BAA0B,CAAA;AACxC,cAAc,kBAAkB,CAAA;AAChC,cAAc,wBAAwB,CAAA;AACtC,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAE/E,cAAc,yBAAyB,CAAA;AAEvC,cAAc,sBAAsB,CAAA"}
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ import {
8
8
  } from "./lib/loadEnvFiles.js";
9
9
  export * from "./lib/paths.js";
10
10
  export * from "./lib/project.js";
11
+ export * from "./lib/transpileTSToJS.js";
11
12
  export * from "./lib/version.js";
12
13
  export * from "./auth/setupHelpers.js";
13
14
  export * from "./lib/installHelpers.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,gBAAgB,EAChB,aAAa,EAEd,MAAM,QAAQ,CAAA;AACf,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AAU9B,eAAO,MAAM,eAAe,GAAI,UAAU,MAAM,EAAE,SAAS,MAAM,6BA8BhE,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,kBAAkB,oBAsB9B,CAAA;AAED,eAAO,MAAM,QAAQ,GACnB,kBAAkB,MAAM,EACxB,kBAAkB,MAAM,KACvB,OAAO,CAAC,MAAM,CAwBhB,CAAA;AAED,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG,MAAM,GAAG,MAAM,CAAA;AAEzD,eAAO,MAAM,SAAS,GAAI,QAAQ,SAAS,OAAO,aAAa,EAC7D,QAAQ,MAAM,EACd,UAAU,MAAM,EAChB,oBAA4B;IAAE,aAAa,CAAC,EAAE,aAAa,CAAA;CAAO,EAGlE,OAAM,gBAAgB,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAI/C,SAoBF,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,cAAc,GAAI,QAAQ,SAAS,OAAO,aAAa,EAClE,OAAO,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC7B,SAAS;IAAE,aAAa,EAAE,aAAa,CAAA;CAAE,qCAuB1C,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,gBAAgB,EAChB,aAAa,EAEd,MAAM,QAAQ,CAAA;AACf,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AAW9B,eAAO,MAAM,eAAe,GAAI,UAAU,MAAM,EAAE,SAAS,MAAM,6BAgBhE,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,kBAAkB,oBAsB9B,CAAA;AAED,eAAO,MAAM,QAAQ,GACnB,kBAAkB,MAAM,EACxB,kBAAkB,MAAM,KACvB,OAAO,CAAC,MAAM,CAwBhB,CAAA;AAED,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG,MAAM,GAAG,MAAM,CAAA;AAEzD,eAAO,MAAM,SAAS,GAAI,QAAQ,SAAS,OAAO,aAAa,EAC7D,QAAQ,MAAM,EACd,UAAU,MAAM,EAChB,oBAA4B;IAAE,aAAa,CAAC,EAAE,aAAa,CAAA;CAAO,EAGlE,OAAM,gBAAgB,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAI/C,SAoBF,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,cAAc,GAAI,QAAQ,SAAS,OAAO,aAAa,EAClE,OAAO,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC7B,SAAS;IAAE,aAAa,EAAE,aAAa,CAAA;CAAE,qCAuB1C,CAAA"}
package/dist/lib/index.js CHANGED
@@ -1,37 +1,23 @@
1
1
  import fs from "node:fs";
2
2
  import { pathToFileURL } from "node:url";
3
3
  import path from "path";
4
- import * as babel from "@babel/core";
5
4
  import { Listr } from "listr2";
6
5
  import { format } from "prettier";
7
6
  import { colors } from "./colors.js";
8
7
  import { getPaths } from "./paths.js";
8
+ import { transpileTSToJS } from "./transpileTSToJS.js";
9
9
  const transformTSToJS = (filename, content) => {
10
10
  if (!content) {
11
11
  return content;
12
12
  }
13
- const babelFileResult = babel.transform(content, {
14
- filename,
15
- // If you ran `yarn cedar generate` in `./web` transformSync would import the `.babelrc.js` file,
16
- // in `./web`? despite us setting `configFile: false`.
17
- cwd: process.env.NODE_ENV === "test" ? void 0 : getPaths().base,
18
- configFile: false,
19
- plugins: [
20
- [
21
- "@babel/plugin-transform-typescript",
22
- {
23
- isTSX: true,
24
- allExtensions: true
25
- }
26
- ]
27
- ],
28
- retainLines: true
29
- });
30
- if (!babelFileResult?.code) {
31
- console.error(colors.error(`Could not transform ${filename} to JS`));
13
+ let code;
14
+ try {
15
+ code = transpileTSToJS(filename, content);
16
+ } catch (e) {
17
+ console.error(colors.error(e instanceof Error ? e.message : String(e)));
32
18
  process.exit(1);
33
19
  }
34
- return prettify(filename.replace(/\.ts(x)?$/, ".js$1"), babelFileResult.code);
20
+ return prettify(filename.replace(/\.ts(x)?$/, ".js$1"), code);
35
21
  };
36
22
  const getPrettierOptions = async () => {
37
23
  try {
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Strips the TypeScript syntax from `content` and returns the resulting
3
+ * JavaScript source. Everything that is not TypeScript syntax, including JSX,
4
+ * comments, blank lines and indentation, is kept byte-for-byte, so the output
5
+ * only needs formatting.
6
+ *
7
+ * `import type` statements, `type` specifiers and imports whose bindings are
8
+ * only used as types are removed. Lines that only held removed syntax (for
9
+ * example an `import type` line or an `interface` body) are dropped so they
10
+ * do not turn into stray blank lines.
11
+ *
12
+ * `filename` is used for error messages. The content is always parsed as TSX
13
+ * because templates can contain JSX regardless of their extension.
14
+ *
15
+ * Throws when sucrase reports a syntax error.
16
+ */
17
+ export declare function transpileTSToJS(filename: string, content: string): string;
18
+ //# sourceMappingURL=transpileTSToJS.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transpileTSToJS.d.ts","sourceRoot":"","sources":["../../src/lib/transpileTSToJS.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,UAwBhE"}
@@ -0,0 +1,38 @@
1
+ import { transform } from "sucrase";
2
+ const BLANK_LINE_REGEX = /^[ \t]*$/;
3
+ function transpileTSToJS(filename, content) {
4
+ let code;
5
+ try {
6
+ code = transform(content, {
7
+ // `jsx` is required to parse JSX at all. `jsxRuntime: 'preserve'` keeps
8
+ // the JSX untouched so the project's own build compiles it.
9
+ transforms: ["typescript", "jsx"],
10
+ jsxRuntime: "preserve",
11
+ // Keep modern ECMAScript syntax (optional chaining, class fields, ...)
12
+ // as written.
13
+ disableESTransforms: true,
14
+ keepUnusedImports: false,
15
+ filePath: filename
16
+ }).code;
17
+ } catch (e) {
18
+ const message = e instanceof Error ? e.message : String(e);
19
+ throw new Error(
20
+ `Could not transform ${filename} from TypeScript to JavaScript:
21
+ ${message}`
22
+ );
23
+ }
24
+ return dropEmptiedLines(content, code);
25
+ }
26
+ function dropEmptiedLines(input, output) {
27
+ const inputLines = input.split("\n");
28
+ const outputLines = output.split("\n");
29
+ if (inputLines.length !== outputLines.length) {
30
+ return output;
31
+ }
32
+ return outputLines.filter(
33
+ (line, index) => !BLANK_LINE_REGEX.test(line) || BLANK_LINE_REGEX.test(inputLines[index])
34
+ ).join("\n");
35
+ }
36
+ export {
37
+ transpileTSToJS
38
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/cli-helpers",
3
- "version": "7.0.0-canary.3009",
3
+ "version": "7.0.0-canary.3012",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/cedarjs/cedar.git",
@@ -72,9 +72,8 @@
72
72
  "test:watch": "vitest watch"
73
73
  },
74
74
  "dependencies": {
75
- "@babel/core": "^7.26.10",
76
- "@cedarjs/project-config": "7.0.0-canary.3009",
77
- "@cedarjs/telemetry": "7.0.0-canary.3009",
75
+ "@cedarjs/project-config": "7.0.0-canary.3012",
76
+ "@cedarjs/telemetry": "7.0.0-canary.3012",
78
77
  "@listr2/prompt-adapter-enquirer": "4.3.0",
79
78
  "@opentelemetry/api": "1.9.1",
80
79
  "ansis": "4.3.1",
@@ -89,11 +88,12 @@
89
88
  "prompts": "2.4.2",
90
89
  "semver": "7.8.5",
91
90
  "smol-toml": "1.8.0",
91
+ "sucrase": "3.35.1",
92
92
  "termi-link": "1.1.0",
93
93
  "yargs-parser": "21.1.1"
94
94
  },
95
95
  "devDependencies": {
96
- "@cedarjs/framework-tools": "7.0.0-canary.3009",
96
+ "@cedarjs/framework-tools": "7.0.0-canary.3012",
97
97
  "@types/dotenv-defaults": "^5.0.0",
98
98
  "@types/lodash": "4.17.25",
99
99
  "@types/pascalcase": "1.0.3",