Fix Windows artifact naming in desktop packaging
- Fix the naming convention in Electron output to align with previous artifact naming to not break external/internal URLs. - In desktop execution tests, make artifact locator logic stricter to test regression.
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
win:
|
win:
|
||||||
target: nsis
|
target: nsis
|
||||||
nsis:
|
nsis:
|
||||||
artifactName: ${name}-${version}-Setup.${ext}
|
artifactName: ${name}-Setup-${version}.${ext}
|
||||||
|
|
||||||
# -----
|
# -----
|
||||||
# Linux
|
# Linux
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
import { join } from 'path';
|
||||||
|
import { readdir } from 'fs/promises';
|
||||||
|
import { die } from '../../../utils/log';
|
||||||
|
import { exists } from '../../../utils/io';
|
||||||
|
import { getAppName } from '../../../utils/npm';
|
||||||
|
|
||||||
|
export async function findByFilePattern(
|
||||||
|
pattern: string,
|
||||||
|
directory: string,
|
||||||
|
projectRootDir: string,
|
||||||
|
): Promise<ArtifactLocation> {
|
||||||
|
if (!directory) { throw new Error('Missing directory'); }
|
||||||
|
if (!pattern) { throw new Error('Missing file pattern'); }
|
||||||
|
|
||||||
|
if (!await exists(directory)) {
|
||||||
|
return die(`Directory does not exist: ${directory}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const directoryContents = await readdir(directory);
|
||||||
|
const appName = await getAppName(projectRootDir);
|
||||||
|
const regexPattern = pattern
|
||||||
|
/* eslint-disable no-template-curly-in-string */
|
||||||
|
.replaceAll('${name}', escapeRegExp(appName))
|
||||||
|
.replaceAll('${version}', '\\d+\\.\\d+\\.\\d+')
|
||||||
|
.replaceAll('${ext}', '.*');
|
||||||
|
/* eslint-enable no-template-curly-in-string */
|
||||||
|
const regex = new RegExp(`^${regexPattern}$`);
|
||||||
|
const foundFileNames = directoryContents.filter((file) => regex.test(file));
|
||||||
|
if (!foundFileNames.length) {
|
||||||
|
return die(`No files found matching pattern "${pattern}" in ${directory} directory.`);
|
||||||
|
}
|
||||||
|
if (foundFileNames.length > 1) {
|
||||||
|
return die(`Found multiple files matching pattern "${pattern}": ${foundFileNames.join(', ')}`);
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
absolutePath: join(directory, foundFileNames[0]),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function escapeRegExp(string: string) {
|
||||||
|
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ArtifactLocation {
|
||||||
|
readonly absolutePath?: string;
|
||||||
|
}
|
||||||
@@ -1,15 +1,18 @@
|
|||||||
import { access, chmod } from 'fs/promises';
|
import { access, chmod } from 'fs/promises';
|
||||||
import { constants } from 'fs';
|
import { constants } from 'fs';
|
||||||
import { findSingleFileByExtension } from '../../utils/io';
|
|
||||||
import { log } from '../../utils/log';
|
import { log } from '../../utils/log';
|
||||||
import { ExtractionResult } from './extraction-result';
|
import { ExtractionResult } from './common/extraction-result';
|
||||||
|
import { findByFilePattern } from './common/app-artifact-locator';
|
||||||
|
|
||||||
export async function prepareLinuxApp(
|
export async function prepareLinuxApp(
|
||||||
desktopDistPath: string,
|
desktopDistPath: string,
|
||||||
|
projectRootDir: string,
|
||||||
): Promise<ExtractionResult> {
|
): Promise<ExtractionResult> {
|
||||||
const { absolutePath: appFile } = await findSingleFileByExtension(
|
const { absolutePath: appFile } = await findByFilePattern(
|
||||||
'AppImage',
|
// eslint-disable-next-line no-template-curly-in-string
|
||||||
|
'${name}-${version}.AppImage',
|
||||||
desktopDistPath,
|
desktopDistPath,
|
||||||
|
projectRootDir,
|
||||||
);
|
);
|
||||||
await makeExecutable(appFile);
|
await makeExecutable(appFile);
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -1,13 +1,20 @@
|
|||||||
import { runCommand } from '../../utils/run-command';
|
import { runCommand } from '../../utils/run-command';
|
||||||
import { findSingleFileByExtension, exists } from '../../utils/io';
|
import { exists } from '../../utils/io';
|
||||||
import { log, die, LogLevel } from '../../utils/log';
|
import { log, die, LogLevel } from '../../utils/log';
|
||||||
import { sleep } from '../../utils/sleep';
|
import { sleep } from '../../utils/sleep';
|
||||||
import { ExtractionResult } from './extraction-result';
|
import { ExtractionResult } from './common/extraction-result';
|
||||||
|
import { findByFilePattern } from './common/app-artifact-locator';
|
||||||
|
|
||||||
export async function prepareMacOsApp(
|
export async function prepareMacOsApp(
|
||||||
desktopDistPath: string,
|
desktopDistPath: string,
|
||||||
|
projectRootDir: string,
|
||||||
): Promise<ExtractionResult> {
|
): Promise<ExtractionResult> {
|
||||||
const { absolutePath: dmgPath } = await findSingleFileByExtension('dmg', desktopDistPath);
|
const { absolutePath: dmgPath } = await findByFilePattern(
|
||||||
|
// eslint-disable-next-line no-template-curly-in-string
|
||||||
|
'${name}-${version}.dmg',
|
||||||
|
desktopDistPath,
|
||||||
|
projectRootDir,
|
||||||
|
);
|
||||||
const { mountPath } = await mountDmg(dmgPath);
|
const { mountPath } = await mountDmg(dmgPath);
|
||||||
const appPath = await findMacAppExecutablePath(mountPath);
|
const appPath = await findMacAppExecutablePath(mountPath);
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -1,20 +1,22 @@
|
|||||||
import { mkdtemp, rm } from 'fs/promises';
|
import { mkdtemp, rm } from 'fs/promises';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { tmpdir } from 'os';
|
import { tmpdir } from 'os';
|
||||||
import { findSingleFileByExtension, exists } from '../../utils/io';
|
import { exists } from '../../utils/io';
|
||||||
import { log, die, LogLevel } from '../../utils/log';
|
import { log, die, LogLevel } from '../../utils/log';
|
||||||
import { runCommand } from '../../utils/run-command';
|
import { runCommand } from '../../utils/run-command';
|
||||||
import { ExtractionResult } from './extraction-result';
|
import { ExtractionResult } from './common/extraction-result';
|
||||||
|
import { findByFilePattern } from './common/app-artifact-locator';
|
||||||
|
|
||||||
export async function prepareWindowsApp(
|
export async function prepareWindowsApp(
|
||||||
desktopDistPath: string,
|
desktopDistPath: string,
|
||||||
|
projectRootDir: string,
|
||||||
): Promise<ExtractionResult> {
|
): Promise<ExtractionResult> {
|
||||||
const workdir = await mkdtemp(join(tmpdir(), 'win-nsis-installation-'));
|
const workdir = await mkdtemp(join(tmpdir(), 'win-nsis-installation-'));
|
||||||
if (await exists(workdir)) {
|
if (await exists(workdir)) {
|
||||||
log(`Temporary directory ${workdir} already exists, cleaning up...`);
|
log(`Temporary directory ${workdir} already exists, cleaning up...`);
|
||||||
await rm(workdir, { recursive: true });
|
await rm(workdir, { recursive: true });
|
||||||
}
|
}
|
||||||
const appExecutablePath = await installNsis(workdir, desktopDistPath);
|
const appExecutablePath = await installNsis(workdir, desktopDistPath, projectRootDir);
|
||||||
return {
|
return {
|
||||||
appExecutablePath,
|
appExecutablePath,
|
||||||
cleanup: async () => {
|
cleanup: async () => {
|
||||||
@@ -31,16 +33,26 @@ export async function prepareWindowsApp(
|
|||||||
async function installNsis(
|
async function installNsis(
|
||||||
installationPath: string,
|
installationPath: string,
|
||||||
desktopDistPath: string,
|
desktopDistPath: string,
|
||||||
|
projectRootDir: string,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const { absolutePath: installerPath } = await findSingleFileByExtension('exe', desktopDistPath);
|
const { absolutePath: installerPath } = await findByFilePattern(
|
||||||
|
// eslint-disable-next-line no-template-curly-in-string
|
||||||
|
'${name}-Setup-${version}.exe',
|
||||||
|
desktopDistPath,
|
||||||
|
projectRootDir,
|
||||||
|
);
|
||||||
log(`Silently installing contents of ${installerPath} to ${installationPath}...`);
|
log(`Silently installing contents of ${installerPath} to ${installationPath}...`);
|
||||||
const { error } = await runCommand(`"${installerPath}" /S /D=${installationPath}`);
|
const { error } = await runCommand(`"${installerPath}" /S /D=${installationPath}`);
|
||||||
if (error) {
|
if (error) {
|
||||||
return die(`Failed to install.\n${error}`);
|
return die(`Failed to install.\n${error}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { absolutePath: appExecutablePath } = await findSingleFileByExtension('exe', installationPath);
|
const { absolutePath: appExecutablePath } = await findByFilePattern(
|
||||||
|
// eslint-disable-next-line no-template-curly-in-string
|
||||||
|
'${name}.exe',
|
||||||
|
installationPath,
|
||||||
|
projectRootDir,
|
||||||
|
);
|
||||||
|
|
||||||
return appExecutablePath;
|
return appExecutablePath;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import {
|
|||||||
SCREENSHOT_PATH,
|
SCREENSHOT_PATH,
|
||||||
} from './config';
|
} from './config';
|
||||||
import { indentText } from './utils/text';
|
import { indentText } from './utils/text';
|
||||||
import { ExtractionResult } from './app/extractors/extraction-result';
|
import { ExtractionResult } from './app/extractors/common/extraction-result';
|
||||||
|
|
||||||
export async function main(): Promise<void> {
|
export async function main(): Promise<void> {
|
||||||
logCurrentArgs();
|
logCurrentArgs();
|
||||||
@@ -47,9 +47,9 @@ async function extractAndRun() {
|
|||||||
const extractors: {
|
const extractors: {
|
||||||
readonly [K in SupportedPlatform]: () => Promise<ExtractionResult>;
|
readonly [K in SupportedPlatform]: () => Promise<ExtractionResult>;
|
||||||
} = {
|
} = {
|
||||||
[SupportedPlatform.macOS]: () => prepareMacOsApp(DESKTOP_DIST_PATH),
|
[SupportedPlatform.macOS]: () => prepareMacOsApp(DESKTOP_DIST_PATH, PROJECT_DIR),
|
||||||
[SupportedPlatform.Linux]: () => prepareLinuxApp(DESKTOP_DIST_PATH),
|
[SupportedPlatform.Linux]: () => prepareLinuxApp(DESKTOP_DIST_PATH, PROJECT_DIR),
|
||||||
[SupportedPlatform.Windows]: () => prepareWindowsApp(DESKTOP_DIST_PATH),
|
[SupportedPlatform.Windows]: () => prepareWindowsApp(DESKTOP_DIST_PATH, PROJECT_DIR),
|
||||||
};
|
};
|
||||||
const extractor = extractors[CURRENT_PLATFORM];
|
const extractor = extractors[CURRENT_PLATFORM];
|
||||||
if (!extractor) {
|
if (!extractor) {
|
||||||
|
|||||||
@@ -1,38 +1,5 @@
|
|||||||
import { extname, join } from 'path';
|
|
||||||
import { readdir, access } from 'fs/promises';
|
import { readdir, access } from 'fs/promises';
|
||||||
import { constants } from 'fs';
|
import { constants } from 'fs';
|
||||||
import { log, die, LogLevel } from './log';
|
|
||||||
|
|
||||||
export async function findSingleFileByExtension(
|
|
||||||
extension: string,
|
|
||||||
directory: string,
|
|
||||||
): Promise<FileSearchResult> {
|
|
||||||
if (!directory) { throw new Error('Missing directory'); }
|
|
||||||
if (!extension) { throw new Error('Missing file extension'); }
|
|
||||||
|
|
||||||
if (!await exists(directory)) {
|
|
||||||
return die(`Directory does not exist: ${directory}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const directoryContents = await readdir(directory);
|
|
||||||
const foundFileNames = directoryContents.filter((file) => extname(file) === `.${extension}`);
|
|
||||||
const withoutUninstaller = foundFileNames.filter(
|
|
||||||
(fileName) => !fileName.toLowerCase().includes('uninstall'), // NSIS build has `Uninstall {app-name}.exe`
|
|
||||||
);
|
|
||||||
if (!withoutUninstaller.length) {
|
|
||||||
return die(`No ${extension} found in ${directory} directory.`);
|
|
||||||
}
|
|
||||||
if (withoutUninstaller.length > 1) {
|
|
||||||
log(`Found multiple ${extension} files: ${withoutUninstaller.join(', ')}. Using first occurrence`, LogLevel.Warn);
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
absolutePath: join(directory, withoutUninstaller[0]),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
interface FileSearchResult {
|
|
||||||
readonly absolutePath?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function exists(path: string): Promise<boolean> {
|
export async function exists(path: string): Promise<boolean> {
|
||||||
if (!path) { throw new Error('Missing path'); }
|
if (!path) { throw new Error('Missing path'); }
|
||||||
|
|||||||
@@ -64,15 +64,22 @@ export async function npmBuild(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const appNameCache = new Map<string, string>();
|
||||||
|
|
||||||
export async function getAppName(projectDir: string): Promise<string> {
|
export async function getAppName(projectDir: string): Promise<string> {
|
||||||
if (!projectDir) { throw new Error('missing project directory'); }
|
if (!projectDir) { throw new Error('missing project directory'); }
|
||||||
|
if (appNameCache.has(projectDir)) {
|
||||||
|
return appNameCache.get(projectDir);
|
||||||
|
}
|
||||||
const packageData = await readPackageJsonContents(projectDir);
|
const packageData = await readPackageJsonContents(projectDir);
|
||||||
try {
|
try {
|
||||||
const packageJson = JSON.parse(packageData);
|
const packageJson = JSON.parse(packageData);
|
||||||
if (!packageJson.name) {
|
const name = packageJson.name as string;
|
||||||
|
if (!name) {
|
||||||
return die(`The \`package.json\` file doesn't specify a name: ${packageData}`);
|
return die(`The \`package.json\` file doesn't specify a name: ${packageData}`);
|
||||||
}
|
}
|
||||||
return packageJson.name;
|
appNameCache.set(projectDir, name);
|
||||||
|
return name;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return die(`Unable to parse \`package.json\`. Error: ${error}\nContent: ${packageData}`);
|
return die(`Unable to parse \`package.json\`. Error: ${error}\nContent: ${packageData}`);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user