@jsenv/github-release-package 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Github Release Package [![npm package](https://img.shields.io/npm/v/@jsenv/github-release-package.svg?logo=npm&label=package)](https://www.npmjs.com/package/@jsenv/github-release-package) [![github ci](https://github.com/jsenv/github-release-package/workflows/main/badge.svg)](https://github.com/jsenv/github-release-package/actions?workflow=main) [![codecov coverage](https://codecov.io/gh/jsenv/jsenv-github-release-package/branch/master/graph/badge.svg)](https://codecov.io/gh/jsenv/github-release-package)
2
+
3
+ Create github release for package version updates.
File without changes
package/package.json CHANGED
@@ -1,14 +1,19 @@
1
1
  {
2
2
  "name": "@jsenv/github-release-package",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Create github release when package version changes.",
5
5
  "license": "MIT",
6
+ "author": {
7
+ "name": "dmail",
8
+ "email": "dmaillard06@gmail.com",
9
+ "url": "https://twitter.com/damienmaillard"
10
+ },
6
11
  "repository": {
7
12
  "type": "git",
8
- "url": "https://github.com/jsenv/jsenv-github-release-package"
13
+ "url": "https://github.com/jsenv/github-release-package"
9
14
  },
10
15
  "engines": {
11
- "node": ">=12.8.0"
16
+ "node": ">=16.13.0"
12
17
  },
13
18
  "publishConfig": {
14
19
  "access": "public",
@@ -17,55 +22,36 @@
17
22
  "type": "module",
18
23
  "exports": {
19
24
  ".": {
20
- "import": "./index.js",
21
- "require": "./dist/commonjs/main.cjs"
25
+ "import": "./main.js"
22
26
  }
23
27
  },
24
- "main": "dist/commonjs/main.cjs",
28
+ "main": "./main.js",
25
29
  "files": [
26
- "/dist/",
27
30
  "/src/",
28
- "/index.js"
31
+ "/main.js"
29
32
  ],
30
33
  "scripts": {
31
- "test": "node ./script/test/test.js",
32
- "test-with-coverage": "node ./script/test/test.js --coverage",
33
- "eslint-check": "eslint .",
34
- "prettier-format": "node ./script/prettier-format/prettier-format.js",
35
- "prettier-format-stage": "npm run prettier-format -- --staged",
36
- "prettier-check": "npm run prettier-format -- --dry-run",
37
- "upload-coverage": "node ./script/upload-coverage/upload-coverage.js",
38
- "generate-commonjs-bundle": "node ./script/generate-commonjs-bundle/generate-commonjs-bundle.js",
39
- "generate-import-map": "node ./script/generate-import-map/generate-import-map.js",
40
- "install-git-hooks": "node ./script/install-git-hooks/install-git-hooks.js",
41
- "dist": "npm run clean && npm run generate-commonjs-bundle",
42
- "clean": "rimraf dist && rimraf coverage",
43
- "reinstall": "npm run clean && rimraf node_modules && npm install",
44
- "prepublishOnly": "node ./script/transform-package/remove-postinstall.js && npm run dist",
45
- "postpublish": "node ./script/transform-package/restore-postinstall.js",
46
- "git-hook-pre-commit": "npm run prettier-format-stage"
34
+ "eslint": "node ./node_modules/eslint/bin/eslint.js . --ext=.js,.mjs",
35
+ "importmap": "node ./script/importmap/importmap.mjs",
36
+ "test": "node ./script/test/test.mjs",
37
+ "test-with-coverage": "npm run test -- --coverage",
38
+ "prettier": "prettier --write ."
47
39
  },
48
40
  "dependencies": {
49
- "@jsenv/cancellation": "1.4.1",
50
- "@jsenv/logger": "3.3.1",
51
- "@jsenv/server": "1.5.0",
52
- "@jsenv/util": "3.4.1",
53
- "node-fetch": "2.6.0"
41
+ "@jsenv/filesystem": "2.7.1",
42
+ "@jsenv/logger": "4.0.1",
43
+ "@jsenv/server": "12.4.0"
54
44
  },
55
45
  "devDependencies": {
56
- "@jsenv/assert": "1.2.2",
57
- "@jsenv/codecov-upload": "3.2.0",
58
- "@jsenv/core": "11.5.0",
59
- "@jsenv/eslint-config": "12.3.1",
60
- "@jsenv/git-hooks": "1.2.0",
61
- "@jsenv/github-release-package": "1.0.0",
62
- "@jsenv/node-module-import-map": "11.0.0",
63
- "@jsenv/package-publish": "1.4.1",
64
- "@jsenv/prettier-config": "1.2.0",
65
- "@jsenv/prettier-check-project": "5.4.0",
66
- "babel-eslint": "11.0.0-beta.0",
67
- "eslint": "6.8.0",
68
- "prettier": "1.19.1",
69
- "rimraf": "3.0.1"
46
+ "@jsenv/assert": "2.4.1",
47
+ "@jsenv/core": "25.3.0",
48
+ "@jsenv/eslint-config": "16.0.9",
49
+ "@jsenv/importmap-eslint-resolver": "5.2.5",
50
+ "@jsenv/importmap-node-module": "5.1.0",
51
+ "@jsenv/package-publish": "1.6.2",
52
+ "@jsenv/performance-impact": "2.2.1",
53
+ "eslint": "8.7.0",
54
+ "eslint-plugin-import": "2.25.4",
55
+ "prettier": "2.5.1"
70
56
  }
71
57
  }
@@ -1,108 +1,108 @@
1
+ import { assertAndNormalizeDirectoryUrl } from "@jsenv/filesystem"
1
2
  import { createLogger } from "@jsenv/logger"
2
- import { assertAndNormalizeDirectoryUrl } from "@jsenv/util"
3
- import { createCancellationTokenForProcessSIGINT } from "@jsenv/cancellation"
4
- import { wrapAsyncFunction } from "./internal/wrapAsyncFunction.js"
3
+
5
4
  import { readProjectPackage } from "./internal/readProjectPackage.js"
6
5
  import { getGithubRelease } from "./internal/getGithubRelease.js"
7
6
  import { createGithubRelease } from "./internal/createGithubRelease.js"
8
7
 
9
8
  export const ensureGithubReleaseForPackage = async ({
10
- cancellationToken = createCancellationTokenForProcessSIGINT(),
11
9
  logLevel,
12
10
  projectDirectoryUrl,
13
- updateProcessExitCode,
14
11
  }) => {
15
- return wrapAsyncFunction(
16
- async () => {
17
- const logger = createLogger({ logLevel })
18
- logger.debug(
19
- `autoReleaseOnGithub(${JSON.stringify({ projectDirectoryUrl, logLevel }, null, " ")})`,
20
- )
12
+ const logger = createLogger({ logLevel })
13
+ logger.debug(
14
+ `autoReleaseOnGithub(${JSON.stringify(
15
+ { projectDirectoryUrl, logLevel },
16
+ null,
17
+ " ",
18
+ )})`,
19
+ )
21
20
 
22
- projectDirectoryUrl = assertAndNormalizeDirectoryUrl(projectDirectoryUrl)
21
+ projectDirectoryUrl = assertAndNormalizeDirectoryUrl(projectDirectoryUrl)
23
22
 
24
- const {
25
- githubToken,
26
- githubRepositoryOwner,
27
- githubRepositoryName,
28
- githubSha,
29
- } = getOptionsFromGithubAction()
23
+ const {
24
+ githubToken,
25
+ githubRepositoryOwner,
26
+ githubRepositoryName,
27
+ githubSha,
28
+ } = getOptionsFromGithubAction()
30
29
 
31
- logger.debug(`reading project package.json`)
32
- const { packageVersion } = await getOptionsFromProjectPackage({ projectDirectoryUrl })
33
- cancellationToken.throwIfRequested()
34
- logger.debug(`${packageVersion} found in package.json`)
30
+ logger.debug(`reading project package.json`)
31
+ const { packageVersion } = await getOptionsFromProjectPackage({
32
+ projectDirectoryUrl,
33
+ })
34
+ logger.debug(`${packageVersion} found in package.json`)
35
35
 
36
- logger.debug(`search release for ${packageVersion} on github`)
37
- const githubReleaseName = `v${packageVersion}`
38
- const existingRelease = await getGithubRelease({
39
- githubToken,
36
+ logger.debug(`search release for ${packageVersion} on github`)
37
+ const githubReleaseName = `v${packageVersion}`
38
+ const existingRelease = await getGithubRelease({
39
+ githubToken,
40
+ githubRepositoryOwner,
41
+ githubRepositoryName,
42
+ githubReleaseName,
43
+ })
44
+ if (existingRelease) {
45
+ logger.info(
46
+ `${packageVersion} already released at ${generateReleaseUrl({
40
47
  githubRepositoryOwner,
41
48
  githubRepositoryName,
42
49
  githubReleaseName,
43
- })
44
- cancellationToken.throwIfRequested()
45
- if (existingRelease) {
46
- logger.info(
47
- `${packageVersion} already released at ${generateReleaseUrl({
48
- githubRepositoryOwner,
49
- githubRepositoryName,
50
- githubReleaseName,
51
- })}`,
52
- )
53
- return
54
- }
50
+ })}`,
51
+ )
52
+ return
53
+ }
55
54
 
56
- logger.info(`creating release for ${packageVersion}`)
57
- await createGithubRelease({
58
- githubToken,
59
- githubRepositoryOwner,
60
- githubRepositoryName,
61
- githubSha,
62
- githubReleaseName,
63
- })
64
- logger.info(
65
- `release created at ${generateReleaseUrl({
66
- githubRepositoryOwner,
67
- githubRepositoryName,
68
- githubReleaseName,
69
- })}`,
70
- )
71
- },
72
- { updateProcessExitCode },
55
+ logger.info(`creating release for ${packageVersion}`)
56
+ await createGithubRelease({
57
+ githubToken,
58
+ githubRepositoryOwner,
59
+ githubRepositoryName,
60
+ githubSha,
61
+ githubReleaseName,
62
+ })
63
+ logger.info(
64
+ `release created at ${generateReleaseUrl({
65
+ githubRepositoryOwner,
66
+ githubRepositoryName,
67
+ githubReleaseName,
68
+ })}`,
73
69
  )
74
70
  }
75
71
 
76
- const generateReleaseUrl = ({ githubRepositoryOwner, githubRepositoryName, githubReleaseName }) => {
72
+ const generateReleaseUrl = ({
73
+ githubRepositoryOwner,
74
+ githubRepositoryName,
75
+ githubReleaseName,
76
+ }) => {
77
77
  return `https://github.com/${githubRepositoryOwner}/${githubRepositoryName}/releases/tag/${githubReleaseName}`
78
78
  }
79
79
 
80
80
  const getOptionsFromGithubAction = () => {
81
81
  const eventName = process.env.GITHUB_EVENT_NAME
82
82
  if (!eventName) {
83
- throw new Error(`missing process.env.GITHUB_EVENT_NAME, we are not in a github action`)
83
+ throw new Error(
84
+ `missing process.env.GITHUB_EVENT_NAME, we are not in a github action`,
85
+ )
84
86
  }
85
87
  if (eventName !== "push") {
86
- throw new Error(`getOptionsFromGithubAction must be called only in a push action`)
88
+ throw new Error(
89
+ `getOptionsFromGithubAction must be called only in a push action`,
90
+ )
87
91
  }
88
-
89
92
  const githubRepository = process.env.GITHUB_REPOSITORY
90
93
  if (!githubRepository) {
91
94
  throw new Error(`missing process.env.GITHUB_REPOSITORY`)
92
95
  }
93
-
94
- const [githubRepositoryOwner, githubRepositoryName] = githubRepository.split("/")
95
-
96
+ const [githubRepositoryOwner, githubRepositoryName] =
97
+ githubRepository.split("/")
96
98
  const githubToken = process.env.GITHUB_TOKEN
97
99
  if (!githubToken) {
98
100
  throw new Error(`missing process.env.GITHUB_TOKEN`)
99
101
  }
100
-
101
102
  const githubSha = process.env.GITHUB_SHA
102
103
  if (!githubSha) {
103
104
  throw new Error(`missing process.env.GITHUB_SHA`)
104
105
  }
105
-
106
106
  return {
107
107
  githubRepositoryOwner,
108
108
  githubRepositoryName,
@@ -22,9 +22,7 @@ export const createGithubRelease = async ({
22
22
  method: "POST",
23
23
  body,
24
24
  })
25
-
26
25
  const responseStatus = response.status
27
-
28
26
  if (responseStatus !== 201) {
29
27
  throw new Error(
30
28
  writeUnexpectedResponseStatus({
@@ -34,7 +32,6 @@ export const createGithubRelease = async ({
34
32
  }),
35
33
  )
36
34
  }
37
-
38
35
  const responseJson = await response.json()
39
36
  return responseJson
40
37
  }
@@ -15,13 +15,10 @@ export const getGithubRelease = async ({
15
15
  },
16
16
  method: "GET",
17
17
  })
18
-
19
18
  const responseStatus = response.status
20
-
21
19
  if (responseStatus === 404) {
22
20
  return null
23
21
  }
24
-
25
22
  if (responseStatus !== 200) {
26
23
  throw new Error(
27
24
  writeUnexpectedResponseStatus({
@@ -31,7 +28,6 @@ export const getGithubRelease = async ({
31
28
  }),
32
29
  )
33
30
  }
34
-
35
31
  const responseJson = await response.json()
36
32
  return responseJson
37
33
  }
@@ -1,8 +1,7 @@
1
- import { resolveUrl, urlToFileSystemPath, readFile } from "@jsenv/util"
1
+ import { resolveUrl, urlToFileSystemPath, readFile } from "@jsenv/filesystem"
2
2
 
3
3
  export const readProjectPackage = async ({ projectDirectoryUrl }) => {
4
4
  const packageFileUrl = resolveUrl("./package.json", projectDirectoryUrl)
5
-
6
5
  let packageInProject
7
6
  try {
8
7
  const packageString = await readFile(packageFileUrl)
@@ -28,6 +27,5 @@ ${urlToFileSystemPath(packageFileUrl)}`,
28
27
  }
29
28
  throw e
30
29
  }
31
-
32
30
  return packageInProject
33
31
  }