sasat 0.20.5 → 0.21.0

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/cli/cli.cjs CHANGED
@@ -9,6 +9,7 @@ require('pluralize');
9
9
  const chalk = require('chalk');
10
10
  const console$1 = require('console');
11
11
  const ts = require('typescript');
12
+ const esbuild = require('esbuild');
12
13
  const fs$1 = require('fs-extra');
13
14
  require('js-yaml');
14
15
  const prettier = require('prettier');
@@ -37,6 +38,7 @@ const path__namespace = /*#__PURE__*/_interopNamespaceCompat(path);
37
38
  const chalk__default = /*#__PURE__*/_interopDefaultCompat(chalk);
38
39
  const console__namespace = /*#__PURE__*/_interopNamespaceCompat(console$1);
39
40
  const ts__default = /*#__PURE__*/_interopDefaultCompat(ts);
41
+ const esbuild__namespace = /*#__PURE__*/_interopNamespaceCompat(esbuild);
40
42
  const fs__default$1 = /*#__PURE__*/_interopDefaultCompat(fs$1);
41
43
  const prettier__namespace = /*#__PURE__*/_interopNamespaceCompat(prettier);
42
44
 
@@ -111,35 +113,6 @@ const getMigrationFileNames = () => {
111
113
  return fs__default.readdirSync(getMigrationFileDir()).filter((it) => it.split(".").pop() === "ts");
112
114
  };
113
115
 
