@rudderhq/cli 0.3.6-canary.31 → 0.3.6-canary.32
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.js +180 -25
- package/dist/index.js.map +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3601,23 +3601,6 @@ async function hasRequiredRuntimePlatformDependencies(cacheDir) {
|
|
|
3601
3601
|
if (!platformPackage) return true;
|
|
3602
3602
|
return await canResolveRuntimePackage(cacheDir, platformPackage);
|
|
3603
3603
|
}
|
|
3604
|
-
async function assertRequiredRuntimePlatformDependencies(cacheDir, command, output) {
|
|
3605
|
-
if (!await canResolveRuntimePackage(cacheDir, EMBEDDED_POSTGRES_PACKAGE_NAME)) return;
|
|
3606
|
-
const platformPackage = resolveEmbeddedPostgresPlatformPackage();
|
|
3607
|
-
if (!platformPackage || await canResolveRuntimePackage(cacheDir, platformPackage)) return;
|
|
3608
|
-
throw new RuntimeInstallError(
|
|
3609
|
-
`Rudder runtime installation is missing required platform package ${platformPackage}. Re-run manually: ${command}`,
|
|
3610
|
-
{
|
|
3611
|
-
cacheDir,
|
|
3612
|
-
command,
|
|
3613
|
-
output: [
|
|
3614
|
-
output,
|
|
3615
|
-
`Missing required optional dependency: ${platformPackage}`,
|
|
3616
|
-
"Your npm registry, mirror, proxy, or cache may have skipped the embedded PostgreSQL platform package."
|
|
3617
|
-
].filter((line) => line.trim().length > 0).join("\n")
|
|
3618
|
-
}
|
|
3619
|
-
);
|
|
3620
|
-
}
|
|
3621
3604
|
async function isRuntimeCacheHit(options) {
|
|
3622
3605
|
const packageName = options.packageName ?? RUNTIME_NPM_PACKAGE_NAME;
|
|
3623
3606
|
const packageVersion = resolveRuntimePackageVersion(options.version);
|
|
@@ -3650,13 +3633,36 @@ async function ensureRuntimeInstalled(options) {
|
|
|
3650
3633
|
});
|
|
3651
3634
|
return { status: "hit", cacheDir, packageSpec, command, output: "", ...prune2 ? { prune: prune2 } : {} };
|
|
3652
3635
|
}
|
|
3636
|
+
const spawnSyncImpl = options.spawnSyncImpl ?? spawnSync;
|
|
3637
|
+
const existingRuntimeOutput = await tryRepairExistingRuntimePackage({
|
|
3638
|
+
spawnSyncImpl,
|
|
3639
|
+
cacheDir,
|
|
3640
|
+
packageName,
|
|
3641
|
+
packageVersion
|
|
3642
|
+
});
|
|
3643
|
+
if (existingRuntimeOutput !== null) {
|
|
3644
|
+
const metadata2 = {
|
|
3645
|
+
version: 1,
|
|
3646
|
+
packageName,
|
|
3647
|
+
packageVersion,
|
|
3648
|
+
installedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3649
|
+
lastUsedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
3650
|
+
};
|
|
3651
|
+
await writeRuntimeInstallMetadata(cacheDir, metadata2);
|
|
3652
|
+
const prune2 = await maybePruneRuntimeCache({
|
|
3653
|
+
homeDir: options.homeDir,
|
|
3654
|
+
requestedVersion: packageVersion,
|
|
3655
|
+
enabled: options.pruneRuntimeCache !== false,
|
|
3656
|
+
retention: options.retention
|
|
3657
|
+
});
|
|
3658
|
+
return { status: "installed", cacheDir, packageSpec, command, output: existingRuntimeOutput, ...prune2 ? { prune: prune2 } : {} };
|
|
3659
|
+
}
|
|
3653
3660
|
await rm(cacheDir, { recursive: true, force: true });
|
|
3654
3661
|
await mkdir(cacheDir, { recursive: true });
|
|
3655
|
-
await writeFile(path4.join(cacheDir, "package.json"), `${JSON.stringify(
|
|
3662
|
+
await writeFile(path4.join(cacheDir, "package.json"), `${JSON.stringify(RUNTIME_CACHE_PACKAGE_JSON, null, 2)}
|
|
3656
3663
|
`, "utf8");
|
|
3657
|
-
const spawnSyncImpl = options.spawnSyncImpl ?? spawnSync;
|
|
3658
3664
|
const result = runNpmRuntimeInstall(spawnSyncImpl, cacheDir, packageSpec);
|
|
3659
|
-
|
|
3665
|
+
let output = collectSpawnOutput(result);
|
|
3660
3666
|
if (result.status !== 0 && packageVersion !== "latest" && isVersionNotFoundError(output)) {
|
|
3661
3667
|
const fallbackVersion = "latest";
|
|
3662
3668
|
const fallbackCacheDir = resolveRuntimeCacheDir(fallbackVersion, options.homeDir);
|
|
@@ -3673,12 +3679,15 @@ async function ensureRuntimeInstalled(options) {
|
|
|
3673
3679
|
}
|
|
3674
3680
|
await rm(fallbackCacheDir, { recursive: true, force: true });
|
|
3675
3681
|
await mkdir(fallbackCacheDir, { recursive: true });
|
|
3676
|
-
await writeFile(path4.join(fallbackCacheDir, "package.json"), `${JSON.stringify(
|
|
3682
|
+
await writeFile(path4.join(fallbackCacheDir, "package.json"), `${JSON.stringify(RUNTIME_CACHE_PACKAGE_JSON, null, 2)}
|
|
3677
3683
|
`, "utf8");
|
|
3678
3684
|
const fallbackResult = runNpmRuntimeInstall(spawnSyncImpl, fallbackCacheDir, fallbackSpec);
|
|
3679
|
-
|
|
3685
|
+
let fallbackOutput = collectSpawnOutput(fallbackResult);
|
|
3680
3686
|
if (fallbackResult.status === 0) {
|
|
3681
|
-
|
|
3687
|
+
fallbackOutput = collectOutputParts(
|
|
3688
|
+
fallbackOutput,
|
|
3689
|
+
await ensureRequiredEmbeddedPostgresPlatformPackage(spawnSyncImpl, fallbackCacheDir)
|
|
3690
|
+
);
|
|
3682
3691
|
const fallbackMetadata = {
|
|
3683
3692
|
version: 1,
|
|
3684
3693
|
packageName,
|
|
@@ -3702,7 +3711,10 @@ async function ensureRuntimeInstalled(options) {
|
|
|
3702
3711
|
{ cacheDir, command, output }
|
|
3703
3712
|
);
|
|
3704
3713
|
}
|
|
3705
|
-
|
|
3714
|
+
output = collectOutputParts(
|
|
3715
|
+
output,
|
|
3716
|
+
await ensureRequiredEmbeddedPostgresPlatformPackage(spawnSyncImpl, cacheDir)
|
|
3717
|
+
);
|
|
3706
3718
|
const metadata = {
|
|
3707
3719
|
version: 1,
|
|
3708
3720
|
packageName,
|
|
@@ -3740,9 +3752,139 @@ function runNpmRuntimeInstall(spawnSyncImpl, cacheDir, packageSpec) {
|
|
|
3740
3752
|
function formatRuntimeInstallCommand(cacheDir, packageSpec) {
|
|
3741
3753
|
return `npm install --prefix ${cacheDir} ${RUNTIME_NPM_INSTALL_FLAGS.join(" ")} ${packageSpec}`;
|
|
3742
3754
|
}
|
|
3755
|
+
function formatRuntimePlatformRepairCommand(cacheDir, packageSpec) {
|
|
3756
|
+
return `npm pack ${packageSpec} --registry=${NPM_PUBLIC_REGISTRY_URL} --silent, then extract it into ${path4.join(cacheDir, "node_modules")}`;
|
|
3757
|
+
}
|
|
3743
3758
|
function collectSpawnOutput(result) {
|
|
3744
3759
|
return [result.stdout, result.stderr, result.error instanceof Error ? result.error.message : null].filter((value) => typeof value === "string" && value.trim().length > 0).join("\n").trim();
|
|
3745
3760
|
}
|
|
3761
|
+
function collectOutputParts(...parts) {
|
|
3762
|
+
return parts.filter((part) => part.trim().length > 0).join("\n").trim();
|
|
3763
|
+
}
|
|
3764
|
+
function runtimePackageJsonPath(cacheDir, packageName) {
|
|
3765
|
+
return path4.join(cacheDir, "node_modules", ...packageName.split("/"), "package.json");
|
|
3766
|
+
}
|
|
3767
|
+
async function readRuntimePackageJson(cacheDir, packageName) {
|
|
3768
|
+
try {
|
|
3769
|
+
return JSON.parse(await readFile(runtimePackageJsonPath(cacheDir, packageName), "utf8"));
|
|
3770
|
+
} catch {
|
|
3771
|
+
return null;
|
|
3772
|
+
}
|
|
3773
|
+
}
|
|
3774
|
+
async function tryRepairExistingRuntimePackage(options) {
|
|
3775
|
+
const runtimePackage = await readRuntimePackageJson(options.cacheDir, options.packageName);
|
|
3776
|
+
if (!runtimePackage) return null;
|
|
3777
|
+
if (options.packageVersion !== "latest" && runtimePackage.version !== options.packageVersion) return null;
|
|
3778
|
+
const output = await ensureRequiredEmbeddedPostgresPlatformPackage(options.spawnSyncImpl, options.cacheDir);
|
|
3779
|
+
return await hasRequiredRuntimePlatformDependencies(options.cacheDir) ? output : null;
|
|
3780
|
+
}
|
|
3781
|
+
async function resolveEmbeddedPostgresPlatformPackageSpec(cacheDir) {
|
|
3782
|
+
if (!await canResolveRuntimePackage(cacheDir, EMBEDDED_POSTGRES_PACKAGE_NAME)) return null;
|
|
3783
|
+
const packageName = resolveEmbeddedPostgresPlatformPackage();
|
|
3784
|
+
if (!packageName) return null;
|
|
3785
|
+
const embeddedPostgresPackage = await readRuntimePackageJson(cacheDir, EMBEDDED_POSTGRES_PACKAGE_NAME);
|
|
3786
|
+
const versionRange = embeddedPostgresPackage?.optionalDependencies?.[packageName];
|
|
3787
|
+
const packageVersion = normalizeOptionalDependencyVersion(versionRange);
|
|
3788
|
+
return packageVersion ? `${packageName}@${packageVersion}` : packageName;
|
|
3789
|
+
}
|
|
3790
|
+
async function ensureRequiredEmbeddedPostgresPlatformPackage(spawnSyncImpl, cacheDir) {
|
|
3791
|
+
const packageSpec = await resolveEmbeddedPostgresPlatformPackageSpec(cacheDir);
|
|
3792
|
+
if (!packageSpec) return "";
|
|
3793
|
+
const packageName = packageNameFromSpec(packageSpec);
|
|
3794
|
+
if (packageName && await canResolveRuntimePackage(cacheDir, packageName)) return "";
|
|
3795
|
+
await removeRuntimeInstallLocks(cacheDir);
|
|
3796
|
+
const result = await installRuntimePackageInStaging(spawnSyncImpl, cacheDir, packageSpec, packageName);
|
|
3797
|
+
const output = collectSpawnOutput(result);
|
|
3798
|
+
if (result.status === 0 && packageName && await canResolveRuntimePackage(cacheDir, packageName)) {
|
|
3799
|
+
return output;
|
|
3800
|
+
}
|
|
3801
|
+
const command = formatRuntimePlatformRepairCommand(cacheDir, packageSpec);
|
|
3802
|
+
throw new RuntimeInstallError(
|
|
3803
|
+
`Rudder runtime installation is missing required platform package ${packageName || packageSpec}. Re-run manually: ${command}`,
|
|
3804
|
+
{ cacheDir, command, output }
|
|
3805
|
+
);
|
|
3806
|
+
}
|
|
3807
|
+
async function installRuntimePackageInStaging(spawnSyncImpl, cacheDir, packageSpec, packageName) {
|
|
3808
|
+
const stagingDir = path4.join(cacheDir, `.platform-repair-${process.pid}-${Date.now()}`);
|
|
3809
|
+
await mkdir(stagingDir, { recursive: true });
|
|
3810
|
+
try {
|
|
3811
|
+
const packResult = runNpmPack(spawnSyncImpl, packageSpec, stagingDir);
|
|
3812
|
+
if (packResult.status !== 0) return packResult;
|
|
3813
|
+
const packFilename = parseNpmPackFilename(packResult.stdout);
|
|
3814
|
+
if (!packFilename) {
|
|
3815
|
+
return createSyntheticSpawnResult(1, "", `Unable to parse npm pack output for ${packageSpec}.`);
|
|
3816
|
+
}
|
|
3817
|
+
const archivePath = path4.join(stagingDir, packFilename);
|
|
3818
|
+
const targetDir = path4.dirname(runtimePackageJsonPath(cacheDir, packageName));
|
|
3819
|
+
await mkdir(path4.dirname(targetDir), { recursive: true });
|
|
3820
|
+
await rm(targetDir, { recursive: true, force: true });
|
|
3821
|
+
await mkdir(targetDir, { recursive: true });
|
|
3822
|
+
const extractResult = runTarExtract(spawnSyncImpl, archivePath, targetDir);
|
|
3823
|
+
return combineSpawnResults(packResult, extractResult);
|
|
3824
|
+
} finally {
|
|
3825
|
+
await rm(stagingDir, { recursive: true, force: true });
|
|
3826
|
+
}
|
|
3827
|
+
}
|
|
3828
|
+
function runNpmPack(spawnSyncImpl, packageSpec, destinationDir) {
|
|
3829
|
+
return spawnSyncImpl(
|
|
3830
|
+
process.platform === "win32" ? "npm.cmd" : "npm",
|
|
3831
|
+
["pack", packageSpec, "--pack-destination", destinationDir, ...RUNTIME_NPM_PACK_FLAGS],
|
|
3832
|
+
{
|
|
3833
|
+
encoding: "utf8",
|
|
3834
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
3835
|
+
env: { ...process.env, ...NPM_PLATFORM_REPAIR_ENV },
|
|
3836
|
+
...process.platform === "win32" ? { shell: true, windowsHide: true } : {}
|
|
3837
|
+
}
|
|
3838
|
+
);
|
|
3839
|
+
}
|
|
3840
|
+
function runTarExtract(spawnSyncImpl, archivePath, targetDir) {
|
|
3841
|
+
return spawnSyncImpl(
|
|
3842
|
+
"tar",
|
|
3843
|
+
["-xzf", archivePath, "-C", targetDir, "--strip-components", "1"],
|
|
3844
|
+
{
|
|
3845
|
+
encoding: "utf8",
|
|
3846
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
3847
|
+
...process.platform === "win32" ? { windowsHide: true } : {}
|
|
3848
|
+
}
|
|
3849
|
+
);
|
|
3850
|
+
}
|
|
3851
|
+
function parseNpmPackFilename(stdout) {
|
|
3852
|
+
if (typeof stdout !== "string") return null;
|
|
3853
|
+
const filename = stdout.trim().split(/\r?\n/).filter(Boolean).at(-1);
|
|
3854
|
+
return filename?.endsWith(".tgz") ? filename : null;
|
|
3855
|
+
}
|
|
3856
|
+
function createSyntheticSpawnResult(status, stdout, stderr) {
|
|
3857
|
+
return { status, stdout, stderr };
|
|
3858
|
+
}
|
|
3859
|
+
function combineSpawnResults(...results) {
|
|
3860
|
+
const last = results.at(-1);
|
|
3861
|
+
return {
|
|
3862
|
+
status: last?.status ?? 0,
|
|
3863
|
+
stdout: results.map((result) => result.stdout).filter(Boolean).join("\n"),
|
|
3864
|
+
stderr: results.map((result) => result.stderr).filter(Boolean).join("\n"),
|
|
3865
|
+
error: results.find((result) => result.error)?.error
|
|
3866
|
+
};
|
|
3867
|
+
}
|
|
3868
|
+
async function removeRuntimeInstallLocks(cacheDir) {
|
|
3869
|
+
await Promise.all([
|
|
3870
|
+
rm(path4.join(cacheDir, "package-lock.json"), { force: true }),
|
|
3871
|
+
rm(path4.join(cacheDir, "node_modules", ".package-lock.json"), { force: true })
|
|
3872
|
+
]);
|
|
3873
|
+
}
|
|
3874
|
+
function packageNameFromSpec(packageSpec) {
|
|
3875
|
+
if (!packageSpec.startsWith("@")) {
|
|
3876
|
+
const versionSeparator2 = packageSpec.indexOf("@");
|
|
3877
|
+
return versionSeparator2 === -1 ? packageSpec : packageSpec.slice(0, versionSeparator2);
|
|
3878
|
+
}
|
|
3879
|
+
const versionSeparator = packageSpec.indexOf("@", 1);
|
|
3880
|
+
return versionSeparator === -1 ? packageSpec : packageSpec.slice(0, versionSeparator);
|
|
3881
|
+
}
|
|
3882
|
+
function normalizeOptionalDependencyVersion(versionRange) {
|
|
3883
|
+
const trimmed = versionRange?.trim();
|
|
3884
|
+
if (!trimmed) return null;
|
|
3885
|
+
const exactVersion = /^[~^]\s*([0-9]+\.[0-9]+\.[0-9]+(?:-[0-9A-Za-z.-]+)?)$/.exec(trimmed);
|
|
3886
|
+
return exactVersion?.[1] ?? trimmed;
|
|
3887
|
+
}
|
|
3746
3888
|
function isVersionNotFoundError(output) {
|
|
3747
3889
|
const normalized = output.toLowerCase();
|
|
3748
3890
|
return normalized.includes("enoent") || normalized.includes("etarget") || normalized.includes("no matching version found");
|
|
@@ -3968,19 +4110,32 @@ function parseRuntimeVersion(version) {
|
|
|
3968
4110
|
canaryNumber: canaryMatch ? Number(canaryMatch[1]) : null
|
|
3969
4111
|
};
|
|
3970
4112
|
}
|
|
3971
|
-
var RUNTIME_NPM_PACKAGE_NAME, RUNTIME_METADATA_FILE, DEFAULT_RUNTIME_CACHE_MAX_ENTRIES, DEFAULT_RUNTIME_CACHE_MAX_AGE_MS, DEFAULT_RUNTIME_CACHE_MAX_BYTES, DEFAULT_RUNTIME_CACHE_KEEP_PREVIOUS, RUNTIME_NPM_INSTALL_FLAGS, EMBEDDED_POSTGRES_PACKAGE_NAME, RuntimeInstallError;
|
|
4113
|
+
var RUNTIME_NPM_PACKAGE_NAME, NPM_PUBLIC_REGISTRY_URL, RUNTIME_METADATA_FILE, DEFAULT_RUNTIME_CACHE_MAX_ENTRIES, DEFAULT_RUNTIME_CACHE_MAX_AGE_MS, DEFAULT_RUNTIME_CACHE_MAX_BYTES, DEFAULT_RUNTIME_CACHE_KEEP_PREVIOUS, RUNTIME_NPM_INSTALL_FLAGS, RUNTIME_NPM_PACK_FLAGS, EMBEDDED_POSTGRES_PACKAGE_NAME, RUNTIME_CACHE_PACKAGE_JSON, NPM_PLATFORM_REPAIR_ENV, RuntimeInstallError;
|
|
3972
4114
|
var init_install = __esm({
|
|
3973
4115
|
"src/runtime/install.ts"() {
|
|
3974
4116
|
"use strict";
|
|
3975
4117
|
init_home();
|
|
3976
4118
|
RUNTIME_NPM_PACKAGE_NAME = "@rudderhq/server";
|
|
4119
|
+
NPM_PUBLIC_REGISTRY_URL = "https://registry.npmjs.org";
|
|
3977
4120
|
RUNTIME_METADATA_FILE = "runtime.json";
|
|
3978
4121
|
DEFAULT_RUNTIME_CACHE_MAX_ENTRIES = 2;
|
|
3979
4122
|
DEFAULT_RUNTIME_CACHE_MAX_AGE_MS = 14 * 24 * 60 * 60 * 1e3;
|
|
3980
4123
|
DEFAULT_RUNTIME_CACHE_MAX_BYTES = 2 * 1024 * 1024 * 1024;
|
|
3981
4124
|
DEFAULT_RUNTIME_CACHE_KEEP_PREVIOUS = 0;
|
|
3982
4125
|
RUNTIME_NPM_INSTALL_FLAGS = ["--omit=dev", "--include=optional", "--no-audit", "--no-fund"];
|
|
4126
|
+
RUNTIME_NPM_PACK_FLAGS = ["--registry", NPM_PUBLIC_REGISTRY_URL, "--silent"];
|
|
3983
4127
|
EMBEDDED_POSTGRES_PACKAGE_NAME = "embedded-postgres";
|
|
4128
|
+
RUNTIME_CACHE_PACKAGE_JSON = {
|
|
4129
|
+
name: "rudder-runtime-cache",
|
|
4130
|
+
version: "0.0.0",
|
|
4131
|
+
private: true,
|
|
4132
|
+
type: "module"
|
|
4133
|
+
};
|
|
4134
|
+
NPM_PLATFORM_REPAIR_ENV = {
|
|
4135
|
+
npm_config_registry: NPM_PUBLIC_REGISTRY_URL,
|
|
4136
|
+
npm_config_update_notifier: "false",
|
|
4137
|
+
NO_UPDATE_NOTIFIER: "1"
|
|
4138
|
+
};
|
|
3984
4139
|
RuntimeInstallError = class extends Error {
|
|
3985
4140
|
cacheDir;
|
|
3986
4141
|
command;
|