├── .codecov.yml ├── .editorconfig ├── .gitattributes ├── .github └── workflows │ ├── checks.yml │ ├── on-pull-request.yml │ ├── on-push-to-base-branch.yml │ └── on-release.yml ├── .gitignore ├── .husky ├── .gitignore ├── commit-msg ├── pre-commit └── pre-push ├── .npmrc ├── .nvmrc ├── CHANGELOG.md ├── LICENSE ├── Makefile ├── README.md ├── SECURITY.md ├── _config.yml ├── bin ├── publish └── server ├── docs └── images │ ├── logo-apollo.png │ ├── logo-facebook.png │ ├── logo-graphql-request.png │ ├── logo-nytimes.png │ ├── logo-swagger.png │ └── logo-vulcanjs.png ├── examples ├── browser │ ├── .npmrc │ ├── index.js │ ├── package.json │ └── puppeteer.js ├── cloud-worker │ ├── .npmrc │ ├── package.json │ ├── src │ │ └── index.js │ └── wrangler.toml ├── node │ ├── .npmrc │ ├── index.js │ ├── package.json │ └── server.js ├── reactnative │ ├── .buckconfig │ ├── .gitignore │ ├── .watchmanconfig │ ├── android │ │ ├── app │ │ │ ├── BUCK │ │ │ ├── build.gradle │ │ │ ├── build_defs.bzl │ │ │ ├── proguard-rules.pro │ │ │ └── src │ │ │ │ ├── debug │ │ │ │ └── AndroidManifest.xml │ │ │ │ └── main │ │ │ │ ├── AndroidManifest.xml │ │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── reactnative │ │ │ │ │ ├── MainActivity.java │ │ │ │ │ └── MainApplication.java │ │ │ │ └── res │ │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ └── values │ │ │ │ ├── strings.xml │ │ │ │ └── styles.xml │ │ ├── build.gradle │ │ ├── gradle.properties │ │ ├── gradle │ │ │ └── wrapper │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ └── settings.gradle │ ├── app.json │ ├── babel.config.js │ ├── components │ │ ├── home.js │ │ ├── poly-page.js │ │ └── pony-page.js │ ├── index.js │ ├── ios │ │ ├── Podfile │ │ ├── Podfile.lock │ │ ├── reactnative-tvOS │ │ │ └── Info.plist │ │ ├── reactnative-tvOSTests │ │ │ └── Info.plist │ │ ├── reactnative.xcodeproj │ │ │ ├── project.pbxproj │ │ │ └── xcshareddata │ │ │ │ └── xcschemes │ │ │ │ ├── reactnative-tvOS.xcscheme │ │ │ │ └── reactnative.xcscheme │ │ ├── reactnative.xcworkspace │ │ │ └── contents.xcworkspacedata │ │ ├── reactnative │ │ │ ├── AppDelegate.h │ │ │ ├── AppDelegate.m │ │ │ ├── Base.lproj │ │ │ │ └── LaunchScreen.xib │ │ │ ├── Images.xcassets │ │ │ │ ├── AppIcon.appiconset │ │ │ │ │ └── Contents.json │ │ │ │ └── Contents.json │ │ │ ├── Info.plist │ │ │ └── main.m │ │ └── reactnativeTests │ │ │ ├── Info.plist │ │ │ └── reactnativeTests.m │ ├── metro.config.js │ └── package.json └── typescript │ ├── .npmrc │ ├── index.ts │ ├── package.json │ └── tsconfig.json ├── index.d.ts ├── package.json ├── polyfill └── package.json ├── rollup.config.js ├── src ├── node-polyfill.js ├── node-ponyfill.js ├── react-native-polyfill.js └── react-native-ponyfill.js ├── test ├── fetch-api │ ├── api.spec.js │ ├── api.spec.ts │ ├── browser │ │ ├── index.html │ │ └── run.sh │ ├── index.html │ ├── node-fetch │ │ ├── index.js │ │ └── run.sh │ ├── node │ │ ├── index.js │ │ └── run.sh │ ├── service-worker │ │ ├── index.html │ │ ├── run.sh │ │ ├── sw.js │ │ ├── sw.reporter.js │ │ └── webpack.config.js │ └── whatwg │ │ ├── index.html │ │ └── run.sh ├── module-system │ ├── module.spec.js │ ├── node.cjs │ │ ├── polyfill.js │ │ ├── ponyfill.js │ │ ├── run.sh │ │ └── webpack.config.js │ ├── node.esm │ │ ├── polyfill.js │ │ ├── ponyfill.js │ │ ├── run.sh │ │ └── webpack.config.js │ ├── react-native │ │ ├── index.js │ │ └── run.sh │ ├── web.cjs │ │ ├── polyfill.html │ │ ├── polyfill.js │ │ ├── ponyfill.html │ │ ├── ponyfill.js │ │ ├── run.sh │ │ └── webpack.config.js │ └── web.esm │ │ ├── polyfill.html │ │ ├── polyfill.js │ │ ├── ponyfill.html │ │ ├── ponyfill.js │ │ ├── run.sh │ │ └── webpack.config.js └── setup │ ├── browser.env.js │ ├── node.env.js │ └── server.sh └── tsconfig.json /.codecov.yml: -------------------------------------------------------------------------------- 1 | comment: off 2 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # top-most EditorConfig file 2 | root = true 3 | 4 | # Unix-style newlines with a newline ending every file 5 | [*] 6 | charset = utf-8 7 | end_of_line = lf 8 | insert_final_newline = true 9 | indent_style = space 10 | indent_size = 2 11 | trim_trailing_whitespace = true 12 | 13 | [*.md] 14 | trim_trailing_whitespace = false 15 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text 2 | dist/** -diff -merge 3 | dist/** linguist-generated=true 4 | -------------------------------------------------------------------------------- /.github/workflows/checks.yml: -------------------------------------------------------------------------------- 1 | name: v4.x checks 2 | 3 | on: 4 | workflow_call: 5 | inputs: 6 | ref: 7 | description: 'The commit the workflow should check out' 8 | required: true 9 | default: ${{ github.sha }} 10 | type: string 11 | 12 | jobs: 13 | test-node: 14 | name: Node Test Specs 15 | runs-on: ubuntu-latest 16 | strategy: 17 | fail-fast: false 18 | matrix: 19 | node-version: [14.x, 16.x, 18.x, 20.x, 22.x] 20 | # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ 21 | steps: 22 | - uses: actions/checkout@v4 23 | with: 24 | ref: ${{ inputs.ref }} 25 | - uses: actions/cache@v4 26 | with: 27 | path: ~/.npm # this is cache where npm installs from before going out to the network 28 | key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }} 29 | - name: Use Node.js ${{ matrix.node-version }} 30 | uses: actions/setup-node@v4 31 | with: 32 | node-version: ${{ matrix.node-version }} 33 | - run: npm install --prefer-offline 34 | - run: make test-node 35 | 36 | test-browser: 37 | name: Browser Test Specs 38 | runs-on: ubuntu-latest 39 | steps: 40 | - uses: actions/checkout@v4 41 | with: 42 | ref: ${{ inputs.ref }} 43 | - uses: actions/cache@v4 44 | with: 45 | path: ~/.npm # this is cache where npm installs from before going out to the network 46 | key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }} 47 | - run: npm install --prefer-offline 48 | - run: make test-browser 49 | 50 | lint: 51 | name: Code Lint 52 | runs-on: ubuntu-latest 53 | steps: 54 | - uses: actions/checkout@v4 55 | with: 56 | ref: ${{ inputs.ref }} 57 | - uses: actions/cache@v4 58 | with: 59 | path: ~/.npm # this is cache where npm installs from before going out to the network 60 | key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }} 61 | - run: npm install --prefer-offline 62 | - run: make lint 63 | 64 | typecheck: 65 | name: Types 66 | runs-on: ubuntu-latest 67 | steps: 68 | - uses: actions/checkout@v4 69 | with: 70 | ref: ${{ inputs.ref }} 71 | - uses: actions/cache@v4 72 | with: 73 | path: ~/.npm # this is cache where npm installs from before going out to the network 74 | key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }} 75 | - run: npm install --prefer-offline 76 | - run: make typecheck 77 | -------------------------------------------------------------------------------- /.github/workflows/on-pull-request.yml: -------------------------------------------------------------------------------- 1 | name: v4.x pull requests 2 | 3 | on: 4 | pull_request_target: 5 | types: 6 | - opened 7 | - edited 8 | - synchronize 9 | branches: 10 | - v4.x 11 | 12 | jobs: 13 | prlint: 14 | name: Validate PR title 15 | runs-on: ubuntu-latest 16 | steps: 17 | - uses: amannn/action-semantic-pull-request@v4 18 | env: 19 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 20 | 21 | debug: 22 | name: Debug 23 | runs-on: ubuntu-latest 24 | steps: 25 | - uses: hmarr/debug-action@v3 26 | 27 | install: 28 | name: Install 29 | runs-on: ubuntu-latest 30 | steps: 31 | - uses: actions/checkout@v4 32 | with: 33 | ref: ${{ github.event.pull_request.head.sha }} 34 | - name: Cache node_modules 35 | id: cacheModules 36 | uses: actions/cache@v4 37 | with: 38 | path: ~/.npm # this is cache where npm installs from before going out to the network 39 | key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }} 40 | - name: Install dependencies 41 | if: steps.cacheModules.outputs.cache-hit != 'true' 42 | run: npm install 43 | 44 | checks: 45 | name: Checks 46 | needs: [install] 47 | uses: ./.github/workflows/checks.yml 48 | with: 49 | ref: ${{ github.event.pull_request.head.sha }} 50 | -------------------------------------------------------------------------------- /.github/workflows/on-push-to-base-branch.yml: -------------------------------------------------------------------------------- 1 | name: v4.x branch 2 | 3 | on: 4 | push: 5 | branches: 6 | - v4.x 7 | 8 | jobs: 9 | install: 10 | name: Install 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v4 14 | - name: Cache node_modules 15 | id: cacheModules 16 | uses: actions/cache@v4 17 | with: 18 | path: ~/.npm # this is cache where npm installs from before going out to the network 19 | key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }} 20 | - name: Install dependencies 21 | if: steps.cacheModules.outputs.cache-hit != 'true' 22 | run: npm install 23 | 24 | debug: 25 | name: Debug 26 | runs-on: ubuntu-latest 27 | steps: 28 | - uses: hmarr/debug-action@v3 29 | 30 | checks: 31 | name: Check 32 | needs: [install] 33 | uses: ./.github/workflows/checks.yml 34 | with: 35 | ref: ${{ github.sha }} 36 | 37 | # The security job can't run on pull requests opened from forks because 38 | # Github doesn't pass down the SNYK_TOKEN environment variable. 39 | security: 40 | name: Check Security 41 | needs: [install] 42 | runs-on: ubuntu-latest 43 | steps: 44 | - uses: actions/checkout@v4 45 | - uses: actions/cache@v4 46 | with: 47 | path: ~/.npm # this is cache where npm installs from before going out to the network 48 | key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }} 49 | - run: npm install --prefer-offline 50 | - run: make secure 51 | env: 52 | SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} 53 | -------------------------------------------------------------------------------- /.github/workflows/on-release.yml: -------------------------------------------------------------------------------- 1 | # Note: The cache steps on this workflow has been removed Supply Chain attack through GitHub Action Pwn Request. 2 | # Here's more info on how that works: https://adnanthekhan.com/2024/05/06/the-monsters-in-your-build-cache-github-actions-cache-poisoning/ 3 | name: v4.x releases 4 | 5 | on: 6 | push: 7 | branches: 8 | # Pushes to the branch below will test the release workflow without 9 | # publishing version on npm or generating new git tags 10 | - v4.x-test 11 | tags: 12 | - 'v4.[0-9]+.[0-9]+' 13 | - 'v4.[0-9]+.[0-9]+-alpha.[0-9]+' 14 | - 'v4.[0-9]+.[0-9]+-beta.[0-9]+' 15 | 16 | jobs: 17 | debug: 18 | name: Debug 19 | runs-on: ubuntu-latest 20 | steps: 21 | - uses: hmarr/debug-action@v3 22 | 23 | test-node: 24 | name: Node Test Specs 25 | runs-on: ubuntu-latest 26 | strategy: 27 | fail-fast: false 28 | matrix: 29 | node-version: [14.x, 16.x, 18.x, 20.x, 22.x] 30 | # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ 31 | steps: 32 | - uses: actions/checkout@v4 33 | - name: Use Node.js ${{ matrix.node-version }} 34 | uses: actions/setup-node@v4 35 | with: 36 | node-version: ${{ matrix.node-version }} 37 | - run: npm install --prefer-offline 38 | - run: make test-node 39 | 40 | test-browser: 41 | name: Browser Test Specs 42 | runs-on: ubuntu-latest 43 | steps: 44 | - uses: actions/checkout@v4 45 | - run: npm install --prefer-offline 46 | - run: make test-browser 47 | 48 | lint: 49 | name: Code Lint 50 | runs-on: ubuntu-latest 51 | steps: 52 | - uses: actions/checkout@v4 53 | - run: npm install --prefer-offline 54 | - run: make lint 55 | 56 | typecheck: 57 | name: Types 58 | runs-on: ubuntu-latest 59 | steps: 60 | - uses: actions/checkout@v4 61 | - run: npm install --prefer-offline 62 | - run: make typecheck 63 | 64 | # The security job can't run on pull requests opened from forks because 65 | # Github doesn't pass down the SNYK_TOKEN environment variable. 66 | security: 67 | name: Check Security 68 | runs-on: ubuntu-latest 69 | steps: 70 | - uses: actions/checkout@v4 71 | - run: npm install --prefer-offline 72 | - run: make secure 73 | env: 74 | SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} 75 | 76 | publish: 77 | name: Publish to NPM registry 78 | runs-on: ubuntu-latest 79 | needs: [test-node, test-browser, lint, typecheck, security] 80 | steps: 81 | - uses: actions/checkout@v4 82 | - uses: actions/setup-node@v4 83 | with: 84 | node-version-file: '.nvmrc' 85 | # Setup .npmrc file to publish to npm 86 | registry-url: 'https://registry.npmjs.org' 87 | - run: npm install --prefer-offline 88 | - run: make publish 89 | env: 90 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 91 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .reports 2 | *.log 3 | dist 4 | *.bundle.js 5 | 6 | # OSX 7 | # 8 | .DS_Store 9 | 10 | # Xcode 11 | # 12 | *.pbxuser 13 | !default.pbxuser 14 | *.mode1v3 15 | !default.mode1v3 16 | *.mode2v3 17 | !default.mode2v3 18 | *.perspectivev3 19 | !default.perspectivev3 20 | xcuserdata 21 | *.xccheckout 22 | *.moved-aside 23 | DerivedData 24 | *.hmap 25 | *.ipa 26 | *.xcuserstate 27 | project.xcworkspace 28 | 29 | # IDEs 30 | # 31 | build/ 32 | .idea 33 | .gradle 34 | .vscode 35 | local.properties 36 | *.iml 37 | 38 | # node.js 39 | # 40 | node_modules/ 41 | package-lock.json 42 | npm-debug.log 43 | yarn-error.log 44 | 45 | # BUCK 46 | # 47 | buck-out/ 48 | \.buckd/ 49 | *.keystore 50 | 51 | # Bundle artifact 52 | # 53 | *.jsbundle 54 | 55 | # CocoaPods 56 | # 57 | /ios/Pods/ 58 | -------------------------------------------------------------------------------- /.husky/.gitignore: -------------------------------------------------------------------------------- 1 | _ 2 | -------------------------------------------------------------------------------- /.husky/commit-msg: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | npx commitlint --edit $1 5 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | npx lint-staged 5 | -------------------------------------------------------------------------------- /.husky/pre-push: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | make 5 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | save-exact=true 2 | package-lock=false 3 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | 20 2 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. 4 | 5 | ## [4.1.0](https://github.com/lquixada/cross-fetch/compare/v4.0.0...v4.1.0) (2024-12-21) 6 | 7 | 8 | ### Features 9 | 10 | * added support for node 22 ([074cd87](https://github.com/lquixada/cross-fetch/commit/074cd875751362d91ab10b8af632680b0fbe89db)) 11 | * updated node-fetch to 2.7.0 ([#192](https://github.com/lquixada/cross-fetch/issues/192)) ([0ab2481](https://github.com/lquixada/cross-fetch/commit/0ab24817f32c30457a6549940e033163c56318d3)) 12 | 13 | 14 | ### Bug Fixes 15 | 16 | * updated whatwg-fetch to 3.6.20 ([#197](https://github.com/lquixada/cross-fetch/issues/197)) ([df46c2a](https://github.com/lquixada/cross-fetch/commit/df46c2ae83dd670fb0f767302d4b09842075e415)) 17 | 18 | ## [4.0.0](https://github.com/lquixada/cross-fetch/compare/v4.0.0-alpha.13...v4.0.0) (2023-07-03) 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Leonardo Quixadá 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all 2 | all: test lint typecheck 3 | 4 | .PHONY: clean 5 | clean: 6 | @echo "" 7 | @echo "=> cleaning dependencies and builds..." 8 | @git clean -dfx 9 | 10 | .PHONY: commit 11 | commit: 12 | @npx cz 13 | 14 | .PHONY: publish 15 | publish: 16 | @./bin/publish 17 | 18 | .PHONY: version 19 | version: 20 | @npx standard-version 21 | 22 | .PHONY: version-alpha 23 | version-alpha: 24 | @npx standard-version --prerelease alpha 25 | 26 | .PHONY: server 27 | server: 28 | @./bin/server --silent --exec "echo Fetch api test suites: http://127.0.0.1:8000/test/fetch-api/" 29 | 30 | ## 31 | # Builds 32 | 33 | node_modules: package.json 34 | @echo "" 35 | @echo "=> installing dependencies..." 36 | @npm install && /usr/bin/touch node_modules 37 | 38 | # alias for "node_modules" target 39 | .PHONY: install 40 | install: node_modules 41 | 42 | dist: rollup.config.js $(wildcard src/*.js) node_modules 43 | @echo "" 44 | @echo "=> make $@" 45 | @npx rollup -c --bundleConfigAsCjs && /usr/bin/touch dist 46 | 47 | # alias for "dist" target 48 | .PHONY: build 49 | build: dist 50 | 51 | test/fetch-api/api.spec.js: test/fetch-api/api.spec.ts 52 | @echo "" 53 | @echo "=> make $@" 54 | @npx tsc 55 | 56 | 57 | ## 58 | # Checks 59 | 60 | .PHONY: commitlint 61 | commitlint: node_modules 62 | @echo "" 63 | @echo "=> linting commits..." 64 | @npx commitlint --from origin/main --to HEAD --verbose 65 | 66 | .PHONY: cov 67 | cov: 68 | @echo "" 69 | @echo "=> checking code coverage..." 70 | @npx nyc report --reporter=text-lcov > .reports/coverage.lcov && npx codecov 71 | 72 | .PHONY: lint 73 | lint: 74 | @echo "" 75 | @echo "=> make $@" 76 | @npx standard 77 | 78 | .PHONY: secure 79 | secure: 80 | @echo "" 81 | @echo "=> make $@" 82 | @npx snyk test 83 | 84 | .PHONY: typecheck 85 | typecheck: 86 | @echo "" 87 | @echo "=> make $@" 88 | @npx tsc --lib ES6 --noEmit index.d.ts ./test/fetch-api/api.spec.ts 89 | 90 | 91 | ## 92 | # Test groups 93 | 94 | .PHONY: test 95 | test: | test-browser test-node 96 | 97 | .PHONY: test-browser 98 | test-browser: |\ 99 | test-fetch-browser-native \ 100 | test-fetch-browser-whatwg \ 101 | test-fetch-browser-service-worker \ 102 | test-module-web-cjs \ 103 | test-module-web-esm \ 104 | test-module-react-native 105 | 106 | .PHONY: test-node 107 | test-node: |\ 108 | test-fetch-node-native \ 109 | test-fetch-node-fetch \ 110 | test-module-node-cjs \ 111 | test-module-node-esm 112 | 113 | 114 | ## 115 | # Test units 116 | 117 | .PHONY: test-fetch-browser-native 118 | test-fetch-browser-native: | dist test/fetch-api/api.spec.js 119 | @echo "" 120 | @echo "=> make $@" 121 | @./test/fetch-api/browser/run.sh 122 | 123 | .PHONY: test-fetch-browser-whatwg 124 | test-fetch-browser-whatwg: | dist test/fetch-api/api.spec.js 125 | @echo "" 126 | @echo "=> make $@" 127 | @./test/fetch-api/whatwg/run.sh 128 | 129 | .PHONY: test-fetch-browser-service-worker 130 | test-fetch-browser-service-worker: dist test/fetch-api/api.spec.js 131 | @echo "" 132 | @echo "=> make $@" 133 | @./test/fetch-api/service-worker/run.sh 134 | 135 | .PHONY: test-fetch-node-native 136 | test-fetch-node-native: | dist test/fetch-api/api.spec.js 137 | @echo "" 138 | @echo "=> make $@" 139 | @./test/fetch-api/node/run.sh 140 | 141 | .PHONY: test-fetch-node-fetch 142 | test-fetch-node-fetch: | dist test/fetch-api/api.spec.js 143 | @echo "" 144 | @echo "=> make $@" 145 | @./test/fetch-api/node-fetch/run.sh 146 | 147 | .PHONY: test-module-web-cjs 148 | test-module-web-cjs: | dist 149 | @echo "" 150 | @echo "=> make $@" 151 | @./test/module-system/web.cjs/run.sh 152 | 153 | .PHONY: test-module-web-esm 154 | test-module-web-esm: | dist 155 | @echo "" 156 | @echo "=> make $@" 157 | @./test/module-system/web.esm/run.sh 158 | 159 | .PHONY: test-module-node-cjs 160 | test-module-node-cjs: | dist 161 | @echo "" 162 | @echo "=> make $@" 163 | @./test/module-system/node.cjs/run.sh 164 | 165 | .PHONY: test-module-node-esm 166 | test-module-node-esm: | dist 167 | @echo "" 168 | @echo "=> make $@" 169 | @./test/module-system/node.esm/run.sh 170 | 171 | .PHONY: test-module-react-native 172 | test-module-react-native: | dist 173 | @echo "" 174 | @echo "=> make $@" 175 | @./test/module-system/react-native/run.sh 176 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | cross-fetch
2 | [![NPM Version](https://img.shields.io/npm/v/cross-fetch.svg?branch=main)](https://www.npmjs.com/package/cross-fetch) 3 | [![Downloads Per Week](https://img.shields.io/npm/dw/cross-fetch.svg?color=blue)](https://www.npmjs.com/package/cross-fetch) 4 | [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) 5 | [![CI](https://github.com/lquixada/cross-fetch/actions/workflows/ci.yml/badge.svg)](https://github.com/lquixada/cross-fetch/actions/workflows/ci.yml) 6 | [![codecov](https://codecov.io/gh/lquixada/cross-fetch/branch/main/graph/badge.svg)](https://codecov.io/gh/lquixada/cross-fetch) 7 | ================ 8 | 9 | Universal WHATWG Fetch API for Node, Browsers, Workers and React Native. The scenario that cross-fetch really shines is when the same JavaScript codebase needs to run on different platforms. 10 | 11 | - **Platform agnostic**: browsers, Node or React Native 12 | - **Optional polyfill**: it's up to you if something is going to be added to the global object or not 13 | - **Simple interface**: no instantiation, no configuration and no extra dependency 14 | - **WHATWG compliant**: it works the same way wherever your code runs 15 | - **TypeScript support**: better development experience with types. 16 | - **Worker support**: works on different types of workers such as Service Workers and CloudFlare Workers 17 | 18 | 19 | * * * 20 | 21 | ## Table of Contents 22 | 23 | - [Install](#install) 24 | - [Usage](#usage) 25 | - [Demo \& API](#demo--api) 26 | - [FAQ](#faq) 27 | - [Yet another fetch library?](#yet-another-fetch-library) 28 | - [Why polyfill might not be a good idea?](#why-polyfill-might-not-be-a-good-idea) 29 | - [How does cross-fetch work?](#how-does-cross-fetch-work) 30 | - [Who's Using It?](#whos-using-it) 31 | - [Thanks](#thanks) 32 | - [License](#license) 33 | - [Author](#author) 34 | 35 | * * * 36 | 37 | ## Install 38 | 39 | ```sh 40 | npm install --save cross-fetch 41 | ``` 42 | 43 | As a [ponyfill](https://github.com/sindresorhus/ponyfill) (imports locally): 44 | 45 | ```javascript 46 | // Using ES6 modules with Babel or TypeScript 47 | import fetch from 'cross-fetch'; 48 | 49 | // Using CommonJS modules 50 | const fetch = require('cross-fetch'); 51 | ``` 52 | 53 | As a polyfill (installs globally): 54 | 55 | ```javascript 56 | // Using ES6 modules 57 | import 'cross-fetch/polyfill'; 58 | 59 | // Using CommonJS modules 60 | require('cross-fetch/polyfill'); 61 | ``` 62 | 63 | 64 | The CDN build is also available on unpkg: 65 | 66 | ```html 67 | 68 | ``` 69 | 70 | This adds the fetch function to the window object. Note that this is not UMD compatible. 71 | 72 | 73 | * * * 74 | 75 | ## Usage 76 | 77 | With [promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise): 78 | 79 | ```javascript 80 | import fetch from 'cross-fetch'; 81 | // Or just: import 'cross-fetch/polyfill'; 82 | 83 | fetch('//api.github.com/users/lquixada') 84 | .then(res => { 85 | if (res.status >= 400) { 86 | throw new Error("Bad response from server"); 87 | } 88 | return res.json(); 89 | }) 90 | .then(user => { 91 | console.log(user); 92 | }) 93 | .catch(err => { 94 | console.error(err); 95 | }); 96 | ``` 97 | 98 | With [async/await](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function): 99 | 100 | ```javascript 101 | import fetch from 'cross-fetch'; 102 | // Or just: import 'cross-fetch/polyfill'; 103 | 104 | (async () => { 105 | try { 106 | const res = await fetch('//api.github.com/users/lquixada'); 107 | 108 | if (res.status >= 400) { 109 | throw new Error("Bad response from server"); 110 | } 111 | 112 | const user = await res.json(); 113 | 114 | console.log(user); 115 | } catch (err) { 116 | console.error(err); 117 | } 118 | })(); 119 | ``` 120 | 121 | ## Demo & API 122 | 123 | You can find a comprehensive doc at [Github's fetch](https://github.github.io/fetch/) page. If you want to play with cross-fetch, check our [**JSFiddle playground**](https://jsfiddle.net/lquixada/3ypqgacp/). 124 | 125 | > **Tip**: Run the fiddle on various browsers and with different settings (for instance: cross-domain requests, wrong urls or text requests). Don't forget to open the console in the test suite page and play around. 126 | 127 | 128 | ## FAQ 129 | 130 | #### Yet another fetch library? 131 | 132 | I did a lot of research in order to find a fetch library that could be simple, cross-platform and provide polyfill as an option. There's a plethora of libs out there but none could match those requirements. 133 | 134 | #### Why polyfill might not be a good idea? 135 | 136 | In a word? Risk. If the spec changes in the future, it might be problematic to debug. Read more about it on [sindresorhus's ponyfill](https://github.com/sindresorhus/ponyfill#how-are-ponyfills-better-than-polyfills) page. It's up to you if you're fine with it or not. 137 | 138 | #### How does cross-fetch work? 139 | 140 | Just like isomorphic-fetch, it is just a proxy. If you're in node, it delivers you the [node-fetch](https://github.com/bitinn/node-fetch/) library, if you're in a browser or React Native, it delivers you the github's [whatwg-fetch](https://github.com/github/fetch/). The same strategy applies whether you're using polyfill or ponyfill. 141 | 142 | 143 | ## Who's Using It? 144 | 145 | |[![The New York Times](./docs/images/logo-nytimes.png)](https://www.nytimes.com/)|[![Apollo GraphQL](./docs/images/logo-apollo.png)](https://github.com/apollographql/apollo-client/)|[![Facebook](./docs/images/logo-facebook.png)](https://github.com/facebook/fbjs/)|[![Swagger](./docs/images/logo-swagger.png)](https://swagger.io/)|[![VulcanJS](./docs/images/logo-vulcanjs.png)](http://vulcanjs.org)|[![graphql-request](./docs/images/logo-graphql-request.png)](https://github.com/prisma/graphql-request)| 146 | |:---:|:---:|:---:|:---:|:---:|:---:| 147 | |The New York Times|Apollo GraphQL|Facebook|Swagger|VulcanJS|graphql-request| 148 | 149 | 150 | ## Thanks 151 | 152 | Heavily inspired by the works of [matthew-andrews](https://github.com/matthew-andrews). Kudos to him! 153 | 154 | 155 | ## License 156 | 157 | cross-fetch is licensed under the [MIT license](https://github.com/lquixada/cross-fetch/blob/main/LICENSE) © [Leonardo Quixadá](https://twitter.com/lquixada/) 158 | 159 | 160 | ## Author 161 | 162 | |[![@lquixada](https://avatars0.githubusercontent.com/u/195494?v=4&s=96)](https://github.com/lquixada)| 163 | |:---:| 164 | |[@lquixada](http://www.github.com/lquixada)| 165 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | The following versions of `cross-fetch` are currently supported with security updates: 6 | 7 | - the latest commit on the `v4.x` branch; 8 | - the 4.x release tagged as [latest](https://www.npmjs.com/package/cross-fetch/v/latest) on npm; 9 | - the 3.x release tagged as [latest-v3.x](https://www.npmjs.com/package/cross-fetch/v/latest-v3.x) on npm; 10 | 11 | 12 | ## Reporting a Vulnerability 13 | 14 | Please report security issues by sending an email to lquixada@gmail.com. 15 | 16 | Do __not__ submit an issue ticket or pull request or otherwise publicly 17 | disclose the issue. 18 | 19 | After receiving your email, the author will respond as soon as possible and suggest 20 | a plan of action. 21 | 22 | 23 | ## Disclosure policy 24 | 25 | After confirming a vulnerability, the author will generally release a security update 26 | as soon as possible, including the minimum amount of information required for 27 | software maintainers and system administrators to assess the urgency of the 28 | update for their particular situation. 29 | 30 | The publication of any further details such as code comments, 31 | tests, commit history and diffs will be postponed in order to enable a substantial share of the 32 | users to install the security fix before this time. 33 | 34 | Upon publication of full details, the reporter will be credited if the reporter wishes 35 | to be publicly identified. 36 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-minimal -------------------------------------------------------------------------------- /bin/publish: -------------------------------------------------------------------------------- 1 | #!/bin/bash -xv 2 | 3 | # Get the git tag that triggered the workflow build 4 | workflow_version=${GITHUB_REF_NAME:1} # Removed the "v" prefix 5 | # Get version major being handled by the current workflow 6 | workflow_major=$(echo $workflow_version | cut -d. -f1) 7 | workflow_track="latest-v${workflow_major}.x" 8 | 9 | # Get latest version on npm registry 10 | latest_version=$(npm view cross-fetch@latest version) 11 | # Get version major published under the current "latest" npm tag 12 | latest_major=$(echo $latest_version | cut -d. -f1) 13 | 14 | 15 | # If this has been triggered by a "vX.x-test" branch, we just want to test the release workflow (dry run it!) 16 | if [[ "$workflow_version" == *"-test"* ]]; then 17 | npm publish --tag $workflow_track --dry-run && exit 0 18 | fi 19 | 20 | npm publish --tag $workflow_track || exit 1 21 | 22 | if [[ "$workflow_major" == "$latest_major" ]]; then 23 | npm dist-tag add cross-fetch@$workflow_version latest 24 | fi 25 | 26 | if [[ "$workflow_major" == "$(($latest_major + 1))" ]]; then 27 | npm dist-tag add cross-fetch@$workflow_version next 28 | fi 29 | -------------------------------------------------------------------------------- /bin/server: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | const yargs = require('yargs/yargs') 3 | const { spawn } = require('child_process') 4 | const express = require('express') 5 | const bodyParser = require('body-parser') 6 | const serveIndex = require('serve-index') 7 | const path = require('path') 8 | const app = express() 9 | const dir = path.join(__dirname, '..') 10 | 11 | app.use(bodyParser.text()) 12 | 13 | app.get('/succeed', (req, res) => res.status(200).send('hello world.')) 14 | app.get('/fail', (req, res) => res.status(404).send('Good bye world.')) 15 | app.get('/error', (req, res) => res.status(500).send('error world.')) 16 | app.get('/request', processRequest) 17 | app.post('/request', processRequest) 18 | app.put('/request', processRequest) 19 | app.patch('/request', processRequest) 20 | app.delete('/request', processRequest) 21 | 22 | // This line needs to be at the end, otherwise it will block any method different than GET 23 | app.use(express.static(dir), serveIndex(dir, { icons: true, view: 'details' })) 24 | 25 | const ip = '127.0.0.1' 26 | const port = 8000 27 | const url = `http://${ip}:${port}/` 28 | const { argv } = yargs(process.argv.slice(2)) 29 | 30 | function processRequest (req, res) { 31 | const headers = {} 32 | const isDelete = req.method === 'DELETE' 33 | 34 | for (const key in req.headers) { 35 | const value = req.headers[key] 36 | headers[key] = Array.isArray(value) ? value[0] : value 37 | } 38 | 39 | res.set('Date', 'Sat, 23 Sep 2017 15:41:16 GMT-0300') 40 | 41 | res.json({ 42 | method: req.method, 43 | headers, 44 | body: isDelete ? '' : req.body 45 | }) 46 | } 47 | 48 | function processFileUrl (args) { 49 | const fileParamIndex = args.indexOf('-f') 50 | 51 | if (fileParamIndex > 0) { 52 | const fileIndex = fileParamIndex + 1 53 | args[fileIndex] = args[fileIndex].replace(/^\.\//, url) 54 | } 55 | 56 | return args 57 | } 58 | 59 | const server = app.listen(port, ip, () => { 60 | if (!argv.silent) { 61 | console.log(`Test server listening at ${url}`) 62 | } 63 | 64 | if (argv.exec) { 65 | const args = processFileUrl(argv.exec.split(' ')) 66 | const command = args[0] 67 | const params = args.slice(1) 68 | const child = spawn(command, params, { 69 | env: { 70 | ...process.env, 71 | FORCE_COLOR: true // ensure mocha outputs colors on node test 72 | } 73 | }) 74 | 75 | child.stdout.pipe(process.stdout) 76 | child.stderr.pipe(process.stdout) 77 | 78 | if (argv.closeOnExec) { 79 | child.on('exit', code => { 80 | server.close() 81 | process.exit(code) 82 | }) 83 | } 84 | } 85 | }) 86 | -------------------------------------------------------------------------------- /docs/images/logo-apollo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lquixada/cross-fetch/9e6898ee848ba6dc942f787f2c35ca6fa30eb014/docs/images/logo-apollo.png -------------------------------------------------------------------------------- /docs/images/logo-facebook.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lquixada/cross-fetch/9e6898ee848ba6dc942f787f2c35ca6fa30eb014/docs/images/logo-facebook.png -------------------------------------------------------------------------------- /docs/images/logo-graphql-request.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lquixada/cross-fetch/9e6898ee848ba6dc942f787f2c35ca6fa30eb014/docs/images/logo-graphql-request.png -------------------------------------------------------------------------------- /docs/images/logo-nytimes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lquixada/cross-fetch/9e6898ee848ba6dc942f787f2c35ca6fa30eb014/docs/images/logo-nytimes.png -------------------------------------------------------------------------------- /docs/images/logo-swagger.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lquixada/cross-fetch/9e6898ee848ba6dc942f787f2c35ca6fa30eb014/docs/images/logo-swagger.png -------------------------------------------------------------------------------- /docs/images/logo-vulcanjs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lquixada/cross-fetch/9e6898ee848ba6dc942f787f2c35ca6fa30eb014/docs/images/logo-vulcanjs.png -------------------------------------------------------------------------------- /examples/browser/.npmrc: -------------------------------------------------------------------------------- 1 | save-exact=true 2 | package-lock=false 3 | -------------------------------------------------------------------------------- /examples/browser/index.js: -------------------------------------------------------------------------------- 1 | const fetch = require('cross-fetch') 2 | 3 | fetch('https://api.github.com/users/lquixada') 4 | .then(res => { 5 | if (res.status >= 400) { 6 | throw new Error('Bad response from server') 7 | } 8 | return res.json() 9 | }) 10 | .then(user => { 11 | console.log(user) 12 | }) 13 | .catch(err => { 14 | console.error(err) 15 | }) 16 | -------------------------------------------------------------------------------- /examples/browser/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cross-fetch-on-browser", 3 | "version": "0.0.1", 4 | "scripts": { 5 | "prestart": "webpack ./index.js --output-filename bundle.js --target=web --mode=development", 6 | "start": "node puppeteer" 7 | }, 8 | "dependencies": { 9 | "cross-fetch": "*" 10 | }, 11 | "devDependencies": { 12 | "puppeteer": "10.4.0" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /examples/browser/puppeteer.js: -------------------------------------------------------------------------------- 1 | const puppeteer = require('puppeteer') 2 | 3 | function describe (jsHandle) { 4 | return jsHandle.executionContext().evaluate(o => o, jsHandle) 5 | } 6 | 7 | (async () => { 8 | const browser = await puppeteer.launch() 9 | const page = await browser.newPage() 10 | 11 | page.on('console', async msg => { 12 | const args = await Promise.all(msg.args().map(describe)) 13 | console.log(args) 14 | }) 15 | 16 | await page.addScriptTag({ 17 | path: './dist/bundle.js' 18 | }) 19 | 20 | // browser.close() 21 | })() 22 | -------------------------------------------------------------------------------- /examples/cloud-worker/.npmrc: -------------------------------------------------------------------------------- 1 | save-exact=true 2 | package-lock=false 3 | -------------------------------------------------------------------------------- /examples/cloud-worker/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cloud-worker-fix", 3 | "version": "0.0.0", 4 | "devDependencies": { 5 | "wrangler": "2.20.1" 6 | }, 7 | "private": true, 8 | "scripts": { 9 | "start": "wrangler dev", 10 | "deploy": "wrangler publish" 11 | }, 12 | "dependencies": { 13 | "cross-fetch": "3.1.5" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/cloud-worker/src/index.js: -------------------------------------------------------------------------------- 1 | import _fetch from '../../../' 2 | 3 | export default { 4 | async fetch (request, env, ctx) { 5 | try { 6 | const res = await _fetch('https://jsonplaceholder.typicode.com/todos/1') 7 | 8 | if (res.status >= 400) { 9 | const err = new Error(`${res.status} ${res.statusText}`) 10 | err.response = res 11 | err.status = res.status 12 | throw err 13 | } 14 | 15 | const user = await res.json() 16 | 17 | return new Response(JSON.stringify(user)) 18 | } catch (err) { 19 | return new Response(err) 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/cloud-worker/wrangler.toml: -------------------------------------------------------------------------------- 1 | name = "cloud-worker-fix" 2 | main = "src/index.js" 3 | compatibility_date = "2023-05-06" 4 | -------------------------------------------------------------------------------- /examples/node/.npmrc: -------------------------------------------------------------------------------- 1 | save-exact=true 2 | package-lock=false 3 | -------------------------------------------------------------------------------- /examples/node/index.js: -------------------------------------------------------------------------------- 1 | const fetch = require('cross-fetch') 2 | 3 | fetch('http://127.0.0.1:6000') 4 | .then(res => { 5 | if (res.status >= 400) { 6 | throw new Error('Bad response from server') 7 | } 8 | return res.json() 9 | }) 10 | .then(data => { 11 | console.log(data) 12 | }) 13 | .catch(err => { 14 | console.error(err) 15 | }) 16 | -------------------------------------------------------------------------------- /examples/node/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cross-fetch-on-node", 3 | "version": "0.0.1", 4 | "scripts": { 5 | "prestart": "webpack ./index.js --output-filename bundle.js --target=node --mode=development", 6 | "start": "node dist/bundle" 7 | }, 8 | "dependencies": { 9 | "cross-fetch": "4.0.0" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /examples/node/server.js: -------------------------------------------------------------------------------- 1 | const http = require('http') 2 | 3 | const hostname = '127.0.0.1' 4 | const port = 6000 5 | 6 | const server = http.createServer((req, res) => { 7 | res.statusCode = 200 8 | res.setHeader('Content-Type', 'application/json') 9 | res.end(JSON.stringify({ foo: 1 })) 10 | }) 11 | 12 | server.listen(port, hostname, () => { 13 | console.log(`Server running at http://${hostname}:${port}/`) 14 | }) 15 | -------------------------------------------------------------------------------- /examples/reactnative/.buckconfig: -------------------------------------------------------------------------------- 1 | 2 | [android] 3 | target = Google Inc.:Google APIs:23 4 | 5 | [maven_repositories] 6 | central = https://repo1.maven.org/maven2 7 | -------------------------------------------------------------------------------- /examples/reactnative/.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # Xcode 6 | # 7 | build/ 8 | *.pbxuser 9 | !default.pbxuser 10 | *.mode1v3 11 | !default.mode1v3 12 | *.mode2v3 13 | !default.mode2v3 14 | *.perspectivev3 15 | !default.perspectivev3 16 | xcuserdata 17 | *.xccheckout 18 | *.moved-aside 19 | DerivedData 20 | *.hmap 21 | *.ipa 22 | *.xcuserstate 23 | project.xcworkspace 24 | 25 | # Android/IntelliJ 26 | # 27 | build/ 28 | .idea 29 | .gradle 30 | local.properties 31 | *.iml 32 | 33 | # node.js 34 | # 35 | node_modules/ 36 | npm-debug.log 37 | yarn-error.log 38 | 39 | # BUCK 40 | buck-out/ 41 | \.buckd/ 42 | *.keystore 43 | 44 | # fastlane 45 | # 46 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 47 | # screenshots whenever they are needed. 48 | # For more information about the recommended setup visit: 49 | # https://docs.fastlane.tools/best-practices/source-control/ 50 | 51 | */fastlane/report.xml 52 | */fastlane/Preview.html 53 | */fastlane/screenshots 54 | 55 | # Bundle artifact 56 | *.jsbundle 57 | 58 | # CocoaPods 59 | /ios/Pods/ 60 | -------------------------------------------------------------------------------- /examples/reactnative/.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /examples/reactnative/android/app/BUCK: -------------------------------------------------------------------------------- 1 | # To learn about Buck see [Docs](https://buckbuild.com/). 2 | # To run your application with Buck: 3 | # - install Buck 4 | # - `npm start` - to start the packager 5 | # - `cd android` 6 | # - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"` 7 | # - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck 8 | # - `buck install -r android/app` - compile, install and run application 9 | # 10 | 11 | load(":build_defs.bzl", "create_aar_targets", "create_jar_targets") 12 | 13 | lib_deps = [] 14 | 15 | create_aar_targets(glob(["libs/*.aar"])) 16 | 17 | create_jar_targets(glob(["libs/*.jar"])) 18 | 19 | android_library( 20 | name = "all-libs", 21 | exported_deps = lib_deps, 22 | ) 23 | 24 | android_library( 25 | name = "app-code", 26 | srcs = glob([ 27 | "src/main/java/**/*.java", 28 | ]), 29 | deps = [ 30 | ":all-libs", 31 | ":build_config", 32 | ":res", 33 | ], 34 | ) 35 | 36 | android_build_config( 37 | name = "build_config", 38 | package = "com.reactnative", 39 | ) 40 | 41 | android_resource( 42 | name = "res", 43 | package = "com.reactnative", 44 | res = "src/main/res", 45 | ) 46 | 47 | android_binary( 48 | name = "app", 49 | keystore = "//android/keystores:debug", 50 | manifest = "src/main/AndroidManifest.xml", 51 | package_type = "debug", 52 | deps = [ 53 | ":app-code", 54 | ], 55 | ) 56 | -------------------------------------------------------------------------------- /examples/reactnative/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "com.android.application" 2 | 3 | import com.android.build.OutputFile 4 | 5 | /** 6 | * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets 7 | * and bundleReleaseJsAndAssets). 8 | * These basically call `react-native bundle` with the correct arguments during the Android build 9 | * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the 10 | * bundle directly from the development server. Below you can see all the possible configurations 11 | * and their defaults. If you decide to add a configuration block, make sure to add it before the 12 | * `apply from: "../../node_modules/react-native/react.gradle"` line. 13 | * 14 | * project.ext.react = [ 15 | * // the name of the generated asset file containing your JS bundle 16 | * bundleAssetName: "index.android.bundle", 17 | * 18 | * // the entry file for bundle generation 19 | * entryFile: "index.android.js", 20 | * 21 | * // https://facebook.github.io/react-native/docs/performance#enable-the-ram-format 22 | * bundleCommand: "ram-bundle", 23 | * 24 | * // whether to bundle JS and assets in debug mode 25 | * bundleInDebug: false, 26 | * 27 | * // whether to bundle JS and assets in release mode 28 | * bundleInRelease: true, 29 | * 30 | * // whether to bundle JS and assets in another build variant (if configured). 31 | * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants 32 | * // The configuration property can be in the following formats 33 | * // 'bundleIn${productFlavor}${buildType}' 34 | * // 'bundleIn${buildType}' 35 | * // bundleInFreeDebug: true, 36 | * // bundleInPaidRelease: true, 37 | * // bundleInBeta: true, 38 | * 39 | * // whether to disable dev mode in custom build variants (by default only disabled in release) 40 | * // for example: to disable dev mode in the staging build type (if configured) 41 | * devDisabledInStaging: true, 42 | * // The configuration property can be in the following formats 43 | * // 'devDisabledIn${productFlavor}${buildType}' 44 | * // 'devDisabledIn${buildType}' 45 | * 46 | * // the root of your project, i.e. where "package.json" lives 47 | * root: "../../", 48 | * 49 | * // where to put the JS bundle asset in debug mode 50 | * jsBundleDirDebug: "$buildDir/intermediates/assets/debug", 51 | * 52 | * // where to put the JS bundle asset in release mode 53 | * jsBundleDirRelease: "$buildDir/intermediates/assets/release", 54 | * 55 | * // where to put drawable resources / React Native assets, e.g. the ones you use via 56 | * // require('./image.png')), in debug mode 57 | * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug", 58 | * 59 | * // where to put drawable resources / React Native assets, e.g. the ones you use via 60 | * // require('./image.png')), in release mode 61 | * resourcesDirRelease: "$buildDir/intermediates/res/merged/release", 62 | * 63 | * // by default the gradle tasks are skipped if none of the JS files or assets change; this means 64 | * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to 65 | * // date; if you have any other folders that you want to ignore for performance reasons (gradle 66 | * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/ 67 | * // for example, you might want to remove it from here. 68 | * inputExcludes: ["android/**", "ios/**"], 69 | * 70 | * // override which node gets called and with what additional arguments 71 | * nodeExecutableAndArgs: ["node"], 72 | * 73 | * // supply additional arguments to the packager 74 | * extraPackagerArgs: [] 75 | * ] 76 | */ 77 | 78 | project.ext.react = [ 79 | entryFile: "index.js", 80 | enableHermes: false, // clean and rebuild if changing 81 | ] 82 | 83 | apply from: "../../node_modules/react-native/react.gradle" 84 | 85 | /** 86 | * Set this to true to create two separate APKs instead of one: 87 | * - An APK that only works on ARM devices 88 | * - An APK that only works on x86 devices 89 | * The advantage is the size of the APK is reduced by about 4MB. 90 | * Upload all the APKs to the Play Store and people will download 91 | * the correct one based on the CPU architecture of their device. 92 | */ 93 | def enableSeparateBuildPerCPUArchitecture = false 94 | 95 | /** 96 | * Run Proguard to shrink the Java bytecode in release builds. 97 | */ 98 | def enableProguardInReleaseBuilds = false 99 | 100 | /** 101 | * The preferred build flavor of JavaScriptCore. 102 | * 103 | * For example, to use the international variant, you can use: 104 | * `def jscFlavor = 'org.webkit:android-jsc-intl:+'` 105 | * 106 | * The international variant includes ICU i18n library and necessary data 107 | * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that 108 | * give correct results when using with locales other than en-US. Note that 109 | * this variant is about 6MiB larger per architecture than default. 110 | */ 111 | def jscFlavor = 'org.webkit:android-jsc:+' 112 | 113 | /** 114 | * Whether to enable the Hermes VM. 115 | * 116 | * This should be set on project.ext.react and mirrored here. If it is not set 117 | * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode 118 | * and the benefits of using Hermes will therefore be sharply reduced. 119 | */ 120 | def enableHermes = project.ext.react.get("enableHermes", false); 121 | 122 | android { 123 | compileSdkVersion rootProject.ext.compileSdkVersion 124 | 125 | compileOptions { 126 | sourceCompatibility JavaVersion.VERSION_1_8 127 | targetCompatibility JavaVersion.VERSION_1_8 128 | } 129 | 130 | defaultConfig { 131 | applicationId "com.reactnative" 132 | minSdkVersion rootProject.ext.minSdkVersion 133 | targetSdkVersion rootProject.ext.targetSdkVersion 134 | versionCode 1 135 | versionName "1.0" 136 | } 137 | splits { 138 | abi { 139 | reset() 140 | enable enableSeparateBuildPerCPUArchitecture 141 | universalApk false // If true, also generate a universal APK 142 | include "armeabi-v7a", "x86", "arm64-v8a", "x86_64" 143 | } 144 | } 145 | signingConfigs { 146 | debug { 147 | storeFile file('debug.keystore') 148 | storePassword 'android' 149 | keyAlias 'androiddebugkey' 150 | keyPassword 'android' 151 | } 152 | } 153 | buildTypes { 154 | debug { 155 | signingConfig signingConfigs.debug 156 | } 157 | release { 158 | // Caution! In production, you need to generate your own keystore file. 159 | // see https://facebook.github.io/react-native/docs/signed-apk-android. 160 | signingConfig signingConfigs.debug 161 | minifyEnabled enableProguardInReleaseBuilds 162 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" 163 | } 164 | } 165 | // applicationVariants are e.g. debug, release 166 | applicationVariants.all { variant -> 167 | variant.outputs.each { output -> 168 | // For each separate APK per architecture, set a unique version code as described here: 169 | // https://developer.android.com/studio/build/configure-apk-splits.html 170 | def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4] 171 | def abi = output.getFilter(OutputFile.ABI) 172 | if (abi != null) { // null for the universal-debug, universal-release variants 173 | output.versionCodeOverride = 174 | versionCodes.get(abi) * 1048576 + defaultConfig.versionCode 175 | } 176 | 177 | } 178 | } 179 | 180 | packagingOptions { 181 | pickFirst '**/armeabi-v7a/libc++_shared.so' 182 | pickFirst '**/x86/libc++_shared.so' 183 | pickFirst '**/arm64-v8a/libc++_shared.so' 184 | pickFirst '**/x86_64/libc++_shared.so' 185 | pickFirst '**/x86/libjsc.so' 186 | pickFirst '**/armeabi-v7a/libjsc.so' 187 | } 188 | } 189 | 190 | dependencies { 191 | implementation fileTree(dir: "libs", include: ["*.jar"]) 192 | implementation "com.facebook.react:react-native:+" // From node_modules 193 | 194 | if (enableHermes) { 195 | def hermesPath = "../../node_modules/hermesvm/android/"; 196 | debugImplementation files(hermesPath + "hermes-debug.aar") 197 | releaseImplementation files(hermesPath + "hermes-release.aar") 198 | } else { 199 | implementation jscFlavor 200 | } 201 | } 202 | 203 | // Run this once to be able to run the application with BUCK 204 | // puts all compile dependencies into folder libs for BUCK to use 205 | task copyDownloadableDepsToLibs(type: Copy) { 206 | from configurations.compile 207 | into 'libs' 208 | } 209 | 210 | apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) 211 | -------------------------------------------------------------------------------- /examples/reactnative/android/app/build_defs.bzl: -------------------------------------------------------------------------------- 1 | """Helper definitions to glob .aar and .jar targets""" 2 | 3 | def create_aar_targets(aarfiles): 4 | for aarfile in aarfiles: 5 | name = "aars__" + aarfile[aarfile.rindex("/") + 1:aarfile.rindex(".aar")] 6 | lib_deps.append(":" + name) 7 | android_prebuilt_aar( 8 | name = name, 9 | aar = aarfile, 10 | ) 11 | 12 | def create_jar_targets(jarfiles): 13 | for jarfile in jarfiles: 14 | name = "jars__" + jarfile[jarfile.rindex("/") + 1:jarfile.rindex(".jar")] 15 | lib_deps.append(":" + name) 16 | prebuilt_jar( 17 | name = name, 18 | binary_jar = jarfile, 19 | ) 20 | -------------------------------------------------------------------------------- /examples/reactnative/android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | -------------------------------------------------------------------------------- /examples/reactnative/android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /examples/reactnative/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 13 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /examples/reactnative/android/app/src/main/java/com/reactnative/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.reactnative; 2 | 3 | import com.facebook.react.ReactActivity; 4 | 5 | public class MainActivity extends ReactActivity { 6 | 7 | /** 8 | * Returns the name of the main component registered from JavaScript. 9 | * This is used to schedule rendering of the component. 10 | */ 11 | @Override 12 | protected String getMainComponentName() { 13 | return "reactnative"; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/reactnative/android/app/src/main/java/com/reactnative/MainApplication.java: -------------------------------------------------------------------------------- 1 | package com.reactnative; 2 | 3 | import android.app.Application; 4 | import android.util.Log; 5 | 6 | import com.facebook.react.PackageList; 7 | import com.facebook.hermes.reactexecutor.HermesExecutorFactory; 8 | import com.facebook.react.bridge.JavaScriptExecutorFactory; 9 | import com.facebook.react.ReactApplication; 10 | import com.facebook.react.ReactNativeHost; 11 | import com.facebook.react.ReactPackage; 12 | import com.facebook.soloader.SoLoader; 13 | 14 | import java.util.List; 15 | 16 | public class MainApplication extends Application implements ReactApplication { 17 | 18 | private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { 19 | @Override 20 | public boolean getUseDeveloperSupport() { 21 | return BuildConfig.DEBUG; 22 | } 23 | 24 | @Override 25 | protected List getPackages() { 26 | @SuppressWarnings("UnnecessaryLocalVariable") 27 | List packages = new PackageList(this).getPackages(); 28 | // Packages that cannot be autolinked yet can be added manually here, for example: 29 | // packages.add(new MyReactNativePackage()); 30 | return packages; 31 | } 32 | 33 | @Override 34 | protected String getJSMainModuleName() { 35 | return "index"; 36 | } 37 | }; 38 | 39 | @Override 40 | public ReactNativeHost getReactNativeHost() { 41 | return mReactNativeHost; 42 | } 43 | 44 | @Override 45 | public void onCreate() { 46 | super.onCreate(); 47 | SoLoader.init(this, /* native exopackage */ false); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /examples/reactnative/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lquixada/cross-fetch/9e6898ee848ba6dc942f787f2c35ca6fa30eb014/examples/reactnative/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /examples/reactnative/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lquixada/cross-fetch/9e6898ee848ba6dc942f787f2c35ca6fa30eb014/examples/reactnative/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /examples/reactnative/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lquixada/cross-fetch/9e6898ee848ba6dc942f787f2c35ca6fa30eb014/examples/reactnative/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /examples/reactnative/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lquixada/cross-fetch/9e6898ee848ba6dc942f787f2c35ca6fa30eb014/examples/reactnative/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /examples/reactnative/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lquixada/cross-fetch/9e6898ee848ba6dc942f787f2c35ca6fa30eb014/examples/reactnative/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /examples/reactnative/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lquixada/cross-fetch/9e6898ee848ba6dc942f787f2c35ca6fa30eb014/examples/reactnative/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /examples/reactnative/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lquixada/cross-fetch/9e6898ee848ba6dc942f787f2c35ca6fa30eb014/examples/reactnative/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /examples/reactnative/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lquixada/cross-fetch/9e6898ee848ba6dc942f787f2c35ca6fa30eb014/examples/reactnative/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /examples/reactnative/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lquixada/cross-fetch/9e6898ee848ba6dc942f787f2c35ca6fa30eb014/examples/reactnative/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /examples/reactnative/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lquixada/cross-fetch/9e6898ee848ba6dc942f787f2c35ca6fa30eb014/examples/reactnative/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /examples/reactnative/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | reactnative 3 | 4 | -------------------------------------------------------------------------------- /examples/reactnative/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /examples/reactnative/android/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | ext { 5 | buildToolsVersion = "28.0.3" 6 | minSdkVersion = 16 7 | compileSdkVersion = 28 8 | targetSdkVersion = 28 9 | supportLibVersion = "28.0.0" 10 | } 11 | repositories { 12 | google() 13 | jcenter() 14 | } 15 | dependencies { 16 | classpath("com.android.tools.build:gradle:3.4.1") 17 | 18 | // NOTE: Do not place your application dependencies here; they belong 19 | // in the individual module build.gradle files 20 | } 21 | } 22 | 23 | allprojects { 24 | repositories { 25 | mavenLocal() 26 | maven { 27 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm 28 | url("$rootDir/../node_modules/react-native/android") 29 | } 30 | maven { 31 | // Android JSC is installed from npm 32 | url("$rootDir/../node_modules/jsc-android/dist") 33 | } 34 | 35 | google() 36 | jcenter() 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /examples/reactnative/android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | 20 | android.useAndroidX=true 21 | android.enableJetifier=true 22 | -------------------------------------------------------------------------------- /examples/reactnative/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lquixada/cross-fetch/9e6898ee848ba6dc942f787f2c35ca6fa30eb014/examples/reactnative/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /examples/reactnative/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /examples/reactnative/android/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | # Determine the Java command to use to start the JVM. 86 | if [ -n "$JAVA_HOME" ] ; then 87 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 88 | # IBM's JDK on AIX uses strange locations for the executables 89 | JAVACMD="$JAVA_HOME/jre/sh/java" 90 | else 91 | JAVACMD="$JAVA_HOME/bin/java" 92 | fi 93 | if [ ! -x "$JAVACMD" ] ; then 94 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 95 | 96 | Please set the JAVA_HOME variable in your environment to match the 97 | location of your Java installation." 98 | fi 99 | else 100 | JAVACMD="java" 101 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 102 | 103 | Please set the JAVA_HOME variable in your environment to match the 104 | location of your Java installation." 105 | fi 106 | 107 | # Increase the maximum file descriptors if we can. 108 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 109 | MAX_FD_LIMIT=`ulimit -H -n` 110 | if [ $? -eq 0 ] ; then 111 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 112 | MAX_FD="$MAX_FD_LIMIT" 113 | fi 114 | ulimit -n $MAX_FD 115 | if [ $? -ne 0 ] ; then 116 | warn "Could not set maximum file descriptor limit: $MAX_FD" 117 | fi 118 | else 119 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 120 | fi 121 | fi 122 | 123 | # For Darwin, add options to specify how the application appears in the dock 124 | if $darwin; then 125 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 126 | fi 127 | 128 | # For Cygwin, switch paths to Windows format before running java 129 | if $cygwin ; then 130 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 131 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 132 | JAVACMD=`cygpath --unix "$JAVACMD"` 133 | 134 | # We build the pattern for arguments to be converted via cygpath 135 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 136 | SEP="" 137 | for dir in $ROOTDIRSRAW ; do 138 | ROOTDIRS="$ROOTDIRS$SEP$dir" 139 | SEP="|" 140 | done 141 | OURCYGPATTERN="(^($ROOTDIRS))" 142 | # Add a user-defined pattern to the cygpath arguments 143 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 144 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 145 | fi 146 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 147 | i=0 148 | for arg in "$@" ; do 149 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 150 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 151 | 152 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 153 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 154 | else 155 | eval `echo args$i`="\"$arg\"" 156 | fi 157 | i=$((i+1)) 158 | done 159 | case $i in 160 | (0) set -- ;; 161 | (1) set -- "$args0" ;; 162 | (2) set -- "$args0" "$args1" ;; 163 | (3) set -- "$args0" "$args1" "$args2" ;; 164 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 165 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 166 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 167 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 168 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 169 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 170 | esac 171 | fi 172 | 173 | # Escape application args 174 | save () { 175 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 176 | echo " " 177 | } 178 | APP_ARGS=$(save "$@") 179 | 180 | # Collect all arguments for the java command, following the shell quoting and substitution rules 181 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 182 | 183 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 184 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 185 | cd "$(dirname "$0")" 186 | fi 187 | 188 | exec "$JAVACMD" "$@" 189 | -------------------------------------------------------------------------------- /examples/reactnative/android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem http://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 33 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 34 | 35 | @rem Find java.exe 36 | if defined JAVA_HOME goto findJavaFromJavaHome 37 | 38 | set JAVA_EXE=java.exe 39 | %JAVA_EXE% -version >NUL 2>&1 40 | if "%ERRORLEVEL%" == "0" goto init 41 | 42 | echo. 43 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 44 | echo. 45 | echo Please set the JAVA_HOME variable in your environment to match the 46 | echo location of your Java installation. 47 | 48 | goto fail 49 | 50 | :findJavaFromJavaHome 51 | set JAVA_HOME=%JAVA_HOME:"=% 52 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 53 | 54 | if exist "%JAVA_EXE%" goto init 55 | 56 | echo. 57 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 58 | echo. 59 | echo Please set the JAVA_HOME variable in your environment to match the 60 | echo location of your Java installation. 61 | 62 | goto fail 63 | 64 | :init 65 | @rem Get command-line arguments, handling Windows variants 66 | 67 | if not "%OS%" == "Windows_NT" goto win9xME_args 68 | 69 | :win9xME_args 70 | @rem Slurp the command line arguments. 71 | set CMD_LINE_ARGS= 72 | set _SKIP=2 73 | 74 | :win9xME_args_slurp 75 | if "x%~1" == "x" goto execute 76 | 77 | set CMD_LINE_ARGS=%* 78 | 79 | :execute 80 | @rem Setup the command line 81 | 82 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 83 | 84 | @rem Execute Gradle 85 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 86 | 87 | :end 88 | @rem End local scope for the variables with windows NT shell 89 | if "%ERRORLEVEL%"=="0" goto mainEnd 90 | 91 | :fail 92 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 93 | rem the _cmd.exe /c_ return code! 94 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 95 | exit /b 1 96 | 97 | :mainEnd 98 | if "%OS%"=="Windows_NT" endlocal 99 | 100 | :omega 101 | -------------------------------------------------------------------------------- /examples/reactnative/android/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'reactnative' 2 | apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) 3 | include ':app' 4 | -------------------------------------------------------------------------------- /examples/reactnative/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "reactnative", 3 | "displayName": "reactnative" 4 | } -------------------------------------------------------------------------------- /examples/reactnative/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ['module:metro-react-native-babel-preset'] 3 | } 4 | -------------------------------------------------------------------------------- /examples/reactnative/components/home.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { Button, Text, ScrollView, Platform, StyleSheet } from 'react-native' 3 | 4 | class Home extends React.Component { 5 | goToPolyfillPage () { 6 | this.props.navigation.navigate('PolyfillPage', { 7 | title: 'Test Polyfill' 8 | }) 9 | } 10 | 11 | goToPonyfillPage () { 12 | this.props.navigation.navigate('PonyfillPage', { 13 | title: 'Test Ponyfill' 14 | }) 15 | } 16 | 17 | render () { 18 | return ( 19 | 20 | 21 | {Platform.select({ 22 | ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu', 23 | android: 24 | 'Double tap R on your keyboard to reload,\n' + 25 | 'Shake or press menu button for dev menu' 26 | })} 27 | 28 |