zotero-plugin-scaffold 0.2.0-beta.16 → 0.2.0-beta.17

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.
@@ -4,7 +4,7 @@ import process from 'node:process';
4
4
  import { Octokit } from 'octokit';
5
5
  import { globSync, glob } from 'tinyglobby';
6
6
  import { isCI } from 'std-env';
7
- import { B as Base } from '../shared/zotero-plugin-scaffold.BhavR4LH.mjs';
7
+ import { B as Base } from '../shared/zotero-plugin-scaffold.0wXNVWwS.mjs';
8
8
  import 'c12';
9
9
  import 'es-toolkit';
10
10
  import 'fs-extra/esm';
package/dist/cli.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import process from 'node:process';
2
2
  import { Command } from '@commander-js/extra-typings';
3
- import { E as ExitSignals, l as logger, C as Config, a as Build, S as Serve, T as Test, R as Release } from './shared/zotero-plugin-scaffold.BhavR4LH.mjs';
3
+ import { E as ExitSignals, l as logger, C as Config, a as Build, S as Serve, T as Test, R as Release } from './shared/zotero-plugin-scaffold.0wXNVWwS.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';
@@ -30,7 +30,7 @@ import 'xvfb-ts';
30
30
 
31
31
  const name = "zotero-plugin-scaffold";
32
32
  const type = "module";
33
- const version = "0.2.0-beta.16";
33
+ const version = "0.2.0-beta.17";
34
34
  const packageManager = "pnpm@9.15.2";
35
35
  const description = "A scaffold for Zotero plugin development.";
36
36
  const author = "northword";
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { a as Build, C as Config, R as Release, S as Serve, T as Test, d as defineConfig } from './shared/zotero-plugin-scaffold.BhavR4LH.mjs';
1
+ export { a as Build, C as Config, R as Release, S as Serve, T as Test, d as defineConfig } from './shared/zotero-plugin-scaffold.0wXNVWwS.mjs';
2
2
  import 'c12';
3
3
  import 'es-toolkit';
4
4
  import 'fs-extra/esm';
@@ -1,5 +1,5 @@
1
1
  import { loadConfig as loadConfig$1 } from 'c12';
2
- import { isPlainObject, kebabCase, mapValues, isNotNil, toMerged, escapeRegExp, delay, debounce } from 'es-toolkit';
2
+ import { isPlainObject, kebabCase, mapValues, toMerged, escapeRegExp, delay, debounce } from 'es-toolkit';
3
3
  import { readJsonSync, outputFile, emptyDir, copy, readJSON, outputJSON, move, writeJson, pathExists, ensureDir, remove } from 'fs-extra/esm';
4
4
  import { createHooks } from 'hookable';
5
5
  import process from 'node:process';
