Skip to content

Commit f5f67e0

Browse files
authored
Merge pull request #643 from soluble-io/redis-esm-first
[cache-redis] esm first, dual packaging cjs/esm
2 parents 9c82439 + 30ca007 commit f5f67e0

10 files changed

Lines changed: 247 additions & 2927 deletions

File tree

.changeset/tasty-comics-wonder.md

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

packages/cache-redis/.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-redis/.size-limit.js

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +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-redis/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-redis/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-redis/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-redis/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
};
4953

50-
module.exports = config;
54+
export default config;

packages/cache-redis/package.json

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,25 @@
1919
"redis",
2020
"node-redis"
2121
],
22-
"jsnext:main": "dist/cache-redis.es.js",
23-
"source": "src/index.ts",
24-
"module": "dist/cache-redis.es.js",
25-
"main": "dist/cache-redis.js",
26-
"umd:main": "dist/cache-redis.umd.js",
27-
"typings": "dist/index.d.ts",
28-
"files": [
29-
"dist"
30-
],
22+
"type": "module",
23+
"main": "./dist/index.cjs",
24+
"module": "./dist/index.js",
25+
"types": "./dist/index.d.ts",
26+
"exports": {
27+
".": {
28+
"import": {
29+
"types": "./dist/index.d.ts",
30+
"default": "./dist/index.js"
31+
}
32+
}
33+
},
3134
"sideEffects": false,
3235
"publishConfig": {
3336
"directory": "_release/package"
3437
},
3538
"scripts": {
36-
"start": "cross-env NODE_ENV=development microbundle watch",
37-
"build": "rimraf ./dist && cross-env NODE_ENV=production microbundle --tsconfig tsconfig.build.json --format esm,cjs --target node --no-compress && mv dist/cache-redis/src/*.d.ts dist/ && rm -rf dist/cache-redis/src/",
39+
"build": "tsup",
40+
"dev": "tsup --watch",
3841
"?build-release": "When https://github.com/atlassian/changesets/issues/432 has a solution we can remove this trick",
3942
"build-release": "yarn build && rimraf ./_release && yarn pack && mkdir ./_release && tar zxvf ./package.tgz --directory ./_release && rm ./package.tgz",
4043
"check-size": "size-limit",
@@ -68,8 +71,8 @@
6871
"@types/redis": "2.8.32",
6972
"cross-env": "7.0.3",
7073
"es-check": "7.0.0",
74+
"get-tsconfig": "4.2.0",
7175
"jest": "28.1.3",
72-
"microbundle": "0.15.0",
7376
"redis": "3.1.2",
7477
"rimraf": "3.0.2",
7578
"size-limit": "8.0.0",
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +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-
"baseUrl": "./src",
7+
"rootDir": "../",
8+
"baseUrl": "./cache-redis/src",
79
"noEmit": false,
810
"declaration": true,
911
"declarationMap": false,
10-
"declarationDir": "./dist"
12+
"declarationDir": "./dist",
13+
"tsBuildInfoFile": "./tsconfig.build.tsbuildinfo" // for tsup rollup dts tsBuildInfoFile is required when using incremental
1114
},
1215
"exclude": ["*.test.ts"]
1316
}

packages/cache-redis/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,
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { defineConfig } from 'tsup';
2+
3+
export default defineConfig((options) => {
4+
return {
5+
entry: ['src/index.ts'],
6+
splitting: true,
7+
clean: true,
8+
dts: true,
9+
format: ['esm', 'cjs'],
10+
platform: 'node',
11+
target: ['node14'],
12+
tsconfig: new URL('./tsconfig.build.json', import.meta.url).pathname,
13+
sourcemap: !options.watch,
14+
// Do not minify node only packages to let patching possible by the consumer (ie: patch-package)
15+
minify: false,
16+
};
17+
});

0 commit comments

Comments
 (0)