Skip to content

Commit 57a7f91

Browse files
committed
Fix nfpm script path issue by copying scripts to working directory
- Copy postinst/postrm scripts to working directory before building - Update nfpm configuration to use relative paths for scripts - Clean up copied scripts after package build completes - This ensures nfpm can find the scripts when running from working directory
1 parent b53451b commit 57a7f91

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

package/src/linux/installer.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,16 @@ async function createNfpmConfig(
7171
},
7272
],
7373

74-
scripts: {
75-
postinstall: join(configuration.directoryInfo.pkg, "scripts", "linux", format, "postinst"),
76-
postremove: join(configuration.directoryInfo.pkg, "scripts", "linux", format, "postrm"),
77-
},
7874

7975
overrides: {},
8076
};
8177

78+
// Use relative paths for scripts (relative to working directory where nfpm runs)
79+
config.scripts = {
80+
postinstall: `./postinst`,
81+
postremove: `./postrm`,
82+
};
83+
8284
// Format-specific configuration
8385
if (format === 'deb') {
8486
config.overrides.deb = {
@@ -139,6 +141,18 @@ async function buildPackageWithNfpm(
139141
overwrite: true,
140142
});
141143

144+
// Copy scripts to working directory for nfpm to find them
145+
const scriptSourceDir = join(configuration.directoryInfo.pkg, "scripts", "linux", format);
146+
const postinstScript = join(scriptSourceDir, "postinst");
147+
const postrmScript = join(scriptSourceDir, "postrm");
148+
149+
if (existsSync(postinstScript)) {
150+
copySync(postinstScript, join(workingDir, "postinst"));
151+
}
152+
if (existsSync(postrmScript)) {
153+
copySync(postrmScript, join(workingDir, "postrm"));
154+
}
155+
142156
// Create nfpm configuration
143157
const nfpmConfig = await createNfpmConfig(configuration, format, workingDir);
144158
const configPath = join(workingDir, "nfpm.yaml");
@@ -165,8 +179,16 @@ async function buildPackageWithNfpm(
165179

166180
info(`Package created: ${outputPath}`);
167181

168-
// Clean up - config file is now in the working directory
182+
// Clean up - config file and scripts are in the working directory
169183
Deno.removeSync(join(workingDir, "nfpm.yaml"));
184+
const postinstPath = join(workingDir, "postinst");
185+
const postrmPath = join(workingDir, "postrm");
186+
if (existsSync(postinstPath)) {
187+
Deno.removeSync(postinstPath);
188+
}
189+
if (existsSync(postrmPath)) {
190+
Deno.removeSync(postrmPath);
191+
}
170192
// Optionally remove working directory
171193
// Deno.removeSync(workingDir, { recursive: true });
172194
}

0 commit comments

Comments
 (0)