npm-pkgbuild 10.14.12 → 10.14.13

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/package.json +1 -1
  2. package/src/publish.mjs +32 -21
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-pkgbuild",
3
- "version": "10.14.12",
3
+ "version": "10.14.13",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/publish.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  import { basename } from "node:path";
2
2
  import { createReadStream } from "node:fs";
3
+ import { mkdir, copyFile } from "node:fs/promises";
3
4
  import fetch from "node-fetch";
4
5
  import { decodePassword } from "./util.mjs";
5
6
 
@@ -29,29 +30,39 @@ export async function publish(fileName, destination, properties) {
29
30
 
30
31
  console.log(`Publishing to ${url}`);
31
32
 
32
- if (publish.scheme === "http:" || publish.scheme === "https:") {
33
- const headers = {
34
- "user-agent": properties["user-agent"] || "npm-pkgbuild"
35
- };
33
+ switch(publish.scheme) {
34
+ case "file:":
35
+ if(url.pathname !== fileName) {
36
+ await mkdir(publish.url, { recursive: true });
37
+ await copyFile(fileName, url);
38
+ }
39
+ break;
40
+ case "http:":
41
+ case "https:":
42
+ {
43
+ const headers = {
44
+ "user-agent": properties["user-agent"] || "npm-pkgbuild"
45
+ };
36
46
 
37
- if (publish.username) {
38
- headers.authorization =
39
- "Basic " +
40
- Buffer.from(publish.username + ":" + publish.password).toString(
41
- "base64"
47
+ if (publish.username) {
48
+ headers.authorization =
49
+ "Basic " +
50
+ Buffer.from(publish.username + ":" + publish.password).toString(
51
+ "base64"
52
+ );
53
+ }
54
+
55
+ const response = await fetch(url, {
56
+ method: "PUT",
57
+ headers,
58
+ body: createReadStream(fileName)
59
+ });
60
+
61
+ if (!response.ok) {
62
+ throw new Error(
63
+ `Unable to publish to ${url}: ${response.statusText}(${response.statusCode})`
42
64
  );
43
- }
44
-
45
- const response = await fetch(url, {
46
- method: "PUT",
47
- headers,
48
- body: createReadStream(fileName)
49
- });
50
-
51
- if (!response.ok) {
52
- throw new Error(
53
- `Unable to publish to ${url}: ${response.statusText}(${response.statusCode})`
54
- );
65
+ }
55
66
  }
56
67
  }
57
68