@jsenv/package-publish 1.7.2 → 1.7.5

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/package-publish",
3
- "version": "1.7.2",
3
+ "version": "1.7.5",
4
4
  "description": "Publish package to one or many registry.",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -34,26 +34,16 @@
34
34
  ],
35
35
  "scripts": {
36
36
  "eslint": "npx eslint . --ext=.js,.mjs",
37
- "importmap": "node ./script/importmap/importmap.mjs",
38
37
  "test": "node --experimental-json-modules ./script/test/test.mjs",
39
38
  "test-with-coverage": "npm run test -- --coverage",
40
39
  "prettier": "prettier --write ."
41
40
  },
42
41
  "dependencies": {
43
- "@jsenv/filesystem": "2.7.1",
42
+ "@jsenv/filesystem": "4.0.0",
43
+ "@jsenv/urls": "1.1.0",
44
44
  "@jsenv/logger": "4.0.1",
45
45
  "node-fetch": "2.6.7",
46
- "@jsenv/log": "1.5.0",
46
+ "@jsenv/log": "1.6.3",
47
47
  "semver": "7.3.5"
48
- },
49
- "devDependencies": {
50
- "@jsenv/assert": "2.4.1",
51
- "@jsenv/core": "25.3.0",
52
- "@jsenv/eslint-config": "16.0.9",
53
- "@jsenv/importmap-eslint-resolver": "5.2.5",
54
- "@jsenv/importmap-node-module": "5.1.3",
55
- "eslint": "8.7.0",
56
- "eslint-plugin-import": "2.25.4",
57
- "prettier": "2.5.1"
58
48
  }
59
49
  }
package/readme.md CHANGED
@@ -13,8 +13,6 @@ Screenshot taken inside a github workflow when the package.json version is alrea
13
13
 
14
14
  Screenshot taken inside a github workflow when the package.json version is not published: ![publishing github workflow screenshot](./docs/publishing-github-workflow-screenshot.png)
15
15
 
