2

npm install and npm update install files in node_modules. The modified timestamps of these files are not what you expect: the time that these files were last installed or updated in the local filesystem. Instead, npm deliberately (I think) ensures that the installed files' mtime value remains the same as in the source archive.

That means, it is possible to find really old files in node_modules:

$ stat node_modules/plotly.js-dist/plotly.js | grep Modify
Modify: 1985-10-26 09:15:00.000000000 +0100

The main issue with this is that I am using these files in a build process, which only triggers if the source file's mtime is more recent than the target file's mtime.

How can I configure npm to update the mtime of a file when it is installed or updated?

Flimm
  • 136,138
  • 45
  • 251
  • 267
  • AFAIK npm doesn't provide such a feature. It has been raised previously in [issue #10052](https://github.com/npm/npm/issues/10052) _(Note: that's from their old/archived repo)_. You'll have to resort to a custom solution to achieve such a requirement. – RobC Jul 14 '20 at 17:40
  • 1
    FYI, since my earlier comments back in July [issue #1887](https://github.com/npm/cli/issues/1887) has been raised. – RobC Nov 11 '20 at 15:44

1 Answers1

0

Well, this one is interesting... Maybe I won't solve your problem technically, but help you get different perspective on it.

PROBLEM: npm install doesn't trigger file watcher.

Solution 1: rm- rf node_modules (delete all npm scripts) run npm install

Solution 2: after npm install update you app entry point manually (src/app.js) or something similar like it.

Solution 3: Configure your file watcher to watch changes on package.js (or package.lock.js). These files always change if you add or remove new modules.

Deividas Cha
  • 531
  • 1
  • 5
  • 9