@dudko.dev/vectorize-cli 0.4.1 → 0.4.2

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/dist/cli.js +20 -1
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env node
2
+ import { realpathSync } from 'node:fs';
2
3
  import { readFile, writeFile } from 'node:fs/promises';
3
4
  import { basename, extname } from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
4
6
  import { parseArgs } from 'node:util';
5
7
  import { toDxf, toEps, toPdf, traceEncoded, withSize } from '@dudko.dev/vectorize-core';
6
8
  const FORMATS = ['svg', 'eps', 'pdf', 'dxf'];
@@ -179,7 +181,24 @@ export async function main(argv) {
179
181
  return 0;
180
182
  }
181
183
  // Run when executed directly (not when imported by tests).
182
- if (process.argv[1] && import.meta.url === new URL(`file://${process.argv[1]}`).href) {
184
+ //
185
+ // argv[1] is the path the user invoked. For an installed CLI that is the
186
+ // node_modules/.bin symlink npm creates, while import.meta.url is always the
187
+ // real file — so comparing the two without resolving the link makes this
188
+ // condition false exactly when someone runs `vectorize`, and the command exits
189
+ // 0 having done nothing. That is how 0.4.1 shipped. Resolve both to real paths.
190
+ //
191
+ // fileURLToPath rather than building a file:// URL by hand, which mangles any
192
+ // path containing a space or a character URLs escape.
193
+ const invokedPath = (() => {
194
+ try {
195
+ return process.argv[1] ? realpathSync(process.argv[1]) : '';
196
+ }
197
+ catch {
198
+ return '';
199
+ }
200
+ })();
201
+ if (invokedPath && invokedPath === realpathSync(fileURLToPath(import.meta.url))) {
183
202
  main(process.argv.slice(2)).then((code) => process.exit(code), (err) => {
184
203
  process.stderr.write(`error: ${err instanceof Error ? err.message : String(err)}\n`);
185
204
  process.exit(1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dudko.dev/vectorize-cli",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "Command-line raster → SVG converter",
5
5
  "type": "module",
6
6
  "license": "PolyForm-Noncommercial-1.0.0",