reading-time icon indicating copy to clipboard operation
reading-time copied to clipboard

reading-time v2

Open Josh-Cena opened this issue 4 years ago • 5 comments

Here are a few changes we can make in v2 (most of which @ngryman has also mentioned), roughly in order of decreasing importance:

  1. Refactor the API to expose two separate functions;
  2. Remove text from the function return;
  3. ~~Remove the badly named IOptions export;~~
  4. ~~Migrate to TypeScript completely;~~
  5. Prefer ESM to CJS (once we have TypeScript this is just a matter of setting the transpilation target);
  6. ~~Use a class-based implementation of readingTimeStream;~~
  7. ~~Change the testing library from mocha to Jest.~~

@ngryman If you have limited availability, I can be here to help.

Josh-Cena avatar Aug 27 '21 09:08 Josh-Cena

All of this sounds great to me, thanks!

I finally moved so I should be more available starting next week. I should be able to help here.

Ref #18 for stuff related to the API changes.

ngryman avatar Sep 03 '21 17:09 ngryman

Number 2, 3 and 5 will be resolved in #40.

Number 6 will be resolved by #41.

Josh-Cena avatar Sep 04 '21 04:09 Josh-Cena

Just jumping in to say that, with my current setup, v1.4.0 worked fine without any changes, but updating to v1.5.0 required me to add the following to my webpack config:

node: {
  global: true
},
resolve: {
  fallback: {
    stream: 'stream-browserify'
  }
},
plugins: [
  new webpack.ProvidePlugin({
    process: 'process/browser',
    Buffer: ['buffer', 'Buffer']
  })
]

and had to install stream-browserify.

The problematic line was const Transform = require('stream').Transform, but this line is also present in v1.4.0. This is a node core package, so it is expected for some kind of polyfill to be needed, but for some strange reason, v1.4.0 just works without any particular configuration change. 🤷‍♂️

miguelcobain avatar Oct 18 '21 02:10 miguelcobain

Just jumping in to say that, with my current setup, v1.4.0 worked fine without any changes, but updating to v1.5.0 required me to add the following to my webpack config:]


Not sure if this is the same issue but I had problems with 1.5 on Vite. Using 1.4 for now.

util.inherits is not a function
TypeError: util.inherits is not a function

sanderjson avatar Dec 15 '21 06:12 sanderjson

@sanderjson Yes, your problem is the same as the previous one. util is a Node library and is not polyfilled by Vite. You can either use 1.4, use 2.0.0-1 (which has a browser field in package.json), or import from reading-time/lib/reading-time instead.

Josh-Cena avatar Dec 15 '21 06:12 Josh-Cena