hd-garden 0.6.0 → 0.6.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.
package/package.json
CHANGED
|
@@ -101,21 +101,44 @@ async function listFiles(root, directory = root) {
|
|
|
101
101
|
return files;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
// The deployment ID vinext writes into pages and payloads, and bakes into the
|
|
105
|
+
// client bundle as CLIENT_DEPLOYMENT_VERSION (vinext 1.x compares the two on
|
|
106
|
+
// every client navigation and loads the whole page when they differ).
|
|
107
|
+
const DEPLOYMENT_ID_SOURCES = [".html", ".rsc", ".txt"];
|
|
108
|
+
const DEPLOYMENT_ID_CARRIERS = [".html", ".rsc", ".txt", ".js", ".mjs", ".json"];
|
|
109
|
+
|
|
110
|
+
function buildDeploymentVersions(text) {
|
|
111
|
+
const found = new Set();
|
|
112
|
+
for (const match of text.matchAll(/"deploymentVersion":"([^"]+)"/gu)) found.add(match[1]);
|
|
113
|
+
for (const match of text.matchAll(/\\["]deploymentVersion\\["]:\\["]([^"\\]+)\\["]/gu)) found.add(match[1]);
|
|
114
|
+
found.delete(deploymentVersionPlaceholder);
|
|
115
|
+
return found;
|
|
116
|
+
}
|
|
117
|
+
|
|
104
118
|
async function stabilizeDeploymentVersion(root) {
|
|
105
119
|
const hash = crypto.createHash("sha256");
|
|
106
120
|
const normalizedFiles = new Map();
|
|
121
|
+
const files = await listFiles(root);
|
|
122
|
+
|
|
123
|
+
// The build's own IDs, read from the pages and payloads.
|
|
124
|
+
const versions = new Set();
|
|
125
|
+
for (const file of files) {
|
|
126
|
+
if (!DEPLOYMENT_ID_SOURCES.includes(path.extname(file.relativePath))) continue;
|
|
127
|
+
for (const version of buildDeploymentVersions(await fs.readFile(file.absolutePath, "utf8"))) versions.add(version);
|
|
128
|
+
}
|
|
107
129
|
|
|
108
|
-
for (const file of
|
|
130
|
+
for (const file of files) {
|
|
109
131
|
const original = await fs.readFile(file.absolutePath);
|
|
110
132
|
let normalized = original;
|
|
133
|
+
const extension = path.extname(file.relativePath);
|
|
111
134
|
// Flight payloads: .rsc from vinext 0.0.x, index.txt / <page>.txt from vinext 1.x static export.
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
);
|
|
118
|
-
normalizedFiles.set(file.absolutePath, normalized);
|
|
135
|
+
// The same ID also sits in the client JavaScript, so every copy gets the same stable value.
|
|
136
|
+
if (DEPLOYMENT_ID_CARRIERS.includes(extension)) {
|
|
137
|
+
let text = original.toString("utf8");
|
|
138
|
+
if (DEPLOYMENT_ID_SOURCES.includes(extension)) text = normalizeDeploymentVersion(text, deploymentVersionPlaceholder);
|
|
139
|
+
for (const version of versions) text = text.replaceAll(version, deploymentVersionPlaceholder);
|
|
140
|
+
normalized = Buffer.from(text, "utf8");
|
|
141
|
+
if (DEPLOYMENT_ID_SOURCES.includes(extension) || !normalized.equals(original)) normalizedFiles.set(file.absolutePath, normalized);
|
|
119
142
|
}
|
|
120
143
|
hash.update(file.relativePath);
|
|
121
144
|
hash.update("\0");
|
|
@@ -133,7 +156,7 @@ async function stabilizeDeploymentVersion(root) {
|
|
|
133
156
|
].join("-");
|
|
134
157
|
|
|
135
158
|
for (const [filePath, content] of normalizedFiles) {
|
|
136
|
-
const stabilized =
|
|
159
|
+
const stabilized = content.toString("utf8").replaceAll(deploymentVersionPlaceholder, version);
|
|
137
160
|
await fs.writeFile(filePath, stabilized);
|
|
138
161
|
}
|
|
139
162
|
}
|