@cedarjs/cli-data-migrate 5.0.3 → 5.0.4-next.167

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/bin.js CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env node
2
- "use strict";var _=Object.create;var y=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var N=Object.getPrototypeOf,O=Object.prototype.hasOwnProperty;var R=(t,r)=>()=>(t&&(r=t(t=0)),r);var U=(t,r,i,a)=>{if(r&&typeof r=="object"||typeof r=="function")for(let e of L(r))!O.call(t,e)&&e!==i&&y(t,e,{get:()=>r[e],enumerable:!(a=I(r,e))||a.enumerable});return t};var l=(t,r,i)=>(i=t!=null?_(N(t)):{},U(r||!t||!t.__esModule?y(i,"default",{value:t,enumerable:!0}):i,t));async function E({importDbClientFromDist:t,distPath:r}){let i,a=!1;if(t){if(!g.default.existsSync(r)){console.warn(`Can't find api dist at ${r}. You may need to build first: yarn cedar build api`),process.exitCode=1;return}let s=p.default.join(r,"lib"),d=p.default.join(s,"db.js");if(!g.default.existsSync(d)){console.error(`Can't find db.js at ${d}. CedarJS expects the db.js file to be in the ${s} directory`),process.exitCode=1;return}i=(await import(d)).db}else(0,M.registerApiSideBabelHook)(),a=!0,i=require(p.default.join((0,f.getPaths)().api.lib,"db")).db;let e=await V(i);if(!e.length){console.info(c.colors.success(`
3
- ${W}
4
- `)),process.exitCode=0;return}let n={run:0,skipped:0,error:0},o=e.map(s=>{let d=p.default.basename(s.path,".js");return{title:d,skip(){return n.error>0?(n.skipped++,!0):!1},async task(){a||(0,M.registerApiSideBabelHook)();try{let{startedAt:u,finishedAt:P}=await H(i,s.path);n.run++,await q(i,{version:s.version,name:d,startedAt:u,finishedAt:P})}catch(u){n.error++,console.error(c.colors.error(`Error in data migration: ${u.message}`))}}}}),m=new k.Listr(o,{renderer:"verbose"});try{await m.run(),await i.$disconnect(),console.log(),A(n),console.log(),n.error&&(process.exitCode=1)}catch{process.exitCode=1,await i.$disconnect(),console.log(),A(n),console.log()}}async function V(t){let r=await(0,f.getDataMigrationsPath)((0,f.getPaths)().api.prismaConfig);if(!g.default.existsSync(r))return[];let i=g.default.readdirSync(r).filter(o=>["js",".ts"].some(m=>o.endsWith(m))).map(o=>{let[m]=o.split("-");return{version:m,path:p.default.join(r,o)}}),e=(await t.rW_DataMigration.findMany({orderBy:{version:"asc"}})).map(o=>o.version.toString());return i.filter(({version:o})=>!e.includes(o)).sort(B)}function B(t,r){let i=parseInt(t.version),a=parseInt(r.version);return i>a?1:i<a?-1:0}async function H(t,r){let i=require(r),a=new Date;return await i.default({db:t}),{startedAt:a,finishedAt:new Date}}async function q(t,{version:r,name:i,startedAt:a,finishedAt:e}){await t.rW_DataMigration.create({data:{version:r,name:i,startedAt:a,finishedAt:e}})}function A(t){t.run&&console.info(c.colors.success(`${t.run} data migration(s) completed successfully.`)),t.error&&console.error(c.colors.error(`${t.error} data migration(s) exited with errors.`)),t.skipped&&console.warn(c.colors.warning(`${t.skipped} data migration(s) skipped due to previous error.`))}var g,p,k,M,c,f,W,j=R(()=>{"use strict";g=l(require("node:fs")),p=l(require("node:path")),k=require("listr2"),M=require("@cedarjs/babel-config"),c=require("@cedarjs/cli-helpers"),f=require("@cedarjs/project-config");W="No pending data migrations run, already up-to-date."});var b=l(require("path")),C=require("dotenv-defaults"),S=require("yargs/helpers"),$=l(require("yargs/yargs")),h=require("@cedarjs/project-config");var w=require("termi-link"),D=require("@cedarjs/project-config");var v="Run any outstanding Data Migrations against the database";function x(t){return t.option("import-db-client-from-dist",{type:"boolean",alias:["db-from-dist"],description:"Import the db client from dist",default:!1}).option("dist-path",{type:"string",alias:"d",description:"Path to the api dist directory",default:(0,D.getPaths)().api.dist}).epilogue(`Also see the ${(0,w.terminalLink)("CedarJS CLI Reference","https://cedarjs.com/docs/cli-commands#datamigrate-up")}`)}j();process.env.CEDAR_ENV_FILES_LOADED||((0,C.config)({path:b.default.join((0,h.getPaths)().base,".env"),defaults:b.default.join((0,h.getPaths)().base,".env.defaults"),multiline:!0}),process.env.CEDAR_ENV_FILES_LOADED="true");(0,$.default)((0,S.hideBin)(process.argv)).scriptName("data-migrate").command("$0",v,x,E).parse();
2
+ var j=(t,i,r)=>()=>{if(r)throw r[0];try{return t&&(i=t(t=0)),i}catch(a){throw r=[a],a}};import g from"node:fs";import{createRequire as C}from"node:module";import c from"node:path";import{Listr as S}from"listr2";import{registerApiSideBabelHook as D}from"@cedarjs/babel-config";import{colors as m}from"@cedarjs/cli-helpers";import{getPaths as b,getDataMigrationsPath as $}from"@cedarjs/project-config";async function y({importDbClientFromDist:t,distPath:i}){let r,a=!1;if(t){if(!g.existsSync(i)){console.warn(`Can't find api dist at ${i}. You may need to build first: yarn cedar build api`),process.exitCode=1;return}let s=c.join(i,"lib"),d=c.join(s,"db.js");if(!g.existsSync(d)){console.error(`Can't find db.js at ${d}. CedarJS expects the db.js file to be in the ${s} directory`),process.exitCode=1;return}r=(await import(d)).db}else D(),a=!0,r=h(c.join(b().api.lib,"db")).db;let n=await P(r);if(!n.length){console.info(m.success(`
3
+ ${L}
4
+ `)),process.exitCode=0;return}let o={run:0,skipped:0,error:0},e=n.map(s=>{let d=c.basename(s.path,".js");return{title:d,skip(){return o.error>0?(o.skipped++,!0):!1},async task(){a||D();try{let{startedAt:f,finishedAt:A}=await I(r,s.path);o.run++,await R(r,{version:s.version,name:d,startedAt:f,finishedAt:A})}catch(f){o.error++,console.error(m.error(`Error in data migration: ${f.message}`))}}}}),p=new S(e,{renderer:"verbose"});try{await p.run(),await r.$disconnect(),console.log(),M(o),console.log(),o.error&&(process.exitCode=1)}catch{process.exitCode=1,await r.$disconnect(),console.log(),M(o),console.log()}}async function P(t){let i=await $(b().api.prismaConfig);if(!g.existsSync(i))return[];let r=g.readdirSync(i).filter(e=>["js",".ts"].some(p=>e.endsWith(p))).map(e=>{let[p]=e.split("-");return{version:p,path:c.join(i,e)}}),n=(await t.rW_DataMigration.findMany({orderBy:{version:"asc"}})).map(e=>e.version.toString());return r.filter(({version:e})=>!n.includes(e)).sort(_)}function _(t,i){let r=parseInt(t.version),a=parseInt(i.version);return r>a?1:r<a?-1:0}async function I(t,i){let r=h(i),a=new Date;return await r.default({db:t}),{startedAt:a,finishedAt:new Date}}async function R(t,{version:i,name:r,startedAt:a,finishedAt:n}){await t.rW_DataMigration.create({data:{version:i,name:r,startedAt:a,finishedAt:n}})}function M(t){t.run&&console.info(m.success(`${t.run} data migration(s) completed successfully.`)),t.error&&console.error(m.error(`${t.error} data migration(s) exited with errors.`)),t.skipped&&console.warn(m.warning(`${t.skipped} data migration(s) skipped due to previous error.`))}var h,L,w=j(()=>{"use strict";h=C(import.meta.url);L="No pending data migrations run, already up-to-date."});import v from"path";import{config as N}from"dotenv-defaults";import{hideBin as O}from"yargs/helpers";import U from"yargs/yargs";import{getPaths as x}from"@cedarjs/project-config";import{terminalLink as k}from"termi-link";import{getPaths as E,projectIsEsm as W}from"@cedarjs/project-config";var l="Run any outstanding Data Migrations against the database";function u(t){return t.option("import-db-client-from-dist",{type:"boolean",alias:["db-from-dist"],description:"Import the db client from dist",default:!1}).option("dist-path",{type:"string",alias:"d",description:"Path to the api dist directory",default:E().api.dist}).epilogue(`Also see the ${k("CedarJS CLI Reference","https://cedarjs.com/docs/cli-commands#datamigrate-up")}`)}w();process.env.CEDAR_ENV_FILES_LOADED||(N({path:v.join(x().base,".env"),defaults:v.join(x().base,".env.defaults"),multiline:!0}),process.env.CEDAR_ENV_FILES_LOADED="true");U(O(process.argv)).scriptName("data-migrate").command("$0",l,u,y).parse();
@@ -1,45 +1,9 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var install_exports = {};
30
- __export(install_exports, {
31
- builder: () => builder,
32
- command: () => command,
33
- description: () => description,
34
- handler: () => handler
35
- });
36
- module.exports = __toCommonJS(install_exports);
37
- var import_termi_link = require("termi-link");
1
+ import { terminalLink } from "termi-link";
38
2
  const command = "install";
