vercel / ncc

Compile a Node.js project into a single file. Supports TypeScript, binary addons, dynamic requires.
https://npmjs.com/@vercel/ncc
MIT License
9.27k stars 291 forks source link

Add ability to disable the path rewriting #390

Open timsuchanek opened 5 years ago

timsuchanek commented 5 years ago

This code:

const runtimePath = path.join(__dirname, '../runtime')

Is being incorrectly rewritten by ncc to

const runtimePath = __dirname + '/runtime'

I actually want it to stay as it is.

My setup looks like this: ./scripts/download.js

const { ensureBinaries } = require('@prisma/fetch-engine')
const path = require('path')
const debug = require('debug')('download')
const runtimePath = path.join(__dirname, '../runtime')
debug(`Downloading binaries to ${runtimePath}`)
ensureBinaries(runtimePath)

ncc command:

ncc build scripts/download.js -o download

Also it takes all files from the ../runtime folder and copies them to ./download/runtime, which I don't need and then manually have to remove. Is there a way to disable it?

I was thinking of some hint that I could give ncc, maybe a comment in the code like this: // ncc-ignore-next-line

I saw that you're doing eval in the ncc source code, is that also because of that problem?

guybedford commented 5 years ago

@timsuchanek yes some way to opt-out sounds sensible for these kinds of valid scenarios. Perhaps we could provide a list of directories to never emit like ncc --noemit ../runtime --noemit ../other or similar.

What I would suggest first is to try this with the latest ncc beta if you can as that already includes some changes to this emission, which might possibly have resolved this.

guybedford commented 5 years ago

And yes, eval() can be used as a workaround to opt-out of the analysis too.