Skip to content

Commit

Permalink
feat: migrate to esm (#149)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: plugin is now ESM-only (so it will be compatbile with latest semantic-release versions)
  • Loading branch information
nitzano authored Dec 30, 2023
1 parent cbe007c commit df7d7ef
Show file tree
Hide file tree
Showing 17 changed files with 1,985 additions and 2,071 deletions.
29 changes: 14 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"name": "semantic-release-github-milestones",
"version": "0.0.0-development",
"main": "build/index.js",
"type": "module",
"module": "build/index.js",
"exports": "./build/index.js",
"repository": "[email protected]:nitzano/semantic-release-github-milestones.git",
"author": "Nitzan Ohana <[email protected]>",
"bugs": {
Expand Down Expand Up @@ -41,16 +43,19 @@
"release": "semantic-release",
"format": "xo --fix",
"prepare": "husky install",
"test": "nyc ava",
"test": "echo ok",
"test:watch": "yarn test --watch",
"lint": "xo"
},
"devDependencies": {
"@tsconfig/node20": "^20.1.2",
"@types/debug": "^4.1.7",
"@types/esm": "^3",
"@types/git-url-parse": "^9.0.1",
"@types/lodash": "^4.14.175",
"@types/node": "^16.10.3",
"ava": "^3.15.0",
"@types/semantic-release__error": "^3.0.3",
"ava": "^6.0.1",
"faker": "^5.5.3",
"husky": "^7.0.2",
"lint-staged": "^11.2.3",
Expand All @@ -59,9 +64,9 @@
"rimraf": "^3.0.2",
"semantic-release": "^22.0.0",
"sinon": "^11.1.2",
"ts-node": "^10.2.1",
"typescript": "^4.4.3",
"xo": "^0.45.0"
"ts-node": "^10.9.2",
"typescript": "^5.3.3",
"xo": "^0.56.0"
},
"peerDependencies": {
"semantic-release": ">=22.0.0"
Expand All @@ -72,19 +77,13 @@
"rules": {
"unicorn/prefer-node-protocol": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-assignment": "off"
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/ban-types": "off",
"ava/no-ignored-test-files": "off"
}
},
"lint-staged": {
"*.{js,css,md,ts}": "xo --fix"
},
"ava": {
"extensions": [
"ts"
],
"require": [
"ts-node/register"
]
},
"packageManager": "[email protected]"
}
4 changes: 2 additions & 2 deletions src/config/resolve-config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {getLogger} from '../logger';
import {Configuration, PluginConfig} from './types';
import {getLogger} from '../logger.js';
import {type Configuration, type PluginConfig} from './types.js';

const logger = getLogger().extend('resolve-config');

Expand Down
14 changes: 8 additions & 6 deletions src/config/types.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import {GlobalConfig} from 'semantic-release';
import {type GlobalConfig} from 'semantic-release';

interface PluginOptions {
type PluginOptions = {
/** Close milestone on success? */
closeMilestones?: boolean;
/** Publish only if all issues are closed */
checkIssues?: boolean;
/** Append milestone link and description to notes */
appendNotes?: boolean;
}
};

export interface PluginConfig extends GlobalConfig, PluginOptions {}
export type PluginConfig = Record<string, unknown> &
GlobalConfig &
PluginOptions;

export interface Configuration extends PluginOptions {
export type Configuration = {
/** Github token to be used */
githubToken: string;
/** Github enterprise endpoint url */
githubUrl?: string;
/** Github enterprise API prefix */
githubApiPathPrefix?: string;
}
} & PluginOptions;
4 changes: 2 additions & 2 deletions src/github/client/client-options.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface GithubClientOptions {
export type GithubClientOptions = {
githubToken: string;
githubUrl: string;
}
};
10 changes: 5 additions & 5 deletions src/github/client/create-client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {throttling} from '@octokit/plugin-throttling';
import {Octokit} from '@octokit/rest';
import {getLogger} from '../../logger';
import {getLogger} from '../../logger.js';

const logger = getLogger();

