pax_global_header00006660000000000000000000000064141555235420014520gustar00rootroot0000000000000052 comment=868690725a0ab6b5d25c5f94849ddc5f5204661b has-dynamic-import-2.0.1/000077500000000000000000000000001415552354200152255ustar00rootroot00000000000000has-dynamic-import-2.0.1/.eslintignore000066400000000000000000000000121415552354200177210ustar00rootroot00000000000000coverage/ has-dynamic-import-2.0.1/.eslintrc000066400000000000000000000005521415552354200170530ustar00rootroot00000000000000{ "root": true, "extends": "@ljharb", "env": { "node": true, "browser": true, }, "rules": { "new-cap": ["error", { "capIsNewExceptions": ["GetIntrinsic"], }], }, "overrides": [ { "files": "./import.js", "extends": "@ljharb/eslint-config/node/14", }, { "files": "test/**/*", "rules": { "id-length": 0, }, }, ], } has-dynamic-import-2.0.1/.github/000077500000000000000000000000001415552354200165655ustar00rootroot00000000000000has-dynamic-import-2.0.1/.github/FUNDING.yml000066400000000000000000000011151415552354200204000ustar00rootroot00000000000000# These are supported funding model platforms github: [ljharb] patreon: # Replace with a single Patreon username open_collective: # Replace with a single Open Collective username ko_fi: # Replace with a single Ko-fi username tidelift: npm/has-dynamic-import community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry liberapay: # Replace with a single Liberapay username issuehunt: # Replace with a single IssueHunt username otechie: # Replace with a single Otechie username custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] has-dynamic-import-2.0.1/.github/workflows/000077500000000000000000000000001415552354200206225ustar00rootroot00000000000000has-dynamic-import-2.0.1/.github/workflows/node-aught.yml000066400000000000000000000005161415552354200234020ustar00rootroot00000000000000name: 'Tests: node.js < 10' on: [pull_request, push] jobs: tests: uses: ljharb/actions/.github/workflows/node.yml@main with: range: '< 10' type: minors command: npm run tests-only node: name: 'node < 10' needs: [tests] runs-on: ubuntu-latest steps: - run: 'echo tests completed' has-dynamic-import-2.0.1/.github/workflows/node-pretest.yml000066400000000000000000000002061415552354200237540ustar00rootroot00000000000000name: 'Tests: pretest/posttest' on: [pull_request, push] jobs: tests: uses: ljharb/actions/.github/workflows/pretest.yml@main has-dynamic-import-2.0.1/.github/workflows/node-tens.yml000066400000000000000000000005211415552354200232370ustar00rootroot00000000000000name: 'Tests: node.js >= 10' on: [pull_request, push] jobs: tests: uses: ljharb/actions/.github/workflows/node.yml@main with: range: '>= 10' type: minors command: npm run tests-only node: name: 'node >= 10' needs: [tests] runs-on: ubuntu-latest steps: - run: 'echo tests completed' has-dynamic-import-2.0.1/.github/workflows/rebase.yml000066400000000000000000000004111415552354200226020ustar00rootroot00000000000000name: Automatic Rebase on: [pull_request_target] jobs: _: name: "Automatic Rebase" runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: ljharb/rebase@master env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} has-dynamic-import-2.0.1/.github/workflows/require-allow-edits.yml000066400000000000000000000003031415552354200252370ustar00rootroot00000000000000name: Require “Allow Edits” on: [pull_request_target] jobs: _: name: "Require “Allow Edits”" runs-on: ubuntu-latest steps: - uses: ljharb/require-allow-edits@main has-dynamic-import-2.0.1/.gitignore000066400000000000000000000032351415552354200172200ustar00rootroot00000000000000# Logs logs *.log npm-debug.log* yarn-debug.log* yarn-error.log* lerna-debug.log* # Diagnostic reports (https://nodejs.org/api/report.html) report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json # Runtime data pids *.pid *.seed *.pid.lock # Directory for instrumented libs generated by jscoverage/JSCover lib-cov # Coverage directory used by tools like istanbul coverage *.lcov # nyc test coverage .nyc_output # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) .grunt # Bower dependency directory (https://bower.io/) bower_components # node-waf configuration .lock-wscript # Compiled binary addons (https://nodejs.org/api/addons.html) build/Release # Dependency directories node_modules/ jspm_packages/ # TypeScript v1 declaration files typings/ # TypeScript cache *.tsbuildinfo # Optional npm cache directory .npm # Optional eslint cache .eslintcache # Microbundle cache .rpt2_cache/ .rts2_cache_cjs/ .rts2_cache_es/ .rts2_cache_umd/ # Optional REPL history .node_repl_history # Output of 'npm pack' *.tgz # Yarn Integrity file .yarn-integrity # dotenv environment variables file .env .env.test # parcel-bundler cache (https://parceljs.org/) .cache # Next.js build output .next # Nuxt.js build / generate output .nuxt dist # Gatsby files .cache/ # Comment in the public line in if your project uses Gatsby and *not* Next.js # https://nextjs.org/blog/next-9-1#public-directory-support # public # vuepress build output .vuepress/dist # Serverless directories .serverless/ # FuseBox cache .fusebox/ # DynamoDB Local files .dynamodb/ # TernJS port file .tern-port # Only apps should have lockfiles npm-shrinkwrap.json package-lock.json yarn.lock has-dynamic-import-2.0.1/.npmignore000066400000000000000000000032601415552354200172250ustar00rootroot00000000000000# Logs logs *.log npm-debug.log* yarn-debug.log* yarn-error.log* lerna-debug.log* # Diagnostic reports (https://nodejs.org/api/report.html) report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json # Runtime data pids *.pid *.seed *.pid.lock # Directory for instrumented libs generated by jscoverage/JSCover lib-cov # Coverage directory used by tools like istanbul coverage *.lcov # nyc test coverage .nyc_output # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) .grunt # Bower dependency directory (https://bower.io/) bower_components # node-waf configuration .lock-wscript # Compiled binary addons (https://nodejs.org/api/addons.html) build/Release # Dependency directories node_modules/ jspm_packages/ # TypeScript v1 declaration files typings/ # TypeScript cache *.tsbuildinfo # Optional npm cache directory .npm # Optional eslint cache .eslintcache # Microbundle cache .rpt2_cache/ .rts2_cache_cjs/ .rts2_cache_es/ .rts2_cache_umd/ # Optional REPL history .node_repl_history # Output of 'npm pack' *.tgz # Yarn Integrity file .yarn-integrity # dotenv environment variables file .env .env.test # parcel-bundler cache (https://parceljs.org/) .cache # Next.js build output .next # Nuxt.js build / generate output .nuxt dist # Gatsby files .cache/ # Comment in the public line in if your project uses Gatsby and *not* Next.js # https://nextjs.org/blog/next-9-1#public-directory-support # public # vuepress build output .vuepress/dist # Serverless directories .serverless/ # FuseBox cache .fusebox/ # DynamoDB Local files .dynamodb/ # TernJS port file .tern-port # Only apps should have lockfiles npm-shrinkwrap.json package-lock.json yarn.lock .github/workflows has-dynamic-import-2.0.1/.npmrc000066400000000000000000000000671415552354200163500ustar00rootroot00000000000000package-lock=false allow-same-version=true message=v%s has-dynamic-import-2.0.1/.nycrc000066400000000000000000000002131415552354200163400ustar00rootroot00000000000000{ "all": true, "check-coverage": false, "reporter": ["text-summary", "text", "html", "json"], "exclude": [ "coverage", "test" ] } has-dynamic-import-2.0.1/CHANGELOG.md000066400000000000000000000100131415552354200170310ustar00rootroot00000000000000# Changelog All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [v2.0.1](https://github.com/inspect-js/has-dynamic-import/compare/v2.0.0...v2.0.1) - 2021-12-12 ### Commits - [actions] reuse common workflows [`308d8fb`](https://github.com/inspect-js/has-dynamic-import/commit/308d8fb4bc8e1330111da4df22be2c80b6e5f9f8) - [Fix] ensure the fake promise resolves on nextTick [`dea0dbc`](https://github.com/inspect-js/has-dynamic-import/commit/dea0dbca11217c8d0b0ecbbee26b7e5ae649cef6) - [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `safe-publish-latest`, `tape` [`5e9431c`](https://github.com/inspect-js/has-dynamic-import/commit/5e9431cea8952bb65905beb1ec23c9f259c36247) - [actions] update codecov uploader [`0b8d3f8`](https://github.com/inspect-js/has-dynamic-import/commit/0b8d3f87e7613976d353768fb45fad5a5ac3d7df) - [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `safe-publish-latest`, `tape` [`8fcdc05`](https://github.com/inspect-js/has-dynamic-import/commit/8fcdc055e32226fa8f76aea0ea0d13dff06e727b) ## [v2.0.0](https://github.com/inspect-js/has-dynamic-import/compare/v1.1.0...v2.0.0) - 2021-05-30 ### Commits - [Breaking] main entry point exports an `async function` and checks functionality; "syntax" entry point exports previous predicate [`dedeaac`](https://github.com/inspect-js/has-dynamic-import/commit/dedeaac1362eff8cf82485f22ed4e26ca79e8adf) ## [v1.1.0](https://github.com/inspect-js/has-dynamic-import/compare/v1.0.1...v1.1.0) - 2021-05-30 ### Commits - [New] add `syntax` entry point that matches current main entry point [`6a1ac52`](https://github.com/inspect-js/has-dynamic-import/commit/6a1ac5209ced527eea97e529b9b9de7752fa62b8) - [Dev Deps] update `eslint`, `auto-changelog` [`c8c737f`](https://github.com/inspect-js/has-dynamic-import/commit/c8c737fc058eb96499e282bd4ed372490a2dcff9) ## [v1.0.1](https://github.com/inspect-js/has-dynamic-import/compare/v1.0.0...v1.0.1) - 2021-05-13 ### Commits - [Fix] typo [`efcfc6e`](https://github.com/inspect-js/has-dynamic-import/commit/efcfc6ea041db51d76f45002bd49513cf8252bea) ## v1.0.0 - 2021-05-13 ### Commits - Tests [`04e7d5a`](https://github.com/inspect-js/has-dynamic-import/commit/04e7d5a7e6bae48fc47b4c383f7d353ceab31ce3) - Initial commit [`2346897`](https://github.com/inspect-js/has-dynamic-import/commit/234689702a12c0eb552693a3fcaa670278054703) - [meta] do not publish github action workflow files [`f81487c`](https://github.com/inspect-js/has-dynamic-import/commit/f81487ce5c70407bff2aa15f7ebb291bb988de0f) - Read me [`c5c096d`](https://github.com/inspect-js/has-dynamic-import/commit/c5c096deb76910954ead5c7b200ae55d66829d77) - Implementation [`cb67ea6`](https://github.com/inspect-js/has-dynamic-import/commit/cb67ea6de3234bc19d5929315f3591b7599746c9) - npm init [`9679f19`](https://github.com/inspect-js/has-dynamic-import/commit/9679f19a83dda19219c5f37c94673a937ace873b) - [meta] add `auto-changelog` [`a8fcf19`](https://github.com/inspect-js/has-dynamic-import/commit/a8fcf19f0810f49f8c5152c7d8721cb8163c7c6d) - Browser implementation. [`8c97791`](https://github.com/inspect-js/has-dynamic-import/commit/8c977914093b144a1d1f8e7cf1679f7e1b7b552b) - [meta] create `FUNDING.yml`, add `funding` field [`89fbce7`](https://github.com/inspect-js/has-dynamic-import/commit/89fbce7387166451156dfb5ad4f591791346c349) - [Tests] add `npm run lint` [`d9a308f`](https://github.com/inspect-js/has-dynamic-import/commit/d9a308f13ece4d5f89ebfbfa879ed6f19d5067e8) - [meta] add `safe-publish-latest` [`eb01fff`](https://github.com/inspect-js/has-dynamic-import/commit/eb01fff88f3b2929e3c3b956ed5763d7495b913d) - Only apps should have lockfiles [`d7f41ab`](https://github.com/inspect-js/has-dynamic-import/commit/d7f41ab00ae113fdd02a21287ddbf33602da5e93) - [Tests] skip `nyc` on `io.js` `v3.0-3.2`, since it core dumps [`1778f5d`](https://github.com/inspect-js/has-dynamic-import/commit/1778f5d500855118e06adc9b5ccc12e382055218) has-dynamic-import-2.0.1/LICENSE000066400000000000000000000020531415552354200162320ustar00rootroot00000000000000MIT License Copyright (c) 2021 Inspect JS 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: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 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. has-dynamic-import-2.0.1/README.md000066400000000000000000000045021415552354200165050ustar00rootroot00000000000000# has-dynamic-import [![Version Badge][npm-version-svg]][package-url] [![github actions][actions-image]][actions-url] [![coverage][codecov-image]][codecov-url] [![dependency status][deps-svg]][deps-url] [![dev dependency status][dev-deps-svg]][dev-deps-url] [![License][license-image]][license-url] [![Downloads][downloads-image]][downloads-url] [![npm badge][npm-badge-png]][package-url] Does the current environment have `import()` support? At the time of this writing, node v12.17+, v13.2+ and v14.0+ has support for dynamic [`import()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#dynamic_imports); the syntax is supported in node v10+. The former can be checked in the package‘s main export, which is an `async function` that returns a boolean indicating if the current environment fully supports dynamic import. Note that in node v12.17 - v12.19 and v13.4 - v13.13, an ExperimentalWarning will be logged. The latter can be checked with `'has-dynamic-import/syntax'`, which is a function that returns a boolean indicating if the current environment supports parsing the syntax of dynamic import. ## Tests Simply clone the repo, `npm install`, and run `npm test` [package-url]: https://npmjs.org/package/has-dynamic-import [npm-version-svg]: https://versionbadg.es/inspect-js/has-dynamic-import.svg [deps-svg]: https://david-dm.org/inspect-js/has-dynamic-import.svg [deps-url]: https://david-dm.org/inspect-js/has-dynamic-import [dev-deps-svg]: https://david-dm.org/inspect-js/has-dynamic-import/dev-status.svg [dev-deps-url]: https://david-dm.org/inspect-js/has-dynamic-import#info=devDependencies [npm-badge-png]: https://nodei.co/npm/has-dynamic-import.png?downloads=true&stars=true [license-image]: https://img.shields.io/npm/l/has-dynamic-import.svg [license-url]: LICENSE [downloads-image]: https://img.shields.io/npm/dm/has-dynamic-import.svg [downloads-url]: https://npm-stat.com/charts.html?package=has-dynamic-import [codecov-image]: https://codecov.io/gh/inspect-js/has-dynamic-import/branch/main/graphs/badge.svg [codecov-url]: https://app.codecov.io/gh/inspect-js/has-dynamic-import/ [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/inspect-js/has-dynamic-import [actions-url]: https://github.com/inspect-js/has-dynamic-import/actions has-dynamic-import-2.0.1/browser-syntax.js000066400000000000000000000003001415552354200205630ustar00rootroot00000000000000'use strict'; module.exports = function hasSyntax() { try { Function('import("").catch(() => {})'); // eslint-disable-line no-new-func return true; } catch (e) { return false; } }; has-dynamic-import-2.0.1/browser.js000066400000000000000000000011261415552354200172460ustar00rootroot00000000000000'use strict'; var callBound = require('call-bind/callBound'); var $then = callBound('Promise.prototype.then', true); var pFalse = $then && Promise.resolve(false); var thunkFalse = function () { return false; }; var thunkTrue = function () { return true; }; module.exports = function hasFunctionality() { if (!$then) { return { then: function (resolve) { resolve(false); } }; } try { var promise = Function('return import("data:text/javascript,")')(); // eslint-disable-line no-new-func return $then(promise, thunkTrue, thunkFalse); } catch (e) { return pFalse; } }; has-dynamic-import-2.0.1/import.js000066400000000000000000000002161415552354200170740ustar00rootroot00000000000000'use strict'; module.exports = function () { const promise = import('data:text/javascript,'); promise.catch(() => {}); return promise; }; has-dynamic-import-2.0.1/index.js000066400000000000000000000017661415552354200167040ustar00rootroot00000000000000'use strict'; var callBound = require('call-bind/callBound'); var callBind = require('call-bind'); var GetIntrinsic = require('get-intrinsic'); var $then = callBound('Promise.prototype.then', true); var $Promise = GetIntrinsic('%Promise%', true); var $PromiseResolve = GetIntrinsic('%Promise.resolve%', true); var $resolve = $Promise && $PromiseResolve && callBind($PromiseResolve, $Promise); var thunkFalse = function () { return false; }; var thunkTrue = function () { return true; }; module.exports = function hasDynamicImport() { if (!$then) { var p = { then: function (resolve) { // eslint-disable-line consistent-return if (typeof resolve === 'function') { process.nextTick(function () { resolve(false); }); } else { return hasDynamicImport(); } } }; return p; } try { var importWrapper = require('./import'); // eslint-disable-line global-require return $then(importWrapper(), thunkTrue, thunkFalse); } catch (e) { return $resolve(false); } }; has-dynamic-import-2.0.1/package.json000066400000000000000000000040561415552354200175200ustar00rootroot00000000000000{ "name": "has-dynamic-import", "version": "2.0.1", "description": "Does the current environment have `import()` support?", "main": "index.js", "browser": { "./": "./browser.js", "./syntax": "./browser-syntax.js" }, "exports": { ".": [ { "browser": "./browser.js", "default": "./index.js" }, "./index.js" ], "./syntax": [ { "browser": "./browser-syntax.js", "default": "./syntax.js" }, "./syntax.js" ], "./package.json": "./package.json" }, "scripts": { "prepublishOnly": "safe-publish-latest", "prepublish": "not-in-publish || npm run prepublishOnly", "lint": "eslint --ext=.js,.mjs .", "pretest": "npm run lint", "tests-only": "nyc tape 'test/**/*.js'", "test": "npm run tests-only", "posttest": "aud --production", "version": "auto-changelog && git add CHANGELOG.md", "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\"" }, "repository": { "type": "git", "url": "git+https://github.com/inspect-js/has-dynamic-import.git" }, "keywords": [ "import", "dynamic", "modules", "esm", "javascript", "ecmascript", "esmodules" ], "author": "Jordan Harband ", "funding": { "url": "https://github.com/sponsors/ljharb" }, "license": "MIT", "bugs": { "url": "https://github.com/inspect-js/has-dynamic-import/issues" }, "homepage": "https://github.com/inspect-js/has-dynamic-import#readme", "devDependencies": { "@ljharb/eslint-config": "^20.0.0", "aud": "^1.1.5", "auto-changelog": "^2.3.0", "eslint": "^8.4.1", "nyc": "^10.3.2", "safe-publish-latest": "^2.0.0", "semver": "^6.3.0", "tape": "^5.3.2" }, "directories": { "test": "test" }, "auto-changelog": { "output": "CHANGELOG.md", "template": "keepachangelog", "unreleased": false, "commitLimit": false, "backfillLimit": false, "hideCredit": true }, "dependencies": { "call-bind": "^1.0.2", "get-intrinsic": "^1.1.1" }, "testling": { "files": "test/index.js" } } has-dynamic-import-2.0.1/syntax.js000066400000000000000000000002611415552354200171100ustar00rootroot00000000000000'use strict'; module.exports = function hasSyntax() { try { require('./import'); // eslint-disable-line global-require return true; } catch (e) { return false; } }; has-dynamic-import-2.0.1/test/000077500000000000000000000000001415552354200162045ustar00rootroot00000000000000has-dynamic-import-2.0.1/test/index.js000066400000000000000000000050351415552354200176540ustar00rootroot00000000000000'use strict'; var test = require('tape'); var semver = require('semver'); var isBrowser = typeof window !== 'undefined'; var isNode = !isBrowser && typeof process !== 'undefined'; // eslint-disable-next-line global-require var spawnSync = isNode && require('child_process').spawnSync; var hasFullSupport = require('../'); var hasSyntax = require('../syntax'); var browserHasFullSupport = require('../browser'); var browserHasSyntax = require('../browser-syntax'); test('hasFullSupport', function (t) { t.equal(typeof hasFullSupport, 'function', 'is a function'); t.test('node', { skip: !isNode }, function (st) { var promise = hasFullSupport(); st.equal(typeof promise.then, 'function', 'returns a thenable'); promise.then(function (result) { st.equal( result, semver.satisfies(process.version, '^12.17 || ^13.2 || >=14'), 'result matches expected node version range' ); st.end(); }); }); t.test('experimental warning', { skip: !spawnSync || process.env.RECURSION }, function (st) { st.plan(1); var res = spawnSync('node', ['test'], { env: { PATH: process.env.PATH, RECURSION: 'recursion' } }); if (semver.satisfies(process.version, '^12.17 <12.20 || ^13.4 < 13.14')) { st.ok(String(res.stderr), 'stderr has an experimental warning in it'); } else { st.equal(String(res.stderr), '', 'stderr is empty'); } }); t.test('browser', function (st) { var promise = browserHasFullSupport(); st.equal(typeof promise.then, 'function', 'returns a thenable'); promise.then(function (result) { hasFullSupport().then(function (nodeResult) { st.equal( result, nodeResult, 'matches result from node implementation' ); st.end(); }); }); }); t.test('browser', function (st) { var result = browserHasSyntax(); st.equal(typeof result, 'boolean', 'returns a boolean'); st.equal( result, hasSyntax(), 'matches result from node implementation' ); st.end(); }); }); test('hasSyntax', function (t) { t.equal(typeof hasSyntax, 'function', 'is a function'); t.test('node', { skip: !isNode }, function (st) { var result = hasSyntax(); st.equal(typeof result, 'boolean', 'returns a boolean'); st.equal( result, semver.satisfies(process.version, '>=10'), 'result matches expected node version range' ); st.end(); }); t.test('browser', function (st) { var result = browserHasSyntax(); st.equal(typeof result, 'boolean', 'returns a boolean'); st.equal( result, hasSyntax(), 'matches result from node implementation' ); st.end(); }); });