@pipelab/cli 2.0.0-beta.6 → 2.0.0-beta.9

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.
Files changed (2) hide show
  1. package/index.mjs +95 -29
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -5,12 +5,12 @@ import "./dist-BC_B45iu.mjs";
5
5
  import path, { delimiter, dirname, isAbsolute, join, normalize, resolve, sep } from "node:path";
6
6
  import { fileURLToPath, pathToFileURL } from "node:url";
7
7
  import { constants, homedir, platform, release, tmpdir } from "node:os";
8
- import fs, { appendFileSync, createReadStream, createWriteStream, existsSync, readFileSync, statSync, writeFileSync } from "node:fs";
8
+ import fs, { appendFileSync, createReadStream, createWriteStream, existsSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
9
9
  import http from "http";
10
10
  import http$1 from "node:http";
11
11
  import { webcrypto } from "node:crypto";
12
12
  import { dirname as dirname$1, isAbsolute as isAbsolute$1, posix, relative, sep as sep$1 } from "path";
13
- import fs$1, { access, chmod, cp, mkdir, mkdtemp, readFile, readdir, realpath, rm, stat, unlink, writeFile } from "node:fs/promises";
13
+ import fs$1, { access, chmod, cp, mkdir, mkdtemp, readFile, readdir, realpath, rename, rm, stat, unlink, writeFile } from "node:fs/promises";
14
14
  import { ChildProcess, execFile, spawn, spawnSync } from "node:child_process";
15
15
  import { StringDecoder } from "node:string_decoder";
16
16
  import { aborted, callbackify, debuglog, inspect, promisify, stripVTControlCharacters, styleText } from "node:util";
@@ -104155,6 +104155,25 @@ async function serveCommand(options, version, _dirname) {
104155
104155
  //#region ../../packages/core-node/src/utils/remote.ts
104156
104156
  const DEFAULT_NODE_VERSION = "24.14.1";
104157
104157
  const DEFAULT_PNPM_VERSION = "10.12.0";
104158
+ function isPackageComplete(packageDir) {
104159
+ return existsSync(join(packageDir, "package.json"));
104160
+ }
104161
+ function isNodeJSComplete(nodePath) {
104162
+ try {
104163
+ return existsSync(nodePath) && statSync(nodePath).size > 0;
104164
+ } catch {
104165
+ return false;
104166
+ }
104167
+ }
104168
+ function isDependenciesInstalledSync(packageDir) {
104169
+ const nodeModulesPath = join(packageDir, "node_modules");
104170
+ if (!existsSync(nodeModulesPath)) return false;
104171
+ try {
104172
+ return readdirSync(nodeModulesPath).length > 0;
104173
+ } catch {
104174
+ return false;
104175
+ }
104176
+ }
104158
104177
  /**
104159
104178
  * In-memory lock to prevent concurrent operations on the same resource (e.g., downloading Node.js).
104160
104179
  */
@@ -104207,15 +104226,35 @@ async function fetchPackage(packageName, versionOrRange, options) {
104207
104226
  }
104208
104227
  const cachePath = join(ctx.userDataPath, "cache", "pacote");
104209
104228
  const packageDir = join(baseDir, resolvedVersion);
104210
- if (existsSync(packageDir) && !options?.installDeps) return {
104229
+ if (options?.installDeps ? isPackageComplete(packageDir) && isDependenciesInstalledSync(packageDir) : isPackageComplete(packageDir)) return {
104211
104230
  packageDir,
104212
104231
  resolvedVersion
104213
104232
  };
104214
104233
  return withLock(`package:${packageName}:${resolvedVersion}`, async () => {
104215
- if (!existsSync(packageDir)) {
104234
+ if (!isPackageComplete(packageDir)) {
104216
104235
  console.log(`[Fetcher] ${packageName}@${resolvedVersion}: Downloading to ${packageDir}...`);
104217
- await mkdir(packageDir, { recursive: true });
104218
- await import_lib.default.extract(`${packageName}@${resolvedVersion}`, packageDir, { cache: cachePath });
104236
+ const tempDir = join(baseDir, `.tmp-${resolvedVersion}-${Math.random().toString(36).slice(2)}`);
104237
+ await mkdir(tempDir, { recursive: true });
104238
+ try {
104239
+ await import_lib.default.extract(`${packageName}@${resolvedVersion}`, tempDir, { cache: cachePath });
104240
+ await resolveEntryPoint(tempDir, packageName);
104241
+ if (existsSync(packageDir)) await rm(packageDir, {
104242
+ recursive: true,
104243
+ force: true
104244
+ }).catch(() => {});
104245
+ try {
104246
+ await rename(tempDir, packageDir);
104247
+ } catch (err) {
104248
+ if (isPackageComplete(packageDir)) console.log(`[Fetcher] Destination ${packageDir} already exists and is valid.`);
104249
+ else throw err;
104250
+ }
104251
+ } catch (err) {
104252
+ await rm(tempDir, {
104253
+ recursive: true,
104254
+ force: true
104255
+ }).catch(() => {});
104256
+ throw err;
104257
+ }
104219
104258
  }
104220
104259
  const entryPoint = await resolveEntryPoint(packageDir, packageName);
104221
104260
  if (options?.installDeps) await installDependencies(packageDir, packageName, options);
@@ -104260,9 +104299,9 @@ async function ensureNodeJS(context, version = DEFAULT_NODE_VERSION) {
104260
104299
  const isWindows = process.platform === "win32";
104261
104300
  const nodeDir = context.getThirdPartyPath("node", version);
104262
104301
  const finalNodePath = join(nodeDir, isWindows ? "node.exe" : "bin/node");
104263
- if (existsSync(finalNodePath)) return finalNodePath;
104302
+ if (isNodeJSComplete(finalNodePath)) return finalNodePath;
104264
104303
  return withLock(`node:${version}`, async () => {
104265
- if (existsSync(finalNodePath)) return finalNodePath;
104304
+ if (isNodeJSComplete(finalNodePath)) return finalNodePath;
104266
104305
  const arch = process.arch === "x64" ? "x64" : process.arch === "arm64" ? "arm64" : "x86";
104267
104306
  const platform = isWindows ? "win" : process.platform === "darwin" ? "osx" : "linux";
104268
104307
  const extension = isWindows ? "zip" : "tar.gz";
@@ -104282,17 +104321,33 @@ async function ensureNodeJS(context, version = DEFAULT_NODE_VERSION) {
104282
104321
  const nodeSubDir = (await readdir(extractTempDir)).find((entry) => entry.startsWith(`node-v${version}`));
104283
104322
  if (!nodeSubDir) throw new Error(`Could not find extracted Node.js directory`);
104284
104323
  const sourceDir = join(extractTempDir, nodeSubDir);
104285
- await mkdir(dirname(nodeDir), { recursive: true });
104286
- await rm(nodeDir, {
104287
- recursive: true,
104288
- force: true
104289
- });
104290
- await cp(sourceDir, nodeDir, { recursive: true });
104291
- await rm(tempDir, {
104292
- recursive: true,
104293
- force: true
104294
- });
104295
- if (!isWindows) await chmod(finalNodePath, 493).catch(() => {});
104324
+ const parentDir = dirname(nodeDir);
104325
+ await mkdir(parentDir, { recursive: true });
104326
+ const tempNodeDir = join(parentDir, `.tmp-node-${version}-${Math.random().toString(36).slice(2)}`);
104327
+ await mkdir(tempNodeDir, { recursive: true });
104328
+ try {
104329
+ await cp(sourceDir, tempNodeDir, { recursive: true });
104330
+ if (!isWindows) await chmod(join(tempNodeDir, "bin/node"), 493).catch(() => {});
104331
+ if (existsSync(nodeDir)) await rm(nodeDir, {
104332
+ recursive: true,
104333
+ force: true
104334
+ }).catch(() => {});
104335
+ try {
104336
+ await rename(tempNodeDir, nodeDir);
104337
+ } catch (err) {
104338
+ if (isNodeJSComplete(finalNodePath)) console.log(`[Fetcher] Node.js directory already exists and is valid.`);
104339
+ else throw err;
104340
+ }
104341
+ } finally {
104342
+ await rm(tempNodeDir, {
104343
+ recursive: true,
104344
+ force: true
104345
+ }).catch(() => {});
104346
+ await rm(tempDir, {
104347
+ recursive: true,
104348
+ force: true
104349
+ }).catch(() => {});
104350
+ }
104296
104351
  return finalNodePath;
104297
104352
  });
104298
104353
  }
@@ -104311,25 +104366,36 @@ async function ensurePNPM(context, version = DEFAULT_PNPM_VERSION) {
104311
104366
  }
104312
104367
  async function installDependencies(packageDir, packageName, options) {
104313
104368
  const nodeModulesPath = join(packageDir, "node_modules");
104314
- if (existsSync(nodeModulesPath)) try {
104315
- if ((await readdir(nodeModulesPath)).length === 0) console.warn(`[Fetcher] ${packageName}: node_modules exists but is empty. Re-installing...`);
104316
- else {
104317
- console.log(`[Fetcher] ${packageName}: Dependencies already installed, skipping.`);
104318
- return;
104319
- }
104320
- } catch (e) {}
104321
- console.log(`[Fetcher] ${packageName}: Ensuring dependencies are installed...`);
104369
+ if (isDependenciesInstalledSync(packageDir)) {
104370
+ console.log(`[Fetcher] ${packageName}: Dependencies already installed, skipping.`);
104371
+ return;
104372
+ }
104373
+ const tempDir = `${packageDir}.tmp-deps-${Math.random().toString(36).slice(2)}`;
104374
+ await mkdir(tempDir, { recursive: true });
104322
104375
  try {
104323
- const { all } = await runPnpm(packageDir, {
104376
+ await cp(join(packageDir, "package.json"), join(tempDir, "package.json"));
104377
+ console.log(`[Fetcher] ${packageName}: Ensuring dependencies are installed...`);
104378
+ const { all } = await runPnpm(tempDir, {
104324
104379
  signal: options.signal,
104325
104380
  context: options.context
104326
104381
  });
104327
104382
  if (all) console.log(`[Fetcher] ${packageName}: Installation trace:\n${all}`);
104383
+ const tempNodeModules = join(tempDir, "node_modules");
104384
+ if (existsSync(nodeModulesPath)) await rm(nodeModulesPath, {
104385
+ recursive: true,
104386
+ force: true
104387
+ }).catch(() => {});
104388
+ await rename(tempNodeModules, nodeModulesPath);
104328
104389
  console.log(`[Fetcher] ${packageName}: Dependencies installed successfully.`);
104329
104390
  } catch (err) {
104330
104391
  console.error(`[Fetcher] ${packageName}: CRITICAL ERROR during dependency installation: ${err.message}`);
104331
104392
  if (err.all) console.error(`[Fetcher] ${packageName}: Error details:\n${err.all}`);
104332
104393
  throw new Error(`Failed to install dependencies for ${packageName}. See logs for details.`);
104394
+ } finally {
104395
+ await rm(tempDir, {
104396
+ recursive: true,
104397
+ force: true
104398
+ }).catch(() => {});
104333
104399
  }
104334
104400
  }
104335
104401
  async function fetchPipelabAsset(packageName, versionOrRange, options) {
@@ -105582,7 +105648,7 @@ async function runPipelineCommand(file, options, version) {
105582
105648
  }
105583
105649
  //#endregion
105584
105650
  //#region package.json
105585
- var version$2 = "2.0.0-beta.6";
105651
+ var version$2 = "2.0.0-beta.9";
105586
105652
  //#endregion
105587
105653
  //#region src/paths.ts
105588
105654
  const getDefaultUserDataPath = () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipelab/cli",
3
- "version": "2.0.0-beta.6",
3
+ "version": "2.0.0-beta.9",
4
4
  "description": "The command line interface for Pipelab",
5
5
  "license": "FSL-1.1-MIT",
6
6
  "author": "CynToolkit",