zotero-plugin-scaffold 0.3.1 → 0.3.3

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.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import process from 'node:process';
2
2
  import { Command } from 'commander';
3
- import { l as logger, E as ExitSignals, C as Config, B as Build, S as Serve, T as Test, R as Release } from './shared/zotero-plugin-scaffold.DWzaUAX4.mjs';
3
+ import { l as logger, E as ExitSignals, C as Config, B as Build, S as Serve, T as Test, R as Release } from './shared/zotero-plugin-scaffold.7eS2y7c2.mjs';
4
4
  import { readFile } from 'node:fs/promises';
5
5
  import { pathExists } from 'fs-extra';
6
6
  import tinyUpdateNotifier from 'tiny-update-notifier';
@@ -31,7 +31,7 @@ import 'node:http';
31
31
  import 'xvfb-ts';
32
32
 
33
33
  const name = "zotero-plugin-scaffold";
34
- const version = "0.3.1";
34
+ const version = "0.3.3";
35
35
  const pkg = {
36
36
  name: name,
37
37
  version: version};
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.DWzaUAX4.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.7eS2y7c2.mjs';
2
2
  import 'c12';
3
3
  import 'es-toolkit';
4
4
  import 'fs-extra/esm';
@@ -9,12 +9,12 @@ import { isDebug, isCI, isWindows, isMacOS, isLinux } from 'std-env';
9
9
  import { p as parseRepoUrl, d as dateFormat, t as template, b as toArray, a as replaceInFile } from './zotero-plugin-scaffold.v8dJZZ-v.mjs';
10
10
  import { createReadStream, existsSync } from 'node:fs';
11
11
  import { readFile, writeFile, stat } from 'node:fs/promises';
12
- import { basename, dirname, join, extname, resolve } from 'node:path';
12
+ import { basename, dirname, join, resolve, extname } from 'node:path';
13
13
  import AdmZip from 'adm-zip';
14
14
  import { build } from 'esbuild';
15
15
  import { glob, globSync } from 'tinyglobby';
16
16
  import { createHash } from 'node:crypto';
17
- import { parseSync } from '@swc/core';
17
+ import { parseSync, printSync } from '@swc/core';
18
18
  import { execSync, spawn } from 'node:child_process';
19
19
  import { versionBump, ProgressEvent } from 'bumpp';
20
20
  import { Octokit } from 'octokit';
@@ -446,9 +446,81 @@ class PrefsManager {
446
446
  else
447
447
  return value;
448
448
  }
449
+ /**
450
+ * Parse Method 2 - Using swc
451
+ */
449
452
  render() {
453
+ const span = { start: 0, end: 0, ctxt: 0 };
454
+ function getExpression(value) {
455
+ switch (typeof value) {
456
+ case "string":
457
+ return {
458
+ type: "StringLiteral",
459
+ span,
460
+ value
461
+ };
462
+ case "boolean":
463
+ return {
464
+ type: "BooleanLiteral",
465
+ span,
466
+ value
467
+ };
468
+ case "number":
469
+ if (value < 0) {
470
+ return {
471
+ type: "UnaryExpression",
472
+ span,
473
+ operator: "-",
474
+ argument: {
475
+ type: "NumericLiteral",
476
+ value: Math.abs(value)
477
+ }
478
+ };
479
+ }
480
+ return {
481
+ type: "NumericLiteral",
482
+ span,
483
+ value
484
+ };
485
+ default:
486
+ throw new Error(`Unsupported value type: ${typeof value}`);
487
+ }
488
+ }
489
+ const ast = {
490
+ type: "Module",
491
+ span,
492
+ // @ts-expect-error no raw property
493
+ body: Object.entries(this.prefs).map(([key, value]) => ({
494
+ type: "ExpressionStatement",
495
+ span,
496
+ expression: {
497
+ type: "CallExpression",
498
+ span,
499
+ ctxt: 0,
500
+ callee: {
501
+ type: "Identifier",
502
+ span,
503
+ ctxt: 0,
504
+ value: this.namespace,
505
+ optional: false
506
+ },
507
+ arguments: [
508
+ { expression: getExpression(key) },
509
+ { expression: getExpression(value) }
510
+ ]
511
+ }
512
+ }))
513
+ };
514
+ const { code } = printSync(ast);
515
+ return code;
516
+ }
517
+ /**
518
+ * Parse Method 1 - Using string
519
+ * @deprecated
520
+ */
521
+ renderByString() {
450
522
  return Object.entries(this.prefs).map(([key, value]) => {
451
- const _v = typeof value === "string" ? `"${value}"` : value;
523
+ const _v = typeof value === "string" ? `"${value.replaceAll("\\", "\\\\").replaceAll('"', '\\"')}"` : value;
452
524
  return `${this.namespace}("${key}", ${_v});`;
453
525
  }).join("\n");
454
526
  }
@@ -749,14 +821,15 @@ class Build extends Base {
749
821
  }
750
822
  esbuild() {
751
823
  const { dist, build: { esbuildOptions } } = this.ctx;
824
+ const distAbsolute = resolve(dist);
752
825
  if (esbuildOptions.length === 0)
753
826
  return;
754
827
  esbuildOptions.map((option, i) => {
755
- if (option.outfile && !option.outfile.startsWith(dist)) {
828
+ if (option.outfile && !resolve(option.outfile).startsWith(distAbsolute)) {
756
829
  this.logger.debug(`'outfile' of esbuildOptions[${i}] is not in dist folder, it will be overwritten.`);
757
830
  option.outfile = `${dist}/${option.outfile}`;
758
831
  }
759
- if (option.outdir && !option.outdir.startsWith(dist)) {
832
+ if (option.outdir && !resolve(option.outdir).startsWith(distAbsolute)) {
760
833
  this.logger.debug(`'outdir' of esbuildOptions[${i}] is not in dist folder, it will be overwritten.`);
761
834
  option.outdir = `${dist}/${option.outdir}`;
762
835
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "zotero-plugin-scaffold",
3
3
  "type": "module",
4
- "version": "0.3.1",
4
+ "version": "0.3.3",
5
5
  "description": "A scaffold for Zotero plugin development.",
6
6
  "author": "northword",
7
7
  "license": "AGPL-3.0-or-later",