two-stroke 1.0.14 → 1.0.15

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/test.ts +21 -13
package/package.json CHANGED
@@ -51,7 +51,7 @@
51
51
  "name": "two-stroke",
52
52
  "packageManager": "yarn@4.1.0",
53
53
  "type": "module",
54
- "version": "1.0.14",
54
+ "version": "1.0.15",
55
55
  "devDependencies": {
56
56
  "@types/eslint": "^8.56.9",
57
57
  "@types/node": "^20.12.7",
package/src/test.ts CHANGED
@@ -65,21 +65,29 @@ export const setupTests = async <Paths extends {}>(bindings: Env) => {
65
65
  const d1 = await miniflare.getD1Database(binding);
66
66
 
67
67
  const migrationsDir = "./migrations";
68
- for (const migrationName of (await nodefs.readdir(migrationsDir)).sort(
69
- (a, b) => {
70
- const migrationNumberA = parseInt(a.split("_")[0]!);
71
- const migrationNumberB = parseInt(b.split("_")[0]!);
72
- if (migrationNumberA < migrationNumberB) {
73
- return -1;
74
- }
75
- if (migrationNumberA > migrationNumberB) {
76
- return 1;
77
- }
68
+ let fileNames: string[] = [];
69
+ try {
70
+ fileNames = await nodefs.readdir(migrationsDir);
71
+ } catch (error) {
72
+ console.log("Error loading migrations", error);
73
+ }
74
+
75
+ if (fileNames.length === 0)
76
+ console.log("No migrations found in ./migrations");
78
77
 
79
- // numbers must be equal
80
- return 0;
78
+ for (const migrationName of fileNames.sort((a, b) => {
79
+ const migrationNumberA = parseInt(a.split("_")[0]!);
80
+ const migrationNumberB = parseInt(b.split("_")[0]!);
81
+ if (migrationNumberA < migrationNumberB) {
82
+ return -1;
81
83
  }
82
- )) {
84
+ if (migrationNumberA > migrationNumberB) {
85
+ return 1;
86
+ }
87
+
88
+ // numbers must be equal
89
+ return 0;
90
+ })) {
83
91
  const migrationPath = path.join(migrationsDir, migrationName);
84
92
  let migration = await nodefs.readFile(migrationPath, "utf8");
85
93
  // Remove migration comment