├── .github ├── CODEOWNERS ├── dependabot.yml └── workflows │ ├── ci.yml │ └── pr.yml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── LICENSE ├── dist ├── ncc │ ├── buildin │ │ └── readme.md │ ├── loaders │ │ └── readme.md │ └── readme.md └── readme.md ├── examples ├── hello-world │ ├── README.md │ ├── index.js │ └── package.json ├── multiple-bundles │ ├── README.md │ ├── cli.js │ ├── main.js │ ├── main.test.js │ └── package.json ├── programmatic │ ├── README.md │ ├── package.json │ ├── scripts │ │ └── build.js │ └── src │ │ ├── __dev__.js │ │ ├── routes │ │ ├── cat.js │ │ ├── dog.js │ │ └── fox.js │ │ └── utils.js └── typescript │ ├── README.md │ ├── index.ts │ ├── package.json │ └── tsconfig.json ├── jest.config.js ├── package-support.md ├── package.json ├── readme.md ├── release.config.js ├── scripts └── build.js ├── src ├── @@notfound.js ├── cli.js ├── index.js ├── loaders │ ├── empty-loader.js │ ├── notfound-loader.js │ ├── relocate-loader.js │ ├── shebang-loader.js │ ├── stringify-loader.js │ ├── ts-loader.js │ └── uncacheable.js ├── sourcemap-register.js.cache.js ├── typescript.js └── utils │ ├── get-package-base.js │ ├── has-type-module.js │ ├── ncc-cache-dir.js │ └── shebang.js ├── test ├── binary │ ├── binding.gyp │ └── hello.cc ├── cli.js ├── cli.test.js ├── fixtures │ ├── error.js │ ├── index.html │ ├── interop-test.mjs │ ├── interop.cjs │ ├── module.cjs │ ├── no-dep.js │ ├── sourcemap-resource-path │ │ ├── index.ts │ │ ├── sum.ts │ │ └── tsconfig.json │ ├── test.cjs │ ├── test.mjs │ ├── ts-error1 │ │ ├── fail.ts │ │ └── tsconfig.json │ ├── ts-error2 │ │ ├── ts-error.ts │ │ └── tsconfig.json │ ├── ts-interop │ │ ├── interop.ts │ │ └── tsconfig.json │ ├── type-module │ │ ├── main.js │ │ └── package.json │ └── with-type-errors │ │ ├── ts-error.ts │ │ └── tsconfig.json ├── integration.test.js ├── integration │ ├── analytics-node.js │ ├── apollo.js │ ├── auth0.js │ ├── aws-sdk.js │ ├── axios.js │ ├── azure-cosmos.js │ ├── azure-storage.js │ ├── binary-require.js │ ├── browserify-middleware.js │ ├── bugsnag-js.js │ ├── canvas.js │ ├── chromeless.js │ ├── core-js.js │ ├── cowsay.js │ ├── env-var.js │ ├── es-module.js │ ├── esm.js │ ├── express-consolidate.js │ ├── express.js │ ├── fetch-h2.js │ ├── ffmpeg.js │ ├── firebase-admin.js │ ├── firebase.js │ ├── firestore.js │ ├── fluent-ffmpeg.js │ ├── google-bigquery.js │ ├── got.js │ ├── hot-shots.js │ ├── include │ │ └── throwing.js │ ├── ioredis.js │ ├── isomorphic-unfetch.js │ ├── jimp.js │ ├── json-without-ext-sample.json │ ├── json-without-ext.js │ ├── jugglingdb.js │ ├── koa.js │ ├── leveldown.js │ ├── lighthouse.js │ ├── loopback.js │ ├── mailgun.js │ ├── mariadb.js │ ├── memcached.js │ ├── mongoose.js │ ├── mysql.js │ ├── node-path │ │ └── foo.js │ ├── node_modules │ │ ├── node_gyp │ │ │ ├── noop.js │ │ │ └── package.json │ │ └── typescript │ │ │ ├── index.js │ │ │ └── lib │ ├── notfound-eval.js │ ├── npm.js │ ├── oracledb.js │ ├── passport.js │ ├── path-platform.js │ ├── pdfkit.js │ ├── pg.js │ ├── pug.js │ ├── react.js │ ├── redis.js │ ├── request-ts.ts │ ├── request.js │ ├── rxjs.js │ ├── saslprep.js │ ├── sentry.js │ ├── sequelize.js │ ├── sharp.js │ ├── slack.js │ ├── socket.io.js │ ├── stack-trace.js │ ├── strict-module-exception-handling.js │ ├── stripe.js │ ├── test.ts │ ├── tiny-json-http.js │ ├── tsconfig.json │ ├── twilio.js │ ├── vm2.js │ ├── vue.js │ └── when.js ├── unit.test.js ├── unit │ ├── browser-mainfield │ │ ├── input.js │ │ ├── node_modules │ │ │ └── crypto-browser │ │ │ │ ├── browser.js │ │ │ │ ├── node.js │ │ │ │ └── package.json │ │ ├── opt.json │ │ ├── output-coverage.js │ │ └── output.js │ ├── bundle-subasset │ │ ├── input.js │ │ ├── output-coverage.js │ │ ├── output.js │ │ ├── pi-bridge.js │ │ ├── pi.ts │ │ └── tsconfig.json │ ├── bundle-subasset2 │ │ ├── input.ts │ │ ├── output-coverage.js │ │ ├── output.js │ │ ├── pi-bridge.js │ │ ├── pi.ts │ │ └── tsconfig.json │ ├── custom-emit │ │ ├── input.js │ │ ├── output-coverage.js │ │ ├── output.js │ │ └── test.json │ ├── double-nested-builds │ │ ├── input.js │ │ ├── output-coverage.js │ │ └── output.js │ ├── exports-nomodule │ │ ├── input.js │ │ ├── no.js │ │ ├── node.js │ │ ├── output-coverage.js │ │ ├── output.js │ │ └── package.json │ ├── exports-wildcard │ │ ├── input.js │ │ ├── no.js │ │ ├── node.js │ │ ├── output-coverage.js │ │ ├── output.js │ │ └── package.json │ ├── externals │ │ ├── input.js │ │ ├── output-coverage.js │ │ └── output.js │ ├── import-meta-esm │ │ ├── input.js │ │ ├── output-coverage.js │ │ ├── output.js │ │ └── package.json │ ├── imports │ │ ├── input.js │ │ ├── no.js │ │ ├── node.js │ │ ├── output-coverage.js │ │ ├── output.js │ │ └── package.json │ ├── minify-err │ │ ├── input.js │ │ ├── opt.json │ │ ├── output-coverage.js │ │ └── output.js │ ├── minify-sourcemap-register │ │ ├── input.js │ │ ├── opt.json │ │ ├── output-coverage.js │ │ ├── output-coverage.js.map │ │ ├── output.js │ │ └── output.js.map │ ├── minify-v8cache-sourcemap-register │ │ ├── input.js │ │ ├── opt.json │ │ ├── output-coverage.js │ │ ├── output-coverage.js.map │ │ ├── output.js │ │ └── output.js.map │ ├── minify │ │ ├── input.js │ │ ├── opt.json │ │ ├── output-coverage.js │ │ ├── output-coverage.js.map │ │ ├── output.js │ │ └── output.js.map │ ├── nested-builds │ │ ├── input.js │ │ ├── output-coverage.js │ │ └── output.js │ ├── runtime-notfound │ │ ├── input.js │ │ ├── output-coverage.js │ │ └── output.js │ ├── shebang │ │ ├── input.js │ │ ├── output-coverage.js │ │ └── output.js │ ├── ts-decl-dir │ │ ├── input.js │ │ ├── output-coverage.js │ │ ├── output.js │ │ ├── test.ts │ │ └── tsconfig.json │ ├── ts-decl │ │ ├── input.js │ │ ├── output-coverage.js │ │ ├── output.js │ │ ├── test.ts │ │ └── tsconfig.json │ ├── ts-exts │ │ ├── dep-dep.ts │ │ ├── dep.ts │ │ ├── input.ts │ │ ├── output-coverage.js │ │ ├── output.js │ │ └── tsconfig.json │ ├── ts-mixed-modules │ │ ├── input.ts │ │ ├── output-coverage.js │ │ ├── output.js │ │ ├── tsconfig.json │ │ └── types.ts │ ├── ts-target-es2018 │ │ ├── input.ts │ │ ├── output-coverage.js │ │ ├── output.js │ │ └── tsconfig.json │ ├── tsconfig-paths-allowjs │ │ ├── input.ts │ │ ├── module.js │ │ ├── output-coverage.js │ │ ├── output.js │ │ └── tsconfig.json │ ├── tsconfig-paths-array-extends │ │ ├── input.ts │ │ ├── module.js │ │ ├── output-coverage.js │ │ ├── output.js │ │ ├── tsconfig.a.json │ │ ├── tsconfig.b.json │ │ └── tsconfig.json │ ├── tsconfig-paths-conflicting-external │ │ ├── input.ts │ │ ├── module.ts │ │ ├── output-coverage.js │ │ ├── output.js │ │ └── tsconfig.json │ └── tsconfig-paths │ │ ├── input.ts │ │ ├── module.ts │ │ ├── output-coverage.js │ │ ├── output.js │ │ └── tsconfig.json └── watcher.test.js ├── update-fixtures.sh └── yarn.lock /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @styfle @Timer 2 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: github-actions 4 | directory: / 5 | schedule: 6 | interval: monthly 7 | - package-ecosystem: npm 8 | directory: / 9 | schedule: 10 | interval: monthly 11 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | tags: 8 | - '!*' 9 | pull_request: 10 | 11 | concurrency: 12 | group: ${{ github.workflow }}-${{ github.ref }} 13 | cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} 14 | 15 | jobs: 16 | test: 17 | name: Node ${{ matrix.node }} and ${{ matrix.os }} 18 | timeout-minutes: 30 19 | strategy: 20 | fail-fast: false 21 | matrix: 22 | os: [ubuntu-latest, macos-latest, windows-latest] 23 | node: [18, 20] 24 | runs-on: ${{ matrix.os }} 25 | steps: 26 | - uses: actions/checkout@v4 27 | # https://github.com/nodejs/node-gyp#installation 28 | - name: Use Python 3.11 29 | uses: actions/setup-python@v5 30 | with: 31 | python-version: '3.11' 32 | # https://github.com/hargasinski/node-canvas/blob/e7abe64833d13ec96449c827b1e14befbdf3105d/.github/workflows/ci.yaml#L70 33 | - name: "macOS dependencies" 34 | if: matrix.os == 'macos-latest' 35 | run: | 36 | brew update 37 | brew install pkg-config cairo pango libpng jpeg giflib librsvg 38 | # https://github.com/hargasinski/node-canvas/blob/e7abe64833d13ec96449c827b1e14befbdf3105d/.github/workflows/ci.yaml#L25 39 | - name: "GNU/Linux dependencies" 40 | if: matrix.os == 'ubuntu-latest' 41 | run: | 42 | sudo apt update 43 | sudo apt install -y libcairo2-dev libjpeg-dev libpango1.0-dev libgif-dev librsvg2-dev 44 | - name: Use Node.js ${{ matrix.node }} 45 | uses: actions/setup-node@v4 46 | with: 47 | cache: yarn 48 | node-version: ${{ matrix.node }} 49 | check-latest: true 50 | - name: Install Dependencies 51 | run: yarn global add node-gyp && yarn install --frozen-lockfile 52 | - name: Build Test Binary 53 | run: yarn build-test-binary 54 | - name: Build 55 | run: yarn build 56 | - name: Run Tests 57 | run: yarn test 58 | - name: Coverage 59 | if: matrix.os == 'ubuntu-latest' && matrix.node == 20 # only run once 60 | run: yarn test-coverage 61 | - name: Maybe Release 62 | if: matrix.os == 'ubuntu-latest' && matrix.node == 20 && github.event_name == 'push' && github.ref == 'refs/heads/main' 63 | env: 64 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 65 | NPM_TOKEN: ${{ secrets.NPM_TOKEN_ELEVATED }} 66 | run: npx semantic-release@19.0.5 67 | -------------------------------------------------------------------------------- /.github/workflows/pr.yml: -------------------------------------------------------------------------------- 1 | name: PR 2 | on: 3 | pull_request: 4 | types: [opened, edited, synchronize] 5 | pull_request_target: 6 | types: [opened, edited, synchronize] 7 | 8 | jobs: 9 | lint: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: amannn/action-semantic-pull-request@0723387faaf9b38adef4775cd42cfd5155ed6017 13 | env: 14 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | dist/**/*.js 3 | !scripts 4 | !src 5 | !src/*.js 6 | !test 7 | !test/integration 8 | !test/integration/*.json 9 | !test/integration/*.js 10 | !test/integration/*.ts 11 | !test/integration/include/ 12 | !test/integration/include/*.js 13 | !test/integration/node-path 14 | !test/integration/node-path/*.js 15 | !test/unit 16 | !test/unit/** 17 | !dist/ 18 | !dist/ncc/ 19 | !dist/buildin/ 20 | !package.json 21 | !yarn.lock 22 | !.circleci 23 | !.github 24 | !.github/ 25 | !.github/** 26 | !release.config.js 27 | !.*ignore 28 | !readme.md 29 | !examples/ 30 | !examples/** 31 | examples/**/node_modules 32 | examples/**/dist 33 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Code of Conduct 2 | 3 | ### Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level of experience, 9 | nationality, personal appearance, race, religion, or sexual identity and 10 | orientation. 11 | 12 | ### Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | - Using welcoming and inclusive language 18 | - Being respectful of differing viewpoints and experiences 19 | - Gracefully accepting constructive criticism 20 | - Focusing on what is best for the community 21 | - Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | - The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | - Trolling, insulting/derogatory comments, and personal or political attacks 28 | - Public or private harassment 29 | - Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | - Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ### Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ### Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ### Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at [abuse@zeit.co](mailto:abuse@zeit.co). All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ### Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at [http://contributor-covenant.org/version/1/4][version] 72 | 73 | [homepage]: http://contributor-covenant.org 74 | [version]: http://contributor-covenant.org/version/1/4/ 75 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2018 ZEIT, Inc. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /dist/ncc/buildin/readme.md: -------------------------------------------------------------------------------- 1 | # About this directory 2 | 3 | This directory will contain the webpack built-ins, like 4 | `module.js`, so that they can be accessed by webpack when 5 | it's being executed inside the bundled ncc file. 6 | 7 | These files are published to npm. 8 | -------------------------------------------------------------------------------- /dist/ncc/loaders/readme.md: -------------------------------------------------------------------------------- 1 | # About this directory 2 | 3 | This directory will contain: 4 | 5 | - `relocate-loader.js` the ncc loader for handling CommonJS asset and reference relocations 6 | - `shebang-loader.js` the ncc loader to ensure proper hash bang support in Node.js CLI files 7 | - `ts-loader.js` the ncc loader for handling TypeScript 8 | 9 | These are generated by the `build` step defined in `../../../package.json`. 10 | 11 | These files are published to npm. 12 | -------------------------------------------------------------------------------- /dist/ncc/readme.md: -------------------------------------------------------------------------------- 1 | # About this directory 2 | 3 | This directory will contain: 4 | 5 | - `index.js` the main ncc bundle 6 | - `cli.js` the CLI bundle, excluding the main ncc bundle 7 | - `typescript.js` the TypeScript detection file 8 | 9 | These are generated by the `build` step defined in `../../package.json`. 10 | 11 | These files are published to npm. 12 | -------------------------------------------------------------------------------- /dist/readme.md: -------------------------------------------------------------------------------- 1 | # About this directory 2 | 3 | This directory will contain: 4 | - `buildin`: the webpack `buildin/` folder, required at runtime 5 | - `ncc`: the output from the ncc build 6 | 7 | They are generated by the `build` script defined in `../package.json`. 8 | 9 | This directory is the only one published to npm. 10 | -------------------------------------------------------------------------------- /examples/hello-world/README.md: -------------------------------------------------------------------------------- 1 | # Hello World 2 | 3 | ## How to use 4 | 5 | Within this directory, run `yarn` to install dependencies. 6 | 7 | To execute the Node.js program with `ncc`, run `yarn dev`. 8 | 9 | To build the program with `ncc`, run `yarn build`. 10 | -------------------------------------------------------------------------------- /examples/hello-world/index.js: -------------------------------------------------------------------------------- 1 | const chalk = require("chalk"); 2 | 3 | console.log(chalk.green("Hello World!")); 4 | -------------------------------------------------------------------------------- /examples/hello-world/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hello-world", 3 | "private": true, 4 | "version": "0.0.0", 5 | "license": "MIT", 6 | "scripts": { 7 | "dev": "ncc run index.js", 8 | "build": "ncc build index.js -o dist" 9 | }, 10 | "dependencies": { 11 | "chalk": "^2.4.1" 12 | }, 13 | "devDependencies": { 14 | "@vercel/ncc": "latest" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/multiple-bundles/README.md: -------------------------------------------------------------------------------- 1 | # Multiple Bundles 2 | 3 | This example shows how you could build a simple module along with a CLI. 4 | 5 | ## How to use 6 | 7 | Within this directory, run `yarn` to install dependencies. 8 | 9 | To build the main module, run `yarn build:main`. You'll notice the resulting `dist/main/index.js` only includes `main.js` and its `chalk` dependency. 10 | 11 | To build the CLI, run `yarn build:cli`. You'll notice the resulting `dist/cli/index.js` includes its `args` dependency in addition to everything required for `main.js`. 12 | 13 | _To build both concurrently, run `yarn build`._ 14 | 15 | To test the main module, run `yarn test`. You'll notice it uses a `strip-ansi` dependency that is not included in any of the builds. 16 | 17 | To use the built CLI, run `./dist/cli/index.js color` or `./dist/cli/index.js number`. If this were published to npm as "lucky", you would be able to run `lucky color` or `lucky number` because of the `bin` declaration in `package.json`. 18 | -------------------------------------------------------------------------------- /examples/multiple-bundles/cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const args = require("args"); 4 | 5 | const { color, number } = require("./main"); 6 | 7 | args 8 | .command("color", "Receive a lucky color", () => { 9 | console.log(color()); 10 | }) 11 | .command("number", "Receive a lucky number", () => { 12 | console.log(number()); 13 | }); 14 | 15 | args.parse(process.argv, { 16 | name: "lucky" 17 | }); 18 | -------------------------------------------------------------------------------- /examples/multiple-bundles/main.js: -------------------------------------------------------------------------------- 1 | const chalk = require("chalk"); 2 | 3 | exports.color = function color() { 4 | const color = Math.random() > 0.5 ? "red" : "blue"; 5 | 6 | return `Your lucky color is ${chalk[color](color)}`; 7 | }; 8 | 9 | exports.number = function number(min = 0, max = 100) { 10 | min = Math.ceil(min); 11 | max = Math.floor(max); 12 | //The maximum is exclusive and the minimum is inclusive 13 | const num = Math.floor(Math.random() * (max - min)) + min; 14 | 15 | return `Your lucky number is ${chalk.bold(num)}`; 16 | }; 17 | -------------------------------------------------------------------------------- /examples/multiple-bundles/main.test.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const chalk = require("chalk"); 3 | const stripAnsi = require("strip-ansi"); 4 | 5 | const { color, number } = require("./main"); 6 | 7 | function getValue(fn) { 8 | return stripAnsi( 9 | fn() 10 | .split(/\s/) 11 | .pop() 12 | ); 13 | } 14 | 15 | // color is a function 16 | assert(typeof color === "function"); 17 | 18 | // color is red or blue for this example 19 | const c = getValue(color); 20 | assert(c === "red" || c === "blue"); 21 | 22 | // number is a function 23 | assert(typeof number === "function"); 24 | 25 | // number returns an integer between 0 and 100 by default 26 | const n = getValue(number); 27 | assert(n > 0 && n <= 100); 28 | 29 | console.log(chalk.green("Tests pass!")); 30 | -------------------------------------------------------------------------------- /examples/multiple-bundles/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "multiple-bundles", 3 | "private": true, 4 | "version": "0.0.0", 5 | "license": "MIT", 6 | "main": "./dist/main/index.js", 7 | "bin": { 8 | "lucky": "./dist/cli/index.js" 9 | }, 10 | "scripts": { 11 | "build:cli": "ncc build cli.js -o dist/cli", 12 | "build:main": "ncc build main.js -o dist/main", 13 | "build": "concurrently 'npm:build:cli' 'npm:build:main'", 14 | "test": "node main.test.js" 15 | }, 16 | "dependencies": { 17 | "args": "^5.0.0", 18 | "chalk": "^2.4.1" 19 | }, 20 | "devDependencies": { 21 | "@vercel/ncc": "latest", 22 | "concurrently": "^4.1.0", 23 | "strip-ansi": "^5.0.0" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /examples/programmatic/README.md: -------------------------------------------------------------------------------- 1 | # Programmatic 2 | 3 | This example shows how you can programmatically build multiple bundles. The build script (`scripts/build.js`) finds `.js` files in `src/routes/`, builds each one with `ncc`, and then writes the resulting file and its sourcemap to a new directory in `dist/`. 4 | 5 | ## How to use 6 | 7 | Within this directory, run `yarn` to install dependencies. 8 | 9 | To run a development server with `ncc`, run `yarn dev`. You can then test the routes: 10 | 11 | - [http://localhost:3000/cat]() 12 | - [http://localhost:3000/dog]() 13 | - [http://localhost:3000/fox]() 14 | 15 | To build all of the bundles, run `yarn build`. 16 | 17 | ``` 18 | ❯ yarn build 19 | yarn run v1.12.3 20 | $ node ./scripts/build.js 21 | ✓ dist/dog/index.js (289.17KB) 22 | ✓ dist/dog/index.map.js (234.37KB) 23 | ✓ dist/fox/index.js (289.18KB) 24 | ✓ dist/fox/index.map.js (234.43KB) 25 | ✓ dist/cat/index.js (289.17KB) 26 | ✓ dist/cat/index.map.js (234.43KB) 27 | ✨ Done in 2.79s. 28 | ``` 29 | 30 | Each subdirectory of `dist/` could be deployed to [a serverless environment](https://zeit.co/examples/nodejs/) to run independent of each other! 31 | 32 | ## Thanks 33 | 34 | Special thanks to [random.cat](http://random.cat/), [AdenFlorian/random.dog](https://github.com/AdenFlorian/random.dog), and [xinitrc-dev/randomfox.ca](https://github.com/xinitrc-dev/randomfox.ca) for their open APIs to make this example more fun and realistic! 35 | -------------------------------------------------------------------------------- /examples/programmatic/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "programmatic", 3 | "private": true, 4 | "version": "0.0.0", 5 | "license": "MIT", 6 | "scripts": { 7 | "dev": "ncc run ./src/__dev__.js --watch", 8 | "build": "node ./scripts/build.js" 9 | }, 10 | "dependencies": { 11 | "node-fetch": "^2.3.0" 12 | }, 13 | "devDependencies": { 14 | "@vercel/ncc": "latest", 15 | "bytes": "^3.0.0", 16 | "glob": "^7.1.3", 17 | "mkdirp": "^0.5.1" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /examples/programmatic/scripts/build.js: -------------------------------------------------------------------------------- 1 | const { statSync, writeFileSync } = require("fs"); 2 | const { basename, relative, resolve } = require("path"); 3 | const { promisify } = require("util"); 4 | 5 | const bytes = require("bytes"); 6 | const glob = promisify(require("glob")); 7 | const mkdirp = promisify(require("mkdirp")); 8 | const ncc = require("@vercel/ncc"); 9 | 10 | // output directories 11 | const DIST_DIR = resolve(__dirname, "../dist"); 12 | const CACHE_DIR = resolve(DIST_DIR, ".cache"); 13 | 14 | // options for ncc with mix of defaults and customization 15 | const options = { 16 | // provide a custom cache path 17 | cache: CACHE_DIR, 18 | // externals to leave as requires of the build 19 | externals: [], 20 | minify: true, 21 | sourceMap: true, 22 | watch: false // default 23 | }; 24 | 25 | // write file to disk and print final size 26 | function write(file, data) { 27 | writeFileSync(file, data); 28 | 29 | console.log( 30 | `✓ ${relative(__dirname + "/../", file)} (${bytes(statSync(file).size)})` 31 | ); 32 | } 33 | 34 | // build file with its dependencies using ncc 35 | async function build(file) { 36 | const { code, map, assets } = await ncc(file, options); 37 | 38 | if (Object.keys(assets).length) 39 | console.error("New unexpected assets are being emitted for", file); 40 | 41 | const name = basename(file, ".js"); 42 | await mkdirp(resolve(DIST_DIR, name)); 43 | write(resolve(DIST_DIR, name, "index.js"), code); 44 | write(resolve(DIST_DIR, name, "index.map.js"), map); 45 | } 46 | 47 | async function main() { 48 | // create our output and custom cache directories 49 | await mkdirp(CACHE_DIR); 50 | 51 | // find all routes we want to bundle 52 | const files = await glob(resolve(__dirname, "../src/routes/*.js")); 53 | 54 | // build all found files 55 | return Promise.all(files.map(build)); 56 | } 57 | 58 | main(); 59 | -------------------------------------------------------------------------------- /examples/programmatic/src/__dev__.js: -------------------------------------------------------------------------------- 1 | // Development server only intended to be used by `yarn dev` 2 | 3 | import { Server, STATUS_CODES } from "http"; 4 | import { parse } from "url"; 5 | 6 | import cat from "./routes/cat"; 7 | import dog from "./routes/dog"; 8 | import fox from "./routes/fox"; 9 | 10 | const server = new Server(async (req, res) => { 11 | const { pathname } = parse(req.url); 12 | 13 | if (pathname === "/cat") return cat(req, res); 14 | if (pathname === "/dog") return dog(req, res); 15 | if (pathname === "/fox") return fox(req, res); 16 | 17 | res.writeHead(404); 18 | res.end(STATUS_CODES[404]); 19 | }); 20 | 21 | const port = process.env.PORT || 3000; 22 | 23 | server.listen(port, () => { 24 | console.log(`Listening for HTTP requests on port ${port}...`); 25 | }); 26 | -------------------------------------------------------------------------------- /examples/programmatic/src/routes/cat.js: -------------------------------------------------------------------------------- 1 | import { animalAPI } from "../utils"; 2 | 3 | export default (req, res) => 4 | animalAPI(res, "Cat", "https://aws.random.cat/meow", "file"); 5 | -------------------------------------------------------------------------------- /examples/programmatic/src/routes/dog.js: -------------------------------------------------------------------------------- 1 | import { animalAPI } from "../utils"; 2 | 3 | export default (req, res) => 4 | animalAPI(res, "Dog", "https://random.dog/woof.json", "url"); 5 | -------------------------------------------------------------------------------- /examples/programmatic/src/routes/fox.js: -------------------------------------------------------------------------------- 1 | import { animalAPI } from "../utils"; 2 | 3 | export default (req, res) => 4 | animalAPI(res, "Fox", "https://randomfox.ca/floof/", "image"); 5 | -------------------------------------------------------------------------------- /examples/programmatic/src/utils.js: -------------------------------------------------------------------------------- 1 | import fetch from "node-fetch"; 2 | 3 | export async function animalAPI(res, title, api, key) { 4 | const resp = await fetch(api); 5 | const json = await resp.json(); 6 | 7 | const body = ` 8 | 9 | 10 | 11 | 12 | ${title} 13 | 14 | 15 | ${title} 16 | 17 | 18 | `; 19 | 20 | res.writeHead(200, { 21 | "Content-Length": Buffer.byteLength(body), 22 | "Content-Type": "text/html; charset=utf-8" 23 | }); 24 | 25 | res.end(body); 26 | } 27 | -------------------------------------------------------------------------------- /examples/typescript/README.md: -------------------------------------------------------------------------------- 1 | # TypeScript 2 | 3 | ## How to use 4 | 5 | Within this directory, run `yarn` to install dependencies. 6 | 7 | To execute the Node.js program with `ncc`, run `yarn dev`. 8 | 9 | To build the program with `ncc`, run `yarn build`. 10 | -------------------------------------------------------------------------------- /examples/typescript/index.ts: -------------------------------------------------------------------------------- 1 | import chalk from "chalk"; 2 | 3 | function logSuccess(msg: string) { 4 | console.log(chalk.green(msg)); 5 | } 6 | 7 | logSuccess("Hello World!"); 8 | -------------------------------------------------------------------------------- /examples/typescript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "typescript", 3 | "private": true, 4 | "version": "0.0.0", 5 | "license": "MIT", 6 | "scripts": { 7 | "dev": "ncc run index.ts", 8 | "build": "ncc build index.ts -o dist" 9 | }, 10 | "dependencies": { 11 | "chalk": "^2.4.1" 12 | }, 13 | "devDependencies": { 14 | "@vercel/ncc": "latest", 15 | "typescript": "^4.4.2" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /examples/typescript/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2015", 4 | "moduleResolution": "node" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | collectCoverageFrom: ["src/**/*.js"], 3 | coverageReporters: ["html", "lcov"], 4 | testEnvironment: "node", 5 | testMatch: ["/test/**/*.test.js"] 6 | }; 7 | -------------------------------------------------------------------------------- /package-support.md: -------------------------------------------------------------------------------- 1 | ## ncc Package Configurations 2 | 3 | Packages that need specific configurations for ncc support are included below. 4 | 5 | If you are having trouble running a package with ncc, try searching for it in the [issue queue](https://github.com/zeit/ncc/issues) or posting an issue. 6 | 7 | ### `sequelize` 8 | 9 | For example, with the `mariadb` dialect: 10 | 11 | ```js 12 | const Sequelize = require('sequelize'); 13 | const db = new Sequelize({ 14 | dialect: 'mariadb', 15 | dialectModule: require('mariadb') 16 | }); 17 | ``` 18 | 19 | The important part here is defining `dialectModule`. 20 | 21 | ### `@google-cloud/vision` 22 | 23 | Add `google-proto-files` in your `package.json` dependencies. 24 | 25 | ```json 26 | { 27 | "name": "example", 28 | "main": "index.js", 29 | "dependencies": { 30 | "@google-cloud/vision": "1.1.1", 31 | "google-proto-files": "1.0.1" 32 | } 33 | } 34 | ``` 35 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@vercel/ncc", 3 | "description": "Simple CLI for compiling a Node.js module into a single file, together with all its dependencies, gcc-style.", 4 | "version": "0.0.0-development", 5 | "repository": "vercel/ncc", 6 | "license": "MIT", 7 | "main": "./dist/ncc/index.js", 8 | "bin": { 9 | "ncc": "./dist/ncc/cli.js" 10 | }, 11 | "files": [ 12 | "dist" 13 | ], 14 | "scripts": { 15 | "build": "node scripts/build.js", 16 | "build-test-binary": "cd test/binary && node-gyp rebuild && cp build/Release/hello.node ../integration/hello.node", 17 | "test": "node --expose-gc --max_old_space_size=4096 node_modules/jest/bin/jest.js", 18 | "test-coverage": "node --expose-gc --max_old_space_size=4096 node_modules/jest/bin/jest.js --runInBand --coverage --globals \"{\\\"coverage\\\":true}\"", 19 | "prepublishOnly": "node scripts/build.js --no-cache" 20 | }, 21 | "devDependencies": { 22 | "@aws-sdk/client-s3": "^3.787.0", 23 | "@azure/cosmos": "^3.17.3", 24 | "@bugsnag/js": "^7.21.0", 25 | "@ffmpeg-installer/ffmpeg": "^1.0.17", 26 | "@google-cloud/bigquery": "^5.7.0", 27 | "@google-cloud/firestore": "^6.7.0", 28 | "@sentry/node": "^7.66.0", 29 | "@slack/web-api": "^6.9.0", 30 | "@vercel/webpack-asset-relocator-loader": "1.7.3", 31 | "analytics-node": "^6.2.0", 32 | "apollo-server-express": "^2.2.2", 33 | "arg": "^5.0.2", 34 | "auth0": "^2.14.0", 35 | "axios": "^1.7.7", 36 | "azure-storage": "^2.10.2", 37 | "browserify-middleware": "^8.1.1", 38 | "bytes": "^3.1.2", 39 | "canvas": "3.0.0-rc2", 40 | "chromeless": "^1.5.2", 41 | "consolidate": "^0.16.0", 42 | "copy": "^0.3.2", 43 | "core-js": "^2.5.7", 44 | "cowsay": "^1.3.1", 45 | "esm": "^3.2.22", 46 | "express": "^4.18.2", 47 | "fetch-h2": "^3.0.2", 48 | "firebase": "^7.24.0", 49 | "firebase-admin": "^11.10.1", 50 | "fluent-ffmpeg": "^2.1.2", 51 | "fontkit": "^1.7.7", 52 | "get-folder-size": "^2.0.0", 53 | "glob": "^8.0.3", 54 | "got": "^12.5.2", 55 | "graceful-fs": "^4.2.11", 56 | "graphql": "^15.5.1", 57 | "hot-shots": "^8.5.0", 58 | "ioredis": "^5.3.2", 59 | "isomorphic-unfetch": "^4.0.2", 60 | "jest": "^27.5.1", 61 | "jimp": "^0.16.1", 62 | "jugglingdb": "2.0.1", 63 | "koa": "^2.14.2", 64 | "leveldown": "^6.0.0", 65 | "license-webpack-plugin": "^4.0.2", 66 | "lighthouse": "^8.1.0", 67 | "loopback": "^3.24.0", 68 | "mailgun": "^0.5.0", 69 | "mariadb": "^2.0.1-beta", 70 | "memcached": "^2.2.2", 71 | "memory-fs": "^0.5.0", 72 | "mkdirp": "^1.0.4", 73 | "mongoose": "^8.8.3", 74 | "mysql": "^2.16.0", 75 | "node-gyp": "^9.4.0", 76 | "npm": "^6.13.4", 77 | "oracledb": "^6.1.0", 78 | "passport": "^0.6.0", 79 | "passport-google-oauth": "^2.0.0", 80 | "path-platform": "^0.11.15", 81 | "pdfkit": "^0.13.0", 82 | "pg": "^8.11.3", 83 | "pug": "^3.0.1", 84 | "react": "^17.0.2", 85 | "react-dom": "^17.0.2", 86 | "redis": "^3.1.1", 87 | "request": "^2.88.0", 88 | "rxjs": "^7.8.1", 89 | "saslprep": "^1.0.2", 90 | "sequelize": "^6.32.1", 91 | "sharp": "^0.32.5", 92 | "shebang-loader": "^0.0.1", 93 | "socket.io": "^4.7.2", 94 | "source-map-support": "^0.5.9", 95 | "stripe": "^8.167.0", 96 | "swig": "^1.4.2", 97 | "terser": "^5.33.0", 98 | "the-answer": "^1.0.0", 99 | "tiny-json-http": "^7.5.1", 100 | "ts-loader": "^9.4.4", 101 | "tsconfig-paths": "^4.2.0", 102 | "tsconfig-paths-webpack-plugin": "^4.1.0", 103 | "twilio": "^3.23.2", 104 | "typescript": "^5.2.2", 105 | "vm2": "^3.9.19", 106 | "vue": "^2.5.17", 107 | "vue-server-renderer": "^2.5.17", 108 | "web-vitals": "^0.2.4", 109 | "webpack": "5.94.0", 110 | "when": "^3.7.8" 111 | }, 112 | "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" 113 | } 114 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # ncc 2 | 3 | [![CI Status](https://github.com/vercel/ncc/workflows/CI/badge.svg)](https://github.com/vercel/ncc/actions?workflow=CI) 4 | 5 | Simple CLI for compiling a Node.js module into a single file, 6 | together with all its dependencies, gcc-style. 7 | 8 | ## Motivation 9 | 10 | - Publish minimal packages to npm 11 | - Only ship relevant app code to serverless environments 12 | - Don't waste time configuring bundlers 13 | - Generally faster bootup time and less I/O overhead 14 | - Compiled language-like experience (e.g.: `go`) 15 | 16 | ## Design goals 17 | 18 | - Zero configuration 19 | - TypeScript built-in 20 | - Only supports Node.js programs as input / output 21 | - Support all Node.js patterns and npm modules 22 | 23 | ## Usage 24 | 25 | ### Installation 26 | ```bash 27 | npm i -g @vercel/ncc 28 | ``` 29 | 30 | ### Usage 31 | 32 | ```bash 33 | $ ncc 34 | ``` 35 | Eg: 36 | ```bash 37 | $ ncc build input.js -o dist 38 | ``` 39 | 40 | If building an `.mjs` or `.js` module inside a `"type": "module"` [package boundary](https://nodejs.org/dist/latest-v16.x/docs/api/packages.html#packages_package_json_and_file_extensions), an ES module output will be created automatically. 41 | 42 | Outputs the Node.js compact build of `input.js` into `dist/index.js`. 43 | 44 | > Note: If the input file is using a `.cjs` extension, then so will the corresponding output file. 45 | > This is useful for packages that want to use `.js` files as modules in native Node.js using 46 | > a `"type": "module"` in the package.json file. 47 | 48 | #### Commands: 49 | ``` 50 | build [opts] 51 | run [opts] 52 | cache clean|dir|size 53 | help 54 | version 55 | ``` 56 | 57 | #### Options: 58 | ``` 59 | -o, --out [dir] Output directory for build (defaults to dist) 60 | -m, --minify Minify output 61 | -C, --no-cache Skip build cache population 62 | -s, --source-map Generate source map 63 | -a, --asset-builds Build nested JS assets recursively, useful for 64 | when code is loaded as an asset eg for workers. 65 | --no-source-map-register Skip source-map-register source map support 66 | -e, --external [mod] Skip bundling 'mod'. Can be used many times 67 | -q, --quiet Disable build summaries / non-error outputs 68 | -w, --watch Start a watched build 69 | -t, --transpile-only Use transpileOnly option with the ts-loader 70 | --v8-cache Emit a build using the v8 compile cache 71 | --license [file] Adds a file containing licensing information to the output 72 | --stats-out [file] Emit webpack stats as json to the specified output file 73 | --target [es] ECMAScript target to use for output (default: es2015) 74 | Learn more: https://webpack.js.org/configuration/target 75 | -d, --debug Show debug logs 76 | ``` 77 | 78 | ### Execution Testing 79 | 80 | For testing and debugging, a file can be built into a temporary directory and executed with full source maps support with the command: 81 | 82 | ```bash 83 | $ ncc run input.js 84 | ``` 85 | 86 | ### With TypeScript 87 | 88 | The only requirement is to point `ncc` to `.ts` or `.tsx` files. A `tsconfig.json` 89 | file is necessary. Most likely you want to indicate `es2015` support: 90 | 91 | ```json 92 | { 93 | "compilerOptions": { 94 | "target": "es2015", 95 | "moduleResolution": "node" 96 | } 97 | } 98 | ``` 99 | 100 | If typescript is found in `devDependencies`, that version will be used. 101 | 102 | ### Package Support 103 | 104 | Some packages may need some extra options for ncc support in order to better work with the static analysis. 105 | 106 | See [package-support.md](package-support.md) for some common packages and their usage with ncc. 107 | 108 | ### Programmatically From Node.js 109 | 110 | ```js 111 | require('@vercel/ncc')('/path/to/input', { 112 | // provide a custom cache path or disable caching 113 | cache: "./custom/cache/path" | false, 114 | // externals to leave as requires of the build 115 | externals: ["externalpackage"], 116 | // directory outside of which never to emit assets 117 | filterAssetBase: process.cwd(), // default 118 | minify: false, // default 119 | sourceMap: false, // default 120 | assetBuilds: false, // default 121 | sourceMapBasePrefix: '../', // default treats sources as output-relative 122 | // when outputting a sourcemap, automatically include 123 | // source-map-support in the output file (increases output by 32kB). 124 | sourceMapRegister: true, // default 125 | watch: false, // default 126 | license: '', // default does not generate a license file 127 | target: 'es2015', // default 128 | v8cache: false, // default 129 | quiet: false, // default 130 | debugLog: false // default 131 | }).then(({ code, map, assets }) => { 132 | console.log(code); 133 | // Assets is an object of asset file names to { source, permissions, symlinks } 134 | // expected relative to the output code (if any) 135 | }) 136 | ``` 137 | 138 | When `watch: true` is set, the build object is not a promise, but has the following signature: 139 | 140 | ```js 141 | { 142 | // handler re-run on each build completion 143 | // watch errors are reported on "err" 144 | handler (({ err, code, map, assets }) => { ... }) 145 | // handler re-run on each rebuild start 146 | rebuild (() => {}) 147 | // close the watcher 148 | void close (); 149 | } 150 | ``` 151 | 152 | ## Caveats 153 | 154 | - Files / assets are relocated based on a [static evaluator](https://github.com/vercel/webpack-asset-relocator-loader#how-it-works). Dynamic non-statically analyzable asset loads may not work out correctly 155 | -------------------------------------------------------------------------------- /release.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | branches: ['main'], 3 | tagFormat: '${version}', 4 | } 5 | -------------------------------------------------------------------------------- /src/@@notfound.js: -------------------------------------------------------------------------------- 1 | module.exports = __non_webpack_require__('UNKNOWN'); 2 | -------------------------------------------------------------------------------- /src/loaders/empty-loader.js: -------------------------------------------------------------------------------- 1 | // returns the base-level package folder based on detecting "node_modules" 2 | // package name boundaries 3 | const pkgNameRegEx = /^(@[^\\\/]+[\\\/])?[^\\\/]+/; 4 | function getPackageBase(id) { 5 | const pkgIndex = id.lastIndexOf('node_modules'); 6 | if (pkgIndex !== -1 && 7 | (id[pkgIndex - 1] === '/' || id[pkgIndex - 1] === '\\') && 8 | (id[pkgIndex + 12] === '/' || id[pkgIndex + 12] === '\\')) { 9 | const pkgNameMatch = id.substr(pkgIndex + 13).match(pkgNameRegEx); 10 | if (pkgNameMatch) 11 | return id.substr(0, pkgIndex + 13 + pkgNameMatch[0].length); 12 | } 13 | } 14 | 15 | const emptyModules = { 'uglify-js': true, 'uglify-es': true }; 16 | 17 | module.exports = function (input, map) { 18 | const id = this.resourcePath; 19 | const pkgBase = getPackageBase(id); 20 | if (pkgBase) { 21 | const baseParts = pkgBase.split('/'); 22 | if (baseParts[baseParts.length - 2] === 'node_modules') { 23 | const pkgName = baseParts[baseParts.length - 1]; 24 | if (pkgName in emptyModules) { 25 | console.warn(`ncc: Ignoring build of ${pkgName}, as it is not statically analyzable. Build with "--external ${pkgName}" if this package is needed.`); 26 | return ''; 27 | } 28 | } 29 | } 30 | this.callback(null, input, map); 31 | }; 32 | -------------------------------------------------------------------------------- /src/loaders/notfound-loader.js: -------------------------------------------------------------------------------- 1 | module.exports = function (input, map) { 2 | if (this.cacheable) 3 | this.cacheable(); 4 | const id = this.resourceQuery.substr(1); 5 | input = input.replace('\'UNKNOWN\'', JSON.stringify(id)); 6 | this.callback(null, input, map); 7 | }; 8 | -------------------------------------------------------------------------------- /src/loaders/relocate-loader.js: -------------------------------------------------------------------------------- 1 | module.exports = require('@vercel/webpack-asset-relocator-loader'); 2 | -------------------------------------------------------------------------------- /src/loaders/shebang-loader.js: -------------------------------------------------------------------------------- 1 | module.exports = require("shebang-loader"); 2 | -------------------------------------------------------------------------------- /src/loaders/stringify-loader.js: -------------------------------------------------------------------------------- 1 | module.exports = (source) => JSON.stringify(source); 2 | -------------------------------------------------------------------------------- /src/loaders/ts-loader.js: -------------------------------------------------------------------------------- 1 | // we re-export so that we generate a unique 2 | // optional bundle for the ts-loader, that 3 | // doesn't get loaded unless the user is 4 | // compiling typescript 5 | const logger = require("ts-loader/dist/logger"); 6 | const makeLogger = logger.makeLogger; 7 | logger.makeLogger = function (loaderOptions, colors) { 8 | const instance = makeLogger(loaderOptions, colors); 9 | const logWarning = instance.logWarning; 10 | instance.logWarning = function (message) { 11 | // Disable TS Loader TypeScript compatibility warning 12 | if (message.indexOf('This version may or may not be compatible with ts-loader') !== -1) 13 | return; 14 | return logWarning(message); 15 | }; 16 | return instance; 17 | }; 18 | 19 | module.exports = require("ts-loader"); 20 | 21 | // ts-loader internally has a require("typescript") that applies 22 | // regardless of "compiler". 23 | // We could remap this too, as soon as ncc supports aliased externals 24 | module.exports.typescript = require("typescript"); 25 | -------------------------------------------------------------------------------- /src/loaders/uncacheable.js: -------------------------------------------------------------------------------- 1 | module.exports = function (input, map) { 2 | this.cacheable(false); 3 | return this.callback(null, input, map); 4 | }; -------------------------------------------------------------------------------- /src/sourcemap-register.js.cache.js: -------------------------------------------------------------------------------- 1 | ../dist/ncc/sourcemap-register.js.cache.js -------------------------------------------------------------------------------- /src/typescript.js: -------------------------------------------------------------------------------- 1 | 2 | const { Module } = require('module'); 3 | const m = new Module('', null); 4 | const { quiet, typescriptLookupPath } = JSON.parse(process.env.__NCC_OPTS || '{}'); 5 | m.paths = Module._nodeModulePaths(process.env.TYPESCRIPT_LOOKUP_PATH || typescriptLookupPath || (process.cwd() + '/')); 6 | let typescript; 7 | try { 8 | typescript = m.require('typescript'); 9 | if (!quiet) console.log("ncc: Using typescript@" + typescript.version + " (local user-provided)"); 10 | } 11 | catch (e) { 12 | typescript = require('typescript'); 13 | if (!quiet) console.log("ncc: Using typescript@" + typescript.version + " (ncc built-in)"); 14 | } 15 | module.exports = typescript; 16 | -------------------------------------------------------------------------------- /src/utils/get-package-base.js: -------------------------------------------------------------------------------- 1 | // returns the base-level package folder based on detecting "node_modules" 2 | // package name boundaries 3 | const pkgNameRegEx = /^(@[^\\\/]+[\\\/])?[^\\\/]+/; 4 | module.exports = function (id) { 5 | const pkgIndex = id.lastIndexOf('node_modules'); 6 | if (pkgIndex !== -1 && 7 | (id[pkgIndex - 1] === '/' || id[pkgIndex - 1] === '\\') && 8 | (id[pkgIndex + 12] === '/' || id[pkgIndex + 12] === '\\')) { 9 | const pkgNameMatch = id.substr(pkgIndex + 13).match(pkgNameRegEx); 10 | if (pkgNameMatch) 11 | return id.substr(0, pkgIndex + 13 + pkgNameMatch[0].length); 12 | } 13 | }; 14 | 15 | module.exports.pkgNameRegEx = pkgNameRegEx; -------------------------------------------------------------------------------- /src/utils/has-type-module.js: -------------------------------------------------------------------------------- 1 | const { resolve } = require('path'); 2 | const { readFileSync } = require('fs'); 3 | 4 | exports.hasTypeModule = function hasTypeModule (path) { 5 | while (path !== (path = resolve(path, '..'))) { 6 | try { 7 | return JSON.parse(readFileSync(eval('resolve')(path, 'package.json')).toString()).type === 'module'; 8 | } 9 | catch (e) { 10 | if (e.code === 'ENOENT') 11 | continue; 12 | throw e; 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/utils/ncc-cache-dir.js: -------------------------------------------------------------------------------- 1 | module.exports = require("os").tmpdir() + "/ncc-cache"; -------------------------------------------------------------------------------- /src/utils/shebang.js: -------------------------------------------------------------------------------- 1 | module.exports = /^#![^\n\r]*[\r\n]/; -------------------------------------------------------------------------------- /test/binary/binding.gyp: -------------------------------------------------------------------------------- 1 | { 2 | "targets": [ 3 | { 4 | "target_name": "hello", 5 | "sources": [ "hello.cc" ], 6 | "include_dirs": [ 7 | " 3 | 4 | namespace demo { 5 | 6 | using v8::FunctionCallbackInfo; 7 | using v8::Isolate; 8 | using v8::Local; 9 | using v8::NewStringType; 10 | using v8::Object; 11 | using v8::String; 12 | using v8::Value; 13 | 14 | void Method(const FunctionCallbackInfo& args) { 15 | Isolate* isolate = args.GetIsolate(); 16 | args.GetReturnValue().Set(String::NewFromUtf8( 17 | isolate, "world", NewStringType::kNormal).ToLocalChecked()); 18 | } 19 | 20 | void Initialize(Local exports) { 21 | NODE_SET_METHOD(exports, "hello", Method); 22 | } 23 | 24 | NODE_MODULE(NODE_GYP_MODULE_NAME, Initialize) 25 | 26 | } // namespace demo -------------------------------------------------------------------------------- /test/cli.js: -------------------------------------------------------------------------------- 1 | const { join, resolve: pathResolve } = require('path'); 2 | 3 | module.exports = [ 4 | { 5 | args: ["run", "test/fixtures/ts-interop/interop.ts"], 6 | expect: { code: 0 } 7 | }, 8 | { 9 | args: ["run", "test/fixtures/interop-test.mjs"], 10 | expect: { code: 0 } 11 | }, 12 | { 13 | args: ["run", "test/integration/test.ts"], 14 | expect: { code: 0 } 15 | }, 16 | { 17 | args: ["build", "test/fixtures/type-module/main.js", "-a", "-o", "tmp"], 18 | expect: { code: 0 } 19 | }, 20 | { 21 | args: ["build", "test/integration/test.ts", "-o", "tmp"], 22 | expect (code, stdout, stderr) { 23 | return stdout.toString().indexOf(join('tmp', 'index.js')) !== -1; 24 | } 25 | }, 26 | { 27 | args: ["run", "--v8-cache", "-a", "test/integration/test.ts"], 28 | expect: { code: 0 } 29 | }, 30 | { 31 | args: ["run", "--v8-cache", "test/integration/stack-trace.js"], 32 | expect: { code: 0 } 33 | }, 34 | { 35 | args: ["run", "test/fixtures/error.js"], 36 | expect: { code: 1 } 37 | }, 38 | { 39 | args: ["run", "test/fixtures/does-not-exist.js"], 40 | expect: { code: 1 } 41 | }, 42 | { 43 | args: ["run", "test/fixtures/error.js", "--no-source-map-register"], 44 | expect (code, stdout, stderr) { 45 | return code === 1 && stderr.toString().indexOf('fixtures/error.js') === -1; 46 | } 47 | }, 48 | { 49 | args: ["run", "--watch", "-a", "test/integration/test.ts"], 50 | expect: { code: 2 } 51 | }, 52 | { 53 | args: ["build", "-o", "tmp", "--watch", "test/fixtures/no-dep.js"], 54 | timeout: 500, 55 | expect: { timeout: true } 56 | }, 57 | { 58 | args: ["run", "test/fixtures/ts-error1/fail.ts"], 59 | expect (code, stdout, stderr) { 60 | return code === 1 && stderr.toString().indexOf('fail.ts:2:1') !== -1; 61 | } 62 | }, 63 | { 64 | args: ["run", "test/fixtures/ts-error2/ts-error.ts"], 65 | expect (code, stdout, stderr) { 66 | return code === 1 && stderr.toString().indexOf('ts-error.ts(3,16)') !== -1 && stderr.toString().split('\n').length < 11; 67 | } 68 | }, 69 | { 70 | args: ["run", "-t", "test/fixtures/with-type-errors/ts-error.ts"], 71 | expect: { code: 0 } 72 | }, 73 | { 74 | args: ["build", "-o", "tmp", "test/fixtures/test.cjs"], 75 | expect (code, stdout, stderr) { 76 | return stdout.toString().indexOf(join('tmp', 'index.cjs')) !== -1; 77 | } 78 | }, 79 | { 80 | args: ["build", "-o", "tmp", "test/fixtures/test.mjs"], 81 | expect (code, stdout, stderr) { 82 | return stdout.toString().indexOf(join('tmp', 'index.mjs')) !== -1; 83 | } 84 | }, 85 | { 86 | args: ["build", "-o", "tmp", "test/fixtures/test.mjs", "--stats-out", "tmp/stats.json"], 87 | expect (code, stdout, stderr) { 88 | const fs = require('fs'); 89 | try { 90 | JSON.parse(fs.readFileSync(join('tmp', 'stats.json'), 'utf8')); 91 | } catch { 92 | return false; 93 | } 94 | return true; 95 | } 96 | }, 97 | { 98 | args: ["build", "--quiet", "test/integration/test.ts"], 99 | expect (code, stdout) { 100 | stdout = stdout.toString().replace(/[\r\n\s]/g, '').trim(); 101 | return stdout.length === 0; 102 | } 103 | }, 104 | { 105 | args: ["build", "test/integration/test.ts"], 106 | env: { 107 | TYPESCRIPT_LOOKUP_PATH: '/tmp/nowhere' 108 | }, 109 | expect (code, stdout) { 110 | return code === 0 && stdout.indexOf('ncc built-in') !== -1; 111 | }, 112 | }, 113 | { 114 | args: ["build", "-o", "tmp", "test/fixtures/module.cjs"], 115 | expect (code, stdout) { 116 | const fs = require('fs'); 117 | return code === 0 && fs.readFileSync(join('tmp', 'index.js'), 'utf8').toString().indexOf('export {') === -1; 118 | } 119 | }, 120 | { 121 | args: ["build", "-o", "tmp", "test/fixtures/sourcemap-resource-path/index.ts", "--source-map", "--no-source-map-register"], 122 | expect (code, stdout, stderr) { 123 | const fs = require('fs'); 124 | const map = JSON.parse(fs.readFileSync(join('tmp', 'index.js.map'), 'utf8')); 125 | const paths = map.sources.map(source=>pathResolve(join('tmp', source))); 126 | function hasPath(path) { 127 | return paths.includes(pathResolve(path)); 128 | } 129 | return code === 0 && hasPath('test/fixtures/sourcemap-resource-path/index.ts') && hasPath('test/fixtures/sourcemap-resource-path/sum.ts'); 130 | } 131 | }, 132 | { 133 | args: ["build", "-o", "tmp", "test/fixtures/sourcemap-resource-path/index.ts", "-m", "--source-map", "--no-source-map-register"], 134 | expect (code, stdout, stderr) { 135 | const fs = require('fs'); 136 | const map = JSON.parse(fs.readFileSync(join('tmp', 'index.js.map'), 'utf8')); 137 | const paths = map.sources.map(source=>pathResolve(join('tmp', source))); 138 | function hasPath(path) { 139 | return paths.includes(pathResolve(path)); 140 | } 141 | return code === 0 && hasPath('test/fixtures/sourcemap-resource-path/index.ts') && hasPath('test/fixtures/sourcemap-resource-path/sum.ts'); 142 | } 143 | } 144 | ] 145 | -------------------------------------------------------------------------------- /test/cli.test.js: -------------------------------------------------------------------------------- 1 | const { fork } = require("child_process"); 2 | const { join } = require("path"); 3 | const cliTests = require("./cli.js"); 4 | const file = global.coverage ? "/../src/cli.js" : "/../dist/ncc/cli.js"; 5 | 6 | jest.setTimeout(20000); 7 | 8 | for (const cliTest of cliTests) { 9 | it(`should execute "ncc ${(cliTest.args || []).join(" ")}"`, async () => { 10 | const ps = fork(join(__dirname, file), cliTest.args || [], { 11 | stdio: "pipe", 12 | env: { ...process.env, ...cliTest.env }, 13 | }); 14 | let stderr = "", stdout = ""; 15 | ps.stderr.on("data", chunk => stderr += chunk.toString()); 16 | ps.stdout.on("data", chunk => stdout += chunk.toString()); 17 | const expected = cliTest.expect || { code: 0 }; 18 | let timedOut = false; 19 | if (cliTest.timeout) 20 | setTimeout(() => { 21 | timedOut = true; 22 | ps.kill(); 23 | }, cliTest.timeout); 24 | const code = await new Promise(resolve => ps.on("close", resolve)); 25 | if (typeof expected === "function") 26 | expect(expected(code, stdout, stderr, timedOut)).toBe(true); 27 | else { 28 | if ("code" in expected) 29 | expect(code).toBe(expected.code); 30 | if ("timeout" in expected) 31 | expect(timedOut).toBe(true); 32 | } 33 | }); 34 | } 35 | -------------------------------------------------------------------------------- /test/fixtures/error.js: -------------------------------------------------------------------------------- 1 | function x () { 2 | console.log('running x'); 3 | throw new Error('xx'); 4 | } 5 | 6 | x(); -------------------------------------------------------------------------------- /test/fixtures/index.html: -------------------------------------------------------------------------------- 1 |

