rbxts-transformer-commit-migrations 1.0.0 → 1.0.2

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/bin/init.js CHANGED
@@ -11,19 +11,20 @@ const huskyDir = resolve(dir, ".husky");
11
11
  const hookFile = resolve(huskyDir, "pre-commit");
12
12
 
13
13
  if (!existsSync(huskyDir)) {
14
- console.error("No .husky folder found. Run `npx husky init` first.");
15
- process.exit(1);
14
+ console.error("No .husky folder found. Run `npx husky init` first.");
15
+ process.exit(1);
16
16
  }
17
17
 
18
18
  const setupResolve = `npx resolve-commit-migrations\n`;
19
19
 
20
20
  if (existsSync(hookFile)) {
21
- const existing = readFileSync(hookFile, "utf-8");
22
- if (!existing.includes(setupResolve)) {
23
- writeFileSync(hookFile, existing + setupResolve);
24
- }
21
+ const existing = readFileSync(hookFile, "utf-8");
22
+
23
+ if (!existing.includes(setupResolve)) {
24
+ writeFileSync(hookFile, existing + `\n${setupResolve}`);
25
+ }
25
26
  } else {
26
- writeFileSync(hookFile, `#!/bin/sh\n${setupResolve}`);
27
+ writeFileSync(hookFile, setupResolve);
27
28
  }
28
29
 
29
- console.log("Added rbxts-macro stamp to .husky/pre-commit");
30
+ console.log("Added commit-migration macro stamp to .husky/pre-commit");
package/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- declare function $migrate(order: number): never;
2
- declare function $migrate(order: "__resolved"): number;
3
- declare function $migrate(order: number | "__resolved"): number?;
1
+ export declare function $migrate(order: number): never;
2
+ export declare function $migrate(order: "__resolved"): number;
3
+ export declare function $migrate(order: number | "__resolved"): number | undefined;
@@ -29,11 +29,7 @@ function walk(node, ctx) {
29
29
  const entry = findEntryName(node);
30
30
  const orderArg = node.arguments[0];
31
31
  const order = orderArg ? ts.isNumericLiteral(orderArg) ? parseInt(orderArg.getText()) : null : 0;
32
- if (order === null) {
33
- console.error("Recieved null order when resolving migration macros.");
34
- process.exit(1);
35
- }
36
- if (usedOrders.has(order)) {
32
+ if (order !== null && usedOrders.has(order)) {
37
33
  console.error("Multiple of the same migration orders found. Every migration has to have a unique order.");
38
34
  process.exit(1);
39
35
  }
@@ -42,8 +38,10 @@ function walk(node, ctx) {
42
38
  process.exit(1);
43
39
  }
44
40
  if (!orderArg?.getText().includes("__resolved")) {
41
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
45
42
  usedOrders.add(order);
46
- migrationData[entry] = { timestamp: Date.now(), order };
43
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
44
+ migrationData[entry] = { timestamp: Date.now(), order: order };
47
45
  ctx.changed = true;
48
46
  }
49
47
  migrations.push(entry);
package/out/index.js CHANGED
@@ -2,19 +2,26 @@ import ts from "typescript";
2
2
  import { findMacroCall, replaceMacroCall } from "./macro.js";
3
3
  import loadMigrationEntries from "./util/loadMigrationEntries.js";
4
4
  import { CONFIG } from "./config.js";
5
- export default function (_) {
5
+ import { existsSync } from "node:fs";
6
+ export default function (_, config) {
6
7
  return (ctx) => {
8
+ const configPath = config?.configPath ?? CONFIG;
9
+ if (!existsSync(configPath)) {
10
+ console.error(`Invalid migration config path ${configPath}`);
11
+ process.exit(1);
12
+ }
13
+ const [entryArr, entries] = loadMigrationEntries(configPath);
14
+ const orderedEntries = entryArr
15
+ .map((i) => ({ i, timestamp: entries[i].timestamp, order: entries[i].order }))
16
+ .toSorted((a, b) => a.timestamp - b.timestamp || a.order - b.order)
17
+ .map(({ i }) => i);
7
18
  return (file) => {
8
- const [entryArr, entries] = loadMigrationEntries(CONFIG);
9
- const orderedEntries = entryArr
10
- .map((i) => ({ i, timestamp: entries[i].timestamp, order: entries[i].order }))
11
- .toSorted((a, b) => a.timestamp - b.timestamp || a.order - b.order)
12
- .map(({ i }) => i);
13
- console.log(orderedEntries);
19
+ if (config?.files && !config.files.some((f) => file.fileName.includes(f)))
20
+ return file;
14
21
  function visit(node) {
15
22
  if (!ts.isPropertyAssignment(node) || !findMacroCall(node.initializer))
16
23
  return ts.visitEachChild(node, visit, ctx);
17
- const entry = node.name.getText(file);
24
+ const entry = ts.isIdentifier(node.name) ? node.name.text : node.name.getText(file);
18
25
  const replacement = orderedEntries.indexOf(entry);
19
26
  if (replacement !== -1) {
20
27
  const newInit = replaceMacroCall(node.initializer, replacement);
@@ -30,7 +30,6 @@ export default function (config) {
30
30
  continue;
31
31
  result.push(prop.name.text);
32
32
  object[prop.name.text] = reconstructProperties(prop.initializer.properties);
33
- console.log(reconstructProperties(prop.initializer.properties));
34
33
  }
35
34
  return [result, object];
36
35
  }
package/package.json CHANGED
@@ -1,9 +1,8 @@
1
1
  {
2
2
  "name": "rbxts-transformer-commit-migrations",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "rbxts transformer used in user data migration builder chains",
5
5
  "main": "out/index.js",
6
- "typegis": "index.d.ts",
7
6
  "type": "module",
8
7
  "scripts": {
9
8
  "build": "tsc"