Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: working on windows installation issue #1762

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"/bin",
"/lib",
"/assets",
"/scripts",
"/npm-shrinkwrap.json",
"/oclif.manifest.json"
],
Expand Down Expand Up @@ -159,7 +160,7 @@
"pack:macos": "oclif pack macos && npm run pack:rename",
"pack:linux": "oclif pack deb && npm run pack:rename",
"pack:tarballs": "oclif pack tarballs -t linux-x64 && npm run pack:rename",
"pack:windows": "oclif pack win && npm run pack:rename",
"pack:windows": "node scripts/pack-windows-fix.js",
"pack:rename": "node scripts/releasePackagesRename.js",
"prepublishOnly": "npm run build",
"pretest": "npm run build",
Expand Down
67 changes: 67 additions & 0 deletions scripts/pack-windows-fix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const { spawnSync } = require('child_process');

Check failure on line 1 in scripts/pack-windows-fix.js

View workflow job for this annotation

GitHub Actions / Test NodeJS PR - ubuntu-latest

Require statement not part of import statement
const fs = require('fs');

Check failure on line 2 in scripts/pack-windows-fix.js

View workflow job for this annotation

GitHub Actions / Test NodeJS PR - ubuntu-latest

Require statement not part of import statement
const path = require('path');

Check failure on line 3 in scripts/pack-windows-fix.js

View workflow job for this annotation

GitHub Actions / Test NodeJS PR - ubuntu-latest

Require statement not part of import statement
const packageJson = require('../package.json');

Check failure on line 4 in scripts/pack-windows-fix.js

View workflow job for this annotation

GitHub Actions / Test NodeJS PR - ubuntu-latest

Require statement not part of import statement
const version = packageJson.version;

console.log(`Packaging AsyncAPI CLI version ${version} for Windows...`);

const targetFile = path.resolve('node_modules/oclif/lib/tarballs/build.js');

if (!fs.existsSync(targetFile)) {
console.error(`File not found: ${targetFile}`);
throw error;
}

console.log(`Found target file: ${targetFile}`);

const backupPath = `${targetFile}.backup`;
if (!fs.existsSync(backupPath)) {
fs.copyFileSync(targetFile, backupPath);
console.log(`Backed up original file to: ${backupPath}`);
}

let fileContent = fs.readFileSync(targetFile, 'utf8');

if (fileContent.includes('--force-local')) {
console.log('Patching file to remove --force-local flag');
fileContent = fileContent.replace(/--force-local/g, '');
fs.writeFileSync(targetFile, fileContent);
console.log('File patched successfully');
} else {
console.log('No --force-local flag found in the file. It may have been already patched.');
}

try {
console.log('Running oclif pack win...');
const oclifResult = spawnSync('oclif', ['pack', 'win'], {
stdio: 'inherit',
shell: true
});

if (oclifResult.status !== 0) {
console.error('Oclif packaging failed with status:', oclifResult.status);
throw error;
}

console.log('Running rename script...');
const renameResult = spawnSync('node', ['scripts/releasePackagesRename.js'], {
stdio: 'inherit',
shell: true
});

if (renameResult.status !== 0) {
console.error('Rename script failed with status:', renameResult.status);
throw error;
}
console.log('Windows packaging completed successfully!');
} catch (err) {
console.error('Error during packaging:', err);
} finally {
if (fs.existsSync(backupPath)) {
fs.copyFileSync(backupPath, targetFile);
console.log('Restored original file');
fs.unlinkSync(backupPath);
console.log('Removed backup file');
}
}
68 changes: 67 additions & 1 deletion scripts/releasePackagesRename.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,78 @@
await checkAndRenameFile(generatedPath, newPath);
}

// async function renameWindows({version, name, sha, arch}) {
// const dist = 'dist/win32';

// const generatedPath = path.resolve(dist, `${name}-v${version}-${sha}-${arch}.exe`);
// const newPath = path.resolve(dist, `asyncapi.${arch}.exe`);
// await checkAndRenameFile(generatedPath, newPath);
// }

async function renameWindows({version, name, sha, arch}) {
const dist = 'dist/win32';

// Ensure directory exists
await createDirectory(dist);

const generatedPath = path.resolve(dist, `${name}-v${version}-${sha}-${arch}.exe`);
const newPath = path.resolve(dist, `asyncapi.${arch}.exe`);
await checkAndRenameFile(generatedPath, newPath);

try {
console.log(`Checking for Windows installer at: ${generatedPath}`);

// Create Windows-specific configuration
const configDir = path.resolve('dist', 'config');
await createDirectory(configDir);

// Create installer configuration to use shorter paths
const winConfig = {
installPath: 'C:\\AsyncAPI',
shortPaths: true,
useShortDirectoryNames: true,
maxPathLength: 200 // Set a safe path limit

Check failure on line 81 in scripts/releasePackagesRename.js

View workflow job for this annotation

GitHub Actions / Test NodeJS PR - ubuntu-latest

Multiple spaces found before '// Set a safe ...'
};

fs.writeFileSync(
path.resolve(configDir, 'win-install-config.json'),
JSON.stringify(winConfig, null, 2)
);

// Create nsis custom script to handle long paths
const nsisScript = `
!include LogicLib.nsh
!include FileFunc.nsh

Function HandleLongPaths
${If} $INSTDIR == ""
StrCpy $INSTDIR "C:\\AsyncAPI"
${EndIf}

; Enable long paths in registry
WriteRegDWORD HKLM "SYSTEM\\CurrentControlSet\\Control\\FileSystem" "LongPathsEnabled" 1
FunctionEnd

!define USE_LONG_PATHS
!define MUI_CUSTOMFUNCTION_GUIINIT HandleLongPaths
`;

fs.writeFileSync(
path.resolve(configDir, 'windows-longpaths.nsh'),
nsisScript
);

// Rename the installer if it exists
if (await fileExists(generatedPath)) {
console.log(`Found Windows installer, renaming to: ${newPath}`);
await rename(generatedPath, newPath);
return true;
}
console.warn(`Warning: Windows installer not found at ${generatedPath}`);
return false;
} catch (err) {
console.error(`Error processing Windows installer: ${err.message}`);
return false;
}
}

async function renamePkg({version, name, sha, arch}) {
Expand Down
Loading