diff --git a/package.json b/package.json index b175ccea..8d479a93 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "@sentry/node": "^4.3.0", "@slack/web-api": "^5.13.0", "@tensorflow/tfjs-node": "^0.3.0", - "@vercel/webpack-asset-relocator-loader": "1.0.0", + "@vercel/webpack-asset-relocator-loader": "1.1.1", "analytics-node": "^3.3.0", "apollo-server-express": "^2.2.2", "arg": "^4.1.0", diff --git a/src/index.js b/src/index.js index 10b2e961..2a9be4c2 100644 --- a/src/index.js +++ b/src/index.js @@ -35,6 +35,7 @@ function ncc ( entry, { cache, + customEmit = undefined, externals = [], filename = 'index' + (entry.endsWith('.cjs') ? '.cjs' : '.js'), minify = false, @@ -243,6 +244,7 @@ function ncc ( }, { loader: eval('__dirname + "/loaders/relocate-loader.js"'), options: { + customEmit, filterAssetBase, existingAssetNames, escapeNonAnalyzableRequires: true, diff --git a/test/index.test.js b/test/index.test.js index 55ad1304..84d91716 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -36,6 +36,10 @@ for (const unitTest of fs.readdirSync(`${__dirname}/unit`)) { const inputFile = fs.readdirSync(testDir).find(file => file.includes("input")); await ncc(`${testDir}/${inputFile}`, Object.assign({ transpileOnly: true, + customEmit (path) { + if (path.endsWith('test.json')) + return false; + }, externals: { 'piscina': 'piscina', 'externaltest': 'externalmapped' diff --git a/test/unit/custom-emit/input.js b/test/unit/custom-emit/input.js new file mode 100644 index 00000000..f218f403 --- /dev/null +++ b/test/unit/custom-emit/input.js @@ -0,0 +1,3 @@ +const { readFileSync } = require('fs'); +console.log(readFileSync(__dirname + './test.json')); + diff --git a/test/unit/custom-emit/output-coverage.js b/test/unit/custom-emit/output-coverage.js new file mode 100644 index 00000000..07084bd6 --- /dev/null +++ b/test/unit/custom-emit/output-coverage.js @@ -0,0 +1,63 @@ +module.exports = +/******/ (() => { // webpackBootstrap +/******/ var __webpack_modules__ = ({ + +/***/ 470: +/***/ ((__unused_webpack_module, __unused_webpack_exports, __nccwpck_require__) => { + +const { readFileSync } = __nccwpck_require__(747); +console.log(readFileSync(__dirname + './test.json')); + + + +/***/ }), + +/***/ 747: +/***/ ((module) => { + +"use strict"; +module.exports = require("fs"); + +/***/ }) + +/******/ }); +/************************************************************************/ +/******/ // The module cache +/******/ var __webpack_module_cache__ = {}; +/******/ +/******/ // The require function +/******/ function __nccwpck_require__(moduleId) { +/******/ // Check if module is in cache +/******/ if(__webpack_module_cache__[moduleId]) { +/******/ return __webpack_module_cache__[moduleId].exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = __webpack_module_cache__[moduleId] = { +/******/ // no module.id needed +/******/ // no module.loaded needed +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ var threw = true; +/******/ try { +/******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__); +/******/ threw = false; +/******/ } finally { +/******/ if(threw) delete __webpack_module_cache__[moduleId]; +/******/ } +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/************************************************************************/ +/******/ /* webpack/runtime/compat */ +/******/ +/******/ __nccwpck_require__.ab = __dirname + "/";/************************************************************************/ +/******/ // module exports must be returned from runtime so entry inlining is disabled +/******/ // startup +/******/ // Load entry module and return exports +/******/ return __nccwpck_require__(470); +/******/ })() +; \ No newline at end of file diff --git a/test/unit/custom-emit/output.js b/test/unit/custom-emit/output.js new file mode 100644 index 00000000..8910c78c --- /dev/null +++ b/test/unit/custom-emit/output.js @@ -0,0 +1,63 @@ +module.exports = +/******/ (() => { // webpackBootstrap +/******/ var __webpack_modules__ = ({ + +/***/ 954: +/***/ ((__unused_webpack_module, __unused_webpack_exports, __nccwpck_require__) => { + +const { readFileSync } = __nccwpck_require__(747); +console.log(readFileSync(__dirname + './test.json')); + + + +/***/ }), + +/***/ 747: +/***/ ((module) => { + +"use strict"; +module.exports = require("fs"); + +/***/ }) + +/******/ }); +/************************************************************************/ +/******/ // The module cache +/******/ var __webpack_module_cache__ = {}; +/******/ +/******/ // The require function +/******/ function __nccwpck_require__(moduleId) { +/******/ // Check if module is in cache +/******/ if(__webpack_module_cache__[moduleId]) { +/******/ return __webpack_module_cache__[moduleId].exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = __webpack_module_cache__[moduleId] = { +/******/ // no module.id needed +/******/ // no module.loaded needed +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ var threw = true; +/******/ try { +/******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__); +/******/ threw = false; +/******/ } finally { +/******/ if(threw) delete __webpack_module_cache__[moduleId]; +/******/ } +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/************************************************************************/ +/******/ /* webpack/runtime/compat */ +/******/ +/******/ __nccwpck_require__.ab = __dirname + "/";/************************************************************************/ +/******/ // module exports must be returned from runtime so entry inlining is disabled +/******/ // startup +/******/ // Load entry module and return exports +/******/ return __nccwpck_require__(954); +/******/ })() +; \ No newline at end of file diff --git a/test/unit/custom-emit/test.json b/test/unit/custom-emit/test.json new file mode 100644 index 00000000..970dccb7 --- /dev/null +++ b/test/unit/custom-emit/test.json @@ -0,0 +1,3 @@ +{ + "custom": "emit" +} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 8394d4b4..3e91515c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1902,10 +1902,10 @@ dependencies: "@types/yargs-parser" "*" -"@vercel/webpack-asset-relocator-loader@1.0.0": - version "1.0.0" - resolved "https://registry.yarnpkg.com/@vercel/webpack-asset-relocator-loader/-/webpack-asset-relocator-loader-1.0.0.tgz#cc3cae3b3cc8f3f631552e1ca97e566f597d5e5b" - integrity sha512-JZGVEFBOR0I7ccwewsWSSOB/ke6wYV4e09qQHtTBLTe/zgWrsjes7SX1Xt9M1UgiMTkhZ/0jyJpdxEqrpaYRMA== +"@vercel/webpack-asset-relocator-loader@1.1.1": + version "1.1.1" + resolved "https://registry.yarnpkg.com/@vercel/webpack-asset-relocator-loader/-/webpack-asset-relocator-loader-1.1.1.tgz#fcc8a67099b94584f58bb25c71ddbfa723ef5eb6" + integrity sha512-yIi9HE1GfPK00eiNQvn/c0tOUjWLn+jJQT+kUToNkUG5AWh3j7SFzSNF7zh+fkCUUp0ij6HkwCUSpkiJ+Th3tw== "@webassemblyjs/ast@1.9.0": version "1.9.0"