Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: updates for latest multiformats #7

Merged
merged 1 commit into from
Apr 26, 2021
Merged

Conversation

rvagg
Copy link
Member

@rvagg rvagg commented Mar 30, 2021

this needs the newer types dist changes migrated from multiformats when finalised there

@rvagg
Copy link
Member Author

rvagg commented Mar 30, 2021

this is against multiformats/js-multiformats#70, so won't pass until that's published

@Gozala
Copy link
Contributor

Gozala commented Mar 30, 2021

Here is the module resolution trace from TS:

======== Resolving module 'multiformats/cid' from '/Users/gozala/Projects/js-car/lib/coding.ts'. ========
Explicitly specified module resolution kind: 'NodeJs'.
'baseUrl' option is set to '/Users/gozala/Projects/js-car', using this value to resolve non-relative module name 'multiformats/cid'.
'paths' option is specified, looking for a pattern to match module name 'multiformats/cid'.
'baseUrl' option is set to '/Users/gozala/Projects/js-car', using this value to resolve non-relative module name 'multiformats/cid'.
Resolving module name 'multiformats/cid' relative to base url '/Users/gozala/Projects/js-car' - '/Users/gozala/Projects/js-car/multiformats/cid'.
Loading module as file / folder, candidate module location '/Users/gozala/Projects/js-car/multiformats/cid', target file type 'TypeScript'.
Loading module 'multiformats/cid' from 'node_modules' folder, target file type 'TypeScript'.
Directory '/Users/gozala/Projects/js-car/lib/node_modules' does not exist, skipping all lookups in it.
Found 'package.json' at '/Users/gozala/Projects/js-car/node_modules/multiformats/package.json'.
'package.json' has a 'typesVersions' field with version-specific path mappings.
'package.json' has a 'typesVersions' entry '*' that matches compiler version '4.2.3', looking for a pattern to match module name 'cid'.
Module name 'cid', matched pattern '*'.
Trying substitution 'types/*', candidate module location: 'types/cid'.
'package.json' does not have a 'typings' field.
'package.json' has 'types' field './types/index.d.ts' that references '/Users/gozala/Projects/js-car/node_modules/multiformats/types/cid/types/index.d.ts'.
'package.json' has a 'typesVersions' entry '*' that matches compiler version '4.2.3', looking for a pattern to match module name 'types/index.d.ts'.
Module name 'types/index.d.ts', matched pattern '*'.
Trying substitution 'types/*', candidate module location: 'types/types/index.d.ts'.
Loading module as file / folder, candidate module location '/Users/gozala/Projects/js-car/node_modules/multiformats/types/cid/types/types/index.d.ts', target file type 'TypeScript'.
Directory '/Users/gozala/Projects/node_modules/@types' does not exist, skipping all lookups in it.
Directory '/Users/gozala/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/node_modules' does not exist, skipping all lookups in it.
Directory '/node_modules' does not exist, skipping all lookups in it.
'baseUrl' option is set to '/Users/gozala/Projects/js-car', using this value to resolve non-relative module name 'multiformats/cid'.
'paths' option is specified, looking for a pattern to match module name 'multiformats/cid'.
'baseUrl' option is set to '/Users/gozala/Projects/js-car', using this value to resolve non-relative module name 'multiformats/cid'.
Resolving module name 'multiformats/cid' relative to base url '/Users/gozala/Projects/js-car' - '/Users/gozala/Projects/js-car/multiformats/cid'.
Loading module as file / folder, candidate module location '/Users/gozala/Projects/js-car/multiformats/cid', target file type 'JavaScript'.
Loading module 'multiformats/cid' from 'node_modules' folder, target file type 'JavaScript'.
Directory '/Users/gozala/Projects/js-car/lib/node_modules' does not exist, skipping all lookups in it.
Found 'package.json' at '/Users/gozala/Projects/js-car/node_modules/multiformats/package.json'.
'package.json' has a 'typesVersions' field with version-specific path mappings.
'package.json' has a 'typesVersions' entry '*' that matches compiler version '4.2.3', looking for a pattern to match module name 'cid'.
Module name 'cid', matched pattern '*'.
Trying substitution 'types/*', candidate module location: 'types/cid'.
'package.json' has 'main' field './src/index.js' that references '/Users/gozala/Projects/js-car/node_modules/multiformats/types/cid/src/index.js'.
'package.json' has a 'typesVersions' entry '*' that matches compiler version '4.2.3', looking for a pattern to match module name 'src/index.js'.
Module name 'src/index.js', matched pattern '*'.
Trying substitution 'types/*', candidate module location: 'types/src/index.js'.
Loading module as file / folder, candidate module location '/Users/gozala/Projects/js-car/node_modules/multiformats/types/cid/types/src/index.js', target file type 'JavaScript'.
File name '/Users/gozala/Projects/js-car/node_modules/multiformats/types/cid/types/src/index.js' has a '.js' extension - stripping it.
Directory '/Users/gozala/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/node_modules' does not exist, skipping all lookups in it.
Directory '/node_modules' does not exist, skipping all lookups in it.
'baseUrl' option is set to '/Users/gozala/Projects/js-car', using this value to resolve non-relative module name 'multiformats/cid'.
'paths' option is specified, looking for a pattern to match module name 'multiformats/cid'.
'baseUrl' option is set to '/Users/gozala/Projects/js-car', using this value to resolve non-relative module name 'multiformats/cid'.
Resolving module name 'multiformats/cid' relative to base url '/Users/gozala/Projects/js-car' - '/Users/gozala/Projects/js-car/multiformats/cid'.
Loading module as file / folder, candidate module location '/Users/gozala/Projects/js-car/multiformats/cid', target file type 'Json'.
Loading module 'multiformats/cid' from 'node_modules' folder, target file type 'Json'.
Directory '/Users/gozala/Projects/js-car/lib/node_modules' does not exist, skipping all lookups in it.
Found 'package.json' at '/Users/gozala/Projects/js-car/node_modules/multiformats/package.json'.
'package.json' has a 'typesVersions' field with version-specific path mappings.
'package.json' has a 'typesVersions' entry '*' that matches compiler version '4.2.3', looking for a pattern to match module name 'cid'.
Module name 'cid', matched pattern '*'.
Trying substitution 'types/*', candidate module location: 'types/cid'.
'package.json' has 'main' field './src/index.js' that references '/Users/gozala/Projects/js-car/node_modules/multiformats/types/cid/src/index.js'.
'package.json' has a 'typesVersions' entry '*' that matches compiler version '4.2.3', looking for a pattern to match module name 'src/index.js'.
Module name 'src/index.js', matched pattern '*'.
Trying substitution 'types/*', candidate module location: 'types/src/index.js'.
Loading module as file / folder, candidate module location '/Users/gozala/Projects/js-car/node_modules/multiformats/types/cid/types/src/index.js', target file type 'Json'.
Directory '/Users/gozala/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/node_modules' does not exist, skipping all lookups in it.
Directory '/node_modules' does not exist, skipping all lookups in it.
======== Module name 'multiformats/cid' was not resolved. ========

