@emarketeer/ts-microservice-commons 8.1.1 → 8.2.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.
@@ -677,6 +677,9 @@ if (script === 'cdk-lint') {
677
677
  result = runCommand('npx eslint -c node_modules/@emarketeer/ts-microservice-commons/dist/cdk/.eslintrc', scriptArgs);
678
678
  }
679
679
  if (script === 'jest') {
680
+ // --experimental-vm-modules is required so Jest can execute ES-module files
681
+ // in its VM — used by AWS SDK v3's dynamic credential-provider imports and
682
+ // by @mikro-orm/* (and other ESM-only packages) under EM_JEST_ESM_FRIENDLY=true.
680
683
  result = runCommand('npx cross-env NODE_OPTIONS="--max_old_space_size=4096 --experimental-vm-modules" jest -w 4 --ci --forceExit --config node_modules/@emarketeer/ts-microservice-commons/dist/lib/jest.config.js', scriptArgs);
681
684
  }
682
685
  if (!supportedCommands.includes(script)) {
@@ -0,0 +1,5 @@
1
+ import { preloadMikroOrmModules } from '@eMarketeerSE/runtime-commons';
2
+
3
+ // Runs at worker module-load phase (before beforeAll) when
4
+ await preloadMikroOrmModules();
5
+ //# sourceMappingURL=jest-esm-warmup.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jest-esm-warmup.mjs","sources":["../../src/lib/jest-esm-warmup.ts"],"sourcesContent":["// Runs at worker module-load phase (before beforeAll) when\n// EM_JEST_ESM_FRIENDLY=true. Populates runtime-commons' internal\n// MikroORM / MySqlDriver closure variables so its lazy loader's\n// `if (!MikroORM)` short-circuits during test execution — the\n// dynamic import() never fires, so Jest's ESM teardown invariant\n// can't race it.\nimport { preloadMikroOrmModules } from '@eMarketeerSE/runtime-commons'\n\nawait preloadMikroOrmModules()\n"],"names":[],"mappings":";;AAAA;AAQA,MAAM,sBAAsB,EAAE"}
@@ -5,6 +5,28 @@
5
5
  }(this, (function () { 'use strict';
6
6
 
7
7
  var esModules = ['@eMarketeerSE/runtime-commons'].join('|');
8
+ // Opt-in mode for services that depend on ESM-only packages (e.g. MikroORM).
9
+ // When EM_JEST_ESM_FRIENDLY=true:
10
+ // - ts-jest compiles .ts as ESM (useESM), targeting es2022.
11
+ // - extensionsToTreatAsEsm lets Jest load .ts through its ESM VM loader,
12
+ // the same realm that handles ESM node_modules like @mikro-orm/*.
13
+ // Opting-in services must import { jest } from '@jest/globals' in test files
14
+ // that use jest.* APIs, since the `jest` global is CJS-only.
15
+ var rawEsmFriendly = process.env.EM_JEST_ESM_FRIENDLY;
16
+ var esmFriendly = (rawEsmFriendly === null || rawEsmFriendly === void 0 ? void 0 : rawEsmFriendly.trim().toLowerCase()) === 'true';
17
+ if (rawEsmFriendly !== undefined && !esmFriendly) {
18
+ // eslint-disable-next-line no-console
19
+ console.warn("[em-commons] EM_JEST_ESM_FRIENDLY=".concat(JSON.stringify(rawEsmFriendly), " ignored;")
20
+ + ' expected \'true\'. Falling back to default CJS Jest config.');
21
+ }
22
+ var tsJestTsConfig = {
23
+ target: esmFriendly ? 'es2022' : 'es6'
24
+ };
25
+ if (esmFriendly) {
26
+ // useESM needs an ES module output from TS; otherwise ts-jest still emits
27
+ // `exports.foo = ...` which explodes when Jest loads the file as ESM.
28
+ tsJestTsConfig.module = 'esnext';
29
+ }
8
30
  var config = {
9
31
  verbose: true,
10
32
  testEnvironment: 'node',
@@ -12,10 +34,9 @@
12
34
  '^.+\\.tsx?$': [
13
35
  'ts-jest',
14
36
  {
15
- tsconfig: {
16
- target: 'es6'
17
- },
18
- isolatedModules: true
37
+ tsconfig: tsJestTsConfig,
38
+ isolatedModules: true,
39
+ useESM: esmFriendly
19
40
  }
20
41
  ]
21
42
  },
@@ -26,6 +47,15 @@
26
47
  moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
27
48
  transformIgnorePatterns: ["/node_modules/(?!".concat(esModules, ")")]
28
49
  };
50
+ if (esmFriendly) {
51
+ // Must match the set of TS extensions transformed above (^.+\.tsx?$), or Jest
52
+ // will load .tsx as CJS while ts-jest emits ESM for it and blow up at import.
53
+ config.extensionsToTreatAsEsm = ['.ts', '.tsx'];
54
+ // Preload runtime-commons' MikroORM modules during the worker's stable
55
+ // module-load phase so lazy loaders short-circuit at test time — avoids
56
+ // Jest's ESM teardown invariant racing dynamic imports in MikroORM.
57
+ config.setupFiles = [require.resolve('./jest-esm-warmup.mjs')];
58
+ }
29
59
  var shouldAddSetup = !process.argv.includes('unit');
30
60
  if (shouldAddSetup) {
31
61
  config.globalSetup = '<rootDir>/src/utils/func-test-setup.ts';
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emarketeer/ts-microservice-commons",
3
- "version": "8.1.1",
3
+ "version": "8.2.1",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "bin": {