lasso-js / lasso

Advanced JavaScript module bundler, asset pipeline and optimizer
581 stars 75 forks source link

LassoCache for read-only filesystems (i.e. AWS Lambda) #197

Open schetnikovich opened 7 years ago

schetnikovich commented 7 years ago

Hi again!

LassoCache's constructor always creates key file, even when it already exists and has the same data. When used with read-only filesystems (i.e. AWS Lambda or Docker read-only images), Lasso fails with the following error:

Error: Render error. Exception: Error: EACCES: permission denied, open '/Users/dmitry/some-site/.cache/lasso/production/2659c12e/key'
    at Object.fs.openSync (fs.js:582:18)
    at Object.fs.writeFileSync (fs.js:1301:33)
    at LassoCache (/Users/dmitry/some-site/node_modules/lasso/lib/LassoCache.js:97:14)
    ...

By making trivial check at line 96 of LassoCache.js I was able to run Lasso + Marko with readonly filesystems (though I'm not 100% sure that I will not hit some hidden issues):

  if (!fs.existsSync(keyFile)) {
    fs.writeFileSync(keyFile, JSON.stringify(keyParts), { encoding: 'utf8' });
  }

We generate all static assets at compile time, that is why we do not need .cache folder to be writable. Do you think that it is safe to use Lasso + Marko with read-only filesystems?

Thank you!