question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for assets not mentioned in `files` of `package.json`

See original GitHub issue

While zip-it-and-ship-it right now supports resolving require statements, if I have a path.join(__dirname, 'somefile') statement, it gets ignored by zip-it-and-ship-it, therefore if a package ships some assets, which are not mentioned in files of the package.json, they’re not included by the packing algorithm.

With Photon.js, we’re downloading binary files in the postinstall hook of the package. These files right now are ignored by zip-it-and-ship-it, making Photon.js broken in Netlify functions.

Note: The binaries are not mentioned in the files field of our package.json, as we don’t want to ship the binaries when publishing. Instead, they’re downloaded in the postinstall hook of the @prisma/photon package.

I see a couple of options here:

  1. Give package authors an explicit way to add files in addition to files. This option would, however, require a custom standard, library authors shouldn’t really have to bother about concrete deployment targets like Netlify.

  2. Just copy over the whole packages, not just what’s mentioned in the files part.

  3. Use smart logic like node-file-trace does (it’s used in Zeit Now). Photon.js is compatible with node-file-trace, by adding path.join(path to binary) statements in the code, which are recognized by node-file-trace.

The first step for this smart logic could basically be, including not only the require statements of a file, but also the path.join / path.resolve statements.

A quick fix could, of course, be having a union of what you have today and the files that node-file-trace suggests.

I know that you’re having a beta implementation, which may have tackled this already, but I don’t have access to the build beta yet. I just filled the beta form, in case that’s needed.

Thanks!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
ehmickycommented, Dec 10, 2019

Hi @timsuchanek, thanks for reaching out!

For reference purpose, I believe you are speaking about the following postinstall script which triggers the following file. Could you please print a tree of files that are typically generated by this Node file?

Please note also that the problem you are mentioning are path.join() is a broader issue: we do not currently support dynamic require(), for example when the path is not a string constant (which is your case) or when put inside a if block. I’ve opened #68 for this specific problem, feel free to provide with some feedback on this.

As you correctly pointed out, the beta should include a fix for your particular issue. I am going to make sure you’re included in our beta so you can make sure Photon.js and Netlify Functions work well together 👍

I will bump this issue once you have access 😃

0reactions
ehmickycommented, Dec 11, 2019

Amazing Tim! Feel free to send us more feedback about the Beta on netlify/zip-it-and-ship-it (for Netlify Functions) and on netlify/build (for the rest). 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Assets not being inferred or included manually #647 - GitHub
I have an express API application where the POST routes will upload files into the directory structure temporarily. The files are uploaded ...
Read more >
npm - How do you use the 'files' and 'directories' properties in ...
In this way, the directories are specified only once, and if they change, they only need changed in a single location (rather than...
Read more >
package.json - npm Docs
This document is all you need to know about what's required in your package.json file. It must be actual JSON, not just a...
Read more >
project.json File Reference for NuGet - Microsoft Learn
The project.json file maintains a list of packages used in a project, known as a package management format. It supersedes packages.config ...
Read more >
Specifying dependencies in Node.js - Cloud Functions
Using npm to install Node.js modules locally; Configuring deployment dependencies ... In this example, a dependency is listed in the package.json file:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found