@prisma/compute-sdk 0.46.0 → 0.47.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/README.md +2 -0
- package/dist/service/build/build-output.d.ts +9 -4
- package/dist/service/build/build-output.d.ts.map +1 -1
- package/dist/service/build/build-output.js +43 -7
- package/dist/service/build/build-output.js.map +1 -1
- package/dist/service/settings/types.d.ts +2 -2
- package/dist/service/settings/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/service/build/build-output.ts +62 -10
- package/src/service/settings/types.ts +2 -2
package/README.md
CHANGED
|
@@ -503,6 +503,8 @@ The start is the first match of:
|
|
|
503
503
|
5. An entry file in the source: `main` or `module` from `package.json`, `index.ts`, `server.ts`, `src/index.ts`, `src/server.ts`, or their `.js` forms.
|
|
504
504
|
6. `index.html` in the Service folder.
|
|
505
505
|
|
|
506
|
+
A folder counts as created by the build when it is new after the build, or when the build wrote a file in it. A file that a build restores from a cache with its old modification time counts as written. So a second build in the same folder finds the same output as the first. A build that writes nothing the second time, such as an incremental TypeScript build with no changed source, has no output to find: state `start` or `static` in the Service config for it.
|
|
507
|
+
|
|
506
508
|
Rules 3 to 6 need the build output. For them `start` is `"after build"`, and `buildService` decides the start once the build has run.
|
|
507
509
|
|
|
508
510
|
```ts
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import type { BuildOutput } from "../settings/types.ts";
|
|
2
|
-
/** The folders of the Service folder at one moment. Taken before the build, it tells what the build
|
|
2
|
+
/** The folders of the Service folder at one moment. Taken before the build, it tells what the build wrote. */
|
|
3
3
|
export interface FolderSnapshot {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
/** Each top-level folder, with the time of the newest change to a file in it. */
|
|
5
|
+
topLevelDirs: Map<string, number>;
|
|
6
|
+
/** Each folder that holds an `index.html`, with the time that file last changed. */
|
|
7
|
+
staticDirs: Map<string, number>;
|
|
6
8
|
}
|
|
7
9
|
export declare function snapshotFolders(serviceDir: string): FolderSnapshot;
|
|
8
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* What the build wrote: the folders that were not in the snapshot, and the folders that the build wrote to again.
|
|
12
|
+
* The second kind is the output of an earlier build in the same folder. Without it a second build would find no output.
|
|
13
|
+
*/
|
|
9
14
|
export declare function buildOutputSince(serviceDir: string, before: FolderSnapshot): BuildOutput;
|
|
10
15
|
/**
|
|
11
16
|
* True when the site in `dir` holds the first scripts and styles its `index.html` links to.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-output.d.ts","sourceRoot":"","sources":["../../../src/service/build/build-output.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD,
|
|
1
|
+
{"version":3,"file":"build-output.d.ts","sourceRoot":"","sources":["../../../src/service/build/build-output.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD,8GAA8G;AAC9G,MAAM,WAAW,cAAc;IAC7B,iFAAiF;IACjF,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,oFAAoF;IACpF,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC;AAeD,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,cAAc,CAelE;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,cAAc,GACrB,WAAW,CAgBb;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAOpD"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// Finds what the build
|
|
1
|
+
// Finds what the build wrote by comparing the Service folder before and after the build.
|
|
2
2
|
// The Build rules must not guess output folders by framework.
|
|
3
|
-
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
3
|
+
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
/** Folders that never hold build output. */
|
|
6
6
|
const SKIPPED_DIRS = new Set(["node_modules", ".git"]);
|
|
@@ -12,16 +12,27 @@ const CHECKED_LINKS = 5;
|
|
|
12
12
|
const LOCAL_SCRIPT_OR_STYLE = /(?:src|href)="(\/[^"/][^"?#]*\.(?:js|mjs|css))["?#]/g;
|
|
13
13
|
export function snapshotFolders(serviceDir) {
|
|
14
14
|
return {
|
|
15
|
-
topLevelDirs: new
|
|
16
|
-
|
|
15
|
+
topLevelDirs: new Map(topLevelDirs(serviceDir).map((dir) => [
|
|
16
|
+
dir,
|
|
17
|
+
newestFileChange(join(serviceDir, dir)),
|
|
18
|
+
])),
|
|
19
|
+
staticDirs: new Map(dirsWithIndexHtml(serviceDir, STATIC_SITE_DEPTH).map((dir) => [
|
|
20
|
+
dir,
|
|
21
|
+
indexHtmlChange(serviceDir, dir),
|
|
22
|
+
])),
|
|
17
23
|
};
|
|
18
24
|
}
|
|
19
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* What the build wrote: the folders that were not in the snapshot, and the folders that the build wrote to again.
|
|
27
|
+
* The second kind is the output of an earlier build in the same folder. Without it a second build would find no output.
|
|
28
|
+
*/
|
|
20
29
|
export function buildOutputSince(serviceDir, before) {
|
|
21
30
|
return {
|
|
22
|
-
newDirs: topLevelDirs(serviceDir).filter((dir) =>
|
|
31
|
+
newDirs: topLevelDirs(serviceDir).filter((dir) => newestFileChange(join(serviceDir, dir)) >
|
|
32
|
+
(before.topLevelDirs.get(dir) ?? Number.NEGATIVE_INFINITY)),
|
|
23
33
|
newStaticDirs: dirsWithIndexHtml(serviceDir, STATIC_SITE_DEPTH)
|
|
24
|
-
.filter((dir) =>
|
|
34
|
+
.filter((dir) => indexHtmlChange(serviceDir, dir) >
|
|
35
|
+
(before.staticDirs.get(dir) ?? Number.NEGATIVE_INFINITY))
|
|
25
36
|
.filter((dir) => isSelfContained(join(serviceDir, dir)))
|
|
26
37
|
.sort(shallowestFirst),
|
|
27
38
|
};
|
|
@@ -37,6 +48,31 @@ export function isSelfContained(dir) {
|
|
|
37
48
|
.slice(0, CHECKED_LINKS);
|
|
38
49
|
return links.every((link) => existsSync(join(dir, link)));
|
|
39
50
|
}
|
|
51
|
+
function indexHtmlChange(serviceDir, dir) {
|
|
52
|
+
return changeTime(join(serviceDir, dir, "index.html"));
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* When the file was last written. A tool that restores a file from a cache can give it its old modification time,
|
|
56
|
+
* so the time the file system recorded the write counts too.
|
|
57
|
+
*/
|
|
58
|
+
function changeTime(file) {
|
|
59
|
+
const stats = statSync(file);
|
|
60
|
+
return Math.max(stats.mtimeMs, stats.ctimeMs);
|
|
61
|
+
}
|
|
62
|
+
/** The time of the newest change to a file in `dir`, at any depth. A folder with no file gives 0. */
|
|
63
|
+
function newestFileChange(dir) {
|
|
64
|
+
let newest = 0;
|
|
65
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
66
|
+
const entryPath = join(dir, entry.name);
|
|
67
|
+
if (entry.isDirectory() && !SKIPPED_DIRS.has(entry.name)) {
|
|
68
|
+
newest = Math.max(newest, newestFileChange(entryPath));
|
|
69
|
+
}
|
|
70
|
+
else if (entry.isFile()) {
|
|
71
|
+
newest = Math.max(newest, changeTime(entryPath));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return newest;
|
|
75
|
+
}
|
|
40
76
|
function topLevelDirs(serviceDir) {
|
|
41
77
|
return readdirSync(serviceDir, { withFileTypes: true })
|
|
42
78
|
.filter((entry) => entry.isDirectory() && !SKIPPED_DIRS.has(entry.name))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-output.js","sourceRoot":"","sources":["../../../src/service/build/build-output.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"build-output.js","sourceRoot":"","sources":["../../../src/service/build/build-output.ts"],"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D,aAAa,EAAE,IAAI;KACpB,CAAC,EAAE,CAAC;QACH,IAAI,KAAK,CAAC,MAAM,EAAE,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;YAClD,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAClB,CAAC;QAED,IAAI,KAAK,CAAC,WAAW,EAAE,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;YACtE,KAAK,CAAC,IAAI,CACR,GAAG,iBAAiB,CAAC,UAAU,EAAE,KAAK,GAAG,CAAC,EAAE,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CACnE,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,eAAe,CAAC,CAAS,EAAE,CAAS;IAC3C,OAAO,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;AACzE,CAAC"}
|
|
@@ -46,9 +46,9 @@ export interface ServiceBuildSettings {
|
|
|
46
46
|
}
|
|
47
47
|
/** What the build step wrote, as far as the start order needs it. */
|
|
48
48
|
export interface BuildOutput {
|
|
49
|
-
/** Top-level folders the build created, such as `dist` or `.output`. */
|
|
49
|
+
/** Top-level folders the build created or wrote to, such as `dist` or `.output`. */
|
|
50
50
|
newDirs: string[];
|
|
51
|
-
/** Folders
|
|
51
|
+
/** Folders that hold a self-contained `index.html` the build wrote, shallowest first. */
|
|
52
52
|
newStaticDirs: string[];
|
|
53
53
|
}
|
|
54
54
|
/** The fields of `package.json` that the Build rules read. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/service/settings/types.ts"],"names":[],"mappings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MAAM,GAAG,IAAI,CAAC;IACpB,sDAAsD;IACtD,OAAO,EAAE,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACjC,iDAAiD;IACjD,KAAK,EAAE,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC/B,6GAA6G;IAC7G,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,aAAa,CAAC;IACvC,wGAAwG;IACxG,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;IAC9B,0FAA0F;IAC1F,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,qEAAqE;AACrE,MAAM,WAAW,WAAW;IAC1B,oFAAoF;IACpF,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,yFAAyF;IACzF,aAAa,EAAE,MAAM,EAAE,CAAC;CACzB;AAED,8DAA8D;AAC9D,MAAM,WAAW,WAAW;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
// Finds what the build
|
|
1
|
+
// Finds what the build wrote by comparing the Service folder before and after the build.
|
|
2
2
|
// The Build rules must not guess output folders by framework.
|
|
3
|
-
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
3
|
+
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import type { BuildOutput } from "../settings/types.ts";
|
|
6
6
|
|
|
7
|
-
/** The folders of the Service folder at one moment. Taken before the build, it tells what the build
|
|
7
|
+
/** The folders of the Service folder at one moment. Taken before the build, it tells what the build wrote. */
|
|
8
8
|
export interface FolderSnapshot {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
/** Each top-level folder, with the time of the newest change to a file in it. */
|
|
10
|
+
topLevelDirs: Map<string, number>;
|
|
11
|
+
/** Each folder that holds an `index.html`, with the time that file last changed. */
|
|
12
|
+
staticDirs: Map<string, number>;
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
/** Folders that never hold build output. */
|
|
@@ -25,22 +27,41 @@ const LOCAL_SCRIPT_OR_STYLE =
|
|
|
25
27
|
|
|
26
28
|
export function snapshotFolders(serviceDir: string): FolderSnapshot {
|
|
27
29
|
return {
|
|
28
|
-
topLevelDirs: new
|
|
29
|
-
|
|
30
|
+
topLevelDirs: new Map(
|
|
31
|
+
topLevelDirs(serviceDir).map((dir) => [
|
|
32
|
+
dir,
|
|
33
|
+
newestFileChange(join(serviceDir, dir)),
|
|
34
|
+
]),
|
|
35
|
+
),
|
|
36
|
+
staticDirs: new Map(
|
|
37
|
+
dirsWithIndexHtml(serviceDir, STATIC_SITE_DEPTH).map((dir) => [
|
|
38
|
+
dir,
|
|
39
|
+
indexHtmlChange(serviceDir, dir),
|
|
40
|
+
]),
|
|
41
|
+
),
|
|
30
42
|
};
|
|
31
43
|
}
|
|
32
44
|
|
|
33
|
-
/**
|
|
45
|
+
/**
|
|
46
|
+
* What the build wrote: the folders that were not in the snapshot, and the folders that the build wrote to again.
|
|
47
|
+
* The second kind is the output of an earlier build in the same folder. Without it a second build would find no output.
|
|
48
|
+
*/
|
|
34
49
|
export function buildOutputSince(
|
|
35
50
|
serviceDir: string,
|
|
36
51
|
before: FolderSnapshot,
|
|
37
52
|
): BuildOutput {
|
|
38
53
|
return {
|
|
39
54
|
newDirs: topLevelDirs(serviceDir).filter(
|
|
40
|
-
(dir) =>
|
|
55
|
+
(dir) =>
|
|
56
|
+
newestFileChange(join(serviceDir, dir)) >
|
|
57
|
+
(before.topLevelDirs.get(dir) ?? Number.NEGATIVE_INFINITY),
|
|
41
58
|
),
|
|
42
59
|
newStaticDirs: dirsWithIndexHtml(serviceDir, STATIC_SITE_DEPTH)
|
|
43
|
-
.filter(
|
|
60
|
+
.filter(
|
|
61
|
+
(dir) =>
|
|
62
|
+
indexHtmlChange(serviceDir, dir) >
|
|
63
|
+
(before.staticDirs.get(dir) ?? Number.NEGATIVE_INFINITY),
|
|
64
|
+
)
|
|
44
65
|
.filter((dir) => isSelfContained(join(serviceDir, dir)))
|
|
45
66
|
.sort(shallowestFirst),
|
|
46
67
|
};
|
|
@@ -59,6 +80,37 @@ export function isSelfContained(dir: string): boolean {
|
|
|
59
80
|
return links.every((link) => existsSync(join(dir, link)));
|
|
60
81
|
}
|
|
61
82
|
|
|
83
|
+
function indexHtmlChange(serviceDir: string, dir: string): number {
|
|
84
|
+
return changeTime(join(serviceDir, dir, "index.html"));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* When the file was last written. A tool that restores a file from a cache can give it its old modification time,
|
|
89
|
+
* so the time the file system recorded the write counts too.
|
|
90
|
+
*/
|
|
91
|
+
function changeTime(file: string): number {
|
|
92
|
+
const stats = statSync(file);
|
|
93
|
+
|
|
94
|
+
return Math.max(stats.mtimeMs, stats.ctimeMs);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** The time of the newest change to a file in `dir`, at any depth. A folder with no file gives 0. */
|
|
98
|
+
function newestFileChange(dir: string): number {
|
|
99
|
+
let newest = 0;
|
|
100
|
+
|
|
101
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
102
|
+
const entryPath = join(dir, entry.name);
|
|
103
|
+
|
|
104
|
+
if (entry.isDirectory() && !SKIPPED_DIRS.has(entry.name)) {
|
|
105
|
+
newest = Math.max(newest, newestFileChange(entryPath));
|
|
106
|
+
} else if (entry.isFile()) {
|
|
107
|
+
newest = Math.max(newest, changeTime(entryPath));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return newest;
|
|
112
|
+
}
|
|
113
|
+
|
|
62
114
|
function topLevelDirs(serviceDir: string): string[] {
|
|
63
115
|
return readdirSync(serviceDir, { withFileTypes: true })
|
|
64
116
|
.filter((entry) => entry.isDirectory() && !SKIPPED_DIRS.has(entry.name))
|
|
@@ -55,9 +55,9 @@ export interface ServiceBuildSettings {
|
|
|
55
55
|
|
|
56
56
|
/** What the build step wrote, as far as the start order needs it. */
|
|
57
57
|
export interface BuildOutput {
|
|
58
|
-
/** Top-level folders the build created, such as `dist` or `.output`. */
|
|
58
|
+
/** Top-level folders the build created or wrote to, such as `dist` or `.output`. */
|
|
59
59
|
newDirs: string[];
|
|
60
|
-
/** Folders
|
|
60
|
+
/** Folders that hold a self-contained `index.html` the build wrote, shallowest first. */
|
|
61
61
|
newStaticDirs: string[];
|
|
62
62
|
}
|
|
63
63
|
|