@cedarjs/cli-data-migrate 6.0.0-canary.2637 → 6.0.0-canary.2639

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.
@@ -1 +1 @@
1
- {"version":3,"file":"upHandlerEsm.d.ts","sourceRoot":"","sources":["../../src/commands/upHandlerEsm.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,oBAAoB,EAAiB,MAAM,UAAU,CAAA;AAoBnE,wBAAsB,OAAO,CAAC,EAC5B,sBAAsB,EACtB,QAAQ,GACT,EAAE,oBAAoB,iBAsHtB;AAiFD,eAAO,MAAM,6BAA6B,wDACa,CAAA"}
1
+ {"version":3,"file":"upHandlerEsm.d.ts","sourceRoot":"","sources":["../../src/commands/upHandlerEsm.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,oBAAoB,EAAiB,MAAM,UAAU,CAAA;AAsCnE,wBAAsB,OAAO,CAAC,EAC5B,sBAAsB,EACtB,QAAQ,GACT,EAAE,oBAAoB,iBAoMtB;AA6DD,eAAO,MAAM,6BAA6B,wDACa,CAAA"}
@@ -34,15 +34,93 @@ __export(upHandlerEsm_exports, {
34
34
  module.exports = __toCommonJS(upHandlerEsm_exports);
35
35
  var import_node_fs = __toESM(require("node:fs"));
36
36
  var import_node_path = __toESM(require("node:path"));
37
- var import_bundle_require = require("bundle-require");
38
37
  var import_listr2 = require("listr2");
38
+ var import_vite = require("vite");
39
39
  var import_cli_helpers = require("@cedarjs/cli-helpers");
40
40
  var import_project_config = require("@cedarjs/project-config");
41
+ function resolveId(id) {
42
+ if (import_node_fs.default.existsSync(id) && import_node_fs.default.statSync(id).isFile()) {
43
+ return id;
44
+ }
45
+ const withoutExt = /\.jsx?$/.test(id) ? id.replace(/\.jsx?$/, "") : id;
46
+ for (const ext of [".ts", ".tsx", ".js", ".jsx"]) {
47
+ if (import_node_fs.default.existsSync(withoutExt + ext)) {
48
+ return withoutExt + ext;
49
+ }
50
+ }
51
+ if (import_node_fs.default.existsSync(id) && import_node_fs.default.statSync(id).isDirectory()) {
52
+ for (const base of ["index", import_node_path.default.basename(id)]) {
53
+ for (const ext of [".ts", ".tsx", ".js", ".jsx"]) {
54
+ const candidate = import_node_path.default.join(id, base + ext);
55
+ if (import_node_fs.default.existsSync(candidate)) {
56
+ return candidate;
57
+ }
58
+ }
59
+ }
60
+ }
61
+ return id;
62
+ }
41
63
  async function handler({
42
64
  importDbClientFromDist,
43
65
  distPath
44
66
  }) {
45
67
  let db;
68
+ let server = null;
69
+ let cedarPlugins;
70
+ async function getRunner() {
71
+ if (!server) {
72
+ if (!cedarPlugins) {
73
+ const mod = await import("@cedarjs/vite");
74
+ cedarPlugins = mod;
75
+ }
76
+ server = await (0, import_vite.createServer)({
77
+ mode: "production",
78
+ optimizeDeps: {
79
+ noDiscovery: true,
80
+ include: void 0
81
+ },
82
+ server: {
83
+ hmr: false,
84
+ watch: null
85
+ },
86
+ environments: {
87
+ nodeRunnerEnv: {}
88
+ },
89
+ resolve: {
90
+ alias: [
91
+ {
92
+ find: /^api\//,
93
+ replacement: (0, import_project_config.getPaths)().api.base + "/"
94
+ },
95
+ {
96
+ find: /^src\//,
97
+ replacement: "src/",
98
+ customResolver: (id, importer, _options) => {
99
+ const apiImportBase = (0, import_project_config.importStatementPath)((0, import_project_config.getPaths)().api.base);
100
+ if (importer?.startsWith(apiImportBase)) {
101
+ const apiImportSrc = (0, import_project_config.importStatementPath)((0, import_project_config.getPaths)().api.src);
102
+ const apiId = id.replace("src", apiImportSrc);
103
+ return { id: resolveId(apiId) };
104
+ }
105
+ return null;
106
+ }
107
+ }
108
+ ]
109
+ },
110
+ plugins: [
111
+ cedarPlugins.cedarCjsCompatPlugin(),
112
+ cedarPlugins.cedarjsResolveCedarStyleImportsPlugin(),
113
+ cedarPlugins.cedarImportDirPlugin(),
114
+ cedarPlugins.cedarAutoImportsPlugin()
115
+ ]
116
+ });
117
+ }
118
+ const env = server.environments.nodeRunnerEnv;
119
+ if (!env || !(0, import_vite.isRunnableDevEnvironment)(env)) {
120
+ throw new Error("Vite environment is not runnable.");
121
+ }
122
+ return env.runner;
123
+ }
46
124
  if (importDbClientFromDist) {
47
125
  if (!import_node_fs.default.existsSync(distPath)) {
48
126
  console.warn(
@@ -68,11 +146,14 @@ async function handler({
68
146
  process.exitCode = 1;
69
147
  return;
70
148
  }
71
- const { mod } = await (0, import_bundle_require.bundleRequire)({
72
- filepath: dbPath
73
- // TODO: Add plugins
74
- });
75
- db = mod.db;
149
+ try {
150
+ const runner = await getRunner();
151
+ const dbModule = await runner.import(dbPath);
152
+ db = dbModule.db;
153
+ } catch (e) {
154
+ await server?.close();
155
+ throw e;
156
+ }
76
157
  }
77
158
  const pendingDataMigrations = await getPendingDataMigrations(db);
78
159
  if (!pendingDataMigrations.length) {
@@ -80,6 +161,7 @@ async function handler({
80
161
  ${NO_PENDING_MIGRATIONS_MESSAGE}
81
162
  `));
82
163
  process.exitCode = 0;
164
+ await server?.close();
83
165
  return;
84
166
  }
85
167
  const counters = { run: 0, skipped: 0, error: 0 };
@@ -110,9 +192,8 @@ ${NO_PENDING_MIGRATIONS_MESSAGE}
110
192
  });
111
193
  } catch (e) {
112
194
  counters.error++;
113
- console.error(
114
- import_cli_helpers.colors.error(`Error in data migration: ${e.message}`)
115
- );
195
+ const message = e instanceof Error ? e.message : String(e);
196
+ console.error(import_cli_helpers.colors.error(`Error in data migration: ${message}`));
116
197
  }
117
198
  }
118
199
  };
@@ -135,6 +216,19 @@ ${NO_PENDING_MIGRATIONS_MESSAGE}
135
216
  console.log();
136
217
  reportDataMigrations(counters);
137
218
  console.log();
219
+ } finally {
220
+ if (server) {
221
+ await server.close();
222
+ }
223
+ }
224
+ async function runDataMigration(db2, dataMigrationPath) {
225
+ const runner = await getRunner();
226
+ const dataMigrationModule = await runner.import(dataMigrationPath);
227
+ const dataMigration = dataMigrationModule.default;
228
+ const startedAt = /* @__PURE__ */ new Date();
229
+ await dataMigration({ db: db2 });
230
+ const finishedAt = /* @__PURE__ */ new Date();
231
+ return { startedAt, finishedAt };
138
232
  }
139
233
  }
140
234
  async function getPendingDataMigrations(db) {
@@ -179,17 +273,6 @@ function sortDataMigrationsByVersion(dataMigrationA, dataMigrationB) {
179
273
  }
180
274
  return 0;
181
275
  }
182
- async function runDataMigration(db, dataMigrationPath) {
183
- const { mod } = await (0, import_bundle_require.bundleRequire)({
184
- filepath: dataMigrationPath
185
- // TODO: Add plugins
186
- });
187
- const dataMigration = mod.default;
188
- const startedAt = /* @__PURE__ */ new Date();
189
- await dataMigration({ db });
190
- const finishedAt = /* @__PURE__ */ new Date();
191
- return { startedAt, finishedAt };
192
- }
193
276
  const NO_PENDING_MIGRATIONS_MESSAGE = "No pending data migrations run, already up-to-date.";
194
277
  async function recordDataMigration(db, { version, name, startedAt, finishedAt }) {
195
278
  await db.rW_DataMigration.create({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/cli-data-migrate",
3
- "version": "6.0.0-canary.2637",
3
+ "version": "6.0.0-canary.2639",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/cedarjs/cedar.git",
@@ -26,18 +26,19 @@
26
26
  "test:unit": "vitest run src"
27
27
  },
28
28
  "dependencies": {
29
- "@cedarjs/babel-config": "6.0.0-canary.2637",
30
- "@cedarjs/cli-helpers": "6.0.0-canary.2637",
31
- "@cedarjs/project-config": "6.0.0-canary.2637",
32
- "bundle-require": "^5.1.0",
29
+ "@cedarjs/babel-config": "6.0.0-canary.2639",
30
+ "@cedarjs/cli-helpers": "6.0.0-canary.2639",
31
+ "@cedarjs/project-config": "6.0.0-canary.2639",
32
+ "@cedarjs/vite": "6.0.0-canary.2639",
33
33
  "dotenv-defaults": "5.0.2",
34
34
  "execa": "5.1.1",
35
35
  "listr2": "10.2.1",
36
36
  "termi-link": "1.1.0",
37
+ "vite": "7.3.5",
37
38
  "yargs": "17.7.3"
38
39
  },
39
40
  "devDependencies": {
40
- "@cedarjs/framework-tools": "6.0.0-canary.2637",
41
+ "@cedarjs/framework-tools": "6.0.0-canary.2639",
41
42
  "@prisma/client": "7.8.0",
42
43
  "@types/yargs": "17.0.35",
43
44
  "memfs": "4.64.0",