@worm-print-platform/marketplace 1.6.3 → 1.6.5

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.
@@ -1,5 +1,6 @@
1
1
  // src/manifest.ts
2
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
2
+ import { randomUUID } from "crypto";
3
+ import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "fs";
3
4
  import { dirname, isAbsolute, join, resolve } from "path";
4
5
  function absPath(p, cwd) {
5
6
  return isAbsolute(p) ? p : resolve(cwd, p);
@@ -15,8 +16,15 @@ function readManifest(dir, cwd = process.cwd()) {
15
16
  function writeManifest(dir, manifest, cwd = process.cwd()) {
16
17
  const path = manifestPath(dir, cwd);
17
18
  mkdirSync(dirname(path), { recursive: true });
18
- writeFileSync(path, `${JSON.stringify(manifest, null, 2)}
19
+ const tmp = `${path}.${process.pid}.${randomUUID()}.tmp`;
20
+ try {
21
+ writeFileSync(tmp, `${JSON.stringify(manifest, null, 2)}
19
22
  `, "utf8");
23
+ renameSync(tmp, path);
24
+ } catch (err) {
25
+ rmSync(tmp, { force: true });
26
+ throw err;
27
+ }
20
28
  }
21
29
  function upsertManifestEntry(dir, id, entry, cwd = process.cwd()) {
22
30
  const manifest = readManifest(dir, cwd);
@@ -136,7 +144,7 @@ function resolveGitSource(source, repo) {
136
144
 
137
145
  // src/install.ts
138
146
  import { execFile } from "child_process";
139
- import { cpSync, existsSync as existsSync2, mkdirSync as mkdirSync2, mkdtempSync, readFileSync as readFileSync2, readdirSync, renameSync, rmSync } from "fs";
147
+ import { cpSync, existsSync as existsSync2, mkdirSync as mkdirSync2, mkdtempSync, readFileSync as readFileSync2, readdirSync, renameSync as renameSync2, rmSync as rmSync2 } from "fs";
140
148
  import { tmpdir } from "os";
141
149
  import { dirname as dirname2, isAbsolute as isAbsolute2, join as join2, resolve as resolve2 } from "path";
142
150
  import { promisify } from "util";
@@ -238,7 +246,7 @@ async function fetchGit(options, id, source, cwd, gitExecutor) {
238
246
  const version = fromHead ? void 0 : resolveVersion(source, tags, options.version);
239
247
  const tag = version ? buildGitTag(id, version) : void 0;
240
248
  const tmp = mkdtempSync(join2(tmpdir(), `mp-git-${id}-`));
241
- const cleanup = () => rmSync(tmp, { recursive: true, force: true });
249
+ const cleanup = () => rmSync2(tmp, { recursive: true, force: true });
242
250
  try {
243
251
  await gitExecutor([
244
252
  "clone",
@@ -273,7 +281,7 @@ function copyFiles(sourceDir, target, meta) {
273
281
  if (existsSync2(src)) cpSync(src, join2(target, file), { recursive: true });
274
282
  }
275
283
  }
276
- function syncLocaleResources(sourceDir, pluginTarget, id) {
284
+ function stageLocaleResources(sourceDir, pluginTarget, id) {
277
285
  const pkgFile = join2(sourceDir, "package.json");
278
286
  if (!existsSync2(pkgFile)) return void 0;
279
287
  const raw = JSON.parse(readFileSync2(pkgFile, "utf8"));
@@ -282,13 +290,21 @@ function syncLocaleResources(sourceDir, pluginTarget, id) {
282
290
  const from = join2(sourceDir, i18n.dir);
283
291
  if (!existsSync2(from)) throw new MarketError("INVALID_PLUGIN", `\u58F0\u660E\u4E86 wormPrint.i18n \u4F46\u76EE\u5F55\u4E0D\u5B58\u5728\uFF1A${i18n.dir}`);
284
292
  const to = join2(dirname2(dirname2(pluginTarget)), "i18n", id);
285
- const tmp = `${to}.tmp`;
286
- rmSync(tmp, { recursive: true, force: true });
287
- cpSync(from, tmp, { recursive: true });
288
- rmSync(to, { recursive: true, force: true });
289
- renameSync(tmp, to);
293
+ mkdirSync2(dirname2(to), { recursive: true });
294
+ const tmp = mkdtempSync(join2(dirname2(to), `.${id}.tmp-`));
295
+ try {
296
+ cpSync(from, tmp, { recursive: true });
297
+ } catch (err) {
298
+ rmSync2(tmp, { recursive: true, force: true });
299
+ throw err;
300
+ }
290
301
  const locales = readdirSync(from).filter((f) => f.endsWith(".json")).map((f) => f.slice(0, -5));
291
- return { base: i18n.base ?? "zh-CN", locales };
302
+ return { staged: tmp, base: i18n.base ?? "zh-CN", locales };
303
+ }
304
+ function reserveBackupPath(target, id) {
305
+ const backup = mkdtempSync(join2(dirname2(target), `.${id}.old-`));
306
+ rmSync2(backup, { recursive: true, force: true });
307
+ return backup;
292
308
  }
293
309
  async function installPlugin(options) {
294
310
  const cwd = options.cwd ?? process.cwd();
@@ -317,24 +333,83 @@ async function installPlugin(options) {
317
333
  if (!existsSync2(join2(fetched.sourceDir, fetched.meta.entry))) {
318
334
  throw new MarketError("INVALID_PLUGIN", `\u63D2\u4EF6\u5165\u53E3\u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${fetched.meta.entry}`);
319
335
  }
320
- mkdirSync2(target, { recursive: true });
321
- copyFiles(fetched.sourceDir, target, fetched.meta);
322
- const i18n = syncLocaleResources(fetched.sourceDir, target, id);
323
- upsertManifestEntry(dir, id, {
324
- version: fetched.version,
325
- i18n,
326
- entry: fetched.meta.entry,
327
- kinds: fetched.meta.kinds,
328
- exportFormats: fetched.meta.exportFormats,
329
- npmName,
330
- source: source === "local" ? { mode: source, path: options.repo } : source === "npm" ? { mode: source } : {
331
- mode: source,
332
- repo: options.repo ?? void 0,
333
- tag: fetched.stable === false ? void 0 : buildGitTag(id, fetched.version)
334
- },
335
- stable: fetched.stable !== false,
336
- installedAt: (/* @__PURE__ */ new Date()).toISOString()
337
- }, cwd);
336
+ mkdirSync2(dirname2(target), { recursive: true });
337
+ const pluginStage = mkdtempSync(join2(dirname2(target), `.${id}.tmp-`));
338
+ const localeTarget = join2(dirname2(dirname2(target)), "i18n", id);
339
+ let localeStage;
340
+ let pluginBackup;
341
+ let localeBackup;
342
+ let pluginBackedUp = false;
343
+ let localeBackedUp = false;
344
+ let pluginSwitched = false;
345
+ let localeSwitched = false;
346
+ let committed = false;
347
+ try {
348
+ copyFiles(fetched.sourceDir, pluginStage, fetched.meta);
349
+ localeStage = stageLocaleResources(fetched.sourceDir, pluginStage, id);
350
+ if (existsSync2(target)) {
351
+ pluginBackup = reserveBackupPath(target, id);
352
+ renameSync2(target, pluginBackup);
353
+ pluginBackedUp = true;
354
+ }
355
+ renameSync2(pluginStage, target);
356
+ pluginSwitched = true;
357
+ if (localeStage || existsSync2(localeTarget)) {
358
+ if (existsSync2(localeTarget)) {
359
+ localeBackup = reserveBackupPath(localeTarget, id);
360
+ renameSync2(localeTarget, localeBackup);
361
+ localeBackedUp = true;
362
+ }
363
+ if (localeStage) renameSync2(localeStage.staged, localeTarget);
364
+ localeSwitched = true;
365
+ }
366
+ upsertManifestEntry(dir, id, {
367
+ version: fetched.version,
368
+ i18n: localeStage ? { base: localeStage.base, locales: localeStage.locales } : void 0,
369
+ entry: fetched.meta.entry,
370
+ kinds: fetched.meta.kinds,
371
+ exportFormats: fetched.meta.exportFormats,
372
+ npmName,
373
+ source: source === "local" ? { mode: source, path: options.repo } : source === "npm" ? { mode: source } : {
374
+ mode: source,
375
+ repo: options.repo ?? void 0,
376
+ tag: fetched.stable === false ? void 0 : buildGitTag(id, fetched.version)
377
+ },
378
+ stable: fetched.stable !== false,
379
+ installedAt: (/* @__PURE__ */ new Date()).toISOString()
380
+ }, cwd);
381
+ committed = true;
382
+ } catch (err) {
383
+ const rollbackErrors = [];
384
+ const attempt = (action) => {
385
+ try {
386
+ action();
387
+ } catch (rollbackError) {
388
+ rollbackErrors.push(rollbackError);
389
+ }
390
+ };
391
+ if (pluginSwitched) attempt(() => rmSync2(target, { recursive: true, force: true }));
392
+ if (localeSwitched) attempt(() => rmSync2(localeTarget, { recursive: true, force: true }));
393
+ if (pluginBackedUp && pluginBackup) attempt(() => renameSync2(pluginBackup, target));
394
+ if (localeBackedUp && localeBackup) attempt(() => renameSync2(localeBackup, localeTarget));
395
+ if (rollbackErrors.length) {
396
+ const failure = new Error(`\u63D2\u4EF6\u5B89\u88C5\u5931\u8D25\u4E14\u56DE\u6EDA\u672A\u5B8C\u6210\uFF1A${id}\uFF1B\u539F\u59CB\u9519\u8BEF\uFF1A${err instanceof Error ? err.message : String(err)}`);
397
+ failure.cause = err;
398
+ throw failure;
399
+ }
400
+ throw err;
401
+ } finally {
402
+ const cleanup = (path) => {
403
+ try {
404
+ rmSync2(path, { recursive: true, force: true });
405
+ } catch {
406
+ }
407
+ };
408
+ cleanup(pluginStage);
409
+ if (localeStage) cleanup(localeStage.staged);
410
+ if (committed && pluginBackup) cleanup(pluginBackup);
411
+ if (committed && localeBackup) cleanup(localeBackup);
412
+ }
338
413
  return {
339
414
  id,
340
415
  version: fetched.version,
@@ -366,8 +441,8 @@ async function removePlugin(options) {
366
441
  }
367
442
  }
368
443
  const pluginDir = absPath2(join2(dir, id), cwd);
369
- rmSync(pluginDir, { recursive: true, force: true });
370
- rmSync(join2(dirname2(dirname2(pluginDir)), "i18n", id), { recursive: true, force: true });
444
+ rmSync2(pluginDir, { recursive: true, force: true });
445
+ rmSync2(join2(dirname2(dirname2(pluginDir)), "i18n", id), { recursive: true, force: true });
371
446
  removeManifestEntry(dir, id, cwd);
372
447
  }
373
448
 
@@ -436,7 +511,7 @@ var BUNDLED_CATALOG = {
436
511
  "zh-CN": "\u57FA\u4E8E ECharts \u7684\u5341\u7C7B\u6253\u5370\u56FE\u8868\u5143\u7D20\uFF0C\u6D4F\u89C8\u5668\u4E0E\u670D\u52A1\u7AEF\u540C\u6784\u51FA\u56FE\u3002\u672C\u63D2\u4EF6\u901A\u8FC7\u63D2\u4EF6\u5E02\u573A CLI \u5206\u53D1\uFF0C\u4E0D\u518D\u5355\u72EC\u53D1\u5E03 npm\uFF1B\u517C\u5BB9\u5E93 @worm-print-platform/echarts \u7EE7\u7EED\u72EC\u7ACB\u53D1\u5E03\u3002",
437
512
  "en": "Ten print chart elements based on ECharts, rendered isomorphically in browser and server. Distributed via the plugin marketplace CLI."
438
513
  },
439
- "version": "1.6.3",
514
+ "version": "1.6.5",
440
515
  "npmName": "@worm-print-platform/plugin-echarts",
441
516
  "path": "plugins/echarts",
442
517
  "entry": "dist/marketplace.js",
@@ -459,20 +534,20 @@ var BUNDLED_CATALOG = {
459
534
  "engines": {
460
535
  "core": ">=1.5.2 <2"
461
536
  },
462
- "publishTimestamp": 1795427088,
537
+ "publishTimestamp": 1795530080,
463
538
  "metadata": {
464
539
  "category": "element",
465
540
  "labels": [
466
541
  "official"
467
542
  ],
468
543
  "sortKeys": {
469
- "publishedAt": 1795427088
544
+ "publishedAt": 1795530080
470
545
  }
471
546
  },
472
547
  "versions": [
473
548
  {
474
- "version": "1.6.3",
475
- "publishTimestamp": 1795427088,
549
+ "version": "1.6.5",
550
+ "publishTimestamp": 1795530080,
476
551
  "engines": {
477
552
  "core": ">=1.5.2 <2"
478
553
  }
package/dist/cli.js CHANGED
@@ -6,12 +6,12 @@ import {
6
6
  localize,
7
7
  removePlugin,
8
8
  validateIndex
9
- } from "./chunk-3ACIXWGF.js";
9
+ } from "./chunk-SIIHBJ4M.js";
10
10
 
11
11
  // src/cli.ts
12
12
  import { realpathSync } from "fs";
13
13
  import { pathToFileURL } from "url";
14
- var VERSION = true ? "1.6.3" : "1.6.3";
14
+ var VERSION = true ? "1.6.5" : "1.6.5";
15
15
  var SOURCES = /* @__PURE__ */ new Set(["npm", "github", "gitee", "auto", "local"]);
16
16
  var PLUGIN_TYPES = /* @__PURE__ */ new Set(["element", "functional", "export"]);
17
17
  var VALUE_FLAGS = /* @__PURE__ */ new Set([
package/dist/index.js CHANGED
@@ -24,7 +24,7 @@ import {
24
24
  upsertManifestEntry,
25
25
  validateIndex,
26
26
  writeManifest
27
- } from "./chunk-3ACIXWGF.js";
27
+ } from "./chunk-SIIHBJ4M.js";
28
28
  export {
29
29
  BUNDLED_CATALOG,
30
30
  DEFAULT_GITEE_REPO,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@worm-print-platform/marketplace",
3
- "version": "1.6.3",
3
+ "version": "1.6.5",
4
4
  "type": "module",
5
5
  "description": "worm-print-platform 插件市场安装器:从 npm / GitHub / Gitee 安装单个插件,默认取最新稳定版。",
6
6
  "license": "MIT",