fix: add tsc-alias to resolve TypeScript path aliases in build
Some checks failed
CI/CD Pipeline - Xpeditis PreProd / Frontend - Docker Build & Push (push) Blocked by required conditions
CI/CD Pipeline - Xpeditis PreProd / Deploy to PreProd Server (push) Blocked by required conditions
CI/CD Pipeline - Xpeditis PreProd / Run Smoke Tests (push) Blocked by required conditions
CI/CD Pipeline - Xpeditis PreProd / Backend - Build & Test (push) Failing after 5m54s
CI/CD Pipeline - Xpeditis PreProd / Backend - Docker Build & Push (push) Has been skipped
CI/CD Pipeline - Xpeditis PreProd / Frontend - Build & Test (push) Has been cancelled

Add tsc-alias to resolve @domain/*, @application/*, and @infrastructure/*
path aliases to relative paths in the compiled JavaScript output.

This fixes the 95 TypeScript "Cannot find module" errors in CI/CD that
occurred because nest build (tsc) doesn't resolve path aliases by default.

Changes:
- Install tsc-alias as dev dependency
- Update build script to run tsc-alias after nest build
- Remove temporary fix-imports.js script

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
David 2025-11-16 02:49:43 +01:00
parent c42c3122fb
commit ccdadfb634
3 changed files with 95 additions and 103 deletions

View File

@ -86,6 +86,7 @@
"ts-jest": "^29.1.1",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"tsc-alias": "^1.8.16",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.3.3"
}
@ -9240,6 +9241,19 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/get-tsconfig": {
"version": "4.13.0",
"resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.13.0.tgz",
"integrity": "sha512-1VKTZJCwBrvbd+Wn3AOgQP/2Av+TfTCOlE4AcRJE72W1ksZXbAx8PPBR9RzgTeSPzlPMHrbANMH3LbltH73wxQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"resolve-pkg-maps": "^1.0.0"
},
"funding": {
"url": "https://github.com/privatenumber/get-tsconfig?sponsor=1"
}
},
"node_modules/glob": {
"version": "10.4.5",
"resolved": "https://registry.npmjs.org/glob/-/glob-10.4.5.tgz",
@ -12065,6 +12079,20 @@
"dev": true,
"license": "ISC"
},
"node_modules/mylas": {
"version": "2.1.14",
"resolved": "https://registry.npmjs.org/mylas/-/mylas-2.1.14.tgz",
"integrity": "sha512-BzQguy9W9NJgoVn2mRWzbFrFWWztGCcng2QI9+41frfk+Athwgx3qhqhvStz7ExeUUu7Kzw427sNzHpEZNINog==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=16.0.0"
},
"funding": {
"type": "github",
"url": "https://github.com/sponsors/raouldeheer"
}
},
"node_modules/natural-compare": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz",
@ -13033,6 +13061,19 @@
"node": ">=8"
}
},
"node_modules/plimit-lit": {
"version": "1.6.1",
"resolved": "https://registry.npmjs.org/plimit-lit/-/plimit-lit-1.6.1.tgz",
"integrity": "sha512-B7+VDyb8Tl6oMJT9oSO2CW8XC/T4UcJGrwOVoNGwOQsQYhlpfajmrMj5xeejqaASq3V/EqThyOeATEOMuSEXiA==",
"dev": true,
"license": "MIT",
"dependencies": {
"queue-lit": "^1.5.1"
},
"engines": {
"node": ">=12"
}
},
"node_modules/pluralize": {
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/pluralize/-/pluralize-8.0.0.tgz",
@ -13275,6 +13316,16 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/queue-lit": {
"version": "1.5.2",
"resolved": "https://registry.npmjs.org/queue-lit/-/queue-lit-1.5.2.tgz",
"integrity": "sha512-tLc36IOPeMAubu8BkW8YDBV+WyIgKlYU7zUNs0J5Vk9skSZ4JfGlPOqplP0aHdfv7HL0B2Pg6nwiq60Qc6M2Hw==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=12"
}
},
"node_modules/queue-microtask": {
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz",
@ -13553,6 +13604,16 @@
"node": ">=4"
}
},
"node_modules/resolve-pkg-maps": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz",
"integrity": "sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==",
"dev": true,
"license": "MIT",
"funding": {
"url": "https://github.com/privatenumber/resolve-pkg-maps?sponsor=1"
}
},
"node_modules/resolve.exports": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/resolve.exports/-/resolve.exports-2.0.3.tgz",
@ -15022,6 +15083,38 @@
}
}
},
"node_modules/tsc-alias": {
"version": "1.8.16",
"resolved": "https://registry.npmjs.org/tsc-alias/-/tsc-alias-1.8.16.tgz",
"integrity": "sha512-QjCyu55NFyRSBAl6+MTFwplpFcnm2Pq01rR/uxfqJoLMm6X3O14KEGtaSDZpJYaE1bJBGDjD0eSuiIWPe2T58g==",
"dev": true,
"license": "MIT",
"dependencies": {
"chokidar": "^3.5.3",
"commander": "^9.0.0",
"get-tsconfig": "^4.10.0",
"globby": "^11.0.4",
"mylas": "^2.1.9",
"normalize-path": "^3.0.0",
"plimit-lit": "^1.2.6"
},
"bin": {
"tsc-alias": "dist/bin/index.js"
},
"engines": {
"node": ">=16.20.2"
}
},
"node_modules/tsc-alias/node_modules/commander": {
"version": "9.5.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-9.5.0.tgz",
"integrity": "sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==",
"dev": true,
"license": "MIT",
"engines": {
"node": "^12.20.0 || >=14"
}
},
"node_modules/tsconfig-paths": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-4.2.0.tgz",

View File

@ -4,7 +4,7 @@
"description": "Xpeditis Backend API - Maritime Freight Booking Platform",
"private": true,
"scripts": {
"build": "nest build",
"build": "nest build && tsc-alias",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"dev": "nest start --watch",
@ -102,6 +102,7 @@
"ts-jest": "^29.1.1",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"tsc-alias": "^1.8.16",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.3.3"
},

View File

@ -1,102 +0,0 @@
#!/usr/bin/env node
/**
* Script to fix relative imports to domain/ports/out
* Replaces ../../domain/ports/out/ with @domain/ports/out/
* Replaces ../../../domain/ports/out/ with @domain/ports/out/
*/
const fs = require('fs');
const path = require('path');
const files = [
'apps/backend/src/infrastructure/pdf/pdf.adapter.ts',
'apps/backend/src/infrastructure/carriers/base-carrier.connector.ts',
'apps/backend/src/infrastructure/storage/s3-storage.adapter.ts',
'apps/backend/src/application/services/csv-booking.service.ts',
'apps/backend/src/infrastructure/storage/storage.module.ts',
'apps/backend/src/infrastructure/persistence/typeorm/repositories/typeorm-webhook.repository.ts',
'apps/backend/src/infrastructure/persistence/typeorm/repositories/typeorm-user.repository.ts',
'apps/backend/src/infrastructure/persistence/typeorm/repositories/typeorm-rate-quote.repository.ts',
'apps/backend/src/infrastructure/persistence/typeorm/repositories/typeorm-port.repository.ts',
'apps/backend/src/infrastructure/persistence/typeorm/repositories/typeorm-organization.repository.ts',
'apps/backend/src/infrastructure/persistence/typeorm/repositories/typeorm-notification.repository.ts',
'apps/backend/src/infrastructure/persistence/typeorm/repositories/typeorm-carrier.repository.ts',
'apps/backend/src/infrastructure/persistence/typeorm/repositories/typeorm-booking.repository.ts',
'apps/backend/src/infrastructure/persistence/typeorm/repositories/typeorm-audit-log.repository.ts',
'apps/backend/src/infrastructure/pdf/pdf.module.ts',
'apps/backend/src/infrastructure/email/email.module.ts',
'apps/backend/src/infrastructure/email/email.adapter.ts',
'apps/backend/src/infrastructure/carriers/one/one.mapper.ts',
'apps/backend/src/infrastructure/carriers/one/one.connector.ts',
'apps/backend/src/infrastructure/carriers/msc/msc.mapper.ts',
'apps/backend/src/infrastructure/carriers/msc/msc.connector.ts',
'apps/backend/src/infrastructure/carriers/maersk/maersk.connector.ts',
'apps/backend/src/infrastructure/carriers/maersk/maersk-request.mapper.ts',
'apps/backend/src/infrastructure/carriers/hapag-lloyd/hapag-lloyd.mapper.ts',
'apps/backend/src/infrastructure/carriers/hapag-lloyd/hapag-lloyd.connector.ts',
'apps/backend/src/infrastructure/carriers/cma-cgm/cma-cgm.mapper.ts',
'apps/backend/src/infrastructure/carriers/cma-cgm/cma-cgm.connector.ts',
'apps/backend/src/infrastructure/cache/redis-cache.adapter.ts',
'apps/backend/src/infrastructure/cache/cache.module.ts',
'apps/backend/src/application/webhooks/webhooks.module.ts',
'apps/backend/src/application/users/users.module.ts',
'apps/backend/src/application/services/webhook.service.ts',
'apps/backend/src/application/services/notification.service.ts',
'apps/backend/src/application/services/booking-automation.service.ts',
'apps/backend/src/application/services/audit.service.ts',
'apps/backend/src/application/services/analytics.service.ts',
'apps/backend/src/application/rates/rates.module.ts',
'apps/backend/src/application/organizations/organizations.module.ts',
'apps/backend/src/application/notifications/notifications.module.ts',
'apps/backend/src/application/controllers/users.controller.ts',
'apps/backend/src/application/controllers/organizations.controller.ts',
'apps/backend/src/application/controllers/bookings.controller.ts',
'apps/backend/src/application/controllers/auth.controller.ts',
'apps/backend/src/application/bookings/bookings.module.ts',
'apps/backend/src/application/auth/auth.service.ts',
'apps/backend/src/application/auth/auth.module.ts',
'apps/backend/src/application/audit/audit.module.ts',
];
let totalReplacements = 0;
files.forEach((filePath) => {
const fullPath = path.join(__dirname, filePath);
if (!fs.existsSync(fullPath)) {
console.log(`⚠️ File not found: ${filePath}`);
return;
}
let content = fs.readFileSync(fullPath, 'utf-8');
const originalContent = content;
// Replace ../../../../domain/ports/out/ with @domain/ports/out/
content = content.replace(
/from ['"]\.\.\/\.\.\/\.\.\/\.\.\/domain\/ports\/out\//g,
"from '@domain/ports/out/"
);
// Replace ../../../domain/ports/out/ with @domain/ports/out/
content = content.replace(
/from ['"]\.\.\/\.\.\/\.\.\/domain\/ports\/out\//g,
"from '@domain/ports/out/"
);
// Replace ../../domain/ports/out/ with @domain/ports/out/
content = content.replace(
/from ['"]\.\.\/\.\.\/domain\/ports\/out\//g,
"from '@domain/ports/out/"
);
if (content !== originalContent) {
fs.writeFileSync(fullPath, content, 'utf-8');
totalReplacements++;
console.log(`✅ Fixed: ${filePath}`);
} else {
console.log(`⏭️ No changes: ${filePath}`);
}
});
console.log(`\n✨ Done! Fixed ${totalReplacements} files.`);