expo-desktop 0.1.24 → 0.1.25
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.
|
@@ -30,7 +30,7 @@ export async function applyWindowsCppAppTemplateAsync(projectRoot, name) {
|
|
|
30
30
|
const replacements = await buildReplacementsRecord(projectRoot, name);
|
|
31
31
|
await renameCppAppPathsAsync(windowsRoot, name.filesafeName);
|
|
32
32
|
await renderMustacheUnderWindowsAsync(windowsRoot, replacements);
|
|
33
|
-
await finalizeWindowsCppTemplateArtifacts(projectRoot
|
|
33
|
+
await finalizeWindowsCppTemplateArtifacts(projectRoot);
|
|
34
34
|
}
|
|
35
35
|
async function looksLikeCppAppTemplateAsync(windowsRoot) {
|
|
36
36
|
try {
|
|
@@ -128,19 +128,33 @@ async function buildReplacementsRecord(projectRoot, name) {
|
|
|
128
128
|
autolinkCppPackageProviders: "\n UNREFERENCED_PARAMETER(packageProviders);",
|
|
129
129
|
};
|
|
130
130
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
131
|
+
/** Placeholder app name baked into the react-native-windows cpp-app template. */
|
|
132
|
+
const TEMPLATE_APP_NAME_PLACEHOLDER = "MyApp";
|
|
133
|
+
/**
|
|
134
|
+
* Basenames in the cpp-app template that need a one-shot literal rename
|
|
135
|
+
* (independent of any `MyApp` substitution).
|
|
136
|
+
*/
|
|
137
|
+
const SPECIAL_BASENAME_RENAMES = {
|
|
138
|
+
_gitignore: ".gitignore",
|
|
139
|
+
NuGet_Config: "NuGet.config",
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* Returns the renamed basename for one entry in the cpp-app template, applying
|
|
143
|
+
* (in order):
|
|
144
|
+
*
|
|
145
|
+
* 1. {@link SPECIAL_BASENAME_RENAMES} (e.g. `_gitignore` → `.gitignore`).
|
|
146
|
+
* 2. `MyApp` → {@link filesafeName}, anywhere in the basename.
|
|
147
|
+
*
|
|
148
|
+
* If the user's `filesafeName` happens to equal `"MyApp"`, step (2) is a no-op
|
|
149
|
+
* (avoids degenerate self-renames that previously hung
|
|
150
|
+
* `renameCppAppPathsAsync`).
|
|
151
|
+
*/
|
|
152
|
+
function renameTemplateBasename(basename, filesafeName) {
|
|
153
|
+
const renamed = SPECIAL_BASENAME_RENAMES[basename] ?? basename;
|
|
154
|
+
if (filesafeName === TEMPLATE_APP_NAME_PLACEHOLDER) {
|
|
155
|
+
return renamed;
|
|
139
156
|
}
|
|
140
|
-
return
|
|
141
|
-
}
|
|
142
|
-
function pathDepth(p) {
|
|
143
|
-
return p.split(path.sep).filter(Boolean).length;
|
|
157
|
+
return renamed.split(TEMPLATE_APP_NAME_PLACEHOLDER).join(filesafeName);
|
|
144
158
|
}
|
|
145
159
|
async function collectWindowsPathsAsync(windowsRoot) {
|
|
146
160
|
const out = [];
|
|
@@ -173,69 +187,46 @@ async function collectWindowsPathsAsync(windowsRoot) {
|
|
|
173
187
|
return out;
|
|
174
188
|
}
|
|
175
189
|
/**
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
190
|
+
* Walks `windowsRoot` pre-order (parents before children), renaming each entry
|
|
191
|
+
* by its basename via {@link renameTemplateBasename}:
|
|
192
|
+
*
|
|
193
|
+
* - `MyApp` (anywhere in the basename) → `filesafeName`
|
|
194
|
+
* - `_gitignore` → `.gitignore`
|
|
195
|
+
* - `NuGet_Config` → `NuGet.config`
|
|
196
|
+
*
|
|
197
|
+
* Pre-order is essential. `fs.rename()` atomically moves an entire directory
|
|
198
|
+
* subtree, so renaming a parent like `MyApp.Package` → `YourApp.Package`
|
|
199
|
+
* already relocates everything beneath it. A bottom-up order would risk
|
|
200
|
+
* `ENOTEMPTY` when the parent later tries to overwrite a non-empty
|
|
201
|
+
* destination.
|
|
202
|
+
*
|
|
203
|
+
* Symlinks are skipped to avoid escaping the template tree. Empty directories
|
|
204
|
+
* are handled naturally — `readdir` simply returns no children.
|
|
180
205
|
*/
|
|
181
206
|
async function renameCppAppPathsAsync(windowsRoot, filesafeName) {
|
|
182
|
-
|
|
183
|
-
const
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
const rel = path.relative(windowsRoot, abs);
|
|
187
|
-
if (!rel || rel.includes("..")) {
|
|
207
|
+
async function walk(dir) {
|
|
208
|
+
const entries = await fs.readdir(dir, { withFileTypes: true });
|
|
209
|
+
for (const entry of entries) {
|
|
210
|
+
if (entry.isSymbolicLink()) {
|
|
188
211
|
continue;
|
|
189
212
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
throw error;
|
|
213
|
+
const sourcePath = path.join(dir, entry.name);
|
|
214
|
+
const newBasename = renameTemplateBasename(entry.name, filesafeName);
|
|
215
|
+
const targetPath = newBasename === entry.name ? sourcePath : path.join(dir, newBasename);
|
|
216
|
+
if (targetPath !== sourcePath) {
|
|
217
|
+
try {
|
|
218
|
+
await fs.rename(sourcePath, targetPath);
|
|
219
|
+
}
|
|
220
|
+
catch (cause) {
|
|
221
|
+
throw new Error(`Failed to rename "${sourcePath}" → "${targetPath}"`, { cause });
|
|
200
222
|
}
|
|
201
|
-
continue;
|
|
202
|
-
}
|
|
203
|
-
if (stat.isSymbolicLink()) {
|
|
204
|
-
continue;
|
|
205
|
-
}
|
|
206
|
-
candidates.push({
|
|
207
|
-
abs,
|
|
208
|
-
rel,
|
|
209
|
-
depth: pathDepth(rel),
|
|
210
|
-
isDir: stat.isDirectory(),
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
if (!candidates.length) {
|
|
214
|
-
break;
|
|
215
|
-
}
|
|
216
|
-
candidates.sort((a, b) => {
|
|
217
|
-
if (a.depth !== b.depth) {
|
|
218
|
-
return a.depth - b.depth;
|
|
219
223
|
}
|
|
220
|
-
if (
|
|
221
|
-
|
|
224
|
+
if (entry.isDirectory()) {
|
|
225
|
+
await walk(targetPath);
|
|
222
226
|
}
|
|
223
|
-
return a.rel.localeCompare(b.rel);
|
|
224
|
-
});
|
|
225
|
-
const chosen = candidates[0];
|
|
226
|
-
const newRelWin = cppAppRelativePathTransform(chosen.rel, filesafeName);
|
|
227
|
-
const newAbs = path.join(windowsRoot, newRelWin);
|
|
228
|
-
if (newAbs === chosen.abs) {
|
|
229
|
-
continue;
|
|
230
|
-
}
|
|
231
|
-
await fs.mkdir(path.dirname(newAbs), { recursive: true });
|
|
232
|
-
try {
|
|
233
|
-
await fs.rename(chosen.abs, newAbs);
|
|
234
|
-
}
|
|
235
|
-
catch (cause) {
|
|
236
|
-
throw new Error(`Failed to rename "${chosen.abs}" -> "${newAbs}"`, { cause });
|
|
237
227
|
}
|
|
238
228
|
}
|
|
229
|
+
await walk(windowsRoot);
|
|
239
230
|
}
|
|
240
231
|
const BINARY_EXTENSIONS = new Set([
|
|
241
232
|
".png",
|
|
@@ -308,17 +299,7 @@ async function renderMustacheUnderWindowsAsync(windowsRoot, view) {
|
|
|
308
299
|
}
|
|
309
300
|
}));
|
|
310
301
|
}
|
|
311
|
-
async function finalizeWindowsCppTemplateArtifacts(projectRoot
|
|
312
|
-
const gitignoreRelPaths = await glob("**/_gitignore", {
|
|
313
|
-
cwd: windowsRoot,
|
|
314
|
-
nodir: true,
|
|
315
|
-
dot: true,
|
|
316
|
-
});
|
|
317
|
-
for (const rel of gitignoreRelPaths.sort().reverse()) {
|
|
318
|
-
const fromAbs = path.join(windowsRoot, rel);
|
|
319
|
-
const toAbs = path.join(windowsRoot, path.dirname(rel), ".gitignore");
|
|
320
|
-
await renameIfExistsPreferDest(fromAbs, toAbs);
|
|
321
|
-
}
|
|
302
|
+
async function finalizeWindowsCppTemplateArtifacts(projectRoot) {
|
|
322
303
|
await renameIfExistsPreferDest(path.join(projectRoot, "NuGet_Config"), path.join(projectRoot, "NuGet.config"));
|
|
323
304
|
const version = packageJson.version;
|
|
324
305
|
const banner = `<!-- This project was created with expo-desktop ${version} -->`;
|
package/build/common/template.js
CHANGED
|
@@ -155,7 +155,11 @@ async function prepareTemplateSourceAsync(taskTitle, source) {
|
|
|
155
155
|
await tasks([
|
|
156
156
|
promisifiedSpawnTask({
|
|
157
157
|
title: taskTitle,
|
|
158
|
-
|
|
158
|
+
// The paths are Windows-style paths rather than POSIX, so make sure to
|
|
159
|
+
// select Windows tar rather than GNU tar (which may be on path, even when
|
|
160
|
+
// invoking from cmd.exe, due to having git bash installed).
|
|
161
|
+
// tar C:\Users\Jamie\AppData\Local\Temp\expo-desktop-template-Uf1F1B\template.tgz -C C:\Users\Jamie\AppData\Local\Temp\expo-desktop-template-Uf1F1B
|
|
162
|
+
command: process.platform === "win32" ? "C:\\Windows\\System32\\tar.exe" : "tar",
|
|
159
163
|
args: ["-xzf", archivePath, "-C", tempRoot],
|
|
160
164
|
}),
|
|
161
165
|
]);
|