ncc
ncc copied to clipboard
weired path.resolve with dirname
code before package:
const createFile = ({ path, fileName, content, withPrefix }) =>
fs.writeFileSync(
resolve(__dirname, path, `./${fileName}`),
`${withPrefix ? filePrefix : ""}${content}`,
_.noop,
);
code after package
const createFile = ({ path, fileName, content, withPrefix }) =>
fs.writeFileSync(
__nccwpck_require__.ab + "src/" + path + '\\' + fileName,
`${withPrefix ? filePrefix : ""}${content}`,
_.noop,
);
if path is an absolute path, the behavior will not as same as code before tranformation
I can't reproduce with @vercel/[email protected]
I had to add the missing variables fs
and _
but it doesn't transform resolve
like you suggested.
Input
const fs = require('fs')
const _ = { noop: () => {} }
const createFile = ({ path, fileName, content, withPrefix }) =>
fs.writeFileSync(
resolve(__dirname, path, `./${fileName}`),
`${withPrefix ? filePrefix : ""}${content}`,
_.noop,
);
Output
(() => {
const fs = __nccwpck_require__(147)
const _ = { noop: () => {} }
const createFile = ({ path, fileName, content, withPrefix }) =>
fs.writeFileSync(
resolve(__dirname, path, `./${fileName}`),
`${withPrefix ? filePrefix : ""}${content}`,
_.noop,
);
})();
@styfle It work well when I write the code directly, just like you mentioned, but if the code is from a dependency it become what i have write, I am using https://github.com/acacode/swagger-typescript-api, and not sure about the root cause.
Can you share the steps to reproduce?