16
- This package is using itself to be published on NPM. It is done during ["publish package" step](https://github.com/jsenv/package-publish/blob/0170a5c859c4732203ff2f3e70b85e705396ccc7/.github/workflows/main.yml#L70-L74) in GitHub worflow.
17
-
18
16
  # Installation
19
17
 
20
18
  ```console
@@ -31,7 +29,7 @@ _publishPackage_ is an async function publishing a package on one or many regist
31
29
  import { publishPackage } from "@jsenv/package-publish"
32
30
 
33
31
  const publishReport = await publishPackage({
34
- projectDirectoryUrl: new URL('./', import.meta.url)
32
+ rootDirectoryUrl: new URL('./', import.meta.url)
35
33
  registriesConfig: {
36
34
  "https://registry.npmjs.org": {
37
35
  token: process.env.NPM_TOKEN,
@@ -43,9 +41,9 @@ const publishReport = await publishPackage({
43
41
  })
44
42
  ```
45
43
 
46
- ## projectDirectoryUrl
44
+ ## rootDirectoryUrl
47
45
 
48
- _projectDirectoryUrl_ parameter is a string leading to a directory containing the package.json.
46
+ _rootDirectoryUrl_ parameter is a string leading to a directory containing the package.json.
49
47
 
50
48
  This parameter is **required**.
51
49
 
@@ -1,11 +1,6 @@
1
1
  import { exec } from "node:child_process"
2
- import {
3
- resolveUrl,
4
- urlToFileSystemPath,
5
- readFile,
6
- writeFile,
7
- removeFileSystemNode,
8
- } from "@jsenv/filesystem"
2
+ import { readFile, writeFile, removeEntry } from "@jsenv/filesystem"
3
+ import { resolveUrl, urlToFileSystemPath } from "@jsenv/urls"
9
4
  import { UNICODE } from "@jsenv/log"
10
5
 
11
6
  import { setNpmConfig } from "./setNpmConfig.js"
@@ -14,7 +9,7 @@ export const publish = async ({
14
9
  logger,
15
10
  packageSlug,
16
11
  logNpmPublishOutput,
17
- projectDirectoryUrl,
12
+ rootDirectoryUrl,
18
13
  registryUrl,
19
14
  token,
20
15
  }) => {
@@ -26,37 +21,29 @@ export const publish = async ({
26
21
  process.env.NODE_AUTH_TOKEN = previousValue
27
22
  }
28
23
  process.env.NODE_AUTH_TOKEN = token
29
- const projectPackageFileUrl = resolveUrl(
30
- "./package.json",
31
- projectDirectoryUrl,
32
- )
33
- const projectPackageString = await readFile(projectPackageFileUrl)
34
- const restoreProjectPackageFile = () =>
35
- writeFile(projectPackageFileUrl, projectPackageString)
36
- const projectPackageObject = JSON.parse(projectPackageString)
37
- projectPackageObject.publishConfig =
38
- projectPackageObject.publishConfig || {}
39
- projectPackageObject.publishConfig.registry = registryUrl
24
+ const rootPackageFileUrl = resolveUrl("./package.json", rootDirectoryUrl)
25
+ const rootPackageString = await readFile(rootPackageFileUrl)
26
+ const restorePackageFile = () =>
27
+ writeFile(rootPackageFileUrl, rootPackageString)
28
+ const packageObject = JSON.parse(rootPackageString)
29
+ packageObject.publishConfig = packageObject.publishConfig || {}
30
+ packageObject.publishConfig.registry = registryUrl
40
31
  promises.push(
41
32
  writeFile(
42
- projectPackageFileUrl,
43
- JSON.stringify(projectPackageObject, null, " "),
33
+ rootPackageFileUrl,
34
+ JSON.stringify(packageObject, null, " "),
44
35
  ),
45
36
  )
46
- const projectNpmConfigFileUrl = resolveUrl(
47
- "./.npmrc",
48
- projectDirectoryUrl,
49
- )
50
- let restoreProjectNpmConfigFile
37
+ const npmConfigFileUrl = resolveUrl("./.npmrc", rootDirectoryUrl)
38
+ let restoreNpmConfigFile
51
39
  let projectNpmConfigString
52
40
  try {
53
- projectNpmConfigString = await readFile(projectNpmConfigFileUrl)
54
- restoreProjectNpmConfigFile = () =>
55
- writeFile(projectNpmConfigFileUrl, projectNpmConfigString)
41
+ projectNpmConfigString = await readFile(npmConfigFileUrl)
42
+ restoreNpmConfigFile = () =>
43
+ writeFile(npmConfigFileUrl, projectNpmConfigString)
56
44
  } catch (e) {
57
45
  if (e.code === "ENOENT") {
58
- restoreProjectNpmConfigFile = () =>
59
- removeFileSystemNode(projectNpmConfigFileUrl)
46
+ restoreNpmConfigFile = () => removeEntry(npmConfigFileUrl)
60
47
  projectNpmConfigString = ""
61
48
  } else {
62
49
  throw e
@@ -64,10 +51,10 @@ export const publish = async ({
64
51
  }
65
52
  promises.push(
66
53
  writeFile(
67
- projectNpmConfigFileUrl,
54
+ npmConfigFileUrl,
68
55
  setNpmConfig(projectNpmConfigString, {
69
56
  [computeRegistryTokenKey(registryUrl)]: token,
70
- [computeRegistryKey(projectPackageObject.name)]: registryUrl,
57
+ [computeRegistryKey(packageObject.name)]: registryUrl,
71
58
  }),
72
59
  ),
73
60
  )
@@ -75,9 +62,9 @@ export const publish = async ({
75
62
  try {
76
63
  return await new Promise((resolve, reject) => {
77
64
  const command = exec(
78
- "npm publish",
65
+ "npm publish --no-workspaces",
79
66
  {
80
- cwd: urlToFileSystemPath(projectDirectoryUrl),
67
+ cwd: urlToFileSystemPath(rootDirectoryUrl),
81
68
  stdio: "silent",
82
69
  },
83
70
  (error) => {
@@ -150,8 +137,8 @@ export const publish = async ({
150
137
  } finally {
151
138
  await Promise.all([
152
139
  restoreProcessEnv(),
153
- restoreProjectPackageFile(),
154
- restoreProjectNpmConfigFile(),
140
+ restorePackageFile(),
141
+ restoreNpmConfigFile(),
155
142
  ])
156
143
  }
157
144
  } catch (e) {
@@ -1,10 +1,11 @@
1
- import { resolveUrl, urlToFileSystemPath, readFile } from "@jsenv/filesystem"
1
+ import { resolveUrl, urlToFileSystemPath } from "@jsenv/urls"
2
+ import { readFile } from "@jsenv/filesystem"
2
3
 
3
- export const readProjectPackage = async ({ projectDirectoryUrl }) => {
4
- const packageFileUrl = resolveUrl("./package.json", projectDirectoryUrl)
4
+ export const readProjectPackage = async ({ rootDirectoryUrl }) => {
5
+ const packageFileUrl = resolveUrl("./package.json", rootDirectoryUrl)
5
6
  let packageObject
6
7
  try {
7
- const packageString = await readFile(packageFileUrl)
8
+ const packageString = await readFile(packageFileUrl, { as: "string" })
8
9
  try {
9
10
  packageObject = JSON.parse(packageString)
10
11
  } catch (e) {
@@ -15,7 +15,7 @@ import {
15
15
 
16
16
  export const publishPackage = async ({
17
17
  logLevel,
18
- projectDirectoryUrl,
18
+ rootDirectoryUrl,
19
19
  registriesConfig,
20
20
  logNpmPublishOutput = true,
21
21
  updateProcessExitCode = true,
@@ -23,17 +23,17 @@ export const publishPackage = async ({
23
23
  const logger = createLogger({ logLevel })
24
24
  logger.debug(
25
25
  `publishPackage(${JSON.stringify(
26
- { projectDirectoryUrl, logLevel, registriesConfig },
26
+ { rootDirectoryUrl, logLevel, registriesConfig },
27
27
  null,
28
28
  " ",
29
29
  )})`,
30
30
  )
31
- projectDirectoryUrl = assertAndNormalizeDirectoryUrl(projectDirectoryUrl)
31
+ rootDirectoryUrl = assertAndNormalizeDirectoryUrl(rootDirectoryUrl)
32
32
  assertRegistriesConfig(registriesConfig)
33
33
 
34
34
  logger.debug(`reading project package.json`)
35
35
  const packageInProject = await readProjectPackage({
36
- projectDirectoryUrl,
36
+ rootDirectoryUrl,
37
37
  })
38
38
 
39
39
  const { name: packageName, version: packageVersion } = packageInProject
@@ -140,7 +140,7 @@ ${actionReason.stack}`)
140
140
  logger,
141
141
  packageSlug: `${packageName}@${packageVersion}`,
142
142
  logNpmPublishOutput,
143
- projectDirectoryUrl,
143
+ rootDirectoryUrl,
144
144
  registryUrl,
145
145
  ...registriesConfig[registryUrl],
146
146
  })