Skip to content

Commit 66e76ca

Browse files
authored
Merge pull request #244 from screendriver/esm
Set package type to ECMAScript module
2 parents 93d155e + b4c3842 commit 66e76ca

16 files changed

+4591
-11821
lines changed

ava.config.integration.mjs renamed to ava.config.integration.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import defaultConfig from './ava.config.mjs';
1+
import defaultConfig from './ava.config.js';
22

33
export default {
44
...defaultConfig,
File renamed without changes.

package-lock.json

Lines changed: 4532 additions & 11769 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
{
22
"name": "gitlab-pipeline-deleter",
3+
"type": "module",
34
"version": "2.3.18",
45
"description": "A CLI tool that deletes old GitLab pipelines",
5-
"main": "target/src/index.js",
6+
"exports": {
7+
"types": "./target/src/index.d.ts",
8+
"default": "./target/src/index.js"
9+
},
610
"engines": {
711
"node": ">=16"
812
},
@@ -36,31 +40,31 @@
3640
"compile": "tsc --build",
3741
"lint": "eslint src test --ext '.ts,.tsx'",
3842
"copy:paste:detection": "jscpd src test",
39-
"test:unit": "TS_NODE_PROJECT=tsconfig.base.json ava",
43+
"test:unit": "ava",
4044
"test:unit:coverage": "c8 npm run test:unit",
41-
"test:integration": "TS_NODE_PROJECT=tsconfig.base.json ava --config ava.config.integration.mjs",
45+
"test:integration": "ava --config ava.config.integration.js",
4246
"release:dry": "release-it --dry-run --no-npm",
4347
"release": "release-it"
4448
},
4549
"dependencies": {
46-
"@sindresorhus/is": "4.6.0",
50+
"@sindresorhus/is": "5.5.0",
4751
"commander": "9.5.0",
4852
"cosmiconfig": "7.1.0",
4953
"date-fns": "2.30.0",
50-
"got": "11.8.6",
51-
"ink": "3.2.0",
52-
"ink-spinner": "4.0.3",
53-
"p-queue": "6.6.2",
54-
"react": "17.0.2",
55-
"true-myth": "4.1.1",
54+
"got": "13.0.0",
55+
"ink": "4.2.0",
56+
"ink-spinner": "5.0.0",
57+
"p-queue": "7.3.4",
58+
"react": "18.2.0",
59+
"true-myth": "7.0.0",
5660
"tslib": "2.6.0",
57-
"urlcat": "2.0.4",
5861
"zod": "3.21.4"
5962
},
6063
"devDependencies": {
6164
"@ava/typescript": "4.1.0",
6265
"@types/common-tags": "1.8.1",
63-
"@types/react": "17.0.62",
66+
"@types/node": "20.4.2",
67+
"@types/react": "18.2.15",
6468
"@types/sinon": "10.0.15",
6569
"@typescript-eslint/eslint-plugin": "5.62.0",
6670
"@typescript-eslint/parser": "5.62.0",
@@ -77,12 +81,11 @@
7781
"eslint-plugin-testing-library": "5.11.0",
7882
"fastify": "4.19.2",
7983
"fishery": "2.2.2",
80-
"get-port": "7.0.0",
81-
"ink-testing-library": "2.1.0",
84+
"ink-testing-library": "3.0.0",
8285
"jscpd": "3.5.9",
8386
"prettier": "2.8.8",
8487
"release-it": "16.1.2",
8588
"sinon": "14.0.2",
86-
"typescript": "4.9.5"
89+
"typescript": "5.1.6"
8790
}
8891
}

src/App.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import React, { Fragment, FunctionComponent, useEffect, useState } from 'react';
22
import { Text, Static } from 'ink';
33
import Spinner from 'ink-spinner';
44
import PQueue from 'p-queue';
5-
import type { ListPipelinesFunction, DeletePipelineFunction, FilterPipelinesByDateFunction } from './gitlab';
6-
import { Error, ErrorProps } from './Error';
7-
import { Pipeline } from './network';
5+
import type { ListPipelinesFunction, DeletePipelineFunction, FilterPipelinesByDateFunction } from './gitlab.js';
6+
import { Error, ErrorProps } from './Error.js';
7+
import { Pipeline } from './network.js';
88

