Skip to content

Commit

Permalink
Merge pull request #780 from wheresrhys/rhys/mts-compat
Browse files Browse the repository at this point in the history
Fix .mts imports
  • Loading branch information
wheresrhys authored Aug 8, 2024
2 parents d02d1ff + 1251af2 commit da082b9
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 20 deletions.
11 changes: 4 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,11 @@ jobs:
- *workspace
- run: npm run build
- run: npm run test:jest
import-compat:
module-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
- run: npm run compat:module
# chrome:
# <<: *browsers
# steps:
Expand Down Expand Up @@ -156,7 +153,7 @@ workflows:
- jest:
<<: *triggerable-by-tag
<<: *run-after-first-jobs
- import-compat:
- module-compat:
<<: *triggerable-by-tag
requires:
- build
Expand All @@ -172,7 +169,7 @@ workflows:
# - chrome
# - firefox
- build
# - import-compat
- module-compat
- typelint
- commonjs
- jest
Expand Down
13 changes: 9 additions & 4 deletions import-compat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
"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": "cp ts-esm.ts js-esm.mjs && node js-esm.mjs",
"compat:js:cjs": "cp ts-cjs.ts js-cjs.js && node js-cjs.js"
"compat:mts:esm": "tsc ts-esm.mts --target esnext --moduleResolution nodenext --module nodenext && node ts-esm.mjs || echo \"\\033[0;31mfailed mts:esm\\033[0m\"",
"compat:ts:esm": "tsc ts-esm.ts --target esnext --moduleResolution nodenext --module nodenext && node ts-esm.js || echo \"\\033[0;31mfailed ts:esm\\033[0m\"",
"compat:ts:cjs": "tsc ts-cjs.ts --target esnext --moduleResolution nodenext --module nodenext && node ts-cjs.js || echo \"\\033[0;31mfailed ts:cjs\\033[0m\"",
"compat:js:esm": "cp ts-esm.ts js-esm.mjs && node js-esm.mjs || echo \"\\033[0;31mfailed js:esm\\033[0m\"",
"compat:js:cjs": "cp ts-cjs.ts js-cjs.js && node js-cjs.js || echo \"\\033[0;31mfailed js:cjs\\033[0m\"",
"compat:module": "npm run compat:mts:esm && npm run compat:ts:esm && npm run compat:ts:cjs && npm run compat:js:esm && npm run compat:js:cjs"
}
}



7 changes: 7 additions & 0 deletions import-compat/ts-esm.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import fetchMockCore, {FetchMock} from "@fetch-mock/core";
fetchMockCore.route("http://example.com", 200);

new FetchMock({})

import fetchMock from "fetch-mock";
fetchMock.mock("http://example.com", 200);
112 changes: 112 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"test": "vitest --ui .",
"test:coverage": "vitest run --coverage ./packages/**/src/__tests__",
"test:jest": "jest ./packages/fetch-mock/test/framework-compat/jest.spec.js",
"coverage:send": "cat ./coverage/lcov.info | coveralls"
"coverage:send": "cat ./coverage/lcov.info | coveralls",
"compat:module": "npm run compat:module -w import-compat"
},
"devDependencies": {
"@commitlint/cli": "^19.3.0",
Expand All @@ -64,6 +65,7 @@
"lint-staged": "^15.2.7",
"prettier": "^3.1.1",
"rollup": "^4.9.1",
"rollup-plugin-copy": "^3.5.0",
"ts-to-jsdoc": "^2.1.0",
"typescript": "^5.5.3",
"v8": "^0.1.0",
Expand Down
12 changes: 9 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@
"main": "./dist/commonjs.js",
"module": "./src/index.js",
"exports": {
"types": "./types/index.d.ts",
"browser": "./src/index.js",
"import": "./src/index.js",
"require": "./dist/commonjs.js"
"import": {
"default": "./src/index.js",
"types": "./types/index.d.ts"
},
"require": {
"types": "./dist/types/index.d.ts",
"default": "./dist/commonjs.js"
}
},
"type": "module",
"types": "./types/index.d.ts",
"scripts": {
"build": "rollup -c"
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/package.json

This file was deleted.

12 changes: 9 additions & 3 deletions packages/fetch-mock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@
"main": "./dist/commonjs.js",
"module": "./src/index.js",
"exports": {
"types": "./types/index.d.ts",
"browser": "./src/index.js",
"import": "./src/index.js",
"require": "./dist/commonjs.js"
"import": {
"default": "./src/index.js",
"types": "./types/index.d.ts"
},
"require": {
"types": "./dist/types/index.d.ts",
"default": "./dist/commonjs.js"
}
},
"types": "./types/index.d.ts",
"type": "module",
"scripts": {
"build": "rollup -c"
},
Expand Down
1 change: 0 additions & 1 deletion packages/fetch-mock/src/package.json

This file was deleted.

24 changes: 24 additions & 0 deletions shared-rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import copy from 'rollup-plugin-copy';
import { writeFile, mkdir } from 'fs/promises';

function createCommonJsPackage() {
const pkg = { type: 'commonjs' };

return {
name: 'cjs-package',
buildEnd: async () => {
await mkdir('./dist', { recursive: true });
await writeFile('./dist/package.json', JSON.stringify(pkg, null, 2));
},
};
}

export default {
input: './src/index.js',
output: {
Expand All @@ -14,5 +29,14 @@ export default {
// sourcemaps(),
// builtins(),
// globals(),
copy({
targets: [
{
src: './types/*.d.ts',
dest: 'dist/types',
},
],
}),
createCommonJsPackage(),
],
};

0 comments on commit da082b9

Please sign in to comment.