enhanced-publish 1.0.1 → 1.0.2

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