{{ title }}

2 | -------------------------------------------------------------------------------- /test/fixtures/interop-test.mjs: -------------------------------------------------------------------------------- 1 | import { strictEqual } from 'assert'; 2 | import * as z from './interop.cjs'; 3 | 4 | strictEqual(z.s, 's'); 5 | strictEqual(z.__esModule, true); 6 | strictEqual(z.default.default, 'z'); 7 | strictEqual(z.default.s, 's'); 8 | -------------------------------------------------------------------------------- /test/fixtures/interop.cjs: -------------------------------------------------------------------------------- 1 | Object.defineProperty(exports, '__esModule', { value: true }); 2 | exports.s = 's'; 3 | exports['com' + 'puted'] = 'y'; 4 | exports.default = 'z'; 5 | 6 | -------------------------------------------------------------------------------- /test/fixtures/module.cjs: -------------------------------------------------------------------------------- 1 | require('./no-dep.js'); 2 | 3 | exports.aRealExport = true; 4 | -------------------------------------------------------------------------------- /test/fixtures/no-dep.js: -------------------------------------------------------------------------------- 1 | console.log('asdf'); 2 | -------------------------------------------------------------------------------- /test/fixtures/sourcemap-resource-path/index.ts: -------------------------------------------------------------------------------- 1 | import { sum } from './sum' 2 | 3 | const s = sum(1, 2) 4 | console.log(s) 5 | -------------------------------------------------------------------------------- /test/fixtures/sourcemap-resource-path/sum.ts: -------------------------------------------------------------------------------- 1 | export function sum(a: number, b: number) { 2 | return a + b 3 | } 4 | -------------------------------------------------------------------------------- /test/fixtures/sourcemap-resource-path/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2015", 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/test.cjs: -------------------------------------------------------------------------------- 1 | module.exports = 'test'; 2 | -------------------------------------------------------------------------------- /test/fixtures/test.mjs: -------------------------------------------------------------------------------- 1 | module.exports = 'test'; 2 | -------------------------------------------------------------------------------- /test/fixtures/ts-error1/fail.ts: -------------------------------------------------------------------------------- 1 | function x () { 2 | throw new Error('Should have correct sourcemap'); 3 | } 4 | 5 | x(); -------------------------------------------------------------------------------- /test/fixtures/ts-error1/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2015" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/ts-error2/ts-error.ts: -------------------------------------------------------------------------------- 1 | require.extensions['.asdf'] = function () {}; 2 | 3 | function p (x: Y) { 4 | 5 | } -------------------------------------------------------------------------------- /test/fixtures/ts-error2/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2015" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/ts-interop/interop.ts: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import * as path2 from 'path'; 3 | path.resolve('dir'); 4 | path2.resolve('dir'); 5 | -------------------------------------------------------------------------------- /test/fixtures/ts-interop/tsconfig.json: -------------------------------------------------------------------------------- 1 | {} 2 | 3 | -------------------------------------------------------------------------------- /test/fixtures/type-module/main.js: -------------------------------------------------------------------------------- 1 | import { readFileSync } from 'fs'; 2 | 3 | readFileSync(new URL('./package.json', import.meta.url)); 4 | 5 | export var p = 5; 6 | 7 | -------------------------------------------------------------------------------- /test/fixtures/type-module/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "module" 3 | } 4 | -------------------------------------------------------------------------------- /test/fixtures/with-type-errors/ts-error.ts: -------------------------------------------------------------------------------- 1 | require.extensions['.asdf'] = function () {}; 2 | 3 | function p (x: Y) { 4 | 5 | } -------------------------------------------------------------------------------- /test/fixtures/with-type-errors/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2015" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /test/integration.test.js: -------------------------------------------------------------------------------- 1 | const os = require("os"); 2 | const fs = require("fs"); 3 | const path = require("path"); 4 | const coverage = global.coverage; 5 | 6 | // the twilio test can take a while (large codebase) 7 | jest.setTimeout(200000); 8 | 9 | const skipOnWindows = [ 10 | 'binary-require.js', 11 | 'browserify-middleware.js', 12 | 'oracledb.js', 13 | 'tensorflow.js', 14 | ] 15 | 16 | const skipOnMacOS = [ 17 | // https://github.com/Level/leveldown/issues/801 18 | 'leveldown.js' 19 | ] 20 | 21 | let nccRun; 22 | if (coverage) { 23 | nccRun = require(__dirname + "/../src/cli.js"); 24 | } 25 | else { 26 | nccRun = require(__dirname + "/../dist/ncc/cli.js"); 27 | } 28 | 29 | const { Writable } = require('stream'); 30 | 31 | class StoreStream extends Writable { 32 | constructor (options) { 33 | super(options); 34 | this.data = []; 35 | } 36 | _write(chunk, encoding, callback) { 37 | this.data.push(chunk); 38 | callback(); 39 | } 40 | } 41 | 42 | for (const integrationTest of fs.readdirSync(__dirname + "/integration")) { 43 | // ignore e.g.: `.json` files 44 | if (!/\.(mjs|tsx?|js)$/.test(integrationTest)) continue; 45 | 46 | // disabled pending https://github.com/zeit/ncc/issues/141 47 | if (integrationTest.endsWith('loopback.js')) continue; 48 | 49 | // ignore a few tests known to fail on windows 50 | if (process.platform === 'win32' && skipOnWindows.includes(integrationTest)) continue; 51 | 52 | // ignore a few tests known to fail on macOS 53 | if (process.platform === 'darwin' && skipOnMacOS.includes(integrationTest)) continue; 54 | 55 | it(`should execute "ncc run ${integrationTest}"`, async () => { 56 | let expectedStdout; 57 | try { 58 | expectedStdout = fs.readFileSync(`${__dirname}/integration/${integrationTest}.stdout`).toString(); 59 | } 60 | catch (e) {} 61 | if (global.gc) global.gc(); 62 | const stdout = new StoreStream(); 63 | const stderr = new StoreStream(); 64 | try { 65 | await nccRun(["run", "--no-cache", `${__dirname}/integration/${integrationTest}`], stdout, stderr); 66 | } 67 | catch (e) { 68 | if (e.silent) { 69 | let lastErr = stderr.data[stderr.data.length - 1]; 70 | if (lastErr) 71 | throw new Error(lastErr); 72 | else 73 | throw new Error('Process exited with code ' + e.exitCode); 74 | } 75 | throw e; 76 | } 77 | if (expectedStdout) { 78 | let stdoutStr = ''; 79 | for (const chunk of stdout.data) 80 | stdoutStr += chunk.toString(); 81 | expect(stdoutStr.startsWith(expectedStdout)); 82 | } 83 | }); 84 | } 85 | 86 | it(`should execute "ncc build web-vitals" with target config`, async () => { 87 | if (global.gc) global.gc(); 88 | const stdout = new StoreStream(); 89 | const stderr = new StoreStream(); 90 | 91 | const tmpOut = path.join(os.tmpdir(), `ncc_${Math.random()}`) 92 | 93 | try { 94 | await nccRun(["build", "-o", tmpOut, "--target", "es5", require.resolve('web-vitals/dist/web-vitals.es5.min.js')], stdout, stderr); 95 | } 96 | catch (e) { 97 | if (e.silent) { 98 | let lastErr = stderr.data[stderr.data.length - 1]; 99 | if (lastErr) 100 | throw new Error(lastErr); 101 | else 102 | throw new Error('Process exited with code ' + e.exitCode); 103 | } 104 | throw e; 105 | } 106 | 107 | const outFile = path.join(tmpOut, 'index.js') 108 | const output = fs.readFileSync(outFile, 'utf8') 109 | 110 | // cleanup tmp output 111 | fs.unlinkSync(outFile) 112 | fs.rmdirSync(tmpOut) 113 | 114 | expect(output).toContain('function') 115 | // make sure es6 wrapper wasn't used 116 | expect(output).not.toContain('=>') 117 | 118 | await new Promise(resolve => setTimeout(resolve, 5000)); 119 | }); 120 | 121 | afterAll(() => { 122 | if (coverage) 123 | process.exit(0); 124 | }); 125 | 126 | // remove me when node.js makes this the default behavior 127 | process.on("unhandledRejection", e => { 128 | throw e; 129 | }); 130 | -------------------------------------------------------------------------------- /test/integration/analytics-node.js: -------------------------------------------------------------------------------- 1 | const Analytics = require("analytics-node"); 2 | 3 | new Analytics("YOUR_WRITE_KEY"); 4 | -------------------------------------------------------------------------------- /test/integration/apollo.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const { ApolloServer, gql } = require("apollo-server-express"); 3 | 4 | // Construct a schema, using GraphQL schema language 5 | const typeDefs = gql` 6 | type Query { 7 | hello: String 8 | } 9 | `; 10 | 11 | // Provide resolver functions for your schema fields 12 | const resolvers = { 13 | Query: { 14 | hello: () => "Hello world!" 15 | } 16 | }; 17 | 18 | 19 | const server = new ApolloServer({ typeDefs, resolvers }); 20 | const app = express(); 21 | server.applyMiddleware({ app }); 22 | -------------------------------------------------------------------------------- /test/integration/auth0.js: -------------------------------------------------------------------------------- 1 | const ManagementClient = require("auth0").ManagementClient; 2 | 3 | try { 4 | new ManagementClient(); 5 | } catch (err) { 6 | if (!/Management API SDK options must be an object/.test(err.message)) { 7 | throw err; 8 | } 9 | } 10 | 11 | -------------------------------------------------------------------------------- /test/integration/aws-sdk.js: -------------------------------------------------------------------------------- 1 | const { S3 } = require('@aws-sdk/client-s3'); 2 | 3 | new S3(); 4 | -------------------------------------------------------------------------------- /test/integration/axios.js: -------------------------------------------------------------------------------- 1 | const axios = require("axios"); 2 | 3 | (async () => { 4 | const { status } = await axios({ 5 | url: "https://example.vercel.sh" 6 | }); 7 | if (status !== 200) { 8 | throw new Error("Unexpected response: " + JSON.stringify(data)); 9 | } 10 | })(); 11 | -------------------------------------------------------------------------------- /test/integration/azure-cosmos.js: -------------------------------------------------------------------------------- 1 | require("@azure/cosmos"); 2 | 3 | -------------------------------------------------------------------------------- /test/integration/azure-storage.js: -------------------------------------------------------------------------------- 1 | require("azure-storage"); 2 | -------------------------------------------------------------------------------- /test/integration/binary-require.js: -------------------------------------------------------------------------------- 1 | const binary = require('./hello.node'); 2 | const assert = require('assert'); 3 | 4 | 5 | assert.equal(binary.hello(), 'world'); -------------------------------------------------------------------------------- /test/integration/browserify-middleware.js: -------------------------------------------------------------------------------- 1 | require('browserify-middleware'); 2 | -------------------------------------------------------------------------------- /test/integration/bugsnag-js.js: -------------------------------------------------------------------------------- 1 | require("@bugsnag/js"); 2 | 3 | module.exports = () => {}; 4 | -------------------------------------------------------------------------------- /test/integration/canvas.js: -------------------------------------------------------------------------------- 1 | const canvas = require('canvas'); 2 | module.exports = () => { 3 | const { createCanvas } = canvas; 4 | const c = createCanvas(200, 200); 5 | const ctx = c.getContext('2d'); 6 | }; -------------------------------------------------------------------------------- /test/integration/chromeless.js: -------------------------------------------------------------------------------- 1 | require('chromeless'); 2 | -------------------------------------------------------------------------------- /test/integration/core-js.js: -------------------------------------------------------------------------------- 1 | 2 | require("core-js").Array.map([], () => {}); 3 | -------------------------------------------------------------------------------- /test/integration/cowsay.js: -------------------------------------------------------------------------------- 1 | const { say } = require("cowsay"); 2 | 3 | const nate = say({ text: "nate" }); 4 | if (!(nate.indexOf("nate") > 0)) { 5 | throw new Error('cowsay did not work. String "nate" not found in: ' + nate); 6 | } 7 | 8 | -------------------------------------------------------------------------------- /test/integration/env-var.js: -------------------------------------------------------------------------------- 1 | const env = process.env.NODE_ENV = 'development' 2 | 3 | module.exports = env; 4 | -------------------------------------------------------------------------------- /test/integration/es-module.js: -------------------------------------------------------------------------------- 1 | export var p = 5; 2 | -------------------------------------------------------------------------------- /test/integration/esm.js: -------------------------------------------------------------------------------- 1 | require = require('esm')(module); 2 | const assert = require('assert'); 3 | assert.equal(require('./es-module.js').p, 5); 4 | -------------------------------------------------------------------------------- /test/integration/express-consolidate.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert'); 2 | var express = require('express') 3 | , cons = require('consolidate') 4 | , app = express(); 5 | 6 | // assign the swig engine to .html files 7 | app.engine('html', cons.swig); 8 | 9 | // set .html as the default extension 10 | app.set('view engine', 'html'); 11 | app.set('views', __dirname + '/../fixtures'); 12 | 13 | app.render('index', { 14 | title: 'Consolidate.js' 15 | }, function (err, rendered) { 16 | assert.ok(rendered.startsWith('

