zotero-plugin-scaffold 0.2.2 → 0.2.4

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/cli.d.mts CHANGED
@@ -1,3 +1,3 @@
1
- declare function run(): Promise<void>;
1
+ declare function mainWithErrorHandler(): Promise<void>;
2
2
 
3
- export { run as default };
3
+ export { mainWithErrorHandler as default };
package/dist/cli.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- declare function run(): Promise<void>;
1
+ declare function mainWithErrorHandler(): Promise<void>;
2
2
 
3
- export { run as default };
3
+ export { mainWithErrorHandler as default };
package/dist/cli.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import process from 'node:process';
2
- import { Command } from '@commander-js/extra-typings';
3
- import { E as ExitSignals, l as logger, C as Config, B as Build, S as Serve, T as Test, R as Release } from './shared/zotero-plugin-scaffold.V3TH4au2.mjs';
2
+ import { Command } from 'commander';
3
+ import { E as ExitSignals, l as logger, C as Config, B as Build, S as Serve, T as Test, R as Release } from './shared/zotero-plugin-scaffold.D7j478bu.mjs';
4
4
  import { readFile, writeFile } from 'node:fs/promises';
5
5
  import { pathExists, ensureFile } from 'fs-extra';
6
6
  import tinyUpdateNotifier from 'tiny-update-notifier';
@@ -32,8 +32,8 @@ import 'xvfb-ts';
32
32
 
33
33
  const name = "zotero-plugin-scaffold";
34
34
  const type = "module";
35
- const version = "0.2.2";
36
- const packageManager = "pnpm@9.15.4";
35
+ const version = "0.2.4";
36
+ const packageManager = "pnpm@10.2.0";
37
37
  const description = "A scaffold for Zotero plugin development.";
38
38
  const author = "northword";
39
39
  const license = "AGPL-3.0-or-later";
@@ -100,8 +100,7 @@ const peerDependenciesMeta = {
100
100
  }
101
101
  };
102
102
  const dependencies = {
103
- "@commander-js/extra-typings": "^13.1.0",
104
- "@swc/core": "^1.10.12",
103
+ "@swc/core": "^1.10.14",
105
104
  "adm-zip": "^0.5.16",
106
105
  bumpp: "^10.0.1",
107
106
  c12: "^2.0.1",
@@ -119,6 +118,7 @@ const dependencies = {
119
118
  "xvfb-ts": "^1.1.0"
120
119
  };
121
120
  const devDependencies = {
121
+ "@commander-js/extra-typings": "^13.1.0",
122
122
  "@types/adm-zip": "^0.5.7",
123
123
  "@types/fs-extra": "^11.0.4"
124
124
  };
@@ -225,7 +225,7 @@ async function main() {
225
225
  });
226
226
  cli.parse();
227
227
  }
