diff --git a/.circleci/config.yml b/.circleci/config.yml index e577bdf9d..ab0185473 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -91,6 +91,14 @@ jobs: - *workspace - run: npm run build - run: npm run test:jest + import-compat: + <<: *nodelts + steps: + - *workspace + - run: npm run compat:ts:cjs -w import-compat + - run: npm run compat:js:cjs -w import-compat + - run: npm run compat:ts:esm -w import-compat + - run: npm run compat:js:esm -w import-compat # chrome: # <<: *browsers # steps: @@ -133,12 +141,10 @@ workflows: <<: *triggerable-by-tag requires: - checkout_code - # could be parallel with build, lint, and unit but it's a slow job - # And circlecifree tier only has 3 concurrent jobs, so overall faster - # to defer - typelint: <<: *triggerable-by-tag - <<: *run-after-first-jobs + requires: + - checkout_code - nodefetch3: <<: *triggerable-by-tag <<: *run-after-first-jobs @@ -148,6 +154,10 @@ workflows: - jest: <<: *triggerable-by-tag <<: *run-after-first-jobs + - import-compat: + <<: *triggerable-by-tag + requires: + - build # - chrome: # <<: *triggerable-by-tag # <<: *run-after-first-jobs @@ -160,6 +170,7 @@ workflows: # - chrome # - firefox - build + - import-compat - typelint - commonjs - jest diff --git a/.gitignore b/.gitignore index 1bc2cf7ab..4b70ef47a 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ coverage/ # built files /docs/fetch-mock/dist/ /packages/**/dist + +import-compat/ts-*.js diff --git a/import-compat/js-cjs.js b/import-compat/js-cjs.js new file mode 100644 index 000000000..ae44de43a --- /dev/null +++ b/import-compat/js-cjs.js @@ -0,0 +1,5 @@ +const fetchMockCore = require('@fetch-mock/core').default; +fetchMockCore.route('http://example.com', 200); + +const fetchMock = require('fetch-mock').default; +fetchMock.mock('http://example.com', 200); diff --git a/import-compat/js-esm.mjs b/import-compat/js-esm.mjs new file mode 100644 index 000000000..f56f561ac --- /dev/null +++ b/import-compat/js-esm.mjs @@ -0,0 +1,5 @@ +import fetchMockCore from "@fetch-mock/core"; +fetchMockCore.route("http://example.com", 200); + +import fetchMock from "fetch-mock"; +fetchMock.mock("http://example.com", 200); diff --git a/import-compat/package.json b/import-compat/package.json new file mode 100644 index 000000000..7f1a95d8f --- /dev/null +++ b/import-compat/package.json @@ -0,0 +1,10 @@ +{ + "name": "fetch-mock-compat-tests", + "version": "1.0.0", + "scripts": { + "compat:ts:esm": "tsc ts-esm.ts --target esnext --moduleResolution nodenext --module nodenext && node ts-esm.js", + "compat:ts:cjs": "tsc ts-cjs.ts --target esnext --moduleResolution nodenext --module nodenext && node ts-cjs.js", + "compat:js:esm": "node js-esm.mjs", + "compat:js:cjs": "node js-cjs.js" + } +} diff --git a/import-compat/ts-cjs.ts b/import-compat/ts-cjs.ts new file mode 100644 index 000000000..9e99142ab --- /dev/null +++ b/import-compat/ts-cjs.ts @@ -0,0 +1,5 @@ +const fetchMockCore = require("@fetch-mock/core").default; +fetchMockCore.route("http://example.com", 200); + +const fetchMock = require("fetch-mock").default; +fetchMock.mock("http://example.com", 200); diff --git a/import-compat/ts-esm.ts b/import-compat/ts-esm.ts new file mode 100644 index 000000000..f56f561ac --- /dev/null +++ b/import-compat/ts-esm.ts @@ -0,0 +1,5 @@ +import fetchMockCore from "@fetch-mock/core"; +fetchMockCore.route("http://example.com", 200); + +import fetchMock from "fetch-mock"; +fetchMock.mock("http://example.com", 200); diff --git a/package-lock.json b/package-lock.json index a0f68d251..aedb6584e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,8 @@ "license": "MIT", "workspaces": [ "packages/*", - "docs" + "docs", + "import-compat" ], "devDependencies": { "@commitlint/cli": "^19.3.0", @@ -67,6 +68,9 @@ "node": ">=18.0" } }, + "import-compat": { + "version": "1.0.0" + }, "node_modules/@algolia/autocomplete-core": { "version": "1.9.3", "resolved": "https://registry.npmjs.org/@algolia/autocomplete-core/-/autocomplete-core-1.9.3.tgz", @@ -2450,6 +2454,32 @@ "node": ">=v18" } }, + "node_modules/@cspotcode/source-map-support": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", + "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", + "dev": true, + "optional": true, + "peer": true, + "dependencies": { + "@jridgewell/trace-mapping": "0.3.9" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@cspotcode/source-map-support/node_modules/@jridgewell/trace-mapping": { + "version": "0.3.9", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", + "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", + "dev": true, + "optional": true, + "peer": true, + "dependencies": { + "@jridgewell/resolve-uri": "^3.0.3", + "@jridgewell/sourcemap-codec": "^1.4.10" + } + }, "node_modules/@discoveryjs/json-ext": { "version": "0.5.7", "resolved": "https://registry.npmjs.org/@discoveryjs/json-ext/-/json-ext-0.5.7.tgz", @@ -5876,6 +5906,38 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/@tsconfig/node10": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.11.tgz", + "integrity": "sha512-DcRjDCujK/kCk/cUe8Xz8ZSpm8mS3mNNpta+jGCA6USEDfktlNvm1+IuZ9eTcDbNk41BHwpHHeW+N1lKCz4zOw==", + "dev": true, + "optional": true, + "peer": true + }, + "node_modules/@tsconfig/node12": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz", + "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==", + "dev": true, + "optional": true, + "peer": true + }, + "node_modules/@tsconfig/node14": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz", + "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==", + "dev": true, + "optional": true, + "peer": true + }, + "node_modules/@tsconfig/node16": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.4.tgz", + "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==", + "dev": true, + "optional": true, + "peer": true + }, "node_modules/@types/acorn": { "version": "4.0.6", "resolved": "https://registry.npmjs.org/@types/acorn/-/acorn-4.0.6.tgz", @@ -9487,6 +9549,14 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, + "node_modules/create-require": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", + "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", + "dev": true, + "optional": true, + "peer": true + }, "node_modules/cross-fetch": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-4.0.0.tgz", @@ -12297,6 +12367,10 @@ "resolved": "packages/fetch-mock", "link": true }, + "node_modules/fetch-mock-compat-tests": { + "resolved": "import-compat", + "link": true + }, "node_modules/fflate": { "version": "0.8.2", "resolved": "https://registry.npmjs.org/fflate/-/fflate-0.8.2.tgz", @@ -17330,6 +17404,14 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/make-error": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", + "dev": true, + "optional": true, + "peer": true + }, "node_modules/makeerror": { "version": "1.0.12", "resolved": "https://registry.npmjs.org/makeerror/-/makeerror-1.0.12.tgz", @@ -24843,6 +24925,70 @@ "code-block-writer": "^12.0.0" } }, + "node_modules/ts-node": { + "version": "10.9.2", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz", + "integrity": "sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==", + "dev": true, + "optional": true, + "peer": true, + "dependencies": { + "@cspotcode/source-map-support": "^0.8.0", + "@tsconfig/node10": "^1.0.7", + "@tsconfig/node12": "^1.0.7", + "@tsconfig/node14": "^1.0.0", + "@tsconfig/node16": "^1.0.2", + "acorn": "^8.4.1", + "acorn-walk": "^8.1.1", + "arg": "^4.1.0", + "create-require": "^1.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "v8-compile-cache-lib": "^3.0.1", + "yn": "3.1.1" + }, + "bin": { + "ts-node": "dist/bin.js", + "ts-node-cwd": "dist/bin-cwd.js", + "ts-node-esm": "dist/bin-esm.js", + "ts-node-script": "dist/bin-script.js", + "ts-node-transpile-only": "dist/bin-transpile.js", + "ts-script": "dist/bin-script-deprecated.js" + }, + "peerDependencies": { + "@swc/core": ">=1.2.50", + "@swc/wasm": ">=1.2.50", + "@types/node": "*", + "typescript": ">=2.7" + }, + "peerDependenciesMeta": { + "@swc/core": { + "optional": true + }, + "@swc/wasm": { + "optional": true + } + } + }, + "node_modules/ts-node/node_modules/arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", + "dev": true, + "optional": true, + "peer": true + }, + "node_modules/ts-node/node_modules/diff": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "dev": true, + "optional": true, + "peer": true, + "engines": { + "node": ">=0.3.1" + } + }, "node_modules/ts-to-jsdoc": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/ts-to-jsdoc/-/ts-to-jsdoc-2.1.0.tgz", @@ -25818,6 +25964,14 @@ "v8": "bin/v8" } }, + "node_modules/v8-compile-cache-lib": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", + "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", + "dev": true, + "optional": true, + "peer": true + }, "node_modules/v8-to-istanbul": { "version": "9.3.0", "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.3.0.tgz", @@ -27127,6 +27281,17 @@ "node": "*" } }, + "node_modules/yn": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", + "dev": true, + "optional": true, + "peer": true, + "engines": { + "node": ">=6" + } + }, "node_modules/yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", @@ -27190,6 +27355,10 @@ "optional": true } } + }, + "tool-compat": { + "version": "1.0.0", + "extraneous": true } } } diff --git a/package.json b/package.json index 99b08d6b9..59172fcbb 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,8 @@ }, "workspaces": [ "packages/*", - "docs" + "docs", + "import-compat" ], "scripts": { "lint:staged": "eslint --cache --fix --ext .js,.cjs", @@ -43,6 +44,8 @@ "@commitlint/config-conventional": "^19.2.2", "@rollup/plugin-commonjs": "^25.0.7", "@rollup/plugin-node-resolve": "^15.2.3", + "@types/events": "^3.0.3", + "@types/globrex": "^0.1.4", "@types/node": "^20.14.10", "@vitest/browser": "^1.1.0", "@vitest/coverage-istanbul": "^1.1.0", @@ -65,8 +68,6 @@ "typescript": "^5.5.3", "v8": "^0.1.0", "vitest": "^1.1.0", - "@types/events": "^3.0.3", - "@types/globrex": "^0.1.4", "webdriverio": "^8.27.0" }, "volta": { @@ -79,7 +80,7 @@ "packages/**/*.js": [ "npm run types:check" ], - "**/*.md":[ + "**/*.md": [ "npm run prettier" ] } diff --git a/shared-rollup.config.js b/shared-rollup.config.js index 316d9c83c..420f01cf2 100644 --- a/shared-rollup.config.js +++ b/shared-rollup.config.js @@ -6,6 +6,7 @@ export default { dir: './dist', entryFileNames: 'commonjs.js', format: 'commonjs', + // exports: 'named', }, plugins: [ nodeResolve({ preferBuiltins: false }),