@prisma/compute-sdk 0.17.0 → 0.18.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.
- package/dist/archive.d.ts +1 -1
- package/dist/archive.js +35 -12
- package/dist/archive.js.map +1 -1
- package/package.json +1 -1
- package/src/archive.ts +64 -15
package/dist/archive.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Create a tar.gz archive in memory from a build artifact directory.
|
|
3
3
|
*
|
|
4
4
|
* - Files are added under the `bundle/` prefix.
|
|
5
|
-
* - Symlinks are
|
|
5
|
+
* - Symlinks are preserved as symlink entries.
|
|
6
6
|
* - A synthetic `compute.manifest.json` entry is injected at the tar root.
|
|
7
7
|
*
|
|
8
8
|
* Returns the gzipped archive as a Uint8Array.
|
package/dist/archive.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { lstat, readdir, readFile, readlink
|
|
1
|
+
import { lstat, readdir, readFile, readlink } from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { createGzip } from "node:zlib";
|
|
4
4
|
import { pack } from "tar-stream";
|
|
@@ -7,7 +7,7 @@ const COMPUTE_MANIFEST_VERSION = "1";
|
|
|
7
7
|
* Create a tar.gz archive in memory from a build artifact directory.
|
|
8
8
|
*
|
|
9
9
|
* - Files are added under the `bundle/` prefix.
|
|
10
|
-
* - Symlinks are
|
|
10
|
+
* - Symlinks are preserved as symlink entries.
|
|
11
11
|
* - A synthetic `compute.manifest.json` entry is injected at the tar root.
|
|
12
12
|
*
|
|
13
13
|
* Returns the gzipped archive as a Uint8Array.
|
|
@@ -35,16 +35,8 @@ async function addDirectory(packer, rootPath, fsPath, tarPrefix) {
|
|
|
35
35
|
const fullPath = path.join(directoryPath, entry.name);
|
|
36
36
|
const tarPath = `${tarPrefix}/${entry.name}`;
|
|
37
37
|
if (entry.isSymbolicLink()) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const resolvedPath = resolvePathWithinRoot(rootPath, path.resolve(directoryPath, target));
|
|
41
|
-
const resolvedStat = await stat(resolvedPath);
|
|
42
|
-
if (resolvedStat.isDirectory()) {
|
|
43
|
-
await addDirectory(packer, rootPath, resolvedPath, tarPath);
|
|
44
|
-
}
|
|
45
|
-
else if (resolvedStat.isFile()) {
|
|
46
|
-
await addFile(packer, rootPath, resolvedPath, tarPath, resolvedStat);
|
|
47
|
-
}
|
|
38
|
+
const linkStat = await lstat(fullPath);
|
|
39
|
+
await addSymlink(packer, rootPath, fullPath, tarPath, linkStat);
|
|
48
40
|
}
|
|
49
41
|
else if (entry.isDirectory()) {
|
|
50
42
|
await addDirectory(packer, rootPath, fullPath, tarPath);
|
|
@@ -65,6 +57,37 @@ async function addFile(packer, rootPath, fsPath, tarPath, fileStat) {
|
|
|
65
57
|
mtime: fileStat.mtime,
|
|
66
58
|
}, content);
|
|
67
59
|
}
|
|
60
|
+
async function addSymlink(packer, rootPath, fsPath, tarPath, linkStat) {
|
|
61
|
+
const symlinkPath = resolvePathWithinRoot(rootPath, fsPath);
|
|
62
|
+
const target = await readlink(symlinkPath);
|
|
63
|
+
const linkname = await resolveArchiveSymlinkTarget(rootPath, symlinkPath, target);
|
|
64
|
+
packer.entry({
|
|
65
|
+
name: tarPath,
|
|
66
|
+
type: "symlink",
|
|
67
|
+
linkname,
|
|
68
|
+
mode: linkStat.mode,
|
|
69
|
+
mtime: linkStat.mtime,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
async function resolveArchiveSymlinkTarget(rootPath, symlinkPath, target) {
|
|
73
|
+
const symlinkDir = path.dirname(symlinkPath);
|
|
74
|
+
const resolvedTarget = resolvePathWithinRoot(rootPath, path.isAbsolute(target) ? target : path.resolve(symlinkDir, target));
|
|
75
|
+
await lstat(resolvedTarget).catch((error) => {
|
|
76
|
+
if (isENOENT(error)) {
|
|
77
|
+
throw new Error(`Symlink target does not exist: ${symlinkPath} -> ${target} (resolved to ${resolvedTarget})`);
|
|
78
|
+
}
|
|
79
|
+
throw error;
|
|
80
|
+
});
|
|
81
|
+
if (!path.isAbsolute(target)) {
|
|
82
|
+
return target;
|
|
83
|
+
}
|
|
84
|
+
return path.relative(symlinkDir, resolvedTarget) || ".";
|
|
85
|
+
}
|
|
86
|
+
function isENOENT(error) {
|
|
87
|
+
return (error instanceof Error &&
|
|
88
|
+
"code" in error &&
|
|
89
|
+
error.code === "ENOENT");
|
|
90
|
+
}
|
|
68
91
|
function resolvePathWithinRoot(rootPath, fsPath) {
|
|
69
92
|
const normalizedRootPath = path.resolve(rootPath);
|
|
70
93
|
const resolvedPath = path.resolve(fsPath);
|
package/dist/archive.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"archive.js","sourceRoot":"","sources":["../src/archive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"archive.js","sourceRoot":"","sources":["../src/archive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAa,IAAI,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,wBAAwB,GAAG,GAAY,CAAC;AAE9C;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,SAAiB,EACjB,UAAkB;IAElB,MAAM,MAAM,GAAG,IAAI,EAAE,CAAC;IACtB,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAEzC,uCAAuC;IACvC,MAAM,YAAY,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAEzD,2CAA2C;IAC3C,MA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,IAAI,KAAK,CAAC,wCAAwC,YAAY,EAAE,CAAC,CAAC;IAC1E,CAAC;IAED,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,SAAS,cAAc,CAAC,MAAY;IAClC,OAAO,IAAI,OAAO,CAAa,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACjD,MAAM,MAAM,GAAa,EAAE,CAAC;QAC5B,MAAM,IAAI,GAAG,UAAU,EAAE,CAAC;QAE1B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAElB,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAa,EAAE,EAAE;YAChC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACrB,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;YAClB,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACzB,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
package/src/archive.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { lstat, readdir, readFile, readlink
|
|
1
|
+
import { lstat, readdir, readFile, readlink } from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { createGzip } from "node:zlib";
|
|
4
4
|
import { type Pack, pack } from "tar-stream";
|
|
@@ -9,7 +9,7 @@ const COMPUTE_MANIFEST_VERSION = "1" as const;
|
|
|
9
9
|
* Create a tar.gz archive in memory from a build artifact directory.
|
|
10
10
|
*
|
|
11
11
|
* - Files are added under the `bundle/` prefix.
|
|
12
|
-
* - Symlinks are
|
|
12
|
+
* - Symlinks are preserved as symlink entries.
|
|
13
13
|
* - A synthetic `compute.manifest.json` entry is injected at the tar root.
|
|
14
14
|
*
|
|
15
15
|
* Returns the gzipped archive as a Uint8Array.
|
|
@@ -56,19 +56,8 @@ async function addDirectory(
|
|
|
56
56
|
const tarPath = `${tarPrefix}/${entry.name}`;
|
|
57
57
|
|
|
58
58
|
if (entry.isSymbolicLink()) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const resolvedPath = resolvePathWithinRoot(
|
|
62
|
-
rootPath,
|
|
63
|
-
path.resolve(directoryPath, target),
|
|
64
|
-
);
|
|
65
|
-
const resolvedStat = await stat(resolvedPath);
|
|
66
|
-
|
|
67
|
-
if (resolvedStat.isDirectory()) {
|
|
68
|
-
await addDirectory(packer, rootPath, resolvedPath, tarPath);
|
|
69
|
-
} else if (resolvedStat.isFile()) {
|
|
70
|
-
await addFile(packer, rootPath, resolvedPath, tarPath, resolvedStat);
|
|
71
|
-
}
|
|
59
|
+
const linkStat = await lstat(fullPath);
|
|
60
|
+
await addSymlink(packer, rootPath, fullPath, tarPath, linkStat);
|
|
72
61
|
} else if (entry.isDirectory()) {
|
|
73
62
|
await addDirectory(packer, rootPath, fullPath, tarPath);
|
|
74
63
|
} else if (entry.isFile()) {
|
|
@@ -98,6 +87,66 @@ async function addFile(
|
|
|
98
87
|
);
|
|
99
88
|
}
|
|
100
89
|
|
|
90
|
+
async function addSymlink(
|
|
91
|
+
packer: Pack,
|
|
92
|
+
rootPath: string,
|
|
93
|
+
fsPath: string,
|
|
94
|
+
tarPath: string,
|
|
95
|
+
linkStat: { mode: number; mtime: Date },
|
|
96
|
+
): Promise<void> {
|
|
97
|
+
const symlinkPath = resolvePathWithinRoot(rootPath, fsPath);
|
|
98
|
+
const target = await readlink(symlinkPath);
|
|
99
|
+
const linkname = await resolveArchiveSymlinkTarget(
|
|
100
|
+
rootPath,
|
|
101
|
+
symlinkPath,
|
|
102
|
+
target,
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
packer.entry({
|
|
106
|
+
name: tarPath,
|
|
107
|
+
type: "symlink",
|
|
108
|
+
linkname,
|
|
109
|
+
mode: linkStat.mode,
|
|
110
|
+
mtime: linkStat.mtime,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async function resolveArchiveSymlinkTarget(
|
|
115
|
+
rootPath: string,
|
|
116
|
+
symlinkPath: string,
|
|
117
|
+
target: string,
|
|
118
|
+
): Promise<string> {
|
|
119
|
+
const symlinkDir = path.dirname(symlinkPath);
|
|
120
|
+
const resolvedTarget = resolvePathWithinRoot(
|
|
121
|
+
rootPath,
|
|
122
|
+
path.isAbsolute(target) ? target : path.resolve(symlinkDir, target),
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
await lstat(resolvedTarget).catch((error) => {
|
|
126
|
+
if (isENOENT(error)) {
|
|
127
|
+
throw new Error(
|
|
128
|
+
`Symlink target does not exist: ${symlinkPath} -> ${target} (resolved to ${resolvedTarget})`,
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
throw error;
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
if (!path.isAbsolute(target)) {
|
|
136
|
+
return target;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return path.relative(symlinkDir, resolvedTarget) || ".";
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function isENOENT(error: unknown): boolean {
|
|
143
|
+
return (
|
|
144
|
+
error instanceof Error &&
|
|
145
|
+
"code" in error &&
|
|
146
|
+
(error as { code?: string }).code === "ENOENT"
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
101
150
|
function resolvePathWithinRoot(rootPath: string, fsPath: string): string {
|
|
102
151
|
const normalizedRootPath = path.resolve(rootPath);
|
|
103
152
|
const resolvedPath = path.resolve(fsPath);
|