Skip to content

Commit

Permalink
feat: support customEmit ncc option (#634)
Browse files Browse the repository at this point in the history
* feat: support customEmit ncc option

* update webpack-asset-relocator-loader

* update yarn.lock

* remove skips

* update fixtures

* update fixtures again

* more fixtures updates

* revert source maps
  • Loading branch information
guybedford authored Jan 11, 2021
1 parent da9b381 commit b4f9b42
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function ncc (
entry,
{
cache,
customEmit = undefined,
externals = [],
filename = 'index' + (entry.endsWith('.cjs') ? '.cjs' : '.js'),
minify = false,
Expand Down Expand Up @@ -243,6 +244,7 @@ function ncc (
}, {
loader: eval('__dirname + "/loaders/relocate-loader.js"'),
options: {
customEmit,
filterAssetBase,
existingAssetNames,
escapeNonAnalyzableRequires: true,
Expand Down
4 changes: 4 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 3 additions & 0 deletions test/unit/custom-emit/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { readFileSync } = require('fs');
console.log(readFileSync(__dirname + './test.json'));

63 changes: 63 additions & 0 deletions test/unit/custom-emit/output-coverage.js
Original file line number Diff line number Diff line change
@@ -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);
/******/ })()
;
63 changes: 63 additions & 0 deletions test/unit/custom-emit/output.js
Original file line number Diff line number Diff line change
@@ -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);
/******/ })()
;
3 changes: 3 additions & 0 deletions test/unit/custom-emit/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"custom": "emit"
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit b4f9b42

Please sign in to comment.