wollardj / simple-plist

A simple API for interacting with binary and plain text plist data.
MIT License
53 stars 22 forks source link

Fix `bplist-parser` import error #65

Closed dnicolson closed 1 year ago

dnicolson commented 2 years ago

This pull request removes TypeScript types in favor of types upstream (https://github.com/joeferner/node-bplist-creator/pull/22, https://github.com/joeferner/node-bplist-parser/pull/34) and also fixes the import of bplist-parser. It's possible that it resolves https://github.com/wollardj/simple-plist/issues/58.

The following code works with version 1.3.0:

import * as plist from 'simple-plist';
console.log(plist)

The following code with adjusted import doesn't work with version 1.3.1 and results in an error:

import plist from 'simple-plist';
console.log(plist)
node_modules/simple-plist/dist/index.d.ts:2:8 - error TS1259: Module '".../node_modules/simple-plist/node_modules/bplist-parser/bplistParser"' can only be default-imported using the 'esModuleInterop' flag

2 import bplistParser from "bplist-parser";
         ~~~~~~~~~~~~

  node_modules/simple-plist/node_modules/bplist-parser/bplistParser.d.ts:6:1
    6 export = bPlistParser
      ~~~~~~~~~~~~~~~~~~~~~
    This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.
oliverschwendener commented 2 years ago

Are there any plans to merge this soon? Would be great as I'm experiencing the issue mentioned in #58

wollardj commented 2 years ago

I haven't looked it over thoroughly yet, but I'll do my best to get this moving along this week.

wollardj commented 2 years ago

@dnicolson / @oliverschwendener - found some additional issues and ended up covering much of what was in this PR. Could either of you try v1.4.0 (simple-plist@next) and let me know if it solves the problems you're facing?

oliverschwendener commented 2 years ago

For me it works like a charm, thanks alot!

dnicolson commented 2 years ago

I get these errors with 1.4.0:

node_modules/simple-plist/dist/index.d.ts:1:10 - error TS2305: Module '"bplist-creator"' has no exported member 'default'.

1 export { default as bplistCreator } from "bplist-creator";
           ~~~~~~~

node_modules/simple-plist/dist/index.d.ts:2:10 - error TS2305: Module '"bplist-parser"' has no exported member 'default'.

2 export { default as bplistParser } from "bplist-parser";
           ~~~~~~~

node_modules/simple-plist/dist/parse.d.ts:3:33 - error TS7016: Could not find a declaration file for module 'plist'. 'node_modules/plist/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/plist` if it exists or add a new declaration (.d.ts) file containing `declare module 'plist';`

3 import type { PlistValue } from "plist";
wollardj commented 2 years ago

@dnicolson I'm not able to reproduce that. Is that in a clean project? I'm wondering if there might be some stale caches laying around on your local or something strange like that.

wollardj commented 2 years ago

hmm...now that I've cleared my own caches I'm seeing similar errors, though not identical for some reason. I'll keep poking around a bit to see what I can find.

wollardj commented 2 years ago

@dnicolson - I'm still having trouble reproducing that exact error, but I've just published 1.4.0-0 which moves the @types/plist package to the dependencies instead of devDependencies. That seems like it should address at least 33% of what you're seeing.

Edit:

If I try your approach of using * instead of default, typescript is throwing an error

image

I'm not sure how you were able to get that to work - can you think of anything relevant?

dnicolson commented 2 years ago

I'm not sure our approaches are the same, it was a bplist-parser import and not a bplist-creator export.

I see similar errors with version 1.4.0-0:

node_modules/simple-plist/dist/index.d.ts:1:10 - error TS2305: Module '"bplist-creator"' has no exported member 'default'.

1 export { default as bplistCreator } from "bplist-creator";
           ~~~~~~~

node_modules/simple-plist/dist/index.d.ts:2:10 - error TS2305: Module '"bplist-parser"' has no exported member 'default'.

2 export { default as bplistParser } from "bplist-parser";
           ~~~~~~~

src/plist-file-format.ts:85:40 - error TS2345: Argument of type 'PlistValue' is not assignable to parameter of type 'PlistJsObj'.
  Type 'string' is not assignable to type 'PlistJsObj'.

85         plist.writeBinaryFileSync(uri, object);
                                          ~~~~~~