Skip to content

Commit 9c82439

Browse files
authored
Merge pull request #642 from soluble-io/cache-ioredis-esm-first
[cache-ioredis] esm first, dual packaging cjs/esm
2 parents 5b2e392 + e7ac27a commit 9c82439

12 files changed

Lines changed: 91 additions & 57 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@soluble/cache-ioredis': minor
3+
---
4+
5+
ESM first, support dual packaging (esm/cjs).

packages/cache-interop/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
"es-check": "7.0.0",
6969
"get-tsconfig": "4.2.0",
7070
"jest": "28.1.3",
71-
"microbundle": "0.15.0",
7271
"rimraf": "3.0.2",
7372
"size-limit": "8.0.0",
7473
"ts-jest": "28.0.7",

packages/cache-interop/tsconfig.jest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"$schema": "https://json.schemastore.org/tsconfig",
33
"extends": "./tsconfig.json",
44
"compilerOptions": {
5-
"target": "es6",
6-
"module": "commonjs",
5+
"target": "ES2020",
6+
"module": "ESNext",
77
"noImplicitAny": false,
88
"declaration": false,
99
"noUnusedLocals": false,

packages/cache-ioredis/.escheckrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"ecmaVersion": "es2017",
2+
"ecmaVersion": "es2020",
33
"module": true,
44
"files": "./dist/**/*.js"
55
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = [
2+
{
3+
name: 'JS',
4+
path: ['dist/index.js'],
5+
limit: '2.5KB',
6+
},
7+
];

packages/cache-ioredis/.size-limit.js

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,54 @@
11
// @ts-check
2+
import { pathsToModuleNameMapper } from 'ts-jest';
3+
import { getTsconfig } from 'get-tsconfig';
4+
import { getJestCachePath } from '../../cache.config.js';
25

3-
const { defaults: tsPreset } = require('ts-jest/presets');
4-
const { pathsToModuleNameMapper } = require('ts-jest');
6+
const tsConfigFile = new URL('./tsconfig.jest.json', import.meta.url).pathname;
57

6-
const {
7-
compilerOptions: { paths: tsConfigPaths },
8-
} = require('../../tsconfig.paths.json');
9-
10-
// Take the paths from tsconfig automatically from base tsconfig.json
11-
// @link https://kulshekhar.github.io/ts-jest/docs/paths-mapping
12-
const getTsConfigBasePaths = () => {
13-
return tsConfigPaths
14-
? pathsToModuleNameMapper(tsConfigPaths, {
15-
prefix: '<rootDir>/tricky-false-path-to-remove-parent/packages',
8+
/**
9+
* Transform the tsconfig paths into jest compatible one (support extends)
10+
* @param {string} tsConfigFile
11+
*/
12+
const getTsConfigBasePaths = (tsConfigFile) => {
13+
const parsedTsConfig = getTsconfig(tsConfigFile);
14+
if (parsedTsConfig === null) {
15+
throw new Error(`Cannot find tsconfig file: ${tsConfigFile}`);
16+
}
17+
const tsPaths = parsedTsConfig.config.compilerOptions?.paths;
18+
return tsPaths
19+
? pathsToModuleNameMapper(tsPaths, {
20+
prefix: '<rootDir>/',
1621
})
1722
: {};
1823
};
1924

20-
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
25+
/** @type {import('ts-jest/dist').InitialOptionsTsJest} */
2126
const config = {
22-
displayName: 'cache-ioredis/unit',
23-
testRunner: 'jest-circus/runner',
27+
displayName: `cache-interop:unit`,
28+
preset: 'ts-jest/presets/default-esm',
29+
cacheDirectory: getJestCachePath('@soluble/cache-interop'),
2430
testEnvironment: 'node',
31+
extensionsToTreatAsEsm: ['.ts'],
2532
verbose: true,
26-
transform: {
27-
...tsPreset.transform,
28-
},
29-
rootDir: '../',
30-
31-
testMatch: ['<rootDir>/cache-ioredis/src/**/*.test.ts'],
33+
rootDir: './src',
34+
testMatch: ['<rootDir>/**/*.{spec,test}.{js,jsx,ts,tsx}'],
3235
moduleNameMapper: {
33-
...getTsConfigBasePaths(),
36+
...getTsConfigBasePaths(tsConfigFile),
3437
},
35-
coverageDirectory: '<rootDir>/cache-ioredis/coverage',
38+
// false by default, overrides in cli, ie: yarn test:unit --collect-coverage=true
39+
collectCoverage: false,
40+
coverageDirectory: '<rootDir>/../coverage',
3641
collectCoverageFrom: [
37-
'<rootDir>/cache-ioredis/src/**/*.{ts,js}',
38-
'!**/*.test.ts',
39-
'!**/index.ts',
40-
'!**/*.d.ts',
42+
'<rootDir>/**/*.{ts,tsx,js,jsx}',
43+
'!**/*.test.{js,ts}',
44+
'!**/__mock__/*',
4145
],
4246
globals: {
4347
'ts-jest': {
44-
diagnostics: true,
45-
tsconfig: './tsconfig.jest.json',
48+
useESM: true,
49+
tsconfig: tsConfigFile,
4650
},
4751
},
4852
};
49-
module.exports = config;
53+
54+
export default config;

packages/cache-ioredis/package.json

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,18 @@
1818
"interop",
1919
"ioredis"
2020
],
21-
"jsnext:main": "dist/cache-ioredis.es.js",
22-
"source": "src/index.ts",
23-
"module": "dist/cache-ioredis.es.js",
24-
"main": "dist/cache-ioredis.js",
25-
"umd:main": "dist/cache-ioredis.umd.js",
26-
"typings": "dist/index.d.ts",
21+
"type": "module",
22+
"main": "./dist/index.cjs",
23+
"module": "./dist/index.js",
24+
"types": "./dist/index.d.ts",
25+
"exports": {
26+
".": {
27+
"import": {
28+
"types": "./dist/index.d.ts",
29+
"default": "./dist/index.js"
30+
}
31+
}
32+
},
2733
"files": [
2834
"dist"
2935
],
@@ -32,8 +38,8 @@
3238
"directory": "_release/package"
3339
},
3440
"scripts": {
35-
"start": "cross-env NODE_ENV=development microbundle watch",
36-
"build": "rimraf ./dist && cross-env NODE_ENV=production microbundle --tsconfig tsconfig.build.json --target node --format esm,cjs --no-compress && mv dist/cache-ioredis/src/*.d.ts dist/ && rm -rf dist/cache-ioredis/src/",
41+
"build": "tsup",
42+
"dev": "tsup --watch",
3743
"?build-release": "When https://github.com/atlassian/changesets/issues/432 has a solution we can remove this trick",
3844
"build-release": "yarn build && rimraf ./_release && yarn pack && mkdir ./_release && tar zxvf ./package.tgz --directory ./_release && rm ./package.tgz",
3945
"check-size": "size-limit",
@@ -67,8 +73,8 @@
6773
"@types/jest": "28.1.6",
6874
"cross-env": "7.0.3",
6975
"es-check": "7.0.0",
76+
"get-tsconfig": "4.2.0",
7077
"jest": "28.1.3",
71-
"microbundle": "0.15.0",
7278
"rimraf": "3.0.2",
7379
"size-limit": "8.0.0",
7480
"ts-jest": "28.0.7",
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
{
2+
"$schema": "https://json.schemastore.org/tsconfig",
23
"extends": "./tsconfig.json",
34
"compilerOptions": {
4-
"target": "ESNext",
5+
"target": "ES2020",
56
"module": "ESNext",
6-
"composite": false,
7+
"rootDir": "../",
8+
"baseUrl": "./cache-ioredis/src",
79
"noEmit": false,
810
"declaration": true,
911
"declarationMap": false,
1012
"declarationDir": "./dist",
11-
"incremental": false
13+
"tsBuildInfoFile": "./tsconfig.build.tsbuildinfo" // for tsup rollup dts tsBuildInfoFile is required when using incremental
1214
},
1315
"exclude": ["*.test.ts"]
1416
}

packages/cache-ioredis/tsconfig.jest.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
2+
"$schema": "https://json.schemastore.org/tsconfig",
23
"extends": "./tsconfig.json",
34
"compilerOptions": {
4-
"target": "es2017",
5-
"module": "commonjs",
5+
"target": "ES2020",
6+
"module": "ESNext",
67
"noImplicitAny": false,
78
"declaration": false,
89
"noUnusedLocals": false,

0 commit comments

Comments
 (0)