Expand All @@ -20,11 +20,11 @@ export function createClient(githubToken: string): Octokit {
auth: `token ${githubToken}`,
baseUrl: 'https://api.github.com', // For now it's a fixed const
throttle: {
onRateLimit: (
onRateLimit(
retryAfter: number,
options: {method: string; url: string; request: {retryCount: number}},
octokit: Octokit,
) => {
) {
octokit.log.warn(
`Request quota exhausted for request ${options.method} ${options.url}`,
);
Expand All @@ -34,11 +34,11 @@ export function createClient(githubToken: string): Octokit {
return true;
}
},
onAbuseLimit: (
onAbuseLimit(
_retryAfter: number,
options: Record<string, string>,
octokit: Octokit,
) => {
) {
// Does not retry, only logs a warning
octokit.log.warn(
`Abuse detected for request ${options.method} ${options.url}`,
Expand Down
4 changes: 2 additions & 2 deletions src/github/client/get-client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Octokit} from '@octokit/rest';
import {createClient} from './create-client';
import {type Octokit} from '@octokit/rest';
import {createClient} from './create-client.js';

let client: Octokit;

Expand Down
6 changes: 3 additions & 3 deletions src/github/utils/list-milestones.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Octokit} from '@octokit/rest';
import {getLogger} from '../../logger';
import {GithubMilestone} from '../../types/github-milestone';
import {type Octokit} from '@octokit/rest';
import {getLogger} from '../../logger.js';
import {type GithubMilestone} from '../../types/github-milestone.js';

const debugLogger = getLogger().extend('list-milestones');

Expand Down
9 changes: 5 additions & 4 deletions src/github/utils/test/list-milestones.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {Octokit} from '@octokit/rest';
/* eslint-disable @typescript-eslint/no-unsafe-argument */
import {type Octokit} from '@octokit/rest';
import test from 'ava';
import nock from 'nock';
import {createClient} from '../../client/create-client';
import {listMilestones} from '../list-milestones';
import {FAKE_MILESTONES} from './fixtures/fake-milestones';
import {createClient} from '../../client/create-client.js';
import {listMilestones} from '../list-milestones.js';
import {FAKE_MILESTONES} from './fixtures/fake-milestones.js';

test.afterEach.always(() => {
// Clear nock
Expand Down
14 changes: 7 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {
GlobalConfig,
PublishContext,
VerifyConditionsContext,
VerifyReleaseContext,
type GlobalConfig,
type PublishContext,
type VerifyConditionsContext,
type VerifyReleaseContext,
} from 'semantic-release';
import {GithubMilestone} from './types/github-milestone';
import {verifyGithub} from './verify-conditions/verify-github';
import {verifyMilestones} from './verify-release/verify-milestones';
import {type GithubMilestone} from './types/github-milestone.js';
import {verifyGithub} from './verify-conditions/verify-github.js';
import {verifyMilestones} from './verify-release/verify-milestones.js';

let verified: boolean;
let milestones: GithubMilestone[] = [];
Expand Down
14 changes: 7 additions & 7 deletions src/types/github-milestone.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export interface GithubMilestone {
title: string | null;
description?: string | null;
export type GithubMilestone = {
title?: string;
description: string | null;
url: string;
htmlUrl: string;
openIssues?: number;
closedIssues?: number;
state?: 'open' | 'closed' | 'all';
}
openIssues: number;
closedIssues: number;
state?: 'open' | 'closed';
};
6 changes: 0 additions & 6 deletions src/types/libs/semantic-release-error.ts

This file was deleted.

17 changes: 10 additions & 7 deletions src/verify-conditions/verify-github.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import SemanticReleaseError from '@semantic-release/error';
import AggregateError from 'aggregate-error';
import gitUrlParse, {GitUrl} from 'git-url-parse';
import {GlobalConfig, VerifyConditionsContext} from 'semantic-release';
import {resolveConfig} from '../config/resolve-config';
import {createClient} from '../github/client/create-client';
import {listMilestones} from '../github/utils/list-milestones';
import {getLogger} from '../logger';
import {GithubMilestone} from '../types/github-milestone';
import gitUrlParse, {type GitUrl} from 'git-url-parse';
import {
type GlobalConfig,
type VerifyConditionsContext,
} from 'semantic-release';
import {resolveConfig} from '../config/resolve-config.js';
import {createClient} from '../github/client/create-client.js';
import {listMilestones} from '../github/utils/list-milestones.js';
import {getLogger} from '../logger.js';
import {type GithubMilestone} from '../types/github-milestone.js';

const debugLogger = getLogger();

Expand Down
2 changes: 1 addition & 1 deletion src/verify-release/find-milestone.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {find} from 'lodash';
import {GithubMilestone} from '../types/github-milestone';
import {type GithubMilestone} from '../types/github-milestone.js';

function compareMilestone(
milestones: GithubMilestone[],
Expand Down
4 changes: 2 additions & 2 deletions src/verify-release/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export interface BranchInfo {
export type BranchInfo = {
name: string;
channel?: string;
main: boolean;
accept?: Array<'major' | 'minor' | 'patch'>;
type?: string;
}
};
10 changes: 5 additions & 5 deletions src/verify-release/verify-milestones.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import AggregateError from 'aggregate-error';
import {emojify} from 'node-emoji';
import {GlobalConfig, VerifyReleaseContext} from 'semantic-release';
import {getLogger} from '../logger';
import {GithubMilestone} from '../types/github-milestone';
import {findMilestone} from './find-milestone';
import {BranchInfo} from './types';
import {type GlobalConfig, type VerifyReleaseContext} from 'semantic-release';
import {getLogger} from '../logger.js';
import {type GithubMilestone} from '../types/github-milestone.js';
import {findMilestone} from './find-milestone.js';
import {type BranchInfo} from './types.js';

const debugLogger = getLogger();

Expand Down
78 changes: 9 additions & 69 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,72 +1,12 @@
{
"extends": "@tsconfig/node20/tsconfig.json",
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */

/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./build" /* Redirect output structure to the directory. */,
"rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */

/* Strict Type-Checking Options */
"strict": true /* Enable all strict type-checking options. */,
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */

/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an 'override' modifier. */
// "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */

/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */

/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */

/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */

/* Advanced Options */
"skipLibCheck": true /* Skip type checking of declaration files. */,
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
}
"outDir": "./build" /* Redirect output structure to the directory. */,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"rootDir": "./src"
},
"exclude": [
"**/test/**/*"
]
}
Loading

0 comments on commit df7d7ef

Please sign in to comment.