39
3
  const description = "Add the RW_DataMigration model to your schema";
40
4
  function builder(yargs) {
41
5
  return yargs.epilogue(
42
- `Also see the ${(0, import_termi_link.terminalLink)(
6
+ `Also see the ${terminalLink(
43
7
  "CedarJS CLI Reference",
44
8
  "https://cedarjs.com/docs/cli-commands#datamigrate-install"
45
9
  )}`
@@ -49,10 +13,9 @@ async function handler() {
49
13
  const { handler: dataMigrateInstallHandler } = await import("./installHandler.js");
50
14
  await dataMigrateInstallHandler();
51
15
  }
52
- // Annotate the CommonJS export names for ESM import in node:
53
- 0 && (module.exports = {
16
+ export {
54
17
  builder,
55
18
  command,
56
19
  description,
57
20
  handler
58
- });
21
+ };
@@ -1,64 +1,32 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var installHandler_exports = {};
30
- __export(installHandler_exports, {
31
- RW_DATA_MIGRATION_MODEL: () => RW_DATA_MIGRATION_MODEL,
32
- createDatabaseMigrationCommand: () => createDatabaseMigrationCommand,
33
- handler: () => handler,
34
- notes: () => notes
35
- });
36
- module.exports = __toCommonJS(installHandler_exports);
37
- var import_node_fs = __toESM(require("node:fs"));
38
- var import_node_path = __toESM(require("node:path"));
39
- var import_execa = __toESM(require("execa"));
40
- var import_listr2 = require("listr2");
41
- var import_cli_helpers = require("@cedarjs/cli-helpers");
42
- var import_project_config = require("@cedarjs/project-config");
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import execa from "execa";
4
+ import { Listr } from "listr2";
5
+ import { colors as c } from "@cedarjs/cli-helpers";
6
+ import {
7
+ getPaths,
8
+ getSchemaPath,
9
+ getDataMigrationsPath
10
+ } from "@cedarjs/project-config";
43
11
  async function handler() {
44
- const cedarProjectPaths = (0, import_project_config.getPaths)();
12
+ const cedarProjectPaths = getPaths();
45
13
  const prismaConfigPath = cedarProjectPaths.api.prismaConfig;
46
- const dataMigrationsPath = await (0, import_project_config.getDataMigrationsPath)(prismaConfigPath);
47
- const tasks = new import_listr2.Listr(
14
+ const dataMigrationsPath = await getDataMigrationsPath(prismaConfigPath);
15
+ const tasks = new Listr(
48
16
  [
49
17
  {
50
18
  title: "Creating the dataMigrations directory...",
51
19
  task() {
52
- import_node_fs.default.mkdirSync(dataMigrationsPath, { recursive: true });
53
- import_node_fs.default.writeFileSync(import_node_path.default.join(dataMigrationsPath, ".keep"), "");
20
+ fs.mkdirSync(dataMigrationsPath, { recursive: true });
21
+ fs.writeFileSync(path.join(dataMigrationsPath, ".keep"), "");
54
22
  }
55
23
  },
56
24
  {
57
25
  title: "Adding the RW_DataMigration model to schema.prisma...",
58
26
  async task() {
59
- const dbSchemaFilePath = await (0, import_project_config.getSchemaPath)(prismaConfigPath);
60
- const dbSchemaFileContent = import_node_fs.default.readFileSync(dbSchemaFilePath, "utf-8");
61
- import_node_fs.default.writeFileSync(
27
+ const dbSchemaFilePath = await getSchemaPath(prismaConfigPath);
28
+ const dbSchemaFileContent = fs.readFileSync(dbSchemaFilePath, "utf-8");
29
+ fs.writeFileSync(
62
30
  dbSchemaFilePath,
63
31
  [dbSchemaFileContent.trim(), "", RW_DATA_MIGRATION_MODEL, ""].join(
64
32
  "\n"
@@ -69,7 +37,7 @@ async function handler() {
69
37
  {
70
38
  title: "Creating the database migration...",
71
39
  task() {
72
- return import_execa.default.command(createDatabaseMigrationCommand, {
40
+ return execa.command(createDatabaseMigrationCommand, {
73
41
  cwd: cedarProjectPaths.base
74
42
  }).stdout;
75
43
  }
@@ -86,7 +54,7 @@ async function handler() {
86
54
  console.log(notes);
87
55
  } catch (e) {
88
56
  process.exitCode = 1;
89
- console.error(import_cli_helpers.colors.error(e.message));
57
+ console.error(c.error(e.message));
90
58
  }
91
59
  }
92
60
  const RW_DATA_MIGRATION_MODEL = `model RW_DataMigration {
@@ -98,15 +66,14 @@ const RW_DATA_MIGRATION_MODEL = `model RW_DataMigration {
98
66
  const createDatabaseMigrationCommand = "yarn cedar prisma migrate dev --name create_data_migrations --create-only";
99
67
  const notes = [
100
68
  "",
101
- import_cli_helpers.colors.warning("Don't forget to apply the migration when you're ready:"),
69
+ c.warning("Don't forget to apply the migration when you're ready:"),
102
70
  "",
103
- ` ${import_cli_helpers.colors.bold("yarn cedar prisma migrate dev")}`,
71
+ ` ${c.bold("yarn cedar prisma migrate dev")}`,
104
72
  ""
105
73
  ].join("\n");
106
- // Annotate the CommonJS export names for ESM import in node:
107
- 0 && (module.exports = {
74
+ export {
108
75
  RW_DATA_MIGRATION_MODEL,
109
76
  createDatabaseMigrationCommand,
110
77
  handler,
111
78
  notes
112
- });
79
+ };
@@ -1,5 +1,5 @@
1
1
  import type { Argv } from 'yargs';
2
- import type { DataMigrateUpOptions } from '../types';
2
+ import type { DataMigrateUpOptions } from '../types.js';
3
3
  export declare const command = "up";
4
4
  export declare const description = "Run any outstanding Data Migrations against the database";
5
5
  export declare function builder(yargs: Argv): Argv;
@@ -1 +1 @@
1
- {"version":3,"file":"up.d.ts","sourceRoot":"","sources":["../../src/commands/up.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAIjC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAEpD,eAAO,MAAM,OAAO,OAAO,CAAA;AAC3B,eAAO,MAAM,WAAW,6DACoC,CAAA;AAE5D,wBAAgB,OAAO,CAAC,KAAK,EAAE,IAAI,GAAG,IAAI,CAoBzC;AAED,wBAAsB,OAAO,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAQ1E"}
1
+ {"version":3,"file":"up.d.ts","sourceRoot":"","sources":["../../src/commands/up.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAIjC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAEvD,eAAO,MAAM,OAAO,OAAO,CAAA;AAC3B,eAAO,MAAM,WAAW,6DACoC,CAAA;AAE5D,wBAAgB,OAAO,CAAC,KAAK,EAAE,IAAI,GAAG,IAAI,CAoBzC;AAED,wBAAsB,OAAO,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAQ1E"}
@@ -1,41 +1,5 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var up_exports = {};
30
- __export(up_exports, {
31
- builder: () => builder,
32
- command: () => command,
33
- description: () => description,
34
- handler: () => handler
35
- });
36
- module.exports = __toCommonJS(up_exports);
37
- var import_termi_link = require("termi-link");
38
- var import_project_config = require("@cedarjs/project-config");
1
+ import { terminalLink } from "termi-link";
2
+ import { getPaths, projectIsEsm } from "@cedarjs/project-config";
39
3
  const command = "up";
40
4
  const description = "Run any outstanding Data Migrations against the database";
41
5
  function builder(yargs) {
@@ -48,16 +12,16 @@ function builder(yargs) {
48
12
  type: "string",
49
13
  alias: "d",
50
14
  description: "Path to the api dist directory",
51
- default: (0, import_project_config.getPaths)().api.dist
15
+ default: getPaths().api.dist
52
16
  }).epilogue(
53
- `Also see the ${(0, import_termi_link.terminalLink)(
17
+ `Also see the ${terminalLink(
54
18
  "CedarJS CLI Reference",
55
19
  "https://cedarjs.com/docs/cli-commands#datamigrate-up"
56
20
  )}`
57
21
  );
58
22
  }
59
23
  async function handler(options) {
60
- if ((0, import_project_config.projectIsEsm)()) {
24
+ if (projectIsEsm()) {
61
25
  const { handler: dataMigrateUpHandler } = await import("./upHandlerEsm.js");
62
26
  await dataMigrateUpHandler(options);
63
27
  } else {
@@ -65,10 +29,9 @@ async function handler(options) {
65
29
  await dataMigrateUpHandler(options);
66
30
  }
67
31
  }
68
- // Annotate the CommonJS export names for ESM import in node:
69
- 0 && (module.exports = {
32
+ export {
70
33
  builder,
71
34
  command,
72
35
  description,
73
36
  handler
74
- });
37
+ };
@@ -1,4 +1,4 @@
1
- import type { DataMigrateUpOptions } from '../types';
1
+ import type { DataMigrateUpOptions } from '../types.js';
2
2
  export declare function handler({ importDbClientFromDist, distPath, }: DataMigrateUpOptions): Promise<void>;
3
3
  export declare const NO_PENDING_MIGRATIONS_MESSAGE = "No pending data migrations run, already up-to-date.";
4
4
  //# sourceMappingURL=upHandler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"upHandler.d.ts","sourceRoot":"","sources":["../../src/commands/upHandler.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,oBAAoB,EAAiB,MAAM,UAAU,CAAA;AAoBnE,wBAAsB,OAAO,CAAC,EAC5B,sBAAsB,EACtB,QAAQ,GACT,EAAE,oBAAoB,iBA2GtB;AA8ED,eAAO,MAAM,6BAA6B,wDACa,CAAA"}
1
+ {"version":3,"file":"upHandler.d.ts","sourceRoot":"","sources":["../../src/commands/upHandler.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,oBAAoB,EAAiB,MAAM,aAAa,CAAA;AA2BtE,wBAAsB,OAAO,CAAC,EAC5B,sBAAsB,EACtB,QAAQ,GACT,EAAE,oBAAoB,iBA2GtB;AA8ED,eAAO,MAAM,6BAA6B,wDACa,CAAA"}
@@ -1,43 +1,11 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var upHandler_exports = {};
30
- __export(upHandler_exports, {
31
- NO_PENDING_MIGRATIONS_MESSAGE: () => NO_PENDING_MIGRATIONS_MESSAGE,
32
- handler: () => handler
33
- });
34
- module.exports = __toCommonJS(upHandler_exports);
35
- var import_node_fs = __toESM(require("node:fs"));
36
- var import_node_path = __toESM(require("node:path"));
37
- var import_listr2 = require("listr2");
38
- var import_babel_config = require("@cedarjs/babel-config");
39
- var import_cli_helpers = require("@cedarjs/cli-helpers");
40
- var import_project_config = require("@cedarjs/project-config");
1
+ import fs from "node:fs";
2
+ import { createRequire } from "node:module";
3
+ import path from "node:path";
4
+ import { Listr } from "listr2";
5
+ import { registerApiSideBabelHook } from "@cedarjs/babel-config";
6
+ import { colors as c } from "@cedarjs/cli-helpers";
7
+ import { getPaths, getDataMigrationsPath } from "@cedarjs/project-config";
8
+ const require2 = createRequire(import.meta.url);
41
9
  async function handler({
42
10
  importDbClientFromDist,
43
11
  distPath
@@ -45,16 +13,16 @@ async function handler({
45
13
  let db;
46
14
  let requireHookRegistered = false;
47
15
  if (importDbClientFromDist) {
48
- if (!import_node_fs.default.existsSync(distPath)) {
16
+ if (!fs.existsSync(distPath)) {
49
17
  console.warn(
50
18
  `Can't find api dist at ${distPath}. You may need to build first: yarn cedar build api`
51
19
  );
52
20
  process.exitCode = 1;
53
21
  return;
54
22
  }
55
- const distLibPath = import_node_path.default.join(distPath, "lib");
56
- const distLibDbPath = import_node_path.default.join(distLibPath, "db.js");
57
- if (!import_node_fs.default.existsSync(distLibDbPath)) {
23
+ const distLibPath = path.join(distPath, "lib");
24
+ const distLibDbPath = path.join(distLibPath, "db.js");
25
+ if (!fs.existsSync(distLibDbPath)) {
58
26
  console.error(
59
27
  `Can't find db.js at ${distLibDbPath}. CedarJS expects the db.js file to be in the ${distLibPath} directory`
60
28
  );
@@ -63,13 +31,13 @@ async function handler({
63
31
  }
64
32
  db = (await import(distLibDbPath)).db;
65
33
  } else {
66
- (0, import_babel_config.registerApiSideBabelHook)();
34
+ registerApiSideBabelHook();
67
35
  requireHookRegistered = true;
68
- db = require(import_node_path.default.join((0, import_project_config.getPaths)().api.lib, "db")).db;
36
+ db = require2(path.join(getPaths().api.lib, "db")).db;
69
37
  }
70
38
  const pendingDataMigrations = await getPendingDataMigrations(db);
71
39
  if (!pendingDataMigrations.length) {
72
- console.info(import_cli_helpers.colors.success(`
40
+ console.info(c.success(`
73
41
  ${NO_PENDING_MIGRATIONS_MESSAGE}
74
42
  `));
75
43
  process.exitCode = 0;
@@ -77,7 +45,7 @@ ${NO_PENDING_MIGRATIONS_MESSAGE}
77
45
  }
78
46
  const counters = { run: 0, skipped: 0, error: 0 };
79
47
  const dataMigrationTasks = pendingDataMigrations.map((dataMigration) => {
80
- const dataMigrationName = import_node_path.default.basename(dataMigration.path, ".js");
48
+ const dataMigrationName = path.basename(dataMigration.path, ".js");
81
49
  return {
82
50
  title: dataMigrationName,
83
51
  skip() {
@@ -90,7 +58,7 @@ ${NO_PENDING_MIGRATIONS_MESSAGE}
90
58
  },
91
59
  async task() {
92
60
  if (!requireHookRegistered) {
93
- (0, import_babel_config.registerApiSideBabelHook)();
61
+ registerApiSideBabelHook();
94
62
  }
95
63
  try {
96
64
  const { startedAt, finishedAt } = await runDataMigration(
@@ -107,13 +75,13 @@ ${NO_PENDING_MIGRATIONS_MESSAGE}
107
75
  } catch (e) {
108
76
  counters.error++;
109
77
  console.error(
110
- import_cli_helpers.colors.error(`Error in data migration: ${e.message}`)
78
+ c.error(`Error in data migration: ${e.message}`)
111
79
  );
112
80
  }
113
81
  }
114
82
  };
115
83
  });
116
- const tasks = new import_listr2.Listr(dataMigrationTasks, {
84
+ const tasks = new Listr(dataMigrationTasks, {
117
85
  renderer: "verbose"
118
86
  });
119
87
  try {
@@ -134,13 +102,13 @@ ${NO_PENDING_MIGRATIONS_MESSAGE}
134
102
  }
135
103
  }
136
104
  async function getPendingDataMigrations(db) {
137
- const dataMigrationsPath = await (0, import_project_config.getDataMigrationsPath)(
138
- (0, import_project_config.getPaths)().api.prismaConfig
105
+ const dataMigrationsPath = await getDataMigrationsPath(
106
+ getPaths().api.prismaConfig
139
107
  );
140
- if (!import_node_fs.default.existsSync(dataMigrationsPath)) {
108
+ if (!fs.existsSync(dataMigrationsPath)) {
141
109
  return [];
142
110
  }
143
- const dataMigrations = import_node_fs.default.readdirSync(dataMigrationsPath).filter(
111
+ const dataMigrations = fs.readdirSync(dataMigrationsPath).filter(
144
112
  (dataMigrationFileName) => ["js", ".ts"].some(
145
113
  (extension) => dataMigrationFileName.endsWith(extension)
146
114
  )
@@ -148,7 +116,7 @@ async function getPendingDataMigrations(db) {
148
116
  const [version] = dataMigrationFileName.split("-");
149
117
  return {
150
118
  version,
151
- path: import_node_path.default.join(dataMigrationsPath, dataMigrationFileName)
119
+ path: path.join(dataMigrationsPath, dataMigrationFileName)
152
120
  };
153
121
  });
154
122
  const ranDataMigrations = await db.rW_DataMigration.findMany(
@@ -176,7 +144,7 @@ function sortDataMigrationsByVersion(dataMigrationA, dataMigrationB) {
176
144
  return 0;
177
145
  }
178
146
  async function runDataMigration(db, dataMigrationPath) {
179
- const dataMigration = require(dataMigrationPath);
147
+ const dataMigration = require2(dataMigrationPath);
180
148
  const startedAt = /* @__PURE__ */ new Date();
181
149
  await dataMigration.default({ db });
182
150
  const finishedAt = /* @__PURE__ */ new Date();
@@ -191,24 +159,23 @@ async function recordDataMigration(db, { version, name, startedAt, finishedAt })
191
159
  function reportDataMigrations(counters) {
192
160
  if (counters.run) {
193
161
  console.info(
194
- import_cli_helpers.colors.success(`${counters.run} data migration(s) completed successfully.`)
162
+ c.success(`${counters.run} data migration(s) completed successfully.`)
195
163
  );
196
164
  }
197
165
  if (counters.error) {
198
166
  console.error(
199
- import_cli_helpers.colors.error(`${counters.error} data migration(s) exited with errors.`)
167
+ c.error(`${counters.error} data migration(s) exited with errors.`)
200
168
  );
201
169
  }
202
170
  if (counters.skipped) {
203
171
  console.warn(
204
- import_cli_helpers.colors.warning(
172
+ c.warning(
205
173
  `${counters.skipped} data migration(s) skipped due to previous error.`
206
174
  )
207
175
  );
208
176
  }
209
177
  }
210
- // Annotate the CommonJS export names for ESM import in node:
211
- 0 && (module.exports = {
178
+ export {
212
179
  NO_PENDING_MIGRATIONS_MESSAGE,
213
180
  handler
214
- });
181
+ };
@@ -1,4 +1,4 @@
1
- import type { DataMigrateUpOptions } from '../types';
1
+ import type { DataMigrateUpOptions } from '../types.js';
2
2
  export declare function handler({ importDbClientFromDist, distPath, }: DataMigrateUpOptions): Promise<void>;
3
3
  export declare const NO_PENDING_MIGRATIONS_MESSAGE = "No pending data migrations run, already up-to-date.";
4
4
  //# sourceMappingURL=upHandlerEsm.d.ts.map
@@ -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,iBAuHtB;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,aAAa,CAAA;AAsCtE,wBAAsB,OAAO,CAAC,EAC5B,sBAAsB,EACtB,QAAQ,GACT,EAAE,oBAAoB,iBAoMtB;AA6DD,eAAO,MAAM,6BAA6B,wDACa,CAAA"}
@@ -1,59 +1,108 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { Listr } from "listr2";
4
+ import { createServer, isRunnableDevEnvironment } from "vite";
5
+ import { colors as c } from "@cedarjs/cli-helpers";
6
+ import {
7
+ getPaths,
8
+ getDataMigrationsPath,
9
+ resolveFile,
10
+ importStatementPath
11
+ } from "@cedarjs/project-config";
12
+ function resolveId(id) {
13
+ if (fs.existsSync(id) && fs.statSync(id).isFile()) {
14
+ return id;
17
15
  }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var upHandlerEsm_exports = {};
30
- __export(upHandlerEsm_exports, {
31
- NO_PENDING_MIGRATIONS_MESSAGE: () => NO_PENDING_MIGRATIONS_MESSAGE,
32
- handler: () => handler
33
- });
34
- module.exports = __toCommonJS(upHandlerEsm_exports);
35
- var import_node_fs = __toESM(require("node:fs"));
36
- var import_node_path = __toESM(require("node:path"));
37
- var import_bundle_require = require("bundle-require");
38
- var import_listr2 = require("listr2");
39
- var import_cli_helpers = require("@cedarjs/cli-helpers");
40
- var import_project_config = require("@cedarjs/project-config");
16
+ const withoutExt = /\.jsx?$/.test(id) ? id.replace(/\.jsx?$/, "") : id;
17
+ for (const ext of [".ts", ".tsx", ".js", ".jsx"]) {
18
+ if (fs.existsSync(withoutExt + ext)) {
19
+ return withoutExt + ext;
20
+ }
21
+ }
22
+ if (fs.existsSync(id) && fs.statSync(id).isDirectory()) {
23
+ for (const base of ["index", path.basename(id)]) {
24
+ for (const ext of [".ts", ".tsx", ".js", ".jsx"]) {
25
+ const candidate = path.join(id, base + ext);
26
+ if (fs.existsSync(candidate)) {
27
+ return candidate;
28
+ }
29
+ }
30
+ }
31
+ }
32
+ return id;
33
+ }
41
34
  async function handler({
42
35
  importDbClientFromDist,
43
36
  distPath
44
37
  }) {
45
38
  let db;
39
+ let server = null;
40
+ let cedarPlugins;
41
+ async function getRunner() {
42
+ if (!server) {
43
+ if (!cedarPlugins) {
44
+ const mod = await import("@cedarjs/vite");
45
+ cedarPlugins = mod;
46
+ }
47
+ server = await createServer({
48
+ mode: "production",
49
+ optimizeDeps: {
50
+ noDiscovery: true,
51
+ include: void 0
52
+ },
53
+ server: {
54
+ hmr: false,
55
+ watch: null
56
+ },
57
+ environments: {
58
+ nodeRunnerEnv: {}
59
+ },
60
+ resolve: {
61
+ alias: [
62
+ {
63
+ find: /^api\//,
64
+ replacement: getPaths().api.base + "/"
65
+ },
66
+ {
67
+ find: /^src\//,
68
+ replacement: "src/",
69
+ customResolver: (id, importer, _options) => {
70
+ const apiImportBase = importStatementPath(getPaths().api.base);
71
+ if (importer?.startsWith(apiImportBase)) {
72
+ const apiImportSrc = importStatementPath(getPaths().api.src);
73
+ const apiId = id.replace("src", apiImportSrc);
74
+ return { id: resolveId(apiId) };
75
+ }
76
+ return null;
77
+ }
78
+ }
79
+ ]
80
+ },
81
+ plugins: [
82
+ cedarPlugins.cedarCjsCompatPlugin(),
83
+ cedarPlugins.cedarjsResolveCedarStyleImportsPlugin(),
84
+ cedarPlugins.cedarImportDirPlugin(),
85
+ cedarPlugins.cedarAutoImportsPlugin()
86
+ ]
87
+ });
88
+ }
89
+ const env = server.environments.nodeRunnerEnv;
90
+ if (!env || !isRunnableDevEnvironment(env)) {
91
+ throw new Error("Vite environment is not runnable.");
92
+ }
93
+ return env.runner;
94
+ }
46
95
  if (importDbClientFromDist) {
47
- if (!import_node_fs.default.existsSync(distPath)) {
96
+ if (!fs.existsSync(distPath)) {
48
97
  console.warn(
49
98
  `Can't find api dist at ${distPath}. You may need to build first: yarn cedar build api`
50
99
  );
51
100
  process.exitCode = 1;
52
101
  return;
53
102
  }
54
- const distLibPath = import_node_path.default.join(distPath, "lib");
55
- const distLibDbPath = import_node_path.default.join(distLibPath, "db.js");
56
- if (!import_node_fs.default.existsSync(distLibDbPath)) {
103
+ const distLibPath = path.join(distPath, "lib");
104
+ const distLibDbPath = path.join(distLibPath, "db.js");
105
+ if (!fs.existsSync(distLibDbPath)) {
57
106
  console.error(
58
107
  `Can't find db.js at ${distLibDbPath}. CedarJS expects the db.js file to be in the ${distLibPath} directory`
59
108
  );
@@ -62,29 +111,33 @@ async function handler({
62
111
  }
63
112
  db = (await import(distLibDbPath)).db;
64
113
  } else {
65
- const dbPath = (0, import_project_config.resolveFile)(import_node_path.default.join((0, import_project_config.getPaths)().api.lib, "db"));
114
+ const dbPath = resolveFile(path.join(getPaths().api.lib, "db"));
66
115
  if (!dbPath) {
67
- console.error(`Can't find your db file in ${(0, import_project_config.getPaths)().api.lib}`);
116
+ console.error(`Can't find your db file in ${getPaths().api.lib}`);
68
117
  process.exitCode = 1;
69
118
  return;
70
119
  }
71
- const { mod } = await (0, import_bundle_require.bundleRequire)({
72
- filepath: dbPath
73
- // TODO: Add plugins
74
- });
75
- db = mod.db;
120
+ try {
121
+ const runner = await getRunner();
122
+ const dbModule = await runner.import(dbPath);
123
+ db = dbModule.db;
124
+ } catch (e) {
125
+ await server?.close();
126
+ throw e;
127
+ }
76
128
  }
77
129
  const pendingDataMigrations = await getPendingDataMigrations(db);
78
130
  if (!pendingDataMigrations.length) {
79
- console.info(import_cli_helpers.colors.success(`
131
+ console.info(c.success(`
80
132
  ${NO_PENDING_MIGRATIONS_MESSAGE}
81
133
  `));
82
134
  process.exitCode = 0;
135
+ await server?.close();
83
136
  return;
84
137
  }
85
138
  const counters = { run: 0, skipped: 0, error: 0 };
86
139
  const dataMigrationTasks = pendingDataMigrations.map((dataMigration) => {
87
- const dataMigrationName = import_node_path.default.basename(dataMigration.path, ".js");
140
+ const dataMigrationName = path.basename(dataMigration.path, ".js");
88
141
  return {
89
142
  title: dataMigrationName,
90
143
  skip() {
@@ -110,14 +163,13 @@ ${NO_PENDING_MIGRATIONS_MESSAGE}
110
163
  });
111
164
  } catch (e) {
112
165
  counters.error++;
113
- console.error(
114
- import_cli_helpers.colors.error(`Error in data migration: ${e.message}`)
115
- );
166
+ const message = e instanceof Error ? e.message : String(e);
167
+ console.error(c.error(`Error in data migration: ${message}`));
116
168
  }
117
169
  }
118
170
  };
119
171
  });
120
- const tasks = new import_listr2.Listr(dataMigrationTasks, {
172
+ const tasks = new Listr(dataMigrationTasks, {
121
173
  renderer: "verbose"
122
174
  });
123
175
  try {
@@ -135,16 +187,29 @@ ${NO_PENDING_MIGRATIONS_MESSAGE}
135
187
  console.log();
136
188
  reportDataMigrations(counters);
137
189
  console.log();
190
+ } finally {
191
+ if (server) {
192
+ await server.close();
193
+ }
194
+ }
195
+ async function runDataMigration(db2, dataMigrationPath) {
196
+ const runner = await getRunner();
197
+ const dataMigrationModule = await runner.import(dataMigrationPath);
198
+ const dataMigration = dataMigrationModule.default;
199
+ const startedAt = /* @__PURE__ */ new Date();
200
+ await dataMigration({ db: db2 });
201
+ const finishedAt = /* @__PURE__ */ new Date();
202
+ return { startedAt, finishedAt };
138
203
  }
139
204
  }
140
205
  async function getPendingDataMigrations(db) {
141
- const dataMigrationsPath = await (0, import_project_config.getDataMigrationsPath)(
142
- (0, import_project_config.getPaths)().api.prismaConfig
206
+ const dataMigrationsPath = await getDataMigrationsPath(
207
+ getPaths().api.prismaConfig
143
208
  );
144
- if (!import_node_fs.default.existsSync(dataMigrationsPath)) {
209
+ if (!fs.existsSync(dataMigrationsPath)) {
145
210
  return [];
146
211
  }
147
- const dataMigrations = import_node_fs.default.readdirSync(dataMigrationsPath).filter(
212
+ const dataMigrations = fs.readdirSync(dataMigrationsPath).filter(
148
213
  (dataMigrationFileName) => ["js", ".ts"].some(
149
214
  (extension) => dataMigrationFileName.endsWith(extension)
150
215
  )
@@ -152,7 +217,7 @@ async function getPendingDataMigrations(db) {
152
217
  const [version] = dataMigrationFileName.split("-");
153
218
  return {
154
219
  version,
155
- path: import_node_path.default.join(dataMigrationsPath, dataMigrationFileName)
220
+ path: path.join(dataMigrationsPath, dataMigrationFileName)
156
221
  };
157
222
  });
158
223
  const ranDataMigrations = await db.rW_DataMigration.findMany(
@@ -179,17 +244,6 @@ function sortDataMigrationsByVersion(dataMigrationA, dataMigrationB) {
179
244
  }
180
245
  return 0;
181
246
  }
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
247
  const NO_PENDING_MIGRATIONS_MESSAGE = "No pending data migrations run, already up-to-date.";
194
248
  async function recordDataMigration(db, { version, name, startedAt, finishedAt }) {
195
249
  await db.rW_DataMigration.create({
@@ -199,24 +253,23 @@ async function recordDataMigration(db, { version, name, startedAt, finishedAt })
199
253
  function reportDataMigrations(counters) {
200
254
  if (counters.run) {
201
255
  console.info(
202
- import_cli_helpers.colors.success(`${counters.run} data migration(s) completed successfully.`)
256
+ c.success(`${counters.run} data migration(s) completed successfully.`)
203
257
  );
204
258
  }
205
259
  if (counters.error) {
206
260
  console.error(
207
- import_cli_helpers.colors.error(`${counters.error} data migration(s) exited with errors.`)
261
+ c.error(`${counters.error} data migration(s) exited with errors.`)
208
262
  );
209
263
  }
210
264
  if (counters.skipped) {
211
265
  console.warn(
212
- import_cli_helpers.colors.warning(
266
+ c.warning(
213
267
  `${counters.skipped} data migration(s) skipped due to previous error.`
214
268
  )
215
269
  );
216
270
  }
217
271
  }
218
- // Annotate the CommonJS export names for ESM import in node:
219
- 0 && (module.exports = {
272
+ export {
220
273
  NO_PENDING_MIGRATIONS_MESSAGE,
221
274
  handler
222
- });
275
+ };
package/dist/index.js CHANGED
@@ -1,35 +1,22 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var index_exports = {};
20
- __export(index_exports, {
21
- commands: () => commands
22
- });
23
- module.exports = __toCommonJS(index_exports);
24
- var import_termi_link = require("termi-link");
25
- var import_install = require("./commands/install");
26
- var import_up = require("./commands/up");
1
+ import { terminalLink } from "termi-link";
2
+ import {
3
+ command as installCommand,
4
+ description as installDescription,
5
+ builder as installBuilder,
6
+ handler as installHandler
7
+ } from "./commands/install.js";
8
+ import {
9
+ command as upCommand,
10
+ description as upDescription,
11
+ builder as upBuilder,
12
+ handler as upHandler
13
+ } from "./commands/up.js";
27
14
  const command = "data-migrate <command>";
28
15
  const aliases = ["dataMigrate", "dm"];
29
16
  const description = "Migrate the data in your database";
30
17
  function builder(yargs) {
31
- yargs.command(import_install.command, import_install.description, import_install.builder, import_install.handler).command(import_up.command, import_up.description, import_up.builder, import_up.handler).epilogue(
32
- `Also see the ${(0, import_termi_link.terminalLink)(
18
+ yargs.command(installCommand, installDescription, installBuilder, installHandler).command(upCommand, upDescription, upBuilder, upHandler).epilogue(
19
+ `Also see the ${terminalLink(
33
20
  "CedarJS CLI Reference",
34
21
  "https://cedarjs.com/docs/cli-commands#datamigrate"
35
22
  )}`
@@ -43,7 +30,6 @@ const commands = [
43
30
  builder
44
31
  }
45
32
  ];
46
- // Annotate the CommonJS export names for ESM import in node:
47
- 0 && (module.exports = {
33
+ export {
48
34
  commands
49
- });
35
+ };
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@cedarjs/cli-data-migrate",
3
- "version": "5.0.3",
3
+ "version": "5.0.4-next.167",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/cedarjs/cedar.git",
7
7
  "directory": "packages/cli-packages/dataMigrate"
8
8
  },
9
9
  "license": "MIT",
10
- "type": "commonjs",
10
+ "type": "module",
11
11
  "exports": "./dist/index.js",
12
12
  "types": "./dist/index.d.ts",
13
13
  "bin": {
@@ -17,32 +17,33 @@
17
17
  "dist"
18
18
  ],
19
19
  "scripts": {
20
- "build": "node ./build.mts && yarn build:types",
20
+ "build": "node ./build.mts",
21
21
  "build:pack": "yarn pack -o cedarjs-cli-data-migrate.tgz",
22
- "build:types": "tsc --build --verbose",
22
+ "build:types": "tsc --build --verbose ./tsconfig.build.json",
23
23
  "prepublishOnly": "NODE_ENV=production yarn build",
24
24
  "test": "yarn test:unit && yarn test:dist",
25
25
  "test:dist": "vitest run ./dist.test.ts",
26
26
  "test:unit": "vitest run src"
27
27
  },
28
28
  "dependencies": {
29
- "@cedarjs/babel-config": "5.0.3",
30
- "@cedarjs/cli-helpers": "5.0.3",
31
- "@cedarjs/project-config": "5.0.3",
32
- "bundle-require": "^5.1.0",
29
+ "@cedarjs/babel-config": "5.0.4-next.167",
30
+ "@cedarjs/cli-helpers": "5.0.4-next.167",
31
+ "@cedarjs/project-config": "5.0.4-next.167",
32
+ "@cedarjs/vite": "5.0.4-next.167",
33
33
  "dotenv-defaults": "5.0.2",
34
34
  "execa": "5.1.1",
35
35
  "listr2": "10.2.2",
36
36
  "termi-link": "1.1.0",
37
+ "vite": "7.3.6",
37
38
  "yargs": "17.7.3"
38
39
  },
39
40
  "devDependencies": {
40
- "@cedarjs/framework-tools": "5.0.3",
41
+ "@cedarjs/framework-tools": "5.0.4-next.167",
41
42
  "@prisma/client": "7.8.0",
42
43
  "@types/yargs": "17.0.35",
43
44
  "memfs": "4.64.0",
44
45
  "typescript": "5.9.3",
45
- "vitest": "3.2.6"
46
+ "vitest": "4.1.10"
46
47
  },
47
48
  "engines": {
48
49
  "node": ">=24"