114
- const getTsConfig = () => {
115
- const configFileName = ts__default.findConfigFile(
116
- "./",
117
- ts__default.sys.fileExists,
118
- "tsconfig.json"
119
- );
120
- if (!configFileName)
121
- return {
122
- module: ts__default.ModuleKind.ESNext
123
- };
124
- const configFile = ts__default.readConfigFile(configFileName, ts__default.sys.readFile);
125
- return {
126
- ...ts__default.parseJsonConfigFileContent(configFile.config, ts__default.sys, "./").options,
127
- module: ts__default.ModuleKind.ESNext
128
- };
129
- };
130
- const changeExtTsToJs = (fileName) => fileName.slice(0, -3) + ".mjs";
131
- const compileMigrationFiles = () => {
132
- const tsFiles = getMigrationFileNames();
133
- const compiles = tsFiles.map(async (fileName) => {
134
- const filePath = path__default.join(getMigrationFileDir(), fileName);
135
- const file = await fs__default$1.readFile(filePath);
136
- const src = ts__default.transpile(file.toString(), getTsConfig()).trim();
137
- await fs__default$1.outputFile(changeExtTsToJs(filePath), src);
138
- return fileName;
139
- });
140
- return Promise.all(compiles);
141
- };
142
-
143
116
  var Direction = /* @__PURE__ */ ((Direction2) => {
144
117
  Direction2["Up"] = "up";
145
118
  Direction2["Down"] = "down";
@@ -196,6 +169,36 @@ in migration history: ${run}`);
196
169
  return runs[runs.length - 1];
197
170
  };
198
171
 
172
+ const changeExtTsToJs = (fileName) => fileName.slice(0, -3) + ".mjs";
173
+ const compileMigrationFiles = () => {
174
+ const tsFiles = getMigrationFileNames();
175
+ const compiles = tsFiles.map(async (fileName) => {
176
+ const filePath = path__default.join(getMigrationFileDir(), fileName);
177
+ const r = await esbuild__namespace.build({
178
+ entryPoints: [filePath],
179
+ bundle: true,
180
+ // loader: 'ts',
181
+ outfile: changeExtTsToJs(filePath),
182
+ platform: "node",
183
+ format: "esm",
184
+ outExtension: {
185
+ ".js": ".mjs"
186
+ },
187
+ banner: {
188
+ js: `
189
+ import { createRequire as topLevelCreateRequire } from 'module';
190
+ const require = topLevelCreateRequire(import.meta.url);
191
+ `
192
+ }
193
+ });
194
+ if (r.errors.length !== 0) {
195
+ throw r.errors;
196
+ }
197
+ return fileName;
198
+ });
199
+ return Promise.all(compiles);
200
+ };
201
+
199
202
  const readMigration = async (store, tsFileName, direction) => {
200
203
  const file = path__default.join(
201
204
  process.cwd(),
@@ -1417,7 +1420,7 @@ const createCurrentMigrationDataStore = async (targetMigrationName) => {
1417
1420
 
1418
1421
  class MigrationController {
1419
1422
  async migrate(options) {
1420
- const fileNames = await compileMigrationFiles();
1423
+ const fileNames = getMigrationFileNames();
1421
1424
  const currentMigration = await getCurrentMigration(options);
1422
1425
  Console.log("--current migration--: " + currentMigration);
1423
1426
  let store = await createCurrentMigrationDataStore(currentMigration);
@@ -5201,6 +5204,7 @@ const migrate = async (options) => {
5201
5204
  let current;
5202
5205
  Console.log("--migration started--");
5203
5206
  try {
5207
+ await compileMigrationFiles();
5204
5208
  const migration = new MigrationController();
5205
5209
  const result = await migration.migrate(options);
5206
5210
  current = result.currentMigration;
@@ -5782,14 +5786,21 @@ const dumpDB = async () => {
5782
5786
  }
5783
5787
  };
5784
5788
 
5789
+ const migrationBuild = async () => {
5790
+ Console.log("--migration build started--");
5791
+ await compileMigrationFiles();
5792
+ Console.success("Done!");
5793
+ };
5794
+
5785
5795
  const cli = cac.cac();
5786
5796
  try {
5787
- cli.usage("yarn sasat <command> [options]\n").command("migrate", "execute migration").option("-g, --generateFiles", "migrate with generate files").option("-d, --dry", "dry run").option("-s, --silent", "do not print logs").action(async (options) => {
5797
+ cli.usage("yarn sasat <command> [options]\n").command("migrate", "execute migration").option("-g, --generateFiles", "migrate with generate files").option("-d, --dry", "dry run").option("-s, --silent", "do not print logs").option("-b, --skipBuild", "skip compile migration files").action(async (options) => {
5788
5798
  await migrate(options).catch((e) => {
5789
- console__namespace.error(e);
5799
+ console.error(e);
5790
5800
  process.exit(1);
5791
5801
  });
5792
5802
  });
5803
+ cli.command("migration:build", "compile migration files").action(migrationBuild);
5793
5804
  cli.command("generate", "generate files").action(generate);
5794
5805
  cli.command("migration:create [name]", "generate new migration file").action(createMigration);
5795
5806
  cli.command("dump-db", "dump database schema").action(dumpDB);
@@ -5798,6 +5809,6 @@ try {
5798
5809
  if (!cli.matchedCommand)
5799
5810
  cli.outputHelp();
5800
5811
  } catch (e) {
5801
- console__namespace.error(e);
5812
+ console.error(e);
5802
5813
  process.exit(1);
5803
5814
  }
package/dist/cli/cli.mjs CHANGED
@@ -9,6 +9,7 @@ import 'pluralize';
9
9
  import chalk from 'chalk';
10
10
  import * as console$1 from 'console';
11
11
  import ts from 'typescript';
12
+ import * as esbuild from 'esbuild';
12
13
  import fs$1 from 'fs-extra';
13
14
  import 'js-yaml';
14
15
  import * as prettier from 'prettier';
@@ -87,35 +88,6 @@ const getMigrationFileNames = () => {
87
88
  return fs__default.readdirSync(getMigrationFileDir()).filter((it) => it.split(".").pop() === "ts");
88
89
  };
89
90
 
90
- const getTsConfig = () => {
91
- const configFileName = ts.findConfigFile(
92
- "./",
93
- ts.sys.fileExists,
94
- "tsconfig.json"
95
- );
96
- if (!configFileName)
97
- return {
98
- module: ts.ModuleKind.ESNext
99
- };
100
- const configFile = ts.readConfigFile(configFileName, ts.sys.readFile);
101
- return {
102
- ...ts.parseJsonConfigFileContent(configFile.config, ts.sys, "./").options,
103
- module: ts.ModuleKind.ESNext
104
- };
105
- };
106
- const changeExtTsToJs = (fileName) => fileName.slice(0, -3) + ".mjs";
107
- const compileMigrationFiles = () => {
108
- const tsFiles = getMigrationFileNames();
109
- const compiles = tsFiles.map(async (fileName) => {
110
- const filePath = path__default.join(getMigrationFileDir(), fileName);
111
- const file = await fs$1.readFile(filePath);
112
- const src = ts.transpile(file.toString(), getTsConfig()).trim();
113
- await fs$1.outputFile(changeExtTsToJs(filePath), src);
114
- return fileName;
115
- });
116
- return Promise.all(compiles);
117
- };
118
-
119
91
  var Direction = /* @__PURE__ */ ((Direction2) => {
120
92
  Direction2["Up"] = "up";
121
93
  Direction2["Down"] = "down";
@@ -172,6 +144,36 @@ in migration history: ${run}`);
172
144
  return runs[runs.length - 1];
173
145
  };
174
146
 
