enhanced-publish 1.0.5 → 1.1.1

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/README.md +6 -0
  2. package/index.js +22 -6
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -10,6 +10,12 @@
10
10
  The package is a command line tool that can be used to publish your package to npm.
11
11
  It works exactly like [npm publish](https://docs.npmjs.com/cli/v8/commands/npm-publish) but it also allows you to specify to only publish the package if there is no version conflict.
12
12
 
13
+ ### --if-possible
14
+
13
15
  The behavior is heavily inspired by lerna's [from-package](https://github.com/lerna/lerna/tree/main/commands/publish#bump-from-package) publishing strategy.
14
16
 
15
17
  The command adds a flag `--if-possible` to the `npm publish` command and will not publish if the package already exists in the registry.
18
+
19
+ ### --use-preid-as-tag
20
+
21
+ Will use the '[preid](https://docs.npmjs.com/cli/v8/commands/npm-version#preid)' as the tag. `1.0.0-alpha.1` becomes `--tag alpha` in the publish command.
package/index.js CHANGED
@@ -26,21 +26,37 @@ async function existsPackageInRegistry(pkg) {
26
26
  )
27
27
  }
28
28
 
29
+ const newFlags = ["--if-possible", "--use-preid-as-tag"]
30
+
29
31
  async function run() {
32
+ if (process.argv.includes("--help") || process.argv.includes("-h")) {
33
+ console.log(`This command will publish your package to the npm registry. It adds the following flags to the original publish command:
34
+ --if-possible - If the package is already published, it will not publish it again.
35
+ --use-preid-as-tag - Will use the 'preid' as the tag. e.g. '1.0.0-alpha.1' -> '--tag alpha'`)
36
+ process.exit(0)
37
+ }
38
+
30
39
  const pkg = getPackageInfo()
31
40
  const isPublished = await existsPackageInRegistry(pkg)
32
41
 
33
42
  if (process.argv.includes("--if-possible") && isPublished) {
34
43
  console.log(`${pkg.name} with version ${pkg.version} is already published.`)
35
44
  process.exit(0)
36
- } else {
37
- let args = [...process.argv]
38
- args.splice(0, 2)
39
- args = args.filter((arg) => arg !== "--if-possible")
45
+ }
46
+
47
+ let args = [...process.argv]
48
+ args.splice(0, 2)
49
+ args = args.filter((arg) => !newFlags.includes(arg))
40
50
 
41
- const child = spawn("npm", ["publish", ...args], { stdio: "inherit" })
42
- child.on("exit", (code) => process.exit(code))
51
+ const semverWithPreidRegex = /^\d+\.\d+\.\d+(?:-([a-z]+)(?:\.\d+)+)?$/
52
+ const semverMatches = semverWithPreidRegex.exec(pkg.version)
53
+ if (process.argv.includes("--use-preid-as-tag") && semverMatches && semverMatches[1]) {
54
+ const preid = semverMatches[1]
55
+ args.push("--tag", preid)
43
56
  }
57
+
58
+ const child = spawn("npm", ["publish", ...args], { stdio: "inherit" })
59
+ child.on("exit", (code) => process.exit(code))
44
60
  }
45
61
 
46
62
  run()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "enhanced-publish",
3
- "version": "1.0.5",
3
+ "version": "1.1.1",
4
4
  "description": "Npm publish command with lerna's from-package publish behaviour.",
5
5
  "repository": "github:js-soft/enhanced-npm-publish",
6
6
  "license": "MIT",
@@ -10,7 +10,7 @@
10
10
  "index.js"
11
11
  ],
12
12
  "dependencies": {
13
- "pacote": "^12.0.3"
13
+ "pacote": "^15.0.6"
14
14
  },
15
15
  "publishConfig": {
16
16
  "access": "public"