Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add types to config-array #3

Merged
merged 8 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
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"
]
}
}
19 changes: 16 additions & 3 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,7 +33,9 @@
},
"homepage": "https://github.com/eslint/rewrite#readme",
"scripts": {
"build": "rollup -c",
"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",
Copy link
Member

@kecrily kecrily Apr 30, 2024

Choose a reason for hiding this comment

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

We need to either delete the copied dist/{esm,cjs}/types.ts at the end of the build, or rename it to .d.ts when we copy it to avoid generating declarations of statements.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, I'm not sure I follow. This outputs both types.ts and types.d.ts in the output directories, unless I'm missing something?

Copy link
Member

@kecrily kecrily May 5, 2024

Choose a reason for hiding this comment

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

Yes, types.ts is not required at publish time. And the contents of types.ts and types.d.ts are the same.

Snapshot 2024-05-05 22 14 57

Copy link
Member Author

Choose a reason for hiding this comment

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

Gotcha. I think we can solve that by using files in package.json to avoid adding another step to this process.

Copy link
Member

Choose a reason for hiding this comment

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

Gotcha. I think we can solve that by using files in package.json to avoid adding another step to this process.

Should we then do the same in the object-schema package?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I'll update all the packages in a separate PR.

"pretest": "npm run build",
"prepare": "npm run build",
aladdin-add marked this conversation as resolved.
Show resolved Hide resolved
"test": "mocha tests/"
},
Expand All @@ -39,10 +51,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,
});
Loading
Loading