147
+ const changeExtTsToJs = (fileName) => fileName.slice(0, -3) + ".mjs";
148
+ const compileMigrationFiles = () => {
149
+ const tsFiles = getMigrationFileNames();
150
+ const compiles = tsFiles.map(async (fileName) => {
151
+ const filePath = path__default.join(getMigrationFileDir(), fileName);
152
+ const r = await esbuild.build({
153
+ entryPoints: [filePath],
154
+ bundle: true,
155
+ // loader: 'ts',
156
+ outfile: changeExtTsToJs(filePath),
157
+ platform: "node",
158
+ format: "esm",
159
+ outExtension: {
160
+ ".js": ".mjs"
161
+ },
162
+ banner: {
163
+ js: `
164
+ import { createRequire as topLevelCreateRequire } from 'module';
165
+ const require = topLevelCreateRequire(import.meta.url);
166
+ `
167
+ }
168
+ });
169
+ if (r.errors.length !== 0) {
170
+ throw r.errors;
171
+ }
172
+ return fileName;
173
+ });
174
+ return Promise.all(compiles);
175
+ };
176
+
175
177
  const readMigration = async (store, tsFileName, direction) => {
176
178
  const file = path__default.join(
177
179
  process.cwd(),
@@ -1393,7 +1395,7 @@ const createCurrentMigrationDataStore = async (targetMigrationName) => {
1393
1395
 
1394
1396
  class MigrationController {
1395
1397
  async migrate(options) {
1396
- const fileNames = await compileMigrationFiles();
1398
+ const fileNames = getMigrationFileNames();
1397
1399
  const currentMigration = await getCurrentMigration(options);
1398
1400
  Console.log("--current migration--: " + currentMigration);
1399
1401
  let store = await createCurrentMigrationDataStore(currentMigration);
@@ -5177,6 +5179,7 @@ const migrate = async (options) => {
5177
5179
  let current;
5178
5180
  Console.log("--migration started--");
5179
5181
  try {
5182
+ await compileMigrationFiles();
5180
5183
  const migration = new MigrationController();
5181
5184
  const result = await migration.migrate(options);
5182
5185
  current = result.currentMigration;
@@ -5758,14 +5761,21 @@ const dumpDB = async () => {
5758
5761
  }
5759
5762
  };
5760
5763
 
5764
+ const migrationBuild = async () => {
5765
+ Console.log("--migration build started--");
5766
+ await compileMigrationFiles();
5767
+ Console.success("Done!");
5768
+ };
5769
+
5761
5770
  const cli = cac();
5762
5771
  try {
5763
- cli.usage("yarn sasat <command> [options]\n").command("migrate", "execute migration").option("-g, --generateFiles", "migrate with generate files").option("-d, --dry", "dry run").option("-s, --silent", "do not print logs").action(async (options) => {
5772
+ cli.usage("yarn sasat <command> [options]\n").command("migrate", "execute migration").option("-g, --generateFiles", "migrate with generate files").option("-d, --dry", "dry run").option("-s, --silent", "do not print logs").option("-b, --skipBuild", "skip compile migration files").action(async (options) => {
5764
5773
  await migrate(options).catch((e) => {
5765
- console$1.error(e);
5774
+ console.error(e);
5766
5775
  process.exit(1);
5767
5776
  });
5768
5777
  });
5778
+ cli.command("migration:build", "compile migration files").action(migrationBuild);
5769
5779
  cli.command("generate", "generate files").action(generate);
5770
5780
  cli.command("migration:create [name]", "generate new migration file").action(createMigration);
5771
5781
  cli.command("dump-db", "dump database schema").action(dumpDB);
@@ -5774,6 +5784,6 @@ try {
5774
5784
  if (!cli.matchedCommand)
5775
5785
  cli.outputHelp();
5776
5786
  } catch (e) {
5777
- console$1.error(e);
5787
+ console.error(e);
5778
5788
  process.exit(1);
5779
5789
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sasat",
3
- "version": "0.20.5",
3
+ "version": "0.21.0",
4
4
  "repository": "https://github.com/nin138/sasat.git",
5
5
  "author": "nin138 <ninian138@gmail.com>",
6
6
  "license": "MIT",
@@ -17,12 +17,13 @@
17
17
  "test:base": "node --experimental-vm-modules node_modules/.bin/jest",
18
18
  "resetdb": "docker-compose exec db sh -c \"mysql -u root < /docker-entrypoint-initdb.d/temp.sql\"",
19
19
  "prepare": "yarn build && husky install",
20
- "sasat": "yarn env-cmd ts-node-esm ./src/cli/cli.ts",
20
+ "sasat": "yarn env-cmd tsx ./src/cli/cli.ts",
21
21
  "server": "yarn env-cmd ts-node-esm -r tsconfig-paths/register ./test/testServer.ts"
22
22
  },
23
23
  "dependencies": {
24
24
  "cac": "^6.7.14",
25
25
  "chalk": "^5.3.0",
26
+ "esbuild": "^0.21.5",
26
27
  "fs-extra": "^11.1.1",
27
28
  "graphql": "^16.8.1",
28
29
  "graphql-subscriptions": "^2.0.0",
@@ -53,10 +54,11 @@
53
54
  "husky": "8.0.3",
54
55
  "jest": "29.7.0",
55
56
  "lint-staged": "13.2.3",
56
- "sasat": "link:./lib",
57
+ "sasat": "link:./dist",
57
58
  "ts-jest": "29.1.4",
58
59
  "ts-node": "10.9.2",
59
60
  "tsconfig-paths": "4.2.0",
61
+ "tsx": "^4.15.2",
60
62
  "unbuild": "^2.0.0"
61
63
  },
62
64
  "peerDependencies": {