enhanced-publish 1.0.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.
Files changed (2) hide show
  1. package/index.mjs +39 -0
  2. package/package.json +14 -0
package/index.mjs ADDED
@@ -0,0 +1,39 @@
1
+ import { spawn } from "child_process"
2
+ import { readFileSync } from "fs"
3
+ import pacote from "pacote"
4
+
5
+ function getPackageInfo() {
6
+ const pJson = JSON.parse(readFileSync("./package.json"))
7
+
8
+ return {
9
+ name: pJson.name,
10
+ version: pJson.version,
11
+ }
12
+ }
13
+
14
+ async function existsPackageInRegistry(pkg) {
15
+ return await pacote.packument(pkg.name).then(
16
+ (packument) => {
17
+ if (packument.versions === undefined) return false
18
+ return packument.versions[pkg.version] !== undefined
19
+ },
20
+ () => {
21
+ console.warn(`Unable to determine published version, assuming ${pkg.name} unpublished.`)
22
+ return false
23
+ }
24
+ )
25
+ }
26
+
27
+ const pkg = getPackageInfo()
28
+ const isPublished = await existsPackageInRegistry(pkg)
29
+
30
+ if (process.argv.includes("--if-possible") && isPublished) {
31
+ console.log(`${pkg.name} with version ${pkg.version} is already published.`)
32
+ process.exit(0)
33
+ } else {
34
+ let args = [...process.argv]
35
+ args.splice(0, 2)
36
+ args = args.filter((arg) => arg !== "--if-possible")
37
+
38
+ spawn("npm", ["publish", ...args], { stdio: "inherit" })
39
+ }
package/package.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "enhanced-publish",
3
+ "version": "1.0.0",
4
+ "description": "Npm publish command with lerna's from-package publish behaviour.",
5
+ "bin": "index.js",
6
+ "author": "js-soft GmbH",
7
+ "license": "MIT",
8
+ "dependencies": {
9
+ "pacote": "^12.0.3"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public"
13
+ }
14
+ }