99
export interface AppProps {
1010
readonly gitlabUrl: string;

src/bin.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import React from 'react';
33
import { createCommand } from 'commander';
44
import { render } from 'ink';
55
import { cosmiconfig } from 'cosmiconfig';
6-
import path from 'path';
6+
import path from 'node:path';
77
import PQueue from 'p-queue';
8-
import { App } from './App';
9-
import { Error } from './Error';
10-
import { getRequest, deleteRequest } from './network';
11-
import { listPipelines, filterPipelinesByDate, deletePipeline } from './gitlab';
12-
import { PartialConfigInput, loadConfig, mergeCliArgumentsWithConfig } from './config';
8+
import { App } from './App.js';
9+
import { Error } from './Error.js';
10+
import { getRequest, deleteRequest } from './network.js';
11+
import { listPipelines, filterPipelinesByDate, deletePipeline } from './gitlab.js';
12+
import { PartialConfigInput, loadConfig, mergeCliArgumentsWithConfig } from './config.js';
1313

1414
function exit() {
1515
process.exitCode = 1;
@@ -46,7 +46,7 @@ program
4646
return mergeCliArgumentsWithConfig(cliArguments, config);
4747
});
4848

49-
if (glpdArguments.isErr()) {
49+
if (glpdArguments.isErr) {
5050
render(<Error exit={exit}>Missing or invalid arguments</Error>);
5151
return;
5252
}

src/gitlab.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import urlcat from 'urlcat';
1+
import { URL } from 'node:url';
22
import { parseISO, differenceInDays } from 'date-fns';
3-
import { GetRequest, DeleteRequest, Pipeline } from './network';
3+
import { GetRequest, DeleteRequest, Pipeline } from './network.js';
44

55
interface ListPipelinesArguments {
66
readonly getRequest: GetRequest;
@@ -12,9 +12,12 @@ export type ListPipelinesFunction = (projectId: number) => Promise<readonly Pipe
1212

1313
export function listPipelines({ getRequest, gitlabUrl, accessToken }: ListPipelinesArguments): ListPipelinesFunction {
1414
return (projectId) => {
15-
const url = urlcat(gitlabUrl, '/api/v4/projects/:id/pipelines', { id: projectId, per_page: 100 });
15+
const escapedProjectId = encodeURIComponent(projectId);
16+
const url = new URL(`/api/v4/projects/${escapedProjectId}/pipelines`, gitlabUrl);
1617

17-
return getRequest(url, accessToken);
18+
url.searchParams.set('per_page', '100');
19+
20+
return getRequest(url.toString(), accessToken);
1821
};
1922
}
2023

@@ -32,12 +35,11 @@ export function deletePipeline({
3235
accessToken,
3336
}: DeletePipelineArguments): DeletePipelineFunction {
3437
return async (projectId, pipeline) => {
35-
const url = urlcat(gitlabUrl, '/api/v4/projects/:id/pipelines/:pipeline_id', {
36-
id: projectId,
37-
pipeline_id: pipeline.id,
38-
});
38+
const escapedProjectId = encodeURIComponent(projectId);
39+
const escapedPipelineId = encodeURIComponent(pipeline.id);
40+
const url = new URL(`/api/v4/projects/${escapedProjectId}/pipelines/${escapedPipelineId}`, gitlabUrl);
3941

40-
await deleteRequest(url, accessToken);
42+
await deleteRequest(url.toString(), accessToken);
4143
};
4244
}
4345

src/network.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ export const deleteRequest: DeleteRequest = (url, accessToken) => {
2424
.delete(url, {
2525
headers: createHeaders(accessToken),
2626
throwHttpErrors: true,
27-
retry: 0,
27+
retry: {
28+
limit: 0,
29+
},
2830
})
2931
.text();
3032
};

test/integration/deletePipelines.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import { parseISO } from 'date-fns';
55
import delay from 'delay';
66
import PQueue from 'p-queue';
77
import sinon from 'sinon';
8-
import { withGitLabServer } from './gitlabServer';
9-
import { App } from '../../src/App';
10-
import { deletePipeline, filterPipelinesByDate, listPipelines } from '../../src/gitlab';
11-
import { getRequest, deleteRequest } from '../../src/network';
8+
import { withGitLabServer } from './gitlabServer.js';
9+
import { App } from '../../src/App.js';
10+
import { deletePipeline, filterPipelinesByDate, listPipelines } from '../../src/gitlab.js';
11+
import { getRequest, deleteRequest } from '../../src/network.js';
1212

1313
test.afterEach(cleanup);
1414

test/integration/gitlabServer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { RouteOptions } from 'fastify';
33
import { Factory } from 'fishery';
44
import { subDays, formatISO, parseISO } from 'date-fns';
55
import { IncomingHttpHeaders } from 'http';
6-
import { Pipeline } from '../../src/network';
6+
import { Pipeline } from '../../src/network.js';
77
import type { ExecutionContext, ImplementationFn } from 'ava';
88

99
interface PipelineTransientParams {

0 commit comments

Comments
 (0)