Some checks are pending
Bidi Control Character Guard / bidi-control-guard (push) Waiting to run
Circular Dependency Check / Check for new circular dependencies (push) Waiting to run
Citus Migration Smoke / Combined migrations on single-node Citus (push) Waiting to run
E2E Fresh Install Tests / fresh-install-e2e (push) Waiting to run
ext-v2 guardrails / Run ext-v2 guard and ESLint (push) Waiting to run
Integration Tests / Check for relevant changes (push) Waiting to run
Integration Tests / ${{ (github.event_name == 'schedule' || github.event.inputs.suite == 'full') && 'Full integration suite' || 'Tier-1 integration subset' }} (push) Blocked by required conditions
Mobile checks / Mobile lint + typecheck (push) Waiting to run
Mobile checks / Mobile unit tests (push) Waiting to run
Mobile checks / Mobile dependency audit (report) (push) Waiting to run
Mobile checks / Mobile reproducibility checks (push) Waiting to run
Secrets guard (env backups) / Ensure no tracked env backup files (push) Waiting to run
Temporal Readiness / fast-readiness (push) Waiting to run
Temporal Readiness / docker-parity (push) Waiting to run
TypeScript Type Check / Nx affected typecheck (push) Waiting to run
Unit Tests / Skipped-test budget (push) Waiting to run
Unit Tests / Nx affected unit tests (push) Waiting to run
Unit Tests / Server unit coverage (informational) (push) Waiting to run
Validate Tenant Management Schema / Check for relevant changes (push) Waiting to run
Validate Tenant Management Schema / Validate Tenant Management Schema (push) Blocked by required conditions
EE Workflows Build Guard / ee-workflows-build-guard (push) Waiting to run
Excluded: .git, node_modules, secrets/, compose.env, assemblyscript tgz Source: /opt/alga-psa on psa.joliet.tech
125 lines
3.1 KiB
JavaScript
125 lines
3.1 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
const SERVICE_ROOT = path.resolve(__dirname, '..');
|
|
const DIST_ROOT = path.join(SERVICE_ROOT, 'dist');
|
|
const JS_FILE_RE = /\.(?:c|m)?js$/i;
|
|
|
|
function isRelative(specifier) {
|
|
return specifier.startsWith('./') || specifier.startsWith('../');
|
|
}
|
|
|
|
function resolveSuffix(fromFile, specifier) {
|
|
if (!isRelative(specifier) || path.extname(specifier)) {
|
|
return null;
|
|
}
|
|
|
|
const fromDir = path.dirname(fromFile);
|
|
const rawPath = path.resolve(fromDir, specifier);
|
|
|
|
const candidates = [
|
|
{ abs: `${rawPath}.js`, suffix: '.js' },
|
|
{ abs: `${rawPath}.mjs`, suffix: '.mjs' },
|
|
{ abs: `${rawPath}.cjs`, suffix: '.cjs' },
|
|
{ abs: path.join(rawPath, 'index.js'), suffix: '/index.js' },
|
|
{ abs: path.join(rawPath, 'index.mjs'), suffix: '/index.mjs' },
|
|
{ abs: path.join(rawPath, 'index.cjs'), suffix: '/index.cjs' },
|
|
];
|
|
|
|
for (const candidate of candidates) {
|
|
if (fs.existsSync(candidate.abs)) {
|
|
return candidate.suffix;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
function rewriteSource(filePath, source) {
|
|
let updated = source;
|
|
let changed = false;
|
|
|
|
const staticImportRe =
|
|
/((?:import|export)\s+(?:[^'"]*?\sfrom\s*)?)(['"])([^'"]+)(\2)/g;
|
|
const dynamicImportRe = /(import\(\s*)(['"])([^'"]+)(\2)(\s*\))/g;
|
|
|
|
updated = updated.replace(
|
|
staticImportRe,
|
|
(full, prefix, quote, specifier, quoteAgain) => {
|
|
const suffix = resolveSuffix(filePath, specifier);
|
|
if (!suffix) {
|
|
return full;
|
|
}
|
|
changed = true;
|
|
return `${prefix}${quote}${specifier}${suffix}${quoteAgain}`;
|
|
}
|
|
);
|
|
|
|
updated = updated.replace(
|
|
dynamicImportRe,
|
|
(full, prefix, quote, specifier, quoteAgain, suffixPart) => {
|
|
const suffix = resolveSuffix(filePath, specifier);
|
|
if (!suffix) {
|
|
return full;
|
|
}
|
|
changed = true;
|
|
return `${prefix}${quote}${specifier}${suffix}${quoteAgain}${suffixPart}`;
|
|
}
|
|
);
|
|
|
|
return { updated, changed };
|
|
}
|
|
|
|
function walk(dir) {
|
|
const out = [];
|
|
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
for (const entry of entries) {
|
|
const full = path.join(dir, entry.name);
|
|
if (entry.isDirectory()) {
|
|
out.push(...walk(full));
|
|
continue;
|
|
}
|
|
if (entry.isFile() && JS_FILE_RE.test(entry.name)) {
|
|
out.push(full);
|
|
}
|
|
}
|
|
return out;
|
|
}
|
|
|
|
function run() {
|
|
if (!fs.existsSync(DIST_ROOT)) {
|
|
throw new Error(`dist not found at ${DIST_ROOT}`);
|
|
}
|
|
|
|
const files = walk(DIST_ROOT);
|
|
let touched = 0;
|
|
|
|
for (const filePath of files) {
|
|
const source = fs.readFileSync(filePath, 'utf8');
|
|
const { updated, changed } = rewriteSource(filePath, source);
|
|
if (!changed) {
|
|
continue;
|
|
}
|
|
fs.writeFileSync(filePath, updated, 'utf8');
|
|
touched += 1;
|
|
}
|
|
|
|
console.log(
|
|
`Rewrote extensionless relative imports in workflow-worker dist files: ${touched}`
|
|
);
|
|
}
|
|
|
|
try {
|
|
run();
|
|
} catch (error) {
|
|
console.error(
|
|
error instanceof Error ? error.message : String(error)
|
|
);
|
|
process.exit(1);
|
|
}
|