228
- async function run() {
228
+ async function mainWithErrorHandler() {
229
229
  main().then(() => {
230
230
  checkGitIgnore();
231
231
  }).catch(onError);
@@ -233,7 +233,10 @@ async function run() {
233
233
  }
234
234
  function onError(err) {
235
235
  logger.error(err);
236
+ if (err.output) {
237
+ logger.log(err.output.stderr);
238
+ }
236
239
  process.exit(1);
237
240
  }
238
241
 
239
- export { run as default };
242
+ export { mainWithErrorHandler as default };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { B as Build, C as Config, R as Release, S as Serve, T as Test, d as defineConfig } from './shared/zotero-plugin-scaffold.V3TH4au2.mjs';
1
+ export { B as Build, C as Config, R as Release, S as Serve, T as Test, d as defineConfig } from './shared/zotero-plugin-scaffold.D7j478bu.mjs';
2
2
  import 'c12';
3
3
  import 'es-toolkit';
4
4
  import 'fs-extra/esm';
@@ -298,49 +298,74 @@ class PrefsManager {
298
298
  /**
299
299
  * Parse Method 3 - Using AST
300
300
  */
301
- parse(content2) {
302
- const _map2 = {};
303
- const ast = parseSync(content2, { syntax: "ecmascript" });
301
+ parse(content) {
302
+ const _map = {};
303
+ const ast = parseSync(content, { syntax: "ecmascript" });
304
304
  for (const node of ast.body) {
305
305
  if (node.type !== "ExpressionStatement" || node.expression.type !== "CallExpression" || node.expression.callee.type !== "Identifier" || node.expression.callee.value !== this.namespace || node.expression.arguments.length !== 2) {
306
306
  throw new Error("Invalid prefs.js file.");
307
307
  }
308
- if (node.expression.arguments[0].expression.type !== "StringLiteral") {
308
+ const [arg1, arg2] = node.expression.arguments;
309
+ if (arg1.expression.type !== "StringLiteral") {
309
310
  throw new Error("Invalid prefs.js file - unsupported key type.");
310
311
  }
311
- if (node.expression.arguments[1].expression.type !== "StringLiteral" && node.expression.arguments[1].expression.type !== "NumericLiteral" && node.expression.arguments[1].expression.type !== "BooleanLiteral") {
312
- throw new Error("Invalid prefs.js file - unsupported value type.");
312
+ const key = arg1.expression.value.trim();
313
+ let value;
314
+ switch (arg2.expression.type) {
315
+ // https://babeljs.io/docs/babel-parser#output
316
+ case "StringLiteral":
317
+ case "NumericLiteral":
318
+ case "BooleanLiteral":
319
+ value = arg2.expression.value;
320
+ break;
321
+ // https://github.com/estree/estree/blob/master/es5.md#unaryexpression
322
+ // https://github.com/northword/zotero-plugin-scaffold/issues/98
323
+ case "UnaryExpression":
324
+ if (arg2.expression.argument.type !== "NumericLiteral")
325
+ throw new Error("Invalid prefs.js file - unsupported value type.");
326
+ if (arg2.expression.operator === "-")
327
+ value = -arg2.expression.argument.value;
328
+ else if (arg2.expression.operator === "+")
329
+ value = arg2.expression.argument.value;
330
+ else
331
+ throw new Error("Invalid prefs.js file - unsupported value type.");
332
+ break;
333
+ default:
334
+ throw new Error("Invalid prefs.js file - unsupported value type.");
313
335
  }
314
- const key = node.expression.arguments[0].expression.value.trim();
315
- const value = node.expression.arguments[1].expression.value;
316
- _map2[key] = value;
336
+ _map[key] = value;
317
337
  }
318
- return _map2;
338
+ return _map;
319
339
  }
320
340
  /**
321
341
  * Parse Method 1 - Using RegExp
322
342
  * @deprecated
323
343
  */
324
- parseByRegExp(content2) {
325
- const _map2 = {};
344
+ parseByRegExp(content) {
345
+ const _map = {};
326
346
  const prefPattern = /^(pref|user_pref)\s*\(\s*["']([^"']+)["']\s*,\s*(.+)\s*,?\s*\)\s*;?$/gm;
327
- const matches = content2.matchAll(prefPattern);
347
+ const matches = content.matchAll(prefPattern);
328
348
  for (const match of matches) {
329
349
  const key = match[2].trim();
330
350
  const value = match[3].trim();
331
- _map2[key] = this.cleanValue(value);
351
+ _map[key] = this.cleanValue(value);
332
352
  }
333
- return _map2;
353
+ return _map;
334
354
  }
335
355
  /**
336
356
  * Parse Method 2 - Using eval
337
357
  * @deprecated
338
358
  */
339
- parseByEval(content) {
340
- const _map = {};
341
- eval(content);
342
- return _map;
343
- }
359
+ // private parseByEval(content: string) {
360
+ // const _map: Prefs = {};
361
+ // // eslint-disable-next-line unused-imports/no-unused-vars
362
+ // const pref = (key: any, value: any) => {
363
+ // _map[key.trim()] = this.cleanValue(value.trim());
364
+ // };
365
+ // // eslint-disable-next-line no-eval
366
+ // eval(content);
367
+ // return _map;
368
+ // }
344
369
  cleanValue(value) {
345
370
  if (value === "true")
346
371
  return true;
@@ -360,13 +385,13 @@ class PrefsManager {
360
385
  }).join("\n");
361
386
  }
362
387
  async read(path) {
363
- const content2 = await readFile(path, "utf-8");
364
- const map = this.parse(content2);
388
+ const content = await readFile(path, "utf-8");
389
+ const map = this.parse(content);
365
390
  this.setPrefs(map);
366
391
  }
367
392
  async write(path) {
368
- const content2 = this.render();
369
- await outputFile(path, content2, "utf-8");
393
+ const content = this.render();
394
+ await outputFile(path, content, "utf-8");
370
395
  logger.debug("The prefs.js has been modified.");
371
396
  }
372
397
  setPref(key, value) {
@@ -393,18 +418,18 @@ class PrefsManager {
393
418
  }
394
419
  getPrefsWithPrefix(prefix) {
395
420
  const _prefs = {};
396
- for (const pref2 in this.prefs) {
397
- if (pref2.startsWith(prefix))
398
- _prefs[pref2] = this.prefs[pref2];
421
+ for (const pref in this.prefs) {
422
+ if (pref.startsWith(prefix))
423
+ _prefs[pref] = this.prefs[pref];
399
424
  else
400
- _prefs[`${prefix}.${pref2}`] = this.prefs[pref2];
425
+ _prefs[`${prefix}.${pref}`] = this.prefs[pref];
401
426
  }
402
427
  return _prefs;
403
428
  }
404
429
  getPrefsWithoutPrefix(prefix) {
405
430
  const _prefs = {};
406
- for (const pref2 in this.prefs) {
407
- _prefs[pref2.replace(`${prefix}.`, "")] = this.prefs[pref2];
431
+ for (const pref in this.prefs) {
432
+ _prefs[pref.replace(`${prefix}.`, "")] = this.prefs[pref];
408
433
  }
409
434
  return _prefs;
410
435
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "zotero-plugin-scaffold",
3
3
  "type": "module",
4
- "version": "0.2.2",
4
+ "version": "0.2.4",
5
5
  "description": "A scaffold for Zotero plugin development.",
6
6
  "author": "northword",
7
7
  "license": "AGPL-3.0-or-later",
@@ -63,8 +63,7 @@
63
63
  }
64
64
  },
65
65
  "dependencies": {
66
- "@commander-js/extra-typings": "^13.1.0",
67
- "@swc/core": "^1.10.12",
66
+ "@swc/core": "^1.10.14",
68
67
  "adm-zip": "^0.5.16",
69
68
  "bumpp": "^10.0.1",
70
69
  "c12": "^2.0.1",
@@ -82,6 +81,7 @@
82
81
  "xvfb-ts": "^1.1.0"
83
82
  },
84
83
  "devDependencies": {
84
+ "@commander-js/extra-typings": "^13.1.0",
85
85
  "@types/adm-zip": "^0.5.7",
86
86
  "@types/fs-extra": "^11.0.4"
87
87
  },