@snowtop/ent 0.1.20 → 0.1.21

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/core/config.d.ts CHANGED
@@ -52,6 +52,7 @@ interface CodegenConfig {
52
52
  userOveriddenFiles?: string[];
53
53
  transformLoadMethod?: string;
54
54
  transformDeleteMethod?: string;
55
+ disableDefaultExportForActions?: boolean;
55
56
  }
56
57
  interface PrettierConfig {
57
58
  custom?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowtop/ent",
3
- "version": "0.1.20",
3
+ "version": "0.1.21",
4
4
  "description": "snowtop ent framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const ast_1 = require("../tsc/ast");
27
+ const transform_1 = require("../tsc/transform");
28
+ const typescript_1 = __importStar(require("typescript"));
29
+ class FixActionExports {
30
+ constructor() {
31
+ this.glob = "src/ent/**/actions/*_action.ts";
32
+ this.prettierGlob = "src/ent/**/actions/*_action.ts";
33
+ }
34
+ traverseChild(sourceFile, contents, file, node) {
35
+ if (!(0, typescript_1.isClassDeclaration)(node)) {
36
+ return { node };
37
+ }
38
+ // only Action classes
39
+ if (!node.name?.text.endsWith("Action")) {
40
+ return { node };
41
+ }
42
+ const modifiers = typescript_1.default.canHaveModifiers(node)
43
+ ? typescript_1.default.getModifiers(node)
44
+ : undefined;
45
+ const exported = modifiers?.filter((mod) => mod.getText(sourceFile) === "export");
46
+ const defaultExport = modifiers?.filter((mod) => mod.getText(sourceFile) === "default");
47
+ // for now, we're only supporting changing from default -> non-default
48
+ // trivial to support the other way around but don't need it yet
49
+ if (!exported?.length || !defaultExport?.length) {
50
+ return { node };
51
+ }
52
+ let classInfo = (0, ast_1.getClassInfo)(contents, sourceFile, node, {
53
+ hasExport: true,
54
+ hasDefault: false,
55
+ });
56
+ if (!classInfo) {
57
+ // somehow don't have classInfo, bye
58
+ return { node };
59
+ }
60
+ let klassContents = "";
61
+ for (const mm of node.members) {
62
+ klassContents += mm.getFullText(sourceFile);
63
+ }
64
+ return {
65
+ traversed: true,
66
+ rawString: classInfo.wrapClassContents(klassContents),
67
+ };
68
+ }
69
+ }
70
+ // ts-node-script --swc --project ./tsconfig.json -r tsconfig-paths/register ../../ts/src/scripts/fix_action_exports.ts
71
+ function main() {
72
+ const f = new FixActionExports();
73
+ (0, transform_1.transform)(f);
74
+ }
75
+ main();
package/tsc/ast.d.ts CHANGED
@@ -9,7 +9,10 @@ export interface ClassInfo {
9
9
  implements?: string[];
10
10
  wrapClassContents(inner: string): string;
11
11
  }
12
- export declare function getClassInfo(fileContents: string, sourceFile: ts.SourceFile, node: ts.ClassDeclaration): ClassInfo | undefined;
12
+ export declare function getClassInfo(fileContents: string, sourceFile: ts.SourceFile, node: ts.ClassDeclaration, override?: {
13
+ hasExport: boolean;
14
+ hasDefault: boolean;
15
+ }): ClassInfo | undefined;
13
16
  type transformImportFn = (imp: string) => string;
14
17
  interface transformOpts {
15
18
  removeImports?: string[];
package/tsc/ast.js CHANGED
@@ -36,7 +36,7 @@ function getPreText(fileContents, node, sourceFile) {
36
36
  return fileContents.substring(node.getFullStart(), node.getStart(sourceFile));
37
37
  }
38
38
  exports.getPreText = getPreText;
39
- function getClassInfo(fileContents, sourceFile, node) {
39
+ function getClassInfo(fileContents, sourceFile, node, override) {
40
40
  let className = node.name?.text;
41
41
  let classExtends;
42
42
  let impl = [];
@@ -83,7 +83,11 @@ function getClassInfo(fileContents, sourceFile, node) {
83
83
  ${inner}
84
84
  }`;
85
85
  };
86
- if (node.modifiers) {
86
+ if (override) {
87
+ hasExport = override.hasExport;
88
+ hasDefault = override.hasDefault;
89
+ }
90
+ else if (node.modifiers) {
87
91
  for (const mod of node.modifiers) {
88
92
  const text = mod.getText(sourceFile);
89
93
  if (text === "export") {
package/tsc/transform.js CHANGED
@@ -168,7 +168,7 @@ function transform(transform) {
168
168
  }
169
169
  });
170
170
  if (transform.prettierGlob) {
171
- (0, child_process_1.execSync)(`prettier ${transform.prettierGlob} --write`);
171
+ (0, child_process_1.spawnSync)(`prettier`, [transform.prettierGlob, "--write"]);
172
172
  }
173
173
  }
174
174
  exports.transform = transform;