@oliasoft-open-source/node-json-migrator 4.5.4 → 4.6.0-beta-1

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/index.cjs CHANGED
@@ -3,7 +3,6 @@
3
3
  var path$1 = require('path');
4
4
  var fs = require('fs');
5
5
  var esToolkit = require('es-toolkit');
6
- var moduleFromString = require('module-from-string');
7
6
  var crypto = require('crypto');
8
7
  var node_url = require('node:url');
9
8
  var node_path = require('node:path');
@@ -668,23 +667,10 @@ const capitalize = (word) => {
668
667
  return word[0].toUpperCase() + word.slice(1);
669
668
  };
670
669
 
671
- const loadModuleFromString = async (script) => {
672
- let patchedScript = script;
673
- try {
674
- await Promise.resolve().then(function () { return require('./immer-ZZLkDBss.cjs'); }).then(({ produce }) => {
675
- if (produce) {
676
- patchedScript = script.replace(
677
- /import\s+produce\s+from\s+['"]immer['"]/,
678
- //relaxed detection of extra spaces
679
- "import { produce } from 'immer'"
680
- );
681
- }
682
- });
683
- } catch {
684
- }
685
- return (await moduleFromString.importFromString(patchedScript))?.default ?? null;
670
+ const loadModuleFromPath = async (filePath, fileHash, _script) => {
671
+ return (await import(filePath + "?v=" + fileHash))?.default ?? null;
686
672
  };
687
- const LoaderModule = { loadModuleFromString };
673
+ const LoaderModule = { loadModuleFromPath };
688
674
 
689
675
  const hash = (string) => crypto.createHash("sha256").update(string).digest("hex");
690
676
 
@@ -7615,8 +7601,12 @@ const generatePlanEntries = (sortedMigrationEntries) => sortedMigrationEntries.m
7615
7601
  }));