@@ -146,7 +146,7 @@ function resolveConfig(config) {
146
146
  config.id ||= config.name;
147
147
  config.namespace ||= config.name;
148
148
  config.xpiName ||= kebabCase(config.name);
149
- config.build.prefs.prefix ||= `extensions.${config.namespace}`;
149
+ config.build.prefs.prefix ||= pkgUser.config.prefsPrefix || `extensions.${config.namespace}`;
150
150
  const isPreRelease = version.includes("-");
151
151
  const templateData = {
152
152
  owner,
@@ -308,22 +308,12 @@ class PrefsManager {
308
308
  for (const match of matches) {
309
309
  const key = match[2].trim();
310
310
  const value = match[3].trim();
311
- this.prefs[key] = value;
311
+ this.setPref(key, value);
312
312
  }
313
313
  }
314
314
  render() {
315
315
  return Object.entries(this.prefs).map(([key, value]) => {
316
- if (!isNotNil(value))
317
- return "";
318
- let cleanValue = "";
319
- if (typeof value === "boolean") {
320
- cleanValue = `${value}`;
321
- } else if (typeof value === "string") {
322
- cleanValue = value;
323
- } else if (typeof value === "number") {
324
- cleanValue = value.toString();
325
- }
326
- return `${this.namespace}("${key}", ${cleanValue});`;
316
+ return `${this.namespace}("${key}", ${value});`;
327
317
  }).filter((c) => !!c).join("\n");
328
318
  }
329
319
  async read(path) {
@@ -336,7 +326,26 @@ class PrefsManager {
336
326
  logger.debug("The <profile>/prefs.js has been modified.");
337
327
  }
338
328
  setPref(key, value) {
339
- this.prefs[key] = value;
329
+ let cleanValue;
330
+ if (value === null || value === void 0) {
331
+ if (key in this.prefs)
332
+ delete this.prefs[key];
333
+ else
334
+ return;
335
+ } else if (value === "true") {
336
+ cleanValue = true;
337
+ } else if (value === "false") {
338
+ cleanValue = false;
339
+ } else if (typeof value === "boolean") {
340
+ cleanValue = value;
341
+ } else if (typeof value === "string") {
342
+ cleanValue = value;
343
+ } else if (typeof value === "number") {
344
+ cleanValue = value;
345
+ } else {
346
+ cleanValue = value;
347
+ }
348
+ this.prefs[key] = cleanValue;
340
349
  }
341
350
  setPrefs(prefs) {
342
351
  Object.entries(prefs).forEach(([key, value]) => {
@@ -376,24 +385,20 @@ function renderPluginPrefsDts(prefs, prefix) {
376
385
  /* eslint-disable */
377
386
  // @ts-nocheck
378
387
 
388
+ // prettier-ignore
379
389
  type _PluginPrefsMap = {
380
390
  ${Object.entries(prefs).map(([key, value]) => {
381
391
  return `"${key}": ${typeof value};`;
382
392
  }).join("\n ")}
383
393
  };
384
394
 
395
+ // prettier-ignore
385
396
  type PluginPrefKey<K extends keyof _PluginPrefsMap> = \`${prefix}.\${K}\`;
386
397
 
398
+ // prettier-ignore
387
399
  type PluginPrefsMap = {
388
400
  [K in keyof _PluginPrefsMap as PluginPrefKey<K>]: _PluginPrefsMap[K]
389
401
  };
390
-
391
- declare namespace _ZoteroTypes {
392
- interface Prefs {
393
- get: <K extends keyof PluginPrefsMap>(key: K, global?: boolean) => PluginPrefsMap[K];
394
- set: <K extends keyof PluginPrefsMap>(key: K, value: PluginPrefsMap[K], global?: boolean) => any;
395
- }
396
- }
397
402
  `;
398
403
  return dtsContent;
399
404
  }
@@ -524,12 +529,11 @@ class Build extends Base {
524
529
  let ftlContent = await readFile(ftlPath, "utf-8");
525
530
  const matches = [...ftlContent.matchAll(FTL_MESSAGE_PATTERN)];
526
531
  for (const match of matches) {
527
- const message = match.groups?.message;
532
+ const [matched, message, _pattern] = match;
528
533
  if (message) {
529
- const namespacedMessage = `${namespace}-${message}`;
530
534
  localeMessages.add(message);
531
535
  allMessages.add(message);
532
- ftlContent = ftlContent.replace(message, namespacedMessage);
536
+ ftlContent = ftlContent.replace(new RegExp(`^${escapeRegExp(matched)}`, "gm"), `${namespace}-${matched}`);
533
537
  }
534
538
  }
535
539
  if (build.fluent.prefixFluentMessages)
@@ -598,14 +602,15 @@ class Build extends Base {
598
602
  const matchs = [...content.matchAll(HTML_PREFERENCE_PATTERN)];
599
603
  for (const match of matchs) {
600
604
  const [matched, key] = match;
601
- if (!prefsWithoutPrefix[key] && !prefsWithoutPrefix[key]) {
602
- this.logger.warn(`preference key '${key}' in ${path} not init in prefs.js`);
605
+ if (!(key in prefsWithoutPrefix) && !(key in prefsWithoutPrefix)) {
606
+ this.logger.warn(`preference key '${key}' in ${path.replace(`${dist}/`, "")} not init in prefs.js`);
603
607
  continue;
604
608
  }
605
- if (key.startsWith(prefix))
609
+ if (key.startsWith(prefix)) {
606
610
  continue;
607
- else
611
+ } else {
608
612
  content = content.replace(matched, `preference="${prefix}.${key}"`);
613
+ }
609
614
  }
610
615
  await outputFile(path, content, "utf-8");
611
616
  }));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "zotero-plugin-scaffold",
3
3
  "type": "module",
4
- "version": "0.2.0-beta.16",
4
+ "version": "0.2.0-beta.17",
5
5
  "description": "A scaffold for Zotero plugin development.",
6
6
  "author": "northword",
7
7
  "license": "AGPL-3.0-or-later",