Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/deploy-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ jobs:
deploy:
uses: croct-tech/shared-public-configs/.github/workflows/publish-public-npm-package.yml@master
with:
build-dir: .
prepare-script: >-
cp package.json README.md build/ &&
cd build &&
tmp=$(mktemp) &&
jq --arg version "$GITHUB_REF_NAME" '.version = $version' package.json > "$tmp" &&
mv "$tmp" package.json
Expand Down
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ We recommend using [NPM](https://www.npmjs.com) to install the package:
npm install @croct/cache
```

The package ships both ESM and CommonJS entry points. ESM consumers can import named exports directly:

```ts
import {InMemoryCache} from '@croct/cache';
```

CommonJS consumers can load the matching CommonJS build with `require`:

```js
const {InMemoryCache} = require('@croct/cache');
```

All source modules are also available as subpath exports, for example `@croct/cache/inMemory`.

## Basic usage

The most common use case of this library is to decorate implementations with caching capabilities:
Expand Down Expand Up @@ -192,12 +206,25 @@ Before building the project, the dependencies must be installed:
npm install
```

The following command builds the library:
The following command builds the library with tsup:

```sh
npm run build
```

The build emits ESM, CommonJS, source map, and TypeScript declaration files in `build/` for the root entry point and each source module:

- `build/*.js` for ESM consumers
- `build/*.cjs` for CommonJS consumers
- `build/*.js.map` and `build/*.cjs.map` for runtime debugging
- `build/*.d.ts` and `build/*.d.cts` for TypeScript consumers

To verify the published package contract, including runtime exports, declaration resolution, and dry-run package contents, run:

```sh
npm run test:package
```

## License

Copyright © 2015-2021 Croct Limited, All Rights Reserved.
Expand Down
28 changes: 27 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,25 @@ import { defineConfig } from 'eslint/config';
import { configs } from '@croct/eslint-plugin';

export default defineConfig(
configs.typescript,
configs.typescript.map(config => ({

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This .map() silently disables every rule on .mjs files

In @croct/eslint-plugin@0.8.3, the @croct/javascript block (which carries all base rules) has no files. The ?? ['**/*.ts','**/*.tsx'] scopes it to TS, so the '*.mjs' 'test/*.mjs' globs added in package.json:61 are inert.

Proof: line 1 of this file uses import { defineConfig } with spaces, violating @stylistic/object-curly-spacing, and lint still passes.

Rewrite using extends — it already propagates files to the extended configs — instead of rewriting the preset's structure:

{files: ['**/*.ts', '**/*.tsx'], extends: [configs.typescript], languageOptions: {parserOptions: {projectService: {allowDefaultProject: ['*.config.ts']}, tsconfigRootDir: import.meta.dirname}}},
{files: ['**/*.mjs'], extends: [configs.javascript], languageOptions: {ecmaVersion: 2022}, rules: {'import-x/no-default-export': 'off'}},

ecmaVersion: 2022 is required because the preset sets 2018 and test/package-contract.mjs uses top-level await.

...config,
files: config.files ?? ['**/*.ts', '**/*.tsx'],
...(config.languageOptions === undefined
? {}
: {languageOptions: {
...config.languageOptions,
parserOptions: {
...config.languageOptions.parserOptions,
projectService: config.languageOptions.parserOptions?.projectService === true
? {allowDefaultProject: ['*.config.ts']}
: config.languageOptions.parserOptions?.projectService,
},
}}),
})),
{
files: ['src/**/*.ts'],
rules: {
'import-x/extensions': 'off',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turning this off for all of src hides the inconsistency

The rule was disabled to accommodate @croct/time/defaultClockProvider.js, but three conventions now coexist unenforced: package subpath with .js in src/holdWhileRevalidate.ts:3, without .js in test/holdWhileRevalidate.test.ts:2 and test/staleWhileRevalidate.test.ts:2, and extensionless relative imports.

eslint-plugin-import-x@4.16.1 supports a targeted override — keep the rule and carve out only where the extension is mandatory:

'import-x/extensions': ['error', 'never', {
    d: 'always', json: 'always',
    pathGroupOverrides: [{pattern: '@croct/time/**', action: 'ignore'}],
}],

And add .js to both @croct/time/clock/fixedClock imports in the tests.

'no-restricted-syntax': [
'error',
{
Expand Down Expand Up @@ -53,5 +68,16 @@ export default defineConfig(
},
],
},
},
{
files: ['tsup.config.ts'],
languageOptions: {
parserOptions: {
tsconfigRootDir: import.meta.dirname,
},
},
rules: {
'import-x/no-default-export': 'off',
},
}
);
7 changes: 0 additions & 7 deletions jest.config.js

This file was deleted.

17 changes: 17 additions & 0 deletions jest.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export default {
restoreMocks: true,
resetMocks: true,
extensionsToTreatAsEsm: ['.ts'],
transform: {
'^.+\\.ts$': [
'ts-jest',
{
useESM: true,
},
],
},
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
setupFilesAfterEnv: ['<rootDir>/test/setup-jest.mjs'],
};
Loading
Loading