7616
7602
  const loadMigrationFunctionsFromStrings = async (sortedMigrationEntries, importModule) => Promise.all(
7617
7603
  sortedMigrationEntries.map(async (m) => {
7618
- const { script } = m;
7619
- const migrator = script && importModule ? await LoaderModule.loadModuleFromString(script) : null;
7604
+ const { filePath, fileHash, script } = m;
7605
+ const migrator = filePath && fileHash && importModule ? await LoaderModule.loadModuleFromPath(
7606
+ path$1.resolve(filePath),
7607
+ fileHash,
7608
+ script
7609
+ ) : null;
7620
7610
  return {
7621
7611
  fileHash: m.fileHash,
7622
7612
  migrator
package/dist/index.d.cts CHANGED
@@ -23,6 +23,7 @@ type TMigration = {
23
23
  skippedFileHashes?: string[];
24
24
  sequenceFromHistory?: string;
25
25
  script?: string;
26
+ filePath?: string;
26
27
  migrator?: (payload: TPayload, metaData?: TMetaData) => TPayload;
27
28
  };
28
29
  type TRecordDetails = {
@@ -144,8 +145,7 @@ declare const migrateAll: ({ config, beforeMigrateRecord, afterMigrateRecord, on
144
145
  * - lodash flow https://lodash.com/docs/4.17.15#flow
145
146
  *
146
147
  * Implementation includes exception handling to extend errors with the filename
147
- * until module-with-string fixes its stack trace handling (see OW-8879 and
148
- * https://github.com/exuanbo/module-from-string/issues/18)
148
+ * until native dynamic imports fix their stack trace handling (see OW-8879)
149
149
  */
150
150
  declare const pipe: (migrations: TMigration[], payload: TPayload, metaData?: TMetaData) => TPayload;
151
151
 
package/dist/index.d.mts CHANGED
@@ -23,6 +23,7 @@ type TMigration = {
23
23
  skippedFileHashes?: string[];
24
24
  sequenceFromHistory?: string;
25
25
  script?: string;
26
+ filePath?: string;
26
27
  migrator?: (payload: TPayload, metaData?: TMetaData) => TPayload;
27
28
  };
28
29
  type TRecordDetails = {
@@ -144,8 +145,7 @@ declare const migrateAll: ({ config, beforeMigrateRecord, afterMigrateRecord, on
144
145
  * - lodash flow https://lodash.com/docs/4.17.15#flow
145
146
  *
146
147
  * Implementation includes exception handling to extend errors with the filename
147
- * until module-with-string fixes its stack trace handling (see OW-8879 and
148
- * https://github.com/exuanbo/module-from-string/issues/18)
148
+ * until native dynamic imports fix their stack trace handling (see OW-8879)
149
149
  */
150
150
  declare const pipe: (migrations: TMigration[], payload: TPayload, metaData?: TMetaData) => TPayload;
151
151
 
package/dist/index.mjs CHANGED
@@ -1,7 +1,6 @@
1
1
  import path$1 from 'path';
2
2
  import { realpathSync as realpathSync$1, readlinkSync, readdirSync, readdir as readdir$1, lstatSync, promises } from 'fs';
3
3
  import { isString, xor, merge, omit } from 'es-toolkit';
4
- import { importFromString } from 'module-from-string';
5
4
  import { createHash } from 'crypto';
6
5
  import { fileURLToPath } from 'node:url';
7
6
  import { win32, posix } from 'node:path';
@@ -647,23 +646,10 @@ const capitalize = (word) => {
647
646
  return word[0].toUpperCase() + word.slice(1);
648
647
  };
649
648
 
650
- const loadModuleFromString = async (script) => {
651
- let patchedScript = script;
652
- try {
653
- await import('./immer-CjiV9AMA.mjs').then(({ produce }) => {
654
- if (produce) {
655
- patchedScript = script.replace(
656
- /import\s+produce\s+from\s+['"]immer['"]/,
657
- //relaxed detection of extra spaces
658
- "import { produce } from 'immer'"
659
- );
660
- }
661
- });
662
- } catch {
663
- }
664
- return (await importFromString(patchedScript))?.default ?? null;
649
+ const loadModuleFromPath = async (filePath, fileHash, _script) => {
650
+ return (await import(filePath + "?v=" + fileHash))?.default ?? null;
665
651
  };
666
- const LoaderModule = { loadModuleFromString };
652
+ const LoaderModule = { loadModuleFromPath };
667
653
 
668
654
  const hash = (string) => createHash("sha256").update(string).digest("hex");
669
655
 
@@ -7594,8 +7580,12 @@ const generatePlanEntries = (sortedMigrationEntries) => sortedMigrationEntries.m
7594
7580
  }));
7595
7581
  const loadMigrationFunctionsFromStrings = async (sortedMigrationEntries, importModule) => Promise.all(
7596
7582
  sortedMigrationEntries.map(async (m) => {
7597
- const { script } = m;
7598
- const migrator = script && importModule ? await LoaderModule.loadModuleFromString(script) : null;
7583
+ const { filePath, fileHash, script } = m;
7584
+ const migrator = filePath && fileHash && importModule ? await LoaderModule.loadModuleFromPath(
7585
+ path$1.resolve(filePath),
7586
+ fileHash,
7587
+ script
7588
+ ) : null;
7599
7589
  return {
7600
7590
  fileHash: m.fileHash,
7601
7591
  migrator
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oliasoft-open-source/node-json-migrator",
3
- "version": "4.5.4",
3
+ "version": "4.6.0-beta-1",
4
4
  "description": "A library for JSON migrations",
5
5
  "homepage": "https://oliasoft-open-source.gitlab.io/node-json-migrator",
6
6
  "bugs": {
@@ -39,7 +39,6 @@
39
39
  "ajv": "^8.17.1",
40
40
  "ajv-errors": "^3.0.0",
41
41
  "es-toolkit": "^1.44.0",
42
- "module-from-string": "^3.3.1",
43
42
  "pg-promise": "^11"
44
43
  },
45
44
  "devDependencies": {