Consolidate.js

')); 17 | }); 18 | -------------------------------------------------------------------------------- /test/integration/express.js: -------------------------------------------------------------------------------- 1 | const app = require('express'); 2 | 3 | -------------------------------------------------------------------------------- /test/integration/fetch-h2.js: -------------------------------------------------------------------------------- 1 | const fetch = require("fetch-h2"); 2 | -------------------------------------------------------------------------------- /test/integration/ffmpeg.js: -------------------------------------------------------------------------------- 1 | let {path} = require('@ffmpeg-installer/ffmpeg'); 2 | console.log(path); 3 | -------------------------------------------------------------------------------- /test/integration/firebase-admin.js: -------------------------------------------------------------------------------- 1 | require("firebase-admin"); -------------------------------------------------------------------------------- /test/integration/firebase.js: -------------------------------------------------------------------------------- 1 | const firebase = require('firebase/app') 2 | require('firebase/firestore') 3 | 4 | firebase.initializeApp({ projectId: 'noop' }) 5 | const store = firebase.firestore() 6 | 7 | store 8 | .collection('users') 9 | .get() 10 | .then( 11 | () => { 12 | process.exit(0) 13 | }, 14 | e => { 15 | /* 16 | Error: unresolvable extensions: 'extend google.protobuf.MethodOptions' in .google.api 17 | at Root.resolveAll (/private/var/folders/c3/vytj6_h56b77f_g72smntm3m0000gn/T/node_modules/protobufjs/src/root.js:243:1) 18 | at Object.loadSync (/private/var/folders/c3/vytj6_h56b77f_g72smntm3m0000gn/T/a707d6b7ee4afe5b484993180e617e2d/index.js:43406:16) 19 | at loadProtos (/private/var/folders/c3/vytj6_h56b77f_g72smntm3m0000gn/T/a707d6b7ee4afe5b484993180e617e2d/index.js:16778:41) 20 | at NodePlatform.module.exports.278.NodePlatform.loadConnection (/private/var/folders/c3/vytj6_h56b77f_g72smntm3m0000gn/T/a707d6b7ee4afe5b484993180e617e2d/index.js:16815:22) 21 | at FirestoreClient.module.exports.278.FirestoreClient.initializeRest (/private/var/folders/c3/vytj6_h56b77f_g72smntm3m0000gn/T/a707d6b7ee4afe5b484993180e617e2d/index.js:28414:14) 22 | at /private/var/folders/c3/vytj6_h56b77f_g72smntm3m0000gn/T/a707d6b7ee4afe5b484993180e617e2d/index.js:28239:64 23 | */ 24 | console.error(e) 25 | process.exit(1) 26 | } 27 | ) 28 | -------------------------------------------------------------------------------- /test/integration/firestore.js: -------------------------------------------------------------------------------- 1 | require("@google-cloud/firestore"); 2 | -------------------------------------------------------------------------------- /test/integration/fluent-ffmpeg.js: -------------------------------------------------------------------------------- 1 | const ffmpeg = require('fluent-ffmpeg'); 2 | const proc = new ffmpeg({ source: 'wat', nolog: true }); -------------------------------------------------------------------------------- /test/integration/google-bigquery.js: -------------------------------------------------------------------------------- 1 | const {BigQuery} = require('@google-cloud/bigquery'); 2 | 3 | const bigquery = new BigQuery({ 4 | projectId: 'PROJECT_ID', 5 | }); 6 | -------------------------------------------------------------------------------- /test/integration/got.js: -------------------------------------------------------------------------------- 1 | require('got'); 2 | -------------------------------------------------------------------------------- /test/integration/hot-shots.js: -------------------------------------------------------------------------------- 1 | require("hot-shots"); 2 | -------------------------------------------------------------------------------- /test/integration/include/throwing.js: -------------------------------------------------------------------------------- 1 | throw new Error('kaboom') 2 | -------------------------------------------------------------------------------- /test/integration/ioredis.js: -------------------------------------------------------------------------------- 1 | const ioredis = require("ioredis"); 2 | -------------------------------------------------------------------------------- /test/integration/isomorphic-unfetch.js: -------------------------------------------------------------------------------- 1 | const fetch = require("isomorphic-unfetch"); 2 | 3 | (async () => { 4 | const { status } = await fetch("https://example.vercel.sh"); 5 | if (status !== 200) { 6 | throw new Error(`Unexpected status: ${status}`); 7 | } 8 | })(); 9 | -------------------------------------------------------------------------------- /test/integration/jimp.js: -------------------------------------------------------------------------------- 1 | const jimp = require('jimp') 2 | -------------------------------------------------------------------------------- /test/integration/json-without-ext-sample.json: -------------------------------------------------------------------------------- 1 | { 2 | "a": "b" 3 | } 4 | -------------------------------------------------------------------------------- /test/integration/json-without-ext.js: -------------------------------------------------------------------------------- 1 | const { a } = require('./json-without-ext-sample') 2 | 3 | -------------------------------------------------------------------------------- /test/integration/jugglingdb.js: -------------------------------------------------------------------------------- 1 | require("jugglingdb"); 2 | module.exports = () => {}; 3 | -------------------------------------------------------------------------------- /test/integration/koa.js: -------------------------------------------------------------------------------- 1 | const Koa = require("koa"); 2 | 3 | new Koa(); 4 | 5 | -------------------------------------------------------------------------------- /test/integration/leveldown.js: -------------------------------------------------------------------------------- 1 | const leveldown = require('leveldown'); 2 | const db = leveldown('tmp/db'); 3 | -------------------------------------------------------------------------------- /test/integration/lighthouse.js: -------------------------------------------------------------------------------- 1 | require('lighthouse'); 2 | -------------------------------------------------------------------------------- /test/integration/loopback.js: -------------------------------------------------------------------------------- 1 | require("loopback"); -------------------------------------------------------------------------------- /test/integration/mailgun.js: -------------------------------------------------------------------------------- 1 | const mailgun = require('mailgun'); 2 | -------------------------------------------------------------------------------- /test/integration/mariadb.js: -------------------------------------------------------------------------------- 1 | require('mariadb') 2 | -------------------------------------------------------------------------------- /test/integration/memcached.js: -------------------------------------------------------------------------------- 1 | const Memcached = require('memcached'); 2 | Memcached.config.poolSize = 25; 3 | 4 | -------------------------------------------------------------------------------- /test/integration/mongoose.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Schema = mongoose.Schema; 3 | 4 | const blogSchema = new Schema({ 5 | title: String, 6 | author: String, 7 | body: String, 8 | comments: [{ body: String, date: Date }], 9 | date: { type: Date, default: Date.now }, 10 | hidden: Boolean, 11 | meta: { 12 | votes: Number, 13 | favs: Number 14 | } 15 | }); 16 | -------------------------------------------------------------------------------- /test/integration/mysql.js: -------------------------------------------------------------------------------- 1 | const mysql = require("mysql"); 2 | 3 | var connection = mysql.createConnection({ 4 | host: "localhost", 5 | user: "me", 6 | password: "secret", 7 | database: "my_db" 8 | }); 9 | -------------------------------------------------------------------------------- /test/integration/node-path/foo.js: -------------------------------------------------------------------------------- 1 | module.exports = 'foo' 2 | -------------------------------------------------------------------------------- /test/integration/node_modules/node_gyp/noop.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vercel/ncc/cbfd660dca6db33f8cae132873293f5db99f9749/test/integration/node_modules/node_gyp/noop.js -------------------------------------------------------------------------------- /test/integration/node_modules/node_gyp/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "main": "noop.js" 3 | } -------------------------------------------------------------------------------- /test/integration/node_modules/typescript/index.js: -------------------------------------------------------------------------------- 1 | node_modules/typescript/lib/typescript.js -------------------------------------------------------------------------------- /test/integration/node_modules/typescript/lib: -------------------------------------------------------------------------------- 1 | ../../../../node_modules/typescript/lib/ -------------------------------------------------------------------------------- /test/integration/notfound-eval.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert'); 2 | const childProcess = require('child_process'); 3 | const path = require('path'); 4 | 5 | (function main() { 6 | if (process.env.CHILD !== 'notfound-eval') { 7 | const cp = childProcess.fork(__filename, [], { 8 | stdio: 'inherit', 9 | env: Object.assign({}, process.env, { 10 | CHILD: 'notfound-eval', 11 | NODE_PATH: path.join(process.cwd(), 'test/integration/node-path') 12 | }) 13 | }); 14 | cp.on('exit', (code) => { 15 | if (code == null) { 16 | code = 1; 17 | } 18 | process.exit(code); 19 | }) 20 | return; 21 | } 22 | const foo = require('foo'); 23 | assert.strictEqual(foo, 'foo'); 24 | })(); 25 | -------------------------------------------------------------------------------- /test/integration/npm.js: -------------------------------------------------------------------------------- 1 | const npm = require('npm'); 2 | const install = require('npm/lib/install'); 3 | const rimraf = require('rimraf'); 4 | 5 | npm.load((err) => { 6 | if (err) { 7 | throw err; 8 | } 9 | npm.config.set('audit', false); 10 | npm.config.set('package-lock', false); 11 | npm.config.set('progress', false); 12 | if (process.env.NPM_REGISTRY_URL) { 13 | npm.config.set('registry', process.env.NPM_REGISTRY_URL); 14 | } 15 | const args = [`lodash@4.1.17`]; 16 | install('./asdf', args, () => {}); 17 | rimraf.sync('./asdf'); 18 | }); 19 | -------------------------------------------------------------------------------- /test/integration/oracledb.js: -------------------------------------------------------------------------------- 1 | require('oracledb'); 2 | -------------------------------------------------------------------------------- /test/integration/passport.js: -------------------------------------------------------------------------------- 1 | require('passport'); 2 | require('passport-google-oauth'); 3 | 4 | -------------------------------------------------------------------------------- /test/integration/path-platform.js: -------------------------------------------------------------------------------- 1 | require('path-platform'); 2 | -------------------------------------------------------------------------------- /test/integration/pdfkit.js: -------------------------------------------------------------------------------- 1 | const fs = require("fs"); 2 | const PDFDocument = require("pdfkit"); 3 | 4 | const doc = new PDFDocument(); 5 | doc.fontSize(15).text("Hi there", 50, 50); 6 | doc.end(); 7 | -------------------------------------------------------------------------------- /test/integration/pg.js: -------------------------------------------------------------------------------- 1 | const { Client } = require("pg"); 2 | const client = new Client(); 3 | -------------------------------------------------------------------------------- /test/integration/pug.js: -------------------------------------------------------------------------------- 1 | const pug = require('pug'); 2 | pug.compile('string of pug'); 3 | -------------------------------------------------------------------------------- /test/integration/react.js: -------------------------------------------------------------------------------- 1 | const React = require("react"); 2 | const { renderToString } = require("react-dom/server"); 3 | 4 | const html = renderToString(React.createElement("h1")); 5 | if (html !== '

') { 6 | throw new Error("Bad react SSR: " + html); 7 | } 8 | -------------------------------------------------------------------------------- /test/integration/redis.js: -------------------------------------------------------------------------------- 1 | const redis = require('redis'); 2 | 3 | redis.add_command('test'); 4 | -------------------------------------------------------------------------------- /test/integration/request-ts.ts: -------------------------------------------------------------------------------- 1 | import { get } from "request"; 2 | 3 | (async () => { 4 | await new Promise((resolve, reject) => { 5 | get("https://example.vercel.sh", { json: false }, (err, res) => { 6 | if (err) return reject(err); 7 | if (res.statusCode !== 200) { 8 | return reject(new Error(`Bad status: ${res.statusCode}`)); 9 | } 10 | resolve(true); 11 | }); 12 | }); 13 | })(); 14 | -------------------------------------------------------------------------------- /test/integration/request.js: -------------------------------------------------------------------------------- 1 | const request = require("request"); 2 | 3 | (async () => { 4 | await new Promise((resolve, reject) => { 5 | request.get("https://example.vercel.sh", { json: false }, (err, res) => { 6 | if (err) return reject(err); 7 | if (res.statusCode !== 200) { 8 | return reject(new Error(`Bad status: ${res.statusCode}`)); 9 | } 10 | resolve(true); 11 | }); 12 | }); 13 | })(); 14 | -------------------------------------------------------------------------------- /test/integration/rxjs.js: -------------------------------------------------------------------------------- 1 | const { Observable, Subject, ReplaySubject, from, of, range } = require("rxjs"); 2 | const { map, filter, switchMap } = require("rxjs/operators"); 3 | 4 | range(1, 200) 5 | .pipe( 6 | filter(x => x % 2 === 1), 7 | map(x => x + x) 8 | ) 9 | .subscribe(x => x); 10 | -------------------------------------------------------------------------------- /test/integration/saslprep.js: -------------------------------------------------------------------------------- 1 | const saslprep = require("saslprep"); 2 | 3 | saslprep("password\u00AD"); 4 | -------------------------------------------------------------------------------- /test/integration/sentry.js: -------------------------------------------------------------------------------- 1 | const sentry = require('@sentry/node'); 2 | -------------------------------------------------------------------------------- /test/integration/sequelize.js: -------------------------------------------------------------------------------- 1 | const Sequelize = require('sequelize'); 2 | 3 | const db = new Sequelize({ 4 | dialect: 'mariadb', 5 | dialectModule: require('mariadb') 6 | }); -------------------------------------------------------------------------------- /test/integration/sharp.js: -------------------------------------------------------------------------------- 1 | import sharp from 'sharp'; 2 | 3 | const roundedCorners = Buffer.from( 4 | '' 5 | ); 6 | 7 | sharp() 8 | .resize(200, 200) 9 | .composite([{ 10 | input: roundedCorners, 11 | blend: 'dest-in' 12 | }]) 13 | .png(); 14 | -------------------------------------------------------------------------------- /test/integration/slack.js: -------------------------------------------------------------------------------- 1 | const { WebClient } = require('@slack/web-api'); 2 | 3 | const slackWebClient = new WebClient({ 4 | token: 'xxxx-xxxxxxxxx-xxxx', 5 | }); 6 | -------------------------------------------------------------------------------- /test/integration/socket.io.js: -------------------------------------------------------------------------------- 1 | const http = require('http') 2 | const io = require('socket.io') 3 | const opts = { port: 3000 } 4 | const server = http.createServer((req, res) => {}); 5 | server.listen(opts.port) 6 | setTimeout(() => { 7 | process.exit(); 8 | }, 100); -------------------------------------------------------------------------------- /test/integration/stack-trace.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert'); 2 | const childProcess = require('child_process'); 3 | const path = require('path'); 4 | 5 | (function main() { 6 | if (process.env.CHILD !== 'stack-trace') { 7 | const cp = childProcess.fork(__filename, [], { 8 | stdio: 'pipe', 9 | env: Object.assign({}, process.env, { 10 | CHILD: 'stack-trace', 11 | }) 12 | }); 13 | let stdoutBuffers = [] 14 | cp.stdout.on('data', data => stdoutBuffers.push(data)); 15 | 16 | cp.on('exit', (code) => { 17 | const stdout = Buffer.concat(stdoutBuffers).toString('utf8') 18 | if (code !== 0) { 19 | process.stderr.write(stdout); 20 | return process.exit(1); 21 | } 22 | assert(stdout.match(/evalmachine./) == null); 23 | assert(stdout.match(path.basename(__filename)) != null); 24 | }); 25 | return; 26 | } 27 | 28 | console.log(new Error('foo')); 29 | })(); 30 | -------------------------------------------------------------------------------- /test/integration/strict-module-exception-handling.js: -------------------------------------------------------------------------------- 1 | try { 2 | require('./include/throwing') 3 | } catch (err) {} 4 | 5 | let threw = false 6 | try { 7 | require('./include/throwing') 8 | } catch (err) { 9 | threw = true 10 | } 11 | 12 | if (!threw) { 13 | process.exit(1) 14 | } 15 | -------------------------------------------------------------------------------- /test/integration/stripe.js: -------------------------------------------------------------------------------- 1 | const stripe = require('stripe'); 2 | -------------------------------------------------------------------------------- /test/integration/test.ts: -------------------------------------------------------------------------------- 1 | var p: boolean = false; 2 | console.log(p); 3 | -------------------------------------------------------------------------------- /test/integration/tiny-json-http.js: -------------------------------------------------------------------------------- 1 | const tiny = require('tiny-json-http'); 2 | -------------------------------------------------------------------------------- /test/integration/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2015" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /test/integration/twilio.js: -------------------------------------------------------------------------------- 1 | const twilio = require("twilio"); 2 | try { 3 | twilio(); 4 | } catch (err) { 5 | if (!/username is required/.test(err.message)) { 6 | throw err; 7 | } 8 | } 9 | 10 | 11 | -------------------------------------------------------------------------------- /test/integration/vm2.js: -------------------------------------------------------------------------------- 1 | const {VM} = require('vm2'); 2 | new VM().run('console.log("HELLO WORLD")'); -------------------------------------------------------------------------------- /test/integration/vue.js: -------------------------------------------------------------------------------- 1 | const Vue = require("vue"); 2 | const renderer = require("vue-server-renderer").createRenderer(); 3 | 4 | const app = new Vue({ 5 | data: () => ({ date: Date.now() }), 6 | template: `
Hello World {{ date }}
` 7 | }); 8 | renderer.renderToString(app); 9 | -------------------------------------------------------------------------------- /test/integration/when.js: -------------------------------------------------------------------------------- 1 | var when = require('when'); 2 | 3 | var deferred = when.defer(); 4 | -------------------------------------------------------------------------------- /test/unit.test.js: -------------------------------------------------------------------------------- 1 | const fs = require("fs"); 2 | const coverage = global.coverage; 3 | const ncc = coverage ? require("../src/index") : require("../"); 4 | 5 | jest.setTimeout(20000); 6 | 7 | function normalizeForWindows(str) { 8 | return str.trim().replace(/\\r/g, '').replace(/\r/g, '').replace(/;+/g, ';'); 9 | } 10 | 11 | for (const unitTest of fs.readdirSync(`${__dirname}/unit`)) { 12 | if (process.platform === 'win32' && unitTest.includes('shebang')) { 13 | continue; 14 | } 15 | it(`should generate correct output for ${unitTest}`, async () => { 16 | const testDir = `${__dirname}/unit/${unitTest}`; 17 | const expected = normalizeForWindows(fs.readFileSync(`${testDir}/output${coverage ? '-coverage' : ''}.js`, 'utf8')); 18 | let expectedSourceMap; 19 | try { 20 | expectedSourceMap = normalizeForWindows(fs.readFileSync(`${testDir}/output${coverage ? '-coverage' : ''}.js.map`, 'utf8')); 21 | } catch (_) {} 22 | 23 | let opts; 24 | try { 25 | opts = fs.readFileSync(`${testDir}/opt.json`, 'utf8'); 26 | opts = JSON.parse(opts); 27 | } catch (_) {} 28 | 29 | // set env variable so tsconfig-paths can find the config 30 | process.env.TS_NODE_PROJECT = `${testDir}/tsconfig.json`; 31 | // find the name of the input file (e.g input.ts) 32 | const inputFile = fs.readdirSync(testDir).find(file => file.includes("input")); 33 | await ncc(`${testDir}/${inputFile}`, Object.assign({ 34 | assetBuilds: true, 35 | transpileOnly: true, 36 | customEmit (path) { 37 | if (path.endsWith('test.json')) 38 | return false; 39 | }, 40 | externals: { 41 | 'piscina': 'piscina', 42 | 'externaltest': 'externalmapped', 43 | '/\\w+-regex/': 'regexexternal', 44 | '/external-replace(/.*)/': 'external-replace/replaced$1' 45 | } 46 | }, opts)).then( 47 | async ({ code, assets, map }) => { 48 | if (unitTest.startsWith('bundle-subasset')) { 49 | expect(assets['pi-bridge.js']).toBeDefined(); 50 | expect(assets['pi-bridge.js'].source.toString()).toContain('Math.PI'); 51 | } 52 | if (unitTest.includes('sourcemap-register')) { 53 | expect(assets['sourcemap-register.js']).toBeDefined() 54 | expect(assets['sourcemap-register.js'].source.toString()).toEqual(fs.readFileSync(__dirname + '/../src/sourcemap-register.js.cache.js').toString()) 55 | } 56 | if (unitTest.includes('minify') && !unitTest.includes('minify-err')) { 57 | expect(assets['index.js.map']).toBeDefined() 58 | } 59 | const actual = normalizeForWindows(code); 60 | try { 61 | expect(actual).toBe(expected); 62 | } catch (e) { 63 | // useful for updating fixtures 64 | fs.writeFileSync(`${testDir}/actual.js`, actual); 65 | throw e; 66 | } 67 | 68 | if (map) { 69 | const actualSourceMap = normalizeForWindows(map); 70 | try { 71 | expect(actualSourceMap).toBe(expectedSourceMap); 72 | } catch (e) { 73 | // useful for updating fixtures 74 | fs.writeFileSync(`${testDir}/actual.js.map`, actualSourceMap); 75 | throw e; 76 | } 77 | } 78 | } 79 | ) 80 | }); 81 | } 82 | -------------------------------------------------------------------------------- /test/unit/browser-mainfield/input.js: -------------------------------------------------------------------------------- 1 | import crypto from 'crypto-browser'; 2 | console.log('main file') -------------------------------------------------------------------------------- /test/unit/browser-mainfield/node_modules/crypto-browser/browser.js: -------------------------------------------------------------------------------- 1 | console.log('browser file!!') -------------------------------------------------------------------------------- /test/unit/browser-mainfield/node_modules/crypto-browser/node.js: -------------------------------------------------------------------------------- 1 | console.log('node file!!') -------------------------------------------------------------------------------- /test/unit/browser-mainfield/node_modules/crypto-browser/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "crypto", 3 | "main": "./node.js", 4 | "browser": "./browser.js" 5 | } -------------------------------------------------------------------------------- /test/unit/browser-mainfield/opt.json: -------------------------------------------------------------------------------- 1 | { 2 | "mainFields": ["browser", "main"] 3 | } -------------------------------------------------------------------------------- /test/unit/browser-mainfield/output-coverage.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ var __webpack_modules__ = ({ 3 | 4 | /***/ 854: 5 | /***/ (() => { 6 | 7 | console.log('browser file!!') 8 | 9 | /***/ }) 10 | 11 | /******/ }); 12 | /************************************************************************/ 13 | /******/ // The module cache 14 | /******/ var __webpack_module_cache__ = {}; 15 | /******/ 16 | /******/ // The require function 17 | /******/ function __nccwpck_require__(moduleId) { 18 | /******/ // Check if module is in cache 19 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; 20 | /******/ if (cachedModule !== undefined) { 21 | /******/ return cachedModule.exports; 22 | /******/ } 23 | /******/ // Create a new module (and put it into the cache) 24 | /******/ var module = __webpack_module_cache__[moduleId] = { 25 | /******/ // no module.id needed 26 | /******/ // no module.loaded needed 27 | /******/ exports: {} 28 | /******/ }; 29 | /******/ 30 | /******/ // Execute the module function 31 | /******/ var threw = true; 32 | /******/ try { 33 | /******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__); 34 | /******/ threw = false; 35 | /******/ } finally { 36 | /******/ if(threw) delete __webpack_module_cache__[moduleId]; 37 | /******/ } 38 | /******/ 39 | /******/ // Return the exports of the module 40 | /******/ return module.exports; 41 | /******/ } 42 | /******/ 43 | /************************************************************************/ 44 | /******/ /* webpack/runtime/compat get default export */ 45 | /******/ (() => { 46 | /******/ // getDefaultExport function for compatibility with non-harmony modules 47 | /******/ __nccwpck_require__.n = (module) => { 48 | /******/ var getter = module && module.__esModule ? 49 | /******/ () => (module['default']) : 50 | /******/ () => (module); 51 | /******/ __nccwpck_require__.d(getter, { a: getter }); 52 | /******/ return getter; 53 | /******/ }; 54 | /******/ })(); 55 | /******/ 56 | /******/ /* webpack/runtime/define property getters */ 57 | /******/ (() => { 58 | /******/ // define getter functions for harmony exports 59 | /******/ __nccwpck_require__.d = (exports, definition) => { 60 | /******/ for(var key in definition) { 61 | /******/ if(__nccwpck_require__.o(definition, key) && !__nccwpck_require__.o(exports, key)) { 62 | /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); 63 | /******/ } 64 | /******/ } 65 | /******/ }; 66 | /******/ })(); 67 | /******/ 68 | /******/ /* webpack/runtime/hasOwnProperty shorthand */ 69 | /******/ (() => { 70 | /******/ __nccwpck_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) 71 | /******/ })(); 72 | /******/ 73 | /******/ /* webpack/runtime/make namespace object */ 74 | /******/ (() => { 75 | /******/ // define __esModule on exports 76 | /******/ __nccwpck_require__.r = (exports) => { 77 | /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 78 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 79 | /******/ } 80 | /******/ Object.defineProperty(exports, '__esModule', { value: true }); 81 | /******/ }; 82 | /******/ })(); 83 | /******/ 84 | /******/ /* webpack/runtime/compat */ 85 | /******/ 86 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; 87 | /******/ 88 | /************************************************************************/ 89 | var __webpack_exports__ = {}; 90 | // This entry need to be wrapped in an IIFE because it need to be in strict mode. 91 | (() => { 92 | "use strict"; 93 | __nccwpck_require__.r(__webpack_exports__); 94 | /* harmony import */ var crypto_browser__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(854); 95 | /* harmony import */ var crypto_browser__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__nccwpck_require__.n(crypto_browser__WEBPACK_IMPORTED_MODULE_0__); 96 | 97 | console.log('main file') 98 | })(); 99 | 100 | module.exports = __webpack_exports__; 101 | /******/ })() 102 | ; -------------------------------------------------------------------------------- /test/unit/browser-mainfield/output.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ var __webpack_modules__ = ({ 3 | 4 | /***/ 267: 5 | /***/ (() => { 6 | 7 | console.log('browser file!!') 8 | 9 | /***/ }) 10 | 11 | /******/ }); 12 | /************************************************************************/ 13 | /******/ // The module cache 14 | /******/ var __webpack_module_cache__ = {}; 15 | /******/ 16 | /******/ // The require function 17 | /******/ function __nccwpck_require__(moduleId) { 18 | /******/ // Check if module is in cache 19 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; 20 | /******/ if (cachedModule !== undefined) { 21 | /******/ return cachedModule.exports; 22 | /******/ } 23 | /******/ // Create a new module (and put it into the cache) 24 | /******/ var module = __webpack_module_cache__[moduleId] = { 25 | /******/ // no module.id needed 26 | /******/ // no module.loaded needed 27 | /******/ exports: {} 28 | /******/ }; 29 | /******/ 30 | /******/ // Execute the module function 31 | /******/ var threw = true; 32 | /******/ try { 33 | /******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__); 34 | /******/ threw = false; 35 | /******/ } finally { 36 | /******/ if(threw) delete __webpack_module_cache__[moduleId]; 37 | /******/ } 38 | /******/ 39 | /******/ // Return the exports of the module 40 | /******/ return module.exports; 41 | /******/ } 42 | /******/ 43 | /************************************************************************/ 44 | /******/ /* webpack/runtime/compat get default export */ 45 | /******/ (() => { 46 | /******/ // getDefaultExport function for compatibility with non-harmony modules 47 | /******/ __nccwpck_require__.n = (module) => { 48 | /******/ var getter = module && module.__esModule ? 49 | /******/ () => (module['default']) : 50 | /******/ () => (module); 51 | /******/ __nccwpck_require__.d(getter, { a: getter }); 52 | /******/ return getter; 53 | /******/ }; 54 | /******/ })(); 55 | /******/ 56 | /******/ /* webpack/runtime/define property getters */ 57 | /******/ (() => { 58 | /******/ // define getter functions for harmony exports 59 | /******/ __nccwpck_require__.d = (exports, definition) => { 60 | /******/ for(var key in definition) { 61 | /******/ if(__nccwpck_require__.o(definition, key) && !__nccwpck_require__.o(exports, key)) { 62 | /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); 63 | /******/ } 64 | /******/ } 65 | /******/ }; 66 | /******/ })(); 67 | /******/ 68 | /******/ /* webpack/runtime/hasOwnProperty shorthand */ 69 | /******/ (() => { 70 | /******/ __nccwpck_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) 71 | /******/ })(); 72 | /******/ 73 | /******/ /* webpack/runtime/make namespace object */ 74 | /******/ (() => { 75 | /******/ // define __esModule on exports 76 | /******/ __nccwpck_require__.r = (exports) => { 77 | /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 78 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 79 | /******/ } 80 | /******/ Object.defineProperty(exports, '__esModule', { value: true }); 81 | /******/ }; 82 | /******/ })(); 83 | /******/ 84 | /******/ /* webpack/runtime/compat */ 85 | /******/ 86 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; 87 | /******/ 88 | /************************************************************************/ 89 | var __webpack_exports__ = {}; 90 | // This entry need to be wrapped in an IIFE because it need to be in strict mode. 91 | (() => { 92 | "use strict"; 93 | __nccwpck_require__.r(__webpack_exports__); 94 | /* harmony import */ var crypto_browser__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(267); 95 | /* harmony import */ var crypto_browser__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__nccwpck_require__.n(crypto_browser__WEBPACK_IMPORTED_MODULE_0__); 96 | 97 | console.log('main file') 98 | })(); 99 | 100 | module.exports = __webpack_exports__; 101 | /******/ })() 102 | ; -------------------------------------------------------------------------------- /test/unit/bundle-subasset/input.js: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | 3 | const file = path.resolve(__dirname, './pi-bridge.js'); 4 | 5 | const obscureRequire = eval(`function obscureRequire (file) { 6 | require(file); 7 | }`); 8 | 9 | console.log(obscureRequire(file)); 10 | -------------------------------------------------------------------------------- /test/unit/bundle-subasset/output-coverage.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ "use strict"; 3 | /******/ var __webpack_modules__ = ({ 4 | 5 | /***/ 928: 6 | /***/ ((module) => { 7 | 8 | module.exports = require("path"); 9 | 10 | /***/ }) 11 | 12 | /******/ }); 13 | /************************************************************************/ 14 | /******/ // The module cache 15 | /******/ var __webpack_module_cache__ = {}; 16 | /******/ 17 | /******/ // The require function 18 | /******/ function __nccwpck_require__(moduleId) { 19 | /******/ // Check if module is in cache 20 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; 21 | /******/ if (cachedModule !== undefined) { 22 | /******/ return cachedModule.exports; 23 | /******/ } 24 | /******/ // Create a new module (and put it into the cache) 25 | /******/ var module = __webpack_module_cache__[moduleId] = { 26 | /******/ // no module.id needed 27 | /******/ // no module.loaded needed 28 | /******/ exports: {} 29 | /******/ }; 30 | /******/ 31 | /******/ // Execute the module function 32 | /******/ var threw = true; 33 | /******/ try { 34 | /******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__); 35 | /******/ threw = false; 36 | /******/ } finally { 37 | /******/ if(threw) delete __webpack_module_cache__[moduleId]; 38 | /******/ } 39 | /******/ 40 | /******/ // Return the exports of the module 41 | /******/ return module.exports; 42 | /******/ } 43 | /******/ 44 | /************************************************************************/ 45 | /******/ /* webpack/runtime/compat get default export */ 46 | /******/ (() => { 47 | /******/ // getDefaultExport function for compatibility with non-harmony modules 48 | /******/ __nccwpck_require__.n = (module) => { 49 | /******/ var getter = module && module.__esModule ? 50 | /******/ () => (module['default']) : 51 | /******/ () => (module); 52 | /******/ __nccwpck_require__.d(getter, { a: getter }); 53 | /******/ return getter; 54 | /******/ }; 55 | /******/ })(); 56 | /******/ 57 | /******/ /* webpack/runtime/define property getters */ 58 | /******/ (() => { 59 | /******/ // define getter functions for harmony exports 60 | /******/ __nccwpck_require__.d = (exports, definition) => { 61 | /******/ for(var key in definition) { 62 | /******/ if(__nccwpck_require__.o(definition, key) && !__nccwpck_require__.o(exports, key)) { 63 | /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); 64 | /******/ } 65 | /******/ } 66 | /******/ }; 67 | /******/ })(); 68 | /******/ 69 | /******/ /* webpack/runtime/hasOwnProperty shorthand */ 70 | /******/ (() => { 71 | /******/ __nccwpck_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) 72 | /******/ })(); 73 | /******/ 74 | /******/ /* webpack/runtime/make namespace object */ 75 | /******/ (() => { 76 | /******/ // define __esModule on exports 77 | /******/ __nccwpck_require__.r = (exports) => { 78 | /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 79 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 80 | /******/ } 81 | /******/ Object.defineProperty(exports, '__esModule', { value: true }); 82 | /******/ }; 83 | /******/ })(); 84 | /******/ 85 | /******/ /* webpack/runtime/compat */ 86 | /******/ 87 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; 88 | /******/ 89 | /************************************************************************/ 90 | var __webpack_exports__ = {}; 91 | __nccwpck_require__.r(__webpack_exports__); 92 | /* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(928); 93 | /* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__nccwpck_require__.n(path__WEBPACK_IMPORTED_MODULE_0__); 94 | 95 | 96 | const file = __nccwpck_require__.ab + "pi-bridge.js"; 97 | 98 | const obscureRequire = eval(`function obscureRequire (file) { 99 | require(file); 100 | }`); 101 | 102 | console.log(obscureRequire(__nccwpck_require__.ab + "pi-bridge.js")); 103 | 104 | module.exports = __webpack_exports__; 105 | /******/ })() 106 | ; -------------------------------------------------------------------------------- /test/unit/bundle-subasset/output.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ "use strict"; 3 | /******/ var __webpack_modules__ = ({ 4 | 5 | /***/ 928: 6 | /***/ ((module) => { 7 | 8 | module.exports = require("path"); 9 | 10 | /***/ }) 11 | 12 | /******/ }); 13 | /************************************************************************/ 14 | /******/ // The module cache 15 | /******/ var __webpack_module_cache__ = {}; 16 | /******/ 17 | /******/ // The require function 18 | /******/ function __nccwpck_require__(moduleId) { 19 | /******/ // Check if module is in cache 20 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; 21 | /******/ if (cachedModule !== undefined) { 22 | /******/ return cachedModule.exports; 23 | /******/ } 24 | /******/ // Create a new module (and put it into the cache) 25 | /******/ var module = __webpack_module_cache__[moduleId] = { 26 | /******/ // no module.id needed 27 | /******/ // no module.loaded needed 28 | /******/ exports: {} 29 | /******/ }; 30 | /******/ 31 | /******/ // Execute the module function 32 | /******/ var threw = true; 33 | /******/ try { 34 | /******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__); 35 | /******/ threw = false; 36 | /******/ } finally { 37 | /******/ if(threw) delete __webpack_module_cache__[moduleId]; 38 | /******/ } 39 | /******/ 40 | /******/ // Return the exports of the module 41 | /******/ return module.exports; 42 | /******/ } 43 | /******/ 44 | /************************************************************************/ 45 | /******/ /* webpack/runtime/compat get default export */ 46 | /******/ (() => { 47 | /******/ // getDefaultExport function for compatibility with non-harmony modules 48 | /******/ __nccwpck_require__.n = (module) => { 49 | /******/ var getter = module && module.__esModule ? 50 | /******/ () => (module['default']) : 51 | /******/ () => (module); 52 | /******/ __nccwpck_require__.d(getter, { a: getter }); 53 | /******/ return getter; 54 | /******/ }; 55 | /******/ })(); 56 | /******/ 57 | /******/ /* webpack/runtime/define property getters */ 58 | /******/ (() => { 59 | /******/ // define getter functions for harmony exports 60 | /******/ __nccwpck_require__.d = (exports, definition) => { 61 | /******/ for(var key in definition) { 62 | /******/ if(__nccwpck_require__.o(definition, key) && !__nccwpck_require__.o(exports, key)) { 63 | /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); 64 | /******/ } 65 | /******/ } 66 | /******/ }; 67 | /******/ })(); 68 | /******/ 69 | /******/ /* webpack/runtime/hasOwnProperty shorthand */ 70 | /******/ (() => { 71 | /******/ __nccwpck_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) 72 | /******/ })(); 73 | /******/ 74 | /******/ /* webpack/runtime/make namespace object */ 75 | /******/ (() => { 76 | /******/ // define __esModule on exports 77 | /******/ __nccwpck_require__.r = (exports) => { 78 | /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 79 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 80 | /******/ } 81 | /******/ Object.defineProperty(exports, '__esModule', { value: true }); 82 | /******/ }; 83 | /******/ })(); 84 | /******/ 85 | /******/ /* webpack/runtime/compat */ 86 | /******/ 87 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; 88 | /******/ 89 | /************************************************************************/ 90 | var __webpack_exports__ = {}; 91 | __nccwpck_require__.r(__webpack_exports__); 92 | /* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(928); 93 | /* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__nccwpck_require__.n(path__WEBPACK_IMPORTED_MODULE_0__); 94 | 95 | 96 | const file = __nccwpck_require__.ab + "pi-bridge.js"; 97 | 98 | const obscureRequire = eval(`function obscureRequire (file) { 99 | require(file); 100 | }`); 101 | 102 | console.log(obscureRequire(__nccwpck_require__.ab + "pi-bridge.js")); 103 | 104 | module.exports = __webpack_exports__; 105 | /******/ })() 106 | ; -------------------------------------------------------------------------------- /test/unit/bundle-subasset/pi-bridge.js: -------------------------------------------------------------------------------- 1 | import Pi from './pi'; 2 | export default Pi; 3 | -------------------------------------------------------------------------------- /test/unit/bundle-subasset/pi.ts: -------------------------------------------------------------------------------- 1 | export default function Pi(num: number) { 2 | return Math.PI * num; 3 | } 4 | -------------------------------------------------------------------------------- /test/unit/bundle-subasset/tsconfig.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/unit/bundle-subasset2/input.ts: -------------------------------------------------------------------------------- 1 | import Piscina from 'piscina'; 2 | import * as path from 'path'; 3 | 4 | const piscina = new Piscina({ 5 | filename: path.resolve(__dirname, './pi-bridge.js'), 6 | }); 7 | 8 | (async function() { 9 | const result = await piscina.runTask(2); 10 | console.log(result); 11 | })(); 12 | -------------------------------------------------------------------------------- /test/unit/bundle-subasset2/output-coverage.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ "use strict"; 3 | /******/ var __webpack_modules__ = ({}); 4 | /************************************************************************/ 5 | /******/ // The module cache 6 | /******/ var __webpack_module_cache__ = {}; 7 | /******/ 8 | /******/ // The require function 9 | /******/ function __nccwpck_require__(moduleId) { 10 | /******/ // Check if module is in cache 11 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; 12 | /******/ if (cachedModule !== undefined) { 13 | /******/ return cachedModule.exports; 14 | /******/ } 15 | /******/ // Create a new module (and put it into the cache) 16 | /******/ var module = __webpack_module_cache__[moduleId] = { 17 | /******/ // no module.id needed 18 | /******/ // no module.loaded needed 19 | /******/ exports: {} 20 | /******/ }; 21 | /******/ 22 | /******/ // Execute the module function 23 | /******/ var threw = true; 24 | /******/ try { 25 | /******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__); 26 | /******/ threw = false; 27 | /******/ } finally { 28 | /******/ if(threw) delete __webpack_module_cache__[moduleId]; 29 | /******/ } 30 | /******/ 31 | /******/ // Return the exports of the module 32 | /******/ return module.exports; 33 | /******/ } 34 | /******/ 35 | /************************************************************************/ 36 | /******/ /* webpack/runtime/compat get default export */ 37 | /******/ (() => { 38 | /******/ // getDefaultExport function for compatibility with non-harmony modules 39 | /******/ __nccwpck_require__.n = (module) => { 40 | /******/ var getter = module && module.__esModule ? 41 | /******/ () => (module['default']) : 42 | /******/ () => (module); 43 | /******/ __nccwpck_require__.d(getter, { a: getter }); 44 | /******/ return getter; 45 | /******/ }; 46 | /******/ })(); 47 | /******/ 48 | /******/ /* webpack/runtime/define property getters */ 49 | /******/ (() => { 50 | /******/ // define getter functions for harmony exports 51 | /******/ __nccwpck_require__.d = (exports, definition) => { 52 | /******/ for(var key in definition) { 53 | /******/ if(__nccwpck_require__.o(definition, key) && !__nccwpck_require__.o(exports, key)) { 54 | /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); 55 | /******/ } 56 | /******/ } 57 | /******/ }; 58 | /******/ })(); 59 | /******/ 60 | /******/ /* webpack/runtime/hasOwnProperty shorthand */ 61 | /******/ (() => { 62 | /******/ __nccwpck_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) 63 | /******/ })(); 64 | /******/ 65 | /******/ /* webpack/runtime/compat */ 66 | /******/ 67 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; 68 | /******/ 69 | /************************************************************************/ 70 | var __webpack_exports__ = {}; 71 | 72 | ;// CONCATENATED MODULE: external "piscina" 73 | const external_piscina_namespaceObject = require("piscina"); 74 | var external_piscina_default = /*#__PURE__*/__nccwpck_require__.n(external_piscina_namespaceObject); 75 | ;// CONCATENATED MODULE: external "path" 76 | const external_path_namespaceObject = require("path"); 77 | ;// CONCATENATED MODULE: ./test/unit/bundle-subasset2/input.ts 78 | 79 | 80 | const piscina = new (external_piscina_default())({ 81 | filename: __nccwpck_require__.ab + "pi-bridge.js", 82 | }); 83 | (async function () { 84 | const result = await piscina.runTask(2); 85 | console.log(result); 86 | })(); 87 | 88 | module.exports = __webpack_exports__; 89 | /******/ })() 90 | ; -------------------------------------------------------------------------------- /test/unit/bundle-subasset2/output.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ "use strict"; 3 | /******/ var __webpack_modules__ = ({}); 4 | /************************************************************************/ 5 | /******/ // The module cache 6 | /******/ var __webpack_module_cache__ = {}; 7 | /******/ 8 | /******/ // The require function 9 | /******/ function __nccwpck_require__(moduleId) { 10 | /******/ // Check if module is in cache 11 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; 12 | /******/ if (cachedModule !== undefined) { 13 | /******/ return cachedModule.exports; 14 | /******/ } 15 | /******/ // Create a new module (and put it into the cache) 16 | /******/ var module = __webpack_module_cache__[moduleId] = { 17 | /******/ // no module.id needed 18 | /******/ // no module.loaded needed 19 | /******/ exports: {} 20 | /******/ }; 21 | /******/ 22 | /******/ // Execute the module function 23 | /******/ var threw = true; 24 | /******/ try { 25 | /******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__); 26 | /******/ threw = false; 27 | /******/ } finally { 28 | /******/ if(threw) delete __webpack_module_cache__[moduleId]; 29 | /******/ } 30 | /******/ 31 | /******/ // Return the exports of the module 32 | /******/ return module.exports; 33 | /******/ } 34 | /******/ 35 | /************************************************************************/ 36 | /******/ /* webpack/runtime/compat get default export */ 37 | /******/ (() => { 38 | /******/ // getDefaultExport function for compatibility with non-harmony modules 39 | /******/ __nccwpck_require__.n = (module) => { 40 | /******/ var getter = module && module.__esModule ? 41 | /******/ () => (module['default']) : 42 | /******/ () => (module); 43 | /******/ __nccwpck_require__.d(getter, { a: getter }); 44 | /******/ return getter; 45 | /******/ }; 46 | /******/ })(); 47 | /******/ 48 | /******/ /* webpack/runtime/define property getters */ 49 | /******/ (() => { 50 | /******/ // define getter functions for harmony exports 51 | /******/ __nccwpck_require__.d = (exports, definition) => { 52 | /******/ for(var key in definition) { 53 | /******/ if(__nccwpck_require__.o(definition, key) && !__nccwpck_require__.o(exports, key)) { 54 | /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); 55 | /******/ } 56 | /******/ } 57 | /******/ }; 58 | /******/ })(); 59 | /******/ 60 | /******/ /* webpack/runtime/hasOwnProperty shorthand */ 61 | /******/ (() => { 62 | /******/ __nccwpck_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) 63 | /******/ })(); 64 | /******/ 65 | /******/ /* webpack/runtime/compat */ 66 | /******/ 67 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; 68 | /******/ 69 | /************************************************************************/ 70 | var __webpack_exports__ = {}; 71 | 72 | ;// CONCATENATED MODULE: external "piscina" 73 | const external_piscina_namespaceObject = require("piscina"); 74 | var external_piscina_default = /*#__PURE__*/__nccwpck_require__.n(external_piscina_namespaceObject); 75 | ;// CONCATENATED MODULE: external "path" 76 | const external_path_namespaceObject = require("path"); 77 | ;// CONCATENATED MODULE: ./test/unit/bundle-subasset2/input.ts 78 | 79 | 80 | const piscina = new (external_piscina_default())({ 81 | filename: __nccwpck_require__.ab + "pi-bridge.js", 82 | }); 83 | (async function () { 84 | const result = await piscina.runTask(2); 85 | console.log(result); 86 | })(); 87 | 88 | module.exports = __webpack_exports__; 89 | /******/ })() 90 | ; -------------------------------------------------------------------------------- /test/unit/bundle-subasset2/pi-bridge.js: -------------------------------------------------------------------------------- 1 | import Pi from './pi'; 2 | export default Pi; 3 | -------------------------------------------------------------------------------- /test/unit/bundle-subasset2/pi.ts: -------------------------------------------------------------------------------- 1 | export default function Pi(num: number) { 2 | return Math.PI * num; 3 | } 4 | -------------------------------------------------------------------------------- /test/unit/bundle-subasset2/tsconfig.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/unit/custom-emit/input.js: -------------------------------------------------------------------------------- 1 | const { readFileSync } = require('fs'); 2 | console.log(readFileSync(__dirname + './test.json')); 3 | 4 | -------------------------------------------------------------------------------- /test/unit/custom-emit/output-coverage.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ var __webpack_modules__ = ({ 3 | 4 | /***/ 896: 5 | /***/ ((module) => { 6 | 7 | "use strict"; 8 | module.exports = require("fs"); 9 | 10 | /***/ }) 11 | 12 | /******/ }); 13 | /************************************************************************/ 14 | /******/ // The module cache 15 | /******/ var __webpack_module_cache__ = {}; 16 | /******/ 17 | /******/ // The require function 18 | /******/ function __nccwpck_require__(moduleId) { 19 | /******/ // Check if module is in cache 20 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; 21 | /******/ if (cachedModule !== undefined) { 22 | /******/ return cachedModule.exports; 23 | /******/ } 24 | /******/ // Create a new module (and put it into the cache) 25 | /******/ var module = __webpack_module_cache__[moduleId] = { 26 | /******/ // no module.id needed 27 | /******/ // no module.loaded needed 28 | /******/ exports: {} 29 | /******/ }; 30 | /******/ 31 | /******/ // Execute the module function 32 | /******/ var threw = true; 33 | /******/ try { 34 | /******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__); 35 | /******/ threw = false; 36 | /******/ } finally { 37 | /******/ if(threw) delete __webpack_module_cache__[moduleId]; 38 | /******/ } 39 | /******/ 40 | /******/ // Return the exports of the module 41 | /******/ return module.exports; 42 | /******/ } 43 | /******/ 44 | /************************************************************************/ 45 | /******/ /* webpack/runtime/compat */ 46 | /******/ 47 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; 48 | /******/ 49 | /************************************************************************/ 50 | var __webpack_exports__ = {}; 51 | const { readFileSync } = __nccwpck_require__(896); 52 | console.log(readFileSync(__dirname + './test.json')); 53 | 54 | 55 | module.exports = __webpack_exports__; 56 | /******/ })() 57 | ; -------------------------------------------------------------------------------- /test/unit/custom-emit/output.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ var __webpack_modules__ = ({ 3 | 4 | /***/ 896: 5 | /***/ ((module) => { 6 | 7 | "use strict"; 8 | module.exports = require("fs"); 9 | 10 | /***/ }) 11 | 12 | /******/ }); 13 | /************************************************************************/ 14 | /******/ // The module cache 15 | /******/ var __webpack_module_cache__ = {}; 16 | /******/ 17 | /******/ // The require function 18 | /******/ function __nccwpck_require__(moduleId) { 19 | /******/ // Check if module is in cache 20 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; 21 | /******/ if (cachedModule !== undefined) { 22 | /******/ return cachedModule.exports; 23 | /******/ } 24 | /******/ // Create a new module (and put it into the cache) 25 | /******/ var module = __webpack_module_cache__[moduleId] = { 26 | /******/ // no module.id needed 27 | /******/ // no module.loaded needed 28 | /******/ exports: {} 29 | /******/ }; 30 | /******/ 31 | /******/ // Execute the module function 32 | /******/ var threw = true; 33 | /******/ try { 34 | /******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__); 35 | /******/ threw = false; 36 | /******/ } finally { 37 | /******/ if(threw) delete __webpack_module_cache__[moduleId]; 38 | /******/ } 39 | /******/ 40 | /******/ // Return the exports of the module 41 | /******/ return module.exports; 42 | /******/ } 43 | /******/ 44 | /************************************************************************/ 45 | /******/ /* webpack/runtime/compat */ 46 | /******/ 47 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; 48 | /******/ 49 | /************************************************************************/ 50 | var __webpack_exports__ = {}; 51 | const { readFileSync } = __nccwpck_require__(896); 52 | console.log(readFileSync(__dirname + './test.json')); 53 | 54 | 55 | module.exports = __webpack_exports__; 56 | /******/ })() 57 | ; -------------------------------------------------------------------------------- /test/unit/custom-emit/test.json: -------------------------------------------------------------------------------- 1 | { 2 | "custom": "emit" 3 | } -------------------------------------------------------------------------------- /test/unit/double-nested-builds/input.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ var __webpack_modules__ = ({ 3 | 4 | /***/ 332: 5 | /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { 6 | 7 | /******/ (() => { // webpackBootstrap 8 | /******/ "use strict"; 9 | /******/ var __webpack_modules__ = ({ 10 | 11 | /***/ 622: 12 | /***/ ((module) => { 13 | 14 | module.exports = __nccwpck_require__(622); 15 | 16 | /***/ }) 17 | 18 | /******/ }); 19 | /************************************************************************/ 20 | /******/ // The module cache 21 | /******/ var __webpack_module_cache__ = {}; 22 | /******/ 23 | /******/ // The require function 24 | /******/ function __nccwpck_require2_(moduleId) { 25 | /******/ // Check if module is in cache 26 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; 27 | /******/ if (cachedModule !== undefined) { 28 | /******/ return cachedModule.exports; 29 | /******/ } 30 | /******/ // Create a new module (and put it into the cache) 31 | /******/ var module = __webpack_module_cache__[moduleId] = { 32 | /******/ // no module.id needed 33 | /******/ // no module.loaded needed 34 | /******/ exports: {} 35 | /******/ }; 36 | /******/ 37 | /******/ // Execute the module function 38 | /******/ var threw = true; 39 | /******/ try { 40 | /******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require2_); 41 | /******/ threw = false; 42 | /******/ } finally { 43 | /******/ if(threw) delete __webpack_module_cache__[moduleId]; 44 | /******/ } 45 | /******/ 46 | /******/ // Return the exports of the module 47 | /******/ return module.exports; 48 | /******/ } 49 | /******/ 50 | /************************************************************************/ 51 | /******/ /* webpack/runtime/compat get default export */ 52 | /******/ (() => { 53 | /******/ // getDefaultExport function for compatibility with non-harmony modules 54 | /******/ __nccwpck_require2_.n = (module) => { 55 | /******/ var getter = module && module.__esModule ? 56 | /******/ () => (module['default']) : 57 | /******/ () => (module); 58 | /******/ __nccwpck_require2_.d(getter, { a: getter }); 59 | /******/ return getter; 60 | /******/ }; 61 | /******/ })(); 62 | /******/ 63 | /******/ /* webpack/runtime/define property getters */ 64 | /******/ (() => { 65 | /******/ // define getter functions for harmony exports 66 | /******/ __nccwpck_require2_.d = (exports, definition) => { 67 | /******/ for(var key in definition) { 68 | /******/ if(__nccwpck_require2_.o(definition, key) && !__nccwpck_require2_.o(exports, key)) { 69 | /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); 70 | /******/ } 71 | /******/ } 72 | /******/ }; 73 | /******/ })(); 74 | /******/ 75 | /******/ /* webpack/runtime/hasOwnProperty shorthand */ 76 | /******/ (() => { 77 | /******/ __nccwpck_require2_.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) 78 | /******/ })(); 79 | /******/ 80 | /******/ /* webpack/runtime/make namespace object */ 81 | /******/ (() => { 82 | /******/ // define __esModule on exports 83 | /******/ __nccwpck_require2_.r = (exports) => { 84 | /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 85 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 86 | /******/ } 87 | /******/ Object.defineProperty(exports, '__esModule', { value: true }); 88 | /******/ }; 89 | /******/ })(); 90 | /******/ 91 | /******/ /* webpack/runtime/compat */ 92 | /******/ 93 | /******/ if (typeof __nccwpck_require2_ !== 'undefined') __nccwpck_require2_.ab = __dirname + "/"; 94 | /******/ 95 | /************************************************************************/ 96 | var __webpack_exports__ = {}; 97 | // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. 98 | (() => { 99 | __nccwpck_require2_.r(__webpack_exports__); 100 | /* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require2_(622); 101 | /* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__nccwpck_require2_.n(path__WEBPACK_IMPORTED_MODULE_0__); 102 | 103 | 104 | const file = __nccwpck_require2_.ab + "pi-bridge.js"; 105 | 106 | const obscureRequire = eval(`function obscureRequire (file) { 107 | require(file); 108 | }`); 109 | 110 | console.log(obscureRequire(__nccwpck_require2_.ab + "pi-bridge.js")); 111 | 112 | })(); 113 | 114 | module.exports = __webpack_exports__; 115 | /******/ })() 116 | ; 117 | 118 | 119 | /***/ }), 120 | 121 | /***/ 622: 122 | /***/ ((module) => { 123 | 124 | "use strict"; 125 | module.exports = require("path"); 126 | 127 | /***/ }) 128 | 129 | /******/ }); 130 | /************************************************************************/ 131 | /******/ // The module cache 132 | /******/ var __webpack_module_cache__ = {}; 133 | /******/ 134 | /******/ // The require function 135 | /******/ function __nccwpck_require__(moduleId) { 136 | /******/ // Check if module is in cache 137 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; 138 | /******/ if (cachedModule !== undefined) { 139 | /******/ return cachedModule.exports; 140 | /******/ } 141 | /******/ // Create a new module (and put it into the cache) 142 | /******/ var module = __webpack_module_cache__[moduleId] = { 143 | /******/ // no module.id needed 144 | /******/ // no module.loaded needed 145 | /******/ exports: {} 146 | /******/ }; 147 | /******/ 148 | /******/ // Execute the module function 149 | /******/ var threw = true; 150 | /******/ try { 151 | /******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__); 152 | /******/ threw = false; 153 | /******/ } finally { 154 | /******/ if(threw) delete __webpack_module_cache__[moduleId]; 155 | /******/ } 156 | /******/ 157 | /******/ // Return the exports of the module 158 | /******/ return module.exports; 159 | /******/ } 160 | /******/ 161 | /************************************************************************/ 162 | /******/ /* webpack/runtime/compat */ 163 | /******/ 164 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; 165 | /******/ 166 | /************************************************************************/ 167 | /******/ 168 | /******/ // startup 169 | /******/ // Load entry module and return exports 170 | /******/ // This entry module is referenced by other modules so it can't be inlined 171 | /******/ var __webpack_exports__ = __nccwpck_require__(332); 172 | /******/ module.exports = __webpack_exports__; 173 | /******/ 174 | /******/ })() 175 | ; -------------------------------------------------------------------------------- /test/unit/exports-nomodule/input.js: -------------------------------------------------------------------------------- 1 | import { x } from 'x'; 2 | console.log(x); 3 | -------------------------------------------------------------------------------- /test/unit/exports-nomodule/no.js: -------------------------------------------------------------------------------- 1 | export var y = 'y'; 2 | -------------------------------------------------------------------------------- /test/unit/exports-nomodule/node.js: -------------------------------------------------------------------------------- 1 | export var x = 'x'; 2 | -------------------------------------------------------------------------------- /test/unit/exports-nomodule/output-coverage.js: -------------------------------------------------------------------------------- 1 | /******/ /* webpack/runtime/compat */ 2 | /******/ 3 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = new URL('.', import.meta.url).pathname.slice(import.meta.url.match(/^file:\/\/\/\w:/) ? 1 : 0, -1) + "/"; 4 | /******/ 5 | /************************************************************************/ 6 | var __webpack_exports__ = {}; 7 | 8 | ;// CONCATENATED MODULE: ./test/unit/exports-nomodule/node.js 9 | var x = 'x'; 10 | 11 | ;// CONCATENATED MODULE: ./test/unit/exports-nomodule/input.js 12 | 13 | console.log(x); -------------------------------------------------------------------------------- /test/unit/exports-nomodule/output.js: -------------------------------------------------------------------------------- 1 | /******/ /* webpack/runtime/compat */ 2 | /******/ 3 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = new URL('.', import.meta.url).pathname.slice(import.meta.url.match(/^file:\/\/\/\w:/) ? 1 : 0, -1) + "/"; 4 | /******/ 5 | /************************************************************************/ 6 | var __webpack_exports__ = {}; 7 | 8 | ;// CONCATENATED MODULE: ./test/unit/exports-nomodule/node.js 9 | var x = 'x'; 10 | 11 | ;// CONCATENATED MODULE: ./test/unit/exports-nomodule/input.js 12 | 13 | console.log(x); -------------------------------------------------------------------------------- /test/unit/exports-nomodule/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "x", 3 | "type": "module", 4 | "exports": { 5 | ".": { 6 | "module": "./no.js", 7 | "default": { 8 | "node": "./node.js" 9 | } 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /test/unit/exports-wildcard/input.js: -------------------------------------------------------------------------------- 1 | import { y } from 'y/no'; 2 | console.log(y); 3 | -------------------------------------------------------------------------------- /test/unit/exports-wildcard/no.js: -------------------------------------------------------------------------------- 1 | export var x = 'x'; 2 | -------------------------------------------------------------------------------- /test/unit/exports-wildcard/node.js: -------------------------------------------------------------------------------- 1 | export var y = 'y'; 2 | -------------------------------------------------------------------------------- /test/unit/exports-wildcard/output-coverage.js: -------------------------------------------------------------------------------- 1 | /******/ /* webpack/runtime/compat */ 2 | /******/ 3 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = new URL('.', import.meta.url).pathname.slice(import.meta.url.match(/^file:\/\/\/\w:/) ? 1 : 0, -1) + "/"; 4 | /******/ 5 | /************************************************************************/ 6 | var __webpack_exports__ = {}; 7 | 8 | ;// CONCATENATED MODULE: ./test/unit/exports-wildcard/node.js 9 | var y = 'y'; 10 | 11 | ;// CONCATENATED MODULE: ./test/unit/exports-wildcard/input.js 12 | 13 | console.log(y); -------------------------------------------------------------------------------- /test/unit/exports-wildcard/output.js: -------------------------------------------------------------------------------- 1 | /******/ /* webpack/runtime/compat */ 2 | /******/ 3 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = new URL('.', import.meta.url).pathname.slice(import.meta.url.match(/^file:\/\/\/\w:/) ? 1 : 0, -1) + "/"; 4 | /******/ 5 | /************************************************************************/ 6 | var __webpack_exports__ = {}; 7 | 8 | ;// CONCATENATED MODULE: ./test/unit/exports-wildcard/node.js 9 | var y = 'y'; 10 | 11 | ;// CONCATENATED MODULE: ./test/unit/exports-wildcard/input.js 12 | 13 | console.log(y); -------------------------------------------------------------------------------- /test/unit/exports-wildcard/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "y", 3 | "type": "module", 4 | "exports": { 5 | "./*": { 6 | "module": "./*.js", 7 | "default": { 8 | "node": "./*de.js" 9 | } 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /test/unit/externals/input.js: -------------------------------------------------------------------------------- 1 | const external = require('externaltest'); 2 | const regexpExternal = require('external-regex'); 3 | const regexpExternalMatch = require('external-replace/some-file') 4 | 5 | console.log(external); 6 | console.log(regexpExternal); 7 | console.log(regexpExternalMatch); 8 | -------------------------------------------------------------------------------- /test/unit/externals/output-coverage.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ var __webpack_modules__ = ({ 3 | 4 | /***/ 708: 5 | /***/ ((module) => { 6 | 7 | "use strict"; 8 | module.exports = require("external-replace/replaced/some-file"); 9 | 10 | /***/ }), 11 | 12 | /***/ 371: 13 | /***/ ((module) => { 14 | 15 | "use strict"; 16 | module.exports = require("externalmapped"); 17 | 18 | /***/ }), 19 | 20 | /***/ 689: 21 | /***/ ((module) => { 22 | 23 | "use strict"; 24 | module.exports = require("regexexternal"); 25 | 26 | /***/ }) 27 | 28 | /******/ }); 29 | /************************************************************************/ 30 | /******/ // The module cache 31 | /******/ var __webpack_module_cache__ = {}; 32 | /******/ 33 | /******/ // The require function 34 | /******/ function __nccwpck_require__(moduleId) { 35 | /******/ // Check if module is in cache 36 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; 37 | /******/ if (cachedModule !== undefined) { 38 | /******/ return cachedModule.exports; 39 | /******/ } 40 | /******/ // Create a new module (and put it into the cache) 41 | /******/ var module = __webpack_module_cache__[moduleId] = { 42 | /******/ // no module.id needed 43 | /******/ // no module.loaded needed 44 | /******/ exports: {} 45 | /******/ }; 46 | /******/ 47 | /******/ // Execute the module function 48 | /******/ var threw = true; 49 | /******/ try { 50 | /******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__); 51 | /******/ threw = false; 52 | /******/ } finally { 53 | /******/ if(threw) delete __webpack_module_cache__[moduleId]; 54 | /******/ } 55 | /******/ 56 | /******/ // Return the exports of the module 57 | /******/ return module.exports; 58 | /******/ } 59 | /******/ 60 | /************************************************************************/ 61 | /******/ /* webpack/runtime/compat */ 62 | /******/ 63 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; 64 | /******/ 65 | /************************************************************************/ 66 | var __webpack_exports__ = {}; 67 | const external = __nccwpck_require__(371); 68 | const regexpExternal = __nccwpck_require__(689); 69 | const regexpExternalMatch = __nccwpck_require__(708) 70 | 71 | console.log(external); 72 | console.log(regexpExternal); 73 | console.log(regexpExternalMatch); 74 | 75 | module.exports = __webpack_exports__; 76 | /******/ })() 77 | ; -------------------------------------------------------------------------------- /test/unit/externals/output.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ var __webpack_modules__ = ({ 3 | 4 | /***/ 708: 5 | /***/ ((module) => { 6 | 7 | "use strict"; 8 | module.exports = require("external-replace/replaced/some-file"); 9 | 10 | /***/ }), 11 | 12 | /***/ 371: 13 | /***/ ((module) => { 14 | 15 | "use strict"; 16 | module.exports = require("externalmapped"); 17 | 18 | /***/ }), 19 | 20 | /***/ 689: 21 | /***/ ((module) => { 22 | 23 | "use strict"; 24 | module.exports = require("regexexternal"); 25 | 26 | /***/ }) 27 | 28 | /******/ }); 29 | /************************************************************************/ 30 | /******/ // The module cache 31 | /******/ var __webpack_module_cache__ = {}; 32 | /******/ 33 | /******/ // The require function 34 | /******/ function __nccwpck_require__(moduleId) { 35 | /******/ // Check if module is in cache 36 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; 37 | /******/ if (cachedModule !== undefined) { 38 | /******/ return cachedModule.exports; 39 | /******/ } 40 | /******/ // Create a new module (and put it into the cache) 41 | /******/ var module = __webpack_module_cache__[moduleId] = { 42 | /******/ // no module.id needed 43 | /******/ // no module.loaded needed 44 | /******/ exports: {} 45 | /******/ }; 46 | /******/ 47 | /******/ // Execute the module function 48 | /******/ var threw = true; 49 | /******/ try { 50 | /******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__); 51 | /******/ threw = false; 52 | /******/ } finally { 53 | /******/ if(threw) delete __webpack_module_cache__[moduleId]; 54 | /******/ } 55 | /******/ 56 | /******/ // Return the exports of the module 57 | /******/ return module.exports; 58 | /******/ } 59 | /******/ 60 | /************************************************************************/ 61 | /******/ /* webpack/runtime/compat */ 62 | /******/ 63 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; 64 | /******/ 65 | /************************************************************************/ 66 | var __webpack_exports__ = {}; 67 | const external = __nccwpck_require__(371); 68 | const regexpExternal = __nccwpck_require__(689); 69 | const regexpExternalMatch = __nccwpck_require__(708) 70 | 71 | console.log(external); 72 | console.log(regexpExternal); 73 | console.log(regexpExternalMatch); 74 | 75 | module.exports = __webpack_exports__; 76 | /******/ })() 77 | ; -------------------------------------------------------------------------------- /test/unit/import-meta-esm/input.js: -------------------------------------------------------------------------------- 1 | console.log(import.meta.url); 2 | -------------------------------------------------------------------------------- /test/unit/import-meta-esm/output-coverage.js: -------------------------------------------------------------------------------- 1 | /******/ /* webpack/runtime/compat */ 2 | /******/ 3 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = new URL('.', import.meta.url).pathname.slice(import.meta.url.match(/^file:\/\/\/\w:/) ? 1 : 0, -1) + "/"; 4 | /******/ 5 | /************************************************************************/ 6 | var __webpack_exports__ = {}; 7 | console.log(import.meta.url); -------------------------------------------------------------------------------- /test/unit/import-meta-esm/output.js: -------------------------------------------------------------------------------- 1 | /******/ /* webpack/runtime/compat */ 2 | /******/ 3 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = new URL('.', import.meta.url).pathname.slice(import.meta.url.match(/^file:\/\/\/\w:/) ? 1 : 0, -1) + "/"; 4 | /******/ 5 | /************************************************************************/ 6 | var __webpack_exports__ = {}; 7 | console.log(import.meta.url); -------------------------------------------------------------------------------- /test/unit/import-meta-esm/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "module" 3 | } 4 | -------------------------------------------------------------------------------- /test/unit/imports/input.js: -------------------------------------------------------------------------------- 1 | import { x } from '#x'; 2 | console.log(x); 3 | -------------------------------------------------------------------------------- /test/unit/imports/no.js: -------------------------------------------------------------------------------- 1 | export var y = 'y'; 2 | -------------------------------------------------------------------------------- /test/unit/imports/node.js: -------------------------------------------------------------------------------- 1 | export var x = 'x'; 2 | -------------------------------------------------------------------------------- /test/unit/imports/output-coverage.js: -------------------------------------------------------------------------------- 1 | /******/ /* webpack/runtime/compat */ 2 | /******/ 3 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = new URL('.', import.meta.url).pathname.slice(import.meta.url.match(/^file:\/\/\/\w:/) ? 1 : 0, -1) + "/"; 4 | /******/ 5 | /************************************************************************/ 6 | var __webpack_exports__ = {}; 7 | 8 | ;// CONCATENATED MODULE: ./test/unit/imports/node.js 9 | var x = 'x'; 10 | 11 | ;// CONCATENATED MODULE: ./test/unit/imports/input.js 12 | 13 | console.log(x); -------------------------------------------------------------------------------- /test/unit/imports/output.js: -------------------------------------------------------------------------------- 1 | /******/ /* webpack/runtime/compat */ 2 | /******/ 3 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = new URL('.', import.meta.url).pathname.slice(import.meta.url.match(/^file:\/\/\/\w:/) ? 1 : 0, -1) + "/"; 4 | /******/ 5 | /************************************************************************/ 6 | var __webpack_exports__ = {}; 7 | 8 | ;// CONCATENATED MODULE: ./test/unit/imports/node.js 9 | var x = 'x'; 10 | 11 | ;// CONCATENATED MODULE: ./test/unit/imports/input.js 12 | 13 | console.log(x); -------------------------------------------------------------------------------- /test/unit/imports/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "x", 3 | "type": "module", 4 | "imports": { 5 | "#x": { 6 | "module": "./no.js", 7 | "default": { 8 | "node": "./node.js" 9 | } 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /test/unit/minify-err/input.js: -------------------------------------------------------------------------------- 1 | if (global.GENTLY) require = GENTLY.hijack(__non_webpack_require__); 2 | console.log(require('fs')); 3 | -------------------------------------------------------------------------------- /test/unit/minify-err/opt.json: -------------------------------------------------------------------------------- 1 | { 2 | "minify": true 3 | } 4 | -------------------------------------------------------------------------------- /test/unit/minify-err/output-coverage.js: -------------------------------------------------------------------------------- 1 | (()=>{var __webpack_modules__={896:_=>{"use strict";_.exports=require("fs")}};var __webpack_module_cache__={};function __nccwpck_require__(_){var e=__webpack_module_cache__[_];if(e!==undefined){return e.exports}var r=__webpack_module_cache__[_]={exports:{}};var a=true;try{__webpack_modules__[_](r,r.exports,__nccwpck_require__);a=false}finally{if(a)delete __webpack_module_cache__[_]}return r.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var __webpack_exports__={};var input_require;if(global.GENTLY)input_require=GENTLY.hijack(eval("require"));console.log(__nccwpck_require__(896));module.exports=__webpack_exports__})(); -------------------------------------------------------------------------------- /test/unit/minify-err/output.js: -------------------------------------------------------------------------------- 1 | (()=>{var __webpack_modules__={896:_=>{"use strict";_.exports=require("fs")}};var __webpack_module_cache__={};function __nccwpck_require__(_){var e=__webpack_module_cache__[_];if(e!==undefined){return e.exports}var r=__webpack_module_cache__[_]={exports:{}};var a=true;try{__webpack_modules__[_](r,r.exports,__nccwpck_require__);a=false}finally{if(a)delete __webpack_module_cache__[_]}return r.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var __webpack_exports__={};var input_require;if(global.GENTLY)input_require=GENTLY.hijack(eval("require"));console.log(__nccwpck_require__(896));module.exports=__webpack_exports__})(); -------------------------------------------------------------------------------- /test/unit/minify-sourcemap-register/input.js: -------------------------------------------------------------------------------- 1 | const foobar = 'qux' 2 | console.log?.("hello"); 3 | exports.foobar = foobar 4 | -------------------------------------------------------------------------------- /test/unit/minify-sourcemap-register/opt.json: -------------------------------------------------------------------------------- 1 | { 2 | "minify": true, 3 | "sourceMap": true, 4 | "sourceMapRegister": true 5 | } 6 | -------------------------------------------------------------------------------- /test/unit/minify-sourcemap-register/output-coverage.js: -------------------------------------------------------------------------------- 1 | require('./sourcemap-register.js');(()=>{if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var e={};(()=>{var _=e;const o="qux";console.log?.("hello");_.foobar=o})();module.exports=e})(); 2 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /test/unit/minify-sourcemap-register/output-coverage.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","names":["__webpack_require__","ab","__dirname","foobar","console","log","exports"],"sources":["../webpack/runtime/compat","../test/unit/minify-sourcemap-register/input.js"],"sourcesContent":["\nif (typeof __webpack_require__ !== 'undefined') __webpack_require__.ab = __dirname + \"/\";","const foobar = 'qux'\nconsole.log?.(\"hello\");\nexports.foobar = foobar\n"],"mappings":"MACA,UAAAA,sBAAA,YAAAA,oBAAAC,GAAAC,UAAA,I,uBCDA,MAAAC,EAAA,MACAC,QAAAC,MAAA,SACAC,EAAAH,Q","ignoreList":[]} -------------------------------------------------------------------------------- /test/unit/minify-sourcemap-register/output.js: -------------------------------------------------------------------------------- 1 | require('./sourcemap-register.js');(()=>{if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var e={};(()=>{var _=e;const o="qux";console.log?.("hello");_.foobar=o})();module.exports=e})(); 2 | //# sourceMappingURL=index.js.map 3 | -------------------------------------------------------------------------------- /test/unit/minify-sourcemap-register/output.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","names":["__webpack_require__","ab","__dirname","foobar","console","log","exports"],"sources":["../webpack/runtime/compat","../test/unit/minify-sourcemap-register/input.js"],"sourcesContent":["\nif (typeof __webpack_require__ !== 'undefined') __webpack_require__.ab = __dirname + \"/\";","const foobar = 'qux'\nconsole.log?.(\"hello\");\nexports.foobar = foobar\n"],"mappings":"MACA,UAAAA,sBAAA,YAAAA,oBAAAC,GAAAC,UAAA,I,uBCDA,MAAAC,EAAA,MACAC,QAAAC,MAAA,SACAC,EAAAH,Q","ignoreList":[]} -------------------------------------------------------------------------------- /test/unit/minify-v8cache-sourcemap-register/input.js: -------------------------------------------------------------------------------- 1 | const foobar = 'qux' 2 | console.log("hello"); 3 | exports.foobar = foobar 4 | -------------------------------------------------------------------------------- /test/unit/minify-v8cache-sourcemap-register/opt.json: -------------------------------------------------------------------------------- 1 | { 2 | "minify": true, 3 | "sourceMap": true, 4 | "sourceMapRegister": true, 5 | "v8cache": true 6 | } 7 | -------------------------------------------------------------------------------- /test/unit/minify-v8cache-sourcemap-register/output-coverage.js: -------------------------------------------------------------------------------- 1 | require('./sourcemap-register.js');const { readFileSync, writeFileSync } = require('fs'), { Script } = require('vm'), { wrap } = require('module'); 2 | const basename = __dirname + '/index.js'; 3 | const source = readFileSync(basename + '.cache.js', 'utf-8'); 4 | const cachedData = !process.pkg && require('process').platform !== 'win32' && readFileSync(basename + '.cache'); 5 | const scriptOpts = { filename: basename + '.cache.js', columnOffset: -62 } 6 | const script = new Script(wrap(source), cachedData ? Object.assign({ cachedData }, scriptOpts) : scriptOpts); 7 | (script.runInThisContext())(exports, require, module, __filename, __dirname); 8 | if (cachedData) process.on('exit', () => { try { writeFileSync(basename + '.cache', script.createCachedData()); } catch(e) {} }); -------------------------------------------------------------------------------- /test/unit/minify-v8cache-sourcemap-register/output-coverage.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","names":["__webpack_require__","ab","__dirname","foobar","console","log","exports"],"sources":["../webpack/runtime/compat","../test/unit/minify-v8cache-sourcemap-register/input.js"],"sourcesContent":["\nif (typeof __webpack_require__ !== 'undefined') __webpack_require__.ab = __dirname + \"/\";","const foobar = 'qux'\nconsole.log(\"hello\");\nexports.foobar = foobar\n"],"mappings":"MACA,UAAAA,sBAAA,YAAAA,oBAAAC,GAAAC,UAAA,I,uBCDA,MAAAC,EAAA,MACAC,QAAAC,IAAA,SACAC,EAAAH,Q","ignoreList":[]} -------------------------------------------------------------------------------- /test/unit/minify-v8cache-sourcemap-register/output.js: -------------------------------------------------------------------------------- 1 | require('./sourcemap-register.js');const { readFileSync, writeFileSync } = require('fs'), { Script } = require('vm'), { wrap } = require('module'); 2 | const basename = __dirname + '/index.js'; 3 | const source = readFileSync(basename + '.cache.js', 'utf-8'); 4 | const cachedData = !process.pkg && require('process').platform !== 'win32' && readFileSync(basename + '.cache'); 5 | const scriptOpts = { filename: basename + '.cache.js', columnOffset: -62 } 6 | const script = new Script(wrap(source), cachedData ? Object.assign({ cachedData }, scriptOpts) : scriptOpts); 7 | (script.runInThisContext())(exports, require, module, __filename, __dirname); 8 | if (cachedData) process.on('exit', () => { try { writeFileSync(basename + '.cache', script.createCachedData()); } catch(e) {} }); 9 | -------------------------------------------------------------------------------- /test/unit/minify-v8cache-sourcemap-register/output.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","names":["__webpack_require__","ab","__dirname","foobar","console","log","exports"],"sources":["../webpack/runtime/compat","../test/unit/minify-v8cache-sourcemap-register/input.js"],"sourcesContent":["\nif (typeof __webpack_require__ !== 'undefined') __webpack_require__.ab = __dirname + \"/\";","const foobar = 'qux'\nconsole.log(\"hello\");\nexports.foobar = foobar\n"],"mappings":"MACA,UAAAA,sBAAA,YAAAA,oBAAAC,GAAAC,UAAA,I,uBCDA,MAAAC,EAAA,MACAC,QAAAC,IAAA,SACAC,EAAAH,Q","ignoreList":[]} -------------------------------------------------------------------------------- /test/unit/minify/input.js: -------------------------------------------------------------------------------- 1 | const foobar = 'qux' 2 | console.log?.("hello"); 3 | exports.foobar = foobar 4 | -------------------------------------------------------------------------------- /test/unit/minify/opt.json: -------------------------------------------------------------------------------- 1 | { 2 | "minify": true, 3 | "sourceMap": true, 4 | "sourceMapRegister": false 5 | } 6 | -------------------------------------------------------------------------------- /test/unit/minify/output-coverage.js: -------------------------------------------------------------------------------- 1 | (()=>{if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var e={};(()=>{var _=e;const o="qux";console.log?.("hello");_.foobar=o})();module.exports=e})(); 2 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /test/unit/minify/output-coverage.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","names":["__webpack_require__","ab","__dirname","foobar","console","log","exports"],"sources":["../webpack/runtime/compat","../test/unit/minify/input.js"],"sourcesContent":["\nif (typeof __webpack_require__ !== 'undefined') __webpack_require__.ab = __dirname + \"/\";","const foobar = 'qux'\nconsole.log?.(\"hello\");\nexports.foobar = foobar\n"],"mappings":"MACA,UAAAA,sBAAA,YAAAA,oBAAAC,GAAAC,UAAA,I,uBCDA,MAAAC,EAAA,MACAC,QAAAC,MAAA,SACAC,EAAAH,Q","ignoreList":[]} -------------------------------------------------------------------------------- /test/unit/minify/output.js: -------------------------------------------------------------------------------- 1 | (()=>{if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var e={};(()=>{var _=e;const o="qux";console.log?.("hello");_.foobar=o})();module.exports=e})(); 2 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /test/unit/minify/output.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","names":["__webpack_require__","ab","__dirname","foobar","console","log","exports"],"sources":["../webpack/runtime/compat","../test/unit/minify/input.js"],"sourcesContent":["\nif (typeof __webpack_require__ !== 'undefined') __webpack_require__.ab = __dirname + \"/\";","const foobar = 'qux'\nconsole.log?.(\"hello\");\nexports.foobar = foobar\n"],"mappings":"MACA,UAAAA,sBAAA,YAAAA,oBAAAC,GAAAC,UAAA,I,uBCDA,MAAAC,EAAA,MACAC,QAAAC,MAAA,SACAC,EAAAH,Q","ignoreList":[]} -------------------------------------------------------------------------------- /test/unit/nested-builds/input.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ "use strict"; 3 | /******/ var __webpack_modules__ = ({ 4 | 5 | /***/ 622: 6 | /***/ ((module) => { 7 | 8 | module.exports = require("path"); 9 | 10 | /***/ }) 11 | 12 | /******/ }); 13 | /************************************************************************/ 14 | /******/ // The module cache 15 | /******/ var __webpack_module_cache__ = {}; 16 | /******/ 17 | /******/ // The require function 18 | /******/ function __nccwpck_require__(moduleId) { 19 | /******/ // Check if module is in cache 20 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; 21 | /******/ if (cachedModule !== undefined) { 22 | /******/ return cachedModule.exports; 23 | /******/ } 24 | /******/ // Create a new module (and put it into the cache) 25 | /******/ var module = __webpack_module_cache__[moduleId] = { 26 | /******/ // no module.id needed 27 | /******/ // no module.loaded needed 28 | /******/ exports: {} 29 | /******/ }; 30 | /******/ 31 | /******/ // Execute the module function 32 | /******/ var threw = true; 33 | /******/ try { 34 | /******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__); 35 | /******/ threw = false; 36 | /******/ } finally { 37 | /******/ if(threw) delete __webpack_module_cache__[moduleId]; 38 | /******/ } 39 | /******/ 40 | /******/ // Return the exports of the module 41 | /******/ return module.exports; 42 | /******/ } 43 | /******/ 44 | /************************************************************************/ 45 | /******/ /* webpack/runtime/compat get default export */ 46 | /******/ (() => { 47 | /******/ // getDefaultExport function for compatibility with non-harmony modules 48 | /******/ __nccwpck_require__.n = (module) => { 49 | /******/ var getter = module && module.__esModule ? 50 | /******/ () => (module['default']) : 51 | /******/ () => (module); 52 | /******/ __nccwpck_require__.d(getter, { a: getter }); 53 | /******/ return getter; 54 | /******/ }; 55 | /******/ })(); 56 | /******/ 57 | /******/ /* webpack/runtime/define property getters */ 58 | /******/ (() => { 59 | /******/ // define getter functions for harmony exports 60 | /******/ __nccwpck_require__.d = (exports, definition) => { 61 | /******/ for(var key in definition) { 62 | /******/ if(__nccwpck_require__.o(definition, key) && !__nccwpck_require__.o(exports, key)) { 63 | /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); 64 | /******/ } 65 | /******/ } 66 | /******/ }; 67 | /******/ })(); 68 | /******/ 69 | /******/ /* webpack/runtime/hasOwnProperty shorthand */ 70 | /******/ (() => { 71 | /******/ __nccwpck_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) 72 | /******/ })(); 73 | /******/ 74 | /******/ /* webpack/runtime/make namespace object */ 75 | /******/ (() => { 76 | /******/ // define __esModule on exports 77 | /******/ __nccwpck_require__.r = (exports) => { 78 | /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 79 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 80 | /******/ } 81 | /******/ Object.defineProperty(exports, '__esModule', { value: true }); 82 | /******/ }; 83 | /******/ })(); 84 | /******/ 85 | /******/ /* webpack/runtime/compat */ 86 | /******/ 87 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; 88 | /******/ 89 | /************************************************************************/ 90 | var __webpack_exports__ = {}; 91 | // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. 92 | (() => { 93 | __nccwpck_require__.r(__webpack_exports__); 94 | /* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(622); 95 | /* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__nccwpck_require__.n(path__WEBPACK_IMPORTED_MODULE_0__); 96 | 97 | 98 | const file = __nccwpck_require__.ab + "pi-bridge.js"; 99 | 100 | const obscureRequire = eval(`function obscureRequire (file) { 101 | require(file); 102 | }`); 103 | 104 | console.log(obscureRequire(__nccwpck_require__.ab + "pi-bridge.js")); 105 | 106 | })(); 107 | 108 | module.exports = __webpack_exports__; 109 | /******/ })() 110 | ; 111 | -------------------------------------------------------------------------------- /test/unit/runtime-notfound/input.js: -------------------------------------------------------------------------------- 1 | require('./not-found.js'); 2 | require('./not-foud2.js'); -------------------------------------------------------------------------------- /test/unit/runtime-notfound/output-coverage.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ var __webpack_modules__ = ({ 3 | 4 | /***/ 580: 5 | /***/ ((module) => { 6 | 7 | module.exports = eval("require")("./not-foud2.js"); 8 | 9 | 10 | /***/ }), 11 | 12 | /***/ 704: 13 | /***/ ((module) => { 14 | 15 | module.exports = eval("require")("./not-found.js"); 16 | 17 | 18 | /***/ }) 19 | 20 | /******/ }); 21 | /************************************************************************/ 22 | /******/ // The module cache 23 | /******/ var __webpack_module_cache__ = {}; 24 | /******/ 25 | /******/ // The require function 26 | /******/ function __nccwpck_require__(moduleId) { 27 | /******/ // Check if module is in cache 28 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; 29 | /******/ if (cachedModule !== undefined) { 30 | /******/ return cachedModule.exports; 31 | /******/ } 32 | /******/ // Create a new module (and put it into the cache) 33 | /******/ var module = __webpack_module_cache__[moduleId] = { 34 | /******/ // no module.id needed 35 | /******/ // no module.loaded needed 36 | /******/ exports: {} 37 | /******/ }; 38 | /******/ 39 | /******/ // Execute the module function 40 | /******/ var threw = true; 41 | /******/ try { 42 | /******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__); 43 | /******/ threw = false; 44 | /******/ } finally { 45 | /******/ if(threw) delete __webpack_module_cache__[moduleId]; 46 | /******/ } 47 | /******/ 48 | /******/ // Return the exports of the module 49 | /******/ return module.exports; 50 | /******/ } 51 | /******/ 52 | /************************************************************************/ 53 | /******/ /* webpack/runtime/compat */ 54 | /******/ 55 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; 56 | /******/ 57 | /************************************************************************/ 58 | var __webpack_exports__ = {}; 59 | __nccwpck_require__(704); 60 | __nccwpck_require__(580); 61 | module.exports = __webpack_exports__; 62 | /******/ })() 63 | ; -------------------------------------------------------------------------------- /test/unit/runtime-notfound/output.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ var __webpack_modules__ = ({ 3 | 4 | /***/ 643: 5 | /***/ ((module) => { 6 | 7 | module.exports = eval("require")("./not-foud2.js"); 8 | 9 | 10 | /***/ }), 11 | 12 | /***/ 875: 13 | /***/ ((module) => { 14 | 15 | module.exports = eval("require")("./not-found.js"); 16 | 17 | 18 | /***/ }) 19 | 20 | /******/ }); 21 | /************************************************************************/ 22 | /******/ // The module cache 23 | /******/ var __webpack_module_cache__ = {}; 24 | /******/ 25 | /******/ // The require function 26 | /******/ function __nccwpck_require__(moduleId) { 27 | /******/ // Check if module is in cache 28 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; 29 | /******/ if (cachedModule !== undefined) { 30 | /******/ return cachedModule.exports; 31 | /******/ } 32 | /******/ // Create a new module (and put it into the cache) 33 | /******/ var module = __webpack_module_cache__[moduleId] = { 34 | /******/ // no module.id needed 35 | /******/ // no module.loaded needed 36 | /******/ exports: {} 37 | /******/ }; 38 | /******/ 39 | /******/ // Execute the module function 40 | /******/ var threw = true; 41 | /******/ try { 42 | /******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__); 43 | /******/ threw = false; 44 | /******/ } finally { 45 | /******/ if(threw) delete __webpack_module_cache__[moduleId]; 46 | /******/ } 47 | /******/ 48 | /******/ // Return the exports of the module 49 | /******/ return module.exports; 50 | /******/ } 51 | /******/ 52 | /************************************************************************/ 53 | /******/ /* webpack/runtime/compat */ 54 | /******/ 55 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; 56 | /******/ 57 | /************************************************************************/ 58 | var __webpack_exports__ = {}; 59 | __nccwpck_require__(875); 60 | __nccwpck_require__(643); 61 | module.exports = __webpack_exports__; 62 | /******/ })() 63 | ; -------------------------------------------------------------------------------- /test/unit/shebang/input.js: -------------------------------------------------------------------------------- 1 | #!/bin/user/env node 2 | module.exports = 'asdf'; -------------------------------------------------------------------------------- /test/unit/shebang/output-coverage.js: -------------------------------------------------------------------------------- 1 | #!/bin/user/env node 2 | /******/ (() => { // webpackBootstrap 3 | /******/ var __webpack_modules__ = ({ 4 | 5 | /***/ 272: 6 | /***/ ((module) => { 7 | 8 | module.exports = 'asdf'; 9 | 10 | /***/ }) 11 | 12 | /******/ }); 13 | /************************************************************************/ 14 | /******/ // The module cache 15 | /******/ var __webpack_module_cache__ = {}; 16 | /******/ 17 | /******/ // The require function 18 | /******/ function __nccwpck_require__(moduleId) { 19 | /******/ // Check if module is in cache 20 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; 21 | /******/ if (cachedModule !== undefined) { 22 | /******/ return cachedModule.exports; 23 | /******/ } 24 | /******/ // Create a new module (and put it into the cache) 25 | /******/ var module = __webpack_module_cache__[moduleId] = { 26 | /******/ // no module.id needed 27 | /******/ // no module.loaded needed 28 | /******/ exports: {} 29 | /******/ }; 30 | /******/ 31 | /******/ // Execute the module function 32 | /******/ var threw = true; 33 | /******/ try { 34 | /******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__); 35 | /******/ threw = false; 36 | /******/ } finally { 37 | /******/ if(threw) delete __webpack_module_cache__[moduleId]; 38 | /******/ } 39 | /******/ 40 | /******/ // Return the exports of the module 41 | /******/ return module.exports; 42 | /******/ } 43 | /******/ 44 | /************************************************************************/ 45 | /******/ /* webpack/runtime/compat */ 46 | /******/ 47 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; 48 | /******/ 49 | /************************************************************************/ 50 | /******/ 51 | /******/ // startup 52 | /******/ // Load entry module and return exports 53 | /******/ // This entry module is referenced by other modules so it can't be inlined 54 | /******/ var __webpack_exports__ = __nccwpck_require__(272); 55 | /******/ module.exports = __webpack_exports__; 56 | /******/ 57 | /******/ })() 58 | ; -------------------------------------------------------------------------------- /test/unit/shebang/output.js: -------------------------------------------------------------------------------- 1 | #!/bin/user/env node 2 | /******/ (() => { // webpackBootstrap 3 | /******/ var __webpack_modules__ = ({ 4 | 5 | /***/ 321: 6 | /***/ ((module) => { 7 | 8 | module.exports = 'asdf'; 9 | 10 | /***/ }) 11 | 12 | /******/ }); 13 | /************************************************************************/ 14 | /******/ // The module cache 15 | /******/ var __webpack_module_cache__ = {}; 16 | /******/ 17 | /******/ // The require function 18 | /******/ function __nccwpck_require__(moduleId) { 19 | /******/ // Check if module is in cache 20 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; 21 | /******/ if (cachedModule !== undefined) { 22 | /******/ return cachedModule.exports; 23 | /******/ } 24 | /******/ // Create a new module (and put it into the cache) 25 | /******/ var module = __webpack_module_cache__[moduleId] = { 26 | /******/ // no module.id needed 27 | /******/ // no module.loaded needed 28 | /******/ exports: {} 29 | /******/ }; 30 | /******/ 31 | /******/ // Execute the module function 32 | /******/ var threw = true; 33 | /******/ try { 34 | /******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__); 35 | /******/ threw = false; 36 | /******/ } finally { 37 | /******/ if(threw) delete __webpack_module_cache__[moduleId]; 38 | /******/ } 39 | /******/ 40 | /******/ // Return the exports of the module 41 | /******/ return module.exports; 42 | /******/ } 43 | /******/ 44 | /************************************************************************/ 45 | /******/ /* webpack/runtime/compat */ 46 | /******/ 47 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; 48 | /******/ 49 | /************************************************************************/ 50 | /******/ 51 | /******/ // startup 52 | /******/ // Load entry module and return exports 53 | /******/ // This entry module is referenced by other modules so it can't be inlined 54 | /******/ var __webpack_exports__ = __nccwpck_require__(321); 55 | /******/ module.exports = __webpack_exports__; 56 | /******/ 57 | /******/ })() 58 | ; -------------------------------------------------------------------------------- /test/unit/ts-decl-dir/input.js: -------------------------------------------------------------------------------- 1 | export * from './test.ts'; 2 | -------------------------------------------------------------------------------- /test/unit/ts-decl-dir/output-coverage.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ "use strict"; 3 | /******/ // The require scope 4 | /******/ var __nccwpck_require__ = {}; 5 | /******/ 6 | /************************************************************************/ 7 | /******/ /* webpack/runtime/define property getters */ 8 | /******/ (() => { 9 | /******/ // define getter functions for harmony exports 10 | /******/ __nccwpck_require__.d = (exports, definition) => { 11 | /******/ for(var key in definition) { 12 | /******/ if(__nccwpck_require__.o(definition, key) && !__nccwpck_require__.o(exports, key)) { 13 | /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); 14 | /******/ } 15 | /******/ } 16 | /******/ }; 17 | /******/ })(); 18 | /******/ 19 | /******/ /* webpack/runtime/hasOwnProperty shorthand */ 20 | /******/ (() => { 21 | /******/ __nccwpck_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) 22 | /******/ })(); 23 | /******/ 24 | /******/ /* webpack/runtime/make namespace object */ 25 | /******/ (() => { 26 | /******/ // define __esModule on exports 27 | /******/ __nccwpck_require__.r = (exports) => { 28 | /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 29 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 30 | /******/ } 31 | /******/ Object.defineProperty(exports, '__esModule', { value: true }); 32 | /******/ }; 33 | /******/ })(); 34 | /******/ 35 | /******/ /* webpack/runtime/compat */ 36 | /******/ 37 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; 38 | /******/ 39 | /************************************************************************/ 40 | var __webpack_exports__ = {}; 41 | // ESM COMPAT FLAG 42 | __nccwpck_require__.r(__webpack_exports__); 43 | 44 | // EXPORTS 45 | __nccwpck_require__.d(__webpack_exports__, { 46 | test: () => (/* reexport */ test) 47 | }); 48 | 49 | ;// CONCATENATED MODULE: ./test/unit/ts-decl-dir/test.ts 50 | function test(arg) { 51 | return arg; 52 | } 53 | 54 | ;// CONCATENATED MODULE: ./test/unit/ts-decl-dir/input.js 55 | 56 | 57 | module.exports = __webpack_exports__; 58 | /******/ })() 59 | ; -------------------------------------------------------------------------------- /test/unit/ts-decl-dir/output.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ "use strict"; 3 | /******/ // The require scope 4 | /******/ var __nccwpck_require__ = {}; 5 | /******/ 6 | /************************************************************************/ 7 | /******/ /* webpack/runtime/define property getters */ 8 | /******/ (() => { 9 | /******/ // define getter functions for harmony exports 10 | /******/ __nccwpck_require__.d = (exports, definition) => { 11 | /******/ for(var key in definition) { 12 | /******/ if(__nccwpck_require__.o(definition, key) && !__nccwpck_require__.o(exports, key)) { 13 | /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); 14 | /******/ } 15 | /******/ } 16 | /******/ }; 17 | /******/ })(); 18 | /******/ 19 | /******/ /* webpack/runtime/hasOwnProperty shorthand */ 20 | /******/ (() => { 21 | /******/ __nccwpck_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) 22 | /******/ })(); 23 | /******/ 24 | /******/ /* webpack/runtime/make namespace object */ 25 | /******/ (() => { 26 | /******/ // define __esModule on exports 27 | /******/ __nccwpck_require__.r = (exports) => { 28 | /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 29 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 30 | /******/ } 31 | /******/ Object.defineProperty(exports, '__esModule', { value: true }); 32 | /******/ }; 33 | /******/ })(); 34 | /******/ 35 | /******/ /* webpack/runtime/compat */ 36 | /******/ 37 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; 38 | /******/ 39 | /************************************************************************/ 40 | var __webpack_exports__ = {}; 41 | // ESM COMPAT FLAG 42 | __nccwpck_require__.r(__webpack_exports__); 43 | 44 | // EXPORTS 45 | __nccwpck_require__.d(__webpack_exports__, { 46 | test: () => (/* reexport */ test) 47 | }); 48 | 49 | ;// CONCATENATED MODULE: ./test/unit/ts-decl-dir/test.ts 50 | function test(arg) { 51 | return arg; 52 | } 53 | 54 | ;// CONCATENATED MODULE: ./test/unit/ts-decl-dir/input.js 55 | 56 | 57 | module.exports = __webpack_exports__; 58 | /******/ })() 59 | ; -------------------------------------------------------------------------------- /test/unit/ts-decl-dir/test.ts: -------------------------------------------------------------------------------- 1 | export function test (arg: string): string { 2 | return arg; 3 | } -------------------------------------------------------------------------------- /test/unit/ts-decl-dir/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": ".", 4 | "outDir": "dist", 5 | "declaration": true, 6 | "declarationDir": "dist/types" 7 | } 8 | } -------------------------------------------------------------------------------- /test/unit/ts-decl/input.js: -------------------------------------------------------------------------------- 1 | export * from './test.ts'; 2 | -------------------------------------------------------------------------------- /test/unit/ts-decl/output-coverage.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ "use strict"; 3 | /******/ // The require scope 4 | /******/ var __nccwpck_require__ = {}; 5 | /******/ 6 | /************************************************************************/ 7 | /******/ /* webpack/runtime/define property getters */ 8 | /******/ (() => { 9 | /******/ // define getter functions for harmony exports 10 | /******/ __nccwpck_require__.d = (exports, definition) => { 11 | /******/ for(var key in definition) { 12 | /******/ if(__nccwpck_require__.o(definition, key) && !__nccwpck_require__.o(exports, key)) { 13 | /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); 14 | /******/ } 15 | /******/ } 16 | /******/ }; 17 | /******/ })(); 18 | /******/ 19 | /******/ /* webpack/runtime/hasOwnProperty shorthand */ 20 | /******/ (() => { 21 | /******/ __nccwpck_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) 22 | /******/ })(); 23 | /******/ 24 | /******/ /* webpack/runtime/make namespace object */ 25 | /******/ (() => { 26 | /******/ // define __esModule on exports 27 | /******/ __nccwpck_require__.r = (exports) => { 28 | /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 29 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 30 | /******/ } 31 | /******/ Object.defineProperty(exports, '__esModule', { value: true }); 32 | /******/ }; 33 | /******/ })(); 34 | /******/ 35 | /******/ /* webpack/runtime/compat */ 36 | /******/ 37 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; 38 | /******/ 39 | /************************************************************************/ 40 | var __webpack_exports__ = {}; 41 | // ESM COMPAT FLAG 42 | __nccwpck_require__.r(__webpack_exports__); 43 | 44 | // EXPORTS 45 | __nccwpck_require__.d(__webpack_exports__, { 46 | test: () => (/* reexport */ test) 47 | }); 48 | 49 | ;// CONCATENATED MODULE: ./test/unit/ts-decl/test.ts 50 | function test(arg) { 51 | return arg; 52 | } 53 | 54 | ;// CONCATENATED MODULE: ./test/unit/ts-decl/input.js 55 | 56 | 57 | module.exports = __webpack_exports__; 58 | /******/ })() 59 | ; -------------------------------------------------------------------------------- /test/unit/ts-decl/output.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ "use strict"; 3 | /******/ // The require scope 4 | /******/ var __nccwpck_require__ = {}; 5 | /******/ 6 | /************************************************************************/ 7 | /******/ /* webpack/runtime/define property getters */ 8 | /******/ (() => { 9 | /******/ // define getter functions for harmony exports 10 | /******/ __nccwpck_require__.d = (exports, definition) => { 11 | /******/ for(var key in definition) { 12 | /******/ if(__nccwpck_require__.o(definition, key) && !__nccwpck_require__.o(exports, key)) { 13 | /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); 14 | /******/ } 15 | /******/ } 16 | /******/ }; 17 | /******/ })(); 18 | /******/ 19 | /******/ /* webpack/runtime/hasOwnProperty shorthand */ 20 | /******/ (() => { 21 | /******/ __nccwpck_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) 22 | /******/ })(); 23 | /******/ 24 | /******/ /* webpack/runtime/make namespace object */ 25 | /******/ (() => { 26 | /******/ // define __esModule on exports 27 | /******/ __nccwpck_require__.r = (exports) => { 28 | /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 29 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 30 | /******/ } 31 | /******/ Object.defineProperty(exports, '__esModule', { value: true }); 32 | /******/ }; 33 | /******/ })(); 34 | /******/ 35 | /******/ /* webpack/runtime/compat */ 36 | /******/ 37 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; 38 | /******/ 39 | /************************************************************************/ 40 | var __webpack_exports__ = {}; 41 | // ESM COMPAT FLAG 42 | __nccwpck_require__.r(__webpack_exports__); 43 | 44 | // EXPORTS 45 | __nccwpck_require__.d(__webpack_exports__, { 46 | test: () => (/* reexport */ test) 47 | }); 48 | 49 | ;// CONCATENATED MODULE: ./test/unit/ts-decl/test.ts 50 | function test(arg) { 51 | return arg; 52 | } 53 | 54 | ;// CONCATENATED MODULE: ./test/unit/ts-decl/input.js 55 | 56 | 57 | module.exports = __webpack_exports__; 58 | /******/ })() 59 | ; -------------------------------------------------------------------------------- /test/unit/ts-decl/test.ts: -------------------------------------------------------------------------------- 1 | export function test (arg: string): string { 2 | return arg; 3 | } -------------------------------------------------------------------------------- /test/unit/ts-decl/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "declaration": true 4 | } 5 | } -------------------------------------------------------------------------------- /test/unit/ts-exts/dep-dep.ts: -------------------------------------------------------------------------------- 1 | export default {}; 2 | -------------------------------------------------------------------------------- /test/unit/ts-exts/dep.ts: -------------------------------------------------------------------------------- 1 | export { default } from './dep-dep.js'; 2 | 3 | -------------------------------------------------------------------------------- /test/unit/ts-exts/input.ts: -------------------------------------------------------------------------------- 1 | import dep from './dep.js'; 2 | 3 | console.log(dep); 4 | -------------------------------------------------------------------------------- /test/unit/ts-exts/output-coverage.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ "use strict"; 3 | /******/ var __webpack_modules__ = ({ 4 | 5 | /***/ 585: 6 | /***/ ((__unused_webpack_module, exports) => { 7 | 8 | 9 | Object.defineProperty(exports, "__esModule", ({ value: true })); 10 | exports["default"] = {}; 11 | 12 | 13 | /***/ }), 14 | 15 | /***/ 733: 16 | /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { 17 | 18 | 19 | Object.defineProperty(exports, "__esModule", ({ value: true })); 20 | exports["default"] = void 0; 21 | var dep_dep_js_1 = __nccwpck_require__(585); 22 | Object.defineProperty(exports, "default", ({ enumerable: true, get: function () { return dep_dep_js_1.default; } })); 23 | 24 | 25 | /***/ }) 26 | 27 | /******/ }); 28 | /************************************************************************/ 29 | /******/ // The module cache 30 | /******/ var __webpack_module_cache__ = {}; 31 | /******/ 32 | /******/ // The require function 33 | /******/ function __nccwpck_require__(moduleId) { 34 | /******/ // Check if module is in cache 35 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; 36 | /******/ if (cachedModule !== undefined) { 37 | /******/ return cachedModule.exports; 38 | /******/ } 39 | /******/ // Create a new module (and put it into the cache) 40 | /******/ var module = __webpack_module_cache__[moduleId] = { 41 | /******/ // no module.id needed 42 | /******/ // no module.loaded needed 43 | /******/ exports: {} 44 | /******/ }; 45 | /******/ 46 | /******/ // Execute the module function 47 | /******/ var threw = true; 48 | /******/ try { 49 | /******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__); 50 | /******/ threw = false; 51 | /******/ } finally { 52 | /******/ if(threw) delete __webpack_module_cache__[moduleId]; 53 | /******/ } 54 | /******/ 55 | /******/ // Return the exports of the module 56 | /******/ return module.exports; 57 | /******/ } 58 | /******/ 59 | /************************************************************************/ 60 | /******/ /* webpack/runtime/compat */ 61 | /******/ 62 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; 63 | /******/ 64 | /************************************************************************/ 65 | var __webpack_exports__ = {}; 66 | // This entry need to be wrapped in an IIFE because it uses a non-standard name for the exports (exports). 67 | (() => { 68 | var exports = __webpack_exports__; 69 | 70 | Object.defineProperty(exports, "__esModule", ({ value: true })); 71 | const dep_js_1 = __nccwpck_require__(733); 72 | console.log(dep_js_1.default); 73 | 74 | })(); 75 | 76 | module.exports = __webpack_exports__; 77 | /******/ })() 78 | ; -------------------------------------------------------------------------------- /test/unit/ts-exts/output.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ "use strict"; 3 | /******/ var __webpack_modules__ = ({ 4 | 5 | /***/ 344: 6 | /***/ ((__unused_webpack_module, exports) => { 7 | 8 | 9 | Object.defineProperty(exports, "__esModule", ({ value: true })); 10 | exports["default"] = {}; 11 | 12 | 13 | /***/ }), 14 | 15 | /***/ 300: 16 | /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { 17 | 18 | 19 | Object.defineProperty(exports, "__esModule", ({ value: true })); 20 | exports["default"] = void 0; 21 | var dep_dep_js_1 = __nccwpck_require__(344); 22 | Object.defineProperty(exports, "default", ({ enumerable: true, get: function () { return dep_dep_js_1.default; } })); 23 | 24 | 25 | /***/ }) 26 | 27 | /******/ }); 28 | /************************************************************************/ 29 | /******/ // The module cache 30 | /******/ var __webpack_module_cache__ = {}; 31 | /******/ 32 | /******/ // The require function 33 | /******/ function __nccwpck_require__(moduleId) { 34 | /******/ // Check if module is in cache 35 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; 36 | /******/ if (cachedModule !== undefined) { 37 | /******/ return cachedModule.exports; 38 | /******/ } 39 | /******/ // Create a new module (and put it into the cache) 40 | /******/ var module = __webpack_module_cache__[moduleId] = { 41 | /******/ // no module.id needed 42 | /******/ // no module.loaded needed 43 | /******/ exports: {} 44 | /******/ }; 45 | /******/ 46 | /******/ // Execute the module function 47 | /******/ var threw = true; 48 | /******/ try { 49 | /******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__); 50 | /******/ threw = false; 51 | /******/ } finally { 52 | /******/ if(threw) delete __webpack_module_cache__[moduleId]; 53 | /******/ } 54 | /******/ 55 | /******/ // Return the exports of the module 56 | /******/ return module.exports; 57 | /******/ } 58 | /******/ 59 | /************************************************************************/ 60 | /******/ /* webpack/runtime/compat */ 61 | /******/ 62 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; 63 | /******/ 64 | /************************************************************************/ 65 | var __webpack_exports__ = {}; 66 | // This entry need to be wrapped in an IIFE because it uses a non-standard name for the exports (exports). 67 | (() => { 68 | var exports = __webpack_exports__; 69 | 70 | Object.defineProperty(exports, "__esModule", ({ value: true })); 71 | const dep_js_1 = __nccwpck_require__(300); 72 | console.log(dep_js_1.default); 73 | 74 | })(); 75 | 76 | module.exports = __webpack_exports__; 77 | /******/ })() 78 | ; -------------------------------------------------------------------------------- /test/unit/ts-exts/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "moduleResolution": "node", 5 | "baseUrl": ".", 6 | "incremental": true, 7 | "paths": { 8 | "@*": ["./*"] 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /test/unit/ts-mixed-modules/input.ts: -------------------------------------------------------------------------------- 1 | import { Config } from './types' 2 | 3 | const config: Config = { 4 | routes: ['/foo'] 5 | }; 6 | 7 | module.exports = config; -------------------------------------------------------------------------------- /test/unit/ts-mixed-modules/output-coverage.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ "use strict"; 3 | /******/ var __webpack_modules__ = ({ 4 | 5 | /***/ 475: 6 | /***/ ((module, exports) => { 7 | 8 | 9 | Object.defineProperty(exports, "__esModule", ({ value: true })); 10 | const config = { 11 | routes: ['/foo'] 12 | }; 13 | module.exports = config; 14 | 15 | 16 | /***/ }) 17 | 18 | /******/ }); 19 | /************************************************************************/ 20 | /******/ // The module cache 21 | /******/ var __webpack_module_cache__ = {}; 22 | /******/ 23 | /******/ // The require function 24 | /******/ function __nccwpck_require__(moduleId) { 25 | /******/ // Check if module is in cache 26 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; 27 | /******/ if (cachedModule !== undefined) { 28 | /******/ return cachedModule.exports; 29 | /******/ } 30 | /******/ // Create a new module (and put it into the cache) 31 | /******/ var module = __webpack_module_cache__[moduleId] = { 32 | /******/ // no module.id needed 33 | /******/ // no module.loaded needed 34 | /******/ exports: {} 35 | /******/ }; 36 | /******/ 37 | /******/ // Execute the module function 38 | /******/ var threw = true; 39 | /******/ try { 40 | /******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__); 41 | /******/ threw = false; 42 | /******/ } finally { 43 | /******/ if(threw) delete __webpack_module_cache__[moduleId]; 44 | /******/ } 45 | /******/ 46 | /******/ // Return the exports of the module 47 | /******/ return module.exports; 48 | /******/ } 49 | /******/ 50 | /************************************************************************/ 51 | /******/ /* webpack/runtime/compat */ 52 | /******/ 53 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; 54 | /******/ 55 | /************************************************************************/ 56 | /******/ 57 | /******/ // startup 58 | /******/ // Load entry module and return exports 59 | /******/ // This entry module is referenced by other modules so it can't be inlined 60 | /******/ var __webpack_exports__ = __nccwpck_require__(475); 61 | /******/ module.exports = __webpack_exports__; 62 | /******/ 63 | /******/ })() 64 | ; -------------------------------------------------------------------------------- /test/unit/ts-mixed-modules/output.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ "use strict"; 3 | /******/ var __webpack_modules__ = ({ 4 | 5 | /***/ 240: 6 | /***/ ((module, exports) => { 7 | 8 | 9 | Object.defineProperty(exports, "__esModule", ({ value: true })); 10 | const config = { 11 | routes: ['/foo'] 12 | }; 13 | module.exports = config; 14 | 15 | 16 | /***/ }) 17 | 18 | /******/ }); 19 | /************************************************************************/ 20 | /******/ // The module cache 21 | /******/ var __webpack_module_cache__ = {}; 22 | /******/ 23 | /******/ // The require function 24 | /******/ function __nccwpck_require__(moduleId) { 25 | /******/ // Check if module is in cache 26 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; 27 | /******/ if (cachedModule !== undefined) { 28 | /******/ return cachedModule.exports; 29 | /******/ } 30 | /******/ // Create a new module (and put it into the cache) 31 | /******/ var module = __webpack_module_cache__[moduleId] = { 32 | /******/ // no module.id needed 33 | /******/ // no module.loaded needed 34 | /******/ exports: {} 35 | /******/ }; 36 | /******/ 37 | /******/ // Execute the module function 38 | /******/ var threw = true; 39 | /******/ try { 40 | /******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__); 41 | /******/ threw = false; 42 | /******/ } finally { 43 | /******/ if(threw) delete __webpack_module_cache__[moduleId]; 44 | /******/ } 45 | /******/ 46 | /******/ // Return the exports of the module 47 | /******/ return module.exports; 48 | /******/ } 49 | /******/ 50 | /************************************************************************/ 51 | /******/ /* webpack/runtime/compat */ 52 | /******/ 53 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; 54 | /******/ 55 | /************************************************************************/ 56 | /******/ 57 | /******/ // startup 58 | /******/ // Load entry module and return exports 59 | /******/ // This entry module is referenced by other modules so it can't be inlined 60 | /******/ var __webpack_exports__ = __nccwpck_require__(240); 61 | /******/ module.exports = __webpack_exports__; 62 | /******/ 63 | /******/ })() 64 | ; -------------------------------------------------------------------------------- /test/unit/ts-mixed-modules/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": ".", 4 | "esModuleInterop": true, 5 | "lib": ["esnext"], 6 | "module": "commonjs", 7 | "moduleResolution": "node", 8 | "outDir": "dist", 9 | "strict": true, 10 | "target": "es2020" 11 | } 12 | } -------------------------------------------------------------------------------- /test/unit/ts-mixed-modules/types.ts: -------------------------------------------------------------------------------- 1 | export interface Config { 2 | routes: string[]; 3 | } -------------------------------------------------------------------------------- /test/unit/ts-target-es2018/input.ts: -------------------------------------------------------------------------------- 1 | if (process?.env.FOO) { 2 | console.log('foo'); 3 | } -------------------------------------------------------------------------------- /test/unit/ts-target-es2018/output-coverage.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ "use strict"; 3 | /******/ /* webpack/runtime/compat */ 4 | /******/ 5 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; 6 | /******/ 7 | /************************************************************************/ 8 | var __webpack_exports__ = {}; 9 | 10 | if (process === null || process === void 0 ? void 0 : process.env.FOO) { 11 | console.log('foo'); 12 | } 13 | 14 | module.exports = __webpack_exports__; 15 | /******/ })() 16 | ; -------------------------------------------------------------------------------- /test/unit/ts-target-es2018/output.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ "use strict"; 3 | /******/ /* webpack/runtime/compat */ 4 | /******/ 5 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; 6 | /******/ 7 | /************************************************************************/ 8 | var __webpack_exports__ = {}; 9 | 10 | if (process === null || process === void 0 ? void 0 : process.env.FOO) { 11 | console.log('foo'); 12 | } 13 | 14 | module.exports = __webpack_exports__; 15 | /******/ })() 16 | ; -------------------------------------------------------------------------------- /test/unit/ts-target-es2018/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "esModuleInterop": true, 4 | "lib": ["esnext"], 5 | "module": "commonjs", 6 | "moduleResolution": "node", 7 | "outDir": "dist", 8 | "strict": true, 9 | "target": "es2018" 10 | } 11 | } -------------------------------------------------------------------------------- /test/unit/tsconfig-paths-allowjs/input.ts: -------------------------------------------------------------------------------- 1 | import module from '@module'; 2 | 3 | console.log(module); 4 | -------------------------------------------------------------------------------- /test/unit/tsconfig-paths-allowjs/module.js: -------------------------------------------------------------------------------- 1 | export default {}; 2 | -------------------------------------------------------------------------------- /test/unit/tsconfig-paths-allowjs/output-coverage.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ "use strict"; 3 | /******/ var __webpack_modules__ = ({ 4 | 5 | /***/ 33: 6 | /***/ ((__unused_webpack_module, __webpack_exports__, __nccwpck_require__) => { 7 | 8 | __nccwpck_require__.r(__webpack_exports__); 9 | /* harmony export */ __nccwpck_require__.d(__webpack_exports__, { 10 | /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) 11 | /* harmony export */ }); 12 | /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({}); 13 | 14 | 15 | /***/ }) 16 | 17 | /******/ }); 18 | /************************************************************************/ 19 | /******/ // The module cache 20 | /******/ var __webpack_module_cache__ = {}; 21 | /******/ 22 | /******/ // The require function 23 | /******/ function __nccwpck_require__(moduleId) { 24 | /******/ // Check if module is in cache 25 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; 26 | /******/ if (cachedModule !== undefined) { 27 | /******/ return cachedModule.exports; 28 | /******/ } 29 | /******/ // Create a new module (and put it into the cache) 30 | /******/ var module = __webpack_module_cache__[moduleId] = { 31 | /******/ // no module.id needed 32 | /******/ // no module.loaded needed 33 | /******/ exports: {} 34 | /******/ }; 35 | /******/ 36 | /******/ // Execute the module function 37 | /******/ var threw = true; 38 | /******/ try { 39 | /******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__); 40 | /******/ threw = false; 41 | /******/ } finally { 42 | /******/ if(threw) delete __webpack_module_cache__[moduleId]; 43 | /******/ } 44 | /******/ 45 | /******/ // Return the exports of the module 46 | /******/ return module.exports; 47 | /******/ } 48 | /******/ 49 | /************************************************************************/ 50 | /******/ /* webpack/runtime/define property getters */ 51 | /******/ (() => { 52 | /******/ // define getter functions for harmony exports 53 | /******/ __nccwpck_require__.d = (exports, definition) => { 54 | /******/ for(var key in definition) { 55 | /******/ if(__nccwpck_require__.o(definition, key) && !__nccwpck_require__.o(exports, key)) { 56 | /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); 57 | /******/ } 58 | /******/ } 59 | /******/ }; 60 | /******/ })(); 61 | /******/ 62 | /******/ /* webpack/runtime/hasOwnProperty shorthand */ 63 | /******/ (() => { 64 | /******/ __nccwpck_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) 65 | /******/ })(); 66 | /******/ 67 | /******/ /* webpack/runtime/make namespace object */ 68 | /******/ (() => { 69 | /******/ // define __esModule on exports 70 | /******/ __nccwpck_require__.r = (exports) => { 71 | /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 72 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 73 | /******/ } 74 | /******/ Object.defineProperty(exports, '__esModule', { value: true }); 75 | /******/ }; 76 | /******/ })(); 77 | /******/ 78 | /******/ /* webpack/runtime/compat */ 79 | /******/ 80 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; 81 | /******/ 82 | /************************************************************************/ 83 | var __webpack_exports__ = {}; 84 | // This entry need to be wrapped in an IIFE because it uses a non-standard name for the exports (exports). 85 | (() => { 86 | var exports = __webpack_exports__; 87 | 88 | Object.defineProperty(exports, "__esModule", ({ value: true })); 89 | const _module_1 = __nccwpck_require__(33); 90 | console.log(_module_1.default); 91 | 92 | })(); 93 | 94 | module.exports = __webpack_exports__; 95 | /******/ })() 96 | ; -------------------------------------------------------------------------------- /test/unit/tsconfig-paths-allowjs/output.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ var __webpack_modules__ = ({ 3 | 4 | /***/ 651: 5 | /***/ ((module) => { 6 | 7 | module.exports = eval("require")("@module"); 8 | 9 | 10 | /***/ }) 11 | 12 | /******/ }); 13 | /************************************************************************/ 14 | /******/ // The module cache 15 | /******/ var __webpack_module_cache__ = {}; 16 | /******/ 17 | /******/ // The require function 18 | /******/ function __nccwpck_require__(moduleId) { 19 | /******/ // Check if module is in cache 20 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; 21 | /******/ if (cachedModule !== undefined) { 22 | /******/ return cachedModule.exports; 23 | /******/ } 24 | /******/ // Create a new module (and put it into the cache) 25 | /******/ var module = __webpack_module_cache__[moduleId] = { 26 | /******/ // no module.id needed 27 | /******/ // no module.loaded needed 28 | /******/ exports: {} 29 | /******/ }; 30 | /******/ 31 | /******/ // Execute the module function 32 | /******/ var threw = true; 33 | /******/ try { 34 | /******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__); 35 | /******/ threw = false; 36 | /******/ } finally { 37 | /******/ if(threw) delete __webpack_module_cache__[moduleId]; 38 | /******/ } 39 | /******/ 40 | /******/ // Return the exports of the module 41 | /******/ return module.exports; 42 | /******/ } 43 | /******/ 44 | /************************************************************************/ 45 | /******/ /* webpack/runtime/compat */ 46 | /******/ 47 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; 48 | /******/ 49 | /************************************************************************/ 50 | var __webpack_exports__ = {}; 51 | // This entry need to be wrapped in an IIFE because it need to be in strict mode. 52 | (() => { 53 | "use strict"; 54 | var exports = __webpack_exports__; 55 | 56 | Object.defineProperty(exports, "__esModule", ({ value: true })); 57 | const _module_1 = __nccwpck_require__(651); 58 | console.log(_module_1.default); 59 | 60 | })(); 61 | 62 | module.exports = __webpack_exports__; 63 | /******/ })() 64 | ; -------------------------------------------------------------------------------- /test/unit/tsconfig-paths-allowjs/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "moduleResolution": "node", 5 | "baseUrl": ".", 6 | "paths": { 7 | "@*": ["./*"] 8 | }, 9 | "allowJs": true 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /test/unit/tsconfig-paths-array-extends/input.ts: -------------------------------------------------------------------------------- 1 | import module from '@module'; 2 | 3 | console.log(module); 4 | -------------------------------------------------------------------------------- /test/unit/tsconfig-paths-array-extends/module.js: -------------------------------------------------------------------------------- 1 | export default {}; 2 | -------------------------------------------------------------------------------- /test/unit/tsconfig-paths-array-extends/output-coverage.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ "use strict"; 3 | /******/ var __webpack_modules__ = ({ 4 | 5 | /***/ 424: 6 | /***/ ((__unused_webpack_module, __webpack_exports__, __nccwpck_require__) => { 7 | 8 | __nccwpck_require__.r(__webpack_exports__); 9 | /* harmony export */ __nccwpck_require__.d(__webpack_exports__, { 10 | /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) 11 | /* harmony export */ }); 12 | /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({}); 13 | 14 | 15 | /***/ }) 16 | 17 | /******/ }); 18 | /************************************************************************/ 19 | /******/ // The module cache 20 | /******/ var __webpack_module_cache__ = {}; 21 | /******/ 22 | /******/ // The require function 23 | /******/ function __nccwpck_require__(moduleId) { 24 | /******/ // Check if module is in cache 25 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; 26 | /******/ if (cachedModule !== undefined) { 27 | /******/ return cachedModule.exports; 28 | /******/ } 29 | /******/ // Create a new module (and put it into the cache) 30 | /******/ var module = __webpack_module_cache__[moduleId] = { 31 | /******/ // no module.id needed 32 | /******/ // no module.loaded needed 33 | /******/ exports: {} 34 | /******/ }; 35 | /******/ 36 | /******/ // Execute the module function 37 | /******/ var threw = true; 38 | /******/ try { 39 | /******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__); 40 | /******/ threw = false; 41 | /******/ } finally { 42 | /******/ if(threw) delete __webpack_module_cache__[moduleId]; 43 | /******/ } 44 | /******/ 45 | /******/ // Return the exports of the module 46 | /******/ return module.exports; 47 | /******/ } 48 | /******/ 49 | /************************************************************************/ 50 | /******/ /* webpack/runtime/define property getters */ 51 | /******/ (() => { 52 | /******/ // define getter functions for harmony exports 53 | /******/ __nccwpck_require__.d = (exports, definition) => { 54 | /******/ for(var key in definition) { 55 | /******/ if(__nccwpck_require__.o(definition, key) && !__nccwpck_require__.o(exports, key)) { 56 | /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); 57 | /******/ } 58 | /******/ } 59 | /******/ }; 60 | /******/ })(); 61 | /******/ 62 | /******/ /* webpack/runtime/hasOwnProperty shorthand */ 63 | /******/ (() => { 64 | /******/ __nccwpck_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) 65 | /******/ })(); 66 | /******/ 67 | /******/ /* webpack/runtime/make namespace object */ 68 | /******/ (() => { 69 | /******/ // define __esModule on exports 70 | /******/ __nccwpck_require__.r = (exports) => { 71 | /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 72 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 73 | /******/ } 74 | /******/ Object.defineProperty(exports, '__esModule', { value: true }); 75 | /******/ }; 76 | /******/ })(); 77 | /******/ 78 | /******/ /* webpack/runtime/compat */ 79 | /******/ 80 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; 81 | /******/ 82 | /************************************************************************/ 83 | var __webpack_exports__ = {}; 84 | // This entry need to be wrapped in an IIFE because it uses a non-standard name for the exports (exports). 85 | (() => { 86 | var exports = __webpack_exports__; 87 | 88 | Object.defineProperty(exports, "__esModule", ({ value: true })); 89 | const _module_1 = __nccwpck_require__(424); 90 | console.log(_module_1.default); 91 | 92 | })(); 93 | 94 | module.exports = __webpack_exports__; 95 | /******/ })() 96 | ; -------------------------------------------------------------------------------- /test/unit/tsconfig-paths-array-extends/output.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ var __webpack_modules__ = ({ 3 | 4 | /***/ 651: 5 | /***/ ((module) => { 6 | 7 | module.exports = eval("require")("@module"); 8 | 9 | 10 | /***/ }) 11 | 12 | /******/ }); 13 | /************************************************************************/ 14 | /******/ // The module cache 15 | /******/ var __webpack_module_cache__ = {}; 16 | /******/ 17 | /******/ // The require function 18 | /******/ function __nccwpck_require__(moduleId) { 19 | /******/ // Check if module is in cache 20 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; 21 | /******/ if (cachedModule !== undefined) { 22 | /******/ return cachedModule.exports; 23 | /******/ } 24 | /******/ // Create a new module (and put it into the cache) 25 | /******/ var module = __webpack_module_cache__[moduleId] = { 26 | /******/ // no module.id needed 27 | /******/ // no module.loaded needed 28 | /******/ exports: {} 29 | /******/ }; 30 | /******/ 31 | /******/ // Execute the module function 32 | /******/ var threw = true; 33 | /******/ try { 34 | /******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__); 35 | /******/ threw = false; 36 | /******/ } finally { 37 | /******/ if(threw) delete __webpack_module_cache__[moduleId]; 38 | /******/ } 39 | /******/ 40 | /******/ // Return the exports of the module 41 | /******/ return module.exports; 42 | /******/ } 43 | /******/ 44 | /************************************************************************/ 45 | /******/ /* webpack/runtime/compat */ 46 | /******/ 47 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; 48 | /******/ 49 | /************************************************************************/ 50 | var __webpack_exports__ = {}; 51 | // This entry need to be wrapped in an IIFE because it need to be in strict mode. 52 | (() => { 53 | "use strict"; 54 | var exports = __webpack_exports__; 55 | 56 | Object.defineProperty(exports, "__esModule", ({ value: true })); 57 | const _module_1 = __nccwpck_require__(651); 58 | console.log(_module_1.default); 59 | 60 | })(); 61 | 62 | module.exports = __webpack_exports__; 63 | /******/ })() 64 | ; -------------------------------------------------------------------------------- /test/unit/tsconfig-paths-array-extends/tsconfig.a.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "allowJs": false 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /test/unit/tsconfig-paths-array-extends/tsconfig.b.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": ".", 4 | "paths": { 5 | "@*": ["./*"] 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /test/unit/tsconfig-paths-array-extends/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["./tsconfig.a.json", "./tsconfig.b.json"], 3 | "compilerOptions": { 4 | "module": "commonjs", 5 | "moduleResolution": "node", 6 | "allowJs": true 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /test/unit/tsconfig-paths-conflicting-external/input.ts: -------------------------------------------------------------------------------- 1 | import module from "@module"; 2 | // this matches the pattern specified in tsconfig, 3 | // but it should use the external module instead of erroring 4 | import * as _ from "@sentry/node"; 5 | 6 | console.log(module); 7 | -------------------------------------------------------------------------------- /test/unit/tsconfig-paths-conflicting-external/module.ts: -------------------------------------------------------------------------------- 1 | export default {}; 2 | -------------------------------------------------------------------------------- /test/unit/tsconfig-paths-conflicting-external/output-coverage.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ "use strict"; 3 | /******/ var __webpack_modules__ = ({ 4 | 5 | /***/ 747: 6 | /***/ ((__unused_webpack_module, exports) => { 7 | 8 | 9 | Object.defineProperty(exports, "__esModule", ({ value: true })); 10 | exports["default"] = {}; 11 | 12 | 13 | /***/ }) 14 | 15 | /******/ }); 16 | /************************************************************************/ 17 | /******/ // The module cache 18 | /******/ var __webpack_module_cache__ = {}; 19 | /******/ 20 | /******/ // The require function 21 | /******/ function __nccwpck_require__(moduleId) { 22 | /******/ // Check if module is in cache 23 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; 24 | /******/ if (cachedModule !== undefined) { 25 | /******/ return cachedModule.exports; 26 | /******/ } 27 | /******/ // Create a new module (and put it into the cache) 28 | /******/ var module = __webpack_module_cache__[moduleId] = { 29 | /******/ // no module.id needed 30 | /******/ // no module.loaded needed 31 | /******/ exports: {} 32 | /******/ }; 33 | /******/ 34 | /******/ // Execute the module function 35 | /******/ var threw = true; 36 | /******/ try { 37 | /******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__); 38 | /******/ threw = false; 39 | /******/ } finally { 40 | /******/ if(threw) delete __webpack_module_cache__[moduleId]; 41 | /******/ } 42 | /******/ 43 | /******/ // Return the exports of the module 44 | /******/ return module.exports; 45 | /******/ } 46 | /******/ 47 | /************************************************************************/ 48 | /******/ /* webpack/runtime/compat */ 49 | /******/ 50 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; 51 | /******/ 52 | /************************************************************************/ 53 | var __webpack_exports__ = {}; 54 | // This entry need to be wrapped in an IIFE because it uses a non-standard name for the exports (exports). 55 | (() => { 56 | var exports = __webpack_exports__; 57 | 58 | Object.defineProperty(exports, "__esModule", ({ value: true })); 59 | const _module_1 = __nccwpck_require__(747); 60 | console.log(_module_1.default); 61 | 62 | })(); 63 | 64 | module.exports = __webpack_exports__; 65 | /******/ })() 66 | ; -------------------------------------------------------------------------------- /test/unit/tsconfig-paths-conflicting-external/output.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ var __webpack_modules__ = ({ 3 | 4 | /***/ 651: 5 | /***/ ((module) => { 6 | 7 | module.exports = eval("require")("@module"); 8 | 9 | 10 | /***/ }) 11 | 12 | /******/ }); 13 | /************************************************************************/ 14 | /******/ // The module cache 15 | /******/ var __webpack_module_cache__ = {}; 16 | /******/ 17 | /******/ // The require function 18 | /******/ function __nccwpck_require__(moduleId) { 19 | /******/ // Check if module is in cache 20 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; 21 | /******/ if (cachedModule !== undefined) { 22 | /******/ return cachedModule.exports; 23 | /******/ } 24 | /******/ // Create a new module (and put it into the cache) 25 | /******/ var module = __webpack_module_cache__[moduleId] = { 26 | /******/ // no module.id needed 27 | /******/ // no module.loaded needed 28 | /******/ exports: {} 29 | /******/ }; 30 | /******/ 31 | /******/ // Execute the module function 32 | /******/ var threw = true; 33 | /******/ try { 34 | /******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__); 35 | /******/ threw = false; 36 | /******/ } finally { 37 | /******/ if(threw) delete __webpack_module_cache__[moduleId]; 38 | /******/ } 39 | /******/ 40 | /******/ // Return the exports of the module 41 | /******/ return module.exports; 42 | /******/ } 43 | /******/ 44 | /************************************************************************/ 45 | /******/ /* webpack/runtime/compat */ 46 | /******/ 47 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; 48 | /******/ 49 | /************************************************************************/ 50 | var __webpack_exports__ = {}; 51 | // This entry need to be wrapped in an IIFE because it need to be in strict mode. 52 | (() => { 53 | "use strict"; 54 | var exports = __webpack_exports__; 55 | 56 | Object.defineProperty(exports, "__esModule", ({ value: true })); 57 | const _module_1 = __nccwpck_require__(651); 58 | console.log(_module_1.default); 59 | 60 | })(); 61 | 62 | module.exports = __webpack_exports__; 63 | /******/ })() 64 | ; -------------------------------------------------------------------------------- /test/unit/tsconfig-paths-conflicting-external/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "moduleResolution": "node", 5 | "baseUrl": ".", 6 | "paths": { 7 | "@*": ["./*"] 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/unit/tsconfig-paths/input.ts: -------------------------------------------------------------------------------- 1 | import module from "@module"; 2 | 3 | console.log(module); 4 | -------------------------------------------------------------------------------- /test/unit/tsconfig-paths/module.ts: -------------------------------------------------------------------------------- 1 | export default {}; 2 | -------------------------------------------------------------------------------- /test/unit/tsconfig-paths/output-coverage.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ "use strict"; 3 | /******/ var __webpack_modules__ = ({ 4 | 5 | /***/ 584: 6 | /***/ ((__unused_webpack_module, exports) => { 7 | 8 | 9 | Object.defineProperty(exports, "__esModule", ({ value: true })); 10 | exports["default"] = {}; 11 | 12 | 13 | /***/ }) 14 | 15 | /******/ }); 16 | /************************************************************************/ 17 | /******/ // The module cache 18 | /******/ var __webpack_module_cache__ = {}; 19 | /******/ 20 | /******/ // The require function 21 | /******/ function __nccwpck_require__(moduleId) { 22 | /******/ // Check if module is in cache 23 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; 24 | /******/ if (cachedModule !== undefined) { 25 | /******/ return cachedModule.exports; 26 | /******/ } 27 | /******/ // Create a new module (and put it into the cache) 28 | /******/ var module = __webpack_module_cache__[moduleId] = { 29 | /******/ // no module.id needed 30 | /******/ // no module.loaded needed 31 | /******/ exports: {} 32 | /******/ }; 33 | /******/ 34 | /******/ // Execute the module function 35 | /******/ var threw = true; 36 | /******/ try { 37 | /******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__); 38 | /******/ threw = false; 39 | /******/ } finally { 40 | /******/ if(threw) delete __webpack_module_cache__[moduleId]; 41 | /******/ } 42 | /******/ 43 | /******/ // Return the exports of the module 44 | /******/ return module.exports; 45 | /******/ } 46 | /******/ 47 | /************************************************************************/ 48 | /******/ /* webpack/runtime/compat */ 49 | /******/ 50 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; 51 | /******/ 52 | /************************************************************************/ 53 | var __webpack_exports__ = {}; 54 | // This entry need to be wrapped in an IIFE because it uses a non-standard name for the exports (exports). 55 | (() => { 56 | var exports = __webpack_exports__; 57 | 58 | Object.defineProperty(exports, "__esModule", ({ value: true })); 59 | const _module_1 = __nccwpck_require__(584); 60 | console.log(_module_1.default); 61 | 62 | })(); 63 | 64 | module.exports = __webpack_exports__; 65 | /******/ })() 66 | ; -------------------------------------------------------------------------------- /test/unit/tsconfig-paths/output.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ var __webpack_modules__ = ({ 3 | 4 | /***/ 651: 5 | /***/ ((module) => { 6 | 7 | module.exports = eval("require")("@module"); 8 | 9 | 10 | /***/ }) 11 | 12 | /******/ }); 13 | /************************************************************************/ 14 | /******/ // The module cache 15 | /******/ var __webpack_module_cache__ = {}; 16 | /******/ 17 | /******/ // The require function 18 | /******/ function __nccwpck_require__(moduleId) { 19 | /******/ // Check if module is in cache 20 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; 21 | /******/ if (cachedModule !== undefined) { 22 | /******/ return cachedModule.exports; 23 | /******/ } 24 | /******/ // Create a new module (and put it into the cache) 25 | /******/ var module = __webpack_module_cache__[moduleId] = { 26 | /******/ // no module.id needed 27 | /******/ // no module.loaded needed 28 | /******/ exports: {} 29 | /******/ }; 30 | /******/ 31 | /******/ // Execute the module function 32 | /******/ var threw = true; 33 | /******/ try { 34 | /******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__); 35 | /******/ threw = false; 36 | /******/ } finally { 37 | /******/ if(threw) delete __webpack_module_cache__[moduleId]; 38 | /******/ } 39 | /******/ 40 | /******/ // Return the exports of the module 41 | /******/ return module.exports; 42 | /******/ } 43 | /******/ 44 | /************************************************************************/ 45 | /******/ /* webpack/runtime/compat */ 46 | /******/ 47 | /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; 48 | /******/ 49 | /************************************************************************/ 50 | var __webpack_exports__ = {}; 51 | // This entry need to be wrapped in an IIFE because it need to be in strict mode. 52 | (() => { 53 | "use strict"; 54 | var exports = __webpack_exports__; 55 | 56 | Object.defineProperty(exports, "__esModule", ({ value: true })); 57 | const _module_1 = __nccwpck_require__(651); 58 | console.log(_module_1.default); 59 | 60 | })(); 61 | 62 | module.exports = __webpack_exports__; 63 | /******/ })() 64 | ; -------------------------------------------------------------------------------- /test/unit/tsconfig-paths/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "moduleResolution": "node", 5 | "baseUrl": ".", 6 | "paths": { 7 | "@*": ["./*"] 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/watcher.test.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const ncc = global.coverage ? require("../src/index") : require("../"); 3 | const fs = require('fs'); 4 | 5 | // Based on the NodeWatchFileSystem class at: 6 | // - https://github.com/webpack/webpack/blob/master/lib/node/NodeWatchFileSystem.js 7 | // which in turn exposes: 8 | // - https://www.npmjs.com/package/watchpack 9 | 10 | class CustomWatchFileSystem { 11 | constructor(watchStart, watchEnd) { 12 | this.closed = false; 13 | // paused allows the watchers to stay open for the next build 14 | this.paused = false; 15 | this.changeCallback = undefined; 16 | this.changeCallbackUndelayed = undefined; 17 | this.watchStart = watchStart; 18 | this.watchEnd = watchEnd; 19 | 20 | // Webpack requires us to track this stuff 21 | this.files = undefined; 22 | this.dirs = undefined; 23 | this.missing = undefined; 24 | this.timestamps = new Map(); 25 | this.changes = new Set(); 26 | this.removals = new Set(); 27 | 28 | // this will be populated for us by ncc 29 | this.inputFileSystem = undefined; 30 | } 31 | 32 | triggerChanges (changed, removed) { 33 | if (!this.paused) { 34 | const newTime = +Date.now(); 35 | for (const file of changed) 36 | this.timestamps.set(file, { 37 | safeTime: newTime + 10, 38 | accuracy: 10, 39 | timestamp: newTime 40 | }); 41 | for (const file of removed) 42 | this.timestamps.set(file, null); 43 | 44 | for (const file of changed) { 45 | this.changes.add(file); 46 | this.inputFileSystem.purge(file); 47 | } 48 | for (const file of removed) { 49 | this.removals.add(file); 50 | this.inputFileSystem.purge(file); 51 | } 52 | 53 | this.changeCallbackUndelayed( 54 | null, 55 | this.timestamps, 56 | this.timestamps, 57 | removed 58 | ); 59 | this.changeCallback( 60 | null, 61 | this.timestamps, 62 | this.timestamps, 63 | removed 64 | ); 65 | } 66 | } 67 | 68 | // This is called on every rebuild 69 | watch (files, dirs, missing, startTime, options, changeCallback, changeCallbackUndelayed) { 70 | this.files = new Set(files); 71 | this.dirs = new Set(dirs); 72 | this.missing = new Set(missing); 73 | 74 | // empty object indicates "unknown" timestamp 75 | // (that is, not cached) 76 | for (const item of files) 77 | this.timestamps.set(item, {}); 78 | for (const item of dirs) 79 | this.timestamps.set(item, {}); 80 | // null represents "no file" 81 | for (const item of missing) 82 | this.timestamps.set(item, null); 83 | 84 | this.paused = false; 85 | this.changeCallback = changeCallback; 86 | this.changeCallbackUndelayed = changeCallbackUndelayed; 87 | 88 | // ...Start watching files, dirs, missing 89 | setImmediate(() => { 90 | this.watchStart(files, dirs, missing); 91 | }); 92 | 93 | return { 94 | close: () => { 95 | this.watchEnd(); 96 | }, 97 | pause: () => { 98 | this.paused = true; 99 | }, 100 | getInfo: () => ({ 101 | changes: this.changes, 102 | removals: this.removals, 103 | fileTimeInfoEntries: this.timestamps, 104 | contextTimeInfoEntries: this.timestamps, 105 | }), 106 | }; 107 | } 108 | } 109 | 110 | jest.setTimeout(30000); 111 | 112 | it('Should support custom watch API', async () => { 113 | let buildCnt = 0; 114 | const buildFile = path.resolve('./test/integration/twilio.js'); 115 | const initialBuildFileContents = fs.readFileSync(buildFile).toString(); 116 | 117 | await new Promise((resolve, reject) => { 118 | const watcher = new CustomWatchFileSystem(function watchStart (files, dirs, missing) { 119 | expect(files._set.size).toBeGreaterThan(100); 120 | if (buildCnt < 3) { 121 | setTimeout(() => { 122 | // NOTE: We actually have to make the change for the rebuild to happen! 123 | fs.writeFileSync(buildFile, fs.readFileSync(buildFile).toString() + '\n'); 124 | watcher.triggerChanges([buildFile], []); 125 | }, 100); 126 | } 127 | }, function watchEnd () { 128 | resolve(); 129 | }); 130 | 131 | console.time('First Build'); 132 | const { handler, rebuild, close } = ncc(buildFile, { 133 | assetBuilds: true, 134 | watch: watcher 135 | }); 136 | 137 | handler(({ err, code, map, assets, permissions }) => { 138 | if (err) return reject(err); 139 | buildCnt++; 140 | if (buildCnt === 1) { 141 | console.timeEnd('First Build'); 142 | } 143 | else { 144 | console.timeEnd('Watched Build'); 145 | } 146 | if (buildCnt === 3) { 147 | close(); 148 | fs.writeFileSync(buildFile, fs.readFileSync(buildFile).toString().slice(0, -2)); 149 | } 150 | }); 151 | rebuild(() => { 152 | console.time('Watched Build'); 153 | }); 154 | }); 155 | 156 | fs.writeFileSync(buildFile, initialBuildFileContents); 157 | }); 158 | 159 | -------------------------------------------------------------------------------- /update-fixtures.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | yarn run build 4 | 5 | node_modules/.bin/jest test/unit 6 | 7 | for f in test/unit/*; do 8 | if [ -e "${f}/actual.js" ]; then 9 | mv "${f}/actual.js" "${f}/output.js" 10 | fi 11 | done 12 | 13 | for f in test/unit/*; do 14 | if [ -e "${f}/actual.js.map" ]; then 15 | mv "${f}/actual.js.map" "${f}/output.js.map" 16 | fi 17 | done 18 | 19 | node --expose-gc node_modules/.bin/jest --coverage --globals "{\"coverage\":true}" test/unit 20 | 21 | for f in test/unit/*; do 22 | if [ -e "${f}/actual.js" ]; then 23 | mv "${f}/actual.js" "${f}/output-coverage.js" 24 | fi 25 | done 26 | 27 | for f in test/unit/*; do 28 | if [ -e "${f}/actual.js.map" ]; then 29 | mv "${f}/actual.js.map" "${f}/output-coverage.js.map" 30 | fi 31 | done 32 | --------------------------------------------------------------------------------