Skip to content

Commit

Permalink
Merge pull request #17 from ManasJayanth/local-npmrc
Browse files Browse the repository at this point in the history
Create .npmrc file local to project path in _esy-package folder
  • Loading branch information
ManasJayanth authored May 29, 2024
2 parents 57d8b22 + be3ecb6 commit 96bc717
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
22 changes: 15 additions & 7 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export async function createSession(
let testUsername = "foo-" + crypto.randomBytes(4).toString("hex"); // TODO centralise this
let testEmail = "[email protected]"; // TODO centralise this
let testPassword = "bar"; // TODO centralise this
let { addr, port } = server;
const registryUrl = NpmServer.getUrl(server);
try {
debug("Attempting npm login");
Expand All @@ -45,8 +44,6 @@ export async function createSession(
registryUrl,
);
}
// Writing to .npmrc by hand. See docs/notes.org to see why
fs.appendFileSync(localNpmRc, `//${addr}:${port}/:_authToken="${token}"\n`);
return token;
}

Expand Down Expand Up @@ -109,11 +106,22 @@ async function setupLocalVerdaccio(
return NpmServer.setup(storagePath, manifest, registryLogLevel);
}

async function publishToLocalVerdaccio(server: any, tarballPath: path) {
async function publishToLocalVerdaccio(
server: any,
tarballPath: path,
cwd: path,
) {
Log.info("Publishing to verdaccio server");
const registryUrl = NpmServer.getUrl(server);
await createSession(server);
Log.process("verdaccio", await NpmClient.publish(registryUrl, tarballPath));
const token = await createSession(server);
// Writing to .npmrc by hand. See docs/notes.org to see why
const tokenFile = Path.join(cwd, "_esy-package", ".npmrc");
const { addr, port } = server;
fs.appendFileSync(tokenFile, `//${addr}:${port}/:_authToken="${token}"\n`);
Log.process(
"verdaccio",
await NpmClient.publish(registryUrl, tarballPath, tokenFile),
);
}

async function getLocalVerdaccioWithPackage(
Expand All @@ -129,7 +137,7 @@ async function getLocalVerdaccioWithPackage(
manifest,
registryLogLevel,
);
await publishToLocalVerdaccio(server, tarballPath);
await publishToLocalVerdaccio(server, tarballPath, cwd);
return server;
}

Expand Down
3 changes: 2 additions & 1 deletion src/lib/npm-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import type { url, path, ProcessOutput } from "../types";
export async function publish(
registryUrl: url,
tarballPath: path,
userconfig: path,
): Promise<ProcessOutput> {
return new Promise(function (resolve, reject) {
cp.exec(
`npm publish --registry ${registryUrl} ${tarballPath}`,
`npm publish --userconfig ${userconfig} --registry ${registryUrl} ${tarballPath}`,
{ maxBuffer: 5000 * 1024 },
(error: Error, stdout, stderr) => {
if (error) {
Expand Down

0 comments on commit 96bc717

Please sign in to comment.