@ghom/orm 1.2.0 → 1.2.3

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.
@@ -23,9 +23,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.ORM = void 0;
26
+ const fs_1 = __importDefault(require("fs"));
27
+ const url_1 = __importDefault(require("url"));
28
+ const path_1 = __importDefault(require("path"));
26
29
  const handler_1 = require("@ghom/handler");
27
30
  const knex_1 = __importDefault(require("knex"));
28
- const table_1 = require("./table");
31
+ const table_js_1 = require("./table.js");
29
32
  class ORM extends handler_1.Handler {
30
33
  /**
31
34
  * @param ormConfig configuration for table handler or just tablePath (path to directory that contains js files of tables)
@@ -46,9 +49,11 @@ class ORM extends handler_1.Handler {
46
49
  async init() {
47
50
  this.once("finish", async (pathList) => {
48
51
  const tables = await Promise.all(pathList.map(async (filepath) => {
49
- return Promise.resolve().then(() => __importStar(require(filepath))).then((file) => file.default);
52
+ return Promise.resolve().then(() => __importStar(require(fs_1.default.existsSync(path_1.default.join(__dirname, "..", "..", "cjs"))
53
+ ? filepath
54
+ : url_1.default.pathToFileURL(filepath).href))).then((file) => file.default);
50
55
  }));
51
- const migration = new table_1.Table({
56
+ const migration = new table_js_1.Table({
52
57
  name: "migration",
53
58
  priority: Infinity,
54
59
  setup: (table) => {
package/dist/cjs/index.js CHANGED
@@ -10,5 +10,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./app/orm"), exports);
14
- __exportStar(require("./app/table"), exports);
13
+ __exportStar(require("./app/orm.js"), exports);
14
+ __exportStar(require("./app/table.js"), exports);
@@ -1,6 +1,9 @@
1
+ import fs from "fs";
2
+ import url from "url";
3
+ import path from "path";
1
4
  import { Handler } from "@ghom/handler";
2
5
  import { default as knex } from "knex";
3
- import { Table } from "./table";
6
+ import { Table } from "./table.js";
4
7
  export class ORM extends Handler {
5
8
  db;
6
9
  ormConfig;
@@ -23,7 +26,9 @@ export class ORM extends Handler {
23
26
  async init() {
24
27
  this.once("finish", async (pathList) => {
25
28
  const tables = await Promise.all(pathList.map(async (filepath) => {
26
- return import(filepath).then((file) => file.default);
29
+ return import(fs.existsSync(path.join(__dirname, "..", "..", "cjs"))
30
+ ? filepath
31
+ : url.pathToFileURL(filepath).href).then((file) => file.default);
27
32
  }));
28
33
  const migration = new Table({
29
34
  name: "migration",
package/dist/esm/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export * from "./app/orm";
2
- export * from "./app/table";
1
+ export * from "./app/orm.js";
2
+ export * from "./app/table.js";
@@ -1,2 +1,2 @@
1
- export * from "./app/orm";
2
- export * from "./app/table";
1
+ export * from "./app/orm.js";
2
+ export * from "./app/table.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ghom/orm",
3
- "version": "1.2.0",
3
+ "version": "1.2.3",
4
4
  "license": "MIT",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
package/src/app/orm.ts CHANGED
@@ -1,6 +1,9 @@
1
+ import fs from "fs"
2
+ import url from "url"
3
+ import path from "path"
1
4
  import { Handler } from "@ghom/handler"
2
5
  import { Knex, default as knex } from "knex"
3
- import { MigrationData, Table } from "./table"
6
+ import { MigrationData, Table } from "./table.js"
4
7
 
5
8
  export interface ORMLogger {
6
9
  log: (message: string, section?: string) => void
@@ -44,7 +47,11 @@ export class ORM extends Handler {
44
47
  this.once("finish", async (pathList) => {
45
48
  const tables: Table<any>[] = await Promise.all(
46
49
  pathList.map(async (filepath) => {
47
- return import(filepath).then((file) => file.default)
50
+ return import(
51
+ fs.existsSync(path.join(__dirname, "..", "..", "cjs"))
52
+ ? filepath
53
+ : url.pathToFileURL(filepath).href
54
+ ).then((file) => file.default)
48
55
  })
49
56
  )
50
57
 
package/src/index.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from "./app/orm"
2
- export * from "./app/table"
1
+ export * from "./app/orm.js"
2
+ export * from "./app/table.js"
package/tsconfig.json CHANGED
@@ -3,6 +3,7 @@
3
3
  "strict": true,
4
4
  "rootDir": "src",
5
5
  "target": "es2020",
6
+ "module": "CommonJS",
6
7
  "lib": ["es2020", "dom"],
7
8
  "moduleResolution": "Node",
8
9
  "esModuleInterop": true