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

fix: include type definitions #186

Merged
merged 2 commits into from
Jul 23, 2024
Merged
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
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
; http://editorconfig.org

root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

20 changes: 0 additions & 20 deletions .eslintrc

This file was deleted.

1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
5 changes: 4 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Release and Publish
on:
push:
branches:
- master
- main
- alpha
- beta
- next
Expand All @@ -26,6 +26,9 @@ jobs:
- name: Lint files
run: npm run lint

- name: Generate type definitions
run: npm run types

- name: Run tests
run: npm run test

Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Run Lint and Tests
on:
push:
branches-ignore:
- master
- main
- alpha
- beta
- next
Expand All @@ -28,4 +28,6 @@ jobs:

- run: npm run lint

- run: npm run types

- run: npm test
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ tmp/**/*
coverage
.vscode
.nyc_output/
.tap/
.tap/
types/
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
package-lock=false
save-exact=true
2 changes: 1 addition & 1 deletion .prettierrc → .prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"tabWidth": 4,
"overrides": [
{
"files": [".prettierrc", "*.json", "*.yml", ".travis.yml", ".eslintrc"],
"files": ["*.json", "*.yml"],
"options": {
"tabWidth": 2
}
Expand Down
22 changes: 22 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import prettierConfig from 'eslint-config-prettier';
import prettierPlugin from 'eslint-plugin-prettier/recommended';
import globals from 'globals';
import js from '@eslint/js';

export default [
js.configs.recommended,
prettierConfig,
prettierPlugin,
{
languageOptions: {
globals: {
...globals.node,
...globals.browser,
global: true,
},
},
},
{
ignores: ['coverage/*', 'dist/*'],
},
];
59 changes: 48 additions & 11 deletions lib/main.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,75 @@
const Sink = class Sink {
write() {
/* eslint-disable no-unused-vars */
export default class Sink {
/**
* @template [T=unknown]
* @param {string} filePath Path to the file to be stored.
* @param {string} contentType The content type of the file (ex `application/javascript`).
* @returns {T | Promise<T>}
*/
write(filePath, contentType) {
throw new Error('.write method is not implemented');
}

read() {
/**
* @template [T=unknown]
* @param {string} filePath
* @returns {T | Promise<T>}
*/
read(filePath) {
throw new Error('.read method is not implemented');
}

delete() {
/**
* @template [T=unknown]
* @param {string} filePath
* @returns {T | Promise<T>}
*/
delete(filePath) {
throw new Error('.delete method is not implemented');
}

exist() {
/**
* @template [T=unknown]
* @param {string} filePath
* @returns {T | Promise<T>}
*/
exist(filePath) {
throw new Error('.exist method is not implemented');
}

get metrics() {
throw new Error('.metrics getter is not implemented');
}

/**
* Validates {@link filePath} and returns it.
* @param {string} filePath
* @throws {TypeError} if validation fails
* @returns {string}
*/
static validateFilePath(filePath) {
if (typeof filePath !== 'string') throw new TypeError('Argument must be a String');
if (filePath === '') throw new TypeError('Argument can not be an empty String');
if (typeof filePath !== 'string')
throw new TypeError('Argument must be a String');
if (filePath === '')
throw new TypeError('Argument can not be an empty String');
return filePath;
}

/**
* Validates {@link contentType} and returns it.
* @param {string} contentType
* @throws {TypeError} if validation fails
* @returns {string}
*/
static validateContentType(contentType) {
if (typeof contentType !== 'string') throw new TypeError('Argument must be a String');
if (contentType === '') throw new TypeError('Argument can not be an empty String');
if (typeof contentType !== 'string')
throw new TypeError('Argument must be a String');
if (contentType === '')
throw new TypeError('Argument can not be an empty String');
return contentType;
}

get [Symbol.toStringTag]() {
return 'Sink';
}
};
export default Sink;
}
20 changes: 13 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
"version": "1.2.1",
"description": "A Sink interface",
"main": "lib/main.js",
"types": "types/main.d.ts",
"type": "module",
"files": [
"CHANGELOG.md",
"package.json",
"README.md",
"lib"
"lib",
"types"
],
"scripts": {
"test": "tap --disable-coverage --allow-empty-coverage test/**/*.js",
"lint": "eslint .",
"lint:fix": "eslint --fix .",
"lint": "eslint ."
"test": "run-s test:*",
"test:unit": "tap --disable-coverage --allow-empty-coverage tests/**/*.js",
"test:types": "tsc --project tsconfig.test.json",
"types": "tsc --declaration --emitDeclarationOnly"
},
"repository": {
"type": "git",
Expand All @@ -29,13 +34,14 @@
"@babel/eslint-parser": "7.24.7",
"@semantic-release/changelog": "6.0.3",
"@semantic-release/git": "10.0.1",
"eslint": "8.57.0",
"eslint-config-airbnb-base": "15.0.0",
"eslint": "9.1.1",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-prettier": "5.1.3",
"globals": "15.0.0",
"npm-run-all": "4.1.5",
"prettier": "3.3.2",
"semantic-release": "24.0.0",
"tap": "18.8.0"
"tap": "18.8.0",
"typescript": "5.5.4"
}
}
32 changes: 19 additions & 13 deletions release.config.cjs
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
module.exports = {
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
["@semantic-release/npm", {
"tarballDir": "release"
}],
["@semantic-release/github", {
"assets": "release/*.tgz"
}],
"@semantic-release/git"
plugins: [
'@semantic-release/commit-analyzer',
'@semantic-release/release-notes-generator',
'@semantic-release/changelog',
[
'@semantic-release/npm',
{
tarballDir: 'release',
},
],
[
'@semantic-release/github',
{
assets: 'release/*.tgz',
},
],
'@semantic-release/git',
],
"preset": "angular"
}
preset: 'angular',
};
92 changes: 0 additions & 92 deletions test/main.js

This file was deleted.

Loading