Skip to content

Commit

Permalink
feat: Add types to config-array (#3)
Browse files Browse the repository at this point in the history
Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
  • Loading branch information
nzakas and mdjermanovic committed May 8, 2024
1 parent dd42ffa commit 8b80e81
Show file tree
Hide file tree
Showing 13 changed files with 492 additions and 192 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
- name: npm install and test
run: |
npm install
npm run build
npm test
env:
CI: true
12 changes: 5 additions & 7 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ jobs:
node-version: lts/*
registry-url: "https://registry.npmjs.org"

- run: npm install
- run: |
npm install
npm run build
if: ${{ steps.release.outputs.releases_created }}
#-----------------------------------------------------------------------------
Expand Down Expand Up @@ -87,9 +89,7 @@ jobs:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

- name: Publish @eslint/object-schema package to JSR
run: |
npm run build --if-present
npx jsr publish
run: npx jsr publish
working-directory: packages/object-schema
if: ${{ steps.release.outputs['packages/object-schema--release_created'] }}

Expand Down Expand Up @@ -120,9 +120,7 @@ jobs:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

- name: Publish @eslint/config-array package to JSR
run: |
npm run build --if-present
npx jsr publish
run: npx jsr publish
working-directory: packages/config-array
if: ${{ steps.release.outputs['packages/config-array--release_created'] }}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"type": "module",
"scripts": {
"test": "npm test --workspaces --if-present",
"build": "node scripts/build.js",
"lint": "eslint .",
"lint:fix": "eslint --fix .",
"fmt": "prettier --write ."
Expand Down
9 changes: 7 additions & 2 deletions packages/config-array/jsr.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
"version": "0.12.3",
"exports": "./dist/esm/index.js",
"publish": {
"exclude": [
"!dist"
"include": [
"dist/esm/index.js",
"dist/esm/index.d.ts",
"dist/esm/types.d.ts",
"README.md",
"jsr.json",
"LICENSE"
]
}
}
20 changes: 16 additions & 4 deletions packages/config-array/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@
"default": "./dist/esm/index.js"
}
},
"files": [
"dist/cjs/index.cjs",
"dist/cjs/index.d.cts",
"dist/cjs/types.d.ts",
"dist/esm/index.js",
"dist/esm/index.d.ts",
"dist/esm/types.d.ts",
"README.md",
"LICENSE"
],
"repository": {
"type": "git",
"url": "git+https://github.com/eslint/rewrite.git"
Expand All @@ -23,8 +33,9 @@
},
"homepage": "https://github.com/eslint/rewrite#readme",
"scripts": {
"build": "rollup -c",
"prepare": "npm run build",
"build:dedupe-types": "node ../../tools/dedupe-types.js dist/cjs/index.cjs dist/esm/index.js",
"build": "rollup -c && npm run build:dedupe-types && tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json",
"pretest": "npm run build",
"test": "mocha tests/"
},
"keywords": [
Expand All @@ -39,10 +50,11 @@
"minimatch": "^3.0.5"
},
"devDependencies": {
"@types/minimatch": "^3.0.5",
"mocha": "^10.4.0",
"rollup": "^4.16.2",
"typescript": "^5.4.5",
"rollup-plugin-copy": "^3.5.0"
"rollup-plugin-copy": "^3.5.0",
"typescript": "^5.4.5"
},
"engines": {
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
Expand Down
23 changes: 17 additions & 6 deletions packages/config-array/src/base-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,27 @@
* @author Nicholas C. Zakas
*/

//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------

/** @typedef {import("@eslint/object-schema").PropertyDefinition} PropertyDefinition */
/** @typedef {import("@eslint/object-schema").ObjectDefinition} ObjectDefinition */

//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------

/**
* A strategy that does nothing.
* @type {PropertyDefinition}
*/
const NOOP_STRATEGY = {
required: false,
merge() {
return undefined;
},
validate() { }
validate() {},
};

//------------------------------------------------------------------------------
Expand All @@ -21,7 +32,7 @@ const NOOP_STRATEGY = {

/**
* The base schema that every ConfigArray uses.
* @type Object
* @type {ObjectDefinition}
*/
export const baseSchema = Object.freeze({
name: {
Expand All @@ -30,11 +41,11 @@ export const baseSchema = Object.freeze({
return undefined;
},
validate(value) {
if (typeof value !== 'string') {
throw new TypeError('Property must be a string.');
if (typeof value !== "string") {
throw new TypeError("Property must be a string.");
}
}
},
},
files: NOOP_STRATEGY,
ignores: NOOP_STRATEGY
ignores: NOOP_STRATEGY,
});

0 comments on commit 8b80e81

Please sign in to comment.