Looks like it does typeVersions resolution twice and fails to resolve for that reason, which reminds me of the that or similar issue I've reported in the past microsoft/TypeScript#41284

Now that we know what is failing, we can try finding a work around

@Gozala
Copy link
Contributor

Gozala commented Mar 30, 2021

I have tried my best to get this resolved but it seems there is a combination of bugs that either breaks js-car or breaks ts-use example in js-multiformats. If we do use * in typeVersions and types field that runs into microsoft/TypeScript#41284

If we do not use types field all the modules resolve except for multiformats.

If we do use multiformats/* pattern in multiformats it works here, but it breaks usage from project that is written in TS as our test in the multiformats repo

At this point I'm not sure if there is a reasonable way to get any of this to work

@Gozala
Copy link
Contributor

Gozala commented Mar 30, 2021

Found a workaround and submitted multiformats/js-multiformats#72

@rvagg
Copy link
Member Author

rvagg commented Mar 31, 2021

Pulled in the enhancement from #8 to here, also copied an additional enhancement from multiformats/js-multiformats#70 that fixes the *.ts.map files by copying in source (and tests in this case) into the dist and running tsc in there. The maps come out nicely, the published asset includes all the things (my preference!) including examples, original source (with comments and types) and tests.

Will update when multiformats/js-multiformats#70 is done and copy the same enhancements to the codecs.

@rvagg rvagg marked this pull request as ready for review March 31, 2021 06:50
@rvagg
Copy link
Member Author

rvagg commented Mar 31, 2021

This is passing now with multiformats@6.0.0 as per multiformats/js-multiformats#70

I'm pretty happy with the pattern emerging here, it seems to be ticking the boxes we care about as far as I can tell.

@rvagg
Copy link
Member Author

rvagg commented Apr 26, 2021

updated to today's multiformats and codecs, removed a bunch of ts-ignores, expanded typing checking and improved the published version a little 🤞

@rvagg rvagg merged commit 989672f into master Apr 26, 2021
@rvagg rvagg deleted the rvagg/multiformats-new branch April 26, 2021 06:06
@rvagg rvagg mentioned this pull request Apr 26, 2021
77 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants